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
35,805
<p>If I create a class <code>A</code> as follows:</p> <pre><code>class A: def __init__(self): self.name = 'A' </code></pre> <p>Inspecting the <code>__dict__</code> member looks like <code>{'name': 'A'}</code></p> <p>If however I create a class <code>B</code>:</p> <pre><code>class B: name = 'B' </cod...
[ { "answer_id": 35823, "author": "Carl Meyer", "author_id": 3207, "author_profile": "https://Stackoverflow.com/users/3207", "pm_score": 7, "selected": true, "text": "<p><code>B.name</code> is a class attribute, not an instance attribute. It shows up in <code>B.__dict__</code>, but not in...
2008/08/30
[ "https://Stackoverflow.com/questions/35805", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3154/" ]
If I create a class `A` as follows: ``` class A: def __init__(self): self.name = 'A' ``` Inspecting the `__dict__` member looks like `{'name': 'A'}` If however I create a class `B`: ``` class B: name = 'B' ``` `__dict__` is empty. What is the difference between the two, and why doesn't `name` sh...
`B.name` is a class attribute, not an instance attribute. It shows up in `B.__dict__`, but not in `b = B(); b.__dict__`. The distinction is obscured somewhat because when you access an attribute on an instance, the class dict is a fallback. So in the above example, `b.name` will give you the value of `B.name`.
35,817
<p>When using os.system() it's often necessary to escape filenames and other arguments passed as parameters to commands. How can I do this? Preferably something that would work on multiple operating systems/shells but in particular for bash.</p> <p>I'm currently doing the following, but am sure there must be a libra...
[ { "answer_id": 35831, "author": "pauldoo", "author_id": 755, "author_profile": "https://Stackoverflow.com/users/755", "pm_score": 2, "selected": false, "text": "<p>I believe that os.system just invokes whatever command shell is configured for the user, so I don't think you can do it in a...
2008/08/30
[ "https://Stackoverflow.com/questions/35817", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3715/" ]
When using os.system() it's often necessary to escape filenames and other arguments passed as parameters to commands. How can I do this? Preferably something that would work on multiple operating systems/shells but in particular for bash. I'm currently doing the following, but am sure there must be a library function ...
This is what I use: ``` def shellquote(s): return "'" + s.replace("'", "'\\''") + "'" ``` The shell will always accept a quoted filename and remove the surrounding quotes before passing it to the program in question. Notably, this avoids problems with filenames that contain spaces or any other kind of nasty shel...
35,842
<p>How do I get the id of my Java process? </p> <p>I know there are several platform-dependent hacks, but I would prefer a more generic solution.</p>
[ { "answer_id": 35885, "author": "Wouter Coekaerts", "author_id": 3432, "author_profile": "https://Stackoverflow.com/users/3432", "pm_score": 10, "selected": true, "text": "<p>There exists no platform-independent way that can be guaranteed to work in all jvm implementations.\n<code>Manage...
2008/08/30
[ "https://Stackoverflow.com/questions/35842", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3583/" ]
How do I get the id of my Java process? I know there are several platform-dependent hacks, but I would prefer a more generic solution.
There exists no platform-independent way that can be guaranteed to work in all jvm implementations. `ManagementFactory.getRuntimeMXBean().getName()` looks like the best (closest) solution, and typically includes the PID. It's short, and *probably* works in every implementation in wide use. On linux+windows it returns ...
35,879
<p>I am building an open search add-on for Firefox/IE and the image needs to be Base64 Encoded so how can I base 64 encode the favicon I have?</p> <p>I am only familiar with PHP</p>
[ { "answer_id": 35881, "author": "OysterD", "author_id": 2638, "author_profile": "https://Stackoverflow.com/users/2638", "pm_score": 0, "selected": false, "text": "<p>Google led me to <a href=\"http://fr.php.net/base64_encode\" rel=\"nofollow noreferrer\">this</a> solution (base64_encode)...
2008/08/30
[ "https://Stackoverflow.com/questions/35879", "https://Stackoverflow.com", "https://Stackoverflow.com/users/115/" ]
I am building an open search add-on for Firefox/IE and the image needs to be Base64 Encoded so how can I base 64 encode the favicon I have? I am only familiar with PHP
As far as I remember there is an xml element for the image data. You can use this [website](http://www.motobit.com/util/base64-decoder-encoder.asp) to encode a file (use the upload field). Then just copy and paste the data to the XML element. You could also use PHP to do this like so: ``` <?php $im = file_ge...
35,896
<p>Is there a portable, not patent-restricted way to play compressed sound files in C# / .Net? I want to play short "jingle" sounds on various events occuring in the program.</p> <p><a href="http://msdn.microsoft.com/en-us/library/system.media.soundplayer.aspx" rel="noreferrer">System.Media.SoundPlayer</a> can handle ...
[ { "answer_id": 36050, "author": "skolima", "author_id": 3205, "author_profile": "https://Stackoverflow.com/users/3205", "pm_score": 4, "selected": true, "text": "<p>I finally revisited this topic, and, using help from <a href=\"https://stackoverflow.com/a/7152153/3205\">BrokenGlass on wr...
2008/08/30
[ "https://Stackoverflow.com/questions/35896", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3205/" ]
Is there a portable, not patent-restricted way to play compressed sound files in C# / .Net? I want to play short "jingle" sounds on various events occuring in the program. [System.Media.SoundPlayer](http://msdn.microsoft.com/en-us/library/system.media.soundplayer.aspx) can handle only WAV, but those are typically to b...
I finally revisited this topic, and, using help from [BrokenGlass on writing WAVE header](https://stackoverflow.com/a/7152153/3205), updated csvorbis. I've added an [OggDecodeStream](https://github.com/mono/csvorbis/blob/master/OggDecoder/OggDecodeStream.cs) that can be passed to `System.Media.SoundPlayer` to simply pl...
35,905
<p>I've created a few <code>autorun</code> script files on various USB devices that run <code>bash</code> scripts when they mount. These scripts run "in the background", how do I get them to run in a terminal window? (Like the "Application in Terminal" gnome Launcher type.)</p>
[ { "answer_id": 35924, "author": "Vagnerr", "author_id": 3720, "author_profile": "https://Stackoverflow.com/users/3720", "pm_score": 4, "selected": true, "text": "<p>Run them as a two stage process with your \"autorun\" script calling the second script in a new terminal eg</p>\n\n<pre><co...
2008/08/30
[ "https://Stackoverflow.com/questions/35905", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3715/" ]
I've created a few `autorun` script files on various USB devices that run `bash` scripts when they mount. These scripts run "in the background", how do I get them to run in a terminal window? (Like the "Application in Terminal" gnome Launcher type.)
Run them as a two stage process with your "autorun" script calling the second script in a new terminal eg ``` gnome-terminal -e top --title Testing ``` Would run the program "top" in a new gnome terminal window with the title "Testing" You can add additional arguments like setting the geometry to determine the size ...
35,914
<p>Here's the situation: I am trying to launch an application, but the location of the .exe isn't known to me. Now, if the file extension is registered (in Windows), I can do something like:</p> <pre><code>Process.Start("Sample.xls"); </code></pre> <p>However, I need to pass some command line arguments as well. I c...
[ { "answer_id": 35928, "author": "Palgar", "author_id": 3479, "author_profile": "https://Stackoverflow.com/users/3479", "pm_score": 2, "selected": false, "text": "<p>If you query the registry, you can retrieve the data about the registered file type and then call the app directly passing ...
2008/08/30
[ "https://Stackoverflow.com/questions/35914", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2258/" ]
Here's the situation: I am trying to launch an application, but the location of the .exe isn't known to me. Now, if the file extension is registered (in Windows), I can do something like: ``` Process.Start("Sample.xls"); ``` However, I need to pass some command line arguments as well. I couldn't get this to work ``...
Using my code from [this](https://stackoverflow.com/questions/24954/windows-list-and-launch-applications-associated-with-an-extension#24974) answer you can get command associated with xls extension. Then you can pass this command to `Process.Start` method.
35,948
<p>I'm using Google App Engine and Django templates.<br> I have a table that I want to display the objects look something like:<br></p> <pre><code>Object Result: Items = [item1,item2] Users = [{name='username',item1=3,item2=4},..] </code></pre> <p>The Django template is:</p> <pre><code>&lt;table&gt; &lt;tr a...
[ { "answer_id": 35978, "author": "David Webb", "author_id": 3171, "author_profile": "https://Stackoverflow.com/users/3171", "pm_score": 3, "selected": false, "text": "<p>I'm assuming that the part the doesn't work is <code>{{ user.item }}</code>.</p>\n\n<p>Django will be trying a dictiona...
2008/08/30
[ "https://Stackoverflow.com/questions/35948", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3117/" ]
I'm using Google App Engine and Django templates. I have a table that I want to display the objects look something like: ``` Object Result: Items = [item1,item2] Users = [{name='username',item1=3,item2=4},..] ``` The Django template is: ``` <table> <tr align="center"> <th>user</th> {% for item ...
I found a "nicer"/"better" solution for getting variables inside Its not the nicest way, but it works. You install a custom filter into django which gets the key of your dict as a parameter To make it work in google app-engine you need to add a file to your main directory, I called mine *django\_hack.py* which contai...
35,954
<p>I have a query that originally looks like this:</p> <pre><code>select c.Id, c.Name, c.CountryCode, c.CustomerNumber, cacc.AccountNumber, ca.Line1, ca.CityName, ca.PostalCode from dbo.Customer as c left join dbo.CustomerAddress as ca on ca.CustomerId = c.Id left join dbo.CustomerAccount as cacc on cacc.CustomerId = ...
[ { "answer_id": 35955, "author": "wesc", "author_id": 3738, "author_profile": "https://Stackoverflow.com/users/3738", "pm_score": 0, "selected": false, "text": "<p>I <em>think</em> that an unordered_map and hash_map are more or less the same thing. The difference is that the STL doesn't o...
2008/08/30
[ "https://Stackoverflow.com/questions/35954", "https://Stackoverflow.com", "https://Stackoverflow.com/users/372/" ]
I have a query that originally looks like this: ``` select c.Id, c.Name, c.CountryCode, c.CustomerNumber, cacc.AccountNumber, ca.Line1, ca.CityName, ca.PostalCode from dbo.Customer as c left join dbo.CustomerAddress as ca on ca.CustomerId = c.Id left join dbo.CustomerAccount as cacc on cacc.CustomerId = c.Id where c....
[Boost documentation of unordered containers](http://www.boost.org/doc/libs/1_36_0/doc/html/unordered.html) The difference is in the method of how you generate the look up. In the map/set containers the `operator<` is used to generate an ordered tree. In the unordered containers, an `operator( key ) => index` is use...
35,973
<p>What is the best approach to define additional data for typedef enums in C?</p> <p>Example:</p> <pre><code>typedef enum { kVizsla = 0, kTerrier = 3, kYellowLab = 10 } DogType; </code></pre> <p>Now I would like to define names for each, for example <code>kVizsla</code> should be "vizsla". I currently use a f...
[ { "answer_id": 35994, "author": "On Freund", "author_id": 2150, "author_profile": "https://Stackoverflow.com/users/2150", "pm_score": 0, "selected": false, "text": "<p>That's kind of an open ended question, but one suggestion would be to use a map with the enum as the key type and the ex...
2008/08/30
[ "https://Stackoverflow.com/questions/35973", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3740/" ]
What is the best approach to define additional data for typedef enums in C? Example: ``` typedef enum { kVizsla = 0, kTerrier = 3, kYellowLab = 10 } DogType; ``` Now I would like to define names for each, for example `kVizsla` should be "vizsla". I currently use a function that returns a string using a large ...
@dmckee: I think the suggested solution is good, but for simple data (e.g. if only the name is needed) it could be augmented with auto-generated code. While there are lots of ways to auto-generate code, for something as simple as this I believe you could write a simple XSLT that takes in an XML representation of the en...
35,988
<p>Is there a way to conveniently define a C-like structure in Python? I'm tired of writing stuff like:</p> <pre><code>class MyStruct(): def __init__(self, field1, field2, field3): self.field1 = field1 self.field2 = field2 self.field3 = field3 </code></pre>
[ { "answer_id": 35990, "author": "Mark Biek", "author_id": 305, "author_profile": "https://Stackoverflow.com/users/305", "pm_score": 6, "selected": false, "text": "<p>How about a dictionary?</p>\n\n<p>Something like this:</p>\n\n<pre><code>myStruct = {'field1': 'some val', 'field2': 'some...
2008/08/30
[ "https://Stackoverflow.com/questions/35988", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3738/" ]
Is there a way to conveniently define a C-like structure in Python? I'm tired of writing stuff like: ``` class MyStruct(): def __init__(self, field1, field2, field3): self.field1 = field1 self.field2 = field2 self.field3 = field3 ```
Use a [named tuple](https://docs.python.org/2/library/collections.html#collections.namedtuple), which was added to the [collections module](http://docs.python.org/library/collections.html) in the standard library in Python 2.6. It's also possible to use Raymond Hettinger's [named tuple](http://code.activestate.com/reci...
36,001
<p>I have a table defined (see code snippet below). How can I add a constraint or whatever so that the LastUpdate column is automatically updated anytime the row is changed?</p> <pre><code>CREATE TABLE dbo.Profiles ( UserName varchar(100) NOT NULL, LastUpdate ...
[ { "answer_id": 36002, "author": "Kibbee", "author_id": 1862, "author_profile": "https://Stackoverflow.com/users/1862", "pm_score": 2, "selected": false, "text": "<p>You're going to have to use triggers for that.</p>\n" }, { "answer_id": 36011, "author": "SQLMenace", "auth...
2008/08/30
[ "https://Stackoverflow.com/questions/36001", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3747/" ]
I have a table defined (see code snippet below). How can I add a constraint or whatever so that the LastUpdate column is automatically updated anytime the row is changed? ``` CREATE TABLE dbo.Profiles ( UserName varchar(100) NOT NULL, LastUpdate ...
A default constraint only works on inserts; for an update use a trigger.
36,014
<p>I'm working on a project using the <a href="http://antlr.org" rel="noreferrer">ANTLR</a> parser library for C#. I've built a grammar to parse some text and it works well. However, when the parser comes across an illegal or unexpected token, it throws one of many exceptions. The problem is that in some cases (not ...
[ { "answer_id": 36029, "author": "Daniel Auger", "author_id": 1644, "author_profile": "https://Stackoverflow.com/users/1644", "pm_score": 2, "selected": false, "text": "<p>Is it possible that the exception is being thrown in another thread? Obviously your calling code is single threaded, ...
2008/08/30
[ "https://Stackoverflow.com/questions/36014", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3347/" ]
I'm working on a project using the [ANTLR](http://antlr.org) parser library for C#. I've built a grammar to parse some text and it works well. However, when the parser comes across an illegal or unexpected token, it throws one of many exceptions. The problem is that in some cases (not all) that my try/catch block won't...
I believe I understand the problem. The exception is being caught, the issue is confusion over the debugger's behavior and differences in the debugger settings among each person trying to repro it. In the 3rd case from your repro I believe you are getting the following message: "NoViableAltException was unhandled by u...
36,028
<p>How do I assign a method's output to a textbox value without code behind?</p> <pre><code>&lt;%@ Page Language="VB" %&gt; &lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; &lt;script runat="server"&gt; Public TextFromString As String =...
[ { "answer_id": 36164, "author": "Toran Billups", "author_id": 2701, "author_profile": "https://Stackoverflow.com/users/2701", "pm_score": 1, "selected": false, "text": "<p>Have you tried using an HTML control instead of the server control? Does it also cause a compilation error?</p>\n\n...
2008/08/30
[ "https://Stackoverflow.com/questions/36028", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3747/" ]
How do I assign a method's output to a textbox value without code behind? ``` <%@ Page Language="VB" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <script runat="server"> Public TextFromString As String = "test text test text" Publi...
There's a couple of different expression types in .ASPX files. There's: ``` <%= TextFromMethod %> ``` which simply reserves a literal control, and outputs the text at render time. and then there's: ``` <%# TextFromMethod %> ``` which is a databinding expression, evaluated when the control is DataBound(). There's...
36,058
<p>I have a popup window containing a form which gathers data for a report. When I click submit in that window, I want it to close the popup, and open the report in the original window that called the popup.</p> <p>I think I can open the report in the correct window by using</p> <pre><code>{ :target =&gt; &lt;name of...
[ { "answer_id": 36065, "author": "Craig", "author_id": 1611, "author_profile": "https://Stackoverflow.com/users/1611", "pm_score": 0, "selected": false, "text": "<p>How is <a href=\"http://railsforum.com/viewtopic.php?id=17785\" rel=\"nofollow noreferrer\">this</a> for starters?</p>\n\n<p...
2008/08/30
[ "https://Stackoverflow.com/questions/36058", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I have a popup window containing a form which gathers data for a report. When I click submit in that window, I want it to close the popup, and open the report in the original window that called the popup. I think I can open the report in the correct window by using ``` { :target => <name of window> } ``` in the `fo...
`:target =>` adds the html attribute target to the link. This opens up a new window and names the new window the target. You have to use javascript or Ajax to redirect the old page, ``` window.opener.location.href="http://new_url"; ``` and then close the old window. ``` window.close(); ``` This can be done eithe...
36,064
<p>I am attempting to update a project from ASP.NET MVC Preview 3 to Preview 5 and it seems that Controller.ReadFromRequest(string key) has been removed from the Controller class. Does anyone know of any alternatives to retrieving information based on an identifier from a form?</p>
[ { "answer_id": 36206, "author": "Dane O'Connor", "author_id": 1946, "author_profile": "https://Stackoverflow.com/users/1946", "pm_score": 2, "selected": false, "text": "<p>Not sure where it went. You could roll your own extension though:</p>\n\n<p>public static class MyBindingExtensions ...
2008/08/30
[ "https://Stackoverflow.com/questions/36064", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3412/" ]
I am attempting to update a project from ASP.NET MVC Preview 3 to Preview 5 and it seems that Controller.ReadFromRequest(string key) has been removed from the Controller class. Does anyone know of any alternatives to retrieving information based on an identifier from a form?
Looks like they've added controller.UpdateModel to address this issue, signature is: ``` UpdateModel(object model, string[] keys) ``` I haven't upgraded my app personally, so I'm not sure of the actual usage. I'll be interested to find out about this myself, as I'm using `controller.ReadFromRequest` as well.
36,077
<p>I'm looking for an answer in MS VC++.</p> <p>When debugging a large C++ application, which unfortunately has a very extensive usage of C++ exceptions. Sometimes I catch an exception a little later than I actually want.</p> <p>Example in pseudo code:</p> <pre><code>FunctionB() { ... throw e; ... } Fun...
[ { "answer_id": 36087, "author": "Paul Tomblin", "author_id": 3333, "author_profile": "https://Stackoverflow.com/users/3333", "pm_score": 0, "selected": false, "text": "<p>Other languages? Well, in Java you call e.printStackTrace(); It doesn't get much simpler than that.</p>\n" }, {...
2008/08/30
[ "https://Stackoverflow.com/questions/36077", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3153/" ]
I'm looking for an answer in MS VC++. When debugging a large C++ application, which unfortunately has a very extensive usage of C++ exceptions. Sometimes I catch an exception a little later than I actually want. Example in pseudo code: ``` FunctionB() { ... throw e; ... } FunctionA() { ... Funct...
If you are just interested in where the exception came from, you could just write a simple macro like ``` #define throwException(message) \ { \ std::ostringstream oss; \ oss << __FILE __ << " " << __LINE__ << " " \ << __FUNC__ << " " << message; \ throw...
36,079
<p>In my PHP web app, I want to be notified via email whenever certain errors occur. I'd like to use my Gmail account for sending these. How could this be done?</p>
[ { "answer_id": 36086, "author": "maxsilver", "author_id": 1477, "author_profile": "https://Stackoverflow.com/users/1477", "pm_score": 2, "selected": false, "text": "<p>You could use PEAR's mail function with Gmail's SMTP Server</p>\n\n<p>Note that when sending e-mail using Gmail's SMTP s...
2008/08/30
[ "https://Stackoverflow.com/questions/36079", "https://Stackoverflow.com", "https://Stackoverflow.com/users/356/" ]
In my PHP web app, I want to be notified via email whenever certain errors occur. I'd like to use my Gmail account for sending these. How could this be done?
Gmail's SMTP-server requires a very specific configuration. From [Gmail help](http://mail.google.com/support/bin/answer.py?answer=13287): ``` Outgoing Mail (SMTP) Server (requires TLS) - smtp.gmail.com - Use Authentication: Yes - Use STARTTLS: Yes (some clients call this SSL) - Port: 465 or 587 Account Name: yo...
36,081
<p>I'm trying to leverage the using block more and more these days when I have an object that implements IDisposable but one thing I have not figured out is how to catch an exception as I would in a normal try/catch/finally ... any code samples to point me in the right direction?</p> <p>Edit: The question was modified...
[ { "answer_id": 36094, "author": "Quibblesome", "author_id": 1143, "author_profile": "https://Stackoverflow.com/users/1143", "pm_score": 2, "selected": false, "text": "<p>Yeah there is nothing different about throwing exceptions in using blocks.\nRemember that the using block basically tr...
2008/08/30
[ "https://Stackoverflow.com/questions/36081", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2701/" ]
I'm trying to leverage the using block more and more these days when I have an object that implements IDisposable but one thing I have not figured out is how to catch an exception as I would in a normal try/catch/finally ... any code samples to point me in the right direction? Edit: The question was modified after rea...
I don't really understand the question - you throw an exception as you normally would. If `MyThing` implements `IDisposable`, then: ``` using ( MyThing thing = new MyThing() ) { ... throw new ApplicationException("oops"); } ``` And `thing.Dispose` will be called as you leave the block, as the exception's thr...
36,101
<p>How do I "name" a browser window in ROR, such that I can open a page in it later, from another (popup) window (using the target="name" html parameter)</p>
[ { "answer_id": 36131, "author": "John Topley", "author_id": 1450, "author_profile": "https://Stackoverflow.com/users/1450", "pm_score": 4, "selected": true, "text": "<p>You have to use JavaScript for this:</p>\n\n<pre><code>&lt;script type=\"text/javascript\"&gt;\n window.name = \"MyWin...
2008/08/30
[ "https://Stackoverflow.com/questions/36101", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3764/" ]
How do I "name" a browser window in ROR, such that I can open a page in it later, from another (popup) window (using the target="name" html parameter)
You have to use JavaScript for this: ``` <script type="text/javascript"> window.name = "MyWindow"; </script> ``` Of course you could easily package this up into a Rails helper method. For example, in `app/helpers/application_helper.rb` add a new method: ``` def window_name(name) content_for(:window_name) do ...
36,109
<p>The following shell script takes a list of arguments, turns Unix paths into WINE/Windows paths and invokes the given executable under WINE.</p> <pre><code>#! /bin/sh if [ "${1+set}" != "set" ] then echo "Usage; winewrap EXEC [ARGS...]" exit 1 fi EXEC="$1" shift ARGS="" for p in "$@"; do if [ -e "$p" ] ...
[ { "answer_id": 36113, "author": "Kyle Cronin", "author_id": 658, "author_profile": "https://Stackoverflow.com/users/658", "pm_score": 0, "selected": false, "text": "<p>You can try preceeding the spaces with \\ like so:</p>\n\n<pre><code>/home/chris/.wine/drive_c/Program Files/Microsoft\\...
2008/08/30
[ "https://Stackoverflow.com/questions/36109", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1412/" ]
The following shell script takes a list of arguments, turns Unix paths into WINE/Windows paths and invokes the given executable under WINE. ``` #! /bin/sh if [ "${1+set}" != "set" ] then echo "Usage; winewrap EXEC [ARGS...]" exit 1 fi EXEC="$1" shift ARGS="" for p in "$@"; do if [ -e "$p" ] then p=$(w...
I you do want to have the assignment to CMD you should use `eval $CMD` instead of just `$CMD` in the last line of your script. This should solve your problem with spaces in the paths, I don't know what to do about the "\t" problem.
36,114
<p>I know I must be missing something, but in a <code>while</code> statement how does the variable hold the data, when it finishes the first pass and goes into the second pass?</p> <hr> <p>{</p> <pre><code>int num1 = 0 ; int num2 = 0; int num3 = 0; while (num1 &lt; 10) {cout &lt;&lt; "enter your first number: ...
[ { "answer_id": 36133, "author": "Kyle Cronin", "author_id": 658, "author_profile": "https://Stackoverflow.com/users/658", "pm_score": 1, "selected": false, "text": "<p>I'm not sure I understand your question. In C any data that's not overwritten is carried over into the next iteration of...
2008/08/30
[ "https://Stackoverflow.com/questions/36114", "https://Stackoverflow.com", "https://Stackoverflow.com/users/335696/" ]
I know I must be missing something, but in a `while` statement how does the variable hold the data, when it finishes the first pass and goes into the second pass? --- { ``` int num1 = 0 ; int num2 = 0; int num3 = 0; while (num1 < 10) {cout << "enter your first number: "; cin >> num1; cout << "Enter your secon...
Is num1 the variable you're having trouble with? This line: ``` cin >> num1; ``` is setting num1 to the value input by the user. So the value calculated for it in the previous run through the loop is being overwritten each time by the new input.
36,129
<p>I'm reading through head first design patterns at the moment and while the book is excellent I also would like to see how these are actually used in the real world.</p> <p>If you know of a good example of design pattern usage (preferably in a OSS program so we can have a look :) then please list it below.</p>
[ { "answer_id": 36167, "author": "rp.", "author_id": 2536, "author_profile": "https://Stackoverflow.com/users/2536", "pm_score": 3, "selected": true, "text": "<p>An ah-ha moment for me for the observer pattern was to realize how closely associated it is with events. Consider a Windows pro...
2008/08/30
[ "https://Stackoverflow.com/questions/36129", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1603/" ]
I'm reading through head first design patterns at the moment and while the book is excellent I also would like to see how these are actually used in the real world. If you know of a good example of design pattern usage (preferably in a OSS program so we can have a look :) then please list it below.
An ah-ha moment for me for the observer pattern was to realize how closely associated it is with events. Consider a Windows program that needs to acheive loosely communications between two forms. That can easily be accomplished with the observer pattern. The code below shows how Form2 fires an event and any other clas...
36,139
<p>What is the best way of creating an alphabetically sorted list in Python?</p>
[ { "answer_id": 36143, "author": "rix0rrr", "author_id": 2474, "author_profile": "https://Stackoverflow.com/users/2474", "pm_score": 5, "selected": false, "text": "<pre><code>list.sort()\n</code></pre>\n\n<p>It really is that simple :)</p>\n" }, { "answer_id": 36156, "author":...
2008/08/30
[ "https://Stackoverflow.com/questions/36139", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3205/" ]
What is the best way of creating an alphabetically sorted list in Python?
Basic answer: ``` mylist = ["b", "C", "A"] mylist.sort() ``` This modifies your original list (i.e. sorts in-place). To get a sorted copy of the list, without changing the original, use the [`sorted()`](http://docs.python.org/library/functions.html#sorted) function: ``` for x in sorted(mylist): print x ``` Ho...
36,144
<p>I'm trying to open a new browser tab with the results of a POST request. I'm trying to do so using a function containing the following code:</p> <pre><code>var windowManager = Components.classes["@mozilla.org/appshell/window-mediator;1"] .getService(Components.interface s.nsIWindowMediator); var browserWindow ...
[ { "answer_id": 36216, "author": "Marius", "author_id": 1585, "author_profile": "https://Stackoverflow.com/users/1585", "pm_score": 0, "selected": false, "text": "<p>try with addTab instead of loadOneTab, and remove the last parameter. </p>\n\n<p>Check out <a href=\"http://developer.mozil...
2008/08/30
[ "https://Stackoverflow.com/questions/36144", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3288/" ]
I'm trying to open a new browser tab with the results of a POST request. I'm trying to do so using a function containing the following code: ``` var windowManager = Components.classes["@mozilla.org/appshell/window-mediator;1"] .getService(Components.interface s.nsIWindowMediator); var browserWindow = windowManager...
Something which is less Mozilla specific and should work reasonably well with most of the browsers: * Create a hidden form with the fields set up the way you need them * Make sure that the "target" attribute of the form is set to "\_BLANK" * Submit the form programatically
36,182
<p>In postgis, is the <code>ST_GeomFromText</code> call very expensive? I ask mostly because I have a frequently called query that attempts to find the point that is nearest another point that matches some criteria, and which is also within a certain distance of that other point, and the way I currently wrote it, it's...
[ { "answer_id": 36165, "author": "Silas Snider", "author_id": 2933, "author_profile": "https://Stackoverflow.com/users/2933", "pm_score": 3, "selected": true, "text": "<p>Go to about:ubiquity in Firefox. Under the section \"subscribed feeds\" there should be an option to unsubscribe to co...
2008/08/30
[ "https://Stackoverflow.com/questions/36182", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3333/" ]
In postgis, is the `ST_GeomFromText` call very expensive? I ask mostly because I have a frequently called query that attempts to find the point that is nearest another point that matches some criteria, and which is also within a certain distance of that other point, and the way I currently wrote it, it's doing the same...
Go to about:ubiquity in Firefox. Under the section "subscribed feeds" there should be an option to unsubscribe to command feeds you no longer desire. Also, if you clear your entire browser history, it will delete all command feeds (this will be fixed by 0.2)
36,183
<p>I'm trying to write a regex function that will identify and replace a single instance of a match within a string without affecting the other instances. For example, I have this string:</p> <pre><code>12||34||56 </code></pre> <p>I want to replace the second set of pipes with ampersands to get this string:</p> <pr...
[ { "answer_id": 36191, "author": "Sam Hasler", "author_id": 2541, "author_profile": "https://Stackoverflow.com/users/2541", "pm_score": 5, "selected": true, "text": "<p>here's something that works:</p>\n\n<pre><code>\"23||45||45||56||67\".replace(/^((?:[0-9]+\\|\\|){n})([0-9]+)\\|\\|/,\"$...
2008/08/30
[ "https://Stackoverflow.com/questions/36183", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2289/" ]
I'm trying to write a regex function that will identify and replace a single instance of a match within a string without affecting the other instances. For example, I have this string: ``` 12||34||56 ``` I want to replace the second set of pipes with ampersands to get this string: ``` 12||34&&56 ``` The regex fun...
here's something that works: ``` "23||45||45||56||67".replace(/^((?:[0-9]+\|\|){n})([0-9]+)\|\|/,"$1$2&&") ``` where n is the one less than the nth pipe, (of course you don't need that first subexpression if n = 0) And if you'd like a function to do this: ``` function pipe_replace(str,n) { var RE = new RegExp("...
36,239
<p>I would like to think that some of the software I'm writing today will be used in 30 years. But I am also aware that a lot of it is based upon the UNIX tradition of exposing time as the number of seconds since 1970.</p> <pre class="lang-c prettyprint-override"><code>#include &lt;stdio.h&gt; #include &lt;time.h&gt; ...
[ { "answer_id": 36242, "author": "rmmh", "author_id": 3694, "author_profile": "https://Stackoverflow.com/users/3694", "pm_score": -1, "selected": false, "text": "<p>By 2038, time libraries should all be using 64-bit integers, so this won't actually be that big of a deal (on software that ...
2008/08/30
[ "https://Stackoverflow.com/questions/36239", "https://Stackoverflow.com", "https://Stackoverflow.com/users/338/" ]
I would like to think that some of the software I'm writing today will be used in 30 years. But I am also aware that a lot of it is based upon the UNIX tradition of exposing time as the number of seconds since 1970. ```c #include <stdio.h> #include <time.h> #include <limits.h> void print(time_t rt) { struct tm * ...
I have written portable replacement for time.h (currently just localtime(), gmtime(), mktime() and timegm()) which uses 64 bit time even on 32 bit machines. It is intended to be dropped into C projects as a replacement for time.h. It is being used in Perl and I intend to fix Ruby and Python's 2038 problems with it as w...
36,260
<p>I'm writing an interpreter for an experimental language. Three of the main constructs of the language are definitions, statements, and expressions. Definitions can contain statements and expressions, statements can contain definitions and expressions, and one kind of expression can contain statements. I represent al...
[ { "answer_id": 36527, "author": "Chris Conway", "author_id": 1412, "author_profile": "https://Stackoverflow.com/users/1412", "pm_score": 5, "selected": true, "text": "<p>Recursive definitions need to appear in the same file. If you want to separate definitions, statements, and expression...
2008/08/30
[ "https://Stackoverflow.com/questions/36260", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1891/" ]
I'm writing an interpreter for an experimental language. Three of the main constructs of the language are definitions, statements, and expressions. Definitions can contain statements and expressions, statements can contain definitions and expressions, and one kind of expression can contain statements. I represent all o...
Recursive definitions need to appear in the same file. If you want to separate definitions, statements, and expressions into separate modules, you can do so using [recursive modules](http://caml.inria.fr/pub/docs/manual-ocaml/manual021.html#htoc100), but they will still need to appear in the same file. DAG-ifying inter...
36,294
<p>Looks like here in StackOveflow there is a group of <strong>F#</strong> enthusiasts. </p> <p>I'd like to know better this language, so, apart from the <a href="http://en.wikipedia.org/wiki/Functional_programming" rel="noreferrer">functional programming theory</a>, can you point me to the better starting points to s...
[ { "answer_id": 36337, "author": "Alexandru Nedelcu", "author_id": 3280, "author_profile": "https://Stackoverflow.com/users/3280", "pm_score": 1, "selected": false, "text": "<p>Check out the <a href=\"http://msdn.microsoft.com/en-gb/fsharp/default.aspx\" rel=\"nofollow noreferrer\">F# Dev...
2008/08/30
[ "https://Stackoverflow.com/questions/36294", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1178/" ]
Looks like here in StackOveflow there is a group of **F#** enthusiasts. I'd like to know better this language, so, apart from the [functional programming theory](http://en.wikipedia.org/wiki/Functional_programming), can you point me to the better starting points to start using the F# language? I mean, tutorials, how-...
Not to whore myself horribly but I wrote a couple F# overview posts on my blog [here](http://www.codegrunt.co.uk/blog/?p=58) and [here](http://www.codegrunt.co.uk/blog/?p=81). Chris Smith (guy on the F# team at MS) has an article called 'F# in 20 minutes' - [part 1](http://blogs.msdn.com/chrsmith/archive/2008/05/02/f-i...
36,296
<p>In <a href="http://channel9.msdn.com/posts/Dan/Countdown-to-PDC2008-By-Developers-for-Developers-Don-Box-and-Chris-Anderson/" rel="nofollow noreferrer">today's channel9.msdn.com video</a>, the PDC guys posted a challenge to decipher this code:</p> <pre><code>2973853263233233753482843823642933243283 6434928432937228...
[ { "answer_id": 36304, "author": "Mike Stone", "author_id": 122, "author_profile": "https://Stackoverflow.com/users/122", "pm_score": 2, "selected": false, "text": "<p>Well, based on the 332 pattern you pointed out and the fact that the number of numbers is divisible by 3, and that severa...
2008/08/30
[ "https://Stackoverflow.com/questions/36296", "https://Stackoverflow.com", "https://Stackoverflow.com/users/536/" ]
In [today's channel9.msdn.com video](http://channel9.msdn.com/posts/Dan/Countdown-to-PDC2008-By-Developers-for-Developers-Don-Box-and-Chris-Anderson/), the PDC guys posted a challenge to decipher this code: ``` 2973853263233233753482843823642933243283 6434928432937228939232737732732535234532 93352833733772823333492873...
Well, based on the 332 pattern you pointed out and the fact that the number of numbers is divisible by 3, and that several of the first 3 digit groups have matches... it might be that each 3 digits represent a character. Get a distribution of the number matches for all the 3 digit groups, then see if that distribution ...
36,314
<p>I've seen references to curried functions in several articles and blogs but I can't find a good explanation (or at least one that makes sense!)</p>
[ { "answer_id": 36321, "author": "Kyle Cronin", "author_id": 658, "author_profile": "https://Stackoverflow.com/users/658", "pm_score": 11, "selected": true, "text": "<p>Currying is when you break down a function that takes multiple arguments into a series of functions that each take only ...
2008/08/30
[ "https://Stackoverflow.com/questions/36314", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3786/" ]
I've seen references to curried functions in several articles and blogs but I can't find a good explanation (or at least one that makes sense!)
Currying is when you break down a function that takes multiple arguments into a series of functions that each take only one argument. Here's an example in JavaScript: ```js function add (a, b) { return a + b; } add(3, 4); // returns 7 ``` This is a function that takes two arguments, a and b, and returns their sum...
36,344
<p>I'm trying to "install SGML::Parser::OpenSP" from the cpan shell, but it fails on the first "make test". I also get the same error if I go into the build directory and run make test.</p> <p>I believe this bit of the output below is the relevant part. Note the Symbol not found when perl gets to the "use" line for t...
[ { "answer_id": 36332, "author": "Glenn Slaven", "author_id": 2975, "author_profile": "https://Stackoverflow.com/users/2975", "pm_score": 4, "selected": true, "text": "<p>If you use the Settings for the project, you can mark each setting as either application or user.</p>\n\n<p>If they're...
2008/08/30
[ "https://Stackoverflow.com/questions/36344", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I'm trying to "install SGML::Parser::OpenSP" from the cpan shell, but it fails on the first "make test". I also get the same error if I go into the build directory and run make test. I believe this bit of the output below is the relevant part. Note the Symbol not found when perl gets to the "use" line for the new libr...
If you use the Settings for the project, you can mark each setting as either application or user. If they're set as user, they will be stored per-user and when you call the Save method it will be updated in the config for that user. Code project has a really detailed [article](http://www.codeproject.com/KB/dotnet/use...
36,347
<p>Java has generics and C++ provides a very strong programming model with <code>template</code>s. So then, what is the difference between C++ and Java generics?</p>
[ { "answer_id": 36356, "author": "Shog9", "author_id": 811, "author_profile": "https://Stackoverflow.com/users/811", "pm_score": 7, "selected": false, "text": "<p>C++ has templates. Java has generics, which look kinda sorta like C++ templates, but they're very, very different.</p>\n\n<p>T...
2008/08/30
[ "https://Stackoverflow.com/questions/36347", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1556/" ]
Java has generics and C++ provides a very strong programming model with `template`s. So then, what is the difference between C++ and Java generics?
There is a big difference between them. In C++ you don't have to specify a class or an interface for the generic type. That's why you can create truly generic functions and classes, with the caveat of a looser typing. ```cpp template <typename T> T sum(T a, T b) { return a + b; } ``` The method above adds two object...
36,350
<p>I have a method which takes params object[] such as:</p> <pre><code>void Foo(params object[] items) { Console.WriteLine(items[0]); } </code></pre> <p>When I pass two object arrays to this method, it works fine:</p> <pre><code>Foo(new object[]{ (object)"1", (object)"2" }, new object[]{ (object)"3", (object)"4"...
[ { "answer_id": 36360, "author": "Lasse V. Karlsen", "author_id": 267, "author_profile": "https://Stackoverflow.com/users/267", "pm_score": 2, "selected": false, "text": "<p>You need to encapsulate it into another object[] array, like this:</p>\n\n<pre><code>Foo(new Object[] { new object[...
2008/08/30
[ "https://Stackoverflow.com/questions/36350", "https://Stackoverflow.com", "https://Stackoverflow.com/users/31505/" ]
I have a method which takes params object[] such as: ``` void Foo(params object[] items) { Console.WriteLine(items[0]); } ``` When I pass two object arrays to this method, it works fine: ``` Foo(new object[]{ (object)"1", (object)"2" }, new object[]{ (object)"3", (object)"4" } ); // Output: System.Object[] ```...
A simple typecast will ensure the compiler knows what you mean in this case. ``` Foo((object)new object[]{ (object)"1", (object)"2" })); ``` As an array is a subtype of object, this all works out. Bit of an odd solution though, I'll agree.
36,417
<p>What is a good way to remove the code from display pages when developing with PHP. Often the pages I work on need to be editted by an outside person. This person is often confused by lots of blocks of PHP, and also likes to break my code.</p> <p>I've tried moving blocks of code out into functions, so now there are ...
[ { "answer_id": 36421, "author": "Mark Biek", "author_id": 305, "author_profile": "https://Stackoverflow.com/users/305", "pm_score": 0, "selected": false, "text": "<p>There's a lot that can be said on this topic but a very basic starting point would be to move as much code as possible out...
2008/08/30
[ "https://Stackoverflow.com/questions/36417", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3800/" ]
What is a good way to remove the code from display pages when developing with PHP. Often the pages I work on need to be editted by an outside person. This person is often confused by lots of blocks of PHP, and also likes to break my code. I've tried moving blocks of code out into functions, so now there are functions ...
You don't need a "system" to do templating. You can do it on your own by keeping presentation & logic separate. This way the designer can screw up the display, but not the logic behind it. Here's a simple example: ``` <?php $people = array('derek','joel','jeff'); $people[0] = 'martin'; // all your logic goes here in...
36,430
<p>I'm not sure of all of them, but what are the commands to do things like update Ruby, download a new gem, or update an existing gem? What other important things are there?</p> <p>Since it might matter, I'm running Windows.</p>
[ { "answer_id": 36447, "author": "Joseph Pecoraro", "author_id": 792, "author_profile": "https://Stackoverflow.com/users/792", "pm_score": 4, "selected": false, "text": "<p>By Ruby commands you probably mean the command line programs for Ruby. These are also called Ruby Helper programs. ...
2008/08/30
[ "https://Stackoverflow.com/questions/36430", "https://Stackoverflow.com", "https://Stackoverflow.com/users/572/" ]
I'm not sure of all of them, but what are the commands to do things like update Ruby, download a new gem, or update an existing gem? What other important things are there? Since it might matter, I'm running Windows.
Useful command: Rake ==================== In addition to the commands listed by Joseph Pecoraro, the 'rake' command is also pretty standard when working with Ruby. Rake makes it easy to automate (simple) tasks; like building a RubyGem or running your unit tests. With rake, the only important command to remember is 'r...
36,475
<p>What would be the best way to design a threaded commenting system so that it doesn't hammer the database?</p>
[ { "answer_id": 36487, "author": "TheSmurf", "author_id": 1975282, "author_profile": "https://Stackoverflow.com/users/1975282", "pm_score": 0, "selected": false, "text": "<p>What I normally do in this case is to have a single thread that is responsible for putting the data into the databa...
2008/08/30
[ "https://Stackoverflow.com/questions/36475", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1745/" ]
What would be the best way to design a threaded commenting system so that it doesn't hammer the database?
**SELECT ... START WITH ... CONNECT BY** Oracle has an extension to SELECT that allows easy tree-based retrieval. This query will traverse a table where the nesting relationship is stored in **parent** and **child** columns. ``` select * from my_table start with parent = :TOP_ARTICLE connect by prior child =...
36,498
<p>I would like to quickly send email from the command line. I realize there are probably a number of different ways to do this.</p> <p>I'm looking for a simple way to do this from a linux terminal (likely a bash shell but anything should do) and an alternative way to do this on Windows. I want to be able to whip up...
[ { "answer_id": 36499, "author": "aryeh", "author_id": 3288, "author_profile": "https://Stackoverflow.com/users/3288", "pm_score": 4, "selected": false, "text": "<pre><code>$ echo \"This is the email body\" | mail -s \"This is the subject\" [email protected]\n</code></pre>\n\n<p>Alternatively:...
2008/08/31
[ "https://Stackoverflow.com/questions/36498", "https://Stackoverflow.com", "https://Stackoverflow.com/users/792/" ]
I would like to quickly send email from the command line. I realize there are probably a number of different ways to do this. I'm looking for a simple way to do this from a linux terminal (likely a bash shell but anything should do) and an alternative way to do this on Windows. I want to be able to whip up an email ri...
You can use mail: ``` $mail -s <subject> <recipients> ``` You then type your message and end it with a line that has only a period. This signals you are done and sends the message. You can also pipe your email in from STDIN and it will be sent as the text of an email: ``` $<mail-generating-program> | mail -s <subj...
36,502
<p>I know Windows Vista (and XP) cache recently loaded DLL's in memory...</p> <p>How can this be disabled via the command prompt?</p>
[ { "answer_id": 36529, "author": "The How-To Geek", "author_id": 291, "author_profile": "https://Stackoverflow.com/users/291", "pm_score": 4, "selected": true, "text": "<p>The only thing you can do is disable SuperFetch, which can be done from the command prompt with this command (there h...
2008/08/31
[ "https://Stackoverflow.com/questions/36502", "https://Stackoverflow.com", "https://Stackoverflow.com/users/383/" ]
I know Windows Vista (and XP) cache recently loaded DLL's in memory... How can this be disabled via the command prompt?
The only thing you can do is disable SuperFetch, which can be done from the command prompt with this command (there has to be a space between the = sign and disabled). ``` sc config Superfetch start= disabled ``` There is a myth out there that you can disable DLL caching, but that only worked for systems prior to Wi...
36,511
<p>I'm attempting to create a dataset based on the properties of an object. For example, I have an instance of a Person class with properties including ID, Forename, Surname, DOB etc. Using reflection, I'm adding columns to a new dataset based on the object properties:</p> <pre><code>For Each pi As PropertyInfo In per...
[ { "answer_id": 36519, "author": "Matt Hamilton", "author_id": 615, "author_profile": "https://Stackoverflow.com/users/615", "pm_score": 1, "selected": false, "text": "<p>I'm guessing that the problem is recognizing whether the property is nullable or not. In C# you do this with this code...
2008/08/31
[ "https://Stackoverflow.com/questions/36511", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I'm attempting to create a dataset based on the properties of an object. For example, I have an instance of a Person class with properties including ID, Forename, Surname, DOB etc. Using reflection, I'm adding columns to a new dataset based on the object properties: ``` For Each pi As PropertyInfo In person.GetType()....
Here's your answer, in VB. This may be overkill for your purposes, but it also might be useful to some other folks. First off, here's the code to find out if you're dealing with a Nullable type: ``` Private Function IsNullableType(ByVal myType As Type) As Boolean Return (myType.IsGenericType) AndAlso (myType.GetG...
36,515
<p>I have a page with a Google Maps mashup that has pushpins that are color-coded by day (Monday, Tuesday, etc.) The IFrame containing the map is dynamically sized, so it gets resized when the browser window is resized. </p> <p>I'd like to put a legend in the corner of the map window that tells the user what each colo...
[ { "answer_id": 36821, "author": "Tom", "author_id": 3715, "author_profile": "https://Stackoverflow.com/users/3715", "pm_score": 2, "selected": false, "text": "<p>I would use HTML like the following:</p>\n\n<pre><code>&lt;div id=\"wrapper\"&gt;\n &lt;div id=\"map\" style=\"width:400px;h...
2008/08/31
[ "https://Stackoverflow.com/questions/36515", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1482/" ]
I have a page with a Google Maps mashup that has pushpins that are color-coded by day (Monday, Tuesday, etc.) The IFrame containing the map is dynamically sized, so it gets resized when the browser window is resized. I'd like to put a legend in the corner of the map window that tells the user what each color means. T...
You can add your own Custom Control and use it as a legend. This code will add a box 150w x 100h (Gray Border/ with White Background) and the words "Hello World" inside of it. You swap out the text for any HTML you would like in the legend. This will stay Anchored to the Top Right (G\_ANCHOR\_TOP\_RIGHT) 10px down and...
36,563
<p>I'm writing a simple app that's going to have a tiny form sitting in one corner of the screen, updating itself.</p> <p>I'd really love for that form to be transparent and to have the transparency be user-configurable.</p> <p>Is there any easy way to achieve this?</p>
[ { "answer_id": 36576, "author": "Eric Haskins", "author_id": 100, "author_profile": "https://Stackoverflow.com/users/100", "pm_score": 0, "selected": false, "text": "<p>You can set the <code>Form.Opacity</code> property. It should do what you want.</p>\n" }, { "answer_id": 36577,...
2008/08/31
[ "https://Stackoverflow.com/questions/36563", "https://Stackoverflow.com", "https://Stackoverflow.com/users/305/" ]
I'm writing a simple app that's going to have a tiny form sitting in one corner of the screen, updating itself. I'd really love for that form to be transparent and to have the transparency be user-configurable. Is there any easy way to achieve this?
You could try using the [Opacity](http://msdn.microsoft.com/en-us/library/system.windows.forms.form.opacity.aspx) property of the Form. Here's the relevant snippet from the MSDN page: ``` private Sub CreateMyOpaqueForm() ' Create a new form. Dim form2 As New Form() ' Set the text displayed in the caption. ...
36,567
<p>I'm looking into writing a audio syntesizer in Java, and was wondering if anybody has any advice or good resources for writing such a program. I'm looking for info on generating raw sound waves, how to output them into a usable form (playing over speakers), as well as general theory on the topic. Thanks guys.</p>
[ { "answer_id": 36588, "author": "David Crow", "author_id": 2783, "author_profile": "https://Stackoverflow.com/users/2783", "pm_score": 2, "selected": false, "text": "<p>Check out <a href=\"http://frinika.sourceforge.net/\" rel=\"nofollow noreferrer\">Frinika</a>. It's a full-featured mus...
2008/08/31
[ "https://Stackoverflow.com/questions/36567", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I'm looking into writing a audio syntesizer in Java, and was wondering if anybody has any advice or good resources for writing such a program. I'm looking for info on generating raw sound waves, how to output them into a usable form (playing over speakers), as well as general theory on the topic. Thanks guys.
1. This problem is basically about mapping functions to arrays of numbers. A language that supports first-class functions would come in really handy here. 2. Check out <http://www.harmony-central.com/Computer/Programming> and <http://www.developer.com/java/other/article.php/3071021> for some Java-related info. 3. If yo...
36,608
<p>I have a record set that includes a date field, and want to determine how many unique dates are represented in the record set.</p> <p>Something like:</p> <pre><code>Record.find(:all).date.unique.count </code></pre> <p>but of course, that doesn't seem to work.</p>
[ { "answer_id": 36618, "author": "Natalie Weizenbaum", "author_id": 2518, "author_profile": "https://Stackoverflow.com/users/2518", "pm_score": 7, "selected": true, "text": "<p>What you're going for is the following SQL:</p>\n\n<pre><code>SELECT COUNT(DISTINCT date) FROM records\n</code><...
2008/08/31
[ "https://Stackoverflow.com/questions/36608", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3764/" ]
I have a record set that includes a date field, and want to determine how many unique dates are represented in the record set. Something like: ``` Record.find(:all).date.unique.count ``` but of course, that doesn't seem to work.
What you're going for is the following SQL: ``` SELECT COUNT(DISTINCT date) FROM records ``` ActiveRecord has this built in: ``` Record.count('date', :distinct => true) ```
36,621
<p>I'm taking the leap: my PHP scripts will ALL fail gracefully!</p> <p>At least, that's what I'm hoping for...`</p> <p>I don't want to wrap (practically) every single line in <code>try...catch</code> statements, so I think my best bet is to make a custom error handler for the beginning of my files.</p> <p>I'm testi...
[ { "answer_id": 36625, "author": "John Millikin", "author_id": 3560, "author_profile": "https://Stackoverflow.com/users/3560", "pm_score": 1, "selected": false, "text": "<blockquote>\n <p>Why isn't my custom error handler catching undefinedd functions? Are there other problems that this ...
2008/08/31
[ "https://Stackoverflow.com/questions/36621", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1615/" ]
I'm taking the leap: my PHP scripts will ALL fail gracefully! At least, that's what I'm hoping for...` I don't want to wrap (practically) every single line in `try...catch` statements, so I think my best bet is to make a custom error handler for the beginning of my files. I'm testing it out on a practice page: ``` ...
`set_error_handler` is designed to handle errors with codes of: `E_USER_ERROR | E_USER_WARNING | E_USER_NOTICE`. This is because `set_error_handler` is meant to be a method of reporting errors thrown by the *user* error function `trigger_error`. However, I did find this comment in the manual that may help you: > > "...
36,636
<p>I asked a question about Currying and closures were mentioned. What is a closure? How does it relate to currying?</p>
[ { "answer_id": 36639, "author": "Kyle Cronin", "author_id": 658, "author_profile": "https://Stackoverflow.com/users/658", "pm_score": 7, "selected": false, "text": "<p>I'll give an example (in JavaScript):</p>\n<pre class=\"lang-js prettyprint-override\"><code>function makeCounter () {\n...
2008/08/31
[ "https://Stackoverflow.com/questions/36636", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3786/" ]
I asked a question about Currying and closures were mentioned. What is a closure? How does it relate to currying?
Variable scope -------------- When you declare a local variable, that variable has a scope. Generally, local variables exist only within the block or function in which you declare them. ```js function() { var a = 1; console.log(a); // works } console.log(a); // fails ``` If I try to access a local variable,...
36,656
<p>I'm parsing text from a file and storing it in a string. The problem is that some of the text in the original files contains <code>ASCII art</code> and whatnot that I would like to preserve. When I print out the string on the <code>HTML page</code>, even if it does have the same formatting and everything since it ...
[ { "answer_id": 36657, "author": "UnkwnTech", "author_id": 115, "author_profile": "https://Stackoverflow.com/users/115", "pm_score": 3, "selected": false, "text": "<p>When you print the data use <a href=\"http://www.php.net/manual/en/function.nl2br.php\" rel=\"noreferrer\"><code>nl2br()</...
2008/08/31
[ "https://Stackoverflow.com/questions/36656", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3831/" ]
I'm parsing text from a file and storing it in a string. The problem is that some of the text in the original files contains `ASCII art` and whatnot that I would like to preserve. When I print out the string on the `HTML page`, even if it does have the same formatting and everything since it is in `HTML`, the spacing a...
use the <pre> tag (pre formatted), that will use a mono spaced font (for your art) and keep all the white space ``` <pre> text goes here and here and here and here Some out here ▄ ▄█▄ █▄ ▄ ▄█▀█▓ ▄▓▀▀█▀ ▀▀▀█▓▀▀ ▀▀ ▄█▀█▓▀▀▀▀▀▓▄▀██▀▀ ██ ██ ▀██▄▄ ▄█ ▀ ░▒ ░▒ ██ ██ ▄█...
36,701
<p>Is it completely against the Java way to create struct like objects?</p> <pre><code>class SomeData1 { public int x; public int y; } </code></pre> <p>I can see a class with accessors and mutators being more Java like.</p> <pre><code>class SomeData2 { int getX(); void setX(int x); int getY(); ...
[ { "answer_id": 36702, "author": "John Topley", "author_id": 1450, "author_profile": "https://Stackoverflow.com/users/1450", "pm_score": 1, "selected": false, "text": "<p>I don't see the harm if you know that it's always going to be a simple struct and that you're never going to want to a...
2008/08/31
[ "https://Stackoverflow.com/questions/36701", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3836/" ]
Is it completely against the Java way to create struct like objects? ``` class SomeData1 { public int x; public int y; } ``` I can see a class with accessors and mutators being more Java like. ``` class SomeData2 { int getX(); void setX(int x); int getY(); void setY(int y); private int...
This is a commonly discussed topic. The drawback of creating public fields in objects is that you have no control over the values that are set to it. In group projects where there are many programmers using the same code, it's important to avoid side effects. Besides, sometimes it's better to return a copy of field's o...
36,707
<p>Are there good reasons why it's a better practice to have only one return statement in a function? </p> <p>Or is it okay to return from a function as soon as it is logically correct to do so, meaning there may be many return statements in the function?</p>
[ { "answer_id": 36711, "author": "Rob Cooper", "author_id": 832, "author_profile": "https://Stackoverflow.com/users/832", "pm_score": 3, "selected": false, "text": "<p>I would say you should have as many as required, or any that make the code cleaner (such as <a href=\"http://www.refactor...
2008/08/31
[ "https://Stackoverflow.com/questions/36707", "https://Stackoverflow.com", "https://Stackoverflow.com/users/381/" ]
Are there good reasons why it's a better practice to have only one return statement in a function? Or is it okay to return from a function as soon as it is logically correct to do so, meaning there may be many return statements in the function?
I often have several statements at the start of a method to return for "easy" situations. For example, this: ```java public void DoStuff(Foo foo) { if (foo != null) { ... } } ``` ... can be made more readable (IMHO) like this: ```java public void DoStuff(Foo foo) { if (foo == null) return; ...
36,733
<p>I am working on a project management web application. The user has a variety of ways to display a list of tasks. When viewing a list page, they click on task and are redirected to the task edit page. </p> <p>Since they are coming from a variety of ways, I am just curious as to the <strong>best</strong> way to <s...
[ { "answer_id": 36735, "author": "Rob Cooper", "author_id": 832, "author_profile": "https://Stackoverflow.com/users/832", "pm_score": 1, "selected": false, "text": "<p>I personally would store the required redirection info in an object and handle globally. I would avoid using a QueryStrin...
2008/08/31
[ "https://Stackoverflow.com/questions/36733", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1768/" ]
I am working on a project management web application. The user has a variety of ways to display a list of tasks. When viewing a list page, they click on task and are redirected to the task edit page. Since they are coming from a variety of ways, I am just curious as to the **best** way to **redirect** the user back t...
I would store the referring URL using the [ViewState](http://msdn.microsoft.com/en-us/library/system.web.ui.control.viewstate.aspx). Storing this outside the scope of the page (i.e. in the Session state or cookie) may cause problems if more than one browser window is open. The example below validates that the page was...
36,742
<p>My GPS logger occassionally leaves "unfinished" lines at the end of the log files. I think they're only at the end, but I want to check all lines just in case. </p> <p>A sample complete sentence looks like:</p> <pre><code>$GPRMC,005727.000,A,3751.9418,S,14502.2569,E,0.00,339.17,210808,,,A*76 </code></pre> <p>The...
[ { "answer_id": 36779, "author": "Motti", "author_id": 3848, "author_profile": "https://Stackoverflow.com/users/3848", "pm_score": 2, "selected": false, "text": "<p>The minimum of testing shows that this should do it:</p>\n\n<pre><code>grep -Ev \"^\\$.*\\*[0-9A-Fa-f]{2}$\" a.txt | grep -v...
2008/08/31
[ "https://Stackoverflow.com/questions/36742", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3715/" ]
My GPS logger occassionally leaves "unfinished" lines at the end of the log files. I think they're only at the end, but I want to check all lines just in case. A sample complete sentence looks like: ``` $GPRMC,005727.000,A,3751.9418,S,14502.2569,E,0.00,339.17,210808,,,A*76 ``` The line should start with a `$` sign...
The minimum of testing shows that this should do it: ``` grep -Ev "^\$.*\*[0-9A-Fa-f]{2}$" a.txt | grep -v ADVER ``` * -E use extended regexp * -v Show lines that do **not** match * ^ starts with * .\* anything * \\* an asterisk * [0-9A-Fa-f] hexadecimal digit * {2} exactly two of the previous * $ end of line * | `g...
36,748
<p>What's the best way to asynchronously load an BitmapImage in C# using WPF? </p>
[ { "answer_id": 36757, "author": "aku", "author_id": 1196, "author_profile": "https://Stackoverflow.com/users/1196", "pm_score": 2, "selected": false, "text": "<p>Assuming you're using data binding, setting <a href=\"http://msdn.microsoft.com/en-us/library/system.windows.data.binding.isas...
2008/08/31
[ "https://Stackoverflow.com/questions/36748", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3837/" ]
What's the best way to asynchronously load an BitmapImage in C# using WPF?
I was just looking into this and had to throw in my two cents, though a few years after the original post (just in case any one else comes looking for this same thing I was looking into). I have an **Image** control that needs to have it's image loaded in the background using a **Stream**, and then displayed. The p...
36,760
<p>I have three tables: page, attachment, page-attachment</p> <p>I have data like this:</p> <pre><code>page ID NAME 1 first page 2 second page 3 third page 4 fourth page attachment ID NAME 1 foo.word 2 test.xsl 3 mm.ppt page-attachment ID PAGE-ID ATTACHMENT-ID 1 2 ...
[ { "answer_id": 36762, "author": "Matt Hamilton", "author_id": 615, "author_profile": "https://Stackoverflow.com/users/615", "pm_score": 6, "selected": true, "text": "<p>Change your \"inner join\" to a \"left outer join\", which means \"get me all the rows on the left of the join, even if...
2008/08/31
[ "https://Stackoverflow.com/questions/36760", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2138/" ]
I have three tables: page, attachment, page-attachment I have data like this: ``` page ID NAME 1 first page 2 second page 3 third page 4 fourth page attachment ID NAME 1 foo.word 2 test.xsl 3 mm.ppt page-attachment ID PAGE-ID ATTACHMENT-ID 1 2 1 2 2 2 3...
Change your "inner join" to a "left outer join", which means "get me all the rows on the left of the join, even if there isn't a matching row on the right." ``` select page.name, count(page-attachment.id) as attachmentsnumber from page left outer join page-attachment on page.id=page-id group by page.name ```
36,806
<p>I have been sold on mod_wsgi and apache rather than mod_python. I have all the parts installed (django, apache, mod_wsgi) but have run into a problem deploying.</p> <p>I am on osx 10.5 with apache 2.2 and django 1.0b2, mod_wsgi-2.3</p> <p>My application is called tred.</p> <p>Here are the relevant files: httpd-vh...
[ { "answer_id": 37009, "author": "John Millikin", "author_id": 3560, "author_profile": "https://Stackoverflow.com/users/3560", "pm_score": 4, "selected": true, "text": "<p>What happens if you remove the <code>Alias /</code> directive?</p>\n" }, { "answer_id": 37218, "author": ...
2008/08/31
[ "https://Stackoverflow.com/questions/36806", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3431280/" ]
I have been sold on mod\_wsgi and apache rather than mod\_python. I have all the parts installed (django, apache, mod\_wsgi) but have run into a problem deploying. I am on osx 10.5 with apache 2.2 and django 1.0b2, mod\_wsgi-2.3 My application is called tred. Here are the relevant files: httpd-vhosts (included in ht...
What happens if you remove the `Alias /` directive?
36,812
<p>Currently, I am writing up a bit of a product-based CMS as my first project.</p> <p>Here is my question. How can I add additional data (products) to my Product model?</p> <p>I have added '/admin/products/add' to my urls.py, but I don't really know where to go from there. How would i build both my view and my templ...
[ { "answer_id": 36818, "author": "Matthew Watson", "author_id": 3839, "author_profile": "https://Stackoverflow.com/users/3839", "pm_score": -1, "selected": false, "text": "<p>Follow the Django tutorial for setting up the \"admin\" part of an application. This will allow you to modify your...
2008/08/31
[ "https://Stackoverflow.com/questions/36812", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2592/" ]
Currently, I am writing up a bit of a product-based CMS as my first project. Here is my question. How can I add additional data (products) to my Product model? I have added '/admin/products/add' to my urls.py, but I don't really know where to go from there. How would i build both my view and my template? Please keep ...
You will want to wire your URL to the Django [create\_object generic view](https://docs.djangoproject.com/en/1.4/ref/generic-views/#django-views-generic-create-update-create-object), and pass it either "model" (the model you want to create) or "form\_class" (a customized [ModelForm](https://docs.djangoproject.com/en/1....
36,831
<p>I'm writing C# code that uses the windows IP Helper API. One of the functions I'm trying to call is "<a href="http://msdn.microsoft.com/en-us/library/aa365920(VS.85).aspx" rel="nofollow noreferrer">GetBestInterface</a>" that takes a 'uint' representation of an IP. What I need is to parse a textual representation of ...
[ { "answer_id": 36841, "author": "aku", "author_id": 1196, "author_profile": "https://Stackoverflow.com/users/1196", "pm_score": 5, "selected": true, "text": "<p>MSDN <a href=\"http://msdn.microsoft.com/en-us/library/system.net.ipaddress.getaddressbytes.aspx\" rel=\"noreferrer\">says</a> ...
2008/08/31
[ "https://Stackoverflow.com/questions/36831", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1596/" ]
I'm writing C# code that uses the windows IP Helper API. One of the functions I'm trying to call is "[GetBestInterface](http://msdn.microsoft.com/en-us/library/aa365920(VS.85).aspx)" that takes a 'uint' representation of an IP. What I need is to parse a textual representation of the IP to create the 'uint' representati...
MSDN [says](http://msdn.microsoft.com/en-us/library/system.net.ipaddress.getaddressbytes.aspx) that IPAddress.Address property (which returns numeric representation of IP address) is obsolete and you should use [GetAddressBytes](http://msdn.microsoft.com/en-us/library/system.net.ipaddress.getaddressbytes.aspx) method. ...
36,832
<p>In C++ when a virtual function is called from within a constructor it doesn't behave like a virtual function.</p> <p>I think everyone who encountered this behavior for the first time was surprised but on second thought it made sense:</p> <p>As long as the derived constructor has not been executed the object is <st...
[ { "answer_id": 36837, "author": "Brian R. Bondy", "author_id": 3153, "author_profile": "https://Stackoverflow.com/users/3153", "pm_score": 3, "selected": false, "text": "<p>Both ways can lead to unexpected results. Your best bet is to not call a virtual function in your constructor at a...
2008/08/31
[ "https://Stackoverflow.com/questions/36832", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3848/" ]
In C++ when a virtual function is called from within a constructor it doesn't behave like a virtual function. I think everyone who encountered this behavior for the first time was surprised but on second thought it made sense: As long as the derived constructor has not been executed the object is **not** yet a *deriv...
There's a fundamental difference in how the languages define an object's life time. In Java and .Net the object members are zero/null initialized before any constructor is run and is at this point that the object life time begins. So when you enter the constructor you've already got an initialized object. In C++ the o...
36,861
<p>I've run into a strange syntax in <a href="http://boo.codehaus.org/Closures" rel="nofollow noreferrer">Boo Language Guide</a> :</p> <pre><code>setter = { value | a = value } </code></pre> <p>What does the | operator mean?</p>
[ { "answer_id": 36866, "author": "Adam Wright", "author_id": 1200, "author_profile": "https://Stackoverflow.com/users/1200", "pm_score": 2, "selected": false, "text": "<p>Well, having never used Boo, my (educated) guess is that it's for passing parameter to the closure lambda-style functi...
2008/08/31
[ "https://Stackoverflow.com/questions/36861", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2313/" ]
I've run into a strange syntax in [Boo Language Guide](http://boo.codehaus.org/Closures) : ``` setter = { value | a = value } ``` What does the | operator mean?
The documentation of Boo seems to be lacking in this area -- it seems that ``` setter = { value | a = value } ``` is shorthand for ``` setter = def(value): a = value ```
36,862
<p>With SVN, I had a single big repository I kept on a server, and checked-out on a few machines. This was a pretty good backup system, and allowed me easily work on any of the machines. I could checkout a specific project, commit and it updated the 'master' project, or I could checkout the entire thing.</p> <p>Now, I...
[ { "answer_id": 36905, "author": "Spoike", "author_id": 3713, "author_profile": "https://Stackoverflow.com/users/3713", "pm_score": 2, "selected": false, "text": "<p>,I haven't tried nesting git repositories yet because I haven't run into a situation where I need to. As I've read on the <...
2008/08/31
[ "https://Stackoverflow.com/questions/36862", "https://Stackoverflow.com", "https://Stackoverflow.com/users/745/" ]
With SVN, I had a single big repository I kept on a server, and checked-out on a few machines. This was a pretty good backup system, and allowed me easily work on any of the machines. I could checkout a specific project, commit and it updated the 'master' project, or I could checkout the entire thing. Now, I have a bu...
I would **strongly** advise against putting unrelated data in a given Git repository. The overhead of creating new repositories is quite low, and that is a *feature* that makes it possible to keep different lineages completely separate. Fighting that idea means ending up with unnecessarily tangled history, which rende...
36,877
<p>How can I set the cookies in my <code>PHP apps</code> as <code>HttpOnly cookies</code>?</p>
[ { "answer_id": 36880, "author": "Polsonby", "author_id": 137, "author_profile": "https://Stackoverflow.com/users/137", "pm_score": 3, "selected": false, "text": "<p>Explanation here from Ilia... 5.2 only though</p>\n\n<p><a href=\"http://ilia.ws/archives/121-httpOnly-cookie-flag-support-...
2008/08/31
[ "https://Stackoverflow.com/questions/36877", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3871/" ]
How can I set the cookies in my `PHP apps` as `HttpOnly cookies`?
* For **your cookies**, see this answer. * For **PHP's own session cookie** (`PHPSESSID`, by default), see [@richie's answer](https://stackoverflow.com/a/8726269/1820) The [`setcookie()`](http://php.net/manual/en/function.setcookie.php) and [`setrawcookie()`](http://php.net/manual/en/function.setrawcookie.php) functio...
36,881
<p>I have an activity that has a TabHost containing a set of TabSpecs each with a listview containing the items to be displayed by the tab. When each TabSpec is created, I set an icon to be displayed in the tab header.</p> <p>The TabSpecs are created in this way within a <code>setupTabs()</code> method which loops to c...
[ { "answer_id": 68078, "author": "dmazzoni", "author_id": 7193, "author_profile": "https://Stackoverflow.com/users/7193", "pm_score": 6, "selected": true, "text": "<p>The short answer is, you're not missing anything. The Android SDK doesn't provide a direct method to change the indicator...
2008/08/31
[ "https://Stackoverflow.com/questions/36881", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1197/" ]
I have an activity that has a TabHost containing a set of TabSpecs each with a listview containing the items to be displayed by the tab. When each TabSpec is created, I set an icon to be displayed in the tab header. The TabSpecs are created in this way within a `setupTabs()` method which loops to create the appropriat...
The short answer is, you're not missing anything. The Android SDK doesn't provide a direct method to change the indicator of a `TabHost` after it's been created. The `TabSpec` is only used to build the tab, so changing the `TabSpec` after the fact will have no effect. I think there's a workaround, though. Call `mTabs....
36,901
<p>What do <code>*args</code> and <code>**kwargs</code> mean?</p> <pre><code>def foo(x, y, *args): def bar(x, y, **kwargs): </code></pre>
[ { "answer_id": 36902, "author": "Chris Upchurch", "author_id": 2600, "author_profile": "https://Stackoverflow.com/users/2600", "pm_score": 4, "selected": false, "text": "<p>From the Python documentation:</p>\n\n<blockquote>\n <p>If there are more positional arguments than there are form...
2008/08/31
[ "https://Stackoverflow.com/questions/36901", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2572/" ]
What do `*args` and `**kwargs` mean? ``` def foo(x, y, *args): def bar(x, y, **kwargs): ```
The `*args` and `**kwargs` is a common idiom to allow arbitrary number of arguments to functions as described in the section [more on defining functions](http://docs.python.org/3/tutorial/controlflow.html#more-on-defining-functions) in the Python documentation. The `*args` will give you all function parameters [as a t...
36,906
<p>I want to swap two integers, and I want to know which of these two implementations will be faster: The obvious way with a temp variable:</p> <pre><code>void swap(int* a, int* b) { int temp = *a; *a = *b; *b = temp; } </code></pre> <p>Or the xor version that I'm sure most people have seen:</p> <pre><co...
[ { "answer_id": 36910, "author": "caramelcarrot", "author_id": 3877, "author_profile": "https://Stackoverflow.com/users/3877", "pm_score": 7, "selected": false, "text": "<p>Number 2 is often quoted as being the \"clever\" way of doing it. It is in fact most likely slower as it obscures th...
2008/08/31
[ "https://Stackoverflow.com/questions/36906", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3869/" ]
I want to swap two integers, and I want to know which of these two implementations will be faster: The obvious way with a temp variable: ``` void swap(int* a, int* b) { int temp = *a; *a = *b; *b = temp; } ``` Or the xor version that I'm sure most people have seen: ``` void swap(int* a, int* b) { *a...
The XOR method fails if a and b point to the same address. The first XOR will clear all of the bits at the memory address pointed to by both variables, so once the function returns (\*a == \*b == 0), regardless of the initial value. More info on the Wiki page: [XOR swap algorithm](http://en.wikipedia.org/wiki/XOR_swap...
36,932
<p>I'm mainly a C# developer, but I'm currently working on a project in Python.</p> <p>How can I represent the equivalent of an Enum in Python? </p>
[ { "answer_id": 36937, "author": "Alexandru Nedelcu", "author_id": 3280, "author_profile": "https://Stackoverflow.com/users/3280", "pm_score": 10, "selected": false, "text": "<p>Before PEP 435, Python didn't have an equivalent but you could implement your own.</p>\n<p>Myself, I like keepi...
2008/08/31
[ "https://Stackoverflow.com/questions/36932", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3880/" ]
I'm mainly a C# developer, but I'm currently working on a project in Python. How can I represent the equivalent of an Enum in Python?
[Enums](https://docs.python.org/3/library/enum.html) have been added to Python 3.4 as described in [PEP 435](http://www.python.org/dev/peps/pep-0435/). It has also been [backported to 3.3, 3.2, 3.1, 2.7, 2.6, 2.5, and 2.4](https://pypi.python.org/pypi/enum34) on pypi. For more advanced Enum techniques try the [aenum l...
36,959
<p>In MS SQL Server, I create my scripts to use customizable variables:</p> <pre><code>DECLARE @somevariable int SELECT @somevariable = -1 INSERT INTO foo VALUES ( @somevariable ) </code></pre> <p>I'll then change the value of <code>@somevariable</code> at runtime, depending on the value that I want in the particu...
[ { "answer_id": 36979, "author": "Craig Walker", "author_id": 3488, "author_profile": "https://Stackoverflow.com/users/3488", "pm_score": 4, "selected": false, "text": "<p>FWIW, the real problem was that I had included a semicolon at the end of my \\set command:</p>\n\n<blockquote>\n <p>...
2008/08/31
[ "https://Stackoverflow.com/questions/36959", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3488/" ]
In MS SQL Server, I create my scripts to use customizable variables: ``` DECLARE @somevariable int SELECT @somevariable = -1 INSERT INTO foo VALUES ( @somevariable ) ``` I'll then change the value of `@somevariable` at runtime, depending on the value that I want in the particular situation. Since it's at the top ...
Postgres variables are created through the \set command, for example ... ``` \set myvariable value ``` ... and can then be substituted, for example, as ... ``` SELECT * FROM :myvariable.table1; ``` ... or ... ``` SELECT * FROM table1 WHERE :myvariable IS NULL; ``` *edit: As of psql 9.1, variables can be expand...
36,991
<p>So, I am a total beginner in any kind of <code>Windows</code> related programming. I have been playing around with the <code>Windows</code> <code>API</code> and came across a couple of examples on how to initialize create windows and such. </p> <p>One example creates a regular window (I abbreviated some of the code...
[ { "answer_id": 36986, "author": "Mark Biek", "author_id": 305, "author_profile": "https://Stackoverflow.com/users/305", "pm_score": 0, "selected": false, "text": "<p>I've always done it exactly the way you're describing. I'm curious to see if there's a more accepted approach.</p>\n" }...
2008/08/31
[ "https://Stackoverflow.com/questions/36991", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2386/" ]
So, I am a total beginner in any kind of `Windows` related programming. I have been playing around with the `Windows` `API` and came across a couple of examples on how to initialize create windows and such. One example creates a regular window (I abbreviated some of the code): ``` int WINAPI WinMain( [...] ) { ...
I would say exposing properties on your custom dialog is the idiomatic way to go because that is how standard dialogs (like the Select/OpenFileDialog) do it. Someone could argue it is more explicit and intention revealing to have a ShowBirthdayDialog() method that returns the result you're looking for, but following th...
37,026
<p>If one Googles for "difference between <code>notify()</code> and <code>notifyAll()</code>" then a lot of explanations will pop up (leaving apart the javadoc paragraphs). It all boils down to the number of waiting threads being waken up: one in <code>notify()</code> and all in <code>notifyAll()</code>.</p> <p>Howeve...
[ { "answer_id": 37038, "author": "Spoike", "author_id": 3713, "author_profile": "https://Stackoverflow.com/users/3713", "pm_score": 2, "selected": false, "text": "<p><code>notify()</code> will wake up one thread while <code>notifyAll()</code> will wake up all. As far as I know there is no...
2008/08/31
[ "https://Stackoverflow.com/questions/37026", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3894/" ]
If one Googles for "difference between `notify()` and `notifyAll()`" then a lot of explanations will pop up (leaving apart the javadoc paragraphs). It all boils down to the number of waiting threads being waken up: one in `notify()` and all in `notifyAll()`. However (if I do understand the difference between these met...
> > However (if I do understand the difference between these methods right), only one thread is always selected for further monitor acquisition. > > > That is not correct. `o.notifyAll()` wakes *all* of the threads that are blocked in `o.wait()` calls. The threads are only allowed to return from `o.wait()` one-by-...
37,069
<p>On Mac OS X 10.5 I downloaded the latest version of Apache 2.2.9. After the usual configure, make, make install dance I had a build of apache without mod_rewrite. This wasn't statically linked and the module was not built in the /modules folder either.</p> <p>I had to do the following to build Apache and mod_rewrit...
[ { "answer_id": 37111, "author": "Brendan", "author_id": 199, "author_profile": "https://Stackoverflow.com/users/199", "pm_score": 5, "selected": true, "text": "<p>Try the <code>./configure</code> option <code>--enable-mods-shared=\"all\"</code>, or <code>--enable-mods-shared=\"&lt;list ...
2008/08/31
[ "https://Stackoverflow.com/questions/37069", "https://Stackoverflow.com", "https://Stackoverflow.com/users/636/" ]
On Mac OS X 10.5 I downloaded the latest version of Apache 2.2.9. After the usual configure, make, make install dance I had a build of apache without mod\_rewrite. This wasn't statically linked and the module was not built in the /modules folder either. I had to do the following to build Apache and mod\_rewrite: ``` ...
Try the `./configure` option `--enable-mods-shared="all"`, or `--enable-mods-shared="<list of modules>"` to compile modules as shared objects. See further [details in Apache 2.2 docs](http://httpd.apache.org/docs/2.2/programs/configure.html#otheroptfeat) To just compile Apache with the ability to load shared objects (...
37,073
<p>What is currently the best way to get a favicon to display in all browsers that currently support it?</p> <p>Please include:</p> <ol> <li><p>Which image formats are supported by which browsers.</p></li> <li><p>Which lines are needed in what places for the various browsers.</p></li> </ol>
[ { "answer_id": 37076, "author": "Ross", "author_id": 2025, "author_profile": "https://Stackoverflow.com/users/2025", "pm_score": 2, "selected": false, "text": "<p>Having a <code>favicon.*</code> in your root directory is automatically detected by most browsers. You can ensure it's detect...
2008/08/31
[ "https://Stackoverflow.com/questions/37073", "https://Stackoverflow.com", "https://Stackoverflow.com/users/177/" ]
What is currently the best way to get a favicon to display in all browsers that currently support it? Please include: 1. Which image formats are supported by which browsers. 2. Which lines are needed in what places for the various browsers.
I go for a belt and braces approach here. I create a 32x32 icon in both the `.ico` and `.png` formats called `favicon.ico` and `favicon.png`. The icon name doesn't really matter unless you are dealing with older browsers. 1. Place `favicon.ico` at your site root to support the older browsers (optional and only relev...
37,101
<p>Is there a way clear or reset the outputcache for an entire website without a restart?</p> <p>I'm just starting to use outputcache on a site and when I make a mistake in setting it up I need a page I can browse to that will reset it.</p>
[ { "answer_id": 37167, "author": "Ethan Gunderson", "author_id": 2066, "author_profile": "https://Stackoverflow.com/users/2066", "pm_score": 4, "selected": true, "text": "<p>This should do the trick:</p>\n\n<pre><code>Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.Eve...
2008/08/31
[ "https://Stackoverflow.com/questions/37101", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3747/" ]
Is there a way clear or reset the outputcache for an entire website without a restart? I'm just starting to use outputcache on a site and when I make a mistake in setting it up I need a page I can browse to that will reset it.
This should do the trick: ``` Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Dim path As String path="/AbosoluteVirtualPath/OutputCached.aspx" HttpResponse.RemoveOutputCacheItem(path) End Sub ```
37,103
<p>I have a container div with a fixed <code>width</code> and <code>height</code>, with <code>overflow: hidden</code>.</p> <p>I want a horizontal row of float: left divs within this container. Divs which are floated left will naturally push onto the 'line' below after they read the right bound of their parent. This wil...
[ { "answer_id": 37125, "author": "Sören Kuklau", "author_id": 1600, "author_profile": "https://Stackoverflow.com/users/1600", "pm_score": 3, "selected": false, "text": "<p>This seems close to what you want:</p>\n\n<p><div class=\"snippet\" data-lang=\"js\" data-hide=\"false\" data-console...
2008/08/31
[ "https://Stackoverflow.com/questions/37103", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1349865/" ]
I have a container div with a fixed `width` and `height`, with `overflow: hidden`. I want a horizontal row of float: left divs within this container. Divs which are floated left will naturally push onto the 'line' below after they read the right bound of their parent. This will happen even if the `height` of the paren...
You may put an inner div in the container that is enough wide to hold all the floated divs. ```css #container { background-color: red; overflow: hidden; width: 200px; } #inner { overflow: hidden; width: 2000px; } .child { float: left; background-color: blue; width: 50px; height: 50px; ...
37,122
<p>How do I make a user's browser blink/flash/highlight in the task bar using JavaScript? For example, if I make an AJAX request every 10 seconds to see if the user has any new messages on the server, I want the user to know it right away, even if he is using another application at the time.</p> <p><em>Edit: These use...
[ { "answer_id": 37134, "author": "Robin Barnes", "author_id": 1349865, "author_profile": "https://Stackoverflow.com/users/1349865", "pm_score": 2, "selected": false, "text": "<p>The only way I can think of doing this is by doing something like alert('you have a new message') when the mess...
2008/08/31
[ "https://Stackoverflow.com/questions/37122", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1191/" ]
How do I make a user's browser blink/flash/highlight in the task bar using JavaScript? For example, if I make an AJAX request every 10 seconds to see if the user has any new messages on the server, I want the user to know it right away, even if he is using another application at the time. *Edit: These users do want to...
this won't make the taskbar button flash in changing colours, but the title will blink on and off until they move the mouse. This should work cross platform, and even if they just have it in a different tab. ``` newExcitingAlerts = (function () { var oldTitle = document.title; var msg = "New!"; var timeout...
37,189
<p>I have a console program written in C# that I am using to send faxes. When I step through the program in Visual Studio it works fine. When I double click on the program in Windows Explorer it works fine. When I setup a Windows scheduled task to run the program it fails with this in the event log.</p> <pre><code>...
[ { "answer_id": 37199, "author": "aku", "author_id": 1196, "author_profile": "https://Stackoverflow.com/users/1196", "pm_score": 0, "selected": false, "text": "<p>Check that you set correct working directory for your task</p>\n" }, { "answer_id": 37200, "author": "Glenn Slaven...
2008/08/31
[ "https://Stackoverflow.com/questions/37189", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1203/" ]
I have a console program written in C# that I am using to send faxes. When I step through the program in Visual Studio it works fine. When I double click on the program in Windows Explorer it works fine. When I setup a Windows scheduled task to run the program it fails with this in the event log. ``` EventType clr20r3...
I can't explain it - but I have a few ideas. Most of the times, when a program works fine testing it, and doesn't when scheduling it - security is the case. In the context of which user is your program scheduled? Maybe that user isn't granted enough access. Is the resource your programm is trying to access a network ...
37,198
<ol> <li>Specifically getting on Windows the "..\Documents &amp; Settings\All Users, basicaly any path that needs the front end to be dynamically derived based on the OS your software is running on. <strong>(Now I need the answer to this)</strong></li> <li>the current users My Documents dirctory <strong>(okay this has...
[ { "answer_id": 37240, "author": "nimish", "author_id": 3926, "author_profile": "https://Stackoverflow.com/users/3926", "pm_score": 3, "selected": false, "text": "<p>My docs would probably best be handled by accessing:</p>\n\n<pre><code>System.getProperty(\"user.home\");\n</code></pre>\n\...
2008/08/31
[ "https://Stackoverflow.com/questions/37198", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3576/" ]
1. Specifically getting on Windows the "..\Documents & Settings\All Users, basicaly any path that needs the front end to be dynamically derived based on the OS your software is running on. **(Now I need the answer to this)** 2. the current users My Documents dirctory **(okay this has been answered)** and basicaly any ...
My docs would probably best be handled by accessing: ``` System.getProperty("user.home"); ``` Look up the docs on [System.getProperty](http://java.sun.com/j2se/1.5.0/docs/api/java/lang/System.html).
37,219
<p>Suppose your git history looks like this:</p> <p>1 2 3 4 5</p> <p>1–5 are separate revisions. You need to remove 3 while still keeping 1, 2, 4 and 5. How can this be done?</p> <p>Is there an efficient method when there are hundreds of revisions after the one to be deleted?</p>
[ { "answer_id": 37267, "author": "garethm", "author_id": 2219, "author_profile": "https://Stackoverflow.com/users/2219", "pm_score": 7, "selected": true, "text": "<p>To combine revision 3 and 4 into a single revision, you can use git rebase. If you want to remove the changes in revision 3...
2008/08/31
[ "https://Stackoverflow.com/questions/37219", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3146/" ]
Suppose your git history looks like this: 1 2 3 4 5 1–5 are separate revisions. You need to remove 3 while still keeping 1, 2, 4 and 5. How can this be done? Is there an efficient method when there are hundreds of revisions after the one to be deleted?
To combine revision 3 and 4 into a single revision, you can use git rebase. If you want to remove the changes in revision 3, you need to use the edit command in the interactive rebase mode. If you want to combine the changes into a single revision, use squash. I have successfully used this squash technique, but have n...
37,248
<p>While the C# spec does include a pre-processor and basic directives (#define, #if, etc), the language does not have the same flexible pre-processor found in languages such as C/C++. I believe the lack of such a flexible pre-processor was a design decision made by Anders Hejlsberg (although, unfortunately, I can't fi...
[ { "answer_id": 37249, "author": "John Millikin", "author_id": 3560, "author_profile": "https://Stackoverflow.com/users/3560", "pm_score": 3, "selected": false, "text": "<blockquote>\n <p>Should I build a C# pre-processor? Is there one available that does the simple things I want to do?<...
2008/08/31
[ "https://Stackoverflow.com/questions/37248", "https://Stackoverflow.com", "https://Stackoverflow.com/users/708/" ]
While the C# spec does include a pre-processor and basic directives (#define, #if, etc), the language does not have the same flexible pre-processor found in languages such as C/C++. I believe the lack of such a flexible pre-processor was a design decision made by Anders Hejlsberg (although, unfortunately, I can't find ...
Consider taking a look at an aspect-oriented solution like [PostSharp](http://www.postsharp.org/), which injects code after the fact based on custom attributes. It's the opposite of a precompiler but can give you the sort of functionality you're looking for (PropertyChanged notifications etc).
37,275
<p>What is the SQL query to select all of the MSSQL Server's logins?</p> <p>Thank you. More than one of you had the answer I was looking for:</p> <pre><code>SELECT * FROM syslogins </code></pre>
[ { "answer_id": 37280, "author": "Matt Hamilton", "author_id": 615, "author_profile": "https://Stackoverflow.com/users/615", "pm_score": 4, "selected": false, "text": "<pre><code>EXEC sp_helplogins\n</code></pre>\n\n<p>You can also pass an \"@LoginNamePattern\" parameter to get informatio...
2008/08/31
[ "https://Stackoverflow.com/questions/37275", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1208/" ]
What is the SQL query to select all of the MSSQL Server's logins? Thank you. More than one of you had the answer I was looking for: ``` SELECT * FROM syslogins ```
Is this what you're after? ``` select * from master.syslogins ```
37,299
<p>What's the instruction to cause a hard-break in Xcode? For example under Visual Studio I could do '_asm int 3' or 'DebugBreak()'. Under some GCC implementations it's asm("break 0") or asm("trap").</p> <p>I've tried various combos under Xcode without any luck. (inline assembler works fine so it's not a syntax issue)...
[ { "answer_id": 37303, "author": "GateKiller", "author_id": 383, "author_profile": "https://Stackoverflow.com/users/383", "pm_score": 2, "selected": false, "text": "<p>I found the following in an <a href=\"http://lists.apple.com/archives/Cocoa-dev/2003/Nov/msg00166.html\" rel=\"nofollow n...
2008/09/01
[ "https://Stackoverflow.com/questions/37299", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1043/" ]
What's the instruction to cause a hard-break in Xcode? For example under Visual Studio I could do '\_asm int 3' or 'DebugBreak()'. Under some GCC implementations it's asm("break 0") or asm("trap"). I've tried various combos under Xcode without any luck. (inline assembler works fine so it's not a syntax issue). For re...
<http://developer.apple.com/documentation/DeveloperTools/Conceptual/XcodeProjectManagement/090_Running_Programs/chapter_11_section_3.html> ``` asm {trap} ; Halts a program running on PPC32 or PPC64. __asm {int 3} ; Halts a program running on IA-32. ```
37,310
<p>I have developed some classes with similar behavior, they all implement the same interface. I implemented a factory that creates the appropriate object and returns the interface. I am writing a unit test for the factory. All you get back is an interface to the object. What is the best way to test that the factory...
[ { "answer_id": 37316, "author": "Cem Catikkas", "author_id": 3087, "author_profile": "https://Stackoverflow.com/users/3087", "pm_score": 6, "selected": true, "text": "<p>Since I don't know how your factory method looks like, all I can advise right now is to </p>\n\n<ol>\n<li><p>Check to ...
2008/09/01
[ "https://Stackoverflow.com/questions/37310", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3576/" ]
I have developed some classes with similar behavior, they all implement the same interface. I implemented a factory that creates the appropriate object and returns the interface. I am writing a unit test for the factory. All you get back is an interface to the object. What is the best way to test that the factory has w...
Since I don't know how your factory method looks like, all I can advise right now is to 1. Check to see the object is the correct concrete implementation you were looking for: ``` IMyInterface fromFactory = factory.create(...); Assert.assertTrue(fromFactory instanceof MyInterfaceImpl1); ``` 2. You can check if th...
37,317
<p>I'm working on a windows forms application (C#) where a user is entering data in a form. At any point while editing the data in the form the user can click one of the buttons on the form to perform certain actions. By default the focus goes to the clicked button so the user has to click back on to the control they...
[ { "answer_id": 37319, "author": "Jon Limjap", "author_id": 372, "author_profile": "https://Stackoverflow.com/users/372", "pm_score": 0, "selected": false, "text": "<p>Your implementation looks good enough -- what I do want to know is why you want to do this in the first place? Won't it b...
2008/09/01
[ "https://Stackoverflow.com/questions/37317", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3452/" ]
I'm working on a windows forms application (C#) where a user is entering data in a form. At any point while editing the data in the form the user can click one of the buttons on the form to perform certain actions. By default the focus goes to the clicked button so the user has to click back on to the control they want...
For a bit of 'simplicity' maybe try. ``` public Form1() { InitializeComponent(); foreach (Control ctrl in Controls) { if (ctrl is TextBox) { ctrl.Enter += delegate(object sender, EventArgs e) { ...
37,324
<p>I'm writing a LINQ to SQL statement, and I'm after the standard syntax for a normal inner join with an <code>ON</code> clause in C#.</p> <p>How do you represent the following in LINQ to SQL:</p> <pre><code>select DealerContact.* from Dealer inner join DealerContact on Dealer.DealerID = DealerContact.DealerID </co...
[ { "answer_id": 37332, "author": "Jon Limjap", "author_id": 372, "author_profile": "https://Stackoverflow.com/users/372", "pm_score": 10, "selected": true, "text": "<p>It goes something like:</p>\n\n<pre><code>from t1 in db.Table1\njoin t2 in db.Table2 on t1.field equals t2.field\nselect ...
2008/09/01
[ "https://Stackoverflow.com/questions/37324", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2975/" ]
I'm writing a LINQ to SQL statement, and I'm after the standard syntax for a normal inner join with an `ON` clause in C#. How do you represent the following in LINQ to SQL: ``` select DealerContact.* from Dealer inner join DealerContact on Dealer.DealerID = DealerContact.DealerID ```
It goes something like: ``` from t1 in db.Table1 join t2 in db.Table2 on t1.field equals t2.field select new { t1.field2, t2.field3} ``` It would be nice to have sensible names and fields for your tables for a better example. :) **Update** I think for your query this might be more appropriate: ``` var dealerconta...
37,346
<p>If I create a class like so: </p> <pre><code>// B.h #ifndef _B_H_ #define _B_H_ class B { private: int x; int y; }; #endif // _B_H_ </code></pre> <p>and use it like this:</p> <pre><code>// main.cpp #include &lt;iostream&gt; #include &lt;vector&gt; class B; // Forward declaration. class A { public: ...
[ { "answer_id": 37347, "author": "Josh", "author_id": 257, "author_profile": "https://Stackoverflow.com/users/257", "pm_score": 3, "selected": false, "text": "<p>To instantiate A::v, the compiler needs to know the concrete type of B.</p>\n\n<p>If you're trying to minimize the amount of #i...
2008/09/01
[ "https://Stackoverflow.com/questions/37346", "https://Stackoverflow.com", "https://Stackoverflow.com/users/61/" ]
If I create a class like so: ``` // B.h #ifndef _B_H_ #define _B_H_ class B { private: int x; int y; }; #endif // _B_H_ ``` and use it like this: ``` // main.cpp #include <iostream> #include <vector> class B; // Forward declaration. class A { public: A() { std::cout << v.size() << std::endl...
The compiler needs to know how big "B" is before it can generate the appropriate layout information. If instead, you said `std::vector<B*>`, then the compiler wouldn't need to know how big B is because it knows how big a pointer is.
37,391
<p>Ok, so PHP isn't the best language to be dealing with arbitrarily large integers in, considering that it only natively supports 32-bit signed integers. What I'm trying to do though is create a class that could represent an arbitrarily large binary number and be able to perform simple arithmetic operations on two of ...
[ { "answer_id": 37422, "author": "SCdF", "author_id": 1666, "author_profile": "https://Stackoverflow.com/users/1666", "pm_score": 2, "selected": false, "text": "<p>There are already various <a href=\"http://www.pear.php.net/package/Crypt_DiffieHellman/docs/latest/Crypt_DiffieHellman/BigIn...
2008/09/01
[ "https://Stackoverflow.com/questions/37391", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1384/" ]
Ok, so PHP isn't the best language to be dealing with arbitrarily large integers in, considering that it only natively supports 32-bit signed integers. What I'm trying to do though is create a class that could represent an arbitrarily large binary number and be able to perform simple arithmetic operations on two of the...
The [PHP GMP extension](http://us2.php.net/gmp) will be better for this. As an added bonus, you can use it to do your decimal-to-binary conversion, like so: ``` gmp_strval(gmp_init($n, 10), 2); ```
37,464
<p>If I create an application on my Mac, is there any way I can get it to run on an iPhone without going through the app store?</p> <p>It doesn't matter if the iPhone has to be jailbroken, as long as I can still run an application created using the official SDK. For reasons I won't get into, I can't have this program ...
[ { "answer_id": 37476, "author": "Robert Höglund", "author_id": 143, "author_profile": "https://Stackoverflow.com/users/143", "pm_score": 4, "selected": false, "text": "<p>Yes, once you have joined the iPhone Developer Program, and paid Apple $99, you can provision your applications on up...
2008/09/01
[ "https://Stackoverflow.com/questions/37464", "https://Stackoverflow.com", "https://Stackoverflow.com/users/752/" ]
If I create an application on my Mac, is there any way I can get it to run on an iPhone without going through the app store? It doesn't matter if the iPhone has to be jailbroken, as long as I can still run an application created using the official SDK. For reasons I won't get into, I can't have this program going thro...
Official Developer Program ========================== For a standard iPhone you'll need to pay the US$99/yr to be a member of the developer program. You can then use the adhoc system to install your application onto up to 100 devices. The developer program has the details but it involves adding UUIDs for each of the d...
37,471
<p>The minimum spanning tree problem is to take a connected weighted graph and find the subset of its edges with the lowest total weight while keeping the graph connected (and as a consequence resulting in an acyclic graph).</p> <p>The algorithm I am considering is:</p> <ul> <li>Find all cycles.</li> <li>remove the l...
[ { "answer_id": 37477, "author": "James A. Rosen", "author_id": 1190, "author_profile": "https://Stackoverflow.com/users/1190", "pm_score": 1, "selected": false, "text": "<p>What happens if two cycles overlap? Which one has its longest edge removed first? Does it matter if the longest e...
2008/09/01
[ "https://Stackoverflow.com/questions/37471", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1343/" ]
The minimum spanning tree problem is to take a connected weighted graph and find the subset of its edges with the lowest total weight while keeping the graph connected (and as a consequence resulting in an acyclic graph). The algorithm I am considering is: * Find all cycles. * remove the largest edge from each cycle....
What happens if two cycles overlap? Which one has its longest edge removed first? Does it matter if the longest edge of each is shared between the two cycles or not? For example: ``` V = { a, b, c, d } E = { (a,b,1), (b,c,2), (c,a,4), (b,d,9), (d,a,3) } ``` There's an a -> b -> c -> a cycle, and an a -> b -> d -> a
37,473
<p>If I use <code>assert()</code> and the assertion fails then <code>assert()</code> will call <code>abort()</code>, ending the running program abruptly. I can't afford that in my production code. Is there a way to assert in runtime yet be able to catch failed assertions so I have the chance to handle them gracefully...
[ { "answer_id": 37474, "author": "wilhelmtell", "author_id": 456, "author_profile": "https://Stackoverflow.com/users/456", "pm_score": 6, "selected": true, "text": "<p>Yes, as a matter of fact there is. You will need to write a custom assert function yourself, as C++'s <code>assert()</co...
2008/09/01
[ "https://Stackoverflow.com/questions/37473", "https://Stackoverflow.com", "https://Stackoverflow.com/users/456/" ]
If I use `assert()` and the assertion fails then `assert()` will call `abort()`, ending the running program abruptly. I can't afford that in my production code. Is there a way to assert in runtime yet be able to catch failed assertions so I have the chance to handle them gracefully?
Yes, as a matter of fact there is. You will need to write a custom assert function yourself, as C++'s `assert()` is exactly C's `assert()`, with the `abort()` "feature" bundled in. Fortunately, this is surprisingly straightforward. *Assert.hh* ``` template <typename X, typename A> inline void Assert(A assertion) { ...
37,479
<p>Below I have a very simple example of what I'm trying to do. I want to be able to use HTMLDecorator with any other class. Ignore the fact it's called decorator, it's just a name.</p> <pre><code>import cgi class ClassX(object): pass # ... with own __repr__ class ClassY(object): pass # ... with own __repr__ ...
[ { "answer_id": 37488, "author": "John Millikin", "author_id": 3560, "author_profile": "https://Stackoverflow.com/users/3560", "pm_score": 0, "selected": false, "text": "<blockquote>\n <p>Is what I'm trying to do possible? If so, what am I doing wrong?</p>\n</blockquote>\n\n<p>It's certa...
2008/09/01
[ "https://Stackoverflow.com/questions/37479", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1057/" ]
Below I have a very simple example of what I'm trying to do. I want to be able to use HTMLDecorator with any other class. Ignore the fact it's called decorator, it's just a name. ``` import cgi class ClassX(object): pass # ... with own __repr__ class ClassY(object): pass # ... with own __repr__ inst_x=ClassX() ...
> > Very close, but then I lose everything from ClassX. Below is something a collegue gave me that does do the trick, but it's hideous. There has to be a better way. > > > Looks like you're trying to set up some sort of proxy object scheme. That's doable, and there are better solutions than your colleague's, but f...
37,486
<p>Because regular expressions scare me, I'm trying to find a way to remove all HTML tags and resolve HTML entities from a string in Python.</p>
[ { "answer_id": 37496, "author": "bernhardrusch", "author_id": 3056, "author_profile": "https://Stackoverflow.com/users/3056", "pm_score": 2, "selected": false, "text": "<p>How about parsing the HTML data and extracting the data with the help of the parser ?</p>\n\n<p>I'd try something li...
2008/09/01
[ "https://Stackoverflow.com/questions/37486", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3971/" ]
Because regular expressions scare me, I'm trying to find a way to remove all HTML tags and resolve HTML entities from a string in Python.
Use [lxml](http://lxml.de/) which is the best xml/html library for python. ``` import lxml.html t = lxml.html.fromstring("...") t.text_content() ``` And if you just want to sanitize the html look at the lxml.html.clean [module](http://lxml.de/lxmlhtml.html#cleaning-up-html)
37,538
<p>How do I determine the size of my array in C? </p> <p>That is, the number of elements the array can hold?</p>
[ { "answer_id": 37539, "author": "Mark Harrison", "author_id": 116, "author_profile": "https://Stackoverflow.com/users/116", "pm_score": 12, "selected": true, "text": "<p><strong>Executive summary:</strong></p>\n\n<pre><code>int a[17];\nsize_t n = sizeof(a)/sizeof(a[0]);\n</code></pre>\n\...
2008/09/01
[ "https://Stackoverflow.com/questions/37538", "https://Stackoverflow.com", "https://Stackoverflow.com/users/116/" ]
How do I determine the size of my array in C? That is, the number of elements the array can hold?
**Executive summary:** ``` int a[17]; size_t n = sizeof(a)/sizeof(a[0]); ``` --- **Full answer:** To determine the size of your array in bytes, you can use the `sizeof` operator: ``` int a[17]; size_t n = sizeof(a); ``` On my computer, ints are 4 bytes long, so n is 68. To determine the number of elements in t...
37,551
<p>I have a problem with an application running on Fedora Core 6 with JDK 1.5.0_08.</p> <p>After some amount of uptime (usually some days) threads begin getting stuck in native methods.</p> <p>The threads are locked in something like this:</p> <pre><code>&quot;pool-2-thread-2571&quot; prio=1 tid=0x08dd0b28 nid=0x319e w...
[ { "answer_id": 38320, "author": "John Smithers", "author_id": 1069, "author_profile": "https://Stackoverflow.com/users/1069", "pm_score": 0, "selected": false, "text": "<p>Maybe you should use another jdk version.<br>\nFor your \"puzzling one\", there is a bug entry for 1.5.0_08. A memor...
2008/09/01
[ "https://Stackoverflow.com/questions/37551", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3904/" ]
I have a problem with an application running on Fedora Core 6 with JDK 1.5.0\_08. After some amount of uptime (usually some days) threads begin getting stuck in native methods. The threads are locked in something like this: ``` "pool-2-thread-2571" prio=1 tid=0x08dd0b28 nid=0x319e waiting for monitor entry [0xb91fe0...
My initial suspicion would be that you are experiencing some sort of class-loader realted dead lock. I imagine, that class loading needs to be synchronized at some level because class information will become available for the entire VM, not just the thread where it was initially loaded. The fact that the methods on to...
37,568
<p>How do I find duplicate addresses in a database, or better stop people already when filling in the form ? I guess the earlier the better?</p> <p>Is there any good way of abstracting street, postal code etc so that typos and simple attempts to get 2 registrations can be detected? like: </p> <pre><code>Quellenstrass...
[ { "answer_id": 37577, "author": "svrist", "author_id": 86, "author_profile": "https://Stackoverflow.com/users/86", "pm_score": 0, "selected": false, "text": "<p>Often you use constraints in a database to ensure data to be \"unique\" in the data-based sense.</p>\n\n<p>Regarding \"isomorph...
2008/09/01
[ "https://Stackoverflow.com/questions/37568", "https://Stackoverflow.com", "https://Stackoverflow.com/users/925/" ]
How do I find duplicate addresses in a database, or better stop people already when filling in the form ? I guess the earlier the better? Is there any good way of abstracting street, postal code etc so that typos and simple attempts to get 2 registrations can be detected? like: ``` Quellenstrasse 66/11 Quellenstr. ...
> > Johannes: > > > > > > > @PConroy: This was my initial thougt also. the interesting part on this is to find good transformation rules for the different parts of the address! Any good suggestions? > > > > > > > > > When we were working on this type of project before, our approach was to take our existing ...
37,591
<p>I would like to display details of an xml error log to a user in a winforms application and am looking for the best control to do the job.</p> <p>The error data contains all of the sever variables at the time that the error occurred. These have been formatted into an XML document that looks something to the effect ...
[ { "answer_id": 37612, "author": "Skizz", "author_id": 1898, "author_profile": "https://Stackoverflow.com/users/1898", "pm_score": 0, "selected": false, "text": "<p>You could try using the <code>DataGridView</code> control. To see an example, load an XML file in DevStudio and then right-c...
2008/09/01
[ "https://Stackoverflow.com/questions/37591", "https://Stackoverflow.com", "https://Stackoverflow.com/users/231/" ]
I would like to display details of an xml error log to a user in a winforms application and am looking for the best control to do the job. The error data contains all of the sever variables at the time that the error occurred. These have been formatted into an XML document that looks something to the effect of: ``` <...
You can transform your XML data using [XSLT](http://www.xml.com/pub/a/2002/08/14/dotnetxslt.html) Another option is to use XLinq. If you want concrete code example provide us with sample data **EDIT**: here is a sample XSLT transform for your XML file: ``` <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3...
37,597
<p>TreeNodeCollection, like some of the other control collections in System.Windows.Forms, implements IEnumerable. Is there any design reason behind this or is it just a hangover from the days before generics?</p>
[ { "answer_id": 37607, "author": "Luke Halliwell", "author_id": 3974, "author_profile": "https://Stackoverflow.com/users/3974", "pm_score": 0, "selected": false, "text": "<p>Yes, Windows Forms dates back to before generics in .Net</p>\n" }, { "answer_id": 37609, "author": "Art...
2008/09/01
[ "https://Stackoverflow.com/questions/37597", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2608/" ]
TreeNodeCollection, like some of the other control collections in System.Windows.Forms, implements IEnumerable. Is there any design reason behind this or is it just a hangover from the days before generics?
Yes, there are many .NET Framework collection, that does not implement generic IEnumerable. I think that's because after 2.0 there was no (at least not so match) development of the core part of FW. Meanwhile I suggest you to make use of following workaround: ``` using System.Linq; ... var nodes = GetTreeNodeColle...
37,628
<p>What is reflection, and why is it useful?</p> <p>I'm particularly interested in Java, but I assume the principles are the same in any language.</p>
[ { "answer_id": 37632, "author": "Matt Sheppard", "author_id": 797, "author_profile": "https://Stackoverflow.com/users/797", "pm_score": 12, "selected": true, "text": "<p>The name reflection is used to describe code which is able to inspect other code in the same system (or itself).</p>\n...
2008/09/01
[ "https://Stackoverflow.com/questions/37628", "https://Stackoverflow.com", "https://Stackoverflow.com/users/142/" ]
What is reflection, and why is it useful? I'm particularly interested in Java, but I assume the principles are the same in any language.
The name reflection is used to describe code which is able to inspect other code in the same system (or itself). For example, say you have an object of an unknown type in Java, and you would like to call a 'doSomething' method on it if one exists. Java's static typing system isn't really designed to support this unles...
37,649
<p>I have a MySQL table with coordinates, the column names are X and Y. Now I want to swap the column values in this table, so that X becomes Y and Y becomes X. The most apparent solution would be renaming the columns, but I don't want to make structure changes since I don't necessarily have permissions to do that.</p>...
[ { "answer_id": 37653, "author": "Unsliced", "author_id": 2902, "author_profile": "https://Stackoverflow.com/users/2902", "pm_score": 2, "selected": false, "text": "<p>Two alternatives \n 1. Use a temporary table \n 2. Investigate\n the <a href=\"http://en.wikipedia.org/wiki/XOR_swap_a...
2008/09/01
[ "https://Stackoverflow.com/questions/37649", "https://Stackoverflow.com", "https://Stackoverflow.com/users/890/" ]
I have a MySQL table with coordinates, the column names are X and Y. Now I want to swap the column values in this table, so that X becomes Y and Y becomes X. The most apparent solution would be renaming the columns, but I don't want to make structure changes since I don't necessarily have permissions to do that. Is th...
I just had to deal with the same and I'll summarize my findings. 1. The `UPDATE table SET X=Y, Y=X` approach obviously doesn't work, as it'll just set both values to Y. 2. Here's a method that uses a temporary variable. Thanks to Antony from the comments of <http://beerpla.net/2009/02/17/swapping-column-values-in-mysq...
37,650
<p>What is the best way to implement, from a web page a download action using asp.net 2.0?</p> <p>Log files for a action are created in a directory called [Application Root]/Logs. I have the full path and want to provide a button, that when clicked will download the log file from the IIS server to the users local pc....
[ { "answer_id": 37656, "author": "Martin", "author_id": 770, "author_profile": "https://Stackoverflow.com/users/770", "pm_score": 6, "selected": true, "text": "<p>Does this help:</p>\n\n<p><a href=\"http://www.west-wind.com/weblog/posts/76293.aspx\" rel=\"noreferrer\">http://www.west-wind...
2008/09/01
[ "https://Stackoverflow.com/questions/37650", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3416/" ]
What is the best way to implement, from a web page a download action using asp.net 2.0? Log files for a action are created in a directory called [Application Root]/Logs. I have the full path and want to provide a button, that when clicked will download the log file from the IIS server to the users local pc.
Does this help: <http://www.west-wind.com/weblog/posts/76293.aspx> ``` Response.ContentType = "application/octet-stream"; Response.AppendHeader("Content-Disposition","attachment; filename=logfile.txt"); Response.TransmitFile( Server.MapPath("~/logfile.txt") ); Response.End(); ``` Response.TransmitFile is the accept...
37,665
<p>When <strong>Eclipse</strong> creates a new file (<strong>.c</strong> or <strong>.h</strong> file) in a C project the editor always auto creates a <code>#define</code> at the top of the file like this: If the file is named 'myCFile.c' there will be a <code>#define</code> at the start of the file like this</p> <pre>...
[ { "answer_id": 37668, "author": "Eugene Yokota", "author_id": 3827, "author_profile": "https://Stackoverflow.com/users/3827", "pm_score": 3, "selected": true, "text": "<p>It's to guard against <a href=\"http://www.fredosaurus.com/notes-cpp/preprocessor/ifdef.html\" rel=\"nofollow norefer...
2008/09/01
[ "https://Stackoverflow.com/questions/37665", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2079/" ]
When **Eclipse** creates a new file (**.c** or **.h** file) in a C project the editor always auto creates a `#define` at the top of the file like this: If the file is named 'myCFile.c' there will be a `#define` at the start of the file like this ``` #ifndef MYCFILE_C_ #define MYCFILE_C_ ``` I have seen other editors...
It's to guard against [multiple definitions](http://www.fredosaurus.com/notes-cpp/preprocessor/ifdef.html).
37,684
<p>I am using the function below to match URLs inside a given text and replace them for HTML links. The regular expression is working great, but currently I am only replacing the first match.</p> <p>How I can replace all the URL? I guess I should be using the <em>exec</em> command, but I did not really figure how to d...
[ { "answer_id": 37687, "author": "Sam Hasler", "author_id": 2541, "author_profile": "https://Stackoverflow.com/users/2541", "pm_score": 8, "selected": false, "text": "<h3>Replacing URLs with links (Answer to the General Problem)</h3>\n\n<p>The regular expression in the question misses <em...
2008/09/01
[ "https://Stackoverflow.com/questions/37684", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2138/" ]
I am using the function below to match URLs inside a given text and replace them for HTML links. The regular expression is working great, but currently I am only replacing the first match. How I can replace all the URL? I guess I should be using the *exec* command, but I did not really figure how to do it. ``` functi...
First off, rolling your own regexp to parse URLs is a *terrible idea*. You must imagine this is a common enough problem that someone has written, debugged and [tested](http://benalman.com/code/test/js-linkify/) a library for it, according to [the RFCs](https://metacpan.org/pod/Regexp::Common::URI#REFERENCES). **URIs ar...
37,696
<p>I have three tables <code>tag</code>, <code>page</code>, <code>pagetag</code></p> <p>With the data below</p> <p><strong><em>page</em></strong></p> <pre><code>ID NAME 1 page 1 2 page 2 3 page 3 4 page 4 </code></pre> <p><strong><em>tag</em></strong></p> <pre><code>ID NAME 1 ...
[ { "answer_id": 37700, "author": "ConroyP", "author_id": 2287, "author_profile": "https://Stackoverflow.com/users/2287", "pm_score": 2, "selected": false, "text": "<p>Yep, you can do it across the 3 something like the below:</p>\n\n<pre><code>SELECT page_tag.id, page.name, group_concat(ta...
2008/09/01
[ "https://Stackoverflow.com/questions/37696", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2138/" ]
I have three tables `tag`, `page`, `pagetag` With the data below ***page*** ``` ID NAME 1 page 1 2 page 2 3 page 3 4 page 4 ``` ***tag*** ``` ID NAME 1 tag 1 2 tag 2 3 tag 3 4 tag 4 ``` ***pagetag*** ``` ID PAGEID TAGID 1 2 1 2 2 ...
> > Sergio del Amo: > > > > > > > However, I am not getting the pages without tags. I guess i need to write my query with left outer joins. > > > > > > > > > ``` SELECT pagetag.id, page.name, group_concat(tag.name) FROM ( page LEFT JOIN pagetag ON page.id = pagetag.pageid ) LEFT JOIN tag ON pagetag.tagi...