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
1,329
<p>I need to copy hundreds of gigs of random files around on my computer and am pretty leery of using the vanilla file copy built into Windows.</p> <p>I don't want it to hang on a "Are you sure?", "Are you really sure?", "Even zip files?", "Surely not read-only files too!" loop as soon as I step away.</p> <p>I don't ...
[ { "answer_id": 1331, "author": "huseyint", "author_id": 39, "author_profile": "https://Stackoverflow.com/users/39", "pm_score": 6, "selected": false, "text": "<p>Use <a href=\"http://en.wikipedia.org/wiki/Robocopy\" rel=\"noreferrer\">Robocopy (Robust File Copy)</a>.</p>\n\n<p>NOTE:</p>\...
2008/08/04
[ "https://Stackoverflow.com/questions/1329", "https://Stackoverflow.com", "https://Stackoverflow.com/users/83/" ]
I need to copy hundreds of gigs of random files around on my computer and am pretty leery of using the vanilla file copy built into Windows. I don't want it to hang on a "Are you sure?", "Are you really sure?", "Even zip files?", "Surely not read-only files too!" loop as soon as I step away. I don't want it to work f...
How about good old Command-Line Xcopy? With S: being the source and T: the target: ``` xcopy /K /R /E /I /S /C /H /G /X /Y s:\*.* t:\ ``` > > /K Copies attributes. Normal Xcopy will reset read-only attributes. > > > /R Overwrites read-only files. > > > /E Copies directories and subdirectories, including empty o...
1,376
<p>I need the name of the current logged in user in my <strong>Air/Flex</strong> application. The application will only be deployed on Windows machines. I think I could attain this by regexing the User directory, but am open to other ways.</p>
[ { "answer_id": 1380, "author": "Shawn", "author_id": 26, "author_profile": "https://Stackoverflow.com/users/26", "pm_score": 1, "selected": false, "text": "<p>Here is a solution that works in XP / Vista, but is definitely expandable to OSX, linux, I'd still be interested in another way.<...
2008/08/04
[ "https://Stackoverflow.com/questions/1376", "https://Stackoverflow.com", "https://Stackoverflow.com/users/26/" ]
I need the name of the current logged in user in my **Air/Flex** application. The application will only be deployed on Windows machines. I think I could attain this by regexing the User directory, but am open to other ways.
Also I would try: ``` File.userDirectory.name ``` But I don't have Air installed so I can't really test this...
1,401
<p>I have a custom validation function in JavaScript in a user control on a .Net 2.0 web site which checks to see that the fee paid is not in excess of the fee amount due. </p> <p>I've placed the validator code in the <code>ascx</code> file, and I have also tried using <code>Page.ClientScript.RegisterClientScriptBlock...
[ { "answer_id": 1405, "author": "brendan", "author_id": 225, "author_profile": "https://Stackoverflow.com/users/225", "pm_score": 3, "selected": false, "text": "<p>When you're using .Net 2.0 and Ajax - you should use:</p>\n\n<pre><code>ScriptManager.RegisterClientScriptBlock\n</code></pre...
2008/08/04
[ "https://Stackoverflow.com/questions/1401", "https://Stackoverflow.com", "https://Stackoverflow.com/users/149/" ]
I have a custom validation function in JavaScript in a user control on a .Net 2.0 web site which checks to see that the fee paid is not in excess of the fee amount due. I've placed the validator code in the `ascx` file, and I have also tried using `Page.ClientScript.RegisterClientScriptBlock()` and in both cases the ...
Try changing the argument names to `sender` and `args`. And, after you have it working, switch the call over to `ScriptManager.RegisterClientScriptBlock`, regardless of AJAX use.
1,408
<p>Is it possible to configure <a href="http://www.apachefriends.org/en/xampp.html" rel="noreferrer">xampp</a> to serve up a file outside of the <code>htdocs</code> directory?</p> <p>For instance, say I have a file located as follows:</p> <p><code>C:\projects\transitCalculator\trunk\TransitCalculator.php</code></p> ...
[ { "answer_id": 1413, "author": "sparkes", "author_id": 269, "author_profile": "https://Stackoverflow.com/users/269", "pm_score": 4, "selected": false, "text": "<p>You can set Apache to serve pages from anywhere with any restrictions but it's normally distributed in a more secure form.</p...
2008/08/04
[ "https://Stackoverflow.com/questions/1408", "https://Stackoverflow.com", "https://Stackoverflow.com/users/58/" ]
Is it possible to configure [xampp](http://www.apachefriends.org/en/xampp.html) to serve up a file outside of the `htdocs` directory? For instance, say I have a file located as follows: `C:\projects\transitCalculator\trunk\TransitCalculator.php` and my [xampp](http://www.apachefriends.org/en/xampp.html) files are no...
Ok, per [pix0r](https://stackoverflow.com/questions/1408/#2471)'s, [Sparks](https://stackoverflow.com/questions/1408/#1413)' and [Dave](https://stackoverflow.com/questions/1408/#1414)'s answers it looks like there are three ways to do this: --- [Virtual Hosts](https://stackoverflow.com/questions/1408/#2471) ---------...
1,451
<p>I often encounter the following scenario where I need to offer many different types of permissions. I primarily use ASP.NET / VB.NET with SQL Server 2000.</p> <p><strong>Scenario</strong></p> <p>I want to offer a dynamic permission system that can work on different parameters. Let's say that I want to give either a ...
[ { "answer_id": 1459, "author": "John Downey", "author_id": 200, "author_profile": "https://Stackoverflow.com/users/200", "pm_score": 4, "selected": false, "text": "<p>The way I typically go about coding permission systems is having 6 tables.</p>\n\n<ul>\n<li>Users - this is pretty straig...
2008/08/04
[ "https://Stackoverflow.com/questions/1451", "https://Stackoverflow.com", "https://Stackoverflow.com/users/106/" ]
I often encounter the following scenario where I need to offer many different types of permissions. I primarily use ASP.NET / VB.NET with SQL Server 2000. **Scenario** I want to offer a dynamic permission system that can work on different parameters. Let's say that I want to give either a department or just a specifi...
I agree with John Downey. Personally, I sometimes use a flagged enumeration of permissions. This way you can use AND, OR, NOT and XOR bitwise operations on the enumeration's items. ``` "[Flags] public enum Permission { VIEWUSERS = 1, // 2^0 // 0000 0001 EDITUSERS = 2, // 2^1 // 0000 0010 VIEWPRODUCTS = 4,...
1,453
<p>I'm trying to do this (which produces an unexpected T_VARIABLE error):</p> <pre><code>public function createShipment($startZip, $endZip, $weight = $this-&gt;getDefaultWeight()){} </code></pre> <p>I don't want to put a magic number in there for weight since the object I am using has a <code>"defaultWeight"</code> ...
[ { "answer_id": 1456, "author": "Kevin", "author_id": 40, "author_profile": "https://Stackoverflow.com/users/40", "pm_score": 5, "selected": true, "text": "<p>This isn't much better:</p>\n\n<pre><code>public function createShipment($startZip, $endZip, $weight=null){\n $weight = !$weigh...
2008/08/04
[ "https://Stackoverflow.com/questions/1453", "https://Stackoverflow.com", "https://Stackoverflow.com/users/58/" ]
I'm trying to do this (which produces an unexpected T\_VARIABLE error): ``` public function createShipment($startZip, $endZip, $weight = $this->getDefaultWeight()){} ``` I don't want to put a magic number in there for weight since the object I am using has a `"defaultWeight"` parameter that all new shipments get if...
This isn't much better: ``` public function createShipment($startZip, $endZip, $weight=null){ $weight = !$weight ? $this->getDefaultWeight() : $weight; } // or... public function createShipment($startZip, $endZip, $weight=null){ if ( !$weight ) $weight = $this->getDefaultWeight(); } ```
1,457
<p>I'm writing an AJAX app, but as the user moves through the app, I'd like the URL in the address bar to update despite the lack of page reloads. Basically, I'd like for them to be able to bookmark at any point and thereby return to the current state. </p> <p>How are people handling maintaining RESTfulness in AJAX ap...
[ { "answer_id": 1465, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 4, "selected": false, "text": "<p>This is similar to what Kevin said. You can have your client state as some javascript object, and when you want to save the ...
2008/08/04
[ "https://Stackoverflow.com/questions/1457", "https://Stackoverflow.com", "https://Stackoverflow.com/users/331/" ]
I'm writing an AJAX app, but as the user moves through the app, I'd like the URL in the address bar to update despite the lack of page reloads. Basically, I'd like for them to be able to bookmark at any point and thereby return to the current state. How are people handling maintaining RESTfulness in AJAX apps?
The way to do this is to manipulate `location.hash` when AJAX updates result in a state change that you'd like to have a discrete URL. For example, if your page's url is: > > <http://example.com/> > > > If a client side function executed this code: ``` // AJAX code to display the "foo" state goes here. location...
1,476
<p>How do you express an integer as a binary number with Python literals?</p> <p>I was easily able to find the answer for hex:</p> <pre><code>&gt;&gt;&gt; 0x12AF 4783 &gt;&gt;&gt; 0x100 256 </code></pre> <p>and octal:</p> <pre><code>&gt;&gt;&gt; 01267 695 &gt;&gt;&gt; 0100 64 </code></pre> <p><strong>How do you us...
[ { "answer_id": 1478, "author": "Mark Biek", "author_id": 305, "author_profile": "https://Stackoverflow.com/users/305", "pm_score": -1, "selected": false, "text": "<p>As far as I can tell Python, up through 2.5, only supports hexadecimal &amp; octal literals. I did find some discussions ...
2008/08/04
[ "https://Stackoverflow.com/questions/1476", "https://Stackoverflow.com", "https://Stackoverflow.com/users/92/" ]
How do you express an integer as a binary number with Python literals? I was easily able to find the answer for hex: ``` >>> 0x12AF 4783 >>> 0x100 256 ``` and octal: ``` >>> 01267 695 >>> 0100 64 ``` **How do you use literals to express binary in Python?** --- ***Summary of Answers*** * Python 2.5 and earlier...
For reference—*future* Python possibilities: Starting with Python 2.6 you can express binary literals using the prefix **0b** or **0B**: ``` >>> 0b101111 47 ``` You can also use the new **bin** function to get the binary representation of a number: ``` >>> bin(173) '0b10101101' ``` Development version of the d...
1,528
<p>I'm looking for some way to effectively hide inherited members. I have a library of classes which inherit from common base classes. Some of the more recent descendant classes inherit dependency properties which have become vestigial and can be a little confusing when using <em>IntelliSense</em> or using the classes...
[ { "answer_id": 1533, "author": "Michael Stum", "author_id": 91, "author_profile": "https://Stackoverflow.com/users/91", "pm_score": 4, "selected": false, "text": "<p>While you cannot prevent usage of those inherited members to my knowledge, you should be able to hide them from IntelliSen...
2008/08/04
[ "https://Stackoverflow.com/questions/1528", "https://Stackoverflow.com", "https://Stackoverflow.com/users/93/" ]
I'm looking for some way to effectively hide inherited members. I have a library of classes which inherit from common base classes. Some of the more recent descendant classes inherit dependency properties which have become vestigial and can be a little confusing when using *IntelliSense* or using the classes in a visua...
Override them like Michael Suggests [above](https://stackoverflow.com/questions/1528/#1533) and to prevent folks from using the overridden (sp?) methods, mark them as obsolete: ``` [Obsolete("These are not supported in this class.", true)] public override void dontcallmeanymore() { } ``` If the second parm is set t...
1,535
<p>I've never been completely happy with the way exception handling works, there's a lot exceptions and try/catch brings to the table (stack unwinding, etc.), but it seems to break a lot of the OO model in the process.</p> <p>Anyway, here's the problem:</p> <p>Let's say you have some class which wraps or includes net...
[ { "answer_id": 1554, "author": "Chris Marasti-Georg", "author_id": 96, "author_profile": "https://Stackoverflow.com/users/96", "pm_score": 2, "selected": false, "text": "<p>Just wondering, what do you feel your method leaves to be desired? You could replace the anonymous delegate with a...
2008/08/04
[ "https://Stackoverflow.com/questions/1535", "https://Stackoverflow.com", "https://Stackoverflow.com/users/332/" ]
I've never been completely happy with the way exception handling works, there's a lot exceptions and try/catch brings to the table (stack unwinding, etc.), but it seems to break a lot of the OO model in the process. Anyway, here's the problem: Let's say you have some class which wraps or includes networked file IO op...
This looks like an excellent opportunity to have a look at Aspect Oriented Programming. Here is a good article on [AOP in .NET](https://learn.microsoft.com/en-us/archive/blogs/simonince/aspect-oriented-interception). The general idea is that you'd extract the cross-functional concern (i.e. Retry for x hours) into a sep...
1,615
<p>The <code>.XFDL</code> file extension identifies <code>XFDL</code> Formatted Document files. These belong to the XML-based document and template formatting standard. This format is exactly like the XML file format however, contains a level of encryption for use in secure communications.</p> <p>I know how to view XF...
[ { "answer_id": 1628, "author": "saniul", "author_id": 52, "author_profile": "https://Stackoverflow.com/users/52", "pm_score": 4, "selected": true, "text": "<p>If the encoding is <strong>base64</strong> then this is the solution I've stumbled upon on the web:</p>\n\n<p>\"Decoding XDFL fil...
2008/08/04
[ "https://Stackoverflow.com/questions/1615", "https://Stackoverflow.com", "https://Stackoverflow.com/users/25/" ]
The `.XFDL` file extension identifies `XFDL` Formatted Document files. These belong to the XML-based document and template formatting standard. This format is exactly like the XML file format however, contains a level of encryption for use in secure communications. I know how to view XFDL files using a file viewer I f...
If the encoding is **base64** then this is the solution I've stumbled upon on the web: "Decoding XDFL files saved with 'encoding=base64'. Files saved with: ``` application/vnd.xfdl;content-encoding="base64-gzip" ``` are simple base64-encoded gzip files. They can be easily restored to XML by first decoding and then...
1,711
<p>If you could go back in time and tell yourself to read a specific book at the beginning of your career as a developer, which book would it be?</p> <p>I expect this list to be varied and to cover a wide range of things.</p> <p><strong>To search:</strong> Use the search box in the upper-right corner. To search the a...
[ { "answer_id": 1713, "author": "Justin Standard", "author_id": 92, "author_profile": "https://Stackoverflow.com/users/92", "pm_score": 11, "selected": false, "text": "<ul>\n<li><em>Code Complete</em> (2nd edition) by Steve McConnell</li>\n<li><em>The Pragmatic Programmer</em></li>\n<li><...
2008/08/04
[ "https://Stackoverflow.com/questions/1711", "https://Stackoverflow.com", "https://Stackoverflow.com/users/303/" ]
If you could go back in time and tell yourself to read a specific book at the beginning of your career as a developer, which book would it be? I expect this list to be varied and to cover a wide range of things. **To search:** Use the search box in the upper-right corner. To search the answers of the current question...
* *Code Complete* (2nd edition) by Steve McConnell * *The Pragmatic Programmer* * *Structure and Interpretation of Computer Programs* * *The C Programming Language* by Kernighan and Ritchie * *Introduction to Algorithms* by Cormen, Leiserson, Rivest & Stein * *Design Patterns* by the Gang of Four * *Refactoring: Improv...
1,746
<p>I am trying to grab the capital letters of a couple of words and wrap them in span tags. I am using <a href="http://php.net/manual/en/function.preg-replace.php" rel="noreferrer">preg_replace</a> for extract and wrapping purposes, but it's not outputting anything.</p> <pre><code>preg_replace("/[A-Z]/", "&lt;span cla...
[ { "answer_id": 1749, "author": "Polsonby", "author_id": 137, "author_profile": "https://Stackoverflow.com/users/137", "pm_score": 7, "selected": true, "text": "<p>You need to put the pattern in parentheses <code>/([A-Z])/</code>, like this:</p>\n\n<pre><code>preg_replace(\"/([A-Z])/\", \...
2008/08/05
[ "https://Stackoverflow.com/questions/1746", "https://Stackoverflow.com", "https://Stackoverflow.com/users/137/" ]
I am trying to grab the capital letters of a couple of words and wrap them in span tags. I am using [preg\_replace](http://php.net/manual/en/function.preg-replace.php) for extract and wrapping purposes, but it's not outputting anything. ``` preg_replace("/[A-Z]/", "<span class=\"initial\">$1</span>", $str) ```
You need to put the pattern in parentheses `/([A-Z])/`, like this: ``` preg_replace("/([A-Z])/", "<span class=\"initial\">$1</span>", $str) ```
1,762
<p>I am trying to set a flag to show or hide a page element, but it always displays even when the expression is false. </p> <pre><code>$canMerge = ($condition1 &amp;&amp; $condition2) ? 'true' : 'false'; ... &lt;?php if ($canMerge) { ?&gt;Stuff&lt;?php } ?&gt; </code></pre> <p>What's up?</p>
[ { "answer_id": 1764, "author": "Polsonby", "author_id": 137, "author_profile": "https://Stackoverflow.com/users/137", "pm_score": 1, "selected": false, "text": "<p>The value of 'false' is true. You need to remove the quotes:</p>\n\n<pre><code>$canMerge = ($condition1 &amp;&amp; $conditio...
2008/08/05
[ "https://Stackoverflow.com/questions/1762", "https://Stackoverflow.com", "https://Stackoverflow.com/users/137/" ]
I am trying to set a flag to show or hide a page element, but it always displays even when the expression is false. ``` $canMerge = ($condition1 && $condition2) ? 'true' : 'false'; ... <?php if ($canMerge) { ?>Stuff<?php } ?> ``` What's up?
This is broken because 'false' as a string will evaluate to true as a boolean. However, this is an unneeded ternary expression, because the resulting values are simple true and false. This would be equivalent: ``` $canMerge = ($condition1 && $condition2); ```
1,829
<p>I've got a menu in Python. That part was easy. I'm using <code>raw_input()</code> to get the selection from the user. </p> <p>The problem is that <code>raw_input</code> (and input) require the user to press <kbd>Enter</kbd> after they make a selection. Is there any way to make the program act immediately upon a key...
[ { "answer_id": 1840, "author": "Mark Harrison", "author_id": 116, "author_profile": "https://Stackoverflow.com/users/116", "pm_score": 3, "selected": false, "text": "<p><strong>On Linux:</strong></p>\n\n<ul>\n<li>set raw mode</li>\n<li>select and read the keystroke</li>\n<li>restore norm...
2008/08/05
[ "https://Stackoverflow.com/questions/1829", "https://Stackoverflow.com", "https://Stackoverflow.com/users/30/" ]
I've got a menu in Python. That part was easy. I'm using `raw_input()` to get the selection from the user. The problem is that `raw_input` (and input) require the user to press `Enter` after they make a selection. Is there any way to make the program act immediately upon a keystroke? Here's what I've got so far: ```...
**On Windows:** ``` import msvcrt answer=msvcrt.getch() ```
1,836
<p>OK. This is a bit of a vanity app, but I had a situation today at work where I was in a training class and the machine was set to lock every 10 minutes. Well, if the trainers got excited about talking - as opposed to changing slides - the machine would lock up.</p> <p>I'd like to write a teeny app that has nothing...
[ { "answer_id": 1843, "author": "lubos hasko", "author_id": 275, "author_profile": "https://Stackoverflow.com/users/275", "pm_score": 6, "selected": true, "text": "<p><strong>for C# 3.5</strong></p>\n\n<p>without notifyicon therefore you will need to terminate this application in task man...
2008/08/05
[ "https://Stackoverflow.com/questions/1836", "https://Stackoverflow.com", "https://Stackoverflow.com/users/172/" ]
OK. This is a bit of a vanity app, but I had a situation today at work where I was in a training class and the machine was set to lock every 10 minutes. Well, if the trainers got excited about talking - as opposed to changing slides - the machine would lock up. I'd like to write a teeny app that has nothing but a task...
**for C# 3.5** without notifyicon therefore you will need to terminate this application in task manager manually ``` using System; using System.Drawing; using System.Windows.Forms; static class Program { static void Main() { Timer timer = new Timer(); // timer.Interval = 4 minutes tim...
1,854
<p>What do I need to look at to see whether I'm on Windows or Unix, etc?</p>
[ { "answer_id": 1857, "author": "Louis Brandy", "author_id": 2089740, "author_profile": "https://Stackoverflow.com/users/2089740", "pm_score": 11, "selected": true, "text": "<pre><code>&gt;&gt;&gt; import os\n&gt;&gt;&gt; os.name\n'posix'\n&gt;&gt;&gt; import platform\n&gt;&gt;&gt; platfo...
2008/08/05
[ "https://Stackoverflow.com/questions/1854", "https://Stackoverflow.com", "https://Stackoverflow.com/users/116/" ]
What do I need to look at to see whether I'm on Windows or Unix, etc?
``` >>> import os >>> os.name 'posix' >>> import platform >>> platform.system() 'Linux' >>> platform.release() '2.6.22-15-generic' ``` The output of [`platform.system()`](https://docs.python.org/library/platform.html#platform.system) is as follows: * Linux: `Linux` * Mac: `Darwin` * Windows: `Windows` See: [`platfo...
1,873
<p>How do I delimit a Javascript data-bound string parameter in an anchor <code>OnClick</code> event?</p> <ul> <li>I have an anchor tag in an ASP.NET Repeater control.</li> <li>The <code>OnClick</code> event of the anchor contains a call to a Javascript function.</li> <li>The Javascript function takes a string for its ...
[ { "answer_id": 1875, "author": "Grant", "author_id": 30, "author_profile": "https://Stackoverflow.com/users/30", "pm_score": 2, "selected": false, "text": "<blockquote>\n <p>Without the extra quotes around the input string parameter, the Javascript function thinks I'm passing in an inte...
2008/08/05
[ "https://Stackoverflow.com/questions/1873", "https://Stackoverflow.com", "https://Stackoverflow.com/users/242/" ]
How do I delimit a Javascript data-bound string parameter in an anchor `OnClick` event? * I have an anchor tag in an ASP.NET Repeater control. * The `OnClick` event of the anchor contains a call to a Javascript function. * The Javascript function takes a string for its input parameter. * The string parameter is popula...
I had recently similar problem and the only way to solve it was to use plain old HTML codes for single (`&#39;`) and double quotes (`&#34;`). Source code was total mess of course but it worked. Try ``` <a id="aShowHide" onclick='ToggleDisplay(&#34;<%# DataBinder.Eval(Container.DataItem, "JobCode") %>&#34;);'>Show/H...
1,908
<p>I have a bunch of latitude/longitude pairs that map to known x/y coordinates on a (geographically distorted) map.</p> <p>Then I have one more latitude/longitude pair. I want to plot it on the map as best is possible. How do I go about doing this?</p> <p>At first I decided to create a system of linear equations for...
[ { "answer_id": 1926, "author": "nlucaroni", "author_id": 157, "author_profile": "https://Stackoverflow.com/users/157", "pm_score": 0, "selected": false, "text": "<p>the problem is that the sphere can be distorted a number of ways, and having all those points known on the equator, lets sa...
2008/08/05
[ "https://Stackoverflow.com/questions/1908", "https://Stackoverflow.com", "https://Stackoverflow.com/users/79/" ]
I have a bunch of latitude/longitude pairs that map to known x/y coordinates on a (geographically distorted) map. Then I have one more latitude/longitude pair. I want to plot it on the map as best is possible. How do I go about doing this? At first I decided to create a system of linear equations for the three neares...
Are there any more specific details on the kind of distortion? If, for example, your latitudes and longitudes are "distorted" onto your 2D map using a Mercator projection, the conversion math is [readily available](http://www.wikipedia.org/wiki/Mercator_projection). If the map is distorted truly arbitrarily, there are...
1,936
<p>Using ASP.NET MVC there are situations (such as form submission) that may require a <code>RedirectToAction</code>. </p> <p>One such situation is when you encounter validation errors after a form submission and need to redirect back to the form, but would like the URL to reflect the URL of the form, not the action ...
[ { "answer_id": 1940, "author": "Matt Mitchell", "author_id": 364, "author_profile": "https://Stackoverflow.com/users/364", "pm_score": 7, "selected": true, "text": "<p>The solution is to use the TempData property to store the desired Request components.</p>\n\n<p>For instance:</p>\n\n<pr...
2008/08/05
[ "https://Stackoverflow.com/questions/1936", "https://Stackoverflow.com", "https://Stackoverflow.com/users/364/" ]
Using ASP.NET MVC there are situations (such as form submission) that may require a `RedirectToAction`. One such situation is when you encounter validation errors after a form submission and need to redirect back to the form, but would like the URL to reflect the URL of the form, not the action page it submits to. A...
The solution is to use the TempData property to store the desired Request components. For instance: ``` public ActionResult Send() { TempData["form"] = Request.Form; return this.RedirectToAction(a => a.Form()); } ``` Then in your "Form" action you can go: ``` public ActionResult Form() { /* Declare vie...
1,949
<p>In order to fully use LinqToSql in an ASP.net 3.5 application, it is necessary to create <a href="http://msdn.microsoft.com/en-us/library/system.data.linq.datacontext.aspx" rel="noreferrer">DataContext</a> <a href="http://dotnetslackers.com/articles/csharp/InsideTheLINQToSQLDataContextClass.aspx" rel="noreferrer">cl...
[ { "answer_id": 2050, "author": "John Downey", "author_id": 200, "author_profile": "https://Stackoverflow.com/users/200", "pm_score": 2, "selected": false, "text": "<p>In my experience with LINQ to SQL and LINQ to Entities a DataContext is synonymous to a connection to the database. So if...
2008/08/05
[ "https://Stackoverflow.com/questions/1949", "https://Stackoverflow.com", "https://Stackoverflow.com/users/51/" ]
In order to fully use LinqToSql in an ASP.net 3.5 application, it is necessary to create [DataContext](http://msdn.microsoft.com/en-us/library/system.data.linq.datacontext.aspx) [classes](http://dotnetslackers.com/articles/csharp/InsideTheLINQToSQLDataContextClass.aspx) (which is usually done using the designer in VS 2...
I disagree with John's answer. The DataContext (or Linq to Entities ObjectContext) is more of a "unit of work" than a connection. It manages change tracking, etc. See this blog post for a description: [Lifetime of a LINQ to SQL DataContext](http://blogs.msdn.com/dinesh.kulkarni/archive/2008/04/27/lifetime-of-a-linq-to...
1,988
<p>I have read a lot that LISP can redefine syntax on the fly, presumably with macros. I am curious how far does this actually go? Can you redefine the language structure so much that it borderline becomes a compiler for another language? For example, could you change the functional nature of LISP into a more object...
[ { "answer_id": 1992, "author": "sparkes", "author_id": 269, "author_profile": "https://Stackoverflow.com/users/269", "pm_score": 2, "selected": false, "text": "<p>If you want lisp to look like Ruby use Ruby. </p>\n\n<p>It's possible to use Ruby (and Python) in a very lisp like way which ...
2008/08/05
[ "https://Stackoverflow.com/questions/1988", "https://Stackoverflow.com", "https://Stackoverflow.com/users/122/" ]
I have read a lot that LISP can redefine syntax on the fly, presumably with macros. I am curious how far does this actually go? Can you redefine the language structure so much that it borderline becomes a compiler for another language? For example, could you change the functional nature of LISP into a more object orien...
That's a really good question. I think it's nuanced but definitely answerable: Macros are not stuck in s-expressions. See the LOOP macro for a very complex language written using keywords (symbols). So, while you may start and end the loop with parentheses, inside it has its own syntax. Example: ``` (loop for x fro...
1,994
<p>When you data bind in C#, the thread that changes the data causes the control to change too. But if this thread is not the one on which the control was created, you'll get an Illegal Cross Thread Operation exception.</p> <p>Is there anyway to prevent this?</p>
[ { "answer_id": 1998, "author": "Mike Stone", "author_id": 122, "author_profile": "https://Stackoverflow.com/users/122", "pm_score": 3, "selected": false, "text": "<p>You should be able to do something like:</p>\n\n<pre><code>if (control.InvokeRequired)\n{\n control.Invoke(delegateWith...
2008/08/05
[ "https://Stackoverflow.com/questions/1994", "https://Stackoverflow.com", "https://Stackoverflow.com/users/195/" ]
When you data bind in C#, the thread that changes the data causes the control to change too. But if this thread is not the one on which the control was created, you'll get an Illegal Cross Thread Operation exception. Is there anyway to prevent this?
You should be able to do something like: ``` if (control.InvokeRequired) { control.Invoke(delegateWithMyCode); } else { delegateWithMyCode(); } ``` InvokeRequired is a property on Controls to see if you are on the correct thread, then Invoke will invoke the delegate on the correct thread. UPDATE: Actually, ...
2,027
<p>When learning a new programming language, one of the possible roadblocks you might encounter is the question whether the language is, by default, <em>pass-by-value or pass-by-reference</em>.</p> <p>So here is my question to all of you, in your favorite language, <em>how</em> is it actually done? And what are the <e...
[ { "answer_id": 2028, "author": "sven", "author_id": 46, "author_profile": "https://Stackoverflow.com/users/46", "pm_score": 5, "selected": false, "text": "<p>Here is my own contribution for the <a href=\"http://en.wikipedia.org/wiki/Java_(programming_language)\" rel=\"nofollow noreferrer...
2008/08/05
[ "https://Stackoverflow.com/questions/2027", "https://Stackoverflow.com", "https://Stackoverflow.com/users/46/" ]
When learning a new programming language, one of the possible roadblocks you might encounter is the question whether the language is, by default, *pass-by-value or pass-by-reference*. So here is my question to all of you, in your favorite language, *how* is it actually done? And what are the *possible pitfalls*? Your...
Here is my own contribution for the [Java programming language](http://en.wikipedia.org/wiki/Java_(programming_language)). first some code: ``` public void swap(int x, int y) { int tmp = x; x = y; y = tmp; } ``` calling this method will result in this: ``` int pi = 3; int everything = 42; swap(pi, everythin...
2,056
<p>When looking beyond the <a href="https://en.wikipedia.org/wiki/Rapid_application_development" rel="noreferrer">RAD</a> (drag-drop and configure) way of building user interfaces that many tools encourage you are likely to come across three design patterns called <a href="http://en.wikipedia.org/wiki/Model%E2%80%93vie...
[ { "answer_id": 2067, "author": "Matt Mitchell", "author_id": 364, "author_profile": "https://Stackoverflow.com/users/364", "pm_score": 4, "selected": false, "text": "<p>Both of these frameworks aim to seperate concerns - for instance, interaction with a data source (model), application l...
2008/08/05
[ "https://Stackoverflow.com/questions/2056", "https://Stackoverflow.com", "https://Stackoverflow.com/users/358/" ]
When looking beyond the [RAD](https://en.wikipedia.org/wiki/Rapid_application_development) (drag-drop and configure) way of building user interfaces that many tools encourage you are likely to come across three design patterns called [Model-View-Controller](http://en.wikipedia.org/wiki/Model%E2%80%93view%E2%80%93contro...
Model-View-Presenter -------------------- In **MVP**, the Presenter contains the UI business logic for the View. All invocations from the View delegate directly to the Presenter. The Presenter is also decoupled directly from the View and talks to it through an interface. This is to allow mocking of the View in a unit ...
2,120
<p>I want to get the MD5 Hash of a string value in SQL Server 2005. I do this with the following command:</p> <pre><code>SELECT HashBytes('MD5', 'HelloWorld') </code></pre> <p>However, this returns a VarBinary instead of a VarChar value. If I attempt to convert <code>0x68E109F0F40CA72A15E05CC22786F8E6</code> into a V...
[ { "answer_id": 2382, "author": "GateKiller", "author_id": 383, "author_profile": "https://Stackoverflow.com/users/383", "pm_score": 8, "selected": true, "text": "<p>I have found the solution else where:</p>\n\n<pre><code>SELECT SUBSTRING(master.dbo.fn_varbintohexstr(HashBytes('MD5', 'Hel...
2008/08/05
[ "https://Stackoverflow.com/questions/2120", "https://Stackoverflow.com", "https://Stackoverflow.com/users/383/" ]
I want to get the MD5 Hash of a string value in SQL Server 2005. I do this with the following command: ``` SELECT HashBytes('MD5', 'HelloWorld') ``` However, this returns a VarBinary instead of a VarChar value. If I attempt to convert `0x68E109F0F40CA72A15E05CC22786F8E6` into a VarChar I get `há ðô§*à\Â'†øæ` instead...
I have found the solution else where: ``` SELECT SUBSTRING(master.dbo.fn_varbintohexstr(HashBytes('MD5', 'HelloWorld')), 3, 32) ```
2,123
<p><code>Checkboxes</code> in <code>HTML</code> forms don't have implicit <em>labels</em> with them. Adding an explicit label (some text) next to it doesn't toggle the <code>checkbox</code>.</p> <p><strong>How do I make a checkbox toggle from clicking on the text label as well?</strong></p>
[ { "answer_id": 2133, "author": "GateKiller", "author_id": 383, "author_profile": "https://Stackoverflow.com/users/383", "pm_score": 6, "selected": false, "text": "<p>If you correctly markup your HTML code, there is no need for javascript. The following code will allow the user to click o...
2008/08/05
[ "https://Stackoverflow.com/questions/2123", "https://Stackoverflow.com", "https://Stackoverflow.com/users/193/" ]
`Checkboxes` in `HTML` forms don't have implicit *labels* with them. Adding an explicit label (some text) next to it doesn't toggle the `checkbox`. **How do I make a checkbox toggle from clicking on the text label as well?**
Set the CSS `display` property for the label to be a block element and use that instead of your div - it keeps the semantic meaning of a label while allowing whatever styling you like. For example: ```css label { width: 100px; height: 100px; display: block; background-color: #e0e0ff; } ``` ```html <labe...
2,155
<p>The web applications I develop often require co-dependent configuration settings and there are also settings that have to change as we move between each of our environments.</p> <p>All our settings are currently simple key-value pairs but it would be useful to create custom config sections so that it is obvious when...
[ { "answer_id": 2178, "author": "John Downey", "author_id": 200, "author_profile": "https://Stackoverflow.com/users/200", "pm_score": 2, "selected": false, "text": "<p>You can accomplish this with Section Handlers. There is a basic overview of how to write one at <a href=\"http://www.code...
2008/08/05
[ "https://Stackoverflow.com/questions/2155", "https://Stackoverflow.com", "https://Stackoverflow.com/users/371/" ]
The web applications I develop often require co-dependent configuration settings and there are also settings that have to change as we move between each of our environments. All our settings are currently simple key-value pairs but it would be useful to create custom config sections so that it is obvious when two valu...
**Using attributes, child config sections and constraints** There is also the possibility to use attributes which automatically takes care of the plumbing, as well as providing the ability to easily add constraints. I here present an example from code I use myself in one of my sites. With a constraint I dictate the m...
2,158
<p>Is there a way to create a <code>JButton</code> with your own button graphic and not just with an image inside the button? </p> <p>If not, is there another way to create a custom <code>JButton</code> in java?</p>
[ { "answer_id": 2181, "author": "John Downey", "author_id": 200, "author_profile": "https://Stackoverflow.com/users/200", "pm_score": 3, "selected": false, "text": "<p>I haven't done SWING development since my early CS classes but if it wasn't built in you could just inherit <code>javax.s...
2008/08/05
[ "https://Stackoverflow.com/questions/2158", "https://Stackoverflow.com", "https://Stackoverflow.com/users/340/" ]
Is there a way to create a `JButton` with your own button graphic and not just with an image inside the button? If not, is there another way to create a custom `JButton` in java?
When I was first learning Java we had to make Yahtzee and I thought it would be cool to create custom Swing components and containers instead of just drawing everything on one `JPanel`. The benefit of extending `Swing` components, of course, is to have the ability to add support for keyboard shortcuts and other accessi...
2,196
<p>I've got a web application that I'm trying to optimize. Some of the controls are hidden in dialog-style <code>DIVs</code>. So, I'd like to have them load in via AJAX only when the user wants to see them. This is fine for controls that are mostly literal-based (various menus and widgets), but when I have what I call...
[ { "answer_id": 2372, "author": "Rob Allen", "author_id": 149, "author_profile": "https://Stackoverflow.com/users/149", "pm_score": 1, "selected": false, "text": "<p>Step one is to make your \"dirty\" pieces self contained user controls</p>\n\n<p>Step two is to embed those controls on you...
2008/08/05
[ "https://Stackoverflow.com/questions/2196", "https://Stackoverflow.com", "https://Stackoverflow.com/users/192/" ]
I've got a web application that I'm trying to optimize. Some of the controls are hidden in dialog-style `DIVs`. So, I'd like to have them load in via AJAX only when the user wants to see them. This is fine for controls that are mostly literal-based (various menus and widgets), but when I have what I call "dirty" contro...
Check out the [RadAjax](http://www.telerik.com/products/aspnet-ajax/controls/ajax/overview.aspx) control from Telerik - it allows you to avoid using UpdatePanels, and limit the amount of info passed back and forth between server and client by declaring direct relationships between calling controls, and controls that sh...
2,209
<p>I specifically want to add the style of <code>background-color</code> to the <code>&lt;body&gt;</code> tag of a master page, from the code behind (C#) of a content page that uses that master page. </p> <p>I have different content pages that need to make the master page has different colors depending on which conte...
[ { "answer_id": 2212, "author": "GateKiller", "author_id": 383, "author_profile": "https://Stackoverflow.com/users/383", "pm_score": 0, "selected": false, "text": "<p>I believe you are talking about a content management system. The way I have delt with this situation in the past is to eit...
2008/08/05
[ "https://Stackoverflow.com/questions/2209", "https://Stackoverflow.com", "https://Stackoverflow.com/users/396/" ]
I specifically want to add the style of `background-color` to the `<body>` tag of a master page, from the code behind (C#) of a content page that uses that master page. I have different content pages that need to make the master page has different colors depending on which content page is loaded, so that the master p...
What I would do for the particular case is: i. Define the body as a server side control ``` <body runat="server" id="masterpageBody"> ``` ii. In your content aspx page, register the MasterPage with the register: ``` <% MasterPageFile="..." %> ``` iii. In the Content Page, you can now simply use ``` Master.Find...
2,222
<p>I'm currently working on an application with a frontend written in Adobe Flex 3. I'm aware of <a href="http://code.google.com/p/as3flexunitlib/" rel="noreferrer">FlexUnit</a> but what I'd really like is a unit test runner for Ant/NAnt and a runner that integrates with the Flex Builder IDE (AKA Eclipse). Does one exi...
[ { "answer_id": 8753, "author": "Theo", "author_id": 1109, "author_profile": "https://Stackoverflow.com/users/1109", "pm_score": 4, "selected": true, "text": "<p>The <a href=\"http://code.google.com/p/dpuint/\" rel=\"noreferrer\">dpUint</a> testing framework has a test runner built with A...
2008/08/05
[ "https://Stackoverflow.com/questions/2222", "https://Stackoverflow.com", "https://Stackoverflow.com/users/266/" ]
I'm currently working on an application with a frontend written in Adobe Flex 3. I'm aware of [FlexUnit](http://code.google.com/p/as3flexunitlib/) but what I'd really like is a unit test runner for Ant/NAnt and a runner that integrates with the Flex Builder IDE (AKA Eclipse). Does one exist? Also, are there any other...
The [dpUint](http://code.google.com/p/dpuint/) testing framework has a test runner built with AIR which can be integrated with a build script. There is also my [FlexUnit](http://developer.iconara.net/objectlib/flexunitautomation.html) automation kit which does more or less the same for FlexUnit. It has an Ant macro th...
2,232
<p>How do I call shell commands from inside of a Ruby program? How do I then get output from these commands back into Ruby?</p>
[ { "answer_id": 2280, "author": "Steve Willard", "author_id": 402, "author_profile": "https://Stackoverflow.com/users/402", "pm_score": 5, "selected": false, "text": "<p>I'm definitely not a Ruby expert, but I'll give it a shot:</p>\n\n<pre><code>$ irb \nsystem \"echo Hi\"\nHi\n=&gt; true...
2008/08/05
[ "https://Stackoverflow.com/questions/2232", "https://Stackoverflow.com", "https://Stackoverflow.com/users/25/" ]
How do I call shell commands from inside of a Ruby program? How do I then get output from these commands back into Ruby?
This explanation is based on a commented [Ruby script](http://gist.github.com/4069) from a friend of mine. If you want to improve the script, feel free to update it at the link. First, note that when Ruby calls out to a shell, it typically calls `/bin/sh`, *not* Bash. Some Bash syntax is not supported by `/bin/sh` on ...
2,256
<p>Is there a way of mapping data collected on a stream or array to a data structure or vice-versa? In C++ this would simply be a matter of casting a pointer to the stream as a data type I want to use (or vice-versa for the reverse) eg: in C++</p> <pre><code>Mystruct * pMyStrct = (Mystruct*)&amp;SomeDataStream; pMyStr...
[ { "answer_id": 2294, "author": "gil", "author_id": 195, "author_profile": "https://Stackoverflow.com/users/195", "pm_score": 2, "selected": false, "text": "<p>if its .net on both sides:</p>\n\n<p>think you should use binary serialization and send the byte[] result.</p>\n\n<p>trusting you...
2008/08/05
[ "https://Stackoverflow.com/questions/2256", "https://Stackoverflow.com", "https://Stackoverflow.com/users/379/" ]
Is there a way of mapping data collected on a stream or array to a data structure or vice-versa? In C++ this would simply be a matter of casting a pointer to the stream as a data type I want to use (or vice-versa for the reverse) eg: in C++ ``` Mystruct * pMyStrct = (Mystruct*)&SomeDataStream; pMyStrct->Item1 = 25; i...
Most people use .NET serialization (there is faster binary and slower XML formatter, they both depend on reflection and are version tolerant to certain degree) However, if you want the fastest (unsafe) way - why not: Writing: ``` YourStruct o = new YourStruct(); byte[] buffer = new byte[Marshal.SizeOf(typeof(YourStr...
2,262
<p>How do I rewrite a URL in ASP.NET?</p> <p>I would like users to be able to go to</p> <pre><code>http://www.website.com/users/smith </code></pre> <p>instead of</p> <pre><code>http://www.website.com/?user=smith </code></pre>
[ { "answer_id": 2268, "author": "Nick Berardi", "author_id": 17, "author_profile": "https://Stackoverflow.com/users/17", "pm_score": 6, "selected": true, "text": "<p>Try the Managed Fusion Url Rewriter and Reverse Proxy:</p>\n\n<p><a href=\"http://urlrewriter.codeplex.com\" rel=\"noreferr...
2008/08/05
[ "https://Stackoverflow.com/questions/2262", "https://Stackoverflow.com", "https://Stackoverflow.com/users/383/" ]
How do I rewrite a URL in ASP.NET? I would like users to be able to go to ``` http://www.website.com/users/smith ``` instead of ``` http://www.website.com/?user=smith ```
Try the Managed Fusion Url Rewriter and Reverse Proxy: <http://urlrewriter.codeplex.com> The rule for rewriting this would be: ``` # clean up old rules and forward to new URL RewriteRule ^/?user=(.*) /users/$1 [NC,R=301] # rewrite the rule internally RewriteRule ^/users/(.*) /?user=$1 [NC,L] ```
2,267
<p>I am building a web page to show a customer what software they purchased and to give them a link to download said software. Unfortunately, the data on what was purchased and the download information are in separate databases so I can't just take care of it with joins in an SQL query.</p> <p>The common item is SKU....
[ { "answer_id": 2283, "author": "Vaibhav", "author_id": 380, "author_profile": "https://Stackoverflow.com/users/380", "pm_score": 0, "selected": false, "text": "<p>I am thinking off the top of my head here. If you load both as Data Tables in the same Data Sets, and define a relation betwe...
2008/08/05
[ "https://Stackoverflow.com/questions/2267", "https://Stackoverflow.com", "https://Stackoverflow.com/users/111/" ]
I am building a web page to show a customer what software they purchased and to give them a link to download said software. Unfortunately, the data on what was purchased and the download information are in separate databases so I can't just take care of it with joins in an SQL query. The common item is SKU. I'll be pu...
As long as the two databases are on the same physical server (assuming MSSQL) and the username/password being used in the connection string has rights to both DBs, then you should be able to perform a join across the two databases. Example: ``` select p.Date, p.Amount, d.SoftwareName, d.DownloadL...
2,300
<p>I want to be able to do:</p> <pre><code>For Each thing In things End For </code></pre> <p>CLASSIC ASP - NOT .NET!</p>
[ { "answer_id": 2312, "author": "Brett Veenstra", "author_id": 307, "author_profile": "https://Stackoverflow.com/users/307", "pm_score": 3, "selected": true, "text": "<p>Whatever your [things] are need to be written outside of VBScript.</p>\n\n<p>In VB6, <a href=\"http://www.vb-helper.com...
2008/08/05
[ "https://Stackoverflow.com/questions/2300", "https://Stackoverflow.com", "https://Stackoverflow.com/users/193/" ]
I want to be able to do: ``` For Each thing In things End For ``` CLASSIC ASP - NOT .NET!
Whatever your [things] are need to be written outside of VBScript. In VB6, [you can write a Custom Collection class](http://www.vb-helper.com/howto_custom_collection_with_for_each.html), then you'll need to compile to an ActiveX DLL and register it on your webserver to access it.
2,311
<p>I have created a PHP-script to update a web server that is live inside a local directory. I'm migrating the script into Python. It works fine for the most part, but after a PUT command, the size of the file appears to change. Thus, the size of the file is different from that of the file on the server. </p> <p>Once ...
[ { "answer_id": 2316, "author": "David Sykes", "author_id": 259, "author_profile": "https://Stackoverflow.com/users/259", "pm_score": 5, "selected": true, "text": "<p>Do you need to open the locfile in binary using <code>rb</code>?</p>\n\n<pre><code>f = open (locfile, \"rb\")\n</code></pr...
2008/08/05
[ "https://Stackoverflow.com/questions/2311", "https://Stackoverflow.com", "https://Stackoverflow.com/users/394/" ]
I have created a PHP-script to update a web server that is live inside a local directory. I'm migrating the script into Python. It works fine for the most part, but after a PUT command, the size of the file appears to change. Thus, the size of the file is different from that of the file on the server. Once I download...
Do you need to open the locfile in binary using `rb`? ``` f = open (locfile, "rb") ```
2,348
<p>In the code below</p> <pre><code>For i = LBound(arr) To UBound(arr) </code></pre> <p>What is the point in asking using <code>LBound</code>? Surely that is always 0.</p>
[ { "answer_id": 2378, "author": "huseyint", "author_id": 39, "author_profile": "https://Stackoverflow.com/users/39", "pm_score": 2, "selected": false, "text": "<p>Probably it comes from VB6. Because with <a href=\"http://msdn.microsoft.com/en-us/library/aa266179(VS.60).aspx\" rel=\"nofoll...
2008/08/05
[ "https://Stackoverflow.com/questions/2348", "https://Stackoverflow.com", "https://Stackoverflow.com/users/193/" ]
In the code below ``` For i = LBound(arr) To UBound(arr) ``` What is the point in asking using `LBound`? Surely that is always 0.
Why not use `For Each`? That way you don't need to care what the `LBound` and `UBound` are. ``` Dim x, y, z x = Array(1, 2, 3) For Each y In x z = DoSomethingWith(y) Next ```
2,384
<p>I'm trying to read binary data using C#. I have all the information about the layout of the data in the files I want to read. I'm able to read the data "chunk by chunk", i.e. getting the first 40 bytes of data converting it to a string, get the next 40 bytes.</p> <p>Since there are at least three slightly different...
[ { "answer_id": 2436, "author": "urini", "author_id": 373, "author_profile": "https://Stackoverflow.com/users/373", "pm_score": 0, "selected": false, "text": "<p>Try this:</p>\n\n<pre><code>using (FileStream stream = new FileStream(fileName, FileMode.Open))\n{\n BinaryFormatter formatt...
2008/08/05
[ "https://Stackoverflow.com/questions/2384", "https://Stackoverflow.com", "https://Stackoverflow.com/users/143/" ]
I'm trying to read binary data using C#. I have all the information about the layout of the data in the files I want to read. I'm able to read the data "chunk by chunk", i.e. getting the first 40 bytes of data converting it to a string, get the next 40 bytes. Since there are at least three slightly different version o...
The problem is the **string**s in your struct. I found that marshaling types like byte/short/int is not a problem; but when you need to marshal into a complex type such as a string, you need your struct to explicitly mimic an unmanaged type. You can do this with the MarshalAs attrib. For your example, the following sh...
2,483
<p>What is actually the difference between these two casts?</p> <pre><code>SomeClass sc = (SomeClass)SomeObject; SomeClass sc2 = SomeObject as SomeClass; </code></pre> <p>Normally, shouldn't they both be explicit casts to the specified type?</p>
[ { "answer_id": 2487, "author": "Rytmis", "author_id": 266, "author_profile": "https://Stackoverflow.com/users/266", "pm_score": 7, "selected": true, "text": "<p>The former will throw an exception if the source type can't be cast to the target type. The latter will result in sc2 being a n...
2008/08/05
[ "https://Stackoverflow.com/questions/2483", "https://Stackoverflow.com", "https://Stackoverflow.com/users/91/" ]
What is actually the difference between these two casts? ``` SomeClass sc = (SomeClass)SomeObject; SomeClass sc2 = SomeObject as SomeClass; ``` Normally, shouldn't they both be explicit casts to the specified type?
The former will throw an exception if the source type can't be cast to the target type. The latter will result in sc2 being a null reference, but no exception. [Edit] My original answer is certainly the most pronounced difference, but as Eric Lippert [points out](http://blogs.msdn.com/ericlippert/archive/2009/10/08/w...
2,509
<p>Test Driven Development has been the rage in the .NET community for the last few years. Recently, I have heard grumblings in the ALT.NET community about BDD. What is it? What makes it different from TDD?</p>
[ { "answer_id": 2515, "author": "Michael Stum", "author_id": 91, "author_profile": "https://Stackoverflow.com/users/91", "pm_score": 2, "selected": false, "text": "<p>Behaviour Driven Development seems to focus more on the interaction and communication between Developers and also between ...
2008/08/05
[ "https://Stackoverflow.com/questions/2509", "https://Stackoverflow.com", "https://Stackoverflow.com/users/303/" ]
Test Driven Development has been the rage in the .NET community for the last few years. Recently, I have heard grumblings in the ALT.NET community about BDD. What is it? What makes it different from TDD?
I understand BDD to be more about **specification** than **testing**. It is linked to Domain Driven Design (don't you love these \*DD acronyms?). It is linked with a certain way to write user stories, including high-level tests. An example by [Tom ten Thij](http://tomtenthij.nl/2008/1/25/rspec-plain-text-story-runner...
2,518
<p>I have 2 SQLite databases, one downloaded from a server (<code>server.db</code>), and one used as storage on the client (<code>client.db</code>). I need to perform various sync queries on the client database, using data from the server database.</p> <p>For example, I want to delete all rows in the <code>client.db t...
[ { "answer_id": 8783, "author": "Theo", "author_id": 1109, "author_profile": "https://Stackoverflow.com/users/1109", "pm_score": 2, "selected": false, "text": "<p>It's possible to open multiple databases at once in SQLite, but it's doubtful if can be done when working from Flex/AIR. In th...
2008/08/05
[ "https://Stackoverflow.com/questions/2518", "https://Stackoverflow.com", "https://Stackoverflow.com/users/26/" ]
I have 2 SQLite databases, one downloaded from a server (`server.db`), and one used as storage on the client (`client.db`). I need to perform various sync queries on the client database, using data from the server database. For example, I want to delete all rows in the `client.db tRole` table, and repopulate with all ...
I just looked at the AIR SQL API, and there's an `attach` method on `SQLConnection` it looks exactly what you need. I haven't tested this, but according to the documentation it should work: ``` var connection : SQLConnection = new SQLConnection(); connection.open(firstDbFile); connection.attach(secondDbFile, "otherD...
2,527
<p>How can I find out which node in a tree list the context menu has been activated? For instance right-clicking a node and selecting an option from the menu. </p> <p>I can't use the TreeViews' <code>SelectedNode</code> property because the node is only been right-clicked and not selected.</p>
[ { "answer_id": 2546, "author": "Jonesinator", "author_id": 152, "author_profile": "https://Stackoverflow.com/users/152", "pm_score": 8, "selected": true, "text": "<p>You can add a mouse click event to the TreeView, then select the correct node using GetNodeAt given the mouse coordinates ...
2008/08/05
[ "https://Stackoverflow.com/questions/2527", "https://Stackoverflow.com", "https://Stackoverflow.com/users/428/" ]
How can I find out which node in a tree list the context menu has been activated? For instance right-clicking a node and selecting an option from the menu. I can't use the TreeViews' `SelectedNode` property because the node is only been right-clicked and not selected.
You can add a mouse click event to the TreeView, then select the correct node using GetNodeAt given the mouse coordinates provided by the MouseEventArgs. ``` void treeView1MouseUp(object sender, MouseEventArgs e) { if(e.Button == MouseButtons.Right) { // Select the clicked node treeView1.Select...
2,530
<p>How do you disable autocomplete in the major browsers for a specific input (or form field)?</p>
[ { "answer_id": 2531, "author": "nlucaroni", "author_id": 157, "author_profile": "https://Stackoverflow.com/users/157", "pm_score": 12, "selected": true, "text": "<p>Firefox 30 ignores <code>autocomplete=&quot;off&quot;</code> for passwords, opting to prompt the user instead whether the p...
2008/08/05
[ "https://Stackoverflow.com/questions/2530", "https://Stackoverflow.com", "https://Stackoverflow.com/users/307/" ]
How do you disable autocomplete in the major browsers for a specific input (or form field)?
Firefox 30 ignores `autocomplete="off"` for passwords, opting to prompt the user instead whether the password should be stored on the client. Note the following [commentary](https://bugzilla.mozilla.org/show_bug.cgi?id=956906#c100) from May 5, 2014: > > * The password manager *always* prompts if it wants to save a pa...
2,647
<p>Using SQL Server, how do I split a string so I can access item x?</p> <p>Take a string "Hello John Smith". How can I split the string by space and access the item at index 1 which should return "John"?</p>
[ { "answer_id": 2657, "author": "Jonesinator", "author_id": 152, "author_profile": "https://Stackoverflow.com/users/152", "pm_score": 9, "selected": true, "text": "<p>You may find the solution in <em><a href=\"http://www.codeproject.com/KB/database/SQL_UDF_to_Parse_a_String.aspx\" rel=\"n...
2008/08/05
[ "https://Stackoverflow.com/questions/2647", "https://Stackoverflow.com", "https://Stackoverflow.com/users/383/" ]
Using SQL Server, how do I split a string so I can access item x? Take a string "Hello John Smith". How can I split the string by space and access the item at index 1 which should return "John"?
You may find the solution in *[SQL User Defined Function to Parse a Delimited String](http://www.codeproject.com/KB/database/SQL_UDF_to_Parse_a_String.aspx)* helpful (from [The Code Project](http://en.wikipedia.org/wiki/The_Code_Project)). You can use this simple logic: ``` Declare @products varchar(200) = '1|20|3|34...
2,649
<p>When writing a T-SQL script that I plan on re-running, often times I use temporary tables to store temporary data. Since the temp table is created on the fly, I'd like to be able to drop that table only if it exists (before I create it).</p> <p>I'll post the method that I use, but I'd like to see if there is a bet...
[ { "answer_id": 2652, "author": "Nathan Bedford", "author_id": 434, "author_profile": "https://Stackoverflow.com/users/434", "pm_score": 4, "selected": false, "text": "<p>The OBJECT_ID function returns the internal object id for the given object name and type. 'tempdb..#t1' refers to the...
2008/08/05
[ "https://Stackoverflow.com/questions/2649", "https://Stackoverflow.com", "https://Stackoverflow.com/users/434/" ]
When writing a T-SQL script that I plan on re-running, often times I use temporary tables to store temporary data. Since the temp table is created on the fly, I'd like to be able to drop that table only if it exists (before I create it). I'll post the method that I use, but I'd like to see if there is a better way.
``` IF Object_Id('TempDB..#TempTable') IS NOT NULL BEGIN DROP TABLE #TempTable END ```
2,658
<p>I need to implement version control, even for just the developing I do at home. I have read about how great subversion is for the past couple of years and was about to dedicate myself to learning this on the side until I heard about Git being the up and coming version control system.</p> <p>Given the situation, sho...
[ { "answer_id": 2665, "author": "Karl Seguin", "author_id": 34, "author_profile": "https://Stackoverflow.com/users/34", "pm_score": 4, "selected": false, "text": "<p>Use subversion, it's easy to setup, easy to use, and has plenty of tools. Any future revision system will have an import fr...
2008/08/05
[ "https://Stackoverflow.com/questions/2658", "https://Stackoverflow.com", "https://Stackoverflow.com/users/406/" ]
I need to implement version control, even for just the developing I do at home. I have read about how great subversion is for the past couple of years and was about to dedicate myself to learning this on the side until I heard about Git being the up and coming version control system. Given the situation, should I hold...
The most important thing about version control is: ***JUST START USING IT*** Not using version control is a horrible idea. If you are not using version control, stop reading right now and start using it. It is very easy to convert from ``` cvs<->svn<->git<->hg ``` It doesn't matter which one you choose. Just pick...
2,702
<p>I know I need to have (although I don't know why) a <code>GROUP BY</code> clause on the end of a SQL query that uses any aggregate functions like <code>count</code>, <code>sum</code>, <code>avg</code>, etc:</p> <pre><code>SELECT count(userID), userName FROM users GROUP BY userName </code></pre> <p>When else would ...
[ { "answer_id": 2704, "author": "GateKiller", "author_id": 383, "author_profile": "https://Stackoverflow.com/users/383", "pm_score": 2, "selected": false, "text": "<p>Counting the number of times tags are used might be a google example:</p>\n\n<pre><code>SELECT TagName, Count(*)\nAS Times...
2008/08/05
[ "https://Stackoverflow.com/questions/2702", "https://Stackoverflow.com", "https://Stackoverflow.com/users/357/" ]
I know I need to have (although I don't know why) a `GROUP BY` clause on the end of a SQL query that uses any aggregate functions like `count`, `sum`, `avg`, etc: ``` SELECT count(userID), userName FROM users GROUP BY userName ``` When else would `GROUP BY` be useful, and what are the performance ramifications?
To retrieve the number of widgets from each widget category that has more than 5 widgets, you could do this: ``` SELECT WidgetCategory, count(*) FROM Widgets GROUP BY WidgetCategory HAVING count(*) > 5 ``` The "having" clause is something people often forget about, instead opting to retrieve all their data to the cl...
2,714
<p>I think most people know how to do this via the GUI (right click table, properties), but doing this in T-SQL totally rocks.</p>
[ { "answer_id": 2715, "author": "Nathan Bedford", "author_id": 434, "author_profile": "https://Stackoverflow.com/users/434", "pm_score": 5, "selected": true, "text": "<pre>\nCREATE TABLE #tmpSizeChar (\n table_name sysname ,\n row_count int,\n reserved_size varchar(50),\n ...
2008/08/05
[ "https://Stackoverflow.com/questions/2714", "https://Stackoverflow.com", "https://Stackoverflow.com/users/434/" ]
I think most people know how to do this via the GUI (right click table, properties), but doing this in T-SQL totally rocks.
``` CREATE TABLE #tmpSizeChar ( table_name sysname , row_count int, reserved_size varchar(50), data_size varchar(50), index_size varchar(50), unused_size varchar(50)) CREATE TABLE #tmpSizeInt ( table_name sysname , row_count int, reserved_size...
2,732
<p>Can anyone explain this behavior? Running:</p> <pre><code>#!/bin/sh echo "hello world" | read var1 var2 echo $var1 echo $var2 </code></pre> <p>results in nothing being ouput, while:</p> <pre><code>#!/bin/sh echo "hello world" &gt; test.file read var1 var2 &lt; test.file echo $var1 echo $var2 </code></pre> <p>pro...
[ { "answer_id": 2764, "author": "Mark Harrison", "author_id": 116, "author_profile": "https://Stackoverflow.com/users/116", "pm_score": 3, "selected": false, "text": "<p>It's because the pipe version is creating a subshell, which reads the variable into its local space which then is destr...
2008/08/05
[ "https://Stackoverflow.com/questions/2732", "https://Stackoverflow.com", "https://Stackoverflow.com/users/75/" ]
Can anyone explain this behavior? Running: ``` #!/bin/sh echo "hello world" | read var1 var2 echo $var1 echo $var2 ``` results in nothing being ouput, while: ``` #!/bin/sh echo "hello world" > test.file read var1 var2 < test.file echo $var1 echo $var2 ``` produces the expected output: ``` hello world ``` Shoul...
A recent addition to `bash` is the `lastpipe` option, which allows the last command in a pipeline to run in the current shell, not a subshell, when job control is deactivated. ``` #!/bin/bash set +m # Deactiveate job control shopt -s lastpipe echo "hello world" | read var1 var2 echo $var1 echo $var2 ``` will in...
2,775
<p>Here's what I use:</p> <pre><code>SELECT CAST(FLOOR(CAST(getdate() as FLOAT)) as DATETIME) </code></pre> <p>I'm thinking there may be a better and more elegant way.</p> <p>Requirements:</p> <ul> <li>It has to be as fast as possible (the less casting, the better).</li> <li>The final result has to be a <code>datet...
[ { "answer_id": 2781, "author": "Michael Stum", "author_id": 91, "author_profile": "https://Stackoverflow.com/users/91", "pm_score": 4, "selected": false, "text": "<p>Your <code>CAST</code>-<code>FLOOR</code>-<code>CAST</code> already seems to be the optimum way, at least on MS SQL Server...
2008/08/05
[ "https://Stackoverflow.com/questions/2775", "https://Stackoverflow.com", "https://Stackoverflow.com/users/434/" ]
Here's what I use: ``` SELECT CAST(FLOOR(CAST(getdate() as FLOAT)) as DATETIME) ``` I'm thinking there may be a better and more elegant way. Requirements: * It has to be as fast as possible (the less casting, the better). * The final result has to be a `datetime` type, not a string.
**SQL Server 2008 and up** In SQL Server 2008 and up, of course the fastest way is `Convert(date, @date)`. This can be cast back to a `datetime` or `datetime2` if necessary. **What Is Really Best In SQL Server 2005 and Older?** I've seen inconsistent claims about what's fastest for truncating the time from a date in...
2,780
<p>Let's say that we have an ARGB color:</p> <pre><code>Color argb = Color.FromARGB(127, 69, 12, 255); //Light Urple. </code></pre> <p>When this is painted on top of an existing color, the colors will blend. So when it is blended with white, the resulting color is <code>Color.FromARGB(255, 162, 133, 255);</code></p> ...
[ { "answer_id": 2789, "author": "Louis Brandy", "author_id": 2089740, "author_profile": "https://Stackoverflow.com/users/2089740", "pm_score": 5, "selected": true, "text": "<p>It's called <a href=\"http://en.wikipedia.org/wiki/Alpha_compositing\" rel=\"noreferrer\">alpha blending</a>.</p>...
2008/08/05
[ "https://Stackoverflow.com/questions/2780", "https://Stackoverflow.com", "https://Stackoverflow.com/users/45/" ]
Let's say that we have an ARGB color: ``` Color argb = Color.FromARGB(127, 69, 12, 255); //Light Urple. ``` When this is painted on top of an existing color, the colors will blend. So when it is blended with white, the resulting color is `Color.FromARGB(255, 162, 133, 255);` The solution should work like this: ```...
It's called [alpha blending](http://en.wikipedia.org/wiki/Alpha_compositing). In psuedocode, assuming the background color (blend) always has 255 alpha. Also assumes alpha is 0-255. ``` alpha=argb.alpha() r = (alpha/255)*argb.r() + (1 - alpha/255)*blend.r() g = (alpha/255)*argb.g() + (1 - alpha/255)*blend.g() b = (al...
2,811
<p>I have a table with a structure like the following:</p> <hr /> <div class="s-table-container"> <table class="s-table"> <thead> <tr> <th>LocationID</th> <th>AccountNumber</th> </tr> </thead> <tbody> <tr> <td>long-guid-here</td> <td>12345</td> </tr> <tr> <td>long-guid-here</td> <td>54321</td> </tr> </tbody> </table> <...
[ { "answer_id": 2825, "author": "Chris Leon", "author_id": 289, "author_profile": "https://Stackoverflow.com/users/289", "pm_score": 3, "selected": true, "text": "<p>try</p>\n\n<pre><code>SELECT\n 1 AS Tag,\n 0 AS Parent,\n AccountNumber AS [Root!1!AccountNumber!element]\nFROM\n ...
2008/08/05
[ "https://Stackoverflow.com/questions/2811", "https://Stackoverflow.com", "https://Stackoverflow.com/users/448/" ]
I have a table with a structure like the following: --- | LocationID | AccountNumber | | --- | --- | | long-guid-here | 12345 | | long-guid-here | 54321 | To pass into another stored procedure, I need the XML to look like this: ``` <root> <clientID>12345</clientID> <clientID>54321</clientID> </root> ``` ...
try ``` SELECT 1 AS Tag, 0 AS Parent, AccountNumber AS [Root!1!AccountNumber!element] FROM Location.LocationMDAccount WHERE LocationID = 'long-guid-here' FOR XML EXPLICIT ```
2,815
<p>I would like to make a nightly cron job that fetches my stackoverflow page and diffs it from the previous day's page, so I can see a change summary of my questions, answers, ranking, etc.</p> <p>Unfortunately, I couldn't get the right set of cookies, etc, to make this work. Any ideas?</p> <p>Also, when the beta i...
[ { "answer_id": 2818, "author": "sparkes", "author_id": 269, "author_profile": "https://Stackoverflow.com/users/269", "pm_score": 2, "selected": false, "text": "<p>Nice idea :)</p>\n\n<p>I presume you've used wget's</p>\n\n<pre><code>--load-cookies (filename)\n</code></pre>\n\n<p>might he...
2008/08/05
[ "https://Stackoverflow.com/questions/2815", "https://Stackoverflow.com", "https://Stackoverflow.com/users/116/" ]
I would like to make a nightly cron job that fetches my stackoverflow page and diffs it from the previous day's page, so I can see a change summary of my questions, answers, ranking, etc. Unfortunately, I couldn't get the right set of cookies, etc, to make this work. Any ideas? Also, when the beta is finished, will m...
Your status page is available now without logging in (click [logout](https://stackoverflow.com/users/logout?returnurl=%2fquestions%2f2815%2fhow-to-curl-or-wget-a-stackoverflow-page) and try it). When the beta-cookie is disabled, there will be nothing between you and your status page. For wget: ``` wget --no-cookies -...
2,840
<p>How do I page results in SQL Server 2005?</p> <p>I tried it in SQL Server 2000, but there was no reliable way to do this. I'm now wondering if SQL Server 2005 has any built in method?</p> <p>What I mean by paging is, for example, if I list users by their username, I want to be able to only return the first 10 reco...
[ { "answer_id": 2843, "author": "Pat", "author_id": 36, "author_profile": "https://Stackoverflow.com/users/36", "pm_score": 6, "selected": true, "text": "<p>You can use <code>the Row_Number()</code> function.\nIts used as follows:</p>\n\n<pre><code>SELECT Row_Number() OVER(ORDER BY UserNa...
2008/08/05
[ "https://Stackoverflow.com/questions/2840", "https://Stackoverflow.com", "https://Stackoverflow.com/users/383/" ]
How do I page results in SQL Server 2005? I tried it in SQL Server 2000, but there was no reliable way to do this. I'm now wondering if SQL Server 2005 has any built in method? What I mean by paging is, for example, if I list users by their username, I want to be able to only return the first 10 records, then the nex...
You can use `the Row_Number()` function. Its used as follows: ``` SELECT Row_Number() OVER(ORDER BY UserName) As RowID, UserFirstName, UserLastName FROM Users ``` From which it will yield a result set with a `RowID` field which you can use to page between. ``` SELECT * FROM ( SELECT Row_Number() OVER(ORDER BY...
2,844
<pre><code>#include &lt;stdio.h&gt; int main() { unsigned long long int num = 285212672; //FYI: fits in 29 bits int normalInt = 5; printf("My number is %d bytes wide and its value is %ul. A normal number is %d.\n", sizeof(num), num, normalInt); return 0; } </code></pre> <p>Output:</p> <pre><code>My nu...
[ { "answer_id": 2850, "author": "John Downey", "author_id": 200, "author_profile": "https://Stackoverflow.com/users/200", "pm_score": 10, "selected": true, "text": "<p>Use the ll (el-el) long-long modifier with the u (unsigned) conversion. (Works in windows, GNU).</p>\n\n<pre><code>printf...
2008/08/05
[ "https://Stackoverflow.com/questions/2844", "https://Stackoverflow.com", "https://Stackoverflow.com/users/432/" ]
``` #include <stdio.h> int main() { unsigned long long int num = 285212672; //FYI: fits in 29 bits int normalInt = 5; printf("My number is %d bytes wide and its value is %ul. A normal number is %d.\n", sizeof(num), num, normalInt); return 0; } ``` Output: ``` My number is 8 bytes wide and its value i...
Use the ll (el-el) long-long modifier with the u (unsigned) conversion. (Works in windows, GNU). ``` printf("%llu", 285212672); ```
2,871
<p>What would be the best way to fill a C# struct from a byte[] array where the data was from a C/C++ struct? The C struct would look something like this (my C is very rusty):</p> <pre><code>typedef OldStuff { CHAR Name[8]; UInt32 User; CHAR Location[8]; UInt32 TimeStamp; UInt32 Sequence; CHAR...
[ { "answer_id": 2881, "author": "Mufaka", "author_id": 449, "author_profile": "https://Stackoverflow.com/users/449", "pm_score": -1, "selected": false, "text": "<p>If you have a byte[] you should be able to use the BinaryReader class and set values on NewStuff using the available ReadX me...
2008/08/05
[ "https://Stackoverflow.com/questions/2871", "https://Stackoverflow.com", "https://Stackoverflow.com/users/206/" ]
What would be the best way to fill a C# struct from a byte[] array where the data was from a C/C++ struct? The C struct would look something like this (my C is very rusty): ``` typedef OldStuff { CHAR Name[8]; UInt32 User; CHAR Location[8]; UInt32 TimeStamp; UInt32 Sequence; CHAR Tracking[16]; ...
From what I can see in that context, you don't need to copy `SomeByteArray` into a buffer. You simply need to get the handle from `SomeByteArray`, pin it, copy the `IntPtr` data using `PtrToStructure` and then release. No need for a copy. That would be: ``` NewStuff ByteArrayToNewStuff(byte[] bytes) { GCHandle ha...
2,872
<p><strong>My Goal</strong></p> <p>I would like to have a main processing thread (non GUI), and be able to spin off GUIs in their own background threads as needed, and having my main non GUI thread keep working. Put another way, I want my main non GUI-thread to be the owner of the GUI-thread and not vice versa. I'm no...
[ { "answer_id": 2901, "author": "Ishmaeel", "author_id": 227, "author_profile": "https://Stackoverflow.com/users/227", "pm_score": 5, "selected": true, "text": "<p><strong>Application.Run</strong> method displays one (or more) forms and initiates the standard message loop which runs until...
2008/08/05
[ "https://Stackoverflow.com/questions/2872", "https://Stackoverflow.com", "https://Stackoverflow.com/users/446/" ]
**My Goal** I would like to have a main processing thread (non GUI), and be able to spin off GUIs in their own background threads as needed, and having my main non GUI thread keep working. Put another way, I want my main non GUI-thread to be the owner of the GUI-thread and not vice versa. I'm not sure this is even pos...
**Application.Run** method displays one (or more) forms and initiates the standard message loop which runs until all the forms are closed. You cannot force a return from that method except by closing all your forms or forcing an application shutdown. You can, however, pass an **ApplicationContext** (instad of a new Fo...
2,874
<p>I have a control that is modelled on a <strong>ComboBox</strong>. I want to render the control so that the control <strong>border</strong> looks like that of a standard <strong>Windows ComboBox</strong>. Specifically, I have followed the MSDN documentation and all the rendering of the control is correct except for r...
[ { "answer_id": 13319, "author": "Nick", "author_id": 1490, "author_profile": "https://Stackoverflow.com/users/1490", "pm_score": 1, "selected": false, "text": "<p>Are any of the <a href=\"http://msdn.microsoft.com/en-us/library/system.windows.forms.controlpaint_members.aspx\" rel=\"nofol...
2008/08/05
[ "https://Stackoverflow.com/questions/2874", "https://Stackoverflow.com", "https://Stackoverflow.com/users/441/" ]
I have a control that is modelled on a **ComboBox**. I want to render the control so that the control **border** looks like that of a standard **Windows ComboBox**. Specifically, I have followed the MSDN documentation and all the rendering of the control is correct except for rendering when the control is disabled. Ju...
I'm not 100% sure if this is what you are looking for but you should check out the **VisualStyleRenderer** in the System.Windows.Forms.VisualStyles-namespace. 1. [VisualStyleRenderer class](http://msdn.microsoft.com/en-us/library/system.windows.forms.visualstyles.visualstylerenderer.aspx) (MSDN) 2. [How to: Render a V...
2,900
<p>I am getting the following error:</p> <blockquote> <p>Access denied for user 'apache'@'localhost' (using password: NO)</p> </blockquote> <p>When using the following code:</p> <pre><code>&lt;?php include("../includes/connect.php"); $query = "SELECT * from story"; $result = mysql_query($query) or die(mysql_err...
[ { "answer_id": 2908, "author": "Teifion", "author_id": 1384652, "author_profile": "https://Stackoverflow.com/users/1384652", "pm_score": 1, "selected": false, "text": "<p>Just to check, if you use <strong>just</strong> this part you get an error?</p>\n\n<pre><code>&lt;?php\ninclude(\"../...
2008/08/05
[ "https://Stackoverflow.com/questions/2900", "https://Stackoverflow.com", "https://Stackoverflow.com/users/454/" ]
I am getting the following error: > > Access denied for user 'apache'@'localhost' (using password: NO) > > > When using the following code: ``` <?php include("../includes/connect.php"); $query = "SELECT * from story"; $result = mysql_query($query) or die(mysql_error()); echo "<h1>Delete Story</h1>"; if (mys...
> > And if it matters at all, apache@localhost is not the name of the user account that I use to get into the database. I don't have any user accounts with the name apache in them at all for that matter. > > > If it is saying 'apache@localhost' the username is not getting passed correctly to the MySQL connection. ...
2,914
<p>Occasionally, I've come across a webpage that tries to pop open a new window (for user input, or something important), but the popup blocker prevents this from happening.</p> <p>What methods can the calling window use to make sure the new window launched properly?</p>
[ { "answer_id": 2917, "author": "omar", "author_id": 453, "author_profile": "https://Stackoverflow.com/users/453", "pm_score": 9, "selected": true, "text": "<p>If you use JavaScript to open the popup, you can use something like this:</p>\n\n<pre><code>var newWin = window.open(url); ...
2008/08/05
[ "https://Stackoverflow.com/questions/2914", "https://Stackoverflow.com", "https://Stackoverflow.com/users/434/" ]
Occasionally, I've come across a webpage that tries to pop open a new window (for user input, or something important), but the popup blocker prevents this from happening. What methods can the calling window use to make sure the new window launched properly?
If you use JavaScript to open the popup, you can use something like this: ``` var newWin = window.open(url); if(!newWin || newWin.closed || typeof newWin.closed=='undefined') { //POPUP BLOCKED } ```
2,970
<p>My dad called me today and said people going to his website were getting 168 viruses trying to download to their computers. He isn't technical at all, and built the whole thing with a WYSIWYG editor.</p> <p>I popped his site open and viewed the source, and there was a line of Javascript includes at the bottom of th...
[ { "answer_id": 2973, "author": "Justin Standard", "author_id": 92, "author_profile": "https://Stackoverflow.com/users/92", "pm_score": 2, "selected": false, "text": "<p>With a six word character password, he may have been brute forced. That is more likely than his ftp being intercepted,...
2008/08/05
[ "https://Stackoverflow.com/questions/2970", "https://Stackoverflow.com", "https://Stackoverflow.com/users/58/" ]
My dad called me today and said people going to his website were getting 168 viruses trying to download to their computers. He isn't technical at all, and built the whole thing with a WYSIWYG editor. I popped his site open and viewed the source, and there was a line of Javascript includes at the bottom of the source r...
Try and gather as much information as you can. See if the host can give you a log showing all the FTP connections that were made to your account. You can use those to see if it was even an FTP connection that was used to make the change and possibly get an IP address. If you're using a prepacked software like Wordpres...
2,993
<p>I'm in an environment with a lot of computers that haven't been properly inventoried. Basically, no one knows which IP goes with which mac address and which hostname. So I wrote the following:</p> <pre><code># This script goes down the entire IP range and attempts to # retrieve the Hostname and mac address and outp...
[ { "answer_id": 3012, "author": "Ecton", "author_id": 457, "author_profile": "https://Stackoverflow.com/users/457", "pm_score": 3, "selected": false, "text": "<p>I would check out <code>getaddrinfo</code>. If you replace the line:</p>\n\n<pre><code>host_name = Socket.gethostbyname(current...
2008/08/06
[ "https://Stackoverflow.com/questions/2993", "https://Stackoverflow.com", "https://Stackoverflow.com/users/155/" ]
I'm in an environment with a lot of computers that haven't been properly inventoried. Basically, no one knows which IP goes with which mac address and which hostname. So I wrote the following: ``` # This script goes down the entire IP range and attempts to # retrieve the Hostname and mac address and outputs them # int...
Today I also needed reverse DNS lookup and I've found very simple standard solution: ``` require 'resolv' host_name = Resolv.getname(ip_address_here) ``` It seems it uses timeout which helps in rough cases.
3,033
<p>If I have a Perl hash with a bunch of (key, value) pairs, what is the preferred method of iterating through all the keys? I have heard that using <code>each</code> may in some way have unintended side effects. So, is that true, and is one of the two following methods best, or is there a better way?</p> <pre><code...
[ { "answer_id": 3066, "author": "jj33", "author_id": 430, "author_profile": "https://Stackoverflow.com/users/430", "pm_score": 2, "selected": false, "text": "<p>I may get bitten by this one but I think that it's personal preference. I can't find any reference in the docs to each() being ...
2008/08/06
[ "https://Stackoverflow.com/questions/3033", "https://Stackoverflow.com", "https://Stackoverflow.com/users/219/" ]
If I have a Perl hash with a bunch of (key, value) pairs, what is the preferred method of iterating through all the keys? I have heard that using `each` may in some way have unintended side effects. So, is that true, and is one of the two following methods best, or is there a better way? ``` # Method 1 while (my ($key...
The rule of thumb is to use the function most suited to your needs. If you just want the keys and do not plan to ever *read* any of the values, use keys(): ``` foreach my $key (keys %hash) { ... } ``` If you just want the values, use values(): ``` foreach my $val (values %hash) { ... } ``` If you need the keys *...
3,058
<p>Inversion of Control (IoC) can be quite confusing when it is first encountered.</p> <ol> <li>What is it?</li> <li>Which problem does it solve?</li> <li>When is it appropriate to use and when not?</li> </ol>
[ { "answer_id": 3082, "author": "Ecton", "author_id": 457, "author_profile": "https://Stackoverflow.com/users/457", "pm_score": 6, "selected": false, "text": "<ol>\n<li><p><a href=\"http://en.wikipedia.org/wiki/Inversion_of_control\" rel=\"noreferrer\">Wikipedia Article</a>. To me, invers...
2008/08/06
[ "https://Stackoverflow.com/questions/3058", "https://Stackoverflow.com", "https://Stackoverflow.com/users/358/" ]
Inversion of Control (IoC) can be quite confusing when it is first encountered. 1. What is it? 2. Which problem does it solve? 3. When is it appropriate to use and when not?
The **`Inversion-of-Control` (IoC)** pattern, is about providing *any kind* of `callback` (which controls reaction), instead of acting ourself directly (in other words, inversion and/or redirecting control to external handler/controller). The **`Dependency-Injection` (DI)** pattern is a more specific version of IoC pat...
3,061
<p>How do I call a function, using a string with the function's name? For example:</p> <pre><code>import foo func_name = &quot;bar&quot; call(foo, func_name) # calls foo.bar() </code></pre>
[ { "answer_id": 3071, "author": "Patrick Johnmeyer", "author_id": 363, "author_profile": "https://Stackoverflow.com/users/363", "pm_score": 12, "selected": true, "text": "<p>Given a module <code>foo</code> with method <code>bar</code>:</p>\n<pre><code>import foo\nbar = getattr(foo, 'bar')...
2008/08/06
[ "https://Stackoverflow.com/questions/3061", "https://Stackoverflow.com", "https://Stackoverflow.com/users/121/" ]
How do I call a function, using a string with the function's name? For example: ``` import foo func_name = "bar" call(foo, func_name) # calls foo.bar() ```
Given a module `foo` with method `bar`: ``` import foo bar = getattr(foo, 'bar') result = bar() ``` [`getattr`](https://docs.python.org/library/functions.html#getattr) can similarly be used on class instance bound methods, module-level methods, class methods... the list goes on.
3,112
<p>I have a perl variable <code>$results</code> that gets returned from a service. The value is supposed to be an array, and <code>$results</code> should be an array reference. However, when the array has only one item in it, <code>$results</code> will be set to that value, and not a referenced array that contains th...
[ { "answer_id": 3126, "author": "svrist", "author_id": 86, "author_profile": "https://Stackoverflow.com/users/86", "pm_score": -1, "selected": false, "text": "<p>I've just tested this with:</p>\n\n<blockquote>\n<pre><code>#!/usr/bin/perl -w\nuse strict;\n\nsub testit {\n\n my @ret = ();\n...
2008/08/06
[ "https://Stackoverflow.com/questions/3112", "https://Stackoverflow.com", "https://Stackoverflow.com/users/219/" ]
I have a perl variable `$results` that gets returned from a service. The value is supposed to be an array, and `$results` should be an array reference. However, when the array has only one item in it, `$results` will be set to that value, and not a referenced array that contains that one item. I want to do a `foreach`...
im not sure there's any other way than: > > > ``` > $result = [ $result ] if ref($result) ne 'ARRAY'; > foreach ..... > > ``` > >
3,136
<p>How can I set up my crontab to execute X script at 11:59PM every day without emailing me or creating any logs?</p> <p>Right now my crontab looks something like this</p> <pre><code>@daily /path/to/script.sh </code></pre>
[ { "answer_id": 3139, "author": "Michael Stum", "author_id": 91, "author_profile": "https://Stackoverflow.com/users/91", "pm_score": 4, "selected": true, "text": "<p>When you do crontab -e, try this:</p>\n\n<pre><code>59 23 * * * /usr/sbin/myscript &gt; /dev/null\n</code></pre>\n\n<p>That...
2008/08/06
[ "https://Stackoverflow.com/questions/3136", "https://Stackoverflow.com", "https://Stackoverflow.com/users/87/" ]
How can I set up my crontab to execute X script at 11:59PM every day without emailing me or creating any logs? Right now my crontab looks something like this ``` @daily /path/to/script.sh ```
When you do crontab -e, try this: ``` 59 23 * * * /usr/sbin/myscript > /dev/null ``` That means: At 59 Minutes and 23 Hours on every day (\*) on every month on every weekday, execute myscript. See **man crontab** for some more info and examples.
3,157
<p>In an application that heavily relies on <code>.htaccess</code> RewriteRules for its PrettyURLs (CakePHP in my case), how do I correctly set up directives to exclude certain directories from this rewriting? That is:</p> <pre><code>/appRoot/.htaccess app/ static/ </code></pre> <p>By default every ...
[ { "answer_id": 3159, "author": "GateKiller", "author_id": 383, "author_profile": "https://Stackoverflow.com/users/383", "pm_score": 1, "selected": false, "text": "<p>Remove the [L] from the previous rules:</p>\n\n<pre><code>RewriteBase /appRoot\n\nRewriteRule ^$ app/webroot/ &amp;nbsp; &...
2008/08/06
[ "https://Stackoverflow.com/questions/3157", "https://Stackoverflow.com", "https://Stackoverflow.com/users/476/" ]
In an application that heavily relies on `.htaccess` RewriteRules for its PrettyURLs (CakePHP in my case), how do I correctly set up directives to exclude certain directories from this rewriting? That is: ``` /appRoot/.htaccess app/ static/ ``` By default every request to `/appRoot/*` is being rewr...
And the correct answer iiiiis... ``` RewriteRule ^(a|bunch|of|old|directories).* - [NC,L] # all other requests will be forwarded to Cake RewriteRule ^$ app/webroot/ [L] RewriteRule (.*) app/webroot/$1 [L] ``` I still don't get why the index.php file in the root directory was called initially even with the...
3,163
<p>I have been trying to find a really fast way to parse yyyy-mm-dd [hh:mm:ss] into a Date object. Here are the 3 ways I have tried doing it and the times it takes each method to parse 50,000 date time strings.</p> <p>Does anyone know any faster ways of doing this or tips to speed up the methods?</p> <pre><code>castM...
[ { "answer_id": 3185, "author": "GateKiller", "author_id": 383, "author_profile": "https://Stackoverflow.com/users/383", "pm_score": 2, "selected": false, "text": "<p>I'm guessing Date.Parse() doesn't work?</p>\n" }, { "answer_id": 3194, "author": "GateKiller", "author_id"...
2008/08/06
[ "https://Stackoverflow.com/questions/3163", "https://Stackoverflow.com", "https://Stackoverflow.com/users/22/" ]
I have been trying to find a really fast way to parse yyyy-mm-dd [hh:mm:ss] into a Date object. Here are the 3 ways I have tried doing it and the times it takes each method to parse 50,000 date time strings. Does anyone know any faster ways of doing this or tips to speed up the methods? ``` castMethod1 takes 3673 ms ...
I've been using the following snipplet to parse UTC date strings: ``` private function parseUTCDate( str : String ) : Date { var matches : Array = str.match(/(\d\d\d\d)-(\d\d)-(\d\d) (\d\d):(\d\d):(\d\d)Z/); var d : Date = new Date(); d.setUTCFullYear(int(matches[1]), int(matches[2]) - 1, int(matches[3])...
3,164
<p>If I have managed to locate and verify the existence of a file using Server.MapPath and I now want to send the user directly to that file, what is the <strong>fastest</strong> way to convert that absolute path back into a relative web path?</p>
[ { "answer_id": 3178, "author": "Yaakov Ellis", "author_id": 51, "author_profile": "https://Stackoverflow.com/users/51", "pm_score": 2, "selected": false, "text": "<p>If you used Server.MapPath, then you should already have the relative web path. According to the <a href=\"http://msdn.mic...
2008/08/06
[ "https://Stackoverflow.com/questions/3164", "https://Stackoverflow.com", "https://Stackoverflow.com/users/192/" ]
If I have managed to locate and verify the existence of a file using Server.MapPath and I now want to send the user directly to that file, what is the **fastest** way to convert that absolute path back into a relative web path?
Perhaps this might work: ``` String RelativePath = AbsolutePath.Replace(Request.ServerVariables["APPL_PHYSICAL_PATH"], String.Empty); ``` *I'm using c# but could be adapted to vb.*
3,196
<p>If I have data like this:</p> <div class="s-table-container"> <table class="s-table"> <thead> <tr> <th>Key</th> <th>Name</th> </tr> </thead> <tbody> <tr> <td>1</td> <td>Dan</td> </tr> <tr> <td>2</td> <td>Tom</td> </tr> <tr> <td>3</td> <td>Jon</td> </tr> <tr> <td>4</td> <td>Tom</td> </tr> <tr> <td>5</td> <td>Sam</td>...
[ { "answer_id": 3197, "author": "GateKiller", "author_id": 383, "author_profile": "https://Stackoverflow.com/users/383", "pm_score": 6, "selected": true, "text": "<p>Couldn't be simpler...</p>\n\n<pre class=\"lang-sql prettyprint-override\"><code>Select Name, Count(Name) As Count \n Fr...
2008/08/06
[ "https://Stackoverflow.com/questions/3196", "https://Stackoverflow.com", "https://Stackoverflow.com/users/230/" ]
If I have data like this: | Key | Name | | --- | --- | | 1 | Dan | | 2 | Tom | | 3 | Jon | | 4 | Tom | | 5 | Sam | | 6 | Dan | What is the SQL query to bring back the records where `Name` is repeated 2 or more times? So the result I would want is | Tom | | --- | | Dan |
Couldn't be simpler... ```sql Select Name, Count(Name) As Count From Table Group By Name Having Count(Name) > 1 Order By Count(Name) Desc ``` This could also be extended to delete duplicates: ```sql Delete From Table Where Key In ( Select Max(Key) From Table Group By Name ...
3,213
<p>Is there an efficient method of converting an integer into the written numbers, for example:</p> <pre><code>string Written = IntegerToWritten(21); </code></pre> <p>would return "Twenty One".</p> <p>Is there any way of doing this that doesn't involve a massive look-up table?</p>
[ { "answer_id": 3215, "author": "lubos hasko", "author_id": 275, "author_profile": "https://Stackoverflow.com/users/275", "pm_score": 2, "selected": false, "text": "<p>why massive lookup table?</p>\n\n<pre><code>string GetWrittenInteger(int n)\n{\n string[] a = new string[] {\"One\", \"T...
2008/08/06
[ "https://Stackoverflow.com/questions/3213", "https://Stackoverflow.com", "https://Stackoverflow.com/users/383/" ]
Is there an efficient method of converting an integer into the written numbers, for example: ``` string Written = IntegerToWritten(21); ``` would return "Twenty One". Is there any way of doing this that doesn't involve a massive look-up table?
This should work reasonably well: ``` public static class HumanFriendlyInteger { static string[] ones = new string[] { "", "One", "Two", "Three", "Four", "Five", "Six", "Seven", "Eight", "Nine" }; static string[] teens = new string[] { "Ten", "Eleven", "Twelve", "Thirteen", "Fourteen", "Fifteen", "Sixteen", "S...
3,224
<p>CSS and Javascript files don't change very often, so I want them to be cached by the web browser. But I also want the web browser to see changes made to these files without requiring the user to clear their browser cache. Also want a solution that works well with a version control system such as Subversion.</p> <hr ...
[ { "answer_id": 3225, "author": "grom", "author_id": 486, "author_profile": "https://Stackoverflow.com/users/486", "pm_score": 6, "selected": true, "text": "<p>I found that if you append the last modified timestamp of the file onto the end of the URL the browser will request the files whe...
2008/08/06
[ "https://Stackoverflow.com/questions/3224", "https://Stackoverflow.com", "https://Stackoverflow.com/users/486/" ]
CSS and Javascript files don't change very often, so I want them to be cached by the web browser. But I also want the web browser to see changes made to these files without requiring the user to clear their browser cache. Also want a solution that works well with a version control system such as Subversion. --- > > ...
I found that if you append the last modified timestamp of the file onto the end of the URL the browser will request the files when it is modified. For example in PHP: ``` function urlmtime($url) { $parsed_url = parse_url($url); $path = $parsed_url['path']; if ($path[0] == "/") { $filename = $_SERVER['...
3,234
<p>How would one display any add content from a "dynamic" aspx page? Currently I am working on using the System.Web.HttpResponse "Page.Response" to write a file that is stored on a web server to a web request.</p> <p>This would allow people to hit a url to the type <a href="http://www.foo.com?Image=test.jpg" rel="nore...
[ { "answer_id": 3240, "author": "GateKiller", "author_id": 383, "author_profile": "https://Stackoverflow.com/users/383", "pm_score": 0, "selected": false, "text": "<p>This is part of a solution I use on a local intranet. Some of the variables you will have to collect yourself as I pull th...
2008/08/06
[ "https://Stackoverflow.com/questions/3234", "https://Stackoverflow.com", "https://Stackoverflow.com/users/231/" ]
How would one display any add content from a "dynamic" aspx page? Currently I am working on using the System.Web.HttpResponse "Page.Response" to write a file that is stored on a web server to a web request. This would allow people to hit a url to the type <http://www.foo.com?Image=test.jpg> and have the image display ...
This is ugly, but the best way is to look at the file and set the content type as appropriate: ``` switch ( fileExtension ) { case "pdf": Response.ContentType = "application/pdf"; break; case "swf": Response.ContentType = "application/x-shockwave-flash"; break; case "gif": Response.ContentType = "image/...
3,255
<p>Most people with a degree in CS will certainly know what <a href="http://www.nist.gov/dads/HTML/bigOnotation.html" rel="noreferrer">Big O stands for</a>. It helps us to measure how well an algorithm scales. </p> <p>But I'm curious, how do <em>you</em> calculate or approximate the complexity of your algorithms?</p>
[ { "answer_id": 3280, "author": "Matt Mitchell", "author_id": 364, "author_profile": "https://Stackoverflow.com/users/364", "pm_score": 3, "selected": false, "text": "<p>Familiarity with the algorithms/data structures I use and/or quick glance analysis of iteration nesting. The difficult...
2008/08/06
[ "https://Stackoverflow.com/questions/3255", "https://Stackoverflow.com", "https://Stackoverflow.com/users/46/" ]
Most people with a degree in CS will certainly know what [Big O stands for](http://www.nist.gov/dads/HTML/bigOnotation.html). It helps us to measure how well an algorithm scales. But I'm curious, how do *you* calculate or approximate the complexity of your algorithms?
I'll do my best to explain it here on simple terms, but be warned that this topic takes my students a couple of months to finally grasp. You can find more information on the Chapter 2 of the [Data Structures and Algorithms in Java](https://rads.stackoverflow.com/amzn/click/com/0321370139) book. --- There is no [mecha...
3,281
<p>I'm wondering if there's a way to do what I can do below with Python, in Ruby:</p> <pre><code>sum = reduce(lambda x, y: x + y, map(lambda x, y: x * y, weights, data)) </code></pre> <p>I have two arrays of equal sizes with the weights and data but I can't seem to find a function similar to map in Ruby, reduce I hav...
[ { "answer_id": 3314, "author": "Curt Hagenlocher", "author_id": 533, "author_profile": "https://Stackoverflow.com/users/533", "pm_score": 2, "selected": false, "text": "<p>The Array.zip function does an elementwise combination of arrays. It's not quite as clean as the Python syntax, but ...
2008/08/06
[ "https://Stackoverflow.com/questions/3281", "https://Stackoverflow.com", "https://Stackoverflow.com/users/484/" ]
I'm wondering if there's a way to do what I can do below with Python, in Ruby: ``` sum = reduce(lambda x, y: x + y, map(lambda x, y: x * y, weights, data)) ``` I have two arrays of equal sizes with the weights and data but I can't seem to find a function similar to map in Ruby, reduce I have working.
@Michiel de Mare Your Ruby 1.9 example can be shortened a bit further: ``` weights.zip(data).map(:*).reduce(:+) ``` Also note that in Ruby 1.8, if you require ActiveSupport (from Rails) you can use: ``` weights.zip(data).map(&:*).reduce(&:+) ```
3,284
<p>I've been working with <a href="http://msdn.microsoft.com/en-us/library/aa479030.aspx" rel="noreferrer">providers</a> a fair bit lately, and I came across an interesting situation where I wanted to have an abstract class that had an abstract static method. I read a few posts on the topic, and it sort of made sense, ...
[ { "answer_id": 3291, "author": "David Wengier", "author_id": 489, "author_profile": "https://Stackoverflow.com/users/489", "pm_score": 6, "selected": false, "text": "<p>Static methods cannot be inherited or overridden, and that is why they can't be abstract. Since static methods are defi...
2008/08/06
[ "https://Stackoverflow.com/questions/3284", "https://Stackoverflow.com", "https://Stackoverflow.com/users/493/" ]
I've been working with [providers](http://msdn.microsoft.com/en-us/library/aa479030.aspx) a fair bit lately, and I came across an interesting situation where I wanted to have an abstract class that had an abstract static method. I read a few posts on the topic, and it sort of made sense, but is there a nice clear expla...
Static methods are not *instantiated* as such, they're just available without an object reference. A call to a static method is done through the class name, not through an object reference, and the Intermediate Language (IL) code to call it will call the abstract method through the name of the class that defined it, n...
3,315
<p>I need to set the height of every textbox on my form, some of which are nested within other controls. I thought I could do something like this:</p> <pre><code>private static IEnumerator&lt;TextBox&gt; FindTextBoxes(Control rootControl) { foreach (Control control in rootControl.Controls) { if (contr...
[ { "answer_id": 3316, "author": "David Wengier", "author_id": 489, "author_profile": "https://Stackoverflow.com/users/489", "pm_score": 5, "selected": true, "text": "<p>As the compiler is telling you, you need to change your return type to IEnumerable. That is how the yield return syntax ...
2008/08/06
[ "https://Stackoverflow.com/questions/3315", "https://Stackoverflow.com", "https://Stackoverflow.com/users/503/" ]
I need to set the height of every textbox on my form, some of which are nested within other controls. I thought I could do something like this: ``` private static IEnumerator<TextBox> FindTextBoxes(Control rootControl) { foreach (Control control in rootControl.Controls) { if (control.Controls.Count > 0...
As the compiler is telling you, you need to change your return type to IEnumerable. That is how the yield return syntax works.
3,319
<p>How can I set the background color of an HTML element using css in JavaScript?</p>
[ { "answer_id": 3320, "author": "tags2k", "author_id": 192, "author_profile": "https://Stackoverflow.com/users/192", "pm_score": 5, "selected": false, "text": "<pre><code>var element = document.getElementById('element');\nelement.style.background = '#FF00AA';\n</code></pre>\n" }, { ...
2008/08/06
[ "https://Stackoverflow.com/questions/3319", "https://Stackoverflow.com", "https://Stackoverflow.com/users/383/" ]
How can I set the background color of an HTML element using css in JavaScript?
In general, CSS properties are converted to JavaScript by making them camelCase without any dashes. So `background-color` becomes `backgroundColor`. ``` function setColor(element, color) { element.style.backgroundColor = color; } // where el is the concerned element var el = document.getElementById('elementId'); ...
3,362
<p>I would like to be able to use the <kbd>Tab</kbd> key within a text box to tab over four spaces. The way it is now, the Tab key jumps my cursor to the next input.</p> <p>Is there some JavaScript that will capture the Tab key in the text box before it bubbles up to the UI?</p> <p>I understand some browsers (i.e. Fi...
[ { "answer_id": 3370, "author": "Tom", "author_id": 20, "author_profile": "https://Stackoverflow.com/users/20", "pm_score": 4, "selected": false, "text": "<p>The previous answer is fine, but I'm one of those guys that's firmly against mixing behavior with presentation (putting JavaScript ...
2008/08/06
[ "https://Stackoverflow.com/questions/3362", "https://Stackoverflow.com", "https://Stackoverflow.com/users/357/" ]
I would like to be able to use the `Tab` key within a text box to tab over four spaces. The way it is now, the Tab key jumps my cursor to the next input. Is there some JavaScript that will capture the Tab key in the text box before it bubbles up to the UI? I understand some browsers (i.e. FireFox) may not allow this....
Even if you capture the `keydown`/`keyup` event, those are the only events that the tab key fires, you still need some way to prevent the default action, moving to the next item in the tab order, from occurring. In Firefox you can call the `preventDefault()` method on the event object passed to your event handler. In ...
3,400
<p><strong>Note:</strong> I <em>am</em> using SQL's Full-text search capabilities, CONTAINS clauses and all - the * is the wildcard in full-text, % is for LIKE clauses only.</p> <p>I've read in several places now that "leading wildcard" searches (e.g. using "*overflow" to match "stackoverflow") is not supported in MS ...
[ { "answer_id": 3405, "author": "Kev", "author_id": 419, "author_profile": "https://Stackoverflow.com/users/419", "pm_score": 2, "selected": false, "text": "<p><strong>Note</strong>: this was the answer I submitted for the original version #1 of the question before the <code>CONTAINS</cod...
2008/08/06
[ "https://Stackoverflow.com/questions/3400", "https://Stackoverflow.com", "https://Stackoverflow.com/users/35/" ]
**Note:** I *am* using SQL's Full-text search capabilities, CONTAINS clauses and all - the \* is the wildcard in full-text, % is for LIKE clauses only. I've read in several places now that "leading wildcard" searches (e.g. using "\*overflow" to match "stackoverflow") is not supported in MS SQL. I'm considering using a...
Workaround only for leading wildcard: * store the text reversed in a different field (or in materialised view) * create a full text index on this column * find the reversed text with an \* ``` SELECT * FROM TABLENAME WHERE CONTAINS(TextColumnREV, '"mrethcraes*"'); ``` Of course there are many drawbacks, just for ...
3,432
<p>I know that you can insert multiple rows at once, is there a way to update multiple rows at once (as in, in one query) in MySQL?</p> <p>Edit: For example I have the following</p> <pre><code>Name id Col1 Col2 Row1 1 6 1 Row2 2 2 3 Row3 3 9 5 Row4 4 16 8 </code></pre> <p>I wan...
[ { "answer_id": 3439, "author": "UnkwnTech", "author_id": 115, "author_profile": "https://Stackoverflow.com/users/115", "pm_score": 3, "selected": false, "text": "<pre><code>UPDATE table1, table2 SET table1.col1='value', table2.col1='value' WHERE table1.col3='567' AND table2.col6='567'\n<...
2008/08/06
[ "https://Stackoverflow.com/questions/3432", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1384652/" ]
I know that you can insert multiple rows at once, is there a way to update multiple rows at once (as in, in one query) in MySQL? Edit: For example I have the following ``` Name id Col1 Col2 Row1 1 6 1 Row2 2 2 3 Row3 3 9 5 Row4 4 16 8 ``` I want to combine all the following Up...
Yes, that's possible - you can use INSERT ... ON DUPLICATE KEY UPDATE. Using your example: ``` INSERT INTO table (id,Col1,Col2) VALUES (1,1,1),(2,2,3),(3,9,3),(4,10,12) ON DUPLICATE KEY UPDATE Col1=VALUES(Col1),Col2=VALUES(Col2); ```
3,437
<p>We recently discovered that the Google Maps API does not play nicely with SSL. Fair enough, but what are some options for overcoming this that others have used effectively?</p> <blockquote> <p><a href="http://code.google.com/support/bin/answer.py?answer=65301&amp;topic=10945" rel="noreferrer">Will the Maps API w...
[ { "answer_id": 3476, "author": "GateKiller", "author_id": 383, "author_profile": "https://Stackoverflow.com/users/383", "pm_score": 2, "selected": false, "text": "<p>I would go with your first solution. This allows the user to focus on entering their credit card details.</p>\n\n<p>You ca...
2008/08/06
[ "https://Stackoverflow.com/questions/3437", "https://Stackoverflow.com", "https://Stackoverflow.com/users/308/" ]
We recently discovered that the Google Maps API does not play nicely with SSL. Fair enough, but what are some options for overcoming this that others have used effectively? > > [Will the Maps API work over SSL (HTTPS)?](http://code.google.com/support/bin/answer.py?answer=65301&topic=10945) > > > At this time, the M...
I'd agree with the previous two answers that in this instance it may be better from a usability perspective to split the two functions into separate screens. You really want your users to be focussed on entering complete and accurate credit card information, and having a map on the same screen may be distracting. For ...
3,470
<p>I have a very simple problem which requires a very quick and simple solution in SQL Server 2005.</p> <p>I have a table with x Columns. I want to be able to select one row from the table and then transform the columns into rows.</p> <pre><code>TableA Column1, Column2, Column3 </code></pre> <p>SQL Statement to rutu...
[ { "answer_id": 3473, "author": "Kev", "author_id": 419, "author_profile": "https://Stackoverflow.com/users/419", "pm_score": 4, "selected": true, "text": "<p>You should take a look at the UNPIVOT clause.</p>\n\n<p><strong>Update1</strong>: GateKiller, strangely enough I read an article (...
2008/08/06
[ "https://Stackoverflow.com/questions/3470", "https://Stackoverflow.com", "https://Stackoverflow.com/users/383/" ]
I have a very simple problem which requires a very quick and simple solution in SQL Server 2005. I have a table with x Columns. I want to be able to select one row from the table and then transform the columns into rows. ``` TableA Column1, Column2, Column3 ``` SQL Statement to ruturn ``` ResultA Value of Column1 ...
You should take a look at the UNPIVOT clause. **Update1**: GateKiller, strangely enough I read an article (about something unrelated) about it this morning and I'm trying to jog my memory where I saw it again, had some decent looking examples too. It'll come back to me I'm sure. **Update2**: Found it: <http://weblogs...
3,486
<p>I have control over the HttpServer but not over the ApplicationServer or the Java Applications sitting there but I need to block direct access to certain pages on those applications. Precisely, I don't want users automating access to forms issuing direct GET/POST HTTP requests to the appropriate servlet. </p> <p>So...
[ { "answer_id": 3502, "author": "Rytmis", "author_id": 266, "author_profile": "https://Stackoverflow.com/users/266", "pm_score": 1, "selected": false, "text": "<p>I don't have a solution, but I'm betting that relying on the referrer will never work because user-agents are free to not send...
2008/08/06
[ "https://Stackoverflow.com/questions/3486", "https://Stackoverflow.com", "https://Stackoverflow.com/users/527/" ]
I have control over the HttpServer but not over the ApplicationServer or the Java Applications sitting there but I need to block direct access to certain pages on those applications. Precisely, I don't want users automating access to forms issuing direct GET/POST HTTP requests to the appropriate servlet. So, I decide...
I'm not sure if I can solve this in one go, but we can go back and forth as necessary. First, I want to repeat what I think you are saying and make sure I'm clear. You want to disallow requests to servlet1 and servlet2 is the request doesn't have the proper referer and it **does** have a query string? I'm not sure I u...
3,510
<p>What is BODMAS and why is it useful in programming?</p>
[ { "answer_id": 3511, "author": "Michael Stum", "author_id": 91, "author_profile": "https://Stackoverflow.com/users/91", "pm_score": 5, "selected": true, "text": "<p><a href=\"http://www.easymaths.com/What_on_earth_is_Bodmas.htm\" rel=\"noreferrer\">http://www.easymaths.com/What_on_earth_...
2008/08/06
[ "https://Stackoverflow.com/questions/3510", "https://Stackoverflow.com", "https://Stackoverflow.com/users/383/" ]
What is BODMAS and why is it useful in programming?
<http://www.easymaths.com/What_on_earth_is_Bodmas.htm>: > > What do you think the answer to 2 + 3 x 5 is? > > > Is it (2 + 3) x 5 = 5 x 5 = 25 ? > > > or 2 + (3 x 5) = 2 + 15 = 17 ? > > > BODMAS can come to the rescue and give us rules to follow so that we always get the right answer: > > > (B)rackets (O)rder...
3,530
<p>I have a <code>Rakefile</code> with a Rake task that I would normally call from the command line:</p> <pre><code>rake blog:post Title </code></pre> <p>I'd like to write a Ruby script that calls that Rake task multiple times, but the only solution I see is shelling out using `` (backticks) or <code>system</code>.</...
[ { "answer_id": 3543, "author": "titanous", "author_id": 399, "author_profile": "https://Stackoverflow.com/users/399", "pm_score": 7, "selected": true, "text": "<p>from <a href=\"http://web.archive.org/web/20090412040557/http://timocracy.com:80/articles/2008/02/21/calling-invoking-rails-r...
2008/08/06
[ "https://Stackoverflow.com/questions/3530", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1388162/" ]
I have a `Rakefile` with a Rake task that I would normally call from the command line: ``` rake blog:post Title ``` I'd like to write a Ruby script that calls that Rake task multiple times, but the only solution I see is shelling out using `` (backticks) or `system`. What's the right way to do this?
from [timocracy.com](http://web.archive.org/web/20090412040557/http://timocracy.com:80/articles/2008/02/21/calling-invoking-rails-rake-tasks-from-within-ruby-for-testing-try-2): ``` require 'rake' def capture_stdout s = StringIO.new oldstdout = $stdout $stdout = s yield s.string ensure $stdout = oldstdout...
3,567
<p>In SQL Server how do you query a database to bring back all the tables that have a field of a specific name?</p>
[ { "answer_id": 3574, "author": "Stu", "author_id": 414, "author_profile": "https://Stackoverflow.com/users/414", "pm_score": 0, "selected": false, "text": "<pre><code>SELECT Table_Name\nFROM Information_Schema.Columns\nWHERE Column_Name = 'YourFieldName'\n</code></pre>\n" }, { "a...
2008/08/06
[ "https://Stackoverflow.com/questions/3567", "https://Stackoverflow.com", "https://Stackoverflow.com/users/230/" ]
In SQL Server how do you query a database to bring back all the tables that have a field of a specific name?
The following query will bring back a unique list of tables where `Column_Name` is equal to the column you are looking for: ``` SELECT Table_Name FROM INFORMATION_SCHEMA.COLUMNS WHERE Column_Name = 'Desired_Column_Name' GROUP BY Table_Name ```
3,585
<p>I want to create my Rails application with MySQL, because I like it so much. How can I do that in the latest version of Rails instead of the default SQLite?</p>
[ { "answer_id": 3586, "author": "Daniel Broekman", "author_id": 124, "author_profile": "https://Stackoverflow.com/users/124", "pm_score": 8, "selected": false, "text": "<p>Normally, you would create a new Rails app using</p>\n\n<pre><code>rails ProjectName\n</code></pre>\n\n<p>To use MySQ...
2008/08/06
[ "https://Stackoverflow.com/questions/3585", "https://Stackoverflow.com", "https://Stackoverflow.com/users/124/" ]
I want to create my Rails application with MySQL, because I like it so much. How can I do that in the latest version of Rails instead of the default SQLite?
If you already have a rails project, change the adapter in the `config/database.yml` file to `mysql` and make sure you specify a valid username and password, and optionally, a socket: ``` development: adapter: mysql2 database: db_name_dev username: koploper password: host: localhost socket: /tmp/mysql.sock...
3,607
<p>I've got TotroiseSVN installed and have a majority of my repositories checking in and out from C:\subversion\ <em>and a couple checking in and out from a network share (I forgot about this when I originally posted this question)</em>.</p> <p>This means that I don't have a "subversion" server per-se.</p> <p>How do ...
[ { "answer_id": 3610, "author": "cmcculloh", "author_id": 58, "author_profile": "https://Stackoverflow.com/users/58", "pm_score": 4, "selected": false, "text": "<p><strong>This answer is incomplete and flawed! It only works from TortoisSVN to Fogbugz, but not the other way around. I still...
2008/08/06
[ "https://Stackoverflow.com/questions/3607", "https://Stackoverflow.com", "https://Stackoverflow.com/users/58/" ]
I've got TotroiseSVN installed and have a majority of my repositories checking in and out from C:\subversion\ *and a couple checking in and out from a network share (I forgot about this when I originally posted this question)*. This means that I don't have a "subversion" server per-se. How do I integrate TortoiseSVN ...
I've been investigating this issue and have managed to get it working. There are a couple of minor problems but they can be worked-around. There are 3 distinct parts to this problem, as follows: 1. **The TortoiseSVN part** - getting TortoiseSVN to insert the Bugid and hyperlink in the svn log 2. **The FogBugz part** ...
3,611
<p>I'm trying to write some PHP to upload a file to a folder on my webserver. Here's what I have:</p> <pre><code>&lt;?php if ( !empty($_FILES['file']['tmp_name']) ) { move_uploaded_file($_FILES['file']['tmp_name'], './' . $_FILES['file']['name']); header('Location: http://www.mywebsite.com/dump/');...
[ { "answer_id": 3617, "author": "sparkes", "author_id": 269, "author_profile": "https://Stackoverflow.com/users/269", "pm_score": 1, "selected": false, "text": "<p>Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'C:\\WINDOWS\\Temp\\phpA30E.tmp' to './people.xml...
2008/08/06
[ "https://Stackoverflow.com/questions/3611", "https://Stackoverflow.com", "https://Stackoverflow.com/users/402/" ]
I'm trying to write some PHP to upload a file to a folder on my webserver. Here's what I have: ``` <?php if ( !empty($_FILES['file']['tmp_name']) ) { move_uploaded_file($_FILES['file']['tmp_name'], './' . $_FILES['file']['name']); header('Location: http://www.mywebsite.com/dump/'); exit; ...
As it's Windows, there is no real 777. If you're using [chmod](http://fr2.php.net/manual/en/function.chmod.php), check the Windows-related comments. Check that the IIS Account can access (read, write, modify) these two folders: ``` E:\inetpub\vhosts\mywebsite.com\httpdocs\dump\ C:\WINDOWS\Temp\ ```
3,625
<p>I can't seem to find Developer Express' version of the <code>LinkButton</code>. (The Windows Forms linkbutton, not the <code>ASP.NET</code> linkbutton.) <code>HyperLinkEdit</code> doesn't seem to be what I'm looking for since it looks like a TextEdit/TextBox.</p> <p>Anyone know what their version of it is? I'm u...
[ { "answer_id": 3785, "author": "Greg Hurlman", "author_id": 35, "author_profile": "https://Stackoverflow.com/users/35", "pm_score": 0, "selected": false, "text": "<p>You should probably just use the standard ASP.Net LinkButton, unless it's really missing something you need.</p>\n" }, ...
2008/08/06
[ "https://Stackoverflow.com/questions/3625", "https://Stackoverflow.com", "https://Stackoverflow.com/users/549/" ]
I can't seem to find Developer Express' version of the `LinkButton`. (The Windows Forms linkbutton, not the `ASP.NET` linkbutton.) `HyperLinkEdit` doesn't seem to be what I'm looking for since it looks like a TextEdit/TextBox. Anyone know what their version of it is? I'm using the latest DevX controls: 8.2.1.
The control is called the HyperLinkEdit. You have to adjust the properties to get it to behave like the System.Windows.Forms control like so: ``` control.BorderStyle = BorderStyles.NoBorder; control.Properties.Appearance.BackColor = Color.Transparent; control.Properties.AppearanceFocused.BackColor = Color....
3,682
<p>I have a MySQL table with approximately 3000 rows per user. One of the columns is a datetime field, which is mutable, so the rows aren't in chronological order.</p> <p>I'd like to visualize the time distribution in a chart, so I need a number of individual datapoints. 20 datapoints would be enough.</p> <p>I could ...
[ { "answer_id": 3691, "author": "Michal Sznajder", "author_id": 501, "author_profile": "https://Stackoverflow.com/users/501", "pm_score": 1, "selected": false, "text": "<p>Something like this came to my mind</p>\n\n<pre><code>select @rownum:=@rownum+1 rownum, entries.* \nfrom (select @row...
2008/08/06
[ "https://Stackoverflow.com/questions/3682", "https://Stackoverflow.com", "https://Stackoverflow.com/users/136/" ]
I have a MySQL table with approximately 3000 rows per user. One of the columns is a datetime field, which is mutable, so the rows aren't in chronological order. I'd like to visualize the time distribution in a chart, so I need a number of individual datapoints. 20 datapoints would be enough. I could do this: ``` sel...
Michal Sznajder almost had it, but you can't use column aliases in a WHERE clause in SQL. So you have to wrap it as a derived table. I tried this and it returns 20 rows: ``` SELECT * FROM ( SELECT @rownum:=@rownum+1 AS rownum, e.* FROM (SELECT @rownum := 0) r, entries e) AS e2 WHERE uid = ? AND rownum % 150 = ...
3,713
<p>I'm writing a web page in ASP.NET. I have some JavaScript code, and I have a submit button with a click event.</p> <p>Is it possible to call a method I created in ASP with JavaScript's click event?</p>
[ { "answer_id": 3726, "author": "brendan", "author_id": 225, "author_profile": "https://Stackoverflow.com/users/225", "pm_score": 4, "selected": false, "text": "<p>You can do it asynchronously using .NET Ajax PageMethods. See <a href=\"http://web.archive.org/web/20170818234231/http://www....
2008/08/06
[ "https://Stackoverflow.com/questions/3713", "https://Stackoverflow.com", "https://Stackoverflow.com/users/557/" ]
I'm writing a web page in ASP.NET. I have some JavaScript code, and I have a submit button with a click event. Is it possible to call a method I created in ASP with JavaScript's click event?
Well, if you don't want to do it using Ajax or any other way and just want a normal ASP.NET postback to happen, here is how you do it (without using any other libraries): *It is a little tricky though... :)* i. In your code file (assuming you are using C# and .NET 2.0 or later) add the following Interface to your Pag...
3,725
<p>I'm writing an application that is basically just a preferences dialog, much like the tree-view preferences dialog that Visual Studio itself uses. The function of the application is simply a pass-through for data from a serial device to a file. It performs many, many transformations on the data before writing it to ...
[ { "answer_id": 3776, "author": "xyz", "author_id": 82, "author_profile": "https://Stackoverflow.com/users/82", "pm_score": 5, "selected": true, "text": "<p>A tidier way is to create separate forms for each 'pane' and, in each form constructor, set</p>\n\n<pre><code>this.TopLevel = false;...
2008/08/06
[ "https://Stackoverflow.com/questions/3725", "https://Stackoverflow.com", "https://Stackoverflow.com/users/551/" ]
I'm writing an application that is basically just a preferences dialog, much like the tree-view preferences dialog that Visual Studio itself uses. The function of the application is simply a pass-through for data from a serial device to a file. It performs many, many transformations on the data before writing it to the...
A tidier way is to create separate forms for each 'pane' and, in each form constructor, set ``` this.TopLevel = false; this.FormBorderStyle = FormBorderStyle.None; this.Dock = DockStyle.Fill; ``` That way, each of these forms can be laid out in its own designer, instantiated one or more times at runtime, and added t...
3,739
<p>I have an unusual situation in which I need a SharePoint timer job to both have local administrator windows privileges and to have <code>SHAREPOINT\System</code> SharePoint privileges.</p> <p>I can get the windows privileges by simply configuring the timer service to use an account which is a member of local admini...
[ { "answer_id": 3741, "author": "Michael Stum", "author_id": 91, "author_profile": "https://Stackoverflow.com/users/91", "pm_score": 1, "selected": false, "text": "<p>I'm not at work so this is off the top of my head, but: If you get a reference to the Site, can you try to create a new SP...
2008/08/06
[ "https://Stackoverflow.com/questions/3739", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I have an unusual situation in which I need a SharePoint timer job to both have local administrator windows privileges and to have `SHAREPOINT\System` SharePoint privileges. I can get the windows privileges by simply configuring the timer service to use an account which is a member of local administrators. I understan...
I'm not at work so this is off the top of my head, but: If you get a reference to the Site, can you try to create a new SPSite with the SYSTEM-UserToken? ``` SPUserToken sut = thisSite.RootWeb.AllUsers["SHAREPOINT\SYSTEM"].UserToken; using (SPSite syssite = new SPSite(thisSite.Url,sut) { // Do what you have to do...
3,793
<p>What's the best way to get the contents of the mixed <code>body</code> element in the code below? The element might contain either XHTML or text, but I just want its contents in string form. The <code>XmlElement</code> type has the <code>InnerXml</code> property which is exactly what I'm after.</p> <p>The code as...
[ { "answer_id": 3794, "author": "Greg Hurlman", "author_id": 35, "author_profile": "https://Stackoverflow.com/users/35", "pm_score": 0, "selected": false, "text": "<p>Is it possible to use the System.Xml namespace objects to get the job done here instead of using LINQ? As you already men...
2008/08/06
[ "https://Stackoverflow.com/questions/3793", "https://Stackoverflow.com", "https://Stackoverflow.com/users/205/" ]
What's the best way to get the contents of the mixed `body` element in the code below? The element might contain either XHTML or text, but I just want its contents in string form. The `XmlElement` type has the `InnerXml` property which is exactly what I'm after. The code as written *almost* does what I want, but inclu...
I wanted to see which of these suggested solutions performed best, so I ran some comparative tests. Out of interest, I also compared the LINQ methods to the plain old **System.Xml** method suggested by Greg. The variation was interesting and not what I expected, with the slowest methods being **more than 3 times slower...
3,839
<p>I'm trying out the following query:</p> <pre><code>SELECT A,B,C FROM table WHERE field LIKE 'query%' UNION SELECT A,B,C FROM table WHERE field LIKE '%query' UNION SELECT A,B,C FROM table WHERE field LIKE '%query%' GROUP BY B ORDER BY B ASC LIMIT 5 </code></pre> <p>That's three queries stuck together, kinda sorta. ...
[ { "answer_id": 3852, "author": "Mark Harrison", "author_id": 116, "author_profile": "https://Stackoverflow.com/users/116", "pm_score": 2, "selected": false, "text": "<p>Can you do it as a subselect, something like</p>\n\n<pre><code>SELECT * FROM (\n SELECT A,B,C FROM table WHERE field...
2008/08/06
[ "https://Stackoverflow.com/questions/3839", "https://Stackoverflow.com", "https://Stackoverflow.com/users/547/" ]
I'm trying out the following query: ``` SELECT A,B,C FROM table WHERE field LIKE 'query%' UNION SELECT A,B,C FROM table WHERE field LIKE '%query' UNION SELECT A,B,C FROM table WHERE field LIKE '%query%' GROUP BY B ORDER BY B ASC LIMIT 5 ``` That's three queries stuck together, kinda sorta. However, the result set th...
Maybe you should try including a fourth column, stating the table it came from, and then order and group by it: ``` SELECT A,B,C, "query 1" as origin FROM table WHERE field LIKE 'query%' UNION SELECT A,B,C, "query 2" as origin FROM table WHERE field LIKE '%query' UNION SELECT A,B,C, "query 3" as origin FROM table WHER...