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
167,990
<p>I am developing a small web app project (ColdFusion) and I am trying to keep my project split into multiple files during development, but deploy just one file on completion.</p> <p>I have references to external files, for instance:</p> <pre><code>&lt;script type="text/javascript" src="jquery-1.2.6.pack.js"&gt;&lt;...
[ { "answer_id": 169052, "author": "Peter Boughton", "author_id": 9360, "author_profile": "https://Stackoverflow.com/users/9360", "pm_score": 2, "selected": false, "text": "<p>Does this do what you want?</p>\n\n<pre><code>&lt;property\n name=\"filename\"\n value=\"jquery-1.2.6.pack.j...
2008/10/03
[ "https://Stackoverflow.com/questions/167990", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5918/" ]
I am developing a small web app project (ColdFusion) and I am trying to keep my project split into multiple files during development, but deploy just one file on completion. I have references to external files, for instance: ``` <script type="text/javascript" src="jquery-1.2.6.pack.js"></script> <link type="text/css"...
Answering my own question after a few hours of hacking... ``` <script language="groovy" src="build.groovy" /> ``` and this groovy script replaces any referenced javascript or css file with the file contents itself. ``` f = new File("${targetDir}/index.cfm") fContent = f.text fContent = jsReplace(fContent) fContent ...
168,046
<p>I'm maintaining a library that contains compiled objects that need to be linked into a 3rd party executable. sometimes the executable has been compiled for Solaris, sometimes as a 32bit Linux Application, sometimes its a 64bit linux application. What I'd love to do is pass one "path" to the library, and have the a...
[ { "answer_id": 168225, "author": "Marty", "author_id": 4131, "author_profile": "https://Stackoverflow.com/users/4131", "pm_score": 1, "selected": false, "text": "<p>Use the system info given from \"uname\" to set the paths automatically?<br>\n'uname -s' gives you the kernel name (eg Linu...
2008/10/03
[ "https://Stackoverflow.com/questions/168046", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6314/" ]
I'm maintaining a library that contains compiled objects that need to be linked into a 3rd party executable. sometimes the executable has been compiled for Solaris, sometimes as a 32bit Linux Application, sometimes its a 64bit linux application. What I'd love to do is pass one "path" to the library, and have the appl...
Use the system info given from "uname" to set the paths automatically? 'uname -s' gives you the kernel name (eg Linux / SunOS) 'uname -i' will give you the architecture (eg x86 / x86\_64)
168,073
<p>I'm currently writing a website that allows people to download Excel and text files. Is there a way to redirect to a different page when they click, so that we run javascript and do analytics (i.e. keep download count)? Currently, nothing prevents the user from simply right-clicking and saving. </p> <p>Edit: </p> ...
[ { "answer_id": 168121, "author": "Joe Skora", "author_id": 14057, "author_profile": "https://Stackoverflow.com/users/14057", "pm_score": 0, "selected": false, "text": "<p>I'm not sure what you are asking here, are you trying to figure out how to redirect in the controller or are you tryi...
2008/10/03
[ "https://Stackoverflow.com/questions/168073", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6833/" ]
I'm currently writing a website that allows people to download Excel and text files. Is there a way to redirect to a different page when they click, so that we run javascript and do analytics (i.e. keep download count)? Currently, nothing prevents the user from simply right-clicking and saving. Edit: To be more spe...
I started describing how you might do this in Grails but then remembered most analytics services (Google, Omniture, etc.) will let you track downloaded files by using the onclick event. If you have some custom javascript based tracking you're doing, you can do the same thing. The onclick will get called before the docu...
168,080
<p>I have a some JPA entities that inherit from one another and uses discriminator to determine what class to be created (untested as of yet).</p> <pre><code>@Entity(name="switches") @DiscriminatorColumn(name="type") @DiscriminatorValue(value="500") public class DmsSwitch extends Switch implements Serializable {} @Ma...
[ { "answer_id": 168439, "author": "Dan Dyer", "author_id": 5171, "author_profile": "https://Stackoverflow.com/users/5171", "pm_score": 0, "selected": false, "text": "<p>I don't think that you can with your current object model. The Switch class is not an entity, therefore it can't be use...
2008/10/03
[ "https://Stackoverflow.com/questions/168080", "https://Stackoverflow.com", "https://Stackoverflow.com/users/22763/" ]
I have a some JPA entities that inherit from one another and uses discriminator to determine what class to be created (untested as of yet). ``` @Entity(name="switches") @DiscriminatorColumn(name="type") @DiscriminatorValue(value="500") public class DmsSwitch extends Switch implements Serializable {} @MappedSuperclass...
As your switch class is not an entity, it cannot be used in an entity relationship... Unfortunately, you'll have to transform your mappedsuperclass as an entity to involve it in a relationship.
168,084
<p>Usually pagination queries look like this. Is there a better way instead of making two almost equal methods, one of which executing "select *..." and the other one "count *..."?</p> <pre><code>public List&lt;Cat&gt; findCats(String name, int offset, int limit) { Query q = session.createQuery("from Cat where na...
[ { "answer_id": 168353, "author": "Kyle Dyer", "author_id": 24011, "author_profile": "https://Stackoverflow.com/users/24011", "pm_score": 3, "selected": false, "text": "<p>If you don't need to display the total number of pages then I'm not sure you need the count query. Lots of sites inc...
2008/10/03
[ "https://Stackoverflow.com/questions/168084", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20128/" ]
Usually pagination queries look like this. Is there a better way instead of making two almost equal methods, one of which executing "select \*..." and the other one "count \*..."? ``` public List<Cat> findCats(String name, int offset, int limit) { Query q = session.createQuery("from Cat where name=:name"); q...
If you don't need to display the total number of pages then I'm not sure you need the count query. Lots of sites including google don't show the total on the paged results. Instead they just say "next>".
168,113
<p>I have a pretty standard django app, and am wondering how to set the url routing so that I don't have to explicitly map each url to a view. </p> <p>For example, let's say that I have the following views: <code>Project, Links, Profile, Contact</code>. I'd rather not have my <code>urlpatterns</code> look like this:</...
[ { "answer_id": 231624, "author": "Dave Cluderay", "author_id": 30933, "author_profile": "https://Stackoverflow.com/users/30933", "pm_score": 1, "selected": false, "text": "<p>In answer to your first question, hopefully, you'll see something in the sys.transmission_queue system view. See\...
2008/10/03
[ "https://Stackoverflow.com/questions/168113", "https://Stackoverflow.com", "https://Stackoverflow.com/users/736/" ]
I have a pretty standard django app, and am wondering how to set the url routing so that I don't have to explicitly map each url to a view. For example, let's say that I have the following views: `Project, Links, Profile, Contact`. I'd rather not have my `urlpatterns` look like this: ``` (r'^Project/$', 'mysite.app....
In answer to your first question, hopefully, you'll see something in the sys.transmission\_queue system view. See <http://msdn.microsoft.com/en-us/library/ms190336.aspx> for documentation on that. If you Google that, you might find some useful troubleshooting resources too. Dave
168,119
<p>I have a pretty unusual problem (for me). I am writing an application that will allow a user to change their system time forward or back either by explicit date (change my date to 6/3/1955) or by increment using buttons (go forward 1 month).</p> <p>I'm writing this to help some of my users test some software that...
[ { "answer_id": 168134, "author": "Richard Harrison", "author_id": 19624, "author_profile": "https://Stackoverflow.com/users/19624", "pm_score": 2, "selected": false, "text": "<p>The VCL has types (TDate and TDateTime) which are doubles and you can use in arithmetic operations. </p>\n\n<p...
2008/10/03
[ "https://Stackoverflow.com/questions/168119", "https://Stackoverflow.com", "https://Stackoverflow.com/users/172/" ]
I have a pretty unusual problem (for me). I am writing an application that will allow a user to change their system time forward or back either by explicit date (change my date to 6/3/1955) or by increment using buttons (go forward 1 month). I'm writing this to help some of my users test some software that requires ju...
As mentioned by gabr and mliesen, have a look at the [DateUtils](http://docwiki.embarcadero.com/VCL/en/DateUtils) and [SysUtils](http://docwiki.embarcadero.com/VCL/en/SysUtils) units, useful functions include. * [IncDay](http://docwiki.embarcadero.com/VCL/en/DateUtils.IncDay) - Add a or subtract a number of days. * [I...
168,150
<p>I've been trying to get up to speed on some of the newer features in C# and one of them that I haven't had occasion to use is anonymous types.</p> <p>I understand the usage as it pertains to LINQ queries and I looked at <a href="https://stackoverflow.com/questions/48668/how-should-anonymous-types-be-used-in-c">this...
[ { "answer_id": 168159, "author": "Giovanni Galbo", "author_id": 4050, "author_profile": "https://Stackoverflow.com/users/4050", "pm_score": 2, "selected": false, "text": "<p>The biggest use for anonymous types is LINQ, in fact that's why it was created.</p>\n\n<p>I guess one reason for a...
2008/10/03
[ "https://Stackoverflow.com/questions/168150", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7862/" ]
I've been trying to get up to speed on some of the newer features in C# and one of them that I haven't had occasion to use is anonymous types. I understand the usage as it pertains to LINQ queries and I looked at [this SO post](https://stackoverflow.com/questions/48668/how-should-anonymous-types-be-used-in-c) which as...
With a bit of reflection, you can turn an anonymous type into a Dictionary<string, object>; Roy Osherove blogs his technique for this here: <http://weblogs.asp.net/rosherove/archive/2008/03/11/turn-anonymous-types-into-idictionary-of-values.aspx> Jacob Carpenter uses anonymous types as a way to initialize immutable ob...
168,169
<p>Has anyone else seen people do this:</p> <pre><code>private string _name; public string Name{ get{ return _name; } set{ _name = value;}}</code></pre> <p>I understand using accessors if you are going to exercise some sort of control over how it gets set or perform some sort of function on it when there is a get. B...
[ { "answer_id": 168180, "author": "marc", "author_id": 12260, "author_profile": "https://Stackoverflow.com/users/12260", "pm_score": 0, "selected": false, "text": "<p>Preparation. You never know when you'll want to removed the set accessor down the road, perform additional operations in ...
2008/10/03
[ "https://Stackoverflow.com/questions/168169", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19038/" ]
Has anyone else seen people do this: ``` private string _name; public string Name{ get{ return _name; } set{ _name = value;}} ``` I understand using accessors if you are going to exercise some sort of control over how it gets set or perform some sort of function on it when there is a get. But if you are just going to...
If you make the member a public field, then you can't later refactor it into a property without changing the interface to your class. If you expose it as a property from the very beginning, you can make whatever changes to the property accessor functions that you need and the class's interface remains unchanged. Note ...
168,171
<p>Can someone provide a regular expression for parsing name/value pairs from a string? The pairs are separated by commas, and the value can optionally be enclosed in quotes. For example:</p> <pre><code>AssemblyName=foo.dll,ClassName="SomeClass",Parameters="Some,Parameters" </code></pre>
[ { "answer_id": 168196, "author": "Markus Jarderot", "author_id": 22364, "author_profile": "https://Stackoverflow.com/users/22364", "pm_score": 6, "selected": true, "text": "<ul>\n<li><p><strong>No escape:</strong></p>\n\n<pre><code>/([^=,]*)=(\"[^\"]*\"|[^,\"]*)/\n</code></pre></li>\n<li...
2008/10/03
[ "https://Stackoverflow.com/questions/168171", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2773/" ]
Can someone provide a regular expression for parsing name/value pairs from a string? The pairs are separated by commas, and the value can optionally be enclosed in quotes. For example: ``` AssemblyName=foo.dll,ClassName="SomeClass",Parameters="Some,Parameters" ```
* **No escape:** ``` /([^=,]*)=("[^"]*"|[^,"]*)/ ``` * **Double quote escape for both key and value:** ``` /((?:"[^"]*"|[^=,])*)=((?:"[^"]*"|[^=,])*)/ key=value,"key with "" in it"="value with "" in it",key=value" "with" "spaces ``` * **Backslash string escape:** ``` /([^=,]*)=("(?:\\.|[^"\\]+)*"|[^,"]*)/ key=va...
168,173
<p>I have a webpage that pulls information from a database, converts it to .csv format, and writes the file to the HTTPResponse. </p> <pre><code>string csv = GetCSV(); Response.Clear(); Response.ContentType = "text/csv"; Response.Write(csv); </code></pre> <p>This works fine, and the file is sent to the client with n...
[ { "answer_id": 168182, "author": "Joe Skora", "author_id": 14057, "author_profile": "https://Stackoverflow.com/users/14057", "pm_score": 5, "selected": true, "text": "<p>I believe this will work for you.</p>\n\n<pre><code>Response.AddHeader(\"content-disposition\", \"attachment; filename...
2008/10/03
[ "https://Stackoverflow.com/questions/168173", "https://Stackoverflow.com", "https://Stackoverflow.com/users/21461/" ]
I have a webpage that pulls information from a database, converts it to .csv format, and writes the file to the HTTPResponse. ``` string csv = GetCSV(); Response.Clear(); Response.ContentType = "text/csv"; Response.Write(csv); ``` This works fine, and the file is sent to the client with no problems. However, when t...
I believe this will work for you. ``` Response.AddHeader("content-disposition", "attachment; filename=NewFileName.csv"); ```
168,186
<p>Trying to update some gems on a Windows machine and I continually get this error output for gems that do not have pre-compiled binaries:</p> <p>Provided configuration options:</p> <blockquote> <pre><code> --with-opt-dir --without-opt-dir --with-opt-include --without-opt-include=${opt-dir}/include ...
[ { "answer_id": 169967, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 1, "selected": false, "text": "<p>I don't know if this works with the native Windows Ruby, but if you use the Cygwin version and have a full Cygwin installed...
2008/10/03
[ "https://Stackoverflow.com/questions/168186", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9550/" ]
Trying to update some gems on a Windows machine and I continually get this error output for gems that do not have pre-compiled binaries: Provided configuration options: > > > ``` > --with-opt-dir > --without-opt-dir > --with-opt-include > --without-opt-include=${opt-dir}/include > --with-opt-lib...
There's a [DevKit](http://wiki.github.com/oneclick/rubyinstaller/development-kit) that could well be what you're after.
168,214
<p>What is the easiest way to encode a PHP string for output to a JavaScript variable?</p> <p>I have a PHP string which includes quotes and newlines. I need the contents of this string to be put into a JavaScript variable.</p> <p>Normally, I would just construct my JavaScript in a PHP file, à la:</p> <pre><code>&lt...
[ { "answer_id": 168245, "author": "Javier", "author_id": 11649, "author_profile": "https://Stackoverflow.com/users/11649", "pm_score": 5, "selected": false, "text": "<p>encode it with JSON</p>\n" }, { "answer_id": 168255, "author": "Adam", "author_id": 1366, "author_pr...
2008/10/03
[ "https://Stackoverflow.com/questions/168214", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13238/" ]
What is the easiest way to encode a PHP string for output to a JavaScript variable? I have a PHP string which includes quotes and newlines. I need the contents of this string to be put into a JavaScript variable. Normally, I would just construct my JavaScript in a PHP file, à la: ``` <script> var myvar = "<?php ec...
Expanding on someone else's answer: ``` <script> var myvar = <?php echo json_encode($myVarValue); ?>; </script> ``` Using [json\_encode()](http://php.net/json_encode) requires: * PHP 5.2.0 or greater * `$myVarValue` encoded as UTF-8 (or US-ASCII, of course) Since UTF-8 supports full Unicode, it should be safe to...
168,236
<p>I am trying to set attributes for an IFRAME html control from the code-behind aspx.cs file.</p> <p>I came across a <a href="https://web.archive.org/web/20210128094503/http://geekswithblogs.net/ranganh/archive/2005/04/25/37635.aspx" rel="nofollow noreferrer">post</a> that says you can use FindControl to find the non-...
[ { "answer_id": 168248, "author": "Ian Jacobs", "author_id": 22818, "author_profile": "https://Stackoverflow.com/users/22818", "pm_score": 0, "selected": false, "text": "<p>Try instantiating contentPanel1 outside the Load event; keep it global to the class.</p>\n" }, { "answer_id"...
2008/10/03
[ "https://Stackoverflow.com/questions/168236", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12597/" ]
I am trying to set attributes for an IFRAME html control from the code-behind aspx.cs file. I came across a [post](https://web.archive.org/web/20210128094503/http://geekswithblogs.net/ranganh/archive/2005/04/25/37635.aspx) that says you can use FindControl to find the non-asp controls using: The aspx file contains: ...
If the iframe is directly on the page where the code is running, you should be able to reference it directly: ``` contentPanel1.Attribute = value; ``` If not (it's in a child control, or the MasterPage), you'll need a good idea of the hierarchy of the page... Or use the brute-force method of writing a recursive ver...
168,249
<p>Let's say I have a multithreaded C++ program that handles requests in the form of a function call to <code>handleRequest(string key)</code>. Each call to <code>handleRequest</code> occurs in a separate thread, and there are an arbitrarily large number of possible values for <code>key</code>.</p> <p>I want the follo...
[ { "answer_id": 168271, "author": "Michael Burr", "author_id": 12711, "author_profile": "https://Stackoverflow.com/users/12711", "pm_score": 5, "selected": true, "text": "<p>You could do something similar to what you have in your question, but instead of a single global_key_map have sever...
2008/10/03
[ "https://Stackoverflow.com/questions/168249", "https://Stackoverflow.com", "https://Stackoverflow.com/users/24923/" ]
Let's say I have a multithreaded C++ program that handles requests in the form of a function call to `handleRequest(string key)`. Each call to `handleRequest` occurs in a separate thread, and there are an arbitrarily large number of possible values for `key`. I want the following behavior: * Simultaneous calls to `ha...
You could do something similar to what you have in your question, but instead of a single global\_key\_map have several (probably in an array or vector) - which one is used is determined by some simple hash function on the string. That way instead of a single global lock, you spread that out over several independent o...
168,273
<p>I've been unable to build <a href="http://www.perforce.com/perforce/loadsupp.html#api" rel="nofollow noreferrer">P4Python</a> for an Intel Mac OS X 10.5.5.</p> <p>These are my steps:</p> <ol> <li>I downloaded p4python.tgz (from <a href="http://filehost.perforce.com/perforce/r07.3/tools/" rel="nofollow noreferrer">...
[ { "answer_id": 170068, "author": "Douglas Leeder", "author_id": 3978, "author_profile": "https://Stackoverflow.com/users/3978", "pm_score": 1, "selected": false, "text": "<p>From <a href=\"http://bugs.mymediasystem.org/?do=details&amp;task_id=676\" rel=\"nofollow noreferrer\">http://bugs...
2008/10/03
[ "https://Stackoverflow.com/questions/168273", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4766/" ]
I've been unable to build [P4Python](http://www.perforce.com/perforce/loadsupp.html#api) for an Intel Mac OS X 10.5.5. These are my steps: 1. I downloaded p4python.tgz (from <http://filehost.perforce.com/perforce/r07.3/tools/>) and expanded it into "P4Python-2007.3". 2. I downloaded p4api.tar (from <http://filehost.p...
The newer version 2008.1 will build with Python 2.4. I had posted the minor changes required to do that on my P4Python page, but they were rolled in to the official version. Robert
168,317
<p>We have a SmartClient built in C# that stubornly remains open when the PC its running on is being restarted. This halts the restart process unless the user first closes the SmartClient or there is some other manual intervention.</p> <p>This is causing problems when the infrastructure team remotely installs new sof...
[ { "answer_id": 168323, "author": "Joel Coehoorn", "author_id": 3043, "author_profile": "https://Stackoverflow.com/users/3043", "pm_score": 0, "selected": false, "text": "<p>Normally a .Net app would respond correctly- at least, that's the 'out of the box' behavior. If it's not, there co...
2008/10/03
[ "https://Stackoverflow.com/questions/168317", "https://Stackoverflow.com", "https://Stackoverflow.com/users/24179/" ]
We have a SmartClient built in C# that stubornly remains open when the PC its running on is being restarted. This halts the restart process unless the user first closes the SmartClient or there is some other manual intervention. This is causing problems when the infrastructure team remotely installs new software that ...
OK, if you have access to the app, you can handle the SessionEnded event. ``` ... Microsoft.Win32.SystemEvents.SessionEnded +=new Microsoft.Win32.SessionEndedEventHandler(shutdownHandler); ... private void shutdownHandler(object sender, Microsoft.Win32.SessionEndedEventArgs e) { // Do stuff } ```
168,349
<p>I have a bunch of regression test data. Each test is just a list of messages (associative arrays), mapping message field names to values. There's a lot of repetition within this data.</p> <p>For example</p> <pre><code> test1 = [ { sender =&gt; 'client', msg =&gt; '123', arg =&gt; '900', foo =&gt; 'bar'...
[ { "answer_id": 170086, "author": "finnw", "author_id": 12048, "author_profile": "https://Stackoverflow.com/users/12048", "pm_score": 1, "selected": false, "text": "<p>This looks very similar to <a href=\"http://en.wikipedia.org/wiki/Database_normalization\" rel=\"nofollow noreferrer\">Da...
2008/10/03
[ "https://Stackoverflow.com/questions/168349", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4540/" ]
I have a bunch of regression test data. Each test is just a list of messages (associative arrays), mapping message field names to values. There's a lot of repetition within this data. For example ``` test1 = [ { sender => 'client', msg => '123', arg => '900', foo => 'bar', ... }, { sender => 'server'...
The following papers describe algortithms for discovering functional dependencies: > > Y. Huhtala, J. Kärkkäinen, P. Porkka, > and H. Toivonen. TANE: An efficient > algorithm for discovering functional > and approximate dependencies. *The > Computer Journal*, 42(2):100–111, > 1999, [doi:10.1093/comjnl/42.2.100]...
168,402
<p>I have run across an XML Schema with the following definition:</p> <pre><code>&lt;xs:simpleType name="ClassRankType"&gt; &lt;xs:restriction base="xs:integer"&gt; &lt;xs:totalDigits value="4"/&gt; &lt;xs:minInclusive value="1"/&gt; &lt;xs:maxInclusive value="9999"/&gt; &lt;/xs:restric...
[ { "answer_id": 168466, "author": "ConroyP", "author_id": 2287, "author_profile": "https://Stackoverflow.com/users/2287", "pm_score": 4, "selected": true, "text": "<blockquote>\n <p>can totalDigits always be represented with a combination of minInclusive and MaxInclusive?</p>\n</blockquo...
2008/10/03
[ "https://Stackoverflow.com/questions/168402", "https://Stackoverflow.com", "https://Stackoverflow.com/users/24954/" ]
I have run across an XML Schema with the following definition: ``` <xs:simpleType name="ClassRankType"> <xs:restriction base="xs:integer"> <xs:totalDigits value="4"/> <xs:minInclusive value="1"/> <xs:maxInclusive value="9999"/> </xs:restriction> </xs:simpleType> ``` However, it seems ...
> > can totalDigits always be represented with a combination of minInclusive and MaxInclusive? > > > In this case, yes. As you're dealing with an integer, the value must be a whole number, so you have a finite set of values between `minInclusive` and `maxInclusive`. If you had decimal values, `totalDigits` would t...
168,408
<p>It looks like I had a fundamental misunderstanding about C++ :&lt;</p> <p>I like the polymorphic container solution. Thank you SO, for bringing that to my attention :)</p> <hr> <p>So, we have a need to create a relatively generic container type object. It also happens to encapsulate some business related logic. H...
[ { "answer_id": 168442, "author": "Lev", "author_id": 7224, "author_profile": "https://Stackoverflow.com/users/7224", "pm_score": 3, "selected": false, "text": "<p>Polymorphism and templates do play very well together, if you use them correctly.</p>\n\n<p>Anyway, I understand that you wan...
2008/10/03
[ "https://Stackoverflow.com/questions/168408", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14621/" ]
It looks like I had a fundamental misunderstanding about C++ :< I like the polymorphic container solution. Thank you SO, for bringing that to my attention :) --- So, we have a need to create a relatively generic container type object. It also happens to encapsulate some business related logic. However, we need to st...
Can you not have a root Container class that contains elements: ``` template <typename T> class Container { public: // You'll likely want to use shared_ptr<T> instead. virtual void push(T *element) = 0; virtual T *pop() = 0; virtual void InvokeSomeMethodOnAllItems() = 0; }; template <typename T> class L...
168,409
<p>What is the best way to get a list of all files in a directory, sorted by date [created | modified], using python, on a windows machine?</p>
[ { "answer_id": 168424, "author": "Jay", "author_id": 20840, "author_profile": "https://Stackoverflow.com/users/20840", "pm_score": 8, "selected": false, "text": "<p>I've done this in the past for a Python script to determine the last updated files in a directory: </p>\n\n<pre><code>impor...
2008/10/03
[ "https://Stackoverflow.com/questions/168409", "https://Stackoverflow.com", "https://Stackoverflow.com/users/24953/" ]
What is the best way to get a list of all files in a directory, sorted by date [created | modified], using python, on a windows machine?
*Update*: to sort `dirpath`'s entries by modification date in Python 3: ``` import os from pathlib import Path paths = sorted(Path(dirpath).iterdir(), key=os.path.getmtime) ``` (put [@Pygirl's answer](https://stackoverflow.com/a/58772122/4279) here for greater visibility) If you already have a list of filenames `f...
168,415
<p>For my current project, I need to request XML data over a tcp/ip socket connection. For this, I am using the TcpClient class:</p> <pre><code>Dim client As New TcpClient() client.Connect(server, port) Dim stream As NetworkStream = client.GetStream() stream.Write(request) stream.Read(buffer, 0, buffer.length) // O...
[ { "answer_id": 168418, "author": "Sunny Milenov", "author_id": 8220, "author_profile": "https://Stackoverflow.com/users/8220", "pm_score": 3, "selected": true, "text": "<p>You create a loop for reading.</p>\n\n<p>Stream.Read returns int for the bytes it read so far, or 0 if the end of st...
2008/10/03
[ "https://Stackoverflow.com/questions/168415", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1574/" ]
For my current project, I need to request XML data over a tcp/ip socket connection. For this, I am using the TcpClient class: ``` Dim client As New TcpClient() client.Connect(server, port) Dim stream As NetworkStream = client.GetStream() stream.Write(request) stream.Read(buffer, 0, buffer.length) // Output buffer an...
You create a loop for reading. Stream.Read returns int for the bytes it read so far, or 0 if the end of stream is reached. So, its like: ``` int bytes_read = 0; while (bytes_read < buffer.Length) bytes_read += stream.Read(buffer, bytes_read, buffer.length - bytes_read); ``` EDIT: now, the question is how you de...
168,423
<p>I have a personal wiki that I take notes on. The wiki's pages are in a subversion working copy directory, "pages", and I set their permissions to 664, owned by www-data:www-data. My username is in the "www-data" group, so I can checkin and mess with the pages manually.</p> <p>For a while, I had an issue because e...
[ { "answer_id": 178038, "author": "Isak Savo", "author_id": 8521, "author_profile": "https://Stackoverflow.com/users/8521", "pm_score": 2, "selected": false, "text": "<p>I think you are using it wrong. What you could do is still have everything in subversion and have your local working co...
2008/10/03
[ "https://Stackoverflow.com/questions/168423", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16034/" ]
I have a personal wiki that I take notes on. The wiki's pages are in a subversion working copy directory, "pages", and I set their permissions to 664, owned by www-data:www-data. My username is in the "www-data" group, so I can checkin and mess with the pages manually. For a while, I had an issue because every time I ...
Set the "sticky" permissions bit. ``` find -type d -exec chgrp www-data {} + find -type d -exec chmod g+s {} + ``` this will encourage checkout's file creation phase to inherit the directories permissions instead of switching to the person whom last edited it. **Edit**: dow +s == setgid. Information left here f...
168,455
<p>How do you post data to an iframe?</p>
[ { "answer_id": 168488, "author": "Dylan Beattie", "author_id": 5017, "author_profile": "https://Stackoverflow.com/users/5017", "pm_score": 10, "selected": true, "text": "<p>Depends what you mean by \"post data\". You can use the HTML <code>target=\"\"</code> attribute on a <code>&lt;form...
2008/10/03
[ "https://Stackoverflow.com/questions/168455", "https://Stackoverflow.com", "https://Stackoverflow.com/users/24958/" ]
How do you post data to an iframe?
Depends what you mean by "post data". You can use the HTML `target=""` attribute on a `<form />` tag, so it could be as simple as: ``` <form action="do_stuff.aspx" method="post" target="my_iframe"> <input type="submit" value="Do Stuff!"> </form> <!-- when the form is submitted, the server response will appear in th...
168,464
<p>Since <em>length</em> is a JavaScript property, does it matter whether I use</p> <pre><code>for( var i = 0; i &lt; myArray.length; i++ ) </code></pre> <p>OR</p> <pre><code>var myArrayLength = myArray.length; for( var i = 0; i &lt; myArrayLength ; i++ ) </code></pre> <p>­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­<...
[ { "answer_id": 168473, "author": "Grant Wagner", "author_id": 9254, "author_profile": "https://Stackoverflow.com/users/9254", "pm_score": 3, "selected": false, "text": "<pre><code>for(var i = 0, iLen = myArray.length; i &lt; iLen; i++)\n</code></pre>\n\n<p>See <a href=\"http://blogs.orac...
2008/10/03
[ "https://Stackoverflow.com/questions/168464", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
Since *length* is a JavaScript property, does it matter whether I use ``` for( var i = 0; i < myArray.length; i++ ) ``` OR ``` var myArrayLength = myArray.length; for( var i = 0; i < myArrayLength ; i++ ) ``` ­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­­
``` for(var i = 0, iLen = myArray.length; i < iLen; i++) ``` See <http://blogs.oracle.com/greimer/resource/loop-test.html> for benchmarks of various Javascript loop constructs.
168,486
<p>For my customer I occasionally do work in their live database in order to fix a problem they have created for themselves, or in order to fix bad data that my product's bugs created. Much like Unix root access, it's just dangerous. What lessons should I learn ahead of time?</p> <p>What is the #1 thing you do to be...
[ { "answer_id": 168494, "author": "Bob King", "author_id": 6897, "author_profile": "https://Stackoverflow.com/users/6897", "pm_score": 5, "selected": false, "text": "<p>Make your changes to a copy, and when you're satisfied, then apply the fix to live.</p>\n" }, { "answer_id": 168...
2008/10/03
[ "https://Stackoverflow.com/questions/168486", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10906/" ]
For my customer I occasionally do work in their live database in order to fix a problem they have created for themselves, or in order to fix bad data that my product's bugs created. Much like Unix root access, it's just dangerous. What lessons should I learn ahead of time? What is the #1 thing you do to be careful abo...
Three things I've learned the hard way over the years... First, if you're doing updates or deletes on live data, first write a SELECT query with the WHERE clause you'll be using. Make sure it works. Make sure it's correct. Then prepend the UPDATE/DELETE statement to the known working WHERE clause. You never want to h...
168,487
<p>How do I solve the error:</p> <blockquote> <p>Unable to read WSDL from URL: <a href="https://workflowtest.site.edu/_vti_bin/Lists.asmx?WSDL" rel="nofollow noreferrer">https://workflowtest.site.edu/_vti_bin/Lists.asmx?WSDL</a>.<br> Error: 401 Unauthorized.</p> </blockquote> <p>I can successfully view the WSDL f...
[ { "answer_id": 168806, "author": "Ryan", "author_id": 20198, "author_profile": "https://Stackoverflow.com/users/20198", "pm_score": 1, "selected": false, "text": "<p>I know nothing about ColdFusion but I my first suspect would be a simple permision problem rather than anything CF specifi...
2008/10/03
[ "https://Stackoverflow.com/questions/168487", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5849/" ]
How do I solve the error: > > Unable to read WSDL from URL: <https://workflowtest.site.edu/_vti_bin/Lists.asmx?WSDL>. > > Error: 401 Unauthorized. > > > I can successfully view the WSDL from the browser using the same user account. I'm not sure which authentication is being used (Basic or Integrated). How wo...
CFInvoke can only pass basic authentication, not windows integrated authentication. Sharepoint won't be able to downgrade to basic authentication since sharepoint needs to know who is calling the services to check authentication and authorization of the data being requested. Your best bet here is to create an asp.ne...
168,528
<p>I know I can get this to technically work but I'd like to implement the cleanest possible solution. Here's the situation:</p> <p>I have a managed library which wraps an unmanaged C-style library. The C-style library functionality I'm currently wrapping does some processing involving a list of strings. The librar...
[ { "answer_id": 168598, "author": "Lou Franco", "author_id": 3937, "author_profile": "https://Stackoverflow.com/users/3937", "pm_score": 2, "selected": false, "text": "<p>.NET can auto-convert the delegate to a pointer to function if it is declared right. There are two caveats</p>\n\n<ol...
2008/10/03
[ "https://Stackoverflow.com/questions/168528", "https://Stackoverflow.com", "https://Stackoverflow.com/users/24965/" ]
I know I can get this to technically work but I'd like to implement the cleanest possible solution. Here's the situation: I have a managed library which wraps an unmanaged C-style library. The C-style library functionality I'm currently wrapping does some processing involving a list of strings. The library's client co...
.NET can auto-convert the delegate to a pointer to function if it is declared right. There are two caveats 1. The C function must be built STDCALL 2. The pointer to function does not count as a reference to the object, so you must arrange for a reference to be kept so that the underlying object is not Garbage collecte...
168,531
<p>I have a very large file that looks like this (see below). I have two basic choices of regex to use on it (I know there may be others but I'm really trying to compare Greedy and Negated Char Class) methods.</p> <pre><code>ftp: [^\D]{1,} ftp: (\d)+ ftp: \d+ </code></pre> <p><strong><em>Note: what if I took off the...
[ { "answer_id": 168551, "author": "Jay", "author_id": 20840, "author_profile": "https://Stackoverflow.com/users/20840", "pm_score": 0, "selected": false, "text": "<p>Not a direct answer to the question, but why not a different approach altogether, since you know the format of the lines al...
2008/10/03
[ "https://Stackoverflow.com/questions/168531", "https://Stackoverflow.com", "https://Stackoverflow.com/users/730/" ]
I have a very large file that looks like this (see below). I have two basic choices of regex to use on it (I know there may be others but I'm really trying to compare Greedy and Negated Char Class) methods. ``` ftp: [^\D]{1,} ftp: (\d)+ ftp: \d+ ``` ***Note: what if I took off the parense around the \d?*** Now + is...
Both your expressions have the same greediness. As others have said here, except for the capturing group they will execute in the same way. Also in this case greediness won't matter much at the execution speed since you don't have anything following \d\*. In this case the expression will simply process all the digits...
168,550
<p>How can I display a tooltip over a button using <a href="http://en.wikipedia.org/wiki/Windows_Forms" rel="noreferrer">Windows Forms</a>?</p>
[ { "answer_id": 168555, "author": "Fry", "author_id": 23553, "author_profile": "https://Stackoverflow.com/users/23553", "pm_score": -1, "selected": false, "text": "<p>Sure, just handle the mousehover event and tell it to display a tool tip.\nt is a tooltip defined either in the globals or...
2008/10/03
[ "https://Stackoverflow.com/questions/168550", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
How can I display a tooltip over a button using [Windows Forms](http://en.wikipedia.org/wiki/Windows_Forms)?
The ToolTip is a **single** WinForms control that handles displaying tool tips for **multiple** elements on a single form. Say your button is called MyButton. 1. Add a ToolTip control (under Common Controls in the Windows Forms toolbox) to your form. 2. Give it a name - say MyToolTip 3. Set the "Tooltip on MyToolTip"...
168,559
<p><a href="http://www.python.org/doc/2.5.2/lib/module-tempfile.html" rel="noreferrer">tempfile.mkstemp()</a> returns:</p> <blockquote> <p>a tuple containing an OS-level handle to an open file (as would be returned by os.open()) and the absolute pathname of that file, in that order.</p> </blockquote> <p>How do I co...
[ { "answer_id": 168584, "author": "Peter Hoffmann", "author_id": 720, "author_profile": "https://Stackoverflow.com/users/720", "pm_score": 7, "selected": true, "text": "<p>You can use </p>\n\n<pre><code>os.write(tup[0], \"foo\\n\")\n</code></pre>\n\n<p>to write to the handle.</p>\n\n<p>If...
2008/10/03
[ "https://Stackoverflow.com/questions/168559", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4766/" ]
[tempfile.mkstemp()](http://www.python.org/doc/2.5.2/lib/module-tempfile.html) returns: > > a tuple containing an OS-level handle to an open file (as would be returned by os.open()) and the absolute pathname of that file, in that order. > > > How do I convert that OS-level handle to a file object? The [documenta...
You can use ``` os.write(tup[0], "foo\n") ``` to write to the handle. If you want to open the handle for writing you need to add the **"w"** mode ``` f = os.fdopen(tup[0], "w") f.write("foo") ```
168,560
<p>What is the best way to perform a couple of tasks together and if one task fails then the next tasks should not be completed? I know if it were the database operations then I should have used Transactions but I am talking about different types of operations like the following: </p> <p>All tasks must pass: </p> <p>...
[ { "answer_id": 168567, "author": "Echostorm", "author_id": 12862, "author_profile": "https://Stackoverflow.com/users/12862", "pm_score": 2, "selected": false, "text": "<p>in C#</p>\n\n<p>return SendEmail() &amp;&amp; ArchiveResportsInDatabase() &amp;&amp; CreateAFile();</p>\n" }, { ...
2008/10/03
[ "https://Stackoverflow.com/questions/168560", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3797/" ]
What is the best way to perform a couple of tasks together and if one task fails then the next tasks should not be completed? I know if it were the database operations then I should have used Transactions but I am talking about different types of operations like the following: All tasks must pass: SendEmail Archive...
Exceptions are generally good for this sort of thing. Pseudo-Java/JavaScript/C++ code: ``` try { if (!SendEmail()) { throw "Could not send e-mail"; } if (!ArchiveReportsInDatabase()) { throw "Could not archive reports in database"; } if (!CreateAFile()) { throw "Could not ...
168,589
<p>I can do this:</p> <pre><code>$ find . . ./b ./b/foo ./c ./c/foo </code></pre> <p>And this:</p> <pre><code>$ find . -type f -exec cat {} \; This is in b. This is in c. </code></pre> <p>But not this:</p> <pre><code>$ find . -type f -exec cat &gt; out.txt {} \; </code></pre> <p>Why not?</p>
[ { "answer_id": 168595, "author": "Commodore Jaeger", "author_id": 4659, "author_profile": "https://Stackoverflow.com/users/4659", "pm_score": 6, "selected": true, "text": "<p>find's -exec argument runs the command you specify once for each file it finds. Try:</p>\n\n<pre><code>$ find . -...
2008/10/03
[ "https://Stackoverflow.com/questions/168589", "https://Stackoverflow.com", "https://Stackoverflow.com/users/22917/" ]
I can do this: ``` $ find . . ./b ./b/foo ./c ./c/foo ``` And this: ``` $ find . -type f -exec cat {} \; This is in b. This is in c. ``` But not this: ``` $ find . -type f -exec cat > out.txt {} \; ``` Why not?
find's -exec argument runs the command you specify once for each file it finds. Try: ``` $ find . -type f -exec cat {} \; > out.txt ``` or: ``` $ find . -type f | xargs cat > out.txt ``` xargs converts its standard input into command-line arguments for the command you specify. If you're worried about embedded spa...
168,594
<p>I am creating some build scripts that interact with Perforce and I would like to mark for delete a few files. What exactly is the P4 syntax using the command line?</p>
[ { "answer_id": 168614, "author": "JR Lawhorne", "author_id": 22917, "author_profile": "https://Stackoverflow.com/users/22917", "pm_score": 4, "selected": true, "text": "<pre><code>p4 delete filename\n</code></pre>\n\n<p>(output of p4 help delete)</p>\n\n<p>delete -- Open an existing file...
2008/10/03
[ "https://Stackoverflow.com/questions/168594", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4872/" ]
I am creating some build scripts that interact with Perforce and I would like to mark for delete a few files. What exactly is the P4 syntax using the command line?
``` p4 delete filename ``` (output of p4 help delete) delete -- Open an existing file to delete it from the depot p4 delete [ -c changelist# ] [ -n ] file ... ``` Opens a file that currently exists in the depot for deletion. If the file is present on the client it is removed. If a pending changelist number is giv...
168,596
<p>When an Event is triggered by a user in IE, it is set to the <code>window.event</code> object. The only way to see what triggered the event is by accessing the <code>window.event</code> object (as far as I know)</p> <p>This causes a problem in ASP.NET validators if an event is triggered programmatically, like when ...
[ { "answer_id": 169370, "author": "Lucas Goodwin", "author_id": 25025, "author_profile": "https://Stackoverflow.com/users/25025", "pm_score": 2, "selected": false, "text": "<p>From what you're describing, this problem is likely a result of the unique event bubbling model that IE uses for ...
2008/10/03
[ "https://Stackoverflow.com/questions/168596", "https://Stackoverflow.com", "https://Stackoverflow.com/users/392/" ]
When an Event is triggered by a user in IE, it is set to the `window.event` object. The only way to see what triggered the event is by accessing the `window.event` object (as far as I know) This causes a problem in ASP.NET validators if an event is triggered programmatically, like when triggering an event through jQue...
I had the same problem. Solved by using this function: ``` jQuery.fn.extend({ fire: function(evttype){ el = this.get(0); if (document.createEvent) { var evt = document.createEvent('HTMLEvents'); evt.initEvent(evttype, false, false); el.dispatchEvent(evt); ...
168,621
<p>I'm having trouble with my php code not indenting correctly...</p> <p>I would like my code to look like this</p> <pre><code>if (foo) { print "i am indented"; } </code></pre> <p>but it always looks like this:</p> <pre><code>if (foo) { print "i am not indented correctly"; } </code></pre> <p>I tired go...
[ { "answer_id": 168696, "author": "Jonathan Arkell", "author_id": 11052, "author_profile": "https://Stackoverflow.com/users/11052", "pm_score": 1, "selected": false, "text": "<p>Customize the variable c-default-style. You either want your \"Other\" mode (or \"php\" if its available) set ...
2008/10/03
[ "https://Stackoverflow.com/questions/168621", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I'm having trouble with my php code not indenting correctly... I would like my code to look like this ``` if (foo) { print "i am indented"; } ``` but it always looks like this: ``` if (foo) { print "i am not indented correctly"; } ``` I tired googling for similar things and tried adding the following...
Customize c-default-style variable. Add this to your .emacs file: ``` (setq c-default-style "bsd" c-basic-offset 4) ``` [Description of bsd style](http://en.wikipedia.org/wiki/Indent_style#Allman_style).
168,639
<p>In Java, suppose I have a String variable S, and I want to search for it inside of another String T, like so:</p> <pre><code> if (T.matches(S)) ... </code></pre> <p>(note: the above line was T.contains() until a few posts pointed out that that method does not use regexes. My bad.)</p> <p>But now suppose S may ...
[ { "answer_id": 168642, "author": "Jay", "author_id": 20840, "author_profile": "https://Stackoverflow.com/users/20840", "pm_score": 2, "selected": false, "text": "<p>Any particular reason not to use String.indexOf() instead? That way it will always be interpreted as a regular string rathe...
2008/10/03
[ "https://Stackoverflow.com/questions/168639", "https://Stackoverflow.com", "https://Stackoverflow.com/users/24973/" ]
In Java, suppose I have a String variable S, and I want to search for it inside of another String T, like so: ``` if (T.matches(S)) ... ``` (note: the above line was T.contains() until a few posts pointed out that that method does not use regexes. My bad.) But now suppose S may have unsavory characters in it. Fo...
String.contains does not use regex, so there isn't a problem in this case. Where a regex is required, rather rejecting strings with regex special characters, use java.util.regex.Pattern.quote to escape them.
168,659
<p>I found this via google: <a href="http://www.mvps.org/access/api/api0008.htm" rel="nofollow noreferrer">http://www.mvps.org/access/api/api0008.htm</a></p> <pre class="lang-vb prettyprint-override"><code>'******************** Code Start ************************** ' This code was originally written by Dev Ashish. ' I...
[ { "answer_id": 168666, "author": "Ken", "author_id": 20621, "author_profile": "https://Stackoverflow.com/users/20621", "pm_score": 4, "selected": true, "text": "<p>You could also use Environ$ but the method specified by the question is better. Users/Applications can change the environme...
2008/10/03
[ "https://Stackoverflow.com/questions/168659", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2462/" ]
I found this via google: <http://www.mvps.org/access/api/api0008.htm> ```vb '******************** Code Start ************************** ' This code was originally written by Dev Ashish. ' It is not to be altered or distributed, ' except as part of an application. ' You are free to use it in any application, ' provided...
You could also use Environ$ but the method specified by the question is better. Users/Applications can change the environment variables.
168,661
<p>I have a table with one column and about ten rows. The first column has rows with text as row headers, "header 1", "header 2". The second column contains fields for the user to type data (<em>textboxes</em> and <em>checkboxes</em>). </p> <p>I want to have a button at the top labelled "<em>Add New...</em>", and h...
[ { "answer_id": 168670, "author": "Tom Ritter", "author_id": 8435, "author_profile": "https://Stackoverflow.com/users/8435", "pm_score": 2, "selected": false, "text": "<p>Something along the lines of</p>\n\n<blockquote>\n<pre><code>function(table)\n{\n for(var i=0;i&lt;table.rows.length;...
2008/10/03
[ "https://Stackoverflow.com/questions/168661", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I have a table with one column and about ten rows. The first column has rows with text as row headers, "header 1", "header 2". The second column contains fields for the user to type data (*textboxes* and *checkboxes*). I want to have a button at the top labelled "*Add New...*", and have it create a third column, with...
Something along the lines of > > > ``` > function(table) > { > for(var i=0;i<table.rows.length;i++) > { > newcell = table.rows[i].cells[0].cloneNode(true); > table.rows[i].appendChild(newcell); > } > } > > ``` > >
168,664
<p>Given a table or a temp table, I'd like to run a procedure that will output a SQL script (i.e. a bunch of INSERT statements) that would populate the table. Is this possible in MS SQL Server 2000?</p>
[ { "answer_id": 168670, "author": "Tom Ritter", "author_id": 8435, "author_profile": "https://Stackoverflow.com/users/8435", "pm_score": 2, "selected": false, "text": "<p>Something along the lines of</p>\n\n<blockquote>\n<pre><code>function(table)\n{\n for(var i=0;i&lt;table.rows.length;...
2008/10/03
[ "https://Stackoverflow.com/questions/168664", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17997/" ]
Given a table or a temp table, I'd like to run a procedure that will output a SQL script (i.e. a bunch of INSERT statements) that would populate the table. Is this possible in MS SQL Server 2000?
Something along the lines of > > > ``` > function(table) > { > for(var i=0;i<table.rows.length;i++) > { > newcell = table.rows[i].cells[0].cloneNode(true); > table.rows[i].appendChild(newcell); > } > } > > ``` > >
168,672
<p>I have a table on SQL2000 with a numeric column and I need the select to return a 01, 02, 03...</p> <p>It currently returns 1,2,3,...10,11...</p> <p>Thanks.</p>
[ { "answer_id": 168689, "author": "John Millikin", "author_id": 3560, "author_profile": "https://Stackoverflow.com/users/3560", "pm_score": 4, "selected": true, "text": "<p>Does this work?</p>\n\n<pre><code>SELECT REPLACE(STR(mycolumn, 2), ' ', '0')\n</code></pre>\n\n<p>From <a href=\"htt...
2008/10/03
[ "https://Stackoverflow.com/questions/168672", "https://Stackoverflow.com", "https://Stackoverflow.com/users/212/" ]
I have a table on SQL2000 with a numeric column and I need the select to return a 01, 02, 03... It currently returns 1,2,3,...10,11... Thanks.
Does this work? ``` SELECT REPLACE(STR(mycolumn, 2), ' ', '0') ``` From <http://foxtricks.blogspot.com/2007/07/zero-padding-numeric-value-in-transact.html>
168,691
<p>If I'm deep in a nest of loops I'm wondering which of these is more efficient:</p> <pre><code>if (!isset($array[$key])) $array[$key] = $val; </code></pre> <p>or</p> <pre><code>$array[$key] = $val; </code></pre> <p>The second form is much more desirable as far as readable code goes. In reality the names are longe...
[ { "answer_id": 168698, "author": "warren", "author_id": 4418, "author_profile": "https://Stackoverflow.com/users/4418", "pm_score": 1, "selected": false, "text": "<p>The overhead of a comparison which may or may not be true seems like it should take longer.</p>\n\n<p>What does running th...
2008/10/03
[ "https://Stackoverflow.com/questions/168691", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8722/" ]
If I'm deep in a nest of loops I'm wondering which of these is more efficient: ``` if (!isset($array[$key])) $array[$key] = $val; ``` or ``` $array[$key] = $val; ``` The second form is much more desirable as far as readable code goes. In reality the names are longer and the array is multidimensional. So the first...
For an array you actually want: `array_key_exists($key, $array)` instead of `isset($array[$key])`.
168,727
<p>A lot of useful features in Python are somewhat "hidden" inside modules. Named tuples (new in <a href="http://docs.python.org/whatsnew/2.6.html" rel="nofollow noreferrer">Python 2.6</a>), for instance, are found in the <a href="http://docs.python.org/library/collections.html" rel="nofollow noreferrer">collections</a...
[ { "answer_id": 168766, "author": "David Segonds", "author_id": 13673, "author_profile": "https://Stackoverflow.com/users/13673", "pm_score": 3, "selected": false, "text": "<p>May be <a href=\"http://www.python.org/dev/peps/pep-0361/\" rel=\"nofollow noreferrer\">PEP 0631</a> and <a href=...
2008/10/03
[ "https://Stackoverflow.com/questions/168727", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8669/" ]
A lot of useful features in Python are somewhat "hidden" inside modules. Named tuples (new in [Python 2.6](http://docs.python.org/whatsnew/2.6.html)), for instance, are found in the [collections](http://docs.python.org/library/collections.html) module. The [Library Documentation page](http://docs.python.org/library/)...
**Essential Libraries** The main challenge for an experienced programmer coming from another language to Python is figuring out how one language maps to another. Here are a few essential libraries and how they relate to Java equivalents. ``` os, os.path ``` Has functionality like in java.io.File, java.lang.Process...
168,736
<p>How do you set a default value for a MySQL Datetime column?</p> <p>In SQL Server it's <code>getdate()</code>. What is the equivalant for MySQL? I'm using MySQL 5.x if that is a factor.</p>
[ { "answer_id": 168763, "author": "KernelM", "author_id": 22328, "author_profile": "https://Stackoverflow.com/users/22328", "pm_score": 4, "selected": false, "text": "<p>You can use now() to set the value of a datetime column, but keep in mind that you can't use that as a default value.</...
2008/10/03
[ "https://Stackoverflow.com/questions/168736", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3747/" ]
How do you set a default value for a MySQL Datetime column? In SQL Server it's `getdate()`. What is the equivalant for MySQL? I'm using MySQL 5.x if that is a factor.
**IMPORTANT EDIT:** It is now possible to achieve this with DATETIME fields since **MySQL 5.6.5**, take a look at the [other post](https://stackoverflow.com/a/10603198/24820) below... Previous versions can't do that with DATETIME... But you can do it with TIMESTAMP: ``` mysql> create table test (str varchar(32), ts ...
168,738
<p>I am building the diagram component in JavaScript. It has two layers rendered separately: foreground and background.</p> <p>To determine the required size of the background:</p> <ol> <li>render the foreground </li> <li>measure the height of the result</li> <li>render the foreground and the background together</li...
[ { "answer_id": 168767, "author": "Dan", "author_id": 17121, "author_profile": "https://Stackoverflow.com/users/17121", "pm_score": 2, "selected": false, "text": "<p>You should never, ever rely on something you just inserted into the DOM being rendered by the next line of code. All browse...
2008/10/03
[ "https://Stackoverflow.com/questions/168738", "https://Stackoverflow.com", "https://Stackoverflow.com/users/24451/" ]
I am building the diagram component in JavaScript. It has two layers rendered separately: foreground and background. To determine the required size of the background: 1. render the foreground 2. measure the height of the result 3. render the foreground and the background together In code it looks like this: ``` var...
You should never, ever rely on something you just inserted into the DOM being rendered by the next line of code. All browsers will group these changes together to some degree, and it can be tricky to work out when and why. The best way to deal with it is to execute the second part in response to some kind of event. Th...
168,798
<p>I've exposed several web services in our product using Java and WS-Security. One of our customers wants to consume the web service using ColdFusion. Does ColdFusion support WS-Security? Can I get around it by writing a Java client and using that in ColdFusion?</p> <p>(I don't know much about ColdFusion).</p>
[ { "answer_id": 168981, "author": "Peter Boughton", "author_id": 9360, "author_profile": "https://Stackoverflow.com/users/9360", "pm_score": 1, "selected": false, "text": "<p>I've never done any ws-security, and don't know if ColdFusion can consume it or not, but to answer your secondary ...
2008/10/03
[ "https://Stackoverflow.com/questions/168798", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1310/" ]
I've exposed several web services in our product using Java and WS-Security. One of our customers wants to consume the web service using ColdFusion. Does ColdFusion support WS-Security? Can I get around it by writing a Java client and using that in ColdFusion? (I don't know much about ColdFusion).
I'm assuming you mean you need to pass the security in as part of the SOAP header. Here's a sample on how to connect to a .Net service. Same approach should apply w/ Java, just the url's would be different. ``` <cfset local.soapHeader = xmlNew()> <cfset local.soapHeader.TheSoapHeader = xmlElemNew(local.soapHeader, "ht...
168,838
<p>I am trying to visualize some values on a form. They range from 0 to 200 and I would like the ones around 0 be green and turn bright red as they go to 200. </p> <p>Basically the function should return color based on the value inputted. Any ideas ?</p>
[ { "answer_id": 168846, "author": "Peter Parker", "author_id": 23264, "author_profile": "https://Stackoverflow.com/users/23264", "pm_score": 3, "selected": false, "text": "<pre><code>red = (float)val / 200 * 255;\n\ngreen = (float)(200 - val) / 200 * 255;\n\nblue = 0;\n\nreturn red &lt;&l...
2008/10/03
[ "https://Stackoverflow.com/questions/168838", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4694/" ]
I am trying to visualize some values on a form. They range from 0 to 200 and I would like the ones around 0 be green and turn bright red as they go to 200. Basically the function should return color based on the value inputted. Any ideas ?
Basically, the general method for smooth transition between two values is the following function: ``` function transition(value, maximum, start_point, end_point): return start_point + (end_point - start_point)*value/maximum ``` That given, you define a function that does the transition for triplets (RGB, HSV etc...
168,886
<p>I'm looking for a homegrown way to scramble production data for use in development and test. I've built a couple of scripts that make random social security numbers, shift birth dates, scramble emails, etc. But I've come up against a wall trying to scramble customer names. I want to keep real names so we can stil...
[ { "answer_id": 168896, "author": "warren", "author_id": 4418, "author_profile": "https://Stackoverflow.com/users/4418", "pm_score": 2, "selected": false, "text": "<p>A very simple solution would be to ROT13 the text.</p>\n\n<p>A better question may be why you feel the need to scramble th...
2008/10/03
[ "https://Stackoverflow.com/questions/168886", "https://Stackoverflow.com", "https://Stackoverflow.com/users/24991/" ]
I'm looking for a homegrown way to scramble production data for use in development and test. I've built a couple of scripts that make random social security numbers, shift birth dates, scramble emails, etc. But I've come up against a wall trying to scramble customer names. I want to keep real names so we can still use ...
I use [generatedata](http://www.generatedata.com/). It is an open source php script which can generate all sorts of dummy data.
168,897
<p>Is it more performant to have a bidimensional array (<code>type[,]</code>) or an array of arrays (<code>type[][]</code>) in C#?</p> <p>Particularly for initial allocation and item access</p>
[ { "answer_id": 168969, "author": "Jeff Kotula", "author_id": 1382162, "author_profile": "https://Stackoverflow.com/users/1382162", "pm_score": 2, "selected": false, "text": "<p>I believe that [,] can allocate one contiguous chunk of memory, while [][] is N+1 chunk allocations where N is ...
2008/10/03
[ "https://Stackoverflow.com/questions/168897", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1782/" ]
Is it more performant to have a bidimensional array (`type[,]`) or an array of arrays (`type[][]`) in C#? Particularly for initial allocation and item access
Of course, if all else fails... test it! Following gives (in "Release", at the console): ``` Size 1000, Repeat 1000 int[,] set: 3460 int[,] get: 4036 (chk=1304808064) int[][] set: 2441 int[][] get: 1283 (chk=1304808064) ``` So a jagged array is quicker, at least in this test. Interesting! However, it...
168,901
<pre><code>private IEnumerable&lt;string&gt; Tables { get { yield return "Foo"; yield return "Bar"; } } </code></pre> <p>Let's say I want iterate on those and write something like processing #n of #m. </p> <p>Is there a way I can find out the value of m without iterating before my main ite...
[ { "answer_id": 168918, "author": "JesperE", "author_id": 13051, "author_profile": "https://Stackoverflow.com/users/13051", "pm_score": 3, "selected": false, "text": "<p>No, not in general. One point in using enumerables is that the actual set of objects in the enumeration is not known (i...
2008/10/03
[ "https://Stackoverflow.com/questions/168901", "https://Stackoverflow.com", "https://Stackoverflow.com/users/23893/" ]
``` private IEnumerable<string> Tables { get { yield return "Foo"; yield return "Bar"; } } ``` Let's say I want iterate on those and write something like processing #n of #m. Is there a way I can find out the value of m without iterating before my main iteration? I hope I made myself cl...
`IEnumerable` doesn't support this. This is by design. `IEnumerable` uses lazy evaluation to get the elements you ask for just before you need them. If you want to know the number of items without iterating over them you can use `ICollection<T>`, it has a `Count` property.
168,912
<p>I need to show only one element at a time when a link is clicked on. Right now I'm cheating by hiding everything again and then toggling the element clicked on. This works, unless i want EVERYTHING to disappear again. Short of adding a "Hide All" button/link what can i do? I would like to be able to click on the lin...
[ { "answer_id": 169036, "author": "micahwittman", "author_id": 11181, "author_profile": "https://Stackoverflow.com/users/11181", "pm_score": 3, "selected": true, "text": "<pre><code>$(\"#linkgarykhit\").click(function(){\n if($(\"#infogarykhit\").css('display') != 'none'){\n $(\"#i...
2008/10/03
[ "https://Stackoverflow.com/questions/168912", "https://Stackoverflow.com", "https://Stackoverflow.com/users/50/" ]
I need to show only one element at a time when a link is clicked on. Right now I'm cheating by hiding everything again and then toggling the element clicked on. This works, unless i want EVERYTHING to disappear again. Short of adding a "Hide All" button/link what can i do? I would like to be able to click on the link a...
``` $("#linkgarykhit").click(function(){ if($("#infogarykhit").css('display') != 'none'){ $("#infogarykhit").hide(); }else{ $("#infocontent *").hide(); $("#infogarykhit").show(); } return false; }); ``` --- We could also [DRY](http://en.wikipedia.org/wiki/Don%27t_repeat_yourself) this u...
168,924
<p>Let's say I've got two strings in JavaScript:</p> <pre><code>var date1 = '2008-10-03T20:24Z' var date2 = '2008-10-04T12:24Z' </code></pre> <p>How would I come to a result like so:</p> <pre><code>'4 weeks ago' </code></pre> <p>or</p> <pre><code>'in about 15 minutes' </code></pre> <p>(should support past and fut...
[ { "answer_id": 169009, "author": "moonshadow", "author_id": 11834, "author_profile": "https://Stackoverflow.com/users/11834", "pm_score": 4, "selected": true, "text": "<p>Looking at the solutions you linked... it is actually as simple as my frivolous comment!</p>\n\n<p>Here's a version o...
2008/10/03
[ "https://Stackoverflow.com/questions/168924", "https://Stackoverflow.com", "https://Stackoverflow.com/users/22468/" ]
Let's say I've got two strings in JavaScript: ``` var date1 = '2008-10-03T20:24Z' var date2 = '2008-10-04T12:24Z' ``` How would I come to a result like so: ``` '4 weeks ago' ``` or ``` 'in about 15 minutes' ``` (should support past and future). There are solutions out there for the past diffs, but I've yet to...
Looking at the solutions you linked... it is actually as simple as my frivolous comment! Here's a version of the Zach Leatherman code that prepends "In " for future dates for you. As you can see, the changes are very minor. ``` function humane_date(date_str){ var time_formats = [ [60, 'Just Now'], ...
168,926
<p>Ok, I'm using the term "Progressive Enhancement" kind of loosely here but basically I have a Flash-based website that supports deep linking and loads content dynamically - what I'd like to do is provide alternate content (text) for those either not having Flash and for search engine bots. So, for a user with flash t...
[ { "answer_id": 169009, "author": "moonshadow", "author_id": 11834, "author_profile": "https://Stackoverflow.com/users/11834", "pm_score": 4, "selected": true, "text": "<p>Looking at the solutions you linked... it is actually as simple as my frivolous comment!</p>\n\n<p>Here's a version o...
2008/10/03
[ "https://Stackoverflow.com/questions/168926", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3435/" ]
Ok, I'm using the term "Progressive Enhancement" kind of loosely here but basically I have a Flash-based website that supports deep linking and loads content dynamically - what I'd like to do is provide alternate content (text) for those either not having Flash and for search engine bots. So, for a user with flash they...
Looking at the solutions you linked... it is actually as simple as my frivolous comment! Here's a version of the Zach Leatherman code that prepends "In " for future dates for you. As you can see, the changes are very minor. ``` function humane_date(date_str){ var time_formats = [ [60, 'Just Now'], ...
168,946
<p>Here's my scenario. I created an application which uses Integrated Windows Authentication in order to work. In <code>Application_AuthenticateRequest()</code>, I use <code>HttpContext.Current.User.Identity</code> to get the current <code>WindowsPrincipal</code> of the user of my website.</p> <p>Now here's the funn...
[ { "answer_id": 168998, "author": "Nick Messick", "author_id": 24988, "author_profile": "https://Stackoverflow.com/users/24988", "pm_score": 1, "selected": false, "text": "<p>Restarting IIS, not the whole machine, should do the trick.</p>\n" }, { "answer_id": 171295, "author":...
2008/10/03
[ "https://Stackoverflow.com/questions/168946", "https://Stackoverflow.com", "https://Stackoverflow.com/users/24995/" ]
Here's my scenario. I created an application which uses Integrated Windows Authentication in order to work. In `Application_AuthenticateRequest()`, I use `HttpContext.Current.User.Identity` to get the current `WindowsPrincipal` of the user of my website. Now here's the funny part. Some of our users have recently gotte...
I've had similar issues lately and as stated in Robert MacLean's [answer](https://stackoverflow.com/questions/168946/iis-returning-old-user-names-to-my-application/581346#581346), AviD's group policy changes don't work if you're not logging in as the users. I found changing the **LSA Lookup Cache** size as described i...
168,951
<hr /> <p><strong> The <a href="http://docs.php.net/manual/en/class.httprequestpool.php" rel="noreferrer">HttpRequestPool</a> class provides a solution. Many thanks to those who pointed this out.</p> <p>A brief tutorial can be found at: <a href="http://www.phptutorial.info/?HttpRequestPool-construct" rel="noreferrer"...
[ { "answer_id": 169001, "author": "bobwienholt", "author_id": 24257, "author_profile": "https://Stackoverflow.com/users/24257", "pm_score": -1, "selected": false, "text": "<p>You could use pcntl_fork() to create a separate process for each request, then wait for them to end:</p>\n\n<p><a ...
2008/10/03
[ "https://Stackoverflow.com/questions/168951", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5343/" ]
--- **The [HttpRequestPool](http://docs.php.net/manual/en/class.httprequestpool.php) class provides a solution. Many thanks to those who pointed this out.** A brief tutorial can be found at: <http://www.phptutorial.info/?HttpRequestPool-construct> --- **Problem** I'd like to make concurrent/parallel/simultaneous H...
I'm pretty sure [HttpRequestPool](http://docs.php.net/manual/en/class.httprequestpool.php) is what you're looking for. To elaborate a little, you can use forking to achieve what you're looking for, but that seems unnecessarily complex and not very useful in a HTML context. While I haven't tested, this code should be i...
168,956
<p>I need a (php) regex to match Yahoo's username rules:</p> <blockquote> <p>Use 4 to 32 characters and start with a letter. You may use letters, numbers, underscores, and one dot (.).</p> </blockquote>
[ { "answer_id": 168965, "author": "Joel Coehoorn", "author_id": 3043, "author_profile": "https://Stackoverflow.com/users/3043", "pm_score": 2, "selected": false, "text": "<p>A one dot limit? That's tricky.</p>\n\n<p>I'm no regex expert, but I think this would get it, except for that:</p>...
2008/10/03
[ "https://Stackoverflow.com/questions/168956", "https://Stackoverflow.com", "https://Stackoverflow.com/users/24999/" ]
I need a (php) regex to match Yahoo's username rules: > > Use 4 to 32 characters and start with a letter. You may use letters, numbers, underscores, and one dot (.). > > >
``` /^[A-Za-z](?=[A-Za-z0-9_.]{3,31}$)[a-zA-Z0-9_]*\.?[a-zA-Z0-9_]*$/ ``` Or a little shorter: ``` /^[a-z](?=[\w.]{3,31}$)\w*\.?\w*$/i ```
168,961
<p>I'm trying to add the lucene sandbox contribution called <a href="http://lucene.apache.org/java/docs/lucene-sandbox/index.html#Term%20Highlighter" rel="nofollow noreferrer">term-highlighter</a> to my pom.xml. I'm not really that familiar with Maven, but the code has a <a href="http://svn.apache.org/repos/asf/lucene/...
[ { "answer_id": 168990, "author": "Sam Merrell", "author_id": 782, "author_profile": "https://Stackoverflow.com/users/782", "pm_score": 1, "selected": false, "text": "<p>You have it right, but you probably want to add the version as well:</p>\n\n<p><a href=\"http://maven.apache.org/guides...
2008/10/03
[ "https://Stackoverflow.com/questions/168961", "https://Stackoverflow.com", "https://Stackoverflow.com/users/459/" ]
I'm trying to add the lucene sandbox contribution called [term-highlighter](http://lucene.apache.org/java/docs/lucene-sandbox/index.html#Term%20Highlighter) to my pom.xml. I'm not really that familiar with Maven, but the code has a [pom.xml.template](http://svn.apache.org/repos/asf/lucene/java/trunk/contrib/highlighter...
You have to add the version number, but you only have to do it once in a project structure. That is, if the version number is defined in a parent pom, you don't have to give the version number again. (But you don't even have to provide the dependency in this case since the dependency will be inherited anyways.)
168,963
<p>I have the following code making a GET request on a URL:</p> <pre><code>$('#searchButton').click(function() { $('#inquiry').load('/portal/?f=searchBilling&amp;pid=' + $('#query').val()); }); </code></pre> <p>But the returned result is not always reflected. For example, I made a change in the respon...
[ { "answer_id": 168972, "author": "Lou Franco", "author_id": 3937, "author_profile": "https://Stackoverflow.com/users/3937", "pm_score": 5, "selected": false, "text": "<p>One way is to add a unique number to the end of the url:</p>\n\n<pre><code>$('#inquiry').load('/portal/?f=searchBillin...
2008/10/03
[ "https://Stackoverflow.com/questions/168963", "https://Stackoverflow.com", "https://Stackoverflow.com/users/204/" ]
I have the following code making a GET request on a URL: ``` $('#searchButton').click(function() { $('#inquiry').load('/portal/?f=searchBilling&pid=' + $('#query').val()); }); ``` But the returned result is not always reflected. For example, I made a change in the response that spit out a stack trace...
You have to use a more complex function like `$.ajax()` if you want to control caching on a per-request basis. Or, if you just want to turn it off for everything, put this at the top of your script: ``` $.ajaxSetup ({ // Disable caching of AJAX responses cache: false }); ```
168,992
<p>I'm trying to display a series of titles varying from 60 characters to 160 or so and the capitalization varies, some of it all caps, some half caps. When it's mostly lowercase the whole 160 characters of text fits in the width I want, but when it starts getting more caps (they must be wider), it starts over flowing...
[ { "answer_id": 168997, "author": "Zebra North", "author_id": 17440, "author_profile": "https://Stackoverflow.com/users/17440", "pm_score": 1, "selected": false, "text": "<p>You could fix the width and hide the overflow, <code>style=\"width: Xpx; overflow: hidden;\"</code></p>\n\n<p>That ...
2008/10/03
[ "https://Stackoverflow.com/questions/168992", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13009/" ]
I'm trying to display a series of titles varying from 60 characters to 160 or so and the capitalization varies, some of it all caps, some half caps. When it's mostly lowercase the whole 160 characters of text fits in the width I want, but when it starts getting more caps (they must be wider), it starts over flowing. I...
**Control the Overflow** The real trick is just setting a limit on size of the text box, and making sure that there aren't overflow problems. You can use overflow: hidden to take care of this, and display: block the element in order to give it the exact dimensions you need. **Monospace is Optional** Yes, you can use...
169,008
<p>I'm trying to write a regex that will parse out the <strong>directory and filename</strong> of a fully qualified path using matching groups.</p> <p>so...</p> <pre><code>/var/log/xyz/10032008.log </code></pre> <p>would recognize <code>group 1 to be "/var/log/xyz"</code> and <code>group 2 to be "10032008.log"</code...
[ { "answer_id": 169014, "author": "tzot", "author_id": 6899, "author_profile": "https://Stackoverflow.com/users/6899", "pm_score": 3, "selected": false, "text": "<p>What language? and why use regex for this simple task?</p>\n\n<p>If you <em>must</em>:</p>\n\n<pre><code>^(.*)/([^/]*)$\n</c...
2008/10/03
[ "https://Stackoverflow.com/questions/169008", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1247/" ]
I'm trying to write a regex that will parse out the **directory and filename** of a fully qualified path using matching groups. so... ``` /var/log/xyz/10032008.log ``` would recognize `group 1 to be "/var/log/xyz"` and `group 2 to be "10032008.log"` Seems simple but I can't get the matching groups to work for the ...
Try this: ``` ^(.+)\/([^\/]+)$ ``` EDIT: escaped the forward slash to prevent problems when copy/pasting the Regex
169,034
<p>Every time I call this method my NSMutableData is leaking and I cannot figure out how to plug it. theData's retain count is upped by one after the decoder is allocated and initialized and I have no idea why. I am stuck with a retain count of 2 at the end of the method and attempting to release it causes an app crash...
[ { "answer_id": 169247, "author": "Chris Hanson", "author_id": 714, "author_profile": "https://Stackoverflow.com/users/714", "pm_score": 2, "selected": false, "text": "<p>Don't worry about retain counts, worry about balance within a method. What you're doing in this method looks correct,...
2008/10/03
[ "https://Stackoverflow.com/questions/169034", "https://Stackoverflow.com", "https://Stackoverflow.com/users/25004/" ]
Every time I call this method my NSMutableData is leaking and I cannot figure out how to plug it. theData's retain count is upped by one after the decoder is allocated and initialized and I have no idea why. I am stuck with a retain count of 2 at the end of the method and attempting to release it causes an app crash. ...
I would suggest replacing this line: ``` venueIOList = [[decoder decodeObjectForKey:inKey] mutableCopy]; ``` with: ``` ListClassName *decodedList = [decoder decodeObjectForKey:inKey]; self.venueIOList = decodedList; ``` This makes the memory management of `decodedList` clear. It is considered best practice to ass...
169,070
<p>How do I write a decorator that restores the current working directory to what it was before the decorated function was called? In other words, if I use the decorator on a function that does an <code>os.chdir()</code>, the cwd will not be changed after the function is called.</p>
[ { "answer_id": 169079, "author": "Daryl Spitzer", "author_id": 4766, "author_profile": "https://Stackoverflow.com/users/4766", "pm_score": 2, "selected": false, "text": "<pre><code>def preserve_cwd(function):\n def decorator(*args, **kwargs):\n cwd = os.getcwd()\n result = fu...
2008/10/03
[ "https://Stackoverflow.com/questions/169070", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4766/" ]
How do I write a decorator that restores the current working directory to what it was before the decorated function was called? In other words, if I use the decorator on a function that does an `os.chdir()`, the cwd will not be changed after the function is called.
The [path.py](https://github.com/jaraco/path.py) module (which you really should use if dealing with paths in python scripts) has a context manager: ``` subdir = d / 'subdir' #subdir is a path object, in the path.py module with subdir: # here current dir is subdir #not anymore ``` (credits goes to [this blog post...
169,080
<p>I'd like to be able to toggle easily between two values for "maximum number of parallel project builds" in Visual Studio 2008 (in Tools->Options->Projects and Solutions->Build and Run). (When I'm planning on doing concurrent work I'd like to reduce it from 4 to 3.) I'm not too well versed in writing macros for the I...
[ { "answer_id": 169093, "author": "Mark Cidade", "author_id": 1659, "author_profile": "https://Stackoverflow.com/users/1659", "pm_score": 3, "selected": true, "text": "<p>It appears to be impossible, according to the MSDN page for <em><a href=\"http://msdn.microsoft.com/en-us/library/ms16...
2008/10/03
[ "https://Stackoverflow.com/questions/169080", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4790/" ]
I'd like to be able to toggle easily between two values for "maximum number of parallel project builds" in Visual Studio 2008 (in Tools->Options->Projects and Solutions->Build and Run). (When I'm planning on doing concurrent work I'd like to reduce it from 4 to 3.) I'm not too well versed in writing macros for the IDE....
It appears to be impossible, according to the MSDN page for *[Determining Names of Property Items in Tools Options Pages](http://msdn.microsoft.com/en-us/library/ms165642.aspx)* If it *was* possible, it would have been something like this: ``` Dim p = DTE.Properties("ProjectsAndSolutions","BuildAndRun") p.Item("MaxN...
169,116
<p>I have a type (System.Type) of an enum and a string containing enumeration value to set.</p> <p>E.g. given: </p> <pre><code>enum MyEnum { A, B, C }; </code></pre> <p>I have typeof(MyEnum) and "B".</p> <p>How do I create MyEnum object set to MyEnum.B?</p>
[ { "answer_id": 169120, "author": "Yuval", "author_id": 23202, "author_profile": "https://Stackoverflow.com/users/23202", "pm_score": 4, "selected": false, "text": "<pre><code>MyEnum enumValue = (MyEnum)Enum.Parse(typeof(MyEnum), \"B\");\n</code></pre>\n\n<p>You also have a case-insensiti...
2008/10/03
[ "https://Stackoverflow.com/questions/169116", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I have a type (System.Type) of an enum and a string containing enumeration value to set. E.g. given: ``` enum MyEnum { A, B, C }; ``` I have typeof(MyEnum) and "B". How do I create MyEnum object set to MyEnum.B?
``` MyEnum enumValue = (MyEnum)Enum.Parse(typeof(MyEnum), "B"); ``` You also have a case-insensitive overload.
169,146
<p>I'm getting an unexpected T_CONCAT_EQUAL error on a line of the following form:</p> <pre><code>$arg1 .= "arg2".$arg3."arg4"; </code></pre> <p>I'm using PHP5. I could simply go an do the following:</p> <pre><code>$arg1 = $arg1."arg2".$arg3."arg4"; </code></pre> <p>but I'd like to know whats going wrong in the fi...
[ { "answer_id": 169159, "author": "Paige Ruten", "author_id": 813, "author_profile": "https://Stackoverflow.com/users/813", "pm_score": 4, "selected": true, "text": "<p>This would happen when $arg1 is undefined (doesn't have a value, was never set.)</p>\n" }, { "answer_id": 169162...
2008/10/03
[ "https://Stackoverflow.com/questions/169146", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2170994/" ]
I'm getting an unexpected T\_CONCAT\_EQUAL error on a line of the following form: ``` $arg1 .= "arg2".$arg3."arg4"; ``` I'm using PHP5. I could simply go an do the following: ``` $arg1 = $arg1."arg2".$arg3."arg4"; ``` but I'd like to know whats going wrong in the first place. Any ideas? Thanks, sweeney
This would happen when $arg1 is undefined (doesn't have a value, was never set.)
169,155
<p>I am using SetCursor to set the system cursor to my own image. The code looks something like this:</p> <pre><code>// member on some class HCURSOR _cursor; // at init time _cursor = LoadCursorFromFile("somefilename.cur"); // in some function SetCursor(_cursor); </code></pre> <p>When I do this the cursor does chan...
[ { "answer_id": 169183, "author": "Mark Ransom", "author_id": 5987, "author_profile": "https://Stackoverflow.com/users/5987", "pm_score": 3, "selected": false, "text": "<p>You need to respond to the Windows message <a href=\"http://msdn.microsoft.com/en-us/library/ms648382(VS.85).aspx\" r...
2008/10/03
[ "https://Stackoverflow.com/questions/169155", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1031/" ]
I am using SetCursor to set the system cursor to my own image. The code looks something like this: ``` // member on some class HCURSOR _cursor; // at init time _cursor = LoadCursorFromFile("somefilename.cur"); // in some function SetCursor(_cursor); ``` When I do this the cursor does change, but on the first mouse...
It seems that I have two options. The first is the one that Mark Ransom suggested here, which is to respond to the windows `WM_SETCURSOR` message and call SetCursor at that time based on where the mouse is. Normally windows will only send you `WM_SETCURSOR` when the cursor is over your window, so you would only set the...
169,170
<p>I am looking for a way to do a keep alive check in .NET. The scenario is for both UDP and TCP.</p> <p>Currently in TCP what I do is that one side connects and when there is no data to send it sends a keep alive every X seconds.</p> <p>I want the other side to check for data, and if non was received in X seconds, t...
[ { "answer_id": 169209, "author": "TToni", "author_id": 20703, "author_profile": "https://Stackoverflow.com/users/20703", "pm_score": 0, "selected": false, "text": "<p>Since you cannot use the blocking (synchronous) receive, you will have to settle for the asynchronous handling. Fortunate...
2008/10/03
[ "https://Stackoverflow.com/questions/169170", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I am looking for a way to do a keep alive check in .NET. The scenario is for both UDP and TCP. Currently in TCP what I do is that one side connects and when there is no data to send it sends a keep alive every X seconds. I want the other side to check for data, and if non was received in X seconds, to raise an event ...
If you literally mean "KeepAlive", try the following. ``` public static void SetTcpKeepAlive(Socket socket, uint keepaliveTime, uint keepaliveInterval) { /* the native structure struct tcp_keepalive { ULONG onoff; ULONG keepalivetime; ULONG keepaliveinterval; }; ...
169,186
<p>I am having a very hard time finding a standard pattern / best practice that deals with rendering child controls inside a composite based on a property value.</p> <p>Here is a basic scenario. I have a Composite Control that has two child controls, a textbox and a dropdown. Lets say there is a property that toggles ...
[ { "answer_id": 169205, "author": "ckramer", "author_id": 20504, "author_profile": "https://Stackoverflow.com/users/20504", "pm_score": 0, "selected": false, "text": "<p>I would think something like:</p>\n\n<pre><code>public bool ShowDropDown\n{\n get{ return (bool)ViewState[\"ShowDrop...
2008/10/03
[ "https://Stackoverflow.com/questions/169186", "https://Stackoverflow.com", "https://Stackoverflow.com/users/25020/" ]
I am having a very hard time finding a standard pattern / best practice that deals with rendering child controls inside a composite based on a property value. Here is a basic scenario. I have a Composite Control that has two child controls, a textbox and a dropdown. Lets say there is a property that toggles which chil...
You use ViewState to store property value so that it persists between postbacks but you have to do it [correctly](http://weblogs.asp.net/infinitiesloop/archive/2006/08/03/truly-understanding-viewstate.aspx "TRULY Understanding ViewState"). ``` public virtual bool ShowDropdown { get { object o = ViewState["...
169,193
<p>There is a way to keep the scroll on bottom for a multi line textbox?</p> <p>Something like in the vb6 </p> <pre><code>txtfoo.selstart=len(txtfoo.text) </code></pre> <p>I'm trying with txtfoo.selectionstart=txtfoo.text.length without success.</p> <p>Regards.</p>
[ { "answer_id": 169210, "author": "MazarD", "author_id": 22672, "author_profile": "https://Stackoverflow.com/users/22672", "pm_score": 4, "selected": true, "text": "<p>Ok, I found that the solution was to use </p>\n\n<pre><code>txtfoo.AppendText \n</code></pre>\n\n<p>instead of </p>\n\n<p...
2008/10/03
[ "https://Stackoverflow.com/questions/169193", "https://Stackoverflow.com", "https://Stackoverflow.com/users/22672/" ]
There is a way to keep the scroll on bottom for a multi line textbox? Something like in the vb6 ``` txtfoo.selstart=len(txtfoo.text) ``` I'm trying with txtfoo.selectionstart=txtfoo.text.length without success. Regards.
Ok, I found that the solution was to use ``` txtfoo.AppendText ``` instead of ``` txtfoo.text+="something" ```
169,201
<p>In ActionScript 3.0, is there an automatic way to calculate the number of days, hours, minutes and seconds between two specified dates?</p> <p>Basicly, what I need is the ActionScript equivalent of the .NET Timespan class.</p> <p>Any idea?</p>
[ { "answer_id": 169218, "author": "Russell Myers", "author_id": 18194, "author_profile": "https://Stackoverflow.com/users/18194", "pm_score": 4, "selected": false, "text": "<p>You can covert the two date times into milliseconds since the epoch, perform your math and then use the resultant...
2008/10/03
[ "https://Stackoverflow.com/questions/169201", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1965/" ]
In ActionScript 3.0, is there an automatic way to calculate the number of days, hours, minutes and seconds between two specified dates? Basicly, what I need is the ActionScript equivalent of the .NET Timespan class. Any idea?
I created an ActionScript TimeSpan class with a similar API to System.TimeSpan to fill that void, but there are differences due to the lack of operator overloading. You can use it like so: ``` TimeSpan.fromDates(later, earlier).totalDays; ``` Below is the code for the class (sorry for the big post - I won't include ...
169,216
<p>As kind of a follow up to <a href="https://stackoverflow.com/questions/111605/what-kind-of-prefix-do-you-use-for-member-variables">this question about prefixes</a>, I agree with most people on the thread that prefixes are bad. But what about if you are using getters and setters? Then you need to differeniate the pub...
[ { "answer_id": 169238, "author": "Garry Shutler", "author_id": 6369, "author_profile": "https://Stackoverflow.com/users/6369", "pm_score": 1, "selected": false, "text": "<p>In a case sensitive language I just use:</p>\n\n<pre><code>private int myValue;\n\npublic int MyValue\n{\n get {...
2008/10/03
[ "https://Stackoverflow.com/questions/169216", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11911/" ]
As kind of a follow up to [this question about prefixes](https://stackoverflow.com/questions/111605/what-kind-of-prefix-do-you-use-for-member-variables), I agree with most people on the thread that prefixes are bad. But what about if you are using getters and setters? Then you need to differeniate the publicly accessib...
This is a completely subjective question. There is no "better" way. One way is: ``` private int _x; public get x():int { return _x; } public set x(int val):void { _x = val; } ``` Another is: ``` private int x; public get X():int { return x; } public set X(int val):void { x = val; } ``` Neither is the right answe...
169,217
<p>In SQL Server you can use the <code>IsNull()</code> function to check if a value is null, and if it is, return another value. Now I am wondering if there is anything similar in C#.</p> <p>For example, I want to do something like:</p> <pre><code>myNewValue = IsNull(myValue, new MyValue()); </code></pre> <p>instead...
[ { "answer_id": 169226, "author": "Kent Boogaart", "author_id": 5380, "author_profile": "https://Stackoverflow.com/users/5380", "pm_score": 9, "selected": true, "text": "<p>It's called the null coalescing (<code>??</code>) operator:</p>\n\n<pre><code>myNewValue = myValue ?? new MyValue();...
2008/10/03
[ "https://Stackoverflow.com/questions/169217", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11989/" ]
In SQL Server you can use the `IsNull()` function to check if a value is null, and if it is, return another value. Now I am wondering if there is anything similar in C#. For example, I want to do something like: ``` myNewValue = IsNull(myValue, new MyValue()); ``` instead of: ``` if (myValue == null) myValue = n...
It's called the null coalescing (`??`) operator: ``` myNewValue = myValue ?? new MyValue(); ```
169,220
<p>I'm used to writing classes like this:</p> <pre><code>public class foo { private string mBar = "bar"; public string Bar { get { return mBar; } set { mBar = value; } } //... other methods, no constructor ... } </code></pre> <p>Converting Bar to an auto-property seems convenient and concise, but how ...
[ { "answer_id": 169232, "author": "Matthew Scharley", "author_id": 15537, "author_profile": "https://Stackoverflow.com/users/15537", "pm_score": 2, "selected": false, "text": "<p>In the default constructor (and any non-default ones if you have any too of course):</p>\n\n<pre><code>public ...
2008/10/03
[ "https://Stackoverflow.com/questions/169220", "https://Stackoverflow.com", "https://Stackoverflow.com/users/459/" ]
I'm used to writing classes like this: ``` public class foo { private string mBar = "bar"; public string Bar { get { return mBar; } set { mBar = value; } } //... other methods, no constructor ... } ``` Converting Bar to an auto-property seems convenient and concise, but how can I retain the initializ...
Update - the answer below was written before C# 6 came along. In C# 6 you can write: ``` public class Foo { public string Bar { get; set; } = "bar"; } ``` You can *also* write read-only automatically-implemented properties, which are only writable in the constructor (but can also be given a default initial value...
169,233
<p><a href="http://thedailywtf.com/Articles/The-Hot-Room.aspx" rel="noreferrer">http://thedailywtf.com/Articles/The-Hot-Room.aspx</a></p> <p>You see how at the bottom there're links to the next and previous articles ("Unprepared For Divide_By_Zero" and "A Completely Different Game")? How do I do that, but selecting th...
[ { "answer_id": 169270, "author": "Paige Ruten", "author_id": 813, "author_profile": "https://Stackoverflow.com/users/813", "pm_score": 3, "selected": false, "text": "<p>Here's how I would do it:</p>\n\n<pre><code>-- next\nSELECT * FROM articles WHERE id &gt; ? AND private IS NULL ORDER B...
2008/10/03
[ "https://Stackoverflow.com/questions/169233", "https://Stackoverflow.com", "https://Stackoverflow.com/users/23107/" ]
<http://thedailywtf.com/Articles/The-Hot-Room.aspx> You see how at the bottom there're links to the next and previous articles ("Unprepared For Divide\_By\_Zero" and "A Completely Different Game")? How do I do that, but selecting the next and previous non-private articles? This works for selecting the next article: `...
Or extending Jeremy's answer... In one query ``` (SELECT * FROM articles WHERE id > ? AND private IS NULL ORDER BY id ASC LIMIT 1) UNION (SELECT * FROM articles WHERE id < ? AND private IS NULL ORDER BY id DESC LIMIT 1) ```
169,240
<p>I have two databases with the same structure. The tables have an integer as a primary key as used in Rails.</p> <p>If I have a patients table, I will have one patient using primary key 123 in one database and another patient using the same primary key in the other database.</p> <p>What would you suggest for mergin...
[ { "answer_id": 169606, "author": "user6325", "author_id": 6325, "author_profile": "https://Stackoverflow.com/users/6325", "pm_score": 3, "selected": false, "text": "<p>Set both your databases up with entries in config/database.yml, then generate a new migration.</p>\n\n<p>Use ActiveRecor...
2008/10/03
[ "https://Stackoverflow.com/questions/169240", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14755/" ]
I have two databases with the same structure. The tables have an integer as a primary key as used in Rails. If I have a patients table, I will have one patient using primary key 123 in one database and another patient using the same primary key in the other database. What would you suggest for merging the data from b...
Set both your databases up with entries in config/database.yml, then generate a new migration. Use ActiveRecord::Base.establish\_connection to switch between the two databases in the migration like this: ``` def self.up ActiveRecord::Base.establish_connection :development patients = Patient.find(:all) ActiveRec...
169,274
<p>I'm making a simple scheduler with C# in .Net. All it does is execute a simple select statement on a table in a SQL Server DB once per minute (this does not need to scale or anything... the db does not have a high load). Here is my proposed implementation:</p> <pre><code>static void Main(string[] args) { whil...
[ { "answer_id": 169305, "author": "Doug Trojan", "author_id": 6982, "author_profile": "https://Stackoverflow.com/users/6982", "pm_score": 3, "selected": true, "text": "<p>While it is technically legal you are probably better of using a timer. They are not much more code to set up and you...
2008/10/03
[ "https://Stackoverflow.com/questions/169274", "https://Stackoverflow.com", "https://Stackoverflow.com/users/22471/" ]
I'm making a simple scheduler with C# in .Net. All it does is execute a simple select statement on a table in a SQL Server DB once per minute (this does not need to scale or anything... the db does not have a high load). Here is my proposed implementation: ``` static void Main(string[] args) { while (true) { ...
While it is technically legal you are probably better of using a timer. They are not much more code to set up and you can let the runtime take care of spawning new threads. If you ever needed to use this again in another program it would also create a performance bottleneck where a timer would not. The timer will add ...
169,277
<p>Is there a Generics Friendly way of using Collection.EMPTY_LIST in my Java Program.</p> <p>I know I could just declare one myself, but I'm just curious to know if there's a way in the JDK to do this.</p> <p>Something like <code>users = Collections&lt;User&gt;.EMPTY_LIST;</code></p>
[ { "answer_id": 169286, "author": "Ryan Delucchi", "author_id": 9931, "author_profile": "https://Stackoverflow.com/users/9931", "pm_score": 6, "selected": true, "text": "<p>By doing the following:</p>\n\n<pre><code>List&lt;User&gt; users = Collections.emptyList();\n</code></pre>\n\n<p>The...
2008/10/03
[ "https://Stackoverflow.com/questions/169277", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2443/" ]
Is there a Generics Friendly way of using Collection.EMPTY\_LIST in my Java Program. I know I could just declare one myself, but I'm just curious to know if there's a way in the JDK to do this. Something like `users = Collections<User>.EMPTY_LIST;`
By doing the following: ``` List<User> users = Collections.emptyList(); ``` The type of the returned list from `Collections.emptyList();` will be *inferred* as a `String` due to the left-hand-side of the assignment. However, if you prefer to not have this inference, you can define it explicitly by doing the followin...
169,278
<p>How do I get modrewrite to ENTIRELY ignore the /vip/ directory so that all requests pass directly to the folder?</p> <pre><code>&lt;IfModule mod_rewrite.c&gt; RewriteEngine On RewriteBase / RewriteRule ^vip/.$ - [PT] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L...
[ { "answer_id": 169347, "author": "ceejayoz", "author_id": 1902010, "author_profile": "https://Stackoverflow.com/users/1902010", "pm_score": 1, "selected": false, "text": "<p>Replace:</p>\n\n<pre><code>RewriteRule ^vip/.$ - [PT]\n</code></pre>\n\n<p>with:</p>\n\n<pre><code>RewriteRule ^vi...
2008/10/03
[ "https://Stackoverflow.com/questions/169278", "https://Stackoverflow.com", "https://Stackoverflow.com/users/24557/" ]
How do I get modrewrite to ENTIRELY ignore the /vip/ directory so that all requests pass directly to the folder? ``` <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^vip/.$ - [PT] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule> ``` ...
Replace: ``` RewriteRule ^vip/.$ - [PT] ``` with: ``` RewriteRule ^vip/.*$ - [PT,L] ```
169,287
<p>Does anyone have a good resource on dlls and how they are used / generated in Visual Studio? A few questions I'm rather hazy on specifically are:</p> <ul> <li>How refresh files work</li> <li>How dll version numbers are generated</li> <li>The difference between adding a reference by project vs browsing for the spec...
[ { "answer_id": 169314, "author": "Rob Walker", "author_id": 3631, "author_profile": "https://Stackoverflow.com/users/3631", "pm_score": 3, "selected": false, "text": "<p>See the question on <a href=\"https://stackoverflow.com/questions/124549/dll-information\">DLL information</a> for som...
2008/10/03
[ "https://Stackoverflow.com/questions/169287", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1574/" ]
Does anyone have a good resource on dlls and how they are used / generated in Visual Studio? A few questions I'm rather hazy on specifically are: * How refresh files work * How dll version numbers are generated * The difference between adding a reference by project vs browsing for the specific dll Any other tips are ...
See the question on [DLL information](https://stackoverflow.com/questions/124549/dll-information) for some background. Version numbers for unmanaged DLLs are stored in the DLL's rc file, same as for an exe. For managed DLLs I believe it uses AssemblyFileInfo attribute, usually in AssemblyInfo.cs for a Visual Studio ge...
169,303
<p>I want to be able to run unstrusted ruby code. I want to be able to pass variables to said untrusted code that it may use. I also want said code to return a result to me. Here is a conceptual example of what I am thinking</p> <pre><code>input = "sweet" output = nil Thread.start { $SAFE = 4 #... untrusted code...
[ { "answer_id": 169878, "author": "James Baker", "author_id": 9365, "author_profile": "https://Stackoverflow.com/users/9365", "pm_score": 5, "selected": true, "text": "<p>$SAFE is not enough; you need to be at least at the level of Why's freaky sandbox. However, I don't know if that sand...
2008/10/03
[ "https://Stackoverflow.com/questions/169303", "https://Stackoverflow.com", "https://Stackoverflow.com/users/21317/" ]
I want to be able to run unstrusted ruby code. I want to be able to pass variables to said untrusted code that it may use. I also want said code to return a result to me. Here is a conceptual example of what I am thinking ``` input = "sweet" output = nil Thread.start { $SAFE = 4 #... untrusted code goes here, it...
$SAFE is not enough; you need to be at least at the level of Why's freaky sandbox. However, I don't know if that sandbox code is actively maintained or if he/they ever solved the holes such as infinite loops, etc. Unsafe generally means hostile. If you can relax from hostile to, say, 'naive', and depending upon the re...
169,342
<p>I have a solution that contains two projects. One project is an ASP.NET Web Application Project, and one is a class library. The web application has a project reference to the class library. Neither of these is strongly-named.</p> <p>In the class library, which I'll call &quot;Framework,&quot; I have an endpoint beh...
[ { "answer_id": 170981, "author": "James Bender", "author_id": 22848, "author_profile": "https://Stackoverflow.com/users/22848", "pm_score": 2, "selected": false, "text": "<p>Do you have a copy of Framework.dll with your custom behavior in the bin directory of your web project? If not tha...
2008/10/03
[ "https://Stackoverflow.com/questions/169342", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8116/" ]
I have a solution that contains two projects. One project is an ASP.NET Web Application Project, and one is a class library. The web application has a project reference to the class library. Neither of these is strongly-named. In the class library, which I'll call "Framework," I have an endpoint behavior (an IEndpoint...
Per [the workaround](http://connect.microsoft.com/wcf/feedback/Workaround.aspx?FeedbackID=386511) that Microsoft posted on [the Connect issue](http://connect.microsoft.com/wcf/feedback/ViewFeedback.aspx?FeedbackID=386511) I filed for this, it's a known issue and there won't be any solution for it, at least in the curre...
169,362
<p>I would like to compress a folder and all its sub-folders/files, and email the zip file as an attachment. What would be the best way to achieve this with Python? </p>
[ { "answer_id": 169395, "author": "S.Lott", "author_id": 10661, "author_profile": "https://Stackoverflow.com/users/10661", "pm_score": 1, "selected": false, "text": "<p>Look at <a href=\"http://www.python.org/doc/2.5.2/lib/module-zipfile.html\" rel=\"nofollow noreferrer\">zipfile</a> for ...
2008/10/03
[ "https://Stackoverflow.com/questions/169362", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I would like to compress a folder and all its sub-folders/files, and email the zip file as an attachment. What would be the best way to achieve this with Python?
You can use the [zipfile](http://docs.python.org/dev/library/zipfile.html) module to compress the file using the zip standard, the [email](http://docs.python.org/dev/library/email.html) module to create the email with the attachment, and the [smtplib](http://docs.python.org/dev/library/smtplib.html) module to send it -...
169,377
<p>As a hobby I'm interesting in programming an Ethernet-connected LED sign to scroll messages across a screen. But I'm having trouble making a UDP sender in <a href="http://en.wikipedia.org/wiki/Visual_Basic_.NET" rel="nofollow noreferrer">VB.NET</a> (I am using 2008 currently).</p> <p>Now the sign is nice enough to ...
[ { "answer_id": 169422, "author": "Grant", "author_id": 30, "author_profile": "https://Stackoverflow.com/users/30", "pm_score": 0, "selected": false, "text": "<p>This might help. At my company we have to communicate with our hardware using sort of a combination of ascii and hex. </p>\n\n<...
2008/10/04
[ "https://Stackoverflow.com/questions/169377", "https://Stackoverflow.com", "https://Stackoverflow.com/users/25031/" ]
As a hobby I'm interesting in programming an Ethernet-connected LED sign to scroll messages across a screen. But I'm having trouble making a UDP sender in [VB.NET](http://en.wikipedia.org/wiki/Visual_Basic_.NET) (I am using 2008 currently). Now the sign is nice enough to have [a specifications sheet on programming for...
You could put together a quickie decoder like this one: ``` Function HexCodeToHexChar(ByVal m as System.Text.RegularExpressions.Match) As String Return Chr(Integer.Parse(m.Value.Substring("<0x".Length, 2), _ Globalization.NumberStyles.HexNumber)) End Function ``` then use this to transform: ``` Dim r A...
169,398
<p>I need to set up an instance of SQL Server 2005 with SQL_Latin1_General_CP850_Bin as the server collation (the vendor did not take into accounting looking at DB collation for a bunch of things so stored procedures and temp tables default to the server level and the default collation will not work). During the instal...
[ { "answer_id": 169413, "author": "GilM", "author_id": 10192, "author_profile": "https://Stackoverflow.com/users/10192", "pm_score": 3, "selected": true, "text": "<p>I think you're looking at instructions for SQL Server 2008.</p>\n\n<p>See the article <a href=\"http://msdn.microsoft.com/e...
2008/10/04
[ "https://Stackoverflow.com/questions/169398", "https://Stackoverflow.com", "https://Stackoverflow.com/users/204/" ]
I need to set up an instance of SQL Server 2005 with SQL\_Latin1\_General\_CP850\_Bin as the server collation (the vendor did not take into accounting looking at DB collation for a bunch of things so stored procedures and temp tables default to the server level and the default collation will not work). During the insta...
I think you're looking at instructions for SQL Server 2008. See the article [here](http://msdn.microsoft.com/en-us/library/ms179254(SQL.90).aspx) for instructions for 2005.
169,404
<p>In a <a href="https://stackoverflow.com/questions/168408/c-alternatives-to-void-pointers-that-isnt-templates">related question</a> I asked about creating a generic container. Using polymorphic templates seems like the right way to go.</p> <p>However, I can't for the life of me figure out how a destructor should be ...
[ { "answer_id": 169429, "author": "Scott Langham", "author_id": 11898, "author_profile": "https://Stackoverflow.com/users/11898", "pm_score": 0, "selected": false, "text": "<p>It can be done, but this is pretty advanced stuff.\nYou'll need to use something like the boost MPL library (<a h...
2008/10/04
[ "https://Stackoverflow.com/questions/169404", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14621/" ]
In a [related question](https://stackoverflow.com/questions/168408/c-alternatives-to-void-pointers-that-isnt-templates) I asked about creating a generic container. Using polymorphic templates seems like the right way to go. However, I can't for the life of me figure out how a destructor should be written. I want the o...
I'd recommend if you want to store pointers to complex types, that you use your container as: `MyContainer<shared_ptr<SomeComplexType> >`, and for primitive types just use `MyContainer<float>`. The `shared_ptr` should take care of deleting the complex type appropriately when it is destructed. And nothing fancy will ha...
169,419
<p>I like having my warning level set at W4 but all new projects start at W3. Is there some way to change the default value for warning levels for new projects?</p>
[ { "answer_id": 169434, "author": "albertein", "author_id": 23020, "author_profile": "https://Stackoverflow.com/users/23020", "pm_score": 2, "selected": false, "text": "<p>I don't know how to do it at the IDE but you cand always edit the new project templates at:</p>\n\n<pre><code>%PROGRA...
2008/10/04
[ "https://Stackoverflow.com/questions/169419", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3176/" ]
I like having my warning level set at W4 but all new projects start at W3. Is there some way to change the default value for warning levels for new projects?
I don't know how to do it at the IDE but you cand always edit the new project templates at: ``` %PROGRAM_FILES%\Microsoft Visual Studio 9.0\Common7\IDE\ProjectTemplates\ ``` If you're using the express version there could be a minor variation in the path: ``` %PROGRAM_FILES%\Microsoft Visual Studio 9.0\Common7\IDE\...
169,420
<p>I've been looking for a generic way to deal with bidirectional associations and a way to handle the inverse updates in manual written Java code.</p> <p>For those who don't know what I'm talking about, here is an example. Below it are my current results of (unsatisfying) solutions.</p> <pre><code>public class A { ...
[ { "answer_id": 169447, "author": "anjanb", "author_id": 11142, "author_profile": "https://Stackoverflow.com/users/11142", "pm_score": 4, "selected": true, "text": "<p>google collections (from google's internal code) -- <a href=\"http://code.google.com/p/google-collections/\" rel=\"nofoll...
2008/10/04
[ "https://Stackoverflow.com/questions/169420", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19935/" ]
I've been looking for a generic way to deal with bidirectional associations and a way to handle the inverse updates in manual written Java code. For those who don't know what I'm talking about, here is an example. Below it are my current results of (unsatisfying) solutions. ``` public class A { public B getB(); ...
google collections (from google's internal code) -- <http://code.google.com/p/google-collections/> is Java Generics compatible(not only compatible, uses generics very well) Class BiMap -- <http://google-collections.googlecode.com/svn/trunk/javadoc/index.html?http://google-collections.googlecode.com/svn/trunk/javadoc/c...
169,428
<p>this code always returns 0 in PHP 5.2.5 for microseconds:</p> <pre><code>&lt;?php $dt = new DateTime(); echo $dt-&gt;format("Y-m-d\TH:i:s.u") . "\n"; ?&gt; </code></pre> <p>Output:</p> <pre><code>[root@www1 ~]$ php date_test.php 2008-10-03T20:31:26.000000 [root@www1 ~]$ php date_test.php 2008-10-03T20:31:27.00000...
[ { "answer_id": 169458, "author": "eydelber", "author_id": 25039, "author_profile": "https://Stackoverflow.com/users/25039", "pm_score": 6, "selected": true, "text": "<p>This seems to work, although it seems illogical that <a href=\"http://us.php.net/date\" rel=\"noreferrer\">http://us.ph...
2008/10/04
[ "https://Stackoverflow.com/questions/169428", "https://Stackoverflow.com", "https://Stackoverflow.com/users/25039/" ]
this code always returns 0 in PHP 5.2.5 for microseconds: ``` <?php $dt = new DateTime(); echo $dt->format("Y-m-d\TH:i:s.u") . "\n"; ?> ``` Output: ``` [root@www1 ~]$ php date_test.php 2008-10-03T20:31:26.000000 [root@www1 ~]$ php date_test.php 2008-10-03T20:31:27.000000 [root@www1 ~]$ php date_test.php 2008-10-03T...
This seems to work, although it seems illogical that <http://us.php.net/date> documents the microsecond specifier yet doesn't really support it: ``` function getTimestamp() { return date("Y-m-d\TH:i:s") . substr((string)microtime(), 1, 8); } ```
169,450
<p><em>Information-Expert</em>, <em>Tell-Don't-Ask</em>, and <em>SRP</em> are often mentioned together as best practices. But I think they are at odds. Here is what I'm talking about.</p> <p>Code that favors SRP but violates Tell-Don't-Ask &amp; Info-Expert:</p> <pre><code>Customer bob = ...; // TransferObjectFactory...
[ { "answer_id": 169493, "author": "Hamish Smith", "author_id": 15572, "author_profile": "https://Stackoverflow.com/users/15572", "pm_score": 3, "selected": false, "text": "<p>I don't think that they are so much at odds as they are emphasizing different things that will cause you pain. One...
2008/10/04
[ "https://Stackoverflow.com/questions/169450", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10759/" ]
*Information-Expert*, *Tell-Don't-Ask*, and *SRP* are often mentioned together as best practices. But I think they are at odds. Here is what I'm talking about. Code that favors SRP but violates Tell-Don't-Ask & Info-Expert: ``` Customer bob = ...; // TransferObjectFactory has to use Customer's accessors to do its wor...
I don't think that they are so much at odds as they are emphasizing different things that will cause you pain. One is about structuring code to make it clear where particular responsibilities are and reducing coupling, the other is about reducing the reasons to modify a class. We all have to make decisions each and ev...
169,459
<p>I have an ISAm table in mySql that was created similar to this:</p> <pre><code>create table mytable ( id int not null auto_increment primary key, name varchar(64) not null ); create unique index nameIndex on mytable (name); </code></pre> <p>I have multiple processes inserting rows into this table. If two proces...
[ { "answer_id": 169462, "author": "Martin", "author_id": 2581, "author_profile": "https://Stackoverflow.com/users/2581", "pm_score": 3, "selected": true, "text": "<p>Do not bother locking, your index will prevent duplicates. You should handle the error code from your application.</p>\n\n...
2008/10/04
[ "https://Stackoverflow.com/questions/169459", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3740/" ]
I have an ISAm table in mySql that was created similar to this: ``` create table mytable ( id int not null auto_increment primary key, name varchar(64) not null ); create unique index nameIndex on mytable (name); ``` I have multiple processes inserting rows into this table. If two processes try to insert the same...
Do not bother locking, your index will prevent duplicates. You should handle the error code from your application. MySQL should return an error code of 1062 (or SQLSTATE 23000) when your unique key constraint is violated.
169,477
<p>I'm trying to implement a server control that frobs a couple of files inside the web directory of an ASP.NET site. I'm using VS Web Dev Express 2008 as my IDE. When I call <code>HttpContext.Current.Request.ApplicationPath</code> to get a path to the web root so I can find those files, it returns C:. What the heck?</...
[ { "answer_id": 169490, "author": "Kibbee", "author_id": 1862, "author_profile": "https://Stackoverflow.com/users/1862", "pm_score": 2, "selected": false, "text": "<p>This might be because it's using the development web server, which can just serve files from any directory on your hard dr...
2008/10/04
[ "https://Stackoverflow.com/questions/169477", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16398/" ]
I'm trying to implement a server control that frobs a couple of files inside the web directory of an ASP.NET site. I'm using VS Web Dev Express 2008 as my IDE. When I call `HttpContext.Current.Request.ApplicationPath` to get a path to the web root so I can find those files, it returns C:. What the heck? Absolute paths...
This might be because it's using the development web server, which can just serve files from any directory on your hard drive. It doesn't have any specific root. Can you run your project under IIS (assuming your version of windows supports it), and see if you get the same results? To get rid of the problem completely...
169,506
<p>I have a form with many input fields.</p> <p>When I catch the submit form event with jQuery, is it possible to get all the input fields of that form in an associative array?</p>
[ { "answer_id": 169553, "author": "Oli", "author_id": 12870, "author_profile": "https://Stackoverflow.com/users/12870", "pm_score": 3, "selected": false, "text": "<p>Associative? Not without some work, but you can use generic selectors:</p>\n\n<pre><code>var items = new Array();\n\n$('#fo...
2008/10/04
[ "https://Stackoverflow.com/questions/169506", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7883/" ]
I have a form with many input fields. When I catch the submit form event with jQuery, is it possible to get all the input fields of that form in an associative array?
``` $('#myForm').submit(function() { // get all the inputs into an array. var $inputs = $('#myForm :input'); // not sure if you wanted this, but I thought I'd add it. // get an associative array of just the values. var values = {}; $inputs.each(function() { values[this.name] = $(this).v...
169,511
<p>How do I iterate over a range of numbers in Bash when the range is given by a variable?</p> <p>I know I can do this (called "sequence expression" in the Bash <a href="http://www.gnu.org/software/bash/manual/bashref.html#Brace-Expansion" rel="noreferrer">documentation</a>):</p> <pre><code> for i in {1..5}; do echo ...
[ { "answer_id": 169515, "author": "Peter Hoffmann", "author_id": 720, "author_profile": "https://Stackoverflow.com/users/720", "pm_score": 5, "selected": false, "text": "<p>You can use</p>\n\n<pre><code>for i in $(seq $END); do echo $i; done\n</code></pre>\n" }, { "answer_id": 169...
2008/10/04
[ "https://Stackoverflow.com/questions/169511", "https://Stackoverflow.com", "https://Stackoverflow.com/users/24923/" ]
How do I iterate over a range of numbers in Bash when the range is given by a variable? I know I can do this (called "sequence expression" in the Bash [documentation](http://www.gnu.org/software/bash/manual/bashref.html#Brace-Expansion)): ``` for i in {1..5}; do echo $i; done ``` Which gives: > > 1 > > 2 ...
``` for i in $(seq 1 $END); do echo $i; done ``` edit: I prefer `seq` over the other methods because I can actually remember it ;)
169,520
<blockquote> <p><strong>Possible Duplicate:</strong><br> <a href="https://stackoverflow.com/questions/795746/warning-mysql-fetch-array-supplied-argument-is-not-a-valid-mysql-result">Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result</a> </p> </blockquote> <p>When I run my php page, I ge...
[ { "answer_id": 169527, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 0, "selected": false, "text": "<pre><code>&lt;?PHP\n\n $user_name = \"root\";\n $password = \"\";\n $database = \"addressbook\";\n $server = \"12...
2008/10/04
[ "https://Stackoverflow.com/questions/169520", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
> > **Possible Duplicate:** > > [Warning: mysql\_fetch\_array(): supplied argument is not a valid MySQL result](https://stackoverflow.com/questions/795746/warning-mysql-fetch-array-supplied-argument-is-not-a-valid-mysql-result) > > > When I run my php page, I get this error and do not know what's wrong, can an...
It generally means that you've got an error in your SQL. ``` $sql = "SELECT * FROM myTable"; // table name only do not add tb $result = mysql_query($sql); var_dump($result); // bool(false) ``` Obviously, `false` is not a MySQL resource, hence you get that error. **EDIT with the code pasted now**: On the line be...
169,529
<p>So I have a ListView with an upper limit of about 1000 items. I need to be able to filter these items using a textbox's TextChanged event. I have some code that works well for a smaller number of items (~400), but when I need to re-display a full list of all 1000 items, it takes about 4 seconds.</p> <p>I am not c...
[ { "answer_id": 169533, "author": "Jeff Yates", "author_id": 23234, "author_profile": "https://Stackoverflow.com/users/23234", "pm_score": 3, "selected": true, "text": "<p>There are two things to address this:</p>\n\n<ol>\n<li>Turn off sorting while manipulating the list contents.</li>\n<...
2008/10/04
[ "https://Stackoverflow.com/questions/169529", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1053/" ]
So I have a ListView with an upper limit of about 1000 items. I need to be able to filter these items using a textbox's TextChanged event. I have some code that works well for a smaller number of items (~400), but when I need to re-display a full list of all 1000 items, it takes about 4 seconds. I am not creating new ...
There are two things to address this: 1. Turn off sorting while manipulating the list contents. 2. Hide the list so it doesn't try to paint. The 1st point is the biggest performance gain in list manipulation out of these two. To achieve this, just set the ListViewItemSorter to null for the duration of the modificatio...
169,555
<p>Greetings,</p> <p>I need to include a property in my class which is a collection of System.IO.FileInfo objects. I am not really sure how to do this and how I would add and removed objects from an instance of the the class (I would assume like any other collection). </p> <p>Please let me know if I need to add m...
[ { "answer_id": 169568, "author": "Frank Krueger", "author_id": 338, "author_profile": "https://Stackoverflow.com/users/338", "pm_score": 1, "selected": false, "text": "<p><code>File</code> is a static class. So let's assume you meant <code>FileInfo</code>.</p>\n\n<p>There are lots of way...
2008/10/04
[ "https://Stackoverflow.com/questions/169555", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5836/" ]
Greetings, I need to include a property in my class which is a collection of System.IO.FileInfo objects. I am not really sure how to do this and how I would add and removed objects from an instance of the the class (I would assume like any other collection). Please let me know if I need to add more information. Tha...
`File` is a static class. So let's assume you meant `FileInfo`. There are lots of ways, you can: * Expose a private field * Use Iterators * Expose a private field through a ReadOnlyCollection<> For example, ``` class Foo { public IEnumerable<FileInfo> LotsOfFile { get { for (int i=0; i < 100...
169,562
<p>Ok, my actual problem was this: I was implementing an <code>IList&lt;T&gt;</code>. When I got to <code>CopyTo(Array array, int index)</code>, this was my solution:</p> <pre><code>void ICollection.CopyTo(Array array, int index) { // Bounds checking, etc here. if (!(array.GetValue(0) is T)) throw new ...
[ { "answer_id": 169579, "author": "justin.m.chase", "author_id": 12958, "author_profile": "https://Stackoverflow.com/users/12958", "pm_score": 2, "selected": false, "text": "<p>There is a method on Type specifically for this, try:</p>\n\n<pre><code>if(!typeof(T).IsAssignableFrom(array.Get...
2008/10/04
[ "https://Stackoverflow.com/questions/169562", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15537/" ]
Ok, my actual problem was this: I was implementing an `IList<T>`. When I got to `CopyTo(Array array, int index)`, this was my solution: ``` void ICollection.CopyTo(Array array, int index) { // Bounds checking, etc here. if (!(array.GetValue(0) is T)) throw new ArgumentException("Cannot cast to this typ...
The only way to be sure is with reflection, but 90% of the time you can avoid the cost of that by using `array is T[]`. Most people are going to pass a properly typed array in, so that will do. But, you should always provide the code to do the reflection check as well, just in case. Here's what my general boiler-plate ...
169,573
<p>I am searching for an open source Java library to generate thumbnails for a given URL. I need to bundle this capability, rather than call out to external services, such as <a href="http://aws.amazon.com/ast/" rel="nofollow noreferrer">Amazon</a> or <a href="http://www.websnapr.com/" rel="nofollow noreferrer">websna...
[ { "answer_id": 169578, "author": "Frank Krueger", "author_id": 338, "author_profile": "https://Stackoverflow.com/users/338", "pm_score": 2, "selected": false, "text": "<p>You're essentially asking for a complete rendering engine accessible by Java. Personally, I would save myself the has...
2008/10/04
[ "https://Stackoverflow.com/questions/169573", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14419/" ]
I am searching for an open source Java library to generate thumbnails for a given URL. I need to bundle this capability, rather than call out to external services, such as [Amazon](http://aws.amazon.com/ast/) or [websnapr](http://www.websnapr.com/). <http://www.webrenderer.com/> was mentioned in this post: [Server gen...
The first thing that comes to mind is using AWT to capture a screen grab (see code below). You could look at capturing the [JEditorPane](http://java.sun.com/javase/6/docs/api/javax/swing/JEditorPane.html), the [JDIC](https://jdic.dev.java.net/) [WebBrowser](https://jdic.dev.java.net/nonav/documentation/javadoc/jdic/org...
169,590
<p>I need to fire an event when the mouse is above a PictureBox with the mouse button already clicked and held down.</p> <p>Problems: </p> <p>The MouseDown and MouseEnter event handlers do not work together very well.</p> <p>For instance once a mouse button is clicked and held down, C# will fire the MouseDown event ...
[ { "answer_id": 169593, "author": "Jack B Nimble", "author_id": 3800, "author_profile": "https://Stackoverflow.com/users/3800", "pm_score": -1, "selected": false, "text": "<p>set a flag or a state on mouse down. release it on mouse up.\nWhen on mouse over fires for the picture box check y...
2008/10/04
[ "https://Stackoverflow.com/questions/169590", "https://Stackoverflow.com", "https://Stackoverflow.com/users/609/" ]
I need to fire an event when the mouse is above a PictureBox with the mouse button already clicked and held down. Problems: The MouseDown and MouseEnter event handlers do not work together very well. For instance once a mouse button is clicked and held down, C# will fire the MouseDown event handler, but when the cu...
When the mouse is pressed down most controls will then *Control.Capture* the mouse input. This means that all *MouseMove* events are sent to the original control that captured rather than the control the mouse happens to be over. This continues until the mouse loses capture which typically happens on the mouse up. If...
169,596
<p><strong>EDIT:</strong> <em>I'm still waiting for more answers. Thanks!</em></p> <p>In SQL 2000 days, I used to use temp table method where you create a temp table with new identity column and primary key then select where identity column between A and B.</p> <p>When <strong>SQL 2005</strong> came along I found out...
[ { "answer_id": 169655, "author": "Mitch Wheat", "author_id": 16076, "author_profile": "https://Stackoverflow.com/users/16076", "pm_score": 3, "selected": false, "text": "<p>The row_number() technique should be quick. I have seen good results for 100,000 rows.</p>\n\n<p>Are you using row_...
2008/10/04
[ "https://Stackoverflow.com/questions/169596", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5704/" ]
**EDIT:** *I'm still waiting for more answers. Thanks!* In SQL 2000 days, I used to use temp table method where you create a temp table with new identity column and primary key then select where identity column between A and B. When **SQL 2005** came along I found out about `Row_Number()` and I've been using it ever ...
Well, for your sample query ROW\_COUNT should be pretty fast with thousands of rows, provided you have an index on your PostDate field. If you don't, the server needs to perform a complete clustered index scan on your PK, practically load every page, fetch your PostDate field, sort by it, determine the rows to extract ...