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
409,916
<p>I'm creating a indoor navigation application (with the intention that a user can store maps for different buildings in the phones file system). The application starts up by asking the user to select a map for the desired building. Once this has been selected, a file parser would be used to parse and convert the map ...
[ { "answer_id": 410043, "author": "Honza", "author_id": 8621, "author_profile": "https://Stackoverflow.com/users/8621", "pm_score": 2, "selected": false, "text": "<p>Animated gifs are not supported in MIDP by default so if you really want to play an animated gif you need to use MMAPI for ...
2009/01/03
[ "https://Stackoverflow.com/questions/409916", "https://Stackoverflow.com", "https://Stackoverflow.com/users/51243/" ]
I'm creating a indoor navigation application (with the intention that a user can store maps for different buildings in the phones file system). The application starts up by asking the user to select a map for the desired building. Once this has been selected, a file parser would be used to parse and convert the map dat...
Animated gifs are not supported in MIDP by default so if you really want to play an animated gif you need to use MMAPI for that. I suggest you split up the animation into separate files and do the animation manualy. That is the most poratble way. This code lets you play an animated gif at the end ``` InputStream is =...
409,919
<p>I'm trying to work this out.</p> <p>In my project, i have a file called 'Hello.java' which is the file with the main() argument and which is called when the program is compiled. And I have another file called MyObj.java which has got just a random class I made up to test java's OO features. I'm trying to do this:</...
[ { "answer_id": 409927, "author": "Ross", "author_id": 29173, "author_profile": "https://Stackoverflow.com/users/29173", "pm_score": 5, "selected": true, "text": "<p>You can either add \"static\" to the member variable as well, or instantiate the class from within your main method. Here i...
2009/01/03
[ "https://Stackoverflow.com/questions/409919", "https://Stackoverflow.com", "https://Stackoverflow.com/users/49153/" ]
I'm trying to work this out. In my project, i have a file called 'Hello.java' which is the file with the main() argument and which is called when the program is compiled. And I have another file called MyObj.java which has got just a random class I made up to test java's OO features. I'm trying to do this: ``` class ...
You can either add "static" to the member variable as well, or instantiate the class from within your main method. Here is some example code for both approaches: ``` /* Static */ class Hello { public static MyObj an_obj; public static void main(String[] args) { setObj(); } public s...
409,945
<p>How, being inside the main form of my WinForm app can I tell if there are any modal windows/dialogs open that belong to the main form?</p>
[ { "answer_id": 409989, "author": "Juliet", "author_id": 40516, "author_profile": "https://Stackoverflow.com/users/40516", "pm_score": 3, "selected": false, "text": "<p>Long story short: opening a modal form is blocks execution on the main form as long as the modal window is open, so your...
2009/01/03
[ "https://Stackoverflow.com/questions/409945", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18046/" ]
How, being inside the main form of my WinForm app can I tell if there are any modal windows/dialogs open that belong to the main form?
``` if (this.Visible && !this.CanFocus) { // modal child windows are open } ```
409,949
<p>I've been using mutagen for reading and writing MP3 tags, but I want to be able to embed album art directly into the file.</p>
[ { "answer_id": 409988, "author": "Andrew Cox", "author_id": 27907, "author_profile": "https://Stackoverflow.com/users/27907", "pm_score": 2, "selected": false, "text": "<p>Looks like you have to add a special type of frame to the MP3. See the site on <a href=\"http://www.id3.org/id3v2.3...
2009/01/03
[ "https://Stackoverflow.com/questions/409949", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I've been using mutagen for reading and writing MP3 tags, but I want to be able to embed album art directly into the file.
Here is how to add example.png as album cover into example.mp3 with mutagen: ``` from mutagen.mp3 import MP3 from mutagen.id3 import ID3, APIC, error audio = MP3('example.mp3', ID3=ID3) # add ID3 tag if it doesn't exist try: audio.add_tags() except error: pass audio.tags.add( APIC( encoding=3, #...
409,955
<p>Does heavy use of unit tests discourage the use of debug asserts? It seems like a debug assert firing in the code under test implies the unit test shouldn't exist or the debug assert shouldn't exist. "There can be only one" seems like a reasonable principle. Is this the common practice? Or do you disable your debu...
[ { "answer_id": 409972, "author": "Andrew Grant", "author_id": 1043, "author_profile": "https://Stackoverflow.com/users/1043", "pm_score": 2, "selected": false, "text": "<p>A good unit test setup will have the ability to catch asserts. If an assert is triggered the current test should fai...
2009/01/03
[ "https://Stackoverflow.com/questions/409955", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3892/" ]
Does heavy use of unit tests discourage the use of debug asserts? It seems like a debug assert firing in the code under test implies the unit test shouldn't exist or the debug assert shouldn't exist. "There can be only one" seems like a reasonable principle. Is this the common practice? Or do you disable your debug ass...
This is a perfectly valid question. First of all, many people are suggesting that you are using assertions wrongly. I think many debugging experts would disagree. Although it is good practice to check invariants with assertions, assertions shouldn't be limited to state invariants. In fact, many expert debuggers will t...
409,991
<p>I am trying to execute this SQL command:</p> <pre><code>SELECT page.page_namespace, pagelinks.pl_namespace, COUNT(*) FROM page, pagelinks WHERE (page.page_namespace &lt;=3 OR page.page_namespace = 12 OR page.page_namespace = 13 ) AND (pagelinks.pl_namespace &...
[ { "answer_id": 410037, "author": "Peter Becker", "author_id": 19820, "author_profile": "https://Stackoverflow.com/users/19820", "pm_score": 0, "selected": false, "text": "<p>I'm not really an expert, but my understanding of that message is that PostgreSQL compains about not being able to...
2009/01/03
[ "https://Stackoverflow.com/questions/409991", "https://Stackoverflow.com", "https://Stackoverflow.com/users/49985/" ]
I am trying to execute this SQL command: ``` SELECT page.page_namespace, pagelinks.pl_namespace, COUNT(*) FROM page, pagelinks WHERE (page.page_namespace <=3 OR page.page_namespace = 12 OR page.page_namespace = 13 ) AND (pagelinks.pl_namespace <=3 OR pagelinks.p...
I haven't checked any documentation but the fact that you have your `GROUP BY` expression in parentheses looks unusual to me. What happens if you don't use parentheses here?
409,995
<p>How would I truncate a sentence at a certain character:</p> <p>$sentence = 'Stack Overflow - Ask Questions Here';</p> <p>so that only the following is echoed:</p> <p>Stack Overflow</p> <p>The character count varies, but the stop point is always "Space Dash Space"</p>
[ { "answer_id": 410032, "author": "Robert Gamble", "author_id": 25222, "author_profile": "https://Stackoverflow.com/users/25222", "pm_score": 0, "selected": false, "text": "<p>Although you didn't mention a language, I am going to guess Perl due to the <code>$variable</code> name. In Perl...
2009/01/03
[ "https://Stackoverflow.com/questions/409995", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
How would I truncate a sentence at a certain character: $sentence = 'Stack Overflow - Ask Questions Here'; so that only the following is echoed: Stack Overflow The character count varies, but the stop point is always "Space Dash Space"
If using python a non-regexp approach would be: ``` >>> s = 'Stack Overflow - Ask Questions Here' >>> s.split(' - ') ['Stack Overflow', 'Ask Questions Here'] >>> # To get the substring before the match >>> s.split(' - ')[0] 'Stack Overflow' ``` A regexp approach might be: ``` >>> import re >>> re.split(' ...
409,999
<p>I want to retrieve information like the city, state, and country of a visitor from their IP address, so that I can customize my web page according to their location. Is there a good and reliable way to do this in PHP? I am using JavaScript for client-side scripting, PHP for server-side scripting, and MySQL for the d...
[ { "answer_id": 410006, "author": "null", "author_id": 25411, "author_profile": "https://Stackoverflow.com/users/25411", "pm_score": 4, "selected": false, "text": "<p>You need to use an external service... such as <a href=\"http://www.hostip.info/\" rel=\"noreferrer\">http://www.hostip.in...
2009/01/03
[ "https://Stackoverflow.com/questions/409999", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I want to retrieve information like the city, state, and country of a visitor from their IP address, so that I can customize my web page according to their location. Is there a good and reliable way to do this in PHP? I am using JavaScript for client-side scripting, PHP for server-side scripting, and MySQL for the data...
You could download a free GeoIP database and lookup the IP address locally, or you could use a third party service and perform a remote lookup. This is the simpler option, as it requires no setup, but it does introduce additional latency. One third party service you could use is mine, <http://ipinfo.io>. They provide...
410,002
<p>PHP has the habit of evaluating (int)0 and (string)"0" as empty when using the <code>empty()</code> function. This can have unintended results if you expect numerical or string values of 0. How can I "fix" it to only return true to empty objects, arrays, strings, etc?</p>
[ { "answer_id": 410003, "author": "null", "author_id": 25411, "author_profile": "https://Stackoverflow.com/users/25411", "pm_score": 0, "selected": false, "text": "<p>I created an <code>IsEmpty()</code> a terse quick function.</p>\n\n<pre><code>function IsEmpty($mData) {\n return is_in...
2009/01/03
[ "https://Stackoverflow.com/questions/410002", "https://Stackoverflow.com", "https://Stackoverflow.com/users/25411/" ]
PHP has the habit of evaluating (int)0 and (string)"0" as empty when using the `empty()` function. This can have unintended results if you expect numerical or string values of 0. How can I "fix" it to only return true to empty objects, arrays, strings, etc?
This didn't work for me. ``` if (empty($variable) && '0' != $variable) { // Do something } ``` I used instead: ``` if (empty($variable) && strlen($variable) == 0) { // Do something } ```
410,005
<p>I'm relatively new to the Component Object Model specification - I have a simple question:</p> <ul> <li> How can I access a <b>COM interface</b> from a C or C++ application </ul> <p>For instance, accessing Microsoft Excel COM interface to perform basic operations, without user intervention.</p> <p>Kind regards</...
[ { "answer_id": 410003, "author": "null", "author_id": 25411, "author_profile": "https://Stackoverflow.com/users/25411", "pm_score": 0, "selected": false, "text": "<p>I created an <code>IsEmpty()</code> a terse quick function.</p>\n\n<pre><code>function IsEmpty($mData) {\n return is_in...
2009/01/03
[ "https://Stackoverflow.com/questions/410005", "https://Stackoverflow.com", "https://Stackoverflow.com/users/51078/" ]
I'm relatively new to the Component Object Model specification - I have a simple question: * How can I access a **COM interface** from a C or C++ application For instance, accessing Microsoft Excel COM interface to perform basic operations, without user intervention. Kind regards
This didn't work for me. ``` if (empty($variable) && '0' != $variable) { // Do something } ``` I used instead: ``` if (empty($variable) && strlen($variable) == 0) { // Do something } ```
410,011
<p>Right now in Flash CS3 and up (using Actionscript 3) if you have the same instance that is used in multiple keyframes in a layer, and you decide to assign or change the instance name later, you would have to go to each keyframe and set the instance name. This is a big nuisance. Is there a quicker or better way to ...
[ { "answer_id": 410488, "author": "Robin Rodricks", "author_id": 41021, "author_profile": "https://Stackoverflow.com/users/41021", "pm_score": 0, "selected": false, "text": "<p>Name your instances <strong>before</strong> copying them to multiple keyframes! <em>(before pressing F6 - Insert...
2009/01/03
[ "https://Stackoverflow.com/questions/410011", "https://Stackoverflow.com", "https://Stackoverflow.com/users/51258/" ]
Right now in Flash CS3 and up (using Actionscript 3) if you have the same instance that is used in multiple keyframes in a layer, and you decide to assign or change the instance name later, you would have to go to each keyframe and set the instance name. This is a big nuisance. Is there a quicker or better way to do th...
You can use JSFL, a javascript-based automation lanaguage in Flash, to automate tasks like this. * Click File > New * Select "Flash JavaScript File" from the list * Paste the following script * Make sure you have your instances selected in your FLA file * Click the Run (Play) button in your JSFL script file You can t...
410,026
<p>The <a href="https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/yield" rel="noreferrer">yield</a> keyword is one of those <a href="https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/" rel="noreferrer">keywords</a> in C# that continues to mystify me, and I've never be...
[ { "answer_id": 410047, "author": "petr k.", "author_id": 15497, "author_profile": "https://Stackoverflow.com/users/15497", "pm_score": 3, "selected": false, "text": "<p>And what about this?</p>\n\n<pre><code>public static IEnumerable&lt;Product&gt; GetAllProducts()\n{\n using (Adventu...
2009/01/03
[ "https://Stackoverflow.com/questions/410026", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10792/" ]
The [yield](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/yield) keyword is one of those [keywords](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/keywords/) in C# that continues to mystify me, and I've never been confident that I'm using it correctly. Of the following...
I tend to use yield-return when I calculate the next item in the list (or even the next group of items). Using your Version 2, you must have the complete list before returning. By using yield-return, you really only need to have the next item before returning. Among other things, this helps spread the computational ...
410,027
<p>This isn't specifically a general programming question but a lot of textmate users I know end up building a textmate command to do something they often do but as it's on it's own never really release it. Mines Below:</p> <p><strong>Objective-C Build and Run</strong></p> <p>For when I'm just quickly writing a small...
[ { "answer_id": 410056, "author": "dlfnation", "author_id": 47555, "author_profile": "https://Stackoverflow.com/users/47555", "pm_score": 2, "selected": false, "text": "<p>The only real TextMate enhancement I use (other than language bundles) the <a href=\"http://ciaranwal.sh/projectplus\...
2009/01/03
[ "https://Stackoverflow.com/questions/410027", "https://Stackoverflow.com", "https://Stackoverflow.com/users/313002/" ]
This isn't specifically a general programming question but a lot of textmate users I know end up building a textmate command to do something they often do but as it's on it's own never really release it. Mines Below: **Objective-C Build and Run** For when I'm just quickly writing a small Objective-C command line prog...
The only real TextMate enhancement I use (other than language bundles) the [ProjectPlus](http://ciaranwal.sh/projectplus) plug-in. It replaces the annoying project drawer with a project panel, adds support for SVN, Git, Mercurial, Bazaar and Svk, and adds lots of other small stuff. Here's the feature list from the pr...
410,062
<p>Functions in Python can be called using keyword arguments of the form keyword = value. For instance, the following function:</p> <pre><code>def parrot(voltage, state='a stiff', action='voom', type='Norwegian Blue'): print "-- This parrot wouldn't", action, print "if you put", voltage, "volts through it." ...
[ { "answer_id": 410079, "author": "Brandon", "author_id": 23133, "author_profile": "https://Stackoverflow.com/users/23133", "pm_score": 0, "selected": false, "text": "<p>You could implement something similar using variable number of arguments to a function shown <a href=\"http://www.flex8...
2009/01/03
[ "https://Stackoverflow.com/questions/410062", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
Functions in Python can be called using keyword arguments of the form keyword = value. For instance, the following function: ``` def parrot(voltage, state='a stiff', action='voom', type='Norwegian Blue'): print "-- This parrot wouldn't", action, print "if you put", voltage, "volts through it." print "-- Lo...
It won't throw any errors at compile time if you mess up but you could do something like this: ``` public function awesomefunction(input:Object):void { if (input.foo) trace("got foo"); if (input.bar) trace("got bar"); } ``` And then when calling it doing like this: ``` awesomefunction( { foo : 23, bar : 99 ...
410,073
<p>I've seen many questions about this, but i've never really got the answer that I need. </p> <p>I'm converting a fairly large web application from Web Forms to MVC and after a while I encountred a problem with passing data to the view. In the Action I execute the code: </p> <p><code>//This is just an example ViewDa...
[ { "answer_id": 410139, "author": "ccook", "author_id": 51275, "author_profile": "https://Stackoverflow.com/users/51275", "pm_score": 1, "selected": false, "text": "<p>Consider explicitly converting to a list and casting the ViewData:</p>\n\n<pre><code>ViewData[\"QUsers\"] = (from u in db...
2009/01/03
[ "https://Stackoverflow.com/questions/410073", "https://Stackoverflow.com", "https://Stackoverflow.com/users/51269/" ]
I've seen many questions about this, but i've never really got the answer that I need. I'm converting a fairly large web application from Web Forms to MVC and after a while I encountred a problem with passing data to the view. In the Action I execute the code: `//This is just an example ViewData["QProducts"] = from...
Rather than an anonymous type, create a type to hold the name and date: ``` public class NameDate { public string Name { get; set; } public DateTime Date { get; set; } } ``` Then use that in your Linq query: ``` from p in db.Products select new NameDate { Name = p.Name, Date = p.Date } ``` Strongly type your ...
410,089
<p>How do I append the previous item in array to the next item in the array for unknown number of items?</p> <p>Here is what I'm trying to do. I have a string containing an LDAP path such as "OU=3,OU=2,OU=1,DC=Internal,DC=Net", I want to create each container in the above LDAP path so from the above string I need to c...
[ { "answer_id": 410117, "author": "JaredPar", "author_id": 23283, "author_profile": "https://Stackoverflow.com/users/23283", "pm_score": 0, "selected": false, "text": "<p>If the string will always end with \",DC=Internal,DC=Net\", the following solution should get you going.</p>\n\n<pre><...
2009/01/03
[ "https://Stackoverflow.com/questions/410089", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
How do I append the previous item in array to the next item in the array for unknown number of items? Here is what I'm trying to do. I have a string containing an LDAP path such as "OU=3,OU=2,OU=1,DC=Internal,DC=Net", I want to create each container in the above LDAP path so from the above string I need to create an a...
I'm not sure I understood correctly. Do you need something like this: ``` string input = "OU=3,OU=2,OU=1,DC=Internal,DC=Net"; string[] split = input.Split(','); string path = ""; for (int i=split.Length-1; i>=0; i--) { path = ((path == "") ? split[i] : split[i] + "," + path); if (path.StartsWith("OU")) ...
410,109
<p>Are there any helper libs to read a cookie file in php. I have a cookie file on my local disk and I would like a better way of reading it. I am currently just reading to file like by line and parsing out the values.</p>
[ { "answer_id": 410159, "author": "null", "author_id": 25411, "author_profile": "https://Stackoverflow.com/users/25411", "pm_score": 0, "selected": false, "text": "<p>I think $_COOKIE is what your looking for.</p>\n\n<p>This superglobal can be used to read cookie data... to set it you nee...
2009/01/03
[ "https://Stackoverflow.com/questions/410109", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
Are there any helper libs to read a cookie file in php. I have a cookie file on my local disk and I would like a better way of reading it. I am currently just reading to file like by line and parsing out the values.
This is pretty simple if you aim to read Netscape's format (e.g. curl saves cookies in COOKIEJAR in this format). First an example (pipes and line numbers are added here and do not occur in real file): ``` 01 | # Netscape HTTP Cookie File 02 | # http://curl.haxx.se/rfc/cookie_spec.html 03 | # This file was generated ...
410,150
<p>I came across a site that demonstrated a Javascript library and it asked that you please not link to the Javascript file directly from your site. That's a reasonable request. In fact, it wouldn't have occurred to me to do that instead of hosting it myself but I guess will try and save on bandwidth any way they can...
[ { "answer_id": 410162, "author": "Salty", "author_id": 50548, "author_profile": "https://Stackoverflow.com/users/50548", "pm_score": 1, "selected": false, "text": "<p><a href=\"http://www.cyberciti.biz/faq/apache-mod_rewrite-hot-linking-images-leeching-howto/\" rel=\"nofollow noreferrer\...
2009/01/04
[ "https://Stackoverflow.com/questions/410150", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18393/" ]
I came across a site that demonstrated a Javascript library and it asked that you please not link to the Javascript file directly from your site. That's a reasonable request. In fact, it wouldn't have occurred to me to do that instead of hosting it myself but I guess will try and save on bandwidth any way they can. Th...
Using an htaccess file you can do this. Simply create a .htaccess file in the directory of the files you wish to protect with the following inside it: ``` RewriteEngine on RewriteCond %{HTTP_REFERER} !^$ RewriteCond %{HTTP_REFERER} !^http://(www\.)?yourdomain.com(/)?.*$ [NC] ``` For more information and some other ...
410,186
<p>I have found some info on the subject (<a href="http://rubylearning.com/satishtalim/object_serialization.html" rel="noreferrer">like this link)</a>, but nothing that tells me how it actually works under the covers. If you don't want to read the essay below, here are the real questions:</p> <ol> <li><p>How should I...
[ { "answer_id": 410290, "author": "Chuck", "author_id": 50742, "author_profile": "https://Stackoverflow.com/users/50742", "pm_score": 4, "selected": true, "text": "<p>The Ruby marshalling methods store the type of the object they're encoding. The way those two hooks work is like this:</p>...
2009/01/04
[ "https://Stackoverflow.com/questions/410186", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1053/" ]
I have found some info on the subject ([like this link)](http://rubylearning.com/satishtalim/object_serialization.html), but nothing that tells me how it actually works under the covers. If you don't want to read the essay below, here are the real questions: 1. How should I implement the `marshal_dump` and `marshal_lo...
The Ruby marshalling methods store the type of the object they're encoding. The way those two hooks work is like this: * `marshal_dump` has to return some data describing the state of your object. Ruby couldn't care less about the format of this data — it just has to be something that your `marshal_load` method can us...
410,221
<p>I'd like a way to show natural times for dated items in Python. Similar to how Twitter will show a message from "a moment ago", "a few minutes ago", "two hours ago", "three days ago", etc.</p> <p>Django 1.0 has a "humanize" method in django.contrib. I'm not using the Django framework, and even if I were, it's more ...
[ { "answer_id": 410328, "author": "lpfavreau", "author_id": 35935, "author_profile": "https://Stackoverflow.com/users/35935", "pm_score": 3, "selected": false, "text": "<p>Are you looking for <a href=\"http://jehiah.cz/archive/printing-relative-dates-in-python\" rel=\"nofollow noreferrer\...
2009/01/04
[ "https://Stackoverflow.com/questions/410221", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9106/" ]
I'd like a way to show natural times for dated items in Python. Similar to how Twitter will show a message from "a moment ago", "a few minutes ago", "two hours ago", "three days ago", etc. Django 1.0 has a "humanize" method in django.contrib. I'm not using the Django framework, and even if I were, it's more limited th...
While not useful to you at this very moment, it may be so for future searchers: The babel module, which deals with all sorts of locale stuff, has a function for doing more or less what you want. Currently it's only in their trunk though, not in the latest public release (version 0.9.4). Once the functionality lands in ...
410,222
<p>I know that a lot of examples exist where a SqlConnection is defined and then a SqlCommand is defined, both in Using blocks:</p> <pre><code>using (var conn = new SqlConnection(connString)) { using (var cmd = new SqlCommand()) { cmd.Connection = conn; //open the connection } } </code></pr...
[ { "answer_id": 410229, "author": "Robert C. Barth", "author_id": 9209, "author_profile": "https://Stackoverflow.com/users/9209", "pm_score": 5, "selected": true, "text": "<p>No, SqlCommand never attempts to close/dispose of the connection.</p>\n" }, { "answer_id": 410232, "au...
2009/01/04
[ "https://Stackoverflow.com/questions/410222", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10104/" ]
I know that a lot of examples exist where a SqlConnection is defined and then a SqlCommand is defined, both in Using blocks: ``` using (var conn = new SqlConnection(connString)) { using (var cmd = new SqlCommand()) { cmd.Connection = conn; //open the connection } } ``` My question: If I d...
No, SqlCommand never attempts to close/dispose of the connection.
410,227
<p>What is the simplest way of testing if an object implements a given interface in C#? (Answer to this question <a href="https://stackoverflow.com/questions/766106/test-if-object-implements-interface">in Java</a>)</p>
[ { "answer_id": 410230, "author": "Robert C. Barth", "author_id": 9209, "author_profile": "https://Stackoverflow.com/users/9209", "pm_score": 10, "selected": true, "text": "<pre><code>if (object is IBlah)\n</code></pre>\n\n<p>or</p>\n\n<pre><code>IBlah myTest = originalObject as IBlah\n\n...
2009/01/04
[ "https://Stackoverflow.com/questions/410227", "https://Stackoverflow.com", "https://Stackoverflow.com/users/23276/" ]
What is the simplest way of testing if an object implements a given interface in C#? (Answer to this question [in Java](https://stackoverflow.com/questions/766106/test-if-object-implements-interface))
``` if (object is IBlah) ``` or ``` IBlah myTest = originalObject as IBlah if (myTest != null) ```
410,236
<p>When overriding the equals() function of java.lang.Object, the javadocs suggest that, </p> <blockquote> <p>it is generally necessary to override the hashCode method whenever this method is overridden, so as to maintain the general contract for the hashCode method, which states that equal objects must have equal ...
[ { "answer_id": 410246, "author": "Marc Novakowski", "author_id": 27020, "author_profile": "https://Stackoverflow.com/users/27020", "pm_score": 6, "selected": true, "text": "<p>It doesn't say the hashcode for an object has to be completely unique, only that the hashcode for two equal obje...
2009/01/04
[ "https://Stackoverflow.com/questions/410236", "https://Stackoverflow.com", "https://Stackoverflow.com/users/48728/" ]
When overriding the equals() function of java.lang.Object, the javadocs suggest that, > > it is generally necessary to override the hashCode method whenever this method is overridden, so as to maintain the general contract for the hashCode method, which states that equal objects must have equal hash codes. > > > ...
It doesn't say the hashcode for an object has to be completely unique, only that the hashcode for two equal objects returns the same hashcode. It's entirely legal to have two non-equal objects return the same hashcode. However, the more unique a hashcode distribution is over a set of objects, the better performance you...
410,243
<p>I have my MySQL database server on Server 1. I want to have my Rails apps on two other servers - say A and B to be able to connect to this Server 1. What's the best way to do this?</p> <p>In the my.cnf file it appears I can use the bind-address to bind to one and only one IP address. I can't specify the IP addresse...
[ { "answer_id": 410244, "author": "Michael Haren", "author_id": 29, "author_profile": "https://Stackoverflow.com/users/29", "pm_score": 2, "selected": false, "text": "<p>The bind address is the local IP address of the <em>server</em>, not the allowable client addresses. In your situation,...
2009/01/04
[ "https://Stackoverflow.com/questions/410243", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I have my MySQL database server on Server 1. I want to have my Rails apps on two other servers - say A and B to be able to connect to this Server 1. What's the best way to do this? In the my.cnf file it appears I can use the bind-address to bind to one and only one IP address. I can't specify the IP addresses of both ...
If MySQL is running on Linux: I am very biased towards using iptables (a.k.a. netfilter, the Linux firewall) to control incoming traffic to various ports. It's simple to use and very robust. ``` iptables -A INPUT -p tcp -s server1address/32 --dport 3306 -j ACCEPT iptables -A INPUT -p tcp -s server2address/32 --dport ...
410,253
<p>We have an embedded device that needs to interact with an enterprise software system. </p> <p>The enterprise system currently uses many different mechanisms for communication between its components: ODBC, RPC, proprietary protocol over TCP/IP, and is moving to .Net-implmented web services.</p> <p>The embedded dev...
[ { "answer_id": 410244, "author": "Michael Haren", "author_id": 29, "author_profile": "https://Stackoverflow.com/users/29", "pm_score": 2, "selected": false, "text": "<p>The bind address is the local IP address of the <em>server</em>, not the allowable client addresses. In your situation,...
2009/01/04
[ "https://Stackoverflow.com/questions/410253", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12570/" ]
We have an embedded device that needs to interact with an enterprise software system. The enterprise system currently uses many different mechanisms for communication between its components: ODBC, RPC, proprietary protocol over TCP/IP, and is moving to .Net-implmented web services. The embedded device runs a flavor ...
If MySQL is running on Linux: I am very biased towards using iptables (a.k.a. netfilter, the Linux firewall) to control incoming traffic to various ports. It's simple to use and very robust. ``` iptables -A INPUT -p tcp -s server1address/32 --dport 3306 -j ACCEPT iptables -A INPUT -p tcp -s server2address/32 --dport ...
410,270
<p>Or should you always create some other lock object?</p>
[ { "answer_id": 410274, "author": "Michael Haren", "author_id": 29, "author_profile": "https://Stackoverflow.com/users/29", "pm_score": 5, "selected": true, "text": "<p>Yes, cast it to an IDictionary and lock on <code>.SyncRoot</code>:</p>\n\n<pre><code>Generic.Dictionary&lt;int, int&gt; ...
2009/01/04
[ "https://Stackoverflow.com/questions/410270", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4653/" ]
Or should you always create some other lock object?
Yes, cast it to an IDictionary and lock on `.SyncRoot`: ``` Generic.Dictionary<int, int> dic = new Generic.Dictionary<int, int>(); lock (((IDictionary)dic).SyncRoot) { // code } ``` Thanks to this [source](http://en.csharp-online.net/CSharp_Generics_Recipes%E2%80%94Replacing_the_Hashtable_with_Its_Generic_Count...
410,278
<p>There are methods to transfer a CGPoint from one UIView to another and from one CALayer to another. I cannot find a way to change a CGPoint from a UIView's coordinate system to a CALayer's coordinate system. </p> <p>Does a layer and it's host view have the same coordinate system? Do I need to transform points bet...
[ { "answer_id": 411951, "author": "Lily Ballard", "author_id": 582, "author_profile": "https://Stackoverflow.com/users/582", "pm_score": 0, "selected": false, "text": "<p>I believe the coordinate system of a UIView and its associated layer should be the same. However, if you create layers...
2009/01/04
[ "https://Stackoverflow.com/questions/410278", "https://Stackoverflow.com", "https://Stackoverflow.com/users/48311/" ]
There are methods to transfer a CGPoint from one UIView to another and from one CALayer to another. I cannot find a way to change a CGPoint from a UIView's coordinate system to a CALayer's coordinate system. Does a layer and it's host view have the same coordinate system? Do I need to transform points between them? ...
You can set the `transform` property of CALayers to the appropriate transform if you want to flip their coordinate system, but note that this will probably flip their drawing of the `contents` as well (I have not tested that, but it makes sense that this would be true). My assertion that the CALayer associated with a U...
410,313
<p>I would like to render to an offscreen bitmap (or array of RGBA values) and then blit those to a <code>UIView</code> during in the view's <code>drawRect</code> function. I would prefer to do full 32-bit rendering (including alpha channel), but would also be content with 24-bit rendering.</p> <p>Would anyone mind po...
[ { "answer_id": 410473, "author": "phi", "author_id": 45890, "author_profile": "https://Stackoverflow.com/users/45890", "pm_score": 2, "selected": false, "text": "<p>You can use a <a href=\"http://developer.apple.com/documentation/GraphicsImaging/Reference/CGBitmapContext/Reference/refere...
2009/01/04
[ "https://Stackoverflow.com/questions/410313", "https://Stackoverflow.com", "https://Stackoverflow.com/users/338/" ]
I would like to render to an offscreen bitmap (or array of RGBA values) and then blit those to a `UIView` during in the view's `drawRect` function. I would prefer to do full 32-bit rendering (including alpha channel), but would also be content with 24-bit rendering. Would anyone mind pointing me in the right direction...
To render into an offscreen context and save it as a CGImageRef: ``` void *bitmapData = calloc(height, bytesPerLine); CGContextRef offscreen = CGBitmapContextCreate(..., bitmapData, ...) // draw stuff into offscreen CGImageRef image = CGBitmapContextCreateImage(offscreen); CFRelease(offscreen); free(bitmapData); ``` ...
410,324
<p>Is there a way I can write text to a file from a certain point in the file?</p> <p>For example, I open a file of 10 lines of text but I want to write a line of text to the 5th line.</p> <p>I guess one way is to get the lines of text in the file back as an array using the readalllines method, and then add a line at...
[ { "answer_id": 410331, "author": "cletus", "author_id": 18393, "author_profile": "https://Stackoverflow.com/users/18393", "pm_score": 2, "selected": false, "text": "<p>If you're reading/writing small files (say, under 20 megabytes--yes I consider 20M \"small\") and not writing them that ...
2009/01/04
[ "https://Stackoverflow.com/questions/410324", "https://Stackoverflow.com", "https://Stackoverflow.com/users/32484/" ]
Is there a way I can write text to a file from a certain point in the file? For example, I open a file of 10 lines of text but I want to write a line of text to the 5th line. I guess one way is to get the lines of text in the file back as an array using the readalllines method, and then add a line at a certain index ...
Oh, sigh. Look up the "master file update" algorithm. here's pseudocode: ``` open master file for reading. count := 0 while not EOF do read line from master file into buffer write line to output file count := count + 1 if count = 5 then write added line to output file fi od rename outpu...
410,343
<p>I have a generic Callback object which provides a (primitive) callback capability for Java, in the absence of closures. The Callback object contains a Method, and returns the parameter and return types for the method via a couple of accessor methods that just delegate to the equivalent methods in Method.</p> <p>I ...
[ { "answer_id": 410352, "author": "Apocalisp", "author_id": 3434, "author_profile": "https://Stackoverflow.com/users/3434", "pm_score": 1, "selected": false, "text": "<p>Why not have the compiler do it?</p>\n\n<pre><code>public interface F&lt;A, B&gt; {\n public B $(A a);\n}\n</code></p...
2009/01/04
[ "https://Stackoverflow.com/questions/410343", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8946/" ]
I have a generic Callback object which provides a (primitive) callback capability for Java, in the absence of closures. The Callback object contains a Method, and returns the parameter and return types for the method via a couple of accessor methods that just delegate to the equivalent methods in Method. I am trying t...
Looking more closely at the documentation for Class.isAssignableFrom(), it specifically states that the types for a primitive do not match any class except themselves. So I will need to specifically check for == equality to Byte.TYPE, Double.TYPE, Float.TYPE, Integer.TYPE, Long.TYPE, and Short.TYPE for the return type.
410,355
<p>I have a model, Thing, that has a has_many with ThingPhoto, using Paperclip to manage everything. On the "show" view for Thing, I want to have a file upload, and have it relate to the Thing model.</p> <p>For some reason, I'm totally glitching on how this should be done. I've tried doing this (Haml):</p> <pre><code...
[ { "answer_id": 410371, "author": "zenazn", "author_id": 46848, "author_profile": "https://Stackoverflow.com/users/46848", "pm_score": 0, "selected": false, "text": "<p>If you're not tied to Paperclip (and if you're just doing images), I've had a <em>lot</em> of luck with <a href=\"http:/...
2009/01/04
[ "https://Stackoverflow.com/questions/410355", "https://Stackoverflow.com", "https://Stackoverflow.com/users/722/" ]
I have a model, Thing, that has a has\_many with ThingPhoto, using Paperclip to manage everything. On the "show" view for Thing, I want to have a file upload, and have it relate to the Thing model. For some reason, I'm totally glitching on how this should be done. I've tried doing this (Haml): ``` - form_for @thing.t...
try `@thing.thing_photos.new` this should instance a new model of thing\_photos. If you're not using nested routes you'll have to add the thing\_id as a hidden field.
410,411
<p>I'm writing a sidebar extension for Firefox and need a way to get the URL of the current page so I can check it against a database and display the results. How can I do this?</p>
[ { "answer_id": 410915, "author": "wimh", "author_id": 33499, "author_profile": "https://Stackoverflow.com/users/33499", "pm_score": 5, "selected": true, "text": "<pre><code>window.top.getBrowser().selectedBrowser.contentWindow.location.href;\n</code></pre>\n\n<p>might work, otherwise I t...
2009/01/04
[ "https://Stackoverflow.com/questions/410411", "https://Stackoverflow.com", "https://Stackoverflow.com/users/51310/" ]
I'm writing a sidebar extension for Firefox and need a way to get the URL of the current page so I can check it against a database and display the results. How can I do this?
``` window.top.getBrowser().selectedBrowser.contentWindow.location.href; ``` might work, otherwise I think you need to use: ``` var mainWindow = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor) .getInterface(Components.interfaces.nsIWebNavigation) .QueryInterfa...
410,417
<p>I was looking through my code and I found a couple of extension methods that I wrote in order to remove items from a System.Collections.Generic.Stack. I was curious, so I looked at the source of Stack with Reflector and I can see that they implemented it as an array instead of a linked list and I'm just wondering wh...
[ { "answer_id": 410432, "author": "commondream", "author_id": 50156, "author_profile": "https://Stackoverflow.com/users/50156", "pm_score": 2, "selected": false, "text": "<p>When you run benchmarks, you end up almost always end up seeing huge performance benefit in Array because of locali...
2009/01/04
[ "https://Stackoverflow.com/questions/410417", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16387/" ]
I was looking through my code and I found a couple of extension methods that I wrote in order to remove items from a System.Collections.Generic.Stack. I was curious, so I looked at the source of Stack with Reflector and I can see that they implemented it as an array instead of a linked list and I'm just wondering why? ...
Consider the size of a `Stack<byte>` with 1,000,000 items. * With an array, size ~= 1,000,000 bytes. Usually more due to spare capacity, but probably not more than double. * With a linked list, each entry needs its own object, the data itself, and at least one reference (for a singly-linked list, which is probably all...
410,450
<p>Archaelus suggested in <a href="https://stackoverflow.com/questions/383407/what-are-some-interesting-projects-to-solve-in-erlang-for-learning-purposes#383456">this post</a> that writing a new format routine to handle named parameters may be a good learning exercise. So, in the spirit of learning the language I wrote...
[ { "answer_id": 410515, "author": "Doug Currie", "author_id": 33252, "author_profile": "https://Stackoverflow.com/users/33252", "pm_score": 3, "selected": true, "text": "<p>Without comment on the algorithm, or on use of appropriate library functions... </p>\n\n<p>I would have expected to ...
2009/01/04
[ "https://Stackoverflow.com/questions/410450", "https://Stackoverflow.com", "https://Stackoverflow.com/users/42050/" ]
Archaelus suggested in [this post](https://stackoverflow.com/questions/383407/what-are-some-interesting-projects-to-solve-in-erlang-for-learning-purposes#383456) that writing a new format routine to handle named parameters may be a good learning exercise. So, in the spirit of learning the language I wrote a formatting ...
Without comment on the algorithm, or on use of appropriate library functions... I would have expected to see more use of pattern matching and recursion; for example parse\_character (no longer folded) might be replaced with something like: ``` parse_in_format ([], FmtStr, ParmStrs, ParmName) -> {FmtStr, ParmStrs}; p...
410,469
<p>I want to spawn another process to display an error message asynchronously while the rest of the application continues. </p> <p>I'm using the <code>multiprocessing</code> module in Python 2.6 to create the process and I'm trying to display the window with <code>TKinter</code>. </p> <p>This code worked okay on Wind...
[ { "answer_id": 410587, "author": "Nicholas Leonard", "author_id": 49985, "author_profile": "https://Stackoverflow.com/users/49985", "pm_score": 0, "selected": false, "text": "<p>Maybe calling the shell command <code>xhost +</code> before calling your program from that same shell will wor...
2009/01/04
[ "https://Stackoverflow.com/questions/410469", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2283/" ]
I want to spawn another process to display an error message asynchronously while the rest of the application continues. I'm using the `multiprocessing` module in Python 2.6 to create the process and I'm trying to display the window with `TKinter`. This code worked okay on Windows, but running it on Linux the `TKint...
This [discussion](http://pyinsci.blogspot.com/2008/09/python-processing.html) could be helpful. > > Here's some sample problems I found: > > > 1. While the multiprocessing module follows threading closely, it's definitely not an exact match. One example: since parameters to a > process must be *pickleable*, I had...
410,471
<p>I have an application where I need to remove one view from the stack of a UINavigationController and replace it with another. The situation is that the first view creates an editable item and then replaces itself with an editor for the item. When I do the obvious solution within the first view:</p> <pre><code>MyEdi...
[ { "answer_id": 410486, "author": "diclophis", "author_id": 32678, "author_profile": "https://Stackoverflow.com/users/32678", "pm_score": 1, "selected": false, "text": "<p>This <code>UINavigationController</code> instance method might work...</p>\n\n<p>Pops view controllers until the spec...
2009/01/04
[ "https://Stackoverflow.com/questions/410471", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7383/" ]
I have an application where I need to remove one view from the stack of a UINavigationController and replace it with another. The situation is that the first view creates an editable item and then replaces itself with an editor for the item. When I do the obvious solution within the first view: ``` MyEditViewControlle...
I've discovered you don't need to manually mess with the `viewControllers` property at all. Basically there are 2 tricky things about this. 1. `self.navigationController` will return `nil` if `self` is not currently on the navigation controller's stack. So save it to a local variable before you lose access to it. 2. Y...
410,485
<p>What is the <code>7n5lu</code> in the reddit URL </p> <blockquote> <p><a href="http://www.reddit.com/r/reddit.com/comments/7n5lu/man_can_fly_if_you_watch_one_video_in_2" rel="nofollow noreferrer">http://www.reddit.com/r/reddit.com/comments/7n5lu/man_can_fly_if_you_watch_one_video_in_2</a></p> </blockquote> <p>.....
[ { "answer_id": 410498, "author": "Ryan Doherty", "author_id": 956, "author_profile": "https://Stackoverflow.com/users/956", "pm_score": 0, "selected": false, "text": "<p>That looks like a unique id for the thread. It's most likely used to find the thread in the database.</p>\n" }, { ...
2009/01/04
[ "https://Stackoverflow.com/questions/410485", "https://Stackoverflow.com", "https://Stackoverflow.com/users/48557/" ]
What is the `7n5lu` in the reddit URL > > <http://www.reddit.com/r/reddit.com/comments/7n5lu/man_can_fly_if_you_watch_one_video_in_2> > > > ...and how is it generated? Update: @Gerald, I initially thought this is some obfuscation of the id. It is just doing the conversion from integer to a more compact represen...
The reddit source code [is available](https://github.com/reddit/reddit)! Here is what I found for generating that string: ``` def to_base(q, alphabet): if q < 0: raise ValueError, "must supply a positive integer" l = len(alphabet) converted = [] while q != 0: q, r = divmod(q, l) convert...
410,516
<p>I have the following doubts on header files usage.</p> <p><strong>1 - Include guards placing after comments</strong></p> <pre><code>/* Copyright Note and licence information (multiple lines) */ #ifndef FOO_H #define FOO_H // Header file contents #endif </code></pre> <p>Herb Sutter says in his "C++ coding standard...
[ { "answer_id": 410523, "author": "Adam Rosenfield", "author_id": 9530, "author_profile": "https://Stackoverflow.com/users/9530", "pm_score": 4, "selected": false, "text": "<ol>\n<li><p>The order of the include guards and the comments is purely a matter of style - it won't have any measur...
2009/01/04
[ "https://Stackoverflow.com/questions/410516", "https://Stackoverflow.com", "https://Stackoverflow.com/users/50419/" ]
I have the following doubts on header files usage. **1 - Include guards placing after comments** ``` /* Copyright Note and licence information (multiple lines) */ #ifndef FOO_H #define FOO_H // Header file contents #endif ``` Herb Sutter says in his "C++ coding standards" book that code like the above is problemati...
1. The order of the include guards and the comments is purely a matter of style - it won't have any measurable effect on speed of compilation. 2. Namespaces absolutely should be used in header files for declaring functions, classes, globals, etc. What you should *not* do is use `using` statements in header files -- it'...
410,576
<p>It's the weirdest thing. When I ran the Rails WEBrick debugger yesterday I could do things like</p> <pre><code>cookies[uid] = s.session_id </code></pre> <p>where 'uid' is a passed argument that has a user id in it, and then expect</p> <pre><code>cookies[uid] </code></pre> <p>to give me back, say: </p> <pre><cod...
[ { "answer_id": 410727, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 2, "selected": false, "text": "<p>Original questioner, here. It turns out that I can set those cookies. The issue is that when you type </p>\n\n<pre><code>co...
2009/01/04
[ "https://Stackoverflow.com/questions/410576", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
It's the weirdest thing. When I ran the Rails WEBrick debugger yesterday I could do things like ``` cookies[uid] = s.session_id ``` where 'uid' is a passed argument that has a user id in it, and then expect ``` cookies[uid] ``` to give me back, say: ``` 29b93443d9ec18168a26e1ab12957b0dd0b799ff ``` Today, I al...
Original questioner, here. It turns out that I can set those cookies. The issue is that when you type ``` cookies[:key] ``` in the debugger, it seems to always give you the value of the cookie as it was read from the browser. I don't know where the value gets stored away in the meantime, but inspecting the cookies ...
410,579
<p>I'm trying to create a custom control - a button - which will have multiple styles applied to it depending on the value of a property within the data context.</p> <p>What I was thinking is using something similar to:</p> <pre><code>&lt;Button Style="{Binding Path=ButtonStyleProperty, Converter={StaticResource styl...
[ { "answer_id": 410599, "author": "aku", "author_id": 1196, "author_profile": "https://Stackoverflow.com/users/1196", "pm_score": 4, "selected": false, "text": "<p>It seems that you need to use <a href=\"http://msdn.microsoft.com/en-us/library/system.windows.datatrigger.aspx\" rel=\"noref...
2009/01/04
[ "https://Stackoverflow.com/questions/410579", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18434/" ]
I'm trying to create a custom control - a button - which will have multiple styles applied to it depending on the value of a property within the data context. What I was thinking is using something similar to: ``` <Button Style="{Binding Path=ButtonStyleProperty, Converter={StaticResource styleConverter}}" Text="{Bin...
If you want to replace the whole style (rather than just elements of it) then you'll probably be storing those styles in resources. You should be able to do something along the lines of: ``` <Button> <Button.Style> <MultiBinding Converter="{StaticResource StyleConverter}"> <MultiBinding.Binding...
410,593
<p>I would like to clarify the differences between by value and by reference.</p> <p>I drew a picture:</p> <p><img src="https://i.stack.imgur.com/fNEsL.jpg" alt="Enter image description here" /></p> <p>So, for passing by value, a copy of an identical object is created with a different reference, and the local variable ...
[ { "answer_id": 410602, "author": "dreeves", "author_id": 4234, "author_profile": "https://Stackoverflow.com/users/4234", "pm_score": 2, "selected": false, "text": "<p>As I parse it, those words are wrong. It should read \"If the function modifies that value, the modifications appear als...
2009/01/04
[ "https://Stackoverflow.com/questions/410593", "https://Stackoverflow.com", "https://Stackoverflow.com/users/36064/" ]
I would like to clarify the differences between by value and by reference. I drew a picture: ![Enter image description here](https://i.stack.imgur.com/fNEsL.jpg) So, for passing by value, a copy of an identical object is created with a different reference, and the local variable is assigned the new reference, so to ...
I think much confusion is generated by not communicating what is meant by *passed by reference*. When some people say *pass by reference* they usually mean not the argument itself, but rather *the object being referenced*. Some other say that pass by reference means that the object can't be changed in the callee. Examp...
410,616
<p>I am programming a server and it seems like my number of connections is being limited since my bandwidth isn't being saturated even when I've set the number of connections to "unlimited".</p> <p>How can I increase or eliminate a maximum number of connections that my Ubuntu Linux box can open at a time? Does the OS ...
[ { "answer_id": 410643, "author": "derobert", "author_id": 27727, "author_profile": "https://Stackoverflow.com/users/27727", "pm_score": 6, "selected": false, "text": "<p>There are a couple of variables to set the max number of connections. Most likely, you're running out of file numbers ...
2009/01/04
[ "https://Stackoverflow.com/questions/410616", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I am programming a server and it seems like my number of connections is being limited since my bandwidth isn't being saturated even when I've set the number of connections to "unlimited". How can I increase or eliminate a maximum number of connections that my Ubuntu Linux box can open at a time? Does the OS limit this...
Maximum number of connections are impacted by certain limits on both client & server sides, albeit a little differently. **On the client side:** Increase the ephermal port range, and decrease the `tcp_fin_timeout` To find out the default values: ``` sysctl net.ipv4.ip_local_port_range sysctl net.ipv4.tcp_fin_timeout...
410,623
<p>I have an array, and I want to make a hash so I can quickly ask "is X in the array?".</p> <p>In perl, there is an easy (and fast) way to do this:</p> <pre><code>my @array = qw( 1 2 3 ); my %hash; @hash{@array} = undef; </code></pre> <p>This generates a hash that looks like:</p> <pre><code>{ 1 =&gt; undef, ...
[ { "answer_id": 410648, "author": "Zach Langley", "author_id": 45230, "author_profile": "https://Stackoverflow.com/users/45230", "pm_score": 3, "selected": false, "text": "<p>If you want to quickly ask \"is X in the array?\" you should use <a href=\"http://www.ruby-doc.org/core/classes/Ar...
2009/01/04
[ "https://Stackoverflow.com/questions/410623", "https://Stackoverflow.com", "https://Stackoverflow.com/users/27727/" ]
I have an array, and I want to make a hash so I can quickly ask "is X in the array?". In perl, there is an easy (and fast) way to do this: ``` my @array = qw( 1 2 3 ); my %hash; @hash{@array} = undef; ``` This generates a hash that looks like: ``` { 1 => undef, 2 => undef, 3 => undef, } ``` The best ...
If all you need the hash for is membership, consider using a [`Set`](http://ruby-doc.org/stdlib/libdoc/set/rdoc/Set.html): > > Set > === > > > [Set](http://ruby-doc.org/stdlib/libdoc/set/rdoc/Set.html) implements a collection of unordered values with no > duplicates. This is a hybrid of Array's intuitive inter-ope...
410,628
<p>I need your help to define a special case in XML schema: A sequence that contains two elements: 'x' and 'y' whereas:</p> <ul> <li><p><code>&lt;x&gt;</code> element can appear 0 to unbound times in the sequence</p></li> <li><p><code>&lt;y&gt;</code> element can appear 0 to 1 time in the sequence</p></li> <li><p><cod...
[ { "answer_id": 410656, "author": "Yuval Adam", "author_id": 24545, "author_profile": "https://Stackoverflow.com/users/24545", "pm_score": 0, "selected": false, "text": "<p>Not too complicated. Off the top of my head, it should be something like this:</p>\n\n<pre><code>&lt;xs:element name...
2009/01/04
[ "https://Stackoverflow.com/questions/410628", "https://Stackoverflow.com", "https://Stackoverflow.com/users/51338/" ]
I need your help to define a special case in XML schema: A sequence that contains two elements: 'x' and 'y' whereas: * `<x>` element can appear 0 to unbound times in the sequence * `<y>` element can appear 0 to 1 time in the sequence * `<x>` and `<y>` locations can be anywhere - that is, it is possible to have unbound...
For various reasons, none of Yuval's, Mo's or davidsheldon's samples work. Here's one that does. ``` <xs:complexType name="myComplexType"> <xs:sequence> <xs:element name="x" type="xs:string" minOccurs="0" maxOccurs="unbounded"/> <xs:sequence minOccurs="0"> <xs:element name="y" type=...
410,630
<p>I have the following Hibernate Mapping, which has to be mapped using the Table per Concrete Class Hierarchy:</p> <pre><code>&lt;hibernate-mapping package='dao'&gt; &lt;meta attribute='class-description'&gt;&lt;/meta&gt; &lt;class name='PropertyDAO'&gt; &lt;id name='id' column='id_property'&gt; ...
[ { "answer_id": 410642, "author": "Arthur Thomas", "author_id": 14009, "author_profile": "https://Stackoverflow.com/users/14009", "pm_score": 1, "selected": false, "text": "<p>I used the following with joined-subclass</p>\n\n<pre><code>&lt;key column=\"id\"/&gt;\n</code></pre>\n\n<p>This ...
2009/01/04
[ "https://Stackoverflow.com/questions/410630", "https://Stackoverflow.com", "https://Stackoverflow.com/users/51336/" ]
I have the following Hibernate Mapping, which has to be mapped using the Table per Concrete Class Hierarchy: ``` <hibernate-mapping package='dao'> <meta attribute='class-description'></meta> <class name='PropertyDAO'> <id name='id' column='id_property'> <generator class='assigned'/> ...
The solution is to create another table that stores the next id; this value should be modified each time a user wants to insert a new entity. In this way, the domain is continuous
410,692
<p>I am trying to do the following in a way or another:</p> <pre><code>const char EscapeChar = '\\'; const string EscapeString = EscapeChar.ToString(); // or ("" + EscapeChar) </code></pre> <p>This does't compile. Is there another way to make it work?</p>
[ { "answer_id": 410695, "author": "Jon Skeet", "author_id": 22656, "author_profile": "https://Stackoverflow.com/users/22656", "pm_score": 3, "selected": false, "text": "<p>I don't see any way of doing it, which I agree is a bit of a pity - but do you really <em>need</em> it to be a <code>...
2009/01/04
[ "https://Stackoverflow.com/questions/410692", "https://Stackoverflow.com", "https://Stackoverflow.com/users/41283/" ]
I am trying to do the following in a way or another: ``` const char EscapeChar = '\\'; const string EscapeString = EscapeChar.ToString(); // or ("" + EscapeChar) ``` This does't compile. Is there another way to make it work?
From the [C# Language Specification](http://guide.opendns.com/track/click.php?q=c%23+specification&curl=http%3A%2F%2Fwww.ecma-international.org%2Fpublications%2Fstandards%2FEcma-334.htm&search_grp=MAINRESULTS&search_pos=2) (§ 17.3 and 14.16): > > **17.3 Constants** > > > A constant is a class member that > represe...
410,704
<p>I'm trying to encode Cyrillic UTF-8 array to JSON string using php's function json_encode. The sample code looks like this:</p> <pre><code>&lt;?php $arr = array( 'едно' =&gt; 'първи', 'две' =&gt; 'втори' ); $str = json_encode($arr); echo $str; ?&gt; </code></pre> <p>It works fine but the result o...
[ { "answer_id": 410712, "author": "Beau Simensen", "author_id": 50453, "author_profile": "https://Stackoverflow.com/users/50453", "pm_score": 2, "selected": false, "text": "<p>It looks like PHP's built in <code>json_encode</code> only works with <code>UTF-8</code>, and no other bells and ...
2009/01/04
[ "https://Stackoverflow.com/questions/410704", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17734/" ]
I'm trying to encode Cyrillic UTF-8 array to JSON string using php's function json\_encode. The sample code looks like this: ``` <?php $arr = array( 'едно' => 'първи', 'две' => 'втори' ); $str = json_encode($arr); echo $str; ?> ``` It works fine but the result of the script is represented as: ``` ...
Can't you use [JSON\_UNESCAPED\_UNICODE](http://php.net/manual/en/function.json-encode.php) constant here?
410,717
<p>F# has a bunch of standard sequence operators I have come to know and love from my experience with Mathematica. F# is getting lots of my attention now, and when it is in general release, I intend to use it frequently.</p> <p>Right now, since F# isn't yet in general release, I can't really use it in production code...
[ { "answer_id": 410759, "author": "Marc Gravell", "author_id": 23354, "author_profile": "https://Stackoverflow.com/users/23354", "pm_score": 3, "selected": false, "text": "<ul>\n<li>fold = <code>Aggregate</code></li>\n</ul>\n\n<p>Tell use what <code>iter</code> and <code>partition</code> ...
2009/01/04
[ "https://Stackoverflow.com/questions/410717", "https://Stackoverflow.com", "https://Stackoverflow.com/users/51345/" ]
F# has a bunch of standard sequence operators I have come to know and love from my experience with Mathematica. F# is getting lots of my attention now, and when it is in general release, I intend to use it frequently. Right now, since F# isn't yet in general release, I can't really use it in production code. LINQ impl...
If you look carefully, many Seq operations have a LINQ equivalent or can be easily derived. Just looking down the [list](http://research.microsoft.com/en-us/um/cambridge/projects/fsharp/manual/fsharp.core/Microsoft.FSharp.Collections.Seq.html)... * `Seq.append = Concat<TSource>(IEnumerable<TSource> second)` * `Seq.con...
410,719
<p>This really, really urks me, so I hope that someone can give me a reasonable justification for why things are as they are.</p> <p><strong>NotImplementedException.</strong> You are pulling my leg, right?</p> <p>No, I'm not going to take the cheap stab at this by saying, "hang on, the method is implemented - it thr...
[ { "answer_id": 410724, "author": "Toon Krijthe", "author_id": 18061, "author_profile": "https://Stackoverflow.com/users/18061", "pm_score": 0, "selected": false, "text": "<p>What about prototypes or unfinished projects?</p>\n\n<p>I don't think this is a really bad idea to use an exceptio...
2009/01/04
[ "https://Stackoverflow.com/questions/410719", "https://Stackoverflow.com", "https://Stackoverflow.com/users/43066/" ]
This really, really urks me, so I hope that someone can give me a reasonable justification for why things are as they are. **NotImplementedException.** You are pulling my leg, right? No, I'm not going to take the cheap stab at this by saying, "hang on, the method is implemented - it throws a NotImplementedException."...
There is one situation I find it useful: TDD. I write my tests, then I create stubs so the tests compile. Those stubs do nothing but `throw new NotImplementedException();`. This way the tests will fail by default, no matter what. If I used some dummy return value, it might generate false positives. Now that all tests ...
410,723
<p>Is there a difference between having a <code>private const</code> variable or a <code>private static readonly</code> variable in C# (other than having to assign the <code>const</code> a compile-time expression)?</p> <p>Since they are both private, there is no linking with other libraries. So would it make any diffe...
[ { "answer_id": 410731, "author": "Steven Robbins", "author_id": 26507, "author_profile": "https://Stackoverflow.com/users/26507", "pm_score": 2, "selected": false, "text": "<p>In use? Not really. Consts are evaluated at compile time, whereas readonly are evaluated at runtime. You can a...
2009/01/04
[ "https://Stackoverflow.com/questions/410723", "https://Stackoverflow.com", "https://Stackoverflow.com/users/41283/" ]
Is there a difference between having a `private const` variable or a `private static readonly` variable in C# (other than having to assign the `const` a compile-time expression)? Since they are both private, there is no linking with other libraries. So would it make any difference? Can it make a performance difference...
Well, you can use consts in attributes, since they exist as compile time. You can't predict the value of a static readonly variable, since the `.cctor` could initialize it from configuration etc. In terms of usage, constants are burnt into the calling code. This means that if you recompile a *library* dll to change a ...
410,749
<p>I use svn for a project im working on with a couple of other developers. Svn works fine for source control however we are all ways getting conflicts when we commit the dlls.</p> <p>When i do i resolve the conflict (which deletes my dlls as the diff program cant handle binary files) then have to rebuild to commit. H...
[ { "answer_id": 410757, "author": "Greg Hewgill", "author_id": 893, "author_profile": "https://Stackoverflow.com/users/893", "pm_score": 2, "selected": false, "text": "<p>Generally, you wouldn't store your own compiled DLLs in source control at all. Do you have a specific reason that you ...
2009/01/04
[ "https://Stackoverflow.com/questions/410749", "https://Stackoverflow.com", "https://Stackoverflow.com/users/23339/" ]
I use svn for a project im working on with a couple of other developers. Svn works fine for source control however we are all ways getting conflicts when we commit the dlls. When i do i resolve the conflict (which deletes my dlls as the diff program cant handle binary files) then have to rebuild to commit. How are you...
As mentioned in other answers here: you shouldn't version your generated dlls in the first place. But if you really **have** to version them, then you can resolve a conflict without using a diff tool which removes your dll files: For every conflicted file, Subversion places three extra unversioned files in your workin...
410,787
<p>According to [MSDN: Array usage guidelines](<a href="http://msdn.microsoft.com/en-us/library/k2604h5s(VS.71).aspx)" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/k2604h5s(VS.71).aspx)</a>: </p> <p>Array Valued Properties</p> <blockquote> <p>You should use collections to avoid code inefficienc...
[ { "answer_id": 410790, "author": "Marc Gravell", "author_id": 23354, "author_profile": "https://Stackoverflow.com/users/23354", "pm_score": 4, "selected": true, "text": "<p>No, it isn't <strong>leaking</strong> memory - it is just making the garbage collector work harder than it might. A...
2009/01/04
[ "https://Stackoverflow.com/questions/410787", "https://Stackoverflow.com", "https://Stackoverflow.com/users/40164/" ]
According to [MSDN: Array usage guidelines](<http://msdn.microsoft.com/en-us/library/k2604h5s(VS.71).aspx)>: Array Valued Properties > > You should use collections to avoid code inefficiencies. In the following code example, each call to the myObj property creates a copy of the array. As a result, 2n+1 copies of th...
No, it isn't **leaking** memory - it is just making the garbage collector work harder than it might. Actually, the MSDN article is slightly misleading: if the property created a new **collection** every time it was called, it would be just as bad (memory wise) as with an array. Perhaps worse, due to the usual over-sizi...
410,811
<p>I need to set up some RewriteRules to redirect a URL which has a space in it. I've tried this:</p> <pre><code>RewriteRule ^article/with%20spaces.html$ /article/without_spaces.html [R=301,L] </code></pre> <p>... but it doesn't work. Putting in a space instead of %20 causes a 500 Internal Server Error. How do I add ...
[ { "answer_id": 410815, "author": "nickf", "author_id": 9021, "author_profile": "https://Stackoverflow.com/users/9021", "pm_score": 1, "selected": false, "text": "<p>Ah, I've found a solution: use the regex style to show a space:</p>\n\n<pre><code>RewriteRule ^article/with\\sspaces.html$ ...
2009/01/04
[ "https://Stackoverflow.com/questions/410811", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9021/" ]
I need to set up some RewriteRules to redirect a URL which has a space in it. I've tried this: ``` RewriteRule ^article/with%20spaces.html$ /article/without_spaces.html [R=301,L] ``` ... but it doesn't work. Putting in a space instead of %20 causes a 500 Internal Server Error. How do I add a space?
Try putting a \ in front of your space to escape it. ``` RewriteRule ^article/with\ spaces.html$ /article/without_spaces.html [R=301,L] ```
410,819
<p>Even better would be if <code>autoResize</code> in latest branch would work as intended, but till then the question is simple: <strong>how to resize a dialog once it is created?</strong></p>
[ { "answer_id": 410871, "author": "Soviut", "author_id": 46914, "author_profile": "https://Stackoverflow.com/users/46914", "pm_score": 2, "selected": false, "text": "<p>All JQuery UI plugins can have their properties updated using .data():</p>\n\n<pre><code>$(document).ready(function(){\n...
2009/01/04
[ "https://Stackoverflow.com/questions/410819", "https://Stackoverflow.com", "https://Stackoverflow.com/users/51357/" ]
Even better would be if `autoResize` in latest branch would work as intended, but till then the question is simple: **how to resize a dialog once it is created?**
The answer from is Soviut is correct for `v1.5. 1.6` adds an `option` method to each plugin: ``` $(document).ready(function(){ var d = $("#example").dialog(); d.dialog("option", "width", 700); }); ```
410,820
<p>I've got a blogging site hosted on Windows Sever, ASP.Net 3.5, ASP.Net AJAX, SQL Server in background.</p> <p>I want to give bloggers a button like 'digg-it' which they can put on their blogs for the readers to click to thumb-up the post if they like it.</p> <p>I know I'll be using Javascript to do that. What can ...
[ { "answer_id": 410828, "author": "Beau Simensen", "author_id": 50453, "author_profile": "https://Stackoverflow.com/users/50453", "pm_score": 3, "selected": true, "text": "<p>You can look into using SCRIPT callbacks loading JSON data instead of using XmlHttpRequest to get around the cross...
2009/01/04
[ "https://Stackoverflow.com/questions/410820", "https://Stackoverflow.com", "https://Stackoverflow.com/users/33052/" ]
I've got a blogging site hosted on Windows Sever, ASP.Net 3.5, ASP.Net AJAX, SQL Server in background. I want to give bloggers a button like 'digg-it' which they can put on their blogs for the readers to click to thumb-up the post if they like it. I know I'll be using Javascript to do that. What can I do to: - 1. Re...
You can look into using SCRIPT callbacks loading JSON data instead of using XmlHttpRequest to get around the crossdomain issues. ``` function dynScript(url){ var script=document.createElement('script'); script.src=url; script.type="text/javascript"; document.getElementsByTagName('head')[0].appendChild(...
410,823
<p>I have the following code for "factory" design pattern implementation.</p> <pre><code>class Pen{ public: virtual void Draw() = 0; }; class RedPen : public Pen{ public: virtual void Draw(){ cout &lt;&lt; "Drawing with red pen" &lt;&lt; endl; } }; class BluePen : public Pen{ public: vir...
[ { "answer_id": 410856, "author": "gnud", "author_id": 27204, "author_profile": "https://Stackoverflow.com/users/27204", "pm_score": 3, "selected": true, "text": "<p>In the example you posted, neither a factory or a template approach makes sense to me.\nMy solution involves a data member ...
2009/01/04
[ "https://Stackoverflow.com/questions/410823", "https://Stackoverflow.com", "https://Stackoverflow.com/users/50419/" ]
I have the following code for "factory" design pattern implementation. ``` class Pen{ public: virtual void Draw() = 0; }; class RedPen : public Pen{ public: virtual void Draw(){ cout << "Drawing with red pen" << endl; } }; class BluePen : public Pen{ public: virtual void Draw(){ ...
In the example you posted, neither a factory or a template approach makes sense to me. My solution involves a data member in the Pen class. ``` class Pen { public: Pen() : m_color(0,0,0,0) /* the default colour is black */ { } Pen(const Color& c) : m_color(c) { } Pen(const Pen...
410,841
<p>This is a bit of a crazy idea, but would there be a way to bootstrap all the functions that php have without using a helper function to call the functions.</p> <p>What I mean is actually calling some code or function before and after every basic function call.</p> <p>Example:</p> <pre><code>&lt;?php echo "Hello";...
[ { "answer_id": 410846, "author": "Paul Dixon", "author_id": 6521, "author_profile": "https://Stackoverflow.com/users/6521", "pm_score": 1, "selected": false, "text": "<p>Just as an FYI, your example picked something which isn't actually a function in the strictest sense, <a href=\"http:/...
2009/01/04
[ "https://Stackoverflow.com/questions/410841", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4985/" ]
This is a bit of a crazy idea, but would there be a way to bootstrap all the functions that php have without using a helper function to call the functions. What I mean is actually calling some code or function before and after every basic function call. Example: ``` <?php echo "Hello"; ?> ``` But these functions w...
"Bootstrapping" is not the correct term here - what you want to do is called [Aspect-oriented Programming](http://en.wikipedia.org/wiki/Aspect-oriented_programming), and [yes, it can be done in PHP](http://sebastian-bergmann.de/archives/573-Current-State-of-AOP-for-PHP.html). However, it seems to require substantial ch...
410,842
<p>How do I hide a child in a accordion? Using visible doesn't seem to work and enabled isn't what I'm after.</p> <pre><code>&lt;mx:Accordion&gt; &lt;mx:VBox width="100%" height="100%" label="Foo" id="viewOverview" visible="false"&gt; ... &lt;/mx:VBox&gt; ... &lt;/mx:Accordion&gt; </code></pre>
[ { "answer_id": 410863, "author": "PEZ", "author_id": 44639, "author_profile": "https://Stackoverflow.com/users/44639", "pm_score": 4, "selected": true, "text": "<p>I think you can't hide it. Strange that the visible property doesn't work... Anyway, I would control the children through co...
2009/01/04
[ "https://Stackoverflow.com/questions/410842", "https://Stackoverflow.com", "https://Stackoverflow.com/users/40939/" ]
How do I hide a child in a accordion? Using visible doesn't seem to work and enabled isn't what I'm after. ``` <mx:Accordion> <mx:VBox width="100%" height="100%" label="Foo" id="viewOverview" visible="false"> ... </mx:VBox> ... </mx:Accordion> ```
I think you can't hide it. Strange that the visible property doesn't work... Anyway, I would control the children through code and remove and insert them as needed by the app. Hiding: ``` function hideFoo():void { this.theAccordion.removeChild(this.vboxFoo); } ``` You'll probably want to keep a reference to the ...
410,853
<p>In my programs infinity usually arises when a value is divided by zero. I get indeterminate when I divide zero by zero. How do you check for infinite and indeterminate values in C++?</p> <p>In C++, infinity is represented by 1.#INF. Indeterminate is represented by -1.#IND. The problem is how to test if a variable i...
[ { "answer_id": 410864, "author": "CB Bailey", "author_id": 19563, "author_profile": "https://Stackoverflow.com/users/19563", "pm_score": 2, "selected": false, "text": "<p>Although not strictly a part of C++03, if your compiler provides some of the new C99 features of the standard &lt;mat...
2009/01/04
[ "https://Stackoverflow.com/questions/410853", "https://Stackoverflow.com", "https://Stackoverflow.com/users/51358/" ]
In my programs infinity usually arises when a value is divided by zero. I get indeterminate when I divide zero by zero. How do you check for infinite and indeterminate values in C++? In C++, infinity is represented by 1.#INF. Indeterminate is represented by -1.#IND. The problem is how to test if a variable is infinite...
For Visual Studio I would use [`_isnan`](http://msdn.microsoft.com/en-us/library/aa298428(VS.60).aspx) and [`_finite`](http://msdn.microsoft.com/en-us/library/aa246875(VS.60).aspx), or perhaps [`_fpclass`](http://msdn.microsoft.com/en-us/library/aa246882(VS.60).aspx). But if you have access to a C++11-able standard li...
410,865
<p>I read about the <code>Conditional</code> attribute today. According to MSDN:</p> <blockquote> <p>Applying <code>ConditionalAttribute</code> to a method indicates to compilers that a call to the method should not be compiled into Microsoft intermediate language (MSIL) unless the conditional compilation symbol tha...
[ { "answer_id": 410873, "author": "R. Martinho Fernandes", "author_id": 46642, "author_profile": "https://Stackoverflow.com/users/46642", "pm_score": 1, "selected": false, "text": "<p>I guess that's due to ease of compiler implementation.</p>\n\n<p>I would be fearful of such code anyways ...
2009/01/04
[ "https://Stackoverflow.com/questions/410865", "https://Stackoverflow.com", "https://Stackoverflow.com/users/41283/" ]
I read about the `Conditional` attribute today. According to MSDN: > > Applying `ConditionalAttribute` to a method indicates to compilers that a call to the method should not be compiled into Microsoft intermediate language (MSIL) unless the conditional compilation symbol that is associated with `ConditionalAttribute...
Expanding on Marc's answer. This is definitely "By Design". The best way to understand the rationalization for this is to think about what this code took the place of. This feature in many, and much cleaner ways, takes the way of conditionally compiled code. For example, ``` #if DEBUG f1(++a); #endif ``` Or anoth...
410,889
<p>I'm not very good at C, and I always get stuck on simple string manipulation tasks (that's why I love Perl!).</p> <p>I have a string that contains a file path like "/Volumes/Media/Music/Arcade Fire/Black Mirror.aac". I need to extract the drive name ("Media" or preferably "/Volumes/Media") from that path.</p> <p>...
[ { "answer_id": 410896, "author": "CB Bailey", "author_id": 19563, "author_profile": "https://Stackoverflow.com/users/19563", "pm_score": 1, "selected": false, "text": "<p>I think that you need to be a little more exact in the specification of your problem.</p>\n\n<p>When you say that you...
2009/01/04
[ "https://Stackoverflow.com/questions/410889", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13563/" ]
I'm not very good at C, and I always get stuck on simple string manipulation tasks (that's why I love Perl!). I have a string that contains a file path like "/Volumes/Media/Music/Arcade Fire/Black Mirror.aac". I need to extract the drive name ("Media" or preferably "/Volumes/Media") from that path. Any help would be ...
I think sscanf could be appropriate: ``` #include <stdlib.h> #include <string.h> #include <stdio.h> void test(char const* path) { int len; if(sscanf(path, "/Volumes/%*[^/]%n", &len) != EOF) { char *drive = malloc(len + 1); strncpy(drive, path, len); drive[len] = '\0'; printf("...
410,890
<p>If I get a NullPointerException in a call like this:</p> <pre><code>someObject.getSomething().getSomethingElse(). getAnotherThing().getYetAnotherObject().getValue(); </code></pre> <p>I get a rather useless exception text like:</p> <pre><code>Exception in thread &quot;main&quot; java.lang.NullPointerException at ...
[ { "answer_id": 410902, "author": "krosenvold", "author_id": 23691, "author_profile": "https://Stackoverflow.com/users/23691", "pm_score": 2, "selected": false, "text": "<p>I generally do not chain getters like this where there is more than one nullable getter.</p>\n\n<p>If you're running...
2009/01/04
[ "https://Stackoverflow.com/questions/410890", "https://Stackoverflow.com", "https://Stackoverflow.com/users/39946/" ]
If I get a NullPointerException in a call like this: ``` someObject.getSomething().getSomethingElse(). getAnotherThing().getYetAnotherObject().getValue(); ``` I get a rather useless exception text like: ``` Exception in thread "main" java.lang.NullPointerException at package.SomeClass.someMethod(SomeClass.java:...
The answer depends on how you view (the contract of) your getters. If they may return `null` you should really check the return value each time. If the getter should not return `null`, the getter should contain a check and throw an exception (`IllegalStateException`?) instead of returning `null`, that you promised neve...
410,898
<p>I have some markup like this:</p> <pre><code>&lt;p&gt;&lt;a id="1" href="#"&gt;Link 1&lt;/a&gt;&lt;/p&gt; &lt;p id="1show" class="starthidden"&gt;Hi! I get shown when link 1 is clicked&lt;/p&gt; &lt;p&gt;&lt;a id="2" href="#"&gt;Link 2&lt;/a&gt;&lt;/p&gt; &lt;p id="2show" class="starthidden"&gt;Hi! I get shown whe...
[ { "answer_id": 410910, "author": "clawr", "author_id": 46201, "author_profile": "https://Stackoverflow.com/users/46201", "pm_score": 2, "selected": false, "text": "<p>Variables inside double strings aren't parsed as they are in PHP, so you must do <code>$(show)</code>. Also, the inner <c...
2009/01/04
[ "https://Stackoverflow.com/questions/410898", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16511/" ]
I have some markup like this: ``` <p><a id="1" href="#">Link 1</a></p> <p id="1show" class="starthidden">Hi! I get shown when link 1 is clicked</p> <p><a id="2" href="#">Link 2</a></p> <p id="2show" class="starthidden">Hi! I get shown when link 2 is clicked</p> <p><a id="3" href="#">Link 3</a></p> <p id="3show" clas...
First off, numerical ID's are not valid HTML. ID attributes must start with a-z. I recommend changing your HTML like this: ``` <p><a href="#msg1">Link 1</a></p> <p id="msg1" class="starthidden">Hi! I get shown when link 1 is clicked</p> <p><a href="#msg2">Link 2</a></p> <p id="msg2" class="starthidden">Hi! I get show...
410,924
<p>I'm trying to create an overridden operator function using both const parameters, but I can't figure out how to do it. Here is a simple example:</p> <pre><code>class Number { Number() { value = 1; }; inline Number operator + (const Number&amp; n) { Number result; result...
[ { "answer_id": 410928, "author": "cletus", "author_id": 18393, "author_profile": "https://Stackoverflow.com/users/18393", "pm_score": 1, "selected": false, "text": "<pre><code>class Number\n{\n Number()\n {\n value = 1;\n };\n\n inline Number operator + (const Number&a...
2009/01/04
[ "https://Stackoverflow.com/questions/410924", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18909/" ]
I'm trying to create an overridden operator function using both const parameters, but I can't figure out how to do it. Here is a simple example: ``` class Number { Number() { value = 1; }; inline Number operator + (const Number& n) { Number result; result.value = value + n...
`inline` is understood in class declarations so you don't need to specify it. Most idiomatically, you would make `operator+` a non-member function declared outside the class definition, like this: ``` Number operator+( const Number& left, const Number& right ); ``` You might need to make it a `friend` of the class ...
410,943
<p>What would be the most efficient method of reading a text file into a dynamic one-dimensional array? reallocing after every read char seems silly, reallocing after every read line doesn't seem much better. I would like to read the entire file into the array. How would you do it?</p>
[ { "answer_id": 410952, "author": "Johannes Schaub - litb", "author_id": 34509, "author_profile": "https://Stackoverflow.com/users/34509", "pm_score": 6, "selected": true, "text": "<p>I don't understand quite what you want. Do you want to incrementally process the file, reading one line f...
2009/01/04
[ "https://Stackoverflow.com/questions/410943", "https://Stackoverflow.com", "https://Stackoverflow.com/users/41839/" ]
What would be the most efficient method of reading a text file into a dynamic one-dimensional array? reallocing after every read char seems silly, reallocing after every read line doesn't seem much better. I would like to read the entire file into the array. How would you do it?
I don't understand quite what you want. Do you want to incrementally process the file, reading one line from it, then abandon it and process the next? Or do you want to read the entire file into a buffer? If you want the latter, I think this is appropriate (check for NULL return for malloc and fopen in real code for wh...
410,954
<p>How do I parse XML from a Google App Engine app? Any examples?</p>
[ { "answer_id": 410962, "author": "joschi", "author_id": 49505, "author_profile": "https://Stackoverflow.com/users/49505", "pm_score": 2, "selected": false, "text": "<p>AFAIK Google App Engine provides a fairly complete Python environment for you to use. Since Python comes with \"batterie...
2009/01/04
[ "https://Stackoverflow.com/questions/410954", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
How do I parse XML from a Google App Engine app? Any examples?
Since the question was asked, Google has whitelisted pyexpat, which includes minidom, so you can use the following code without having to upload any libraries: ``` from xml.dom import minidom dom = minidom.parseString('<eg>example text</eg>') ``` More information: <http://docs.python.org/library/xml.dom.minidom.htm...
410,966
<p>When an object has various formats (XML,CSV) it can be represented in, where should one store knowledge of those formats.</p> <p>Should the object have knowledge of how it's represented in XML (i.e. letting the object convert itself through some method on the object such as <code>GetXML()</code>). Is this too much ...
[ { "answer_id": 411104, "author": "Aaron Maenpaa", "author_id": 2603, "author_profile": "https://Stackoverflow.com/users/2603", "pm_score": 4, "selected": true, "text": "<p>Generally speaking you want the object's XML (or other...) formatting code to be separate for the object itself. The...
2009/01/04
[ "https://Stackoverflow.com/questions/410966", "https://Stackoverflow.com", "https://Stackoverflow.com/users/34991/" ]
When an object has various formats (XML,CSV) it can be represented in, where should one store knowledge of those formats. Should the object have knowledge of how it's represented in XML (i.e. letting the object convert itself through some method on the object such as `GetXML()`). Is this too much knowledge for the obj...
Generally speaking you want the object's XML (or other...) formatting code to be separate for the object itself. The practical reason for this is wanting to have more than one XML representation (say a summary and detailed representation). If these methods where all part of the object's API then you start having: ``` ...
410,967
<p>I'm searching for a possibility to get a list of installed printers. I'm using JDK 1.6 with a Windows operating system. Does anyone know a solution? </p> <p>Thank you in advance.</p>
[ { "answer_id": 410972, "author": "Ronald Blaschke", "author_id": 49604, "author_profile": "https://Stackoverflow.com/users/49604", "pm_score": 2, "selected": false, "text": "<p>I haven't used this myself, but maybe <a href=\"http://java.sun.com/javase/6/docs/api/javax/print/PrintServiceL...
2009/01/04
[ "https://Stackoverflow.com/questions/410967", "https://Stackoverflow.com", "https://Stackoverflow.com/users/42659/" ]
I'm searching for a possibility to get a list of installed printers. I'm using JDK 1.6 with a Windows operating system. Does anyone know a solution? Thank you in advance.
Just wanted to add a little snippet: ``` import javax.print.*; class Test { public static void main (String [] args) { PrintService[] printServices = PrintServiceLookup.lookupPrintServices(null, null); System.out.println("Number of print services: " + printServices.length); for (Prin...
410,980
<p>Is there a way to include an entire text file as a string in a C program at compile-time?</p> <p>something like:</p> <ul> <li><p>file.txt:</p> <pre><code>This is a little text file </code></pre></li> <li><p>main.c:</p> <pre><code>#include &lt;stdio.h&gt; int main(void) { #blackmagicinclude("file.txt", content...
[ { "answer_id": 410988, "author": "Dominik Grabiec", "author_id": 3719, "author_profile": "https://Stackoverflow.com/users/3719", "pm_score": 0, "selected": false, "text": "<p>What <strong>might</strong> work is if you do something like:</p>\n\n<pre><code>int main()\n{\n const char* te...
2009/01/04
[ "https://Stackoverflow.com/questions/410980", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
Is there a way to include an entire text file as a string in a C program at compile-time? something like: * file.txt: ``` This is a little text file ``` * main.c: ``` #include <stdio.h> int main(void) { #blackmagicinclude("file.txt", content) /* equiv: char[] content = "This is\na little\ntext file"; *...
I'd suggest using (unix util)[xxd](http://www.manpagez.com/man/1/xxd/) for this. you can use it like so ``` $ echo hello world > a $ xxd -i a ``` outputs: ``` unsigned char a[] = { 0x68, 0x65, 0x6c, 0x6c, 0x6f, 0x20, 0x77, 0x6f, 0x72, 0x6c, 0x64, 0x0a }; unsigned int a_len = 12; ```
410,981
<p>What harm can come from defining BOOST_DISABLE_ABI_HEADERS when compiling boost? </p> <p>From the boost file: boost_1_37_0\boost\config\user.hpp</p> <pre><code>// BOOST_DISABLE_ABI_HEADERS: Stops boost headers from including any // prefix/suffix headers that normally control things like struct // packing and ali...
[ { "answer_id": 410992, "author": "Stefan", "author_id": 48003, "author_profile": "https://Stackoverflow.com/users/48003", "pm_score": 2, "selected": false, "text": "<p>The define assures that the ABI (<a href=\"http://en.wikipedia.org/wiki/Application_binary_interface\" rel=\"nofollow no...
2009/01/04
[ "https://Stackoverflow.com/questions/410981", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3153/" ]
What harm can come from defining BOOST\_DISABLE\_ABI\_HEADERS when compiling boost? From the boost file: boost\_1\_37\_0\boost\config\user.hpp ``` // BOOST_DISABLE_ABI_HEADERS: Stops boost headers from including any // prefix/suffix headers that normally control things like struct // packing and alignment. //#def...
Here is a rundown of defining BOOST\_DISABLE\_ABI\_HEADERS: * If you use some shared boost dlls, you will get undefined behavior * If you statically link to your boost libraries, or you are sure you are only using your own dlls then you may be safe, keep reading for why I say may. * If you use boost in several .libs i...
410,982
<p>Or to reformulate the question: is there a performance penalty in using unsigned values?</p> <p>And in general: what is the most performant type (16bit signed?, 32bit signed? etc.) on the IPhone ARM processor?</p>
[ { "answer_id": 411015, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 3, "selected": false, "text": "<p>The C99 standard allows you to answer your general question; the fastest type on the target system which is above a particu...
2009/01/04
[ "https://Stackoverflow.com/questions/410982", "https://Stackoverflow.com", "https://Stackoverflow.com/users/50335/" ]
Or to reformulate the question: is there a performance penalty in using unsigned values? And in general: what is the most performant type (16bit signed?, 32bit signed? etc.) on the IPhone ARM processor?
It always depends: For loops signed integers as counters and limits are a tad faster because in C the compiler is free to assume that overflow never happends. Consider this: You have a loop with an unsigned loop counter like this: ``` void function (unsigned int first, unsigned int last) { unsigned int i; for (...
410,986
<p>Microsoft's live service has an amazing contact details form in their "Account" > "Registered information" page. You are first asked for your country and the rest of the contact form changes accordingly. For example, if you select "United States", the form fields will change to: Address 1, Address 2, City, State (dr...
[ { "answer_id": 411015, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 3, "selected": false, "text": "<p>The C99 standard allows you to answer your general question; the fastest type on the target system which is above a particu...
2009/01/04
[ "https://Stackoverflow.com/questions/410986", "https://Stackoverflow.com", "https://Stackoverflow.com/users/45735/" ]
Microsoft's live service has an amazing contact details form in their "Account" > "Registered information" page. You are first asked for your country and the rest of the contact form changes accordingly. For example, if you select "United States", the form fields will change to: Address 1, Address 2, City, State (drop ...
It always depends: For loops signed integers as counters and limits are a tad faster because in C the compiler is free to assume that overflow never happends. Consider this: You have a loop with an unsigned loop counter like this: ``` void function (unsigned int first, unsigned int last) { unsigned int i; for (...
410,993
<p>We have a website made by Django. And there is no problem when access following url on local working environment: </p> <pre><code>http://site/tags/c%23/ </code></pre> <p>"c%23" is urlencode of "c#", that works fine locally. But after we deploy it on Bluehost hosting server (apache+fastcgi), this URL has been res...
[ { "answer_id": 411216, "author": "lpfavreau", "author_id": 35935, "author_profile": "https://Stackoverflow.com/users/35935", "pm_score": 4, "selected": true, "text": "<p>Just some tips before going further:</p>\n\n<p>Have you tried with other characters such as a space (%20) or an accent...
2009/01/04
[ "https://Stackoverflow.com/questions/410993", "https://Stackoverflow.com", "https://Stackoverflow.com/users/43997/" ]
We have a website made by Django. And there is no problem when access following url on local working environment: ``` http://site/tags/c%23/ ``` "c%23" is urlencode of "c#", that works fine locally. But after we deploy it on Bluehost hosting server (apache+fastcgi), this URL has been resolved to a new address lik...
Just some tips before going further: Have you tried with other characters such as a space (%20) or an accented ASCII character? Also, have you tried putting other characters after the %23 (other than the slash) to see if they're stripped also? One guess could be that as the # is considered as an anchor on the current...
411,048
<p>What is the difference between using Private Properties instead of Private Fields</p> <pre><code>private String MyValue { get; set; } // instead of private String _myValue; public void DoSomething() { MyValue = "Test"; // Instead of _myValue = "Test"; } </code></pre> <p>Is there any performance issue...
[ { "answer_id": 411060, "author": "Rowland Shaw", "author_id": 50447, "author_profile": "https://Stackoverflow.com/users/50447", "pm_score": 1, "selected": false, "text": "<p>Property access will be (fractionally) slower as it will call the getter/setter. The benefit is that you can do da...
2009/01/04
[ "https://Stackoverflow.com/questions/411048", "https://Stackoverflow.com", "https://Stackoverflow.com/users/50974/" ]
What is the difference between using Private Properties instead of Private Fields ``` private String MyValue { get; set; } // instead of private String _myValue; public void DoSomething() { MyValue = "Test"; // Instead of _myValue = "Test"; } ``` Is there any performance issue ? or just a naming conven...
Private properties allow you to abstract your internal data so that changes to the internal representation don't need to affect other parts of your implementation, even in the same class. Private fields do not offer this advantage. With automatic properties in C# 3.0, I rarely see a need to implement fields directly --...
411,054
<p>I'm try to figure out how to handle the following scenario. In general, i have a bunch of records in a table. All of these have ID and ParentID fields to form a tree. </p> <pre><code>Page1 - Page2 - Page3 Page4 - Page5 -- Page6 </code></pre> <p>Now, i want my routes for Page3 and Page6 to be like <code>/Page1/...
[ { "answer_id": 411062, "author": "Yoann. B", "author_id": 50974, "author_profile": "https://Stackoverflow.com/users/50974", "pm_score": -1, "selected": false, "text": "<p>You should use </p>\n\n<pre><code>routes.MapRoute(\"Page6\", \"Page3/Page5/Page6\", new { controller = \"Page6\", act...
2009/01/04
[ "https://Stackoverflow.com/questions/411054", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19610/" ]
I'm try to figure out how to handle the following scenario. In general, i have a bunch of records in a table. All of these have ID and ParentID fields to form a tree. ``` Page1 - Page2 - Page3 Page4 - Page5 -- Page6 ``` Now, i want my routes for Page3 and Page6 to be like `/Page1/Page6` and `/Page3/Page5/Page6`...
You could use a wildcard match. A possible route: ``` routes.MapRoute("SomeName", "{*Page}", new { controller = "ControllerName", action = "ActionName" }); ``` and in the action accept the string Page, and parse it manually, perhaps with a split? This might also be useful: [URL Routing](http://weblogs.asp.net/scot...
411,057
<p>Is there a way to generate a class constraint with CodeDom.</p> <p>Because when I use something like</p> <pre><code>var method = new CodeMemberMethod(); var genericParam = new CodeTypeParameter("InterfaceType"); genericParam.Constraints.Add("class"); method.TypeParameters.Add(genericParam); </code></pre> <p>the g...
[ { "answer_id": 976071, "author": "Max Galkin", "author_id": 2351099, "author_profile": "https://Stackoverflow.com/users/2351099", "pm_score": 4, "selected": true, "text": "<p>It seems that there is no straigntforward way to specify that constraint. Neither <a href=\"http://msdn.microsoft...
2009/01/04
[ "https://Stackoverflow.com/questions/411057", "https://Stackoverflow.com", "https://Stackoverflow.com/users/21566/" ]
Is there a way to generate a class constraint with CodeDom. Because when I use something like ``` var method = new CodeMemberMethod(); var genericParam = new CodeTypeParameter("InterfaceType"); genericParam.Constraints.Add("class"); method.TypeParameters.Add(genericParam); ``` the generated code is like ``` privat...
It seems that there is no straigntforward way to specify that constraint. Neither [for the "struct" constraint](http://msdn.microsoft.com/en-us/library/d5x73970(VS.80).aspx). For the "T : new()" constraint use the flag `HasConstructorConstraint` For the rest use CodeTypeReference as in [this msdn example](http://msd...
411,058
<p>I'm experiencing something really strange!</p> <p>I have a div that I'm hiding with JS (jQuery). Like this:</p> <pre><code>$('#myDiv').hide(); </code></pre> <p>Then when I make a fadeIn like this:</p> <pre><code>$("#myDiv").fadeIn('slow'); </code></pre> <p>then the text loses ClearType in IE but not in FF. If I...
[ { "answer_id": 411066, "author": "SuperRoach", "author_id": 25031, "author_profile": "https://Stackoverflow.com/users/25031", "pm_score": 2, "selected": false, "text": "<p>When fade is applied to IE, it is applying it (at least via jquery) the dxtransform class, which will make it lose a...
2009/01/04
[ "https://Stackoverflow.com/questions/411058", "https://Stackoverflow.com", "https://Stackoverflow.com/users/50896/" ]
I'm experiencing something really strange! I have a div that I'm hiding with JS (jQuery). Like this: ``` $('#myDiv').hide(); ``` Then when I make a fadeIn like this: ``` $("#myDiv").fadeIn('slow'); ``` then the text loses ClearType in IE but not in FF. If I go with toggle insted of fadeIn, then it's all fine. W...
A quick search on the subject shows the following: [jQuery fadeIn/fadeOut IE cleartype glitch](http://blog.bmn.name/2008/03/jquery-fadeinfadeout-ie-cleartype-glitch/) The problem seems to be that the CSS "filter" attribute is not automatically removed. **The most simple solution** to this problem would be removing it...
411,092
<p>I have this bash script running my backup to an external hard drive... only if that drive is mounted (OS X):</p> <pre><code>DIR=/Volumes/External; if [ -e $DIR ]; then rsync -av ~/dir_to_backup $DIR; else echo "$DIR does not exist"; fi </code></pre> <p>This works, but I sense I am misreading the rsync man page...
[ { "answer_id": 411097, "author": "Ray Booysen", "author_id": 42124, "author_profile": "https://Stackoverflow.com/users/42124", "pm_score": 2, "selected": false, "text": "<p>These two flags look like what you're looking for: </p>\n\n<pre><code>--existing, --ignore-non-existing\n</code></...
2009/01/04
[ "https://Stackoverflow.com/questions/411092", "https://Stackoverflow.com", "https://Stackoverflow.com/users/26848/" ]
I have this bash script running my backup to an external hard drive... only if that drive is mounted (OS X): ``` DIR=/Volumes/External; if [ -e $DIR ]; then rsync -av ~/dir_to_backup $DIR; else echo "$DIR does not exist"; fi ``` This works, but I sense I am misreading the rsync man page. Is there a builtin rsync...
These two flags look like what you're looking for: ``` --existing, --ignore-non-existing ``` From the man page: > > --existing, --ignore-non-existing > > This tells rsync to skip creating files (including directories) that do not exist yet on the destination. If this option is combined with the --ignore-exist...
411,103
<p>I have a function with the same name, but with different signature in a base and derived classes. When I am trying to use the base class's function in another class that inherits from the derived, I receive an error. See the following code:</p> <pre><code>class A { public: void foo(string s){}; }; class B ...
[ { "answer_id": 411112, "author": "Johannes Schaub - litb", "author_id": 34509, "author_profile": "https://Stackoverflow.com/users/34509", "pm_score": 7, "selected": false, "text": "<p>It is because name lookup stops if it finds a name in one of your bases. It won't look beyond in other b...
2009/01/04
[ "https://Stackoverflow.com/questions/411103", "https://Stackoverflow.com", "https://Stackoverflow.com/users/44673/" ]
I have a function with the same name, but with different signature in a base and derived classes. When I am trying to use the base class's function in another class that inherits from the derived, I receive an error. See the following code: ``` class A { public: void foo(string s){}; }; class B : public A { ...
Functions in derived classes which don't override functions in base classes but which have the same name will *hide* other functions of the same name in the base class. It is generally considered bad practice to have have functions in derived classes which have the same name as functions in the bass class which aren't...
411,114
<p>I'm used to thinking of member functions as just being a special case of normal functions, where member functions have an extra parameter at the beginning of their parameter list for the 'this' pointer, that is, the object on which the member function is supposed to act. I've used boost::function this way in the pas...
[ { "answer_id": 411125, "author": "jalf", "author_id": 33213, "author_profile": "https://Stackoverflow.com/users/33213", "pm_score": 4, "selected": true, "text": "<p>The standard says next to nothing about where the <code>this</code> pointer should be placed, and in fact it is fairly comm...
2009/01/04
[ "https://Stackoverflow.com/questions/411114", "https://Stackoverflow.com", "https://Stackoverflow.com/users/50385/" ]
I'm used to thinking of member functions as just being a special case of normal functions, where member functions have an extra parameter at the beginning of their parameter list for the 'this' pointer, that is, the object on which the member function is supposed to act. I've used boost::function this way in the past a...
The standard says next to nothing about where the `this` pointer should be placed, and in fact it is fairly common to use a different calling convention for member functions. (So the 'this' pointer is not just an extra first argument, it's actually stored in a different location than the first arg usually is) In parti...
411,134
<p>Rails gurus: I've just discovered <code>named_scope</code> thanks to another SO user. :)</p> <p>I'd like to get the count of a set of rows - i.e. a <code>SELECT COUNT(*)</code>. Additionally, I want to still be able to chain named scopes in the call. </p> <p>Is this a legitimate (albeit weird) usage of named scope...
[ { "answer_id": 411184, "author": "allesklar", "author_id": 19893, "author_profile": "https://Stackoverflow.com/users/19893", "pm_score": 2, "selected": false, "text": "<p>I don't think this is correct at all. Scopes are used to refine find statements and the count query won't play well w...
2009/01/04
[ "https://Stackoverflow.com/questions/411134", "https://Stackoverflow.com", "https://Stackoverflow.com/users/42914/" ]
Rails gurus: I've just discovered `named_scope` thanks to another SO user. :) I'd like to get the count of a set of rows - i.e. a `SELECT COUNT(*)`. Additionally, I want to still be able to chain named scopes in the call. Is this a legitimate (albeit weird) usage of named scope? ``` named_scope :count, :select => "...
The functionality you're looking for is built in. ``` Foobar.count # SELECT count(*) AS count_all FROM "foobars" Foobar.named_scope.count # SELECT count(*) AS count_all FROM "foobars" WHERE .... ``` If you run `script/server` in dev mode, you'll see the queries as they get executed.
411,142
<p>In Visual Studio (C++), is there a way to easily find duplicate headers that are defined in .cpp files?</p> <p>I'm also trying to find ways to detect this situation:</p> <ul> <li>A includes B includes C</li> <li>A includes C</li> <li>=> A doesn't need to include C</li> </ul>
[ { "answer_id": 411156, "author": "JaredPar", "author_id": 23283, "author_profile": "https://Stackoverflow.com/users/23283", "pm_score": 4, "selected": true, "text": "<p>If you want to detect this situation you could add this macro to the top of every file. Substitute A for the name of t...
2009/01/04
[ "https://Stackoverflow.com/questions/411142", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3153/" ]
In Visual Studio (C++), is there a way to easily find duplicate headers that are defined in .cpp files? I'm also trying to find ways to detect this situation: * A includes B includes C * A includes C * => A doesn't need to include C
If you want to detect this situation you could add this macro to the top of every file. Substitute A for the name of the file ``` #if A_H #error "Duplicate include" #else #define A_H #endif ```
411,145
<p>Could anyone explain me why:</p> <pre><code>function doAjax() { var xmlHttpReq = false; try { // Firefox, Opera 8.0+ and Safari xmlHttpReq = new XMLHttpRequest(); } catch (e) { // Internet Explorer try { xmlHttpReq = new ActiveXObject("Msxml2.XMLHTTP"); } ...
[ { "answer_id": 411150, "author": "tvanfosson", "author_id": 12950, "author_profile": "https://Stackoverflow.com/users/12950", "pm_score": 2, "selected": false, "text": "<p>You are reusing the variable e in each try/catch block. Try renaming them to avoid the collision. The other issues...
2009/01/04
[ "https://Stackoverflow.com/questions/411145", "https://Stackoverflow.com", "https://Stackoverflow.com/users/45974/" ]
Could anyone explain me why: ``` function doAjax() { var xmlHttpReq = false; try { // Firefox, Opera 8.0+ and Safari xmlHttpReq = new XMLHttpRequest(); } catch (e) { // Internet Explorer try { xmlHttpReq = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { ...
It would be more sensible to use framework like jQuery (especially if you seriously want to support older versions of IE (pre v6) ) but I'll assume there is a reason you're not doing that. It would be better if a) you don't nest try-catches and b) you factored out a set of functions namely one to get an Xhr object, an...
411,167
<p>I'm using URL rewrite on my site to get URLs like:<br> <em><a href="http://mysite.com/users/john" rel="nofollow noreferrer">http://mysite.com/users/john</a></em><br> instead of<br> <em><a href="http://mysite.com/index.aspx?user=john" rel="nofollow noreferrer">http://mysite.com/index.aspx?user=john</a></em></p> <p>T...
[ { "answer_id": 411179, "author": "brendan", "author_id": 225, "author_profile": "https://Stackoverflow.com/users/225", "pm_score": 2, "selected": false, "text": "<p>Scott Guthrie covers different ways of doing this here without IIS access:</p>\n\n<p><a href=\"http://weblogs.asp.net/scott...
2009/01/04
[ "https://Stackoverflow.com/questions/411167", "https://Stackoverflow.com", "https://Stackoverflow.com/users/39636/" ]
I'm using URL rewrite on my site to get URLs like: *<http://mysite.com/users/john>* instead of *<http://mysite.com/index.aspx?user=john>* To achive this extensionless rewrite with IIS6 and no access to the hosting-server I use the "404-approach". When a request that the server can't find, the mapped 404-page ...
``` form1.Action = Request.RawUrl ``` in combination with ``` HttpContext.Current.RewritePath("/Default.aspx", true); ``` works very well for me. setting the form Action attribute was the piece i was missing... Thanks for the solution!!!
411,228
<p><em>I removed the footer for the time being, site had to go online. So the link is gone as well.</em></p> <p>As you can see (in FF2 as well as in IE7) the footer is at the bottom of the SCREEN, but not at the bottom of the page (content).</p> <p>I have this in my code:</p> <pre><code>&lt;div id="wrap"&gt; &lt...
[ { "answer_id": 411253, "author": "Kon", "author_id": 22303, "author_profile": "https://Stackoverflow.com/users/22303", "pm_score": 2, "selected": false, "text": "<p>How about <a href=\"http://ryanfait.com/sticky-footer/\" rel=\"nofollow noreferrer\">this one</a>?</p>\n" }, { "ans...
2009/01/04
[ "https://Stackoverflow.com/questions/411228", "https://Stackoverflow.com", "https://Stackoverflow.com/users/42389/" ]
*I removed the footer for the time being, site had to go online. So the link is gone as well.* As you can see (in FF2 as well as in IE7) the footer is at the bottom of the SCREEN, but not at the bottom of the page (content). I have this in my code: ``` <div id="wrap"> <div id="top"></div> <div id="content"><...
Right, so with the #size inside the 100%, take the padding off the wrap and add the following to the #content ``` overflow:auto; padding-bottom:30px; ``` then your link works for me in FF
411,247
<p>How can I run a CMD or .bat file in silent mode? I'm looking to prevent the CMD interface from being shown to the user.</p>
[ { "answer_id": 411269, "author": "Frederick The Fool", "author_id": 32688, "author_profile": "https://Stackoverflow.com/users/32688", "pm_score": 6, "selected": false, "text": "<p>Include the phrase:</p>\n<pre><code>@echo off\n</code></pre>\n<p>right at the top of your bat script.</p>\n"...
2009/01/04
[ "https://Stackoverflow.com/questions/411247", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2140183/" ]
How can I run a CMD or .bat file in silent mode? I'm looking to prevent the CMD interface from being shown to the user.
I have proposed in StackOverflow question a way to [run a batch file in the background (**no DOS windows displayed**)](https://stackoverflow.com/questions/298562) That should answer your question. Here it is: --- From your first script, call your second script with the following line: ``` wscript.exe invis.vbs run...
411,249
<p>I'm working for a company that has strict coding style guidelines but no automatic tool to validate them. I've looked around and the only tools I could find were lint like tools that seem to be aimed at verifying what the code does, and preventing bugs and not at making sure the coding style is correct.</p> <p>What...
[ { "answer_id": 411264, "author": "Vinko Vrsalovic", "author_id": 5190, "author_profile": "https://Stackoverflow.com/users/5190", "pm_score": 3, "selected": false, "text": "<p>You are looking for a '<a href=\"http://google.com/search?q=c+code+beautifier\" rel=\"noreferrer\">code beautifie...
2009/01/04
[ "https://Stackoverflow.com/questions/411249", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15109/" ]
I'm working for a company that has strict coding style guidelines but no automatic tool to validate them. I've looked around and the only tools I could find were lint like tools that seem to be aimed at verifying what the code does, and preventing bugs and not at making sure the coding style is correct. What tool shou...
The traditional beautifier [indent](http://en.wikipedia.org/wiki/Indent_(Unix)), available on every Unix machine. The version found on some is [GNU indent](http://www.gnu.org/software/indent/), which can be compiled and installed on every machine. GNU indent can read a set of rules from the file `~/.indent.pro`, for in...
411,254
<p>What are the main differences between PHP and Java that someone proficient in PHP but learning Java should know about?</p> <p><strong>Edit:</strong> I mean differences in the syntax of the languages, i.e their data types, how they handle arrays &amp; reference variables, and so forth :)</p>
[ { "answer_id": 411281, "author": "Lena Schimmel", "author_id": 39946, "author_profile": "https://Stackoverflow.com/users/39946", "pm_score": 4, "selected": false, "text": "<p>I think these two languages (as well as their runtime systems) are too different to list all differences. Some re...
2009/01/04
[ "https://Stackoverflow.com/questions/411254", "https://Stackoverflow.com", "https://Stackoverflow.com/users/49153/" ]
What are the main differences between PHP and Java that someone proficient in PHP but learning Java should know about? **Edit:** I mean differences in the syntax of the languages, i.e their data types, how they handle arrays & reference variables, and so forth :)
Not an exhaustive list, and I'm PHP developer who did a tour of Java a while back so Caveat Emptor. Every variable in Java needs to be prepended with a data type. This includes primitive types such as boolean, int, double and char, as well as Object data-types, such as ArrayList, String, and your own objects ``` int ...
411,255
<p>I have a problem I have a:</p> <pre><code>stack { flow { para "Enter text:" edit_line } edit_box } </code></pre> <p>(simplified version). When user is on edit_line and presses tab, I want it to move to edit_box control (currently, it just loses focus).</p> <pre><code> Thanks, Juraj. </code></pre>
[ { "answer_id": 433789, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 0, "selected": false, "text": "<p>I had a go @ the example listed above and am experiencing the expected behaviour you describe.</p>\n\n<p>What platform are ...
2009/01/04
[ "https://Stackoverflow.com/questions/411255", "https://Stackoverflow.com", "https://Stackoverflow.com/users/45148/" ]
I have a problem I have a: ``` stack { flow { para "Enter text:" edit_line } edit_box } ``` (simplified version). When user is on edit\_line and presses tab, I want it to move to edit\_box control (currently, it just loses focus). ``` Thanks, Juraj. ```
Currently, this only works on linux (and maybe windows) It is a problem with the way the native widgets are rendered on other platforms. Maybe it can be fixed!
411,302
<p>does anyone know why this is a bad request?</p> <pre><code>http://chart.apis.google.com/chart?cht=lxy&amp; chd=t:0,0.7,1.4,2.2,2.9,3.6,4.3,5,5.8,6.5,7.2,7.9,8.6,9.4,10.1,10.8,11.5,12.2,12.9,13.7,14.4,15.1,15.8,16.5,17.3,18,18.7,19.4,20.1,20.9,21.6,22.3,23,23.7,24.5,25.2,25.9,26.6,27.3,28.1,28.8,29.5,30.2,30.9,31.7,...
[ { "answer_id": 411383, "author": "Greg Hewgill", "author_id": 893, "author_profile": "https://Stackoverflow.com/users/893", "pm_score": 3, "selected": false, "text": "<p>Google Charts has a maximum length of URL that it will handle without giving that error. I'm not sure what that limit ...
2009/01/04
[ "https://Stackoverflow.com/questions/411302", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
does anyone know why this is a bad request? ``` http://chart.apis.google.com/chart?cht=lxy& chd=t:0,0.7,1.4,2.2,2.9,3.6,4.3,5,5.8,6.5,7.2,7.9,8.6,9.4,10.1,10.8,11.5,12.2,12.9,13.7,14.4,15.1,15.8,16.5,17.3,18,18.7,19.4,20.1,20.9,21.6,22.3,23,23.7,24.5,25.2,25.9,26.6,27.3,28.1,28.8,29.5,30.2,30.9,31.7,32.4,33.1,33.8,34....
Google Charts has a maximum length of URL that it will handle without giving that error. I'm not sure what that limit is precisely, but your URL is 4774 characters long and I think the limit is just over 2000 characters. You may need to use the simple or extended data encoding instead of text encoding. Text encoding i...
411,306
<p>I have some XML code that looks like this</p> <pre><code>&lt;SEARCHRESULTS&gt; &lt;FUNCTION name="BarGraph"&gt; &lt;PARAMETER name="numList"&gt;&lt;/PARAMETER&gt; &lt;PARAMETER name="maxValue"&gt;&lt;/PARAMETER&gt; &lt;CODE&gt;Some code&lt;/CODE&gt; &lt;/FUNCTION&gt; &lt;/SEARCHRESULTS&gt; </code></...
[ { "answer_id": 411323, "author": "Dirk Vollmar", "author_id": 40347, "author_profile": "https://Stackoverflow.com/users/40347", "pm_score": 3, "selected": true, "text": "<p>Try with a second foreach :</p>\n\n<pre><code>&lt;xsl:template match=\"/\"&gt;\n&lt;xsl:for-each select=\"SEARCHRES...
2009/01/04
[ "https://Stackoverflow.com/questions/411306", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6106/" ]
I have some XML code that looks like this ``` <SEARCHRESULTS> <FUNCTION name="BarGraph"> <PARAMETER name="numList"></PARAMETER> <PARAMETER name="maxValue"></PARAMETER> <CODE>Some code</CODE> </FUNCTION> </SEARCHRESULTS> ``` And I want to extract a list of parameter names for each function, so far I'v...
Try with a second foreach : ``` <xsl:template match="/"> <xsl:for-each select="SEARCHRESULTS/FUNCTION"> <ROW> <COL> <DATA> <xsl:value-of select="@name" /> </DATA> </COL> <COL> <DATA> <xsl:for-each select="PARAMETER"> <!-- separate the names by a semicolon (do n...
411,316
<p>I've made a C# usercontrol with one textbox and one richtextbox.</p> <p>How can I access the properties of the richtextbox from outside the usercontrol.</p> <p>For example.. if i put it in a form, how can i use the Text propertie of the richtextbox???</p> <p>thanks</p>
[ { "answer_id": 411327, "author": "Robert Venables", "author_id": 39315, "author_profile": "https://Stackoverflow.com/users/39315", "pm_score": 2, "selected": false, "text": "<p>Change the access modifier (\"Modifiers\") of the RichTextBox in the property grid to Public.</p>\n" }, { ...
2009/01/04
[ "https://Stackoverflow.com/questions/411316", "https://Stackoverflow.com", "https://Stackoverflow.com/users/50069/" ]
I've made a C# usercontrol with one textbox and one richtextbox. How can I access the properties of the richtextbox from outside the usercontrol. For example.. if i put it in a form, how can i use the Text propertie of the richtextbox??? thanks
Cleanest way is to expose the desired properties as properties of your usercontrol, e.g: ``` class MyUserControl { // expose the Text of the richtext control (read-only) public string TextOfRichTextBox { get { return richTextBox.Text; } } // expose the Checked Property of a checkbox (read/write) public...
411,330
<p>Which one of the following do you do:</p> <pre><code>var = true; if (...) var = false; </code></pre> <p>Or</p> <pre><code>if (...) var = false; else var = true; </code></pre> <p>Is there a reason you pick on or the other?</p> <p>I'm working on the premise that nothing else is happening to var. The next line of ...
[ { "answer_id": 411338, "author": "Daniel Sloof", "author_id": 51133, "author_profile": "https://Stackoverflow.com/users/51133", "pm_score": 1, "selected": false, "text": "<p>Depends on the context. I would use the second option when it is clear that 'var' needs to be true when IF fails....
2009/01/04
[ "https://Stackoverflow.com/questions/411330", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5441/" ]
Which one of the following do you do: ``` var = true; if (...) var = false; ``` Or ``` if (...) var = false; else var = true; ``` Is there a reason you pick on or the other? I'm working on the premise that nothing else is happening to var. The next line of code might be something like: ``` if (var) { ... } ```
How about `var = { ... }` directly since it's a `boolean`?
411,331
<p>I found several other questions on SO regarding the JavaMail API and sending mail through an SMTP server, but none of them discussed using TLS security. I'm trying to use JavaMail to send status updates to myself through my work SMTP mail server, but it requires TLS, and I can't find any examples online of how to us...
[ { "answer_id": 411362, "author": "Sarat", "author_id": 18937, "author_profile": "https://Stackoverflow.com/users/18937", "pm_score": 7, "selected": true, "text": "<p>We actually have some notification code in our product that uses TLS to send mail if it is available.</p>\n\n<p>You will n...
2009/01/04
[ "https://Stackoverflow.com/questions/411331", "https://Stackoverflow.com", "https://Stackoverflow.com/users/42891/" ]
I found several other questions on SO regarding the JavaMail API and sending mail through an SMTP server, but none of them discussed using TLS security. I'm trying to use JavaMail to send status updates to myself through my work SMTP mail server, but it requires TLS, and I can't find any examples online of how to use J...
We actually have some notification code in our product that uses TLS to send mail if it is available. You will need to set the Java Mail properties. You only need the TLS one but you might need SSL if your SMTP server uses SSL. ``` Properties props = new Properties(); props.put("mail.smtp.starttls.enable","true"); pr...
411,352
<p>I have now seen 2 methods for determining if an argument has been passed to a JavaScript function. I'm wondering if one method is better than the other or if one is just bad to use?</p> <pre><code> function Test(argument1, argument2) { if (Test.arguments.length == 1) argument2 = 'blah'; alert(argument2...
[ { "answer_id": 411372, "author": "Christoph", "author_id": 48015, "author_profile": "https://Stackoverflow.com/users/48015", "pm_score": 9, "selected": true, "text": "<p>There are several different ways to check if an argument was passed to a function. In addition to the two you mentione...
2009/01/04
[ "https://Stackoverflow.com/questions/411352", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5441/" ]
I have now seen 2 methods for determining if an argument has been passed to a JavaScript function. I'm wondering if one method is better than the other or if one is just bad to use? ``` function Test(argument1, argument2) { if (Test.arguments.length == 1) argument2 = 'blah'; alert(argument2); } Test('...
There are several different ways to check if an argument was passed to a function. In addition to the two you mentioned in your (original) question - checking `arguments.length` or using the `||` operator to provide default values - one can also explicitly check the arguments for `undefined` via `argument2 === undefine...
411,396
<p>Hi I've got a DIV section that has only its title visible initially. What I would like to achieve is that when the visitor clicks anywhere on the area of <code>toggle_section</code> the <code>toggle_stuff</code> div toggles between visible/hidden.</p> <pre><code>&lt;div id="toggle_section" onclick="javascript...
[ { "answer_id": 411458, "author": "andyk", "author_id": 26721, "author_profile": "https://Stackoverflow.com/users/26721", "pm_score": 0, "selected": false, "text": "<p>I don't really know if this would work, but try giving the link element a bigger <code>z-index</code> value than the togg...
2009/01/04
[ "https://Stackoverflow.com/questions/411396", "https://Stackoverflow.com", "https://Stackoverflow.com/users/47193/" ]
Hi I've got a DIV section that has only its title visible initially. What I would like to achieve is that when the visitor clicks anywhere on the area of `toggle_section` the `toggle_stuff` div toggles between visible/hidden. ``` <div id="toggle_section" onclick="javascript: new Effect.toggle('toggle_stuff', 'sl...
The most simple solution is to **add an extra onclick handler to the link** within your DIV which stops event propagation: ``` <div id="toggle_section" onclick="javascript: new Effect.toggle('toggle_stuff', 'slide');"> <div id="toggle_title">Some title</div> <div id="toggle_stuff"> some content s...
411,410
<p>What's the best practice for setting up a subversion repository on a linux development machine. External users need to be able to access a specific repository, but nothing else on the machine. I know one answer is to set up a dedicated repository, but I'm looking for a single machine solution: location of reposito...
[ { "answer_id": 411433, "author": "Eugene Yokota", "author_id": 3827, "author_profile": "https://Stackoverflow.com/users/3827", "pm_score": 3, "selected": false, "text": "<p>One of the popular access methods to Subversion is via Apache module. You can set put different rights at the direc...
2009/01/04
[ "https://Stackoverflow.com/questions/411410", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14167/" ]
What's the best practice for setting up a subversion repository on a linux development machine. External users need to be able to access a specific repository, but nothing else on the machine. I know one answer is to set up a dedicated repository, but I'm looking for a single machine solution: location of repositories,...
I work for an IT operations infrastructure automation company; we do this all the time. Location of repository: We use "/srv/svn" by default to store all SVN repositories, unless a customer has a specific requirement, for example an existing repository might be stored on a ReadyNAS shared filesystem. Accounts: All o...
411,422
<p>I'm reading some code in the <a href="http://www.ogre3d.org" rel="nofollow noreferrer">Ogre3D</a> implementation and I can't understand what a <code>void *</code> type variable means. What does a pointer to <code>void</code> mean in C++?</p>
[ { "answer_id": 411424, "author": "Otávio Décio", "author_id": 48684, "author_profile": "https://Stackoverflow.com/users/48684", "pm_score": 2, "selected": false, "text": "<p>It's a raw pointer to a spot in memory. It doesn't allow any pointer arithmetic like char * or int *. </p>\n\n<p>H...
2009/01/04
[ "https://Stackoverflow.com/questions/411422", "https://Stackoverflow.com", "https://Stackoverflow.com/users/25418/" ]
I'm reading some code in the [Ogre3D](http://www.ogre3d.org) implementation and I can't understand what a `void *` type variable means. What does a pointer to `void` mean in C++?
A pointer to void, `void*` can point to any object: ``` int a = 5; void *p = &a; double b = 3.14; p = &b; ``` You can't dereference, increment or decrement that pointer, because you don't know what type you point to. The idea is that `void*` can be used for functions like `memcpy` that just copy memory blocks aroun...
411,447
<p>After posting <a href="https://stackoverflow.com/questions/410890/how-to-trace-a-nullpointerexception-in-a-chain-of-getters" title="How to trace a NullPointerException in a chain of getters?">this question</a> and reading <a href="https://stackoverflow.com/questions/271526/How-to-avoid-null-statements-in-java" title...
[ { "answer_id": 411454, "author": "Ray Booysen", "author_id": 42124, "author_profile": "https://Stackoverflow.com/users/42124", "pm_score": 1, "selected": false, "text": "<p>Have you had a look at <a href=\"http://research.microsoft.com/en-us/projects/specsharp/\" rel=\"nofollow noreferre...
2009/01/04
[ "https://Stackoverflow.com/questions/411447", "https://Stackoverflow.com", "https://Stackoverflow.com/users/39946/" ]
After posting [this question](https://stackoverflow.com/questions/410890/how-to-trace-a-nullpointerexception-in-a-chain-of-getters "How to trace a NullPointerException in a chain of getters?") and reading [that one](https://stackoverflow.com/questions/271526/How-to-avoid-null-statements-in-java "how to avoid null state...
A very good follow up question. I consider `null` a truly special value, and if a method may return `null` it must clearly document in the Javadoc when it does (`@return some value ..., or null if ...`). When coding I'm defensive, and assume a method may return `null` unless I'm convinced it can't (e.g., because the Ja...
411,457
<p>I'm binding a domain objects property to the Text property of a System.Windows.Forms.Label using the <code>DataBindings</code>:</p> <pre><code>Label l = new Label(); l.DataBindings.Add(new Binding("Text",myDomainObject,"MyProperty")); </code></pre> <p>However, when I change the domain object, the Label does not re...
[ { "answer_id": 411483, "author": "Kent Boogaart", "author_id": 5380, "author_profile": "https://Stackoverflow.com/users/5380", "pm_score": 3, "selected": true, "text": "<p>Your domain object should implement <a href=\"http://msdn.microsoft.com/en-us/library/system.componentmodel.inotifyp...
2009/01/04
[ "https://Stackoverflow.com/questions/411457", "https://Stackoverflow.com", "https://Stackoverflow.com/users/50697/" ]
I'm binding a domain objects property to the Text property of a System.Windows.Forms.Label using the `DataBindings`: ``` Label l = new Label(); l.DataBindings.Add(new Binding("Text",myDomainObject,"MyProperty")); ``` However, when I change the domain object, the Label does not reflect the change. I know that for com...
Your domain object should implement [INotifyPropertyChanged](http://msdn.microsoft.com/en-us/library/system.componentmodel.inotifypropertychanged.aspx) so that the binding knows when the underlying property has changed.