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
34,128
<p>We are trying to create a web-service that we plan to pass a variable amount of variables to it.</p> <p>Can this be done?</p> <p>Basically instead of pass all possible parameters we wish to pass only the set values and use the defaults set in the web-service.</p> <p>Here is an example of the XML we are looking to...
[ { "answer_id": 34132, "author": "Konrad Rudolph", "author_id": 1968, "author_profile": "https://Stackoverflow.com/users/1968", "pm_score": 0, "selected": false, "text": "<p>You can simply pass a variable-length array as a parameter.</p>\n" }, { "answer_id": 34138, "author": "...
2008/08/29
[ "https://Stackoverflow.com/questions/34128", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3582/" ]
We are trying to create a web-service that we plan to pass a variable amount of variables to it. Can this be done? Basically instead of pass all possible parameters we wish to pass only the set values and use the defaults set in the web-service. Here is an example of the XML we are looking to send, we would sent an ...
I would pass in an xml document instead of doing concreate functions for this. The webservice in your example is leaky - the consumer needs to know too much about this interface and the implementation of the webservice internally. XML Document and then tie that with an XSD. That way you can prevalidte the input to ...
34,144
<p>I would like to know which dependency described in my pom.xml brings a transitive dependency in my target directory.</p> <p>To be more precise, I have the library "poi-2.5.1-final-20040804.jar" in my WEB-INF/lib directory and I would like to know which dependency in my pom.xml brings that.</p>
[ { "answer_id": 34156, "author": "David Crow", "author_id": 2783, "author_profile": "https://Stackoverflow.com/users/2783", "pm_score": 6, "selected": false, "text": "<p>Using the <a href=\"http://maven.apache.org/plugins/maven-dependency-plugin/\" rel=\"noreferrer\">Maven Dependency Plug...
2008/08/29
[ "https://Stackoverflow.com/questions/34144", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3122/" ]
I would like to know which dependency described in my pom.xml brings a transitive dependency in my target directory. To be more precise, I have the library "poi-2.5.1-final-20040804.jar" in my WEB-INF/lib directory and I would like to know which dependency in my pom.xml brings that.
To add to @David Crow, here's [a dependency:tree example](http://maven.apache.org/plugins/maven-dependency-plugin/examples/filtering-the-dependency-tree.html) from the Maven site: ``` mvn dependency:tree -Dincludes=velocity:velocity ``` might output ``` [INFO] [dependency:tree] [INFO] org.apache.maven.plugins:maven...
34,155
<p>I'm trying to grasp the concept of continuations and I found several small teaching examples like this one from the <a href="http://en.wikipedia.org/wiki/Continuation" rel="noreferrer">Wikipedia article</a>:</p> <pre><code>(define the-continuation #f) (define (test) (let ((i 0)) ; call/cc calls its first fun...
[ { "answer_id": 34173, "author": "A. Rex", "author_id": 3508, "author_profile": "https://Stackoverflow.com/users/3508", "pm_score": 2, "selected": false, "text": "<p>Continuations can be used in \"real-life\" examples whenever the program flow is not linear, or not even pre-determined. A...
2008/08/29
[ "https://Stackoverflow.com/questions/34155", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2797/" ]
I'm trying to grasp the concept of continuations and I found several small teaching examples like this one from the [Wikipedia article](http://en.wikipedia.org/wiki/Continuation): ``` (define the-continuation #f) (define (test) (let ((i 0)) ; call/cc calls its first function argument, passing ; a continuat...
In Algo & Data II we used these all the times to "exit" or "return" from a (long) function for example the BFS algorthm to traverse trees with was implemented like this: ``` (define (BFS graph root-discovered node-discovered edge-discovered edge-bumped . nodes) (define visited (make-vector (graph.order graph) #f)) ...
34,161
<p>I have the following situation: I built an Access form with a subform (which records are linked to the records of main form via certain key). When I try to delete any record in the subform, I get the following message: “Access has suspended the action because you and another user tried to change the data” (approxima...
[ { "answer_id": 34172, "author": "samjudson", "author_id": 1908, "author_profile": "https://Stackoverflow.com/users/1908", "pm_score": 2, "selected": true, "text": "<p>If you are currently 'editing' the current form then it will not allow the action. Editing a record can sometimes be trig...
2008/08/29
[ "https://Stackoverflow.com/questions/34161", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2717/" ]
I have the following situation: I built an Access form with a subform (which records are linked to the records of main form via certain key). When I try to delete any record in the subform, I get the following message: “Access has suspended the action because you and another user tried to change the data” (approximate ...
If you are currently 'editing' the current form then it will not allow the action. Editing a record can sometimes be triggered by simply clicking inside a field, or other simple actions you wouldn't normally consider 'editing'. This is usually avoided in Access by using the RunCommand method to undo any edits before d...
34,183
<p>I'm trying to run a batch file, as another user, from my web app. For some reason, the batch file hangs! I can see "cmd.exe" running in the task manager, but it just sits there forever, unable to be killed, and the batch file is not running. Here's my code:</p> <pre><code>SecureString password = new SecureString();...
[ { "answer_id": 34187, "author": "Espo", "author_id": 2257, "author_profile": "https://Stackoverflow.com/users/2257", "pm_score": 0, "selected": false, "text": "<p>My guess would be that the build.cmd is waiting for some sort of user-interaction/reply. If you log the output of the command...
2008/08/29
[ "https://Stackoverflow.com/questions/34183", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2527/" ]
I'm trying to run a batch file, as another user, from my web app. For some reason, the batch file hangs! I can see "cmd.exe" running in the task manager, but it just sits there forever, unable to be killed, and the batch file is not running. Here's my code: ``` SecureString password = new SecureString(); foreach (char...
I believe I've found the answer. It seems that Microsoft, in all their infinite wisdom, has blocked batch files from being executed by IIS in Windows Server 2003. Brenden Tompkins has a work-around here: <http://codebetter.com/blogs/brendan.tompkins/archive/2004/05/13/13484.aspx> That won't work for me, because my ba...
34,194
<p>Where can I find some good pointers on best practices for running ASP.NET MVC on IIS6?</p> <p>I haven't seen any realistic options for web-hosts who provide IIS7-hosting yet. Mostly because I don't live in the U.S.</p> <p>So I was wondering on how you best build applications in ASP.NET MVC and make it easily avail...
[ { "answer_id": 34206, "author": "Espo", "author_id": 2257, "author_profile": "https://Stackoverflow.com/users/2257", "pm_score": 2, "selected": false, "text": "<p>With IIS6 you can do one of two things:</p>\n\n<ol>\n<li>Setup an ISAPI filter to map MVC URLs to ASP.NET</li>\n<li><a href=\...
2008/08/29
[ "https://Stackoverflow.com/questions/34194", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2429/" ]
Where can I find some good pointers on best practices for running ASP.NET MVC on IIS6? I haven't seen any realistic options for web-hosts who provide IIS7-hosting yet. Mostly because I don't live in the U.S. So I was wondering on how you best build applications in ASP.NET MVC and make it easily available to deploy on...
It took me a bit, but I figured out how to make the extensions work with IIS 6. First, you need to rework the base routing to include .aspx so that they will be routed through the ASP.NET ISAPI filter. ``` routes.MapRoute( "Default", // Route name "{controller}.aspx...
34,204
<p>How do I get the latest version of my solution recursively like its done in the solution explorer context menu of Visual Studio? I want to do this from the command line or via a macro. I'm trying to automate a part of my daily routine by using a set of batch files. I am sure a lot of developers would love to have so...
[ { "answer_id": 35169, "author": "NotMe", "author_id": 2424, "author_profile": "https://Stackoverflow.com/users/2424", "pm_score": 1, "selected": false, "text": "<p>Well... It looks like you have three options.</p>\n\n<ol>\n<li><p>In your batch file, issue a tf get at each directory branc...
2008/08/29
[ "https://Stackoverflow.com/questions/34204", "https://Stackoverflow.com", "https://Stackoverflow.com/users/45603/" ]
How do I get the latest version of my solution recursively like its done in the solution explorer context menu of Visual Studio? I want to do this from the command line or via a macro. I'm trying to automate a part of my daily routine by using a set of batch files. I am sure a lot of developers would love to have somet...
TFS has a [.Net SDK](http://msdn.microsoft.com/en-us/library/bb130146(VS.80).aspx) that allows you to create your own custom programs that interact with a TFS Server. You could write a small program that performs the task you need: ``` TeamFoundationServer tfs = TeamFoundationServerFactory.GetServer("MyServer"); Versi...
34,209
<p>In the transition to newforms admin I'm having difficulty figuring out how specify core=False for ImageFields.</p> <p>I get the following error:</p> <pre><code>TypeError: __init__() got an unexpected keyword argument 'core' </code></pre> <p>[Edit] However, by just removing the core argument I get a "This field is...
[ { "answer_id": 34391, "author": "dguaraglia", "author_id": 2384, "author_profile": "https://Stackoverflow.com/users/2384", "pm_score": 2, "selected": false, "text": "<p>This is simple. I started getting this problems a few revisions ago. Basically, just remove the \"core=True\" parameter...
2008/08/29
[ "https://Stackoverflow.com/questions/34209", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3594/" ]
In the transition to newforms admin I'm having difficulty figuring out how specify core=False for ImageFields. I get the following error: ``` TypeError: __init__() got an unexpected keyword argument 'core' ``` [Edit] However, by just removing the core argument I get a "This field is required." error in the admin in...
To get rid of "This field is required," you need to make it not required, by using blank=True (and possibly null=True as well, if it's not a CharField).
34,249
<p>What's the best (halting) algorithm for determining if a linked list has a cycle in it?</p> <p>[Edit] Analysis of asymptotic complexity for both time and space would be sweet so answers can be compared better.</p> <p>[Edit] Original question was not addressing nodes with outdegree > 1, but there's some talk about ...
[ { "answer_id": 34253, "author": "OysterD", "author_id": 2638, "author_profile": "https://Stackoverflow.com/users/2638", "pm_score": 0, "selected": false, "text": "<p>What about using a hash table to store the already seen nodes (you look at them in order from the start of the list)? In p...
2008/08/29
[ "https://Stackoverflow.com/questions/34249", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3594/" ]
What's the best (halting) algorithm for determining if a linked list has a cycle in it? [Edit] Analysis of asymptotic complexity for both time and space would be sweet so answers can be compared better. [Edit] Original question was not addressing nodes with outdegree > 1, but there's some talk about it. That question...
Have two pointers iterating through the list; make one iterate through at twice the speed of the other, and compare their positions at each step. Off the top of my head, something like: ``` node* tortoise(begin), * hare(begin); while(hare = hare->next) { if(hare == tortoise) { throw std::logic_error("There's a cyc...
34,312
<p>I was wondering if anyone that has experience in both this stuff can shed some light on the <em>significant</em> difference between the two if any?</p> <p>Any specific strength of each that makes it suitable for any specific case?</p>
[ { "answer_id": 34338, "author": "Erik Öjebo", "author_id": 276, "author_profile": "https://Stackoverflow.com/users/276", "pm_score": 3, "selected": false, "text": "<p>I found SimpleTest was even easier than PHPUnit to set up. Just extract it and you are good to go. A benefit of this is i...
2008/08/29
[ "https://Stackoverflow.com/questions/34312", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2976/" ]
I was wondering if anyone that has experience in both this stuff can shed some light on the *significant* difference between the two if any? Any specific strength of each that makes it suitable for any specific case?
This question is quite dated but as it is still getting traffic and answers I though I state my point here again even so I already did it on some other (newer) questions. I'm ***really really*** baffled that SimpleTest **still** is considered an alternative to phpunit. Maybe i'm just misinformed but as far as I've see...
34,365
<p>Here's a wierd one. I'm reusing a code base that unfortunately must not be updated. This code makes a call to <code>HttpContext.Current.Request.QueryString</code>. Ideally, I need to push a value into this collection with every request that is made. Is this possible - perhaps in an HTTP Module?</p>
[ { "answer_id": 34375, "author": "Espo", "author_id": 2257, "author_profile": "https://Stackoverflow.com/users/2257", "pm_score": 4, "selected": true, "text": "<p>Without using reflection, the simplest way to do it would be to use the RewritePath function on the current HttpContext object...
2008/08/29
[ "https://Stackoverflow.com/questions/34365", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1735/" ]
Here's a wierd one. I'm reusing a code base that unfortunately must not be updated. This code makes a call to `HttpContext.Current.Request.QueryString`. Ideally, I need to push a value into this collection with every request that is made. Is this possible - perhaps in an HTTP Module?
Without using reflection, the simplest way to do it would be to use the RewritePath function on the current HttpContext object in order to modify the querystring. Using an [IHttpModule](http://msdn.microsoft.com/en-us/library/system.web.ihttpmodule.aspx), it might look something like: ``` context.RewritePath(context...
34,390
<p>Since there are no header sections for user controls in asp.net, user controls have no way of knowing about stylesheet files. So css classes in the user controls are not recognized by visual studio and produces warnings. How can I make a user control know that it will relate to a css class, so if it is warning me ab...
[ { "answer_id": 34432, "author": "Rob Cooper", "author_id": 832, "author_profile": "https://Stackoverflow.com/users/832", "pm_score": 0, "selected": false, "text": "<p>If you are creating composite UserControl, then you can set the <a href=\"http://msdn.microsoft.com/en-us/library/system....
2008/08/29
[ "https://Stackoverflow.com/questions/34390", "https://Stackoverflow.com", "https://Stackoverflow.com/users/31505/" ]
Since there are no header sections for user controls in asp.net, user controls have no way of knowing about stylesheet files. So css classes in the user controls are not recognized by visual studio and produces warnings. How can I make a user control know that it will relate to a css class, so if it is warning me about...
Here's what I did: ``` <link rel="Stylesheet" type="text/css" href="Stylesheet.css" id="style" runat="server" visible="false" /> ``` It fools Visual Studio into thinking you've added a stylesheet to the page but it doesn't get rendered. --- Here's an even more concise way to do this with multiple references; ``` ...
34,394
<p>How would you programmacially abbreviate <code>XHTML</code> to an arbitrary number of words without leaving unclosed or corrupted tags?</p> <p>i.e.</p> <pre><code>&lt;p&gt; Proin tristique dapibus neque. Nam eget purus sit amet leo tincidunt accumsan. &lt;/p&gt; &lt;p&gt; Proin semper, orci at mattis b...
[ { "answer_id": 34432, "author": "Rob Cooper", "author_id": 832, "author_profile": "https://Stackoverflow.com/users/832", "pm_score": 0, "selected": false, "text": "<p>If you are creating composite UserControl, then you can set the <a href=\"http://msdn.microsoft.com/en-us/library/system....
2008/08/29
[ "https://Stackoverflow.com/questions/34394", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3187/" ]
How would you programmacially abbreviate `XHTML` to an arbitrary number of words without leaving unclosed or corrupted tags? i.e. ``` <p> Proin tristique dapibus neque. Nam eget purus sit amet leo tincidunt accumsan. </p> <p> Proin semper, orci at mattis blandit, augue justo blandit nulla. <span>Quisq...
Here's what I did: ``` <link rel="Stylesheet" type="text/css" href="Stylesheet.css" id="style" runat="server" visible="false" /> ``` It fools Visual Studio into thinking you've added a stylesheet to the page but it doesn't get rendered. --- Here's an even more concise way to do this with multiple references; ``` ...
34,395
<p>I would like to put a string into a byte array, but the string may be too big to fit. In the case where it's too large, I would like to put as much of the string as possible into the array. Is there an efficient way to find out how many characters will fit?</p>
[ { "answer_id": 34431, "author": "otsdr", "author_id": 321238, "author_profile": "https://Stackoverflow.com/users/321238", "pm_score": 4, "selected": true, "text": "<p>In order to truncate a string to a UTF8 byte array without splitting in the middle of a character I use this:</p>\n\n<pre...
2008/08/29
[ "https://Stackoverflow.com/questions/34395", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2348/" ]
I would like to put a string into a byte array, but the string may be too big to fit. In the case where it's too large, I would like to put as much of the string as possible into the array. Is there an efficient way to find out how many characters will fit?
In order to truncate a string to a UTF8 byte array without splitting in the middle of a character I use this: ``` static string Truncate(string s, int maxLength) { if (Encoding.UTF8.GetByteCount(s) <= maxLength) return s; var cs = s.ToCharArray(); int length = 0; int i = 0; while (i < cs.Le...
34,398
<p>I have a new database table I need to create...<br> It logically contains an <code>ID</code>, a <code>name</code>, and a <code>"value"</code>.<br> That value field could be either numeric or a character string in nature. </p> <p>I don't think I want to just make the field a <code>varchar</code>, because I also wan...
[ { "answer_id": 34402, "author": "Tundey", "author_id": 1453, "author_profile": "https://Stackoverflow.com/users/1453", "pm_score": 0, "selected": false, "text": "<p>If you want to store numeric and string values in the same column, I am not sure you can avoid doing a lot of casts and con...
2008/08/29
[ "https://Stackoverflow.com/questions/34398", "https://Stackoverflow.com", "https://Stackoverflow.com/users/404/" ]
I have a new database table I need to create... It logically contains an `ID`, a `name`, and a `"value"`. That value field could be either numeric or a character string in nature. I don't think I want to just make the field a `varchar`, because I also want to be able to query with filters like `WHERE value > 0....
Your issue with mixing data may be how Sql 2005 sorts text data. It's not a 'natural' sort. If you have a varchar field and you do: ``` where value > '20.5' ``` Values like "5" will be in your result (as in a character based sort "5" comes after "20.5") You're going to be better off with separate columns for stora...
34,401
<p>Is anyone using Elmah to send exceptions via email? I've got Elmah logging set up via SQL Server, and can view the errors page via the Elmah.axd page, but I am unable to get the email component working. The idea here is to get the email notification so we can react more quickly to exceptions. Here is my web.config (...
[ { "answer_id": 34434, "author": "Rob Bazinet", "author_id": 2305, "author_profile": "https://Stackoverflow.com/users/2305", "pm_score": 3, "selected": false, "text": "<p>I have used Elmah myself in this configuration and I had to setup the server with SMTP locally. It is a straight-forw...
2008/08/29
[ "https://Stackoverflow.com/questions/34401", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1284/" ]
Is anyone using Elmah to send exceptions via email? I've got Elmah logging set up via SQL Server, and can view the errors page via the Elmah.axd page, but I am unable to get the email component working. The idea here is to get the email notification so we can react more quickly to exceptions. Here is my web.config (unn...
You need the ErrorMail httpModule. add this line inside the <httpModules> section ``` <add name="ErrorMail" type="Elmah.ErrorMailModule, Elmah" /> ``` If you're using a remote SMTP server (which it looks like you are) you don't need SMTP on the server.
34,411
<p>I always tend to forget these built-in <strong>Symfony</strong> functions for making links.</p>
[ { "answer_id": 34426, "author": "andyuk", "author_id": 2108, "author_profile": "https://Stackoverflow.com/users/2108", "pm_score": 1, "selected": false, "text": "<p>This advice is for symfony 1.0. It probably will work for later versions.</p>\n\n<p><strong>Within your sfAction class</str...
2008/08/29
[ "https://Stackoverflow.com/questions/34411", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2108/" ]
I always tend to forget these built-in **Symfony** functions for making links.
If your goal is to have user-friendly URLs throughout your application, use the following approach: 1) Create a routing rule for your module/action in the application's routing.yml file. The following example is a routing rule for an action that shows the most recent questions in an application, defaulting to page 1 (...
34,439
<p>Given a Python object of any kind, is there an easy way to get the list of all methods that this object has?</p> <p>Or,</p> <p>if this is not possible, is there at least an easy way to check if it has a particular method other than simply checking if an error occurs when the method is called?</p>
[ { "answer_id": 34452, "author": "ljs", "author_id": 3394, "author_profile": "https://Stackoverflow.com/users/3394", "pm_score": 10, "selected": true, "text": "<p><strong>For many objects</strong>, you can use this code, replacing 'object' with the object you're interested in:</p>\n<pre c...
2008/08/29
[ "https://Stackoverflow.com/questions/34439", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3587/" ]
Given a Python object of any kind, is there an easy way to get the list of all methods that this object has? Or, if this is not possible, is there at least an easy way to check if it has a particular method other than simply checking if an error occurs when the method is called?
**For many objects**, you can use this code, replacing 'object' with the object you're interested in: ```py object_methods = [method_name for method_name in dir(object) if callable(getattr(object, method_name))] ``` I discovered it at [diveintopython.net](https://web.archive.org/web/20180901124519/...
34,486
<p>I have a small JS function that does Ajax for me and another like it that adds in POST data to the request. With Ajax being such a big topic with so many libraries about it, what am I missing from my function, is it insecure or something else worrying?</p> <pre><code>function loadPage(pagePath, displayElement) { ...
[ { "answer_id": 34538, "author": "MattGrommes", "author_id": 3098, "author_profile": "https://Stackoverflow.com/users/3098", "pm_score": 5, "selected": true, "text": "<p>I strongly recommend you not roll your own Ajax code. Instead, use a framework such as Prototype, Dojo, or any of the o...
2008/08/29
[ "https://Stackoverflow.com/questions/34486", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1384652/" ]
I have a small JS function that does Ajax for me and another like it that adds in POST data to the request. With Ajax being such a big topic with so many libraries about it, what am I missing from my function, is it insecure or something else worrying? ``` function loadPage(pagePath, displayElement) { var xmlHttp;...
I strongly recommend you not roll your own Ajax code. Instead, use a framework such as Prototype, Dojo, or any of the others. They've taken care of handling all the ReadyStates you're not handling (2 means it's been sent, 3 means it's in process, etc.), and they should escape the reponse you're getting so you don't ins...
34,488
<p>Will limiting a query to one result record, improve performance in a large(ish) MySQL table if the table only has one matching result?</p> <p>for example</p> <pre><code> select * from people where name = "Re0sless" limit 1 </code></pre> <p>if there is only one record with that name? and what about if <code>name</...
[ { "answer_id": 34499, "author": "Owen Fraser-Green", "author_id": 3382, "author_profile": "https://Stackoverflow.com/users/3382", "pm_score": 0, "selected": false, "text": "<p>I believe the LIMIT is something done after the data set is found and the result set is being built up so I woul...
2008/08/29
[ "https://Stackoverflow.com/questions/34488", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2098/" ]
Will limiting a query to one result record, improve performance in a large(ish) MySQL table if the table only has one matching result? for example ``` select * from people where name = "Re0sless" limit 1 ``` if there is only one record with that name? and what about if `name` was the primary key/ set to unique? an...
If the column has **a unique index: no,** it's no faster **a non-unique index: maybe,** because it will prevent sending any additional rows beyond the first matched, if any exist **no index: sometimes** * if 1 or more rows match the query, **yes**, because the full table scan will be halted after the first row is ...
34,490
<p><a href="http://en.wikipedia.org/wiki/SHA-1" rel="noreferrer">SHA Hash functions</a></p>
[ { "answer_id": 34514, "author": "devstopfix", "author_id": 3366, "author_profile": "https://Stackoverflow.com/users/3366", "pm_score": 10, "selected": true, "text": "<pre><code>require 'digest/sha1'\nDigest::SHA1.hexdigest 'foo'\n</code></pre>\n" }, { "answer_id": 5269105, "a...
2008/08/29
[ "https://Stackoverflow.com/questions/34490", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3624/" ]
[SHA Hash functions](http://en.wikipedia.org/wiki/SHA-1)
``` require 'digest/sha1' Digest::SHA1.hexdigest 'foo' ```
34,493
<p>We have a few very large Excel workbooks (dozens of tabs, over a MB each, very complex calculations) with many dozens, perhaps hundreds of formulas that use the dreaded INDIRECT function. These formulas are spread out throughout the workbook, and target several tables of data to look-up for values.</p> <p>Now I nee...
[ { "answer_id": 34719, "author": "sdfx", "author_id": 3445, "author_profile": "https://Stackoverflow.com/users/3445", "pm_score": 4, "selected": true, "text": "<p>You could iterate over the entire Workbook using vba (i've included the code from @PabloG and @euro-micelli ):</p>\n\n<pre><co...
2008/08/29
[ "https://Stackoverflow.com/questions/34493", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2230/" ]
We have a few very large Excel workbooks (dozens of tabs, over a MB each, very complex calculations) with many dozens, perhaps hundreds of formulas that use the dreaded INDIRECT function. These formulas are spread out throughout the workbook, and target several tables of data to look-up for values. Now I need to move ...
You could iterate over the entire Workbook using vba (i've included the code from @PabloG and @euro-micelli ): ``` Sub iterateOverWorkbook() For Each i In ThisWorkbook.Worksheets Set rRng = i.UsedRange For Each j In rRng If (Not IsEmpty(j)) Then If (j.HasFormula) Then If InS...
34,505
<p>The MSDN documentation on <a href="http://msdn.microsoft.com/en-us/library/system.object.gethashcode.aspx" rel="noreferrer">Object.GetHashCode()</a> describes 3 contradicting rules for how the method should work. </p> <ol> <li>If two objects of the same type represent the same value, the hash function must return ...
[ { "answer_id": 34511, "author": "Darren Kopp", "author_id": 77, "author_profile": "https://Stackoverflow.com/users/77", "pm_score": 0, "selected": false, "text": "<p>By default it does it based on the reference to the object, but that means that it's the exact same object, so both would ...
2008/08/29
[ "https://Stackoverflow.com/questions/34505", "https://Stackoverflow.com", "https://Stackoverflow.com/users/392/" ]
The MSDN documentation on [Object.GetHashCode()](http://msdn.microsoft.com/en-us/library/system.object.gethashcode.aspx) describes 3 contradicting rules for how the method should work. 1. If two objects of the same type represent the same value, the hash function must return the same constant value for either object....
> > Rules 1 & 3 are contradictory to me. > > > To a certain extent, they are. The reason is simple: if an object is stored in a hash table and, by changing its value, you change its hash then the hash table has lost the value and you can't find it again by querying the hash table. It is important that while object...
34,506
<p>Is there anyway to have a sort of virtual static member in C++?</p> <p>For example:</p> <pre><code>class BaseClass { public: BaseClass(const string&amp; name) : _name(name) {} string GetName() const { return _name; } virtual void UseClass() = 0; private: const string _name; ...
[ { "answer_id": 34591, "author": "Hershi", "author_id": 1596, "author_profile": "https://Stackoverflow.com/users/1596", "pm_score": 2, "selected": false, "text": "<p>It seems like the answer is in the question - the method you suggested seems to be the right direction to go, except that i...
2008/08/29
[ "https://Stackoverflow.com/questions/34506", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3373/" ]
Is there anyway to have a sort of virtual static member in C++? For example: ``` class BaseClass { public: BaseClass(const string& name) : _name(name) {} string GetName() const { return _name; } virtual void UseClass() = 0; private: const string _name; }; class DerivedClass : ...
Here is one solution: ``` struct BaseData { const string my_word; const int my_number; }; class Base { public: Base(const BaseData* apBaseData) { mpBaseData = apBaseData; } const string getMyWord() { return mpBaseData->my_word; } int getMyNumber() { return ...
34,509
<p>We have a large database on which we have DB side pagination. This is quick, returning a page of 50 rows from millions of records in a small fraction of a second.</p> <p>Users can define their own sort, basically choosing what column to sort by. Columns are dynamic - some have numeric values, some dates and some t...
[ { "answer_id": 35382, "author": "Grzegorz Gierlik", "author_id": 1483, "author_profile": "https://Stackoverflow.com/users/1483", "pm_score": -1, "selected": false, "text": "<p>I still don't understand (probably because of my poor English).</p>\n\n<p>You could try:</p>\n\n<pre><code>ROW_N...
2008/08/29
[ "https://Stackoverflow.com/questions/34509", "https://Stackoverflow.com", "https://Stackoverflow.com/users/905/" ]
We have a large database on which we have DB side pagination. This is quick, returning a page of 50 rows from millions of records in a small fraction of a second. Users can define their own sort, basically choosing what column to sort by. Columns are dynamic - some have numeric values, some dates and some text. While...
Most of the SQL-based solutions I have seen break when the data gets complex enough (e.g. more than one or two numbers in it). Initially I tried implementing a NaturalSort function in T-SQL that met my requirements (among other things, handles an arbitrary number of numbers within the string), but the performance was *...
34,510
<p>When writing multithreaded applications, one of the most common problems experienced is race conditions.</p> <p>My questions to the community are:</p> <ul> <li>What is the race condition?</li> <li>How do you detect them?</li> <li>How do you handle them?</li> <li>Finally, how do you prevent them from occurring?</li> ...
[ { "answer_id": 34537, "author": "Steve Gury", "author_id": 1578, "author_profile": "https://Stackoverflow.com/users/1578", "pm_score": 5, "selected": false, "text": "<p>A race condition is a kind of bug, that happens only with certain temporal conditions.</p>\n\n<p>Example:\nImagine you ...
2008/08/29
[ "https://Stackoverflow.com/questions/34510", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1931/" ]
When writing multithreaded applications, one of the most common problems experienced is race conditions. My questions to the community are: * What is the race condition? * How do you detect them? * How do you handle them? * Finally, how do you prevent them from occurring?
A race condition occurs when two or more threads can access shared data and they try to change it at the same time. Because the thread scheduling algorithm can swap between threads at any time, you don't know the order in which the threads will attempt to access the shared data. Therefore, the result of the change in d...
34,516
<p>Is there a standard convention (like phpdoc or python's docstring) for commenting C# code so that class documentation can be automatically generated from the source code?</p>
[ { "answer_id": 34530, "author": "jason saldo", "author_id": 1293, "author_profile": "https://Stackoverflow.com/users/1293", "pm_score": 2, "selected": false, "text": "<pre><code>/// &lt;summary&gt;\n///\n/// &lt;/summary&gt;\n/// &lt;param name=\"strFilePath\"&gt;&lt;/param&gt;\n</code><...
2008/08/29
[ "https://Stackoverflow.com/questions/34516", "https://Stackoverflow.com", "https://Stackoverflow.com/users/305/" ]
Is there a standard convention (like phpdoc or python's docstring) for commenting C# code so that class documentation can be automatically generated from the source code?
You can use XML style comments, and use tools to pull those comments out into API documentation. Here is an example of the comment style: ``` /// <summary> /// Authenticates a user based on a username and password. /// </summary> /// <param name="username">The username.</param> /// <param name="password">The password...
34,518
<p>How do you sort an array of strings <a href="http://blog.codinghorror.com/sorting-for-humans-natural-sort-order/" rel="nofollow noreferrer">naturally</a> in different programming languages? Post your implementation and what language it is in in the answer.</p>
[ { "answer_id": 34528, "author": "Marius", "author_id": 1585, "author_profile": "https://Stackoverflow.com/users/1585", "pm_score": 3, "selected": false, "text": "<p><strong>JavaScript</strong></p>\n\n<pre><code>Array.prototype.alphanumSort = function(caseInsensitive) {\n for (var z = 0,...
2008/08/29
[ "https://Stackoverflow.com/questions/34518", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1585/" ]
How do you sort an array of strings [naturally](http://blog.codinghorror.com/sorting-for-humans-natural-sort-order/) in different programming languages? Post your implementation and what language it is in in the answer.
**JavaScript** ``` Array.prototype.alphanumSort = function(caseInsensitive) { for (var z = 0, t; t = this[z]; z++) { this[z] = [], x = 0, y = -1, n = 0, i, j; while (i = (j = t.charAt(x++)).charCodeAt(0)) { var m = (i == 46 || (i >=48 && i <= 57)); if (m !== n) { this[z][++y] = ""; ...
34,519
<p>A semaphore is a programming concept that is frequently used to solve multi-threading problems. My question to the community: </p> <p>What is a semaphore and how do you use it?</p>
[ { "answer_id": 34529, "author": "Craig H", "author_id": 2328, "author_profile": "https://Stackoverflow.com/users/2328", "pm_score": -1, "selected": false, "text": "<p>A semaphore is a way to lock a resource so that it is guaranteed that while a piece of code is executed, only this piece ...
2008/08/29
[ "https://Stackoverflow.com/questions/34519", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1931/" ]
A semaphore is a programming concept that is frequently used to solve multi-threading problems. My question to the community: What is a semaphore and how do you use it?
Think of semaphores as bouncers at a nightclub. There are a dedicated number of people that are allowed in the club at once. If the club is full no one is allowed to enter, but as soon as one person leaves another person might enter. It's simply a way to limit the number of consumers for a specific resource. For examp...
34,536
<p>This most be the second most simple rollover effect, still I don't find any simple solution.</p> <p><strong>Wanted:</strong> I have a list of items and a corresponding list of slides (DIVs). After loading, the first list item should be selected (bold) and the first slide should be visible. When the user hovers over...
[ { "answer_id": 34564, "author": "Konrad Rudolph", "author_id": 1968, "author_profile": "https://Stackoverflow.com/users/1968", "pm_score": 0, "selected": false, "text": "<p>The only thing that's wrong with this code (at least to me) is that you're not using a loop to process all elements...
2008/08/29
[ "https://Stackoverflow.com/questions/34536", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3377/" ]
This most be the second most simple rollover effect, still I don't find any simple solution. **Wanted:** I have a list of items and a corresponding list of slides (DIVs). After loading, the first list item should be selected (bold) and the first slide should be visible. When the user hovers over another list item, tha...
Rather than displaying all slides when JS is off (which would likely break the page layout) I would place inside the switch LIs real A links to server-side code which returns the page with the "active" class pre-set on the proper switch/slide. ```js $(document).ready(function() { switches = $('#switches > li'); ...
34,565
<p>Additionally, how can I format it as a string padded with zeros?</p>
[ { "answer_id": 34582, "author": "quackingduck", "author_id": 3624, "author_profile": "https://Stackoverflow.com/users/3624", "pm_score": 7, "selected": false, "text": "<p>To generate the number call rand with the result of the expression \"10 to the power of 10\"</p>\n\n<pre><code>rand(1...
2008/08/29
[ "https://Stackoverflow.com/questions/34565", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3624/" ]
Additionally, how can I format it as a string padded with zeros?
To generate the number call rand with the result of the expression "10 to the power of 10" ``` rand(10 ** 10) ``` To pad the number with zeros you can use the string format operator ``` '%010d' % rand(10 ** 10) ``` or the `rjust` method of string ``` rand(10 ** 10).to_s.rjust(10,'0') ```
34,571
<p>How do I use JUnit to test a class that has internal private methods, fields or nested classes?</p> <p>It seems bad to change the access modifier for a method just to be able to run a test.</p>
[ { "answer_id": 34586, "author": "Sir Rippov the Maple", "author_id": 2822, "author_profile": "https://Stackoverflow.com/users/2822", "pm_score": 10, "selected": false, "text": "<p>The best way to test a private method is via another public method. If this cannot be done, then one of the ...
2008/08/29
[ "https://Stackoverflow.com/questions/34571", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3098/" ]
How do I use JUnit to test a class that has internal private methods, fields or nested classes? It seems bad to change the access modifier for a method just to be able to run a test.
If you have somewhat of a legacy **Java** application, and you're not allowed to change the visibility of your methods, the best way to test private methods is to use [reflection](http://en.wikipedia.org/wiki/Reflection_%28computer_programming%29). Internally we're using helpers to get/set `private` and `private stati...
34,579
<p>I've recently been working with a MySQL database, and using MySQL workbench to design the Database.</p> <p>When I use the export to SQL function, so I can actually get the layout in to the Database, I get:</p> <blockquote> <p>"Error 1005: Cannot create table"</p> </blockquote> <p>This appears to be related to F...
[ { "answer_id": 34642, "author": "joev", "author_id": 3449, "author_profile": "https://Stackoverflow.com/users/3449", "pm_score": 1, "selected": false, "text": "<p>I ran into this situation recently when I attempted (in InnoDB tables) to make a foreign key reference to a column that had a...
2008/08/29
[ "https://Stackoverflow.com/questions/34579", "https://Stackoverflow.com", "https://Stackoverflow.com/users/655/" ]
I've recently been working with a MySQL database, and using MySQL workbench to design the Database. When I use the export to SQL function, so I can actually get the layout in to the Database, I get: > > "Error 1005: Cannot create table" > > > This appears to be related to Foreign Keys in the create table stateme...
When you get this (and other errors out of the InnoDB engine) issue: ``` SHOW ENGINE INNODB STATUS; ``` It will give a more detailed reason why the operation couldn't be completed. Make sure to run that from something that'll allow you to scroll or copy the data, as the response is quite long.
34,581
<p>I expected the two <code>span</code> tags in the following sample to display next to each other, instead they display one below the other. If I set the <code>width</code> of the class <code>span</code>.right to 49% they display next to each other. I am not able to figure out why the right span is pushed down like th...
[ { "answer_id": 34587, "author": "Teifion", "author_id": 1384652, "author_profile": "https://Stackoverflow.com/users/1384652", "pm_score": 3, "selected": true, "text": "<pre><code>float: left;\n</code></pre>\n\n<p>Try adding that to span.left</p>\n\n<p>It will cause it to float to the lef...
2008/08/29
[ "https://Stackoverflow.com/questions/34581", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3635/" ]
I expected the two `span` tags in the following sample to display next to each other, instead they display one below the other. If I set the `width` of the class `span`.right to 49% they display next to each other. I am not able to figure out why the right span is pushed down like the right span has some invisible `pad...
``` float: left; ``` Try adding that to span.left It will cause it to float to the left (as suggested by the syntax). --- I am not a CSS expert by any means so please don't take this as unarguable fact but I find that when something is floated, it makes no difference to the vertical position of things below it. I...
34,588
<p>When running my application I sometimes get an error about <code>too many files open</code>.</p> <p>Running <code>ulimit -a</code> reports that the limit is 1024. How do I increase the limit above 1024? </p> <p><strong>Edit</strong> <code>ulimit -n 2048</code> results in a permission error.</p>
[ { "answer_id": 34645, "author": "hoyhoy", "author_id": 3499, "author_profile": "https://Stackoverflow.com/users/3499", "pm_score": 8, "selected": true, "text": "<p>You could always try doing a <code>ulimit -n 2048</code>. This will only reset the limit for your current shell and the num...
2008/08/29
[ "https://Stackoverflow.com/questions/34588", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3535/" ]
When running my application I sometimes get an error about `too many files open`. Running `ulimit -a` reports that the limit is 1024. How do I increase the limit above 1024? **Edit** `ulimit -n 2048` results in a permission error.
You could always try doing a `ulimit -n 2048`. This will only reset the limit for your current shell and the number you specify must not exceed the hard limit Each operating system has a different hard limit setup in a configuration file. For instance, the hard open file limit on Solaris can be set on boot from /etc/s...
34,595
<p>What is a good Hash function? I saw a lot of hash function and applications in my data structures courses in college, but I mostly got that it's pretty hard to make a good hash function. As a rule of thumb to avoid collisions my professor said that:</p> <pre><code>function Hash(key) return key mod PrimeNumber end...
[ { "answer_id": 34606, "author": "Einar", "author_id": 2964, "author_profile": "https://Stackoverflow.com/users/2964", "pm_score": 2, "selected": false, "text": "<p>I'd say that the main rule of thumb is not to roll your own. Try to use something that has been thoroughly tested, e.g., SHA...
2008/08/29
[ "https://Stackoverflow.com/questions/34595", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3485/" ]
What is a good Hash function? I saw a lot of hash function and applications in my data structures courses in college, but I mostly got that it's pretty hard to make a good hash function. As a rule of thumb to avoid collisions my professor said that: ``` function Hash(key) return key mod PrimeNumber end ``` (mod is...
For doing "normal" hash table lookups on basically any kind of data - this one by Paul Hsieh is the best I've ever used. <http://www.azillionmonkeys.com/qed/hash.html> If you care about cryptographically secure or anything else more advanced, then YMMV. If you just want a kick ass general purpose hash function for a ...
34,623
<p>Why would you do an automatic HTML post rather than a simple redirect?</p> <p>Is this so developers can automatically generate a login form that posts directory to the remote server when the OpenID is known?</p> <p>eg.</p> <ol> <li>User is not logged in and visits your login page.</li> <li>You detect the user's o...
[ { "answer_id": 35960, "author": "Mark Brackett", "author_id": 2199, "author_profile": "https://Stackoverflow.com/users/2199", "pm_score": 3, "selected": false, "text": "<p>I can think of a couple of reasons:</p>\n\n<ul>\n<li>A modicum of security by obscurity - it's slightly more work to...
2008/08/29
[ "https://Stackoverflow.com/questions/34623", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2108/" ]
Why would you do an automatic HTML post rather than a simple redirect? Is this so developers can automatically generate a login form that posts directory to the remote server when the OpenID is known? eg. 1. User is not logged in and visits your login page. 2. You detect the user's openID from a cookie. 3. Form is g...
The primary motivation was, as Mark Brackett says, the limits on payload size imposed by using redirects and GET. Some implementations are smart enough to only use POST when the message goes over a certain size, as there are certainly disadvantages to the POST technique. (Chief among them being the fact that your Back ...
34,655
<p>I would like to have an <code>iframe</code> take as much vertical space as it needs to display its content and not display a scrollbar. Is it at all possible ?</p> <p>Are there any workarounds?</p>
[ { "answer_id": 34663, "author": "Daniel Jennings", "author_id": 3641, "author_profile": "https://Stackoverflow.com/users/3641", "pm_score": 0, "selected": false, "text": "<p>This CSS snippet should remove the vertical scrollbar:</p>\n\n<pre class=\"lang-css prettyprint-override\"><code>b...
2008/08/29
[ "https://Stackoverflow.com/questions/34655", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1983/" ]
I would like to have an `iframe` take as much vertical space as it needs to display its content and not display a scrollbar. Is it at all possible ? Are there any workarounds?
This should set the `IFRAME` height to its content's height: ``` <script type="text/javascript"> the_height = document.getElementById('the_iframe').contentWindow.document.body.scrollHeight; document.getElementById('the_iframe').height = the_height; </script> ``` You may want to add `scrolling="no"` to your `IFRAME` ...
34,664
<p>Has anyone found a useful solution to the DesignMode problem when developing controls?</p> <p>The issue is that if you nest controls then DesignMode only works for the first level. The second and lower levels DesignMode will always return FALSE.</p> <p>The standard hack has been to look at the name of the process...
[ { "answer_id": 34696, "author": "Will Dean", "author_id": 987, "author_profile": "https://Stackoverflow.com/users/987", "pm_score": 2, "selected": false, "text": "<p>I've never been caught by this myself, but couldn't you just walk back up the Parent chain from the control to see if Desi...
2008/08/29
[ "https://Stackoverflow.com/questions/34664", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2862/" ]
Has anyone found a useful solution to the DesignMode problem when developing controls? The issue is that if you nest controls then DesignMode only works for the first level. The second and lower levels DesignMode will always return FALSE. The standard hack has been to look at the name of the process that is running a...
Revisiting this question, I have now 'discovered' 5 different ways of doing this, which are as follows: ``` System.ComponentModel.DesignMode property System.ComponentModel.LicenseManager.UsageMode property private string ServiceString() { if (GetService(typeof(System.ComponentModel.Design.IDesignerHost)) != null...
34,674
<p>You can use a standard dot notation or a method call in Objective-C to access a property of an object in Objective-C.</p> <pre><code>myObject.property = YES; </code></pre> <p>or</p> <pre><code>[myObject setProperty:YES]; </code></pre> <p>Is there a difference in performance (in terms of accessing the property)? ...
[ { "answer_id": 34688, "author": "Daniel Jennings", "author_id": 3641, "author_profile": "https://Stackoverflow.com/users/3641", "pm_score": 0, "selected": false, "text": "<p>As far as I've seen, there isn't a significant performance difference between the two. I'm reasonably certain that...
2008/08/29
[ "https://Stackoverflow.com/questions/34674", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1987/" ]
You can use a standard dot notation or a method call in Objective-C to access a property of an object in Objective-C. ``` myObject.property = YES; ``` or ``` [myObject setProperty:YES]; ``` Is there a difference in performance (in terms of accessing the property)? Is it just a matter of preference in terms of cod...
Dot notation for property access in Objective-C **is** a message send, just as bracket notation. That is, given this: ``` @interface Foo : NSObject @property BOOL bar; @end Foo *foo = [[Foo alloc] init]; foo.bar = YES; [foo setBar:YES]; ``` The last two lines will compile exactly the same. The only thing that chang...
34,687
<p>When I try to do any svn command and supply the <code>--username</code> and/or <code>--password</code> options, it prompts me for my password anyways, and always will attempt to use my current user instead of the one specified by <code>--username</code>. Neither <code>--no-auth-cache</code> nor <code>--non-interacti...
[ { "answer_id": 34755, "author": "Tom Mayfield", "author_id": 2314, "author_profile": "https://Stackoverflow.com/users/2314", "pm_score": 0, "selected": false, "text": "<p>Best I can give you is a \"works for me\" on SVN 1.5. You may try adding <code>--no-auth-cache</code> to your <code>...
2008/08/29
[ "https://Stackoverflow.com/questions/34687", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3625/" ]
When I try to do any svn command and supply the `--username` and/or `--password` options, it prompts me for my password anyways, and always will attempt to use my current user instead of the one specified by `--username`. Neither `--no-auth-cache` nor `--non-interactive` have any effect on this. This is a problem becau...
The prompt you're getting doesn't look like Subversion asking you for a password, it looks like ssh asking for a password. So my guess is that you have checked out an svn+ssh:// checkout, not an svn:// or http:// or https:// checkout. IIRC all the options you're trying only work for the svn/http/https checkouts. Can y...
34,708
<p>A few months back I was tasked with implementing a unique and random code for our web application. The code would have to be user friendly and as small as possible, but still be essentially random (so users couldn't easily predict the next code in the sequence).</p> <p>It ended up generating values that looked som...
[ { "answer_id": 34722, "author": "Anthony Mastrean", "author_id": 3619, "author_profile": "https://Stackoverflow.com/users/3619", "pm_score": 2, "selected": false, "text": "<p>In C#, I have used the '<a href=\"http://msdn.microsoft.com/en-us/library/system.io.path.getrandomfilename.aspx\"...
2008/08/29
[ "https://Stackoverflow.com/questions/34708", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1931/" ]
A few months back I was tasked with implementing a unique and random code for our web application. The code would have to be user friendly and as small as possible, but still be essentially random (so users couldn't easily predict the next code in the sequence). It ended up generating values that looked something like...
In .NET you can use the RNGCryptoServiceProvider method GetBytes() which will "fill an array of bytes with a cryptographically strong sequence of random values" (from ms documentation). ``` byte[] randomBytes = new byte[4]; RNGCryptoServiceProvider rng = new RNGCryptoServiceProvider(); rng.GetBytes(randomBytes); ``` ...
34,712
<p>I have some UI in VB 2005 that looks great in XP Style, but goes hideous in Classic Style.</p> <p>Any ideas about how to detect which mode the user is in and re-format the forms on the fly?</p> <hr> <p>Post Answer Edit:</p> <p>Thanks Daniel, looks like this will work. I'm using the first solution you posted with...
[ { "answer_id": 34724, "author": "Konrad Rudolph", "author_id": 1968, "author_profile": "https://Stackoverflow.com/users/1968", "pm_score": 0, "selected": false, "text": "<p>There's the <a href=\"http://msdn.microsoft.com/en-us/library/bb759813%28VS.85%29.aspx\" rel=\"nofollow noreferrer\...
2008/08/29
[ "https://Stackoverflow.com/questions/34712", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3648/" ]
I have some UI in VB 2005 that looks great in XP Style, but goes hideous in Classic Style. Any ideas about how to detect which mode the user is in and re-format the forms on the fly? --- Post Answer Edit: Thanks Daniel, looks like this will work. I'm using the first solution you posted with the GetCurrentThemeName(...
Try using a combination of [GetCurrentThemeName](http://www.pinvoke.net/default.aspx/uxtheme/GetCurrentThemeName.html) ([MSDN Page](http://msdn.microsoft.com/en-us/library/bb773365%28VS.85%29.aspx)) and [DwmIsCompositionEnabled](http://msdn.microsoft.com/en-us/library/aa969518%28VS.85%29.aspx) I linked the first to PI...
34,732
<p>How do I list the symbols being exported from a .so file? If possible, I'd also like to know their source (e.g. if they are pulled in from a static library).</p> <p>I'm using gcc 4.0.2, if that makes a difference.</p>
[ { "answer_id": 34758, "author": "Konrad Rudolph", "author_id": 1968, "author_profile": "https://Stackoverflow.com/users/1968", "pm_score": 4, "selected": false, "text": "<p>You can use the <code>nm -g</code> tool from the binutils toolchain. However, their source is not always readily av...
2008/08/29
[ "https://Stackoverflow.com/questions/34732", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3051/" ]
How do I list the symbols being exported from a .so file? If possible, I'd also like to know their source (e.g. if they are pulled in from a static library). I'm using gcc 4.0.2, if that makes a difference.
The standard tool for listing symbols is `nm`, you can use it simply like this: ``` nm -gD yourLib.so ``` If you want to see symbols of a C++ library, add the "-C" option which demangle the symbols (it's far more readable demangled). ``` nm -gDC yourLib.so ``` If your .so file is in elf format, you have two optio...
34,768
<p>I have recently installed .net 3.5 SP1. When I deployed a compiled web site that contained a form with its action set:</p> <pre><code>&lt;form id="theForm" runat="server" action="post.aspx"&gt; </code></pre> <p>I received this error.<br> Method not found: 'Void System.Web.UI.HtmlControls.HtmlForm.set_Action(Syste...
[ { "answer_id": 34776, "author": "Daniel Jennings", "author_id": 3641, "author_profile": "https://Stackoverflow.com/users/3641", "pm_score": 1, "selected": false, "text": "<p>I don't know the specific solution, but HtmlForm.set_Action() is a function the compiler creates that acts as the ...
2008/08/29
[ "https://Stackoverflow.com/questions/34768", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2903/" ]
I have recently installed .net 3.5 SP1. When I deployed a compiled web site that contained a form with its action set: ``` <form id="theForm" runat="server" action="post.aspx"> ``` I received this error. Method not found: 'Void System.Web.UI.HtmlControls.HtmlForm.set\_Action(System.String)'. If a fellow develo...
[.NET 3.5 SP1 tries to use the action="" attribute](http://johnsheehan.me/blog/less-code-is-fun-aspnet-35-sp1-removes-need-for-control-adapter-when-using-url-rewriting/) (.NET 3.5 RTM did not). So, when you deploy, your code is attempting to set the HtmlForm.Action property and failing, as the System.Web.dll on the dep...
34,784
<p>What is a good setup for .hgignore file when working with Visual Studio 2008?</p> <p>I mostly develop on my own, only occasionly I clone the repository for somebody else to work on it.</p> <p>I'm thinking about obj folders, .suo, .sln, .user files etc.. Can they just be included or are there file I shouldn't inclu...
[ { "answer_id": 34805, "author": "Daniel Jennings", "author_id": 3641, "author_profile": "https://Stackoverflow.com/users/3641", "pm_score": 5, "selected": false, "text": "<p>This is specific to a C# project, but I ignore these files/directories:</p>\n\n<blockquote>\n <ul>\n <li><code>*...
2008/08/29
[ "https://Stackoverflow.com/questions/34784", "https://Stackoverflow.com", "https://Stackoverflow.com/users/925/" ]
What is a good setup for .hgignore file when working with Visual Studio 2008? I mostly develop on my own, only occasionly I clone the repository for somebody else to work on it. I'm thinking about obj folders, .suo, .sln, .user files etc.. Can they just be included or are there file I shouldn't include? Thanks! p.s...
Here's my standard .hgignore file for use with VS2008 that was originally modified from a Git ignore file: ``` # Ignore file for Visual Studio 2008 # use glob syntax syntax: glob # Ignore Visual Studio 2008 files *.obj *.exe *.pdb *.user *.aps *.pch *.vspscc *_i.c *_p.c *.ncb *.suo *.tlb *.tlh *.bak *.cache *.ilk *....
34,790
<p>The <code>datepicker</code> function only works on the first input box that is created.</p> <p>I'm trying to duplicate a datepicker by cloning the <code>div</code> that is containing it.</p> <pre><code>&lt;a href="#" id="dupMe"&gt;click&lt;/a&gt; &lt;div id="template"&gt; input-text &lt;input type="text" value="...
[ { "answer_id": 34807, "author": "Dave Ward", "author_id": 60, "author_profile": "https://Stackoverflow.com/users/60", "pm_score": 4, "selected": false, "text": "<p>I use a CSS class instead:</p>\n\n<pre><code>&lt;input type=\"text\" id=\"BeginDate\" class=\"calendar\" /&gt;\n&lt;input ty...
2008/08/29
[ "https://Stackoverflow.com/questions/34790", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1842864/" ]
The `datepicker` function only works on the first input box that is created. I'm trying to duplicate a datepicker by cloning the `div` that is containing it. ``` <a href="#" id="dupMe">click</a> <div id="template"> input-text <input type="text" value="text1" id="txt" /> date time picker <input type="text" id="exa...
I'd recommend just using a common class name as well. However, if you're against this for some reason, you could also write a function to create date pickers for all text boxes in your template `div` (to be called after each duplication). Something like: ``` function makeDatePickers() { $("#template input[type=text]...
34,798
<p>I have a gridview that is within an updatepanel for a modal popup I have on a page.<br> The issue is that the entire page refreshes every time I click an imagebutton that is within my gridview. This causes my entire page to load and since I have grayed out the rest of the page so that the user cannot click on it thi...
[ { "answer_id": 34875, "author": "Ben Scheirman", "author_id": 3381, "author_profile": "https://Stackoverflow.com/users/3381", "pm_score": 2, "selected": false, "text": "<p>do you have ChildrenAsTriggers=\"false\" on the UpdatePanel?</p>\n\n<p>Are there any javascript errors on the page?<...
2008/08/29
[ "https://Stackoverflow.com/questions/34798", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2486/" ]
I have a gridview that is within an updatepanel for a modal popup I have on a page. The issue is that the entire page refreshes every time I click an imagebutton that is within my gridview. This causes my entire page to load and since I have grayed out the rest of the page so that the user cannot click on it this is...
Several months later this problem was fixed. The project I was working in was a previous v1.1 which was converted with 2.0. However, in the web.config this line remained: ``` <xhtmlConformance mode="Legacy"/> ``` When it was commented out all of the bugs that we seemed to have with the ajax control toolkit disappear...
34,802
<p>I'm trying to write a custom WPF ValidationRule to enforce that a certain property is unique within the context of a given collection. For example: I am editing a collection of custom objects bound to a ListView and I need to ensure that the Name property of each object in the collection is unique. Does anyone know ...
[ { "answer_id": 34885, "author": "Daniel Jennings", "author_id": 3641, "author_profile": "https://Stackoverflow.com/users/3641", "pm_score": 3, "selected": true, "text": "<p>First, I'd create a simple DependencyObject class to hold your collection: </p>\n\n<pre><code>class YourCollectionT...
2008/08/29
[ "https://Stackoverflow.com/questions/34802", "https://Stackoverflow.com", "https://Stackoverflow.com/users/317/" ]
I'm trying to write a custom WPF ValidationRule to enforce that a certain property is unique within the context of a given collection. For example: I am editing a collection of custom objects bound to a ListView and I need to ensure that the Name property of each object in the collection is unique. Does anyone know how...
First, I'd create a simple DependencyObject class to hold your collection: ``` class YourCollectionType : DependencyObject { [PROPERTY DEPENDENCY OF ObservableCollection<YourType> NAMED: BoundList] } ``` Then, on your ValidationRule-derived class, create a property: ``` YourCollectionType ListToCheck { get; ...
34,806
<p>I have a little dilemma that maybe you can help me sort out. </p> <p>I've been working today in modifying ASP.NET's Membership to add a level of indirection. Basically, ASP.NET's Membership supports Users and Roles, leaving all authorization rules to be based on whether a user belongs to a Role or not. </p> <p>Wha...
[ { "answer_id": 34832, "author": "James A. Rosen", "author_id": 1190, "author_profile": "https://Stackoverflow.com/users/1190", "pm_score": 2, "selected": true, "text": "<p>I feel the best combination of DRYness and forcing the contract is as follows (in pseudocode):</p>\n\n<pre><code>cla...
2008/08/29
[ "https://Stackoverflow.com/questions/34806", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1782/" ]
I have a little dilemma that maybe you can help me sort out. I've been working today in modifying ASP.NET's Membership to add a level of indirection. Basically, ASP.NET's Membership supports Users and Roles, leaving all authorization rules to be based on whether a user belongs to a Role or not. What I need to do is...
I feel the best combination of DRYness and forcing the contract is as follows (in pseudocode): ``` class Base { public final constructor(name) { constructor(name, null) end public abstract constructor(name, description); } ``` or, alternatively: ``` class Base { public abstract constructor(name); pu...
34,848
<p>When using a <code>Zend_Form</code>, the only way to validate that an input is not left blank is to do</p> <pre><code>$element-&gt;setRequired(true); </code></pre> <p>If this is not set and the element is blank, it appears to me that validation is not run on the element.</p> <p>If I do use <code>setRequired()</co...
[ { "answer_id": 34862, "author": "mk.", "author_id": 1797, "author_profile": "https://Stackoverflow.com/users/1797", "pm_score": 1, "selected": false, "text": "<p>Change the <a href=\"http://framework.zend.com/manual/en/zend.form.forms.html#zend.form.forms.validation.errors\" rel=\"nofoll...
2008/08/29
[ "https://Stackoverflow.com/questions/34848", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1349865/" ]
When using a `Zend_Form`, the only way to validate that an input is not left blank is to do ``` $element->setRequired(true); ``` If this is not set and the element is blank, it appears to me that validation is not run on the element. If I do use `setRequired()`, the element is automatically given the standard NotEm...
I did it this way (ZF 1.5): ``` $name = new Zend_Form_Element_Text('name'); $name->setLabel('Full Name: ') ->setRequired(true) ->addFilter('StripTags') ->addFilter('StringTrim') ->addValidator($MyNotEmpty); ``` so, the addValidator() is the interesting part. The Message is set in an "Errormessage...
34,852
<p>I have an NHibernate session. In this session, I am performing exactly 1 operation, which is to run this code to get a list:</p> <pre><code>public IList&lt;Customer&gt; GetCustomerByFirstName(string customerFirstName) { return _session.CreateCriteria(typeof(Customer)) .Add(new NHibernate.Expression.EqExpression...
[ { "answer_id": 34965, "author": "Ryan Duffield", "author_id": 2696, "author_profile": "https://Stackoverflow.com/users/2696", "pm_score": 5, "selected": true, "text": "<p>I have seen this once before when one of my models was not mapped correctly (wasn't using nullable types correctly). ...
2008/08/29
[ "https://Stackoverflow.com/questions/34852", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1284/" ]
I have an NHibernate session. In this session, I am performing exactly 1 operation, which is to run this code to get a list: ``` public IList<Customer> GetCustomerByFirstName(string customerFirstName) { return _session.CreateCriteria(typeof(Customer)) .Add(new NHibernate.Expression.EqExpression("FirstName", custom...
I have seen this once before when one of my models was not mapped correctly (wasn't using nullable types correctly). May you please paste your model and mapping?
34,868
<p>In the PHP manual, to show the syntax for functions with optional parameters, they use brackets around each set of dependent optional parameter. For example, for the <a href="http://php.net/date" rel="noreferrer"><code>date()</code></a> function, the manual reads:</p> <pre><code>string date ( string $format [, int ...
[ { "answer_id": 34869, "author": "Jeff Winkworth", "author_id": 1306, "author_profile": "https://Stackoverflow.com/users/1306", "pm_score": 9, "selected": true, "text": "<p>Much like the manual, use an equals (<code>=</code>) sign in your definition of the parameters:</p>\n\n<pre><code>fu...
2008/08/29
[ "https://Stackoverflow.com/questions/34868", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2687/" ]
In the PHP manual, to show the syntax for functions with optional parameters, they use brackets around each set of dependent optional parameter. For example, for the [`date()`](http://php.net/date) function, the manual reads: ``` string date ( string $format [, int $timestamp = time() ] ) ``` Where `$timestamp` is a...
Much like the manual, use an equals (`=`) sign in your definition of the parameters: ``` function dosomething($var1, $var2, $var3 = 'somevalue'){ // Rest of function here... } ```
34,879
<p>I need debug some old code that uses a Hashtable to store response from various threads.</p> <p>I need a way to go through the entire Hashtable and print out both keys and the data in the Hastable.</p> <p>How can this be done?</p>
[ { "answer_id": 34884, "author": "Ben Scheirman", "author_id": 3381, "author_profile": "https://Stackoverflow.com/users/3381", "pm_score": 6, "selected": true, "text": "<pre><code>foreach(string key in hashTable.Keys)\n{\n Console.WriteLine(String.Format(\"{0}: {1}\", key, hashTable[key...
2008/08/29
[ "https://Stackoverflow.com/questions/34879", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2469/" ]
I need debug some old code that uses a Hashtable to store response from various threads. I need a way to go through the entire Hashtable and print out both keys and the data in the Hastable. How can this be done?
``` foreach(string key in hashTable.Keys) { Console.WriteLine(String.Format("{0}: {1}", key, hashTable[key])); } ```
34,913
<p>I'm experimenting with Linq and am having trouble figuring out grouping. I've gone through several tutorials but for some reason can't figure this out.</p> <p>As an example, say I have a table (SiteStats) with multiple website IDs that stores a count of how many visitors by type have accessed each site in total and...
[ { "answer_id": 34951, "author": "Tom Mayfield", "author_id": 2314, "author_profile": "https://Stackoverflow.com/users/2314", "pm_score": 2, "selected": false, "text": "<p>Easiest way for me to illustrate is using in-memory objects so it's clear what's happening. LINQ to SQL should be abl...
2008/08/29
[ "https://Stackoverflow.com/questions/34913", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2034/" ]
I'm experimenting with Linq and am having trouble figuring out grouping. I've gone through several tutorials but for some reason can't figure this out. As an example, say I have a table (SiteStats) with multiple website IDs that stores a count of how many visitors by type have accessed each site in total and for the p...
Actually, although Thomas' code will work, it is more succint to use a lambda expression: ``` var totals = from s in sites group s by s.SiteID into grouped select new { SiteID = grouped.Key, Last30Sum = grouped.Sum( s => s.Last30 ) }; ``` which uses the Sum extension method without the need for a nested LINQ...
34,914
<p>The manual page for <code>XML::Parser::Style::Objects</code> is horrible. A simple hello world style program would really be helpful.</p> <p>I really wanted to do something like this: (not real code of course)</p> <pre><code>use XML::Parser; my $p = XML::Parser-&gt;new(Style =&gt; 'Objects', Pkg =&gt; 'MyNode'); ...
[ { "answer_id": 35450, "author": "Pat", "author_id": 238, "author_profile": "https://Stackoverflow.com/users/238", "pm_score": 2, "selected": false, "text": "<p>When ever I need to do something similar, usually I end up using <a href=\"http://search.cpan.org/~ebohlman/XML-Parser-EasyTree-...
2008/08/29
[ "https://Stackoverflow.com/questions/34914", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3657/" ]
The manual page for `XML::Parser::Style::Objects` is horrible. A simple hello world style program would really be helpful. I really wanted to do something like this: (not real code of course) ``` use XML::Parser; my $p = XML::Parser->new(Style => 'Objects', Pkg => 'MyNode'); my $tree = $p->parsefile('foo.xml'); $tree...
In all cases here is actual code that runs ... doesn't mean much but produces output and hopefully can get you started ... ``` use XML::Parser; package MyNode::inner; sub doSomething { my $self = shift; print "This is an inner node containing : "; print $self->{Kids}->[0]->{Text}; print "\...
34,920
<p>What is the best way to create a lock on a file in Perl?</p> <p>Is it best to flock on the file or to create a lock file to place a lock on and check for a lock on the lock file?</p>
[ { "answer_id": 34928, "author": "mk.", "author_id": 1797, "author_profile": "https://Stackoverflow.com/users/1797", "pm_score": 0, "selected": false, "text": "<p>Use the <a href=\"http://perldoc.perl.org/functions/flock.html\" rel=\"nofollow noreferrer\">flock</a> Luke. </p>\n\n<p><stron...
2008/08/29
[ "https://Stackoverflow.com/questions/34920", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1539/" ]
What is the best way to create a lock on a file in Perl? Is it best to flock on the file or to create a lock file to place a lock on and check for a lock on the lock file?
If you end up using flock, here's some code to do it: ``` use Fcntl ':flock'; # Import LOCK_* constants # We will use this file path in error messages and function calls. # Don't type it out more than once in your code. Use a variable. my $file = '/path/to/some/file'; # Open the file for appending. Note the file p...
34,925
<p>I've seen quite a few posts on changes in .NET 3.5 SP1, but stumbled into one that I've yet to see documentation for yesterday. I had code working just fine on my machine, from VS, msbuild command line, everything, but it failed on the build server (running .NET 3.5 RTM).</p> <pre><code>[XmlRoot("foo")] public cla...
[ { "answer_id": 35223, "author": "TonyB", "author_id": 3543, "author_profile": "https://Stackoverflow.com/users/3543", "pm_score": 3, "selected": true, "text": "<p>In SP1 does the foo.Bar property get properly deserialized?</p>\n\n<p>In pre SP1 you wouldn't be able to deserialize the obje...
2008/08/29
[ "https://Stackoverflow.com/questions/34925", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2314/" ]
I've seen quite a few posts on changes in .NET 3.5 SP1, but stumbled into one that I've yet to see documentation for yesterday. I had code working just fine on my machine, from VS, msbuild command line, everything, but it failed on the build server (running .NET 3.5 RTM). ``` [XmlRoot("foo")] public class Foo { st...
In SP1 does the foo.Bar property get properly deserialized? In pre SP1 you wouldn't be able to deserialize the object because the set method of the Bar property is private so the XmlSerializer doesn't have a way to set that value. I'm not sure how SP1 is pulling it off. You could try adding this to your web.config/ap...
34,926
<p>my <b>SSRS DataSet</b> returns a field with HTML, e.g.</p> <pre><code>&lt;b&gt;blah blah &lt;/b&gt;&lt;i&gt; blah &lt;/i&gt;. </code></pre> <p>how do i strip all the HTML tags? has to be done with <b>inline</b> VB.NET</p> <p>Changing the data in the table is not an option.</p> <p><strong>Solution found</strong> ...
[ { "answer_id": 34935, "author": "Daniel Jennings", "author_id": 3641, "author_profile": "https://Stackoverflow.com/users/3641", "pm_score": 2, "selected": false, "text": "<p>Here's a good example using Regular Expressions: <a href=\"https://web.archive.org/web/20210619174622/https://www....
2008/08/29
[ "https://Stackoverflow.com/questions/34926", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3661/" ]
my **SSRS DataSet** returns a field with HTML, e.g. ``` <b>blah blah </b><i> blah </i>. ``` how do i strip all the HTML tags? has to be done with **inline** VB.NET Changing the data in the table is not an option. **Solution found** ... = System.Text.RegularExpressions.Regex.Replace(StringWithHTMLtoStrip, "<[^>]+>"...
Thanx to Daniel, but I needed it to be done inline ... here's the solution: `= System.Text.RegularExpressions.Regex.Replace(StringWithHTMLtoStrip, "<[^>]+>","")` Here are the links: <http://weblogs.asp.net/rosherove/archive/2003/05/13/6963.aspx> <http://msdn.microsoft.com/en-us/library/ms157328.aspx>
34,938
<p>I have an if statement with two conditions (separated by an OR operator), one of the conditions covers +70% of situations and takes far less time to process/execute than the second condition, so in the interests of speed I only want the second condition to be processed if the first condition evaluates to false.</p> ...
[ { "answer_id": 34941, "author": "dagorym", "author_id": 171, "author_profile": "https://Stackoverflow.com/users/171", "pm_score": 0, "selected": false, "text": "<p>Since this is tagged language agnostic I'll chime in. For Perl at least, the first option is sufficient, I'm not familiar w...
2008/08/29
[ "https://Stackoverflow.com/questions/34938", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2083/" ]
I have an if statement with two conditions (separated by an OR operator), one of the conditions covers +70% of situations and takes far less time to process/execute than the second condition, so in the interests of speed I only want the second condition to be processed if the first condition evaluates to false. if I o...
For C, C++, C#, Java and other .NET languages boolean expressions are optimised so that as soon as enough is known nothing else is evaluated. An old trick for doing obfuscated code was to use this to create if statements, such as: ``` a || b(); ``` if "a" is true, "b()" would never be evaluated, so we can rewrite i...
34,955
<p>When building projects in C++, I've found debugging linking errors to be tricky, especially when picking up other people's code. What strategies do people use for debugging and fixing linking errors?</p>
[ { "answer_id": 34967, "author": "Nathan Fellman", "author_id": 1084, "author_profile": "https://Stackoverflow.com/users/1084", "pm_score": 2, "selected": false, "text": "<p>One of the common linking errors I've run into is when a function is used differently from how it's defined. If yo...
2008/08/29
[ "https://Stackoverflow.com/questions/34955", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3575/" ]
When building projects in C++, I've found debugging linking errors to be tricky, especially when picking up other people's code. What strategies do people use for debugging and fixing linking errors?
Not sure what your level of expertise is, but here are the basics. Below is a linker error from VS 2005 - yes, it's a giant mess if you're not familiar with it. ``` ByteComparator.obj : error LNK2019: unresolved external symbol "int __cdecl does_not_exist(void)" (?does_not_exist@@YAHXZ) referenced in function "void ...
34,977
<p>I have a protocol that requires a length field up to 32-bits, and it must be generated at runtime to describe how many bytes are in a given packet.</p> <p>The code below is kind of ugly but I am wondering if this can be refactored to be slightly more efficient or easily understandable. The problem is that the code...
[ { "answer_id": 35027, "author": "Daniel Jennings", "author_id": 3641, "author_profile": "https://Stackoverflow.com/users/3641", "pm_score": 0, "selected": false, "text": "<p>Try this loop:</p>\n\n<pre><code>{\n extern char byte_stream[];\n int bytes = offset_in_packet;\n int n =...
2008/08/29
[ "https://Stackoverflow.com/questions/34977", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3663/" ]
I have a protocol that requires a length field up to 32-bits, and it must be generated at runtime to describe how many bytes are in a given packet. The code below is kind of ugly but I am wondering if this can be refactored to be slightly more efficient or easily understandable. The problem is that the code will only ...
Really you're only doing four calculations, so ***readability seems way more important*** here than efficiency. My approach to make something like this more readable is to 1. Extract common code to a function 2. Put similar calculations together to make the patterns more obvious 3. Get rid of the intermediate variabl...
34,987
<p>I am trying to iterate over all the elements of a static array of strings in the best possible way. I want to be able to declare it on one line and easily add/remove elements from it without having to keep track of the number. Sounds really simple, doesn't it?</p> <p>Possible non-solutions:</p> <pre><code>vector&l...
[ { "answer_id": 35006, "author": "Will Dean", "author_id": 987, "author_profile": "https://Stackoverflow.com/users/987", "pm_score": 5, "selected": false, "text": "<blockquote>\n <p>Problems - no way to get the number of strings automatically (that i know of).</p>\n</blockquote>\n\n<p>Th...
2008/08/29
[ "https://Stackoverflow.com/questions/34987", "https://Stackoverflow.com", "https://Stackoverflow.com/users/779/" ]
I am trying to iterate over all the elements of a static array of strings in the best possible way. I want to be able to declare it on one line and easily add/remove elements from it without having to keep track of the number. Sounds really simple, doesn't it? Possible non-solutions: ``` vector<string> v; v.push_back...
C++ 11 added initialization lists to allow the following syntax: ``` std::vector<std::string> v = {"Hello", "World"}; ``` Support for this C++ 11 feature was added in at least [GCC 4.4](http://gcc.gnu.org/projects/cxx0x.html) and only in [Visual Studio 2013](https://msdn.microsoft.com/en-us/library/hh567368.aspx#cor...
35,002
<p><strong>Is there anything built into the core C# libraries that can give me an immutable Dictionary?</strong> </p> <p>Something along the lines of <em>Java's</em>:</p> <pre><code>Collections.unmodifiableMap(myMap); </code></pre> <p>And just to clarify, I am not looking to stop the keys / values themselves from b...
[ { "answer_id": 35045, "author": "Kevin Dente", "author_id": 9, "author_profile": "https://Stackoverflow.com/users/9", "pm_score": 2, "selected": false, "text": "<p>I don't think so. There is a way to create a read-only List and read only Collection, but I don't think there's a built in r...
2008/08/29
[ "https://Stackoverflow.com/questions/35002", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1853/" ]
**Is there anything built into the core C# libraries that can give me an immutable Dictionary?** Something along the lines of *Java's*: ``` Collections.unmodifiableMap(myMap); ``` And just to clarify, I am not looking to stop the keys / values themselves from being changed, just the structure of the Dictionary. I ...
No, but a wrapper is rather trivial: ``` public class ReadOnlyDictionary<TKey, TValue> : IDictionary<TKey, TValue> { IDictionary<TKey, TValue> _dict; public ReadOnlyDictionary(IDictionary<TKey, TValue> backingDict) { _dict = backingDict; } public void Add(TKey key, TValue value) { ...
35,007
<p>Every time I create an object that has a collection property I go back and forth on the best way to do it?</p> <ol> <li>public property with a getter that returns a reference to private variable</li> <li>explicit get_ObjList and set_ObjList methods that return and create new or cloned objects every time</li> <li>ex...
[ { "answer_id": 35018, "author": "Ryan Duffield", "author_id": 2696, "author_profile": "https://Stackoverflow.com/users/2696", "pm_score": 0, "selected": false, "text": "<p>If you're simply looking to expose a collection on your instance, then using a getter/setter to a private member var...
2008/08/29
[ "https://Stackoverflow.com/questions/35007", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2582/" ]
Every time I create an object that has a collection property I go back and forth on the best way to do it? 1. public property with a getter that returns a reference to private variable 2. explicit get\_ObjList and set\_ObjList methods that return and create new or cloned objects every time 3. explicit get\_ObjList tha...
How you expose a collection depends entirely on how users are intended to interact with it. **1)** If users will be adding and removing items from an object's collection, then a simple get-only collection property is best (option #1 from the original question): ``` private readonly Collection<T> myCollection_ = new ....
35,011
<p>I've got a whole directory of dll's I need to register to the GAC. I'd like to avoid registering each file explicitly- but it appears that gacutil has no "register directory" option. Anyone have a fast/simple solution?</p>
[ { "answer_id": 35057, "author": "Euro Micelli", "author_id": 2230, "author_profile": "https://Stackoverflow.com/users/2230", "pm_score": 6, "selected": true, "text": "<p>GACUTIL doesn't register DLLs -- not in the \"COM\" sense. Unlike in COM, GACUTIL copies the file to an opaque directo...
2008/08/29
[ "https://Stackoverflow.com/questions/35011", "https://Stackoverflow.com", "https://Stackoverflow.com/users/667/" ]
I've got a whole directory of dll's I need to register to the GAC. I'd like to avoid registering each file explicitly- but it appears that gacutil has no "register directory" option. Anyone have a fast/simple solution?
GACUTIL doesn't register DLLs -- not in the "COM" sense. Unlike in COM, GACUTIL copies the file to an opaque directory under %SYSTEMROOT%\assembly and that's where they run from. It wouldn't make sense to ask GACUTIL "register a folder" (not that you can do that with RegSvr32 either). You can use a batch FOR command s...
35,037
<p>I have a directory with PDF files that I need to create an index for. It is a PHP page with a list of links:</p> <pre><code>&lt;A HREF="path to file"&gt;filename&lt;/A&gt; </code></pre> <p>The filenames can be complicated:</p> <pre><code>LVD 2-1133 - Ändring av dumpningslina (1984-11-20).pdf </code></pre> <p>Wha...
[ { "answer_id": 35046, "author": "Andy", "author_id": 1993, "author_profile": "https://Stackoverflow.com/users/1993", "pm_score": 0, "selected": false, "text": "<p><a href=\"http://se.php.net/manual/en/function.urlencode.php\" rel=\"nofollow noreferrer\">urlencode()</a> should probably do...
2008/08/29
[ "https://Stackoverflow.com/questions/35037", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2703/" ]
I have a directory with PDF files that I need to create an index for. It is a PHP page with a list of links: ``` <A HREF="path to file">filename</A> ``` The filenames can be complicated: ``` LVD 2-1133 - Ändring av dumpningslina (1984-11-20).pdf ``` What is the correct way to link to this file on a Linux/Apache s...
You can use [rawurlencode()](http://php.net/manual/en/function.rawurlencode.php) to convert a string according to the RFC 1738 spec. This function replaces all non-alphanumeric characters by their associated code. The difference with [urlencode()](http://php.net/manual/en/function.urlencode.php) is that spaces are enc...
35,047
<p>Perhaps the biggest risk in pushing new functionality to live lies with the database modifications required by the new code. In Rails, I believe they have 'migrations', in which you can programmatically make changes to your development host, and then make the same changes live along with the code that uses the revis...
[ { "answer_id": 35061, "author": "jcoby", "author_id": 2884, "author_profile": "https://Stackoverflow.com/users/2884", "pm_score": 2, "selected": false, "text": "<p>Symfony has a plugin called sfMigrationsLight that handles basic migrations. CakePHP also has migrations.</p>\n\n<p>For wha...
2008/08/29
[ "https://Stackoverflow.com/questions/35047", "https://Stackoverflow.com", "https://Stackoverflow.com/users/137/" ]
Perhaps the biggest risk in pushing new functionality to live lies with the database modifications required by the new code. In Rails, I believe they have 'migrations', in which you can programmatically make changes to your development host, and then make the same changes live along with the code that uses the revised ...
I've never come across a tool that would do the job. Instead I've used individual files, numbered so that I know which order to run them: essentially, a manual version of Rails migrations, but without the rollback. Here's the sort of thing I'm talking about: ``` 000-clean.sql # wipe out everything in the DB 0...
35,070
<p>What's the best way to programmatically merge a .reg file into the registry? This is for unit testing; the .reg file is a test artifact which will be added then removed at the start and end of testing.</p> <p>Or, if there's a better way to unit test against the registry...</p>
[ { "answer_id": 35092, "author": "Javache", "author_id": 1074, "author_profile": "https://Stackoverflow.com/users/1074", "pm_score": 2, "selected": false, "text": "<p>I looked into it by checking out my file associations.</p>\n\n<p>It seems that a .reg file is just called as the first par...
2008/08/29
[ "https://Stackoverflow.com/questions/35070", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1683/" ]
What's the best way to programmatically merge a .reg file into the registry? This is for unit testing; the .reg file is a test artifact which will be added then removed at the start and end of testing. Or, if there's a better way to unit test against the registry...
It is possible to remove registry keys using a .reg file, although I'm not sure how well it's documented. Here's how: ``` REGEDIT4 [-HKEY_CURRENT_USER\Software\<otherpath>] ``` The `-` in front of the key name tells `Regedit` that you want to remove the key. To run this silently, type: ``` regedit /s "myfile.reg"...
35,076
<p>I'm working with a SQL Server 2000 database that likely has a few dozen tables that are no longer accessed. I'd like to clear out the data that we no longer need to be maintaining, but I'm not sure how to identify which tables to remove.</p> <p>The database is shared by several different applications, so I can't b...
[ { "answer_id": 35087, "author": "SQLMenace", "author_id": 740, "author_profile": "https://Stackoverflow.com/users/740", "pm_score": 0, "selected": false, "text": "<p>If you have lastupdate columns you can check for the writes, there is really no easy way to check for reads. You could run...
2008/08/29
[ "https://Stackoverflow.com/questions/35076", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3344/" ]
I'm working with a SQL Server 2000 database that likely has a few dozen tables that are no longer accessed. I'd like to clear out the data that we no longer need to be maintaining, but I'm not sure how to identify which tables to remove. The database is shared by several different applications, so I can't be 100% conf...
MSSQL2000 won't give you that kind of information. But a way you can identify what tables ARE used (and then deduce which ones are not) is to use the SQL Profiler, to save all the queries that go to a certain database. Configure the profiler to record the results to a new table, and then check the queries saved there t...
35,102
<p>In emacs, I've read the following code snippet in <code>simple.el</code>:</p> <pre><code>(frame-parameter frame 'buried-buffer-list) </code></pre> <p>What is the exact meaning of the <code>'buried-buffer-list</code> parameter? What it is used for?</p>
[ { "answer_id": 35087, "author": "SQLMenace", "author_id": 740, "author_profile": "https://Stackoverflow.com/users/740", "pm_score": 0, "selected": false, "text": "<p>If you have lastupdate columns you can check for the writes, there is really no easy way to check for reads. You could run...
2008/08/29
[ "https://Stackoverflow.com/questions/35102", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3673/" ]
In emacs, I've read the following code snippet in `simple.el`: ``` (frame-parameter frame 'buried-buffer-list) ``` What is the exact meaning of the `'buried-buffer-list` parameter? What it is used for?
MSSQL2000 won't give you that kind of information. But a way you can identify what tables ARE used (and then deduce which ones are not) is to use the SQL Profiler, to save all the queries that go to a certain database. Configure the profiler to record the results to a new table, and then check the queries saved there t...
35,103
<p>I'd like to bind a configuration file to my executable. I'd like to do this by storing an MD5 hash of the file inside the executable. This should keep anyone but the executable from modifying the file.</p> <p>Essentially if someone modifies this file outside of the program the program should fail to load it again.<...
[ { "answer_id": 35109, "author": "Joel Martinez", "author_id": 3433, "author_profile": "https://Stackoverflow.com/users/3433", "pm_score": -1, "selected": false, "text": "<p>just make a const string that holds the md5 hash and compile it into your app ... your app can then just refer to t...
2008/08/29
[ "https://Stackoverflow.com/questions/35103", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2191/" ]
I'd like to bind a configuration file to my executable. I'd like to do this by storing an MD5 hash of the file inside the executable. This should keep anyone but the executable from modifying the file. Essentially if someone modifies this file outside of the program the program should fail to load it again. EDIT: The...
A better solution is to store the MD5 in the configuration file. But instead of the MD5 being just of the configuration file, also include some secret "key" value, like a fixed guid, in the MD5. ``` write(MD5(SecretKey + ConfigFileText)); ``` Then you simply remove that MD5 and rehash the file (including your secret...
35,106
<p>I've found <a href="http://msdn.microsoft.com/en-us/library/system.web.configuration.scriptingjsonserializationsection.scriptingjsonserializationsection.aspx" rel="noreferrer"><code>ScriptingJsonSerializationSection</code></a> but I'm not sure how to use it. I could write a function to convert the object to a JSON s...
[ { "answer_id": 35125, "author": "TonyB", "author_id": 3543, "author_profile": "https://Stackoverflow.com/users/3543", "pm_score": 5, "selected": true, "text": "<p>This should do the trick</p>\n\n<pre><code>Dim jsonSerialiser As New System.Web.Script.Serialization.JavaScriptSerializer\nDi...
2008/08/29
[ "https://Stackoverflow.com/questions/35106", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1414/" ]
I've found [`ScriptingJsonSerializationSection`](http://msdn.microsoft.com/en-us/library/system.web.configuration.scriptingjsonserializationsection.scriptingjsonserializationsection.aspx) but I'm not sure how to use it. I could write a function to convert the object to a JSON string manually, but since .Net can do it o...
This should do the trick ``` Dim jsonSerialiser As New System.Web.Script.Serialization.JavaScriptSerializer Dim jsonString as String = jsonSerialiser.Serialize(yourObject) ```
35,123
<p>What did I do wrong?</p> <p>Here is an excerpt from my code:</p> <pre><code>public void createPartControl(Composite parent) { parent.setLayout(new FillLayout()); ScrolledComposite scrollBox = new ScrolledComposite(parent, SWT.V_SCROLL); scrollBox.setExpandHorizontal(true); mParent = new Composite(scrollBox...
[ { "answer_id": 35503, "author": "SCdF", "author_id": 1666, "author_profile": "https://Stackoverflow.com/users/1666", "pm_score": 0, "selected": false, "text": "<p>Don't you need to recompute the size of the scrollBox after the layout?</p>\n" }, { "answer_id": 36306, "author":...
2008/08/29
[ "https://Stackoverflow.com/questions/35123", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3657/" ]
What did I do wrong? Here is an excerpt from my code: ``` public void createPartControl(Composite parent) { parent.setLayout(new FillLayout()); ScrolledComposite scrollBox = new ScrolledComposite(parent, SWT.V_SCROLL); scrollBox.setExpandHorizontal(true); mParent = new Composite(scrollBox, SWT.NONE); scroll...
This is a common hurdle when using `ScrolledComposite`. When it gets so small that the scroll bar must be shown, the client control has to shrink horizontally to make room for the scroll bar. This has the side effect of making some labels wrap lines, which moved the following controls farther down, which increased the ...
35,167
<p>I know that the following is true</p> <pre><code>int i = 17; //binary 10001 int j = i &lt;&lt; 1; //decimal 34, binary 100010 </code></pre> <p>But, if you shift too far, the bits fall off the end. Where this happens is a matter of the size of integer you are working with.</p> <p>Is there a way to perform a shift...
[ { "answer_id": 35172, "author": "Chris Marasti-Georg", "author_id": 96, "author_profile": "https://Stackoverflow.com/users/96", "pm_score": 7, "selected": true, "text": "<p>If you know the size of type, you could do something like:</p>\n\n<pre><code>uint i = 17;\nuint j = i &lt;&lt; 1 | ...
2008/08/29
[ "https://Stackoverflow.com/questions/35167", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2470/" ]
I know that the following is true ``` int i = 17; //binary 10001 int j = i << 1; //decimal 34, binary 100010 ``` But, if you shift too far, the bits fall off the end. Where this happens is a matter of the size of integer you are working with. Is there a way to perform a shift so that the bits rotate around to the o...
If you know the size of type, you could do something like: ``` uint i = 17; uint j = i << 1 | i >> 31; ``` ... which would perform a circular shift of a 32 bit value. As a generalization to circular shift left n bits, on a b bit variable: ``` /*some unsigned numeric type*/ input = 17; var result = input << n | in...
35,170
<p>What does it mean if a task is declared with the automatic keyword in Verilog?</p> <pre><code>task automatic do_things; input [31:0] number_of_things; reg [31:0] tmp_thing; begin // ... end endtask; </code></pre> <p>Note: This question is mostly because I'm curious if there are any hardware programmers...
[ { "answer_id": 35193, "author": "Will Dean", "author_id": 987, "author_profile": "https://Stackoverflow.com/users/987", "pm_score": 5, "selected": true, "text": "<p>It means that the task is re-entrant - items declared within the task are dynamically allocated rather than shared between ...
2008/08/29
[ "https://Stackoverflow.com/questions/35170", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3594/" ]
What does it mean if a task is declared with the automatic keyword in Verilog? ``` task automatic do_things; input [31:0] number_of_things; reg [31:0] tmp_thing; begin // ... end endtask; ``` Note: This question is mostly because I'm curious if there are any hardware programmers on the site. :)
It means that the task is re-entrant - items declared within the task are dynamically allocated rather than shared between different invocations of the task. You see - some of us do Verilog... (ugh)
35,178
<p>I am working on a C++ code base that was recently moved from X/Motif to Qt. I am trying to write a Perl script that will replace all occurrences of Boolean (from X) with bool. The script just does a simple replacement. </p> <pre><code>s/\bBoolean\b/bool/g </code></pre> <p>There are a few conditions. </p> <p>...
[ { "answer_id": 35198, "author": "John Meagher", "author_id": 3535, "author_profile": "https://Stackoverflow.com/users/3535", "pm_score": 0, "selected": false, "text": "<p>To fix condition 1 try:</p>\n\n<pre><code>s/[^:]\\bBoolean\\b(?!\")/bool/g\n</code></pre>\n\n<p>The [^:] says to matc...
2008/08/29
[ "https://Stackoverflow.com/questions/35178", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2897/" ]
I am working on a C++ code base that was recently moved from X/Motif to Qt. I am trying to write a Perl script that will replace all occurrences of Boolean (from X) with bool. The script just does a simple replacement. ``` s/\bBoolean\b/bool/g ``` There are a few conditions. 1) We have CORBA in our code and \b ma...
> > s/[^:]\bBoolean\b(?!")/bool/g > > > This does not match strings where Boolean is at that the beginning of the line becuase [^:] is "match a character that is not :".
35,185
<p>What would be the best algorithm for finding a number that occurs only once in a list which has all other numbers occurring exactly twice.</p> <p>So, in the list of integers (lets take it as an array) each integer repeats exactly twice, except one. To find that one, what is the best algorithm.</p>
[ { "answer_id": 35192, "author": "Jason Bunting", "author_id": 1790, "author_profile": "https://Stackoverflow.com/users/1790", "pm_score": 0, "selected": false, "text": "<p>You need to specify what you mean by \"best\" - to some, speed is all that matters and would qualify an answer as \"...
2008/08/29
[ "https://Stackoverflow.com/questions/35185", "https://Stackoverflow.com", "https://Stackoverflow.com/users/380/" ]
What would be the best algorithm for finding a number that occurs only once in a list which has all other numbers occurring exactly twice. So, in the list of integers (lets take it as an array) each integer repeats exactly twice, except one. To find that one, what is the best algorithm.
The fastest (O(n)) and most memory efficient (O(1)) way is with the XOR operation. In C: ``` int arr[] = {3, 2, 5, 2, 1, 5, 3}; int num = 0, i; for (i=0; i < 7; i++) num ^= arr[i]; printf("%i\n", num); ``` This prints "1", which is the only one that occurs once. This works because the first time you hit a n...
35,208
<p>I have a page with many forms in panels and usercontrols, and a requiredfield validator I just added to one form is preventing all of my other forms from submitting. what's the rule that I'm not following?</p>
[ { "answer_id": 35213, "author": "Serhat Ozgel", "author_id": 31505, "author_profile": "https://Stackoverflow.com/users/31505", "pm_score": 0, "selected": false, "text": "<p>You should be setting ValidationGroup property to a different value for each group of elements. Your validator's Va...
2008/08/29
[ "https://Stackoverflow.com/questions/35208", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2462/" ]
I have a page with many forms in panels and usercontrols, and a requiredfield validator I just added to one form is preventing all of my other forms from submitting. what's the rule that I'm not following?
Are you using ValidationGroups? Try assigning each control with a validation group as well as the validator that you want to use. Something like: ``` <asp:TextBox ID="txt1" ValidationGroup="Group1" ruant="server" /> <asp:RequiredFieldValidator ID="rfv1" ... ValidationGroup="Group1" /> ``` Note, if a button doesn't s...
35,211
<p>The compiler usually chokes when an event doesn't appear beside a <code>+=</code> or a <code>-=</code>, so I'm not sure if this is possible.</p> <p>I want to be able to identify an event by using an Expression tree, so I can create an event watcher for a test. The syntax would look something like this:</p> <pre><c...
[ { "answer_id": 36255, "author": "Curt Hagenlocher", "author_id": 533, "author_profile": "https://Stackoverflow.com/users/533", "pm_score": 2, "selected": false, "text": "<p>A .NET event isn't actually an object, it's an endpoint represented by two functions -- one for adding and one for ...
2008/08/29
[ "https://Stackoverflow.com/questions/35211", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
The compiler usually chokes when an event doesn't appear beside a `+=` or a `-=`, so I'm not sure if this is possible. I want to be able to identify an event by using an Expression tree, so I can create an event watcher for a test. The syntax would look something like this: ``` using(var foo = new EventWatcher(target...
**Edit:** As [Curt](https://stackoverflow.com/questions/35211/identify-an-event-via-a-linq-expression-tree#36255) has pointed out, my implementation is rather flawed in that it can only be used from within the class that declares the event :) Instead of "`x => x.MyEvent`" returning the event, it was returning the backi...
35,240
<p>I used the jQuery Form plugin for asynchronous form submission. For forms that contain files, it copies the form to a hidden iframe, submits it, and copies back the iframe's contents. The problem is that I can't figure out how to find what HTTP status code was returned by the server. For example, if the server retur...
[ { "answer_id": 1847965, "author": "Coyod", "author_id": 223888, "author_profile": "https://Stackoverflow.com/users/223888", "pm_score": 4, "selected": false, "text": "<p>You can't get page headers by JS, but you can distinguish error from success:\nTry something like this:</p>\n\n<pre><c...
2008/08/29
[ "https://Stackoverflow.com/questions/35240", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3560/" ]
I used the jQuery Form plugin for asynchronous form submission. For forms that contain files, it copies the form to a hidden iframe, submits it, and copies back the iframe's contents. The problem is that I can't figure out how to find what HTTP status code was returned by the server. For example, if the server returns ...
You can't get page headers by JS, but you can distinguish error from success: Try something like this: ``` <script type="text/javascript"> var uploadStarted = false; function OnUploadStart(){ uploadStarted = true; } function OnUploadComplete(state,message){ if(state...
35,286
<p>I want to escape a DOS filename so I can use it with sed. I have a DOS batch file something like this:</p> <pre><code>set FILENAME=%~f1 sed 's/Some Pattern/%FILENAME%/' inputfile </code></pre> <p>(Note: <code>%~f1</code> - expands <code>%1</code> to a Fully qualified path name - <code>C:\utils\MyFile.txt</code>)<...
[ { "answer_id": 35386, "author": "Jeremy", "author_id": 3657, "author_profile": "https://Stackoverflow.com/users/3657", "pm_score": 3, "selected": true, "text": "<p>This will work. It's messy because in BAT files you can't use set var=`cmd` like you can in unix.\nThe fact that echo doesn...
2008/08/29
[ "https://Stackoverflow.com/questions/35286", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2541/" ]
I want to escape a DOS filename so I can use it with sed. I have a DOS batch file something like this: ``` set FILENAME=%~f1 sed 's/Some Pattern/%FILENAME%/' inputfile ``` (Note: `%~f1` - expands `%1` to a Fully qualified path name - `C:\utils\MyFile.txt`) I found that the backslashes in `%FILENAME%` are just esca...
This will work. It's messy because in BAT files you can't use set var=`cmd` like you can in unix. The fact that echo doesn't understand quotes is also messy, and could lead to trouble if `Some Pattern` contains shell meta characters. ``` set FILENAME=%~f1 echo s/Some Pattern/%FILENAME%/ | sed -e "s/\\/\\\\/g" >sedcmd....
35,301
<p>I have always used <code>||</code> (two pipes) in OR expressions, both in C# and PHP. Occasionally I see a single pipe used: <code>|</code>. What is the difference between those two usages? Are there any caveats when using one over the other or are they interchangeable?</p>
[ { "answer_id": 35303, "author": "nsanders", "author_id": 1244, "author_profile": "https://Stackoverflow.com/users/1244", "pm_score": 5, "selected": false, "text": "<p>One is a \"bitwise or\".</p>\n\n<blockquote>\n <p>10011b | 01000b => 11011b</p>\n</blockquote>\n\n<p>The other is a logi...
2008/08/29
[ "https://Stackoverflow.com/questions/35301", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3238/" ]
I have always used `||` (two pipes) in OR expressions, both in C# and PHP. Occasionally I see a single pipe used: `|`. What is the difference between those two usages? Are there any caveats when using one over the other or are they interchangeable?
Just like the `&` and `&&` operator, the double Operator is a "short-circuit" operator. For example: ``` if(condition1 || condition2 || condition3) ``` If condition1 is true, condition 2 and 3 will NOT be checked. ``` if(condition1 | condition2 | condition3) ``` This will check conditions 2 and 3, even if 1 is a...
35,317
<p>When I log into a remote machine using ssh X11 forwarding, Vista pops up a box complaining about a process that died unexpectedly. Once I dismiss the box, everything is fine. So I really don't care if some process died. How do I get Vista to shut up about it?</p> <hr> <p>Specifically, the message reads:</p> <p...
[ { "answer_id": 35324, "author": "Brad Wilson", "author_id": 1554, "author_profile": "https://Stackoverflow.com/users/1554", "pm_score": 1, "selected": false, "text": "<p>The problem is, the process didn't just die, it died unexpectedly. Sounds like there's a bug in your SSH client that V...
2008/08/29
[ "https://Stackoverflow.com/questions/35317", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1438/" ]
When I log into a remote machine using ssh X11 forwarding, Vista pops up a box complaining about a process that died unexpectedly. Once I dismiss the box, everything is fine. So I really don't care if some process died. How do I get Vista to shut up about it? --- Specifically, the message reads: ``` sh.exe has stopp...
Well, I don't know what the original problem was, but when I update Cygwin recently the error message stopped popping up. My guess it that [rebasing](http://sourceware.org/ml/cygwin/2006-11/msg00059.html) was necessary.
35,320
<p>In the code below I am using a recursive CTE(Common Table Expression) in SQL Server 2005 to try and find the top level parent of a basic hierarchical structure. The rule of this hierarchy is that every CustID has a ParentID and if the CustID has no parent then the ParentID = CustID and it is the highest level.</p> ...
[ { "answer_id": 35425, "author": "Trevor Abell", "author_id": 2916, "author_profile": "https://Stackoverflow.com/users/2916", "pm_score": 1, "selected": false, "text": "<p>I'm not certain I fully understand the problem, but just to hack &amp; slash at it you could try:</p>\n\n<pre><code>S...
2008/08/29
[ "https://Stackoverflow.com/questions/35320", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3677/" ]
In the code below I am using a recursive CTE(Common Table Expression) in SQL Server 2005 to try and find the top level parent of a basic hierarchical structure. The rule of this hierarchy is that every CustID has a ParentID and if the CustID has no parent then the ParentID = CustID and it is the highest level. ``` DEC...
If you just want want the highest recursion depth couldn't you do something like this?Then, when you actually query the CTE just look for the row with max(Depth)? Like so: ``` DECLARE @LookupID int --Our test value SET @LookupID = 1; WITH cteLevelOne (ParentID, CustID, Depth) AS ( SELECT a.ParentID, a.Cust...
35,322
<p>I'm writing an app using asp.net-mvc deploying to iis6. I'm using forms authentication. Usually when a user tries to access a resource without proper authorization I want them to be redirected to a login page. FormsAuth does this for me easy enough.</p> <p>Problem: Now I have an action being accessed by a console a...
[ { "answer_id": 35341, "author": "Andy", "author_id": 1993, "author_profile": "https://Stackoverflow.com/users/1993", "pm_score": -1, "selected": false, "text": "<p>I did some googling and this is what I came up with:</p>\n\n<pre><code>\n HttpContext.Current.Response.StatusCode = 401;\...
2008/08/29
[ "https://Stackoverflow.com/questions/35322", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1946/" ]
I'm writing an app using asp.net-mvc deploying to iis6. I'm using forms authentication. Usually when a user tries to access a resource without proper authorization I want them to be redirected to a login page. FormsAuth does this for me easy enough. Problem: Now I have an action being accessed by a console app. Whats ...
Ok, I worked around this. I made a custom ActionResult (HttpForbiddenResult) and custom ActionFilter (NoFallBackAuthorize). To avoid redirection, HttpForbiddenResult marks responses with status code 403. FormsAuthentication doesn't catch responses with this code so the login redirection is effectively skipped. The NoF...
35,333
<p>I'm compiling a simple .c in visual c++ with Compile as C Code (/TC) and i get this compiler error </p> <blockquote> <p>error C2143: syntax error : missing ';' before 'type'</p> </blockquote> <p>on a line that calls for a simple struct </p> <pre><code> struct foo test; </code></pre> <p>same goes for using the ...
[ { "answer_id": 35336, "author": "Greg Hewgill", "author_id": 893, "author_profile": "https://Stackoverflow.com/users/893", "pm_score": 1, "selected": false, "text": "<p>Did you accidentally omit a semicolon on a previous line? If the previous line is an <code>#include</code>, you might h...
2008/08/29
[ "https://Stackoverflow.com/questions/35333", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2566/" ]
I'm compiling a simple .c in visual c++ with Compile as C Code (/TC) and i get this compiler error > > error C2143: syntax error : missing ';' before 'type' > > > on a line that calls for a simple struct ``` struct foo test; ``` same goes for using the typedef of the struct. > > error C2275: 'FOO' : illeg...
I forgot that in C you have to declare all your variables before any code.
35,407
<p>I'm working on a system with four logical CPS (two dual-core CPUs if it matters). I'm using make to parallelize twelve trivially parallelizable tasks and doing it from cron.</p> <p>The invocation looks like:</p> <pre><code>make -k -j 4 -l 3.99 -C [dir] [12 targets] </code></pre> <p>The trouble I'm running into i...
[ { "answer_id": 35447, "author": "KannoN", "author_id": 2897, "author_profile": "https://Stackoverflow.com/users/2897", "pm_score": 0, "selected": false, "text": "<p>Does make think one of the targets is failing? If so, it will stop the make after the running jobs finish. You can use -...
2008/08/29
[ "https://Stackoverflow.com/questions/35407", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1447/" ]
I'm working on a system with four logical CPS (two dual-core CPUs if it matters). I'm using make to parallelize twelve trivially parallelizable tasks and doing it from cron. The invocation looks like: ``` make -k -j 4 -l 3.99 -C [dir] [12 targets] ``` The trouble I'm running into is that sometimes one job will fini...
I'd drop the '-l' If all you plan to run the the system is this build I *think* the -j 4 does what you want. Based on my memory, if you have anything else running (crond?), that can push the load average over 4. [GNU make ref](http://sunsite.ualberta.ca/Documentation/Gnu/make-3.79/html_chapter/make_5.html#SEC47)
35,420
<p>I've had a tough time setting up my replication server. Is there any program (OS X, Windows, Linux, or PHP no problem) that lets me monitor and resolve replication issues? (btw, for those following, I've been on this issue <a href="https://stackoverflow.com/questions/8166/mysql-replication-if-i-dont-specify-any-data...
[ { "answer_id": 35438, "author": "Alexandru Nedelcu", "author_id": 3280, "author_profile": "https://Stackoverflow.com/users/3280", "pm_score": 3, "selected": true, "text": "<p>To monitor the servers we use the free <a href=\"http://www.maatkit.org/tools.html\" rel=\"nofollow noreferrer\">...
2008/08/29
[ "https://Stackoverflow.com/questions/35420", "https://Stackoverflow.com", "https://Stackoverflow.com/users/547/" ]
I've had a tough time setting up my replication server. Is there any program (OS X, Windows, Linux, or PHP no problem) that lets me monitor and resolve replication issues? (btw, for those following, I've been on this issue [here](https://stackoverflow.com/questions/8166/mysql-replication-if-i-dont-specify-any-databases...
To monitor the servers we use the free [tools from Maatkit](http://www.maatkit.org/tools.html) ... simple, yet efficient. The binary replication is available in 5.1, so I guess you've got some balls. We still use 5.0 and it works OK, but of course we had our share of issues with it. We use a Master-Master replication...
35,463
<p>Some code that rounds up the division to demonstrate (C-syntax):</p> <pre><code>#define SINT64 long long int #define SINT32 long int SINT64 divRound(SINT64 dividend, SINT64 divisor) { SINT32 quotient1 = dividend / divisor; SINT32 modResult = dividend % divisor; SINT32 multResult = modResult * 2; SINT32 qu...
[ { "answer_id": 35468, "author": "Mat Noguchi", "author_id": 1799, "author_profile": "https://Stackoverflow.com/users/1799", "pm_score": 0, "selected": false, "text": "<p><code>ldiv</code> ?</p>\n\n<p>Edit: reread title, so you might want to ignore this. Or not, depending on if it has an ...
2008/08/29
[ "https://Stackoverflow.com/questions/35463", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
Some code that rounds up the division to demonstrate (C-syntax): ``` #define SINT64 long long int #define SINT32 long int SINT64 divRound(SINT64 dividend, SINT64 divisor) { SINT32 quotient1 = dividend / divisor; SINT32 modResult = dividend % divisor; SINT32 multResult = modResult * 2; SINT32 quotient2 = mult...
This functionality is introduced in [/linux/lib/div64.c](http://lxr.linux.no/linux+v2.6.22/lib/div64.c) as early as kernel v2.6.22.
35,480
<p>I'm currently working on a large implementation of Class::DBI for an existing database structure, and am running into a problem with clearing the cache from Class::DBI. This is a mod_perl implementation, so an instance of a class can be quite old between times that it is accessed. From the man pages I found two opt...
[ { "answer_id": 35529, "author": "John Siracusa", "author_id": 164, "author_profile": "https://Stackoverflow.com/users/164", "pm_score": 4, "selected": true, "text": "<p>The \"<a href=\"http://wiki.class-dbi.com/wiki/Common_problems\" rel=\"nofollow noreferrer\">common problems</a>\" page...
2008/08/29
[ "https://Stackoverflow.com/questions/35480", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3421/" ]
I'm currently working on a large implementation of Class::DBI for an existing database structure, and am running into a problem with clearing the cache from Class::DBI. This is a mod\_perl implementation, so an instance of a class can be quite old between times that it is accessed. From the man pages I found two option...
The "[common problems](http://wiki.class-dbi.com/wiki/Common_problems)" page on the [Class::DBI wiki](http://wiki.class-dbi.com/wiki) has a [section](http://wiki.class-dbi.com/wiki/Common_problems#Old_data_due_to_object_index) on this subject. The simplest solution is to disable the live object index entirely using: `...
35,485
<p>I want to be able to get an estimate of how much code &amp; static data is used by my C++ program?</p> <p>Is there a way to find this out by looking at the executable or object files? Or perhaps something I can do at runtime?</p> <p>Will objdump &amp; readelf help?</p>
[ { "answer_id": 35508, "author": "C. K. Young", "author_id": 13, "author_profile": "https://Stackoverflow.com/users/13", "pm_score": 1, "selected": false, "text": "<p><code>readelf</code> will indeed help. You can use the <code>-S</code> option; that will show the sizes of all sections. <...
2008/08/30
[ "https://Stackoverflow.com/questions/35485", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1841/" ]
I want to be able to get an estimate of how much code & static data is used by my C++ program? Is there a way to find this out by looking at the executable or object files? Or perhaps something I can do at runtime? Will objdump & readelf help?
"size" is the traditional tool. "readelf" has a lot of options. ``` $ size /bin/sh text data bss dec hex filename 712739 37524 21832 772095 bc7ff /bin/sh ```
35,491
<p>I want to be able to get an estimate of how much code &amp; static data is used by my C++ program?</p> <p>Is there a way to find this out by looking at the executable or object files? Or perhaps something I can do at runtime?</p> <p>Will otool help?</p>
[ { "answer_id": 35583, "author": "Mike Haboustak", "author_id": 2146, "author_profile": "https://Stackoverflow.com/users/2146", "pm_score": 2, "selected": false, "text": "<p>I think otool can help. Specifically, \"otool -s {segment} {section}\" should print out the details. I'm not sure i...
2008/08/30
[ "https://Stackoverflow.com/questions/35491", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1841/" ]
I want to be able to get an estimate of how much code & static data is used by my C++ program? Is there a way to find this out by looking at the executable or object files? Or perhaps something I can do at runtime? Will otool help?
* "size" is the traditional tool and works on all unix flavors. * "otool" has a bit finer grain control and has a lot of options. . ``` $ size python __TEXT __DATA __OBJC others dec hex 860160 159744 0 2453504 3473408 350000 ```
35,507
<p>I have been working with Struts for some time, but for a project I am finishing I was asked to separate Templates (velocity .vm files), configs (struts.xml, persistence.xml) from main WAR file.</p> <p>I have all in default structure like: </p> <pre> application |-- <i><b>META-INF</b></i> -- Some...
[ { "answer_id": 35867, "author": "Peter Hilton", "author_id": 2670, "author_profile": "https://Stackoverflow.com/users/2670", "pm_score": 0, "selected": false, "text": "<p>For <em>persistence.xml</em>, specifically, you can put a persistence unit in a separate JAR, which you can deploy se...
2008/08/30
[ "https://Stackoverflow.com/questions/35507", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2274/" ]
I have been working with Struts for some time, but for a project I am finishing I was asked to separate Templates (velocity .vm files), configs (struts.xml, persistence.xml) from main WAR file. I have all in default structure like: ``` application |-- ***META-INF*** -- Some configs are here |...
If I understood your question about Struts config files right, they are specified in web.xml. Find the Struts servlet config param. The param-value can be a list of comma separated list of XML files to load. Eg: ``` <servlet> <servlet-name>action</servlet-name> <servlet-class>org.apache.struts.action.ActionSer...
35,538
<p>What's the best way to go about validating that a document follows some version of HTML (prefereably that I can specify)? I'd like to be able to know where the failures occur, as in a web-based validator, except in a native Python app.</p>
[ { "answer_id": 35543, "author": "John Millikin", "author_id": 3560, "author_profile": "https://Stackoverflow.com/users/3560", "pm_score": 5, "selected": true, "text": "<p>XHTML is easy, use <a href=\"http://lxml.de/validation.html\" rel=\"noreferrer\">lxml</a>.</p>\n\n<pre><code>from lxm...
2008/08/30
[ "https://Stackoverflow.com/questions/35538", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3594/" ]
What's the best way to go about validating that a document follows some version of HTML (prefereably that I can specify)? I'd like to be able to know where the failures occur, as in a web-based validator, except in a native Python app.
XHTML is easy, use [lxml](http://lxml.de/validation.html). ``` from lxml import etree from StringIO import StringIO etree.parse(StringIO(html), etree.HTMLParser(recover=False)) ``` HTML is harder, since there's traditionally not been as much interest in validation among the HTML crowd (run StackOverflow itself throu...
35,548
<p>I use this tool called <a href="http://www.lazycplusplus.com/" rel="nofollow noreferrer">Lazy C++</a> which breaks a single C++ .lzz file into a .h and .cpp file. I want <a href="http://makepp.sourceforge.net/" rel="nofollow noreferrer">Makepp</a> to expect both of these files to exist after my rule for building .lz...
[ { "answer_id": 35592, "author": "Tynan", "author_id": 3548, "author_profile": "https://Stackoverflow.com/users/3548", "pm_score": 3, "selected": true, "text": "<p>I've never used Makepp personally, but since it's a drop-in replacement for GNU Make, you should be able to do something like...
2008/08/30
[ "https://Stackoverflow.com/questions/35548", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3594/" ]
I use this tool called [Lazy C++](http://www.lazycplusplus.com/) which breaks a single C++ .lzz file into a .h and .cpp file. I want [Makepp](http://makepp.sourceforge.net/) to expect both of these files to exist after my rule for building .lzz files, but I'm not sure how to put two targets into a single build line.
I've never used Makepp personally, but since it's a drop-in replacement for GNU Make, you should be able to do something like: ``` build: foo.h foo.cpp g++ $(CFLAGS) foo.cpp -o $(LFLAGS) foo foo.h foo.cpp: foo.lzz lzz foo.lzz ``` Also not sure about the lzz invocation there, but that should help. You can read...
35,551
<p>In a project I'm working on FxCop shows me lots of (and I mean more than 400) errors on the InitializeComponent() methods generated by the Windows Forms designer. Most of those errors are just the assignment of the Text property of labels.</p> <p>I'd like to suppress those methods in source, so I copied the suppres...
[ { "answer_id": 35556, "author": "Matt Hamilton", "author_id": 615, "author_profile": "https://Stackoverflow.com/users/615", "pm_score": 5, "selected": true, "text": "<p>You've probably got the right code, but you also need to add CODE_ANALYSIS as a precompiler defined symbol in the proje...
2008/08/30
[ "https://Stackoverflow.com/questions/35551", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2148/" ]
In a project I'm working on FxCop shows me lots of (and I mean more than 400) errors on the InitializeComponent() methods generated by the Windows Forms designer. Most of those errors are just the assignment of the Text property of labels. I'd like to suppress those methods in source, so I copied the suppression code ...
You've probably got the right code, but you also need to add CODE\_ANALYSIS as a precompiler defined symbol in the project properties. I think those SuppressMessage attributes are only left in the compiled binaries if CODE\_ANALYSIS is defined.
35,699
<p>I'm trying to make a two-column page using a div-based layout (no tables please!). Problem is, I can't grow the left div to match the height of the right one. My right div typically has a lot of content. </p> <p>Here's a paired down example of my template to illustrate the problem.</p> <pre><code>&lt;div style="...
[ { "answer_id": 35711, "author": "DevelopingChris", "author_id": 1220, "author_profile": "https://Stackoverflow.com/users/1220", "pm_score": 3, "selected": false, "text": "<p>Your simplest answer lies in the next version of css (3), which currently no browser supports.</p>\n\n<p>For now y...
2008/08/30
[ "https://Stackoverflow.com/questions/35699", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3499/" ]
I'm trying to make a two-column page using a div-based layout (no tables please!). Problem is, I can't grow the left div to match the height of the right one. My right div typically has a lot of content. Here's a paired down example of my template to illustrate the problem. ``` <div style="float:left; width: 150px; ...
Use jQuery for this problem; just call this function in your ready function: ``` function setHeight(){ var height = $(document).height(); //optionally, subtract some from the height $("#leftDiv").css("height", height + "px"); } ```
35,743
<p>According to <a href="http://msdn.microsoft.com/en-us/library/bb386454.aspx" rel="noreferrer">Microsoft</a> the FileUpload control is not compatible with an AJAX UpdatePanel. </p> <p>I am aware that a PostBackTrigger can be added to the submit button of the form like this:</p> <pre><code>&lt;Triggers&gt; &lt;asp...
[ { "answer_id": 35754, "author": "sven", "author_id": 46, "author_profile": "https://Stackoverflow.com/users/46", "pm_score": 3, "selected": false, "text": "<p>I know of a third party component that can do that. It's called <a href=\"http://swfupload.org/\" rel=\"noreferrer\">\"<em>swfupl...
2008/08/30
[ "https://Stackoverflow.com/questions/35743", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3677/" ]
According to [Microsoft](http://msdn.microsoft.com/en-us/library/bb386454.aspx) the FileUpload control is not compatible with an AJAX UpdatePanel. I am aware that a PostBackTrigger can be added to the submit button of the form like this: ``` <Triggers> <asp:PostBackTrigger ControlID="Button1" /> </Triggers> ``` ...
I know of a third party component that can do that. It's called ["*swfupload*"](http://swfupload.org/) and is free to use and open source, and uses javascript and flash to do the magic. here is a list of the features they offer: (from their site) > > * Upload multiple files at once by ctrl/shift-selecting in dialog ...
35,782
<p>I need to produce a calculation trace file containing tabular data showing intermediate results. I am currently using a combination of the standard ascii pipe symbols (|) and dashes (-) to draw the table lines:</p> <p>E.g. </p> <pre><code>Numerator | Denominator | Result ----------|-------------|------- 6 ...
[ { "answer_id": 35784, "author": "Greg Hewgill", "author_id": 893, "author_profile": "https://Stackoverflow.com/users/893", "pm_score": 3, "selected": true, "text": "<p>There are <a href=\"http://www.unicode.org/charts/symbols.html\" rel=\"nofollow noreferrer\">Unicode box drawing charact...
2008/08/30
[ "https://Stackoverflow.com/questions/35782", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1131/" ]
I need to produce a calculation trace file containing tabular data showing intermediate results. I am currently using a combination of the standard ascii pipe symbols (|) and dashes (-) to draw the table lines: E.g. ``` Numerator | Denominator | Result ----------|-------------|------- 6 | 2 | ...
There are [Unicode box drawing characters](http://www.unicode.org/charts/symbols.html) (look for Box Drawing under Geometrical Symbols - the [chart itself](http://www.unicode.org/charts/PDF/U2500.pdf) is a PDF). I don't have any idea how widely supported those characters are, though.