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
185,573
<p>I couldn't really find this in Rails documentation but it seems like <strong>'mattr_accessor'</strong> is the <strong>Module</strong> corollary for <strong>'attr_accessor'</strong> (getter &amp; setter) in a normal Ruby <strong>class</strong>.</p> <p>Eg. in a class</p> <pre><code>class User attr_accessor :name ...
[ { "answer_id": 185632, "author": "Avdi", "author_id": 20487, "author_profile": "https://Stackoverflow.com/users/20487", "pm_score": 9, "selected": true, "text": "<p>Rails extends Ruby with both <code>mattr_accessor</code> (Module accessor) and <code>cattr_accessor</code> (as well as _<co...
2008/10/09
[ "https://Stackoverflow.com/questions/185573", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6048/" ]
I couldn't really find this in Rails documentation but it seems like **'mattr\_accessor'** is the **Module** corollary for **'attr\_accessor'** (getter & setter) in a normal Ruby **class**. Eg. in a class ``` class User attr_accessor :name def set_fullname @name = "#{self.first_name} #{self.last_name}" end...
Rails extends Ruby with both `mattr_accessor` (Module accessor) and `cattr_accessor` (as well as \_`reader`/`_writer` versions). As Ruby's `attr_accessor` generates getter/setter methods for *instances*, `cattr/mattr_accessor` provide getter/setter methods at the *class* or *module* level. Thus: ``` module Config ma...
185,575
<p>In bash the ampersand (&amp;) can be used to run a command in the background and return interactive control to the user before the command has finished running. Is there an equivalent method of doing this in Powershell?</p> <p>Example of usage in bash:</p> <pre><code> sleep 30 &amp; </code></pre>
[ { "answer_id": 186736, "author": "Jeffery Hicks", "author_id": 25508, "author_profile": "https://Stackoverflow.com/users/25508", "pm_score": 0, "selected": false, "text": "<p>I've used the solution described here <a href=\"http://jtruher.spaces.live.com/blog/cns!7143DA6E51A2628D!130.entr...
2008/10/09
[ "https://Stackoverflow.com/questions/185575", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5769/" ]
In bash the ampersand (&) can be used to run a command in the background and return interactive control to the user before the command has finished running. Is there an equivalent method of doing this in Powershell? Example of usage in bash: ``` sleep 30 & ```
As long as the command is an executable or a file that has an associated executable, use **Start-Process** (available from v2): ``` Start-Process -NoNewWindow ping google.com ``` You can also add this as a function in your profile: ``` function bg() {Start-Process -NoNewWindow @args} ``` and then the invocation b...
185,591
<p>What is this error? </p> <pre><code>cannot find symbol, symbol: method getstring(java.lang.String) Location: class InternalFrameDemo if &lt;!windowTitleField.getText().equals(getstring("InternalFrameDemo.frame_label"))) </code></pre>
[ { "answer_id": 185596, "author": "Draemon", "author_id": 26334, "author_profile": "https://Stackoverflow.com/users/26334", "pm_score": 2, "selected": false, "text": "<p>it means that the class InternalFrameDemo has no getstring() method - shouldn't that be \"getString\" with an uppercase...
2008/10/09
[ "https://Stackoverflow.com/questions/185591", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
What is this error? ``` cannot find symbol, symbol: method getstring(java.lang.String) Location: class InternalFrameDemo if <!windowTitleField.getText().equals(getstring("InternalFrameDemo.frame_label"))) ```
Java is case-sensitive. Because "getstring" is not equal to "getString", the compiler thinks the "getstring" method does not exist in the InternalFrameDemo class and throws back that error. In Java, methods will generally have the first letter of each word after the first word capitalized (e.g. toString(), toUpperCase...
185,594
<p>What data structure does the following declaration specify?</p> <pre><code> List&lt;ArrayList&gt;[] myArray; </code></pre> <p>I think it should declare an array where each element is a <code>List</code> (e.g., a <code>LinkedList</code> or an <code>ArrayList</code>) and require that each <code>List</code> contain <...
[ { "answer_id": 185619, "author": "Mark", "author_id": 26310, "author_profile": "https://Stackoverflow.com/users/26310", "pm_score": 3, "selected": false, "text": "<p>Mr Josh Bloch says: </p>\n\n<blockquote>\n <p>\"Prefer lists to array because arrays\n are covariant and generics are\n ...
2008/10/09
[ "https://Stackoverflow.com/questions/185594", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19685/" ]
What data structure does the following declaration specify? ``` List<ArrayList>[] myArray; ``` I think it should declare an array where each element is a `List` (e.g., a `LinkedList` or an `ArrayList`) and require that each `List` contain `ArrayList` objects. My reasoning: ``` List<String> someList; ...
The answer is that arrays can only hold reified types. And generified classes are not reified. That is, the runtime "type" of the List<ArrayList> is just List. Generics are erased at runtime (google "wall of erasure" for more). So this: ``` List<ArrayList>[] myArray ``` really means: ``` List[] myArray ``` Th...
185,606
<p>I wonder if this would be doable ? To insert an array into one field in the database.</p> <p>For instance I have a title, I want to have that title with only one id, but it's going to be bilingually used on the website.</p> <p>It feels a bit unnecessary to make another table to have their global ids and then anoth...
[ { "answer_id": 185616, "author": "bmdhacks", "author_id": 14032, "author_profile": "https://Stackoverflow.com/users/14032", "pm_score": 3, "selected": false, "text": "<p>There's really only two reasonable choices here:</p>\n\n<p><strong>Join with another table</strong><br/>\npros: unlimi...
2008/10/09
[ "https://Stackoverflow.com/questions/185606", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18671/" ]
I wonder if this would be doable ? To insert an array into one field in the database. For instance I have a title, I want to have that title with only one id, but it's going to be bilingually used on the website. It feels a bit unnecessary to make another table to have their global ids and then another table with the...
it's doable: ``` $title = serialize($array); ``` and then to decode: ``` $title = unserialize($mysql_data); ``` but as mentioned it really lessens the benefits of a database in the first place. i'd definitely suggest looking into a multi-table or multi-column option instead, depending on the amount of languages y...
185,624
<p>I have a function that is declared and defined in a header file. This is a problem all by itself. When that function is not inlined, every translation unit that uses that header gets a copy of the function, and when they are linked together there are duplicated. I "fixed" that by making the function inline, but I'm ...
[ { "answer_id": 185630, "author": "Jason Etheridge", "author_id": 2193, "author_profile": "https://Stackoverflow.com/users/2193", "pm_score": -1, "selected": false, "text": "<p>I believe you will end up with one per translation unit. You've effectively got many versions of that function (...
2008/10/09
[ "https://Stackoverflow.com/questions/185624", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13562/" ]
I have a function that is declared and defined in a header file. This is a problem all by itself. When that function is not inlined, every translation unit that uses that header gets a copy of the function, and when they are linked together there are duplicated. I "fixed" that by making the function inline, but I'm afr...
I guess you're missing something, here. static function? ---------------- Declaring a function static will make it "hidden" in its compilation unit. > > A name having namespace scope (3.3.6) has internal linkage if it is the name of > > > — a variable, function or function template that is explicitly declared sta...
185,648
<p>I have a ListBox with a bunch of images in it (done through a datatemplate). The images are created by setting the items source:</p> <pre><code>&lt;Image x:Name="ItemImage" Source="{Binding ImageUrl}"/&gt; </code></pre> <p>and then they are cleared by using the listbox's Items.Clear() method. New Images are add...
[ { "answer_id": 185655, "author": "David Aldridge", "author_id": 6742, "author_profile": "https://Stackoverflow.com/users/6742", "pm_score": 4, "selected": true, "text": "<p>Monitoring of the system health using statspack (9i) or AWR (10g+) would be the best method of identifying bottlene...
2008/10/09
[ "https://Stackoverflow.com/questions/185648", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3798/" ]
I have a ListBox with a bunch of images in it (done through a datatemplate). The images are created by setting the items source: ``` <Image x:Name="ItemImage" Source="{Binding ImageUrl}"/> ``` and then they are cleared by using the listbox's Items.Clear() method. New Images are added by using the Items.Add method o...
Monitoring of the system health using statspack (9i) or AWR (10g+) would be the best method of identifying bottlenecks. In particular: * lookout for redo waits. The redo log is critical in maintaining a high write rate * Use bind variables * Use bulk operations wherever possible. * Watch for index contention where mu...
185,652
<p>I have a UIImageView and the objective is to scale it down proportionally by giving it either a height or width. </p> <pre><code>UIImage *image = [[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://farm4.static.flickr.com/3092/2915896504_a88b69c9de.jpg"]]]; UIImageView *imageVi...
[ { "answer_id": 185788, "author": "user26359", "author_id": 26359, "author_profile": "https://Stackoverflow.com/users/26359", "pm_score": 0, "selected": false, "text": "<p>I think you can do something like</p>\n\n<pre><code>image.center = [[imageView window] center];\n</code></pre>\n" }...
2008/10/09
[ "https://Stackoverflow.com/questions/185652", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1987/" ]
I have a UIImageView and the objective is to scale it down proportionally by giving it either a height or width. ``` UIImage *image = [[UIImage alloc] initWithData:[NSData dataWithContentsOfURL:[NSURL URLWithString:@"http://farm4.static.flickr.com/3092/2915896504_a88b69c9de.jpg"]]]; UIImageView *imageView = [[UIImage...
Fixed easily, once I found the documentation! ``` imageView.contentMode = .scaleAspectFit ```
185,661
<p>I'd like to know if Flash/AS3 has any nice way to convert an AS3 'Date' object to/from rfc-850 timestamp format (as used by HTTP date and last-modified).</p> <p>This question is very similar to <a href="https://stackoverflow.com/questions/17017/how-do-i-parse-and-convert-datetimes-to-the-rfc-3339-date-time-format">...
[ { "answer_id": 185858, "author": "Raleigh Buckner", "author_id": 1153, "author_profile": "https://Stackoverflow.com/users/1153", "pm_score": 2, "selected": false, "text": "<p>The <a href=\"http://as3corelib.googlecode.com\" rel=\"nofollow noreferrer\">as3corelib</a> libraries have DateUt...
2008/10/09
[ "https://Stackoverflow.com/questions/185661", "https://Stackoverflow.com", "https://Stackoverflow.com/users/26331/" ]
I'd like to know if Flash/AS3 has any nice way to convert an AS3 'Date' object to/from rfc-850 timestamp format (as used by HTTP date and last-modified). This question is very similar to [this question about rfc 3339](https://stackoverflow.com/questions/17017/how-do-i-parse-and-convert-datetimes-to-the-rfc-3339-date-t...
Alright, so here's a couple of functions to do RFC-802/`Date` conversion in Flash. I learned that the `Date` object doesn't really have any notion of a timezone, and assumes that it is in the local timezone. If you pass an RFC-802 date to the `Date()` constructor, it parses it everything except the "GMT" timezone toke...
185,664
<p>I'm trying to create a user control that allows users to make something like the following:</p> <pre><code> &lt;uc1:MyControl id="controlThing" runat="server"&gt; &lt;uc1:BoundColumn id="column1" Column="Name" runat="server" /&gt; &lt;uc1:CheckBoxBoundColumn id="column2" Column="Selector" runat="server" /...
[ { "answer_id": 185672, "author": "Aaron Powell", "author_id": 11388, "author_profile": "https://Stackoverflow.com/users/11388", "pm_score": 0, "selected": false, "text": "<p>Is it possible for you to override an existing control such as a ListView or GridView? That's your simplest option...
2008/10/09
[ "https://Stackoverflow.com/questions/185664", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19753/" ]
I'm trying to create a user control that allows users to make something like the following: ``` <uc1:MyControl id="controlThing" runat="server"> <uc1:BoundColumn id="column1" Column="Name" runat="server" /> <uc1:CheckBoxBoundColumn id="column2" Column="Selector" runat="server" /> <uc1:BoundColumn id="co...
The PersistenceMode.InnerProperty is what you want.. Here are the [MSDN docs.](http://msdn.microsoft.com/en-us/library/system.web.ui.persistencemode.aspx) Doing something like this will get you what you want: ``` [PersistenceMode(PersistenceMode.InnerProperty)] public ListItem Items { get; set; } ``` and then you...
185,680
<p>How do I define nested class in Java Script. </p> <p>Here is the code snippet I have:</p> <pre><code>objA = new TestA(); function TestB () { this.testPrint = function () { print ( " Inside testPrint " ); } } function TestA () { var myObjB = new TestB(); } </code></pre> <p>Now I am trying to acces...
[ { "answer_id": 185684, "author": "Leo", "author_id": 20689, "author_profile": "https://Stackoverflow.com/users/20689", "pm_score": 3, "selected": false, "text": "<p>use this.myObjB instead of var myObjB</p>\n" }, { "answer_id": 185695, "author": "Aaron Maenpaa", "author_i...
2008/10/09
[ "https://Stackoverflow.com/questions/185680", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
How do I define nested class in Java Script. Here is the code snippet I have: ``` objA = new TestA(); function TestB () { this.testPrint = function () { print ( " Inside testPrint " ); } } function TestA () { var myObjB = new TestB(); } ``` Now I am trying to access testPrint using objA ``` objA....
If you want the prototype definition of the inner nested classes to be not accessible from outside the outer class, as well as a cleaner OO implementation, take a look at this. ``` var BobsGarage = BobsGarage || {}; // namespace /** * BobsGarage.Car * @constructor * @returns {BobsGarage.Car} */ BobsGarage.Car = f...
185,681
<p>How to parse the DOM and determine what row is selected in an ASP.NET <code>ListView</code>? I'm able to interact with the DOM via the <code>HtmlElement</code> in Silverlight, but I have not been able to locate a property indicating the row is selected.</p> <p>For reference, this managed method works fine for an ASP...
[ { "answer_id": 185897, "author": "Bryant", "author_id": 10893, "author_profile": "https://Stackoverflow.com/users/10893", "pm_score": 0, "selected": false, "text": "<p>I don't have my dev environment up to test this, but could you call GetProperty('selectedIndex') on the ListBoxID elemen...
2008/10/09
[ "https://Stackoverflow.com/questions/185681", "https://Stackoverflow.com", "https://Stackoverflow.com/users/21410/" ]
How to parse the DOM and determine what row is selected in an ASP.NET `ListView`? I'm able to interact with the DOM via the `HtmlElement` in Silverlight, but I have not been able to locate a property indicating the row is selected. For reference, this managed method works fine for an ASP.NET ListBox ``` var elm = Htm...
If your listview has a specific css class for selected row, you can try to filter on it
185,690
<p>I'm using the <a href="http://www.componentace.com/zlib_.NET.htm" rel="noreferrer">zlib.NET</a> library to try and inflate files that are compressed by zlib (on a Linux box, perhaps). Here's what I'm doing:</p> <pre><code>zlib.ZInputStream zinput = new zlib.ZInputStream(File.Open(path, FileMode.Open, FileAcces...
[ { "answer_id": 185736, "author": "Jon Skeet", "author_id": 22656, "author_profile": "https://Stackoverflow.com/users/22656", "pm_score": 3, "selected": false, "text": "<p>Other than failing to use a \"using\" statement to close the stream even in the face of an exception, that looks okay...
2008/10/09
[ "https://Stackoverflow.com/questions/185690", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3279/" ]
I'm using the [zlib.NET](http://www.componentace.com/zlib_.NET.htm) library to try and inflate files that are compressed by zlib (on a Linux box, perhaps). Here's what I'm doing: ``` zlib.ZInputStream zinput = new zlib.ZInputStream(File.Open(path, FileMode.Open, FileAccess.Read)); while (stopByte != (data = zinpu...
It appears I made the mistake of assuming all virtual methods were overridden, which wasn't the case. I was using zlib.ZInputStream.ReadByte(), which is just the inherited Stream.ReadByte(), which doesn't do any inflate. I used zlib.ZInputStream.Read() instead, and it worked like it should.
185,697
<p>Input: A positive integer K and a big text. The text can actually be viewed as word sequence. So we don't have to worry about how to break down it into word sequence.<br> Output: The most frequent K words in the text.</p> <p>My thinking is like this. </p> <ol> <li><p>use a Hash table to record all words' frequency...
[ { "answer_id": 185705, "author": "Aaron Maenpaa", "author_id": 2603, "author_profile": "https://Stackoverflow.com/users/2603", "pm_score": 3, "selected": false, "text": "<p>If your \"big word list\" is big enough, you can simply sample and get estimates. Otherwise, I like hash aggregatio...
2008/10/09
[ "https://Stackoverflow.com/questions/185697", "https://Stackoverflow.com", "https://Stackoverflow.com/users/26349/" ]
Input: A positive integer K and a big text. The text can actually be viewed as word sequence. So we don't have to worry about how to break down it into word sequence. Output: The most frequent K words in the text. My thinking is like this. 1. use a Hash table to record all words' frequency while traverse the whol...
This can be done in O(n) time **Solution 1:** Steps: 1. Count words and hash it, which will end up in the structure like this ``` var hash = { "I" : 13, "like" : 3, "meow" : 3, "geek" : 3, "burger" : 2, "cat" : 1, "foo" : 100, ... ... ``` 2. Traverse through the hash and find the most frequently ...
185,698
<p>I have a directory with several subdirectories with files.<br> How can I copy all files in the subdirectories to a new location?<br></p> <p><strong>Edit:</strong> I do not want to copy the directories, just the files...</p> <p>As this is still on XP, I chose the below solution:</p> <pre><code> for /D %S IN ("src\...
[ { "answer_id": 185703, "author": "Eric Tuttleman", "author_id": 25677, "author_profile": "https://Stackoverflow.com/users/25677", "pm_score": 2, "selected": false, "text": "<p>The Xcopy command should help here.</p>\n\n<pre><code>XCOPY /E SrcDir\\*.* DestDir\\\n</code></pre>\n\n<p>Or if ...
2008/10/09
[ "https://Stackoverflow.com/questions/185698", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14484/" ]
I have a directory with several subdirectories with files. How can I copy all files in the subdirectories to a new location? **Edit:** I do not want to copy the directories, just the files... As this is still on XP, I chose the below solution: ``` for /D %S IN ("src\*.*") DO @COPY "%S\" "dest\" ``` Thanks!
Ok. With your edit that says you don't want the directory structure, i think you're going to want to use something like this: ``` for /F "usebackq" %s IN (`DIR /B /S /A-D SrcDir`) DO @( XCOPY %s DestDir\%~nxs ) ```
185,741
<p>We can use Bitmapsource object as the content of a Image control, However if I only have Bitmap object, can I use it directly, if I convert Bitmap to Bitmapsouce using the following method:</p> <pre><code> Bitmap bitmap = imageObjToBeConvert; IntPtr HBitmap = bitmap.GetHbitmap(); result = Ima...
[ { "answer_id": 185775, "author": "Mark Cidade", "author_id": 1659, "author_profile": "https://Stackoverflow.com/users/1659", "pm_score": 3, "selected": false, "text": "<p>I think REST would make more sense than traditional RPC. Even the <a href=\"http://msdn.microsoft.com/en-us/library/b...
2008/10/09
[ "https://Stackoverflow.com/questions/185741", "https://Stackoverflow.com", "https://Stackoverflow.com/users/25749/" ]
We can use Bitmapsource object as the content of a Image control, However if I only have Bitmap object, can I use it directly, if I convert Bitmap to Bitmapsouce using the following method: ``` Bitmap bitmap = imageObjToBeConvert; IntPtr HBitmap = bitmap.GetHbitmap(); result = Imaging.CreateBit...
I think REST would make more sense than traditional RPC. Even the [Micorosft Robotics Studio runtime application model](http://msdn.microsoft.com/en-us/library/bb466255.aspx) uses REST. The robot can consist of different resources that are identified by URI, including one for each sensor and actuator or composite abst...
185,747
<p>I am trying to convert an <code>int</code> into three <code>bytes</code> representing that <code>int</code> (big endian).</p> <p>I'm sure it has something to do with bit-wise and and bit shifting. But I have no idea how to go about doing it.</p> <p>For example:</p> <pre><code>int myInt; // some code byte b1, b...
[ { "answer_id": 185763, "author": "Paul Tomblin", "author_id": 3333, "author_profile": "https://Stackoverflow.com/users/3333", "pm_score": 2, "selected": false, "text": "<p>An int doesn't fit into 3 bytes. However, assuming that you know these particular ones do:</p>\n\n<pre><code> byt...
2008/10/09
[ "https://Stackoverflow.com/questions/185747", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2598/" ]
I am trying to convert an `int` into three `bytes` representing that `int` (big endian). I'm sure it has something to do with bit-wise and and bit shifting. But I have no idea how to go about doing it. For example: ``` int myInt; // some code byte b1, b2 , b3; // b1 is most significant, then b2 then b3. ``` \*No...
To get the least significant byte: ``` b3 = myInt & 0xFF; ``` The 2nd least significant byte: ``` b2 = (myInt >> 8) & 0xFF; ``` And the 3rd least significant byte: ``` b1 = (myInt >> 16) & 0xFF; ``` **Explanation:** Bitwise ANDing a value with 0xFF (11111111 in binary) will return the least significant 8 bits...
185,778
<p>I am using trigger_error to "throw" errors in a custom class. My problem is that trigger_error prints out the line number where trigger_error was called. For example, given the following code:</p> <pre><code>01 &lt;?php 02 class Test { 03 function doAction() { 04 $this-&gt;doSubA...
[ { "answer_id": 185793, "author": "Jerub", "author_id": 14648, "author_profile": "https://Stackoverflow.com/users/14648", "pm_score": 2, "selected": false, "text": "<p>The best thing to do is set up an error handler that shows a full stack trace.</p>\n\n<p>Set up a custom error handler, a...
2008/10/09
[ "https://Stackoverflow.com/questions/185778", "https://Stackoverflow.com", "https://Stackoverflow.com/users/26210/" ]
I am using trigger\_error to "throw" errors in a custom class. My problem is that trigger\_error prints out the line number where trigger\_error was called. For example, given the following code: ``` 01 <?php 02 class Test { 03 function doAction() { 04 $this->doSubAction(); 05 ...
Alright, for those of you who are interested in my final solution, I integrated the following piece of code in our framework which returns the correct line number in all the cases that we could of tested. We are using it in production. [`ErrorHandler` class](http://pastebin.com/f12a290d1) It catches uncaught PHP exce...
185,780
<p>I'm adding repeating events to a Cocoa app I'm working on. I have repeat every day and week fine because I can define these mathematically (3600*24*7 = 1 week). I use the following code to modify the date:</p> <pre><code>[NSDate dateWithTimeIntervalSinceNow:(3600*24*7*(weeks))] </code></pre> <p>I know how many mon...
[ { "answer_id": 185927, "author": "Heng-Cheong Leong", "author_id": 6904, "author_profile": "https://Stackoverflow.com/users/6904", "pm_score": 0, "selected": false, "text": "<p>I'll probably use NSCalendarDate.</p>\n\n<p>Get current date's dayOfMonth, monthOfYear and yearOfCommonEra, as ...
2008/10/09
[ "https://Stackoverflow.com/questions/185780", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13069/" ]
I'm adding repeating events to a Cocoa app I'm working on. I have repeat every day and week fine because I can define these mathematically (3600\*24\*7 = 1 week). I use the following code to modify the date: ``` [NSDate dateWithTimeIntervalSinceNow:(3600*24*7*(weeks))] ``` I know how many months have passed since th...
(Almost the same as [this question](https://stackoverflow.com/questions/181459/is-there-a-better-way-to-find-midnight-tomorrow/181495#181495).) From the [documentation](http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSCalendarDate_Class/Reference/Reference.html): > > Use of NSCalendarDat...
185,781
<p>I read an interesting DailyWTF post today, <a href="http://thedailywtf.com/Articles/Out-of-All-the-Possible-Answers.aspx" rel="noreferrer">"Out of All The Possible Answers..."</a> and it interested me enough to dig up the original <a href="http://forums.thedailywtf.com/forums/t/10030.aspx" rel="noreferrer">forum pos...
[ { "answer_id": 185815, "author": "warren", "author_id": 4418, "author_profile": "https://Stackoverflow.com/users/4418", "pm_score": -1, "selected": false, "text": "<p>In expanding on @Alexander's comment, I'd point out that if you can factor the numbers to their primes, remove duplicates...
2008/10/09
[ "https://Stackoverflow.com/questions/185781", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20840/" ]
I read an interesting DailyWTF post today, ["Out of All The Possible Answers..."](http://thedailywtf.com/Articles/Out-of-All-the-Possible-Answers.aspx) and it interested me enough to dig up the original [forum post](http://forums.thedailywtf.com/forums/t/10030.aspx) where it was submitted. This got me thinking how I wo...
This problem is interesting because it doesn't require you to find the LCM of an arbitrary set of numbers, you're given a consecutive range. You can use a variation of the [Sieve of Eratosthenes](http://en.wikipedia.org/wiki/Sieve_of_Eratosthenes) to find the answer. ``` def RangeLCM(first, last): factors = range(...
185,804
<p>I created an app for a small business. Some of the employees in the office can not see the form correctly. The reason is they have their DPI setting set to above 96dpi. Does anybody know of a way to control this?</p> <p>For all of you who have experience with winforms apps, how do you control your form layout so ...
[ { "answer_id": 187626, "author": "Nick", "author_id": 1490, "author_profile": "https://Stackoverflow.com/users/1490", "pm_score": 4, "selected": false, "text": "<p>Set the AutoScaleMode to Inherit everywhere (ie all your UserControls) via a global search/replace, then set the AutoScaleMo...
2008/10/09
[ "https://Stackoverflow.com/questions/185804", "https://Stackoverflow.com", "https://Stackoverflow.com/users/21325/" ]
I created an app for a small business. Some of the employees in the office can not see the form correctly. The reason is they have their DPI setting set to above 96dpi. Does anybody know of a way to control this? For all of you who have experience with winforms apps, how do you control your form layout so that DPI doe...
Assuming you do not try to honor the user's UI font choice (SystemFonts.IconTitleFont), and hard-code your forms for one font size only (e.g. Tahoma 8pt, Microsoft Sans Serif 8.25pt), you can set your form's `AutoScaleMode` to `ScaleMode.Dpi`. This will scale the size of the form and *most* of it child controls by the...
185,836
<p>Does anyone know if it possible to define the equivalent of a "java custom class loader" in .NET?</p> <p><strong>To give a little background:</strong></p> <p>I am in the process of developing a new programming language that targets the CLR, called "Liberty". One of the features of the language is its ability to de...
[ { "answer_id": 185854, "author": "Kevin Dostalek", "author_id": 22732, "author_profile": "https://Stackoverflow.com/users/22732", "pm_score": -1, "selected": false, "text": "<p>I think this is the type of thing the DLR is supposed to provide in C# 4.0. Kind of hard to come by informatio...
2008/10/09
[ "https://Stackoverflow.com/questions/185836", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1737192/" ]
Does anyone know if it possible to define the equivalent of a "java custom class loader" in .NET? **To give a little background:** I am in the process of developing a new programming language that targets the CLR, called "Liberty". One of the features of the language is its ability to define "type constructors", whic...
The answer is yes, but the solution is a little tricky. The [`System.Reflection.Emit`](http://msdn.microsoft.com/en-us/library/system.reflection.emit.aspx) namespace defines types that allows assemblies to be generated dynamically. They also allow the generated assemblies to be defined incrementally. In other words it...
185,844
<p>What is the best way to initialize a private, static data member in C++? I tried this in my header file, but it gives me weird linker errors:</p> <pre><code>class foo { private: static int i; }; int foo::i = 0; </code></pre> <p>I'm guessing this is because I can't initialize a private member from out...
[ { "answer_id": 185848, "author": "Martin York", "author_id": 14065, "author_profile": "https://Stackoverflow.com/users/14065", "pm_score": 10, "selected": true, "text": "<p>The class declaration should be in the header file (Or in the source file if not shared).<br>\nFile: foo.h</p>\n<pr...
2008/10/09
[ "https://Stackoverflow.com/questions/185844", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2147/" ]
What is the best way to initialize a private, static data member in C++? I tried this in my header file, but it gives me weird linker errors: ``` class foo { private: static int i; }; int foo::i = 0; ``` I'm guessing this is because I can't initialize a private member from outside the class. So what's t...
The class declaration should be in the header file (Or in the source file if not shared). File: foo.h ``` class foo { private: static int i; }; ``` But the initialization should be in source file. File: foo.cpp ``` int foo::i = 0; ``` If the initialization is in the header file then each file th...
185,934
<p>It appears that in PHP objects are passed by reference. Even assignment operators do not appear to be creating a copy of the Object.</p> <p>Here's a simple, contrived proof:</p> <pre><code>&lt;?php class A { public $b; } function set_b($obj) { $obj-&gt;b = "after"; } $a = new A(); $a-&gt;b = "before"; $c =...
[ { "answer_id": 185938, "author": "Leo", "author_id": 20689, "author_profile": "https://Stackoverflow.com/users/20689", "pm_score": 4, "selected": false, "text": "<p>According to the docs (<a href=\"http://ca3.php.net/language.oop5.cloning\" rel=\"noreferrer\">http://ca3.php.net/language....
2008/10/09
[ "https://Stackoverflow.com/questions/185934", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4960/" ]
It appears that in PHP objects are passed by reference. Even assignment operators do not appear to be creating a copy of the Object. Here's a simple, contrived proof: ``` <?php class A { public $b; } function set_b($obj) { $obj->b = "after"; } $a = new A(); $a->b = "before"; $c = $a; //i would especially expec...
In PHP 5+ objects are passed by reference. In PHP 4 they are passed by value (that's why it had runtime pass by reference, which became deprecated). You can use the 'clone' operator in PHP5 to copy objects: ``` $objectB = clone $objectA; ``` Also, it's just objects that are passed by reference, not everything as yo...
185,936
<p>How can I delete the contents of a local folder in Python?</p> <p>The current project is for Windows, but I would like to see *nix also.</p>
[ { "answer_id": 185941, "author": "Nick Stinemates", "author_id": 4960, "author_profile": "https://Stackoverflow.com/users/4960", "pm_score": 10, "selected": true, "text": "<pre><code>import os, shutil\nfolder = '/path/to/folder'\nfor filename in os.listdir(folder):\n file_path = os.pa...
2008/10/09
[ "https://Stackoverflow.com/questions/185936", "https://Stackoverflow.com", "https://Stackoverflow.com/users/115/" ]
How can I delete the contents of a local folder in Python? The current project is for Windows, but I would like to see \*nix also.
``` import os, shutil folder = '/path/to/folder' for filename in os.listdir(folder): file_path = os.path.join(folder, filename) try: if os.path.isfile(file_path) or os.path.islink(file_path): os.unlink(file_path) elif os.path.isdir(file_path): shutil.rmtree(file_path) ...
185,937
<p>I ran into an interesting (and very frustrating) issue with the <code>equals()</code> method today which caused what I thought to be a well tested class to crash and cause a bug that took me a very long time to track down. </p> <p>Just for completeness, I wasn't using an IDE or debugger - just good old fashioned te...
[ { "answer_id": 185942, "author": "jjnguy", "author_id": 2598, "author_profile": "https://Stackoverflow.com/users/2598", "pm_score": 9, "selected": true, "text": "<p>In Java, the <code>equals()</code> method that is inherited from <code>Object</code> is:</p>\n\n<pre><code>public boolean e...
2008/10/09
[ "https://Stackoverflow.com/questions/185937", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10583/" ]
I ran into an interesting (and very frustrating) issue with the `equals()` method today which caused what I thought to be a well tested class to crash and cause a bug that took me a very long time to track down. Just for completeness, I wasn't using an IDE or debugger - just good old fashioned text editor and System....
In Java, the `equals()` method that is inherited from `Object` is: ``` public boolean equals(Object other); ``` In other words, the parameter must be of type `Object`. This is called *overriding*; your method `public boolean equals(Book other)` does what is called *overloading* to the `equals()` method. The `ArrayL...
185,947
<p>As a programming exercise, I've written a Ruby snippet that creates a class, instantiates two objects from that class, monkeypatches one object, and relies on method_missing to monkeypatch the other one.</p> <p>Here's the deal. This works as intended:</p> <pre><code>class Monkey def chatter puts "I am a ch...
[ { "answer_id": 185969, "author": "Avdi", "author_id": 20487, "author_profile": "https://Stackoverflow.com/users/20487", "pm_score": 8, "selected": true, "text": "<p><code>define_method</code> is a (private) method of the object <em>Class</em>. You are calling it from an <em>instance</em...
2008/10/09
[ "https://Stackoverflow.com/questions/185947", "https://Stackoverflow.com", "https://Stackoverflow.com/users/21493/" ]
As a programming exercise, I've written a Ruby snippet that creates a class, instantiates two objects from that class, monkeypatches one object, and relies on method\_missing to monkeypatch the other one. Here's the deal. This works as intended: ``` class Monkey def chatter puts "I am a chattering monkey!" e...
`define_method` is a (private) method of the object *Class*. You are calling it from an *instance*. There is no instance method called `define_method`, so it recurses to your `method_missing`, this time with `:define_method` (the name of the missing method), and `:screech` (the sole argument you passed to `define_metho...
185,965
<p>What is the best way to create a custom title for pages in a Rails app without using a plug-in?</p>
[ { "answer_id": 185973, "author": "Avdi", "author_id": 20487, "author_profile": "https://Stackoverflow.com/users/20487", "pm_score": 4, "selected": false, "text": "<p>Look into <code>content_for</code>: <a href=\"http://railscasts.com/episodes/8\" rel=\"noreferrer\">http://railscasts.com/...
2008/10/09
[ "https://Stackoverflow.com/questions/185965", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1632/" ]
What is the best way to create a custom title for pages in a Rails app without using a plug-in?
In your views do something like this: ``` <% content_for :title, "Title for specific page" %> <!-- or --> <h1><%= content_for(:title, "Title for specific page") %></h1> ``` The following goes in the layout file: ``` <head> <title><%= yield(:title) %></title> <!-- Additional header tags here --> </head> <body> ...
185,966
<pre><code>&lt;div id="myDiv"&gt; &lt;a&gt;...&lt;/a&gt; &lt;a&gt;...&lt;/a&gt; &lt;a&gt;...&lt;/a&gt; &lt;a&gt;...&lt;/a&gt; &lt;a&gt;...&lt;/a&gt; &lt;a&gt;...&lt;/a&gt; &lt;/div&gt; </code></pre> <p>If you wanted to select the 2nd, 3rd and 4th <code>a</code> tags in the above example, ...
[ { "answer_id": 185977, "author": "nickf", "author_id": 9021, "author_profile": "https://Stackoverflow.com/users/9021", "pm_score": 3, "selected": false, "text": "<p>Using the <a href=\"http://docs.jquery.com/Traversing/slice\" rel=\"nofollow noreferrer\">.slice()</a> function does exactl...
2008/10/09
[ "https://Stackoverflow.com/questions/185966", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9021/" ]
``` <div id="myDiv"> <a>...</a> <a>...</a> <a>...</a> <a>...</a> <a>...</a> <a>...</a> </div> ``` If you wanted to select the 2nd, 3rd and 4th `a` tags in the above example, how would you do that? The only thing I can think of is: ``` $("#myDiv a:eq(1), #myDiv a:eq(2), #myDiv a:eq(3)") ...
jQuery [slice()](http://docs.jquery.com/Traversing/slice) function taking indexes of the first and the last needed elements selects a subset of the matched elements. Note what it doesn't include last element itself. In your particular case you should use ``` $("#myDiv a").slice(1, 4) ```
185,972
<p>In javascript, we can do:</p> <pre><code>["a string", 10, {x : 1}, function() {}].push("another value"); </code></pre> <p>What is the Scala equivalent?</p>
[ { "answer_id": 188235, "author": "Daniel Spiewak", "author_id": 9815, "author_profile": "https://Stackoverflow.com/users/9815", "pm_score": 6, "selected": true, "text": "<p>Arrays in Scala are very much homogeneous. This is because Scala is a statically typed language. If you really ne...
2008/10/09
[ "https://Stackoverflow.com/questions/185972", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20689/" ]
In javascript, we can do: ``` ["a string", 10, {x : 1}, function() {}].push("another value"); ``` What is the Scala equivalent?
Arrays in Scala are very much homogeneous. This is because Scala is a statically typed language. If you really need pseudo-heterogeneous features, you need to use an immutable data structure that is parametrized covariantly (most immutable data structures are). `List` is the canonical example there, but [`Vector`](http...
186,004
<p>Specifically, I want to listen to when programs are run and record information such as: timestamp, executable, windows name and user.</p>
[ { "answer_id": 186011, "author": "Nick", "author_id": 26240, "author_profile": "https://Stackoverflow.com/users/26240", "pm_score": 0, "selected": false, "text": "<p>Look into using the Perfmon API's (check MSDN for references).</p>\n" }, { "answer_id": 186149, "author": "bug...
2008/10/09
[ "https://Stackoverflow.com/questions/186004", "https://Stackoverflow.com", "https://Stackoverflow.com/users/24416/" ]
Specifically, I want to listen to when programs are run and record information such as: timestamp, executable, windows name and user.
Alternatively, use the WMI interface to find out what's running and take appropriate action. In the VBScript code below the WMI subsystem is being queried with `Select * from Win32_Process` so as to change the process priority. Find out what other attributes are available for `Win32_Process` and you should find stuff t...
186,015
<p>I have had to do this several times, usually when trying to find in what files a variable or a function is used.</p> <p>I remember using xargs with grep in the past to do this, but I am wondering if there are any easier ways.</p>
[ { "answer_id": 186020, "author": "C. K. Young", "author_id": 13, "author_profile": "https://Stackoverflow.com/users/13", "pm_score": 6, "selected": true, "text": "<pre><code>grep -r REGEX .\n</code></pre>\n\n<p>Replace <code>.</code> with whatever directory you want to search from.</p>\n...
2008/10/09
[ "https://Stackoverflow.com/questions/186015", "https://Stackoverflow.com", "https://Stackoverflow.com/users/25910/" ]
I have had to do this several times, usually when trying to find in what files a variable or a function is used. I remember using xargs with grep in the past to do this, but I am wondering if there are any easier ways.
``` grep -r REGEX . ``` Replace `.` with whatever directory you want to search from.
186,024
<pre><code>(function() { //codehere } )(); </code></pre> <p>What is special about this kind of syntax? What does ()(); imply?</p>
[ { "answer_id": 186030, "author": "Geoff", "author_id": 10427, "author_profile": "https://Stackoverflow.com/users/10427", "pm_score": 5, "selected": false, "text": "<p>The creates an anonymous function, closure and all, and the final () tells it to execute itself.</p>\n\n<p>It is basicall...
2008/10/09
[ "https://Stackoverflow.com/questions/186024", "https://Stackoverflow.com", "https://Stackoverflow.com/users/21572/" ]
``` (function() { //codehere } )(); ``` What is special about this kind of syntax? What does ()(); imply?
The creates an anonymous function, closure and all, and the final () tells it to execute itself. It is basically the same as: ``` function name (){...} name(); ``` So basically there is nothing special about this code, it just a 'shortcut' to creating a method and invoking it without having to name it. This also ...
186,035
<p>I have a simple "accordion" type page containing a list of H3 headers and DIV content boxes (each H3 is followed by a DIV). On this page I start with all DIVs hidden. When a H3 is clicked the DIV directly below (after) is revealed with jQuery's <a href="http://jquery.com/api/#slideDown" rel="nofollow noreferrer">"...
[ { "answer_id": 186036, "author": "Matt Mitchell", "author_id": 364, "author_profile": "https://Stackoverflow.com/users/364", "pm_score": 0, "selected": false, "text": "<p>Yes.</p>\n\n<p>On load add a class (e.g. \"hideme\") to all relevant DIVs like so:</p>\n\n<pre><code>$('div#accordion...
2008/10/09
[ "https://Stackoverflow.com/questions/186035", "https://Stackoverflow.com", "https://Stackoverflow.com/users/364/" ]
I have a simple "accordion" type page containing a list of H3 headers and DIV content boxes (each H3 is followed by a DIV). On this page I start with all DIVs hidden. When a H3 is clicked the DIV directly below (after) is revealed with jQuery's ["slideDown"](http://jquery.com/api/#slideDown) function while all other DI...
You can use the !important clause in CSS. This will override the inline style. So if you setup a print media stylesheet - you can do something like ``` div.accordian { display:block !important; } ```
186,044
<p>I was developing a web page, where I was laying out a board for a Chess-like game, along with a couple of piece trays. It's all done using HTML (with jQuery for dynamic updating as the game is played). Somewhere I'd got the notion that using absolute positioning of elements within a page was considered a bad practic...
[ { "answer_id": 186058, "author": "Ash", "author_id": 5023, "author_profile": "https://Stackoverflow.com/users/5023", "pm_score": 8, "selected": true, "text": "<p>For a chess like game such as you are developing, there is nothing inherently wrong with using absolute positioning. As you s...
2008/10/09
[ "https://Stackoverflow.com/questions/186044", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2193/" ]
I was developing a web page, where I was laying out a board for a Chess-like game, along with a couple of piece trays. It's all done using HTML (with jQuery for dynamic updating as the game is played). Somewhere I'd got the notion that using absolute positioning of elements within a page was considered a bad practice, ...
For a chess like game such as you are developing, there is nothing inherently wrong with using absolute positioning. As you said, relative positioning and normal flow layout make this sort of task quite difficult. Of course, if you were developing a more standard website, such as a site providing some public service,...
186,062
<p>Can I create a Controller that simply returns an image asset?</p> <p>I would like to route this logic through a controller, whenever a URL such as the following is requested:</p> <pre><code>www.mywebsite.com/resource/image/topbanner </code></pre> <p>The controller will look up <code>topbanner.png</code> and send ...
[ { "answer_id": 186123, "author": "Matt Mitchell", "author_id": 364, "author_profile": "https://Stackoverflow.com/users/364", "pm_score": 2, "selected": false, "text": "<p>I see two options:</p>\n\n<p>1) Implement your own IViewEngine and set the ViewEngine property of the Controller you ...
2008/10/09
[ "https://Stackoverflow.com/questions/186062", "https://Stackoverflow.com", "https://Stackoverflow.com/users/23341/" ]
Can I create a Controller that simply returns an image asset? I would like to route this logic through a controller, whenever a URL such as the following is requested: ``` www.mywebsite.com/resource/image/topbanner ``` The controller will look up `topbanner.png` and send that image directly back to the client. I'v...
Use the base controllers File method. ``` public ActionResult Image(string id) { var dir = Server.MapPath("/Images"); var path = Path.Combine(dir, id + ".jpg"); //validate the path for security or use other means to generate the path. return base.File(path, "image/jpeg"); } ``` As a note, this seems to b...
186,071
<p>I've been profiling some queries in an application I'm working on, and I came across a query that was retrieving more rows than necessary, the result set being trimmed down in the application code.</p> <p>Changing a LEFT JOIN to an INNER JOIN trimmed the result set to just what was needed, and presumably would also...
[ { "answer_id": 186120, "author": "HAdes", "author_id": 11989, "author_profile": "https://Stackoverflow.com/users/11989", "pm_score": 3, "selected": false, "text": "<p>It's probably due to the INNER JOIN having to check each row in both tables to see if the column values (email in your ca...
2008/10/09
[ "https://Stackoverflow.com/questions/186071", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10585/" ]
I've been profiling some queries in an application I'm working on, and I came across a query that was retrieving more rows than necessary, the result set being trimmed down in the application code. Changing a LEFT JOIN to an INNER JOIN trimmed the result set to just what was needed, and presumably would also be more p...
If you think that the implementation of LEFT JOIN is INNER JOIN + more work, then this result is confusing. What if the implementation of INNER JOIN is (LEFT JOIN + filtering)? Ah, it is clear now. In the query plans, the only difference is this: *users... extra: using where* . This means filtering. There's an **extra...
186,084
<p>Just this - How do you add a timer to a C# console application? It would be great if you could supply some example coding.</p>
[ { "answer_id": 186086, "author": "Ash", "author_id": 5023, "author_profile": "https://Stackoverflow.com/users/5023", "pm_score": 6, "selected": false, "text": "<p>Use the System.Threading.Timer class.</p>\n\n<p>System.Windows.Forms.Timer is designed primarily for use in a single thread u...
2008/10/09
[ "https://Stackoverflow.com/questions/186084", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3535708/" ]
Just this - How do you add a timer to a C# console application? It would be great if you could supply some example coding.
That's very nice, however in order to simulate some time passing we need to run a command that takes some time and that's very clear in second example. However, the style of using a for loop to do some functionality forever takes a lot of device resources and instead we can use the Garbage Collector to do some thing l...
186,094
<p>I'm setting up a simple SQLite database to hold sensor readings. The tables will look something like this:</p> <pre><code>sensors - id (pk) - name - description - units sensor_readings - id (pk) - sensor_id (fk to sensors) - value (actual sensor value stored here) - time (date/time the sensor...
[ { "answer_id": 186177, "author": "Roel", "author_id": 11449, "author_profile": "https://Stackoverflow.com/users/11449", "pm_score": 2, "selected": false, "text": "<p>Are you setting indexes properly? Besides that and reading <a href=\"http://web.utk.edu/~jplyon/sqlite/SQLite_optimization...
2008/10/09
[ "https://Stackoverflow.com/questions/186094", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10428/" ]
I'm setting up a simple SQLite database to hold sensor readings. The tables will look something like this: ``` sensors - id (pk) - name - description - units sensor_readings - id (pk) - sensor_id (fk to sensors) - value (actual sensor value stored here) - time (date/time the sensor sample was tak...
Are you setting indexes properly? Besides that and reading <http://web.utk.edu/~jplyon/sqlite/SQLite_optimization_FAQ.html>, the only answer is 'you'll have to measure yourself' - especially since this will be heavily dependent on the hardware and on whether you're using an in-memory database or on disk, and on if you ...
186,099
<p>I many times have to work with directories containing hundreds of thousands of files, doing text matching, replacing and so on. If I go the standard route of, say</p> <pre><code>grep foo * </code></pre> <p>I get the too many files error message, so I end up doing</p> <pre><code>for i in *; do grep foo $i; done </...
[ { "answer_id": 186139, "author": "camh", "author_id": 23744, "author_profile": "https://Stackoverflow.com/users/23744", "pm_score": 2, "selected": false, "text": "<p>xargs does not start a new process for each file. It bunches together the arguments. Have a look at the -n option to xargs...
2008/10/09
[ "https://Stackoverflow.com/questions/186099", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5190/" ]
I many times have to work with directories containing hundreds of thousands of files, doing text matching, replacing and so on. If I go the standard route of, say ``` grep foo * ``` I get the too many files error message, so I end up doing ``` for i in *; do grep foo $i; done ``` or ``` find ../path/ | xargs -I{...
In newer versions of findutils, find can do the work of xargs (including the glomming behavior, such that only as many grep processes as needed are used): ``` find ../path -exec grep foo '{}' + ``` The use of `+` rather than `;` as the last argument triggers this behavior.
186,106
<p>I am new to web programming and have been exploring issues related to web security.</p> <p>I have a form where the user can post two types of data - lets call them &quot;safe&quot; and &quot;unsafe&quot; (from the point of view of sql).</p> <p>Most places recommend storing both parts of the data in database after sa...
[ { "answer_id": 186110, "author": "Andy Lester", "author_id": 8454, "author_profile": "https://Stackoverflow.com/users/8454", "pm_score": 0, "selected": false, "text": "<p>What do you consider \"safe\" and \"unsafe\"? Are you considering data with the slashes escaped to be \"safe\"? If ...
2008/10/09
[ "https://Stackoverflow.com/questions/186106", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I am new to web programming and have been exploring issues related to web security. I have a form where the user can post two types of data - lets call them "safe" and "unsafe" (from the point of view of sql). Most places recommend storing both parts of the data in database after sanitizing the "unsafe" part (to make...
You know the "safe" data you're talking about? It isn't. It's *all* unsafe and you should treat it as such. Not by storing it al in files, but by properly constructing your SQL statements. As others have mentioned, using prepared statements, or a library which which simulates them, is the way to go, e.g. ``` $db->Exe...
186,108
<p>In a vxWorks Real-Time process, you can pass environment variables as one of the parameter of the <strong>main</strong> routine.</p> <p>How do you use the environment variables in the kernel context?</p>
[ { "answer_id": 186119, "author": "Benoit", "author_id": 10703, "author_profile": "https://Stackoverflow.com/users/10703", "pm_score": 2, "selected": false, "text": "<p>Vxworks environment variable support is provided by the envLib.</p>\n\n<p>use <strong>putenv(\"VAR=value\")</strong> to ...
2008/10/09
[ "https://Stackoverflow.com/questions/186108", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10703/" ]
In a vxWorks Real-Time process, you can pass environment variables as one of the parameter of the **main** routine. How do you use the environment variables in the kernel context?
Call this directly from the VxWorks shell: ``` putenv "<VARIABLE NAME>=<VALUE>" ``` replace with your environment variable name and with the value you want to set it to.
186,125
<p>I would like to use a secure SSL login on my website! I have not used SSL before, so I am looking for some good reading. Can anyone tell me where I can find some sample code of SSL snippets or page code. (Not too technical)</p> <ul> <li>I do have a static IP</li> <li>My host is set-up to handle SSL Pages. </li> </...
[ { "answer_id": 186138, "author": "Matt Mitchell", "author_id": 364, "author_profile": "https://Stackoverflow.com/users/364", "pm_score": 2, "selected": false, "text": "<p>My first thought would be to simply call a function to redirect to the https: version of the current page when you ne...
2008/10/09
[ "https://Stackoverflow.com/questions/186125", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I would like to use a secure SSL login on my website! I have not used SSL before, so I am looking for some good reading. Can anyone tell me where I can find some sample code of SSL snippets or page code. (Not too technical) * I do have a static IP * My host is set-up to handle SSL Pages. Interested in: Basic page cod...
My first thought would be to simply call a function to redirect to the https: version of the current page when you need to be secure. Some code like this: ``` if($requireSSL && $_SERVER['SERVER_PORT'] != 443) { header("HTTP/1.1 301 Moved Permanently"); header("Location: https://".$_SERVER['HTTP_HOST'].$_SERVER...
186,131
<p>He're an interesting problem that looks for the most Pythonic solution. Suppose I have a list of mappings <code>{'id': id, 'url': url}</code>. Some <code>id</code>s in the list are duplicate, and I want to create a new list, with all the duplicates removed. I came up with the following function:</p> <pre><code>def ...
[ { "answer_id": 186295, "author": "DzinX", "author_id": 18745, "author_profile": "https://Stackoverflow.com/users/18745", "pm_score": 3, "selected": true, "text": "<p>Your example can be rewritten slightly to construct the first dictionary using a generator expression and to remove necess...
2008/10/09
[ "https://Stackoverflow.com/questions/186131", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8206/" ]
He're an interesting problem that looks for the most Pythonic solution. Suppose I have a list of mappings `{'id': id, 'url': url}`. Some `id`s in the list are duplicate, and I want to create a new list, with all the duplicates removed. I came up with the following function: ``` def unique_mapping(map): d = {} ...
Your example can be rewritten slightly to construct the first dictionary using a generator expression and to remove necessity of construction of another mappings. Just reuse the old ones: ``` def unique_mapping(mappings): return dict((m['id'], m) for m in mappings).values() ``` Although this came out as a one-li...
186,160
<p>I have a table in the database that I'm retrieving using LINQ to SQL, and as a part of my processing I want to add to this list, then update the database with the new items + any changes I've made.</p> <p>What I thought I could do was this:</p> <pre><code>var list = (from item in db.Table select item)....
[ { "answer_id": 186188, "author": "leppie", "author_id": 15541, "author_profile": "https://Stackoverflow.com/users/15541", "pm_score": 1, "selected": false, "text": "<p>You have to add the new items via InsertOnSubmit.</p>\n" }, { "answer_id": 186221, "author": "James Curran",...
2008/10/09
[ "https://Stackoverflow.com/questions/186160", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2975/" ]
I have a table in the database that I'm retrieving using LINQ to SQL, and as a part of my processing I want to add to this list, then update the database with the new items + any changes I've made. What I thought I could do was this: ``` var list = (from item in db.Table select item).ToList(); [do proces...
The List is meaningless. It's just happens to hold objects that the DataContext knows about. We need to make sure that the DataContext knows about the new ones. The important thing is that they don't have to be complete when we alert the DataContext to them: ``` Item item; if (needNewOne) { item = new Item(); ...
186,202
<p>What is the most elegant way to solve this:</p> <ul> <li>open a file for reading, but only if it is not already opened for writing</li> <li>open a file for writing, but only if it is not already opened for reading or writing</li> </ul> <p>The built-in functions work like this</p> <pre><code>&gt;&gt;&gt; path = r"...
[ { "answer_id": 186300, "author": "kender", "author_id": 4172, "author_profile": "https://Stackoverflow.com/users/4172", "pm_score": 0, "selected": false, "text": "<p>To make you safe when opening files within one application, you could try something like this:</p>\n\n<pre><code>import ti...
2008/10/09
[ "https://Stackoverflow.com/questions/186202", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19166/" ]
What is the most elegant way to solve this: * open a file for reading, but only if it is not already opened for writing * open a file for writing, but only if it is not already opened for reading or writing The built-in functions work like this ``` >>> path = r"c:\scr.txt" >>> file1 = open(path, "w") >>> print file1...
I don't think there is a fully crossplatform way. On unix, the fcntl module will do this for you. However on windows (which I assume you are by the paths), you'll need to use the win32file module. Fortunately, there is a portable implementation ([portalocker](https://github.com/WoLpH/portalocker)) using the platform a...
186,208
<p>What Latex styles do you use and where do you find them?</p> <p>The reason I'm asking this is that it seems that some 99.9999% of all styles on the internet are copies of each other and of a <a href="http://www.tug.org/texshowcase/ps_s_1b.pdf" rel="noreferrer">physics exam paper</a></p> <p>However, when you try to...
[ { "answer_id": 186306, "author": "Michael Pliskin", "author_id": 9777, "author_profile": "https://Stackoverflow.com/users/9777", "pm_score": 2, "selected": false, "text": "<p>Well I think <a href=\"http://ctan.org/\" rel=\"nofollow noreferrer\">CTAN</a> is the best resource for LaTeX and...
2008/10/09
[ "https://Stackoverflow.com/questions/186208", "https://Stackoverflow.com", "https://Stackoverflow.com/users/445049/" ]
What Latex styles do you use and where do you find them? The reason I'm asking this is that it seems that some 99.9999% of all styles on the internet are copies of each other and of a [physics exam paper](http://www.tug.org/texshowcase/ps_s_1b.pdf) However, when you try to find a style for a paper like [this one](htt...
LaTeX was originally designed as a reasonably flexible system on which a few standard classes were distributed — that were themselves rather *in*flexible. In the current state of affairs, if you want a custom layout, you need to write a few amount of supporting code yourself. How else would it happen? It's not like HT...
186,211
<p>I am using Windows 2003. I have mapped a web application into a virtual directory. This is built on framework 1.1 When i try to browse to the default page i get a error as </p> <p>Description: An error occurred during the processing of a configuration file required to service this request. Please review the specifi...
[ { "answer_id": 186306, "author": "Michael Pliskin", "author_id": 9777, "author_profile": "https://Stackoverflow.com/users/9777", "pm_score": 2, "selected": false, "text": "<p>Well I think <a href=\"http://ctan.org/\" rel=\"nofollow noreferrer\">CTAN</a> is the best resource for LaTeX and...
2008/10/09
[ "https://Stackoverflow.com/questions/186211", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20951/" ]
I am using Windows 2003. I have mapped a web application into a virtual directory. This is built on framework 1.1 When i try to browse to the default page i get a error as Description: An error occurred during the processing of a configuration file required to service this request. Please review the specific error de...
LaTeX was originally designed as a reasonably flexible system on which a few standard classes were distributed — that were themselves rather *in*flexible. In the current state of affairs, if you want a custom layout, you need to write a few amount of supporting code yourself. How else would it happen? It's not like HT...
186,232
<p>I want to use implicit linking in my project , and nmake really wants a .def file . The problem is , that this is a class , and I don't know what to write in the exports section . Could anyone point me in the right direction ?</p> <p>The error message is the following :</p> <p><strong>NMAKE : U1073: don't know ho...
[ { "answer_id": 186240, "author": "Greg Hewgill", "author_id": 893, "author_profile": "https://Stackoverflow.com/users/893", "pm_score": 3, "selected": false, "text": "<p>If I recall correctly, you can use <code>__declspec(dllexport)</code> on the <em>class</em>, and VC++ will automatical...
2008/10/09
[ "https://Stackoverflow.com/questions/186232", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11234/" ]
I want to use implicit linking in my project , and nmake really wants a .def file . The problem is , that this is a class , and I don't know what to write in the exports section . Could anyone point me in the right direction ? The error message is the following : **NMAKE : U1073: don't know how to make 'DLLCLASS.def'...
You can always find the decorated name for the member function by using [dumpbin](http://msdn.microsoft.com/en-us/library/c1h23y6c(VS.80).aspx) /symbols myclass.obj in my case ``` class A { public: A( int ){} }; ``` the `dumpbin` dump showed the symbol `??0A@@QAE@H@Z (public: __thiscall A::A(int))` Putting...
186,307
<p>A project I'm working on will pull XML from a web-server and build a data store from it. The data will have certain core fields but needs to be extendable... for example I have a and later might want to have which adds extra fields.</p> <p>In the Flex app, I don't want the central data store to be working on XML ...
[ { "answer_id": 186991, "author": "Raleigh Buckner", "author_id": 1153, "author_profile": "https://Stackoverflow.com/users/1153", "pm_score": 2, "selected": false, "text": "<p>I don't think this can be done automatically. I generally create the a class to mirror the XML structure I have a...
2008/10/09
[ "https://Stackoverflow.com/questions/186307", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13220/" ]
A project I'm working on will pull XML from a web-server and build a data store from it. The data will have certain core fields but needs to be extendable... for example I have a and later might want to have which adds extra fields. In the Flex app, I don't want the central data store to be working on XML objects or s...
I don't think this can be done automatically. I generally create the a class to mirror the XML structure I have and then create a static class method to create an instance of the object given an XML node. For example: ``` package { public class Foo{ public function Foo(barparam1:String, barparam2:uint, barpar...
186,311
<p>I have a list of Date objects, and a target Date. I want to find the date in the list that's nearest to the target date, but only dates that are before the target date.</p> <p>Example: 2008-10-1 2008-10-2 2008-10-4</p> <p>With a target date of 2008-10-3, I want to get 2008-10-2</p> <p>What is the best way to do i...
[ { "answer_id": 186318, "author": "Sietse", "author_id": 6400, "author_profile": "https://Stackoverflow.com/users/6400", "pm_score": 2, "selected": false, "text": "<p>I currently use the following method, but I'm not sure it's the most effective one, because this assumes an already sorted...
2008/10/09
[ "https://Stackoverflow.com/questions/186311", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6400/" ]
I have a list of Date objects, and a target Date. I want to find the date in the list that's nearest to the target date, but only dates that are before the target date. Example: 2008-10-1 2008-10-2 2008-10-4 With a target date of 2008-10-3, I want to get 2008-10-2 What is the best way to do it?
Sietse de Kaper solution assumes a *reverse* sorted list, definitely not the most natural thing to have around The natural sort order in java is following the ascending natural ordering. (see Collection.sort <http://java.sun.com/j2se/1.5.0/docs/api/java/util/Collections.html#sort(java.util.List)> documentation) From ...
186,313
<p>I'm using the Scriptaculous library to slap an appealing UI on an application which helps an enduser build lists. Let's say its for pizza creation.</p> <p>To fill out an order, you drag a size of pizza from the pizza palette into the orders droppable. Once it is put in there, it gets replaced with a new div which...
[ { "answer_id": 187094, "author": "Diodeus - James MacFarlane", "author_id": 12579, "author_profile": "https://Stackoverflow.com/users/12579", "pm_score": 0, "selected": false, "text": "<p>Try this, I think it's close to what you're trying to do. I'm using a sortable for the list on the l...
2008/10/09
[ "https://Stackoverflow.com/questions/186313", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15046/" ]
I'm using the Scriptaculous library to slap an appealing UI on an application which helps an enduser build lists. Let's say its for pizza creation. To fill out an order, you drag a size of pizza from the pizza palette into the orders droppable. Once it is put in there, it gets replaced with a new div which is both dra...
It turns out, after a few days of banging my heads into various walls, that Scriptaculous will happily nest things by default. The issue is when your call to `draggable_element` looks like this ``` <% draggable_element blah blah blah blah blah blah blah%> ``` instead of ``` <%= draggable_element blah blah blah bl...
186,328
<p>Which is generally fastest when reading/comparing row info from a DataTable?</p> <pre><code>'assume dt as datatable' 'method 1' dim i as int32 for i = 0 to dt.rows.count - 1 .... next 'method 2' dim row as datarow for each row in dt.rows .... next </code></pre> <p>And if there's a difference, in what circ...
[ { "answer_id": 186343, "author": "Greg Dean", "author_id": 1200558, "author_profile": "https://Stackoverflow.com/users/1200558", "pm_score": 2, "selected": false, "text": "<p>In reality no difference. Although you technically pay a small price in the foreach method, for going through th...
2008/10/09
[ "https://Stackoverflow.com/questions/186328", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17235/" ]
Which is generally fastest when reading/comparing row info from a DataTable? ``` 'assume dt as datatable' 'method 1' dim i as int32 for i = 0 to dt.rows.count - 1 .... next 'method 2' dim row as datarow for each row in dt.rows .... next ``` And if there's a difference, in what circumstances does it pay to u...
The compiler expands For Each to a short while loop. ``` for each row in dt.rows // expands to: IEnumerator e = dt.rows.GetEnumerator() while e.MoveNext() row = e.Current ``` So you pay a small amount of overhead. But for clarities sake, I'd still stick with For Each if you're only working on one row, and you ar...
186,338
<p>Everything I read about better PHP coding practices keeps saying don't use <code>require_once</code> because of speed.</p> <p>Why is this?</p> <p>What is the proper/better way to do the same thing as <code>require_once</code>? If it matters, I'm using PHP&nbsp;5.</p>
[ { "answer_id": 186346, "author": "Greg", "author_id": 24181, "author_profile": "https://Stackoverflow.com/users/24181", "pm_score": 3, "selected": false, "text": "<p>A better way to do things is to use an object-oriented approach and use <a href=\"http://www.php.net/__autoload\" rel=\"no...
2008/10/09
[ "https://Stackoverflow.com/questions/186338", "https://Stackoverflow.com", "https://Stackoverflow.com/users/314/" ]
Everything I read about better PHP coding practices keeps saying don't use `require_once` because of speed. Why is this? What is the proper/better way to do the same thing as `require_once`? If it matters, I'm using PHP 5.
`require_once` and `include_once` both require that the system keeps a log of what's already been included/required. Every `*_once` call means checking that log. So there's definitely *some* extra work being done there but enough to detriment the speed of the whole app? ... I really doubt it... Not unless you're on *r...
186,345
<p>I have a HTML select list with quite a few (1000+) names. I have a javascript in place which will select the first matching name if someone starts typing. This matching looks at the start of the item: </p> <pre><code>var optionsLength = dropdownlist.options.length; for (var n=0; n &lt; optionsLength; n++) { ...
[ { "answer_id": 186393, "author": "MDCore", "author_id": 1896, "author_profile": "https://Stackoverflow.com/users/1896", "pm_score": 2, "selected": false, "text": "<p>Change</p>\n\n<pre><code>if (optionText.indexOf(dropdownlist.keypressBuffer,0) == 0)\n</code></pre>\n\n<p>to</p>\n\n<pre><...
2008/10/09
[ "https://Stackoverflow.com/questions/186345", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6399/" ]
I have a HTML select list with quite a few (1000+) names. I have a javascript in place which will select the first matching name if someone starts typing. This matching looks at the start of the item: ``` var optionsLength = dropdownlist.options.length; for (var n=0; n < optionsLength; n++) { var optionText =...
use this filter script <http://www.barelyfitz.com/projects/filterlist/>
186,385
<p>Which is the best timer approach for a C# console batch application that has to process as follows:</p> <ol> <li>Connect to datasources</li> <li>process batch until timeout occurs or processing complete. "Do something with datasources"</li> <li>stop console app gracefully.</li> </ol> <p>related question: <a href="...
[ { "answer_id": 186439, "author": "Jon Skeet", "author_id": 22656, "author_profile": "https://Stackoverflow.com/users/22656", "pm_score": 2, "selected": false, "text": "<p>When you say \"until timeout occurs\" do you mean \"keep processing for an hour and then stop\"? If so, I'd probably ...
2008/10/09
[ "https://Stackoverflow.com/questions/186385", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3535708/" ]
Which is the best timer approach for a C# console batch application that has to process as follows: 1. Connect to datasources 2. process batch until timeout occurs or processing complete. "Do something with datasources" 3. stop console app gracefully. related question: [How do you add a timer to a C# console applicat...
Sorry for this being an entire console app... but here's a complete console app that will get you started. Again, I appologize for so much code, but everyone else seems to be giving a "oh, all you have to do is do it" answer :) ``` using System; using System.Collections.Generic; using System.Threading; namespace Cons...
186,403
<p>When you create a procedure (or a function) in Oracle PL/SQL, you cannot specify the maximum length of the varchar2 arguments, only the datatype. For example</p> <pre><code>create or replace procedure testproc(arg1 in varchar2) is begin null; end; </code></pre> <p>Do you know the maximum length of a string that ...
[ { "answer_id": 186424, "author": "Gravstar", "author_id": 17381, "author_profile": "https://Stackoverflow.com/users/17381", "pm_score": 5, "selected": true, "text": "<p>In PL/SQL procedure it may be up to 32KB</p>\n\n<p>Futher information here:\n<a href=\"http://it.toolbox.com/blogs/orac...
2008/10/09
[ "https://Stackoverflow.com/questions/186403", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20037/" ]
When you create a procedure (or a function) in Oracle PL/SQL, you cannot specify the maximum length of the varchar2 arguments, only the datatype. For example ``` create or replace procedure testproc(arg1 in varchar2) is begin null; end; ``` Do you know the maximum length of a string that you can pass as the arg1 a...
In PL/SQL procedure it may be up to 32KB Futher information here: <http://it.toolbox.com/blogs/oracle-guide/learn-oracle-sql-and-plsql-datatypes-strings-10804>
186,405
<p>This is a very basic problem that's frustrating me at the moment. Let's say within a single solution, I have two projects. Let's call the first project SimpleMath. It has one header file "Add.h" which has </p> <pre><code>int add(int i, int j) </code></pre> <p>and the implementation "Add.cpp" which has</p> <pre><c...
[ { "answer_id": 186412, "author": "Gerald", "author_id": 19404, "author_profile": "https://Stackoverflow.com/users/19404", "pm_score": 2, "selected": false, "text": "<p>You either have to make Add.cpp part of a library and include it in both projects. or you have to add Add.cpp to your se...
2008/10/09
[ "https://Stackoverflow.com/questions/186405", "https://Stackoverflow.com", "https://Stackoverflow.com/users/23120/" ]
This is a very basic problem that's frustrating me at the moment. Let's say within a single solution, I have two projects. Let's call the first project SimpleMath. It has one header file "Add.h" which has ``` int add(int i, int j) ``` and the implementation "Add.cpp" which has ``` int add(int i, int j) { return ...
The reason for the error you're getting is that by including the header file you're telling the compiler that there is a symbol ``` int add (int, int) ``` That will be present during linkage, but you haven't actually included that symbol (the code for the function) in your project. A quick way to resolve the issue i...
186,413
<p>I need to add a <code>xml:lang</code> attribute on the root xml node in the outbound document from BizTalk.</p> <p>This is a fixed value, so it may be set in the schema or something.</p> <p>This is what I want to get out:</p> <pre><code>&lt;Catalog xml:lang="NB-NO"&gt; ... &lt;/Catalog&gt; </code></pre> <p>I've ...
[ { "answer_id": 186435, "author": "Tomalak", "author_id": 18771, "author_profile": "https://Stackoverflow.com/users/18771", "pm_score": 1, "selected": false, "text": "<p>Try to add the xml namespace declaration to the schema </p>\n\n<pre><code>xmlns:xml=\"http://www.w3.org/XML/1998/namesp...
2008/10/09
[ "https://Stackoverflow.com/questions/186413", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I need to add a `xml:lang` attribute on the root xml node in the outbound document from BizTalk. This is a fixed value, so it may be set in the schema or something. This is what I want to get out: ``` <Catalog xml:lang="NB-NO"> ... </Catalog> ``` I've tried to define the attribute "xml:lang", but it doesn't allow ...
Try to add the xml namespace declaration to the schema ``` xmlns:xml="http://www.w3.org/XML/1998/namespace" ``` Beware that this addition will be removed when the schema file is recreated.
186,431
<p>Given a week number, e.g. <code>date -u +%W</code>, how do you calculate the days in that week starting from Monday?</p> <p>Example rfc-3339 output for week 40:</p> <pre><code>2008-10-06 2008-10-07 2008-10-08 2008-10-09 2008-10-10 2008-10-11 2008-10-12 </code></pre>
[ { "answer_id": 186478, "author": "ConroyP", "author_id": 2287, "author_profile": "https://Stackoverflow.com/users/2287", "pm_score": 7, "selected": true, "text": "<p><strong>PHP</strong></p>\n\n<pre><code>$week_number = 40;\n$year = 2008;\nfor($day=1; $day&lt;=7; $day++)\n{\n echo dat...
2008/10/09
[ "https://Stackoverflow.com/questions/186431", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4534/" ]
Given a week number, e.g. `date -u +%W`, how do you calculate the days in that week starting from Monday? Example rfc-3339 output for week 40: ``` 2008-10-06 2008-10-07 2008-10-08 2008-10-09 2008-10-10 2008-10-11 2008-10-12 ```
**PHP** ``` $week_number = 40; $year = 2008; for($day=1; $day<=7; $day++) { echo date('m/d/Y', strtotime($year."W".$week_number.$day))."\n"; } ``` --- Below post was because I was an idiot who didn't read the question properly, but will get the dates in a week starting from Monday, given the date, not the week ...
186,443
<p>At the moment I pull data from remote MS SQL Server databases using custom-built JDBC connectors. This works fine but doesn't feel like the way to do it.</p> <p>I feel I should be able to put a JDBC connection string into tnsnames on the server and have it "just work". I've looked around a little for this functiona...
[ { "answer_id": 186811, "author": "Matthew Watson", "author_id": 3839, "author_profile": "https://Stackoverflow.com/users/3839", "pm_score": 3, "selected": true, "text": "<p><a href=\"http://www.oracle.com/pls/db102/search?remark=quick_search&amp;word=Generic+Connectivity&amp;tab_id=&amp;...
2008/10/09
[ "https://Stackoverflow.com/questions/186443", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4003/" ]
At the moment I pull data from remote MS SQL Server databases using custom-built JDBC connectors. This works fine but doesn't feel like the way to do it. I feel I should be able to put a JDBC connection string into tnsnames on the server and have it "just work". I've looked around a little for this functionality but i...
[Generic Connectivity](http://www.oracle.com/pls/db102/search?remark=quick_search&word=Generic+Connectivity&tab_id=&format=ranked) is what you are after, it will let you setup a remote database link against MS SQL Server, so you can do queries like ``` select * from mytable@my_ms_sql_server; ``` I've only used it in...
186,467
<p>We have a web application that passes parameters in the url along the lines of this:</p> <pre><code>www.example.com/ViewCustomer?customer=3945 </code></pre> <p>Reasonably often, we will see attempts to access just:</p> <pre><code>www.example.com/ViewCustomer </code></pre> <p>Or system logs this as invalid and se...
[ { "answer_id": 186474, "author": "Jon Skeet", "author_id": 22656, "author_profile": "https://Stackoverflow.com/users/22656", "pm_score": 2, "selected": false, "text": "<p>Do your logs include the referrer information? If there's any information present then it could help to pinpoint the ...
2008/10/09
[ "https://Stackoverflow.com/questions/186467", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14663/" ]
We have a web application that passes parameters in the url along the lines of this: ``` www.example.com/ViewCustomer?customer=3945 ``` Reasonably often, we will see attempts to access just: ``` www.example.com/ViewCustomer ``` Or system logs this as invalid and sends back a "An error has occurred, contact suppor...
I now think this was actually a tomcat bug [getParameter() fails on POST with transfer-encoding: chunked](https://issues.apache.org/bugzilla/show_bug.cgi?id=37794).
186,472
<p>I've seen some Python programmers use the following style fairly consistently (we'll call it style 1):</p> <pre><code>import some_module # Use some_module.some_identifier in various places. </code></pre> <p>For support of this style, you can cite the <a href="http://www.python.org/dev/peps/pep-0020/" rel="nofollow...
[ { "answer_id": 186483, "author": "Greg Hewgill", "author_id": 893, "author_profile": "https://Stackoverflow.com/users/893", "pm_score": 3, "selected": false, "text": "<p>With the existence of the following syntax:</p>\n\n<pre><code>import some_other_module as some_module\n</code></pre>\n...
2008/10/09
[ "https://Stackoverflow.com/questions/186472", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3594/" ]
I've seen some Python programmers use the following style fairly consistently (we'll call it style 1): ``` import some_module # Use some_module.some_identifier in various places. ``` For support of this style, you can cite the ["explicit is better than implicit"](http://www.python.org/dev/peps/pep-0020/) maxim. I've...
There are uses for both cases, so I don't think this is an either-or issue. I'd consider using from module `import x,y,z` when: * There are a fairly small number of things to import * The purpose of the functions imported is obvious when divorced from the module name. If the names are fairly generic, they may clash wi...
186,475
<p>I would like to use databinding when displaying data in a TextBox. I'm basically doing like:</p> <pre><code> public void ShowRandomObject(IRandomObject randomObject) { Binding binding = new Binding {Source = randomObject, Path = new PropertyPath("Name")}; txtName.SetBinding(TextBox.TextProperty, bin...
[ { "answer_id": 186479, "author": "Pop Catalin", "author_id": 4685, "author_profile": "https://Stackoverflow.com/users/4685", "pm_score": 7, "selected": true, "text": "<p>When available</p>\n\n<pre><code>BindingOperations.ClearBinding(txtName, TextBox.TextProperty)\n</code></pre>\n\n<p>Fo...
2008/10/09
[ "https://Stackoverflow.com/questions/186475", "https://Stackoverflow.com", "https://Stackoverflow.com/users/143/" ]
I would like to use databinding when displaying data in a TextBox. I'm basically doing like: ``` public void ShowRandomObject(IRandomObject randomObject) { Binding binding = new Binding {Source = randomObject, Path = new PropertyPath("Name")}; txtName.SetBinding(TextBox.TextProperty, binding); } ...
When available ``` BindingOperations.ClearBinding(txtName, TextBox.TextProperty) ``` For older SilverLight versions, but not reliable as stated in comments: ``` txtName.SetBinding(TextBox.TextProperty, null); ``` C# 6.0 features enabled ``` this.btnFinish.ClearBinding(ButtonBase.CommandProperty); ```
186,477
<p>I have a function which parses one string into two strings. In C# I would declare it like this:</p> <pre><code>void ParseQuery(string toParse, out string search, out string sort) { ... } </code></pre> <p>and I'd call it like this:</p> <pre><code>string searchOutput, sortOutput; ParseQuery(userInput, out sear...
[ { "answer_id": 186504, "author": "Greg Dean", "author_id": 1200558, "author_profile": "https://Stackoverflow.com/users/1200558", "pm_score": -1, "selected": false, "text": "<p>It's not supported. The closest you can get is ref</p>\n\n<p>Granted you can fake it, but you lose a compile ti...
2008/10/09
[ "https://Stackoverflow.com/questions/186477", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15371/" ]
I have a function which parses one string into two strings. In C# I would declare it like this: ``` void ParseQuery(string toParse, out string search, out string sort) { ... } ``` and I'd call it like this: ``` string searchOutput, sortOutput; ParseQuery(userInput, out searchOutput, out sortOutput); ``` The c...
C++/CLI itself doesn't support a real 'out' argument, but you can mark a reference as an out argument to make other languages see it as a real out argument. You can do this for reference types as: ``` void ReturnString([Out] String^% value) { value = "Returned via out parameter"; } // Called as String^ result; Re...
186,522
<p>Is there a better way to profile code then:</p> <pre><code>$start1 = microtime(TRUE); for($i=0;$i&lt;count($array);$i++) { //do something } $time1 = microtime(TRUE) - $start1; </code></pre>
[ { "answer_id": 186596, "author": "Dinoboff", "author_id": 1771, "author_profile": "https://Stackoverflow.com/users/1771", "pm_score": 3, "selected": true, "text": "<p>Xdebug or Zend Debugger if you have some difficulty to install Xdebug.</p>\n\n<p>Their profiler will time everything for ...
2008/10/09
[ "https://Stackoverflow.com/questions/186522", "https://Stackoverflow.com", "https://Stackoverflow.com/users/115/" ]
Is there a better way to profile code then: ``` $start1 = microtime(TRUE); for($i=0;$i<count($array);$i++) { //do something } $time1 = microtime(TRUE) - $start1; ```
Xdebug or Zend Debugger if you have some difficulty to install Xdebug. Their profiler will time everything for you without any modification of your code. <http://www.xdebug.org/> <http://www.zend.com/en/community/pdt> <http://devzone.zend.com/article/2899-Profiling-PHP-Applications-With-xdebug> - a serie of tutoria...
186,544
<p>I need a function which executes an INSERT statement on a database and returns the Auto_Increment primary key. I have the following C# code but, while the INSERT statement works fine (I can see the record in the database, the PK is generated correctly and rows == 1), the id value is always 0. Any ideas on what might...
[ { "answer_id": 186555, "author": "Richard Harrison", "author_id": 19624, "author_profile": "https://Stackoverflow.com/users/19624", "pm_score": 1, "selected": false, "text": "<p>I think you need to have the Select @@identity with the first create command - try appending it via \";SELECT ...
2008/10/09
[ "https://Stackoverflow.com/questions/186544", "https://Stackoverflow.com", "https://Stackoverflow.com/users/23826/" ]
I need a function which executes an INSERT statement on a database and returns the Auto\_Increment primary key. I have the following C# code but, while the INSERT statement works fine (I can see the record in the database, the PK is generated correctly and rows == 1), the id value is always 0. Any ideas on what might b...
1) combine the INSERT and SELECT statement (concatenate using ";") into 1 db command 2) use SCOPE\_IDENTITY() instead of @@IDENTITY INSERT INTO blabla... ; SELECT OID FROM table WHERE OID = SCOPE\_IDENTITY() -- update: as it turned out that the question was related to MS ACCESS, I found [this article](http://www.mi...
186,548
<p>I am using IIS6, I've written an HttpModule, and I get this error? After googling the web I find that this problem is caused by the .NET framework 3.5, so I put this on a machine where I didn't install .NET 3.5, but the problem is still there!</p>
[ { "answer_id": 186574, "author": "AnthonyWJones", "author_id": 17516, "author_profile": "https://Stackoverflow.com/users/17516", "pm_score": 3, "selected": false, "text": "<p>Only IIS7 supports the integrated pipeline. On IIS7 a HttpModule can participate in all requests coming to the w...
2008/10/09
[ "https://Stackoverflow.com/questions/186548", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20142/" ]
I am using IIS6, I've written an HttpModule, and I get this error? After googling the web I find that this problem is caused by the .NET framework 3.5, so I put this on a machine where I didn't install .NET 3.5, but the problem is still there!
My attempt at psychic debugging: you're using a statement like: ``` Response.Headers("X-Foo") = "bar" ``` If this is indeed the case, changing this as shown below will work around the problem: ``` Response.AddHeader("X-Foo", "bar") ```
186,553
<p>There is the button control in silverlight application . Can I send a mouse click event to it programmatically?</p>
[ { "answer_id": 186618, "author": "Oli", "author_id": 12870, "author_profile": "https://Stackoverflow.com/users/12870", "pm_score": -1, "selected": false, "text": "<p>I've not used Silverlight but I assume it's the same process as Windows.Forms and WebControls. You'll just need to call th...
2008/10/09
[ "https://Stackoverflow.com/questions/186553", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
There is the button control in silverlight application . Can I send a mouse click event to it programmatically?
If you still want to do that. You can now upgrade to Silverlight version 3.0 or later versions and do the following: You can use the button automation peer from System.Windows.Automation.Peers to accomplish what you want. ``` if (button is Button) { ButtonAutomationPeer peer = new ButtonAutomationPeer((Button)but...
186,556
<p>Say you have 100 directories and for each directory you have a file named .pdf stored somewhere else. If you want to move/copy each file into the directory with the same name, can this be done on the Windows command line?</p>
[ { "answer_id": 186580, "author": "Liam", "author_id": 445016, "author_profile": "https://Stackoverflow.com/users/445016", "pm_score": 0, "selected": false, "text": "<p>You would need to write a script to iterate through each file (and its path), extract the filename-'.pdf' and then move ...
2008/10/09
[ "https://Stackoverflow.com/questions/186556", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13220/" ]
Say you have 100 directories and for each directory you have a file named .pdf stored somewhere else. If you want to move/copy each file into the directory with the same name, can this be done on the Windows command line?
You can do it using the [FOR command](http://technet.microsoft.com/en-us/library/bb490909.aspx). Something in the line of: ``` for /f %%f in ('dir /s /b c:\source\*.pdf') do copy "%%f" c:\target ``` If you have a list of the file names w/ full path in a text file, say files.txt, you can also do ``` for /f %%f in (f...
186,588
<p>When you limit the number of rows to be returned by a SQL query, usually used in paging, there are two methods to determine the total number of records:</p> <h3>Method 1</h3> <p>Include the <code>SQL_CALC_FOUND_ROWS</code> option in the original <code>SELECT</code>, and then get the total number of rows by running...
[ { "answer_id": 188682, "author": "nathan", "author_id": 16430, "author_profile": "https://Stackoverflow.com/users/16430", "pm_score": 8, "selected": true, "text": "<p>It depends. See the MySQL Performance Blog post on this subject: <a href=\"https://www.percona.com/blog/2007/08/28/to-sq...
2008/10/09
[ "https://Stackoverflow.com/questions/186588", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6681/" ]
When you limit the number of rows to be returned by a SQL query, usually used in paging, there are two methods to determine the total number of records: ### Method 1 Include the `SQL_CALC_FOUND_ROWS` option in the original `SELECT`, and then get the total number of rows by running `SELECT FOUND_ROWS()`: ``` SELECT S...
It depends. See the MySQL Performance Blog post on this subject: [To `SQL_CALC_FOUND_ROWS` or not to `SQL_CALC_FOUND_ROWS`?](https://www.percona.com/blog/2007/08/28/to-sql_calc_found_rows-or-not-to-sql_calc_found_rows/) Just a quick summary: Peter says that it depends on your indexes and other factors. Many of the com...
186,606
<p>Can i override fetchall method in a model? I need to check sth everytime fetchAll is called. The model extends Zend_db_table_abstract</p>
[ { "answer_id": 198102, "author": "Kieran Hall", "author_id": 6085, "author_profile": "https://Stackoverflow.com/users/6085", "pm_score": 3, "selected": false, "text": "<p>To override this method you would need to subclass the Zend_Db_Table_Abstract. Like so:</p>\n\n<pre><code>&lt;?php\n...
2008/10/09
[ "https://Stackoverflow.com/questions/186606", "https://Stackoverflow.com", "https://Stackoverflow.com/users/24789/" ]
Can i override fetchall method in a model? I need to check sth everytime fetchAll is called. The model extends Zend\_db\_table\_abstract
To override this method you would need to subclass the Zend\_Db\_Table\_Abstract. Like so: ``` <?php abstract class My_Db_Table_Abstract extends Zend_Db_Table_Abstract { ... public function fetchAll($where, $order) { ... } ... } ``` Then make sure your models extend My\_Db\_Table\_Abstr...
186,622
<ol> <li>How precise is the VB6 <code>Date</code> data type (by way of fractions of a second)?</li> <li>How to format it to show fractions of a second?</li> </ol> <p>I'm revisiting VB6 after many years absence, and for the life of me can't remember the things I used to know. I considered putting a <a href="/questions/...
[ { "answer_id": 186669, "author": "dummy", "author_id": 6297, "author_profile": "https://Stackoverflow.com/users/6297", "pm_score": 1, "selected": false, "text": "<p>I think that the Date Datatype in VB6 can not handle fractions of a second.</p>\n" }, { "answer_id": 186675, "a...
2008/10/09
[ "https://Stackoverflow.com/questions/186622", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18797/" ]
1. How precise is the VB6 `Date` data type (by way of fractions of a second)? 2. How to format it to show fractions of a second? I'm revisiting VB6 after many years absence, and for the life of me can't remember the things I used to know. I considered putting a [memory-leak](/questions/tagged/memory-leak "show questio...
1) Seconds only, and 2) There's no way.
186,631
<p>I have a WCF service and I want to expose it as both a RESTfull service and as a SOAP service. Anyone has done something like this before?</p>
[ { "answer_id": 186695, "author": "Ray Lu", "author_id": 11413, "author_profile": "https://Stackoverflow.com/users/11413", "pm_score": 10, "selected": true, "text": "<p>You can expose the service in two different endpoints.\nthe SOAP one can use the binding that support SOAP e.g. basicHtt...
2008/10/09
[ "https://Stackoverflow.com/questions/186631", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15314/" ]
I have a WCF service and I want to expose it as both a RESTfull service and as a SOAP service. Anyone has done something like this before?
You can expose the service in two different endpoints. the SOAP one can use the binding that support SOAP e.g. basicHttpBinding, the RESTful one can use the webHttpBinding. I assume your REST service will be in JSON, in that case, you need to configure the two endpoints with the following behaviour configuration ``` <...
186,634
<p>I've got the following example running in a simple Silverlight page:</p> <pre><code>public Page() { InitializeComponent(); InitializeOther(); } private DoubleCollection dashes; public DoubleCollection Dashes { get { //dashes = new DoubleCollection(); //works ok //dashes.Add(2.0); //dashes.Add(...
[ { "answer_id": 187228, "author": "Santiago Palladino", "author_id": 12791, "author_profile": "https://Stackoverflow.com/users/12791", "pm_score": 0, "selected": false, "text": "<p>The fact that StrokeDashArray is a dependency property shouldn't have anything to do with that code failing,...
2008/10/09
[ "https://Stackoverflow.com/questions/186634", "https://Stackoverflow.com", "https://Stackoverflow.com/users/23724/" ]
I've got the following example running in a simple Silverlight page: ``` public Page() { InitializeComponent(); InitializeOther(); } private DoubleCollection dashes; public DoubleCollection Dashes { get { //dashes = new DoubleCollection(); //works ok //dashes.Add(2.0); //dashes.Add(2.0); if ...
Thank you for your answers and comments. I can run exactly the same code in a WPF application and it does not fail. For me, this is a clear indication that it is a Silverlight bug. I don't now think it has anything to do with dependency properties.
186,648
<p>I'm working on a C++ library that (among other stuff) has functions to read config files; and I want to add tests for this. So far, this has lead me to create lots of valid and invalid config files, each with only a few lines that test one specific functionality. But it has now got very unwieldy, as there are so man...
[ { "answer_id": 186690, "author": "richq", "author_id": 4596, "author_profile": "https://Stackoverflow.com/users/4596", "pm_score": 3, "selected": false, "text": "<p>Perhaps the library could accept some kind of stream input, so you could pass in a string-like object and avoid all the inp...
2008/10/09
[ "https://Stackoverflow.com/questions/186648", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2148773/" ]
I'm working on a C++ library that (among other stuff) has functions to read config files; and I want to add tests for this. So far, this has lead me to create lots of valid and invalid config files, each with only a few lines that test one specific functionality. But it has now got very unwieldy, as there are so many f...
Perhaps the library could accept some kind of stream input, so you could pass in a string-like object and avoid all the input files? Or depending on the type of configuration, you could provide "get/setAttribute()" functions to directly, publicy, fiddle the parameters. If that is not really a design goal, then never mi...
186,649
<p>I have a class hierarchy as such:</p> <pre><code> +-- VirtualNode | INode --+ +-- SiteNode | | +-- AbstractNode --+ | +-- SiteSubNode </code></pre> <p>And a corresponding <code>NodeCollection</cod...
[ { "answer_id": 186654, "author": "Andrew", "author_id": 826, "author_profile": "https://Stackoverflow.com/users/826", "pm_score": 2, "selected": true, "text": "<p>What you're after is the <a href=\"http://en.wikipedia.org/wiki/Visitor_pattern\" rel=\"nofollow noreferrer\">visitor pattern...
2008/10/09
[ "https://Stackoverflow.com/questions/186649", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7028/" ]
I have a class hierarchy as such: ``` +-- VirtualNode | INode --+ +-- SiteNode | | +-- AbstractNode --+ | +-- SiteSubNode ``` And a corresponding `NodeCollection` class that is build on `INode`. In...
What you're after is the [visitor pattern](http://en.wikipedia.org/wiki/Visitor_pattern), I think.
186,671
<p>What avenues are there for using an XSD to generate message instances? I seem to remember reading about generating classes from XSD, but can't find anything specific now. I know you can generate classes and datasets from XSD, but I'm looking for a pattern for automating the actual generation of the messages.</p> ...
[ { "answer_id": 186684, "author": "leppie", "author_id": 15541, "author_profile": "https://Stackoverflow.com/users/15541", "pm_score": 2, "selected": true, "text": "<pre><code>xsd /c yourschema.xsd &gt; yourschema.cs\n</code></pre>\n" }, { "answer_id": 526236, "author": "ccook...
2008/10/09
[ "https://Stackoverflow.com/questions/186671", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8741/" ]
What avenues are there for using an XSD to generate message instances? I seem to remember reading about generating classes from XSD, but can't find anything specific now. I know you can generate classes and datasets from XSD, but I'm looking for a pattern for automating the actual generation of the messages. BTW, SO i...
``` xsd /c yourschema.xsd > yourschema.cs ```
186,693
<p>I'm trying to balance a set of currency values using vb.net. The totals for both these values is cast as a double. I'm getting rounding errors in some situations. </p> <p>What's the best way to avoid this? Is there a type I can use in preference to double? How do I round the resultant value to two decimal places?</...
[ { "answer_id": 186697, "author": "Inisheer", "author_id": 2982, "author_profile": "https://Stackoverflow.com/users/2982", "pm_score": 2, "selected": false, "text": "<p>Try using the Decimal type.</p>\n\n<p><a href=\"http://msdn.microsoft.com/en-us/library/system.decimal.aspx\" rel=\"nofo...
2008/10/09
[ "https://Stackoverflow.com/questions/186693", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1726/" ]
I'm trying to balance a set of currency values using vb.net. The totals for both these values is cast as a double. I'm getting rounding errors in some situations. What's the best way to avoid this? Is there a type I can use in preference to double? How do I round the resultant value to two decimal places? Here's my ...
For financial calculations I believe that the current wisdom is to use Decimals instead of Doubles. You might be interested in this discussion [Decimal Vs. Double](https://stackoverflow.com/questions/4/decimal-vs-double).
186,718
<p>I have some really complicated legacy code I've been working on that crashes when collecting big chunks of data. I've been unable to find the exact reason for the crashes and am trying different ways to solve it or at least recover nicely. The last thing I did was enclose the crashing code in a</p> <pre><code>try ...
[ { "answer_id": 186739, "author": "gabr", "author_id": 4997, "author_profile": "https://Stackoverflow.com/users/4997", "pm_score": 4, "selected": true, "text": "<p>\"Very low address\" probably means that somebody tried to call a virtual method on an object that was not really there (i.e....
2008/10/09
[ "https://Stackoverflow.com/questions/186718", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9077/" ]
I have some really complicated legacy code I've been working on that crashes when collecting big chunks of data. I've been unable to find the exact reason for the crashes and am trying different ways to solve it or at least recover nicely. The last thing I did was enclose the crashing code in a ``` try ... except ...
"Very low address" probably means that somebody tried to call a virtual method on an object that was not really there (i.e. was 'nil'). For example: TStringList(nil).Clear; The first part is very mysterious, though. I have no idea how that can happen. I think you should try to catch that exception with [madExcept](h...
186,737
<p>I want to delete a folder that contains thousands of files and folders. If I use Windows Explorer to delete the folder it can take 10-15 minutes (not always, but often). Is there a faster way in Windows to delete folders? </p> <p>Other details:</p> <ul> <li>I don't care about the recycle bin.</li> <li>It's an NTFS...
[ { "answer_id": 186748, "author": "Stephen Denne", "author_id": 11721, "author_profile": "https://Stackoverflow.com/users/11721", "pm_score": 10, "selected": true, "text": "<h3>Using Windows Command Prompt:</h3>\n<pre><code>rmdir /s /q folder\n</code></pre>\n<h3>Using Powershell:</h3>\n<p...
2008/10/09
[ "https://Stackoverflow.com/questions/186737", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11766/" ]
I want to delete a folder that contains thousands of files and folders. If I use Windows Explorer to delete the folder it can take 10-15 minutes (not always, but often). Is there a faster way in Windows to delete folders? Other details: * I don't care about the recycle bin. * It's an NTFS drive.
### Using Windows Command Prompt: ``` rmdir /s /q folder ``` ### Using Powershell: ``` powershell -Command "Remove-Item -LiteralPath 'folder' -Force -Recurse" ``` Note that in more cases `del` and `rmdir` wil leave you with leftover files, where Powershell manages to delete the files.
186,756
<p>How do I generate a range of consecutive numbers (one per line) from a MySQL query so that I can insert them into a table?</p> <p>For example:</p> <pre><code>nr 1 2 3 4 5 </code></pre> <p>I would like to use only MySQL for this (not PHP or other languages).</p>
[ { "answer_id": 186780, "author": "Tomalak", "author_id": 18771, "author_profile": "https://Stackoverflow.com/users/18771", "pm_score": 3, "selected": false, "text": "<pre><code>DECLARE i INT DEFAULT 0;\n\nWHILE i &lt; 6 DO\n /* insert into table... */\n SET i = i + 1;\nEND WHILE;\n</co...
2008/10/09
[ "https://Stackoverflow.com/questions/186756", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14635/" ]
How do I generate a range of consecutive numbers (one per line) from a MySQL query so that I can insert them into a table? For example: ``` nr 1 2 3 4 5 ``` I would like to use only MySQL for this (not PHP or other languages).
If you need the records in a table and you want to avoid concurrency issues, here's how to do it. First you create a table in which to store your records ``` CREATE TABLE `incr` ( `Id` int(11) NOT NULL auto_increment, PRIMARY KEY (`Id`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; ``` Secondly create a stored proced...
186,799
<p>When using JDBC, I often come across constructs like </p> <pre><code>ResultSet rs = ps.executeQuery(); while (rs.next()) { int id = rs.getInt(1); // Some other actions } </code></pre> <p>I asked myself (and authors of code too) why not to use labels for retrieving column values: </p> <pre><code>int id =...
[ { "answer_id": 186812, "author": "zloster", "author_id": 25429, "author_profile": "https://Stackoverflow.com/users/25429", "pm_score": 1, "selected": false, "text": "<p>The JDBC driver takes care for the column to index look-up. So if you extract values by column name each time the drive...
2008/10/09
[ "https://Stackoverflow.com/questions/186799", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11732/" ]
When using JDBC, I often come across constructs like ``` ResultSet rs = ps.executeQuery(); while (rs.next()) { int id = rs.getInt(1); // Some other actions } ``` I asked myself (and authors of code too) why not to use labels for retrieving column values: ``` int id = rs.getInt("CUSTOMER_ID"); ``` The be...
You should use **string labels by default.** **Pros:** * Independence of column order * Better readability/maintainability **Cons:** * You have no control over the column names (access via stored procedures) **Which would you prefer?** ints? ``` int i = 1; customerId = resultSet.getInt(i++); customerName = r...
186,800
<p>I need to configure a website to access a webservice on another machine, via a proxy. I can configure the website to use a proxy, but I can't find a way of specifying the credentials that the proxy requires, is that possible? Here is my current configuration:</p> <pre><code>&lt;defaultProxy useDefaultCredentials=...
[ { "answer_id": 186859, "author": "questzen", "author_id": 25210, "author_profile": "https://Stackoverflow.com/users/25210", "pm_score": 1, "selected": false, "text": "<p>Directory Services/LDAP lookups can be used to serve this purpose. It involves some changes at infrastructure level, b...
2008/10/09
[ "https://Stackoverflow.com/questions/186800", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5793/" ]
I need to configure a website to access a webservice on another machine, via a proxy. I can configure the website to use a proxy, but I can't find a way of specifying the credentials that the proxy requires, is that possible? Here is my current configuration: ``` <defaultProxy useDefaultCredentials="false"> <proxy...
Yes, it is possible to specify your own credentials without modifying the current code. It requires a small piece of code from your part though. Create an assembly called *SomeAssembly.dll* with this class : ``` namespace SomeNameSpace { public class MyProxy : IWebProxy { public ICredentials Credentia...
186,802
<p>I have named_scope which is reused in multiple ActiveRecord models. For example:</p> <pre><code> named_scope :limit, lambda {|limit| {:limit =&gt; limit}} </code></pre> <p>What is the best practice to extract this code to be shared across models. Is it possible to extract it to a module or should I rather reo...
[ { "answer_id": 187097, "author": "Ben Scofield", "author_id": 6478, "author_profile": "https://Stackoverflow.com/users/6478", "pm_score": 4, "selected": false, "text": "<p>Use a module. Something like this should work:</p>\n\n<pre><code>module CommonScopes\n def self.included(base)\n ...
2008/10/09
[ "https://Stackoverflow.com/questions/186802", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18715/" ]
I have named\_scope which is reused in multiple ActiveRecord models. For example: ``` named_scope :limit, lambda {|limit| {:limit => limit}} ``` What is the best practice to extract this code to be shared across models. Is it possible to extract it to a module or should I rather reopen ActiveRecord::Base class...
Use a module. Something like this should work: ``` module CommonScopes def self.included(base) base.class_eval do named_scope :limit, lambda {|limit| {:limit => limit}} end end end ``` Then just include CommonScopes and you'll be good to go.
186,822
<p>How do I invoke a console application from my .NET application and capture all the output generated in the console? </p> <p>(Remember, I don't want to save the information first in a file and then relist as I would love to receive it as live.)</p>
[ { "answer_id": 186833, "author": "mdb", "author_id": 8562, "author_profile": "https://Stackoverflow.com/users/8562", "pm_score": 8, "selected": true, "text": "<p>This can be quite easily achieved using the <a href=\"http://msdn.microsoft.com/en-us/library/system.diagnostics.processstarti...
2008/10/09
[ "https://Stackoverflow.com/questions/186822", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17519/" ]
How do I invoke a console application from my .NET application and capture all the output generated in the console? (Remember, I don't want to save the information first in a file and then relist as I would love to receive it as live.)
This can be quite easily achieved using the [ProcessStartInfo.RedirectStandardOutput](http://msdn.microsoft.com/en-us/library/system.diagnostics.processstartinfo.redirectstandardoutput.aspx) property. A full sample is contained in the linked MSDN documentation; the only caveat is that you may have to redirect the stand...
186,827
<p>I need to send email through an (external) SMTP server from Java however this server will only accept CRAM-MD5 authentication, which is not supported by JavaMail.</p> <p>What would be a good way to get these emails to send? (It must be in Java.)</p>
[ { "answer_id": 186906, "author": "C. K. Young", "author_id": 13, "author_profile": "https://Stackoverflow.com/users/13", "pm_score": 2, "selected": false, "text": "<p>This doesn't help you directly, however, IMAP connections in JavaMail do support SASL (and thus CRAM-MD5, see the <a href...
2008/10/09
[ "https://Stackoverflow.com/questions/186827", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15355/" ]
I need to send email through an (external) SMTP server from Java however this server will only accept CRAM-MD5 authentication, which is not supported by JavaMail. What would be a good way to get these emails to send? (It must be in Java.)
Here is [thread](http://lists.gnu.org/archive/html/classpathx-javamail/2010-10/msg00004.html) which says that you need to add the following property: ``` props.put("mail.smtp.auth.mechanisms", "CRAM-MD5") ``` Also in Geronimo implementation there is [CramMD5Authenticator](http://geronimo.apache.org/maven/javamail/1....
186,829
<p>Conventional IPv4 dotted quad notation separates the address from the port with a colon, as in this example of a webserver on the loopback interface:</p> <pre><code>127.0.0.1:80 </code></pre> <p>but with IPv6 notation the address itself can contain colons. For example, this is the short form of the loopback addres...
[ { "answer_id": 186842, "author": "Oli", "author_id": 12870, "author_profile": "https://Stackoverflow.com/users/12870", "pm_score": 3, "selected": false, "text": "<p>They're the same, aren't they? Now I'm losing confidence in myself but I really thought IPv6 was just an addressing change....
2008/10/09
[ "https://Stackoverflow.com/questions/186829", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1715673/" ]
Conventional IPv4 dotted quad notation separates the address from the port with a colon, as in this example of a webserver on the loopback interface: ``` 127.0.0.1:80 ``` but with IPv6 notation the address itself can contain colons. For example, this is the short form of the loopback address: ``` ::1 ``` How are ...
They work almost the same as today. However, be sure you include `[]` around your IP. For example : [`http://[1fff:0:a88:85a3::ac1f]:8001/index.html`](http://en.wikipedia.org/wiki/IPv6_address#Literal_IPv6_addresses_in_network_resource_identifiers) Wikipedia has a pretty good article about IPv6: <http://en.wikipedia....
186,840
<p>My company runs a webmail service, and we were trying to diagnose a problem with Word downloads not opening automatically - the same *.doc file download from Yahoo Mail would open, but one from ours would not.</p> <p>In the course of investigating the headers we saw this coming from Yahoo:</p> <pre><code>content-d...
[ { "answer_id": 186886, "author": "Alphager", "author_id": 21684, "author_profile": "https://Stackoverflow.com/users/21684", "pm_score": 0, "selected": false, "text": "<p>What Mime-Type are you using?</p>\n\n<p>The asterisk is required as per RFC 2183 (<a href=\"http://www.ietf.org/rfc/rf...
2008/10/09
[ "https://Stackoverflow.com/questions/186840", "https://Stackoverflow.com", "https://Stackoverflow.com/users/25487/" ]
My company runs a webmail service, and we were trying to diagnose a problem with Word downloads not opening automatically - the same \*.doc file download from Yahoo Mail would open, but one from ours would not. In the course of investigating the headers we saw this coming from Yahoo: ``` content-disposition attachmen...
I think the correct answer to this is in rfc 2231: Asterisks ("\*") are reused to provide the indicator that language and character set information is present and encoding is being used. A single quote ("'") is used to delimit the character set and language information at the beginning of the parameter value. Perce...
186,854
<p>I can hookup to <code>AppDomain.CurrentDomain.UnhandledException</code> to log exceptions from background threads, but how do I prevent them terminating the runtime?</p>
[ { "answer_id": 186863, "author": "Mitch Wheat", "author_id": 16076, "author_profile": "https://Stackoverflow.com/users/16076", "pm_score": 3, "selected": false, "text": "<p>From Joe Albahari's excellent <a href=\"http://www.albahari.com/threading/\" rel=\"noreferrer\">threading</a> artic...
2008/10/09
[ "https://Stackoverflow.com/questions/186854", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5978/" ]
I can hookup to `AppDomain.CurrentDomain.UnhandledException` to log exceptions from background threads, but how do I prevent them terminating the runtime?
First, you really should try not to have exceptions thrown - and not handled - in a background thread. If you control the way your delegate is run, encapsulate it in a try catch block and figure a way to pass the exception information back to your main thread (using EndInvoke if you explicitly called BeginInvoke, or by...
186,857
<p>I have a string that looks like this:</p> <pre><code>"Name1=Value1;Name2=Value2;Name3=Value3" </code></pre> <p>Is there a built-in class/function in Python that will take that string and construct a dictionary, as though I had done this:</p> <pre><code>dict = { "Name1": "Value1", "Name2": "Value2", "N...
[ { "answer_id": 186873, "author": "Brian", "author_id": 9493, "author_profile": "https://Stackoverflow.com/users/9493", "pm_score": 8, "selected": true, "text": "<p>There's no builtin, but you can accomplish this fairly simply with a generator comprehension:</p>\n\n<pre><code>s= \"Name1=V...
2008/10/09
[ "https://Stackoverflow.com/questions/186857", "https://Stackoverflow.com", "https://Stackoverflow.com/users/267/" ]
I have a string that looks like this: ``` "Name1=Value1;Name2=Value2;Name3=Value3" ``` Is there a built-in class/function in Python that will take that string and construct a dictionary, as though I had done this: ``` dict = { "Name1": "Value1", "Name2": "Value2", "Name3": "Value3" } ``` I have looked...
There's no builtin, but you can accomplish this fairly simply with a generator comprehension: ``` s= "Name1=Value1;Name2=Value2;Name3=Value3" dict(item.split("=") for item in s.split(";")) ``` **[Edit]** From your update you indicate you may need to handle quoting. This does complicate things, depending on what the ...
186,867
<p>I need to stream a file to the Response for saving on the end user's machine. The file is plain text, so what content type can I use to prevent the text being displayed in the browser?</p>
[ { "answer_id": 186871, "author": "Tomalak", "author_id": 18771, "author_profile": "https://Stackoverflow.com/users/18771", "pm_score": 3, "selected": false, "text": "<p>I don't think it works that way.</p>\n\n<p>Use a <code>Content-Disposition: attachment</code> header, but stick with th...
2008/10/09
[ "https://Stackoverflow.com/questions/186867", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8741/" ]
I need to stream a file to the Response for saving on the end user's machine. The file is plain text, so what content type can I use to prevent the text being displayed in the browser?
To be on the safe side and ensure consistent behavior in all browsers, it's usually better to use both: ``` Content-Type: application/octet-stream Content-Disposition: attachment;filename=\"My Text File.txt\" ```
186,876
<p>The following works in Firefox, but breaks in IE7 &amp; 8:</p> <pre><code>$("#my-first-div, #my-second-div").hide(); </code></pre> <p>so I have to do this:</p> <pre><code>$("#my-first-div").hide(); $("#my-second-div").hide(); </code></pre> <p>Is this normal?</p> <p>EDIT: ok, my actual real-life code is this:</...
[ { "answer_id": 186914, "author": "Adam Bellaire", "author_id": 21632, "author_profile": "https://Stackoverflow.com/users/21632", "pm_score": 1, "selected": false, "text": "<p>Hmm, I can't seem to duplicate the problem in IE7 (both forms work fine for me). How does it break? Does it not...
2008/10/09
[ "https://Stackoverflow.com/questions/186876", "https://Stackoverflow.com", "https://Stackoverflow.com/users/26107/" ]
The following works in Firefox, but breaks in IE7 & 8: ``` $("#my-first-div, #my-second-div").hide(); ``` so I have to do this: ``` $("#my-first-div").hide(); $("#my-second-div").hide(); ``` Is this normal? EDIT: ok, my actual real-life code is this: ``` $("#charges-gsm,#charges-gsm-faq,#charges-gsm-prices").ht...
The location you specify states: ``` Message: 'nodeName' is null or not an object Line: 19 Char: 150 Code: 0 URI: http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js ``` That particular piece of jquery is: ``` nodeName:function(elem,name){ return elem.nodeName&&elem.nodeName.toUpperCase()==n...
186,883
<p>When deploying a ready to use erlang application I <strong>don't</strong> want the user to </p> <ul> <li>Find the right erl release on the internet.</li> <li>Install the erl vm</li> <li>unzip and decide a location for the beam files (with the application)</li> <li>read a readme</li> <li>modify anything that even lo...
[ { "answer_id": 186914, "author": "Adam Bellaire", "author_id": 21632, "author_profile": "https://Stackoverflow.com/users/21632", "pm_score": 1, "selected": false, "text": "<p>Hmm, I can't seem to duplicate the problem in IE7 (both forms work fine for me). How does it break? Does it not...
2008/10/09
[ "https://Stackoverflow.com/questions/186883", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15638/" ]
When deploying a ready to use erlang application I **don't** want the user to * Find the right erl release on the internet. * Install the erl vm * unzip and decide a location for the beam files (with the application) * read a readme * modify anything that even looks like a config file I have a couple of ideas of wha...
The location you specify states: ``` Message: 'nodeName' is null or not an object Line: 19 Char: 150 Code: 0 URI: http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js ``` That particular piece of jquery is: ``` nodeName:function(elem,name){ return elem.nodeName&&elem.nodeName.toUpperCase()==n...
186,891
<p>If I am passing an object to a method, why should I use the ref keyword? Isn't this the default behaviour anyway?</p> <p>For example:</p> <pre><code>class Program { static void Main(string[] args) { TestRef t = new TestRef(); t.Something = "Foo"; DoSomething(t); Console.Wri...
[ { "answer_id": 186897, "author": "Andrew", "author_id": 826, "author_profile": "https://Stackoverflow.com/users/826", "pm_score": 2, "selected": false, "text": "<p>If you're passing a value, however, things are different. You can force a value to be passed by reference. This allows you t...
2008/10/09
[ "https://Stackoverflow.com/questions/186891", "https://Stackoverflow.com", "https://Stackoverflow.com/users/93743/" ]
If I am passing an object to a method, why should I use the ref keyword? Isn't this the default behaviour anyway? For example: ``` class Program { static void Main(string[] args) { TestRef t = new TestRef(); t.Something = "Foo"; DoSomething(t); Console.WriteLine(t.Something); ...
Pass a `ref` if you want to change what the object is: ``` TestRef t = new TestRef(); t.Something = "Foo"; DoSomething(ref t); void DoSomething(ref TestRef t) { t = new TestRef(); t.Something = "Not just a changed t, but a completely different TestRef object"; } ``` After calling DoSomething, `t` does not refer...
186,894
<p>I am looking for the best way to test if a website is alive from a C# application.</p> <h3>Background</h3> <p>My application consists of a <em>Winforms UI</em>, a backend <em>WCF service</em> and a <em>website</em> to publish content to the UI and other consumers. To prevent the situation where the UI starts up and ...
[ { "answer_id": 186915, "author": "Robert Rouse", "author_id": 25129, "author_profile": "https://Stackoverflow.com/users/25129", "pm_score": -1, "selected": false, "text": "<p>You'll want to check the status code for OK (status 200).</p>\n" }, { "answer_id": 186931, "author": ...
2008/10/09
[ "https://Stackoverflow.com/questions/186894", "https://Stackoverflow.com", "https://Stackoverflow.com/users/231/" ]
I am looking for the best way to test if a website is alive from a C# application. ### Background My application consists of a *Winforms UI*, a backend *WCF service* and a *website* to publish content to the UI and other consumers. To prevent the situation where the UI starts up and fails to work properly because of ...
``` HttpWebResponse response = (HttpWebResponse)request.GetResponse(); if (response == null || response.StatusCode != HttpStatusCode.OK) ``` As @Yanga mentioned, HttpClient is probably the more common way to do this now. ``` HttpClient client = new HttpClient(); var checkingResponse = await client.GetAsync(url); if ...
186,916
<p>I have a python script that analyzes a set of error messages and checks for each message if it matches a certain pattern (regular expression) in order to group these messages. For example "file x does not exist" and "file y does not exist" would match "file .* does not exist" and be accounted as two occurrences of "...
[ { "answer_id": 186937, "author": "Andrew Wilkinson", "author_id": 2990, "author_profile": "https://Stackoverflow.com/users/2990", "pm_score": 2, "selected": false, "text": "<p>I think you want the <a href=\"http://docs.python.org/library/configparser.html#module-ConfigParser\" rel=\"nofo...
2008/10/09
[ "https://Stackoverflow.com/questions/186916", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15622/" ]
I have a python script that analyzes a set of error messages and checks for each message if it matches a certain pattern (regular expression) in order to group these messages. For example "file x does not exist" and "file y does not exist" would match "file .\* does not exist" and be accounted as two occurrences of "fi...
You have two decent options: 1. Python standard config file format using [ConfigParser](http://docs.python.org/lib/module-ConfigParser.html "ConfigParser") 2. [YAML](http://www.yaml.org/ "YAML") using a library like [PyYAML](http://pyyaml.org/ "PyYAML") The standard Python configuration files look like INI files with...
186,917
<p>I'm trying to catch a ClassCastException when deserializing an object from xml.</p> <p>So,</p> <pre><code>try { restoredItem = (T) decoder.readObject(); } catch (ClassCastException e){ //don't need to crash at this point, //just let the user know that a wrong file has been passed. } </code></pre> <p>An...
[ { "answer_id": 186977, "author": "yanchenko", "author_id": 15187, "author_profile": "https://Stackoverflow.com/users/15187", "pm_score": 0, "selected": false, "text": "<p>Well, I can't use <code>instanceof</code> operator as the method is a parametrized one:</p>\n\n<pre><code>public T re...
2008/10/09
[ "https://Stackoverflow.com/questions/186917", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15187/" ]
I'm trying to catch a ClassCastException when deserializing an object from xml. So, ``` try { restoredItem = (T) decoder.readObject(); } catch (ClassCastException e){ //don't need to crash at this point, //just let the user know that a wrong file has been passed. } ``` And yet this won't as the exception...
The code in the question should give you an unchecked cast warning. Listen to -Xlint. All the compiler knows about T is its bounds, which it probably doesn't have (other than explicitly extending Object and a super of the null type). So effectively the cast at runtime is (Object) - not very useful. What you can do is...
186,918
<p>My master page contains a list as shown here. What I'd like to do though, is add the "class=active" attribute to the list li thats currently active but I have no idea how to do this. I know that the code goes in the aspx page's page_load event, but no idea how to access the li I need to add the attribute. Please enl...
[ { "answer_id": 186926, "author": "Adam Naylor", "author_id": 17540, "author_profile": "https://Stackoverflow.com/users/17540", "pm_score": 0, "selected": false, "text": "<p>If they were runat=server you could use the attributes property.</p>\n" }, { "answer_id": 186976, "auth...
2008/10/09
[ "https://Stackoverflow.com/questions/186918", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17211/" ]
My master page contains a list as shown here. What I'd like to do though, is add the "class=active" attribute to the list li thats currently active but I have no idea how to do this. I know that the code goes in the aspx page's page\_load event, but no idea how to access the li I need to add the attribute. Please enlig...
In order to access these controls from the server-side, you need to make them runat="server" ``` <ul id="nav" runat="server"> <li class="forcePadding"><img src="css/site-style-images/menu_corner_right.jpg" /></li> <li id="screenshots"><a href="screenshots.aspx" title="Screenshots">Screenshots</a></l...
186,942
<p>I have this script:</p> <pre><code>select name,create_date,modify_date from sys.procedures order by modify_date desc </code></pre> <p>I can see what procedures were modified lately. I will add a "where modify_date >= " And I'd like to use some system stored procedure, that will generate me : drop + create scripts...
[ { "answer_id": 187063, "author": "jdecuyper", "author_id": 296, "author_profile": "https://Stackoverflow.com/users/296", "pm_score": 0, "selected": false, "text": "<p>You could use a cursor to iterate through each record: </p>\n\n<pre><code>DECLARE @spName NVARCHAR(128)\nDECLARE myCursor...
2008/10/09
[ "https://Stackoverflow.com/questions/186942", "https://Stackoverflow.com", "https://Stackoverflow.com/users/26472/" ]
I have this script: ``` select name,create_date,modify_date from sys.procedures order by modify_date desc ``` I can see what procedures were modified lately. I will add a "where modify\_date >= " And I'd like to use some system stored procedure, that will generate me : drop + create scripts for the (let's say 5 matc...
This ain't pretty, but it works. Run the output from it manually or execute it with sp\_executesql. ``` SELECT OBJECT_DEFINITION(object_id), 'drop procedure [' + name + ']' FROM sys.procedures WHERE modify_date >= @date ``` You will have to worry about lost rights as well.