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
51,032
<p>Consider these two function definitions:</p> <pre><code>void foo() { } void foo(void) { } </code></pre> <p>Is there any difference between these two? If not, why is the <code>void</code> argument there? Aesthetic reasons?</p>
[ { "answer_id": 51041, "author": "Paul Tomblin", "author_id": 3333, "author_profile": "https://Stackoverflow.com/users/3333", "pm_score": 2, "selected": false, "text": "<p>In C, you use a void in an empty function reference so that the compiler has a prototype, and that prototype has \"no...
2008/09/09
[ "https://Stackoverflow.com/questions/51032", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1597/" ]
Consider these two function definitions: ``` void foo() { } void foo(void) { } ``` Is there any difference between these two? If not, why is the `void` argument there? Aesthetic reasons?
In **C**: * `void foo()` means "a function `foo` taking an unspecified number of arguments of unspecified type" * `void foo(void)` means "a function `foo` taking no arguments" In **C++**: * `void foo()` means "a function `foo` taking no arguments" * `void foo(void)` means "a function `foo` taking no arguments" By...
51,054
<p>I am looking for a way to delete all files older than 7 days in a batch file. I've searched around the web, and found some examples with hundreds of lines of code, and others that required installing extra command line utilities to accomplish the task.</p> <p>Similar things can be <a href="https://stackoverflow.co...
[ { "answer_id": 51069, "author": "aku", "author_id": 1196, "author_profile": "https://Stackoverflow.com/users/1196", "pm_score": 11, "selected": true, "text": "<p>Enjoy:</p>\n\n<pre><code>forfiles -p \"C:\\what\\ever\" -s -m *.* -d &lt;number of days&gt; -c \"cmd /c del @path\"\n</code></...
2008/09/09
[ "https://Stackoverflow.com/questions/51054", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1862/" ]
I am looking for a way to delete all files older than 7 days in a batch file. I've searched around the web, and found some examples with hundreds of lines of code, and others that required installing extra command line utilities to accomplish the task. Similar things can be [done in BASH](https://stackoverflow.com/que...
Enjoy: ``` forfiles -p "C:\what\ever" -s -m *.* -d <number of days> -c "cmd /c del @path" ``` See [`forfiles` documentation](http://ss64.com/nt/forfiles.html) for more details. For more goodies, refer to *[An A-Z Index of the Windows XP command line](http://www.ss64.com/nt/)*. If you don't have `forfiles` installe...
51,092
<p>Consider the Oracle <code>emp</code> table. I'd like to get the employees with the top salary with <code>department = 20</code> and <code>job = clerk</code>. Also assume that there is no "empno" column, and that the primary key involves a number of columns. You can do this with:</p> <pre><code>select * from scott.e...
[ { "answer_id": 51103, "author": "Mark Nold", "author_id": 4134, "author_profile": "https://Stackoverflow.com/users/4134", "pm_score": 3, "selected": true, "text": "<p>The following is slightly over-engineered, but is a good SQL pattern for \"top x\" queries.</p>\n\n<pre><code>SELECT \n *...
2008/09/09
[ "https://Stackoverflow.com/questions/51092", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5295/" ]
Consider the Oracle `emp` table. I'd like to get the employees with the top salary with `department = 20` and `job = clerk`. Also assume that there is no "empno" column, and that the primary key involves a number of columns. You can do this with: ``` select * from scott.emp where deptno = 20 and job = 'CLERK' and sal ...
The following is slightly over-engineered, but is a good SQL pattern for "top x" queries. ``` SELECT * FROM scott.emp WHERE (deptno,job,sal) IN (SELECT deptno, job, max(sal) FROM scott.emp WHERE deptno = 20 and job = 'CLERK' GROUP BY deptno, job ) ``` Also note that this...
51,093
<p>Jeff covered this a while back <a href="http://www.codinghorror.com/blog/archives/000811.html" rel="nofollow noreferrer">on his blog</a> in terms of 32 bit Vista.</p> <p>Does the same 32 bit 4 GB memory cap that applies in 32 bit Vista apply to 32 bit Ubuntu? Are there any 32 bit operating systems that have creativ...
[ { "answer_id": 51100, "author": "Rob Rolnick", "author_id": 4798, "author_profile": "https://Stackoverflow.com/users/4798", "pm_score": 2, "selected": false, "text": "<p>In theory, all 32-bit OSes have that problem. You have 32 bits to do addressing.</p>\n\n<pre><code>2^32 bits / 2^10 (b...
2008/09/09
[ "https://Stackoverflow.com/questions/51093", "https://Stackoverflow.com", "https://Stackoverflow.com/users/357/" ]
Jeff covered this a while back [on his blog](http://www.codinghorror.com/blog/archives/000811.html) in terms of 32 bit Vista. Does the same 32 bit 4 GB memory cap that applies in 32 bit Vista apply to 32 bit Ubuntu? Are there any 32 bit operating systems that have creatively solved this problem?
In theory, all 32-bit OSes have that problem. You have 32 bits to do addressing. ``` 2^32 bits / 2^10 (bits per kb) / 2^10 (kb per mb) / 2^10 (mb per gb) = 2^2 = 4gb. ``` Although there are some ways around it. (Look up the jump from 16-bit computing to 32-bit computing. They hit the same problem.)
51,098
<p>I have two spreadsheets... when one gets modified in a certain way I want to have a macro run that modifies the second in an appropriate manner. I've already isolated the event I need to act on (the modification of any cell in a particular column), I just can't seem to find any concrete information on accessing and...
[ { "answer_id": 51111, "author": "Michael Pryor", "author_id": 245, "author_profile": "https://Stackoverflow.com/users/245", "pm_score": 4, "selected": true, "text": "<p>In Excel, you would likely just write code to open the other worksheet, modify it and then save the data.</p>\n\n<p>See...
2008/09/09
[ "https://Stackoverflow.com/questions/51098", "https://Stackoverflow.com", "https://Stackoverflow.com/users/271/" ]
I have two spreadsheets... when one gets modified in a certain way I want to have a macro run that modifies the second in an appropriate manner. I've already isolated the event I need to act on (the modification of any cell in a particular column), I just can't seem to find any concrete information on accessing and mod...
In Excel, you would likely just write code to open the other worksheet, modify it and then save the data. See [this tutorial](http://pubs.logicalexpressions.com/Pub0009/LPMArticle.asp?ID=302) for more info. I'll have to edit my VBA later, so pretend this is pseudocode, but it should look something like: ``` Dim xl: ...
51,108
<p>I really enjoyed <a href="http://www.codinghorror.com/blog/archives/001148.html" rel="noreferrer">Jeff's post</a> on <a href="http://ssdl-wiki.cs.technion.ac.il/wiki/index.php/Spartan_programming" rel="noreferrer">Spartan Programming</a>. I agree that code like that is a joy to read. Unfortunately, I'm not so sure i...
[ { "answer_id": 51112, "author": "jjnguy", "author_id": 2598, "author_profile": "https://Stackoverflow.com/users/2598", "pm_score": 2, "selected": false, "text": "<p>One expression per line.</p>\n\n<p>There is no reason to obfuscate your code. The extra time you take typing the few extra...
2008/09/09
[ "https://Stackoverflow.com/questions/51108", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4910/" ]
I really enjoyed [Jeff's post](http://www.codinghorror.com/blog/archives/001148.html) on [Spartan Programming](http://ssdl-wiki.cs.technion.ac.il/wiki/index.php/Spartan_programming). I agree that code like that is a joy to read. Unfortunately, I'm not so sure it would necessarily be a joy to work with. For years I hav...
In **The Pragmatic Programmer** Hunt and Thomas talk about a study they term the Law of Demeter and it focuses on the coupling of functions to modules other than there own. By allowing a function to never reach a 3rd level in it's coupling you significantly reduce the number of errors and increase the maintainability o...
51,113
<p>It seems like IDataReader.Read() is always true at least one time (If I'm wrong about this let me know.) So how do you tell if it has no records without just wrapping it in a try/catch?</p>
[ { "answer_id": 51120, "author": "Ben Scheirman", "author_id": 3381, "author_profile": "https://Stackoverflow.com/users/3381", "pm_score": 5, "selected": false, "text": "<pre><code>if(dr.Read())\n{\n //do stuff\n}\nelse\n{\n //it's empty\n}\n</code></pre>\n\n<p>usually you'll do this th...
2008/09/09
[ "https://Stackoverflow.com/questions/51113", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4541/" ]
It seems like IDataReader.Read() is always true at least one time (If I'm wrong about this let me know.) So how do you tell if it has no records without just wrapping it in a try/catch?
``` if(dr.Read()) { //do stuff } else { //it's empty } ``` usually you'll do this though: ``` while(dr.Read()) { } ```
51,129
<p>In C#, if I need to open an HTTP connection, download XML and get one value from the result, how would I do that?</p> <p>For consistency, imagine the webservice is at www.webservice.com and that if you pass it the POST argument fXML=1 it gives you back </p> <pre><code>&lt;xml&gt;&lt;somekey&gt;somevalue&lt;/someke...
[ { "answer_id": 51136, "author": "Jon Limjap", "author_id": 372, "author_profile": "https://Stackoverflow.com/users/372", "pm_score": 2, "selected": false, "text": "<p>I think it will be useful to read this first:</p>\n\n<p><a href=\"https://web.archive.org/web/20211020134836/https://aspn...
2008/09/09
[ "https://Stackoverflow.com/questions/51129", "https://Stackoverflow.com", "https://Stackoverflow.com/users/245/" ]
In C#, if I need to open an HTTP connection, download XML and get one value from the result, how would I do that? For consistency, imagine the webservice is at www.webservice.com and that if you pass it the POST argument fXML=1 it gives you back ``` <xml><somekey>somevalue</somekey></xml> ``` I'd like it to spit o...
I use this code and it works great: ``` System.Xml.XmlDocument xd = new System.Xml.XmlDocument; xd.Load("http://www.webservice.com/webservice?fXML=1"); string xPath = "/xml/somekey"; // this node's inner text contains "somevalue" return xd.SelectSingleNode(xPath).InnerText; ``` --- EDIT: I just realized you're talk...
51,139
<p>I'm trying to create an SSIS package that takes data from an XML data source and for each row inserts another row with some preset values. Any ideas? I'm thinking I could use a DataReader source to generate the preset values by doing the following:</p> <pre><code>SELECT 'foo' as 'attribute1', 'bar' as 'attribute2...
[ { "answer_id": 51158, "author": "Tadmas", "author_id": 3750, "author_profile": "https://Stackoverflow.com/users/3750", "pm_score": 2, "selected": false, "text": "<p>I've never tried it, but it looks like you might be able to use a <a href=\"http://msdn.microsoft.com/en-us/library/ms14106...
2008/09/09
[ "https://Stackoverflow.com/questions/51139", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4550/" ]
I'm trying to create an SSIS package that takes data from an XML data source and for each row inserts another row with some preset values. Any ideas? I'm thinking I could use a DataReader source to generate the preset values by doing the following: ``` SELECT 'foo' as 'attribute1', 'bar' as 'attribute2' ``` The ques...
I've never tried it, but it looks like you might be able to use a [Derived Column transformation](http://msdn.microsoft.com/en-us/library/ms141069(SQL.90).aspx) to do it: set the expression for attribute1 to `"foo"` and the expression for attribute2 to `"bar"`. You'd then transform the original data source, then only ...
51,148
<p>I have C# winforms application that needs to start an external exe from time to time, but I do not wish to start another process if one is already running, but rather switch to it.</p> <p>So how in C# would I so this in the example below?</p> <pre><code>using System.Diagnostics; ... Process foo = new Process(); ...
[ { "answer_id": 51149, "author": "DaveK", "author_id": 4244, "author_profile": "https://Stackoverflow.com/users/4244", "pm_score": 6, "selected": true, "text": "<p>This should do it for ya.</p>\n\n<p><a href=\"http://www.dreamincode.net/code/snippet1541.htm\" rel=\"noreferrer\">Check Proc...
2008/09/09
[ "https://Stackoverflow.com/questions/51148", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1292/" ]
I have C# winforms application that needs to start an external exe from time to time, but I do not wish to start another process if one is already running, but rather switch to it. So how in C# would I so this in the example below? ``` using System.Diagnostics; ... Process foo = new Process(); foo.StartInfo.FileNa...
This should do it for ya. [Check Processes](http://www.dreamincode.net/code/snippet1541.htm) ``` //Namespaces we need to use using System.Diagnostics; public bool IsProcessOpen(string name) { //here we're going to get a list of all running processes on //the computer foreach (Process clsProcess in Proces...
51,150
<p>When an application is behind another applications and I click on my application's taskbar icon, I expect the entire application to come to the top of the z-order, even if an app-modal, WS_POPUP dialog box is open.</p> <p>However, some of the time, for some of my (and others') dialog boxes, only the dialog box come...
[ { "answer_id": 51160, "author": "jmatthias", "author_id": 2768, "author_profile": "https://Stackoverflow.com/users/2768", "pm_score": 0, "selected": false, "text": "<p>Is the dialog's parent window set correctly?</p>\n\n<p>After I posted this, I started my own Windows Forms application a...
2008/09/09
[ "https://Stackoverflow.com/questions/51150", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5309/" ]
When an application is behind another applications and I click on my application's taskbar icon, I expect the entire application to come to the top of the z-order, even if an app-modal, WS\_POPUP dialog box is open. However, some of the time, for some of my (and others') dialog boxes, only the dialog box comes to the ...
I know this is very old now, but I just stumbled across it, and I know the answer. In the applications you've seen (and written) where bringing the dialog box to the foreground did **not** bring the main window up along with it, the developer has simply neglected to specify the owner of the dialog box. This applies t...
51,165
<p>I have a list of objects I wish to sort based on a field <code>attr</code> of type string. I tried using <code>-</code></p> <pre><code>list.sort(function (a, b) { return a.attr - b.attr }) </code></pre> <p>but found that <code>-</code> doesn't appear to work with strings in JavaScript. How can I sort a list of...
[ { "answer_id": 51169, "author": "Shog9", "author_id": 811, "author_profile": "https://Stackoverflow.com/users/811", "pm_score": 11, "selected": true, "text": "<p>Use <a href=\"https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/String/localeCompare\" rel=\"norefe...
2008/09/09
[ "https://Stackoverflow.com/questions/51165", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5304/" ]
I have a list of objects I wish to sort based on a field `attr` of type string. I tried using `-` ``` list.sort(function (a, b) { return a.attr - b.attr }) ``` but found that `-` doesn't appear to work with strings in JavaScript. How can I sort a list of objects based on an attribute with type string?
Use [`String.prototype.localeCompare`](https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/String/localeCompare) a per your example: ``` list.sort(function (a, b) { return ('' + a.attr).localeCompare(b.attr); }) ``` We force a.attr to be a string to avoid exceptions. `localeCompare` has ...
51,176
<p>I recently started a new webforms project and decided to separate the business classes from any DBML references. My business layer classes instead access discrete Data layer methods and are returned collections of DTO's. So the data layer might project DTO's like the following:</p> <pre><code>(from c in dataContext...
[ { "answer_id": 51186, "author": "aku", "author_id": 1196, "author_profile": "https://Stackoverflow.com/users/1196", "pm_score": 2, "selected": false, "text": "<p>In my opinion in most cases DTO objects are not needed when dealing with LINQ. Generated LINQ classes can be easily tested. LI...
2008/09/09
[ "https://Stackoverflow.com/questions/51176", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5136/" ]
I recently started a new webforms project and decided to separate the business classes from any DBML references. My business layer classes instead access discrete Data layer methods and are returned collections of DTO's. So the data layer might project DTO's like the following: ``` (from c in dataContext.Customers whe...
I don't know if it's best practice but I have written similar code in the not so recent past because I too felt that I could improve the separation of concerns by using my own classes instead of the LINQ-designer-generated ones within my application. You may want to consider just returning an IQueryable<Customer> inst...
51,180
<p>I'm tearing my hair out with this one. If I start a block comment <code>/*</code> in VS.NET 2005+ then carriage return, Visual Studio insists that I have another asterisk <code>*</code>. I know there's an option to turn this off but I just can't find it. Anyone know how to turn this feature off?</p>
[ { "answer_id": 51194, "author": "Michael Haren", "author_id": 29, "author_profile": "https://Stackoverflow.com/users/29", "pm_score": 6, "selected": true, "text": "<p><strong>Update: this setting was changed in VS 2015 update 2. See <a href=\"https://stackoverflow.com/a/36319097/4294399\...
2008/09/09
[ "https://Stackoverflow.com/questions/51180", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4458/" ]
I'm tearing my hair out with this one. If I start a block comment `/*` in VS.NET 2005+ then carriage return, Visual Studio insists that I have another asterisk `*`. I know there's an option to turn this off but I just can't find it. Anyone know how to turn this feature off?
**Update: this setting was changed in VS 2015 update 2. See [this answer](https://stackoverflow.com/a/36319097/4294399).** [This post](http://forums.msdn.microsoft.com/en-US/csharpide/thread/a41e3652-efe2-4f81-ad3e-94994974fcb2/) addresses your question. The gist of it is: ``` Text Editor > C# > Advanced > Generate X...
51,185
<p>Does javascript use immutable or mutable strings? Do I need a "string builder"?</p>
[ { "answer_id": 51188, "author": "JC Grubbs", "author_id": 4541, "author_profile": "https://Stackoverflow.com/users/4541", "pm_score": 0, "selected": false, "text": "<p>JavaScript strings are indeed immutable.</p>\n" }, { "answer_id": 51191, "author": "Glenn Slaven", "auth...
2008/09/09
[ "https://Stackoverflow.com/questions/51185", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1220/" ]
Does javascript use immutable or mutable strings? Do I need a "string builder"?
They are immutable. You cannot change a character within a string with something like `var myString = "abbdef"; myString[2] = 'c'`. The string manipulation methods such as [`trim`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/trim), [`slice`](https://developer.mozilla.org/en-U...
51,195
<p>I want to write a little "DBQuery" function in perl so I can have one-liners which send an SQL statement and receive back and an array of hashes, i.e. a recordset. However, I'm running into an issue with Perl syntax (and probably some odd pointer/reference issue) which is preventing me from packing out the informati...
[ { "answer_id": 51205, "author": "Commodore Jaeger", "author_id": 4659, "author_profile": "https://Stackoverflow.com/users/4659", "pm_score": 6, "selected": true, "text": "<p>The nested data structure contains a hash <em>reference</em>, not a hash.</p>\n\n<pre><code># Will work (the -&gt;...
2008/09/09
[ "https://Stackoverflow.com/questions/51195", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4639/" ]
I want to write a little "DBQuery" function in perl so I can have one-liners which send an SQL statement and receive back and an array of hashes, i.e. a recordset. However, I'm running into an issue with Perl syntax (and probably some odd pointer/reference issue) which is preventing me from packing out the information ...
The nested data structure contains a hash *reference*, not a hash. ``` # Will work (the -> dereferences the reference) $row = $records[$index]; print "This will work: ", $row->{firstName}, "\n"; # This will also work, by promoting the hash reference into a hash %row = %{ $records[$index] }; print "This will work: ", ...
51,210
<p>I'm playing with the routing.rb code in Rails 2.1, and trying to to get it to the point where I can do something useful with the RoutingError exception that is thrown when it can't find the appropriate path.</p> <p>This is a somewhat tricky problem, because there are some class of URLs which are just plain BAD: the...
[ { "answer_id": 51378, "author": "Matthias Winkelmann", "author_id": 4494, "author_profile": "https://Stackoverflow.com/users/4494", "pm_score": 1, "selected": false, "text": "<p>There's the method_missing method. You could implement that in your Application Controller and catch all missi...
2008/09/09
[ "https://Stackoverflow.com/questions/51210", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5266/" ]
I'm playing with the routing.rb code in Rails 2.1, and trying to to get it to the point where I can do something useful with the RoutingError exception that is thrown when it can't find the appropriate path. This is a somewhat tricky problem, because there are some class of URLs which are just plain BAD: the /azenv.ph...
Nooooo!!! Don't implement method\_missing on your controller! And please try to avoid action\_missing as well. The frequently touted pattern is to add a route: ``` map.connect '*', :controller => 'error', :action => 'not_found' ``` Where you can show an appropriate error. Rails also has a mechanism called rescue\_...
51,212
<p>I am writing a little application to download files over http (as, for example, described <a href="https://stackoverflow.com/questions/22676/how-do-i-download-a-file-over-http-using-python#22776">here</a>).</p> <p>I also want to include a little download progress indicator showing the percentage of the download pro...
[ { "answer_id": 51214, "author": "hazzen", "author_id": 5066, "author_profile": "https://Stackoverflow.com/users/5066", "pm_score": 2, "selected": false, "text": "<p>If you use the <code>curses</code> package, you have much greater control of the console. It also comes at a higher cost i...
2008/09/09
[ "https://Stackoverflow.com/questions/51212", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2386/" ]
I am writing a little application to download files over http (as, for example, described [here](https://stackoverflow.com/questions/22676/how-do-i-download-a-file-over-http-using-python#22776)). I also want to include a little download progress indicator showing the percentage of the download progress. Here is what ...
There's a text progress bar library for python at <http://pypi.python.org/pypi/progressbar/2.2> that you might find useful: > > This library provides a text mode progressbar. This is tipically used to display the progress of a long running operation, providing a visual clue that processing is underway. > > > The Pr...
51,217
<p>I work for a company whose primary business is not software related. Most documentation for using source control is written with a development team writing for commercial or open source projects in mind. As someone who writes in house software I can say that work is done differently then it would be in a commercial ...
[ { "answer_id": 51220, "author": "Eric", "author_id": 5277, "author_profile": "https://Stackoverflow.com/users/5277", "pm_score": 2, "selected": false, "text": "<p>You could use a service like www.unfuddle.com to set up a free SVN or GIT repository.</p>\n\n<p>We use Unfuddle and it's real...
2008/09/09
[ "https://Stackoverflow.com/questions/51217", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4491/" ]
I work for a company whose primary business is not software related. Most documentation for using source control is written with a development team writing for commercial or open source projects in mind. As someone who writes in house software I can say that work is done differently then it would be in a commercial or ...
Setting up SVN repositories can be tricky only in the sense of how you organize them. Before we setup SVN, I actually RTFM'd the online [Subversion manual](http://svnbook.red-bean.com/) which discusses organizational techniques for repositories and some of the gotchas you should think about in advance, namely what you ...
51,224
<p>I'm trying to write a regular expression that validates a date. The regex needs to match the following</p> <ul> <li>M/D/YYYY</li> <li>MM/DD/YYYY</li> <li>Single digit months can start with a leading zero (eg: 03/12/2008)</li> <li>Single digit days can start with a leading zero (eg: 3/02/2008)</li> <li>CANNOT inclu...
[ { "answer_id": 51227, "author": "Wedge", "author_id": 332, "author_profile": "https://Stackoverflow.com/users/332", "pm_score": 2, "selected": false, "text": "<p>Sounds like you're overextending regex for this purpose. What I would do is use a regex to match a few date formats and then u...
2008/09/09
[ "https://Stackoverflow.com/questions/51224", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3742/" ]
I'm trying to write a regular expression that validates a date. The regex needs to match the following * M/D/YYYY * MM/DD/YYYY * Single digit months can start with a leading zero (eg: 03/12/2008) * Single digit days can start with a leading zero (eg: 3/02/2008) * CANNOT include February 30 or February 31 (eg: 2/31/200...
This is not an appropriate use of regular expressions. You'd be better off using ``` [0-9]{2}/[0-9]{2}/[0-9]{4} ``` and then checking ranges in a higher-level language.
51,233
<p>How can I retrieve the page title of a webpage (title html tag) using Python?</p>
[ { "answer_id": 51240, "author": "Peter Hoffmann", "author_id": 720, "author_profile": "https://Stackoverflow.com/users/720", "pm_score": 7, "selected": true, "text": "<p>I'll always use <a href=\"http://lxml.de/\" rel=\"nofollow noreferrer\">lxml</a> for such tasks. You could use <a href...
2008/09/09
[ "https://Stackoverflow.com/questions/51233", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2386/" ]
How can I retrieve the page title of a webpage (title html tag) using Python?
I'll always use [lxml](http://lxml.de/) for such tasks. You could use [beautifulsoup](http://www.crummy.com/software/BeautifulSoup/) as well. ``` import lxml.html t = lxml.html.parse(url) print(t.find(".//title").text) ``` EDIT based on comment: ``` from urllib2 import urlopen from lxml.html import parse url = "ht...
51,238
<p>I have a table in a MySql database that stores user accounts. One of the columns, expires, stores an expiration date but defaults to NULL. I need to be able to remove an expiration date and set it back to the default value.</p> <p>Currently, all of my CRUD routines are written using MySqlCommand with parameters. Ca...
[ { "answer_id": 51257, "author": "aku", "author_id": 1196, "author_profile": "https://Stackoverflow.com/users/1196", "pm_score": 0, "selected": false, "text": "<p>It's not clear what conditions you're talking about. If you want to set column to default value, you can use <a href=\"http://...
2008/09/09
[ "https://Stackoverflow.com/questions/51238", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1249/" ]
I have a table in a MySql database that stores user accounts. One of the columns, expires, stores an expiration date but defaults to NULL. I need to be able to remove an expiration date and set it back to the default value. Currently, all of my CRUD routines are written using MySqlCommand with parameters. Can this be ...
The problem was DBNull, doing: ``` command.Parameters.AddWithValue("@parameter", null); ``` compiles OK.
51,262
<p>How can you find out what are the long running queries are on Informix database server? I have a query that is using up the CPU and want to find out what the query is.</p>
[ { "answer_id": 52121, "author": "Jason Navarrete", "author_id": 3920, "author_profile": "https://Stackoverflow.com/users/3920", "pm_score": -1, "selected": false, "text": "<pre><code>SELECT ELAPSED_TIME_MIN,SUBSTR(AUTHID,1,10) AS AUTH_ID, \nAGENT_ID, APPL_STATUS,SUBSTR(STMT_TEXT,1,20) AS...
2008/09/09
[ "https://Stackoverflow.com/questions/51262", "https://Stackoverflow.com", "https://Stackoverflow.com/users/486/" ]
How can you find out what are the long running queries are on Informix database server? I have a query that is using up the CPU and want to find out what the query is.
If the query is currently running watch the **onstat -g act -r 1** output and look for items with an ***rstcb*** that is not 0 ``` Running threads: tid tcb rstcb prty status vp-class name 106 c0000000d4860950 0 2 running 107soc ...
51,264
<p>What object do you query against to select all the table names in a schema in Oracle?</p>
[ { "answer_id": 51265, "author": "jatanp", "author_id": 959, "author_profile": "https://Stackoverflow.com/users/959", "pm_score": -1, "selected": false, "text": "<p>You may use:</p>\n\n<pre><code>select tabname from tabs \n</code></pre>\n\n<p>to get the name of tables present in schema.</...
2008/09/09
[ "https://Stackoverflow.com/questions/51264", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4491/" ]
What object do you query against to select all the table names in a schema in Oracle?
To see all the tables you have access to ``` select table_name from all_tables where owner='<SCHEMA>'; ``` To select all tables for the current logged in schema (eg, your tables) ``` select table_name from user_tables; ```
51,269
<p>I am not sure whether is it possible to change attribute's parameter during runtime? For example, inside an assembly I have the following class</p> <pre><code>public class UserInfo { [Category("change me!")] public int Age { get; set; } [Category("change me!")] public string ...
[ { "answer_id": 51278, "author": "Glenn Slaven", "author_id": 2975, "author_profile": "https://Stackoverflow.com/users/2975", "pm_score": 0, "selected": false, "text": "<p>I really don't think so, unless there's some funky reflection that can pull it off. The property decorations are set...
2008/09/09
[ "https://Stackoverflow.com/questions/51269", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3834/" ]
I am not sure whether is it possible to change attribute's parameter during runtime? For example, inside an assembly I have the following class ``` public class UserInfo { [Category("change me!")] public int Age { get; set; } [Category("change me!")] public string Name { ...
Well you learn something new every day, apparently I lied: > > What isn’t generally realised is that > you can change attribute **instance** values fairly > easily at runtime. The reason is, of > course, that the instances of the > attribute classes that are created are > perfectly normal objects and can be > u...
51,320
<p>For a project I'm working on. I need to look for an executable on the filesystem. For UNIX derivatives, I assume the user has the file in the mighty $PATH variable, but there is no such thing on Windows.</p> <p>I can safely assume the file is at most 2 levels deep into the filesystem, but I don't know on what drive...
[ { "answer_id": 51327, "author": "Frank Krueger", "author_id": 338, "author_profile": "https://Stackoverflow.com/users/338", "pm_score": -1, "selected": false, "text": "<p>Of course there is a <code>PATH</code> environment variable <a href=\"http://en.wikipedia.org/wiki/Environment_variab...
2008/09/09
[ "https://Stackoverflow.com/questions/51320", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2018/" ]
For a project I'm working on. I need to look for an executable on the filesystem. For UNIX derivatives, I assume the user has the file in the mighty $PATH variable, but there is no such thing on Windows. I can safely assume the file is at most 2 levels deep into the filesystem, but I don't know on what drive it will b...
<http://docs.oracle.com/javase/7/docs/api/java/io/File.html#listRoots()> ``` File[] roots = File.listRoots(); for(int i = 0; i < roots.length ; i++) System.out.println("Root["+i+"]:" + roots[i]); ``` google: list drives java, first hit:-)
51,339
<p>I'm a bit stuck on this. Basically I want to do something like the following SQL query in LINQ to SQL:</p> <pre><code>SELECT f.* FROM Foo f WHERE f.FooId IN ( SELECT fb.FooId FROM FooBar fb WHERE fb.BarId = 1000 ) </code></pre> <p>Any help would be gratefully received.</p>
[ { "answer_id": 51345, "author": "Daren Thomas", "author_id": 2260, "author_profile": "https://Stackoverflow.com/users/2260", "pm_score": 2, "selected": false, "text": "<p>Try using two separate steps:</p>\n\n<pre><code>// create a Dictionary / Set / Collection fids first\nvar fids = (fro...
2008/09/09
[ "https://Stackoverflow.com/questions/51339", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1904/" ]
I'm a bit stuck on this. Basically I want to do something like the following SQL query in LINQ to SQL: ``` SELECT f.* FROM Foo f WHERE f.FooId IN ( SELECT fb.FooId FROM FooBar fb WHERE fb.BarId = 1000 ) ``` Any help would be gratefully received.
Have a look at [this article](http://blog.wekeroad.com/2008/02/27/creating-in-queries-with-linq-to-sql). Basically, if you want to get the equivalent of IN, you need to construct an inner query first, and then use the Contains() method. Here's my attempt at translating: ``` var innerQuery = from fb in FoorBar where fb...
51,352
<p>I'm currently working on a web application which has a page which displays a single chart (a .png image). On another part of this page there are a set of links which, when clicked, the entire page reloads and looks exactly the same as before except for the chart in the middle of the page.</p> <p>What I want to do ...
[ { "answer_id": 51360, "author": "Mauro", "author_id": 2208, "author_profile": "https://Stackoverflow.com/users/2208", "pm_score": 1, "selected": false, "text": "<p>put the spinner in a div the same size as the chart, you know the height and width so you can use relative positioning to ce...
2008/09/09
[ "https://Stackoverflow.com/questions/51352", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3847/" ]
I'm currently working on a web application which has a page which displays a single chart (a .png image). On another part of this page there are a set of links which, when clicked, the entire page reloads and looks exactly the same as before except for the chart in the middle of the page. What I want to do is when a l...
I've used something like this to preload an image and then automatically call back to my javascript when the image is finished loading. You want to check complete before you setup the callback because the image may already be cached and it may not call your callback. ``` function PreloadImage(imgSrc, callback){ var ...
51,407
<p>I want to load a desktop application, via reflection, as a Control inside another application.</p> <p>The application I'm reflecting is a legacy one - I can't make changes to it.</p> <p>I can dynamically access the Form, but can't load it as a Control.</p> <p>In .Net Form expands on Control, and I can assign the ...
[ { "answer_id": 51428, "author": "Rob Stevenson-Leggett", "author_id": 4950, "author_profile": "https://Stackoverflow.com/users/4950", "pm_score": 1, "selected": false, "text": "<p>You should be able to add the form to the controls collection of your parent form...</p>\n\n<p>See here: \n<...
2008/09/09
[ "https://Stackoverflow.com/questions/51407", "https://Stackoverflow.com", "https://Stackoverflow.com/users/905/" ]
I want to load a desktop application, via reflection, as a Control inside another application. The application I'm reflecting is a legacy one - I can't make changes to it. I can dynamically access the Form, but can't load it as a Control. In .Net Form expands on Control, and I can assign the reflected Form as a Cont...
Yes, this works just fine. I'm working on a .NET app right now that loads forms into a panel on a host form. The relevant snippet: ``` // setup the new form form.TopLevel = false; form.FormBorderStyle = FormBorderStyle.None; form.Dock = DockStyle.Fill; form.Show ( ); // add to the panel's list of child controls pane...
51,412
<p>Say I have the following methods:</p> <pre><code>def methodA(arg, **kwargs): pass def methodB(arg, *args, **kwargs): pass </code></pre> <p>In methodA I wish to call methodB, passing on the kwargs. However, it seems that if I define <code>methodA</code> as follows, the second argument will be passed on as ...
[ { "answer_id": 51414, "author": "Staale", "author_id": 3355, "author_profile": "https://Stackoverflow.com/users/3355", "pm_score": 1, "selected": false, "text": "<p>Some experimentation and I figured this one out:</p>\n\n<p>def methodA(arg, **kwargs):\n methodB(\"argvalue\", **kwargs)...
2008/09/09
[ "https://Stackoverflow.com/questions/51412", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3355/" ]
Say I have the following methods: ``` def methodA(arg, **kwargs): pass def methodB(arg, *args, **kwargs): pass ``` In methodA I wish to call methodB, passing on the kwargs. However, it seems that if I define `methodA` as follows, the second argument will be passed on as positional rather than named variable...
Put the asterisks before the kwargs variable. This makes Python pass the variable (which is assumed to be a dictionary) as keyword arguments. ``` methodB("argvalue", **kwargs) ```
51,420
<p>I want to get the base 10 logarithm of a Fixnum using Ruby, but found that n.log or n.log10 are not defined. Math::log is defined but uses a different base than 10.</p> <p>What is the easiest way to get the base 10 logarithm of a Fixnum?</p>
[ { "answer_id": 51423, "author": "Wes Oldenbeuving", "author_id": 4187, "author_profile": "https://Stackoverflow.com/users/4187", "pm_score": 2, "selected": false, "text": "<p>Reading the documentation for module Math the answer is really obvious:</p>\n\n<pre><code>Math::log10(n) \n</code...
2008/09/09
[ "https://Stackoverflow.com/questions/51420", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4187/" ]
I want to get the base 10 logarithm of a Fixnum using Ruby, but found that n.log or n.log10 are not defined. Math::log is defined but uses a different base than 10. What is the easiest way to get the base 10 logarithm of a Fixnum?
There is ``` Math::log10 (n) ``` And there is also a property of logarithms that `logx(y) = log(y)/log(x)`
51,429
<p>Can anyone give me some pointers on how to display the results of an XPath query in a textbox using code (C#)? My datascource <i>seems</i> to (re)bind correctly once the XPath query has been applied, but I cannot find how to get at the resulting data.<br /><br /> Any help would be greatly appreciated.</p>
[ { "answer_id": 51490, "author": "d91-jal", "author_id": 5085, "author_profile": "https://Stackoverflow.com/users/5085", "pm_score": 0, "selected": false, "text": "<p>Some more information would be nice to have to be able to give you a decent answer. Do you have any existing code snippets...
2008/09/09
[ "https://Stackoverflow.com/questions/51429", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
Can anyone give me some pointers on how to display the results of an XPath query in a textbox using code (C#)? My datascource *seems* to (re)bind correctly once the XPath query has been applied, but I cannot find how to get at the resulting data. Any help would be greatly appreciated.
XMLDataSource is designed to be used with data-bound controls. ASP.NET's TextBox is not a data-bound control. So to accomplish what you want you either have to find a textbox control with data binding or display the result in some other way. For example, you could use a [Repeater control](http://msdn.microsoft.com/en...
51,470
<p>In <a href="http://en.wikipedia.org/wiki/PostgreSQL" rel="noreferrer">PostgreSQL</a>, I can do something like this:</p> <pre><code>ALTER SEQUENCE serial RESTART WITH 0; </code></pre> <p>Is there an Oracle equivalent?</p>
[ { "answer_id": 51482, "author": "Mo.", "author_id": 1870, "author_profile": "https://Stackoverflow.com/users/1870", "pm_score": 7, "selected": false, "text": "<p>A true restart is not possible <a href=\"http://en.wiktionary.org/wiki/AFAIK\" rel=\"noreferrer\">AFAIK</a>. (Please correct m...
2008/09/09
[ "https://Stackoverflow.com/questions/51470", "https://Stackoverflow.com", "https://Stackoverflow.com/users/917/" ]
In [PostgreSQL](http://en.wikipedia.org/wiki/PostgreSQL), I can do something like this: ``` ALTER SEQUENCE serial RESTART WITH 0; ``` Is there an Oracle equivalent?
Here is a good procedure for resetting any sequence to 0 from Oracle guru [Tom Kyte](http://asktom.oracle.com). Great discussion on the pros and cons in the links below too. ``` tkyte@TKYTE901.US.ORACLE.COM> create or replace procedure reset_seq( p_seq_name in varchar2 ) is l_val number; begin execute immedia...
51,492
<p>For me <strong>usable</strong> means that:</p> <ul> <li>it's being used in real-wold</li> <li>it has tools support. (at least some simple editor)</li> <li>it has human readable syntax (no angle brackets please) </li> </ul> <p>Also I want it to be as close to XML as possible, i.e. there must be support for attribut...
[ { "answer_id": 51494, "author": "Staale", "author_id": 3355, "author_profile": "https://Stackoverflow.com/users/3355", "pm_score": 4, "selected": false, "text": "<p><a href=\"http://www.json.org/\" rel=\"nofollow noreferrer\">JSON</a> is a very good alternative, and there are tools for i...
2008/09/09
[ "https://Stackoverflow.com/questions/51492", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1196/" ]
For me **usable** means that: * it's being used in real-wold * it has tools support. (at least some simple editor) * it has human readable syntax (no angle brackets please) Also I want it to be as close to XML as possible, i.e. there must be support for attributes as well as for properties. So, no [YAML](http://en.wi...
YAML is a 100% superset of JSON, so it doesn't make sense to reject YAML and then consider JSON instead. YAML does everything JSON does, but YAML gives so much more too (like references). I can't think of anything XML can do that YAML can't, except to validate a document with a DTD, which in my experience has never be...
51,502
<p>I've been really enjoying Python programming lately. I come from a background of a strong love for C-based coding, where everything is perhaps more complicated than it should be (but puts hair on your chest, at least). So switching from C to Python for more complex things that don't require tons of speed has been mo...
[ { "answer_id": 51505, "author": "Anders Sandvig", "author_id": 1709, "author_profile": "https://Stackoverflow.com/users/1709", "pm_score": 3, "selected": false, "text": "<p>You could try increasing the indent size, but in general I would just say, relax, it will come with time. I don't t...
2008/09/09
[ "https://Stackoverflow.com/questions/51502", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5342/" ]
I've been really enjoying Python programming lately. I come from a background of a strong love for C-based coding, where everything is perhaps more complicated than it should be (but puts hair on your chest, at least). So switching from C to Python for more complex things that don't require tons of speed has been more ...
Part of learning a new programming language is learning to read code in that language. A crutch like this may make it easier to read your own code, but it's going to impede the process of learning how to read anyone else's Python code. I really think you'd be better off getting rid of the end of block comments and gett...
51,520
<p>Given a path such as <code>&quot;mydir/myfile.txt&quot;</code>, how do I find the file's absolute path in Python? E.g. on Windows, I might end up with:</p> <pre><code>&quot;C:/example/cwd/mydir/myfile.txt&quot; </code></pre>
[ { "answer_id": 51523, "author": "sherbang", "author_id": 5026, "author_profile": "https://Stackoverflow.com/users/5026", "pm_score": 11, "selected": true, "text": "<pre><code>&gt;&gt;&gt; import os\n&gt;&gt;&gt; os.path.abspath(\"mydir/myfile.txt\")\n'C:/example/cwd/mydir/myfile.txt'\n</...
2008/09/09
[ "https://Stackoverflow.com/questions/51520", "https://Stackoverflow.com", "https://Stackoverflow.com/users/974/" ]
Given a path such as `"mydir/myfile.txt"`, how do I find the file's absolute path in Python? E.g. on Windows, I might end up with: ``` "C:/example/cwd/mydir/myfile.txt" ```
``` >>> import os >>> os.path.abspath("mydir/myfile.txt") 'C:/example/cwd/mydir/myfile.txt' ``` Also works if it is already an absolute path: ``` >>> import os >>> os.path.abspath("C:/example/cwd/mydir/myfile.txt") 'C:/example/cwd/mydir/myfile.txt' ```
51,526
<p>I have a list of structs and I want to change one element. For example :</p> <pre><code>MyList.Add(new MyStruct("john"); MyList.Add(new MyStruct("peter"); </code></pre> <p>Now I want to change one element:</p> <pre><code>MyList[1].Name = "bob" </code></pre> <p>However, whenever I try and do this I get the follow...
[ { "answer_id": 51537, "author": "Andrew", "author_id": 1948, "author_profile": "https://Stackoverflow.com/users/1948", "pm_score": 6, "selected": true, "text": "<pre><code>MyList[1] = new MyStruct(\"bob\");\n</code></pre>\n\n<p>structs in C# should almost always be designed to be immutab...
2008/09/09
[ "https://Stackoverflow.com/questions/51526", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3989/" ]
I have a list of structs and I want to change one element. For example : ``` MyList.Add(new MyStruct("john"); MyList.Add(new MyStruct("peter"); ``` Now I want to change one element: ``` MyList[1].Name = "bob" ``` However, whenever I try and do this I get the following error: > > Cannot modify the return value o...
``` MyList[1] = new MyStruct("bob"); ``` structs in C# should almost always be designed to be immutable (that is, have no way to change their internal state once they have been created). In your case, what you want to do is to replace the entire struct in specified array index, not to try to change just a single pro...
51,553
<p>I need a real DBA's opinion. Postgres 8.3 takes 200 ms to execute this query on my Macbook Pro while Java and Python perform the same calculation in under 20 ms (350,000 rows):</p> <pre><code>SELECT count(id), avg(a), avg(b), avg(c), avg(d) FROM tuples; </code></pre> <p>Is this normal behaviour when using a SQL da...
[ { "answer_id": 51668, "author": "Rob Walker", "author_id": 3631, "author_profile": "https://Stackoverflow.com/users/3631", "pm_score": 1, "selected": false, "text": "<p>I don't think that your results are all that surprising -- if anything it is that Postgres is so fast.</p>\n\n<p>Does t...
2008/09/09
[ "https://Stackoverflow.com/questions/51553", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5357/" ]
I need a real DBA's opinion. Postgres 8.3 takes 200 ms to execute this query on my Macbook Pro while Java and Python perform the same calculation in under 20 ms (350,000 rows): ``` SELECT count(id), avg(a), avg(b), avg(c), avg(d) FROM tuples; ``` Is this normal behaviour when using a SQL database? The schema (the t...
Postgres is doing a lot more than it looks like (maintaining data consistency for a start!) If the values don't have to be 100% spot on, or if the table is updated rarely, but you are running this calculation often, you might want to look into Materialized Views to speed it up. (Note, I have not used materialized vie...
51,572
<p>How does one <strong>reliably</strong> determine a file's type? File extension analysis is not acceptable. There must be a rubyesque tool similar to the UNIX file(1) command?</p> <p>This is regarding MIME or content type, not file system classifications, such as directory, file, or socket.</p>
[ { "answer_id": 51616, "author": "Bobby Jack", "author_id": 5058, "author_profile": "https://Stackoverflow.com/users/5058", "pm_score": -1, "selected": false, "text": "<p>You could give a go with <a href=\"http://mime-types.rubyforge.org/\" rel=\"nofollow noreferrer\">MIME::Types for Ruby...
2008/09/09
[ "https://Stackoverflow.com/questions/51572", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
How does one **reliably** determine a file's type? File extension analysis is not acceptable. There must be a rubyesque tool similar to the UNIX file(1) command? This is regarding MIME or content type, not file system classifications, such as directory, file, or socket.
There is a ruby binding to `libmagic` that does what you need. It is available as a gem named [ruby-filemagic](https://rubygems.org/gems/ruby-filemagic/versions/0.7.1): ``` gem install ruby-filemagic ``` Require `libmagic-dev`. The documentation seems a little thin, but this should get you started: ``` $ irb irb(...
51,582
<p>Let's say I have the following class:</p> <pre><code>public class Test&lt;E&gt; { public boolean sameClassAs(Object o) { // TODO help! } } </code></pre> <p>How would I check that <code>o</code> is the same class as <code>E</code>?</p> <pre><code>Test&lt;String&gt; test = new Test&lt;String&gt;(); ...
[ { "answer_id": 51603, "author": "Slartibartfast", "author_id": 4433, "author_profile": "https://Stackoverflow.com/users/4433", "pm_score": 2, "selected": false, "text": "<p>I could only make it working like this:</p>\n\n<pre><code>public class Test&lt;E&gt; { \n\n private E e; \n\n ...
2008/09/09
[ "https://Stackoverflow.com/questions/51582", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1666/" ]
Let's say I have the following class: ``` public class Test<E> { public boolean sameClassAs(Object o) { // TODO help! } } ``` How would I check that `o` is the same class as `E`? ``` Test<String> test = new Test<String>(); test.sameClassAs("a string"); // returns true; test.sameClassAs(4); // return...
An instance of `Test` has no information as to what `E` is at runtime. So, you need to pass a `Class<E>` to the constructor of Test. ``` public class Test<E> { private final Class<E> clazz; public Test(Class<E> clazz) { if (clazz == null) { throw new NullPointerException(); } ...
51,586
<p>Is there a way to collect (e.g. in a List) multiple 'generic' objects that don't share a common super class? If so, how can I access their common properties?</p> <p>For example:</p> <pre><code>class MyObject&lt;T&gt; { public T Value { get; set; } public string Name { get; set; } public MyObject(string n...
[ { "answer_id": 51611, "author": "aku", "author_id": 1196, "author_profile": "https://Stackoverflow.com/users/1196", "pm_score": 2, "selected": false, "text": "<p>C# doesn't support duck typing. You have 2 choices: interfaces and inheritance, otherwise you can't access similar properties ...
2008/09/09
[ "https://Stackoverflow.com/questions/51586", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2597/" ]
Is there a way to collect (e.g. in a List) multiple 'generic' objects that don't share a common super class? If so, how can I access their common properties? For example: ``` class MyObject<T> { public T Value { get; set; } public string Name { get; set; } public MyObject(string name, T value) { Na...
I don't think it is possible in C#, because MyObject is not a baseclass of MyObject. What I usually do is to define an interface (a 'normal' one, not generic) and make MyObject implement that interface, e.g. ``` interface INamedObject { string Name {get;} } ``` and then you can use the interface: ``` List<IName...
51,593
<p>What is the easiest way to extract the original exception from an exception returned via Apache's implementation of XML-RPC?</p>
[ { "answer_id": 52995, "author": "ScArcher2", "author_id": 1310, "author_profile": "https://Stackoverflow.com/users/1310", "pm_score": 1, "selected": false, "text": "<p>According to the <a href=\"http://www.xmlrpc.com/spec\" rel=\"nofollow noreferrer\">XML-RPC Spec</a> it returns the \"fa...
2008/09/09
[ "https://Stackoverflow.com/questions/51593", "https://Stackoverflow.com", "https://Stackoverflow.com/users/279/" ]
What is the easiest way to extract the original exception from an exception returned via Apache's implementation of XML-RPC?
It turns out that getting the cause exception from the Apache exception is the right one. ``` } catch (XmlRpcException rpce) { Throwable cause = rpce.getCause(); if(cause != null) { if(cause instanceof ExceptionYouCanHandleException) { handler(cause); } else { throw(cause);...
51,645
<p>How can I discover any USB storage devices and/or CD/DVD writers available at a given time (using C# .Net2.0).</p> <p>I would like to present users with a choice of devices onto which a file can be stored for physically removal - i.e. not the hard drive.</p>
[ { "answer_id": 51656, "author": "sven", "author_id": 46, "author_profile": "https://Stackoverflow.com/users/46", "pm_score": 1, "selected": false, "text": "<p>this is VB.NET code to check for any removable drives or CDRom drives attached to the computer:</p>\n\n<pre><code>Me.lstDrives.It...
2008/09/09
[ "https://Stackoverflow.com/questions/51645", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5019/" ]
How can I discover any USB storage devices and/or CD/DVD writers available at a given time (using C# .Net2.0). I would like to present users with a choice of devices onto which a file can be stored for physically removal - i.e. not the hard drive.
``` using System.IO; DriveInfo[] allDrives = DriveInfo.GetDrives(); foreach (DriveInfo d in allDrives) { if (d.IsReady && d.DriveType == DriveType.Removable) { // This is the drive you want... } } ``` The DriveInfo class documentation is here: <http://msdn.microsoft.com/en-us/library/system.io.driveinfo.a...
51,654
<p>I have the situation where i use GIS software which stores the information about GIS objects into separate database table for each type/class of GIS object (road, river, building, sea, ...) and keeps the metadata table in which it stores info about the class name and its DB table.</p> <p>Those GIS objects of differ...
[ { "answer_id": 51683, "author": "lomaxx", "author_id": 493, "author_profile": "https://Stackoverflow.com/users/493", "pm_score": 0, "selected": false, "text": "<p>one way you could do it is to declare an interface say IGisObject that has the common properties declared on the interface. T...
2008/09/09
[ "https://Stackoverflow.com/questions/51654", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4723/" ]
I have the situation where i use GIS software which stores the information about GIS objects into separate database table for each type/class of GIS object (road, river, building, sea, ...) and keeps the metadata table in which it stores info about the class name and its DB table. Those GIS objects of different classe...
@Brian Chiasson Unfortunately, it's not an option to create all classes of GIS data because classes are created dynamically in the application. Every GIS data of the same type should be a class, but my user has the possibility to get new set of data and put it in the database. I can't know in front which classes my us...
51,658
<p>I need a way to determine the space remaining on a disk volume using python on linux, Windows and OS X. I'm currently parsing the output of the various system calls (df, dir) to accomplish this - is there a better way?</p>
[ { "answer_id": 51663, "author": "Greg Hewgill", "author_id": 893, "author_profile": "https://Stackoverflow.com/users/893", "pm_score": 1, "selected": false, "text": "<p>The <a href=\"https://docs.python.org/2.7/library/os.html\" rel=\"nofollow noreferrer\">os.statvfs()</a> function is a ...
2008/09/09
[ "https://Stackoverflow.com/questions/51658", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I need a way to determine the space remaining on a disk volume using python on linux, Windows and OS X. I'm currently parsing the output of the various system calls (df, dir) to accomplish this - is there a better way?
``` import ctypes import os import platform import sys def get_free_space_mb(dirname): """Return folder/drive free space (in megabytes).""" if platform.system() == 'Windows': free_bytes = ctypes.c_ulonglong(0) ctypes.windll.kernel32.GetDiskFreeSpaceExW(ctypes.c_wchar_p(dirname), None, None, cty...
51,684
<p>I have a <a href="http://www.samurize.com/modules/news/" rel="noreferrer">Samurize</a> config that shows a CPU usage graph similar to Task manager. </p> <p>How do I also display the name of the process with the current highest CPU usage percentage? </p> <p>I would like this to be updated, at most, once per secon...
[ { "answer_id": 51705, "author": "hasseg", "author_id": 4111, "author_profile": "https://Stackoverflow.com/users/4111", "pm_score": 1, "selected": false, "text": "<p>You might be able to use <a href=\"http://commandwindows.com/server2003tools.htm\" rel=\"nofollow noreferrer\">Pmon.exe</a>...
2008/09/09
[ "https://Stackoverflow.com/questions/51684", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5023/" ]
I have a [Samurize](http://www.samurize.com/modules/news/) config that shows a CPU usage graph similar to Task manager. How do I also display the name of the process with the current highest CPU usage percentage? I would like this to be updated, at most, once per second. Samurize can call a command line tool and di...
With PowerShell: ``` Get-Process | Sort-Object CPU -desc | Select-Object -first 3 | Format-Table CPU,ProcessName -hidetableheader ``` returns somewhat like: ``` 16.8641632 System 12.548072 csrss 11.9892168 powershell ```
51,686
<p>Is it possible to deploy a native Delphi application with ClickOnce without a stub C# exe that would be used to launch the Delphi application?</p> <p>The same question applies to VB6, C++ and other native Windows applications.</p>
[ { "answer_id": 51691, "author": "DaveK", "author_id": 4244, "author_profile": "https://Stackoverflow.com/users/4244", "pm_score": 1, "selected": false, "text": "<p>I'm not 100% sure if this can be accomplished without the stub, but this article may provide some insight:</p>\n\n<p><a href...
2008/09/09
[ "https://Stackoverflow.com/questions/51686", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5362/" ]
Is it possible to deploy a native Delphi application with ClickOnce without a stub C# exe that would be used to launch the Delphi application? The same question applies to VB6, C++ and other native Windows applications.
Personally, I build my own mechanism to kick off self update process when my application timestamp is out of sync with the server. Not too difficult, but it's not a simple task. By the way, for Delphi you can use some thirdparty help: <http://www.tmssoftware.com/site/wupdate.asp> UPDATED: For my implementation: My...
51,687
<p>Has anyone implemented Lightbox style background dimming on a modal dialog box in a MFC/non .net app.<br> I think the procedure would have to be something like:</p> <p>steps:</p> <ol> <li><p>Get dialog parent HWND or CWnd* </p></li> <li><p>Get the rect of the parent window and draw an overlay with a translucen...
[ { "answer_id": 51979, "author": "Brian Lyttle", "author_id": 636, "author_profile": "https://Stackoverflow.com/users/636", "pm_score": 2, "selected": false, "text": "<p>I think you just need to create a window and set the transparency. There is an MFC <a href=\"http://www.codeproject.com...
2008/09/09
[ "https://Stackoverflow.com/questions/51687", "https://Stackoverflow.com", "https://Stackoverflow.com/users/379/" ]
Has anyone implemented Lightbox style background dimming on a modal dialog box in a MFC/non .net app. I think the procedure would have to be something like: steps: 1. Get dialog parent HWND or CWnd\* 2. Get the rect of the parent window and draw an overlay with a translucency over that window 3. allow the dialog t...
Here's what I did\* based on Brian's links First create a dialog resource with the properties: * border **FALSE** * 3D look **FALSE** * client edge **FALSE** * Popup style * static edge **FALSE** * Transparent **TRUE** * Title bar **FALSE** and you should end up with a dialog window with no frame or anything, just...
51,690
<p>Recently I got IE7 crashed on Vista on jar loading (presumably) with the following error:</p> <pre><code>Problem signature: Problem Event Name: BEX Application Name: iexplore.exe Application Version: 7.0.6001.18000 Application Timestamp: 47918f11 Fault Module Name: ntdll....
[ { "answer_id": 166316, "author": "MSalters", "author_id": 15416, "author_profile": "https://Stackoverflow.com/users/15416", "pm_score": 3, "selected": true, "text": "<p>BEX=Buffer overflow exception. See <a href=\"http://technet.microsoft.com/en-us/library/cc738483.aspx\" rel=\"nofollow ...
2008/09/09
[ "https://Stackoverflow.com/questions/51690", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5383/" ]
Recently I got IE7 crashed on Vista on jar loading (presumably) with the following error: ``` Problem signature: Problem Event Name: BEX Application Name: iexplore.exe Application Version: 7.0.6001.18000 Application Timestamp: 47918f11 Fault Module Name: ntdll.dll Fault Mo...
BEX=Buffer overflow exception. See <http://technet.microsoft.com/en-us/library/cc738483.aspx> for details. However, c000000d is STATUS\_INVALID\_PARAMETER; the technet article talks primarily about status c0000005 or c0000409 (access violation/DEP)
51,700
<p>I am using .Net 2 and the normal way to store my settings. I store my custom object serialized to xml. I am trying to retrieve the default value of the property (but without reseting other properties). I use:</p> <pre><code>ValuationInput valuationInput = (ValuationInput) Settings.Default.Properties["ValuationInput...
[ { "answer_id": 166316, "author": "MSalters", "author_id": 15416, "author_profile": "https://Stackoverflow.com/users/15416", "pm_score": 3, "selected": true, "text": "<p>BEX=Buffer overflow exception. See <a href=\"http://technet.microsoft.com/en-us/library/cc738483.aspx\" rel=\"nofollow ...
2008/09/09
[ "https://Stackoverflow.com/questions/51700", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5363/" ]
I am using .Net 2 and the normal way to store my settings. I store my custom object serialized to xml. I am trying to retrieve the default value of the property (but without reseting other properties). I use: ``` ValuationInput valuationInput = (ValuationInput) Settings.Default.Properties["ValuationInput"].DefaultValu...
BEX=Buffer overflow exception. See <http://technet.microsoft.com/en-us/library/cc738483.aspx> for details. However, c000000d is STATUS\_INVALID\_PARAMETER; the technet article talks primarily about status c0000005 or c0000409 (access violation/DEP)
51,741
<p>I was given an .xml file that I needed to read into my code as a DataSet (as background, the file was created by creating a <code>DataSet</code> in C# and calling <code>dataSet.WriteXml(file, XmlWriteMode.IgnoreSchema)</code>, but this was done by someone else). </p> <p>The .xml file was shaped like this:</p> <pre...
[ { "answer_id": 51777, "author": "rohancragg", "author_id": 5351, "author_profile": "https://Stackoverflow.com/users/5351", "pm_score": 0, "selected": false, "text": "<p>These are my observations rather than a full answer:</p>\n\n<p>My guess (without trying to re-produce it myself) is tha...
2008/09/09
[ "https://Stackoverflow.com/questions/51741", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4660/" ]
I was given an .xml file that I needed to read into my code as a DataSet (as background, the file was created by creating a `DataSet` in C# and calling `dataSet.WriteXml(file, XmlWriteMode.IgnoreSchema)`, but this was done by someone else). The .xml file was shaped like this: ``` <?xml version="1.0" standalone="yes...
This appears to be correct for your *nested* Foo tags: ``` <NewDataSet> <Foo> <!-- Foo-Id: 0 --> <Bar>abcd</Bar> <Foo>efg</Foo> <!-- Foo-Id: 1, Parent-Id: 0 --> </Foo> <Foo> <!-- Foo-Id: 2 --> <Bar>hijk</Bar> <Foo>lmn</Foo> <!-- Foo-Id: 3, Parent-Id: 2 --> </Foo>...
51,751
<p>I have a ASP.Net website that is failing on AJAX postbacks (both with ASP.Net AJAX and a 3rd part control) in IE. FireFox works fine. If I install the website on another machine without .Net 3.5 SP1, it works as expected.</p> <p>When it fails, Fiddler shows that I'm getting a 405 "Method Not Allowed". The form...
[ { "answer_id": 51777, "author": "rohancragg", "author_id": 5351, "author_profile": "https://Stackoverflow.com/users/5351", "pm_score": 0, "selected": false, "text": "<p>These are my observations rather than a full answer:</p>\n\n<p>My guess (without trying to re-produce it myself) is tha...
2008/09/09
[ "https://Stackoverflow.com/questions/51751", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5389/" ]
I have a ASP.Net website that is failing on AJAX postbacks (both with ASP.Net AJAX and a 3rd part control) in IE. FireFox works fine. If I install the website on another machine without .Net 3.5 SP1, it works as expected. When it fails, Fiddler shows that I'm getting a 405 "Method Not Allowed". The form seems to be po...
This appears to be correct for your *nested* Foo tags: ``` <NewDataSet> <Foo> <!-- Foo-Id: 0 --> <Bar>abcd</Bar> <Foo>efg</Foo> <!-- Foo-Id: 1, Parent-Id: 0 --> </Foo> <Foo> <!-- Foo-Id: 2 --> <Bar>hijk</Bar> <Foo>lmn</Foo> <!-- Foo-Id: 3, Parent-Id: 2 --> </Foo>...
51,768
<p>As part of some error handling in our product, we'd like to dump some stack trace information. However, we experience that many users will simply take a screenshot of the error message dialog instead of sending us a copy of the full report available from the program, and thus I'd like to make some minimal stack trac...
[ { "answer_id": 51803, "author": "Curt Hagenlocher", "author_id": 533, "author_profile": "https://Stackoverflow.com/users/533", "pm_score": 7, "selected": true, "text": "<p>You should be able to get a StackTrace object instead of a string by saying</p>\n\n<pre><code>var trace = new System...
2008/09/09
[ "https://Stackoverflow.com/questions/51768", "https://Stackoverflow.com", "https://Stackoverflow.com/users/267/" ]
As part of some error handling in our product, we'd like to dump some stack trace information. However, we experience that many users will simply take a screenshot of the error message dialog instead of sending us a copy of the full report available from the program, and thus I'd like to make some minimal stack trace i...
You should be able to get a StackTrace object instead of a string by saying ``` var trace = new System.Diagnostics.StackTrace(exception); ``` You can then look at the frames yourself without relying on the framework's formatting. See also: [StackTrace reference](http://msdn.microsoft.com/en-us/library/system.diagno...
51,781
<p>I have a variable of type <code>Dynamic</code> and I know for sure one of its fields, lets call it <code>a</code>, actually is an array. But when I'm writing </p> <pre><code>var d : Dynamic = getDynamic(); for (t in d.a) { } </code></pre> <p>I get a compilation error on line two:</p> <blockquote> <p>You can't i...
[ { "answer_id": 51802, "author": "Danny Wilson", "author_id": 5364, "author_profile": "https://Stackoverflow.com/users/5364", "pm_score": 4, "selected": true, "text": "<p>Haxe can't iterate over <code>Dynamic</code> variables (as the compiler says).</p>\n\n<p>You can make it work in sever...
2008/09/09
[ "https://Stackoverflow.com/questions/51781", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I have a variable of type `Dynamic` and I know for sure one of its fields, lets call it `a`, actually is an array. But when I'm writing ``` var d : Dynamic = getDynamic(); for (t in d.a) { } ``` I get a compilation error on line two: > > You can't iterate on a Dynamic value, please specify Iterator or Iterable > ...
Haxe can't iterate over `Dynamic` variables (as the compiler says). You can make it work in several ways, where this one is probably easiest (depending on your situation): ``` var d : {a:Array<Dynamic>} = getDynamic(); for (t in d.a) { ... } ``` You could also change `Dynamic` to the type of the contents of the arr...
51,783
<p>Flat files and relational databases give us a mechanism to serialize structured data. XML is superb for serializing un-structured tree-like data.</p> <p>But many problems are best represented by graphs. A thermal simulation program will, for instance, work with temperature nodes connected to each others through res...
[ { "answer_id": 51794, "author": "jodonnell", "author_id": 4223, "author_profile": "https://Stackoverflow.com/users/4223", "pm_score": 3, "selected": false, "text": "<p>XML is very verbose. Whenever I do it, I roll my own. Here's an example of a 3 node directed acyclic graph. It's pret...
2008/09/09
[ "https://Stackoverflow.com/questions/51783", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1428/" ]
Flat files and relational databases give us a mechanism to serialize structured data. XML is superb for serializing un-structured tree-like data. But many problems are best represented by graphs. A thermal simulation program will, for instance, work with temperature nodes connected to each others through resistive edg...
How do you represent your graph in memory? Basically you have two (good) options: * [an adjacency list representation](http://en.wikipedia.org/wiki/Adjacency_list) * [an adjacency matrix representation](http://en.wikipedia.org/wiki/Adjacency_matrix) in which the adjacency list representation is best used for a spa...
51,786
<p>How can I generate UML diagrams (especially sequence diagrams) from existing Java code?</p>
[ { "answer_id": 51864, "author": "prakash", "author_id": 123, "author_profile": "https://Stackoverflow.com/users/123", "pm_score": 5, "selected": false, "text": "<p>What is your codebase? Java or C++?</p>\n\n<p><a href=\"http://marketplace.eclipse.org/content/euml2-free-edition\" rel=\"no...
2008/09/09
[ "https://Stackoverflow.com/questions/51786", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1772/" ]
How can I generate UML diagrams (especially sequence diagrams) from existing Java code?
[ObjectAid UML Explorer](http://www.objectaid.com/home) ======================================================= Is what I used. It is easily **[installed](https://www.objectaid.com/install-objectaid)** from the repository: ``` Name: ObjectAid UML Explorer Location: http://www.objectaid.com/update/current ``` An...
51,827
<p>I want to ask how other programmers are producing Dynamic SQL strings for execution as the CommandText of a SQLCommand object.</p> <p>I am producing parameterized queries containing user-generated WHERE clauses and SELECT fields. Sometimes the queries are complex and I need a lot of control over how the different p...
[ { "answer_id": 51839, "author": "Ryan Lanciaux", "author_id": 1385358, "author_profile": "https://Stackoverflow.com/users/1385358", "pm_score": 0, "selected": false, "text": "<p>Out of curiousity, have you considered using an ORM for managing your data access. A lot of the functionality ...
2008/09/09
[ "https://Stackoverflow.com/questions/51827", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5197/" ]
I want to ask how other programmers are producing Dynamic SQL strings for execution as the CommandText of a SQLCommand object. I am producing parameterized queries containing user-generated WHERE clauses and SELECT fields. Sometimes the queries are complex and I need a lot of control over how the different parts are b...
I had the need to do this on one of my recent projects. Here is the scheme that I am using for generating the SQL: * Each component of the query is represented by an Object (which in my case is a Linq-to-Sql entity that maps to a table in the DB). So I have the following classes: Query, SelectColumn, Join, WhereCondi...
51,837
<p>I have up to 4 files based on this structure (note the prefixes are dates)</p> <ul> <li>0830filename.txt</li> <li>0907filename.txt</li> <li>0914filename.txt</li> <li>0921filename.txt</li> </ul> <p>I want to open the the most recent one (0921filename.txt). how can i do this in a batch file?</p> <p>Thanks.</p>
[ { "answer_id": 51861, "author": "Graviton", "author_id": 3834, "author_profile": "https://Stackoverflow.com/users/3834", "pm_score": -1, "selected": false, "text": "<p>Use regular expression to parse the relevant integer out and compare them.</p>\n" }, { "answer_id": 51868, "...
2008/09/09
[ "https://Stackoverflow.com/questions/51837", "https://Stackoverflow.com", "https://Stackoverflow.com/users/730/" ]
I have up to 4 files based on this structure (note the prefixes are dates) * 0830filename.txt * 0907filename.txt * 0914filename.txt * 0921filename.txt I want to open the the most recent one (0921filename.txt). how can i do this in a batch file? Thanks.
This method uses the actual file modification date, to figure out which one is the latest file: ``` @echo off for /F %%i in ('dir /B /O:-D *.txt') do ( call :open "%%i" exit /B 0 ) :open start "dummy" "%~1" exit /B 0 ``` This method, however, chooses the last file in alphabetic order (or the first one, i...
51,927
<p>How do I figure out if an array contains an element? I thought there might be something like <code>[1, 2, 3].includes(1)</code> which would evaluate as <code>true</code>.</p>
[ { "answer_id": 51951, "author": "banderson623", "author_id": 5419, "author_profile": "https://Stackoverflow.com/users/5419", "pm_score": 6, "selected": false, "text": "<p>For lists, use <code>contains</code>:</p>\n\n<pre><code>[1,2,3].contains(1) == true\n</code></pre>\n" }, { "a...
2008/09/09
[ "https://Stackoverflow.com/questions/51927", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5419/" ]
How do I figure out if an array contains an element? I thought there might be something like `[1, 2, 3].includes(1)` which would evaluate as `true`.
.contains() is the best method for lists, but for maps you will need to use .containsKey() or .containsValue() ``` [a:1,b:2,c:3].containsValue(3) [a:1,b:2,c:3].containsKey('a') ```
51,931
<p>I'm having a problem running a T4 template using TextTransform.exe on my build server. On my dev machine the template works perfectly. The error message is as follows.</p> <blockquote> <p>error : Running transformation: System.TypeLoadException: Could not instantiate type System.Xml.Linq.XDocument</p> </blockquot...
[ { "answer_id": 51951, "author": "banderson623", "author_id": 5419, "author_profile": "https://Stackoverflow.com/users/5419", "pm_score": 6, "selected": false, "text": "<p>For lists, use <code>contains</code>:</p>\n\n<pre><code>[1,2,3].contains(1) == true\n</code></pre>\n" }, { "a...
2008/09/09
[ "https://Stackoverflow.com/questions/51931", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2086/" ]
I'm having a problem running a T4 template using TextTransform.exe on my build server. On my dev machine the template works perfectly. The error message is as follows. > > error : Running transformation: System.TypeLoadException: Could not instantiate type System.Xml.Linq.XDocument > > > The build server has the ...
.contains() is the best method for lists, but for maps you will need to use .containsKey() or .containsValue() ``` [a:1,b:2,c:3].containsValue(3) [a:1,b:2,c:3].containsKey('a') ```
51,941
<p>I have created a database report generator in Excel. I am trying to create a dialog box that displays status information as the program runs.</p> <p>When I generate the report, although the dialog box appears, I cannot refresh/update the information it displays. Most of the time, the dialog box only partially appea...
[ { "answer_id": 51946, "author": "Gulzar Nazim", "author_id": 4337, "author_profile": "https://Stackoverflow.com/users/4337", "pm_score": 0, "selected": false, "text": "<p>The dialog box is also running on the same UI thread. So, it is too busy to repaint itself. Not sure if VBA has good ...
2008/09/09
[ "https://Stackoverflow.com/questions/51941", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2665/" ]
I have created a database report generator in Excel. I am trying to create a dialog box that displays status information as the program runs. When I generate the report, although the dialog box appears, I cannot refresh/update the information it displays. Most of the time, the dialog box only partially appears. I have...
The code below works well when performing actions within Excel (XP or later). For actions that take place outside Excel, for example connecting to a database and retrieving data the best this offers is the opportunity to show dialogs before and after the action (e.g. *"Getting data"*, *"Got data"*) Create a form call...
51,950
<p>I would like my Core assembly to not expose a certain class and I would still like to be able to test it. How can I do that ?</p>
[ { "answer_id": 51958, "author": "aku", "author_id": 1196, "author_profile": "https://Stackoverflow.com/users/1196", "pm_score": 8, "selected": true, "text": "<p><a href=\"http://msdn.microsoft.com/en-us/library/system.runtime.compilerservices.internalsvisibletoattribute(VS.80).aspx\" rel...
2008/09/09
[ "https://Stackoverflow.com/questions/51950", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4694/" ]
I would like my Core assembly to not expose a certain class and I would still like to be able to test it. How can I do that ?
[InternalsVisibleTo](http://msdn.microsoft.com/en-us/library/system.runtime.compilerservices.internalsvisibletoattribute(VS.80).aspx) attribute to the rescue! Just add: ``` [assembly:InternalsVisibleToAttribute("UnitTestAssemblyName")] ``` to your Core classes AssemblyInfo.cs file See [Friend Assemblies (C# Progr...
51,964
<p>In my base page I need to remove an item from the query string and redirect. I can't use<br/></p> <pre><code>Request.QueryString.Remove("foo") </code></pre> <p>because the collection is read-only. Is there any way to get the query string (except for that one item) without iterating through the collection and re-bu...
[ { "answer_id": 51981, "author": "hollystyles", "author_id": 2083160, "author_profile": "https://Stackoverflow.com/users/2083160", "pm_score": 2, "selected": false, "text": "<pre><code>Response.Redirect(String.Format(\"nextpage.aspx?{0}\", Request.QueryString.ToString().Replace(\"foo\", \...
2008/09/09
[ "https://Stackoverflow.com/questions/51964", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2757/" ]
In my base page I need to remove an item from the query string and redirect. I can't use ``` Request.QueryString.Remove("foo") ``` because the collection is read-only. Is there any way to get the query string (except for that one item) without iterating through the collection and re-building it?
You'd have to reconstruct the url and then redirect. Something like this: ``` string url = Request.RawUrl; NameValueCollection params = Request.QueryString; for (int i=0; i<params.Count; i++) { if (params[i].GetKey(i).ToLower() == "foo") { url += string.Concat((i==0 ? "?" : "&"), params[i].GetKey(i), ...
51,969
<p>In Microsoft SQL Server, is there a way to detect whether a database has had its isolation level set via the T-SQL command <code>ALTER DATABASE &lt;database&gt; SET READ_COMMITTED_SNAPSHOT ON;</code>?</p> <p>I cannot find a simple way to detect this in either T-SQL or via the Management Studio's GUI.</p>
[ { "answer_id": 51977, "author": "Galwegian", "author_id": 3201, "author_profile": "https://Stackoverflow.com/users/3201", "pm_score": 9, "selected": true, "text": "<pre><code>SELECT is_read_committed_snapshot_on FROM sys.databases \nWHERE name= 'YourDatabase'\n</code></pre>\n<p>Return va...
2008/09/09
[ "https://Stackoverflow.com/questions/51969", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5217/" ]
In Microsoft SQL Server, is there a way to detect whether a database has had its isolation level set via the T-SQL command `ALTER DATABASE <database> SET READ_COMMITTED_SNAPSHOT ON;`? I cannot find a simple way to detect this in either T-SQL or via the Management Studio's GUI.
``` SELECT is_read_committed_snapshot_on FROM sys.databases WHERE name= 'YourDatabase' ``` Return value: * **1**: `READ_COMMITTED_SNAPSHOT` option is **ON**. Read operations under the `READ COMMITTED` isolation level are based on snapshot scans and do not acquire locks. * **0** (default): `READ_COMMITTED_SNAPSHOT` ...
52,002
<p><strong>Definition:</strong></p> <p><em>A palindrome is a word, phrase, number or other sequence of units that has the property of reading the same in either direction</em></p> <p>How to check if the given string is a palindrome?</p> <p>This was one of the FAIQ [Frequently Asked Interview Question] a while ago bu...
[ { "answer_id": 52013, "author": "Ryan Ahearn", "author_id": 75, "author_profile": "https://Stackoverflow.com/users/75", "pm_score": 2, "selected": false, "text": "<pre><code>boolean isPalindrome(String str1) {\n //first strip out punctuation and spaces\n String stripped = str1.replaceA...
2008/09/09
[ "https://Stackoverflow.com/questions/52002", "https://Stackoverflow.com", "https://Stackoverflow.com/users/123/" ]
**Definition:** *A palindrome is a word, phrase, number or other sequence of units that has the property of reading the same in either direction* How to check if the given string is a palindrome? This was one of the FAIQ [Frequently Asked Interview Question] a while ago but that mostly using C. Looking for solution...
**PHP sample**: ``` $string = "A man, a plan, a canal, Panama"; function is_palindrome($string) { $a = strtolower(preg_replace("/[^A-Za-z0-9]/","",$string)); return $a==strrev($a); } ``` Removes any non-alphanumeric characters (spaces, commas, exclamation points, etc.) to allow for full sentences as above, ...
52,008
<p>I need to design a small project for generating excel reports in .NET, which will be sent to users to use.</p> <p>The excel reports will contain PivotTables.</p> <p>I don't have much experience with them, but I can think of three implementation alternatives:</p> <ol> <li>Set a query for it, populate it, send it d...
[ { "answer_id": 52013, "author": "Ryan Ahearn", "author_id": 75, "author_profile": "https://Stackoverflow.com/users/75", "pm_score": 2, "selected": false, "text": "<pre><code>boolean isPalindrome(String str1) {\n //first strip out punctuation and spaces\n String stripped = str1.replaceA...
2008/09/09
[ "https://Stackoverflow.com/questions/52008", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1782/" ]
I need to design a small project for generating excel reports in .NET, which will be sent to users to use. The excel reports will contain PivotTables. I don't have much experience with them, but I can think of three implementation alternatives: 1. Set a query for it, populate it, send it disconnected. This way the u...
**PHP sample**: ``` $string = "A man, a plan, a canal, Panama"; function is_palindrome($string) { $a = strtolower(preg_replace("/[^A-Za-z0-9]/","",$string)); return $a==strrev($a); } ``` Removes any non-alphanumeric characters (spaces, commas, exclamation points, etc.) to allow for full sentences as above, ...
52,080
<p>How can I build a loop in JavaScript?</p>
[ { "answer_id": 52083, "author": "UnkwnTech", "author_id": 115, "author_profile": "https://Stackoverflow.com/users/115", "pm_score": -1, "selected": false, "text": "<p>A loop in JavaScript looks like this:</p>\n\n<pre><code>for (var = startvalue; var &lt;= endvalue; var = var + increment)...
2008/09/09
[ "https://Stackoverflow.com/questions/52080", "https://Stackoverflow.com", "https://Stackoverflow.com/users/115/" ]
How can I build a loop in JavaScript?
**For loops** ``` for (i = startValue; i <= endValue; i++) { // Before the loop: i is set to startValue // After each iteration of the loop: i++ is executed // The loop continues as long as i <= endValue is true } ``` **For...in loops** ``` for (i in things) { // If things is an array, i will usuall...
52,084
<p>There is a field in my company's "Contacts" table. In that table, there is an XML type column. The column holds misc data about a particular contact. EG. </p> <pre><code>&lt;contact&gt; &lt;refno&gt;123456&lt;/refno&gt; &lt;special&gt;a piece of custom data&lt;/special&gt; &lt;/contact&gt; </code></pre> <p>The tag...
[ { "answer_id": 52097, "author": "Paulj", "author_id": 5433, "author_profile": "https://Stackoverflow.com/users/5433", "pm_score": 2, "selected": true, "text": "<p>I've found the msdn xml best practices helpful for working with xml blob columns, might provide some inspiration...\n<a href=...
2008/09/09
[ "https://Stackoverflow.com/questions/52084", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5197/" ]
There is a field in my company's "Contacts" table. In that table, there is an XML type column. The column holds misc data about a particular contact. EG. ``` <contact> <refno>123456</refno> <special>a piece of custom data</special> </contact> ``` The tags below `contact` can be different for each contact, and I mus...
I've found the msdn xml best practices helpful for working with xml blob columns, might provide some inspiration... <http://msdn.microsoft.com/en-us/library/ms345115.aspx#sql25xmlbp_topic4>
52,160
<p>How can you obtain the Type (the name as a string is sufficient) of an Object in VB6 at runtime?</p> <p>i.e. something like:</p> <pre><code>If Typeof(foobar) = "CommandButton" Then ... </code></pre> <p><strong>/EDIT:</strong> to clarify, I need to check on Dynamically Typed objects. An example:</p> <pre><code>Di...
[ { "answer_id": 52181, "author": "Daren Thomas", "author_id": 2260, "author_profile": "https://Stackoverflow.com/users/2260", "pm_score": 0, "selected": false, "text": "<p>This should prove difficult, since in VB6 all objects are COM (<code>IDispatch</code>) things. Thus they are only an ...
2008/09/09
[ "https://Stackoverflow.com/questions/52160", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1111/" ]
How can you obtain the Type (the name as a string is sufficient) of an Object in VB6 at runtime? i.e. something like: ``` If Typeof(foobar) = "CommandButton" Then ... ``` **/EDIT:** to clarify, I need to check on Dynamically Typed objects. An example: ``` Dim y As Object Set y = CreateObject("SomeType") Debug.P...
I think what you are looking for is TypeName rather than TypeOf. ``` If TypeName(foobar) = "CommandButton" Then DoSomething End If ``` Edit: What do you mean Dynamic Objects? Do you mean objects created with CreateObject(""), cause that should still work. Edit: ``` Private Sub Command1_Click() Dim oObject ...
52,213
<p>When a user hits Refresh on their browser, it reloads the page but keeps the contents of form fields. While I can see this being a useful default, it can be annoying on some dynamic pages, leading to a broken user experience.</p> <p>Is there a way, in HTTP headers or equivalents, to change this behaviour?</p>
[ { "answer_id": 52221, "author": "Edward Wilde", "author_id": 5182, "author_profile": "https://Stackoverflow.com/users/5182", "pm_score": 2, "selected": false, "text": "<p>You could call the reset() method of the forms object from the body load event of your html document to clear the for...
2008/09/09
[ "https://Stackoverflow.com/questions/52213", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1000/" ]
When a user hits Refresh on their browser, it reloads the page but keeps the contents of form fields. While I can see this being a useful default, it can be annoying on some dynamic pages, leading to a broken user experience. Is there a way, in HTTP headers or equivalents, to change this behaviour?
``` <input autocomplete="off"> ```
52,234
<p>Creating a patch is very easy in SubVersion, With Tortoise, you right-click and select Create Patch. But for the life of me, I can't find this functionality in TFS. Is this possible?</p> <p>If not, what's the standard way to submit patches in open source TFS hosted projects (a la CodePlex)?</p>
[ { "answer_id": 52242, "author": "Curt Hagenlocher", "author_id": 533, "author_profile": "https://Stackoverflow.com/users/533", "pm_score": 7, "selected": true, "text": "<pre><code>tf diff /shelveset:shelveset /format:unified\n</code></pre>\n\n<p><strong>Edit:</strong> This writes to stan...
2008/09/09
[ "https://Stackoverflow.com/questions/52234", "https://Stackoverflow.com", "https://Stackoverflow.com/users/736/" ]
Creating a patch is very easy in SubVersion, With Tortoise, you right-click and select Create Patch. But for the life of me, I can't find this functionality in TFS. Is this possible? If not, what's the standard way to submit patches in open source TFS hosted projects (a la CodePlex)?
``` tf diff /shelveset:shelveset /format:unified ``` **Edit:** This writes to standard output. You can pipe the output to a file. For more options, see [Difference Command](http://msdn.microsoft.com/en-us/library/6fd7dc73%28v=vs.100%29.aspx).
52,238
<p>How can I use the Prototype library and create unobtrusive javascript to inject the onmouseover and onmouseout events to each row, rather than putting the javascript in each table row tag?</p> <p>An answer utilizing the Prototype library (instead of mootools, jQuery, etc) would be most helpful.</p>
[ { "answer_id": 52250, "author": "pix0r", "author_id": 72, "author_profile": "https://Stackoverflow.com/users/72", "pm_score": 3, "selected": false, "text": "<p>You can use Prototype's <code>addClassName</code> and <code>removeClassName</code> methods.</p>\n\n<p>Create a CSS class \"hilig...
2008/09/09
[ "https://Stackoverflow.com/questions/52238", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3920/" ]
How can I use the Prototype library and create unobtrusive javascript to inject the onmouseover and onmouseout events to each row, rather than putting the javascript in each table row tag? An answer utilizing the Prototype library (instead of mootools, jQuery, etc) would be most helpful.
``` <table id="mytable"> <tbody> <tr><td>Foo</td><td>Bar</td></tr> <tr><td>Bork</td><td>Bork</td></tr> </tbody> </table> <script type="text/javascript"> $$('#mytable tr').each(function(item) { item.observe('mouseover', function() { item.setStyle({ backgroundColor: '#ddd' }); }...
52,239
<p>We are working with an oracle database in which the person that set it up is "long gone" and thus do not know the sysdba password, but need it. We have root access to the box (its on linux). Is there any way to recover or change the sys passwords?</p>
[ { "answer_id": 52244, "author": "Paul Hargreaves", "author_id": 5330, "author_profile": "https://Stackoverflow.com/users/5330", "pm_score": 6, "selected": true, "text": "<p>Have you tried logging into Linux as your installed Oracle user then</p>\n\n<pre><code>sqlplus \"/ as sysdba\"\n</c...
2008/09/09
[ "https://Stackoverflow.com/questions/52239", "https://Stackoverflow.com", "https://Stackoverflow.com/users/673/" ]
We are working with an oracle database in which the person that set it up is "long gone" and thus do not know the sysdba password, but need it. We have root access to the box (its on linux). Is there any way to recover or change the sys passwords?
Have you tried logging into Linux as your installed Oracle user then ``` sqlplus "/ as sysdba" ``` When you log in you'll be able to change your password. ``` alter user sys identified by <new password>; ``` Good luck :)
52,286
<p>Wrote the following in PowersHell as a quick iTunes demonstration:</p> <pre><code>$iTunes = New-Object -ComObject iTunes.Application $LibrarySource = $iTunes.LibrarySource foreach ($PList in $LibrarySource.Playlists) { write-host $PList.name } </code></pre> <p>This works well and pulls back a list of playlist na...
[ { "answer_id": 52309, "author": "bruceatk", "author_id": 791, "author_profile": "https://Stackoverflow.com/users/791", "pm_score": 3, "selected": true, "text": "<p>Here is one thing that I did on my a Powershell script that adds podcasts to iTunes. I use Juice on a server to download all...
2008/09/09
[ "https://Stackoverflow.com/questions/52286", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5330/" ]
Wrote the following in PowersHell as a quick iTunes demonstration: ``` $iTunes = New-Object -ComObject iTunes.Application $LibrarySource = $iTunes.LibrarySource foreach ($PList in $LibrarySource.Playlists) { write-host $PList.name } ``` This works well and pulls back a list of playlist names. However on trying to ...
Here is one thing that I did on my a Powershell script that adds podcasts to iTunes. I use Juice on a server to download all the podcasts that I listen to. The script uses .Net methods to release the COM objects. When I wrote my iTunes script I had read a couple of articles that stated you should release your COM objec...
52,313
<p>This question is kind of an add-on to this <a href="https://stackoverflow.com/questions/44905/c-switch-statement-limitations-why">question</a></p> <p>In C#, a switch case cannot fall through to other cases, this causes a compilation error. In this case I am just adding some number to the month total for the select...
[ { "answer_id": 52314, "author": "Brian Warshaw", "author_id": 1344, "author_profile": "https://Stackoverflow.com/users/1344", "pm_score": 1, "selected": false, "text": "<p>There is already a question addressing this topic:</p>\n\n<p><a href=\"https://stackoverflow.com/questions/44905/c-s...
2008/09/09
[ "https://Stackoverflow.com/questions/52313", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4144/" ]
This question is kind of an add-on to this [question](https://stackoverflow.com/questions/44905/c-switch-statement-limitations-why) In C#, a switch case cannot fall through to other cases, this causes a compilation error. In this case I am just adding some number to the month total for the selected month and each subs...
Often times when you see the noise from a huge switch statement or many if statements that might fall into more than one block, you're trying to suppress a bad design. Instead, what if you implemented the Specification pattern to see if something matched, and then act on it? ``` foreach(MonthSpecification spec in thi...
52,315
<p>We have some input data that sometimes appears with &amp;nbsp characters on the end.</p> <p>The data comes in from the source system as varchar() and our attempts to cast as decimal fail b/c of these characters.</p> <p>Ltrim and Rtrim don't remove the characters, so we're forced to do something like:</p> <pre><co...
[ { "answer_id": 52327, "author": "Espo", "author_id": 2257, "author_profile": "https://Stackoverflow.com/users/2257", "pm_score": 4, "selected": true, "text": "<p><a href=\"http://www.lazydba.com/sql/1__4390.html\" rel=\"noreferrer\">This page</a> has a sample of how you can remove non-al...
2008/09/09
[ "https://Stackoverflow.com/questions/52315", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5202/" ]
We have some input data that sometimes appears with &nbsp characters on the end. The data comes in from the source system as varchar() and our attempts to cast as decimal fail b/c of these characters. Ltrim and Rtrim don't remove the characters, so we're forced to do something like: ``` UPDATE myTable SET myColumn =...
[This page](http://www.lazydba.com/sql/1__4390.html) has a sample of how you can remove non-alphanumeric chars: ``` -- Put something like this into a user function: DECLARE @cString VARCHAR(32) DECLARE @nPos INTEGER SELECT @cString = '90$%45623 *6%}~:@' SELECT @nPos = PATINDEX('%[^0-9]%', @cString) WHILE @nPo...
52,321
<p>Using the obsolete System.Web.Mail sending email works fine, here's the code snippet:</p> <pre><code> Public Shared Sub send(ByVal recipent As String, ByVal from As String, ByVal subject As String, ByVal body As String) Try Dim Message As System.Web.Mail.MailMessage = New System.Web.Mail.MailMes...
[ { "answer_id": 52361, "author": "Kevin Fairchild", "author_id": 3743, "author_profile": "https://Stackoverflow.com/users/3743", "pm_score": 0, "selected": false, "text": "<p>Have you tried adding </p>\n\n<pre><code>smtp.UseDefaultCredentials = True \n</code></pre>\n\n<p>before the send?<...
2008/09/09
[ "https://Stackoverflow.com/questions/52321", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4827/" ]
Using the obsolete System.Web.Mail sending email works fine, here's the code snippet: ``` Public Shared Sub send(ByVal recipent As String, ByVal from As String, ByVal subject As String, ByVal body As String) Try Dim Message As System.Web.Mail.MailMessage = New System.Web.Mail.MailMessage ...
I've tested your code and my mail is sent successfully. Assuming that you're using the same parameters for the old code, I would suggest that your mail server (MAIL\_SERVER) is accepting the message and there's a delay in processing or it considers it spam and discards it. I would suggest sending a message using a thi...
52,353
<p>I have an application that reads a CSV file with piles of data rows. I give the user a summary of the number of rows based on types of data, but I want to make sure that I don't read in too many rows of data and cause <code>OutOfMemoryError</code>s. Each row translates into an object. Is there an easy way to find...
[ { "answer_id": 52362, "author": "jodonnell", "author_id": 4223, "author_profile": "https://Stackoverflow.com/users/4223", "pm_score": -1, "selected": false, "text": "<p>I doubt you want to do it programmatically unless you just want to do it once and store it for future use. It's a cost...
2008/09/09
[ "https://Stackoverflow.com/questions/52353", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5074/" ]
I have an application that reads a CSV file with piles of data rows. I give the user a summary of the number of rows based on types of data, but I want to make sure that I don't read in too many rows of data and cause `OutOfMemoryError`s. Each row translates into an object. Is there an easy way to find out the size of ...
You can use the [`java.lang.instrument` package](http://docs.oracle.com/javase/8/docs/api/java/lang/instrument/Instrumentation.html). Compile and put this class in a JAR: ``` import java.lang.instrument.Instrumentation; public class ObjectSizeFetcher { private static Instrumentation instrumentation; public ...
52,356
<p>I'm still fairly new to T-SQL and SQL 2005. I need to import a column of integers from a table in database1 to a identical table (only missing the column I need) in database2. Both are sql 2005 databases. I've tried the built in import command in Server Management Studio but it's forcing me to copy the entire table....
[ { "answer_id": 52368, "author": "Craig", "author_id": 2894, "author_profile": "https://Stackoverflow.com/users/2894", "pm_score": 0, "selected": false, "text": "<p>insert into Test2.dbo.MyTable (MyValue) select MyValue from Test1.dbo.MyTable</p>\n\n<p>This is assuming a great deal. Firs...
2008/09/09
[ "https://Stackoverflow.com/questions/52356", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5433/" ]
I'm still fairly new to T-SQL and SQL 2005. I need to import a column of integers from a table in database1 to a identical table (only missing the column I need) in database2. Both are sql 2005 databases. I've tried the built in import command in Server Management Studio but it's forcing me to copy the entire table. Th...
Inserting won't do it since it'll attempt to insert new rows at the end of the table. What it sounds like your trying to do is add a column to the end of existing rows. I'm not sure if the syntax is exactly right but, if I understood you then this will do what you're after. 1. Create the column allowing nulls in data...
52,357
<p>I've been wondering, what is the point of clog? As near as I can tell, clog is the same as cerr but with buffering so it is more efficient. Usually stderr is the same as stdout, so clog is the same as cout. This seems pretty lame to me, so I figure I must be misunderstanding it. If I have log messages going out to t...
[ { "answer_id": 52365, "author": "Konrad Rudolph", "author_id": 1968, "author_profile": "https://Stackoverflow.com/users/1968", "pm_score": 6, "selected": true, "text": "<blockquote>\n <p>Is it possible to redirect clog, cerr, cout, stdin, stdout, and/or stderr?</p>\n</blockquote>\n\n<p>...
2008/09/09
[ "https://Stackoverflow.com/questions/52357", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4662/" ]
I've been wondering, what is the point of clog? As near as I can tell, clog is the same as cerr but with buffering so it is more efficient. Usually stderr is the same as stdout, so clog is the same as cout. This seems pretty lame to me, so I figure I must be misunderstanding it. If I have log messages going out to the ...
> > Is it possible to redirect clog, cerr, cout, stdin, stdout, and/or stderr? > > > Yes. You want the [`rdbuf`](http://www.cplusplus.com/reference/iostream/ios/rdbuf.html) function. ``` ofstream ofs("logfile"); cout.rdbuf(ofs.rdbuf()); cout << "Goes to file." << endl; ``` > > Is the only difference between cl...
52,400
<p>I'm sure this has already been asked and answered so I apologize in advance for that but I'm not figuring out the correct keywords to search for. Searching for "Pattern" hits way too many Q &amp; A's to be useful.</p> <p>I'm working on a regression testing app. I'm displaying a form on the screen and according to...
[ { "answer_id": 52413, "author": "Dan Blair", "author_id": 1327, "author_profile": "https://Stackoverflow.com/users/1327", "pm_score": 1, "selected": false, "text": "<p>At first blush it sounds more like you have two different types of users and they have different access levels. This co...
2008/09/09
[ "https://Stackoverflow.com/questions/52400", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2820/" ]
I'm sure this has already been asked and answered so I apologize in advance for that but I'm not figuring out the correct keywords to search for. Searching for "Pattern" hits way too many Q & A's to be useful. I'm working on a regression testing app. I'm displaying a form on the screen and according to which user is l...
Table driven designs can be effective. Steve Maguire had few nice examples in *Writing* *Solid* *Code* . They are also a great way to capture tests, see [fit](http://fit.c2.com/) . In your case something like: ``` Field1ReadonlyRules = { 'user class 1' : True, 'user class 2' : False } field1.readOnly = Fie...
52,430
<p>I've got the following rough structure:</p> <pre><code>Object -&gt; Object Revisions -&gt; Data </code></pre> <p>The Data can be shared between several Objects.</p> <p>What I'm trying to do is clean out old Object Revisions. I want to keep the first, active, and a spread of revisions so that the last change for a...
[ { "answer_id": 52455, "author": "Peter", "author_id": 5189, "author_profile": "https://Stackoverflow.com/users/5189", "pm_score": 2, "selected": false, "text": "<p>Here is example SQL. If you have an Identity column, you can use this instead of \"ActivityDate\".</p>\n\n<pre><code>SELECT...
2008/09/09
[ "https://Stackoverflow.com/questions/52430", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5201/" ]
I've got the following rough structure: ``` Object -> Object Revisions -> Data ``` The Data can be shared between several Objects. What I'm trying to do is clean out old Object Revisions. I want to keep the first, active, and a spread of revisions so that the last change for a time period is kept. The Data might be...
If the identity column is sequential you can use this approach: `SELECT curr.*, DATEDIFF(MINUTE, prev.EventDateTime,curr.EventDateTime) Duration FROM DWLog curr join DWLog prev on prev.EventID = curr.EventID - 1`
52,438
<p>I've been doing c# for a long time, and have never come across an easy way to just new up a hash.</p> <p>I've recently become acquainted with the ruby syntax of hashes and wonder, does anyone know of a simple way to declare a hash as a literal, without doing all the add calls.</p> <pre><code>{ "whatever" =&gt; {i ...
[ { "answer_id": 52443, "author": "Wheelie", "author_id": 1131, "author_profile": "https://Stackoverflow.com/users/1131", "pm_score": 6, "selected": true, "text": "<p>If you're using C# 3.0 (.NET 3.5) then you can use collection initializers. They're not quite as terse as in Ruby but still...
2008/09/09
[ "https://Stackoverflow.com/questions/52438", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1220/" ]
I've been doing c# for a long time, and have never come across an easy way to just new up a hash. I've recently become acquainted with the ruby syntax of hashes and wonder, does anyone know of a simple way to declare a hash as a literal, without doing all the add calls. ``` { "whatever" => {i => 1}; "and then somethi...
If you're using C# 3.0 (.NET 3.5) then you can use collection initializers. They're not quite as terse as in Ruby but still an improvement. This example is based on the [MSDN Example](http://msdn.microsoft.com/en-us/library/bb531208.aspx) ``` var students = new Dictionary<int, StudentName>() { { 111, new StudentN...
52,449
<p>Can I return it as an object if I am doing a </p> <pre><code>Select OneItem from Table Where OtherItem = "blah"? </code></pre> <p>Is there a better way to do this?</p> <p>I am building a constructor to return an object based on its name rather than its ID.</p>
[ { "answer_id": 52470, "author": "Ben Scheirman", "author_id": 3381, "author_profile": "https://Stackoverflow.com/users/3381", "pm_score": 4, "selected": true, "text": "<p><code>query.UniqueResult&lt;T&gt;()</code> returns just one <strong>T</strong></p>\n" }, { "answer_id": 21431...
2008/09/09
[ "https://Stackoverflow.com/questions/52449", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4140/" ]
Can I return it as an object if I am doing a ``` Select OneItem from Table Where OtherItem = "blah"? ``` Is there a better way to do this? I am building a constructor to return an object based on its name rather than its ID.
`query.UniqueResult<T>()` returns just one **T**
52,485
<p>I have a Question class:</p> <pre><code>class Question { public int QuestionNumber { get; set; } public string Question { get; set; } public string Answer { get; set; } } </code></pre> <p>Now I make an ICollection of these available through an ObjectDataSource, and display them using a Repeater bound t...
[ { "answer_id": 52513, "author": "Ben Scheirman", "author_id": 3381, "author_profile": "https://Stackoverflow.com/users/3381", "pm_score": 2, "selected": true, "text": "<p>You have to handle the postback event (button click or whatever) then enumerate the repeater items like this:</p>\n\n...
2008/09/09
[ "https://Stackoverflow.com/questions/52485", "https://Stackoverflow.com", "https://Stackoverflow.com/users/366/" ]
I have a Question class: ``` class Question { public int QuestionNumber { get; set; } public string Question { get; set; } public string Answer { get; set; } } ``` Now I make an ICollection of these available through an ObjectDataSource, and display them using a Repeater bound to the DataSource. I use **...
You have to handle the postback event (button click or whatever) then enumerate the repeater items like this: ``` foreach(RepeaterItem item in rptQuestions.Items) { //pull out question var question = (Question)item.DataItem; question.Answer = ((TextBox)item.FindControl("txtAnswer")).Text; question.Save() ...
52,506
<p>A friend and I were discussing C++ templates. He asked me what this should do:</p> <pre><code>#include &lt;iostream&gt; template &lt;bool&gt; struct A { A(bool) { std::cout &lt;&lt; "bool\n"; } A(void*) { std::cout &lt;&lt; "void*\n"; } }; int main() { A&lt;true&gt; *d = 0; const int b = 2; co...
[ { "answer_id": 52515, "author": "Ben Collins", "author_id": 3279, "author_profile": "https://Stackoverflow.com/users/3279", "pm_score": 0, "selected": false, "text": "<p>The greediness of the lexer is probably the determining factor in the absence of parentheses to make it explicit. I'd...
2008/09/09
[ "https://Stackoverflow.com/questions/52506", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4798/" ]
A friend and I were discussing C++ templates. He asked me what this should do: ``` #include <iostream> template <bool> struct A { A(bool) { std::cout << "bool\n"; } A(void*) { std::cout << "void*\n"; } }; int main() { A<true> *d = 0; const int b = 2; const int c = 1; new A< b > (c) > (d); } ...
AFAIK it would be compiled as `new A<b>(c) > d`. This is the only reasonable way to parse it IMHO. If the parser can't assume under normal circumstances a > end a template argument, that would result it much more ambiguity. If you want it the other way, you should have written: ``` new A<(b > c)>(d); ```
52,550
<p>What does the <code>,</code> operator do in C?</p>
[ { "answer_id": 52558, "author": "lillq", "author_id": 2064, "author_profile": "https://Stackoverflow.com/users/2064", "pm_score": 8, "selected": true, "text": "<p>The expression:</p>\n<pre><code>(expression1, expression2)\n</code></pre>\n<p>First <code>expression1</code> is evaluated, t...
2008/09/09
[ "https://Stackoverflow.com/questions/52550", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2064/" ]
What does the `,` operator do in C?
The expression: ``` (expression1, expression2) ``` First `expression1` is evaluated, then `expression2` is evaluated, and the value of `expression2` is returned for the whole expression.
52,561
<p>What is iPhone's browser tag and how iPhone optimized web site is different from a usual mobile web site?</p> <p>Thanks!</p>
[ { "answer_id": 52570, "author": "Espen Herseth Halvorsen", "author_id": 1542, "author_profile": "https://Stackoverflow.com/users/1542", "pm_score": 2, "selected": true, "text": "<p>Nettuts has a great introduction to web-developement for iPhone. You find it <a href=\"http://nettuts.com/m...
2008/09/09
[ "https://Stackoverflow.com/questions/52561", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4808/" ]
What is iPhone's browser tag and how iPhone optimized web site is different from a usual mobile web site? Thanks!
Nettuts has a great introduction to web-developement for iPhone. You find it [here](http://nettuts.com/misc/learn-how-to-develop-for-the-iphone/) This is the specific code you asked for (taken from that article): ``` <!--#if expr="(${HTTP_USER_AGENT} = /iPhone/)"--> <!-- place iPhone code in here --> <!--...
52,563
<p>I'm trying to let an <code>&lt;input type="text"&gt;</code> (henceforth referred to as “textbox”) fill a parent container by settings its <code>width</code> to <code>100%</code>. This works until I give the textbox a padding. This is then added to the content width and the input field overflows. Notice that in Firef...
[ { "answer_id": 52575, "author": "Darren Kopp", "author_id": 77, "author_profile": "https://Stackoverflow.com/users/77", "pm_score": 0, "selected": false, "text": "<p>i believe you can counter the overflow with a negative margin. ie</p>\n\n<pre><code>margin: -1em;\n</code></pre>\n" }, ...
2008/09/09
[ "https://Stackoverflow.com/questions/52563", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1968/" ]
I'm trying to let an `<input type="text">` (henceforth referred to as “textbox”) fill a parent container by settings its `width` to `100%`. This works until I give the textbox a padding. This is then added to the content width and the input field overflows. Notice that in Firefox this only happens when rendering the co...
With CSS3 you can use the box-sizing property on your inputs to standardise their box models. Something like this would enable you to add padding and have 100% width: ```css input[type="text"] { -webkit-box-sizing: border-box; // Safari/Chrome, other WebKit -moz-box-sizing: border-box; // Firefox, other Gec...
52,591
<p>A requirement for an ASP.Net 2.0 project I'm working on limits a certain field to a max of 10 words (not characters). I'm currently using a CustomValidator control with the following ServerValidate method:</p> <pre><code>Protected Sub TenWordsTextBoxValidator_ServerValidate(ByVal source As Object, ByVal args As Sys...
[ { "answer_id": 52610, "author": "Michael Haren", "author_id": 29, "author_profile": "https://Stackoverflow.com/users/29", "pm_score": 3, "selected": false, "text": "<p>You can use one of the builtin validators with a regex that counts the words.</p>\n\n<p>I'm a little rusty with regex so...
2008/09/09
[ "https://Stackoverflow.com/questions/52591", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1414/" ]
A requirement for an ASP.Net 2.0 project I'm working on limits a certain field to a max of 10 words (not characters). I'm currently using a CustomValidator control with the following ServerValidate method: ``` Protected Sub TenWordsTextBoxValidator_ServerValidate(ByVal source As Object, ByVal args As System.Web.UI.Web...
This regex seems to be working great: ``` "^(\b\S+\b\s*){0,10}$" ``` **Update**: the above had a few flaws so I ended up using this RegEx: ``` [\s\x21-\x2F\x3A-\x40\x5B-\x60\x7B-\xBF]+ ``` I `split()` the string on that regex and use the `length` of the resulting array to get the correct word count.
52,600
<p>I have to use a third-party component without source code. I have the release DLL and release PDB file. Let's call it 'CorporateComponent.dll'. My own code creates objects from this DLL and calls methods on these objects.</p> <pre><code>CorpObject o = new CorpObject(); Int32 result = o.DoSomethingLousy(); </code></...
[ { "answer_id": 52609, "author": "Mark Cidade", "author_id": 1659, "author_profile": "https://Stackoverflow.com/users/1659", "pm_score": 2, "selected": false, "text": "<p>The PDB is a database file that maps the instructions to their line numbers in the original code so when you get a sta...
2008/09/09
[ "https://Stackoverflow.com/questions/52600", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3619/" ]
I have to use a third-party component without source code. I have the release DLL and release PDB file. Let's call it 'CorporateComponent.dll'. My own code creates objects from this DLL and calls methods on these objects. ``` CorpObject o = new CorpObject(); Int32 result = o.DoSomethingLousy(); ``` While debugging, ...
To confirm if you're using the provided PDB, CorporateComponent.pdb, during debugging within the Visual Studio IDE review the output window and locate the line indicating that the CorporateComponent.dll is loaded and followed by the string `Symbols loaded`. To illustrate from a project of mine: ``` The thread 0x6a0 h...
52,634
<p>So I'm been pounding on this problem all day. I've got a LinqDataSource that points to my model and a GridView that consumes it. When I attempt to do an update on the GridView, it does not update the underlying data source. I thought it might have to do with the LinqDataSource, so I added a SqlDataSource and the sam...
[ { "answer_id": 52644, "author": "17 of 26", "author_id": 2284, "author_profile": "https://Stackoverflow.com/users/2284", "pm_score": 0, "selected": false, "text": "<p>This is a total shot in the dark since I haven't used ASP at all.</p>\n\n<p>I've been just learning XAML and WPF, which a...
2008/09/09
[ "https://Stackoverflow.com/questions/52634", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1194/" ]
So I'm been pounding on this problem all day. I've got a LinqDataSource that points to my model and a GridView that consumes it. When I attempt to do an update on the GridView, it does not update the underlying data source. I thought it might have to do with the LinqDataSource, so I added a SqlDataSource and the same t...
It turns out that we had a DataBind() call in the Page\_Load of the master page of the aspx file that was probably causing the state of the GridView to get tossed out on every page load. As a note - update parameters for a LINQ query are not required unless you want to set them some non-null default.
52,674
<p>Let's say you have a variable in a makefile fragment like the following:</p> <pre><code>MY_LIST=a b c d </code></pre> <p>How do I then reverse the order of that list? I need:</p> <pre><code>$(warning MY_LIST=${MY_LIST}) </code></pre> <p>to show</p> <pre><code>MY_LIST=d c b a </code></pre> <p>Edit: the real ...
[ { "answer_id": 52722, "author": "Ben Collins", "author_id": 3279, "author_profile": "https://Stackoverflow.com/users/3279", "pm_score": 3, "selected": false, "text": "<p>Doh! I could have just used a shell script-let:</p>\n\n<p><code>(for d in ${MY_LIST}; do echo $$d; done) | tac</code>...
2008/09/09
[ "https://Stackoverflow.com/questions/52674", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3279/" ]
Let's say you have a variable in a makefile fragment like the following: ``` MY_LIST=a b c d ``` How do I then reverse the order of that list? I need: ``` $(warning MY_LIST=${MY_LIST}) ``` to show ``` MY_LIST=d c b a ``` Edit: the real problem is that ``` ld -r some_object.o ${MY_LIST} ``` produces an `a....
A solution in pure GNU make: > > default: all > > > foo = please reverse me > > > reverse = $(if $(1),$(call > reverse,$(wordlist 2,$(words > $(1)),$(1)))) $(firstword $(1)) > > > all : @echo $(call reverse,$(foo)) > > > Gives: > > $ make > > > me reverse please > > >
52,702
<p>I am looking to stream a file housed in a SharePoint 2003 document library down to the browser. Basically the idea is to open the file as a stream and then to "write" the file stream to the reponse, specifying the content type and content disposition headers. Content disposition is used to preserve the file name, ...
[ { "answer_id": 53078, "author": "Mauro", "author_id": 2208, "author_profile": "https://Stackoverflow.com/users/2208", "pm_score": 2, "selected": false, "text": "<p>It might be something really simple, believe it or not I coded exactly the same thing today, i think the issue might be that...
2008/09/09
[ "https://Stackoverflow.com/questions/52702", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4764/" ]
I am looking to stream a file housed in a SharePoint 2003 document library down to the browser. Basically the idea is to open the file as a stream and then to "write" the file stream to the reponse, specifying the content type and content disposition headers. Content disposition is used to preserve the file name, conte...
It might be something really simple, believe it or not I coded exactly the same thing today, i think the issue might be that the content disposition doesnt tell the browser its an attachment and therefore able to be saved. ``` Response.AddHeader("Content-Disposition", "attachment;filename=myfile.doc"); ``` failing ...
52,703
<p>Has anyone encountered this oddity?</p> <p>I'm checking for the existence of a number of directories in one of my unit tests. <code>is_dir</code> is reporting true (1) in spite of the folder not existing at the time it is called. The code looks like this (with a few extraneous intermediate vars to ease debugging):<...
[ { "answer_id": 52712, "author": "reefnet_alex", "author_id": 2745, "author_profile": "https://Stackoverflow.com/users/2745", "pm_score": 1, "selected": false, "text": "<p>For what its worth, <code>is_readable</code> can be used as a work around.</p>\n" }, { "answer_id": 52716, ...
2008/09/09
[ "https://Stackoverflow.com/questions/52703", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2745/" ]
Has anyone encountered this oddity? I'm checking for the existence of a number of directories in one of my unit tests. `is_dir` is reporting true (1) in spite of the folder not existing at the time it is called. The code looks like this (with a few extraneous intermediate vars to ease debugging): ``` foreach($userfol...
I don't think this would cause your problem, but $path does have the trailing slash, correct?
52,704
<p>How do I discard changes in my working copy that are not in the index?</p>
[ { "answer_id": 52713, "author": "Tobi", "author_id": 5422, "author_profile": "https://Stackoverflow.com/users/5422", "pm_score": 13, "selected": false, "text": "<p>For all <em>unstaged</em> files in current working directory use:</p>\n<pre><code>git restore .\n</code></pre>\n<p>For a spe...
2008/09/09
[ "https://Stackoverflow.com/questions/52704", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4883/" ]
How do I discard changes in my working copy that are not in the index?
Another quicker way is: ``` git stash save --keep-index --include-untracked ``` You don't need to include `--include-untracked` if you don't want to be thorough about it. After that, you can drop that stash with a `git stash drop` command if you like.
52,723
<p>I am trying to paginate the results of an SQL query for use on a web page. The language and the database backend are PHP and SQLite.</p> <p>The code I'm using works something like this (page numbering starts at 0)</p> <p><a href="http://example.com/table?page=0" rel="nofollow noreferrer">http://example.com/table?...
[ { "answer_id": 52742, "author": "Owen", "author_id": 4853, "author_profile": "https://Stackoverflow.com/users/4853", "pm_score": 2, "selected": true, "text": "<p>i'd suggest just doing the count first. a count(primary key) is a very efficient query.</p>\n" }, { "answer_id": 52747...
2008/09/09
[ "https://Stackoverflow.com/questions/52723", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2581/" ]
I am trying to paginate the results of an SQL query for use on a web page. The language and the database backend are PHP and SQLite. The code I'm using works something like this (page numbering starts at 0) <http://example.com/table?page=0> ``` page = request(page) per = 10 // results per page offset = page * per /...
i'd suggest just doing the count first. a count(primary key) is a very efficient query.
52,732
<p>I need to dynamically create a Video object in ActionScript 2 and add it to a movie clip. In AS3 I just do this:</p> <pre><code>var videoViewComp:UIComponent; // created elsewhere videoView = new Video(); videoView.width = 400; videoView.height = 400; this.videoViewComp.addChild(videoView); </code></pre> <p>...
[ { "answer_id": 53254, "author": "Pedro", "author_id": 5488, "author_profile": "https://Stackoverflow.com/users/5488", "pm_score": 0, "selected": false, "text": "<p>I recommend you create a single instance of the Video object, leave it invisible (i.e., <code>videoview.visible = false</cod...
2008/09/09
[ "https://Stackoverflow.com/questions/52732", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1409/" ]
I need to dynamically create a Video object in ActionScript 2 and add it to a movie clip. In AS3 I just do this: ``` var videoViewComp:UIComponent; // created elsewhere videoView = new Video(); videoView.width = 400; videoView.height = 400; this.videoViewComp.addChild(videoView); ``` Unfortunately, I can't figu...
Ok, I've got something working. First, I created a new Library symbol and called it "VideoWrapper". I then added a single Video object to that with an ID of "video". Now, any time I need to dynamically add a Video to my state I can use MovieClip.attachMovie() to add a new copy of the Video object. To make things eas...
52,755
<p>I am using Windows, and I have two monitors.</p> <p>Some applications will <em>always</em> start on my primary monitor, no matter where they were when I closed them.</p> <p>Others will always start on the <em>secondary</em> monitor, no matter where they were when I closed them.</p> <p>Is there a registry setting ...
[ { "answer_id": 52775, "author": "Kevin Fairchild", "author_id": 3743, "author_profile": "https://Stackoverflow.com/users/3743", "pm_score": 2, "selected": false, "text": "<p>I'm fairly sure the primary monitor is the default. If the app was coded decently, when it's closed, it'll rememb...
2008/09/09
[ "https://Stackoverflow.com/questions/52755", "https://Stackoverflow.com", "https://Stackoverflow.com/users/672/" ]
I am using Windows, and I have two monitors. Some applications will *always* start on my primary monitor, no matter where they were when I closed them. Others will always start on the *secondary* monitor, no matter where they were when I closed them. Is there a registry setting buried somewhere, which I can manipula...
Correctly written Windows apps that want to save their location from run to run will save the results of [`GetWindowPlacement()`](http://msdn.microsoft.com/ru-ru/library/windows/desktop/ms633518%28v=vs.85%29.aspx) before shutting down, then use `SetWindowPlacement()` on startup to restore their position. Frequently, a...
52,785
<p>I think this is specific to IE 6.0 but...</p> <p>In JavaScript I add a <code>div</code> to the DOM. I assign an <code>id</code> attribute. When I later try to pick up the <code>div</code> by the <code>id</code> all I get is <code>null</code>.</p> <p>Any suggestions?</p> <p>Example:</p> <pre><code>var newDiv = do...
[ { "answer_id": 52791, "author": "David Basarab", "author_id": 2469, "author_profile": "https://Stackoverflow.com/users/2469", "pm_score": 1, "selected": false, "text": "<p>You have to add the div to the dom.</p>\n\n<pre><code>// Create the Div\nvar oDiv = document.createElement('div');\n...
2008/09/09
[ "https://Stackoverflow.com/questions/52785", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2490/" ]
I think this is specific to IE 6.0 but... In JavaScript I add a `div` to the DOM. I assign an `id` attribute. When I later try to pick up the `div` by the `id` all I get is `null`. Any suggestions? Example: ``` var newDiv = document.createElement("DIV"); newDiv.setAttribute("ID", "obj_1000"); document.appendChild(n...
In addition to what the other answers suggest (that you need to actually insert the element into the DOM for it to be found via `getElementById()`), you also need to use a lower-case attribute name in order for IE6 to recognize it as the `id`: ``` var newDiv = document.createElement("DIV"); newDiv.setAttribute("id", ...