qid
int64
4
8.14M
question
stringlengths
20
48.3k
answers
list
date
stringlengths
10
10
metadata
list
input
stringlengths
12
45k
output
stringlengths
2
31.8k
503,414
<p>I have a program which has some Textareas / Labels these can be anywhere on the Window and in any order - however I want to assign them values from a List, Collection or Array so I want one label to read MyCollection(1) and another MyCollection(2) and so on - they are not always together or in the same order so a Li...
[ { "answer_id": 503461, "author": "DanSingerman", "author_id": 43965, "author_profile": "https://Stackoverflow.com/users/43965", "pm_score": 2, "selected": false, "text": "<p>I think the problem here is that you are using the initialize method to save the record to the filesystem, when if...
2009/02/02
[ "https://Stackoverflow.com/questions/503414", "https://Stackoverflow.com", "https://Stackoverflow.com/users/61529/" ]
I have a program which has some Textareas / Labels these can be anywhere on the Window and in any order - however I want to assign them values from a List, Collection or Array so I want one label to read MyCollection(1) and another MyCollection(2) and so on - they are not always together or in the same order so a ListB...
I think the problem here is that you are using the initialize method to save the record to the filesystem, when if you want to instantiate an article object to return with ``` Article.new ``` then that will also call the initialize method; which is probably why it's confusing; you seem to be conflating two things in...
503,436
<p>In my numerical simulation I have code similar to the following snippet</p> <pre><code>double x; do { x = /* some computation */; } while (x &lt;= 0.0); /* some algorithm that requires x to be (precisely) larger than 0 */ </code></pre> <p>With certain compilers (e.g. gcc) on certain platforms (e.g. linux, x87 ma...
[ { "answer_id": 503474, "author": "John D. Cook", "author_id": 25188, "author_profile": "https://Stackoverflow.com/users/25188", "pm_score": 1, "selected": false, "text": "<p>I wonder whether you have the right stopping criterion. It sounds like x &lt;= 0 is an <strong>exception</strong>...
2009/02/02
[ "https://Stackoverflow.com/questions/503436", "https://Stackoverflow.com", "https://Stackoverflow.com/users/61510/" ]
In my numerical simulation I have code similar to the following snippet ``` double x; do { x = /* some computation */; } while (x <= 0.0); /* some algorithm that requires x to be (precisely) larger than 0 */ ``` With certain compilers (e.g. gcc) on certain platforms (e.g. linux, x87 math) it is possible that `x` i...
As Arkadiy stated in the comments, an explicit cast `((double)x) <= 0.0` *should* work - at least according to the standard. C99:TC3, 5.2.4.2.2 §8: > > Except for assignment and cast (which remove all extra range and precision), the values of operations with floating operands and values subject to the usual arithmet...
503,456
<p>I have been trying to use a formula that is used to work out exclusive VAT in a program that our team is creating. The formula works correctly when used in a calculator or in excel, though gives a different output when used within a function in our program!</p> <p>here is the function:</p> <pre><code>function fn_c...
[ { "answer_id": 503475, "author": "duffymo", "author_id": 37213, "author_profile": "https://Stackoverflow.com/users/37213", "pm_score": 0, "selected": false, "text": "<p>I'm guessing that it's due to the difference between integers and floating point numbers.</p>\n\n<p>Try it like this:</...
2009/02/02
[ "https://Stackoverflow.com/questions/503456", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I have been trying to use a formula that is used to work out exclusive VAT in a program that our team is creating. The formula works correctly when used in a calculator or in excel, though gives a different output when used within a function in our program! here is the function: ``` function fn_calcVat() { var v...
The formula is incorrect, it should be ``` vAmt = vTranAmt * (vRate / 100.0d); ```
503,459
<p>I'm having trouble getting in touch with SQL Server Managemen Studio 2008! I want to create a link-table that will link an Event to many Audiences (EventAudience).</p> <p>An example of the data that could be contained:</p> <h2>EventId | AudienceId</h2> <pre><code> 4 1 5 1 4 ...
[ { "answer_id": 503470, "author": "Dave Markle", "author_id": 24995, "author_profile": "https://Stackoverflow.com/users/24995", "pm_score": 4, "selected": true, "text": "<p>Just use:</p>\n\n<pre><code>CREATE UNIQUE INDEX UQ_EventAudience ON dbo.EventAudience(EventID, AudienceID);\n</code>...
2009/02/02
[ "https://Stackoverflow.com/questions/503459", "https://Stackoverflow.com", "https://Stackoverflow.com/users/57591/" ]
I'm having trouble getting in touch with SQL Server Managemen Studio 2008! I want to create a link-table that will link an Event to many Audiences (EventAudience). An example of the data that could be contained: EventId | AudienceId -------------------- ``` 4 1 5 1 4 2 `...
Just use: ``` CREATE UNIQUE INDEX UQ_EventAudience ON dbo.EventAudience(EventID, AudienceID); ```
503,462
<p>I'm trying to integrate some photo related functionality with my site and facebook. I checked out facebook connect and it seems like the way to go for this (since I don't want to make an app, just have users authenticate and then grab some content from facebook to integrate into our site)</p> <p>First of all, if yo...
[ { "answer_id": 512919, "author": "Jiaaro", "author_id": 2908, "author_profile": "https://Stackoverflow.com/users/2908", "pm_score": 0, "selected": false, "text": "<p>the solution proposeed by van gale (removing the lines which reference the signals.py file) work well enough. I think I ma...
2009/02/02
[ "https://Stackoverflow.com/questions/503462", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2908/" ]
I'm trying to integrate some photo related functionality with my site and facebook. I checked out facebook connect and it seems like the way to go for this (since I don't want to make an app, just have users authenticate and then grab some content from facebook to integrate into our site) First of all, if you think th...
I've just added the missing file folks. Sorry for the inconveniences. :/
503,469
<p>I have coded some JavaScript to perform an ajax call in an asp.net application. This triggers a method that calls a URL, sending some parameters in the POST.</p> <p>The receiving page processes the data and updates our database.</p> <p>We will be providing this code to customers to allow them to send us the data w...
[ { "answer_id": 503494, "author": "Vinze", "author_id": 26859, "author_profile": "https://Stackoverflow.com/users/26859", "pm_score": 1, "selected": false, "text": "<p>You should secure you're service using SSL</p>\n\n<p>Edit : I forgot the most \"basic\" : HTTP authentication (using logi...
2009/02/02
[ "https://Stackoverflow.com/questions/503469", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12318/" ]
I have coded some JavaScript to perform an ajax call in an asp.net application. This triggers a method that calls a URL, sending some parameters in the POST. The receiving page processes the data and updates our database. We will be providing this code to customers to allow them to send us the data we need in their c...
You can use SOAP to pass a username/password with the request. SSL should be used to encrypt the data going over the wire. Here is some code that we use: This is a class that will hold the Credentials that are sent with the request: ``` Imports System.Web.Services.Protocols Public Class ServiceCredentials Inherits S...
503,480
<p>As a newbie to FoxPro (but an old-hand at Clipper), I'm a bit at a loss to figure out how to return an array from the following OLEPUBLIC class. <em>edit</em>: I've modified the code belw to take into consideration the remarks made by @Stuart below. </p> <pre><code>DEFINE CLASS db AS CUSTOM OLEPUBLIC DIMENSION...
[ { "answer_id": 504470, "author": "stuartd", "author_id": 43846, "author_profile": "https://Stackoverflow.com/users/43846", "pm_score": 1, "selected": true, "text": "<p>Try 'return @ada', but VFP arrays have never played nicely with other languages despite <a href=\"http://msdn.microsoft....
2009/02/02
[ "https://Stackoverflow.com/questions/503480", "https://Stackoverflow.com", "https://Stackoverflow.com/users/426/" ]
As a newbie to FoxPro (but an old-hand at Clipper), I'm a bit at a loss to figure out how to return an array from the following OLEPUBLIC class. *edit*: I've modified the code belw to take into consideration the remarks made by @Stuart below. ``` DEFINE CLASS db AS CUSTOM OLEPUBLIC DIMENSION ada(1) && public sco...
Try 'return @ada', but VFP arrays have never played nicely with other languages despite [attempts to make them do so](http://msdn.microsoft.com/en-us/library/aa728495(VS.71).aspx).
503,488
<p>I want to get my <code>ComboBox</code> in XAML to bind to my <code>List</code> collection of custom objects in code behind.</p> <p>Currently the <code>ComboBox</code> lists for each entry <code>dpwpf.Contact</code> which is my <code>{namespace}.{classname}</code>.</p> <p>What do I need to put in the XAML to tell i...
[ { "answer_id": 503515, "author": "user61477", "author_id": 61477, "author_profile": "https://Stackoverflow.com/users/61477", "pm_score": 2, "selected": false, "text": "<p>you need to use DisplayMember=\"TheValue\"</p>\n\n<p>you can add this in the XAML or in the CLR\nalso note your bindi...
2009/02/02
[ "https://Stackoverflow.com/questions/503488", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4639/" ]
I want to get my `ComboBox` in XAML to bind to my `List` collection of custom objects in code behind. Currently the `ComboBox` lists for each entry `dpwpf.Contact` which is my `{namespace}.{classname}`. What do I need to put in the XAML to tell it to list out, e.g. LastName + FirstName? I know it's something like `{...
You can override the `ToString` method of `Contact`, or you can define a `DataTemplate` in WPF. ``` xmlns:dpwpf="... namespace of dpwpf" <Window.Resources> <DataTemplate DataType="{x:Type dpwpf:Contact}"> <StackPanel Orientation="Horizontal"> <TextBlock Text="{Binding LastName}"> <...
503,549
<p>I'm working through the "Data Binding" chapter in Pro WPF in C# 2008.</p> <p>They have you set up this class:</p> <pre><code>public class StoreDB { public Contact GetContact(int id) {...} public List&lt;Contact&gt; GetContacts() {...} } </code></pre> <p>The idea is to call these methods, getting either a ...
[ { "answer_id": 503572, "author": "user61477", "author_id": 61477, "author_profile": "https://Stackoverflow.com/users/61477", "pm_score": 1, "selected": false, "text": "<p>I dont know the book your using but the question here is what database are you using if its SQL then you can use LINQ...
2009/02/02
[ "https://Stackoverflow.com/questions/503549", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4639/" ]
I'm working through the "Data Binding" chapter in Pro WPF in C# 2008. They have you set up this class: ``` public class StoreDB { public Contact GetContact(int id) {...} public List<Contact> GetContacts() {...} } ``` The idea is to call these methods, getting either a `Contact` or a `List<Contact>` and bind...
Welcome in the Linq world! You want to return an `IQueryable<Contact>`: ``` public class StoreDB { public Contact GetContact(int id) {...} // change to this: public IQueryable<Contact> GetContacts() {...} } ``` Now you can say this without wasting cycles or bandwidth: ``` IQueryable<Contact> SerachByF...
503,560
<p>I have a database that has four columns like this</p> <p>level_1, level_2, level_3, level_4</p> <p>There are also id, name, etc., but only these four are the ones that matter to me at the moment.</p> <p>I need to know which column, by columnname, has the value 'BOSS'.</p> <p>For example, level_2 may have the val...
[ { "answer_id": 503586, "author": "Sergio", "author_id": 32037, "author_profile": "https://Stackoverflow.com/users/32037", "pm_score": 0, "selected": false, "text": "<p>I am not sure what you need... your question is a bit fuzzy...</p>\n\n<p>If you need to access the column name do like s...
2009/02/02
[ "https://Stackoverflow.com/questions/503560", "https://Stackoverflow.com", "https://Stackoverflow.com/users/28045/" ]
I have a database that has four columns like this level\_1, level\_2, level\_3, level\_4 There are also id, name, etc., but only these four are the ones that matter to me at the moment. I need to know which column, by columnname, has the value 'BOSS'. For example, level\_2 may have the value BOSS. I need to know th...
Ok, so you have 4 columns that could have the value BOSS. I guess the best way to solve your problem would be to cycle thought these 4 columns until you get the Value BOSS, when you do find it, store the column name on a variable so you can get it back later.
503,564
<p>I have a service written in C# (.NET 1.1) and want it to perform some cleanup actions at midnight every night. I have to keep all code contained within the service, so what's the easiest way to accomplish this? Use of <code>Thread.Sleep()</code> and checking for the time rolling over?</p>
[ { "answer_id": 503581, "author": "CubanX", "author_id": 27555, "author_profile": "https://Stackoverflow.com/users/27555", "pm_score": 2, "selected": false, "text": "<p>The way I accomplish this is with a timer.</p>\n\n<p>Run a server timer, have it check the Hour/Minute every 60 seconds....
2009/02/02
[ "https://Stackoverflow.com/questions/503564", "https://Stackoverflow.com", "https://Stackoverflow.com/users/61545/" ]
I have a service written in C# (.NET 1.1) and want it to perform some cleanup actions at midnight every night. I have to keep all code contained within the service, so what's the easiest way to accomplish this? Use of `Thread.Sleep()` and checking for the time rolling over?
I wouldn't use Thread.Sleep(). Either use a scheduled task (as others have mentioned), or set up a timer inside your service, which fires periodically (every 10 minutes for example) and check if the date changed since the last run: ``` private Timer _timer; private DateTime _lastRun = DateTime.Now.AddDays(-1); protec...
503,566
<p>What would be the most efficient way to do a paging query in SQLServer 2000?</p> <p>Where a "paging query" would be the equivalent of using the LIMIT statement in MySQL.</p> <p>EDIT: Could a stored procedure be more efficient than any set based query in that case?</p>
[ { "answer_id": 503579, "author": "mmx", "author_id": 33708, "author_profile": "https://Stackoverflow.com/users/33708", "pm_score": 3, "selected": false, "text": "<p>I think a nested <code>SELECT TOP n</code> query is probably the most efficient way to accomplish it.</p>\n\n<pre><code>SEL...
2009/02/02
[ "https://Stackoverflow.com/questions/503566", "https://Stackoverflow.com", "https://Stackoverflow.com/users/39057/" ]
What would be the most efficient way to do a paging query in SQLServer 2000? Where a "paging query" would be the equivalent of using the LIMIT statement in MySQL. EDIT: Could a stored procedure be more efficient than any set based query in that case?
[Paging of Large Resultsets](http://www.codeproject.com/KB/aspnet/PagingLarge.aspx) and the winner is using RowCount. Also there's a generalized version for more complex queries. But give credit to **Jasmin Muharemovic** :) ``` DECLARE @Sort /* the type of the sorting column */ SET ROWCOUNT @StartRow SELECT @Sort = So...
503,573
<p>I'm trying to find out the best practice when removing characters from the start of a string.</p> <p>In some languages, you can use MID without a length parameter however, in TSQL the length is required.</p> <p>Considering the following code, what is the best practise? (The hex string is variable length)</p> <pre...
[ { "answer_id": 503576, "author": "Marc Gravell", "author_id": 23354, "author_profile": "https://Stackoverflow.com/users/23354", "pm_score": 5, "selected": true, "text": "<p>Well, the first is more expressive of your intent. The last is clearly messy (hard-coded length etc). I doubt you'd...
2009/02/02
[ "https://Stackoverflow.com/questions/503573", "https://Stackoverflow.com", "https://Stackoverflow.com/users/59754/" ]
I'm trying to find out the best practice when removing characters from the start of a string. In some languages, you can use MID without a length parameter however, in TSQL the length is required. Considering the following code, what is the best practise? (The hex string is variable length) ``` DECLARE @sHex VARCHAR...
Well, the first is more expressive of your intent. The last is clearly messy (hard-coded length etc). I doubt you'd find much performance difference between the first & second, so I'd use the simplest - `RIGHT`. Of course, if you are doing this lots, you could write a udf that encapsulates this - then if you change yo...
503,578
<p>I have a bit of code which runs in 10.919 s. Profiling it shows that 10.182 s are wasted in </p> <pre><code>opaque.double </code></pre> <p>Which is called when I use</p> <pre><code>jClass.GetArrays(jArray1,jArray2); struct.prop1 = double(jArray1); struct.prop2 = double(jArray1); </code></pre> <p>What can be don...
[ { "answer_id": 503598, "author": "Adam Davis", "author_id": 2915, "author_profile": "https://Stackoverflow.com/users/2915", "pm_score": 1, "selected": false, "text": "<p>You might consider saving it to a file, then reading it in on the other end. It might also be similarly slow (especia...
2009/02/02
[ "https://Stackoverflow.com/questions/503578", "https://Stackoverflow.com", "https://Stackoverflow.com/users/28772/" ]
I have a bit of code which runs in 10.919 s. Profiling it shows that 10.182 s are wasted in ``` opaque.double ``` Which is called when I use ``` jClass.GetArrays(jArray1,jArray2); struct.prop1 = double(jArray1); struct.prop2 = double(jArray1); ``` What can be done? I have to use Java to interact with external A...
The problem lays in the usage of boxed Java primitives - ***java.lang.Double*** in this case. Simply changing the signature of the Java from Double to double cause Matlab to seamlessly work with the array without the casting overhead.
503,583
<p>Is there a way to access everything in the symbol table in Ruby? I want to be able to serialize or otherwise save the current state of a run of a program. To do this, it seems I need to be able to iterate over all the variables in scope.</p>
[ { "answer_id": 504028, "author": "Allyn", "author_id": 57414, "author_profile": "https://Stackoverflow.com/users/57414", "pm_score": 0, "selected": false, "text": "<p>I don't believe there is, but you could always use <a href=\"http://www.ruby-doc.org/core-1.8.7/classes/Marshal.html\" re...
2009/02/02
[ "https://Stackoverflow.com/questions/503583", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12887/" ]
Is there a way to access everything in the symbol table in Ruby? I want to be able to serialize or otherwise save the current state of a run of a program. To do this, it seems I need to be able to iterate over all the variables in scope.
I think he comes from a perl background , and that he would like to obtain all the variables defined in a script and serialize them . This way , when he'll load the file , he'll get them back . I'm still searching about how to get a list of the variables , but serialization will be made using Marshal.dump and reading t...
503,592
<p>I have a form which has a lot of SELECTs. For various reasons, I'd like to only pass to the form the ones that are selected by the user. In other words, each SELECT is something like this:</p> <pre><code>&lt;SELECT name=field001&gt; &lt;option value=-1&gt;Please pick a value&lt;/option&gt; &lt;option value=1&gt...
[ { "answer_id": 503623, "author": "Sergio", "author_id": 32037, "author_profile": "https://Stackoverflow.com/users/32037", "pm_score": 4, "selected": true, "text": "<p>When you post a form it will send the values of every single control to the server. If you need to prevent this I think y...
2009/02/02
[ "https://Stackoverflow.com/questions/503592", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11522/" ]
I have a form which has a lot of SELECTs. For various reasons, I'd like to only pass to the form the ones that are selected by the user. In other words, each SELECT is something like this: ``` <SELECT name=field001> <option value=-1>Please pick a value</option> <option value=1>1</option> <option value=2>2</optio...
When you post a form it will send the values of every single control to the server. If you need to prevent this I think your best option is to overwrite the onSubmit action and redirect to a new instance of the same page placing only the information you want on the querystring. Take in mind that this will increase you...
503,626
<p>I am creating an application in which I have two mxml components, MainPanel.mxml and TextPanel.mxml, that are contained in a parent application called index.mxml. When I type something the textbox that exists in TextPanel.mxml, I want to be able to bind this data to a label that exists in TextPanel.mxml. I know this...
[ { "answer_id": 503973, "author": "hasseg", "author_id": 4111, "author_profile": "https://Stackoverflow.com/users/4111", "pm_score": 1, "selected": false, "text": "<p>What you've done here is a kind of implementation of the <a href=\"http://en.wikipedia.org/wiki/Mediator_pattern\" rel=\"n...
2009/02/02
[ "https://Stackoverflow.com/questions/503626", "https://Stackoverflow.com", "https://Stackoverflow.com/users/56225/" ]
I am creating an application in which I have two mxml components, MainPanel.mxml and TextPanel.mxml, that are contained in a parent application called index.mxml. When I type something the textbox that exists in TextPanel.mxml, I want to be able to bind this data to a label that exists in TextPanel.mxml. I know this ca...
That's one way of doing it, sure. But you could also create another class, say, to hold the data written by one (or any) of your components, then give each component a reference to that object; that might get you the same effect with a bit less code and manual event handling. For example, the class object holding the ...
503,627
<p>I'm trying to execute a asp.net webservice using jquery. When I pass only one input parameter it works fine: </p> <pre><code>$.ajax({ type: "POST", url: url, data: "{'Id1':'2'}", contentType: "application/json; charset=utf-8", dataType: "json", success: callback }); </code></pre> ...
[ { "answer_id": 503652, "author": "Mark W", "author_id": 31377, "author_profile": "https://Stackoverflow.com/users/31377", "pm_score": 3, "selected": false, "text": "<p>This is a stab in the dark, but maybe do you need to wrap your JSON arguments; like say something like this:</p>\n\n<pre...
2009/02/02
[ "https://Stackoverflow.com/questions/503627", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15928/" ]
I'm trying to execute a asp.net webservice using jquery. When I pass only one input parameter it works fine: ``` $.ajax({ type: "POST", url: url, data: "{'Id1':'2'}", contentType: "application/json; charset=utf-8", dataType: "json", success: callback }); ``` but if I try to pass mu...
Found the solution: It should be: ``` "{'Id1':'2','Id2':'2'}" ``` and not ``` "{'Id1':'2'},{'Id2':'2'}" ```
503,630
<p>I have a form that has a few similar controls and the parent contains the properties, but the child actually has the html controls. How could I setup my getters/setters using the "child" controls in the parent class? (Webforms - fyi)</p> <p>I found the below via search, and what I'm looking for is the inverse</p> ...
[ { "answer_id": 503653, "author": "Sergio", "author_id": 32037, "author_profile": "https://Stackoverflow.com/users/32037", "pm_score": 1, "selected": false, "text": "<p>If I understood you correctly you have one usercontrol (child) inside another usercontrol(parent) and you need to access...
2009/02/02
[ "https://Stackoverflow.com/questions/503630", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2701/" ]
I have a form that has a few similar controls and the parent contains the properties, but the child actually has the html controls. How could I setup my getters/setters using the "child" controls in the parent class? (Webforms - fyi) I found the below via search, and what I'm looking for is the inverse [Getting value...
Follwing up on the comments: Ok, so if i understood correctly, you want to have the controls on the usercontrols but the code on the parent(because you don't want to duplicate code). You have 2 ways of doing this: 1 - Place your code at the parent and create properties on each child so you can access the values of ...
503,632
<p>My development team is moving to branching soon - we've been cursed with SourceSafe and we're moving to Team Foundation Server - and I'm curious about something.</p> <p>Traditionally when we do major revisions to our product, to the point where not even the folder structure or the filenames stay the same, we do a n...
[ { "answer_id": 503676, "author": "ern", "author_id": 5609, "author_profile": "https://Stackoverflow.com/users/5609", "pm_score": 3, "selected": true, "text": "<p>Our development team uses a pretty standard branching structure in Subversion. In the main repository we have 3 folders:</p>\n...
2009/02/02
[ "https://Stackoverflow.com/questions/503632", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2577/" ]
My development team is moving to branching soon - we've been cursed with SourceSafe and we're moving to Team Foundation Server - and I'm curious about something. Traditionally when we do major revisions to our product, to the point where not even the folder structure or the filenames stay the same, we do a new root fo...
Our development team uses a pretty standard branching structure in Subversion. In the main repository we have 3 folders: * branches * tags * trunk In your example, all of the V\* folders would go under tags. All of the main development happens in trunk, and we use branches when we need to have a variation on what is ...
503,633
<p>I'm trying to execute a linux command through a PHP command-line script, which is no problem using the exec command.</p> <p>The problem is, the command I am executing (mysqldump) outputs an error message if something is wrong (for example user/password is incorrect). I can't seem to be able to capture this error in...
[ { "answer_id": 503641, "author": "ZombieSheep", "author_id": 377, "author_profile": "https://Stackoverflow.com/users/377", "pm_score": 0, "selected": false, "text": "<p>Have you looked at the <a href=\"http://php.net/manual/en/function.system.php\" rel=\"nofollow noreferrer\">system()</a...
2009/02/02
[ "https://Stackoverflow.com/questions/503633", "https://Stackoverflow.com", "https://Stackoverflow.com/users/49226/" ]
I'm trying to execute a linux command through a PHP command-line script, which is no problem using the exec command. The problem is, the command I am executing (mysqldump) outputs an error message if something is wrong (for example user/password is incorrect). I can't seem to be able to capture this error in order to ...
``` exec("mysqldump -u user -p passwod database > outputfile.sql 2> error.log"); ```
503,651
<p>I'm trying to figure out how to best lay this out. I'll explain what I have now, but I'm wondering if there is a better way to do this.</p> <p>I have a class Section that has basic properties: Name, Description, et.al. I use a list of Sections for the users to choose from. They can add a Section as many times as th...
[ { "answer_id": 503685, "author": "C. Ross", "author_id": 16487, "author_profile": "https://Stackoverflow.com/users/16487", "pm_score": 0, "selected": false, "text": "<p>I would add the group property. A null value would be appropriate for a section that had not been assigned to a parent...
2009/02/02
[ "https://Stackoverflow.com/questions/503651", "https://Stackoverflow.com", "https://Stackoverflow.com/users/54617/" ]
I'm trying to figure out how to best lay this out. I'll explain what I have now, but I'm wondering if there is a better way to do this. I have a class Section that has basic properties: Name, Description, et.al. I use a list of Sections for the users to choose from. They can add a Section as many times as they want to...
It sounds like the group isn't an intrinsic property of a section. It's only meaningful when relating sections to parents. Given this, I wouldn't add a group property. Maybe make a section container class that exposes the group: ``` interface IGroupedSection { ISection Section { get; } string Group { get; } } ...
503,662
<p>So I have a <code>UserControl</code> with some cascading <code>DropDownList</code>s on it. Selecting from list 1 enables list 2, which in turn enables list 3. Once you've made a selection in all three lists, you can move to the next page.</p> <p>The <code>DropDownList</code>s are all inside an <code>UpdatePanel</...
[ { "answer_id": 503693, "author": "thmsn", "author_id": 28145, "author_profile": "https://Stackoverflow.com/users/28145", "pm_score": 4, "selected": true, "text": "<p>Could you not add a update panel around the \"next page\" and then add a trigger to the dropdownlist updatepanel for trigg...
2009/02/02
[ "https://Stackoverflow.com/questions/503662", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5486/" ]
So I have a `UserControl` with some cascading `DropDownList`s on it. Selecting from list 1 enables list 2, which in turn enables list 3. Once you've made a selection in all three lists, you can move to the next page. The `DropDownList`s are all inside an `UpdatePanel`. But the "Next Page" button is outside the `Update...
Could you not add a update panel around the "next page" and then add a trigger to the dropdownlist updatepanel for triggering the next page update panel? Just throwing out ideas, without actually having tried it :)
503,664
<p>While designing an interface for a class I normally get caught in two minds whether should I provide member functions which can be calculated / derived by using combinations of other member functions. For example:</p> <pre><code>class DocContainer { public: Doc* getDoc(int index) const; bool isDocSelected(Do...
[ { "answer_id": 503710, "author": "David Norman", "author_id": 34502, "author_profile": "https://Stackoverflow.com/users/34502", "pm_score": 2, "selected": false, "text": "<p>I think its fine to have getSelectedDocs as a member function. It's a perfectly reasonable operation for a DocCon...
2009/02/02
[ "https://Stackoverflow.com/questions/503664", "https://Stackoverflow.com", "https://Stackoverflow.com/users/39742/" ]
While designing an interface for a class I normally get caught in two minds whether should I provide member functions which can be calculated / derived by using combinations of other member functions. For example: ``` class DocContainer { public: Doc* getDoc(int index) const; bool isDocSelected(Doc*) const; ...
In general, you should probably prefer free functions. Think about it from an OOP perspective. If the function does not need access to any private members, then why should it be *given* access to them? That's not good for encapsulation. It means more code that may potentially fail when the internals of the class is mo...
503,666
<p>I have a TSQL script that is used to set up a database as part of my product's installation. It takes a number of steps which all together take five minutes or so. Sometimes this script fails on the last step because the user running the script does not have sufficient rights to the database. In this case I would li...
[ { "answer_id": 503683, "author": "BradC", "author_id": 21398, "author_profile": "https://Stackoverflow.com/users/21398", "pm_score": 0, "selected": false, "text": "<p>I assume it is failing on an update or insert after a long series of selects.</p>\n\n<p>Just try a <em>simple</em> update...
2009/02/02
[ "https://Stackoverflow.com/questions/503666", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20553/" ]
I have a TSQL script that is used to set up a database as part of my product's installation. It takes a number of steps which all together take five minutes or so. Sometimes this script fails on the last step because the user running the script does not have sufficient rights to the database. In this case I would like ...
``` select * from fn_my_permissions(NULL, 'SERVER') ``` This gives you a list of permissions the current session has on the server ``` select * from fn_my_permissions(NULL, 'DATABASE') ``` This gives you a list of permissions for the current session on the current database. [See here for more information](http:/...
503,673
<p>I'm writing a SQL query in SQL Server in which I need to replace multiple string values with a single string value. For example</p> <pre><code>Product Quantity ------- -------- Apple 2 Orange 3 Banana 1 Vegetable 7 Dairy 6 </code></pre> <p>would become</p> <pre><code>Product Q...
[ { "answer_id": 503682, "author": "Rockcoder", "author_id": 5290, "author_profile": "https://Stackoverflow.com/users/5290", "pm_score": 1, "selected": false, "text": "<p>If there are no other products than those mentioned you could do:</p>\n\n<pre><code>SELECT 'Fruit' AS Product,\n ...
2009/02/02
[ "https://Stackoverflow.com/questions/503673", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18891/" ]
I'm writing a SQL query in SQL Server in which I need to replace multiple string values with a single string value. For example ``` Product Quantity ------- -------- Apple 2 Orange 3 Banana 1 Vegetable 7 Dairy 6 ``` would become ``` Product Quantity ------- -------- Fruit ...
BradC has the best answer so far, but in case you are for some reason unable to create the additional table I wanted to post an adaption of Kibbee's answer: ``` SELECT CASE WHEN Product IN ('Banana', 'Apple', 'Orange') Then 'Fruit' ELSE Product END FROM [Table] ```
503,684
<p>I have used PHP for awhile now and have used it well with CodeIgniter, which is a great framework. I am starting on a new personal project and last time I was considering what to use (PHP vs ROR) I used PHP because of the scalability problems I heard ROR had, especially after reading what the Twitter devs had to say...
[ { "answer_id": 503720, "author": "phresus", "author_id": 56808, "author_profile": "https://Stackoverflow.com/users/56808", "pm_score": 3, "selected": false, "text": "<p>What is breaks down to with RoR is that unless you're in Alexa's top 100, you will not have any scalability problems. ...
2009/02/02
[ "https://Stackoverflow.com/questions/503684", "https://Stackoverflow.com", "https://Stackoverflow.com/users/49018/" ]
I have used PHP for awhile now and have used it well with CodeIgniter, which is a great framework. I am starting on a new personal project and last time I was considering what to use (PHP vs ROR) I used PHP because of the scalability problems I heard ROR had, especially after reading what the Twitter devs had to say ab...
To expand on Ryan Doherty's answer a bit... I work in a statically typed language for my day job (.NET/C#), as well as Ruby as a side thing. Prior to my current day job, I was the lead programmer for a ruby development firm doing work for the New York Times Syndication service. Before that, I worked in PHP as well (th...
503,689
<p>Say I had the following code:</p> <pre><code>% Cellmode_subfunction_test.m %% Cell 1 foo(1); %% Cell 2 foo(2); %% Definition of the foo subfunction function foo(num) disp(['num=' num2str(num)]); </code></pre> <p>How can test cell 1 and cell 2 with the subfunction defined at the end?</p> <p>Edit: Basically each ...
[ { "answer_id": 503724, "author": "gnovice", "author_id": 52738, "author_profile": "https://Stackoverflow.com/users/52738", "pm_score": 4, "selected": true, "text": "<p>CORRECTION:</p>\n\n<p>I misunderstood your use of the word CELL. My apologies. It appears you simply want to define a fu...
2009/02/02
[ "https://Stackoverflow.com/questions/503689", "https://Stackoverflow.com", "https://Stackoverflow.com/users/34772/" ]
Say I had the following code: ``` % Cellmode_subfunction_test.m %% Cell 1 foo(1); %% Cell 2 foo(2); %% Definition of the foo subfunction function foo(num) disp(['num=' num2str(num)]); ``` How can test cell 1 and cell 2 with the subfunction defined at the end? Edit: Basically each of the cells in this example perf...
CORRECTION: I misunderstood your use of the word CELL. My apologies. It appears you simply want to define a function at the command line without saving it to a .m file. For this, you can use anonymous functions: ``` foo = @(num) disp(['num=' num2str(num)]); ``` Then you can use "foo" as you would any other function...
503,691
<p>I want to trigger a hyperlink by hitting Enter using jQuery. I have the following html but all an Enter-stroke does is trigger the alert, it doesn't navigate to the link. Clicking the link, however, does navigate to the new address. What am I missing?</p> <p>I know my test function is working since the addClass/rem...
[ { "answer_id": 503753, "author": "smack0007", "author_id": 26566, "author_profile": "https://Stackoverflow.com/users/26566", "pm_score": 2, "selected": true, "text": "<p>Add a window.location = this.href; to your click function. That should work.</p>\n" }, { "answer_id": 503761, ...
2009/02/02
[ "https://Stackoverflow.com/questions/503691", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1523/" ]
I want to trigger a hyperlink by hitting Enter using jQuery. I have the following html but all an Enter-stroke does is trigger the alert, it doesn't navigate to the link. Clicking the link, however, does navigate to the new address. What am I missing? I know my test function is working since the addClass/removeClass f...
Add a window.location = this.href; to your click function. That should work.
503,716
<p>View this code:</p> <pre><code>function testprecision(){ var isNotNumber = parseFloat('1.3').toPrecision(6); alert(typeof isNotNumber); //=&gt; string } </code></pre> <p>I would have expected a number. If 'isNotNumber' should be a real number, recasting is the solution:</p> <pre><code>alert(typeof parseFl...
[ { "answer_id": 503729, "author": "Otávio Décio", "author_id": 48684, "author_profile": "https://Stackoverflow.com/users/48684", "pm_score": 2, "selected": false, "text": "<p>Because it is a formatting function.</p>\n" }, { "answer_id": 503731, "author": "Godeke", "author_...
2009/02/02
[ "https://Stackoverflow.com/questions/503716", "https://Stackoverflow.com", "https://Stackoverflow.com/users/58186/" ]
View this code: ``` function testprecision(){ var isNotNumber = parseFloat('1.3').toPrecision(6); alert(typeof isNotNumber); //=> string } ``` I would have expected a number. If 'isNotNumber' should be a real number, recasting is the solution: ``` alert(typeof parseFloat(isNotNumber)) //=> number ``` [Edi...
From the docs: "Returns a string representing the Number object to the specified precision." toPrecision() seems intended for formatting output, in which case a string is the most reasonable outcome. It represents the final output in a form that will not be mangled by further manipulation. If you are looking to do so...
503,721
<p>I have a question about Generics in Java, namely using wildcards. I have an example class GenClass like this:</p> <pre><code>public class GenClass&lt;E&gt; { private E var; public void setVar(E x) { var = x; } public E getVar() { return var; } } </code></pre> <p>I have anothe...
[ { "answer_id": 503765, "author": "Michael Myers", "author_id": 13531, "author_profile": "https://Stackoverflow.com/users/13531", "pm_score": 4, "selected": false, "text": "<p>This exact situation is covered in the <a href=\"http://java.sun.com/docs/books/tutorial/extra/generics/wildcards...
2009/02/02
[ "https://Stackoverflow.com/questions/503721", "https://Stackoverflow.com", "https://Stackoverflow.com/users/42155/" ]
I have a question about Generics in Java, namely using wildcards. I have an example class GenClass like this: ``` public class GenClass<E> { private E var; public void setVar(E x) { var = x; } public E getVar() { return var; } } ``` I have another simple class: ``` public clas...
This exact situation is covered in the [Java Generics Tutorial](http://java.sun.com/docs/books/tutorial/extra/generics/wildcards.html). > > Notice that [with the wildcard], we can still read elements from [the generic `Collection`] and give them type `Object`. This is always safe, since whatever the actual type of th...
503,734
<p>If you have a List how do you return the item if a specified property or collection of properties exists?</p> <pre><code>public class Testing { public string value1 { get; set; } public string value2 { get; set; } public int value3 { get; set; } } public class TestingList { public void TestingNewLis...
[ { "answer_id": 503754, "author": "CubanX", "author_id": 27555, "author_profile": "https://Stackoverflow.com/users/27555", "pm_score": 6, "selected": true, "text": "<p>If you're using .NET 3.5 or better, LINQ is the answer to this one:</p>\n\n<pre><code>testList.Where(t =&gt; t.value3 == ...
2009/02/02
[ "https://Stackoverflow.com/questions/503734", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3080/" ]
If you have a List how do you return the item if a specified property or collection of properties exists? ``` public class Testing { public string value1 { get; set; } public string value2 { get; set; } public int value3 { get; set; } } public class TestingList { public void TestingNewList() { ...
If you're using .NET 3.5 or better, LINQ is the answer to this one: ``` testList.Where(t => t.value3 == 3); testList.Where(t => t.value3 == 2 && t.value1 == "Value1 - 2"); ``` If not using .NET 3.5 then you can just loop through and pick out the ones you want.
503,739
<p>I am a beginning in visual basic. What I am trying to do is whenever a box is clicked, highlight a specific range. Then, if another box is clicked after that, the previous range will unhighlight, and another range will highlight. Here is my code but it doesn't work right now. </p> <pre><code>Dim FSelect As Boolean...
[ { "answer_id": 503868, "author": "Jason Punyon", "author_id": 6212, "author_profile": "https://Stackoverflow.com/users/6212", "pm_score": 1, "selected": false, "text": "<p>When I throw this code into excel it complains about Select. I don't think you can use Select as a variable...</p>\...
2009/02/02
[ "https://Stackoverflow.com/questions/503739", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I am a beginning in visual basic. What I am trying to do is whenever a box is clicked, highlight a specific range. Then, if another box is clicked after that, the previous range will unhighlight, and another range will highlight. Here is my code but it doesn't work right now. ``` Dim FSelect As Boolean Dim myRange As...
When I throw this code into excel it complains about Select. I don't think you can use Select as a variable... EDIT: Select is a reserved keyword in VB/A, It begins the Select Case block.
503,769
<p>Given a subroutine reference, is there a way to find out the file and line number where the subroutine was declared? warn and friends seems to get this right, but I need this externally. Here's my test program:</p> <pre><code>#!/usr/bin/perl -l use strict; use warnings; use B; # line 99 'bin/some_code.pl' { n...
[ { "answer_id": 503804, "author": "dsm", "author_id": 7780, "author_profile": "https://Stackoverflow.com/users/7780", "pm_score": 2, "selected": false, "text": "<p>You could try looking at <a href=\"http://perldoc.perl.org/functions/caller.html\" rel=\"nofollow noreferrer\"><code>caller</...
2009/02/02
[ "https://Stackoverflow.com/questions/503769", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8003/" ]
Given a subroutine reference, is there a way to find out the file and line number where the subroutine was declared? warn and friends seems to get this right, but I need this externally. Here's my test program: ``` #!/usr/bin/perl -l use strict; use warnings; use B; # line 99 'bin/some_code.pl' { no strict 'refs...
You could try looking at [`caller`](http://perldoc.perl.org/functions/caller.html). This is what the debugger uses to build stack traces, so maybe it is what you want. I don't think `__LINE__`, `__FILE__` and `__PACKAGE__` help you here as they only provide the location of the *current* point of execution, meaning tha...
503,774
<p>I am creating a suite of custom cmdlets and providers in C#. I also have a PowerShell SnapIn that takes care of registering the cmdlets and providers. I have exported a console session so that I can start PowerShell with the -PSConsoleFile parameter to automatically load my snap in. </p> <p>I also want to mount ...
[ { "answer_id": 503841, "author": "Dustin Venegas", "author_id": 61570, "author_profile": "https://Stackoverflow.com/users/61570", "pm_score": 0, "selected": false, "text": "<p>You might try adding the statements to your Powershell global or environment profile. Both are located at %usern...
2009/02/02
[ "https://Stackoverflow.com/questions/503774", "https://Stackoverflow.com", "https://Stackoverflow.com/users/37812/" ]
I am creating a suite of custom cmdlets and providers in C#. I also have a PowerShell SnapIn that takes care of registering the cmdlets and providers. I have exported a console session so that I can start PowerShell with the -PSConsoleFile parameter to automatically load my snap in. I also want to mount a drive whene...
You can create a PSDrive in you snapin. There is a method that you can override, [InitializeDefaultDrives](http://msdn.microsoft.com/en-us/library/system.management.automation.provider.drivecmdletprovider.initializedefaultdrives(VS.85).aspx), as part of your provider. Example: ``` protected override Collection<PSDriv...
503,781
<p>I'm trying to develop a sql query that will return a list of serial numbers. The table is set up that whenever a serial number reaches a step, the date and time are entered. When it completes the step, another date and time are entered. I want to develop a query that will give me the list of serial numbers that h...
[ { "answer_id": 503790, "author": "mmx", "author_id": 33708, "author_profile": "https://Stackoverflow.com/users/33708", "pm_score": 1, "selected": false, "text": "<pre><code>SELECT DISTINCT Serial\nFROM Table t\nWHERE (SELECT COUNT(*) FROM Table t2 WHERE t.Serial = t2.Serial AND Step = 'e...
2009/02/02
[ "https://Stackoverflow.com/questions/503781", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I'm trying to develop a sql query that will return a list of serial numbers. The table is set up that whenever a serial number reaches a step, the date and time are entered. When it completes the step, another date and time are entered. I want to develop a query that will give me the list of serial numbers that have en...
This will give you all 'enter' records that don't have an ending 'exit'. If you only want a list of serial numbers you should then also group by serial number and select only that column. ``` SELECT t1.* FROM Table1 t1 LEFT JOIN Table1 t2 ON t2.Serial=t1.Serial AND t2.Step='Exit' AND t2.[Date] >= t1.[Date] WHERE...
503,784
<p>What unit testing strategies do people recommend for testing xml is being generated correctly.</p> <p>The my current tests seem abit primitive, something along the lines of:</p> <pre><code>[Test] public void pseudo_test() { XmlDocument myDOC = new XmlDocument(); mydoc = _task.MyMethodToMakeXMLDoc(); Asse...
[ { "answer_id": 503808, "author": "Vitor Silva", "author_id": 1842864, "author_profile": "https://Stackoverflow.com/users/1842864", "pm_score": 0, "selected": false, "text": "<p>why not assume that some commercial xml parser is correct and validate your xml code against it? something like...
2009/02/02
[ "https://Stackoverflow.com/questions/503784", "https://Stackoverflow.com", "https://Stackoverflow.com/users/230/" ]
What unit testing strategies do people recommend for testing xml is being generated correctly. The my current tests seem abit primitive, something along the lines of: ``` [Test] public void pseudo_test() { XmlDocument myDOC = new XmlDocument(); mydoc = _task.MyMethodToMakeXMLDoc(); Assert.AreEqual(myDoc.Out...
First, as pretty much everyone is saying, validate the XML if there's a schema defined for it. (If there's not, define one.) But you can build tests that are a lot more granular than that by executing XPath queries against the document, e.g.: ``` string xml="Your xml string here" ; XmlDocument doc = new XmlDocument()...
503,789
<p>In your opinions, is it better to return a newly allocated memory stream from a function, or pass it into the function? For instance,</p> <pre><code>void Foo(MemoryStream m) { m.Write(somebuffer, 0, somebuffer.Length); } </code></pre> <p>or</p> <pre><code>void MemoryStream Foo() { MemoryStream retval =...
[ { "answer_id": 503795, "author": "Otávio Décio", "author_id": 48684, "author_profile": "https://Stackoverflow.com/users/48684", "pm_score": 2, "selected": false, "text": "<p>You can safely return it from the function. You have to call <code>Dispose()</code> or put it inside a <code>using...
2009/02/02
[ "https://Stackoverflow.com/questions/503789", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
In your opinions, is it better to return a newly allocated memory stream from a function, or pass it into the function? For instance, ``` void Foo(MemoryStream m) { m.Write(somebuffer, 0, somebuffer.Length); } ``` or ``` void MemoryStream Foo() { MemoryStream retval = new MemoryStream(); retval.Write(...
This is a bit like asking whether you should return a string from a method or take a StringBuilder and append to it. The answer depends on what the use case is. Is it likely that the caller will want to call your method with an existing stream containing some data? Might they want to call it several times using the sa...
503,826
<p>I am trying to style some form labels by selecting them with their 'for' attribute. But nothing is being picked up when I preview it in IE7. I'm doing this because I'd like to style them differently to each other, without adding to the existing markup. </p> <p>So if my css looks like the following, I get nothing:</...
[ { "answer_id": 503870, "author": "roflwaffle", "author_id": 49887, "author_profile": "https://Stackoverflow.com/users/49887", "pm_score": 3, "selected": true, "text": "<p>This user seems to have had the same problem you are having:\n<a href=\"http://reference.sitepoint.com/css/attributes...
2009/02/02
[ "https://Stackoverflow.com/questions/503826", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2977/" ]
I am trying to style some form labels by selecting them with their 'for' attribute. But nothing is being picked up when I preview it in IE7. I'm doing this because I'd like to style them differently to each other, without adding to the existing markup. So if my css looks like the following, I get nothing: ``` <style...
This user seems to have had the same problem you are having: [here](http://reference.sitepoint.com/css/attributeselector#usernote472) He says that because "for" is a reserved word, it can't be used as a property name. But 'htmlFor' is the DOM property name associated with the for attribute
503,846
<p>I have a batch script that executes a task and sends the output to a text file. Is there a way to have the output show on the console window as well?</p> <p>For Example:</p> <pre><code>c:\Windows&gt;dir &gt; windows-dir.txt </code></pre> <p>Is there a way to have the output of <code>dir</code> display in the con...
[ { "answer_id": 503854, "author": "Otávio Décio", "author_id": 48684, "author_profile": "https://Stackoverflow.com/users/48684", "pm_score": 2, "selected": false, "text": "<pre><code>command &gt; file &gt;&amp;1\n</code></pre>\n" }, { "answer_id": 503856, "author": "Mark Pim",...
2009/02/02
[ "https://Stackoverflow.com/questions/503846", "https://Stackoverflow.com", "https://Stackoverflow.com/users/28540/" ]
I have a batch script that executes a task and sends the output to a text file. Is there a way to have the output show on the console window as well? For Example: ``` c:\Windows>dir > windows-dir.txt ``` Is there a way to have the output of `dir` display in the console window as well as put it into the text file?
No, you can't with pure redirection. But with some tricks (like [tee.bat](https://stackoverflow.com/a/10719322/463115)) you can. I try to explain the redirection a bit. You redirect one of the ten streams with **> file** or **< file** It is unimportant, if the redirection is before or after the command, so thes...
503,865
<p>There must be an easy way to do this. I build a Flex app using ant that depends on a SWC library, which works fine except that it rebuilds the library whether it needs to or not. How do I tell ant to only run the task if any of the sources files of the library (*.as, *.mxml) are newer than the SWC? </p> <p>I've ...
[ { "answer_id": 504037, "author": "Mnementh", "author_id": 21005, "author_profile": "https://Stackoverflow.com/users/21005", "pm_score": 5, "selected": true, "text": "<p>You may use the Ant <a href=\"http://ant.apache.org/manual/Tasks/uptodate.html\" rel=\"noreferrer\">uptodate task</a> t...
2009/02/02
[ "https://Stackoverflow.com/questions/503865", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15899/" ]
There must be an easy way to do this. I build a Flex app using ant that depends on a SWC library, which works fine except that it rebuilds the library whether it needs to or not. How do I tell ant to only run the task if any of the sources files of the library (\*.as, \*.mxml) are newer than the SWC? I've looked at <...
You may use the Ant [uptodate task](http://ant.apache.org/manual/Tasks/uptodate.html) to create a property, and execute your other target only if that property is set. I don't know much about flex, but you probably want something like this: ``` <?xml version="1.0" encoding="UTF-8"?> <project name="test" default="comp...
503,866
<p>I need a timer to execute callbacks with relatively low resolution. What's the best way to implement such C++ timer class in Linux? Are there any libraries I could use?</p>
[ { "answer_id": 504241, "author": "John Snelson", "author_id": 56656, "author_profile": "https://Stackoverflow.com/users/56656", "pm_score": 0, "selected": false, "text": "<p>Try the clock_gettime() function, defined in time.h:</p>\n\n<pre><code>int clock_gettime(clockid_t clk_id, struct ...
2009/02/02
[ "https://Stackoverflow.com/questions/503866", "https://Stackoverflow.com", "https://Stackoverflow.com/users/48461/" ]
I need a timer to execute callbacks with relatively low resolution. What's the best way to implement such C++ timer class in Linux? Are there any libraries I could use?
If you're writing within a framework (Glib, Qt, Wx, ...), you'll already have an event loop with timed callback functionalities. I'll assume that's not the case. If you're writing your own event loop, you can use the `gettimeofday`/`select` pair (`struct timeval`, microsecond precision) or the `clock_gettime`/`nanosle...
503,871
<p>What’s the best way to remove comments from a PHP file?</p> <p>I want to do something similar to strip-whitespace() - but it shouldn't remove the line breaks as well.</p> <p>For example,</p> <p>I want this:</p> <pre><code>&lt;?PHP // something if ($whatsit) { do_something(); # we do something here echo '&lt;...
[ { "answer_id": 503887, "author": "Adam Davis", "author_id": 2915, "author_profile": "https://Stackoverflow.com/users/2915", "pm_score": 0, "selected": false, "text": "<p>The catch is that a less robust matching algorithm (simple regex, for instance) will start stripping here when it clea...
2009/02/02
[ "https://Stackoverflow.com/questions/503871", "https://Stackoverflow.com", "https://Stackoverflow.com/users/39161/" ]
What’s the best way to remove comments from a PHP file? I want to do something similar to strip-whitespace() - but it shouldn't remove the line breaks as well. For example, I want this: ``` <?PHP // something if ($whatsit) { do_something(); # we do something here echo '<html>Some embedded HTML</html>'; } /*...
I'd use [tokenizer](http://www.php.net/manual/en/book.tokenizer.php). Here's my solution. It should work on both PHP 4 and 5: ``` $fileStr = file_get_contents('path/to/file'); $newStr = ''; $commentTokens = array(T_COMMENT); if (defined('T_DOC_COMMENT')) { $commentTokens[] = T_DOC_COMMENT; // PHP 5 } if (defin...
503,873
<p>Seem to be having a lot of problems doing what should be simple things with XAML / WPF - I have created some XAML-based images using shapes like Rectangle and Ellipse to create icons which I need other parts of my application to use - but I cannot seem to find out how to do this - I seem to be able to store a Canvas...
[ { "answer_id": 504705, "author": "Adrian", "author_id": 55160, "author_profile": "https://Stackoverflow.com/users/55160", "pm_score": 2, "selected": false, "text": "<p>You don't want to be using a Canvas to store these resources in a Resource Dictionary. The root of your geometry is prob...
2009/02/02
[ "https://Stackoverflow.com/questions/503873", "https://Stackoverflow.com", "https://Stackoverflow.com/users/61529/" ]
Seem to be having a lot of problems doing what should be simple things with XAML / WPF - I have created some XAML-based images using shapes like Rectangle and Ellipse to create icons which I need other parts of my application to use - but I cannot seem to find out how to do this - I seem to be able to store a Canvas in...
You should use a Drawing and display it using a DrawingBrush like KP Adrian suggested or a DrawingImage and an Image control, but if you can't use a drawing you can use a Canvas inside a VisualBrush. ``` <Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.c...
503,877
<p>I saw on the Internet that I was supposed to use <code>System.nanoTime()</code> but that doesn't work for me - it gives me the time with milliseconds precision. I just need the microseconds before and after my function executes so that I know how long it takes. I'm using Windows XP.</p> <p>Basically, I have this co...
[ { "answer_id": 503905, "author": "Jon Skeet", "author_id": 22656, "author_profile": "https://Stackoverflow.com/users/22656", "pm_score": 5, "selected": false, "text": "<p>It's not clear to me exactly what you're benchmarking, but in general, any test which takes <em>such</em> a short amo...
2009/02/02
[ "https://Stackoverflow.com/questions/503877", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I saw on the Internet that I was supposed to use `System.nanoTime()` but that doesn't work for me - it gives me the time with milliseconds precision. I just need the microseconds before and after my function executes so that I know how long it takes. I'm using Windows XP. Basically, I have this code that, for example,...
It's not clear to me exactly what you're benchmarking, but in general, any test which takes *such* a short amount of time to run, that accuracy lower than 50 ms is relevant, is going to be *very* prone to other disturbances. I generally try to make benchmarks run for at least 10 seconds. The framework I'm writing at t...
503,878
<p>When calling <code>execl(...)</code>, I get an <code>errno=2</code>. What does it mean? How can I know the meaning of this <code>errno</code>?</p>
[ { "answer_id": 503884, "author": "Otávio Décio", "author_id": 48684, "author_profile": "https://Stackoverflow.com/users/48684", "pm_score": 0, "selected": false, "text": "<p>It means:</p>\n\n<blockquote>\n <p>File or Directory not found.</p>\n</blockquote>\n" }, { "answer_id": 5...
2009/02/02
[ "https://Stackoverflow.com/questions/503878", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20986/" ]
When calling `execl(...)`, I get an `errno=2`. What does it mean? How can I know the meaning of this `errno`?
You can use [`strerror()`](http://en.cppreference.com/w/c/string/byte/strerror) to get a human-readable string for the error number. This is the same string printed by [`perror()`](http://en.cppreference.com/w/c/io/perror) but it's useful if you're formatting the error message for something other than standard error ou...
503,897
<p>Should I use the resource file directly in the aspx page like</p> <pre><code>&lt;asp:Literal ID="userManagementSave" Text="&lt;%$ Resources: save_lbl %&gt;" runat="server" /&gt; </code></pre> <p>or creating a sub in the code like</p> <pre><code>private sub setLang() userManagementSave.text = GetLocalResourceOb...
[ { "answer_id": 503922, "author": "ern", "author_id": 5609, "author_profile": "https://Stackoverflow.com/users/5609", "pm_score": 2, "selected": true, "text": "<p>I favor referencing the text inline, since it is easier to update by not being in the code behind.</p>\n\n<p>Since the only fu...
2009/02/02
[ "https://Stackoverflow.com/questions/503897", "https://Stackoverflow.com", "https://Stackoverflow.com/users/40868/" ]
Should I use the resource file directly in the aspx page like ``` <asp:Literal ID="userManagementSave" Text="<%$ Resources: save_lbl %>" runat="server" /> ``` or creating a sub in the code like ``` private sub setLang() userManagementSave.text = GetLocalResourceObject("save_lbl") end sub ```
I favor referencing the text inline, since it is easier to update by not being in the code behind. Since the only functionality you are after is content output, you'll be fine doing it inline. If you were doing anything more complicated, then a method in the code behind would be better.
503,898
<p>Okay so I have a scenario similar to the below code, I have a parent class that implements IComparable and a child class. </p> <pre><code>class Parent : IComparable&lt;Parent&gt; class Child : Parent Child a = new Child(); Child b = new Child(); a.CompareTo(b); </code></pre> <p>Now the above works fine, i can co...
[ { "answer_id": 503928, "author": "Jon Skeet", "author_id": 22656, "author_profile": "https://Stackoverflow.com/users/22656", "pm_score": 4, "selected": true, "text": "<p>Your type implements <code>IComparable&lt;Parent&gt;</code> rather than <code>IComparable&lt;Child&gt;</code>. As the ...
2009/02/02
[ "https://Stackoverflow.com/questions/503898", "https://Stackoverflow.com", "https://Stackoverflow.com/users/55990/" ]
Okay so I have a scenario similar to the below code, I have a parent class that implements IComparable and a child class. ``` class Parent : IComparable<Parent> class Child : Parent Child a = new Child(); Child b = new Child(); a.CompareTo(b); ``` Now the above works fine, i can compare two of the child objects t...
Your type implements `IComparable<Parent>` rather than `IComparable<Child>`. As the [MSDN docs for Sort](http://msdn.microsoft.com/en-us/library/b0zbh7b6.aspx) say, it will throw InvalidOperationException if "the default comparer Comparer(T).Default cannot find an implementation of the IComparable(T) generic interface ...
503,911
<p>I am submitting a ColdFusion Form and I want to run some JavaScript to check field validation before I run my ColdFusion code to process the form as needed.</p> <p>How can I do this? What do I do in JS to call my .cfm file after the form passes validation?</p> <p>Thanks!</p> <p>-Jason</p>
[ { "answer_id": 503963, "author": "Miguel Ping", "author_id": 22992, "author_profile": "https://Stackoverflow.com/users/22992", "pm_score": 0, "selected": false, "text": "<p>You can attach a <code>onclick</code> event to your input button, for example:</p>\n<pre><code>&lt;input type=&quot...
2009/02/02
[ "https://Stackoverflow.com/questions/503911", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I am submitting a ColdFusion Form and I want to run some JavaScript to check field validation before I run my ColdFusion code to process the form as needed. How can I do this? What do I do in JS to call my .cfm file after the form passes validation? Thanks! -Jason
You need ``` <form name="myform" action="myserverscript.cfm" onsubmit="return validate()"> ``` if you return true the form submits, false it doesn't
503,916
<p>I have 2 vector of with one has vec1{e1,e2,e3,e4} and the other one with vec2 {e2,e4,e5,e7} </p> <p>How to effectively get three vector from above vectors such that 1.has elements that is available only in vec1 similarly 2 has only vec2 elements and 3.with common elements</p>
[ { "answer_id": 503953, "author": "jalf", "author_id": 33213, "author_profile": "https://Stackoverflow.com/users/33213", "pm_score": 4, "selected": true, "text": "<p><code>std::set_intersection</code> should do the trick, if both vectors are sorted:\n<a href=\"http://msdn.microsoft.com/en...
2009/02/02
[ "https://Stackoverflow.com/questions/503916", "https://Stackoverflow.com", "https://Stackoverflow.com/users/22076/" ]
I have 2 vector of with one has vec1{e1,e2,e3,e4} and the other one with vec2 {e2,e4,e5,e7} How to effectively get three vector from above vectors such that 1.has elements that is available only in vec1 similarly 2 has only vec2 elements and 3.with common elements
`std::set_intersection` should do the trick, if both vectors are sorted: <http://msdn.microsoft.com/en-us/library/zfd331yx.aspx> ``` std::set_intersection(vec1.begin(), vec1.end(), vec2.begin(), vec2.end(), std::back_inserter(vec3)); ``` A custom predicate can be used for the comparison too: ``` std::set_intersecti...
503,925
<p>I have a webpage that I use h1 tags multiple times within various DIVs and I style h1 for each div to be the appropriate size.</p> <p>For example...</p> <pre><code>#content h1 { font-size:22px; } #left-nav h1 { font-size:14px; } #content .recent-news h1 { font-size:16px; } </code></pre> <p>Is this alright?</...
[ { "answer_id": 503949, "author": "sykora", "author_id": 53850, "author_profile": "https://Stackoverflow.com/users/53850", "pm_score": 3, "selected": false, "text": "<p>In general, you should only have one h1 per page, and that h1 should succintly represent the content on that page. As lo...
2009/02/02
[ "https://Stackoverflow.com/questions/503925", "https://Stackoverflow.com", "https://Stackoverflow.com/users/26130/" ]
I have a webpage that I use h1 tags multiple times within various DIVs and I style h1 for each div to be the appropriate size. For example... ``` #content h1 { font-size:22px; } #left-nav h1 { font-size:14px; } #content .recent-news h1 { font-size:16px; } ``` Is this alright?
In my opinion, you don't need to worry, its ok to do it like this. H1 designates part of your contents to be a first level heading. So if you have a first level heading in your navigation div (e.g. `<H1>Navigation Menu</H1>`), of course that should be `#nav h1`. If you should have several H1s within your contents dep...
503,948
<p>Following the advice of wcoenen, I've decided to try using registration-free COM. This works perfectly, excepting on pre-XP machines, of course. One idea which I thought would be kind of neat would be to add to some files, <code>SelfRegCost='[var]'</code>. It is quite likely that this is not <em>The Right Thing™<...
[ { "answer_id": 513426, "author": "Rob McCready", "author_id": 47525, "author_profile": "https://Stackoverflow.com/users/47525", "pm_score": 2, "selected": false, "text": "<p>I haven't had to do COM installation with WiX (thank god). But from the docs and <a href=\"http://n2.nabble.com/Ho...
2009/02/02
[ "https://Stackoverflow.com/questions/503948", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18192/" ]
Following the advice of wcoenen, I've decided to try using registration-free COM. This works perfectly, excepting on pre-XP machines, of course. One idea which I thought would be kind of neat would be to add to some files, `SelfRegCost='[var]'`. It is quite likely that this is not *The Right Thing™* but I still want to...
You need to use conditional components to install in different ways to different OS's. What you are suggesting is to have part of the installation fail, but hopefully silently. Using a custom action, you can do just that! ``` <CustomAction Id="YourId" Directory="INSTALLDIR" ExeCommand='regsvr32.exe /s "[INSTALLDIR]Y...
503,981
<p>This is a follow up question to that at <a href="https://stackoverflow.com/questions/495194/can-i-create-a-html-table-width-a-percentage-height-but-pixel-accurate-row-height">Can I create a HTML table width a percentage height but pixel accurate row heights?</a>.</p> <p>I have a table in a HTML page that will be us...
[ { "answer_id": 504473, "author": "olemarius", "author_id": 61635, "author_profile": "https://Stackoverflow.com/users/61635", "pm_score": 0, "selected": false, "text": "<p>I try to use % as less as possible because padding, borders and margins are added to the 100% width if any, unless yo...
2009/02/02
[ "https://Stackoverflow.com/questions/503981", "https://Stackoverflow.com", "https://Stackoverflow.com/users/44938/" ]
This is a follow up question to that at [Can I create a HTML table width a percentage height but pixel accurate row heights?](https://stackoverflow.com/questions/495194/can-i-create-a-html-table-width-a-percentage-height-but-pixel-accurate-row-height). I have a table in a HTML page that will be used for tabular data (...
There's an easy way to fix this, especially if the page just contains this table, and you just want it to work. I'm not sure if ASP.NET will let you though: Add a comment in front of the doctype. E.g. ``` <!-- Here for IE6/7 --> <!DOCTYPE html (etc.)> ... The HTML that works in quirks mode ... ``` This will make IE6...
503,982
<p>My application receives strings that represent objects. I have to parse the strings to get the property values for the object I'm creating. Each object will have to know the specifics about how many attributes there are, what each attribute means, etc. However, I want to avoid having each class know about how to ...
[ { "answer_id": 504000, "author": "user54650", "author_id": 54650, "author_profile": "https://Stackoverflow.com/users/54650", "pm_score": 2, "selected": false, "text": "<p>I suggest the BinaryFormatter.</p>\n\n<p><a href=\"http://www.codeguru.com/columns/dotnet/article.php/c6595\" rel=\"n...
2009/02/02
[ "https://Stackoverflow.com/questions/503982", "https://Stackoverflow.com", "https://Stackoverflow.com/users/132931/" ]
My application receives strings that represent objects. I have to parse the strings to get the property values for the object I'm creating. Each object will have to know the specifics about how many attributes there are, what each attribute means, etc. However, I want to avoid having each class know about how to parse ...
I might have understood your question incorrectly, but I think standard .NET serialization suits your needs: ``` var ms = new MemoryStream(); var formatter = new BinaryFormatter(); formatter.Serialize(ms, myObject); // Deserialization: var deserialized = (MyClass)formatter.Deserialize(stream); ```
503,992
<p>I am trying to create a small tooltip script that mostly relies on css. The bit of JavaScript I can't figure out is how to position the div based on its distance to the browsers edge.</p> <p>When the div appears I would like it to check how close it is to the top, bottom, left and right. For example if there is not...
[ { "answer_id": 504016, "author": "Galwegian", "author_id": 3201, "author_profile": "https://Stackoverflow.com/users/3201", "pm_score": 1, "selected": false, "text": "<p>See <a href=\"http://msdn.microsoft.com/en-us/library/ms530302.aspx\" rel=\"nofollow noreferrer\">Measuring Element Dim...
2009/02/02
[ "https://Stackoverflow.com/questions/503992", "https://Stackoverflow.com", "https://Stackoverflow.com/users/42648/" ]
I am trying to create a small tooltip script that mostly relies on css. The bit of JavaScript I can't figure out is how to position the div based on its distance to the browsers edge. When the div appears I would like it to check how close it is to the top, bottom, left and right. For example if there is not enough sp...
I just had to write very similar code myself, for use with [tipsy](http://onehackoranother.com/projects/jquery/tipsy/) (so my solution uses jQuery). Here's the basic math, assuming `<div id="mydiv">...</div>` is the div you're working with. I account for the div's height and width when measuring the distances to the ri...
504,003
<p>Is it possible to have IF statements without braces in Java, e.g:</p> <pre><code>if (x == y) z = x * y; else z = y - x; </code></pre> <p>It's possible in PHP, and I'm not sure if I'm doing something wrong.</p> <p><strong>Clarification:</strong> Here's my actual code that i'm using:</p> <pre><code>if (other i...
[ { "answer_id": 504005, "author": "Sean Bright", "author_id": 21926, "author_profile": "https://Stackoverflow.com/users/21926", "pm_score": 5, "selected": true, "text": "<p>Yes, you can follow an <code>if</code> statement with a single statement without using curly braces (but do you real...
2009/02/02
[ "https://Stackoverflow.com/questions/504003", "https://Stackoverflow.com", "https://Stackoverflow.com/users/49153/" ]
Is it possible to have IF statements without braces in Java, e.g: ``` if (x == y) z = x * y; else z = y - x; ``` It's possible in PHP, and I'm not sure if I'm doing something wrong. **Clarification:** Here's my actual code that i'm using: ``` if (other instanceof Square) Square realOther = (Square) other; ...
Yes, you can follow an `if` statement with a single statement without using curly braces (but do you really want to?), but your problem is more subtle. Try changing: ``` if (x=y) ``` to: ``` if (x==y) ``` Some languages (like PHP, for example) treat any non-zero value as true and zero (or `NULL`, `null`, `nil`, w...
504,036
<p>I have a very common situation here. And for years I haven't found if what i am doing is RIGHT by industry standards.Consider an application which connects to the database, but where the connection string instead of being stored in some file/setting is being passed as a command line parameter at startup OR the datab...
[ { "answer_id": 504070, "author": "AwesomeTown", "author_id": 59397, "author_profile": "https://Stackoverflow.com/users/59397", "pm_score": 4, "selected": true, "text": "<p>In general global state, be it a global class or a singleton, should be avoided wherever possible.</p>\n\n<p>The ide...
2009/02/02
[ "https://Stackoverflow.com/questions/504036", "https://Stackoverflow.com", "https://Stackoverflow.com/users/52960/" ]
I have a very common situation here. And for years I haven't found if what i am doing is RIGHT by industry standards.Consider an application which connects to the database, but where the connection string instead of being stored in some file/setting is being passed as a command line parameter at startup OR the database...
In general global state, be it a global class or a singleton, should be avoided wherever possible. The ideal solution would be to have your application load up the connection string out of config and [inject](http://en.wikipedia.org/wiki/Dependency_injection) it into any classes that need it. Depending on the size of ...
504,060
<p>I want to do something like:</p> <pre><code>DELETE FROM student WHERE student.course, student.major IN (SELECT schedule.course, schedule.major FROM schedule) </code></pre> <p>However, it seems that you can only use one column with the IN operator. Is that true? Seems like a query like this should be possible.</p>
[ { "answer_id": 504076, "author": "Tony Andrews", "author_id": 18747, "author_profile": "https://Stackoverflow.com/users/18747", "pm_score": 7, "selected": true, "text": "<p>No, you just need parentheses:</p>\n\n<pre><code>DELETE FROM student WHERE\n(student.course, student.major) IN\n(SE...
2009/02/02
[ "https://Stackoverflow.com/questions/504060", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I want to do something like: ``` DELETE FROM student WHERE student.course, student.major IN (SELECT schedule.course, schedule.major FROM schedule) ``` However, it seems that you can only use one column with the IN operator. Is that true? Seems like a query like this should be possible.
No, you just need parentheses: ``` DELETE FROM student WHERE (student.course, student.major) IN (SELECT schedule.course, schedule.major FROM schedule) ```
504,071
<p>In a JSP page(index.jsp):</p> <pre><code>${requestContext.requestURL} is the URL </code></pre> <p>just shows the expression itself. It used to be evaluated to something like "<a href="http://.../somerset/" rel="nofollow noreferrer">http://.../somerset/</a>"</p> <p>I created the Maven project with maven-archetype-...
[ { "answer_id": 504096, "author": "krosenvold", "author_id": 23691, "author_profile": "https://Stackoverflow.com/users/23691", "pm_score": 1, "selected": false, "text": "<p>Incorrectly matched quotes can cause this behavior, where the expression just gets treated as a string. Your IDE wou...
2009/02/02
[ "https://Stackoverflow.com/questions/504071", "https://Stackoverflow.com", "https://Stackoverflow.com/users/24349/" ]
In a JSP page(index.jsp): ``` ${requestContext.requestURL} is the URL ``` just shows the expression itself. It used to be evaluated to something like "<http://.../somerset/>" I created the Maven project with maven-archetype-webapp archetype in Eclipse. The Jetty version is jetty-6.1.14. My web.xml is simple: ``` ...
See [Javascript String.replace(/\$/,str) works weirdly in jsp file](https://stackoverflow.com/questions/472500/javascript-string-replace-str-works-weirdly-in-jsp-file/472573#472573) for some possible reasons. Your web.xml should contain reference to web-app\_2\_4.xsd schema, like ``` <web-app xmlns="http://java.sun.c...
504,080
<p>I am putting some email functionality into one of my asp.net projects:</p> <p>I need to send an email to a list of subscribers, list varies from a few dozen to a few hundred subscribers - (down the road there could be thousands).</p> <p>When I have a few dozen emails, I do this:</p> <pre><code>Mailmsg.Bcc.Add(New...
[ { "answer_id": 504163, "author": "keithwarren7", "author_id": 40714, "author_profile": "https://Stackoverflow.com/users/40714", "pm_score": 3, "selected": true, "text": "<p>The limit is more driven by your connectivity and SMTP server...BUT, you are going about it the wrong way. One sure...
2009/02/02
[ "https://Stackoverflow.com/questions/504080", "https://Stackoverflow.com", "https://Stackoverflow.com/users/53686/" ]
I am putting some email functionality into one of my asp.net projects: I need to send an email to a list of subscribers, list varies from a few dozen to a few hundred subscribers - (down the road there could be thousands). When I have a few dozen emails, I do this: ``` Mailmsg.Bcc.Add(New System.Net.Mail.MailAddress...
The limit is more driven by your connectivity and SMTP server...BUT, you are going about it the wrong way. One sure fire way to be seen as spam is to send an email with a bunch of BCC items. Send one email per recipient with them as the TO address and you will be better off.
504,102
<p>I would like to fadeOut() an image on the page and remove it from the DOM after the animation is finished. Sounds easy enough?</p> <p>Example code (image has the id "img1"):</p> <pre> $("#img1").fadeOut("slow", function() { $(this).remove() }); </pre> <p>This does does not work. When I inspect the page with Fi...
[ { "answer_id": 504138, "author": "Russ Cam", "author_id": 1831, "author_profile": "https://Stackoverflow.com/users/1831", "pm_score": 3, "selected": true, "text": "<p>Both of examples work as expected for me, as demonstrated <a href=\"http://jsbin.com/exacu\" rel=\"nofollow noreferrer\">...
2009/02/02
[ "https://Stackoverflow.com/questions/504102", "https://Stackoverflow.com", "https://Stackoverflow.com/users/61599/" ]
I would like to fadeOut() an image on the page and remove it from the DOM after the animation is finished. Sounds easy enough? Example code (image has the id "img1"): ``` $("#img1").fadeOut("slow", function() { $(this).remove() }); ``` This does does not work. When I inspect the page with Firebug the image is s...
Both of examples work as expected for me, as demonstrated [here](http://jsbin.com/exacu) (apologies for the bad image, it was the first thing I found!). Image 1 fades out and then is removed from the DOM, Image2 fades out then back in, in the position of where Image1 was originally positioned. Have I understood you co...
504,116
<p>I have a <code>users</code> table that has a column called <code>money_sent</code>. I want to order this table by <code>money_sent</code> in descending order, and then find out what "rank" a specific user has.</p> <p>For example, only 111 people have spent more money than User 12392, so they would be rank 112.</p> ...
[ { "answer_id": 504131, "author": "Chris J", "author_id": 59867, "author_profile": "https://Stackoverflow.com/users/59867", "pm_score": 4, "selected": false, "text": "<p>How about:</p>\n\n<pre><code>SELECT count(*) FROM users WHERE money_sent &lt; (\n SELECT money_sent FROM users WHERE...
2009/02/02
[ "https://Stackoverflow.com/questions/504116", "https://Stackoverflow.com", "https://Stackoverflow.com/users/61602/" ]
I have a `users` table that has a column called `money_sent`. I want to order this table by `money_sent` in descending order, and then find out what "rank" a specific user has. For example, only 111 people have spent more money than User 12392, so they would be rank 112. How could I query this?
How about: ``` SELECT count(*) FROM users WHERE money_sent < ( SELECT money_sent FROM users WHERE user = 'joe' ); ```
504,118
<p>I am trying to figure out how to write a new line of text at the beginning of a file (a header). I know I can open the file, or seek to the beginning of a file, but if I write with that, it will overwrite what's there. Do I have to write a new file and then write the other data to it line by line, or is there a bett...
[ { "answer_id": 504126, "author": "Tiago", "author_id": 55283, "author_profile": "https://Stackoverflow.com/users/55283", "pm_score": 0, "selected": false, "text": "<p>You have to open a new file and write all over again.</p>\n" }, { "answer_id": 504135, "author": "Bryan Oakle...
2009/02/02
[ "https://Stackoverflow.com/questions/504118", "https://Stackoverflow.com", "https://Stackoverflow.com/users/53007/" ]
I am trying to figure out how to write a new line of text at the beginning of a file (a header). I know I can open the file, or seek to the beginning of a file, but if I write with that, it will overwrite what's there. Do I have to write a new file and then write the other data to it line by line, or is there a better ...
You will have to rewrite the whole file, but that doesn't necessarily mean you have to read and write the original data line-by-line. Reading by lines is relatively slow, so if the file is small enough to fit in memory, read it all in one big chunk (or in large sized blocks) and then write it back after writing your ne...
504,127
<p>What am I doing wrong here? My use of the INTO clause seems to match the example I found in Microsoft's Transact-SQL reference pages, but I must be missing something.</p> <pre><code>DECLARE @rowtemp table(TestRunID int, RunOrder int) SELECT TestRunID, ROW_NUMBER() OVER (ORDER BY TestRuns.TestTime ASC) AS 'RunOrde...
[ { "answer_id": 504139, "author": "Joe", "author_id": 57135, "author_profile": "https://Stackoverflow.com/users/57135", "pm_score": 1, "selected": false, "text": "<p>You can't use a table variable with a SELECT INTO. Use a # temp table instead.</p>\n" }, { "answer_id": 504143, ...
2009/02/02
[ "https://Stackoverflow.com/questions/504127", "https://Stackoverflow.com", "https://Stackoverflow.com/users/26140/" ]
What am I doing wrong here? My use of the INTO clause seems to match the example I found in Microsoft's Transact-SQL reference pages, but I must be missing something. ``` DECLARE @rowtemp table(TestRunID int, RunOrder int) SELECT TestRunID, ROW_NUMBER() OVER (ORDER BY TestRuns.TestTime ASC) AS 'RunOrder' INTO @rowte...
You cannot use SELECT INTO with a table variable and also SELECT INTO would create a table so you would not create the table first try this ``` DECLARE @rowtemp table(TestRunID int, RunOrder int) INSERT INTO @rowtemp SELECT TestRunID, ROW_NUMBER() OVER (ORDER BY TestRuns.TestTime ASC) AS 'RunOrder' FROM TestRuns ...
504,129
<p>I'm trying to build a reusable $.ajax method for my current application but I'm struggling to find solid information about how to build the <b>data:</b> section dynamically ...</p> <p>Currently I'm looking at something similar to the function below, but I'm not sure how to implement this w/ jQuery 1.3.x (or if this...
[ { "answer_id": 504190, "author": "Bobby Borszich", "author_id": 35585, "author_profile": "https://Stackoverflow.com/users/35585", "pm_score": 3, "selected": true, "text": "<p>I use this method as a wrapper so that I can send parameters. Also using the variables at the top of the method a...
2009/02/02
[ "https://Stackoverflow.com/questions/504129", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2701/" ]
I'm trying to build a reusable $.ajax method for my current application but I'm struggling to find solid information about how to build the **data:** section dynamically ... Currently I'm looking at something similar to the function below, but I'm not sure how to implement this w/ jQuery 1.3.x (or if this type of thin...
I use this method as a wrapper so that I can send parameters. Also using the variables at the top of the method allows it to be minimized at a higher ratio and allows for some code reuse if making multiple similar calls. ``` function InfoByDate(sDate, eDate) { var divToBeWorkedOn = '#AjaxPlaceHolder'; var web...
504,136
<p>We need to parse <code>Received:</code> email headers according to RFC 5321. We need to extract domains or IPs through which the mail has traversed. Also, we need to figure out if an IP is an internal IP.</p> <p>Is there already a library which can help out, preferably in C\C++?</p> <p>For example:</p> <pre><code>Re...
[ { "answer_id": 504160, "author": "Keltia", "author_id": 16143, "author_profile": "https://Stackoverflow.com/users/16143", "pm_score": -1, "selected": false, "text": "<p>It is not difficult to parse such headers, even manually line-by-line. A regex could help there by looking at <code>by...
2009/02/02
[ "https://Stackoverflow.com/questions/504136", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9087/" ]
We need to parse `Received:` email headers according to RFC 5321. We need to extract domains or IPs through which the mail has traversed. Also, we need to figure out if an IP is an internal IP. Is there already a library which can help out, preferably in C\C++? For example: ``` Received: from server.mymailhost.com (...
The format used by 'Received' lines is defined in RFC 2821, and regex can't parse it. (You can try anyway, and for a limited subset of headers produced by known software you might succeed, but when you attach this to the range of strange stuff found in real-world mail it will fail.) Use an existing RFC 2821 parser an...
504,174
<p>How can I add an opaque type to a collection in cocoa?</p> <p>I get a compiler warning for this (obviously, because opaque types are not objects):</p> <pre><code>CGColorSpaceRef colorSpace; NSArray *myArray = [NSArray arrayWithObject:colorSpace]; </code></pre>
[ { "answer_id": 504301, "author": "Martin Gordon", "author_id": 2481, "author_profile": "https://Stackoverflow.com/users/2481", "pm_score": 2, "selected": false, "text": "<p>You can use the NSValue class to wrap your opaque types in an object. From <a href=\"http://developer.apple.com/doc...
2009/02/02
[ "https://Stackoverflow.com/questions/504174", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3740/" ]
How can I add an opaque type to a collection in cocoa? I get a compiler warning for this (obviously, because opaque types are not objects): ``` CGColorSpaceRef colorSpace; NSArray *myArray = [NSArray arrayWithObject:colorSpace]; ```
CoreFoundation data types (CFTypes) can be directly added to collections. (They need to be cast to (id) to suppress warnings.) This is called "toll free bridging." ``` CGColorSpaceRef colorSpace; NSArray *myArray = [NSArray arrayWithObject:(id)colorSpace]; ```
504,189
<p>I'm working on a simple little swing component, and I'm tearing out my hair trying to figure out why my paint method isn't working.</p> <p>The idea behind this component is that it's a small JPanel with a label. The background (behind the label) is supposed to be white, with a colored rectangle on the left-hand sid...
[ { "answer_id": 504254, "author": "David Z", "author_id": 56541, "author_profile": "https://Stackoverflow.com/users/56541", "pm_score": 0, "selected": false, "text": "<p>Not sure if this is the source of your problem, but in Swing you're supposed to override <code>paintComponent(Graphics2...
2009/02/02
[ "https://Stackoverflow.com/questions/504189", "https://Stackoverflow.com", "https://Stackoverflow.com/users/22979/" ]
I'm working on a simple little swing component, and I'm tearing out my hair trying to figure out why my paint method isn't working. The idea behind this component is that it's a small JPanel with a label. The background (behind the label) is supposed to be white, with a colored rectangle on the left-hand side indicati...
I think you've almost answered your own question in the comments, along with David's answer. Change `paint(Graphics g)` to `paintComponent(Graphics g)` and remove the last two lines of the method, and you should be fine. **EDIT:** Oddly, this only works for the first bar of the three. More testing in progress... By t...
504,198
<p>MS SQL Server doesn't have row level triggers, correct? If I needed to insert a row from within a trigger and then insert another row, based on the result of the first insert, would a cursor be the best solution?</p> <p>For example, is there a better way to do this:</p> <pre><code>CREATE TABLE t1 (foo int) CREATE ...
[ { "answer_id": 504252, "author": "SAMills", "author_id": 56546, "author_profile": "https://Stackoverflow.com/users/56546", "pm_score": 1, "selected": false, "text": "<p>Why not cascade the triggers - Use an INSERT trigger on T2 to perform the insert on T3. Then you can avoid the cursor ...
2009/02/02
[ "https://Stackoverflow.com/questions/504198", "https://Stackoverflow.com", "https://Stackoverflow.com/users/37500/" ]
MS SQL Server doesn't have row level triggers, correct? If I needed to insert a row from within a trigger and then insert another row, based on the result of the first insert, would a cursor be the best solution? For example, is there a better way to do this: ``` CREATE TABLE t1 (foo int) CREATE TABLE t2 (id int IDEN...
I assume you are on 2005 or better? If so, look into the OUTPUT clause, you shouldn't need row-level triggers. For example: ``` USE tempdb; GO CREATE TABLE t1 (foo int); CREATE TABLE t2 (id int IDENTITY, foo int); CREATE TABLE t3 (t2_id int); GO CREATE TRIGGER t1_insert ON t1 FOR INSERT AS BEGIN DECLARE @new_...
504,199
<p>Alright, I find the code below to be quite repetitive and annoying. Any other way to refactor the code without using an array as a starting point (that is, to avoid using <code>array[x]</code>, <code>array[y]</code>, <code>array[z]</code> later on in the code as a result of starting with an array because <code>x</co...
[ { "answer_id": 504210, "author": "krosenvold", "author_id": 23691, "author_profile": "https://Stackoverflow.com/users/23691", "pm_score": 1, "selected": false, "text": "<p>Is there a reason you initialize x,y and z to \"\" ?</p>\n\n<p>If you just do</p>\n\n<pre><code> var x;\n\n ..... ma...
2009/02/02
[ "https://Stackoverflow.com/questions/504199", "https://Stackoverflow.com", "https://Stackoverflow.com/users/49881/" ]
Alright, I find the code below to be quite repetitive and annoying. Any other way to refactor the code without using an array as a starting point (that is, to avoid using `array[x]`, `array[y]`, `array[z]` later on in the code as a result of starting with an array because `x`,`y`,`z` are completely unrelated and it mak...
In addition to what joel said you could also do the following: ``` function doOnValid(x, func){ if(x != undefined && x != "") func(); } ``` Then you could do: ``` doOnValid(x, doSomething); doOnValid(y, doSomethingElse); doOnvalid(z, function() { /*Yay lambda function*/ }); ```
504,208
<p>How can I obtain the command line arguments of another process? </p> <p>Using static functions of the <code>System.Diagnostics.Process</code> class I can obtain a list of running processes, e.g. by name:</p> <pre><code>Process[] processList = Process.GetProcessesByName(processName); </code></pre> <p>However, ther...
[ { "answer_id": 504220, "author": "plinth", "author_id": 20481, "author_profile": "https://Stackoverflow.com/users/20481", "pm_score": 1, "selected": false, "text": "<p><code>Process.StartInfo</code> returns a <a href=\"http://msdn.microsoft.com/en-us/library/system.diagnostics.processsta...
2009/02/02
[ "https://Stackoverflow.com/questions/504208", "https://Stackoverflow.com", "https://Stackoverflow.com/users/40347/" ]
How can I obtain the command line arguments of another process? Using static functions of the `System.Diagnostics.Process` class I can obtain a list of running processes, e.g. by name: ``` Process[] processList = Process.GetProcessesByName(processName); ``` However, there is no way to access the command line used ...
> > If you did not use the Start method to start a process, the StartInfo property does not reflect the parameters used to start the process. For example, if you use GetProcesses to get an array of processes running on the computer, the StartInfo property of each Process does not contain the original file name or argu...
504,219
<p>I have a string that looks like "(3) New stuff" where 3 can be any number.<br> I would like to add or subtract to this number. </p> <p>I figured out the following way:</p> <pre><code>var thenumber = string.match((/\d+/)); thenumber++; string = string.replace(/\(\d+\)/ ,'('+ thenumber +')'); </code></pre> <p>Is t...
[ { "answer_id": 504247, "author": "Allain Lalonde", "author_id": 2443, "author_profile": "https://Stackoverflow.com/users/2443", "pm_score": 1, "selected": false, "text": "<p>Short of extending the String object, it looks good to me.</p>\n\n<pre><code>String.prototype.incrementNumber = fu...
2009/02/02
[ "https://Stackoverflow.com/questions/504219", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1011/" ]
I have a string that looks like "(3) New stuff" where 3 can be any number. I would like to add or subtract to this number. I figured out the following way: ``` var thenumber = string.match((/\d+/)); thenumber++; string = string.replace(/\(\d+\)/ ,'('+ thenumber +')'); ``` Is there a more elegant way to do it?
I believe Gumbo was on the right track ``` "(42) plus (1)".replace(/\((\d+)\)/g, function(a,n){ return "("+ (+n+1) +")"; }); ```
504,256
<p>I'm using C#.NET to launch and control a Delphi-written executable. The Delphi application has a COM interface.</p> <p>I've imported the Delphi executable -- we'll call it DelphiApp.exe -- into Visual Studio as a resource. </p> <p>The following C# code works -- <em>if</em> no other instance of DelphiApp.exe is run...
[ { "answer_id": 505029, "author": "Scott W", "author_id": 3032, "author_profile": "https://Stackoverflow.com/users/3032", "pm_score": 0, "selected": false, "text": "<p>There was a question asked last week that sounds like it may be the opposite of your problem (wants to reuse the applicat...
2009/02/02
[ "https://Stackoverflow.com/questions/504256", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I'm using C#.NET to launch and control a Delphi-written executable. The Delphi application has a COM interface. I've imported the Delphi executable -- we'll call it DelphiApp.exe -- into Visual Studio as a resource. The following C# code works -- *if* no other instance of DelphiApp.exe is running: ``` DelphiApp.Del...
When you create your delphi automation server make sure that you use **ciSingleInstance** for the 4th parameter in the constructor of the automaton object. For example: ``` TAutoObjectFactory.Create(ComServer, TTestServer, Class_TestServer, ciSingleInstance, tmApartment); ``` This will require each object have a n...
504,257
<p>I have a class (class A) that is designed to be inherited by other classes written by other people. I also have another class (class B), that also inherits from A.</p> <p>B has to access some A's member functions that shouldn't be accessed by other inheriting classes.</p> <p>So, these A's member functions should b...
[ { "answer_id": 504327, "author": "Dave Swersky", "author_id": 34796, "author_profile": "https://Stackoverflow.com/users/34796", "pm_score": 0, "selected": false, "text": "<p>If I understand:</p>\n\n<ul>\n<li>A will be subclassed by other developers.</li>\n<li>B will be subclassed by othe...
2009/02/02
[ "https://Stackoverflow.com/questions/504257", "https://Stackoverflow.com", "https://Stackoverflow.com/users/44673/" ]
I have a class (class A) that is designed to be inherited by other classes written by other people. I also have another class (class B), that also inherits from A. B has to access some A's member functions that shouldn't be accessed by other inheriting classes. So, these A's member functions should be public for B, b...
What you say is: there are two sets of subclasses of A. One set should have access, the other set shouldn't. It feels wrong to have only one brand of subclasses (i.e. B) 'see' A's members. If what you mean is: only *we* can use *this* part of functionality, while our clients can't, there are other resorts. (Functiona...
504,267
<p>I am creating ASP.NET textbox controls dynamically. I want to know the difference between assigning the property of the control and adding it as an attribute. </p> <p>For ex: I can do:</p> <pre><code>TextBox txtBox = new TextBox(); txtBox.MaxLength = 100; </code></pre> <p>or I could do</p> <pre><code>txtBox.Attr...
[ { "answer_id": 504295, "author": "Otávio Décio", "author_id": 48684, "author_profile": "https://Stackoverflow.com/users/48684", "pm_score": 0, "selected": false, "text": "<p>In the end they get translated to the maxlength HTML attribute. TextBox offers a property mostly for convenience.<...
2009/02/02
[ "https://Stackoverflow.com/questions/504267", "https://Stackoverflow.com", "https://Stackoverflow.com/users/58348/" ]
I am creating ASP.NET textbox controls dynamically. I want to know the difference between assigning the property of the control and adding it as an attribute. For ex: I can do: ``` TextBox txtBox = new TextBox(); txtBox.MaxLength = 100; ``` or I could do ``` txtBox.Attributes.Add("maxlength", "100); ```
The first example is strongly typed, so the compiler will check to make sure that a) MaxLength exists and b) an integer is set for that property. The second example will work, but the compiler has no way to check to see if the attribute you are adding is correct.
504,268
<p>Assuming that I want to use a hash as an ID instead of a numeric. Would it be an performance advantage to store them as <code>BINARY</code> over non-binary?</p> <pre><code>CREATE TABLE `test`.`foobar` ( `id` CHAR(32) BINARY CHARACTER SET ascii COLLATE ascii_bin NOT NULL, PRIMARY KEY (`id`) ) CHARACTER SET ascii...
[ { "answer_id": 504359, "author": "Allain Lalonde", "author_id": 2443, "author_profile": "https://Stackoverflow.com/users/2443", "pm_score": 3, "selected": false, "text": "<p>From <a href=\"http://dev.mysql.com/doc/refman/5.0/en/binary-varbinary.html\" rel=\"nofollow noreferrer\">the manu...
2009/02/02
[ "https://Stackoverflow.com/questions/504268", "https://Stackoverflow.com", "https://Stackoverflow.com/users/53114/" ]
Assuming that I want to use a hash as an ID instead of a numeric. Would it be an performance advantage to store them as `BINARY` over non-binary? ``` CREATE TABLE `test`.`foobar` ( `id` CHAR(32) BINARY CHARACTER SET ascii COLLATE ascii_bin NOT NULL, PRIMARY KEY (`id`) ) CHARACTER SET ascii; ```
Yes. Often a hash digest is stored as the ASCII representation of hex digits, for example MD5 of the word 'hash' is: ``` 0800fc577294c34e0b28ad2839435945 ``` This is a 32-character ASCII string. But MD5 really produces a 128-bit binary hash value. This *should* require only 16 bytes to be stored as binary values in...
504,284
<p>I have an array of unsigned numbers, called dataArray (actually in the program I am trying to figure out, they are entered as hexadecimal numbers, but I don't think that's important). I have another variable of type unsigned char, called c.</p> <p>What does this do?</p> <pre><code>unsigned int dataArray[]={1,2,3,4...
[ { "answer_id": 504307, "author": "Johnny Graettinger", "author_id": 61620, "author_profile": "https://Stackoverflow.com/users/61620", "pm_score": 4, "selected": false, "text": "<p>The parenthesis don't impact the semantics here. x is computed as the bitwise exclusive-or of c (undefined h...
2009/02/02
[ "https://Stackoverflow.com/questions/504284", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I have an array of unsigned numbers, called dataArray (actually in the program I am trying to figure out, they are entered as hexadecimal numbers, but I don't think that's important). I have another variable of type unsigned char, called c. What does this do? ``` unsigned int dataArray[]={1,2,3,4,5}; unsigned char c;...
The parenthesis don't impact the semantics here. x is computed as the bitwise exclusive-or of c (undefined here) and dataArray[i].
504,285
<p>Say I have this table:</p> <pre><code>Person table -------------- PersonId Address table ------------ AddressId PersonAddressId </code></pre> <p>where PersonAddressId is PersonId and the foreign key. Is there any type of database violation in renaming the foreign key? It can become very confusing to work with w...
[ { "answer_id": 504315, "author": "Allain Lalonde", "author_id": 2443, "author_profile": "https://Stackoverflow.com/users/2443", "pm_score": 0, "selected": false, "text": "<p>Agreed and that's why the convention is to name PersonAddressId as PersonId.</p>\n" }, { "answer_id": 5043...
2009/02/02
[ "https://Stackoverflow.com/questions/504285", "https://Stackoverflow.com", "https://Stackoverflow.com/users/40106/" ]
Say I have this table: ``` Person table -------------- PersonId Address table ------------ AddressId PersonAddressId ``` where PersonAddressId is PersonId and the foreign key. Is there any type of database violation in renaming the foreign key? It can become very confusing to work with when they have different name...
It's generally helpful to name the foreign key column the same as the primary key column it references, where possible. Of course, sometimes it's not possible: * Two columns in `Address` might both be foreign keys to `Person`, so obviously you can't name both columns `PersonId`. * Some tables contain a foreign key to...
504,290
<p>I'm currently working on a Silverlight app and need to convert XML data into appropriate objects to data bind to. The basic class definition for this discussion is:</p> <pre><code>public class TabularEntry { public string Tag { get; set; } public string Description { get; set; } public ...
[ { "answer_id": 504462, "author": "Amy B", "author_id": 8155, "author_profile": "https://Stackoverflow.com/users/8155", "pm_score": 0, "selected": false, "text": "<p>Descendants will get you all of the <code>I</code> children. The <code>FirstNode</code> will help seperate the value of <c...
2009/02/02
[ "https://Stackoverflow.com/questions/504290", "https://Stackoverflow.com", "https://Stackoverflow.com/users/26516/" ]
I'm currently working on a Silverlight app and need to convert XML data into appropriate objects to data bind to. The basic class definition for this discussion is: ``` public class TabularEntry { public string Tag { get; set; } public string Description { get; set; } public string Code { g...
Try this: ``` List<TabularEntry> GetTabularEntries(XElement source) { List<TabularEntry> result; result = (from tabularentry in source.Elements() select new TabularEntry() { Tag = tabularentry.Name.ToString(), Desc...
504,296
<p>I know that often using a for loop to generate repetitive content is the better way than pasting something 20 times and changing each paste to the correct number by hand. But let's say for cases where content is hard-coded and I just want a list from 1-20.</p> <p>I would like a text editor with a "smart" paste co...
[ { "answer_id": 504341, "author": "Pete Kirkham", "author_id": 1527, "author_profile": "https://Stackoverflow.com/users/1527", "pm_score": 1, "selected": false, "text": "<p><a href=\"http://armedbear.org/j.html\" rel=\"nofollow noreferrer\">Armed bear J</a> has a renumber region command, ...
2009/02/02
[ "https://Stackoverflow.com/questions/504296", "https://Stackoverflow.com", "https://Stackoverflow.com/users/57625/" ]
I know that often using a for loop to generate repetitive content is the better way than pasting something 20 times and changing each paste to the correct number by hand. But let's say for cases where content is hard-coded and I just want a list from 1-20. I would like a text editor with a "smart" paste command that t...
In [Zeus](http://www.zeusedit.com) this can be easily done as follows: 1. Column mark the area to be converted to a numbers 2. Use the *Macros, Execute Script* menu 3. Type in *numbers* to run the [numbers](http://www.zeusedit.com/forum/viewtopic.php?t=2092) Lua macro 4. Type in the *first number* of the sequence The...
504,332
<p>This question is self explanatory if you know how to use JMockit: How do I mock a method that has generics on it? I want to mock this method: public T save(T entity) but it always throws an exception like this:</p> <pre><code>mockit.RealMethodNotFoundForMockException: Corresponding real methods not found for the f...
[ { "answer_id": 504580, "author": "IAdapter", "author_id": 30453, "author_profile": "https://Stackoverflow.com/users/30453", "pm_score": 2, "selected": true, "text": "<p>it does work for me, example</p>\n\n<pre>\npackage a;\n\nimport junit.framework.TestCase;\nimport mockit.Mockit;\n\npub...
2009/02/02
[ "https://Stackoverflow.com/questions/504332", "https://Stackoverflow.com", "https://Stackoverflow.com/users/61624/" ]
This question is self explanatory if you know how to use JMockit: How do I mock a method that has generics on it? I want to mock this method: public T save(T entity) but it always throws an exception like this: ``` mockit.RealMethodNotFoundForMockException: Corresponding real methods not found for the following mocks:...
it does work for me, example ``` package a; import junit.framework.TestCase; import mockit.Mockit; public class JMockitCoreExampleTest extends TestCase { public class MockMe { public T save(T t) { return null; } } public void testDoOperationAbc() { Mockit.redefineMe...
504,338
<p>I'm going back to the basics here but in Lua, you can define a table like so:</p> <pre><code>myTable = {} myTable [1] = 12 </code></pre> <p>Printing the table reference itself brings back a pointer to it. To access its elements you need to specify an index (i.e. exactly like you would an array)</p> <pre><code>pr...
[ { "answer_id": 504474, "author": "Judge Maygarden", "author_id": 1491, "author_profile": "https://Stackoverflow.com/users/1491", "pm_score": 0, "selected": false, "text": "<p>You could accomplish this by creating an <a href=\"http://www.lua.org/manual/5.1/manual.html#2.9\" rel=\"nofollow...
2009/02/02
[ "https://Stackoverflow.com/questions/504338", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I'm going back to the basics here but in Lua, you can define a table like so: ``` myTable = {} myTable [1] = 12 ``` Printing the table reference itself brings back a pointer to it. To access its elements you need to specify an index (i.e. exactly like you would an array) ``` print(myTable ) --prints pointer prin...
There is no way to get access to body source code of given function in plain Lua. Source code is thrown away after compilation to byte-code. Note BTW that function may be defined in run-time with loadstring-like facility. Partial solutions are possible — depending on what you actually want to achieve. You may get so...
504,342
<p>I currently have a site where different users can login, and depending on their sub domain, are presented with different data from different databases. I am overriding the SqlMembershipProvider to use a "temp" connection string, that I dynamically set during the Initialize Method, per this post's instructions:</p> ...
[ { "answer_id": 504361, "author": "ScottS", "author_id": 51851, "author_profile": "https://Stackoverflow.com/users/51851", "pm_score": 0, "selected": false, "text": "<p>I have done exactly this using a single membership database to handle all the logins, and then hook them up to the appro...
2009/02/02
[ "https://Stackoverflow.com/questions/504342", "https://Stackoverflow.com", "https://Stackoverflow.com/users/57698/" ]
I currently have a site where different users can login, and depending on their sub domain, are presented with different data from different databases. I am overriding the SqlMembershipProvider to use a "temp" connection string, that I dynamically set during the Initialize Method, per this post's instructions: <http:/...
The code for the SQLMembershipProvider is provided [here](http://download.microsoft.com/download/a/b/3/ab3c284b-dc9a-473d-b7e3-33bacfcc8e98/ProviderToolkitSamples.msi). You could extend/change what you think is necessary by adding the project to your solution and changing the namespace references in web.config.
504,367
<p>I have a section of code that is being used to determine if a certain event should happen. The code looks like this.</p> <pre><code> If (Date.Now.Ticks Mod 100) &lt; 4 Then Return True Else Return False End If </code></pre> <p>The idea here is that this event should h...
[ { "answer_id": 504380, "author": "Canavar", "author_id": 55351, "author_profile": "https://Stackoverflow.com/users/55351", "pm_score": 2, "selected": false, "text": "<p>Why don't you use this : </p>\n\n<pre><code>Dim r As New Random(System.DateTime.Now.Millisecond)\nReturn r.Next(0, 100)...
2009/02/02
[ "https://Stackoverflow.com/questions/504367", "https://Stackoverflow.com", "https://Stackoverflow.com/users/42845/" ]
I have a section of code that is being used to determine if a certain event should happen. The code looks like this. ``` If (Date.Now.Ticks Mod 100) < 4 Then Return True Else Return False End If ``` The idea here is that this event should happen 4 time out of 100, or 4...
The reason you're getting that behavior is *you're not asking for 4% of the time that you be given a True value*, you're asking that any time the number of Ticks modulo 100 is less than 4. Given a uniform random number generator, as in [System.Random](http://msdn.microsoft.com/en-us/library/system.random.aspx): ``` D...
504,368
<p>You have usage: <a href="http://mojohaus.org/findbugs-maven-plugin/usage.html" rel="nofollow noreferrer">findbugs-maven-plugin</a></p> <pre><code>&lt;project&gt; [...] &lt;reporting&gt; [...] &lt;plugin&gt; &lt;groupId&gt;org.codehaus.mojo&lt;/groupId&gt; &lt;artifactId&gt;findbugs-maven-plu...
[ { "answer_id": 504394, "author": "Loki", "author_id": 39057, "author_profile": "https://Stackoverflow.com/users/39057", "pm_score": 2, "selected": false, "text": "<p>try that:</p>\n\n<pre><code>&lt;version&gt;1.2&lt;/version&gt;\n</code></pre>\n\n<p><a href=\"http://repo2.maven.org/maven...
2009/02/02
[ "https://Stackoverflow.com/questions/504368", "https://Stackoverflow.com", "https://Stackoverflow.com/users/61628/" ]
You have usage: [findbugs-maven-plugin](http://mojohaus.org/findbugs-maven-plugin/usage.html) ``` <project> [...] <reporting> [...] <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>findbugs-maven-plugin</artifactId> <version>1.2.1</version> <configuration> <xmlOutpu...
Looking at the repository, your version should be 1.2, not 1.2.1 Also, your configuration is wrong, you need to choose some of the options. So it should look like: ``` <plugin> <groupId>org.codehaus.mojo</groupId> <artifactId>findbugs-maven-plugin</artifactId> <version>1.2</version> <configuration> <t...
504,383
<p>I'm using the VideoDisplay to play flv's, mov's, and mp4's and everything is working great. They are all being loaded via progressive download and are not being streamed. What I'd like to do is to grab a single specified frame (like whatever is being shown at the 10 second mark), convert it to a bitmap and use tha...
[ { "answer_id": 504524, "author": "James Hay", "author_id": 47339, "author_profile": "https://Stackoverflow.com/users/47339", "pm_score": 1, "selected": false, "text": "<p>I'm pretty sure this isn't possible. It may well be... but don't think so. I think the only way to load in video is...
2009/02/02
[ "https://Stackoverflow.com/questions/504383", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3435/" ]
I'm using the VideoDisplay to play flv's, mov's, and mp4's and everything is working great. They are all being loaded via progressive download and are not being streamed. What I'd like to do is to grab a single specified frame (like whatever is being shown at the 10 second mark), convert it to a bitmap and use that bit...
Ryan and James are correct -- the right way's probably to extract frames at upload/transcode-time. But if that's not an option, you could opt for using some sort of a default/placeholder image of your own (something generic or somehow suitable for all videos whose thumbs haven't yet been captured), and just use VideoDi...
504,402
<p>I've been looking through the ANTLR v3 documentation (and my trusty copy of "The Definitive ANTLR reference"), and I can't seem to find a clean way to implement escape sequences in string literals (I'm currently using the Java target). I had hoped to be able to do something like:</p> <pre><code>fragment ESCAPE_SE...
[ { "answer_id": 552945, "author": "Bruno Ranschaert", "author_id": 4900, "author_profile": "https://Stackoverflow.com/users/4900", "pm_score": 5, "selected": true, "text": "<p>Here is how I accomplished this in the JSON parser I wrote.</p>\n\n<pre><code>STRING \n@init{StringBuilder l...
2009/02/02
[ "https://Stackoverflow.com/questions/504402", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19088/" ]
I've been looking through the ANTLR v3 documentation (and my trusty copy of "The Definitive ANTLR reference"), and I can't seem to find a clean way to implement escape sequences in string literals (I'm currently using the Java target). I had hoped to be able to do something like: ``` fragment ESCAPE_SEQUENCE : '\...
Here is how I accomplished this in the JSON parser I wrote. ``` STRING @init{StringBuilder lBuf = new StringBuilder();} : '"' ( escaped=ESC {lBuf.append(getText());} | normal=~('"'|'\\'|'\n'|'\r') {lBuf.appendCodePoint(normal);} )* '"' {...
504,403
<p>I have a function that I use to add vectors, like this:</p> <pre><code>public static Vector AddVector(Vector v1, Vector v2) { return new Vector( v1.X + v2.X, v1.Y + v2.Y, v1.Z + v2.Z); } </code></pre> <p>Not very interesting. However, I overload the '+' operator for vectors and in the overloa...
[ { "answer_id": 504443, "author": "Szymon Rozga", "author_id": 7583, "author_profile": "https://Stackoverflow.com/users/7583", "pm_score": 2, "selected": false, "text": "<blockquote>\n <p>\"And I suppose it's not just the overhead of the method call, but also the copying of the method ar...
2009/02/02
[ "https://Stackoverflow.com/questions/504403", "https://Stackoverflow.com", "https://Stackoverflow.com/users/61632/" ]
I have a function that I use to add vectors, like this: ``` public static Vector AddVector(Vector v1, Vector v2) { return new Vector( v1.X + v2.X, v1.Y + v2.Y, v1.Z + v2.Z); } ``` Not very interesting. However, I overload the '+' operator for vectors and in the overload I call the AddVector fun...
Don't assume that `struct` is the right choice for performance. The copying cost can be significant in some scenarios. Until you measure you don't know. Furthermore, `struct`s have [spooky](https://stackoverflow.com/questions/370859/why-isnan-is-a-static-method-on-the-double-class-instead-of-an-instance-property/370996...
504,417
<p>I have a text string structured like this:</p> <pre><code>= Some Heading (1) Some text == Some Sub-Heading (2) Some more text === Some Sub-sub-heading (3) Some details here = Some other Heading (4) </code></pre> <p>I want to extract the content of second heading, including any subsection. I do not know befor...
[ { "answer_id": 504430, "author": "jasedit", "author_id": 59184, "author_profile": "https://Stackoverflow.com/users/59184", "pm_score": 4, "selected": true, "text": "<p>I make an effort to clean up my revision history. My workflow goes along the lines of make a small but meaningful edit, ...
2009/02/02
[ "https://Stackoverflow.com/questions/504417", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I have a text string structured like this: ``` = Some Heading (1) Some text == Some Sub-Heading (2) Some more text === Some Sub-sub-heading (3) Some details here = Some other Heading (4) ``` I want to extract the content of second heading, including any subsection. I do not know beforehand what is the depth of...
I make an effort to clean up my revision history. My workflow goes along the lines of make a small but meaningful edit, commit, repeat until some series of larger modifications are made. Then I go back and re-order/group commits together into functionally atomic commits, and push those revised commits out. This allows ...
504,423
<p>I've written a powershell script that I've turned into a scheduled task. So far, so good. The issue I have is that every time Powershell is started, it causes my floppy drive to seek; this means every five minutes (on the task schedule), I get a little "grind" from the floppy drive.</p> <p>How do I disable this beh...
[ { "answer_id": 504477, "author": "Steven Murawski", "author_id": 1233, "author_profile": "https://Stackoverflow.com/users/1233", "pm_score": 1, "selected": false, "text": "<p>It could be something in your profile script(s). I've not experienced PowerShell causing any floppy drive activi...
2009/02/02
[ "https://Stackoverflow.com/questions/504423", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5453/" ]
I've written a powershell script that I've turned into a scheduled task. So far, so good. The issue I have is that every time Powershell is started, it causes my floppy drive to seek; this means every five minutes (on the task schedule), I get a little "grind" from the floppy drive. How do I disable this behavior? ``...
I'd say its the drive enumeration that happens at runtime. Powershell builds a list of drives and creates aliases for each one so you can type "A:" and have it work like cmd.exe. I think this because if you start Powershell on a clustered server, that does not own a shared drive (is owned by the other node), it issues ...
504,427
<p>I'm trying to make a Tetris-like game in XNA, and currently I'm thinking of what way would be the best to handle it.</p> <p>This is what I have so far: I have a class called Block, which has for example texture and color tint.</p> <p>Then I was planning on having everything in a double array, like:</p> <pre><code...
[ { "answer_id": 504460, "author": "BFree", "author_id": 15861, "author_profile": "https://Stackoverflow.com/users/15861", "pm_score": 3, "selected": true, "text": "<p>No, you're just moving pointers around. When you say:</p>\n\n<pre><code>blocks[x,y+1] = blocks[x,y];\n</code></pre>\n\n<p>...
2009/02/02
[ "https://Stackoverflow.com/questions/504427", "https://Stackoverflow.com", "https://Stackoverflow.com/users/56179/" ]
I'm trying to make a Tetris-like game in XNA, and currently I'm thinking of what way would be the best to handle it. This is what I have so far: I have a class called Block, which has for example texture and color tint. Then I was planning on having everything in a double array, like: ``` Block[,] blocks = new Block...
No, you're just moving pointers around. When you say: ``` blocks[x,y+1] = blocks[x,y]; ``` what you're essentially doing is swapping the pointer. The object will stay exactly where it is, but now instead of it being at index x,y it'll be at index of x , y+1. When you say ``` blocks[x,y] = null; ``` there you're ...
504,431
<p>I would like to do the following. Basically have a stored procedure call another stored procedure that returns a table. How is this done? </p> <pre><code> ALTER PROC [GETSomeStuff] AS BEGIN @table = exec CB_GetLedgerView @accountId, @fromDate, @toDate, @pageSize, @pageNumber, @filter, @status, @...
[ { "answer_id": 504449, "author": "cmsjr", "author_id": 23114, "author_profile": "https://Stackoverflow.com/users/23114", "pm_score": 6, "selected": true, "text": "<p>The target of a stored procedure has to be a temp or actual table so you can </p>\n\n<pre><code> Insert into #table exe...
2009/02/02
[ "https://Stackoverflow.com/questions/504431", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16628/" ]
I would like to do the following. Basically have a stored procedure call another stored procedure that returns a table. How is this done? ``` ALTER PROC [GETSomeStuff] AS BEGIN @table = exec CB_GetLedgerView @accountId, @fromDate, @toDate, @pageSize, @pageNumber, @filter, @status, @sortExpression, @s...
The target of a stored procedure has to be a temp or actual table so you can ``` Insert into #table exec CB_GetLedgerView @accountId, @fromDate, @toDate, @pageSize, @pageNumber, @filter, @status, @sortExpression, @sortOrder, @virtualCount OUTPUT ``` If the output result set of the stored procedure does not m...
504,442
<p>I have a list of values such as "12000","12345","123456" that need to be converted to currency ("120.00", "123.45", "1234.56"). The only way I know is to convert the value to a string, copy the first strlen()-2 characters to one string (dollars) and the remainging two digits to another string(cents) and then write t...
[ { "answer_id": 504452, "author": "Phaedrus", "author_id": 46072, "author_profile": "https://Stackoverflow.com/users/46072", "pm_score": 4, "selected": true, "text": "<pre><code>printf(\"$%.2f\", value/100);\n</code></pre>\n" }, { "answer_id": 506321, "author": "Tim Ring", ...
2009/02/02
[ "https://Stackoverflow.com/questions/504442", "https://Stackoverflow.com", "https://Stackoverflow.com/users/53007/" ]
I have a list of values such as "12000","12345","123456" that need to be converted to currency ("120.00", "123.45", "1234.56"). The only way I know is to convert the value to a string, copy the first strlen()-2 characters to one string (dollars) and the remainging two digits to another string(cents) and then write them...
``` printf("$%.2f", value/100); ```
504,464
<p>I want to use Thickbox (or one of the varieties) on our site to display information messages returned from the server. Examples include warning messages returned from biz logic, etc.</p> <p>The first place to need this functionality will be the navigation buttons on an asp:wizard control. When the user tries to m...
[ { "answer_id": 629003, "author": "Chris", "author_id": 59198, "author_profile": "https://Stackoverflow.com/users/59198", "pm_score": 0, "selected": false, "text": "<p>One thing i've often encountered is that when you return javascript from an AJAX request, it won't get executed by defaul...
2009/02/02
[ "https://Stackoverflow.com/questions/504464", "https://Stackoverflow.com", "https://Stackoverflow.com/users/61640/" ]
I want to use Thickbox (or one of the varieties) on our site to display information messages returned from the server. Examples include warning messages returned from biz logic, etc. The first place to need this functionality will be the navigation buttons on an asp:wizard control. When the user tries to move forward,...
Late answer, but maybe not too late. I'm a litte bit confused by your question, I will just answer this part : > > What we really want is to be able to > invoke this from any code behind in > some fashion like: > > > Page.ShowMessage("Hello lightbox!") > > > Let's do it with Thickbox and jQuery, that's what I...
504,475
<p>I use the mysqldump tool to make copies of my database. The problem is, when I use the --routines parameter to output my stored procedures along with my data, the generated output causes an error when I try to import it.</p> <p>It goes something like this:</p> <pre><code>% mysqldump --routines MyDB | mysql MyDB2 ...
[ { "answer_id": 629003, "author": "Chris", "author_id": 59198, "author_profile": "https://Stackoverflow.com/users/59198", "pm_score": 0, "selected": false, "text": "<p>One thing i've often encountered is that when you return javascript from an AJAX request, it won't get executed by defaul...
2009/02/02
[ "https://Stackoverflow.com/questions/504475", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1449/" ]
I use the mysqldump tool to make copies of my database. The problem is, when I use the --routines parameter to output my stored procedures along with my data, the generated output causes an error when I try to import it. It goes something like this: ``` % mysqldump --routines MyDB | mysql MyDB2 ``` (where MyDB2 alr...
Late answer, but maybe not too late. I'm a litte bit confused by your question, I will just answer this part : > > What we really want is to be able to > invoke this from any code behind in > some fashion like: > > > Page.ShowMessage("Hello lightbox!") > > > Let's do it with Thickbox and jQuery, that's what I...
504,494
<p>I've got a Checkedlistbox, which is 3 rows high, and large enough to display about 5 elements.</p> <p>As long as I've got less than 15 elements, everything runs fine. However, if I add a sixteenth element, the checkedlistbox displays an horizontal scrollbar which takes 2 item rows, which means all the Items are now...
[ { "answer_id": 504503, "author": "bdukes", "author_id": 2688, "author_profile": "https://Stackoverflow.com/users/2688", "pm_score": 1, "selected": false, "text": "<p>If you're okay with taking a dependency on Java, you can use <a href=\"http://developer.yahoo.com/yui/compressor/\" rel=\"...
2009/02/02
[ "https://Stackoverflow.com/questions/504494", "https://Stackoverflow.com", "https://Stackoverflow.com/users/47341/" ]
I've got a Checkedlistbox, which is 3 rows high, and large enough to display about 5 elements. As long as I've got less than 15 elements, everything runs fine. However, if I add a sixteenth element, the checkedlistbox displays an horizontal scrollbar which takes 2 item rows, which means all the Items are now on only o...
If you're okay with taking a dependency on Java, you can use [YUI Compressor](http://developer.yahoo.com/yui/compressor/) (otherwise there's the [.NET port of it](http://www.codeplex.com/YUICompressor)).
504,500
<p>I need to be able to read a file format that mixes binary and non-binary data. Assuming I know the input is good, what's the best way to do this? As an example, let's take a file that has a double as the first line, a newline (0x0D 0x0A) and then ten bytes of binary data afterward. I could, of course, calculate t...
[ { "answer_id": 504516, "author": "Jon Skeet", "author_id": 22656, "author_profile": "https://Stackoverflow.com/users/22656", "pm_score": 2, "selected": false, "text": "<p>Is this file format already fixed? If it's not, it's a really good idea to change to use a length-prefixed format for...
2009/02/02
[ "https://Stackoverflow.com/questions/504500", "https://Stackoverflow.com", "https://Stackoverflow.com/users/52513/" ]
I need to be able to read a file format that mixes binary and non-binary data. Assuming I know the input is good, what's the best way to do this? As an example, let's take a file that has a double as the first line, a newline (0x0D 0x0A) and then ten bytes of binary data afterward. I could, of course, calculate the pos...
You can use System.IO.BinaryReader. The problem with this though is you *must* know what type of data you are going to be reading before you call any of the Read methods. ``` Read(byte[], int, int) Read(char[], int, int) Read() Read7BitEncodedInt() ReadBoolean() ReadByte() ReadBytes(int) ReadChar() ReadChars() ReadDec...
504,504
<p>I have a flash piece that loads external SWF files. I need to be able to move the loaded swf file to the next frame in the main timeline.</p> <p>Here's the code snippet:</p> <pre><code>var request:URLRequest = new URLRequest(file); loader.load(request); var swfTimeline:MovieClip = loader.content as MovieClip; swf...
[ { "answer_id": 504566, "author": "Matt W", "author_id": 32396, "author_profile": "https://Stackoverflow.com/users/32396", "pm_score": 2, "selected": false, "text": "<p>Use the content property of the Loader object in which you are loading the SWF into. For example...</p>\n\n<pre><code>va...
2009/02/02
[ "https://Stackoverflow.com/questions/504504", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10420/" ]
I have a flash piece that loads external SWF files. I need to be able to move the loaded swf file to the next frame in the main timeline. Here's the code snippet: ``` var request:URLRequest = new URLRequest(file); loader.load(request); var swfTimeline:MovieClip = loader.content as MovieClip; swfTimeline.nextFrame(); ...
You need to add an event listener o the loader first so that you know when the load is complete. So from your code snippet i would suggest something like ``` var request:URLRequest = new URLRequest(file); loader.addEventListener(Event.COMPLETE, function(event : Event) : void { var swfTimeline:MovieClip = loader.conten...
504,508
<p>Given the tables:</p> <p>role: roleid, name<br> permission: permissionid, name<br> role_permission: roleid, permissionid </p> <p>I have a set of permissions, and I want to see if there is an existing role that has these permissions, or if I need to make a new one. Note that I already know the permissionid, so...
[ { "answer_id": 504529, "author": "mmx", "author_id": 33708, "author_profile": "https://Stackoverflow.com/users/33708", "pm_score": 3, "selected": true, "text": "<p>You can select all roles that have the subset of permissions you are looking for. Count the number of permissions and see if...
2009/02/02
[ "https://Stackoverflow.com/questions/504508", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7913/" ]
Given the tables: role: roleid, name permission: permissionid, name role\_permission: roleid, permissionid I have a set of permissions, and I want to see if there is an existing role that has these permissions, or if I need to make a new one. Note that I already know the permissionid, so really the permissio...
You can select all roles that have the subset of permissions you are looking for. Count the number of permissions and see if it's exactly equal to the number of permissions you need: ``` select r.roleid from role r where not exists (select * from role_permissions rp where rp.roleid = r.roleid and rp.permissionid not ...
504,533
<p>I have a scenario where I have a WPF TreeView control that has an <code>HierarchicalDataTemplate</code> for its items. Now inside the <code>HierarchicalDataTemplate</code>, I have a <code>Label</code> and the <code>Label</code> has a <code>ContextMenu</code> with a menuitem for <code>Delete</code>. The Delete menuit...
[ { "answer_id": 504556, "author": "Szymon Rozga", "author_id": 7583, "author_profile": "https://Stackoverflow.com/users/7583", "pm_score": 0, "selected": false, "text": "<p>Take a look at <a href=\"https://stackoverflow.com/questions/257396/wpf-commandparameter-binding-problem\">WPF Comma...
2009/02/02
[ "https://Stackoverflow.com/questions/504533", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I have a scenario where I have a WPF TreeView control that has an `HierarchicalDataTemplate` for its items. Now inside the `HierarchicalDataTemplate`, I have a `Label` and the `Label` has a `ContextMenu` with a menuitem for `Delete`. The Delete menuitem is bound to a Command called `DeleteCommand` which is a part of th...
The problem is that the ContextMenu is at the root of its own visual tree, so any RelativeSource.FindAncestor bindings won't go past the ContextMenu. One solution is to use the [PlacementTarget](http://msdn.microsoft.com/en-us/library/system.windows.controls.contextmenu.placementtarget.aspx) property to set up a two-s...