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 |
|---|---|---|---|---|---|---|
28,110 | <p>I have a large table with 1 million+ records. Unfortunately, the person who created the table decided to put dates in a <code>varchar(50)</code> field.</p>
<p>I need to do a simple date comparison -</p>
<pre><code>datediff(dd, convert(datetime, lastUpdate, 100), getDate()) < 31
</code></pre>
<p>But it fails on... | [
{
"answer_id": 28135,
"author": "SQLMenace",
"author_id": 740,
"author_profile": "https://Stackoverflow.com/users/740",
"pm_score": 0,
"selected": false,
"text": "<p>I would suggest cleaning up the mess and changing the column to a datetime because doing stuff like this</p>\n\n<pre><code... | 2008/08/26 | [
"https://Stackoverflow.com/questions/28110",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/357/"
] | I have a large table with 1 million+ records. Unfortunately, the person who created the table decided to put dates in a `varchar(50)` field.
I need to do a simple date comparison -
```
datediff(dd, convert(datetime, lastUpdate, 100), getDate()) < 31
```
But it fails on the `convert()`:
```
Conversion failed when c... | Place the `CASE` and `ISDATE` inside the `CONVERT()` function.
```sql
SELECT COUNT(*) FROM MyTable
WHERE
DATEDIFF(dd, CONVERT(DATETIME, CASE IsDate(lastUpdate)
WHEN 1 THEN lastUpdate
ELSE '12-30-1899'
END), GetDate()) < 31
```
Replace `'12-30-1899'` with the default date of your choice. |
28,165 | <p>Python has this wonderful way of handling string substitutions using dictionaries:</p>
<pre><code>>>> 'The %(site)s site %(adj)s because it %(adj)s' % {'site':'Stackoverflow', 'adj':'rocks'}
'The Stackoverflow site rocks because it rocks'
</code></pre>
<p>I love this because you can specify a value once i... | [
{
"answer_id": 28199,
"author": "Tom Mayfield",
"author_id": 2314,
"author_profile": "https://Stackoverflow.com/users/2314",
"pm_score": 1,
"selected": false,
"text": "<p>Some of the user-contributed notes and functions in <a href=\"http://us3.php.net/sprintf\" rel=\"nofollow noreferrer\... | 2008/08/26 | [
"https://Stackoverflow.com/questions/28165",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/305/"
] | Python has this wonderful way of handling string substitutions using dictionaries:
```
>>> 'The %(site)s site %(adj)s because it %(adj)s' % {'site':'Stackoverflow', 'adj':'rocks'}
'The Stackoverflow site rocks because it rocks'
```
I love this because you can specify a value once in the dictionary and then replace i... | ```
function subst($str, $dict){
return preg_replace(array_map(create_function('$a', 'return "/%\\($a\\)s/";'), array_keys($dict)), array_values($dict), $str);
}
```
You call it like so:
```
echo subst('The %(site)s site %(adj)s because it %(adj)s', array('site'=>'Stackoverflow', 'adj'=>'rocks'));
``` |
28,196 | <p>This is a very specific question regarding <strong>MySQL</strong> as implemented in <strong>WordPress</strong>.</p>
<p>I'm trying to develop a plugin that will show (select) posts that have specific '<strong>tags</strong>' and belong to specific '<strong>categories</strong>' (both multiple)</p>
<p>I was told it's im... | [
{
"answer_id": 28233,
"author": "Matt Rogish",
"author_id": 2590,
"author_profile": "https://Stackoverflow.com/users/2590",
"pm_score": 2,
"selected": false,
"text": "<p>What a gross DB structure.</p>\n\n<p>Anyway, I'd do something like this (note I prefer EXISTS to joins, but you can re... | 2008/08/26 | [
"https://Stackoverflow.com/questions/28196",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1011/"
] | This is a very specific question regarding **MySQL** as implemented in **WordPress**.
I'm trying to develop a plugin that will show (select) posts that have specific '**tags**' and belong to specific '**categories**' (both multiple)
I was told it's impossible because of the way categories and tags are stored:
1. `wp... | I misunderstood you. I thought you wanted Nuclear or Deals. The below should give you only Nuclear and Deals.
```
select p.*
from wp_posts p, wp_terms t, wp_term_taxonomy tt, wp_term_relationship tr,
wp_terms t2, wp_term_taxonomy tt2, wp_term_relationship tr2
wp_terms t2, wp_term_taxonomy tt2, wp_term_relationship tr2... |
28,202 | <p>Every time I create a new project I copy the last project's ant file to the new one and make the appropriate changes (trying at the same time to make it more flexible for the next project). But since I didn't really thought about it at the beginning, the file started to look really ugly.</p>
<p>Do you have an Ant t... | [
{
"answer_id": 28304,
"author": "Vinnie",
"author_id": 2890,
"author_profile": "https://Stackoverflow.com/users/2890",
"pm_score": 0,
"selected": false,
"text": "<p>I used to do exactly the same thing.... then I switched to <a href=\"http://maven.apache.org/\" rel=\"nofollow noreferrer\"... | 2008/08/26 | [
"https://Stackoverflow.com/questions/28202",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2644/"
] | Every time I create a new project I copy the last project's ant file to the new one and make the appropriate changes (trying at the same time to make it more flexible for the next project). But since I didn't really thought about it at the beginning, the file started to look really ugly.
Do you have an Ant template th... | An alternative to making a template is to evolve one by gradually generalising your current project's Ant script so that there are fewer changes to make the next time you copy it for use on a new project. There are several things you can do.
Use ${ant.project.name} in file names, so you only have to mention your appli... |
28,212 | <p>I'm using two different libraries in my project, and both of them supply a basic rectangle <code>struct</code>. The problem with this is that there seems to be no way to insert a conversion between the types, so I can't call a function in one library with the result from a function in the other. If I was the author ... | [
{
"answer_id": 28223,
"author": "dmckee --- ex-moderator kitten",
"author_id": 2509,
"author_profile": "https://Stackoverflow.com/users/2509",
"pm_score": 0,
"selected": false,
"text": "<p>It may not be feasible in your case, but I've seen people employ a little preprocessor-foo to massa... | 2008/08/26 | [
"https://Stackoverflow.com/questions/28212",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1421/"
] | I'm using two different libraries in my project, and both of them supply a basic rectangle `struct`. The problem with this is that there seems to be no way to insert a conversion between the types, so I can't call a function in one library with the result from a function in the other. If I was the author of either of t... | If you can't modify the structures then you have no alternative to writing a manual conversion function because overloading conversion operators only works within the class body. There's no other way. |
28,219 | <p>Can I get a 'when to use' for these and others? </p>
<pre><code><% %>
<%# EVAL() %>
</code></pre>
<p>Thanks</p>
| [
{
"answer_id": 28225,
"author": "bdukes",
"author_id": 2688,
"author_profile": "https://Stackoverflow.com/users/2688",
"pm_score": 5,
"selected": true,
"text": "<p>Check out the <a href=\"http://quickstarts.asp.net/QuickStartv20/aspnet/doc/pages/syntax.aspx#expressions\" rel=\"noreferrer... | 2008/08/26 | [
"https://Stackoverflow.com/questions/28219",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1293/"
] | Can I get a 'when to use' for these and others?
```
<% %>
<%# EVAL() %>
```
Thanks | Check out the [Web Forms Syntax Reference](http://quickstarts.asp.net/QuickStartv20/aspnet/doc/pages/syntax.aspx#expressions) on MSDN.
For basics,
* <% %> is used for pure code blocks. I generally only use this for if statements
>
>
>
> <div class="authenticated">
>
>
>
> <div class="unauthenticat... |
28,224 | <p>Is there a way to run a regexp-string replace on the current line in the bash?</p>
<p>I find myself rather often in the situation, where I have typed a long commandline and then realize, that I would like to change a word somewhere in the line.</p>
<p>My current approach is to finish the line, press <kbd>Ctrl</kbd... | [
{
"answer_id": 28228,
"author": "Rob Wells",
"author_id": 2974,
"author_profile": "https://Stackoverflow.com/users/2974",
"pm_score": 2,
"selected": false,
"text": "<p>G'day,</p>\n\n<p>What about using vi mode instead? Just enter set -o vi</p>\n\n<p>Then you can go to the word you want t... | 2008/08/26 | [
"https://Stackoverflow.com/questions/28224",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1870/"
] | Is there a way to run a regexp-string replace on the current line in the bash?
I find myself rather often in the situation, where I have typed a long commandline and then realize, that I would like to change a word somewhere in the line.
My current approach is to finish the line, press `Ctrl`+`A` (to get to the start... | Unfortunately, no, there's not really a better way. If you're just tired of making the keystrokes, you can use macros to trim them down. Add the following to your `~/.inputrc`:
```
"\C-x6": "\C-a#\C-m^"
"\C-x7": "\C-m\C-P\C-a\C-d\C-m"
```
Now, in a new bash instance (or after reloading `.inputrc` in your current she... |
28,235 | <p>Using <a href="http://www.oracle.com/technology/products/jdev" rel="noreferrer">JDeveloper</a>, I started developing a set of web pages for a project at work. Since I didn't know much about JDev at the time, I ran over to Oracle to follow some tutorials. The JDev tutorials recommended doing <a href="http://www.filei... | [
{
"answer_id": 28250,
"author": "Matthew Ruston",
"author_id": 506,
"author_profile": "https://Stackoverflow.com/users/506",
"pm_score": 3,
"selected": false,
"text": "<p>Hello fellow JDeveloper developer!</p>\n\n<p>I have been working with JSPX pages for over two years and I never had a... | 2008/08/26 | [
"https://Stackoverflow.com/questions/28235",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | Using [JDeveloper](http://www.oracle.com/technology/products/jdev), I started developing a set of web pages for a project at work. Since I didn't know much about JDev at the time, I ran over to Oracle to follow some tutorials. The JDev tutorials recommended doing [JSPX](http://www.fileinfo.net/extension/jspx) instead o... | The main difference is that a JSPX file (officially called a 'JSP document') may be easier to work with because the requirement for well-formed XML may allow your editor to identify more typos and syntax errors as you type.
However, there are also disadvantages. For example, well-formed XML must escape things like les... |
28,243 | <p>I'm trying to install some Ruby Gems so I can use Ruby to notify me when I get twitter messages. However, after doing a <code>gem update --system</code>, I now get a zlib error every time I try and do a <code>gem install</code> of anything. below is the console output I get when trying to install ruby gems. (along w... | [
{
"answer_id": 30609,
"author": "seanyboy",
"author_id": 1726,
"author_profile": "https://Stackoverflow.com/users/1726",
"pm_score": 1,
"selected": false,
"text": "<p>A reinstall of Ruby sorted this issue out. It's not what I wanted; I wanted to know why I was getting the issue, but it's... | 2008/08/26 | [
"https://Stackoverflow.com/questions/28243",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1726/"
] | I'm trying to install some Ruby Gems so I can use Ruby to notify me when I get twitter messages. However, after doing a `gem update --system`, I now get a zlib error every time I try and do a `gem install` of anything. below is the console output I get when trying to install ruby gems. (along with the output from `gem ... | I just started getting this tonight as well. Googling turned up a bunch of suggestions that didn't deliver results
```
gem update --system
```
and some paste in code from jamis that is supposed to replace a function in package.rb but the original it is supposed to replace is nowhere to be found.
Reinstalling rubyge... |
28,256 | <p>I've developed an equation parser using a simple stack algorithm that will handle binary (+, -, |, &, *, /, etc) operators, unary (!) operators, and parenthesis.</p>
<p>Using this method, however, leaves me with everything having the same precedence - it's evaluated left to right regardless of operator, although... | [
{
"answer_id": 28272,
"author": "OysterD",
"author_id": 2638,
"author_profile": "https://Stackoverflow.com/users/2638",
"pm_score": 4,
"selected": false,
"text": "<p>It would help if you could describe the grammar you are currently using to parse. Sounds like the problem might lie there!... | 2008/08/26 | [
"https://Stackoverflow.com/questions/28256",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2915/"
] | I've developed an equation parser using a simple stack algorithm that will handle binary (+, -, |, &, \*, /, etc) operators, unary (!) operators, and parenthesis.
Using this method, however, leaves me with everything having the same precedence - it's evaluated left to right regardless of operator, although precedence ... | ### The hard way
You want a [recursive descent parser](http://en.wikipedia.org/wiki/Recursive_descent_parser).
To get precedence you need to think recursively, for example, using your sample string,
```
1+11*5
```
to do this manually, you would have to read the `1`, then see the plus and start a whole new recursi... |
28,280 | <p>I have a SQL script that inserts data (via INSERT statements currently numbering in the thousands) One of the columns contains a unique identifier (though not an IDENTITY type, just a plain ol' int) that's actually unique across a few different tables. </p>
<p>I'd like to add a scalar function to my script that get... | [
{
"answer_id": 28285,
"author": "SQLMenace",
"author_id": 740,
"author_profile": "https://Stackoverflow.com/users/740",
"pm_score": 2,
"selected": false,
"text": "<p>If you have 2 users hitting it at the same time they will get the same id. Why didn't you use an id table with an identity... | 2008/08/26 | [
"https://Stackoverflow.com/questions/28280",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2187/"
] | I have a SQL script that inserts data (via INSERT statements currently numbering in the thousands) One of the columns contains a unique identifier (though not an IDENTITY type, just a plain ol' int) that's actually unique across a few different tables.
I'd like to add a scalar function to my script that gets the next... | >
> I'm starting to think it can't be done that way since there doesn't seem to be a way to maintain the offset counter between calls. Is that right, or is there something I'm missing.
>
>
>
You aren't missing anything; SQL Server does not support global variables, and it doesn't support data modification within U... |
28,293 | <p>I have an XML document with a DTD, and would love to be able to access the XML model, something like this:</p>
<pre><code>title = Thing.Items[0].Title
</code></pre>
<p>Is there a way, in Ruby, to generate this kind of object model based on a DTD? Or am I stuck using REXML?</p>
<p>Thanks!</p>
| [
{
"answer_id": 28557,
"author": "John Duff",
"author_id": 3041,
"author_profile": "https://Stackoverflow.com/users/3041",
"pm_score": 2,
"selected": false,
"text": "<p>if you include the active_support gem (comes with rails) it adds the method from_xml to the Hash object. You can then c... | 2008/08/26 | [
"https://Stackoverflow.com/questions/28293",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/722/"
] | I have an XML document with a DTD, and would love to be able to access the XML model, something like this:
```
title = Thing.Items[0].Title
```
Is there a way, in Ruby, to generate this kind of object model based on a DTD? Or am I stuck using REXML?
Thanks! | You can use the ruby version of xml-simple.
You shouldn't need to install the gem as I believe it's already installed with rails.
<http://xml-simple.rubyforge.org/> |
28,301 | <p>I'm unsure whether the following code would ensure all conditions given in Comparator's Javadoc. </p>
<pre><code>class TotalOrder<T> implements Comparator<T> {
public boolean compare(T o1, T o2) {
if (o1 == o2 || equal(o1, o2)) return 0;
int h1 = System.identityHashCode(o1);
... | [
{
"answer_id": 28343,
"author": "Damien B",
"author_id": 3069,
"author_profile": "https://Stackoverflow.com/users/3069",
"pm_score": 1,
"selected": false,
"text": "<p>You answered in your comment: </p>\n\n<blockquote>\n <p>equals returned false but identity hash code was same, assume o1... | 2008/08/26 | [
"https://Stackoverflow.com/questions/28301",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3071/"
] | I'm unsure whether the following code would ensure all conditions given in Comparator's Javadoc.
```
class TotalOrder<T> implements Comparator<T> {
public boolean compare(T o1, T o2) {
if (o1 == o2 || equal(o1, o2)) return 0;
int h1 = System.identityHashCode(o1);
int h2 = System.identity... | >
> Hey, look at what I found!
>
>
> <http://gafter.blogspot.com/2007/03/compact-object-comparator.html>
>
>
>
Oh yes, I forgot about the IdentityHashMap (Java 6 and above only). Just have to pay attention at releasing your comparator. |
28,353 | <p>We have a couple of mirrored SQL Server databases.</p>
<p>My first problem - the key problem - is to get a notification when the db fails over. I don't <em>need</em> to know because, erm, its mirrored and so it (almost) all carries on working automagically but it would useful to be advised and I'm currently getting... | [
{
"answer_id": 29277,
"author": "Rob Allen",
"author_id": 149,
"author_profile": "https://Stackoverflow.com/users/149",
"pm_score": 1,
"selected": false,
"text": "<p>If the failover logic is in your application you could write a status screen that shows which box you're connected by writ... | 2008/08/26 | [
"https://Stackoverflow.com/questions/28353",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1070/"
] | We have a couple of mirrored SQL Server databases.
My first problem - the key problem - is to get a notification when the db fails over. I don't *need* to know because, erm, its mirrored and so it (almost) all carries on working automagically but it would useful to be advised and I'm currently getting failovers when I... | Right,
The two answers and a little thought got me to something approaching an answer.
First a little more clarification:
The app is written in C# (2.0+) and uses ADO.NET to talk to SQL Server 2005.
The mirror setup is two W2k3 servers hosting the Principal and the Mirror plus a third server hosting an express inst... |
28,369 | <p>I'm looking for a "safe" eval function, to implement spreadsheet-like calculations (using numpy/scipy).</p>
<p>The functionality to do this (the <a href="http://docs.python.org/lib/module-rexec.html" rel="nofollow noreferrer">rexec module</a>) has been removed from Python since 2.3 due to apparently unfixable secur... | [
{
"answer_id": 28436,
"author": "pix0r",
"author_id": 72,
"author_profile": "https://Stackoverflow.com/users/72",
"pm_score": 2,
"selected": false,
"text": "<p>Writing your own parser could be fun! It might be a better option because people are expecting to use the familiar spreadsheet ... | 2008/08/26 | [
"https://Stackoverflow.com/questions/28369",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3002/"
] | I'm looking for a "safe" eval function, to implement spreadsheet-like calculations (using numpy/scipy).
The functionality to do this (the [rexec module](http://docs.python.org/lib/module-rexec.html)) has been removed from Python since 2.3 due to apparently unfixable security problems. There are several third-party hac... | Depends on your definition of safe I suppose. A lot of the security depends on what you pass in and what you are allowed to pass in the context. For instance, if a file is passed in, I can open arbitrary files:
```
>>> names['f'] = open('foo', 'w+')
>>> safe_eval.safe_eval("baz = type(f)('baz', 'w+')", names)
>>> name... |
28,377 | <p>In Visual Basic, is there a performance difference when using the <code>IIf</code> function instead of the <code>If</code> statement?</p>
| [
{
"answer_id": 28383,
"author": "Greg Hurlman",
"author_id": 35,
"author_profile": "https://Stackoverflow.com/users/35",
"pm_score": 3,
"selected": false,
"text": "<p>According to <a href=\"http://www.vb-helper.com/howto_compare_iif_ifthen_speeds.html\" rel=\"noreferrer\">this guy</a>, I... | 2008/08/26 | [
"https://Stackoverflow.com/questions/28377",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/299/"
] | In Visual Basic, is there a performance difference when using the `IIf` function instead of the `If` statement? | VB has the following `If` statement which the question refers to, I think:
```
' Usage 1
Dim result = If(a > 5, "World", "Hello")
' Usage 2
Dim foo = If(result, "Alternative")
```
The first is basically C#'s ternary conditional operator and the second is its coalesce operator (return `result` unless it’s `Nothing`, ... |
28,380 | <p>Has anybody managed to get the Android Emulator working behind a proxy that requires authentication?</p>
<p>I've tried setting the -http-proxy argument to</p>
<pre><code>http://DOMAIN/USERNAME:PASSWORD@IP:PORT
</code></pre>
<p>but am having no success.</p>
<p>I've tried following the docs to no avail. I've also trie... | [
{
"answer_id": 28406,
"author": "dlamblin",
"author_id": 459,
"author_profile": "https://Stackoverflow.com/users/459",
"pm_score": 2,
"selected": false,
"text": "<p>I've not used the Android Emulator but I have set the $http_proxy environment variable for perl and wget and a few cygwin t... | 2008/08/26 | [
"https://Stackoverflow.com/questions/28380",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1281/"
] | Has anybody managed to get the Android Emulator working behind a proxy that requires authentication?
I've tried setting the -http-proxy argument to
```
http://DOMAIN/USERNAME:PASSWORD@IP:PORT
```
but am having no success.
I've tried following the docs to no avail. I've also tried the `-verbose-proxy` setting but t... | I Managed to do it in the Adndroid 2.2 Emulator.
```
Go to "Settings" -> "Wireless & Networks" -> "Mobile Networks" -> "Access Point Names" -> "Telkila"
```
Over there set the proxy host name in the property "Proxy"
and the Proxy port in the property "Port" |
28,395 | <p>How do you pass <code>$_POST</code> values to a page using <code>cURL</code>?</p>
| [
{
"answer_id": 28411,
"author": "Ross",
"author_id": 2025,
"author_profile": "https://Stackoverflow.com/users/2025",
"pm_score": 8,
"selected": true,
"text": "<p>Should work fine.</p>\n\n<pre><code>$data = array('name' => 'Ross', 'php_master' => true);\n\n// You can POST a file by ... | 2008/08/26 | [
"https://Stackoverflow.com/questions/28395",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2863/"
] | How do you pass `$_POST` values to a page using `cURL`? | Should work fine.
```
$data = array('name' => 'Ross', 'php_master' => true);
// You can POST a file by prefixing with an @ (for <input type="file"> fields)
$data['file'] = '@/home/user/world.jpg';
$handle = curl_init($url);
curl_setopt($handle, CURLOPT_POST, true);
curl_setopt($handle, CURLOPT_POSTFIELDS, $data);
cu... |
28,428 | <p>I want to bring up a file dialog in Java that defaults to the application installation directory.</p>
<p>What's the best way to get that information programmatically?</p>
| [
{
"answer_id": 28454,
"author": "Rich Lawrence",
"author_id": 1281,
"author_profile": "https://Stackoverflow.com/users/1281",
"pm_score": 4,
"selected": true,
"text": "<pre><code>System.getProperty(\"user.dir\") \n</code></pre>\n\n<p>gets the directory the Java VM was started from.</p>\n... | 2008/08/26 | [
"https://Stackoverflow.com/questions/28428",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1288/"
] | I want to bring up a file dialog in Java that defaults to the application installation directory.
What's the best way to get that information programmatically? | ```
System.getProperty("user.dir")
```
gets the directory the Java VM was started from. |
28,478 | <p>I recently asked a question about <a href="https://stackoverflow.com/questions/28377/iif-vs-if">IIf vs. If</a> and found out that there is another function in VB called <strong>If</strong> which basically does the same thing as <strong>IIf</strong> but is a short-circuit.</p>
<p>Does this <strong>If</strong> functi... | [
{
"answer_id": 28498,
"author": "Konrad Rudolph",
"author_id": 1968,
"author_profile": "https://Stackoverflow.com/users/1968",
"pm_score": 5,
"selected": true,
"text": "<p>Damn, I really thought you were talking about the operator all along. ;-) Anyway …</p>\n\n<blockquote>\n <p>Does th... | 2008/08/26 | [
"https://Stackoverflow.com/questions/28478",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/299/"
] | I recently asked a question about [IIf vs. If](https://stackoverflow.com/questions/28377/iif-vs-if) and found out that there is another function in VB called **If** which basically does the same thing as **IIf** but is a short-circuit.
Does this **If** function perform better than the **IIf** function? Does the **If**... | Damn, I really thought you were talking about the operator all along. ;-) Anyway …
>
> Does this If function perform better than the IIf function?
>
>
>
Definitely. Remember, it's built into the language. Only one of the two conditional arguments has to be evaluated, potentially saving a costly operation.
>
> D... |
28,529 | <p>When using <a href="http://jquery.com/" rel="nofollow noreferrer">jQuery</a>'s <a href="http://docs.jquery.com/Ajax/jQuery.ajax#options" rel="nofollow noreferrer">ajax method</a> to submit form data, what is the best way to handle errors?
This is an example of what a call might look like:</p>
<pre><code>$.ajax({
... | [
{
"answer_id": 28537,
"author": "Ian Robinson",
"author_id": 326,
"author_profile": "https://Stackoverflow.com/users/326",
"pm_score": 5,
"selected": true,
"text": "<blockquote>\n <p>Should I be throwing the errors in the\n ashx, or should I be returning a\n status code as part of the... | 2008/08/26 | [
"https://Stackoverflow.com/questions/28529",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1403/"
] | When using [jQuery](http://jquery.com/)'s [ajax method](http://docs.jquery.com/Ajax/jQuery.ajax#options) to submit form data, what is the best way to handle errors?
This is an example of what a call might look like:
```
$.ajax({
url: "userCreation.ashx",
data: { u:userName, p:password, e:email },
type: "PO... | >
> Should I be throwing the errors in the
> ashx, or should I be returning a
> status code as part of the data
> returned by the call to
> userCreation.ashx, then using this to
> decide what action to take? How do you
> handle these situations?
>
>
>
Personally, if possible, I would prefer to handle this on... |
28,542 | <p>My C code snippet takes the address of an argument and stores it in a volatile memory location (preprocessed code):</p>
<pre><code>void foo(unsigned int x) {
*(volatile unsigned int*)(0x4000000 + 0xd4) = (unsigned int)(&x);
}
int main() {
foo(1);
while(1);
}
</code></pre>
<p>I used an SVN version ... | [
{
"answer_id": 28569,
"author": "sparkes",
"author_id": 269,
"author_profile": "https://Stackoverflow.com/users/269",
"pm_score": -1,
"selected": false,
"text": "<blockquote>\n <p>Is this just expected/undefined\n behaviour? Have I done something wrong\n or have I in fact found a Comp... | 2008/08/26 | [
"https://Stackoverflow.com/questions/28542",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/616/"
] | My C code snippet takes the address of an argument and stores it in a volatile memory location (preprocessed code):
```
void foo(unsigned int x) {
*(volatile unsigned int*)(0x4000000 + 0xd4) = (unsigned int)(&x);
}
int main() {
foo(1);
while(1);
}
```
I used an SVN version of GCC for compiling this code... | Once you return from `foo()`, `x` is gone, and any pointers to it are invalid. Subsequently using such a pointer results in what the C standard likes to call "undefined behavior," which means the compiler is absolutely allowed to assume you won't dereference it, or (if you insist on doing it anyway) need not produce co... |
28,559 | <p>What's the best Python idiom for this C construct?</p>
<pre><code>while ((x = next()) != END) {
....
}
</code></pre>
<p>I don't have the ability to recode next().</p>
<p>update: and the answer from seems to be:</p>
<pre><code>for x in iter(next, END):
....
</code></pre>
| [
{
"answer_id": 28563,
"author": "Blair Conrad",
"author_id": 1199,
"author_profile": "https://Stackoverflow.com/users/1199",
"pm_score": 2,
"selected": false,
"text": "<p>Maybe it's not terribly idiomatic, but I'd be inclined to go with</p>\n\n<pre><code>x = next()\nwhile x != END:\n ... | 2008/08/26 | [
"https://Stackoverflow.com/questions/28559",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/116/"
] | What's the best Python idiom for this C construct?
```
while ((x = next()) != END) {
....
}
```
I don't have the ability to recode next().
update: and the answer from seems to be:
```
for x in iter(next, END):
....
``` | Short answer: there's no way to do inline variable assignment in a while loop in Python. Meaning that I **cannot** say:
```
while x=next():
// do something here!
```
Since that's not possible, there are a number of "idiomatically correct" ways of doing this:
```
while 1:
x = next()
if x != END:
... |
28,577 | <p>I need to store products for an e-commerce solution in a database. Each product should have descriptive information, such as name, description etc.</p>
<p>I need any product to be localized to x number of languages.</p>
<p>What I've done so far, is to make any column that should be localized and <code>nvarchar(MAX... | [
{
"answer_id": 28603,
"author": "bdukes",
"author_id": 2688,
"author_profile": "https://Stackoverflow.com/users/2688",
"pm_score": 1,
"selected": false,
"text": "<p>Rob Conery's MVC Storefront webcast series has <a href=\"http://blog.wekeroad.com/mvc-storefront/mvcstore-part-5/\" rel=\"n... | 2008/08/26 | [
"https://Stackoverflow.com/questions/28577",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2972/"
] | I need to store products for an e-commerce solution in a database. Each product should have descriptive information, such as name, description etc.
I need any product to be localized to x number of languages.
What I've done so far, is to make any column that should be localized and `nvarchar(MAX)` and then i store an... | You should store the current language somewhere (in a [singleton](http://www.yoda.arachsys.com/csharp/singleton.html), for instance) and in the product.Name property use the language setting to get the correct string. This way you only have to write the language specific code once for each field rather than thinking ab... |
28,637 | <p>I need to find a bottleneck and need to accurately as possible measure time.</p>
<p>Is the following code snippet the best way to measure the performance?</p>
<pre><code>DateTime startTime = DateTime.Now;
// Some execution process
DateTime endTime = DateTime.Now;
TimeSpan totalTimeTaken = endTime.Subtract(startT... | [
{
"answer_id": 28646,
"author": "jsight",
"author_id": 1432,
"author_profile": "https://Stackoverflow.com/users/1432",
"pm_score": 4,
"selected": false,
"text": "<p>The <a href=\"http://cplus.about.com/od/howtodothingsinc/a/timing.htm\" rel=\"noreferrer\">stopwatch</a> functionality woul... | 2008/08/26 | [
"https://Stackoverflow.com/questions/28637",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2469/"
] | I need to find a bottleneck and need to accurately as possible measure time.
Is the following code snippet the best way to measure the performance?
```
DateTime startTime = DateTime.Now;
// Some execution process
DateTime endTime = DateTime.Now;
TimeSpan totalTimeTaken = endTime.Subtract(startTime);
``` | No, it's not. Use the [Stopwatch](http://msdn2.microsoft.com/en-us/library/system.diagnostics.stopwatch.aspx) (in `System.Diagnostics`)
```
Stopwatch sw = Stopwatch.StartNew();
PerformWork();
sw.Stop();
Console.WriteLine("Time taken: {0}ms", sw.Elapsed.TotalMilliseconds);
```
Stopwatch automatically checks for the ... |
28,642 | <p>Having a heckuva time with this one, though I feel I'm missing something obvious. I have a control that inherits from <code>System.Web.UI.WebControls.Button</code>, and then implements an interface that I have set up. So think...</p>
<pre><code>public class Button : System.Web.UI.WebControls.Button, IMyButtonInterf... | [
{
"answer_id": 28662,
"author": "bdukes",
"author_id": 2688,
"author_profile": "https://Stackoverflow.com/users/2688",
"pm_score": 1,
"selected": false,
"text": "<p>Interfaces are close enough to types that it should feel about the same. I'd use the <a href=\"http://msdn.microsoft.com/e... | 2008/08/26 | [
"https://Stackoverflow.com/questions/28642",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1212/"
] | Having a heckuva time with this one, though I feel I'm missing something obvious. I have a control that inherits from `System.Web.UI.WebControls.Button`, and then implements an interface that I have set up. So think...
```
public class Button : System.Web.UI.WebControls.Button, IMyButtonInterface { ... }
```
In the ... | Longhorn213 almost has the right answer, but as as Sean Chambers and bdukes say, you should use
```
ctrl is IInterfaceToFind
```
instead of
```
ctrl.GetType() == aTypeVariable
```
The reason why is that if you use `.GetType()` you will get the true type of an object, not necessarily what it can also be cast t... |
28,708 | <p>My code needs to determine how long a particular process has been running. But it continues to fail with an access denied error message on the <code>Process.StartTime</code> request. This is a process running with a User's credentials (ie, not a high-privilege process). There's clearly a security setting or a policy... | [
{
"answer_id": 28727,
"author": "Will Dean",
"author_id": 987,
"author_profile": "https://Stackoverflow.com/users/987",
"pm_score": 1,
"selected": false,
"text": "<p>The underlying code needs to be able to call OpenProcess, for which you may require SeDebugPrivilege.</p>\n\n<p>Is the pro... | 2008/08/26 | [
"https://Stackoverflow.com/questions/28708",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1975282/"
] | My code needs to determine how long a particular process has been running. But it continues to fail with an access denied error message on the `Process.StartTime` request. This is a process running with a User's credentials (ie, not a high-privilege process). There's clearly a security setting or a policy setting, or *... | I've read something similar to what you said in the past, Lars. Unfortunately, I'm somewhat restricted with what I can do with the machine in question (in other words, I can't go creating user groups willy-nilly: it's a server, not just some random PC).
Thanks for the answers, Will and Lars. Unfortunately, they didn't... |
28,709 | <p>In Eclipse 3.2.2 on Linux content assist is not finding classes within the same project. Upgrading above 3.2 is not an option as SWT is not available above 3.2 for Solaris.</p>
<p>I have seen suggestions to clean the workspace, reopen the workspace, run eclipse with the <code>-clean</code> command, none of which ha... | [
{
"answer_id": 28733,
"author": "Cem Catikkas",
"author_id": 3087,
"author_profile": "https://Stackoverflow.com/users/3087",
"pm_score": 2,
"selected": false,
"text": "<p>Go to Java/Editor/Content Assist/Advanced in Preferences, and make sure that the correct proposal kinds are selected.... | 2008/08/26 | [
"https://Stackoverflow.com/questions/28709",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1539/"
] | In Eclipse 3.2.2 on Linux content assist is not finding classes within the same project. Upgrading above 3.2 is not an option as SWT is not available above 3.2 for Solaris.
I have seen suggestions to clean the workspace, reopen the workspace, run eclipse with the `-clean` command, none of which has worked. | Thanks for your last comment it worked partially.
If there is any kind of errors, the content assist wont work. Once fixed, it partially works.
I say partially because, there appear to be a bug, when I do Perl EPIC inheritance ex:
```
package FG::CatalogueFichier;
use FG::Catalogue;
our @ISA = qw(FG::Catalogue);
use ... |
28,713 | <p>Is there a simple way of getting a HTML textarea and an input type="text" to render with (approximately) equal width (in pixels), that works in different browsers?</p>
<p>A CSS/HTML solution would be brilliant. I would prefer not to have to use Javascript.</p>
<p>Thanks
/Erik</p>
| [
{
"answer_id": 28728,
"author": "Re0sless",
"author_id": 2098,
"author_profile": "https://Stackoverflow.com/users/2098",
"pm_score": 5,
"selected": true,
"text": "<p>You should be able to use</p>\n<p><div class=\"snippet\" data-lang=\"js\" data-hide=\"false\" data-console=\"true\" data-b... | 2008/08/26 | [
"https://Stackoverflow.com/questions/28713",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/276/"
] | Is there a simple way of getting a HTML textarea and an input type="text" to render with (approximately) equal width (in pixels), that works in different browsers?
A CSS/HTML solution would be brilliant. I would prefer not to have to use Javascript.
Thanks
/Erik | You should be able to use
```css
.mywidth {
width: 100px;
}
```
```html
<input class="mywidth">
<br>
<textarea class="mywidth"></textarea>
``` |
28,723 | <p>In handling a form post I have something like</p>
<pre><code> public ActionResult Insert()
{
Order order = new Order();
BindingHelperExtensions.UpdateFrom(order, this.Request.Form);
this.orderService.Save(order);
return this.RedirectToAction("Details", new { id = order.ID })... | [
{
"answer_id": 28799,
"author": "Matt Hinze",
"author_id": 2676,
"author_profile": "https://Stackoverflow.com/users/2676",
"pm_score": 0,
"selected": false,
"text": "<p>Wrap it in an interface and mock it.</p>\n"
},
{
"answer_id": 29087,
"author": "liammclennan",
"author_... | 2008/08/26 | [
"https://Stackoverflow.com/questions/28723",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3046/"
] | In handling a form post I have something like
```
public ActionResult Insert()
{
Order order = new Order();
BindingHelperExtensions.UpdateFrom(order, this.Request.Form);
this.orderService.Save(order);
return this.RedirectToAction("Details", new { id = order.ID });
}
```
... | I'm now using [ModelBinder](https://stackoverflow.com/questions/34709/how-do-you-use-the-new-modelbinder-classes-in-aspnet-mvc-preview-5#34725) so that my action method can look (basically) like:
```
public ActionResult Insert(Contact contact)
{
if (this.ViewData.ModelState.IsValid)
{
... |
28,765 | <p>I recently upgraded a VS2005 web deployment project to VS2008 - and now I get the following error when building:</p>
<pre><code>The specified task executable location "bin\aspnet_merge.exe" is invalid.
</code></pre>
<p>Here is the source of the error (from the web deployment targets file):</p>
<pre><code><Targ... | [
{
"answer_id": 28822,
"author": "Adam",
"author_id": 1341,
"author_profile": "https://Stackoverflow.com/users/1341",
"pm_score": 4,
"selected": true,
"text": "<p>Apparently aspnet_merge.exe (and all the other SDK tools) are NOT packaged in Visual Studio 2008. Visual Studio 2005 packaged... | 2008/08/26 | [
"https://Stackoverflow.com/questions/28765",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1341/"
] | I recently upgraded a VS2005 web deployment project to VS2008 - and now I get the following error when building:
```
The specified task executable location "bin\aspnet_merge.exe" is invalid.
```
Here is the source of the error (from the web deployment targets file):
```
<Target Name="AspNetMerge" Condition="'$(UseM... | Apparently aspnet\_merge.exe (and all the other SDK tools) are NOT packaged in Visual Studio 2008. Visual Studio 2005 packaged these tools as part of its installation.
The place to get this is an installation of the Windows 2008 SDK ([latest download](http://www.microsoft.com/downloads/thankyou.aspx?familyId=e6e1c3df-... |
28,817 | <p>There is a legacy CVS repository, which contains a large number of directories, sub-directories, and paths. There is also a large number of branches and tags that do not necessarilly cover all paths & files - usually a subset. How can I find out, which branch / tag covers, which files and paths?</p>
<p>CVS log ... | [
{
"answer_id": 28855,
"author": "Johannes Hoff",
"author_id": 3102,
"author_profile": "https://Stackoverflow.com/users/3102",
"pm_score": 0,
"selected": false,
"text": "<p>I don't know of any tool that can help you, but if you are writing your own, I can save you from one headace: Direct... | 2008/08/26 | [
"https://Stackoverflow.com/questions/28817",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2877/"
] | There is a legacy CVS repository, which contains a large number of directories, sub-directories, and paths. There is also a large number of branches and tags that do not necessarilly cover all paths & files - usually a subset. How can I find out, which branch / tag covers, which files and paths?
CVS log already provid... | To determine what tags apply to a particular file use:
```
cvs log <filename>
```
This will output all the versions of the file and what tags have been applied to the version.
To determine what files are included in a single tag, the only thing I can think of is to check out using the tag and see what files come ba... |
28,823 | <p>I have never worked with web services and rails, and obviously this is something I need to learn.
I have chosen to use hpricot because it looks great.
Anyway, _why's been nice enough to provide the following example on the <a href="http://code.whytheluckystiff.net/hpricot/" rel="nofollow noreferrer">hpricot website<... | [
{
"answer_id": 28841,
"author": "John Topley",
"author_id": 1450,
"author_profile": "https://Stackoverflow.com/users/1450",
"pm_score": 0,
"selected": false,
"text": "<p>I'd probably go for a REST approach and have resources that represent the different entities within the XML file being... | 2008/08/26 | [
"https://Stackoverflow.com/questions/28823",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2293/"
] | I have never worked with web services and rails, and obviously this is something I need to learn.
I have chosen to use hpricot because it looks great.
Anyway, \_why's been nice enough to provide the following example on the [hpricot website](http://code.whytheluckystiff.net/hpricot/):
```
#!ruby
require 'hpricot'
r... | Model, model, model, model, model. Skinny controllers, simple views.
The RedHandedHomePage model does the parsing on initialization, then call 'def render' in the controller, set output to an instance variable, and print that in a view. |
28,832 | <p>If I call <code>finalize()</code> on an object from my program code, will the <strong>JVM</strong> still run the method again when the garbage collector processes this object?</p>
<p>This would be an approximate example:</p>
<pre><code>MyObject m = new MyObject();
m.finalize();
m = null;
System.gc()
</code></pr... | [
{
"answer_id": 28856,
"author": "John Topley",
"author_id": 1450,
"author_profile": "https://Stackoverflow.com/users/1450",
"pm_score": 2,
"selected": false,
"text": "<p>The finalize method is never invoked more than once by a JVM for any given object. You shouldn't be relying on finaliz... | 2008/08/26 | [
"https://Stackoverflow.com/questions/28832",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2697/"
] | If I call `finalize()` on an object from my program code, will the **JVM** still run the method again when the garbage collector processes this object?
This would be an approximate example:
```
MyObject m = new MyObject();
m.finalize();
m = null;
System.gc()
```
Would the explicit call to `finalize()` make the *... | According to this simple test program, the JVM will still make its call to finalize() even if you explicitly called it:
```
private static class Blah
{
public void finalize() { System.out.println("finalizing!"); }
}
private static void f() throws Throwable
{
Blah blah = new Blah();
blah.finalize();
}
public ... |
28,878 | <p>I'm translating my C# code for YouTube video comments into PHP. In order to properly nest comment replies, I need to re-arrange XML nodes. In PHP I'm using DOMDocument and DOMXPath which closely corresponds to C# XmlDocument. I've gotten pretty far in my translation but now I'm stuck on getting the parent node of a ... | [
{
"answer_id": 28944,
"author": "Marius",
"author_id": 1585,
"author_profile": "https://Stackoverflow.com/users/1585",
"pm_score": 5,
"selected": false,
"text": "<p><a href=\"http://no2.php.net/manual/en/class.domelement.php\" rel=\"noreferrer\">DOMElement</a> is a subclass of <a href=\"... | 2008/08/26 | [
"https://Stackoverflow.com/questions/28878",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2601/"
] | I'm translating my C# code for YouTube video comments into PHP. In order to properly nest comment replies, I need to re-arrange XML nodes. In PHP I'm using DOMDocument and DOMXPath which closely corresponds to C# XmlDocument. I've gotten pretty far in my translation but now I'm stuck on getting the parent node of a DOM... | [DOMElement](http://no2.php.net/manual/en/class.domelement.php) is a subclass of [DOMNode](http://no2.php.net/manual/en/class.domnode.php), so it does have parent\_node property. Just use $domNode->parentNode; to find the parent node.
In your example, the parent node of $importnode is null, because it has been importe... |
28,894 | <p>For years I have been using the DEBUG compiler constant in VB.NET to write messages to the console. I've also been using System.Diagnostics.Debug.Write in similar fashion. It was always my understanding that when RELEASE was used as the build option, that all of these statements were left out by the compiler, free... | [
{
"answer_id": 28907,
"author": "Vincent",
"author_id": 1508,
"author_profile": "https://Stackoverflow.com/users/1508",
"pm_score": -1,
"selected": false,
"text": "<p>In my experience choosing between Debug and Release in VB.NET makes no difference. You may add custom actions to both con... | 2008/08/26 | [
"https://Stackoverflow.com/questions/28894",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3059/"
] | For years I have been using the DEBUG compiler constant in VB.NET to write messages to the console. I've also been using System.Diagnostics.Debug.Write in similar fashion. It was always my understanding that when RELEASE was used as the build option, that all of these statements were left out by the compiler, freeing y... | The preferred method is to actually use the conditional attribute to wrap your debug calls, not use the compiler directives. #ifs can get tricky and can lead to weird build problems.
An example of using a conditional attribute is as follows (in C#, but works in VB.NET too):
```
[ Conditional("Debug") ]
private void W... |
28,896 | <p>I'm currently designing a program that will involve some physics (nothing too fancy, a few balls crashing to each other)</p>
<p>What's the most exact datatype I can use to represent position (without a feeling of discrete jumps) in c#?</p>
<p>Also, what's the smallest ammount of time I can get between t and t+1? O... | [
{
"answer_id": 28914,
"author": "OysterD",
"author_id": 2638,
"author_profile": "https://Stackoverflow.com/users/2638",
"pm_score": 0,
"selected": false,
"text": "<p>I'm not sure I understand your last question, could you please clarify?</p>\n\n<p>Edit:</p>\n\n<p>I might still not unders... | 2008/08/26 | [
"https://Stackoverflow.com/questions/28896",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1782/"
] | I'm currently designing a program that will involve some physics (nothing too fancy, a few balls crashing to each other)
What's the most exact datatype I can use to represent position (without a feeling of discrete jumps) in c#?
Also, what's the smallest ammount of time I can get between t and t+1? One tick?
EDIT: C... | In .Net a `decimal` will be the most precise datatype that you could use for position. I would just write a class for the position:
```
public class Position
{
decimal x;
decimal y;
decimal z;
}
```
As for time, your processor can't give you anything smaller than one tick.
Sounds like an fun project! Go... |
28,922 | <p>I have an SQL server database that I am querying and I only want to get the information when a specific row is null. I used a where statement such as:</p>
<pre><code>WHERE database.foobar = NULL
</code></pre>
<p>and it does not return anything. However, I know that there is at least one result because I created an... | [
{
"answer_id": 28924,
"author": "bdukes",
"author_id": 2688,
"author_profile": "https://Stackoverflow.com/users/2688",
"pm_score": 4,
"selected": true,
"text": "<p>Correct syntax is WHERE database.foobar IS NULL. See <a href=\"http://msdn.microsoft.com/en-us/library/ms188795.aspx\" rel=... | 2008/08/26 | [
"https://Stackoverflow.com/questions/28922",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2486/"
] | I have an SQL server database that I am querying and I only want to get the information when a specific row is null. I used a where statement such as:
```
WHERE database.foobar = NULL
```
and it does not return anything. However, I know that there is at least one result because I created an instance in the database ... | Correct syntax is WHERE database.foobar IS NULL. See <http://msdn.microsoft.com/en-us/library/ms188795.aspx> for more info |
28,952 | <p>Is it possible to get a breakdown of CPU utilization <strong>by database</strong>?</p>
<p>I'm ideally looking for a Task Manager type interface for SQL server, but instead of looking at the CPU utilization of each PID (like <code>taskmgr</code>) or each SPID (like <code>spwho2k5</code>), I want to view the total CP... | [
{
"answer_id": 28974,
"author": "Adam",
"author_id": 1341,
"author_profile": "https://Stackoverflow.com/users/1341",
"pm_score": 4,
"selected": false,
"text": "<p>SQL Server (starting with 2000) will install performance counters (viewable from Performance Monitor or Perfmon).</p>\n\n<p>O... | 2008/08/26 | [
"https://Stackoverflow.com/questions/28952",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1690/"
] | Is it possible to get a breakdown of CPU utilization **by database**?
I'm ideally looking for a Task Manager type interface for SQL server, but instead of looking at the CPU utilization of each PID (like `taskmgr`) or each SPID (like `spwho2k5`), I want to view the total CPU utilization of each database. Assume a sing... | Sort of. Check this query out:
```
SELECT total_worker_time/execution_count AS AvgCPU
, total_worker_time AS TotalCPU
, total_elapsed_time/execution_count AS AvgDuration
, total_elapsed_time AS TotalDuration
, (total_logical_reads+total_physical_reads)/execution_count AS AvgReads
, (total_logical_reads+total_ph... |
28,982 | <p>Related to my <a href="https://stackoverflow.com/questions/28975/anyone-using-couchdb">CouchDB</a> question.</p>
<p>Can anyone explain MapReduce in terms a numbnuts could understand?</p>
| [
{
"answer_id": 28991,
"author": "Frank Krueger",
"author_id": 338,
"author_profile": "https://Stackoverflow.com/users/338",
"pm_score": 5,
"selected": false,
"text": "<ol>\n<li>Take a bunch of data</li>\n<li>Perform some kind of transformation that converts every datum to another kind of... | 2008/08/26 | [
"https://Stackoverflow.com/questions/28982",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2745/"
] | Related to my [CouchDB](https://stackoverflow.com/questions/28975/anyone-using-couchdb) question.
Can anyone explain MapReduce in terms a numbnuts could understand? | Going all the way down to the basics for Map and Reduce.
---
**Map** is a function which "transforms" items in some kind of list to another kind of item and put them back in the same kind of list.
suppose I have a list of numbers: [1,2,3] and I want to double every number, in this case, the function to "double every... |
29,004 | <p>Sometimes I need to quickly extract some arbitrary data from XML files to put into a CSV format. What's your best practices for doing this in the Unix terminal? I would love some code examples, so for instance how can I get the following problem solved?</p>
<p>Example XML input:</p>
<pre class="lang-html prettyprint... | [
{
"answer_id": 29023,
"author": "Peter Hilton",
"author_id": 2670,
"author_profile": "https://Stackoverflow.com/users/2670",
"pm_score": 3,
"selected": false,
"text": "<p>Use a command-line XSLT processor such as <a href=\"http://xmlsoft.org/XSLT/xsltproc2.html\" rel=\"noreferrer\">xsltp... | 2008/08/26 | [
"https://Stackoverflow.com/questions/29004",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/261/"
] | Sometimes I need to quickly extract some arbitrary data from XML files to put into a CSV format. What's your best practices for doing this in the Unix terminal? I would love some code examples, so for instance how can I get the following problem solved?
Example XML input:
```html
<root>
<myel name="Foo" />
<m... | If you just want the name attributes of any element, here is a quick but incomplete solution.
(Your example text is in the file *example*)
>
> grep "name" example | cut -d"\"" -f2,2
> | xargs -I{} echo "{},"
>
>
> |
29,011 | <p>I have</p>
<pre><code>class Foo < ActiveRecord::Base
named_scope :a, lambda { |a| :conditions => { :a => a } }
named_scope :b, lambda { |b| :conditions => { :b => b } }
end
</code></pre>
<p>I'd like</p>
<pre><code>class Foo < ActiveRecord::Base
named_scope :ab, lambda { |a,b| :conditions =... | [
{
"answer_id": 30719,
"author": "PJ.",
"author_id": 3230,
"author_profile": "https://Stackoverflow.com/users/3230",
"pm_score": 3,
"selected": true,
"text": "<p>Well I'm still new to rails and I'm not sure exactly what you're going for here, but if you're just going for code reuse why no... | 2008/08/26 | [
"https://Stackoverflow.com/questions/29011",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1190/"
] | I have
```
class Foo < ActiveRecord::Base
named_scope :a, lambda { |a| :conditions => { :a => a } }
named_scope :b, lambda { |b| :conditions => { :b => b } }
end
```
I'd like
```
class Foo < ActiveRecord::Base
named_scope :ab, lambda { |a,b| :conditions => { :a => a, :b => b } }
end
```
but I'd prefer to do... | Well I'm still new to rails and I'm not sure exactly what you're going for here, but if you're just going for code reuse why not use a regular class method?
```
def self.ab(a, b)
a(a).b(b)
end
```
You could make that more flexible by taking \*args instead of a and b, and then possibly m... |
29,053 | <p>Code:</p>
<pre><code><html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Unusual Array Lengths!</title>
<script type="text/javascript">
var arrayList = new Array();
arrayList = [1, 2, 3, 4, 5, ];
alert(arrayList.length);
</script>
</... | [
{
"answer_id": 29062,
"author": "Damien B",
"author_id": 3069,
"author_profile": "https://Stackoverflow.com/users/3069",
"pm_score": 2,
"selected": false,
"text": "<p>\"3\" for those cases, I usually put in my scripts </p>\n\n<pre><code>if(!arrayList[arrayList.length -1]) arrayList.pop()... | 2008/08/26 | [
"https://Stackoverflow.com/questions/29053",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/384/"
] | Code:
```
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Unusual Array Lengths!</title>
<script type="text/javascript">
var arrayList = new Array();
arrayList = [1, 2, 3, 4, 5, ];
alert(arrayList.length);
</script>
</head>
<body>
</body>
</html>
```
Notice the extra c... | It seems to me that the Firefox behavior is correct. What is the value of the 6th value in IE (sorry I don't have it handy to test). Since there is no actual value provided, I imagine it's filling it with something like 'null' which certainly doesn't seem to be what you intended to have happen when you created the arra... |
29,061 | <p>When I try to use an <strong>ssh</strong> command in a shell script, the command just sits there. Do you have an example of how to use <strong>ssh</strong> in a shell script?</p>
| [
{
"answer_id": 29078,
"author": "Iker Jimenez",
"author_id": 2697,
"author_profile": "https://Stackoverflow.com/users/2697",
"pm_score": 0,
"selected": false,
"text": "<p>You can use <a href=\"https://en.wikipedia.org/wiki/Expect\" rel=\"nofollow noreferrer\"><code>expect</code></a> comm... | 2008/08/26 | [
"https://Stackoverflow.com/questions/29061",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1438/"
] | When I try to use an **ssh** command in a shell script, the command just sits there. Do you have an example of how to use **ssh** in a shell script? | Depends on what you want to do, and how you use it. If you just want to execute a command remotely and safely on another machine, just use
```
ssh user@host command
```
for example
```
ssh user@host ls
```
In order to do this safely you need to either ask the user for the password during runtime, or set up keys o... |
29,067 | <p>I have a repeater that is bound to some data.</p>
<p>I bind to the <strong>ItemDataBound</strong> event, and I am attempting to <strong>programmatically</strong> create a <strong>UserControl</strong>:</p>
<p>In a nutshell:</p>
<pre><code>void rptrTaskList_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
... | [
{
"answer_id": 29080,
"author": "FlySwat",
"author_id": 1965,
"author_profile": "https://Stackoverflow.com/users/1965",
"pm_score": 1,
"selected": false,
"text": "<p>Eh, figured out one way to do it:</p>\n\n<pre><code>ExecTaskControl foo = (ExecTaskControl)LoadControl(\"tasks\\\\ExecTask... | 2008/08/26 | [
"https://Stackoverflow.com/questions/29067",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1965/"
] | I have a repeater that is bound to some data.
I bind to the **ItemDataBound** event, and I am attempting to **programmatically** create a **UserControl**:
In a nutshell:
```
void rptrTaskList_ItemDataBound(object sender, RepeaterItemEventArgs e)
{
CCTask task = (CCTask)e.Item.DataItem;
if (task is ExecTask)... | Eh, figured out one way to do it:
```
ExecTaskControl foo = (ExecTaskControl)LoadControl("tasks\\ExecTaskControl.ascx");
```
It seems silly to have a file depedancy like that, but maybe thats how UserControls must be done. |
29,088 | <p>What is the difference between a <a href="http://msdn.microsoft.com/en-us/library/system.text.regularexpressions.group.aspx" rel="nofollow noreferrer">Group</a> and a <a href="http://msdn.microsoft.com/en-us/library/system.text.regularexpressions.match.aspx" rel="nofollow noreferrer">Match</a> in .NET's RegEx?</p>
| [
{
"answer_id": 29108,
"author": "Blair Conrad",
"author_id": 1199,
"author_profile": "https://Stackoverflow.com/users/1199",
"pm_score": 4,
"selected": true,
"text": "<p>A <a href=\"http://msdn.microsoft.com/en-us/library/system.text.regularexpressions.match.aspx\" rel=\"noreferrer\">Mat... | 2008/08/26 | [
"https://Stackoverflow.com/questions/29088",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1463/"
] | What is the difference between a [Group](http://msdn.microsoft.com/en-us/library/system.text.regularexpressions.group.aspx) and a [Match](http://msdn.microsoft.com/en-us/library/system.text.regularexpressions.match.aspx) in .NET's RegEx? | A [Match](http://msdn.microsoft.com/en-us/library/system.text.regularexpressions.match.aspx) is an object that indicates a particular regular expression matched (a portion of) the target text. A [Group](http://msdn.microsoft.com/en-us/library/system.text.regularexpressions.group.aspx) indicates a portion of a match, if... |
29,107 | <p>Can anyone suggest a good implementation of a generic collection class that implements the <code>IBindingListView</code> & <code>IBindingList</code> interfaces and provides Filtering and Searching capabilities?</p>
<p>I see my current options as:<br /></p>
<ul>
<li>Using a class that someone else has written a... | [
{
"answer_id": 29146,
"author": "Joseph Daigle",
"author_id": 507,
"author_profile": "https://Stackoverflow.com/users/507",
"pm_score": 1,
"selected": false,
"text": "<p>A couple of solutions I can think of:</p>\n\n<ol>\n<li><p>The <a href=\"http://subsonicproject.com/\" rel=\"nofollow n... | 2008/08/26 | [
"https://Stackoverflow.com/questions/29107",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/708/"
] | Can anyone suggest a good implementation of a generic collection class that implements the `IBindingListView` & `IBindingList` interfaces and provides Filtering and Searching capabilities?
I see my current options as:
* Using a class that someone else has written and tested
* Inheriting from `BindingList<T>`, and i... | I used and built upon an implementation I found on and old MSDN forum post from a few years ago, but recently I searched around again and found a sourceforge project called [BindingListView](http://blw.sourceforge.net/). It looks pretty nice, I just haven't pulled it in to replace my hacked version yet.
nuget package... |
29,141 | <p>The problem: Loading an excel spreadsheet template. Using the Save command with a different filename and then quitting the interop object. This ends up saving the original template file. Not the result that is liked.</p>
<pre><code>public void saveAndExit(string filename)
{
excelApplication.Save(filen... | [
{
"answer_id": 29218,
"author": "Joel Lucsy",
"author_id": 645,
"author_profile": "https://Stackoverflow.com/users/645",
"pm_score": 0,
"selected": false,
"text": "<p>Have you tried the SaveAs from the Worksheet?</p>\n"
},
{
"answer_id": 29222,
"author": "Jason Z",
"autho... | 2008/08/26 | [
"https://Stackoverflow.com/questions/29141",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3135/"
] | The problem: Loading an excel spreadsheet template. Using the Save command with a different filename and then quitting the interop object. This ends up saving the original template file. Not the result that is liked.
```
public void saveAndExit(string filename)
{
excelApplication.Save(filename);
excelA... | Excel interop is pretty painful. I dug up an old project I had, did a little fiddling, and I think this is what you're looking for. The other commenters are right, but, at least in my experience, there's a lot more to calling SaveAs() than you'd expect if you've used the same objects (without the interop wrapper) in VB... |
29,142 | <p>This is a follow-on question to the <a href="https://stackoverflow.com/questions/29061/how-do-you-use-ssh-in-a-shell-script">How do you use ssh in a shell script?</a> question. If I want to execute a command on the remote machine that runs in the background on that machine, how do I get the ssh command to return? ... | [
{
"answer_id": 29172,
"author": "Jax",
"author_id": 23,
"author_profile": "https://Stackoverflow.com/users/23",
"pm_score": 10,
"selected": true,
"text": "<p>I had this problem in a program I wrote a year ago -- turns out the answer is rather complicated. You'll need to use nohup as well... | 2008/08/26 | [
"https://Stackoverflow.com/questions/29142",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/171/"
] | This is a follow-on question to the [How do you use ssh in a shell script?](https://stackoverflow.com/questions/29061/how-do-you-use-ssh-in-a-shell-script) question. If I want to execute a command on the remote machine that runs in the background on that machine, how do I get the ssh command to return? When I try to ju... | I had this problem in a program I wrote a year ago -- turns out the answer is rather complicated. You'll need to use nohup as well as output redirection, as explained in the wikipedia artcle on [nohup](http://en.wikipedia.org/wiki/Nohup), copied here for your convenience.
>
> Nohuping backgrounded jobs is for
> exa... |
29,157 | <p>I am using StretchImage because the box is resizable with splitters. It looks like the default is some kind of smooth bilinear filtering, causing my image to be blurry and have moire patterns. </p>
| [
{
"answer_id": 29209,
"author": "Joel Lucsy",
"author_id": 645,
"author_profile": "https://Stackoverflow.com/users/645",
"pm_score": 3,
"selected": false,
"text": "<p>I suspect you're going to have to do the resizing manually thru the Image class and DrawImage function and respond to the... | 2008/08/26 | [
"https://Stackoverflow.com/questions/29157",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2543/"
] | I am using StretchImage because the box is resizable with splitters. It looks like the default is some kind of smooth bilinear filtering, causing my image to be blurry and have moire patterns. | I needed this functionality also. I made a class that inherits PictureBox, overrides `OnPaint` and adds a property to allow the interpolation mode to be set:
```
using System.Drawing.Drawing2D;
using System.Windows.Forms;
/// <summary>
/// Inherits from PictureBox; adds Interpolation Mode Setting
/// </summary>
publi... |
29,168 | <p>My master branch layout is like this:</p>
<p><strong>/</strong> <-- top level</p>
<p><strong>/client</strong> <-- desktop client source files</p>
<p><strong>/server</strong> <-- Rails app</p>
<p>What I'd like to do is only pull down the /server directory in my <code>deploy.rb</code>, but I can't seem to... | [
{
"answer_id": 29628,
"author": "Silas Snider",
"author_id": 2933,
"author_profile": "https://Stackoverflow.com/users/2933",
"pm_score": 1,
"selected": false,
"text": "<p>Unfortunately, git provides no way to do this. Instead, the 'git way' is to have two repositories -- client and serve... | 2008/08/26 | [
"https://Stackoverflow.com/questions/29168",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/574/"
] | My master branch layout is like this:
**/** <-- top level
**/client** <-- desktop client source files
**/server** <-- Rails app
What I'd like to do is only pull down the /server directory in my `deploy.rb`, but I can't seem to find any way to do that. The /client directory is huge, so setting up a hook to copy /ser... | Without any dirty forking action but even dirtier !
In my config/deploy.rb :
```
set :deploy_subdir, "project/subdir"
```
Then I added this new strategy to my Capfile :
```
require 'capistrano/recipes/deploy/strategy/remote_cache'
class RemoteCacheSubdir < Capistrano::Deploy::Strategy::RemoteCache
private
d... |
29,242 | <p>I work a lot with network and serial communications software, so it is often necessary for me to have code to display or log hex dumps of data packets.</p>
<p>Every time I do this, I write yet another hex-dump routine from scratch. I'm about to do so again, but figured I'd ask here: Is there any good free hex dum... | [
{
"answer_id": 29254,
"author": "Damien B",
"author_id": 3069,
"author_profile": "https://Stackoverflow.com/users/3069",
"pm_score": 1,
"selected": false,
"text": "<p>Could you write your <a href=\"http://www.richardsharpe.com/ethereal-stuff.html#Writing%20a%20Dissector\" rel=\"nofollow ... | 2008/08/27 | [
"https://Stackoverflow.com/questions/29242",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1175/"
] | I work a lot with network and serial communications software, so it is often necessary for me to have code to display or log hex dumps of data packets.
Every time I do this, I write yet another hex-dump routine from scratch. I'm about to do so again, but figured I'd ask here: Is there any good free hex dump code for C... | The unix tool `xxd` is distributed as part of [`vim`](http://www.vim.org/download.php), and according to <http://www.vmunix.com/vim/util.html#xxd>, the source for xxd is <ftp://ftp.uni-erlangen.de:21/pub/utilities/etc/xxd-1.10.tar.gz>. It was written in C and is about 721 lines. The only licensing information given for... |
29,243 | <p>Here is my sample code:</p>
<pre><code>from xml.dom.minidom import *
def make_xml():
doc = Document()
node = doc.createElement('foo')
node.innerText = 'bar'
doc.appendChild(node)
return doc
if __name__ == '__main__':
make_xml().writexml(sys.stdout)
</code></pre>
<p>when I run the above code... | [
{
"answer_id": 29255,
"author": "dF.",
"author_id": 3002,
"author_profile": "https://Stackoverflow.com/users/3002",
"pm_score": 4,
"selected": true,
"text": "<p>Setting an attribute on an object won't give a compile-time or a run-time error, it will just do nothing useful if the object d... | 2008/08/27 | [
"https://Stackoverflow.com/questions/29243",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1638/"
] | Here is my sample code:
```
from xml.dom.minidom import *
def make_xml():
doc = Document()
node = doc.createElement('foo')
node.innerText = 'bar'
doc.appendChild(node)
return doc
if __name__ == '__main__':
make_xml().writexml(sys.stdout)
```
when I run the above code I get this:
```
<?xml ve... | Setting an attribute on an object won't give a compile-time or a run-time error, it will just do nothing useful if the object doesn't access it (i.e. "`node.noSuchAttr = 'bar'`" would also not give an error).
Unless you need a specific feature of `minidom`, I would look at `ElementTree`:
```
import sys
from xml.etree... |
29,244 | <p>I have the following HTML (note the CSS making the background black and text white)</p>
<pre><code><html>
<select id="opts" style="background-color: black; color: white;">
<option>first</option>
<option>second</option>
</select>
</html>
</code></pre>
<p>... | [
{
"answer_id": 29245,
"author": "Re0sless",
"author_id": 2098,
"author_profile": "https://Stackoverflow.com/users/2098",
"pm_score": 2,
"selected": false,
"text": "<p>Does the button need to be black? you could apply the black background to the options instead.</p>\n"
},
{
"answe... | 2008/08/27 | [
"https://Stackoverflow.com/questions/29244",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/234/"
] | I have the following HTML (note the CSS making the background black and text white)
```
<html>
<select id="opts" style="background-color: black; color: white;">
<option>first</option>
<option>second</option>
</select>
</html>
```
Safari is smart enough to make the small triangle that appears to the righ... | Must be a `Vista` problem. I have `XP SP 2` and it looks normal. |
29,284 | <p>I was testing on a customer's box this afternoon which has Windows Vista (He had home, but I am testing on a Business Edition with same results).</p>
<p>We make use of a .DLL that gets the Hardware ID of the computer. It's usage is very simple and the sample program I have created works. The Dll is <a href="http://... | [
{
"answer_id": 29313,
"author": "Dale Ragan",
"author_id": 1117,
"author_profile": "https://Stackoverflow.com/users/1117",
"pm_score": 1,
"selected": false,
"text": "<p>Is the machine you have the code deployed on a 64-bit machine? You could also be running into a <a href=\"http://en.wi... | 2008/08/27 | [
"https://Stackoverflow.com/questions/29284",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2684/"
] | I was testing on a customer's box this afternoon which has Windows Vista (He had home, but I am testing on a Business Edition with same results).
We make use of a .DLL that gets the Hardware ID of the computer. It's usage is very simple and the sample program I have created works. The Dll is [This from AzSdk](http://w... | @[Martín](https://stackoverflow.com/questions/29284/windows-vista-unable-to-load-dll-xdll-invalid-access-to-memory-location-dllnotf#29400)
The reason you were not getting the UAC prompt is because UAC can only change how a process is **started**, once the process is running it must stay at the same elevation level. Th... |
29,308 | <p>In the <a href="http://herdingcode.com/" rel="nofollow noreferrer">herding code</a> podcast 14 someone mentions that stackoverflow displayed the queries that were executed during a request at the bottom of the page. </p>
<p>It sounds like an excellent idea to me. Every time a page loads I want to know what sql stat... | [
{
"answer_id": 29319,
"author": "Jedi Master Spooky",
"author_id": 1154,
"author_profile": "https://Stackoverflow.com/users/1154",
"pm_score": 2,
"selected": false,
"text": "<p>If you put .ToString() to a var query variable you get the sql. You can laso use this in Debug en VS2008. <a h... | 2008/08/27 | [
"https://Stackoverflow.com/questions/29308",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2785/"
] | In the [herding code](http://herdingcode.com/) podcast 14 someone mentions that stackoverflow displayed the queries that were executed during a request at the bottom of the page.
It sounds like an excellent idea to me. Every time a page loads I want to know what sql statements are executed and also a count of the tot... | If you put .ToString() to a var query variable you get the sql. You can laso use this in Debug en VS2008. [Debug Visualizer](http://weblogs.asp.net/scottgu/archive/2007/07/31/linq-to-sql-debug-visualizer.aspx)
ex:
```
var query = from p in db.Table
select p;
MessageBox.SHow(query.ToString());
``` |
29,324 | <p>What is the most straightforward way to create a hash table (or associative array...) in Java? My google-fu has turned up a couple examples, but is there a standard way to do this?</p>
<p>And is there a way to populate the table with a list of key->value pairs without individually calling an add method on the obje... | [
{
"answer_id": 29334,
"author": "John",
"author_id": 2168,
"author_profile": "https://Stackoverflow.com/users/2168",
"pm_score": 2,
"selected": false,
"text": "<pre><code>import java.util.HashMap;\n\nMap map = new HashMap();\n</code></pre>\n"
},
{
"answer_id": 29336,
"author"... | 2008/08/27 | [
"https://Stackoverflow.com/questions/29324",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/145/"
] | What is the most straightforward way to create a hash table (or associative array...) in Java? My google-fu has turned up a couple examples, but is there a standard way to do this?
And is there a way to populate the table with a list of key->value pairs without individually calling an add method on the object for each... | ```
Map map = new HashMap();
Hashtable ht = new Hashtable();
```
Both classes can be found from the java.util package. The difference between the 2 is explained in the following [jGuru FAQ entry](http://www.jguru.com/faq/view.jsp?EID=430247). |
29,335 | <p>My current employer uses a 3rd party hosted CRM provider and we have a fairly sophisticated integration tier between the two systems. Amongst the capabilities of the CRM provider is for developers to author business logic in a Java like language and on events such as the user clicking a button or submitting a new... | [
{
"answer_id": 29334,
"author": "John",
"author_id": 2168,
"author_profile": "https://Stackoverflow.com/users/2168",
"pm_score": 2,
"selected": false,
"text": "<pre><code>import java.util.HashMap;\n\nMap map = new HashMap();\n</code></pre>\n"
},
{
"answer_id": 29336,
"author"... | 2008/08/27 | [
"https://Stackoverflow.com/questions/29335",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2228/"
] | My current employer uses a 3rd party hosted CRM provider and we have a fairly sophisticated integration tier between the two systems. Amongst the capabilities of the CRM provider is for developers to author business logic in a Java like language and on events such as the user clicking a button or submitting a new accou... | ```
Map map = new HashMap();
Hashtable ht = new Hashtable();
```
Both classes can be found from the java.util package. The difference between the 2 is explained in the following [jGuru FAQ entry](http://www.jguru.com/faq/view.jsp?EID=430247). |
29,382 | <p>I'm deploying to Ubuntu slice on slicehost, using Rails 2.1.0 (from <code>gem</code>)</p>
<p>If I try <code>mongrel_rails</code> start or script/server I get this error:</p>
<pre><code> Rails requires RubyGems >= 0.9.4. Please install RubyGems
</code></pre>
<p>When I type <code>gem -v</code> I have version <co... | [
{
"answer_id": 29401,
"author": "Chris Bunch",
"author_id": 422,
"author_profile": "https://Stackoverflow.com/users/422",
"pm_score": 1,
"selected": false,
"text": "<p>Have you tried reinstalling RubyGems? I had a pretty similar error message until I reuninstalled and for some reason, it... | 2008/08/27 | [
"https://Stackoverflow.com/questions/29382",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2477/"
] | I'm deploying to Ubuntu slice on slicehost, using Rails 2.1.0 (from `gem`)
If I try `mongrel_rails` start or script/server I get this error:
```
Rails requires RubyGems >= 0.9.4. Please install RubyGems
```
When I type `gem -v` I have version `1.2.0` installed. Any quick tips on what to look at to fix? | Just finally found [this answer](http://www.shorepound.net/wpblog/?p=65)... I was missing a gem, and thrown off by bad error message from Rails... |
29,383 | <p>Maybe this is a dumb question, but is there any way to convert a boolean value to a string such that 1 turns to "true" and 0 turns to "false"? I could just use an if statement, but it would be nice to know if there is a way to do that with the language or standard libraries. Plus, I'm a pedant. :)</p>
| [
{
"answer_id": 29394,
"author": "Joseph Pecoraro",
"author_id": 792,
"author_profile": "https://Stackoverflow.com/users/792",
"pm_score": -1,
"selected": false,
"text": "<p>I agree that a macro might be the best fit. I just whipped up a test case (believe me I'm no good with C/C++ but t... | 2008/08/27 | [
"https://Stackoverflow.com/questions/29383",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2147/"
] | Maybe this is a dumb question, but is there any way to convert a boolean value to a string such that 1 turns to "true" and 0 turns to "false"? I could just use an if statement, but it would be nice to know if there is a way to do that with the language or standard libraries. Plus, I'm a pedant. :) | How about using the C++ language itself?
```
bool t = true;
bool f = false;
std::cout << std::noboolalpha << t << " == " << std::boolalpha << t << std::endl;
std::cout << std::noboolalpha << f << " == " << std::boolalpha << f << std::endl;
```
UPDATE:
If you want more than 4 lines of code without any conso... |
29,436 | <p>I'm using the .NET CF 3.5. The type I want to create does not have a default constructor so I want to pass a string to an overloaded constructor. How do I do this?</p>
<p>Code:</p>
<pre><code>Assembly a = Assembly.LoadFrom("my.dll");
Type t = a.GetType("type info here");
// All ok so far, assembly loads and I can ... | [
{
"answer_id": 29444,
"author": "Matt Hamilton",
"author_id": 615,
"author_profile": "https://Stackoverflow.com/users/615",
"pm_score": 0,
"selected": false,
"text": "<p>See if this works for you (untested):</p>\n\n<pre><code>Type t = a.GetType(\"type info here\");\nvar ctors = t.GetCons... | 2008/08/27 | [
"https://Stackoverflow.com/questions/29436",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/636/"
] | I'm using the .NET CF 3.5. The type I want to create does not have a default constructor so I want to pass a string to an overloaded constructor. How do I do this?
Code:
```
Assembly a = Assembly.LoadFrom("my.dll");
Type t = a.GetType("type info here");
// All ok so far, assembly loads and I can get my type
string s... | ```
MyObj o = null;
Assembly a = Assembly.LoadFrom("my.dll");
Type t = a.GetType("type info here");
ConstructorInfo ctor = t.GetConstructor(new Type[] { typeof(string) });
if(ctor != null)
o = ctor.Invoke(new object[] { s });
``` |
29,437 | <p>I want to shift the contents of an array of bytes by 12-bit to the left.</p>
<p>For example, starting with this array of type <code>uint8_t shift[10]</code>:</p>
<pre><code>{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0A, 0xBC}
</code></pre>
<p>I'd like to shift it to the left by 12-bits resulting in:</p>
... | [
{
"answer_id": 29463,
"author": "Joseph Pecoraro",
"author_id": 792,
"author_profile": "https://Stackoverflow.com/users/792",
"pm_score": 2,
"selected": false,
"text": "<p>Lets make it the best way to shift <code>N</code> bits in the array of 8 bit integers.</p>\n\n<pre><code>N ... | 2008/08/27 | [
"https://Stackoverflow.com/questions/29437",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/609/"
] | I want to shift the contents of an array of bytes by 12-bit to the left.
For example, starting with this array of type `uint8_t shift[10]`:
```
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0A, 0xBC}
```
I'd like to shift it to the left by 12-bits resulting in:
```
{0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0... | Hurray for pointers!
This code works by looking ahead 12 bits for each byte and copying the proper bits forward. 12 bits is the bottom half (nybble) of the next byte and the top half of 2 bytes away.
```
unsigned char length = 10;
unsigned char data[10] = {0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0A,0xBC};
unsigned char *s... |
29,482 | <p>How do I cast an <code>int</code> to an <code>enum</code> in C#?</p>
| [
{
"answer_id": 29485,
"author": "FlySwat",
"author_id": 1965,
"author_profile": "https://Stackoverflow.com/users/1965",
"pm_score": 13,
"selected": true,
"text": "<p>From an int:</p>\n<pre><code>YourEnum foo = (YourEnum)yourInt;\n</code></pre>\n<p>From a string:</p>\n<pre><code>YourEnum ... | 2008/08/27 | [
"https://Stackoverflow.com/questions/29482",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/493/"
] | How do I cast an `int` to an `enum` in C#? | From an int:
```
YourEnum foo = (YourEnum)yourInt;
```
From a string:
```
YourEnum foo = (YourEnum) Enum.Parse(typeof(YourEnum), yourString);
// The foo.ToString().Contains(",") check is necessary for
// enumerations marked with a [Flags] attribute.
if (!Enum.IsDefined(typeof(YourEnum), foo) && !foo.ToString().Co... |
29,496 | <p>I'd like to write a script/batch that will bunch up my daily IIS logs and zip them up by month.</p>
<p>ex080801.log which is in the format of ex<em>yymmdd</em>.log</p>
<p>ex080801.log - ex080831.log gets zipped up and the log files deleted.</p>
<p>The reason we do this is because on a heavy site a log file for on... | [
{
"answer_id": 29507,
"author": "paan",
"author_id": 2976,
"author_profile": "https://Stackoverflow.com/users/2976",
"pm_score": 0,
"selected": false,
"text": "<p>Regex will do the trick... create a perl/python/php script to do the job for you..<br>\nI'm pretty sure windows batch file ca... | 2008/08/27 | [
"https://Stackoverflow.com/questions/29496",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/648/"
] | I'd like to write a script/batch that will bunch up my daily IIS logs and zip them up by month.
ex080801.log which is in the format of ex*yymmdd*.log
ex080801.log - ex080831.log gets zipped up and the log files deleted.
The reason we do this is because on a heavy site a log file for one day could be 500mb to 1gb so ... | You'll need a command line tool to zip up the files. I recommend [7-Zip](http://www.7-zip.org/download.html) which is free and easy to use. The self-contained command line version (7za.exe) is the most portable choice.
Here's a two-line batch file that would zip the log files and delete them afterwards:
```
7za.exe a... |
29,511 | <p>In Ruby, trying to print out the individual elements of a String is giving me trouble. Instead of seeing each character, I'm seeing their ASCII values instead: </p>
<pre><code>>> a = "0123"
=> "0123"
>> a[0]
=> 48
</code></pre>
<p>I've looked online but can't find any way to get the original "0" ... | [
{
"answer_id": 29512,
"author": "SCdF",
"author_id": 1666,
"author_profile": "https://Stackoverflow.com/users/1666",
"pm_score": 3,
"selected": false,
"text": "<p>You want <code>a[0,1]</code> instead of <code>a[0]</code>.</p>\n"
},
{
"answer_id": 29517,
"author": "Stuart",
... | 2008/08/27 | [
"https://Stackoverflow.com/questions/29511",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/422/"
] | In Ruby, trying to print out the individual elements of a String is giving me trouble. Instead of seeing each character, I'm seeing their ASCII values instead:
```
>> a = "0123"
=> "0123"
>> a[0]
=> 48
```
I've looked online but can't find any way to get the original "0" back out of it. I'm a little new to Ruby to ... | Or you can convert the integer to its character value:
```
a[0].chr
``` |
29,531 | <p>I want to use CodeDOM to both declare and initialize my static field in one statement. How can I do this?</p>
<pre><code>// for example
public static int MyField = 5;
</code></pre>
<p>I can seem to figure out how to declare a static field, and I can set its value later, but I can't seem to get the above effect.</... | [
{
"answer_id": 29534,
"author": "Timothy Fries",
"author_id": 3163,
"author_profile": "https://Stackoverflow.com/users/3163",
"pm_score": 4,
"selected": true,
"text": "<p>Once you create your CodeMemberField instance to represent the static field, you can assign the InitExpression proper... | 2008/08/27 | [
"https://Stackoverflow.com/questions/29531",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/404/"
] | I want to use CodeDOM to both declare and initialize my static field in one statement. How can I do this?
```
// for example
public static int MyField = 5;
```
I can seem to figure out how to declare a static field, and I can set its value later, but I can't seem to get the above effect.
@lomaxx,
Naw, I just want s... | Once you create your CodeMemberField instance to represent the static field, you can assign the InitExpression property to the expression you want to use to populate the field. |
29,539 | <p>Is there a one line function call that quits the program and displays a message? I know in Perl it's as simple as:</p>
<pre><code>die("Message goes here")
</code></pre>
<p>I'm tired of typing this:</p>
<pre><code>puts "Message goes here"
exit
</code></pre>
| [
{
"answer_id": 29547,
"author": "Mike Stone",
"author_id": 122,
"author_profile": "https://Stackoverflow.com/users/122",
"pm_score": 1,
"selected": false,
"text": "<p>I've never heard of such a function, but it would be trivial enough to implement...</p>\n\n<pre><code>def die(msg)\n put... | 2008/08/27 | [
"https://Stackoverflow.com/questions/29539",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/422/"
] | Is there a one line function call that quits the program and displays a message? I know in Perl it's as simple as:
```
die("Message goes here")
```
I'm tired of typing this:
```
puts "Message goes here"
exit
``` | The `abort` function does this. For example:
```
abort("Message goes here")
```
Note: the `abort` message will be written to `STDERR` as opposed to `puts` which will write to `STDOUT`. |
29,562 | <p>I wrote a quick program in python to add a gtk GUI to a cli program. I was wondering how I can create an installer using distutils. Since it's just a GUI frontend for a command line app it only works in *nix anyway so I'm not worried about it being cross platform.</p>
<p>my main goal is to create a .deb package for... | [
{
"answer_id": 29575,
"author": "Sander",
"author_id": 2928,
"author_profile": "https://Stackoverflow.com/users/2928",
"pm_score": 5,
"selected": true,
"text": "<p>See the <a href=\"http://docs.python.org/dist/simple-example.html\" rel=\"noreferrer\">distutils simple example</a>. That's ... | 2008/08/27 | [
"https://Stackoverflow.com/questions/29562",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2908/"
] | I wrote a quick program in python to add a gtk GUI to a cli program. I was wondering how I can create an installer using distutils. Since it's just a GUI frontend for a command line app it only works in \*nix anyway so I'm not worried about it being cross platform.
my main goal is to create a .deb package for debian/u... | See the [distutils simple example](http://docs.python.org/dist/simple-example.html). That's basically what it is like, except real install scripts usually contain a bit more information. I have not seen any that are fundamentally more complicated, though. In essence, you just give it a list of what needs to be installe... |
29,621 | <p>On Windows I can do:</p>
<pre><code>HANDLE hCurrentProcess = GetCurrentProcess();
SetPriorityClass(hCurrentProcess, ABOVE_NORMAL_PRIORITY_CLASS);
</code></pre>
<p>How can I do the same thing on *nix?</p>
| [
{
"answer_id": 29623,
"author": "Silas Snider",
"author_id": 2933,
"author_profile": "https://Stackoverflow.com/users/2933",
"pm_score": 6,
"selected": true,
"text": "<p>Try:</p>\n\n<pre><code>#include <sys/time.h>\n#include <sys/resource.h>\n\nint main(){\n setpriority(PR... | 2008/08/27 | [
"https://Stackoverflow.com/questions/29621",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/163/"
] | On Windows I can do:
```
HANDLE hCurrentProcess = GetCurrentProcess();
SetPriorityClass(hCurrentProcess, ABOVE_NORMAL_PRIORITY_CLASS);
```
How can I do the same thing on \*nix? | Try:
```
#include <sys/time.h>
#include <sys/resource.h>
int main(){
setpriority(PRIO_PROCESS, 0, -20);
}
```
Note that you must be running as superuser for this to work.
(for more info, type 'man setpriority' at a prompt.) |
29,624 | <p>I have a form element that contains multiple lines of inputs. Think of each line as attributes of a new object that I want to create in my web application. And, I want to be able to create multiple new objects in one HTTP POST. I'm using Javascript's built-in cloneNode(true) method to clone each line. The problem ... | [
{
"answer_id": 29771,
"author": "Fredrik Kalseth",
"author_id": 1710,
"author_profile": "https://Stackoverflow.com/users/1710",
"pm_score": -1,
"selected": false,
"text": "<p>Looks like you're using jQuery? It has a method to clone an element with events: <a href=\"http://docs.jquery.com... | 2008/08/27 | [
"https://Stackoverflow.com/questions/29624",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1376/"
] | I have a form element that contains multiple lines of inputs. Think of each line as attributes of a new object that I want to create in my web application. And, I want to be able to create multiple new objects in one HTTP POST. I'm using Javascript's built-in cloneNode(true) method to clone each line. The problem is th... | Don't put handler on each link (this really should be a button, BTW). Use [event bubbling](http://www.quirksmode.org/js/events_order.html) to handle *all* buttons with one handler:
```
formObject.onclick = function(e)
{
e=e||event; // IE sucks
var target = e.target||e.srcElement; // and sucks again
// tar... |
29,626 | <p>In a VB.NET WinForms project, I get an exception</p>
<blockquote>
<p>Cannot access a disposed of object</p>
</blockquote>
<p>when closing a form. It occurs very rarely and I cannot recreate it on demand. The stack trace looks like this:</p>
<pre><code>Cannot access a disposed object. Object name: 'dbiSchedule'.... | [
{
"answer_id": 29634,
"author": "jfs",
"author_id": 718,
"author_profile": "https://Stackoverflow.com/users/718",
"pm_score": 5,
"selected": false,
"text": "<p>Try checking the <a href=\"http://msdn.microsoft.com/en-us/library/system.windows.forms.control.isdisposed.aspx\" rel=\"noreferr... | 2008/08/27 | [
"https://Stackoverflow.com/questions/29626",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/961/"
] | In a VB.NET WinForms project, I get an exception
>
> Cannot access a disposed of object
>
>
>
when closing a form. It occurs very rarely and I cannot recreate it on demand. The stack trace looks like this:
```
Cannot access a disposed object. Object name: 'dbiSchedule'.
at System.Windows.Forms.Control.CreateHa... | Try checking the [IsDisposed](http://msdn.microsoft.com/en-us/library/system.windows.forms.control.isdisposed.aspx) property before accessing the control. You can also check it on the [FormClosing](http://msdn.microsoft.com/en-us/library/system.windows.forms.form.formclosing.aspx) event, assuming you're using the FormC... |
29,645 | <p>I have a few lines of PowerShell code that I would like to use as an automated script. The way I would like it to be able to work is to be able to call it using one of the following options:</p>
<ol>
<li>One command line that opens PowerShell, executes script and closes PowerShell (this would be used for a global b... | [
{
"answer_id": 29649,
"author": "Matt Hamilton",
"author_id": 615,
"author_profile": "https://Stackoverflow.com/users/615",
"pm_score": 4,
"selected": true,
"text": "<p>Save your script as a .ps1 file and launch it using powershell.exe, like this:</p>\n\n<pre><code>powershell.exe .\\foo.... | 2008/08/27 | [
"https://Stackoverflow.com/questions/29645",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/51/"
] | I have a few lines of PowerShell code that I would like to use as an automated script. The way I would like it to be able to work is to be able to call it using one of the following options:
1. One command line that opens PowerShell, executes script and closes PowerShell (this would be used for a global build-routine)... | Save your script as a .ps1 file and launch it using powershell.exe, like this:
```
powershell.exe .\foo.ps1
```
Make sure you specify the full path to the script, and make sure you have set your execution policy level to at least "RemoteSigned" so that unsigned local scripts can be run. |
29,664 | <p>I need to specifically catch SQL server timeout exceptions so that they can be handled differently. I know I could catch the SqlException and then check if the message string Contains "Timeout" but was wondering if there is a better way to do it?</p>
<pre><code>try
{
//some code
}
catch (SqlException ex)
{
... | [
{
"answer_id": 29666,
"author": "Rob Cooper",
"author_id": 832,
"author_profile": "https://Stackoverflow.com/users/832",
"pm_score": 0,
"selected": false,
"text": "<p>Whats the value for the SqlException.ErrorCode property? Can you work with that?</p>\n\n<p>When having timeouts, it may b... | 2008/08/27 | [
"https://Stackoverflow.com/questions/29664",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2231/"
] | I need to specifically catch SQL server timeout exceptions so that they can be handled differently. I know I could catch the SqlException and then check if the message string Contains "Timeout" but was wondering if there is a better way to do it?
```
try
{
//some code
}
catch (SqlException ex)
{
if (ex.Messag... | To check for a timeout, I believe you check the value of ex.Number. If it is -2, then you have a timeout situation.
-2 is the error code for timeout, returned from DBNETLIB, the MDAC driver for SQL Server. This can be seen by downloading [Reflector](http://www.red-gate.com/products/reflector/), and looking under Syste... |
29,680 | <p>In a recent sharepoint project, I implemented an authentication webpart which should replace the NTLM authentication dialog box. It works fine as long as the user provides valid credentials. Whenever the user provides invalid credentials, the NTLM dialog box pops up in Internet Explorer.</p>
<p>My Javascript code w... | [
{
"answer_id": 29908,
"author": "Mark Brackett",
"author_id": 2199,
"author_profile": "https://Stackoverflow.com/users/2199",
"pm_score": 2,
"selected": false,
"text": "<p>IIRC, the browser pops the auth dialog when the following comes back in the request stream:</p>\n\n<ul>\n<li>Http st... | 2008/08/27 | [
"https://Stackoverflow.com/questions/29680",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/830/"
] | In a recent sharepoint project, I implemented an authentication webpart which should replace the NTLM authentication dialog box. It works fine as long as the user provides valid credentials. Whenever the user provides invalid credentials, the NTLM dialog box pops up in Internet Explorer.
My Javascript code which does ... | [Mark](https://stackoverflow.com/users/2199/mark-brackett)'s comment is correct; The NTLM auth prompt is triggered by a 401 response code and the presence of NTLM as the first mechanism offered in the WWW-Authenticate header (Ref: [The NTLM Authentication Protocol](http://curl.haxx.se/rfc/ntlm.html)).
I'm not sure if ... |
29,686 | <p>I'll have an ASP.net page that creates some Excel Sheets and sends them to the user. The problem is, sometimes I get Http timeouts, presumably because the Request runs longer than executionTimeout (110 seconds per default).</p>
<p>I just wonder what my options are to prevent this, without wanting to generally incre... | [
{
"answer_id": 29688,
"author": "Rob Cooper",
"author_id": 832,
"author_profile": "https://Stackoverflow.com/users/832",
"pm_score": 1,
"selected": false,
"text": "<p>I've not really had to face this issue too much yet myself, so please keep that in mind.</p>\n\n<p>Is there not anyway yo... | 2008/08/27 | [
"https://Stackoverflow.com/questions/29686",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/91/"
] | I'll have an ASP.net page that creates some Excel Sheets and sends them to the user. The problem is, sometimes I get Http timeouts, presumably because the Request runs longer than executionTimeout (110 seconds per default).
I just wonder what my options are to prevent this, without wanting to generally increase the ex... | If you want to increase the execution timeout for this one request you can set
```
HttpContext.Current.Server.ScriptTimeout
```
But you still may have the problem of the client timing out which you can't reliably solve directly from the server. To get around that you could implement a "processing" page (like Rob sugg... |
29,696 | <p>How do you stop the designer from auto generating code that sets the value for public properties on a user control?</p>
| [
{
"answer_id": 29717,
"author": "Will Dean",
"author_id": 987,
"author_profile": "https://Stackoverflow.com/users/987",
"pm_score": 3,
"selected": false,
"text": "<p>Add the following attributes to the property in your control:</p>\n\n<pre><code>[Browsable(false), DesignerSerializationVi... | 2008/08/27 | [
"https://Stackoverflow.com/questions/29696",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2253/"
] | How do you stop the designer from auto generating code that sets the value for public properties on a user control? | Use the DesignerSerializationVisibilityAttribute on the properties that you want to hide from the designer serialization and set the parameter to Hidden.
```
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
public string Name
{
get;
set;
}
``` |
29,699 | <p>I have a database with names in it such as John Doe etc. Unfortunately some of these names contain quotes like Keiran O'Keefe. Now when I try and search for such names as follows:</p>
<pre><code>SELECT * FROM PEOPLE WHERE SURNAME='O'Keefe'
</code></pre>
<p>I (understandably) get an error.</p>
<p>How do I preven... | [
{
"answer_id": 29703,
"author": "Rob Cooper",
"author_id": 832,
"author_profile": "https://Stackoverflow.com/users/832",
"pm_score": -1,
"selected": false,
"text": "<p>Found in under 30s on Google...</p>\n\n<p><a href=\"http://www.orafaq.com/wiki/SQL_FAQ#How_does_one_escape_special_chara... | 2008/08/27 | [
"https://Stackoverflow.com/questions/29699",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/445/"
] | I have a database with names in it such as John Doe etc. Unfortunately some of these names contain quotes like Keiran O'Keefe. Now when I try and search for such names as follows:
```
SELECT * FROM PEOPLE WHERE SURNAME='O'Keefe'
```
I (understandably) get an error.
How do I prevent this error from occurring. I am ... | The escape character is ', so you would need to replace the quote with two quotes.
For example,
`SELECT * FROM PEOPLE WHERE SURNAME='O'Keefe'`
becomes
`SELECT * FROM PEOPLE WHERE SURNAME='O''Keefe'`
That said, it's probably incorrect to do this yourself. Your language may have a function to escape strings for use ... |
29,731 | <p>I have done a bit of research into this and it seems that the only way to sort a data bound combo box is to sort the data source itself (a DataTable in a DataSet in this case). </p>
<p>If that is the case then the question becomes what is the best way to sort a DataTable?</p>
<p>The combo box bindings are set in ... | [
{
"answer_id": 29735,
"author": "Andy Rose",
"author_id": 1762,
"author_profile": "https://Stackoverflow.com/users/1762",
"pm_score": 0,
"selected": false,
"text": "<p>Does the data need to be in a DataTable?\nUsing a SortedList and binding that to a combo box would be a simpler way.</p>... | 2008/08/27 | [
"https://Stackoverflow.com/questions/29731",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2253/"
] | I have done a bit of research into this and it seems that the only way to sort a data bound combo box is to sort the data source itself (a DataTable in a DataSet in this case).
If that is the case then the question becomes what is the best way to sort a DataTable?
The combo box bindings are set in the designer initi... | If you're using a DataTable, you can use the (DataTable.DefaultView) [DataView.Sort](http://msdn.microsoft.com/en-us/library/system.data.dataview.sort.aspx) property. For greater flexibility you can use the [BindingSource](http://msdn.microsoft.com/en-us/library/system.windows.forms.bindingsource.aspx) component. Bindi... |
29,746 | <p>I'm looking for something that will show me the size of each folder within my main folder recursively.</p>
<p>This is a <a href="http://en.wikipedia.org/wiki/LAMP_%28software_bundle%29" rel="nofollow noreferrer">LAMP</a> server with a CGI-Bin so most any PHP script should work or anything that will work in the CGI-... | [
{
"answer_id": 29755,
"author": "lubos hasko",
"author_id": 275,
"author_profile": "https://Stackoverflow.com/users/275",
"pm_score": 4,
"selected": true,
"text": "<p>Strange, I came up on Google with <a href=\"http://www.google.com.au/search?hl=en&q=php+directory+size&btnG=Googl... | 2008/08/27 | [
"https://Stackoverflow.com/questions/29746",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/115/"
] | I'm looking for something that will show me the size of each folder within my main folder recursively.
This is a [LAMP](http://en.wikipedia.org/wiki/LAMP_%28software_bundle%29) server with a CGI-Bin so most any PHP script should work or anything that will work in the CGI-Bin.
My hosting company does not provide an in... | Strange, I came up on Google with [many relevant results](http://www.google.com.au/search?hl=en&q=php+directory+size&btnG=Google+Search&meta=) and [this one](http://www.go4expert.com/forums/showthread.php?t=290) is probably the most complete.
>
> The function "getDirectorySize" will
> ignore link/shorcuts to
> file... |
29,751 | <p>I am having problems submitting forms which contain UTF-8 strings with Ajax. I am developing a <a href="http://en.wikipedia.org/wiki/Apache_Struts" rel="noreferrer">Struts</a> web application which runs in a <a href="http://en.wikipedia.org/wiki/Apache_Tomcat" rel="noreferrer">Tomcat</a> server. This is the environm... | [
{
"answer_id": 29756,
"author": "Pat",
"author_id": 238,
"author_profile": "https://Stackoverflow.com/users/238",
"pm_score": 4,
"selected": false,
"text": "<p>have you tried adding the following before the call :</p>\n\n<pre><code>$.ajaxSetup({ \n scriptCharset: \"utf-8\" , \n con... | 2008/08/27 | [
"https://Stackoverflow.com/questions/29751",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2138/"
] | I am having problems submitting forms which contain UTF-8 strings with Ajax. I am developing a [Struts](http://en.wikipedia.org/wiki/Apache_Struts) web application which runs in a [Tomcat](http://en.wikipedia.org/wiki/Apache_Tomcat) server. This is the environment I set up to work with UTF-8:
* I have added the attrib... | have you tried adding the following before the call :
```
$.ajaxSetup({
scriptCharset: "utf-8" ,
contentType: "application/json; charset=utf-8"
});
```
The options are explained [here](http://docs.jquery.com/Ajax/jQuery.ajax#toptions).
contentType : When sending data to the server, use this content-type. ... |
29,822 | <p>One of our weblogic 8.1s has suddenly started logging giant amounts of logs and filling the disk.</p>
<p>The logs giving us hassle resides in </p>
<pre><code>mydrive:\bea\weblogic81\common\nodemanager\NodeManagerLogs\generatedManagedServer1\managedserveroutput.log
</code></pre>
<p>and the entries in the logfile i... | [
{
"answer_id": 29825,
"author": "urini",
"author_id": 373,
"author_profile": "https://Stackoverflow.com/users/373",
"pm_score": 2,
"selected": false,
"text": "<p>One option is to use serialization. Here's a blog post explaining it:</p>\n\n<p><a href=\"http://weblogs.java.net/blog/emcmanu... | 2008/08/27 | [
"https://Stackoverflow.com/questions/29822",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/86/"
] | One of our weblogic 8.1s has suddenly started logging giant amounts of logs and filling the disk.
The logs giving us hassle resides in
```
mydrive:\bea\weblogic81\common\nodemanager\NodeManagerLogs\generatedManagedServer1\managedserveroutput.log
```
and the entries in the logfile is just the some kind of entries r... | Turn that into a spec:
-that objects need to implement an interface in order to be allowed into the collection
Something like `ArrayList<ICloneable>()`
Then you can be assured that you always do a deep copy - the interface should have a method that is guaranteed to return a deep copy.
I think that's the best you ... |
29,841 | <p>We have a Windows Service written in C#. The service spawns a thread that does this: </p>
<pre><code>private void ThreadWorkerFunction()
{
while(false == _stop) // stop flag set by other thread
{
try
{
openConnection();
doStuff();
closeConnection();
}
catch (Exception ex)
... | [
{
"answer_id": 29843,
"author": "James B",
"author_id": 2951,
"author_profile": "https://Stackoverflow.com/users/2951",
"pm_score": 0,
"selected": false,
"text": "<p>Have you tried using <a href=\"http://msdn.microsoft.com/en-us/library/system.threading.monitor.pulse.aspx\" rel=\"nofollo... | 2008/08/27 | [
"https://Stackoverflow.com/questions/29841",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1039/"
] | We have a Windows Service written in C#. The service spawns a thread that does this:
```
private void ThreadWorkerFunction()
{
while(false == _stop) // stop flag set by other thread
{
try
{
openConnection();
doStuff();
closeConnection();
}
catch (Exception ex)
{
log.E... | Dig in and find out? Stick a debugger on that bastard!
I can see at least the following possibilities:
1. the logging system hangs;
2. the thread exited just fine but the service is still running because some other part has a logic error.
And maybe, but almost certainly not, the following:
* Sleep() hangs.
But in ... |
29,845 | <p>I have an application on which I am implementing localization.</p>
<p>I now need to dynamically reference a name in the resouce file.</p>
<p>assume I have a resource file called Login.resx, an a number of strings: foo="hello", bar="cruel" and baz="world"</p>
<p>normally, I will refer as:
String result =Login.foo... | [
{
"answer_id": 29866,
"author": "Konrad Rudolph",
"author_id": 1968,
"author_profile": "https://Stackoverflow.com/users/1968",
"pm_score": 5,
"selected": true,
"text": "<p>You'll need to instance a <a href=\"http://msdn.microsoft.com/en-us/library/aa984408%28VS.71%29.aspx\" rel=\"norefer... | 2008/08/27 | [
"https://Stackoverflow.com/questions/29845",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1090/"
] | I have an application on which I am implementing localization.
I now need to dynamically reference a name in the resouce file.
assume I have a resource file called Login.resx, an a number of strings: foo="hello", bar="cruel" and baz="world"
normally, I will refer as:
String result =Login.foo;
and result=="hello";
... | You'll need to instance a [`ResourceManager`](http://msdn.microsoft.com/en-us/library/aa984408%28VS.71%29.aspx) for the `Login.resx`:
```
var resman = new System.Resources.ResourceManager(
"RootNamespace.Login",
System.Reflection.Assembly.GetExecutingAssembly()
)
var text = resman.GetString("resname");
```
I... |
29,847 | <p>I have a History Table in SQL Server that basically tracks an item through a process. The item has some fixed fields that don't change throughout the process, but has a few other fields including status and Id which increment as the steps of the process increase.</p>
<p>Basically I want to retrieve the last step fo... | [
{
"answer_id": 29848,
"author": "ZombieSheep",
"author_id": 377,
"author_profile": "https://Stackoverflow.com/users/377",
"pm_score": 3,
"selected": false,
"text": "<p>Assuming you have an identity column in the table...</p>\n\n<pre><code>select \n top 1 <fields> \nfrom \n Hi... | 2008/08/27 | [
"https://Stackoverflow.com/questions/29847",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1075/"
] | I have a History Table in SQL Server that basically tracks an item through a process. The item has some fixed fields that don't change throughout the process, but has a few other fields including status and Id which increment as the steps of the process increase.
Basically I want to retrieve the last step for each ite... | It's kind of hard to make sense of your table design - I think SO ate your delimiters.
The basic way of handling this is to GROUP BY your fixed fields, and select a MAX (or MIN) for some unqiue value (a datetime usually works well). In your case, I *think* that the GROUP BY would be BatchRef and ItemCount, and Id will... |
29,869 | <p>I need to match and remove all tags using a regular expression in Perl. I have the following:</p>
<pre><code><\\??(?!p).+?>
</code></pre>
<p>But this still matches with the closing <code></p></code> tag. Any hint on how to match with the closing tag as well?</p>
<p>Note, this is being performed on x... | [
{
"answer_id": 29871,
"author": "Brian Warshaw",
"author_id": 1344,
"author_profile": "https://Stackoverflow.com/users/1344",
"pm_score": 1,
"selected": false,
"text": "<p>Assuming that this will work in PERL as it does in languages that claim to use PERL-compatible syntax:</p>\n\n<p><co... | 2008/08/27 | [
"https://Stackoverflow.com/questions/29869",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/274/"
] | I need to match and remove all tags using a regular expression in Perl. I have the following:
```
<\\??(?!p).+?>
```
But this still matches with the closing `</p>` tag. Any hint on how to match with the closing tag as well?
Note, this is being performed on xhtml. | I came up with this:
```
<(?!\/?p(?=>|\s.*>))\/?.*?>
x/
< # Match open angle bracket
(?! # Negative lookahead (Not matching and not consuming)
\/? # 0 or 1 /
p # p
(?= # Positive lookahead (Matching and not consuming)
> # > - No attributes
| # or... |
29,883 | <p>What I am trying to do is change the background colour of a table cell <td> and then when a user goes to print the page, the changes are now showing.</p>
<p>I am currently using an unobtrusive script to run the following command on a range of cells:</p>
<pre><code>element.style.backgroundColor = "#f00"
</cod... | [
{
"answer_id": 29888,
"author": "Espo",
"author_id": 2257,
"author_profile": "https://Stackoverflow.com/users/2257",
"pm_score": 1,
"selected": true,
"text": "<p>Have you tried hard-coding the values just to see if background-colors are showing on the print-preview at all? I think it is ... | 2008/08/27 | [
"https://Stackoverflow.com/questions/29883",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/383/"
] | What I am trying to do is change the background colour of a table cell <td> and then when a user goes to print the page, the changes are now showing.
I am currently using an unobtrusive script to run the following command on a range of cells:
```
element.style.backgroundColor = "#f00"
```
This works on screen in IE... | Have you tried hard-coding the values just to see if background-colors are showing on the print-preview at all? I think it is a setting in the Browser. |
29,890 | <ol>
<li>You have multiple network adapters.</li>
<li>Bind a UDP socket to an local port, without specifying an address.</li>
<li>Receive packets on one of the adapters.</li>
</ol>
<p>How do you get the local ip address of the adapter which received the packet?</p>
<p>The question is, "What is the ip address from the... | [
{
"answer_id": 29912,
"author": "diciu",
"author_id": 2811,
"author_profile": "https://Stackoverflow.com/users/2811",
"pm_score": -1,
"selected": false,
"text": "<pre>\nssize_t\n recvfrom(int socket, void *restrict buffer, size_t length, int flags,\n struct sockaddr *restrict... | 2008/08/27 | [
"https://Stackoverflow.com/questions/29890",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3186/"
] | 1. You have multiple network adapters.
2. Bind a UDP socket to an local port, without specifying an address.
3. Receive packets on one of the adapters.
How do you get the local ip address of the adapter which received the packet?
The question is, "What is the ip address from the receiver adapter?" not the address fro... | You could enumerate all the network adapters, get their IP addresses and compare the part covered by the subnet mask with the sender's address.
Like:
```
IPAddress FindLocalIPAddressOfIncomingPacket( senderAddr )
{
foreach( adapter in EnumAllNetworkAdapters() )
{
adapterSubnet = adapter.subnetmask & a... |
29,943 | <p>Can someone please tell me how to submit an HTML form when the return key is pressed and if there are no buttons in the form?
<strong>The submit button is not there</strong>. I am using a custom div instead of that.</p>
| [
{
"answer_id": 29945,
"author": "Ross",
"author_id": 2025,
"author_profile": "https://Stackoverflow.com/users/2025",
"pm_score": 0,
"selected": false,
"text": "<p>Why don't you just apply the div submit styles to a submit button? I'm sure there's a javascript for this but that would be ... | 2008/08/27 | [
"https://Stackoverflow.com/questions/29943",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/184/"
] | Can someone please tell me how to submit an HTML form when the return key is pressed and if there are no buttons in the form?
**The submit button is not there**. I am using a custom div instead of that. | IMO, this is the cleanest answer:
```html
<form action="" method="get">
Name: <input type="text" name="name"/><br/>
Pwd: <input type="password" name="password"/><br/>
<div class="yourCustomDiv"/>
<input type="submit" style="display:none"/>
</form>
```
Better yet, if you are using javascript to submit th... |
29,976 | <p>We have a couple of ASP.Net dataview column templates that are dynamically added to the dataview depending on columns selected by users.</p>
<p>These templated cells need to handle custom databindings:</p>
<pre><code>public class CustomColumnTemplate:
ITemplate
{
public void InstantiateIn( Control contain... | [
{
"answer_id": 30536,
"author": "David Basarab",
"author_id": 2469,
"author_profile": "https://Stackoverflow.com/users/2469",
"pm_score": 3,
"selected": true,
"text": "<p>I have worked extensively with templated control and I have not found a better solution.</p>\n\n<p>Why are you refere... | 2008/08/27 | [
"https://Stackoverflow.com/questions/29976",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/905/"
] | We have a couple of ASP.Net dataview column templates that are dynamically added to the dataview depending on columns selected by users.
These templated cells need to handle custom databindings:
```
public class CustomColumnTemplate:
ITemplate
{
public void InstantiateIn( Control container )
{
//... | I have worked extensively with templated control and I have not found a better solution.
Why are you referencing the contentLable in the event handler?
The sender is the label you can cast it to the label and have the reference to the label. Like below.
```
//add a custom data binding
contentLabel.Da... |
29,980 | <p>So I'm working on some legacy code that's heavy on the manual database operations. I'm trying to maintain some semblance of quality here, so I'm going TDD as much as possible.</p>
<p>The code I'm working on needs to populate, let's say a <code>List<Foo></code> from a DataReader that returns all the fields req... | [
{
"answer_id": 30055,
"author": "kokos",
"author_id": 1065,
"author_profile": "https://Stackoverflow.com/users/1065",
"pm_score": 0,
"selected": false,
"text": "<p>You can put the Foo instances in a list and compare the objects with what you read: </p>\n\n<pre><code>var arrFoos = new Fo... | 2008/08/27 | [
"https://Stackoverflow.com/questions/29980",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/266/"
] | So I'm working on some legacy code that's heavy on the manual database operations. I'm trying to maintain some semblance of quality here, so I'm going TDD as much as possible.
The code I'm working on needs to populate, let's say a `List<Foo>` from a DataReader that returns all the fields required for a functioning Foo... | To make this less tedious, you will need to encapsulate/refactor the mapping between the DataReader and the Object you hold in the list. There is quite of few steps to encapsulate that logic out. If that is the road you want to take, I can post code for you. I am just not sure how practical it would be to post the code... |
30,003 | <p>I have the following html code: </p>
<pre><code><h3 id="headerid"><span onclick="expandCollapse('headerid')">&uArr;</span>Header title</h3>
</code></pre>
<p>I would like to toggle between up arrow and down arrow each time the user clicks the span tag. </p>
<pre><code>function expandCol... | [
{
"answer_id": 30013,
"author": "jason saldo",
"author_id": 1293,
"author_profile": "https://Stackoverflow.com/users/1293",
"pm_score": 1,
"selected": false,
"text": "<p>Check out the <a href=\"http://docs.jquery.com/Effects/toggle\" rel=\"nofollow noreferrer\">.toggle()</a> effect.</p>\... | 2008/08/27 | [
"https://Stackoverflow.com/questions/30003",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2138/"
] | I have the following html code:
```
<h3 id="headerid"><span onclick="expandCollapse('headerid')">⇑</span>Header title</h3>
```
I would like to toggle between up arrow and down arrow each time the user clicks the span tag.
```
function expandCollapse(id) {
var arrow = $("#"+id+" span").html(); // I hav... | When the HTML is parsed, what JQuery sees in the DOM is a `UPWARDS DOUBLE ARROW` ("⇑"), not the entity reference. Thus, in your Javascript code you should test for `"⇑"` or `"\u21d1"`. Also, you need to change what you're switching to:
```
function expandCollapse(id) {
var arrow = $("#"+id+" span").html();
if(... |
30,018 | <p>How can I use XPath to select an XML-node based on its content? </p>
<p>If I e.g. have the following xml and I want to select the <author>-node that contains Ritchie to get the author's full name:</p>
<pre><code><books>
<book isbn='0131103628'>
<title>The C Programming Language&... | [
{
"answer_id": 30019,
"author": "Cros",
"author_id": 1523,
"author_profile": "https://Stackoverflow.com/users/1523",
"pm_score": 2,
"selected": false,
"text": "<p>The XPath for this is: </p>\n\n<pre><code>/books/book/authors/author[contains(., 'Ritchie')]\n</code></pre>\n\n<p>In C# the f... | 2008/08/27 | [
"https://Stackoverflow.com/questions/30018",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1523/"
] | How can I use XPath to select an XML-node based on its content?
If I e.g. have the following xml and I want to select the <author>-node that contains Ritchie to get the author's full name:
```
<books>
<book isbn='0131103628'>
<title>The C Programming Language</title>
<authors>
<author... | ```
/books/book/authors/author[contains(., 'Ritchie')]
```
or
```
//author[contains(., 'Ritchie')]
``` |
30,049 | <p>I got embroiled in a discussion about DOM implementation quirks yesterday, with gave rise to an interesting question regarding Text.splitText and Element.normalise behaviours, and how they should behave.</p>
<p>In <a href="http://www.w3.org/TR/1998/REC-DOM-Level-1-19981001/level-one-core.html" rel="nofollow norefer... | [
{
"answer_id": 34202,
"author": "Sam Brightman",
"author_id": 2492,
"author_profile": "https://Stackoverflow.com/users/2492",
"pm_score": 2,
"selected": false,
"text": "<p>While it would seem like a reasonable assumption, I agree that it is not explicityly made clear in the specification... | 2008/08/27 | [
"https://Stackoverflow.com/questions/30049",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1200/"
] | I got embroiled in a discussion about DOM implementation quirks yesterday, with gave rise to an interesting question regarding Text.splitText and Element.normalise behaviours, and how they should behave.
In [DOM Level 1 Core](http://www.w3.org/TR/1998/REC-DOM-Level-1-19981001/level-one-core.html), Text.splitText is de... | I was on the DOM Working Group in the early days; I'm sure we *meant* for textNode to contain the new joined value, but if we didn't *say* it in the spec, it's possible that *some* implementation *might* create a new node instead of reusing textNode, though that would require more work for the implementors.
When in do... |
30,058 | <p>The <a href="http://developer.apple.com/documentation/AppleApplications/Reference/SafariWebContent/UsingiPhoneApplications/chapter_6_section_4.html" rel="nofollow noreferrer">Apple Developer Documentation</a> (link is dead now) explains that if you place a link in a web page and then click it whilst using Mobile Saf... | [
{
"answer_id": 30079,
"author": "Adam Wright",
"author_id": 1200,
"author_profile": "https://Stackoverflow.com/users/1200",
"pm_score": 7,
"selected": true,
"text": "<p>For iOS 5.1.1 and lower, use the <code>openURL</code> method of <code>UIApplication</code>. It will perform the normal ... | 2008/08/27 | [
"https://Stackoverflow.com/questions/30058",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2183/"
] | The [Apple Developer Documentation](http://developer.apple.com/documentation/AppleApplications/Reference/SafariWebContent/UsingiPhoneApplications/chapter_6_section_4.html) (link is dead now) explains that if you place a link in a web page and then click it whilst using Mobile Safari on the iPhone, the Google Maps appli... | For iOS 5.1.1 and lower, use the `openURL` method of `UIApplication`. It will perform the normal iPhone magical URL reinterpretation. so
```
[someUIApplication openURL:[NSURL URLWithString:@"http://maps.google.com/maps?q=London"]]
```
should invoke the Google maps app.
From iOS 6, you'll be invoking Apple's own Map... |
30,062 | <p>Yesterday I wanted to add a boolean field to an Oracle table. However, there isn't actually a boolean data type in Oracle. Does anyone here know the best way to simulate a boolean? Googling the subject discovered several approaches</p>
<ol>
<li><p>Use an integer and just don't bother assigning anything other tha... | [
{
"answer_id": 30069,
"author": "Ryan Ahearn",
"author_id": 75,
"author_profile": "https://Stackoverflow.com/users/75",
"pm_score": 1,
"selected": false,
"text": "<p>In our databases we use an enum that ensures we pass it either TRUE or FALSE. If you do it either of the first two ways i... | 2008/08/27 | [
"https://Stackoverflow.com/questions/30062",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1694/"
] | Yesterday I wanted to add a boolean field to an Oracle table. However, there isn't actually a boolean data type in Oracle. Does anyone here know the best way to simulate a boolean? Googling the subject discovered several approaches
1. Use an integer and just don't bother assigning anything other than 0 or 1 to it.
2. ... | I found [this](http://www.techrepublic.com/article/oracle-tip-choosing-an-efficient-design-for-boolean-column-values/) link useful.
Here is the paragraph highlighting some of the pros/cons of each approach.
>
> The most commonly seen design is to imitate the many Boolean-like
> flags that Oracle's data dictionary v... |
30,080 | <p>I have two points (a line segment) and a rectangle. I would like to know how to calculate if the line segment intersects the rectangle. </p>
| [
{
"answer_id": 30098,
"author": "kokos",
"author_id": 1065,
"author_profile": "https://Stackoverflow.com/users/1065",
"pm_score": 2,
"selected": false,
"text": "<p>Do <a href=\"http://mathworld.wolfram.com/Line-LineIntersection.html\" rel=\"nofollow noreferrer\">http://mathworld.wolfram.... | 2008/08/27 | [
"https://Stackoverflow.com/questions/30080",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/623/"
] | I have two points (a line segment) and a rectangle. I would like to know how to calculate if the line segment intersects the rectangle. | From my "Geometry" class:
```
public struct Line
{
public static Line Empty;
private PointF p1;
private PointF p2;
public Line(PointF p1, PointF p2)
{
this.p1 = p1;
this.p2 = p2;
}
public PointF P1
{
get { return p1; }
set { p1 = value; }
}
pu... |
30,099 | <p>In my browsings amongst the Internet, I came across <a href="http://www.reddit.com/r/programming/comments/6y6lr/ask_proggit_which_is_more_useful_to_know_c_or_java/" rel="nofollow noreferrer">this post</a>, which includes this</p>
<blockquote>
<p>"(Well written) C++ goes to great
lengths to make stack automatic
... | [
{
"answer_id": 30125,
"author": "Brad Barker",
"author_id": 12081,
"author_profile": "https://Stackoverflow.com/users/12081",
"pm_score": 1,
"selected": false,
"text": "<p>Variables in C++ can either be declared on the stack or the heap. When you declare a variable in C++, it automatical... | 2008/08/27 | [
"https://Stackoverflow.com/questions/30099",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/841/"
] | In my browsings amongst the Internet, I came across [this post](http://www.reddit.com/r/programming/comments/6y6lr/ask_proggit_which_is_more_useful_to_know_c_or_java/), which includes this
>
> "(Well written) C++ goes to great
> lengths to make stack automatic
> objects work "just like" primitives,
> as reflected ... | Stack objects are handled automatically by the compiler.
When the scope is left, it is deleted.
```
{
obj a;
} // a is destroyed here
```
When you do the same with a 'newed' object you get a memory leak :
```
{
obj* b = new obj;
}
```
b is not destroyed, so we lost the ability to reclaim the memory b owns... |
30,170 | <p>Are there any useful techniques for reducing the repetition of constants in a CSS file?</p>
<p>(For example, a bunch of different selectors which should all apply the same colour, or the same font size)?</p>
| [
{
"answer_id": 30177,
"author": "samjudson",
"author_id": 1908,
"author_profile": "https://Stackoverflow.com/users/1908",
"pm_score": 0,
"selected": false,
"text": "<p>You can use multiple inheritance in your html elements (e.g. <code><div class=\"one two\"></code>) but I'm not awa... | 2008/08/27 | [
"https://Stackoverflow.com/questions/30170",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/797/"
] | Are there any useful techniques for reducing the repetition of constants in a CSS file?
(For example, a bunch of different selectors which should all apply the same colour, or the same font size)? | Recently, [**variables have been added**](https://www.w3.org/TR/css-variables/) to the official CSS specs.
Variables allow you to so something like this :
```css
body, html {
margin: 0;
height: 100%;
}
.theme-default {
--page-background-color: #cec;
--page-color: #333;
--button-border-width: 1px;... |
30,171 | <p>Help! I have an Axis web service that is being consumed by a C# application. Everything works great, except that arrays of long values always come across as [0,0,0,0] - the right length, but the values aren't deserialized. I have tried with other primitives (ints, doubles) and the same thing happens. What do I d... | [
{
"answer_id": 30172,
"author": "Chris Marasti-Georg",
"author_id": 96,
"author_profile": "https://Stackoverflow.com/users/96",
"pm_score": 4,
"selected": true,
"text": "<p>Here's what I ended up with. I have never found another solution out there for this, so if you have something bett... | 2008/08/27 | [
"https://Stackoverflow.com/questions/30171",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/96/"
] | Help! I have an Axis web service that is being consumed by a C# application. Everything works great, except that arrays of long values always come across as [0,0,0,0] - the right length, but the values aren't deserialized. I have tried with other primitives (ints, doubles) and the same thing happens. What do I do? I do... | Here's what I ended up with. I have never found another solution out there for this, so if you have something better, by all means, contribute.
First, the long array definition in the wsdl:types area:
```
<xsd:complexType name="ArrayOf_xsd_long">
<xsd:complexContent mixed="false">
<xsd:restriction base="s... |
30,184 | <p>I am creating a small modal form that is used in Winforms application. It is basically a progress bar of sorts. But I would like the user to be able to click anywhere in the form and drag it to move it around on the desktop while it is still being displayed.</p>
<p>How can I implement this behavior?</p>
| [
{
"answer_id": 30241,
"author": "Timothy Fries",
"author_id": 3163,
"author_profile": "https://Stackoverflow.com/users/3163",
"pm_score": 6,
"selected": true,
"text": "<p><a href=\"http://support.microsoft.com/kb/320687\" rel=\"nofollow noreferrer\" title=\"KB Article 320687\">Microsoft ... | 2008/08/27 | [
"https://Stackoverflow.com/questions/30184",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/507/"
] | I am creating a small modal form that is used in Winforms application. It is basically a progress bar of sorts. But I would like the user to be able to click anywhere in the form and drag it to move it around on the desktop while it is still being displayed.
How can I implement this behavior? | [Microsoft KB Article 320687](http://support.microsoft.com/kb/320687 "KB Article 320687") has a detailed answer to this question.
Basically, you override the WndProc method to return HTCAPTION to the WM\_NCHITTEST message when the point being tested is in the client area of the form -- which is, in effect, telling Win... |