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
130,396
<p>Is there a way to use constants in <strong>JavaScript</strong>?</p> <p>If not, what's the common practice for specifying variables that are used as constants?</p>
[ { "answer_id": 130398, "author": "Jason Bunting", "author_id": 1790, "author_profile": "https://Stackoverflow.com/users/1790", "pm_score": 5, "selected": false, "text": "<p>No, not in general. Firefox implements <code>const</code> but I know IE doesn't.</p>\n\n<hr>\n\n<p><a href=\"https:...
2008/09/24
[ "https://Stackoverflow.com/questions/130396", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10708/" ]
Is there a way to use constants in **JavaScript**? If not, what's the common practice for specifying variables that are used as constants?
Since [ES2015](https://www.ecma-international.org/ecma-262/6.0/), JavaScript has a notion of [`const`](https://www.ecma-international.org/ecma-262/6.0/#sec-let-and-const-declarations): ``` const MY_CONSTANT = "some-value"; ``` This will work in [pretty much all browsers except IE 8, 9 and 10](https://caniuse.com/#se...
130,404
<p>I'm trying to find a way to &quot;pretty print&quot; a JavaScript data structure in a human-readable form for debugging.</p> <p>I have a rather big and complicated data structure being stored in JS and I need to write some code to manipulate it. In order to work out what I'm doing and where I'm going wrong, what I r...
[ { "answer_id": 130420, "author": "John Millikin", "author_id": 3560, "author_profile": "https://Stackoverflow.com/users/3560", "pm_score": 4, "selected": false, "text": "<p>In <code>Firebug</code>, if you just <code>console.debug (\"%o\", my_object)</code> you can click on it in the cons...
2008/09/24
[ "https://Stackoverflow.com/questions/130404", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17121/" ]
I'm trying to find a way to "pretty print" a JavaScript data structure in a human-readable form for debugging. I have a rather big and complicated data structure being stored in JS and I need to write some code to manipulate it. In order to work out what I'm doing and where I'm going wrong, what I really need is to be...
I wrote a function to dump a JS object in a readable form, although the output isn't indented, but it shouldn't be too hard to add that: I made this function from one I made for Lua (which is much more complex) which handled this indentation issue. Here is the "simple" version: ``` function DumpObject(obj) { var od...
130,427
<p>Here's the situation. I have a webservice (C# 2.0), which consists of (mainly) a class inheriting from System.Web.Services.WebService. It contains a few methods, which all need to call a method that checks if they're authorized or not.</p> <p>Basically something like this (pardon the architecture, this is purely as...
[ { "answer_id": 130584, "author": "GregK", "author_id": 8653, "author_profile": "https://Stackoverflow.com/users/8653", "pm_score": 2, "selected": false, "text": "<p>You can implement the so-called SOAP extension by deriving from <a href=\"http://msdn.microsoft.com/en-us/library/system.we...
2008/09/24
[ "https://Stackoverflow.com/questions/130427", "https://Stackoverflow.com", "https://Stackoverflow.com/users/909/" ]
Here's the situation. I have a webservice (C# 2.0), which consists of (mainly) a class inheriting from System.Web.Services.WebService. It contains a few methods, which all need to call a method that checks if they're authorized or not. Basically something like this (pardon the architecture, this is purely as an exampl...
Here is what you need to do to get this to work correctly. It is possible to create your own custom SoapHeader: ``` public class ServiceAuthHeader : SoapHeader { public string SiteKey; public string Password; public ServiceAuthHeader() {} } ``` Then you need a SoapExtensionAttribute: ``` public class ...
130,506
<p>I recently inherited a small Java program that takes information from a large database, does some processing and produces a detailed image regarding the information. The original author wrote the code using a single thread, then later modified it to allow it to use multiple threads. </p> <p>In the code he defines a...
[ { "answer_id": 130527, "author": "Rob", "author_id": 3542, "author_profile": "https://Stackoverflow.com/users/3542", "pm_score": 2, "selected": false, "text": "<p>The number that your application needs; no more, and no less.</p>\n\n<p>Obviously, if you're writing an application which con...
2008/09/24
[ "https://Stackoverflow.com/questions/130506", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7613/" ]
I recently inherited a small Java program that takes information from a large database, does some processing and produces a detailed image regarding the information. The original author wrote the code using a single thread, then later modified it to allow it to use multiple threads. In the code he defines a constant;...
Threads are fine, but as others have noted, you have to be highly aware of your bottlenecks. Your algorithm sounds like it would be susceptible to cache contention between multiple CPUs - this is particularly nasty because it has the potential to hit the performance of all of your threads (normally you think of using m...
130,547
<p>Ok I followed the steps for setting up ruby and rails on my Vista machine and I am having a problem connecting to the database.</p> <h2>Contents of <code>database.yml</code></h2> <pre><code>development: adapter: sqlserver database: APPS_SETUP Host: WindowsVT06\SQLEXPRESS Username: se Password: paswd </co...
[ { "answer_id": 131501, "author": "hectorsq", "author_id": 14755, "author_profile": "https://Stackoverflow.com/users/14755", "pm_score": 2, "selected": false, "text": "<p>Did you install the SQL Server adapter?</p>\n\n<pre><code>gem install activerecord-sqlserver-adapter --source=http://g...
2008/09/24
[ "https://Stackoverflow.com/questions/130547", "https://Stackoverflow.com", "https://Stackoverflow.com/users/453046/" ]
Ok I followed the steps for setting up ruby and rails on my Vista machine and I am having a problem connecting to the database. Contents of `database.yml` -------------------------- ``` development: adapter: sqlserver database: APPS_SETUP Host: WindowsVT06\SQLEXPRESS Username: se Password: paswd ``` Run `...
I ran into the same problem yesterday. Apparently 'deprecated' is a gem, so you want to run "gem install deprecated" to grab and install the latest version. Good luck.
130,561
<p>I am building an application where a page will load user controls (x.ascx) dynamically based on query string. </p> <p>I have a validation summary on the page and want to update it from the User Controls. This will allow me to have multiple controls using one Validation Summary. How can I pass data between controls ...
[ { "answer_id": 130671, "author": "Jorge Alves", "author_id": 6195, "author_profile": "https://Stackoverflow.com/users/6195", "pm_score": 0, "selected": false, "text": "<p>Assuming you're talking about asp's validator controls, making them work with the validation summary should be easy: ...
2008/09/24
[ "https://Stackoverflow.com/questions/130561", "https://Stackoverflow.com", "https://Stackoverflow.com/users/709/" ]
I am building an application where a page will load user controls (x.ascx) dynamically based on query string. I have a validation summary on the page and want to update it from the User Controls. This will allow me to have multiple controls using one Validation Summary. How can I pass data between controls and pages....
**Found a way of doing this:** Step 1: Create a Base User Control and define Delegates and Events in this control. Step 2: Create a Public function in the base user control to Raise Events defined in Step1. ``` 'SourceCode for Step 1 and Step 2 Public Delegate Sub UpdatePageHeaderHandler(ByVal PageHeading As String...
130,570
<p>We have recently moved back to InstallShield 2008 from rolling our own install. So, I am still trying to get up the learning curve on it. </p> <p>We are using Firebird and a usb driver, that we couldn't find good msi install solutions. So, we have a cmd line to install firebird silently and the usb driver mostly si...
[ { "answer_id": 130757, "author": "Chris Tybur", "author_id": 741, "author_profile": "https://Stackoverflow.com/users/741", "pm_score": 0, "selected": false, "text": "<p>There are MSI properties you can look at that will tell you if a product is already installed or if an uninstall is tak...
2008/09/24
[ "https://Stackoverflow.com/questions/130570", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12425/" ]
We have recently moved back to InstallShield 2008 from rolling our own install. So, I am still trying to get up the learning curve on it. We are using Firebird and a usb driver, that we couldn't find good msi install solutions. So, we have a cmd line to install firebird silently and the usb driver mostly silently. W...
Chris, I had trouble getting the MsiGetProperty to work at all. Just adding the code that you have ``` string sRemove; number nBuffer; nBuffer = 256; if (MsiGetProperty(ISMSI_HANDLE, "REMOVE", sRemove, nBuffer) = ERROR_SUCCESS) then //do something endif; ``` I get "undefined identifier". I tried several thing...
130,573
<p>The <a href="http://msdn.microsoft.com/en-us/library/ms724284(VS.85).aspx" rel="nofollow noreferrer"><code>FILETIME</code> structure</a> counts from January 1 1601 (presumably the start of that day) according to the Microsoft documentation, but does this include leap seconds?</p>
[ { "answer_id": 130659, "author": "Brent.Longborough", "author_id": 9634, "author_profile": "https://Stackoverflow.com/users/9634", "pm_score": -1, "selected": false, "text": "<p>A very crude summary:</p>\n\n<p>UTC = (Atomic Time) + (Leap Seconds) ~~ (Mean Solar Time)</p>\n\n<p>The MS doc...
2008/09/24
[ "https://Stackoverflow.com/questions/130573", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10168/" ]
The [`FILETIME` structure](http://msdn.microsoft.com/en-us/library/ms724284(VS.85).aspx) counts from January 1 1601 (presumably the start of that day) according to the Microsoft documentation, but does this include leap seconds?
The question shouldn't be if `FILETIME` includes leap seconds. It should be: > > Do the people, functions, and libraries, who interpret a `FILETIME` (i.e. `FileTimeToSystemTime`) include leap seconds when counting the duration? > > > The simple answer is *"no"*. `FileTimeToSystemTime` returns seconds as `0..59`...
130,574
<p>I seek an algorithm that will let me represent an incoming sequence of bits as letters ('a' .. 'z' ), in a minimal matter such that the stream of bits can be regenerated from the letters, without ever holding the entire sequence in memory.</p> <p>That is, given an external bit source (each read returns a practicall...
[ { "answer_id": 130597, "author": "Smashery", "author_id": 14902, "author_profile": "https://Stackoverflow.com/users/14902", "pm_score": 2, "selected": false, "text": "<p>Could <a href=\"http://en.wikipedia.org/wiki/Huffman_coding\" rel=\"nofollow noreferrer\">Huffman coding</a> be what y...
2008/09/24
[ "https://Stackoverflow.com/questions/130574", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I seek an algorithm that will let me represent an incoming sequence of bits as letters ('a' .. 'z' ), in a minimal matter such that the stream of bits can be regenerated from the letters, without ever holding the entire sequence in memory. That is, given an external bit source (each read returns a practically random b...
If you assign a different number of bits per letter, you should be able to exactly encode the bits in the twenty-six letters allowed without wasting any bits. (This is a lot like a Huffman code, only with a pre-built balanced tree.) To encode bits into letters: Accumulate bits until you match exactly one of the bit co...
130,587
<p><em>[NOTE: This questions is similar to but <strong>not the same</strong> as <a href="https://stackoverflow.com/questions/128634/how-to-use-system-environment-variables-in-vs-2008-post-build-events">this one</a>.]</em></p> <p>Visual Studio defines several dozen "Macros" which are sort of simulated environment varia...
[ { "answer_id": 130773, "author": "TonyOssa", "author_id": 3276, "author_profile": "https://Stackoverflow.com/users/3276", "pm_score": 0, "selected": false, "text": "<p>This is a bit hacky, but it could work.</p>\n\n<p>Why not call multiple .py scripts in a row?</p>\n\n<p>Each scripts can...
2008/09/24
[ "https://Stackoverflow.com/questions/130587", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10559/" ]
*[NOTE: This questions is similar to but **not the same** as [this one](https://stackoverflow.com/questions/128634/how-to-use-system-environment-variables-in-vs-2008-post-build-events).]* Visual Studio defines several dozen "Macros" which are sort of simulated environment variables (completely unrelated to C++ macros)...
As far as I can tell, the method described in the question is the only way to pass build variables to a Python script. Perhaps Visual Studio 2010 has something better?
130,604
<p>I use int.MaxValue as a penalty and sometimes I am computing the penalties together. Is there a function or how would you create one with the most grace and efficiency that does that. </p> <p>ie. </p> <p>50 + 100 = 150</p> <p>int.Max + 50 = int.Max and not int.Min + 50 </p>
[ { "answer_id": 130660, "author": "Derek Park", "author_id": 872, "author_profile": "https://Stackoverflow.com/users/872", "pm_score": 3, "selected": true, "text": "<pre><code>int penaltySum(int a, int b)\n{\n return (int.MaxValue - a &lt; b) ? int.MaxValue : a + b;\n}\n</code></pre>\n...
2008/09/24
[ "https://Stackoverflow.com/questions/130604", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4694/" ]
I use int.MaxValue as a penalty and sometimes I am computing the penalties together. Is there a function or how would you create one with the most grace and efficiency that does that. ie. 50 + 100 = 150 int.Max + 50 = int.Max and not int.Min + 50
``` int penaltySum(int a, int b) { return (int.MaxValue - a < b) ? int.MaxValue : a + b; } ``` Update: If your penalties can be negative, this would be more appropriate: ``` int penaltySum(int a, int b) { if (a > 0 && b > 0) { return (int.MaxValue - a < b) ? int.MaxValue : a + b; } if (a...
130,605
<p>I have a table of Users that includes a bitmask of roles that the user belongs to. I'd like to select users that belong to one or more of the roles in a bitmask value. For example:</p> <pre>select * from [User] where UserRolesBitmask | 22 = 22</pre> <p>This selects all users that have the roles '2', '4' or '16'...
[ { "answer_id": 130691, "author": "KevDog", "author_id": 13139, "author_profile": "https://Stackoverflow.com/users/13139", "pm_score": 4, "selected": true, "text": "<p>I think this will work, but I haven't tested it.Substitute the name of your DataContext object. YMMV. </p>\n\n<pre><code>...
2008/09/24
[ "https://Stackoverflow.com/questions/130605", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14072/" ]
I have a table of Users that includes a bitmask of roles that the user belongs to. I'd like to select users that belong to one or more of the roles in a bitmask value. For example: ``` select * from [User] where UserRolesBitmask | 22 = 22 ``` This selects all users that have the roles '2', '4' or '16' in their bit...
I think this will work, but I haven't tested it.Substitute the name of your DataContext object. YMMV. ``` from u in DataContext.Users where UserRolesBitmask | 22 == 22 select u ```
130,614
<p>I've got a dictionary, something like</p> <pre><code>Dictionary&lt;Foo,String&gt; fooDict </code></pre> <p>I step through everything in the dictionary, e.g.</p> <pre><code>foreach (Foo foo in fooDict.Keys) MessageBox.show(fooDict[foo]); </code></pre> <p>It does that in the order the foos were added to the di...
[ { "answer_id": 130653, "author": "Statement", "author_id": 2166173, "author_profile": "https://Stackoverflow.com/users/2166173", "pm_score": 0, "selected": false, "text": "<p>I am <em>not fully educated in the domain</em> to properly answer the question, but I have <strong>a feeling</str...
2008/09/24
[ "https://Stackoverflow.com/questions/130614", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18210/" ]
I've got a dictionary, something like ``` Dictionary<Foo,String> fooDict ``` I step through everything in the dictionary, e.g. ``` foreach (Foo foo in fooDict.Keys) MessageBox.show(fooDict[foo]); ``` It does that in the order the foos were added to the dictionary, so the first item added is the first foo retu...
If you read the documentation on MSDN you'll see this: "The order in which the items are returned is undefined." You can't gaurantee the order, because a Dictionary is not a list or an array. It's meant to look up a value by the key, and any ability to iterate values is just a convenience but the order is not behavio...
130,616
<p>I'm trying to start a service as a user and things work fine, until I try a user that doesn't have a password. Then, it fails to start (due to log-on error).</p> <p>Am I doing something wrong or is this "by design"?</p> <p>The code to register this service:</p> <pre><code> SC_HANDLE schService = CreateService(...
[ { "answer_id": 130658, "author": "1800 INFORMATION", "author_id": 3146, "author_profile": "https://Stackoverflow.com/users/3146", "pm_score": 0, "selected": false, "text": "<p>You need to specify an empty string, not NULL if there is no password. NULL is not a valid empty string, \"\" is...
2008/09/24
[ "https://Stackoverflow.com/questions/130616", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20208/" ]
I'm trying to start a service as a user and things work fine, until I try a user that doesn't have a password. Then, it fails to start (due to log-on error). Am I doing something wrong or is this "by design"? The code to register this service: ``` SC_HANDLE schService = CreateService( schSCManager, ...
It may be due to an OS security requirement or security policy. Check the security policies to see if anything is relevant there.
130,617
<p>I got a program that writes some data to a file using a method like the one below.</p> <pre><code> public void ExportToFile(string filename) { using(FileStream fstream = new FileStream(filename,FileMode.Create)) using (TextWriter writer = new StreamWriter(fstream)) { // try catch block for w...
[ { "answer_id": 130641, "author": "Josh", "author_id": 11702, "author_profile": "https://Stackoverflow.com/users/11702", "pm_score": 7, "selected": true, "text": "<p><strong>UPDATE:</strong></p>\n\n<p>Modified the code based on <a href=\"https://stackoverflow.com/a/4397002/11702\">this an...
2008/09/24
[ "https://Stackoverflow.com/questions/130617", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1361/" ]
I got a program that writes some data to a file using a method like the one below. ``` public void ExportToFile(string filename) { using(FileStream fstream = new FileStream(filename,FileMode.Create)) using (TextWriter writer = new StreamWriter(fstream)) { // try catch block for write permissio...
**UPDATE:** Modified the code based on [this answer](https://stackoverflow.com/a/4397002/11702) to get rid of obsolete methods. You can use the Security namespace to check this: ``` public void ExportToFile(string filename) { var permissionSet = new PermissionSet(PermissionState.None); var writePermissio...
130,618
<p>I would like to find out if a particular python datetime object is older than X hours or minutes. I am trying to do something similar to: </p> <pre><code>if (datetime.now() - self.timestamp) &gt; 100 # Where 100 is either seconds or minutes </code></pre> <p>This generates a type error. </p> <p>What is the proper...
[ { "answer_id": 130623, "author": "William Keller", "author_id": 17095, "author_profile": "https://Stackoverflow.com/users/17095", "pm_score": 0, "selected": false, "text": "<p>You can subtract two <a href=\"http://docs.python.org/lib/module-datetime.html\" rel=\"nofollow noreferrer\">dat...
2008/09/24
[ "https://Stackoverflow.com/questions/130618", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20794/" ]
I would like to find out if a particular python datetime object is older than X hours or minutes. I am trying to do something similar to: ``` if (datetime.now() - self.timestamp) > 100 # Where 100 is either seconds or minutes ``` This generates a type error. What is the proper way to do date time comparison in py...
Use the `datetime.timedelta` class: ``` >>> from datetime import datetime, timedelta >>> then = datetime.now() - timedelta(hours = 2) >>> now = datetime.now() >>> (now - then) > timedelta(days = 1) False >>> (now - then) > timedelta(hours = 1) True ``` Your example could be written as: ``` if (datetime.now() - self...
130,636
<p>When I try to compile the newest version of Clisp on Ubuntu 8.04 I always get this error after running configure:</p> <pre><code>Configure findings: FFI: no (user requested: default) readline: yes (user requested: yes) libsigsegv: no, consider installing GNU libsigsegv ./configure: libsigsegv was not detec...
[ { "answer_id": 130655, "author": "PiedPiper", "author_id": 19315, "author_profile": "https://Stackoverflow.com/users/19315", "pm_score": 1, "selected": false, "text": "<p>If you look at 'config.log' it might tell you why configure is not finding libsigsegv</p>\n" }, { "answer_id"...
2008/09/24
[ "https://Stackoverflow.com/questions/130636", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19922/" ]
When I try to compile the newest version of Clisp on Ubuntu 8.04 I always get this error after running configure: ``` Configure findings: FFI: no (user requested: default) readline: yes (user requested: yes) libsigsegv: no, consider installing GNU libsigsegv ./configure: libsigsegv was not detected, thus some...
Here are my notes from compiling CLISP on Ubuntu in the past, hope this helps: ``` sudo apt-get install libsigsegv-dev libreadline5-dev # as of 7.10, Ubuntu's libffcall1-dev is broken and I had to get it from CVS # and make sure CLISP didn't use Ubuntu's version. sudo apt-get remove libffcall1-dev libffcall1 cvs -z3 ...
130,640
<p>I would like to be able to say things like</p> <p><strong>cd [.fred]</strong> and have my default directory go there, and my prompt change to indicate the full path to my current location.</p>
[ { "answer_id": 131235, "author": "Ferruccio", "author_id": 4086, "author_profile": "https://Stackoverflow.com/users/4086", "pm_score": 2, "selected": false, "text": "<p>My DCL is <em>really</em> rusty, but can't you create an alias for SET DEFAULT named CD?</p>\n" }, { "answer_id...
2008/09/24
[ "https://Stackoverflow.com/questions/130640", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7734/" ]
I would like to be able to say things like **cd [.fred]** and have my default directory go there, and my prompt change to indicate the full path to my current location.
Here's my setup: You need 2 files (typed below) : godir.com and prompt.com in your sys$login You may define a symbole ``` CD == "@sys$login:godir.com" ``` But I suggest you to use something else... (ie SD == "@sys$login:godir.com") I modify the help text. It was in french... You will have to retype the escape ca...
130,698
<p>I want to wrap a <a href="https://en.wikipedia.org/wiki/One-liner_program#Perl" rel="nofollow noreferrer">Perl one-liner</a> in a batch file. For a (trivial) example, in a Unix shell, I could quote up a command like this:</p> <pre><code>perl -e 'print localtime() . "\n"' </code></pre> <p>But DOS chokes on that wit...
[ { "answer_id": 130726, "author": "brian d foy", "author_id": 2766176, "author_profile": "https://Stackoverflow.com/users/2766176", "pm_score": 5, "selected": true, "text": "<p>For Perl stuff on Windows, I try to use the generalized quoting as much as possible so I don't get leaning tooth...
2008/09/24
[ "https://Stackoverflow.com/questions/130698", "https://Stackoverflow.com", "https://Stackoverflow.com/users/21938/" ]
I want to wrap a [Perl one-liner](https://en.wikipedia.org/wiki/One-liner_program#Perl) in a batch file. For a (trivial) example, in a Unix shell, I could quote up a command like this: ``` perl -e 'print localtime() . "\n"' ``` But DOS chokes on that with this helpful error message: > > Can't find string terminato...
For Perl stuff on Windows, I try to use the generalized quoting as much as possible so I don't get leaning toothpick syndrome. I save the quotes for the stuff that DOS needs: ``` perl -e "print scalar localtime() . qq(\n)" ``` If you just need a newline at the end of the print, you can let the `-l` switch do that fo...
130,720
<p>In certain cases, I can't seem to get components to receive events.</p> <p>[edit] </p> <p>To clarify, the example code is just for demonstration sake, what I was really asking was if there was a central location that a listener could be added, to which one can reliably dispatch events to and from arbitrary objects...
[ { "answer_id": 131046, "author": "Antti", "author_id": 6037, "author_profile": "https://Stackoverflow.com/users/6037", "pm_score": 0, "selected": false, "text": "<p>You are attaching the listener to <code>this</code> when the event is getting dispatched from <code>btnMenu</code>.</p>\n\n...
2008/09/25
[ "https://Stackoverflow.com/questions/130720", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16258/" ]
In certain cases, I can't seem to get components to receive events. [edit] To clarify, the example code is just for demonstration sake, what I was really asking was if there was a central location that a listener could be added, to which one can reliably dispatch events to and from arbitrary objects. I ended up usi...
Above is correct. You are dispatching the event from btnMenu, but you are not listening for events on btnMenu - you are listening for events on the Application. Either dispatch from Application: ``` dispatchEvent(new Event("stepchild", true)); ``` or listen on the btnMenu ``` btnMenu.addEventListener("stepchild",h...
130,730
<p>I have an immutable class with some private fields that are set during the constructor execution. I want to unit test this constructor but I'm not sure the "best practice" in this case.</p> <p><strong>Simple Example</strong></p> <p>This class is defined in Assembly1:</p> <pre><code>public class Class2Test { ...
[ { "answer_id": 130732, "author": "Eric Schoonover", "author_id": 3957, "author_profile": "https://Stackoverflow.com/users/3957", "pm_score": 1, "selected": false, "text": "<p>I have properly enabled <code>[InternalsVisibleTo]</code> on Assembly1 (code) so that there is a trust relationsh...
2008/09/25
[ "https://Stackoverflow.com/questions/130730", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3957/" ]
I have an immutable class with some private fields that are set during the constructor execution. I want to unit test this constructor but I'm not sure the "best practice" in this case. **Simple Example** This class is defined in Assembly1: ``` public class Class2Test { private readonly string _StringProperty; ...
Nothing, unless you are using that field. You don't want over-specification via tests. In other words, there is no need to test that the assignment operator works. If you are using that field in a method or something, call that method and assert on that. Edit: > > assume the constructor has some more complex logic...
130,734
<p>It's been a while since I've had to do any HTML-like code in <code>Vim</code>, but recently I came across this again. Say I'm writing some simple <code>HTML</code>:</p> <pre><code>&lt;html&gt;&lt;head&gt;&lt;title&gt;This is a title&lt;/title&gt;&lt;/head&gt;&lt;/html&gt; </code></pre> <p>How do I write those clos...
[ { "answer_id": 130741, "author": "Ian P", "author_id": 10853, "author_profile": "https://Stackoverflow.com/users/10853", "pm_score": 6, "selected": true, "text": "<p>Check this out..</p>\n\n<p>closetag.vim </p>\n\n<pre><code>Functions and mappings to close open HTML/XML tags\n</code></pr...
2008/09/25
[ "https://Stackoverflow.com/questions/130734", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10098/" ]
It's been a while since I've had to do any HTML-like code in `Vim`, but recently I came across this again. Say I'm writing some simple `HTML`: ``` <html><head><title>This is a title</title></head></html> ``` How do I write those closing tags for title, head and html down quickly? I feel like I'm missing some really ...
Check this out.. closetag.vim ``` Functions and mappings to close open HTML/XML tags ``` <https://www.vim.org/scripts/script.php?script_id=13> I use something similar.
130,740
<p>I have the following program:</p> <pre><code>~/test&gt; cat test.cc int main() { int i = 3; int j = __sync_add_and_fetch(&amp;i, 1); return 0; } </code></pre> <p>I'm compiling this program using GCC 4.2.2 on Linux running on a multi-cpu 64-bit Intel machine:</p> <pre><code>~/test&gt; uname --all Linux doom ...
[ { "answer_id": 130754, "author": "Dan Udey", "author_id": 21450, "author_profile": "https://Stackoverflow.com/users/21450", "pm_score": 5, "selected": true, "text": "<p>From the <a href=\"http://gcc.gnu.org/onlinedocs/gcc-4.1.0/gcc/Atomic-Builtins.html#Atomic-Builtins\" rel=\"noreferrer\...
2008/09/25
[ "https://Stackoverflow.com/questions/130740", "https://Stackoverflow.com", "https://Stackoverflow.com/users/21435/" ]
I have the following program: ``` ~/test> cat test.cc int main() { int i = 3; int j = __sync_add_and_fetch(&i, 1); return 0; } ``` I'm compiling this program using GCC 4.2.2 on Linux running on a multi-cpu 64-bit Intel machine: ``` ~/test> uname --all Linux doom 2.6.9-67.ELsmp #1 SMP Wed Nov 7 13:56:44 EST 20...
From the [GCC page on Atomic Builtins](http://gcc.gnu.org/onlinedocs/gcc-4.1.0/gcc/Atomic-Builtins.html#Atomic-Builtins): > > Not all operations are supported by > all target processors. If a particular > operation cannot be implemented on the > target processor, a warning will be > generated and a call an extern...
130,748
<p>I've got a form where I have two radio buttons and two interchangeable controls (made up of a ListView and a handful of buttons). Based on which radio button is selected I want to display the proper control to the user.</p> <p>The way I'm doing this now is just loading both controls and setting up an OnRadioButtonS...
[ { "answer_id": 130805, "author": "Lloyd Cotten", "author_id": 21807, "author_profile": "https://Stackoverflow.com/users/21807", "pm_score": 3, "selected": true, "text": "<p>Yep, that's pretty much how I do it. I would set the CheckedChanged event of both radio buttons to point at a sing...
2008/09/25
[ "https://Stackoverflow.com/questions/130748", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1512/" ]
I've got a form where I have two radio buttons and two interchangeable controls (made up of a ListView and a handful of buttons). Based on which radio button is selected I want to display the proper control to the user. The way I'm doing this now is just loading both controls and setting up an OnRadioButtonSelectionCh...
Yep, that's pretty much how I do it. I would set the CheckedChanged event of both radio buttons to point at a single event handler and would place the following code to swap out the visible control. ``` private void OnRadioButtonCheckedChanged(object sender, EventArgs e) { Control1.Visible = RadioButton1.Checked; ...
130,763
<p>I want my Python script to copy files on Vista. When I run it from a normal <code>cmd.exe</code> window, no errors are generated, yet the files are NOT copied. If I run <code>cmd.exe</code> "as administator" and then run my script, it works fine.</p> <p>This makes sense since User Account Control (UAC) normally pre...
[ { "answer_id": 131092, "author": "dguaraglia", "author_id": 2384, "author_profile": "https://Stackoverflow.com/users/2384", "pm_score": 5, "selected": false, "text": "<p>It seems there's no way to elevate the application privileges for a while for you to perform a particular task. Window...
2008/09/25
[ "https://Stackoverflow.com/questions/130763", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10559/" ]
I want my Python script to copy files on Vista. When I run it from a normal `cmd.exe` window, no errors are generated, yet the files are NOT copied. If I run `cmd.exe` "as administator" and then run my script, it works fine. This makes sense since User Account Control (UAC) normally prevents many file system actions. ...
As of 2017, an easy method to achieve this is the following: ``` import ctypes, sys def is_admin(): try: return ctypes.windll.shell32.IsUserAnAdmin() except: return False if is_admin(): # Code of your program here else: # Re-run the program with admin rights ctypes.windll.shell32....
130,775
<p>As far as variable naming conventions go, should iterators be named <code>i</code> or something more semantic like <code>count</code>? If you don't use <code>i</code>, why not? If you feel that <code>i</code> is acceptable, are there cases of iteration where it shouldn't be used?</p>
[ { "answer_id": 130782, "author": "Matthew Rapati", "author_id": 15000, "author_profile": "https://Stackoverflow.com/users/15000", "pm_score": 0, "selected": false, "text": "<p>It helps if you name it something that describes what it is looping through. But I usually just use i.</p>\n" ...
2008/09/25
[ "https://Stackoverflow.com/questions/130775", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13281/" ]
As far as variable naming conventions go, should iterators be named `i` or something more semantic like `count`? If you don't use `i`, why not? If you feel that `i` is acceptable, are there cases of iteration where it shouldn't be used?
Depends on the context I suppose. If you where looping through a set of Objects in some collection then it should be fairly obvious from the context what you are doing. ``` for(int i = 0; i < 10; i++) { // i is well known here to be the index objectCollection[i].SomeProperty = someValue; } ``` However if it...
130,789
<p>I heard that decision tables in relational database have been researched a lot in academia. I also know that business rules engines use decision tables and that many BPMS use them as well. I was wondering if people today use decision tables within their relational databases?</p>
[ { "answer_id": 130910, "author": "Dana the Sane", "author_id": 2567, "author_profile": "https://Stackoverflow.com/users/2567", "pm_score": -1, "selected": false, "text": "<p>I would look into using an Object database rather than a traditional RDBMS (Relational Database Management System)...
2008/09/25
[ "https://Stackoverflow.com/questions/130789", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19272/" ]
I heard that decision tables in relational database have been researched a lot in academia. I also know that business rules engines use decision tables and that many BPMS use them as well. I was wondering if people today use decision tables within their relational databases?
A decision table is a cluster of conditions and actions. A condition can be simple enough that you can represent it with a simple "match a column against this value" string. Or a condition could be hellishly complex. An action, similarly, could be as simple as "move this value to a column". Or the action could involve ...
130,790
<p>I have some C# code in an ASP.Net application that does this:</p> <p>Bitmap bmp = new Bitmap(1184, 1900);</p> <p>And occasionally it throws an exception "Parameter is not valid". Now i've been googling around and apparently GDI+ is infamous for throwing random exceptions, and lots of people have had this problem, ...
[ { "answer_id": 130891, "author": "Lou Franco", "author_id": 3937, "author_profile": "https://Stackoverflow.com/users/3937", "pm_score": 1, "selected": false, "text": "<p>You not only need enough memory, it needs to be contiguous. Over time memory becomes fragmented and it becomes harder...
2008/09/25
[ "https://Stackoverflow.com/questions/130790", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I have some C# code in an ASP.Net application that does this: Bitmap bmp = new Bitmap(1184, 1900); And occasionally it throws an exception "Parameter is not valid". Now i've been googling around and apparently GDI+ is infamous for throwing random exceptions, and lots of people have had this problem, but nobody has a ...
Stop using GDI+ and start using the WPF Imaging classes (.NET 3.0). These are a major cleanup of the GDI+ classes and tuned for performance. Additionally, it sets up a "bitmap chain" that allows you to easily perform multiple actions on the bitmap in an efficient manner. Find more by reading about [BitmapSource](http:...
130,794
<p>There have been several questions already posted with specific questions about <a href="http://en.wikipedia.org/wiki/Dependency_injection" rel="noreferrer">dependency injection</a>, such as when to use it and what frameworks are there for it. However,</p> <p><strong>What is dependency injection and when/why should ...
[ { "answer_id": 130862, "author": "wds", "author_id": 10098, "author_profile": "https://Stackoverflow.com/users/10098", "pm_score": 12, "selected": true, "text": "<p><strong>Dependency Injection</strong> is passing dependency to other <strong>objects</strong> or <strong>framework</strong>...
2008/09/25
[ "https://Stackoverflow.com/questions/130794", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1354/" ]
There have been several questions already posted with specific questions about [dependency injection](http://en.wikipedia.org/wiki/Dependency_injection), such as when to use it and what frameworks are there for it. However, **What is dependency injection and when/why should or shouldn't it be used?**
**Dependency Injection** is passing dependency to other **objects** or **framework**( dependency injector). Dependency injection makes testing easier. The injection can be done through **constructor**. `SomeClass()` has its constructor as following: ```csh public SomeClass() { myObject = Factory.getObject(); } ...
130,801
<p>I'm using GNU autotools for the build system on a particular project. I want to start writing automated tests for verifcation. I would like to just type "make check" to have it automatically run these. My project is in C++, although I am still curious about writing automated tests for other languages as well.</p> <...
[ { "answer_id": 131256, "author": "Kyle Burton", "author_id": 19784, "author_profile": "https://Stackoverflow.com/users/19784", "pm_score": 3, "selected": false, "text": "<p>You seem to be asking 2 questions in the first paragraph.</p>\n\n<p>The first is about adding tests to the GNU auto...
2008/09/25
[ "https://Stackoverflow.com/questions/130801", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5963/" ]
I'm using GNU autotools for the build system on a particular project. I want to start writing automated tests for verifcation. I would like to just type "make check" to have it automatically run these. My project is in C++, although I am still curious about writing automated tests for other languages as well. *Is this...
To make test run when you issue `make check`, you need to add them to the `TESTS` variable Assuming you've already built the executable that runs the unit tests, you just add the name of the executable to the TESTS variable like this: ``` TESTS=my-test-executable ``` It should then be automatically run when you `ma...
130,829
<p>I have 3 points in a 3D space of which I know the exact locations. Suppose they are: <code>(x0,y0,z0)</code>, <code>(x1,y1,z1)</code> and <code>(x2,y2,z2)</code>.</p> <p>Also I have a camera that is looking at these 3 points and I know the 2D locations of those three points on camera view plane. So for example <cod...
[ { "answer_id": 130909, "author": "tye", "author_id": 21496, "author_profile": "https://Stackoverflow.com/users/21496", "pm_score": 5, "selected": true, "text": "<p>This gives you two sets, each of three equations in 3 variables:</p>\n\n<pre><code>a*x0+b*y0+c*z0 = x0'\na*x1+b*y1+c*z1 = x1...
2008/09/25
[ "https://Stackoverflow.com/questions/130829", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I have 3 points in a 3D space of which I know the exact locations. Suppose they are: `(x0,y0,z0)`, `(x1,y1,z1)` and `(x2,y2,z2)`. Also I have a camera that is looking at these 3 points and I know the 2D locations of those three points on camera view plane. So for example `(x0,y0,z0)` will be `(x0',y0')`, and `(x1,y1,z...
This gives you two sets, each of three equations in 3 variables: ``` a*x0+b*y0+c*z0 = x0' a*x1+b*y1+c*z1 = x1' a*x2+b*y2+c*z2 = x2' d*x0+e*y0+f*z0 = y0' d*x1+e*y1+f*z1 = y1' d*x2+e*y2+f*z2 = y2' ``` Just use whatever method of solving simultaneous equations is easiest in your situation (it isn't even hard to solve ...
130,837
<p>I'm still learning RegEx at the moment, but for the time being could someone help me out with this? I have a few special requirements for formatting the string:</p> <ol> <li>No directories. JUST the file name.</li> <li>File name needs to be all lowercase.</li> <li>Whitespaces need to be replaced with underscores....
[ { "answer_id": 130845, "author": "Grank", "author_id": 12975, "author_profile": "https://Stackoverflow.com/users/12975", "pm_score": 2, "selected": false, "text": "<p>If you're in a super-quick hurry, you can usually find acceptable regular expressions in the library at <a href=\"http://...
2008/09/25
[ "https://Stackoverflow.com/questions/130837", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19825/" ]
I'm still learning RegEx at the moment, but for the time being could someone help me out with this? I have a few special requirements for formatting the string: 1. No directories. JUST the file name. 2. File name needs to be all lowercase. 3. Whitespaces need to be replaced with underscores. Shouldn't be hard, but I'...
And a simple combination of RegExp and other javascript is what I would recommend: ``` var a = "c:\\some\\path\\to\\a\\file\\with Whitespace.TXT"; a = a.replace(/^.*[\\\/]([^\\\/]*)$/i,"$1"); a = a.replace(/\s/g,"_"); a = a.toLowerCase(); alert(a); ```
130,843
<p>Using Prototype 1.6's "new Element(...)" I am trying to create a &lt;table&gt; element with both a &lt;thead&gt; and &lt;tbody&gt; but nothing happens in IE6.</p> <pre><code>var tableProto = new Element('table').update('&lt;thead&gt;&lt;tr&gt;&lt;th&gt;Situation Task&lt;/th&gt;&lt;th&gt;Action&lt;/th&gt;&lt;th&gt;R...
[ { "answer_id": 130884, "author": "scunliffe", "author_id": 6144, "author_profile": "https://Stackoverflow.com/users/6144", "pm_score": 2, "selected": false, "text": "<p>If prototypes' .update() method internally tries to set the .innerHTML it will fail in IE. In IE, <strong>the .innerHT...
2008/09/25
[ "https://Stackoverflow.com/questions/130843", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18265/" ]
Using Prototype 1.6's "new Element(...)" I am trying to create a <table> element with both a <thead> and <tbody> but nothing happens in IE6. ``` var tableProto = new Element('table').update('<thead><tr><th>Situation Task</th><th>Action</th><th>Result</th></tr></thead><tbody><tr><td>a</td><td>b</td><td>c</td></tr></tbo...
As it turns out, there's nothing wrong with the example code I provided in the question--it works in IE6 just fine. The issue I was facing is that I was also specifying a class for the <table> element in the constructor incorrectly, but omitted that from my example. The "real" code was as follows, and is incorrect: `...
130,877
<p>What function will let us know whether a date in VBA is in DST or not?</p>
[ { "answer_id": 130879, "author": "Lance Roberts", "author_id": 13295, "author_profile": "https://Stackoverflow.com/users/13295", "pm_score": 4, "selected": true, "text": "<p><b>For non-current dates (DST 2007+):</b></p>\n\n<p>First, you need a function to find the number of specific week...
2008/09/25
[ "https://Stackoverflow.com/questions/130877", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13295/" ]
What function will let us know whether a date in VBA is in DST or not?
**For non-current dates (DST 2007+):** First, you need a function to find the number of specific weekdays in a month: ``` Public Function NDow(Y As Integer, M As Integer, _ N As Integer, DOW As Integer) As Date ' Returns Date of Nth Day of the Week in Month NDow = DateSerial(Y, M, (8 - Weekday(D...
130,878
<p>What is the benefit of using singleton instead of global for database connections in PHP? I feel using singleton instead of global makes the code unnecessarily complex.</p> <h2>Code with Global</h2> <pre><code>$conn = new PDO(...); function getSomething() { global $conn; . . . } </code></pre> <h2...
[ { "answer_id": 130889, "author": "1800 INFORMATION", "author_id": 3146, "author_profile": "https://Stackoverflow.com/users/3146", "pm_score": 0, "selected": false, "text": "<p>It is quite simple. Never use global OR Singleton.</p>\n" }, { "answer_id": 130900, "author": "Gavin...
2008/09/25
[ "https://Stackoverflow.com/questions/130878", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1897/" ]
What is the benefit of using singleton instead of global for database connections in PHP? I feel using singleton instead of global makes the code unnecessarily complex. Code with Global ---------------- ``` $conn = new PDO(...); function getSomething() { global $conn; . . . } ``` Code with Singleto...
I know this is old, but Dr8k's answer was *almost* there. When you are considering writing a piece of code, assume it's going to change. That doesn't mean that you're assuming the kinds of changes it will have hoisted upon it at some point in the future, but rather that some form of change will be made. Make it a goa...
130,894
<p>I have the source of a program (taken from cvs/svn/git/...) and I'd like to build a Debian/Ubuntu package for it. The package is present in the repositories, but:</p> <ul> <li>It is an older version (lacking features I need)</li> <li>I need slightly different compile options than the default.</li> </ul> <p>What is...
[ { "answer_id": 130908, "author": "Bernard", "author_id": 61, "author_profile": "https://Stackoverflow.com/users/61", "pm_score": 2, "selected": false, "text": "<p>I believe <a href=\"http://www.debian.org/doc/maint-guide/\" rel=\"nofollow noreferrer\">this</a> is the Debian package 'bibl...
2008/09/25
[ "https://Stackoverflow.com/questions/130894", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19922/" ]
I have the source of a program (taken from cvs/svn/git/...) and I'd like to build a Debian/Ubuntu package for it. The package is present in the repositories, but: * It is an older version (lacking features I need) * I need slightly different compile options than the default. What is the easiest way of doing it? I am ...
you can use the special package "checkinstall" for all packages which are not even in debian/ubuntu yet. You can use "uupdate" (`apt-get install devscripts`) to build a package from source with existing debian sources: Example for libdrm2: ``` apt-get build-dep libdrm2 apt-get source libdrm2 cd libdrm-2.3.1 uupdate ...
130,898
<p>How can I perform list comprehensions in C#?</p>
[ { "answer_id": 130915, "author": "Ian P", "author_id": 10853, "author_profile": "https://Stackoverflow.com/users/10853", "pm_score": -1, "selected": false, "text": "<p>While this isn't a tutorial, here's some code that illustrates the concept:</p>\n\n<pre><code>public List&lt;string&gt; ...
2008/09/25
[ "https://Stackoverflow.com/questions/130898", "https://Stackoverflow.com", "https://Stackoverflow.com/users/21944/" ]
How can I perform list comprehensions in C#?
Found this when I was looking up how to do list comprehensions in C#... When someone says list comprehensions I immediately think about Python. The below code generates a list that looks like this: ``` [0,2,4,6,8,10,12,14,16,18] ``` The Python way is like this: ``` list = [2*number for number in range(0,10)] ``` ...
130,913
<p>Is it at the state where it is actually useful and can do more than rename classes?</p>
[ { "answer_id": 130926, "author": "Benoit", "author_id": 10703, "author_profile": "https://Stackoverflow.com/users/10703", "pm_score": 6, "selected": true, "text": "<p>CDT (C/C++ Development Tools - eclipse project) 5.0 has a bunch of new refactorings</p>\n\n<pre><code>* Declare Method\n*...
2008/09/25
[ "https://Stackoverflow.com/questions/130913", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13760/" ]
Is it at the state where it is actually useful and can do more than rename classes?
CDT (C/C++ Development Tools - eclipse project) 5.0 has a bunch of new refactorings ``` * Declare Method * Extract Baseclass * Extract Constant * Extract Method * Extract Subclass * Hide Method * Implement Method * Move Field / Method * Replace Number * Separate Class * Generate Getters and Setters ``` There is a CD...
130,916
<p>I need to keep as much as I can of large file in the operating system block cache even though it's bigger than I can fit in ram, and I'm continously reading another very very large file. ATM I'll remove large chunk of large important file from system cache when I stream read form another file.</p>
[ { "answer_id": 130955, "author": "William Hutchen", "author_id": 21944, "author_profile": "https://Stackoverflow.com/users/21944", "pm_score": 1, "selected": false, "text": "<p>Some operating systems have ramdisks that you can use to set aside a segment of ram for storage and then mounti...
2008/09/25
[ "https://Stackoverflow.com/questions/130916", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15307/" ]
I need to keep as much as I can of large file in the operating system block cache even though it's bigger than I can fit in ram, and I'm continously reading another very very large file. ATM I'll remove large chunk of large important file from system cache when I stream read form another file.
In a POSIX system like Linux or Solaris, try using posix\_fadvise. On the streaming file, do something like this: ``` posix_fadvise(fd, 0, 0, POSIX_FADV_SEQUENTIAL); while( bytes > 0 ) { bytes = pread(fd, buffer, 64 * 1024, current_pos); current_pos += 64 * 1024; posix_fadvise(fd, 0, current_pos, POSIX_FADV_DON...
130,941
<p>In a VB.Net Windows Service I'm currently pooling units of work with: </p> <pre><code>ThreadPool.QueueUserWorkItem(operation, nextQueueID) </code></pre> <p>In each unit of work (or thread I'll use for ease of understanding), it will make a couple MSSQL operations like so: </p> <pre><code> Using sqlcmd As N...
[ { "answer_id": 130963, "author": "Kev", "author_id": 419, "author_profile": "https://Stackoverflow.com/users/419", "pm_score": 3, "selected": true, "text": "<p>From the MS Docs -</p>\n\n<p>\"Connections are pooled per process, per application domain, per connection string and when integr...
2008/09/25
[ "https://Stackoverflow.com/questions/130941", "https://Stackoverflow.com", "https://Stackoverflow.com/users/952/" ]
In a VB.Net Windows Service I'm currently pooling units of work with: ``` ThreadPool.QueueUserWorkItem(operation, nextQueueID) ``` In each unit of work (or thread I'll use for ease of understanding), it will make a couple MSSQL operations like so: ``` Using sqlcmd As New SqlCommand("", New SqlConnection(Con...
From the MS Docs - "Connections are pooled per process, per application domain, per connection string and when integrated security is used, per Windows identity" <http://msdn.microsoft.com/en-us/library/8xx3tyca.aspx> Are you experiencing errors such as - *Exception Details: System.InvalidOperationException: Timeou...
130,948
<p>I need an easy way to take a tar file and convert it into a string (and vice versa). Is there a way to do this in Ruby? My best attempt was this:</p> <pre><code>file = File.open("path-to-file.tar.gz") contents = "" file.each {|line| contents &lt;&lt; line } </code></pre> <p>I thought that would be enough to conv...
[ { "answer_id": 130984, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 3, "selected": false, "text": "<p>You can probably encode the tar file in Base64. Base 64 will give you a pure ASCII representation of the file that you can ...
2008/09/25
[ "https://Stackoverflow.com/questions/130948", "https://Stackoverflow.com", "https://Stackoverflow.com/users/422/" ]
I need an easy way to take a tar file and convert it into a string (and vice versa). Is there a way to do this in Ruby? My best attempt was this: ``` file = File.open("path-to-file.tar.gz") contents = "" file.each {|line| contents << line } ``` I thought that would be enough to convert it to a string, but then whe...
First, you should open the file as a binary file. Then you can read the entire file in, in one command. ``` file = File.open("path-to-file.tar.gz", "rb") contents = file.read ``` That will get you the entire file in a string. After that, you probably want to `file.close`. If you don’t do that, `file` won’t be close...
131,014
<p>I have a table that has redundant data and I'm trying to identify all rows that have duplicate sub-rows (for lack of a better word). By sub-rows I mean considering <code>COL1</code> and <code>COL2</code> only. </p> <p>So let's say I have something like this:</p> <pre><code> COL1 COL2 COL3 --------------------...
[ { "answer_id": 131018, "author": "Jerub", "author_id": 14648, "author_profile": "https://Stackoverflow.com/users/14648", "pm_score": 2, "selected": false, "text": "<p>Join on yourself like this:</p>\n\n<pre><code>SELECT a.col3, b.col3, a.col1, a.col2 \nFROM tablename a, tablename b\nWHER...
2008/09/25
[ "https://Stackoverflow.com/questions/131014", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10708/" ]
I have a table that has redundant data and I'm trying to identify all rows that have duplicate sub-rows (for lack of a better word). By sub-rows I mean considering `COL1` and `COL2` only. So let's say I have something like this: ``` COL1 COL2 COL3 --------------------- aa 111 blah_x aa 111 blah...
Does this work for you? ``` select t.* from table t left join ( select col1, col2, count(*) as count from table group by col1, col2 ) c on t.col1=c.col1 and t.col2=c.col2 where c.count > 1 ```
131,021
<p>I have a backroundrb scheduled task that takes quite a long time to run. However it seems that the process is ending after only 2.5 minutes.</p> <p>My background.yml file:</p> <pre><code>:schedules: :named_worker: :task_name: :trigger_args: 0 0 12 * * * * :data: input_data </code></pre> <p>I hav...
[ { "answer_id": 131779, "author": "Andrew", "author_id": 17408, "author_profile": "https://Stackoverflow.com/users/17408", "pm_score": 3, "selected": true, "text": "<p>There's not much information here that allows us to get to the bottom of the problem.\nBecause backgroundrb operates in t...
2008/09/25
[ "https://Stackoverflow.com/questions/131021", "https://Stackoverflow.com", "https://Stackoverflow.com/users/757/" ]
I have a backroundrb scheduled task that takes quite a long time to run. However it seems that the process is ending after only 2.5 minutes. My background.yml file: ``` :schedules: :named_worker: :task_name: :trigger_args: 0 0 12 * * * * :data: input_data ``` I have zero activity on the server whe...
There's not much information here that allows us to get to the bottom of the problem. Because backgroundrb operates in the background, it can be quite hard to monitor/debug. Here are some ideas I use: 1. Write a unit test to test the worker code itself and make sure there are no problems there 2. Put "puts" statement...
131,040
<p>I am creating a component and want to expose a color property as many flex controls do, lets say I have simple component like this, lets call it foo_label:</p> <pre> <code> &lt;mx:Canvas> &lt;mx:Script> [Bindable] public var color:uint; &lt;/mx:Script> &lt;mx:Label text="foobar" color="{color}" ...
[ { "answer_id": 132076, "author": "Borek Bernard", "author_id": 21728, "author_profile": "https://Stackoverflow.com/users/21728", "pm_score": 4, "selected": true, "text": "<p>Color is not a property, it is a style. You need to define the style like this:</p>\n\n<pre><code>[Style(name=\"la...
2008/09/25
[ "https://Stackoverflow.com/questions/131040", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1638/" ]
I am creating a component and want to expose a color property as many flex controls do, lets say I have simple component like this, lets call it foo\_label: ``` <mx:Canvas> <mx:Script> [Bindable] public var color:uint; </mx:Script> <mx:Label text="foobar" color="{color}" /> </mx:Canvas> ``` and ...
Color is not a property, it is a style. You need to define the style like this: ``` [Style(name="labelColor", type="uint", format="Color" )] ``` (enclose it in tag if you define it directly in MXML). You then need to add some ActionScript to handle this style and apply it to whichever control you need, please refer ...
131,049
<p>I installed mediawiki on my server as my personal knowledge base. Sometimes I copy some stuff from Web and paste to my wiki - such as tips &amp; tricks from somebody's blog. How do I make the copied content appear in a box with border?</p> <p>For example, the box at the end of this blog post looks pretty nice:<br> ...
[ { "answer_id": 131330, "author": "Steve K", "author_id": 739, "author_profile": "https://Stackoverflow.com/users/739", "pm_score": 2, "selected": false, "text": "<p>Mediawiki supports the div tag. Combine the div tag with some styles:</p>\n\n<pre><code>&lt;div style=\"background-color: ...
2008/09/25
[ "https://Stackoverflow.com/questions/131049", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14068/" ]
I installed mediawiki on my server as my personal knowledge base. Sometimes I copy some stuff from Web and paste to my wiki - such as tips & tricks from somebody's blog. How do I make the copied content appear in a box with border? For example, the box at the end of this blog post looks pretty nice: <http://blog.dr...
``` <blockquote style="background-color: lightgrey; border: solid thin grey;"> Det er jeg som kjenner hemmeligheten din. Ikke et pip, gutten min. </blockquote> ``` The blockquotes are better than divs because they "explain" that the text is actually a blockqoute, and not "just-some-text". Also a blockquote will most ...
131,050
<p>Since AS3 does not allow private constructors, it seems the only way to construct a singleton and guarantee the constructor isn't explicitly created via "new" is to pass a single parameter and check it.</p> <p>I've heard two recommendations, one is to check the caller and ensure it's the static getInstance(), and t...
[ { "answer_id": 131294, "author": "Adam Ness", "author_id": 21973, "author_profile": "https://Stackoverflow.com/users/21973", "pm_score": 0, "selected": false, "text": "<p>The pattern which is used by Cairngorm (which may not be the best) is to throw a runtime exception in the constructor...
2008/09/25
[ "https://Stackoverflow.com/questions/131050", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14747/" ]
Since AS3 does not allow private constructors, it seems the only way to construct a singleton and guarantee the constructor isn't explicitly created via "new" is to pass a single parameter and check it. I've heard two recommendations, one is to check the caller and ensure it's the static getInstance(), and the other i...
A slight adaptation of enobrev's answer is to have instance as a getter. Some would say this is more elegant. Also, enobrev's answer won't enforce a Singleton if you call the constructor before calling getInstance. This may not be perfect, but I have tested this and it works. (There is definitely another good way to do...
131,053
<p>I have been getting an error in <strong>VB .Net</strong> </p> <blockquote> <p>object reference not set to an instance of object.</p> </blockquote> <p>Can you tell me what are the causes of this error ?</p>
[ { "answer_id": 131055, "author": "Nescio", "author_id": 14484, "author_profile": "https://Stackoverflow.com/users/14484", "pm_score": 3, "selected": false, "text": "<p>The object has not been initialized before use.</p>\n\n<p>At the top of your code file type:</p>\n\n<pre><code>Option St...
2008/09/25
[ "https://Stackoverflow.com/questions/131053", "https://Stackoverflow.com", "https://Stackoverflow.com/users/21963/" ]
I have been getting an error in **VB .Net** > > object reference not set to an instance of object. > > > Can you tell me what are the causes of this error ?
sef, If the problem is with Database return results, I presume it is in this scenario: ``` dsData = getSQLData(conn,sql, blah,blah....) dt = dsData.Tables(0) 'Perhaps the obj ref not set is occurring here ``` To fix that: ``` dsData = getSQLData(conn,sql, blah,blah....) If dsData.Tables.Count = 0 Then E...
131,056
<p>Not sure how to ask a followup on SO, but this is in reference to an earlier question: <a href="https://stackoverflow.com/questions/94930/fetch-one-row-per-account-id-from-list">Fetch one row per account id from list</a></p> <p>The query I'm working with is:</p> <pre><code>SELECT * FROM scores s1 WHERE accountid N...
[ { "answer_id": 131060, "author": "Josh", "author_id": 11702, "author_profile": "https://Stackoverflow.com/users/11702", "pm_score": 0, "selected": false, "text": "<p>If you are selecting a subset of columns then you can use the DISTINCT keyword to filter results.</p>\n\n<pre><code>SELECT...
2008/09/25
[ "https://Stackoverflow.com/questions/131056", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13636/" ]
Not sure how to ask a followup on SO, but this is in reference to an earlier question: [Fetch one row per account id from list](https://stackoverflow.com/questions/94930/fetch-one-row-per-account-id-from-list) The query I'm working with is: ``` SELECT * FROM scores s1 WHERE accountid NOT IN (SELECT accountid FROM sco...
If you're only interested in the accountid and the score, then you can use the simple GROUP BY query given by Paul above. ``` SELECT accountid, MAX(score) FROM scores GROUP BY accountid; ``` If you need other attributes from the scores table, then you can get other attributes from the row with a query like the fol...
131,062
<p>I've read numerous posts about people having problems with <code>viewWillAppear</code> when you do not create your view hierarchy <em>just</em> right. My problem is I can't figure out what that means.</p> <p>If I create a <code>RootViewController</code> and call <code>addSubView</code> on that controller, I would e...
[ { "answer_id": 135418, "author": "Josh Gagnon", "author_id": 7944, "author_profile": "https://Stackoverflow.com/users/7944", "pm_score": 3, "selected": false, "text": "<p>I've been using a navigation controller. When I want to either descend to another level of data or show my custom vie...
2008/09/25
[ "https://Stackoverflow.com/questions/131062", "https://Stackoverflow.com", "https://Stackoverflow.com/users/21964/" ]
I've read numerous posts about people having problems with `viewWillAppear` when you do not create your view hierarchy *just* right. My problem is I can't figure out what that means. If I create a `RootViewController` and call `addSubView` on that controller, I would expect the added view(s) to be wired up for `viewWi...
If you use a navigation controller and set its delegate, then the view{Will,Did}{Appear,Disappear} methods are not invoked. You need to use the navigation controller delegate methods instead: ``` navigationController:willShowViewController:animated: navigationController:didShowViewController:animated: ```
131,116
<p>I'm wondering if updating statistics has helped you before and how did you know to update them?</p>
[ { "answer_id": 131168, "author": "Ben Hoffstein", "author_id": 4482, "author_profile": "https://Stackoverflow.com/users/4482", "pm_score": 3, "selected": true, "text": "<pre><code>exec sp_updatestats\n</code></pre>\n\n<p>Yes, updating statistics can be very helpful if you find that your ...
2008/09/25
[ "https://Stackoverflow.com/questions/131116", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12261/" ]
I'm wondering if updating statistics has helped you before and how did you know to update them?
``` exec sp_updatestats ``` Yes, updating statistics can be very helpful if you find that your queries are not performing as well as they should. This is evidenced by inspecting the query plan and noticing when, for example, table scans or index scans are being performed instead of index seeks. All of this assumes th...
131,121
<p>If I have a Range object--for example, let's say it refers to cell <code>A1</code> on a worksheet called <code>Book1</code>. So I know that calling <code>Address()</code> will get me a simple local reference: <code>$A$1</code>. I know it can also be called as <code>Address(External:=True)</code> to get a referenc...
[ { "answer_id": 131155, "author": "Ben Hoffstein", "author_id": 4482, "author_profile": "https://Stackoverflow.com/users/4482", "pm_score": 7, "selected": true, "text": "<p>Only way I can think of is to concatenate the worksheet name with the cell reference, as follows:</p>\n\n<pre><code>...
2008/09/25
[ "https://Stackoverflow.com/questions/131121", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6209/" ]
If I have a Range object--for example, let's say it refers to cell `A1` on a worksheet called `Book1`. So I know that calling `Address()` will get me a simple local reference: `$A$1`. I know it can also be called as `Address(External:=True)` to get a reference including the workbook name and worksheet name: `[Book1]She...
Only way I can think of is to concatenate the worksheet name with the cell reference, as follows: ``` Dim cell As Range Dim cellAddress As String Set cell = ThisWorkbook.Worksheets(1).Cells(1, 1) cellAddress = cell.Parent.Name & "!" & cell.Address(External:=False) ``` EDIT: Modify last line to : ``` cellAddress = ...
131,128
<p>Short version: I'm wondering if it's possible, and how best, to utilise CPU specific instructions within a DLL?</p> <p>Slightly longer version: When downloading (32bit) DLLs from, say, Microsoft it seems that one size fits all processors.</p> <p>Does this mean that they are strictly built for the lowest common den...
[ { "answer_id": 131199, "author": "ypnos", "author_id": 21974, "author_profile": "https://Stackoverflow.com/users/21974", "pm_score": 2, "selected": false, "text": "<p>The DLL is expected to work on every computer WIN32 runs on, so you are stuck to the i386 instruction set in general. The...
2008/09/25
[ "https://Stackoverflow.com/questions/131128", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11694/" ]
Short version: I'm wondering if it's possible, and how best, to utilise CPU specific instructions within a DLL? Slightly longer version: When downloading (32bit) DLLs from, say, Microsoft it seems that one size fits all processors. Does this mean that they are strictly built for the lowest common denominator (ie. the...
I don't know of any *standard* technique but if I had to make such a thing, I would write some code in the DllMain() function to detect the CPU type and populate a jump table with function pointers to CPU-optimized versions of each function. There would also need to be a lowest common denominator function for when the...
131,164
<p>I have a number of code value tables that contain a code and a description with a Long id.</p> <p>I now want to create an entry for an Account Type that references a number of codes, so I have something like this:</p> <pre><code>insert into account_type_standard (account_type_Standard_id, tax_status_id, recipient_...
[ { "answer_id": 131183, "author": "oglester", "author_id": 2017, "author_profile": "https://Stackoverflow.com/users/2017", "pm_score": 6, "selected": true, "text": "<p>Outter joins don't work \"as expected\" in that case because you have explicitly told Oracle you only want data if that c...
2008/09/25
[ "https://Stackoverflow.com/questions/131164", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5382/" ]
I have a number of code value tables that contain a code and a description with a Long id. I now want to create an entry for an Account Type that references a number of codes, so I have something like this: ``` insert into account_type_standard (account_type_Standard_id, tax_status_id, recipient_id) ( select account_...
Outter joins don't work "as expected" in that case because you have explicitly told Oracle you only want data if that criteria on that table matches. In that scenario, the outter join is rendered useless. A work-around ``` INSERT INTO account_type_standard (account_type_Standard_id, tax_status_id, recipient_id) V...
131,179
<p>Trying to install the RMagick gem is failing with an error about being unable to find ImageMagick libraries, even though I'm sure they are installed.</p> <p>The pertinent output from gem install rmagick is:</p> <pre><code>checking for InitializeMagick() in -lMagick... no checking for InitializeMagick() in -lMagick...
[ { "answer_id": 131194, "author": "Vinko Vrsalovic", "author_id": 5190, "author_profile": "https://Stackoverflow.com/users/5190", "pm_score": 0, "selected": false, "text": "<p>The linker cannot find libMagick in the standard places. Maybe you installed ImageMagick in a non standard place ...
2008/09/25
[ "https://Stackoverflow.com/questions/131179", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8063/" ]
Trying to install the RMagick gem is failing with an error about being unable to find ImageMagick libraries, even though I'm sure they are installed. The pertinent output from gem install rmagick is: ``` checking for InitializeMagick() in -lMagick... no checking for InitializeMagick() in -lMagickCore... no checking f...
problem solved. RMagick was unable to find ImageMagick because I neglected to build the shared objects (there were no .so files installed as you can see from the "ls" in the original question). The solution was to add `--with-shared` to my configure options. This however caused other problems. Most notably, `make` fa...
131,217
<p>In one of our application im getting an exception that i can not seem to find or trap. </p> <pre><code>... Application.CreateForm(TFrmMain, FrmMain); outputdebugstring(pansichar('Application Run')); //this is printed Application.Run; outputdebugstring(pansichar('Application Run After')); //this is print...
[ { "answer_id": 131233, "author": "Blorgbeard", "author_id": 369, "author_profile": "https://Stackoverflow.com/users/369", "pm_score": 4, "selected": true, "text": "<p>Try installing <a href=\"http://www.madshi.net/\" rel=\"noreferrer\">MadExcept</a> - it should catch the exception and gi...
2008/09/25
[ "https://Stackoverflow.com/questions/131217", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11016/" ]
In one of our application im getting an exception that i can not seem to find or trap. ``` ... Application.CreateForm(TFrmMain, FrmMain); outputdebugstring(pansichar('Application Run')); //this is printed Application.Run; outputdebugstring(pansichar('Application Run After')); //this is printed end. <--- The E...
Try installing [MadExcept](http://www.madshi.net/) - it should catch the exception and give you a stack-trace. It helped me when I had a similar issue.
131,238
<p>In Sharepoint designer's workflow editor I wish to retrieve the username/name of the work flow initiator (i.e. who kicked it off or triggered the workflow) - this is relatively easy to do using 3rd party products such as Nintex Workflow 2007 (where I would use something like {Common:Initiator}) - but I can't seem to...
[ { "answer_id": 131999, "author": "Bryan Friedman", "author_id": 16985, "author_profile": "https://Stackoverflow.com/users/16985", "pm_score": 3, "selected": true, "text": "<p>I don't think this is possible to do in SharePoint Designer out of the box. You could probably write a custom ac...
2008/09/25
[ "https://Stackoverflow.com/questions/131238", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4843/" ]
In Sharepoint designer's workflow editor I wish to retrieve the username/name of the work flow initiator (i.e. who kicked it off or triggered the workflow) - this is relatively easy to do using 3rd party products such as Nintex Workflow 2007 (where I would use something like {Common:Initiator}) - but I can't seem to fi...
I don't think this is possible to do in SharePoint Designer out of the box. You could probably write a custom action to get the originator, but I don't believe it is exposed through the SPD workflow interface at all. The best you could probably do is get the user who created or modified the item in the list, but this...
131,241
<p>Take the following two lines of code:</p> <pre><code>for (int i = 0; i &lt; some_vector.size(); i++) { //do stuff } </code></pre> <p>And this:</p> <pre><code>for (some_iterator = some_vector.begin(); some_iterator != some_vector.end(); some_iterator++) { //do stuff } </code></pre> <p>I'm told that th...
[ { "answer_id": 131253, "author": "cruizer", "author_id": 6441, "author_profile": "https://Stackoverflow.com/users/6441", "pm_score": 6, "selected": false, "text": "<p>because you are not tying your code to the particular implementation of the some_vector list. if you use array indices, i...
2008/09/25
[ "https://Stackoverflow.com/questions/131241", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2147/" ]
Take the following two lines of code: ``` for (int i = 0; i < some_vector.size(); i++) { //do stuff } ``` And this: ``` for (some_iterator = some_vector.begin(); some_iterator != some_vector.end(); some_iterator++) { //do stuff } ``` I'm told that the second way is preferred. Why exactly is this?
The first form is efficient only if vector.size() is a fast operation. This is true for vectors, but not for lists, for example. Also, what are you planning to do within the body of the loop? If you plan on accessing the elements as in ``` T elem = some_vector[i]; ``` then you're making the assumption that the conta...
131,303
<p>How do you measure the memory usage of an application or process in Linux?</p> <p>From the blog article of <em><a href="http://virtualthreads.blogspot.com/2006/02/understanding-memory-usage-on-linux.html" rel="noreferrer">Understanding memory usage on Linux</a></em>, <code>ps</code> is not an accurate tool to use fo...
[ { "answer_id": 131346, "author": "ypnos", "author_id": 21974, "author_profile": "https://Stackoverflow.com/users/21974", "pm_score": 10, "selected": true, "text": "<p>With <code>ps</code> or similar tools you will only get the amount of memory pages allocated by that process. This number...
2008/09/25
[ "https://Stackoverflow.com/questions/131303", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16139/" ]
How do you measure the memory usage of an application or process in Linux? From the blog article of *[Understanding memory usage on Linux](http://virtualthreads.blogspot.com/2006/02/understanding-memory-usage-on-linux.html)*, `ps` is not an accurate tool to use for this intent. > > **Why `ps` is "wrong"** > > > De...
With `ps` or similar tools you will only get the amount of memory pages allocated by that process. This number is correct, but: * does not reflect the actual amount of memory used by the application, only the amount of memory reserved for it * can be misleading if pages are shared, for example by several threads or by...
131,326
<p>I'm looking for resources that can help me determine which approach to use in creating a 2d data structure with C#.</p>
[ { "answer_id": 131339, "author": "aku", "author_id": 1196, "author_profile": "https://Stackoverflow.com/users/1196", "pm_score": 2, "selected": false, "text": "<p>Do you mean multidimensional array? It's simple:</p>\n\n<pre><code>&lt;type&gt;[,] &lt;name&gt; = new &lt;type&gt;[&lt;first ...
2008/09/25
[ "https://Stackoverflow.com/questions/131326", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I'm looking for resources that can help me determine which approach to use in creating a 2d data structure with C#.
Do you mean multidimensional array? It's simple: ``` <type>[,] <name> = new <type>[<first dimenison>,<second dimension>]; ``` Here is MSDN reference: [Multidimensional Arrays (C#)](https://learn.microsoft.com/en-us/dotnet/csharp/programming-guide/arrays/multidimensional-arrays)
131,406
<p>There are several different methods for converting floating point numbers to Integers in JavaScript. My question is what method gives the best performance, is most compatible, or is considered the best practice?</p> <p>Here are a few methods that I know of:</p> <pre><code>var a = 2.5; window.parseInt(a); // 2 Math...
[ { "answer_id": 131413, "author": "Jeff Hubbard", "author_id": 8844, "author_profile": "https://Stackoverflow.com/users/8844", "pm_score": -1, "selected": false, "text": "<p>parseInt() is probably the best one. <code>a | 0</code> doesn't do what you really want (it just assigns 0 if a is ...
2008/09/25
[ "https://Stackoverflow.com/questions/131406", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10942/" ]
There are several different methods for converting floating point numbers to Integers in JavaScript. My question is what method gives the best performance, is most compatible, or is considered the best practice? Here are a few methods that I know of: ``` var a = 2.5; window.parseInt(a); // 2 Math.floor(a); // 2 ...
According to [**this website**](http://www.jibbering.com/faq/faq_notes/type_convert.html#tcParseIn): > > parseInt is occasionally used as a means of turning a floating point number into an integer. It is very ill suited to that task because if its argument is of numeric type it will first be converted into a string a...
131,439
<p>I want a C program to produce a core dump under certain circumstances. This is a program that runs in a production environment and isn't easily stopped and restarted to adjust other kinds of debugging code. Also, since it's in a production environment, I don't want to call abort(). The issues under investigation are...
[ { "answer_id": 131461, "author": "Chris", "author_id": 15578, "author_profile": "https://Stackoverflow.com/users/15578", "pm_score": 2, "selected": false, "text": "<p>The source code to produce a core dump is in 'gcore', which is part of the gdb package.</p>\n\n<p>Also, the Sun has <a hr...
2008/09/25
[ "https://Stackoverflow.com/questions/131439", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14732/" ]
I want a C program to produce a core dump under certain circumstances. This is a program that runs in a production environment and isn't easily stopped and restarted to adjust other kinds of debugging code. Also, since it's in a production environment, I don't want to call abort(). The issues under investigation aren't...
``` void create_dump(void) { if(!fork()) { // Crash the app in your favorite way here *((void*)0) = 42; } } ``` Fork the process then crash the child - it'll give you a snapshot whenever you want
131,449
<p>I have this code:</p> <pre><code>chars = #some list try: indx = chars.index(chars) except ValueError: #doSomething else: #doSomethingElse </code></pre> <p>I want to be able to do this because I don't like knowfully causing Exceptions:</p> <pre><code>chars = #some list indx = chars.index(chars) if in...
[ { "answer_id": 131452, "author": "Jerub", "author_id": 14648, "author_profile": "https://Stackoverflow.com/users/14648", "pm_score": 3, "selected": false, "text": "<pre><code>if element in mylist:\n index = mylist.index(element)\n # ... do something\nelse:\n # ... do something e...
2008/09/25
[ "https://Stackoverflow.com/questions/131449", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2598/" ]
I have this code: ``` chars = #some list try: indx = chars.index(chars) except ValueError: #doSomething else: #doSomethingElse ``` I want to be able to do this because I don't like knowfully causing Exceptions: ``` chars = #some list indx = chars.index(chars) if indx == -1: #doSomething else: #...
Note that the latter approach is going against the generally accepted "pythonic" philosophy of [EAFP, or "It is Easier to Ask for Forgiveness than Permission."](http://en.wikipedia.org/wiki/Python_syntax_and_semantics#Exceptions), while the former follows it.
131,456
<p>How do I apply the MarshalAsAttribute to the return type of the code below?</p> <pre><code>public ISomething Foo() { return new MyFoo(); } </code></pre>
[ { "answer_id": 131467, "author": "Franci Penov", "author_id": 17028, "author_profile": "https://Stackoverflow.com/users/17028", "pm_score": 6, "selected": true, "text": "<p>According to <a href=\"http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.marshalasattribute.as...
2008/09/25
[ "https://Stackoverflow.com/questions/131456", "https://Stackoverflow.com", "https://Stackoverflow.com/users/21429/" ]
How do I apply the MarshalAsAttribute to the return type of the code below? ``` public ISomething Foo() { return new MyFoo(); } ```
According to <http://msdn.microsoft.com/en-us/library/system.runtime.interopservices.marshalasattribute.aspx>: ``` [return: MarshalAs(<your marshal type>)] public ISomething Foo() { return new MyFoo(); } ```
131,473
<p>G'day Stackoverflowers,</p> <p>I'm the author of Perl's <a href="http://search.cpan.org/perldoc?autodie" rel="nofollow noreferrer">autodie</a> pragma, which changes Perl's built-ins to throw exceptions on failure. It's similar to <a href="http://search.cpan.org/perldoc?Fatal" rel="nofollow noreferrer">Fatal</a>, b...
[ { "answer_id": 131798, "author": "tye", "author_id": 21496, "author_profile": "https://Stackoverflow.com/users/21496", "pm_score": 5, "selected": true, "text": "<p>Under Win32 \"native\" Perl, note that $^E is more descriptive at 33, \"The process cannot access the file because another p...
2008/09/25
[ "https://Stackoverflow.com/questions/131473", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19422/" ]
G'day Stackoverflowers, I'm the author of Perl's [autodie](http://search.cpan.org/perldoc?autodie) pragma, which changes Perl's built-ins to throw exceptions on failure. It's similar to [Fatal](http://search.cpan.org/perldoc?Fatal), but with lexical scope, an extensible exception model, more intelligent return checkin...
Under Win32 "native" Perl, note that $^E is more descriptive at 33, "The process cannot access the file because another process locked a portion of the file" which is `ERROR_LOCK_VIOLATION` (available from [Win32::WinError](http://search.cpan.org/dist/Win32-WinError/)).
131,516
<p>I've got a BPG file that I've modified to use as a make file for our company's automated build server. In order to get it to work I had to change </p> <pre> Uses * Uses unit1 in 'unit1.pas' * unit1 unit2 in 'unit2.pas' * unit2 ... * ... </pre> <p>in ...
[ { "answer_id": 131526, "author": "Peter Turner", "author_id": 1765, "author_profile": "https://Stackoverflow.com/users/1765", "pm_score": 1, "selected": false, "text": "<p>Well this work-around worked for me. </p>\n\n<pre>\n//{$define PACKAGE}\n{$ifdef PACKAGE}\n uses \n unit1 in 'unit1...
2008/09/25
[ "https://Stackoverflow.com/questions/131516", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1765/" ]
I've got a BPG file that I've modified to use as a make file for our company's automated build server. In order to get it to work I had to change ``` Uses * Uses unit1 in 'unit1.pas' * unit1 unit2 in 'unit2.pas' * unit2 ... * ... ``` in the DPR file ...
It could come from the fact, that the search path in the IDE and the search path of the command line compiler are not the same. If you change the serach path of the command line compiler you might be able to use the exactely same source code as within the IDE. One possibility to configure the search path for the comma...
131,518
<p>In my ASP.Net 1.1 application, i've added the following to my Web.Config (within the System.Web tag section):</p> <pre><code>&lt;httpHandlers&gt; &lt;add verb="*" path="*.bcn" type="Internet2008.Beacon.BeaconHandler, Internet2008" /&gt; &lt;/httpHandlers&gt; </code></pre> <p>This works fine, and the HTTPHandler ...
[ { "answer_id": 131531, "author": "Quintin Robinson", "author_id": 12707, "author_profile": "https://Stackoverflow.com/users/12707", "pm_score": 2, "selected": false, "text": "<p>It sounds like it as an inherant &lt;clear /&gt; in it although I don't know if I've seen this behaviour befor...
2008/09/25
[ "https://Stackoverflow.com/questions/131518", "https://Stackoverflow.com", "https://Stackoverflow.com/users/21969/" ]
In my ASP.Net 1.1 application, i've added the following to my Web.Config (within the System.Web tag section): ``` <httpHandlers> <add verb="*" path="*.bcn" type="Internet2008.Beacon.BeaconHandler, Internet2008" /> </httpHandlers> ``` This works fine, and the HTTPHandler kicks in for files of type .bcn, and does it...
It sounds like it as an inherant <clear /> in it although I don't know if I've seen this behaviour before, you could just add the general handler back, let me find you the code. ``` <add verb="*" path="*.asmx" type="System.Web.Services.Protocols.WebServiceHandlerFactory, System.Web.Services" validate="false"> ``` I ...
131,559
<p>Is there a way to search for multiple strings simultaneously in Vim? I recall reading somewhere that it was possible but somehow forgot the technique.</p> <p>So for example, I have a text file and I want to search for "foo" and "bar" simultaneously (not necessarily as a single string, can be in different lines alto...
[ { "answer_id": 131563, "author": "Ana Betts", "author_id": 5728, "author_profile": "https://Stackoverflow.com/users/5728", "pm_score": -1, "selected": false, "text": "<pre><code>/(foo|bar)\n</code></pre>\n" }, { "answer_id": 131572, "author": "ChronoPositron", "author_id"...
2008/09/25
[ "https://Stackoverflow.com/questions/131559", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17716/" ]
Is there a way to search for multiple strings simultaneously in Vim? I recall reading somewhere that it was possible but somehow forgot the technique. So for example, I have a text file and I want to search for "foo" and "bar" simultaneously (not necessarily as a single string, can be in different lines altogether). ...
``` /^joe.*fred.*bill/ : find joe AND fred AND Bill (Joe at start of line) /fred\|joe : Search for FRED OR JOE ```
131,605
<p>What version control systems have you used with MS Excel (2003/2007)? What would you recommend and Why? What limitations have you found with your top rated version control system?</p> <p>To put this in perspective, here are a couple of use cases:</p> <ol> <li>version control for VBA modules </li> <li>more than one...
[ { "answer_id": 131636, "author": "Dheer", "author_id": 17266, "author_profile": "https://Stackoverflow.com/users/17266", "pm_score": 1, "selected": false, "text": "<p>Use any of the standard version control tools like SVN or CVS. Limitations would depend on whats the objective. Apart fro...
2008/09/25
[ "https://Stackoverflow.com/questions/131605", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20879/" ]
What version control systems have you used with MS Excel (2003/2007)? What would you recommend and Why? What limitations have you found with your top rated version control system? To put this in perspective, here are a couple of use cases: 1. version control for VBA modules 2. more than one person is working on a Exc...
I've just setup a spreadsheet that uses Bazaar, with manual checkin/out via TortiseBZR. Given that the topic helped me with the save portion, I wanted to post my solution here. *The solution for me was to create a spreadsheet that exports all modules on save, and removes and re-imports the modules on open. Yes, this c...
131,619
<h2>Question</h2> <p>Using XSLT 1.0, given a string with arbitrary characters how can I get back a string that meets the following rules.</p> <ol> <li>First character must be one of these: a-z, A-Z, colon, or underscore</li> <li>All other characters must be any of those above or 0-9, period, or hyphen</li> <li>If any...
[ { "answer_id": 131687, "author": "Jim Burger", "author_id": 20164, "author_profile": "https://Stackoverflow.com/users/20164", "pm_score": 1, "selected": false, "text": "<p>As far as Im aware XSLT 1.0 doesnt have a builtin for this. XSLT 2.0 allows you to <a href=\"http://www.xml.com/pub/...
2008/09/25
[ "https://Stackoverflow.com/questions/131619", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8507/" ]
Question -------- Using XSLT 1.0, given a string with arbitrary characters how can I get back a string that meets the following rules. 1. First character must be one of these: a-z, A-Z, colon, or underscore 2. All other characters must be any of those above or 0-9, period, or hyphen 3. If any character does not meet ...
You *could* write a recursive template to do this, working through the characters in the string one by one, testing them and changing them if necessary. Something like: ``` <xsl:template name="normalizeName"> <xsl:param name="name" /> <xsl:param name="isFirst" select="true()" /> <xsl:if test="$name != ''"> <...
131,653
<p>I know that embedding CSS styles directly into the HTML tags they affect defeats much of the purpose of CSS, but sometimes it's useful for debugging purposes, as in:</p> <pre><code>&lt;p style="font-size: 24px"&gt;asdf&lt;/p&gt; </code></pre> <p>What's the syntax for embedding a rule like:</p> <pre><code>a:hover ...
[ { "answer_id": 131660, "author": "Glenn Slaven", "author_id": 2975, "author_profile": "https://Stackoverflow.com/users/2975", "pm_score": 8, "selected": true, "text": "<p>I'm afraid it can't be done, the pseudo-class selectors can't be set in-line, you'll have to do it on the page or on ...
2008/09/25
[ "https://Stackoverflow.com/questions/131653", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7598/" ]
I know that embedding CSS styles directly into the HTML tags they affect defeats much of the purpose of CSS, but sometimes it's useful for debugging purposes, as in: ``` <p style="font-size: 24px">asdf</p> ``` What's the syntax for embedding a rule like: ``` a:hover {text-decoration: underline;} ``` into the styl...
I'm afraid it can't be done, the pseudo-class selectors can't be set in-line, you'll have to do it on the page or on a stylesheet. I should mention that *technically* you *should* be able to do it [according to the CSS spec](http://www.w3.org/TR/css-style-attr#cascading), but most browsers don't support it **Edit:** ...
131,704
<p>Eclipse 3.4[.x] - also known as <a href="http://www.eclipse.org/downloads/packages/" rel="noreferrer">Ganymede</a> - comes with this new mechanism of provisioning called <strong>p2</strong>.</p> <p>"Provisioning" is the process allowing to discover and update on demand some parts of an application, as explained in ...
[ { "answer_id": 182019, "author": "Chris Kimpton", "author_id": 48310, "author_profile": "https://Stackoverflow.com/users/48310", "pm_score": 1, "selected": false, "text": "<p>It seems like you need to have one update work via the web which will mirror (download) what you need. But after...
2008/09/25
[ "https://Stackoverflow.com/questions/131704", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6309/" ]
Eclipse 3.4[.x] - also known as [Ganymede](http://www.eclipse.org/downloads/packages/) - comes with this new mechanism of provisioning called **p2**. "Provisioning" is the process allowing to discover and update on demand some parts of an application, as explained in general in this article on the [Sun Web site](http:...
Yes, you can specify the repository locations if you use the p2.director this for example is a snippet of a script that I use to install eclipse (Ganymede) from a local copy of the Ganymede repository ``` ./eclipse\ -nosplash -consolelog -debug\ -vm "${VM}"\ -application org.eclipse.equinox.p2.direc...
131,718
<p>Is there a simple way to write a common function for each of the <code>CRUD (create, retreive, update, delete)</code> operations in <code>PHP</code> WITHOUT using any framework. For example I wish to have a single create function that takes the table name and field names as parameters and inserts data into a <code>m...
[ { "answer_id": 131727, "author": "unexist", "author_id": 18179, "author_profile": "https://Stackoverflow.com/users/18179", "pm_score": 2, "selected": false, "text": "<p>Without any frameworks includes without any ORMs? Otherwise I would suggest to have a look at <a href=\"http://www.doct...
2008/09/25
[ "https://Stackoverflow.com/questions/131718", "https://Stackoverflow.com", "https://Stackoverflow.com/users/22009/" ]
Is there a simple way to write a common function for each of the `CRUD (create, retreive, update, delete)` operations in `PHP` WITHOUT using any framework. For example I wish to have a single create function that takes the table name and field names as parameters and inserts data into a `mySQL database`. Another requir...
I wrote this very thing, it's kind of a polished scaffold. It's basically a class the constructor of which takes the table to be used, an array containing field names and types, and an action. Based on this action the object calls a method on itself. For example: This is the array I pass: ``` $data = array(array('nam...
131,728
<p>I'm using the Telerik RAD Controls RADEditor/WYSIWYG control as part of a Dynamic Data solution.</p> <p>I would like to be able to upload files using the Document Manager of this control.</p> <p>However, these files are larger than whatever the default setting is for maximum upload file size.</p> <p>Can anyone po...
[ { "answer_id": 131737, "author": "Yaakov Ellis", "author_id": 51, "author_profile": "https://Stackoverflow.com/users/51", "pm_score": 3, "selected": true, "text": "<p>The Telerik website has instructions <a href=\"http://www.telerik.com/help/aspnet-ajax/upload_uploadinglargefiles.html\" ...
2008/09/25
[ "https://Stackoverflow.com/questions/131728", "https://Stackoverflow.com", "https://Stackoverflow.com/users/364/" ]
I'm using the Telerik RAD Controls RADEditor/WYSIWYG control as part of a Dynamic Data solution. I would like to be able to upload files using the Document Manager of this control. However, these files are larger than whatever the default setting is for maximum upload file size. Can anyone point me in the right dire...
The Telerik website has instructions [here](http://www.telerik.com/help/aspnet-ajax/upload_uploadinglargefiles.html). Short version: in Web.config set the maxRequestLength ``` <system.web> <httpRuntime maxRequestLength="102400" executionTimeout= "3600" /> </system.web> ```
131,788
<p>I'm writing a Perl script and I've come to a point where I need to parse a Java source file line by line checking for references to a fully qualified Java class name. I know the class I'm looking for up front; also the fully qualified name of the source file that is being searched (based on its path). </p> <p>For e...
[ { "answer_id": 131869, "author": "Paul Wicks", "author_id": 85, "author_profile": "https://Stackoverflow.com/users/85", "pm_score": 3, "selected": false, "text": "<p>A Regex is probably the best solution for this, although I did find the following module in CPAN that you might be able to...
2008/09/25
[ "https://Stackoverflow.com/questions/131788", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3636/" ]
I'm writing a Perl script and I've come to a point where I need to parse a Java source file line by line checking for references to a fully qualified Java class name. I know the class I'm looking for up front; also the fully qualified name of the source file that is being searched (based on its path). For example fin...
You also need to skip quoted strings (you can't even skip comments correctly if you don't also deal with quoted strings). I'd probably write a fairly simple, efficient, and incomplete tokenizer very similar to the one I wrote in [node 566467](http://perlmonks.org/?node_id=566467). Based on that code I'd probably just...
131,793
<p>I have an old Delphi codebase I have to maintain, lots of DLLs, some older than others. In some of these DLLs there is no version information in the Project Options dialog. The controls for adding a version are greyed out and I can't even add a version number by manually editing the .DOF file. How can I include a ve...
[ { "answer_id": 131826, "author": "John Ferguson", "author_id": 8312, "author_profile": "https://Stackoverflow.com/users/8312", "pm_score": 4, "selected": true, "text": "<p>Check if the default .RES file exists in the project source location. Delphi includes the version number of the proj...
2008/09/25
[ "https://Stackoverflow.com/questions/131793", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8312/" ]
I have an old Delphi codebase I have to maintain, lots of DLLs, some older than others. In some of these DLLs there is no version information in the Project Options dialog. The controls for adding a version are greyed out and I can't even add a version number by manually editing the .DOF file. How can I include a versi...
Check if the default .RES file exists in the project source location. Delphi includes the version number of the project in a .res file with the same name as the .dpr file. If the .RES file does not exist, the simplest way to recreate it is to add the {$R \*.RES} compiler directive to the .DPR file, immediately after th...
131,805
<p>What is the SQL command to copy a table from one database to another database? I am using MySQL and I have two databases x and y. Suppose I have a table in x called a and I need to copy that table to y database. Sorry if the question is too novice.</p> <p>Thanks.</p>
[ { "answer_id": 131824, "author": "bzlm", "author_id": 7724, "author_profile": "https://Stackoverflow.com/users/7724", "pm_score": 1, "selected": false, "text": "<p>If you just want to copy the contents, you might be looking for <code>select into</code>:\n<a href=\"http://www.w3schools.co...
2008/09/25
[ "https://Stackoverflow.com/questions/131805", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11193/" ]
What is the SQL command to copy a table from one database to another database? I am using MySQL and I have two databases x and y. Suppose I have a table in x called a and I need to copy that table to y database. Sorry if the question is too novice. Thanks.
If your two database are separated, the simplest thing to do would be to create a dump of your table and to load it into the second database. Refer to your database manual to see how a dump can be performed. Otherwise you can use the following syntax (for MySQL) ``` INSERT INTO database_b.table (SELECT * FROM databas...
131,811
<p>Can someone explain why how the result for the following unpack is computed?</p> <pre><code>"aaa".unpack('h2H2') #=&gt; ["16", "61"] </code></pre> <p>In binary, 'a' = 0110 0001. I'm not sure how the 'h2' can become 16 (0001 0000) or 'H2' can become 61 (0011 1101).</p>
[ { "answer_id": 131850, "author": "Chris Bunch", "author_id": 422, "author_profile": "https://Stackoverflow.com/users/422", "pm_score": 3, "selected": false, "text": "<p>Check out the Programming Ruby <a href=\"http://www.ruby-doc.org/core-1.9.3/String.html#method-i-unpack\" rel=\"nofollo...
2008/09/25
[ "https://Stackoverflow.com/questions/131811", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18432/" ]
Can someone explain why how the result for the following unpack is computed? ``` "aaa".unpack('h2H2') #=> ["16", "61"] ``` In binary, 'a' = 0110 0001. I'm not sure how the 'h2' can become 16 (0001 0000) or 'H2' can become 61 (0011 1101).
Not 16 - it is showing 1 and then 6. h is giving the hex value of each nibble, so you get 0110 (6), then 0001 (1), depending on whether its the high or low bit you're looking at. Use the high nibble first and you get 61, which is hex for 97 - the value of 'a'
131,847
<p>I have an ellipse centered at (0,0) and the bounding rectangle is x = [-5,5], y = [-6,6]. The ellipse intersects the rectangle at (-5,3),(-2.5,6),(2.5,-6),and (5,-3)</p> <p>I know nothing else about the ellipse, but the only thing I need to know is what angle the major axis is rotated at.</p> <p>seems like the ans...
[ { "answer_id": 131876, "author": "paxdiablo", "author_id": 14860, "author_profile": "https://Stackoverflow.com/users/14860", "pm_score": 2, "selected": false, "text": "<p>The gradient of the ellipse is identical to the gradient of the intersects with the bounding rectangle along one side...
2008/09/25
[ "https://Stackoverflow.com/questions/131847", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I have an ellipse centered at (0,0) and the bounding rectangle is x = [-5,5], y = [-6,6]. The ellipse intersects the rectangle at (-5,3),(-2.5,6),(2.5,-6),and (5,-3) I know nothing else about the ellipse, but the only thing I need to know is what angle the major axis is rotated at. seems like the answer must be reall...
The gradient of the ellipse is identical to the gradient of the intersects with the bounding rectangle along one side of the ellipse. In your case, that's the line from (-2.5,6) to (5,-3), the top side of your ellipse. That line has a vertical drop of 9 and a horizontal run of 7.5. So we end up with the following righ...
131,871
<p>I'd love to figure it out myself but I was wondering <strong>roughly what's the algorithm for converting a function with yield statements into a state machine for an enumerator?</strong> For example how does C# turn this:</p> <pre><code>IEnumerator&lt;string&gt; strings(IEnumerable&lt;string&gt; args) { IEnumerato...
[ { "answer_id": 131891, "author": "Steve Cooper", "author_id": 6722, "author_profile": "https://Stackoverflow.com/users/6722", "pm_score": 3, "selected": false, "text": "<p>Raymond Chen answers this <a href=\"https://devblogs.microsoft.com/oldnewthing/20080812-00/?p=21273\" rel=\"nofollow...
2008/09/25
[ "https://Stackoverflow.com/questions/131871", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1659/" ]
I'd love to figure it out myself but I was wondering **roughly what's the algorithm for converting a function with yield statements into a state machine for an enumerator?** For example how does C# turn this: ``` IEnumerator<string> strings(IEnumerable<string> args) { IEnumerator<string> enumerator2 = getAnotherEnume...
The particular code sample you are looking at involves a series of transformations. Please note that this is an approximate description of the algorithm. The actual names used by the compiler and the exact code it generates may be different. The idea is the same, however. The first transformation is the "foreach" tran...
131,901
<p>I am trying to copy a file using the following code:</p> <pre><code>File targetFile = new File(targetPath + File.separator + filename); ... targetFile.createNewFile(); fileInputStream = new FileInputStream(fileToCopy); fileOutputStream = new FileOutputStream(targetFile); byte[] buffer = new byte[64*1024]; int i = 0...
[ { "answer_id": 131943, "author": "The Archetypal Paul", "author_id": 21755, "author_profile": "https://Stackoverflow.com/users/21755", "pm_score": 0, "selected": false, "text": "<p>Do you check that the targetPath is a directory, or just that something exists with that name? (I know you ...
2008/09/25
[ "https://Stackoverflow.com/questions/131901", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5271/" ]
I am trying to copy a file using the following code: ``` File targetFile = new File(targetPath + File.separator + filename); ... targetFile.createNewFile(); fileInputStream = new FileInputStream(fileToCopy); fileOutputStream = new FileOutputStream(targetFile); byte[] buffer = new byte[64*1024]; int i = 0; while((i = f...
Try this, as it takes more care of adjusting directory separator characters in the path between targetPath and filename: ``` File targetFile = new File(targetPath, filename); ```
131,902
<p>I am wondering what security concerns there are to implementing a <code>PHP evaluator</code> like this:</p> <pre><code>&lt;?php eval($_POST['codeInput']); %&gt; </code></pre> <p>This is in the context of making a <code>PHP sandbox</code> so sanitising against <code>DB input</code> etc. isn't a massive issue.</p> ...
[ { "answer_id": 131911, "author": "Owen", "author_id": 4853, "author_profile": "https://Stackoverflow.com/users/4853", "pm_score": 4, "selected": false, "text": "<p>don't do that.</p>\n\n<p>they basically have access to anything you can do in PHP (look around the file system, get/set any ...
2008/09/25
[ "https://Stackoverflow.com/questions/131902", "https://Stackoverflow.com", "https://Stackoverflow.com/users/364/" ]
I am wondering what security concerns there are to implementing a `PHP evaluator` like this: ``` <?php eval($_POST['codeInput']); %> ``` This is in the context of making a `PHP sandbox` so sanitising against `DB input` etc. isn't a massive issue. Users destroying the server the file is hosted on is. I've seen `Rub...
could potentially be in really big trouble if you `eval()`'d something like ``` <?php eval("shell_exec(\"rm -rf {$_SERVER['DOCUMENT_ROOT']}\");"); ?> ``` it's an extreme example but it that case your site would just get deleted. hopefully your permissions wouldn't allow it but, it helps illustrate the need for s...
131,923
<p>Here's my situation:</p> <ul> <li>Windows Server</li> <li>Apache</li> <li>CruiseControl</li> </ul> <p>The last step of my CruiseControl deploy scripts copies the build to Apache's htdocs folder, in a "demos" folder (I believe this is referred to as a "hot deploy"?)</p> <p>All is good and dandy, except that SOMETI...
[ { "answer_id": 136751, "author": "hubbardr", "author_id": 22457, "author_profile": "https://Stackoverflow.com/users/22457", "pm_score": 0, "selected": false, "text": "<p>Apache won't delete the contents of the directory. Something in the script is removing the contents would be my guess....
2008/09/25
[ "https://Stackoverflow.com/questions/131923", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1199623/" ]
Here's my situation: * Windows Server * Apache * CruiseControl The last step of my CruiseControl deploy scripts copies the build to Apache's htdocs folder, in a "demos" folder (I believe this is referred to as a "hot deploy"?) All is good and dandy, except that SOMETIMES (not common, but it happens enough that it bu...
I would suggest creating a backup of the old files prior to copying the new files out. Name the old files with the timestamp for when they were replaced. Doing this and then seeing what is in the directory the next time it fails will most likely give you a clue as to where to look next.
131,944
<p>How do I read a time value and then insert it into a TimeSpan variables?</p>
[ { "answer_id": 131960, "author": "TraumaPony", "author_id": 18658, "author_profile": "https://Stackoverflow.com/users/18658", "pm_score": 1, "selected": false, "text": "<pre><code>TimeSpan span = new TimeSpan(days,hours,minutes,seconds,milliseonds);\n</code></pre>\n\n<p>Or, if you mean D...
2008/09/25
[ "https://Stackoverflow.com/questions/131944", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
How do I read a time value and then insert it into a TimeSpan variables?
If I understand you correctly you're trying to get some user input in the form of "08:00" and want to store the time in a timespan variable? So.. something like this? ``` string input = "08:00"; DateTime time; if (!DateTime.TryParse(input, out time)) { // invalid input return; } TimeSpan timeSpan = new TimeS...
131,955
<p>Is there a keyboard shortcut for pasting the content of the clipboard into a command prompt window on Windows XP (instead of using the right mouse button)?</p> <p>The typical <kbd>Shift</kbd>+<kbd>Insert</kbd> does not seem to work here.</p>
[ { "answer_id": 131969, "author": "Nescio", "author_id": 14484, "author_profile": "https://Stackoverflow.com/users/14484", "pm_score": 9, "selected": false, "text": "<p>Yes.. but awkward. <a href=\"https://learn.microsoft.com/en-gb/archive/blogs/adioltean/useful-copypaste-trick-in-cmd-exe...
2008/09/25
[ "https://Stackoverflow.com/questions/131955", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4497/" ]
Is there a keyboard shortcut for pasting the content of the clipboard into a command prompt window on Windows XP (instead of using the right mouse button)? The typical `Shift`+`Insert` does not seem to work here.
I personally use a little [AutoHotkey](http://www.autohotkey.com/) script to remap certain keyboard functions, for the console window (CMD) I use: ``` ; Redefine only when the active window is a console window #IfWinActive ahk_class ConsoleWindowClass ; Close Command Window with Ctrl+w $^w:: WinGetTitle sTitle If (I...
131,975
<p>I understand benefits of dependency injection itself. Let's take Spring for instance. I also understand benefits of other Spring featureslike AOP, helpers of different kinds, etc. I'm just wondering, what are the benefits of XML configuration such as:</p> <pre><code>&lt;bean id="Mary" class="foo.bar.Female"&gt; &...
[ { "answer_id": 131986, "author": "Romain Verdier", "author_id": 4687, "author_profile": "https://Stackoverflow.com/users/4687", "pm_score": 1, "selected": false, "text": "<p>In the .NET world, most of IoC frameworks provide both XML and Code configuration.</p>\n\n<p>StructureMap and Ninj...
2008/09/25
[ "https://Stackoverflow.com/questions/131975", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5507/" ]
I understand benefits of dependency injection itself. Let's take Spring for instance. I also understand benefits of other Spring featureslike AOP, helpers of different kinds, etc. I'm just wondering, what are the benefits of XML configuration such as: ``` <bean id="Mary" class="foo.bar.Female"> <property name="age" ...
For myself one of the main reasons to use an IoC (and make use of external configuration) is around the two areas of: * Testing * Production maintenance **Testing** If you split your testing into 3 scenarios (which is fairly normal in large scale development): 1. Unit testing 2. Integration testing 3. Black box tes...
131,989
<p>I want to find out all the subdomains of a given domain. I found a hint which tells me to dig the authoritative Nameserver with the following option:</p> <pre><code>dig @ns1.foo.example example.com axfr </code></pre> <p>But this never works. Has anyone a better idea/approach</p>
[ { "answer_id": 131998, "author": "Steve Moyer", "author_id": 17008, "author_profile": "https://Stackoverflow.com/users/17008", "pm_score": 2, "selected": false, "text": "<p>If the DNS server is configured properly, you won't be able to get the entire domain. If for some reason is allows...
2008/09/25
[ "https://Stackoverflow.com/questions/131989", "https://Stackoverflow.com", "https://Stackoverflow.com/users/22029/" ]
I want to find out all the subdomains of a given domain. I found a hint which tells me to dig the authoritative Nameserver with the following option: ``` dig @ns1.foo.example example.com axfr ``` But this never works. Has anyone a better idea/approach
The hint (using axfr) only works if the NS you're querying (`ns1.foo.example` in your example) is configured to allow AXFR requests from the IP you're using; this is unlikely, unless your IP is configured as a secondary for the domain in question. Basically, there's no easy way to do it if you're not allowed to use ax...
131,993
<p>Subversion is a great way to update our web applications on our servers. With a simple <code>svn update</code> all changed files get... well, changed.</p> <p>Except for the omnipresent configuration files such as <code>config.php</code> which hold the database access configuration, server paths etc. And are therefo...
[ { "answer_id": 132002, "author": "xmjx", "author_id": 15259, "author_profile": "https://Stackoverflow.com/users/15259", "pm_score": 2, "selected": false, "text": "<p>Create a template for the file (e.g. config.php-default) and let the user copy the template. She can also do a diff to see...
2008/09/25
[ "https://Stackoverflow.com/questions/131993", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6260/" ]
Subversion is a great way to update our web applications on our servers. With a simple `svn update` all changed files get... well, changed. Except for the omnipresent configuration files such as `config.php` which hold the database access configuration, server paths etc. And are therefore different on my local develop...
I find the easiest way is to switch on the machine's hostname. I have a .ini file with a general section that also overrides this for production, testing and development systems. ``` [general] info=misc db.password=secret db.host=localhost [production : general] info=only on production system db.password=secret1 [te...
132,030
<p>Right now I have a visual studio project which contains a custom content type that I made. It also contains all the necessary files for making a sharepoint solution (wsp) file and a script to generate this. </p> <p>Now, I would like to do 2 things. </p> <p>First, I'd like to create a custom display form for the co...
[ { "answer_id": 146879, "author": "Nat", "author_id": 13813, "author_profile": "https://Stackoverflow.com/users/13813", "pm_score": 2, "selected": true, "text": "<p>Use <a href=\"http://www.codeplex.com/stsdev\" rel=\"nofollow noreferrer\">STSDev</a> to create the solution package. \nThat...
2008/09/25
[ "https://Stackoverflow.com/questions/132030", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17577/" ]
Right now I have a visual studio project which contains a custom content type that I made. It also contains all the necessary files for making a sharepoint solution (wsp) file and a script to generate this. Now, I would like to do 2 things. First, I'd like to create a custom display form for the content type and in...
Use [STSDev](http://www.codeplex.com/stsdev) to create the solution package. That should help with creating the WSP. The custom form, CQWP webpart and the .xls file should also be deployable within the project. To deploy the xslt, your feature will have an `<ElementManifest Location="mywebpartManifest.xml">` This t...
132,038
<p>I am trying to implement in windows scripting host the same function as windows Send To/Mail Recipient does. Did not find anything usefull on google except steps to instantiate <code>Outlook.Application</code> and directly calling its methods.</p> <p>I need to go the same path as windows do, as there is a mix of Ou...
[ { "answer_id": 146879, "author": "Nat", "author_id": 13813, "author_profile": "https://Stackoverflow.com/users/13813", "pm_score": 2, "selected": true, "text": "<p>Use <a href=\"http://www.codeplex.com/stsdev\" rel=\"nofollow noreferrer\">STSDev</a> to create the solution package. \nThat...
2008/09/25
[ "https://Stackoverflow.com/questions/132038", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10560/" ]
I am trying to implement in windows scripting host the same function as windows Send To/Mail Recipient does. Did not find anything usefull on google except steps to instantiate `Outlook.Application` and directly calling its methods. I need to go the same path as windows do, as there is a mix of Outlook and Lotus Notes...
Use [STSDev](http://www.codeplex.com/stsdev) to create the solution package. That should help with creating the WSP. The custom form, CQWP webpart and the .xls file should also be deployable within the project. To deploy the xslt, your feature will have an `<ElementManifest Location="mywebpartManifest.xml">` This t...
132,052
<p>I deploy a webapp on two different containers (Tomcat and Jetty), but their default servlets for serving the static content have a different way of handling the URL structure I want to use (<a href="http://issues.apache.org/bugzilla/show_bug.cgi?id=42411" rel="noreferrer">details</a>).</p> <p>I am therefore looking...
[ { "answer_id": 132103, "author": "Panagiotis Korros", "author_id": 19331, "author_profile": "https://Stackoverflow.com/users/19331", "pm_score": 4, "selected": false, "text": "<p>I had the same problem and I solved it by using the code of the 'default servlet' from the Tomcat codebase.</...
2008/09/25
[ "https://Stackoverflow.com/questions/132052", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6918/" ]
I deploy a webapp on two different containers (Tomcat and Jetty), but their default servlets for serving the static content have a different way of handling the URL structure I want to use ([details](http://issues.apache.org/bugzilla/show_bug.cgi?id=42411)). I am therefore looking to include a small servlet in the web...
I ended up rolling my own `StaticServlet`. It supports `If-Modified-Since`, gzip encoding and it should be able to serve static files from war-files as well. It is not very difficult code, but it is not entirely trivial either. The code is available: [StaticServlet.java](http://bruno.defraine.net/StaticServlet.java). ...
132,058
<p>I have this Python application that gets stuck from time to time and I can't find out where.</p> <p>Is there any way to signal Python interpreter to show you the exact code that's running? </p> <p>Some kind of on-the-fly stacktrace?</p> <p><strong><em>Related questions:</em></strong></p> <ul> <li><a href="https:...
[ { "answer_id": 132108, "author": "Gustavo Rubio", "author_id": 14533, "author_profile": "https://Stackoverflow.com/users/14533", "pm_score": 4, "selected": false, "text": "<p><em>python -dv yourscript.py</em></p>\n\n<p>That will make the interpreter to run in debug mode and to give you a...
2008/09/25
[ "https://Stackoverflow.com/questions/132058", "https://Stackoverflow.com", "https://Stackoverflow.com/users/189/" ]
I have this Python application that gets stuck from time to time and I can't find out where. Is there any way to signal Python interpreter to show you the exact code that's running? Some kind of on-the-fly stacktrace? ***Related questions:*** * [Print current call stack from a method in Python code](https://stacko...
I have module I use for situations like this - where a process will be running for a long time but gets stuck sometimes for unknown and irreproducible reasons. Its a bit hacky, and only works on unix (requires signals): ``` import code, traceback, signal def debug(sig, frame): """Interrupt running process, and pr...
132,070
<p>I have a really big database (running on PostgreSQL) containing a lot of tables with sophisticated relations between them (foreign keys, on delete cascade and so on). I need remove some data from a number of tables, but I'm not sure what amount of data will be really deleted from database due to cascade removals.</p...
[ { "answer_id": 132080, "author": "DrStalker", "author_id": 17007, "author_profile": "https://Stackoverflow.com/users/17007", "pm_score": 0, "selected": false, "text": "<p>If the worry is keys left dangling (i.e.: pointing to a deleted record) then run the deletion on your test database, ...
2008/09/25
[ "https://Stackoverflow.com/questions/132070", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19101/" ]
I have a really big database (running on PostgreSQL) containing a lot of tables with sophisticated relations between them (foreign keys, on delete cascade and so on). I need remove some data from a number of tables, but I'm not sure what amount of data will be really deleted from database due to cascade removals. How ...
You can query the information\_schema to draw yourself a picture on how the constraints are defined in the database. Then you'll know what is going to happen when you delete. This will be useful not only for this case, but always. Something like (for constraints) ``` select table_catalog,table_schema,table_name,colu...
132,092
<p>I think everyone would agree that the MATLAB language is not pretty, or particularly consistent. But nevermind! We still have to use it to get things done.</p> <p>What are your favourite tricks for making things easier? Let's have one per answer so people can vote them up if they agree. Also, try to illustrate your...
[ { "answer_id": 132096, "author": "Matt", "author_id": 15368, "author_profile": "https://Stackoverflow.com/users/15368", "pm_score": 4, "selected": false, "text": "<p>Here's a quick example:</p>\n\n<p>I find the comma separated list syntax quite useful for building function calls:</p>\n\n...
2008/09/25
[ "https://Stackoverflow.com/questions/132092", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15368/" ]
I think everyone would agree that the MATLAB language is not pretty, or particularly consistent. But nevermind! We still have to use it to get things done. What are your favourite tricks for making things easier? Let's have one per answer so people can vote them up if they agree. Also, try to illustrate your answer wi...
Turn a matrix into a vector using a single colon. ``` x = rand(4,4); x(:) ```
132,118
<p>When you're using Tiles with Struts and do...</p> <pre><code>request.getRequestURL() </code></pre> <p>...you get the URL to e.g. <code>/WEB-INF/jsp/layout/newLayout.jsp</code> instead of the real URL that was entered/clicked by the user, something like <code>/context/action.do</code>.</p> <p>In newer Struts versi...
[ { "answer_id": 135713, "author": "Mwanji Ezana", "author_id": 7288, "author_profile": "https://Stackoverflow.com/users/7288", "pm_score": 1, "selected": false, "text": "<p>I don't know if Struts 1.2.x has a similar Globals constant, but you could create your own in at least two ways:</p>...
2008/09/25
[ "https://Stackoverflow.com/questions/132118", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
When you're using Tiles with Struts and do... ``` request.getRequestURL() ``` ...you get the URL to e.g. `/WEB-INF/jsp/layout/newLayout.jsp` instead of the real URL that was entered/clicked by the user, something like `/context/action.do`. In newer Struts versions, 1.3.x and after, you can use the [solution mention...
I use this, which also works on Spring: ``` <% out.println(request.getAttribute("javax.servlet.forward.request_uri")); %> ``` If you also need the query string (contributed by [matchew](https://stackoverflow.com/users/638649/matchew)): ``` <% out.println(request.getAttribute("javax.servlet.forward.query_string")); ...
132,136
<p>Does anyone know if IE6 ever misrenders pages with hidden <code>divs</code>? We currently have several <code>divs</code> which we display in the same space on the page, only showing one at a time and hiding all others.</p> <p>The problem is that the hidden <code>divs</code> components (specifically option menus) so...
[ { "answer_id": 132162, "author": "Santiago Cepas", "author_id": 6547, "author_profile": "https://Stackoverflow.com/users/6547", "pm_score": 2, "selected": false, "text": "<p>One hack you could use is to move your div outside the screen:</p>\n\n<pre><code>MyDiv.style.left = \"-1000px\";\n...
2008/09/25
[ "https://Stackoverflow.com/questions/132136", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
Does anyone know if IE6 ever misrenders pages with hidden `divs`? We currently have several `divs` which we display in the same space on the page, only showing one at a time and hiding all others. The problem is that the hidden `divs` components (specifically option menus) sometimes show through. If the page is scroll...
One hack you could use is to move your div outside the screen: ``` MyDiv.style.left = "-1000px"; ``` And then put it back on its original position when you want to show it.
132,164
<p>These <code>for</code>-loops are among the first basic examples of formal correctness proofs of algorithms. They have different but equivalent termination conditions:</p> <pre><code>1 for ( int i = 0; i != N; ++i ) 2 for ( int i = 0; i &lt; N; ++i ) </code></pre> <p>The difference becomes clear in the postcon...
[ { "answer_id": 132175, "author": "C. K. Young", "author_id": 13, "author_profile": "https://Stackoverflow.com/users/13", "pm_score": 1, "selected": false, "text": "<p>In C++, using the <code>!=</code> test is preferred for generality. Iterators in C++ have various concepts, like <a href=...
2008/09/25
[ "https://Stackoverflow.com/questions/132164", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2686/" ]
These `for`-loops are among the first basic examples of formal correctness proofs of algorithms. They have different but equivalent termination conditions: ``` 1 for ( int i = 0; i != N; ++i ) 2 for ( int i = 0; i < N; ++i ) ``` The difference becomes clear in the postconditions: * The first one gives the stro...
We shouldn't look at the counter in isolation - if for any reason someone changed the way the counter is incremented they would change the termination conditions and the resulting logic if it's required for i==N. I would prefer the the second condition since it's more standard and will not result in endless loop.
132,186
<p>I wish to test a function that will generate <code>lorem ipsum</code> text, but it does so within html tags. So I cant know in advance the textual content, but i know the html structure. That is what I want to test. And maybe that the length of the texts are within certain limits. So what I am wondering is if the as...
[ { "answer_id": 132420, "author": "Ken", "author_id": 20074, "author_profile": "https://Stackoverflow.com/users/20074", "pm_score": 0, "selected": false, "text": "<p>Extend the SimpleExpectation class and then use your new Expectation class in the assert statement</p>\n\n<p>see: <a href=\...
2008/09/25
[ "https://Stackoverflow.com/questions/132186", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4013/" ]
I wish to test a function that will generate `lorem ipsum` text, but it does so within html tags. So I cant know in advance the textual content, but i know the html structure. That is what I want to test. And maybe that the length of the texts are within certain limits. So what I am wondering is if the assertTags can d...
``` $expected = array( '<p', 'preg:/[A-Za-z\.\s\,]+/', '/p' ); ```
132,231
<p>When I'm writing a Spring command line application which parses command line arguments, how do I pass them to Spring? Would I want to have my main() structured so that it first parses the command line args and then inits Spring? Even so, how would it pass the object holding the parsed args to Spring?</p>
[ { "answer_id": 132546, "author": "Bradley Beddoes", "author_id": 22087, "author_profile": "https://Stackoverflow.com/users/22087", "pm_score": 1, "selected": false, "text": "<p>Here is an example to boot strap spring for a Main method, simply grab the passed params as normal then make th...
2008/09/25
[ "https://Stackoverflow.com/questions/132231", "https://Stackoverflow.com", "https://Stackoverflow.com/users/22063/" ]
When I'm writing a Spring command line application which parses command line arguments, how do I pass them to Spring? Would I want to have my main() structured so that it first parses the command line args and then inits Spring? Even so, how would it pass the object holding the parsed args to Spring?
Two possibilities I can think of. 1) Set a static reference. (A static variable, although typically frowned upon, is OK in this case, because there can only be 1 command line invocation). ``` public class MyApp { public static String[] ARGS; public static void main(String[] args) { ARGS = args; // cre...
132,242
<p>Consider this case:</p> <pre><code>dll = LoadDLL() dll-&gt;do() ... void do() { char *a = malloc(1024); } ... UnloadDLL(dll); </code></pre> <p>At this point, will the 1k allocated in the call to malloc() be available to the host process again? The DLL is statically linking to the CRT.</p>
[ { "answer_id": 132308, "author": "gbjbaanb", "author_id": 13744, "author_profile": "https://Stackoverflow.com/users/13744", "pm_score": -1, "selected": true, "text": "<p>No, you do not leak. </p>\n\n<p>If you mix dll models (static, dynamic) then you can end up with a memory error if you...
2008/09/25
[ "https://Stackoverflow.com/questions/132242", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17424/" ]
Consider this case: ``` dll = LoadDLL() dll->do() ... void do() { char *a = malloc(1024); } ... UnloadDLL(dll); ``` At this point, will the 1k allocated in the call to malloc() be available to the host process again? The DLL is statically linking to the CRT.
No, you do not leak. If you mix dll models (static, dynamic) then you can end up with a memory error if you allocate memory in a dll, that you free in a different one (or freed in the exe) This means that the heap created by the statically-linked CRT is not the same heap as a different dll's CRT. If you'd linked wi...
132,245
<p>The simple demo below captures what I am trying to do. In the real program, I have to use the object initialiser block since it is reading a list in a LINQ to SQL select expression, and there is a value that that I want to read off the database and store on the object, but the object doesn't have a simple property t...
[ { "answer_id": 132275, "author": "Tigraine", "author_id": 21699, "author_profile": "https://Stackoverflow.com/users/21699", "pm_score": 3, "selected": false, "text": "<p>Object Initializers are just syntactic sugar that requires a clever compiler, and as of the current implementation you...
2008/09/25
[ "https://Stackoverflow.com/questions/132245", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5599/" ]
The simple demo below captures what I am trying to do. In the real program, I have to use the object initialiser block since it is reading a list in a LINQ to SQL select expression, and there is a value that that I want to read off the database and store on the object, but the object doesn't have a simple property that...
Even better: ``` public static T SetBarValue<T>(this T dataObject, int barValue) where T : BaseDataObject { dataObject.SetData("bar", barValue); return dataObject; } ``` and you can use this extension method for derived types of BaseDataObject to chain methods without casts and prese...