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
176,840
<p>It's the first <a href="http://oreilly.com/catalog/opensources/book/larry.html" rel="nofollow noreferrer">great virtue</a> of programmers. All of us have, at one time or another automated a task with a bit of throw-away code. Sometimes it takes a couple seconds tapping out a one-liner, sometimes we spend an exorbita...
[ { "answer_id": 176843, "author": "Kibbee", "author_id": 1862, "author_profile": "https://Stackoverflow.com/users/1862", "pm_score": 1, "selected": false, "text": "<p>Sorry, don't have the exact code handy, but I coded a regular expression for searching source code in VS.Net that allowed...
2008/10/07
[ "https://Stackoverflow.com/questions/176840", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1582786/" ]
It's the first [great virtue](http://oreilly.com/catalog/opensources/book/larry.html) of programmers. All of us have, at one time or another automated a task with a bit of throw-away code. Sometimes it takes a couple seconds tapping out a one-liner, sometimes we spend an exorbitant amount of time automating away a two-...
i found this on dotfiles.org just today. it's very simple, but clever. i felt stupid for not having thought of it myself. ``` ### ### Handy Extract Program ### extract () { if [ -f $1 ] ; then case $1 in *.tar.bz2) tar xvjf $1 ;; *.tar.gz) tar xvzf $1 ;; ...
176,850
<p>I've used NUnit before, but not in a while, and never on this machine. I unzipped version 2.4.8 under <code>Program Files</code>, and I keep getting this error when trying to load my tests.</p> <blockquote> <p>Could not load file or assembly 'nunit.framework, Version=2.4.8.0, Culture=neutral, PublicKeyToken=96d09...
[ { "answer_id": 176859, "author": "Scott Pedersen", "author_id": 16002, "author_profile": "https://Stackoverflow.com/users/16002", "pm_score": 4, "selected": false, "text": "<p>Make sure you have added a reference to nunit.framework. If you have, then make sure the properties of that ref...
2008/10/07
[ "https://Stackoverflow.com/questions/176850", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4525/" ]
I've used NUnit before, but not in a while, and never on this machine. I unzipped version 2.4.8 under `Program Files`, and I keep getting this error when trying to load my tests. > > Could not load file or assembly 'nunit.framework, Version=2.4.8.0, Culture=neutral, PublicKeyToken=96d09a1eb7f44a77' or one of its depe...
If you install using NUnit-2.4.8-net-2.0.msi, the NUnit assemblies are added to the [GAC](http://en.wikipedia.org/wiki/Global_Assembly_Cache). You can also reinstall manually by running gacutil from the Visual Studio 2005 command prompt.
176,851
<p>I have taken a copy of a database home with me so I can do some testing. However when I try to run a stored procedure I get Cannot open user default database. Login failed.. </p> <p>I have checked and checked and checked I can open tables in the databases login to sql management studio and access the default as wel...
[ { "answer_id": 176864, "author": "Brian Kim", "author_id": 5704, "author_profile": "https://Stackoverflow.com/users/5704", "pm_score": 2, "selected": false, "text": "<p><strong>EDIT:</strong> Mine was from 2005 to 2005. Not sure if this will work for your case...</p>\n\n<p>I had a simila...
2008/10/07
[ "https://Stackoverflow.com/questions/176851", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16989/" ]
I have taken a copy of a database home with me so I can do some testing. However when I try to run a stored procedure I get Cannot open user default database. Login failed.. I have checked and checked and checked I can open tables in the databases login to sql management studio and access the default as well as other...
I moved 8 databases from SQL Server 2000 to SQL Server 2005 and onto a whole different computer. I normally like to know what stored procs are doing so I dug a little bit and found that the actual command is **ALTER USER**. It's what everybody else has been saying. The users get disassociated when you detach and reatt...
176,856
<p>What's the best way for constructing headers, and footers? Should you call it all from the controller, or include it from the view file? I'm using CodeIgniter, and I'm wanting to know what's the best practice for this. Loading all the included view files from the controller, like this?</p> <pre><code>class Page ext...
[ { "answer_id": 176988, "author": "gradbot", "author_id": 17919, "author_profile": "https://Stackoverflow.com/users/17919", "pm_score": 2, "selected": false, "text": "<p>It's bad practice to call views inside of other views. This could be a form of controller view mixing. The view funct...
2008/10/07
[ "https://Stackoverflow.com/questions/176856", "https://Stackoverflow.com", "https://Stackoverflow.com/users/24708/" ]
What's the best way for constructing headers, and footers? Should you call it all from the controller, or include it from the view file? I'm using CodeIgniter, and I'm wanting to know what's the best practice for this. Loading all the included view files from the controller, like this? ``` class Page extends Controlle...
You could also try it this way -- define a default view template, which then pulls in the content based on a variable ('content' in my example) passed by the controller. In your controller: ``` $data['content'] = 'your_controller/index'; // more code... $this->load->vars($data); $this->load->view('layouts/default')...
176,858
<p>In a static view, how can I view an old version of a file?</p> <p>Given an empty file (called <code>empty</code> in this example) I can subvert <code>diff</code> to show me the old version:</p> <pre> % cleartool diff -ser empty File@@/main/28 </pre> <p>This feels like a pretty ugly hack. Have I missed a more ...
[ { "answer_id": 177273, "author": "Chris Arguin", "author_id": 25704, "author_profile": "https://Stackoverflow.com/users/25704", "pm_score": 2, "selected": false, "text": "<p>[ Rewritten based on the first comment ]</p>\n\n<p>All files in Clearcase, including versions, are available in th...
2008/10/07
[ "https://Stackoverflow.com/questions/176858", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17221/" ]
In a static view, how can I view an old version of a file? Given an empty file (called `empty` in this example) I can subvert `diff` to show me the old version: ``` % cleartool diff -ser empty File@@/main/28 ``` This feels like a pretty ugly hack. Have I missed a more basic command? Is there a neater way to do...
> > I'm trying to look at a bunch of old versions > > > I am not sure if you are speaking about "a bunch of old versions" of *one file*, "a bunch of old versions" from *several* files. To visualize several old versions of one file, the simplest mean is to display its version tree (`ct lsvtree -graph File`), and t...
176,902
<p>How do I run a .jar executable java file from outside NetBeans IDE? (Windows Vista). My project has a .jar file created by Netbeans. We'd like to run it. Either: how do we run the file or how do we create a 'proper' executable file in NetBeans 6.1?</p>
[ { "answer_id": 176905, "author": "Laplie Anderson", "author_id": 14204, "author_profile": "https://Stackoverflow.com/users/14204", "pm_score": 4, "selected": false, "text": "<p>Running a jar is as simple as</p>\n\n<pre><code>java -jar filename.jar\n</code></pre>\n" }, { "answer_i...
2008/10/07
[ "https://Stackoverflow.com/questions/176902", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
How do I run a .jar executable java file from outside NetBeans IDE? (Windows Vista). My project has a .jar file created by Netbeans. We'd like to run it. Either: how do we run the file or how do we create a 'proper' executable file in NetBeans 6.1?
Running a jar is as simple as ``` java -jar filename.jar ```
176,913
<p>I basically want to run all JUnit <strong><em>unit</em></strong> tests in my IntelliJ IDEA project (excluding JUnit integration tests), using the static suite() method of JUnit. Why use the static suite() method? Because I can then use IntelliJ IDEA's JUnit test runner to run all unit tests in my application (and ea...
[ { "answer_id": 178030, "author": "Roel Spilker", "author_id": 12634, "author_profile": "https://Stackoverflow.com/users/12634", "pm_score": 4, "selected": true, "text": "<p>I've written some code to do most of the work. It works only if your files are on the local disk instead of in a JA...
2008/10/07
[ "https://Stackoverflow.com/questions/176913", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13041/" ]
I basically want to run all JUnit ***unit*** tests in my IntelliJ IDEA project (excluding JUnit integration tests), using the static suite() method of JUnit. Why use the static suite() method? Because I can then use IntelliJ IDEA's JUnit test runner to run all unit tests in my application (and easily exclude all integr...
I've written some code to do most of the work. It works only if your files are on the local disk instead of in a JAR. All you need is one class in the package. You could, for this purpose, create a Locator.java class, just to be able to find the package. ``` public class ClassEnumerator { public static void main(S...
176,918
<p>Given a list <code>[&quot;foo&quot;, &quot;bar&quot;, &quot;baz&quot;]</code> and an item in the list <code>&quot;bar&quot;</code>, how do I get its index <code>1</code>?</p>
[ { "answer_id": 176921, "author": "Alex Coventry", "author_id": 1941213, "author_profile": "https://Stackoverflow.com/users/1941213", "pm_score": 13, "selected": true, "text": "<pre><code>&gt;&gt;&gt; [&quot;foo&quot;, &quot;bar&quot;, &quot;baz&quot;].index(&quot;bar&quot;)\n1\n</code></...
2008/10/07
[ "https://Stackoverflow.com/questions/176918", "https://Stackoverflow.com", "https://Stackoverflow.com/users/25680/" ]
Given a list `["foo", "bar", "baz"]` and an item in the list `"bar"`, how do I get its index `1`?
``` >>> ["foo", "bar", "baz"].index("bar") 1 ``` Reference: [Data Structures > More on Lists](https://docs.python.org/tutorial/datastructures.html#more-on-lists) Caveats follow ============== Note that while this is perhaps the cleanest way to answer the question *as asked*, `index` is a rather weak component of th...
176,931
<p>How can I get MSBuild to evaluate and print in a <code>&lt;Message /&gt;</code> task an absolute path given a relative path?</p> <p><strong>Property Group</strong></p> <pre><code>&lt;Source_Dir&gt;..\..\..\Public\Server\&lt;/Source_Dir&gt; &lt;Program_Dir&gt;c:\Program Files (x86)\Program\&lt;/Program_Dir&gt; </co...
[ { "answer_id": 177136, "author": "brock.holum", "author_id": 15860, "author_profile": "https://Stackoverflow.com/users/15860", "pm_score": 3, "selected": false, "text": "<p>Wayne is correct that well-known metadata does not apply to properties - only to items. Using properties such as \"...
2008/10/07
[ "https://Stackoverflow.com/questions/176931", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3957/" ]
How can I get MSBuild to evaluate and print in a `<Message />` task an absolute path given a relative path? **Property Group** ``` <Source_Dir>..\..\..\Public\Server\</Source_Dir> <Program_Dir>c:\Program Files (x86)\Program\</Program_Dir> ``` **Task** ``` <Message Importance="low" Text="Copying '$(Source_Dir.FullP...
**In MSBuild 4.0**, the easiest way is the following: ``` $([System.IO.Path]::GetFullPath('$(MSBuildThisFileDirectory)\your\path')) ``` This method works even if the script is `<Import>`ed into another script; the path is relative to the file containing the above code. (consolidated from [Aaron's answer](https://st...
176,964
<p>I want to return top 10 records from each section in one query. Can anyone help with how to do it? Section is one of the columns in the table.</p> <p>Database is SQL Server 2005. I want to return the top 10 by date entered. Sections are business, local, and feature. For one particular date I want only the top (1...
[ { "answer_id": 176970, "author": "sblundy", "author_id": 4893, "author_profile": "https://Stackoverflow.com/users/4893", "pm_score": 2, "selected": false, "text": "<p>Might the <a href=\"http://www.w3schools.com/sql/sql_union.asp\" rel=\"nofollow noreferrer\">UNION</a> operator work for ...
2008/10/07
[ "https://Stackoverflow.com/questions/176964", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14752/" ]
I want to return top 10 records from each section in one query. Can anyone help with how to do it? Section is one of the columns in the table. Database is SQL Server 2005. I want to return the top 10 by date entered. Sections are business, local, and feature. For one particular date I want only the top (10) business r...
If you are using SQL 2005 you can do something like this... ``` SELECT rs.Field1,rs.Field2 FROM ( SELECT Field1,Field2, Rank() over (Partition BY Section ORDER BY RankCriteria DESC ) AS Rank FROM table ) rs WHERE Rank <= 10 ``` If your RankCriteria has ties the...
176,966
<p>I've been looking for the answer for how to use BSWAP for lower 32-bit sub-register of 64-bit register. For example, <code>0x0123456789abcdef</code> is inside RAX register, and I want to change it to <code>0x01234567efcdab89</code> with a single instruction (because of performance).</p> <p>So I tried following inli...
[ { "answer_id": 176981, "author": "Dan Lenski", "author_id": 20789, "author_profile": "https://Stackoverflow.com/users/20789", "pm_score": -1, "selected": false, "text": "<p>Check the assembly output generated by gcc! Use the <code>gcc -s</code> flag to compile the code and generate asm ...
2008/10/07
[ "https://Stackoverflow.com/questions/176966", "https://Stackoverflow.com", "https://Stackoverflow.com/users/25683/" ]
I've been looking for the answer for how to use BSWAP for lower 32-bit sub-register of 64-bit register. For example, `0x0123456789abcdef` is inside RAX register, and I want to change it to `0x01234567efcdab89` with a single instruction (because of performance). So I tried following inline function: ```c #define BSWAP...
Ah, yes, I understand the problem now: the x86-64 processors *[implicitly zero-extend](http://www.x86-64.org/documentation/assembly.html)* the 32-bit registers to 64-bit when doing 32-bit operations (on %eax, %ebx, etc). This is to maintain compatibility with legacy code that expects 32-bit semantics for these registe...
176,983
<p>I am trying to learn CodeIgniter to use for a shopping site, but I am not having luck with the official doc. Does anyone know of anything that will help?</p>
[ { "answer_id": 177010, "author": "csjohnst", "author_id": 1292, "author_profile": "https://Stackoverflow.com/users/1292", "pm_score": 2, "selected": false, "text": "<p>We've used Code Igniter on a couple of projects and found the videos on their site to be helpful for an intro:\n<a href=...
2008/10/07
[ "https://Stackoverflow.com/questions/176983", "https://Stackoverflow.com", "https://Stackoverflow.com/users/25695/" ]
I am trying to learn CodeIgniter to use for a shopping site, but I am not having luck with the official doc. Does anyone know of anything that will help?
re: CSS. I've got my CSS a separate folder at the root. (same place as 'index.php') ... /content/css/main.css Called as: ``` <link href="<?=base_url();?>content/css/main.css" rel="stylesheet" type="text/css" /> ```
176,989
<p>In the early days of C++ when it was bolted on top of C, you could not use NULL as it was defined as <code>(void*)0</code>. You could not assign NULL to any pointer other than <code>void*</code>, which made it kind of useless. Back in those days, it was accepted that you used <code>0</code> (zero) for null pointers....
[ { "answer_id": 177007, "author": "Martin Cote", "author_id": 9936, "author_profile": "https://Stackoverflow.com/users/9936", "pm_score": 9, "selected": true, "text": "<p>Here's Stroustrup's take on this: <a href=\"http://www.stroustrup.com/bs_faq2.html#null\" rel=\"noreferrer\">C++ Style...
2008/10/07
[ "https://Stackoverflow.com/questions/176989", "https://Stackoverflow.com", "https://Stackoverflow.com/users/23744/" ]
In the early days of C++ when it was bolted on top of C, you could not use NULL as it was defined as `(void*)0`. You could not assign NULL to any pointer other than `void*`, which made it kind of useless. Back in those days, it was accepted that you used `0` (zero) for null pointers. To this day, I have continued to u...
Here's Stroustrup's take on this: [C++ Style and Technique FAQ](http://www.stroustrup.com/bs_faq2.html#null) > > In C++, the definition of `NULL` is 0, so there is only an aesthetic difference. I prefer to avoid macros, so I use 0. Another problem with `NULL` is that people sometimes mistakenly believe that it is dif...
177,011
<p>OK I have an array of tserversocket and am using the tag property to keep track of its index. When an event is fired off such as _clientconnect i am using Index := (Sender as TServerSocket).Tag; but i get an error that highlights that line and tells me its an invalid typecast. What am I doing wrong if all I want to ...
[ { "answer_id": 177270, "author": "Chris Latta", "author_id": 20977, "author_profile": "https://Stackoverflow.com/users/20977", "pm_score": 2, "selected": false, "text": "<p>Are you sure Sender is the TServerSocket? Isn't the event defined like below:</p>\n\n<pre><code>procedure TfrmServe...
2008/10/07
[ "https://Stackoverflow.com/questions/177011", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
OK I have an array of tserversocket and am using the tag property to keep track of its index. When an event is fired off such as \_clientconnect i am using Index := (Sender as TServerSocket).Tag; but i get an error that highlights that line and tells me its an invalid typecast. What am I doing wrong if all I want to do...
Are you sure Sender is the TServerSocket? Isn't the event defined like below: ``` procedure TfrmServer.sskServerClientConnect(Sender: TObject; Socket: TCustomWinSocket); ``` In which case your code probably should be: ``` Index := (Socket as TServerSocket).Tag; ``` Have a look at `Sender.ClassName` to see what Se...
177,039
<p>First, two examples:</p> <pre><code>// This works int foo = 43; long lFoo = foo; // This doesn't object foo = (int)43; long? nullFoo = foo as long?; // returns null long lFoo = (long)foo; // throws InvalidCastException if (foo.GetType() == typeof(int)) Console.WriteLine("But foo is an int..."); // This gets wr...
[ { "answer_id": 177057, "author": "tomasr", "author_id": 10292, "author_profile": "https://Stackoverflow.com/users/10292", "pm_score": 2, "selected": false, "text": "<p>When you're casting to a value type you're really forcing an unbox IL operation, which requires that the type you're cas...
2008/10/07
[ "https://Stackoverflow.com/questions/177039", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15537/" ]
First, two examples: ``` // This works int foo = 43; long lFoo = foo; // This doesn't object foo = (int)43; long? nullFoo = foo as long?; // returns null long lFoo = (long)foo; // throws InvalidCastException if (foo.GetType() == typeof(int)) Console.WriteLine("But foo is an int..."); // This gets written out ```...
``` object foo = (int) 43; long lFoo = ((IConvertible) foo).ToInt64(null); ```
177,042
<p>I am having an issue setting up cURL with IIS 6.0, Windows Server 2003, PHP 5.2.6</p> <p>I have installed to <code>C:\PHP</code></p> <pre><code>set PHPRC = C:\PHP\php.ini </code></pre> <p>copied <code>ssleay32.dll</code> and <code>libeay32.dll</code> to <code>C:\PHP</code></p> <p>in php.ini, uncommented the line...
[ { "answer_id": 177112, "author": "Randy", "author_id": 9361, "author_profile": "https://Stackoverflow.com/users/9361", "pm_score": 2, "selected": false, "text": "<p>Make sure php_curl.dll is in the directory listed under \"extension_dir\" in php.ini. If it is already, try restarting IIS...
2008/10/07
[ "https://Stackoverflow.com/questions/177042", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20641/" ]
I am having an issue setting up cURL with IIS 6.0, Windows Server 2003, PHP 5.2.6 I have installed to `C:\PHP` ``` set PHPRC = C:\PHP\php.ini ``` copied `ssleay32.dll` and `libeay32.dll` to `C:\PHP` in php.ini, uncommented the line ``` extension=php_curl.dll extension_dir="C:\PHP\ext" ``` `c:\php\ext` has the ...
Make sure php\_curl.dll is in the directory listed under "extension\_dir" in php.ini. If it is already, try restarting IIS (Apache always needs a restart from me when making php.ini changes). EDIT 1: Try opening up a command prompt to c:\php and running: ``` php -c . -i | find /i "curl" ``` Does it come back with ...
177,052
<p>I am working on integrating geolocation services into a website and the best source of data I've found so far is MaxMind's GeoIP API with GeoLite City data. Even this data seems to often be questionable though. For example, I am located in downtown Palo Alto, but it locates my IP as being in Portola Valley, which ...
[ { "answer_id": 177274, "author": "FryHard", "author_id": 231, "author_profile": "https://Stackoverflow.com/users/231", "pm_score": 0, "selected": false, "text": "<p>I am not sure if this will help, but here is a site that has done a pretty good job of IP mapping. Maybe you could ask them...
2008/10/07
[ "https://Stackoverflow.com/questions/177052", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2168/" ]
I am working on integrating geolocation services into a website and the best source of data I've found so far is MaxMind's GeoIP API with GeoLite City data. Even this data seems to often be questionable though. For example, I am located in downtown Palo Alto, but it locates my IP as being in Portola Valley, which is ab...
Where an IP comes up at the wrong end of the country, you probably won't find a better match elsewhere because it's probably an ISP that uses one group of IPs for customers in a wide area. My favourite example is trains here in the UK where the on-board wifi is identified as being in Sweden because they use a satellite...
177,054
<p>There's a common way to store multiple values in one variable, by using a bitmask. For example, if a user has read, write and execute privileges on an item, that can be converted to a single number by saying <code>read = 4 (2^2), write = 2 (2^1), execute = 1 (2^0)</code> and then add them together to get 7.</p> <p>...
[ { "answer_id": 177066, "author": "Tim Williscroft", "author_id": 2789, "author_profile": "https://Stackoverflow.com/users/2789", "pm_score": 2, "selected": false, "text": "<p>I've used bit masks in filesystem code where the bit mask is many times bigger than a machine word. think of it l...
2008/10/07
[ "https://Stackoverflow.com/questions/177054", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9021/" ]
There's a common way to store multiple values in one variable, by using a bitmask. For example, if a user has read, write and execute privileges on an item, that can be converted to a single number by saying `read = 4 (2^2), write = 2 (2^1), execute = 1 (2^0)` and then add them together to get 7. I use this technique ...
Off the top of my head, I'd write a `set_bit` and `get_bit` function that could take an array of bytes and a bit offset in the array, and use some bit-twiddling to set/get the appropriate bit in the array. Something like this (in C, but hopefully you get the idea): ```c // sets the n-th bit in |bytes|. num_bytes is th...
177,080
<p>Method signature in Java:</p> <pre><code>public List&lt;String&gt; getFilesIn(List&lt;File&gt; directories) </code></pre> <p>similar one in ruby</p> <pre><code>def get_files_in(directories) </code></pre> <p>In the case of Java, the type system gives me information about what the method expects and delivers. In ...
[ { "answer_id": 177103, "author": "Camilo Díaz Repka", "author_id": 861, "author_profile": "https://Stackoverflow.com/users/861", "pm_score": 1, "selected": false, "text": "<p>It's by no means a maintenance nightmare, just another way of working, that calls for consistence in the API and ...
2008/10/07
[ "https://Stackoverflow.com/questions/177080", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3029/" ]
Method signature in Java: ``` public List<String> getFilesIn(List<File> directories) ``` similar one in ruby ``` def get_files_in(directories) ``` In the case of Java, the type system gives me information about what the method expects and delivers. In Ruby's case, I have **no** clue what I'm supposed to pass in, ...
What it comes down to is that `get_files_in` is a bad name *in Ruby* - let me explain. In java/C#/C++, and especially in objective C, the function arguments *are part of the name*. In ruby they are not. The fancy term for this is [Method Overloading](http://en.wikipedia.org/wiki/Method_overloading), and it's enforc...
177,118
<p>I saw this question on Reddit, and there were no positive solutions presented, and I thought it would be a perfect question to ask here. This was in a thread about interview questions:</p> <blockquote> <p>Write a method that takes an int array of size m, and returns (True/False) if the array consists of the numbers ...
[ { "answer_id": 177126, "author": "hazzen", "author_id": 5066, "author_profile": "https://Stackoverflow.com/users/5066", "pm_score": 4, "selected": false, "text": "<p>Under the assumption numbers less than one are not allowed and there are no duplicates, there is a simple summation identi...
2008/10/07
[ "https://Stackoverflow.com/questions/177118", "https://Stackoverflow.com", "https://Stackoverflow.com/users/658/" ]
I saw this question on Reddit, and there were no positive solutions presented, and I thought it would be a perfect question to ask here. This was in a thread about interview questions: > > Write a method that takes an int array of size m, and returns (True/False) if the array consists of the numbers n...n+m-1, all nu...
Under the assumption numbers less than one are not allowed and there are no duplicates, there is a simple summation identity for this - the sum of numbers from `1` to `m` in increments of `1` is `(m * (m + 1)) / 2`. You can then sum the array and use this identity. You can find out if there is a dupe under the above g...
177,133
<p>I am trying to override the DataGridViewTextBoxCell's paint method in a derived class so that I can indent the foreground text by some variable amount of pixels. I would like it if the width of the column adjusts so that its total width is the length of my cells text plus the "buffer" indent. Does anyone know of a...
[ { "answer_id": 177184, "author": "BFree", "author_id": 15861, "author_profile": "https://Stackoverflow.com/users/15861", "pm_score": 2, "selected": false, "text": "<p>You can just hook up to the CellFormattingEvent in the datagridview and do your formatting there. Or, if you're inherting...
2008/10/07
[ "https://Stackoverflow.com/questions/177133", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10446/" ]
I am trying to override the DataGridViewTextBoxCell's paint method in a derived class so that I can indent the foreground text by some variable amount of pixels. I would like it if the width of the column adjusts so that its total width is the length of my cells text plus the "buffer" indent. Does anyone know of a way ...
If you are trying to auto-size the columns (depending on size of the cell contents) then you should look at `Column.AutoSizeMode` property and `Column.DefaultCellStyle` property. ``` static const int INDENTCOEFF = 5; DataGridViewCellStyle cellStyle = new DataGridViewCellStyle(); cellStyle.Padding = new Padd...
177,154
<p>I'm trying to create an instance of a class at run time. The classes I'm trying to create all inherit from a base class, ConfigMgrObj, and are named <code>ConfigMgr_xxxxxx</code> e.g. <code>ConfigMgr_Collection</code>. They all take a special object that I'm calling oController and a string as arguments.</p> <p>Thi...
[ { "answer_id": 177159, "author": "Matt Hamilton", "author_id": 615, "author_profile": "https://Stackoverflow.com/users/615", "pm_score": 4, "selected": true, "text": "<p>Are the types you're trying to instantiate actually declared within the same assembly? Passing null as the first param...
2008/10/07
[ "https://Stackoverflow.com/questions/177154", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5133/" ]
I'm trying to create an instance of a class at run time. The classes I'm trying to create all inherit from a base class, ConfigMgrObj, and are named `ConfigMgr_xxxxxx` e.g. `ConfigMgr_Collection`. They all take a special object that I'm calling oController and a string as arguments. This is the line I'm using to do it...
Are the types you're trying to instantiate actually declared within the same assembly? Passing null as the first parameter is telling Activator that the types live in the current assembly.
177,161
<p>I need to get just the first item (actually, just the first key) off a rather large associative array in JavaScript. Here's how I'm doing it currently (using jQuery):</p> <pre><code>getKey = function (data) { var firstKey; $.each(data, function (key, val) { firstKey = key; return false; ...
[ { "answer_id": 177191, "author": "Jonathan Lonowski", "author_id": 15031, "author_profile": "https://Stackoverflow.com/users/15031", "pm_score": 7, "selected": true, "text": "<p>There isn't really a <strong>first</strong> or <strong>last</strong> element in associative arrays (i.e. objec...
2008/10/07
[ "https://Stackoverflow.com/questions/177161", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11577/" ]
I need to get just the first item (actually, just the first key) off a rather large associative array in JavaScript. Here's how I'm doing it currently (using jQuery): ``` getKey = function (data) { var firstKey; $.each(data, function (key, val) { firstKey = key; return false; }); return...
There isn't really a **first** or **last** element in associative arrays (i.e. objects). The only order you can hope to acquire is the order the elements were saved by the parser -- and no guarantees for consistency with that. But, if you want ***the first to come up***, the classic manner might actually be a bit easi...
177,188
<p>I'm not talking about a post build event for a project. Rather, I want to run an executable automatically after the entire solution is built. Is there a way to do a post build event for the solution?</p>
[ { "answer_id": 177194, "author": "shoosh", "author_id": 9611, "author_profile": "https://Stackoverflow.com/users/9611", "pm_score": 2, "selected": false, "text": "<p>not directly.<br>\nyou can make a project which has a dependency in all other projects and add a post build step to it. Ef...
2008/10/07
[ "https://Stackoverflow.com/questions/177188", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5469/" ]
I'm not talking about a post build event for a project. Rather, I want to run an executable automatically after the entire solution is built. Is there a way to do a post build event for the solution?
Visual Studio 2010 and before ----------------------------- You can do this in the Macro Editor by handling OnBuildDone. The event gives you a couple of handy properties you can check: scope (project/solution/batch) and action (build/rebuild/clean/deploy). To do what you want would be something like this (not tested, ...
177,240
<p>Lets just say you have a table in Oracle:</p> <pre><code>CREATE TABLE person ( id NUMBER PRIMARY KEY, given_names VARCHAR2(50), surname VARCHAR2(50) ); </code></pre> <p>with these function-based indices:</p> <pre><code>CREATE INDEX idx_person_upper_given_names ON person (UPPER(given_names)); CREATE INDEX id...
[ { "answer_id": 177304, "author": "CaptainPicard", "author_id": 15203, "author_profile": "https://Stackoverflow.com/users/15203", "pm_score": 2, "selected": false, "text": "<p>In your example you've created the same index twice - this would give an error so I'm assuming that was a mistake...
2008/10/07
[ "https://Stackoverflow.com/questions/177240", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18393/" ]
Lets just say you have a table in Oracle: ``` CREATE TABLE person ( id NUMBER PRIMARY KEY, given_names VARCHAR2(50), surname VARCHAR2(50) ); ``` with these function-based indices: ``` CREATE INDEX idx_person_upper_given_names ON person (UPPER(given_names)); CREATE INDEX idx_person_upper_last_name ON person (U...
The index can be used, though the optimiser may have chosen not to use it for your particular example: ``` SQL> create table my_objects 2 as select object_id, object_name 3 from all_objects; Table created. SQL> select count(*) from my_objects; 2 / COUNT(*) ---------- 83783 SQL> alter table my_objec...
177,241
<p>I know how to load themes dynamically when they are stored locally. Is it possible to store theses themes in the database yet still apply them programmatically as described in referenced MSDN article?</p> <p>Also - If you do store them in the filesystem, is it possible to change the path of the App_Themes directory...
[ { "answer_id": 177304, "author": "CaptainPicard", "author_id": 15203, "author_profile": "https://Stackoverflow.com/users/15203", "pm_score": 2, "selected": false, "text": "<p>In your example you've created the same index twice - this would give an error so I'm assuming that was a mistake...
2008/10/07
[ "https://Stackoverflow.com/questions/177241", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12442/" ]
I know how to load themes dynamically when they are stored locally. Is it possible to store theses themes in the database yet still apply them programmatically as described in referenced MSDN article? Also - If you do store them in the filesystem, is it possible to change the path of the App\_Themes directory to a dif...
The index can be used, though the optimiser may have chosen not to use it for your particular example: ``` SQL> create table my_objects 2 as select object_id, object_name 3 from all_objects; Table created. SQL> select count(*) from my_objects; 2 / COUNT(*) ---------- 83783 SQL> alter table my_objec...
177,258
<p>Please can someone help me make sense of the Batch madness?</p> <p>I'm trying to debug an Axapta 3.0 implementation that has about 50 Batch Jobs. Most of the batched classes do not implement the <strong><code>description()</code></strong> method, so when you look at the <em>Batch List</em> form (Basic>>Inquiries>>B...
[ { "answer_id": 177357, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 3, "selected": false, "text": "<p>Jay's answer provides two comprehensive solutions. </p>\n\n<p>I've just discovered that the global class <strong>ClassId2Na...
2008/10/07
[ "https://Stackoverflow.com/questions/177258", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
Please can someone help me make sense of the Batch madness? I'm trying to debug an Axapta 3.0 implementation that has about 50 Batch Jobs. Most of the batched classes do not implement the **`description()`** method, so when you look at the *Batch List* form (Basic>>Inquiries>>Batch list) the description field is blank...
Jay's answer provides two comprehensive solutions. I've just discovered that the global class **ClassId2Name** does the same thing, so you can simply have: ``` display str Classname() { return ClassId2Name(this.ClassNum); } ```
177,271
<p>Can anyone provide some pseudo code for a roulette selection function? How would I implement this:</p> <p><img src="https://upload.wikimedia.org/math/0/d/2/0d24a82d8e813380f670bf80ae74486b.png" alt="alt text"></p> <p>I don't really understand how to read this math notation. I never took any probability or statisti...
[ { "answer_id": 177278, "author": "Jarod Elliott", "author_id": 1061, "author_profile": "https://Stackoverflow.com/users/1061", "pm_score": 6, "selected": true, "text": "<p>It's been a few years since i've done this myself, however the following pseudo code was found easily enough on goog...
2008/10/07
[ "https://Stackoverflow.com/questions/177271", "https://Stackoverflow.com", "https://Stackoverflow.com/users/577/" ]
Can anyone provide some pseudo code for a roulette selection function? How would I implement this: ![alt text](https://upload.wikimedia.org/math/0/d/2/0d24a82d8e813380f670bf80ae74486b.png) I don't really understand how to read this math notation. I never took any probability or statistics.
It's been a few years since i've done this myself, however the following pseudo code was found easily enough on google. ``` for all members of population sum += fitness of this individual end for for all members of population probability = sum of probabilities + (fitness / sum) sum of probabilities += pr...
177,277
<p>I have a TreeView control in my WinForms .NET application that has multiple levels of childnodes that have childnodes with more childnodes, with no defined depth. When a user selects any parent node (not necessarily at the root level), how can I get a list of all the nodes beneith that parent node?</p> <p>For examp...
[ { "answer_id": 177282, "author": "Steven A. Lowe", "author_id": 9345, "author_profile": "https://Stackoverflow.com/users/9345", "pm_score": 4, "selected": false, "text": "<p>you need a recursive function to do this [or a loop equivalent, but the recursive version is simpler] - pseudocode...
2008/10/07
[ "https://Stackoverflow.com/questions/177277", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5473/" ]
I have a TreeView control in my WinForms .NET application that has multiple levels of childnodes that have childnodes with more childnodes, with no defined depth. When a user selects any parent node (not necessarily at the root level), how can I get a list of all the nodes beneith that parent node? For example, I star...
Use recursion ``` Function GetChildren(parentNode as TreeNode) as List(Of String) Dim nodes as List(Of String) = New List(Of String) GetAllChildren(parentNode, nodes) return nodes End Function Sub GetAllChildren(parentNode as TreeNode, nodes as List(Of String)) For Each childNode as TreeNode in parentNode.Nod...
177,284
<p>I have a table that looks something like this:</p> <pre> word big expensive smart fast dog 9 -10 -20 4 professor 2 4 40 -7 ferrari 7 50 0 48 alaska 10 0 1 0 gnat -3 0 0 0 </pre> <p>Th...
[ { "answer_id": 177302, "author": "Toby Hede", "author_id": 14971, "author_profile": "https://Stackoverflow.com/users/14971", "pm_score": 0, "selected": false, "text": "<p>Can you use the built-in database aggregate functions like MAX(column)?</p>\n" }, { "answer_id": 177308, ...
2008/10/07
[ "https://Stackoverflow.com/questions/177284", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11596/" ]
I have a table that looks something like this: ``` word big expensive smart fast dog 9 -10 -20 4 professor 2 4 40 -7 ferrari 7 50 0 48 alaska 10 0 1 0 gnat -3 0 0 0 ``` The + and - val...
abs value fartherest from zero: ``` select max(abs(mycol)) from mytbl ``` will be zero if the value is negative: ``` select n+abs(mycol) from zzz where abs(mycol)=(select max(abs(mycol)) from mytbl); ```
177,287
<p>Is it possible to produce an alert similar to JavaScript's alert("message") in python, with an application running as a daemon.</p> <p>This will be run in Windows, Most likely XP but 2000 and Vista are also very real possibilities.</p> <p>Update:<br /> This is intended to run in the background and alert the user w...
[ { "answer_id": 177312, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 7, "selected": true, "text": "<p>what about this:</p>\n\n<pre><code>import win32api\n\nwin32api.MessageBox(0, 'hello', 'title')\n</code></pre>\n\n<p>Addition...
2008/10/07
[ "https://Stackoverflow.com/questions/177287", "https://Stackoverflow.com", "https://Stackoverflow.com/users/115/" ]
Is it possible to produce an alert similar to JavaScript's alert("message") in python, with an application running as a daemon. This will be run in Windows, Most likely XP but 2000 and Vista are also very real possibilities. Update: This is intended to run in the background and alert the user when certain conditio...
what about this: ``` import win32api win32api.MessageBox(0, 'hello', 'title') ``` Additionally: ``` win32api.MessageBox(0, 'hello', 'title', 0x00001000) ``` will make the box appear on top of other windows, for urgent messages. See [MessageBox function](http://msdn.microsoft.com/en-us/library/windows/desktop/ms...
177,323
<p>What is the most efficient way to read the last row with SQL Server?</p> <p>The table is indexed on a unique key -- the "bottom" key values represent the last row.</p>
[ { "answer_id": 177325, "author": "willurd", "author_id": 1943957, "author_profile": "https://Stackoverflow.com/users/1943957", "pm_score": 4, "selected": false, "text": "<p>You'll need some sort of uniquely identifying column in your table, like an auto-filling primary key or a datetime ...
2008/10/07
[ "https://Stackoverflow.com/questions/177323", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2536/" ]
What is the most efficient way to read the last row with SQL Server? The table is indexed on a unique key -- the "bottom" key values represent the last row.
If you're using MS SQL, you can try: ``` SELECT TOP 1 * FROM table_Name ORDER BY unique_column DESC ```
177,373
<p>I have a generic list...</p> <p>public List&lt;ApprovalEventDto&gt; ApprovalEvents</p> <p>The ApprovalEventDto has </p> <pre><code>public class ApprovalEventDto { public string Event { get; set; } public DateTime EventDate { get; set; } } </code></pre> <p>How do I sort the list by the event date?</p>
[ { "answer_id": 177377, "author": "SmacL", "author_id": 22564, "author_profile": "https://Stackoverflow.com/users/22564", "pm_score": -1, "selected": false, "text": "<p>Merge sorts work very well for lists. See <a href=\"http://en.wikipedia.org/wiki/Merge_sort\" rel=\"nofollow noreferrer...
2008/10/07
[ "https://Stackoverflow.com/questions/177373", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6268/" ]
I have a generic list... public List<ApprovalEventDto> ApprovalEvents The ApprovalEventDto has ``` public class ApprovalEventDto { public string Event { get; set; } public DateTime EventDate { get; set; } } ``` How do I sort the list by the event date?
You can use List.Sort() as follows: ``` ApprovalEvents.Sort((lhs, rhs) => (lhs.EventDate.CompareTo(rhs.EventDate))); ```
177,389
<p>This question will expand on: <a href="https://stackoverflow.com/questions/68774/best-way-to-open-a-socket-in-python">Best way to open a socket in Python</a><br /> When opening a socket how can I test to see if it has been established, and that it did not timeout, or generally fail. <br /><br /> Edit: I tried this:<...
[ { "answer_id": 177411, "author": "kender", "author_id": 4172, "author_profile": "https://Stackoverflow.com/users/4172", "pm_score": 7, "selected": true, "text": "<p>It seems that you catch not the exception you wanna catch out there :)</p>\n\n<p>if the <code>s</code> is a <code>socket.so...
2008/10/07
[ "https://Stackoverflow.com/questions/177389", "https://Stackoverflow.com", "https://Stackoverflow.com/users/115/" ]
This question will expand on: [Best way to open a socket in Python](https://stackoverflow.com/questions/68774/best-way-to-open-a-socket-in-python) When opening a socket how can I test to see if it has been established, and that it did not timeout, or generally fail. Edit: I tried this: ``` try: s.connect((addr...
It seems that you catch not the exception you wanna catch out there :) if the `s` is a `socket.socket()` object, then the right way to call `.connect` would be: ``` import socket s = socket.socket() address = '127.0.0.1' port = 80 # port number is a number, not string try: s.connect((address, port)) # origi...
177,393
<p>In our code we used to have something like this:</p> <pre><code> *(controller-&gt;bigstruct) = ( struct bigstruct ){ 0 }; </code></pre> <p>This used to work great, and then we upgraded versions of GCC and suddenly started seeing stack overflows. Looking at the assembly, the old GCC code (2.x) was basically doing...
[ { "answer_id": 177401, "author": "SmacL", "author_id": 22564, "author_profile": "https://Stackoverflow.com/users/22564", "pm_score": 3, "selected": false, "text": "<p>If you don't want to use memset, you could always declare a static copy of your struct and use memcpy, which will give si...
2008/10/07
[ "https://Stackoverflow.com/questions/177393", "https://Stackoverflow.com", "https://Stackoverflow.com/users/25704/" ]
In our code we used to have something like this: ``` *(controller->bigstruct) = ( struct bigstruct ){ 0 }; ``` This used to work great, and then we upgraded versions of GCC and suddenly started seeing stack overflows. Looking at the assembly, the old GCC code (2.x) was basically doing this: ``` memset(controller...
memset is the way to go. You do not have many alternatives. Do something like: ``` #define InitStruct(var, type) type var; memset(&var, 0, sizeof(type)) ``` So that you only have to: ``` InitStruct(st, BigStruct); ``` And then use st as usual... I do not get how "0" is not a valid "0" type for a struct. The on...
177,437
<pre><code>const static int foo = 42; </code></pre> <p>I saw this in some code here on StackOverflow and I couldn't figure out what it does. Then I saw some confused answers on other forums. My best guess is that it's used in C to hide the constant <code>foo</code> from other modules. Is this correct? If so, why would...
[ { "answer_id": 177443, "author": "Kevin", "author_id": 6386, "author_profile": "https://Stackoverflow.com/users/6386", "pm_score": 3, "selected": false, "text": "<p>It's missing an 'int'. It should be:</p>\n\n<pre><code>const static int foo = 42;\n</code></pre>\n\n<p>In C and C++, it de...
2008/10/07
[ "https://Stackoverflow.com/questions/177437", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2079/" ]
``` const static int foo = 42; ``` I saw this in some code here on StackOverflow and I couldn't figure out what it does. Then I saw some confused answers on other forums. My best guess is that it's used in C to hide the constant `foo` from other modules. Is this correct? If so, why would anyone use it in a C++ contex...
It has uses in both C and C++. As you guessed, the `static` part limits its scope to that [compilation unit](https://stackoverflow.com/questions/1106149/what-is-a-translation-unit-in-c). It also provides for static initialization. `const` just tells the compiler to not let anybody modify it. This variable is either pu...
177,496
<p>I have a simple HTML. I am using the JQuery for AJAX purpose. Now, I want to put my javascript function in a separate javascript file. What is the syntax for this? For example, currently my script section in the HTML is something like this:</p> <pre><code>&lt;script&gt; &lt;script type="text/javascript" src="scrip...
[ { "answer_id": 177499, "author": "Mote", "author_id": 24789, "author_profile": "https://Stackoverflow.com/users/24789", "pm_score": -1, "selected": false, "text": "<pre><code>$('head').append('&amp;lt;script type=\"text/javascript\" src=\"scripts/scripts.js\"/&amp;gt;')\n</code></pre>\n"...
2008/10/07
[ "https://Stackoverflow.com/questions/177496", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3834/" ]
I have a simple HTML. I am using the JQuery for AJAX purpose. Now, I want to put my javascript function in a separate javascript file. What is the syntax for this? For example, currently my script section in the HTML is something like this: ``` <script> <script type="text/javascript" src="scripts/scripts.js"></script>...
Move the scripts.js `script` tag down beneath the jQuery `script` tag and then just move the whole of that inline script block into scripts.js. As jQuery will already have been instantiated by the time scripts.js loads, the Javascript will just execute inline in the same way that it does at the moment. Also on a separ...
177,506
<pre class="lang-cpp prettyprint-override"><code>double r = 11.631; double theta = 21.4; </code></pre> <p>In the debugger, these are shown as <code>11.631000000000000</code> and <code>21.399999618530273</code>.</p> <p>How can I avoid this?</p>
[ { "answer_id": 177512, "author": "Konrad Rudolph", "author_id": 1968, "author_profile": "https://Stackoverflow.com/users/1968", "pm_score": 7, "selected": true, "text": "<p>These <a href=\"http://en.wikipedia.org/wiki/Floating_point_number#Accuracy_problems\" rel=\"noreferrer\">accuracy ...
2008/10/07
[ "https://Stackoverflow.com/questions/177506", "https://Stackoverflow.com", "https://Stackoverflow.com/users/22076/" ]
```cpp double r = 11.631; double theta = 21.4; ``` In the debugger, these are shown as `11.631000000000000` and `21.399999618530273`. How can I avoid this?
These [accuracy problems](http://en.wikipedia.org/wiki/Floating_point_number#Accuracy_problems) are due to the [internal representation](http://en.wikipedia.org/wiki/Floating_point_number#Internal_representation) of floating point numbers and there's not much you can do to avoid it. By the way, printing these values a...
177,520
<p>I am wondering if there are any alternatives to using the Expand key word when performing an LINQ to ADO.net Data Services query. The expand method does get me the data I am interested in, but it requires me to know all of the sub-objects that I am going to be working with in advance. My absolute preference would ...
[ { "answer_id": 178391, "author": "Craig Stuntz", "author_id": 7714, "author_profile": "https://Stackoverflow.com/users/7714", "pm_score": 2, "selected": false, "text": "<p>With LINQ to Entities you can also use the <a href=\"http://msdn.microsoft.com/en-us/library/bb896272.aspx\" rel=\"n...
2008/10/07
[ "https://Stackoverflow.com/questions/177520", "https://Stackoverflow.com", "https://Stackoverflow.com/users/25719/" ]
I am wondering if there are any alternatives to using the Expand key word when performing an LINQ to ADO.net Data Services query. The expand method does get me the data I am interested in, but it requires me to know all of the sub-objects that I am going to be working with in advance. My absolute preference would be th...
Loading sub-objects via ADO.net Data Services seem to have two choices: Eager Loading ------------- Accomplished by .Expand("[MemberVariableName]") on the LINQ to Data Services example ``` var me = (from m in ctx.Member.Expand("MailingAddress") where m.MemberID == 10000 select m...
177,536
<p>Is there a simple way to prevent browser from downloading and displaying images, best would be via some magic style tag or javasctipe.</p> <p>The thing is, I'd like to tweak the company's website a bit to be more usable via mobile devices. The company is a gaming one, there's like 5MBs of images on it's main page (...
[ { "answer_id": 177549, "author": "Gene", "author_id": 22673, "author_profile": "https://Stackoverflow.com/users/22673", "pm_score": 1, "selected": false, "text": "<p>I would not rely on javascript or any other client side method with mobile browsers. Most mobile browsers just don't suppo...
2008/10/07
[ "https://Stackoverflow.com/questions/177536", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4172/" ]
Is there a simple way to prevent browser from downloading and displaying images, best would be via some magic style tag or javasctipe. The thing is, I'd like to tweak the company's website a bit to be more usable via mobile devices. The company is a gaming one, there's like 5MBs of images on it's main page (and those ...
You can use htaccess to redirect image requests made from mobile browser users. I haven't tested this but it should work: ``` RewriteCond %{HTTP_USER_AGENT} (nokia¦symbian¦iphone¦blackberry) [NC] RewriteCond %{REQUEST_URI} !^/images/$ RewriteRule (.*) /blank.jpg [L] ``` This code redirects all requests made to file...
177,538
<p>Every time I need to do something <em>N</em> times inside an algorithm using C# I write this code</p> <pre><code>for (int i = 0; i &lt; N; i++) { ... } </code></pre> <p>Studying Ruby I have learned about method <em>times()</em> which can be used with the same semantics like this</p> <pre><code>N.times do ...
[ { "answer_id": 177551, "author": "cvk", "author_id": 25397, "author_profile": "https://Stackoverflow.com/users/25397", "pm_score": 4, "selected": false, "text": "<p>It is indeed possible with C# 3.0:</p>\n\n<pre><code>public interface ILoopIterator\n{\n void Do(Action action);\n vo...
2008/10/07
[ "https://Stackoverflow.com/questions/177538", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11256/" ]
Every time I need to do something *N* times inside an algorithm using C# I write this code ``` for (int i = 0; i < N; i++) { ... } ``` Studying Ruby I have learned about method *times()* which can be used with the same semantics like this ``` N.times do ... end ``` Code fragment in C# looks more complex a...
A slightly briefer version of [cvk's answer](https://stackoverflow.com/questions/177538/any-chances-to-imitate-times-ruby-method-in-c#177551): ``` public static class Extensions { public static void Times(this int count, Action action) { for (int i=0; i < count; i++) { action(); ...
177,560
<p>I have an app written in C# that lies on a network share. When I run it from a local drive, everything works fine. When I start it from the remote share, calls like</p> <pre><code>try { System.Reflection.Assembly.GetExecutingAssembly(); System.IO.Directory.GetCurrentDirectory(); } </code></pre> <p>throw a ...
[ { "answer_id": 177580, "author": "Marc Gravell", "author_id": 23354, "author_profile": "https://Stackoverflow.com/users/23354", "pm_score": 4, "selected": true, "text": "<p>This is due to <a href=\"http://msdn.microsoft.com/en-us/library/930b76w0.aspx\" rel=\"nofollow noreferrer\">CAS</a...
2008/10/07
[ "https://Stackoverflow.com/questions/177560", "https://Stackoverflow.com", "https://Stackoverflow.com/users/22114/" ]
I have an app written in C# that lies on a network share. When I run it from a local drive, everything works fine. When I start it from the remote share, calls like ``` try { System.Reflection.Assembly.GetExecutingAssembly(); System.IO.Directory.GetCurrentDirectory(); } ``` throw a SecurityException 'Request...
This is due to [CAS](http://msdn.microsoft.com/en-us/library/930b76w0.aspx); code started from the local machine has much more trust than code in the intranet, which in turn has more trust that code from the internet. IIRC, with the latest SP (3.5SP1?) if you have *mapped* the share (i.e. as F:) it is trusted; otherwi...
177,569
<p>I have Eclipse 3.3.2 with PDT doing PHP development. All projects that I create, even SVN projects have code completion. Now I just opened another SVN project and it has no code completion or PHP templates (CTRL-space does nothing in that project). However, I can open the other projects and code completion all work ...
[ { "answer_id": 177601, "author": "Guido", "author_id": 12388, "author_profile": "https://Stackoverflow.com/users/12388", "pm_score": 6, "selected": true, "text": "<p>Maybe Eclipse doesn't understand the project has a \"PHP nature\".\nTry comparing the .project file on both projects to lo...
2008/10/07
[ "https://Stackoverflow.com/questions/177569", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4639/" ]
I have Eclipse 3.3.2 with PDT doing PHP development. All projects that I create, even SVN projects have code completion. Now I just opened another SVN project and it has no code completion or PHP templates (CTRL-space does nothing in that project). However, I can open the other projects and code completion all work in ...
Maybe Eclipse doesn't understand the project has a "PHP nature". Try comparing the .project file on both projects to look for differences. It should contain something like: ``` <natures> <nature>org.eclipse.php.core.PHPNature</nature> </natures> ``` The .project file will be in your workspace under the project d...
177,606
<p>I am running windows XP with ruby 1.8.6 patchlevel 111. I am using HTTP to connect to a remote server and it has been running fine. All of a sudden it started to through the exception listed below (I did not change any code since the last time I ran it successfully). Does anybody know what is going on?</p> <pre> ...
[ { "answer_id": 177656, "author": "Vinko Vrsalovic", "author_id": 5190, "author_profile": "https://Stackoverflow.com/users/5190", "pm_score": 1, "selected": false, "text": "<p>Maybe the remote host is down? Or a new firewall has been put between your machine and the remote host?</p>\n\n<p...
2008/10/07
[ "https://Stackoverflow.com/questions/177606", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5004/" ]
I am running windows XP with ruby 1.8.6 patchlevel 111. I am using HTTP to connect to a remote server and it has been running fine. All of a sudden it started to through the exception listed below (I did not change any code since the last time I ran it successfully). Does anybody know what is going on? ``` c:/ruby/li...
Maybe the remote host is down? Or a new firewall has been put between your machine and the remote host? "Timeout::Error" usually points to that direction.
177,611
<p>I am creating an Eclipse RCP application.</p> <p>I am following Joel's advice in the following article "Daily Builds are your friend":</p> <p><a href="http://www.joelonsoftware.com/articles/fog0000000023.html" rel="nofollow noreferrer">http://www.joelonsoftware.com/articles/fog0000000023.html</a></p> <p>So, I've ...
[ { "answer_id": 178237, "author": "Tom", "author_id": 20979, "author_profile": "https://Stackoverflow.com/users/20979", "pm_score": 4, "selected": true, "text": "<p>sure its easy, Inno project is a plain text file so you can even edit setupper script easily by ant, however I would recomm...
2008/10/07
[ "https://Stackoverflow.com/questions/177611", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2309/" ]
I am creating an Eclipse RCP application. I am following Joel's advice in the following article "Daily Builds are your friend": <http://www.joelonsoftware.com/articles/fog0000000023.html> So, I've written a nice build script that creates an Eclipse RCP product and that runs unit tests on the code. All results are th...
sure its easy, Inno project is a plain text file so you can even edit setupper script easily by ant, however I would recommend creating a separate small include file by your script. You can have store there "variables" such as version+build number that you show in begin of setup. put this line to your setupper: ``` #...
177,613
<p>My <code>Account</code> model has the following two associations:</p> <pre><code>has_many :expenses, :order =&gt; 'expenses.dated_on DESC', :dependent =&gt; :destroy has_many :recent_expenses, :class_name =&gt; 'Expense', :conditions =&gt; "expenses.dated_on &lt;= '#{D...
[ { "answer_id": 177794, "author": "Andrew", "author_id": 17408, "author_profile": "https://Stackoverflow.com/users/17408", "pm_score": 4, "selected": true, "text": "<p>Rails is building the query when loaded and then will re-use that query every time you call @account.recent_expenses whic...
2008/10/07
[ "https://Stackoverflow.com/questions/177613", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1174/" ]
My `Account` model has the following two associations: ``` has_many :expenses, :order => 'expenses.dated_on DESC', :dependent => :destroy has_many :recent_expenses, :class_name => 'Expense', :conditions => "expenses.dated_on <= '#{Date.today}'", :order => 'dated...
Rails is building the query when loaded and then will re-use that query every time you call @account.recent\_expenses which is exactly what you're experiencing. If you're using Rails 2.1 you can use named\_scope to achieve what you're looking for. in your **Expense** model, put the following: ``` named_scope :recent...
177,638
<p>I had a little discussion with a friend about the usage of collections in return/input values of a method. He told me that we have to use - the most derived type for return values. - the least derived type for input parameters.</p> <p>So, it means that, for example, a method has to get a ReadOnlyCollection as param...
[ { "answer_id": 177647, "author": "Joe", "author_id": 13087, "author_profile": "https://Stackoverflow.com/users/13087", "pm_score": 4, "selected": true, "text": "<p>Regarding input parameters, it's generally more flexible to use the least specific type. For example, if all your method is...
2008/10/07
[ "https://Stackoverflow.com/questions/177638", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12703/" ]
I had a little discussion with a friend about the usage of collections in return/input values of a method. He told me that we have to use - the most derived type for return values. - the least derived type for input parameters. So, it means that, for example, a method has to get a ReadOnlyCollection as parameter, and ...
Regarding input parameters, it's generally more flexible to use the least specific type. For example, if all your method is going to do is enumerate the items in a collection passed as an argument, it's more flexible to accept IEnumerable<T>. For example, consider a method "ProcessCustomers" that accepts a parameter t...
177,640
<p>How can I programmatically lock/unlock, or otherwise prevent/enable editing, a source file on Linux using C++.</p> <p>I want to be able to lock source file so that if I open it in an editor it will not allow me to save back to the same source file.</p> <p>I am thinking of maybe changing the permissions to read-onl...
[ { "answer_id": 177646, "author": "David Dibben", "author_id": 5022, "author_profile": "https://Stackoverflow.com/users/5022", "pm_score": 4, "selected": true, "text": "<p>Try man fchmod:</p>\n\n<pre>\nNAME\n chmod, fchmod - change permissions of a file\n\nSYNOPSIS\n #include ...
2008/10/07
[ "https://Stackoverflow.com/questions/177640", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15161/" ]
How can I programmatically lock/unlock, or otherwise prevent/enable editing, a source file on Linux using C++. I want to be able to lock source file so that if I open it in an editor it will not allow me to save back to the same source file. I am thinking of maybe changing the permissions to read-only (and change it ...
Try man fchmod: ``` NAME chmod, fchmod - change permissions of a file SYNOPSIS #include <sys/types.h> #include <sys/stat.h> int chmod(const char *path, mode_t mode); int fchmod(int fildes, mode_t mode); ```
177,673
<p>I have a strongly-typed MVC View Control which is responsible for the UI where users can create and edit Client items. I'd like them to be able to define the <code>ClientId</code> on creation, but not edit, and this to be reflected in the UI.</p> <p>To this end, I have the following line:</p> <pre><code>&lt;%= Ht...
[ { "answer_id": 178024, "author": "Panos", "author_id": 8049, "author_profile": "https://Stackoverflow.com/users/8049", "pm_score": 6, "selected": true, "text": "<p>Tough problem... However, if you want to define only the <code>readonly</code> attribute, you can do it like this:</p>\n\n<p...
2008/10/07
[ "https://Stackoverflow.com/questions/177673", "https://Stackoverflow.com", "https://Stackoverflow.com/users/192/" ]
I have a strongly-typed MVC View Control which is responsible for the UI where users can create and edit Client items. I'd like them to be able to define the `ClientId` on creation, but not edit, and this to be reflected in the UI. To this end, I have the following line: ``` <%= Html.TextBox("Client.ClientId", ViewDa...
Tough problem... However, if you want to define only the `readonly` attribute, you can do it like this: ``` <%= Html.TextBox("Client.ClientId", ViewData.Model.ClientId, ViewData.Model.ClientId != null && ViewData.Model.ClientId.Length > 0 ? new { @readonly = "readonly" } : null) %> ``` If you want to ...
177,677
<p>I am trying to uncompress some data created in VB6 using the zlib API.</p> <p>I have read this is possible with the qUncompress function: <a href="http://doc.trolltech.com/4.4/qbytearray.html#qUncompress" rel="nofollow noreferrer">http://doc.trolltech.com/4.4/qbytearray.html#qUncompress</a></p> <p>I have read the ...
[ { "answer_id": 177793, "author": "Mike G.", "author_id": 18901, "author_profile": "https://Stackoverflow.com/users/18901", "pm_score": 3, "selected": true, "text": "<p>I haven't used VB6 in <em>ages</em>, so I hope this is approximately correct. I <em>think</em> that vb6 used () for arr...
2008/10/07
[ "https://Stackoverflow.com/questions/177677", "https://Stackoverflow.com", "https://Stackoverflow.com/users/24459/" ]
I am trying to uncompress some data created in VB6 using the zlib API. I have read this is possible with the qUncompress function: <http://doc.trolltech.com/4.4/qbytearray.html#qUncompress> I have read the data in from QDataStream via readRawBytes into a char array, which I then converted to a QByteArray for decompre...
I haven't used VB6 in *ages*, so I hope this is approximately correct. I *think* that vb6 used () for array indexing. If I got anything wrong, please let me know. Looking at the qUncompress docs, you should have put your data in your QByteArray starting at byte 5 (I'm going to assume that you left the array index base...
177,708
<p>I can't retrieve cookie maxage it always returns -1</p> <p>Creating cookie:</p> <pre><code>Cookie securityCookie = new Cookie("sec", "somevalue"); securityCookie.setMaxAge(EXPIRATION_TIME); </code></pre> <p>Retrieve cookie:</p> <pre><code>Cookie[] cookies = request.getCookies(); if (cookies != null) { for(in...
[ { "answer_id": 177790, "author": "Lazarin", "author_id": 24124, "author_profile": "https://Stackoverflow.com/users/24124", "pm_score": 1, "selected": false, "text": "<p>The API says that -1 means until browser is running: </p>\n\n<blockquote>\n <p>Returns the maximum age of the cookie, ...
2008/10/07
[ "https://Stackoverflow.com/questions/177708", "https://Stackoverflow.com", "https://Stackoverflow.com/users/23968/" ]
I can't retrieve cookie maxage it always returns -1 Creating cookie: ``` Cookie securityCookie = new Cookie("sec", "somevalue"); securityCookie.setMaxAge(EXPIRATION_TIME); ``` Retrieve cookie: ``` Cookie[] cookies = request.getCookies(); if (cookies != null) { for(int i=0; i<cookies.length; i++) { Cook...
When a browser sends a cookie back to the origin server, it doesn't include any age. So it is logical that your "retrieve" code above does not receive a max age: it is not included in the request. When the cookie is received from the server, the browser uses the max age parameter to determine how long the cookie shoul...
177,717
<p>Please share you experiences regarding how you localized your WPF applications to support multiple languages and any resources that helped you in it?</p> <p>Thanks for your feedbacks.</p>
[ { "answer_id": 181456, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 0, "selected": false, "text": "<p>Sorry if it is vague (above question),basically it about how you implemented it in your application and what you felt was t...
2008/10/07
[ "https://Stackoverflow.com/questions/177717", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
Please share you experiences regarding how you localized your WPF applications to support multiple languages and any resources that helped you in it? Thanks for your feedbacks.
For our WPF application, all of our strings are localized as resources in a `ResourceDictionary` that we put in a .xaml file named after the language (like en-US.xaml, ja-JP.xaml, etc). For example, somewhere in the application a button might look like this: ``` <Button Content="{StaticResource Strings.FooDialog.BarB...
177,719
<p>I'm trying to get a case-insensitive search with two strings in JavaScript working.</p> <p>Normally it would be like this:</p> <pre><code>var string="Stackoverflow is the BEST"; var result= string.search(/best/i); alert(result); </code></pre> <p>The <code>/i</code> flag would be for case-insensitive.</p> <p>But ...
[ { "answer_id": 177724, "author": "Dan", "author_id": 17121, "author_profile": "https://Stackoverflow.com/users/17121", "pm_score": 10, "selected": true, "text": "<p>Yeah, use <code>.match</code>, rather than <code>.search</code>. The result from the <code>.match</code> call will return t...
2008/10/07
[ "https://Stackoverflow.com/questions/177719", "https://Stackoverflow.com", "https://Stackoverflow.com/users/25741/" ]
I'm trying to get a case-insensitive search with two strings in JavaScript working. Normally it would be like this: ``` var string="Stackoverflow is the BEST"; var result= string.search(/best/i); alert(result); ``` The `/i` flag would be for case-insensitive. But I need to search for a second string; without the f...
Yeah, use `.match`, rather than `.search`. The result from the `.match` call will return the actual string that was matched itself, but it can still be used as a boolean value. ``` var string = "Stackoverflow is the BEST"; var result = string.match(/best/i); // result == 'BEST'; if (result){ alert('Matched'); } ...
177,722
<p>Perl has several built-in functions for accessing /etc/passwd on Unix systems (and elsewhere when supported) for user and group information. For instance,</p> <pre><code>my $name = getpwuid($uid); </code></pre> <p>will return the user name given the user ID, or undef if there is no such user.</p> <p>If a Perl scr...
[ { "answer_id": 177865, "author": "David Webb", "author_id": 3171, "author_profile": "https://Stackoverflow.com/users/3171", "pm_score": 3, "selected": false, "text": "<p>You could use the <a href=\"http://aspn.activestate.com/ASPN/CodeDoc/libwin32/NetAdmin/NetAdmin.html\" rel=\"nofollow ...
2008/10/07
[ "https://Stackoverflow.com/questions/177722", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
Perl has several built-in functions for accessing /etc/passwd on Unix systems (and elsewhere when supported) for user and group information. For instance, ``` my $name = getpwuid($uid); ``` will return the user name given the user ID, or undef if there is no such user. If a Perl script needs to be portable and run ...
You could use the [`Win32::NetAdmin` module](http://aspn.activestate.com/ASPN/CodeDoc/libwin32/NetAdmin/NetAdmin.html). `UserGetAttributes` and `GroupIsMember` look like they do what you need.
177,723
<p>I'm currently working on a project that depends on me providing a path to a file (eg. <code>C:\Path.pth</code>). Now, I had everything working yesterday by calling my <code>std::string</code> with:</p> <pre><code>std::string path(`"C:\\Path.pth`"); </code></pre> <p>But now it doesn't work. It throws a <code>bad_al...
[ { "answer_id": 177730, "author": "Danny Whitt", "author_id": 375, "author_profile": "https://Stackoverflow.com/users/375", "pm_score": 0, "selected": false, "text": "<p>Define the string as: \"C:\\\\Path.pth\"</p>\n" }, { "answer_id": 177731, "author": "user22044", "autho...
2008/10/07
[ "https://Stackoverflow.com/questions/177723", "https://Stackoverflow.com", "https://Stackoverflow.com/users/25745/" ]
I'm currently working on a project that depends on me providing a path to a file (eg. `C:\Path.pth`). Now, I had everything working yesterday by calling my `std::string` with: ``` std::string path(`"C:\\Path.pth`"); ``` But now it doesn't work. It throws a `bad_alloc`. Seems like the '`\`' character is the problem. ...
As your error suggest, the problem is due to **memory allocation** (i.e. the bad\_alloc exception). So either you have no more memory (unlikely) or you have a buffer overrun somewhere before (quite likely in my opinion) or some other memory issues like double free. In short, you do something that messes up the memory...
177,727
<p>When I add &amp;nbsp; or &amp;eacute; to a text value of a listitem, it display the code of the HTML entity instead of the result (a space or é).</p> <p>I can add "physical" non-breaking spaces or special chars, but I would like to avoid that if possible. Sometimes the data stored in database is encoded, and I don'...
[ { "answer_id": 177737, "author": "Quentin", "author_id": 19068, "author_profile": "https://Stackoverflow.com/users/19068", "pm_score": 0, "selected": false, "text": "<p>Standard drop down lists are very poor at representing treeviews . </p>\n\n<p>They can handle going one level deep if t...
2008/10/07
[ "https://Stackoverflow.com/questions/177727", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6776/" ]
When I add &nbsp; or &eacute; to a text value of a listitem, it display the code of the HTML entity instead of the result (a space or é). I can add "physical" non-breaking spaces or special chars, but I would like to avoid that if possible. Sometimes the data stored in database is encoded, and I don't want to always p...
ListItems are automatically HtmlEncoded. You can HtmlDecode the list items before hand, so when they are HtmlEncoded you get the proper characters: ``` DropDownList1.DataSource = new List<string> { Server.HtmlDecode("A&hellip;"), Server.HtmlDecode("B&nbsp;C") }; DropDownList1.DataBind(); ```
177,747
<p>We have a "master database structure", and need a routine to keep the database structure on client sites up-to-date.</p> <p>A number of suggestions have been given <a href="https://stackoverflow.com/questions/115389/update-sql-sever-database-schema-with-software-update" title="here">to a related question</a>, but I...
[ { "answer_id": 177737, "author": "Quentin", "author_id": 19068, "author_profile": "https://Stackoverflow.com/users/19068", "pm_score": 0, "selected": false, "text": "<p>Standard drop down lists are very poor at representing treeviews . </p>\n\n<p>They can handle going one level deep if t...
2008/10/07
[ "https://Stackoverflow.com/questions/177747", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18651/" ]
We have a "master database structure", and need a routine to keep the database structure on client sites up-to-date. A number of suggestions have been given [to a related question](https://stackoverflow.com/questions/115389/update-sql-sever-database-schema-with-software-update "here"), but I am looking for a more spec...
ListItems are automatically HtmlEncoded. You can HtmlDecode the list items before hand, so when they are HtmlEncoded you get the proper characters: ``` DropDownList1.DataSource = new List<string> { Server.HtmlDecode("A&hellip;"), Server.HtmlDecode("B&nbsp;C") }; DropDownList1.DataBind(); ```
177,750
<p>I am trying to get some XML data with LINQ, but running into a problem.</p> <p>I am using a schema, which is set in the attribute xmlns ...</p> <pre><code>&lt;CarsForSale xmlns="http://schemas.sharplogic.net/CarSales.xsd"&gt; &lt;CarForSale&gt; </code></pre> <p>There are many CarForSale elements.</p> <p>When t...
[ { "answer_id": 177754, "author": "Mark Cidade", "author_id": 1659, "author_profile": "https://Stackoverflow.com/users/1659", "pm_score": 4, "selected": true, "text": "<p>You need to prepend the namespace:</p>\n\n<pre><code>var ns = \"http://schemas.sharplogic.net/CarSales.xsd\";\nvar ...
2008/10/07
[ "https://Stackoverflow.com/questions/177750", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6125/" ]
I am trying to get some XML data with LINQ, but running into a problem. I am using a schema, which is set in the attribute xmlns ... ``` <CarsForSale xmlns="http://schemas.sharplogic.net/CarSales.xsd"> <CarForSale> ``` There are many CarForSale elements. When the schema is set and I do this... ``` XElement doc ...
You need to prepend the namespace: ``` var ns = "http://schemas.sharplogic.net/CarSales.xsd"; var cars2 = from d in doc.Descendants(ns + "CarForSale") select d; ``` otherwise search by local name: ``` var cars2 = from d in doc.Descendants() where d.Name.LocalName == "CarForSal...
177,752
<p>I'm migrating a TSQL stored procedure to PL/SQL and have encountered a problem - the lack of a CONTINUE keyword in Oracle 10g.</p> <p>I've read that Oracle 11g has this as a new feature, but upgrading is not an option unfortunately.</p> <p>Is there any alternative to CONTINUE in 10g? I don't believe it's practical...
[ { "answer_id": 177768, "author": "cagcowboy", "author_id": 19629, "author_profile": "https://Stackoverflow.com/users/19629", "pm_score": 2, "selected": false, "text": "<p>Can you refactor the IFs into a function, returning at the appropriate point (early if necessary). Then the control ...
2008/10/07
[ "https://Stackoverflow.com/questions/177752", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5827/" ]
I'm migrating a TSQL stored procedure to PL/SQL and have encountered a problem - the lack of a CONTINUE keyword in Oracle 10g. I've read that Oracle 11g has this as a new feature, but upgrading is not an option unfortunately. Is there any alternative to CONTINUE in 10g? I don't believe it's practical to restructure t...
You can simulate a continue using [goto and labels](http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14261/controlstructures.htm#BCGFGDAA). ``` DECLARE done BOOLEAN; BEGIN FOR i IN 1..50 LOOP IF done THEN GOTO end_loop; END IF; <<end_loop>> -- not allowed unless an executable st...
177,762
<p>Trying to perform a single boolean NOT operation, it appears that under MS SQL Server 2005, the following block does not work</p> <pre><code>DECLARE @MyBoolean bit; SET @MyBoolean = 0; SET @MyBoolean = NOT @MyBoolean; SELECT @MyBoolean; </code></pre> <p>Instead, I am getting more successful with</p> <pre><code>DE...
[ { "answer_id": 177770, "author": "Galwegian", "author_id": 3201, "author_profile": "https://Stackoverflow.com/users/3201", "pm_score": 5, "selected": false, "text": "<p>Your solution is a good one... you can also use this syntax to toggle a bit in SQL...</p>\n\n<pre><code>DECLARE @MyBoo...
2008/10/07
[ "https://Stackoverflow.com/questions/177762", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18858/" ]
Trying to perform a single boolean NOT operation, it appears that under MS SQL Server 2005, the following block does not work ``` DECLARE @MyBoolean bit; SET @MyBoolean = 0; SET @MyBoolean = NOT @MyBoolean; SELECT @MyBoolean; ``` Instead, I am getting more successful with ``` DECLARE @MyBoolean bit; SET @MyBoolean ...
Use the ~ operator: ``` DECLARE @MyBoolean bit SET @MyBoolean = 0 SET @MyBoolean = ~@MyBoolean SELECT @MyBoolean ```
177,835
<p>One of our unit tests is to populate properties within our business objects with random data.</p> <p>These properties are of different intrinsic types and therefore we would like to use the power of generics to return data of the type you pass in. Something along the lines of:</p> <pre><code>public static T GetDat...
[ { "answer_id": 177847, "author": "Jon Skeet", "author_id": 22656, "author_profile": "https://Stackoverflow.com/users/22656", "pm_score": 4, "selected": false, "text": "<p>You could keep the \"easy to use\" GetData interface you've got there, but internally have a Dictionary&lt;Type, obje...
2008/10/07
[ "https://Stackoverflow.com/questions/177835", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17540/" ]
One of our unit tests is to populate properties within our business objects with random data. These properties are of different intrinsic types and therefore we would like to use the power of generics to return data of the type you pass in. Something along the lines of: ``` public static T GetData<T>() ``` How woul...
It depends on what data you want to randomize, because the *way* or the *algorithm* you want to use is totally different depending on the type. For example: ``` // Random int Random r = new Random(); return r.Next(); // Random Guid return Guid.NewGuid(); ... ``` So this obviously makes the use of generics a nice ...
177,836
<p>In the 'DBUtility' project of Petshop 4.0,the abstract class SqlHelper has a method 'GetCachedParameters':</p> <pre><code> public static SqlParameter[] GetCachedParameters(string cacheKey) { SqlParameter[] cachedParms = (SqlParameter[])parmCache[cacheKey]; if (cachedParms == null) ...
[ { "answer_id": 177840, "author": "Jon Skeet", "author_id": 22656, "author_profile": "https://Stackoverflow.com/users/22656", "pm_score": 4, "selected": true, "text": "<p>If cachedParms were returned directly, the caller could then change the elements of the array. The contents of the cac...
2008/10/07
[ "https://Stackoverflow.com/questions/177836", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20910/" ]
In the 'DBUtility' project of Petshop 4.0,the abstract class SqlHelper has a method 'GetCachedParameters': ``` public static SqlParameter[] GetCachedParameters(string cacheKey) { SqlParameter[] cachedParms = (SqlParameter[])parmCache[cacheKey]; if (cachedParms == null) return null;...
If cachedParms were returned directly, the caller could then change the elements of the array. The contents of the cache would then be effectively corrupted - the next caller to fetch the parameters from the cache with the same cache key would get unexpected results. EDIT: Cloning the array itself prevents the element...
177,863
<p>I am using the next class (simplified for the sake of understandability) to download images in a struts web application. It is working fine in every browser but firefox, which cuts names containing spaces. That it is to say: <strong>file with spaces.pdf</strong> gets downloaded in firefox as: <strong>file</strong> ...
[ { "answer_id": 177871, "author": "Henry B", "author_id": 6414, "author_profile": "https://Stackoverflow.com/users/6414", "pm_score": 0, "selected": false, "text": "<p>This is a security feature of firefox 3 I believe.</p>\n\n<p>Here we go</p>\n\n<p><a href=\"http://support.mozilla.com/ti...
2008/10/07
[ "https://Stackoverflow.com/questions/177863", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2138/" ]
I am using the next class (simplified for the sake of understandability) to download images in a struts web application. It is working fine in every browser but firefox, which cuts names containing spaces. That it is to say: **file with spaces.pdf** gets downloaded in firefox as: **file** while in chrome, IE7 IE6 is d...
The filename should be a **quoted** string. (According to [Section 19.5.1 of RFC 2616](http://www.w3.org/Protocols/rfc2616/rfc2616-sec19.html#sec19.5.1)) ``` response.setHeader("Content-Disposition","attachment; filename=\"" + filename + "\""); ```
177,867
<p>I need to copy data values from one element to another, but jQuery's clone() method doesn't clone the data. And I can't iterate over the data either:</p> <pre><code>element.data().each </code></pre> <p>because <code>data()</code> is a function and not a jQuery object. It seems I have to keep a separate list of att...
[ { "answer_id": 7805272, "author": "simon", "author_id": 76777, "author_profile": "https://Stackoverflow.com/users/76777", "pm_score": 1, "selected": false, "text": "<p>To give another alternative, i.e. instead of cloning the whole object you can copy the data object to a new array contai...
2008/10/07
[ "https://Stackoverflow.com/questions/177867", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1896/" ]
I need to copy data values from one element to another, but jQuery's clone() method doesn't clone the data. And I can't iterate over the data either: ``` element.data().each ``` because `data()` is a function and not a jQuery object. It seems I have to keep a separate list of attribute names and reference those but ...
To really only copy the data-\*, this is quite straightforward: ``` $(destination).data( $(source).data() ); ``` This is because using .data() no arguments will return a key-value object of all pieces of data and vice versa you can also update multiple pieces data at once using a key-value object. --- **UPDATE 25t...
177,883
<p>is it possible to include a servlet in a jsp page? if so how?</p>
[ { "answer_id": 7805272, "author": "simon", "author_id": 76777, "author_profile": "https://Stackoverflow.com/users/76777", "pm_score": 1, "selected": false, "text": "<p>To give another alternative, i.e. instead of cloning the whole object you can copy the data object to a new array contai...
2008/10/07
[ "https://Stackoverflow.com/questions/177883", "https://Stackoverflow.com", "https://Stackoverflow.com/users/24481/" ]
is it possible to include a servlet in a jsp page? if so how?
To really only copy the data-\*, this is quite straightforward: ``` $(destination).data( $(source).data() ); ``` This is because using .data() no arguments will return a key-value object of all pieces of data and vice versa you can also update multiple pieces data at once using a key-value object. --- **UPDATE 25t...
177,885
<p>I'm looking for a way to obtain offsets of data members of a C++ class which is of non-POD nature.</p> <p>Here's why: </p> <p>I'd like to store data in <a href="http://www.hdfgroup.org/HDF5/whatishdf5.html" rel="noreferrer">HDF5</a> format, which seems most suited for my kind of material (numerical simulation outp...
[ { "answer_id": 177887, "author": "Greg Hewgill", "author_id": 893, "author_profile": "https://Stackoverflow.com/users/893", "pm_score": 2, "selected": false, "text": "<p>You could declare the POD types in a base class, then extend that class (perhaps with <code>private</code> inheritance...
2008/10/07
[ "https://Stackoverflow.com/questions/177885", "https://Stackoverflow.com", "https://Stackoverflow.com/users/25756/" ]
I'm looking for a way to obtain offsets of data members of a C++ class which is of non-POD nature. Here's why: I'd like to store data in [HDF5](http://www.hdfgroup.org/HDF5/whatishdf5.html) format, which seems most suited for my kind of material (numerical simulation output), but it is perhaps a rather C-oriented li...
Greg Hewgill's solution is probably preferable to this (maybe with composition rather than inheritance). However, I think that with GCC on x86 and x86\_64, offsetof will actually work even for members of non-POD types, as long as it "makes sense". So for example it won't work for members inherited from virtual base cl...
177,910
<p>I've produced a python egg using setuptools and would like to access it's metadata at runtime. I currently got working this:</p> <pre><code>import pkg_resources dist = pkg_resources.get_distribution("my_project") print(dist.version) </code></pre> <p>but this would probably work incorrectly if I had multiple versio...
[ { "answer_id": 177939, "author": "Adam Bellaire", "author_id": 21632, "author_profile": "https://Stackoverflow.com/users/21632", "pm_score": 3, "selected": true, "text": "<p>I am somewhat new to Python as well, but from what I understand: </p>\n\n<p>Although you can install multiple vers...
2008/10/07
[ "https://Stackoverflow.com/questions/177910", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5821/" ]
I've produced a python egg using setuptools and would like to access it's metadata at runtime. I currently got working this: ``` import pkg_resources dist = pkg_resources.get_distribution("my_project") print(dist.version) ``` but this would probably work incorrectly if I had multiple versions of the same egg install...
I am somewhat new to Python as well, but from what I understand: Although you can install multiple versions of the "same" egg (having the same name), only one of them will be available to any particular piece of code at runtime (based on your discovery method). So if your egg is the one calling this code, it must hav...
177,911
<p>I've got a WPF browser-like application with a few pages. When I switch between pages, I'd like to set the keyboard focus.</p> <p>When a page is loaded the first time, this works by calling <code>Control.Focus()</code> in the constructor.</p> <p>But when I switch between pages this does not work anymore - the focu...
[ { "answer_id": 177995, "author": "Matt Hamilton", "author_id": 615, "author_profile": "https://Stackoverflow.com/users/615", "pm_score": 1, "selected": false, "text": "<p>Have you tried setting the focus in the Loaded event handler rather than the constructor? Pages aren't re-constructed...
2008/10/07
[ "https://Stackoverflow.com/questions/177911", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7021/" ]
I've got a WPF browser-like application with a few pages. When I switch between pages, I'd like to set the keyboard focus. When a page is loaded the first time, this works by calling `Control.Focus()` in the constructor. But when I switch between pages this does not work anymore - the focus is just on the first field...
Since I found no solution to this problem, I used a simple workaround: I fire up a secondary thread, which changes the focus after the page has loaded. Luckily this is done very easily using BeginInvoke: ``` myControl.Dispatcher.BeginInvoke(System.Windows.Threading.DispatcherPriority.Background, (System.Threading.S...
177,927
<p>In JPA the Entities are nice annotated Plain Old Java Objects. But I have not found a good way to interact with them and the database.</p> <p>In my current app, my basic design is always to have a sequence based id as primary key so I usually have to look up entities by other properties than PK.</p> <p>And for eac...
[ { "answer_id": 177932, "author": "Sietse", "author_id": 6400, "author_profile": "https://Stackoverflow.com/users/6400", "pm_score": 3, "selected": true, "text": "<p>Try Seam. The <a href=\"http://docs.jboss.com/seam/2.1.0.BETA1/reference/en-US/html_single/#d0e7527\" rel=\"nofollow norefe...
2008/10/07
[ "https://Stackoverflow.com/questions/177927", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8805/" ]
In JPA the Entities are nice annotated Plain Old Java Objects. But I have not found a good way to interact with them and the database. In my current app, my basic design is always to have a sequence based id as primary key so I usually have to look up entities by other properties than PK. And for each Entity I have a...
Try Seam. The [Query Objects](http://docs.jboss.com/seam/2.1.0.BETA1/reference/en-US/html_single/#d0e7527) do most of the work for you, and they're easily extendable. Or, you could always implement a similar pattern. In general, Seam does a lot of useful stuff to bridge the gap between JPA and you view and business la...
177,945
<p>I would like to create XML Schema for this chunk of xml, I would like to restrict the values of "name" attribute, so that in output document on and only one instance of day is allowed for each week day:</p> <pre><code>&lt;a&gt; &lt;day name="monday" /&gt; &lt;day name="tuesday" /&gt; &lt;day name="wednesday" ...
[ { "answer_id": 177954, "author": "Micah", "author_id": 17744, "author_profile": "https://Stackoverflow.com/users/17744", "pm_score": 0, "selected": false, "text": "<p>Try this:</p>\n\n<pre><code>&lt;xs:schema attributeFormDefault=\"unqualified\" elementFormDefault=\"qualified\" xmlns:xs=...
2008/10/07
[ "https://Stackoverflow.com/questions/177945", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10560/" ]
I would like to create XML Schema for this chunk of xml, I would like to restrict the values of "name" attribute, so that in output document on and only one instance of day is allowed for each week day: ``` <a> <day name="monday" /> <day name="tuesday" /> <day name="wednesday" /> </a> ``` I have tried to use t...
You need something like this: ``` <?xml version="1.0" encoding="UTF-8"?> <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified"> <xs:element name="a"> <xs:complexType> <xs:sequence> <xs:element maxOccurs="unbounded" ref="day"/> </xs:sequence> </xs:complexTyp...
177,956
<p>What is the best way to convert an int or null to boolean value in an SQL query, such that:</p> <ul> <li>Any non-null value is <strong>TRUE</strong> in the results</li> <li>Any null value is <strong>FALSE</strong> in the results</li> </ul>
[ { "answer_id": 177967, "author": "Torbjörn Gyllebring", "author_id": 21182, "author_profile": "https://Stackoverflow.com/users/21182", "pm_score": 2, "selected": false, "text": "<pre><code>isnull(column - column + 1, 0) != 0\n</code></pre>\n" }, { "answer_id": 177978, "author...
2008/10/07
[ "https://Stackoverflow.com/questions/177956", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15985/" ]
What is the best way to convert an int or null to boolean value in an SQL query, such that: * Any non-null value is **TRUE** in the results * Any null value is **FALSE** in the results
To my knowledge (correct me if I'm wrong), there is no concept of literal boolean values in SQL. You can have expressions evaluating to boolean values, but you cannot output them. This said, you can use CASE WHEN to produce a value you can use in a comparison: ``` SELECT CASE WHEN ValueColumn IS NULL THEN 'FALSE...
177,960
<p>Have someone ever done this before???</p> <p>I am trying to use MinGW to compile a program using the MySQL libraries. I keep getting the message that the function 'rint' is redefined. Ok it's true that the function is in both files config-win.h, from MySQL and math.h from the standard library, but both of them are ...
[ { "answer_id": 178031, "author": "Onorio Catenacci", "author_id": 2820, "author_profile": "https://Stackoverflow.com/users/2820", "pm_score": 0, "selected": false, "text": "<p>I don't know the stack in question but my guess would be that somehow math.h is getting double included. Take a...
2008/10/07
[ "https://Stackoverflow.com/questions/177960", "https://Stackoverflow.com", "https://Stackoverflow.com/users/366094/" ]
Have someone ever done this before??? I am trying to use MinGW to compile a program using the MySQL libraries. I keep getting the message that the function 'rint' is redefined. Ok it's true that the function is in both files config-win.h, from MySQL and math.h from the standard library, but both of them are suppose to...
Also a guess, but it appears as if math.h AND config-win.h have a function called rint, make sure that there aren't two functions with the same names. BTW, because I am not entirely sure, I'm making this community editable, feel free to edit this post if I am incorrect.
177,974
<p>How can I test sending email from my application without flooding my inbox? </p> <p>Is there a way to tell IIS/ASP.NET how to deliver email to a local folder for inspection?</p>
[ { "answer_id": 178072, "author": "GEOCHET", "author_id": 5640, "author_profile": "https://Stackoverflow.com/users/5640", "pm_score": 6, "selected": true, "text": "<p>Yes there is a way.</p>\n\n<blockquote>\n <p>You can alter web.config like this so\n that when you send email it will\n ...
2008/10/07
[ "https://Stackoverflow.com/questions/177974", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10676/" ]
How can I test sending email from my application without flooding my inbox? Is there a way to tell IIS/ASP.NET how to deliver email to a local folder for inspection?
Yes there is a way. > > You can alter web.config like this so > that when you send email it will > instead be created as an .EML file in > c:\LocalDir. > > > ``` <configuration> <system.net> <mailSettings> <smtp deliveryMethod="SpecifiedPickupDirectory"> <speci...
178,016
<p>I'm trying to select a specific HTML element in a document, for firefox i just use:</p> <pre><code>xpathobj = document.evaluate(xpath, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null); </code></pre> <p>which works fine. However when I try the IE equivilent:</p> <pre><code>xmlDoc=new Activ...
[ { "answer_id": 178021, "author": "cllpse", "author_id": 20946, "author_profile": "https://Stackoverflow.com/users/20946", "pm_score": 0, "selected": false, "text": "<p>Are you sure X-Path is implemented in your version of Internet Explorer? As in: what version are you using?</p>\n" }, ...
2008/10/07
[ "https://Stackoverflow.com/questions/178016", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11198/" ]
I'm trying to select a specific HTML element in a document, for firefox i just use: ``` xpathobj = document.evaluate(xpath, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null); ``` which works fine. However when I try the IE equivilent: ``` xmlDoc=new ActiveXObject("Microsoft.XMLDOM"); xmlDoc....
Take a look at <http://dev.abiss.gr/sarissa/> project. They have migrated most of XML-related APIs to IE. Otherwise it is indeed also easy to implement. The problems you would need to solve would be: serialization of HTML into valid XML, syncing result of XMLDOM XPath query with original HTMLDOM. To my knowledge they'v...
178,026
<p>We noticed that lots of bugs in our software developed in C# (or Java) cause a NullReferenceException.</p> <p>Is there a reason why "null" has even been included in the language?</p> <p>After all, if there were no "null", I would have no bug, right?</p> <p>In other words, what feature in the language couldn't wor...
[ { "answer_id": 178046, "author": "peacedog", "author_id": 1734, "author_profile": "https://Stackoverflow.com/users/1734", "pm_score": 1, "selected": false, "text": "<p>I can't speak to your specific issue, but it sounds like the problem isn't the existence of null. Null exists in databa...
2008/10/07
[ "https://Stackoverflow.com/questions/178026", "https://Stackoverflow.com", "https://Stackoverflow.com/users/25781/" ]
We noticed that lots of bugs in our software developed in C# (or Java) cause a NullReferenceException. Is there a reason why "null" has even been included in the language? After all, if there were no "null", I would have no bug, right? In other words, what feature in the language couldn't work without null?
Anders Hejlsberg, "C# father", just spoke about that point in [his Computerworld interview](https://www2.computerworld.com.au/article/261958/a-z_programming_languages_c_/?pp=3): > > For example, in the type system we do not have separation between value and reference types and nullability of types. This may sound a l...
178,114
<p>Is there any easier solution in porting a windows manual-reset event to pthread, than a pthread conditional-variable + pthread mutex + a flag if event is set or unset?</p>
[ { "answer_id": 178962, "author": "ephemient", "author_id": 20713, "author_profile": "https://Stackoverflow.com/users/20713", "pm_score": 4, "selected": false, "text": "<p>Pthreads are low level constructs. No, there isn't a simpler mechanism; <code>pthread_cond__*</code> is conceptually...
2008/10/07
[ "https://Stackoverflow.com/questions/178114", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
Is there any easier solution in porting a windows manual-reset event to pthread, than a pthread conditional-variable + pthread mutex + a flag if event is set or unset?
Pthreads are low level constructs. No, there isn't a simpler mechanism; `pthread_cond__*` is conceptually similar to an auto-reset event. Be careful, `pthread_cond_wait` may have spurious wakeups, so it should never be used without some sort of external flag regardless of the situation. Building your own wouldn't be t...
178,135
<p>I have a UserControl (Composite control) that can be shown as the following pseudo XAML code:</p> <pre><code>&lt;UserControl&gt; &lt;DockPanel&gt; &lt;TextBox /&gt; &lt;Button /&gt; &lt;/DockPanel&gt; &lt;/UserControl&gt; </code></pre> <p>I use this custom control in a bunch of places and style some of...
[ { "answer_id": 178427, "author": "Kent Boogaart", "author_id": 5380, "author_profile": "https://Stackoverflow.com/users/5380", "pm_score": 3, "selected": false, "text": "<p>There are a number of ways to do this, but I would suggest exposing your own property on your user control and bind...
2008/10/07
[ "https://Stackoverflow.com/questions/178135", "https://Stackoverflow.com", "https://Stackoverflow.com/users/39/" ]
I have a UserControl (Composite control) that can be shown as the following pseudo XAML code: ``` <UserControl> <DockPanel> <TextBox /> <Button /> </DockPanel> </UserControl> ``` I use this custom control in a bunch of places and style some of them with a WPF Style. This style sets the Background propert...
There are a number of ways to do this, but I would suggest exposing your own property on your user control and binding to that inside your user control. For example: ``` <UserControl x:Name="_root" ...> ... <Button Background="{Binding ButtonBackground, ElementName=_root}"/> </UserControl> ``` Another way wo...
178,138
<p>I fear this is probably a bit of a dummy question, but it has me pretty stumped.</p> <p>I'm looking for the simplest way possible to pass a method of an object into a procedure, so that the procedure can call the object's method (e.g. after a timeout, or maybe in a different thread). So basically I want to:</p> <...
[ { "answer_id": 178174, "author": "Roman Ganz", "author_id": 17981, "author_profile": "https://Stackoverflow.com/users/17981", "pm_score": 5, "selected": true, "text": "<p>Just remove the Pointer stuff. Delphi will do it for you:</p>\n\n<pre><code>procedure TCallbackObject.SetupCallback;\...
2008/10/07
[ "https://Stackoverflow.com/questions/178138", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11961/" ]
I fear this is probably a bit of a dummy question, but it has me pretty stumped. I'm looking for the simplest way possible to pass a method of an object into a procedure, so that the procedure can call the object's method (e.g. after a timeout, or maybe in a different thread). So basically I want to: * Capture a refe...
Just remove the Pointer stuff. Delphi will do it for you: ``` procedure TCallbackObject.SetupCallback; begin CallbackTheCallback(CallbackMethodImpl); end; ```
178,144
<p>Originally I thought to ask if there would be an easy way to provide an automatically managed last update field with MS Access.</p> <p>After some googling I found following approach:</p> <pre><code>Private Sub Form_Dirty(Cancel As Integer) Me.Last_Update = Date() End Sub </code></pre> <p>Which seems to do th...
[ { "answer_id": 178170, "author": "tom.dietrich", "author_id": 15769, "author_profile": "https://Stackoverflow.com/users/15769", "pm_score": 2, "selected": false, "text": "<p>That might be your best choice on an access database with an access back end- but if you've got a MS-SQL back end,...
2008/10/07
[ "https://Stackoverflow.com/questions/178144", "https://Stackoverflow.com", "https://Stackoverflow.com/users/28482/" ]
Originally I thought to ask if there would be an easy way to provide an automatically managed last update field with MS Access. After some googling I found following approach: ``` Private Sub Form_Dirty(Cancel As Integer) Me.Last_Update = Date() End Sub ``` Which seems to do the job. I thought I'd share it wit...
You could also put that same code into a BeforeUpdate. The difference being that the OnDirty will tag the record when you first started to edit the record; while the BeforeUpdate will tag the record just before it gets committed to the database. The latter may be preferable if you have a user who starts editing a re...
178,147
<p>I have an application in C# (2.0 running on XP embedded) that is communicating with a 'watchdog' that is implemented as a Windows Service. When the device boots, this service typically takes some time to start. I'd like to check, from my code, if the service is running. How can I accomplish this?</p>
[ { "answer_id": 178162, "author": "Carl", "author_id": 951280, "author_profile": "https://Stackoverflow.com/users/951280", "pm_score": 10, "selected": true, "text": "<p>I guess something like this would work:</p>\n\n<p>Add <code>System.ServiceProcess</code> to your project references (It'...
2008/10/07
[ "https://Stackoverflow.com/questions/178147", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6399/" ]
I have an application in C# (2.0 running on XP embedded) that is communicating with a 'watchdog' that is implemented as a Windows Service. When the device boots, this service typically takes some time to start. I'd like to check, from my code, if the service is running. How can I accomplish this?
I guess something like this would work: Add `System.ServiceProcess` to your project references (It's on the .NET tab). ``` using System.ServiceProcess; ServiceController sc = new ServiceController(SERVICENAME); switch (sc.Status) { case ServiceControllerStatus.Running: return "Running"; case Service...
178,187
<p>I am designing a class for log entries of my mail server. I have parsed the log entries and created the class hierarchy. Now I need to save the in memory representation to the disk. I need to save it to multiple destinations like mysql and disk files. I am at a loss to find out the proper way to design the persisten...
[ { "answer_id": 178504, "author": "Jon Wood", "author_id": 25258, "author_profile": "https://Stackoverflow.com/users/25258", "pm_score": 3, "selected": true, "text": "<p>Personally I'd break things out a bit - the object representing a log entry really shouldn't be worrying about how it s...
2008/10/07
[ "https://Stackoverflow.com/questions/178187", "https://Stackoverflow.com", "https://Stackoverflow.com/users/25453/" ]
I am designing a class for log entries of my mail server. I have parsed the log entries and created the class hierarchy. Now I need to save the in memory representation to the disk. I need to save it to multiple destinations like mysql and disk files. I am at a loss to find out the proper way to design the persistence ...
Personally I'd break things out a bit - the object representing a log entry really shouldn't be worrying about how it should save it, so I'd probably create a MySQLObjectStore, and FileObjectStore, which you can configure separately, and gets passed the object to save. You could give your Object class a class variable ...
178,188
<p>So, bitfields. Specifically, large bitfields. I understand how to manipulate individual values in a bitfield, but how would I go about doing this on a large set, such as say:</p> <pre><code>uint[] bitfield = new uint[4] { 0x0080000, 0x00FA3020, 0x00C8000, 0x0FF00D0 }; </code></pre> <p>The specific problem I'm havi...
[ { "answer_id": 178197, "author": "Jon Skeet", "author_id": 22656, "author_profile": "https://Stackoverflow.com/users/22656", "pm_score": 3, "selected": true, "text": "<p>What makes you think that BitArray uses bools internally? It uses Boolean values to represent the bits in terms of the...
2008/10/07
[ "https://Stackoverflow.com/questions/178188", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15537/" ]
So, bitfields. Specifically, large bitfields. I understand how to manipulate individual values in a bitfield, but how would I go about doing this on a large set, such as say: ``` uint[] bitfield = new uint[4] { 0x0080000, 0x00FA3020, 0x00C8000, 0x0FF00D0 }; ``` The specific problem I'm having is doing left and right...
What makes you think that BitArray uses bools internally? It uses Boolean values to represent the bits in terms of the API, but under the hood I believe it uses an int[].
178,194
<p>I am developing an application using MVC Preview 5. I have used typed views.</p> <p>After setting debug="false", I have found that I am receiving errors of the form:</p> <blockquote> <p>"The model item passed into the dictionary is of type 'blah.Models.UserAdmin.IndexData' but this dictionary requires a m...
[ { "answer_id": 178417, "author": "leppie", "author_id": 15541, "author_profile": "https://Stackoverflow.com/users/15541", "pm_score": 2, "selected": true, "text": "<p>Yes, the bug has been reported. Best leave debug on for now, or modify the offending code (sorry cant recall where).</p>...
2008/10/07
[ "https://Stackoverflow.com/questions/178194", "https://Stackoverflow.com", "https://Stackoverflow.com/users/24289/" ]
I am developing an application using MVC Preview 5. I have used typed views. After setting debug="false", I have found that I am receiving errors of the form: > > "The model item passed into the > dictionary is of type > 'blah.Models.UserAdmin.IndexData' but > this dictionary requires a model item > of type > '...
Yes, the bug has been reported. Best leave debug on for now, or modify the offending code (sorry cant recall where).
178,199
<p>In PHP I can name my array indices so that I may have something like:</p> <pre><code>$shows = Array(0 =&gt; Array('id' =&gt; 1, 'name' =&gt; 'Sesame Street'), 1 =&gt; Array('id' =&gt; 2, 'name' =&gt; 'Dora The Explorer')); </code></pre> <p>Is this possible in Python?</p>
[ { "answer_id": 178211, "author": "Lou Franco", "author_id": 3937, "author_profile": "https://Stackoverflow.com/users/3937", "pm_score": 3, "selected": false, "text": "<p>Yes,</p>\n\n<pre><code>a = {\"id\": 1, \"name\":\"Sesame Street\"}\n</code></pre>\n" }, { "answer_id": 178213,...
2008/10/07
[ "https://Stackoverflow.com/questions/178199", "https://Stackoverflow.com", "https://Stackoverflow.com/users/115/" ]
In PHP I can name my array indices so that I may have something like: ``` $shows = Array(0 => Array('id' => 1, 'name' => 'Sesame Street'), 1 => Array('id' => 2, 'name' => 'Dora The Explorer')); ``` Is this possible in Python?
This sounds like the PHP array using named indices is very similar to a python dict: ``` shows = [ {"id": 1, "name": "Sesaeme Street"}, {"id": 2, "name": "Dora The Explorer"}, ] ``` See <http://docs.python.org/tutorial/datastructures.html#dictionaries> for more on this.
178,200
<p>I have the following JSP code, that protects my web page and displays it only to know IP's</p> <pre><code>String ip_h = request.getRemoteAddr(); String host_h = request.getRemoteHost(); String iplist[] = new String[1]; iplist[0] = "127.0.0.1"; iplist[1] = "10.217.106.248"; int count = iplist.length; bo...
[ { "answer_id": 178266, "author": "Will Wagner", "author_id": 25468, "author_profile": "https://Stackoverflow.com/users/25468", "pm_score": 2, "selected": false, "text": "<p>IP addresses (at least, IPv4 addresses) are really intended to be represented as 32-bit integers. If you convert th...
2008/10/07
[ "https://Stackoverflow.com/questions/178200", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I have the following JSP code, that protects my web page and displays it only to know IP's ``` String ip_h = request.getRemoteAddr(); String host_h = request.getRemoteHost(); String iplist[] = new String[1]; iplist[0] = "127.0.0.1"; iplist[1] = "10.217.106.248"; int count = iplist.length; boolean flag = f...
IP addresses (at least, IPv4 addresses) are really intended to be represented as 32-bit integers. If you convert the IP address to an integer first, checking subnet ranges becomes a relatively simple matter of checking (in your example) whether the first 16 bits match the first 16 bits of the range.
178,210
<p>We are building a multi-tenant website in ASP.NET, and we must let each customer configure their own security model. They must be able to define their own roles, and put users in those roles. What is the best way to do this?</p> <p>There are tons of simple examples of page_load events that have code like:</p> <p...
[ { "answer_id": 178238, "author": "ullmark", "author_id": 23044, "author_profile": "https://Stackoverflow.com/users/23044", "pm_score": 0, "selected": false, "text": "<p>I would create a configuration system for the website that is easily managed in config-files. Where you could get typed...
2008/10/07
[ "https://Stackoverflow.com/questions/178210", "https://Stackoverflow.com", "https://Stackoverflow.com/users/681/" ]
We are building a multi-tenant website in ASP.NET, and we must let each customer configure their own security model. They must be able to define their own roles, and put users in those roles. What is the best way to do this? There are tons of simple examples of page\_load events that have code like: ``` if (!user.I...
Perhaps put the configurable roles in a DB table, where you store the roles and tenant, and then the PagePermissions in another table, for example: ``` Table "Role" RoleId, TenantId, Role Table "PagePermissions" PageId, RoleId Table "UserRoles" UserId, RoleId ``` Then in the page load check whether the User is in ...
178,216
<p>In Informix, how can I cast a <code>char(8)</code> type into a <code>money</code> type, so that I can compare it to another <code>money</code> type?</p> <p>Using "<code>tblAid.amt::money as aid_amt</code>" did not work. Using "<code>(tblAid.amt * 1) AS aid_amt</code>" did not work.</p>
[ { "answer_id": 185890, "author": "SKapsal", "author_id": 24721, "author_profile": "https://Stackoverflow.com/users/24721", "pm_score": 4, "selected": true, "text": "<p>try this --> </p>\n\n<pre><code>select (disb_amt::NUMERIC) disb_amt from tmp_kygrants;\n</code></pre>\n\n<p>You may be a...
2008/10/07
[ "https://Stackoverflow.com/questions/178216", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13832/" ]
In Informix, how can I cast a `char(8)` type into a `money` type, so that I can compare it to another `money` type? Using "`tblAid.amt::money as aid_amt`" did not work. Using "`(tblAid.amt * 1) AS aid_amt`" did not work.
try this --> ``` select (disb_amt::NUMERIC) disb_amt from tmp_kygrants; ``` You may be able to compare the amounts as numeric.
178,247
<p>I have minified my javascript and my css.</p> <p>Now, Which is better?</p> <pre><code>&lt;script type="text/javascript"&gt; &lt;? $r = file_get_contents('min.js'); if($r) echo $r; ?&gt; &lt;/script&gt; </code></pre> <p>OR</p> <pre><code>&lt;script type="text/javascript" src="min.js"&gt;&lt;/script&gt; </code...
[ { "answer_id": 178269, "author": "Jonny Buchanan", "author_id": 6760, "author_profile": "https://Stackoverflow.com/users/6760", "pm_score": 6, "selected": true, "text": "<pre><code>&lt;script type=\"text/javascript\" src=\"min.js\"&gt;&lt;/script&gt;\n</code></pre>\n\n<p>...is better, as...
2008/10/07
[ "https://Stackoverflow.com/questions/178247", "https://Stackoverflow.com", "https://Stackoverflow.com/users/144/" ]
I have minified my javascript and my css. Now, Which is better? ``` <script type="text/javascript"> <? $r = file_get_contents('min.js'); if($r) echo $r; ?> </script> ``` OR ``` <script type="text/javascript" src="min.js"></script> ``` Same question for CSS. If the answer is 'sometimes because browsers fetch...
``` <script type="text/javascript" src="min.js"></script> ``` ...is better, as the user's browser can cache the file. Adding a parameter to the `src` such as the file's last modified timestamp is even better, as the user's browser will cache the file but will always retrieve the most up to date version when the file...
178,255
<p>I'm talking about c# <del>3.5</del> 3.0. I know how to do it when cache or ServiceProvider can have only one instance for the whole application. In this case ServiceProvider can look like this</p> <pre><code>public static class Service&lt;T&gt; { public static T Value {get; set;} } </code></pre> <p>and can be ...
[ { "answer_id": 178310, "author": "Jon Skeet", "author_id": 22656, "author_profile": "https://Stackoverflow.com/users/22656", "pm_score": 2, "selected": false, "text": "<p>Why are you particularly desperate to avoid casting? Yes, it feels \"unsafe\" - but you can basically guarantee that ...
2008/10/07
[ "https://Stackoverflow.com/questions/178255", "https://Stackoverflow.com", "https://Stackoverflow.com/users/22569/" ]
I'm talking about c# ~~3.5~~ 3.0. I know how to do it when cache or ServiceProvider can have only one instance for the whole application. In this case ServiceProvider can look like this ``` public static class Service<T> { public static T Value {get; set;} } ``` and can be used for different types like this: ``...
Why are you particularly desperate to avoid casting? Yes, it feels "unsafe" - but you can basically guarantee that it's not going to be an issue in ServiceProvider, and the clients aren't doing any casting. This is a reasonably common problem, but I don't believe there's any nice solution to it within .NET generics - ...
178,257
<p>Huge files take forever to load and work with in vim, due to syntax-highlighting.</p> <p>I'm looking for a way to limit size of highlighted files, such that files larger than (say) 10MB will be colorless.</p>
[ { "answer_id": 178267, "author": "tomasr", "author_id": 10292, "author_profile": "https://Stackoverflow.com/users/10292", "pm_score": 3, "selected": false, "text": "<p>I haven't tried it myself, but the <a href=\"http://www.vim.org/scripts/script.php?script_id=1506\" rel=\"noreferrer\">L...
2008/10/07
[ "https://Stackoverflow.com/questions/178257", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6984/" ]
Huge files take forever to load and work with in vim, due to syntax-highlighting. I'm looking for a way to limit size of highlighted files, such that files larger than (say) 10MB will be colorless.
Adding the following line to \_vimrc does the trick, with a bonus: it handles gzipped files, too (which is a common case with huge files): ``` autocmd BufWinEnter * if line2byte(line("$") + 1) > 1000000 | syntax clear | endif ```
178,263
<p>I am testing a web app that writes cookies to subdomain.thisdomain.com and several subfolders within that. I'm looking for JavaScript that I can put into a bookmarklet that will delete all cookies under that subdomain, regardless of the folder in which they exist.</p> <p>Any ideas?</p>
[ { "answer_id": 178294, "author": "Sergey Ilinsky", "author_id": 23815, "author_profile": "https://Stackoverflow.com/users/23815", "pm_score": 2, "selected": false, "text": "<p>I would recommend <a href=\"https://addons.mozilla.org/en-US/firefox/addon/6683\" rel=\"nofollow noreferrer\">Fi...
2008/10/07
[ "https://Stackoverflow.com/questions/178263", "https://Stackoverflow.com", "https://Stackoverflow.com/users/335036/" ]
I am testing a web app that writes cookies to subdomain.thisdomain.com and several subfolders within that. I'm looking for JavaScript that I can put into a bookmarklet that will delete all cookies under that subdomain, regardless of the folder in which they exist. Any ideas?
Derived from [my answer here](https://stackoverflow.com/questions/179355/clearing-all-cookies-with-javascript#179514): ``` javascript:new function(){var c=document.cookie.split(";");for(var i=0;i<c.length;i++){var e=c[i].indexOf("=");var n=e>-1?c[i].substr(0,e):c[i];document.cookie=n+"=;expires=Thu, 01 Jan 1970 00:00:...
178,265
<p>Today at work we came across the following code (some of you might recognize it):</p> <pre><code>#define GET_VAL( val, type ) \ { \ ASSERT( ( pIP + sizeof(type) ) &lt;= pMethodEnd ); \ val = ( *((type *&amp;)(pIP))++ ); \ } <...
[ { "answer_id": 178308, "author": "Simon", "author_id": 24039, "author_profile": "https://Stackoverflow.com/users/24039", "pm_score": 2, "selected": false, "text": "<p>C, but present in C++, I find the comma operator really obfuscates code, take this...</p>\n\n<pre><code>ihi = y[0]&gt;y[1...
2008/10/07
[ "https://Stackoverflow.com/questions/178265", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11361/" ]
Today at work we came across the following code (some of you might recognize it): ``` #define GET_VAL( val, type ) \ { \ ASSERT( ( pIP + sizeof(type) ) <= pMethodEnd ); \ val = ( *((type *&)(pIP))++ ); \ } ``` Basically we hav...
The inverse square root implementation in Quake 3: ``` float InvSqrt (float x){ float xhalf = 0.5f*x; int i = *(int*)&x; i = 0x5f3759df - (i>>1); x = *(float*)&i; x = x*(1.5f - xhalf*x*x); return x; } ``` **Update:** [How this works](http://www.lomont.org/Math/Papers/2003/InvSqrt.pdf) (thanks...
178,325
<p>How do I toggle the visibility of an element using <code>.hide()</code>, <code>.show()</code>, or <code>.toggle()</code>?</p> <p>How do I test if an element is <code>visible</code> or <code>hidden</code>?</p>
[ { "answer_id": 178344, "author": "Mote", "author_id": 24789, "author_profile": "https://Stackoverflow.com/users/24789", "pm_score": 10, "selected": false, "text": "<pre><code>if ( $(element).css('display') == 'none' || $(element).css(\"visibility\") == \"hidden\"){\n // 'element' is h...
2008/10/07
[ "https://Stackoverflow.com/questions/178325", "https://Stackoverflow.com", "https://Stackoverflow.com/users/21709/" ]
How do I toggle the visibility of an element using `.hide()`, `.show()`, or `.toggle()`? How do I test if an element is `visible` or `hidden`?
Since the question refers to a single element, this code might be more suitable: ``` // Checks CSS content for display:[none|block], ignores visibility:[true|false] $(element).is(":visible"); // The same works with hidden $(element).is(":hidden"); ``` It is the same as [twernt's suggestion](https://stackoverflow.co...
178,328
<p>In PHP, function parameters can be passed by reference by prepending an ampersand to the parameter in the function declaration, like so:</p> <pre><code>function foo(&amp;$bar) { // ... } </code></pre> <p>Now, I am aware that this is <i>not</i> designed to improve performance, but to allow functions to change v...
[ { "answer_id": 178340, "author": "Greg", "author_id": 24181, "author_profile": "https://Stackoverflow.com/users/24181", "pm_score": 2, "selected": false, "text": "<p>I'm pretty sure that no, it's not faster.\nAdditionally, it says specifically in the manual not to try using references to...
2008/10/07
[ "https://Stackoverflow.com/questions/178328", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2077/" ]
In PHP, function parameters can be passed by reference by prepending an ampersand to the parameter in the function declaration, like so: ``` function foo(&$bar) { // ... } ``` Now, I am aware that this is *not* designed to improve performance, but to allow functions to change variables that are normally out of t...
The Zend Engine uses copy-on-write, and when you use a reference yourself, it incurs a little extra overhead. Can only find [this mention](http://web.archive.org/web/20130406174901/http://www.thedeveloperday.com/php-lazy-copy/) at time of writing though, and comments in [the manual](http://www.php.net/references) conta...
178,333
<p>Since multiple inheritance is bad (it makes the source more complicated) C# does not provide such a pattern directly. But sometimes it would be helpful to have this ability.</p> <p>For instance I'm able to implement the missing multiple inheritance pattern using interfaces and three classes like that:</p> <pre><code...
[ { "answer_id": 178346, "author": "Joel Coehoorn", "author_id": 3043, "author_profile": "https://Stackoverflow.com/users/3043", "pm_score": 3, "selected": false, "text": "<p>You could have one abstract base class that implements both IFirst and ISecond, and then inherit from just that bas...
2008/10/07
[ "https://Stackoverflow.com/questions/178333", "https://Stackoverflow.com", "https://Stackoverflow.com/users/25782/" ]
Since multiple inheritance is bad (it makes the source more complicated) C# does not provide such a pattern directly. But sometimes it would be helpful to have this ability. For instance I'm able to implement the missing multiple inheritance pattern using interfaces and three classes like that: ``` public interface I...
> > Since multiple inheritance is bad (it makes the source more complicated) C# does not provide such a pattern directly. But sometimes it would be helpful to have this ability. > > > C# and the .net CLR have not implemented MI because they have not concluded how it would inter-operate between C#, VB.net and the o...
178,398
<p>Generally, MVC frameeworks have a structure that looks something like:</p> <pre><code>/models /views /controllers /utils </code></pre> <p>However, in a web application suite, I've decided that clumping all models, views, and controllers together probably wouldn't be the best for clarity, unless I treated the syste...
[ { "answer_id": 178411, "author": "Adam Bellaire", "author_id": 21632, "author_profile": "https://Stackoverflow.com/users/21632", "pm_score": 1, "selected": false, "text": "<p>If your apps share data, it could make sense (to me) to group the models together. </p>\n\n<p>However, for the v...
2008/10/07
[ "https://Stackoverflow.com/questions/178398", "https://Stackoverflow.com", "https://Stackoverflow.com/users/572/" ]
Generally, MVC frameeworks have a structure that looks something like: ``` /models /views /controllers /utils ``` However, in a web application suite, I've decided that clumping all models, views, and controllers together probably wouldn't be the best for clarity, unless I treated the system as one application inste...
It seems like 2) would be your best option, assuming you want some separation of applications. You could also have a "/common" folder at the "/app#" level for shared resources across all applications... like a shared utility class or whatever.
178,407
<p>Say I have the following:</p> <pre><code>&lt;ul&gt; &lt;li&gt;First item&lt;/li&gt; &lt;li&gt;Second item&lt;/li&gt; &lt;li&gt;Third item&lt;/li&gt; &lt;/ul&gt; </code></pre> <p>How would I select all the child elements after the first one using jQuery? So I can achieve something like:</p> <pre><code>&lt;ul&g...
[ { "answer_id": 178422, "author": "Jonny Buchanan", "author_id": 6760, "author_profile": "https://Stackoverflow.com/users/6760", "pm_score": 4, "selected": false, "text": "<p><a href=\"http://docs.jquery.com/Traversing/slice\" rel=\"noreferrer\">http://docs.jquery.com/Traversing/slice</a>...
2008/10/07
[ "https://Stackoverflow.com/questions/178407", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5802/" ]
Say I have the following: ``` <ul> <li>First item</li> <li>Second item</li> <li>Third item</li> </ul> ``` How would I select all the child elements after the first one using jQuery? So I can achieve something like: ``` <ul> <li>First item</li> <li class="something">Second item</li> <li class="something">Third...
You should be able to use the "not" and "first child" selectors. ``` $("li:not(:first-child)").addClass("something"); ``` <http://docs.jquery.com/Selectors/not> <http://docs.jquery.com/Selectors/firstChild>
178,444
<p>I need to get existing web pages into an existing ASP.NET web site project in Visual Studio 2008. I simply tried to drag and drop the whole file folder content into the Visual Studio Solution Explorer or even to copy them into the web site folder.</p> <p>Both ways, Visual Studio seems unable to map the .designer.cs...
[ { "answer_id": 178514, "author": "YonahW", "author_id": 3821, "author_profile": "https://Stackoverflow.com/users/3821", "pm_score": 0, "selected": false, "text": "<p>try copying the files through the filesystem and then right clicking on the project and selecting to add an existing item ...
2008/10/07
[ "https://Stackoverflow.com/questions/178444", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17713/" ]
I need to get existing web pages into an existing ASP.NET web site project in Visual Studio 2008. I simply tried to drag and drop the whole file folder content into the Visual Studio Solution Explorer or even to copy them into the web site folder. Both ways, Visual Studio seems unable to map the .designer.cs files to ...
It sounds like you are trying to bring web application files into a web site. *IIf that is the case*, The designer files are not even needed. Just dont include them. They are generated and compiled in at runtime when the website runs.
178,456
<p>Is it better to do this:</p> <pre><code>try { ... } catch (Exception ex) { ... throw; } </code></pre> <p>Or this:</p> <pre><code>try { ... } catch (Exception ex) { ... throw ex; } </code></pre> <p>Do they do the same thing? Is one better than the other?</p>
[ { "answer_id": 178464, "author": "Torbjörn Gyllebring", "author_id": 21182, "author_profile": "https://Stackoverflow.com/users/21182", "pm_score": 11, "selected": true, "text": "<p>You should always use the following syntax to rethrow an exception. Else you'll stomp the stack trace:</p>\...
2008/10/07
[ "https://Stackoverflow.com/questions/178456", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13913/" ]
Is it better to do this: ``` try { ... } catch (Exception ex) { ... throw; } ``` Or this: ``` try { ... } catch (Exception ex) { ... throw ex; } ``` Do they do the same thing? Is one better than the other?
You should always use the following syntax to rethrow an exception. Else you'll stomp the stack trace: ``` throw; ``` If you print the trace resulting from `throw ex`, you'll see that it ends on that statement and not at the real source of the exception. Basically, it should be deemed a criminal offense to use `thr...
178,458
<p>I am in a project where we are starting refactoring some massive code base. One problem that immediately sprang up is that each file imports a lot of other files. How do I in an elegant way mock this in my unit test without having to alter the actual code so I can start to write unit-tests?</p> <p>As an example: Th...
[ { "answer_id": 178582, "author": "S.Lott", "author_id": 10661, "author_profile": "https://Stackoverflow.com/users/10661", "pm_score": 1, "selected": false, "text": "<p>&quot;imports a lot of other files&quot;? Imports a lot of other files that are part of your customized code base? Or ...
2008/10/07
[ "https://Stackoverflow.com/questions/178458", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12126/" ]
I am in a project where we are starting refactoring some massive code base. One problem that immediately sprang up is that each file imports a lot of other files. How do I in an elegant way mock this in my unit test without having to alter the actual code so I can start to write unit-tests? As an example: The file wit...
If you want to import a module while at the same time ensuring that it doesn't import anything, you can replace the `__import__` builtin function. For example, use this class: ``` class ImportWrapper(object): def __init__(self, real_import): self.real_import = real_import def wrapper(self, wantedModu...