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
406,533
<p>Which dependency should be added in pom file to import <code>org.apache.tiles.controller</code>?</p>
[ { "answer_id": 406562, "author": "Andrew Newdigate", "author_id": 50131, "author_profile": "https://Stackoverflow.com/users/50131", "pm_score": 1, "selected": false, "text": "<p>org.apache.struts.tiles.Controller is an interface in Struts Tiles 1.x, which you can find in the maven artifa...
2009/01/02
[ "https://Stackoverflow.com/questions/406533", "https://Stackoverflow.com", "https://Stackoverflow.com/users/40933/" ]
Which dependency should be added in pom file to import `org.apache.tiles.controller`?
org.apache.struts.tiles.Controller is an interface in Struts Tiles 1.x, which you can find in the maven artifact "org.apache.struts:struts-tiles" ```xml <dependency> <groupId>org.apache.struts</groupId> <artifactId>struts-tiles</artifactId> <version>1.3.10</version> </dependency> ``` Keep in mind, this o...
406,550
<p>I am trying to find the best way to design the database in order to allow the following scenario:</p> <ol> <li>The user is presented with a dropdown list of Universities (for example)</li> <li>The user selects his/her university from the list if it exists</li> <li>If the university does not exist, he should enter h...
[ { "answer_id": 406553, "author": "S.Lott", "author_id": 10661, "author_profile": "https://Stackoverflow.com/users/10661", "pm_score": -1, "selected": false, "text": "<p>This isn't a database design issue. It's a UI issue.</p>\n\n<p>The Drop down list of universities is based on rows in ...
2009/01/02
[ "https://Stackoverflow.com/questions/406550", "https://Stackoverflow.com", "https://Stackoverflow.com/users/47582/" ]
I am trying to find the best way to design the database in order to allow the following scenario: 1. The user is presented with a dropdown list of Universities (for example) 2. The user selects his/her university from the list if it exists 3. If the university does not exist, he should enter his own university in a te...
``` CREATE TABLE university ( id smallint NOT NULL, name text, public smallint, CONSTRAINT university_pk PRIMARY KEY (id) ); CREATE TABLE person ( id smallint NOT NULL, university smallint, -- more columns here... CONSTRAINT person_pk PRIMARY KEY (id), CONSTRAINT person_university_fk FOREIGN KEY (uni...
406,552
<p>I cannot seem to access the context object using a loop context is set: <code>var context = [id1, id2, id3];</code></p> <p>This callback function works:</p> <pre><code>function OnChangeSucceeded(result, context, methodName) { document.getElementById(context[0]).disabled = result; document.getElementById(co...
[ { "answer_id": 406553, "author": "S.Lott", "author_id": 10661, "author_profile": "https://Stackoverflow.com/users/10661", "pm_score": -1, "selected": false, "text": "<p>This isn't a database design issue. It's a UI issue.</p>\n\n<p>The Drop down list of universities is based on rows in ...
2009/01/02
[ "https://Stackoverflow.com/questions/406552", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3416/" ]
I cannot seem to access the context object using a loop context is set: `var context = [id1, id2, id3];` This callback function works: ``` function OnChangeSucceeded(result, context, methodName) { document.getElementById(context[0]).disabled = result; document.getElementById(context[1]).disabled = result; ...
``` CREATE TABLE university ( id smallint NOT NULL, name text, public smallint, CONSTRAINT university_pk PRIMARY KEY (id) ); CREATE TABLE person ( id smallint NOT NULL, university smallint, -- more columns here... CONSTRAINT person_pk PRIMARY KEY (id), CONSTRAINT person_university_fk FOREIGN KEY (uni...
406,558
<p>I usually get so confused with UML and this situation is no different. Let's say I have an interface IAnimal, class Food and Cat:</p> <pre><code>interface IAnimal { void Feed(Food food); } class Cat : IAnimal { void Feed(Food food) { //code } } </code></pre> <p>I've got 3 questions about drawi...
[ { "answer_id": 406581, "author": "Arne Burmeister", "author_id": 12890, "author_profile": "https://Stackoverflow.com/users/12890", "pm_score": 0, "selected": false, "text": "<p>Assuming a class diagramm, you should have a \"use\" association between IAnimal and Food and a \"is a\" associ...
2009/01/02
[ "https://Stackoverflow.com/questions/406558", "https://Stackoverflow.com", "https://Stackoverflow.com/users/40872/" ]
I usually get so confused with UML and this situation is no different. Let's say I have an interface IAnimal, class Food and Cat: ``` interface IAnimal { void Feed(Food food); } class Cat : IAnimal { void Feed(Food food) { //code } } ``` I've got 3 questions about drawing UML class diagram for t...
UML defines a number of **relationship** types. Relationships have a number of different notations: * Association relationships have a base notation of a solid path * Dependency relationships have a base notation of a dashed arrow * Generalization relationships have a base notation of a solid path with a triangular a...
406,561
<p>I have a file "atest.txt" that have some text..</p> <p>I want to print this text at files "asdasd.txt asgfaya.txt asdjfusfdgh.txt asyeiuyhavujh.txt"</p> <p>This files is not exist on my server..</p> <p>I'm running Debian.. What can i do?</p>
[ { "answer_id": 406571, "author": "Eineki", "author_id": 29125, "author_profile": "https://Stackoverflow.com/users/29125", "pm_score": 1, "selected": false, "text": "<p>In bash you can write </p>\n\n<pre><code>#!/bin/bash\n$TEXT=\"hello\\nthis is a test\\nthank you\"\nfor i in `seq 1 $1`;...
2009/01/02
[ "https://Stackoverflow.com/questions/406561", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I have a file "atest.txt" that have some text.. I want to print this text at files "asdasd.txt asgfaya.txt asdjfusfdgh.txt asyeiuyhavujh.txt" This files is not exist on my server.. I'm running Debian.. What can i do?
Use the *tee*(1) command, which duplicates its standard input to standard output and any files specified on the command line. E.g. ``` printf "Hello\nthis is a test\nthank you\n" | tee test1.txt test2.txt $OTHER_FILES >/dev/null ``` Using your example: ``` cat atest.txt | tee asdasd.txt asgfaya.txt asdjfusfdgh.t...
406,587
<p>I'm working on an 'advanced search' page on a site where you would enter a keyword such as 'I like apples' and it can search the database using the following options:</p> <blockquote> <p>Find : With all the words, With the exact phrase , With at least one of the words, Without the words</p> </blockquote> <p>...
[ { "answer_id": 406596, "author": "Re0sless", "author_id": 2098, "author_profile": "https://Stackoverflow.com/users/2098", "pm_score": 2, "selected": false, "text": "<p>You could use</p>\n\n<p>With at least one of the words</p>\n\n<pre><code>SELECT * FROM myTable WHERE field LIKE '%$keywo...
2009/01/02
[ "https://Stackoverflow.com/questions/406587", "https://Stackoverflow.com", "https://Stackoverflow.com/users/49153/" ]
I'm working on an 'advanced search' page on a site where you would enter a keyword such as 'I like apples' and it can search the database using the following options: > > Find : With all the words, With the > exact phrase , With at least one of > the words, Without the words > > > I can take care of the 'Exact ...
I would suggest the use of [MySQL FullText Search](http://dev.mysql.com/doc/refman/5.1/en/fulltext-search.html) using this with the [Boolean Full-Text Searches](http://dev.mysql.com/doc/refman/5.1/en/fulltext-boolean.html) functionality you should be able to get your desired result. Edit: Requested example based on y...
406,613
<p>I recently wrote a piece of code which did</p> <pre><code>SomeClass someObject; mysqlpp::StoreQueryResult result = someObject.getResult(); </code></pre> <p>where SomeClass::getResult() looks like:</p> <pre><code>mysqlpp::StoreQueryResult SomeClass::getResult() { mysqlpp::StoreQueryResult res = ...&lt;something&gt...
[ { "answer_id": 406618, "author": "Frederick The Fool", "author_id": 32688, "author_profile": "https://Stackoverflow.com/users/32688", "pm_score": 3, "selected": true, "text": "<p>I don't think there's any difference in the two cases. The same copy constructor is called both times.</p>\n\...
2009/01/02
[ "https://Stackoverflow.com/questions/406613", "https://Stackoverflow.com", "https://Stackoverflow.com/users/42387/" ]
I recently wrote a piece of code which did ``` SomeClass someObject; mysqlpp::StoreQueryResult result = someObject.getResult(); ``` where SomeClass::getResult() looks like: ``` mysqlpp::StoreQueryResult SomeClass::getResult() { mysqlpp::StoreQueryResult res = ...<something>...; return res; } ``` Now, using the ex...
I don't think there's any difference in the two cases. The same copy constructor is called both times. Are you sure this is *exactly* what you've written in your code?
406,616
<p>I want to display an image gallery, and on the view page, one should be able to have a look at a bunch of thumbnails: the current picture, wrapped with the two previous entries and the two next ones.</p> <p>The problem of fetching two next/prev is that I can't (unless I'm mistaken) select something like MAX(id) WHE...
[ { "answer_id": 406639, "author": "Steven Robbins", "author_id": 26507, "author_profile": "https://Stackoverflow.com/users/26507", "pm_score": 0, "selected": false, "text": "<p>If you are just interested in the previous and next records by id couldn't you just have a where clause that res...
2009/01/02
[ "https://Stackoverflow.com/questions/406616", "https://Stackoverflow.com", "https://Stackoverflow.com/users/50871/" ]
I want to display an image gallery, and on the view page, one should be able to have a look at a bunch of thumbnails: the current picture, wrapped with the two previous entries and the two next ones. The problem of fetching two next/prev is that I can't (unless I'm mistaken) select something like MAX(id) WHERE idxx. ...
if your IDs are continuous you could do ``` where id >= @id-2 and id <= @id+2 ``` Otherwise I think you'd have to `union` 3 queries, one to get the record with the given id and two others messing about with `top` and `order by` like this ``` select * from table where id = @id union select top 2 * from table where...
406,637
<p>See code below, for some reason it only works when I put a breakpoint on line 2 (*) is there some delay? Is it starting the next line before it finishes the 2nd one?</p> <pre><code>dp.SSLCertStoreType = nsoftware.IBizPayPal.DirectpaymentSSLCertStoreTypes.sstPEMKey *dp.SSLCertStore = My.Computer.FileSystem.ReadAllT...
[ { "answer_id": 406645, "author": "Frederick The Fool", "author_id": 32688, "author_profile": "https://Stackoverflow.com/users/32688", "pm_score": 0, "selected": false, "text": "<p>I have no knowledge of ASP, so just wondering aloud: Could this be due to multithreading? You know when you ...
2009/01/02
[ "https://Stackoverflow.com/questions/406637", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18309/" ]
See code below, for some reason it only works when I put a breakpoint on line 2 (\*) is there some delay? Is it starting the next line before it finishes the 2nd one? ``` dp.SSLCertStoreType = nsoftware.IBizPayPal.DirectpaymentSSLCertStoreTypes.sstPEMKey *dp.SSLCertStore = My.Computer.FileSystem.ReadAllText(Server.Ma...
Almost certainly a threading issue, but nobody is going to be able to answer definitively unless they're familiar with `nsoftware.IBizPayPal`
406,667
<p>I'm teaching myself Objective-C from a book (<em>Cocoa programming for mac OS X</em>) and am about halfway through however I have two questions that aren't answered or defined in the book.</p> <ol> <li><p>When defining class methods what is the difference between (assuming there in a .h file):</p> <p>- (int) popul...
[ { "answer_id": 406684, "author": "Paul Dixon", "author_id": 6521, "author_profile": "https://Stackoverflow.com/users/6521", "pm_score": 0, "selected": false, "text": "<p>You can see some discussion of when to use static methods in <a href=\"https://stackoverflow.com/questions/202560/when...
2009/01/02
[ "https://Stackoverflow.com/questions/406667", "https://Stackoverflow.com", "https://Stackoverflow.com/users/313002/" ]
I'm teaching myself Objective-C from a book (*Cocoa programming for mac OS X*) and am about halfway through however I have two questions that aren't answered or defined in the book. 1. When defining class methods what is the difference between (assuming there in a .h file): - (int) population; + (int) population; T...
The -/+ in method declarations for Objective-C simply denote whether the method is a class method or an instance method. For example, with Objective-C, you cannot send an instance a message that was declared as a class method. For example: ``` @interface MyObject : NSObject -(void)myInstanceMethod; +(void)myClassMetho...
406,682
<p>I'm having a little problem with the following:</p> <p>When I execute this line:</p> <pre><code>echo exec(createDir($somevariable)); </code></pre> <p>I get this error:</p> <pre><code>Warning: exec() [function.exec]: Cannot execute a blank command in /home/mydir/myfile.inc.php on line 32 </code></pre> <p>Any ide...
[ { "answer_id": 406688, "author": "Max", "author_id": 50023, "author_profile": "https://Stackoverflow.com/users/50023", "pm_score": -1, "selected": false, "text": "<p>I'm guessing createDir() doesn't have a return value.</p>\n\n<p>Try <code>exec(\"mkdir $somevariable\");</code></p>\n" }...
2009/01/02
[ "https://Stackoverflow.com/questions/406682", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1071/" ]
I'm having a little problem with the following: When I execute this line: ``` echo exec(createDir($somevariable)); ``` I get this error: ``` Warning: exec() [function.exec]: Cannot execute a blank command in /home/mydir/myfile.inc.php on line 32 ``` Any ideas. Thanks.
[`exec()`](http://php.net/exec) expects a string argument, which it would pass on to your operating system to be executed. In other words, this is a portal to the server's command line. I'm not sure what function `createDir()` is, but unless it's returning a valid command line string, it's probably failing because of ...
406,695
<p>I want to (quickly) put a program/script together to read the fileset from a .torrent file. I want to then use that set to delete any files from a specific directory that do not belong to the torrent.</p> <p>Any recommendations on a handy library for reading this index from the .torrent file? Whilst I don't object ...
[ { "answer_id": 406735, "author": "bobince", "author_id": 18936, "author_profile": "https://Stackoverflow.com/users/18936", "pm_score": 2, "selected": false, "text": "<p>bencode.py from the original Mainline BitTorrent 5.x client (<a href=\"http://download.bittorrent.com/dl/BitTorrent-5.2...
2009/01/02
[ "https://Stackoverflow.com/questions/406695", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1820/" ]
I want to (quickly) put a program/script together to read the fileset from a .torrent file. I want to then use that set to delete any files from a specific directory that do not belong to the torrent. Any recommendations on a handy library for reading this index from the .torrent file? Whilst I don't object to it, I d...
[Effbot has your question answered](http://effbot.org/zone/bencode.htm). Here is the complete code to read the list of files from .torrent file (Python 2.4+): ``` import re def tokenize(text, match=re.compile("([idel])|(\d+):|(-?\d+)").match): i = 0 while i < len(text): m = match(text, i) s = ...
406,700
<p>Would there be difference in speed between<br/></p> <pre><code>if (myInt == CONST_STATE1) </code></pre> <p>and</p> <pre><code>if (myEnum == myENUM.State1) </code></pre> <p>in c#?</p>
[ { "answer_id": 406705, "author": "Rowland Shaw", "author_id": 50447, "author_profile": "https://Stackoverflow.com/users/50447", "pm_score": 5, "selected": true, "text": "<p>In C# Enums are in-lined to be constants by the compilier anyway, so the benefit is code legibility</p>\n" }, {...
2009/01/02
[ "https://Stackoverflow.com/questions/406700", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17540/" ]
Would there be difference in speed between ``` if (myInt == CONST_STATE1) ``` and ``` if (myEnum == myENUM.State1) ``` in c#?
In C# Enums are in-lined to be constants by the compilier anyway, so the benefit is code legibility
406,776
<p><em>Removed link, problem solved</em></p> <p>The menu at the top is supposed to be a dropdown menu, but it expands to the right instead. </p> <p>My CSS is this (I believe this is the relevant bit anyway)</p> <pre><code>#primary-nav, #primary-nav ul { list-style: none; margin: 0px; padding: 0px; } #primary-nav ul...
[ { "answer_id": 406784, "author": "stuartloxton", "author_id": 313002, "author_profile": "https://Stackoverflow.com/users/313002", "pm_score": 2, "selected": false, "text": "<p>Remove the <code>position: absolute;</code> from the CSS of <code>#primary-nav ul</code> also maybe have a look ...
2009/01/02
[ "https://Stackoverflow.com/questions/406776", "https://Stackoverflow.com", "https://Stackoverflow.com/users/42389/" ]
*Removed link, problem solved* The menu at the top is supposed to be a dropdown menu, but it expands to the right instead. My CSS is this (I believe this is the relevant bit anyway) ``` #primary-nav, #primary-nav ul { list-style: none; margin: 0px; padding: 0px; } #primary-nav ul { position: absolute; top: auto; di...
Take a small and nice reading [here](http://www.alistapart.com/articles/dropdowns).
406,791
<p>I'm having a problem with the following code snippet:</p> <pre><code>using System; using System.Collections.Generic; using System.Text; namespace trees_by_firas { class Program { static void Main(string[] args) { BinarySearchTree t = new BinarySearchTree(); t.insert...
[ { "answer_id": 406796, "author": "Jon Skeet", "author_id": 22656, "author_profile": "https://Stackoverflow.com/users/22656", "pm_score": 2, "selected": false, "text": "<p>_left and _right are fields in TreeNode. You're trying to use them as if they're part of BinarySearchTree. I believe ...
2009/01/02
[ "https://Stackoverflow.com/questions/406791", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I'm having a problem with the following code snippet: ``` using System; using System.Collections.Generic; using System.Text; namespace trees_by_firas { class Program { static void Main(string[] args) { BinarySearchTree t = new BinarySearchTree(); t.insert(ref t.root, 1...
\_left and \_right are fields in TreeNode. You're trying to use them as if they're part of BinarySearchTree. I believe you can just prefix them with `root.`: ``` public int CountNodes() { int count = 1; // me! if (root._left != null) count += root._left.CountNodes(); if (root._right != null...
406,810
<p>I have a html page A and a link in the page which opens up page B in a new window. How to reload the page A on clicking and opening this link ? </p> <p><strong>EDIT:</strong></p> <p>I should have been more clear. Page B opens in a new window and not as a popup. The hyperlink in question has its target attribute se...
[ { "answer_id": 406817, "author": "Mark Davidson", "author_id": 50866, "author_profile": "https://Stackoverflow.com/users/50866", "pm_score": 1, "selected": false, "text": "<p>The simplest way would be to do </p>\n\n<pre><code>&lt;a href=\"# \" onClick=\"window.open('newPage.htm','window'...
2009/01/02
[ "https://Stackoverflow.com/questions/406810", "https://Stackoverflow.com", "https://Stackoverflow.com/users/27474/" ]
I have a html page A and a link in the page which opens up page B in a new window. How to reload the page A on clicking and opening this link ? **EDIT:** I should have been more clear. Page B opens in a new window and not as a popup. The hyperlink in question has its target attribute set to \_blank. Taking a clue fr...
Something like this: ``` <a href="javascript:window.open('pageB.htm');window.location.reload();">open page b</a> ```
406,813
<p>I have a contactbook, and a form close to it... For the form, one of the requirements is to fill in the receiver for the message. So when the user clicks on a contact from the contactbook, automaticly the username from the titel-tag should appear in the receiver inpunt in the form.</p> <p>All help with this is appr...
[ { "answer_id": 406839, "author": "stuartloxton", "author_id": 313002, "author_profile": "https://Stackoverflow.com/users/313002", "pm_score": 1, "selected": false, "text": "<p>A few extra questions, 1) is the <code>&lt;title&gt;</code> tag just the username or does it have extra text in ...
2009/01/02
[ "https://Stackoverflow.com/questions/406813", "https://Stackoverflow.com", "https://Stackoverflow.com/users/50896/" ]
I have a contactbook, and a form close to it... For the form, one of the requirements is to fill in the receiver for the message. So when the user clicks on a contact from the contactbook, automaticly the username from the titel-tag should appear in the receiver inpunt in the form. All help with this is appreciated!!
SO basically in your example the process goes like this: 1. User clicks the a link saying username 2. input with name pmAmne *(pmName?)* gets filled with 'username' (title **attribute** of paragraph parent of a link clicked? If so then the code below should work: ``` jQuery(function() { jQuery('a.addTitleTag').c...
406,830
<p>Is there a way in Java to declare an enumeration whose values can be used together? For example:</p> <pre><code>enum FileAccess { Read, Write, ReadWrite } </code></pre> <p>Is it possible to define ReadWrite as <code>Read | Write</code> (or anything that would yield the same result)?</p>
[ { "answer_id": 406841, "author": "Jon Skeet", "author_id": 22656, "author_profile": "https://Stackoverflow.com/users/22656", "pm_score": 6, "selected": true, "text": "<p>You use <a href=\"http://java.sun.com/javase/6/docs/api/java/util/EnumSet.html\" rel=\"noreferrer\">EnumSet</a>:</p>\n...
2009/01/02
[ "https://Stackoverflow.com/questions/406830", "https://Stackoverflow.com", "https://Stackoverflow.com/users/41283/" ]
Is there a way in Java to declare an enumeration whose values can be used together? For example: ``` enum FileAccess { Read, Write, ReadWrite } ``` Is it possible to define ReadWrite as `Read | Write` (or anything that would yield the same result)?
You use [EnumSet](http://java.sun.com/javase/6/docs/api/java/util/EnumSet.html): ``` EnumSet<FileAccess> readWrite = EnumSet.of(FileAccess.Read, FileAccess.Write); ``` This is actually somewhat more elegant than the C#/.NET way, IMO - aside from anything else, you can easily distinguish between a set and a single va...
406,880
<p>I've used the following code to map <a href="https://live.example.com" rel="nofollow noreferrer">https://live.example.com</a> on to <a href="http://example.com/api" rel="nofollow noreferrer">http://example.com/api</a></p> <pre><code>Options +FollowSymLinks RewriteEngine On RewriteCond %{HTTPS} =on RewriteCond %{...
[ { "answer_id": 406983, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 2, "selected": false, "text": "<p>I got it fixed:</p>\n\n<p>Added to apache2.conf (httpd.conf):</p>\n\n<pre><code>RewriteMap escapemap int:escape \n</code></...
2009/01/02
[ "https://Stackoverflow.com/questions/406880", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I've used the following code to map <https://live.example.com> on to <http://example.com/api> ``` Options +FollowSymLinks RewriteEngine On RewriteCond %{HTTPS} =on RewriteCond %{HTTP_HOST} ^live\.example\.com [NC] RewriteRule (.+)$ "http://example.com/api/$1" [L,P] ``` The following url: ``` https://live.example...
I got it fixed: Added to apache2.conf (httpd.conf): ``` RewriteMap escapemap int:escape ``` .htaccess: ``` Options +FollowSymLinks RewriteEngine On RewriteCond %{HTTPS} =on RewriteCond "%{HTTP_HOST}" "^live\.domain\.com" [NC] RewriteRule "(.*)$" "http://domain.com/api/${escapemap:$1}" [L,P] ``` *source: <htt...
406,903
<p>I need a template like this, which work perfectly</p> <pre><code>template &lt;typename container&gt; void mySuperTempalte (const container myCont) { //do something here } </code></pre> <p>then i want to specialize the above template for std::string so i came up with</p> <pre><code>template &lt;typename contai...
[ { "answer_id": 406935, "author": "sep", "author_id": 30333, "author_profile": "https://Stackoverflow.com/users/30333", "pm_score": 3, "selected": false, "text": "<p>To specialize:</p>\n\n<pre><code>template&lt;&gt; void mySuperTempalte&lt;std:string&gt;(const std::string myCont)\n{\n ...
2009/01/02
[ "https://Stackoverflow.com/questions/406903", "https://Stackoverflow.com", "https://Stackoverflow.com/users/28954/" ]
I need a template like this, which work perfectly ``` template <typename container> void mySuperTempalte (const container myCont) { //do something here } ``` then i want to specialize the above template for std::string so i came up with ``` template <typename container> void mySuperTempalte (const container<std...
If I am understanding your problem correctly you have an algorithm that will work for STL containers vector, deque etc but are trying to write a template specialisation for string. If this is the case then you can write the generalised templated method that you defined in your question:- ``` template<typename containe...
406,912
<p>I have 2 textbox in my asp.net page and also have one hiddenfield in my asp.net page , my hiddenfield will always have numeric value like 123.00 , and in my one textbox also I will always have numeric value like 20.00 now I want to add this hiddenfield value and textbox value and display it into second textbox thru...
[ { "answer_id": 406920, "author": "annakata", "author_id": 13018, "author_profile": "https://Stackoverflow.com/users/13018", "pm_score": 2, "selected": false, "text": "<p>the value of an input is just a string - <a href=\"http://www.w3schools.com/jsref/jsref_parseFloat.asp\" rel=\"nofollo...
2009/01/02
[ "https://Stackoverflow.com/questions/406912", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14299/" ]
I have 2 textbox in my asp.net page and also have one hiddenfield in my asp.net page , my hiddenfield will always have numeric value like 123.00 , and in my one textbox also I will always have numeric value like 20.00 now I want to add this hiddenfield value and textbox value and display it into second textbox thru jav...
``` amt.value = parseFloat(hiddenamt) + parseFloat(fee); ```
406,915
<p>Andreas Huber's answer to <a href="https://stackoverflow.com/questions/405600/detecting-that-a-threadpool-workitem-has-completed-waiting-for-completion">this question</a> gave me an idea to implement <code>Concurrent&lt;T&gt;</code> with async delegates instead of the ThreadPool. However, I am finding it harder to u...
[ { "answer_id": 406920, "author": "annakata", "author_id": 13018, "author_profile": "https://Stackoverflow.com/users/13018", "pm_score": 2, "selected": false, "text": "<p>the value of an input is just a string - <a href=\"http://www.w3schools.com/jsref/jsref_parseFloat.asp\" rel=\"nofollo...
2009/01/02
[ "https://Stackoverflow.com/questions/406915", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9204/" ]
Andreas Huber's answer to [this question](https://stackoverflow.com/questions/405600/detecting-that-a-threadpool-workitem-has-completed-waiting-for-completion) gave me an idea to implement `Concurrent<T>` with async delegates instead of the ThreadPool. However, I am finding it harder to understand what's going on when ...
``` amt.value = parseFloat(hiddenamt) + parseFloat(fee); ```
406,927
<p>How can I detect if an application is not used for more than x minutes in DELPHI</p>
[ { "answer_id": 406950, "author": "Rowland Shaw", "author_id": 50447, "author_profile": "https://Stackoverflow.com/users/50447", "pm_score": 0, "selected": false, "text": "<p>Depends on how you're defining \"used\" -- if you were monitoring yourself, you could look at the last time you re...
2009/01/02
[ "https://Stackoverflow.com/questions/406927", "https://Stackoverflow.com", "https://Stackoverflow.com/users/48705/" ]
How can I detect if an application is not used for more than x minutes in DELPHI
Use the applications OnDeactivate and onActive events.. That way you can abort the longrunning job if the user activates your program again. ex: ``` Application.OnDeactivate = yourDeactivProcedure; procedure mainform.YourDecativateProcedure (sender : tObject); begin // do your job.. end; ``` To handle the act...
406,939
<p>I'm having difficulty getting widgets in a QDialog resized automatically when the dialog itself is resized.</p> <p>In the following program, the textarea resizes automatically if you resize the main window. However, the textarea within the dialog stays the same size when the dialog is resized.</p> <p>Is there any...
[ { "answer_id": 406982, "author": "Judge Maygarden", "author_id": 1491, "author_profile": "https://Stackoverflow.com/users/1491", "pm_score": 4, "selected": true, "text": "<p>QMainWindow has special behavior for the central widget that a QDialog does not. To achieve the desired behavior y...
2009/01/02
[ "https://Stackoverflow.com/questions/406939", "https://Stackoverflow.com", "https://Stackoverflow.com/users/48503/" ]
I'm having difficulty getting widgets in a QDialog resized automatically when the dialog itself is resized. In the following program, the textarea resizes automatically if you resize the main window. However, the textarea within the dialog stays the same size when the dialog is resized. Is there any way of making the...
QMainWindow has special behavior for the central widget that a QDialog does not. To achieve the desired behavior you need to create a [layout](http://doc.trolltech.com/3.3/layout.html), add the text area to the layout and assign the layout to the dialog.
406,955
<p>I've got an app which is using a WCF service. Now I'd like to add unit tests to the app.</p> <p>For some cases I need to mock the WCF service, since getting the desired behaviour from the service sometimes is tough (e.g. service throws special exceptions).</p> <p>I could add yet another interface to the wcf client...
[ { "answer_id": 407240, "author": "David Schmitt", "author_id": 4918, "author_profile": "https://Stackoverflow.com/users/4918", "pm_score": 4, "selected": true, "text": "<p>Why can't you use something like <a href=\"http://nmock2.sourceforge.net/\" rel=\"noreferrer\">NMock2</a> to mock th...
2009/01/02
[ "https://Stackoverflow.com/questions/406955", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7021/" ]
I've got an app which is using a WCF service. Now I'd like to add unit tests to the app. For some cases I need to mock the WCF service, since getting the desired behaviour from the service sometimes is tough (e.g. service throws special exceptions). I could add yet another interface to the wcf client, but this seems ...
Why can't you use something like [NMock2](http://nmock2.sourceforge.net/) to mock the `IMyWcfService` interfaces directly? If you need to be able to create new instances on the fly, use the Factory to hide the `ChannelFactory<IMyWcfService>` from the client. This way you can replace the factory, providing the client o...
406,963
<p>I'm probably missing something simple here, but I can't find the answer elsewhere. I just want to display an applet in my GWT code. </p> <p>OS: Windows XP Java: JDK 1.6.0_10 Other: GWT, GWT-Ext 2.0.5</p> <p>Here is the applet (obviously simplified for testing):</p> <pre><code>package foo.applet; import javax.swi...
[ { "answer_id": 406999, "author": "duffymo", "author_id": 37213, "author_profile": "https://Stackoverflow.com/users/37213", "pm_score": -1, "selected": false, "text": "<p>\"The import javax.swing cannot be resolved\" - sorry, I'm not a GWT maven, but this error is classpath-esque. Sounds...
2009/01/02
[ "https://Stackoverflow.com/questions/406963", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9945/" ]
I'm probably missing something simple here, but I can't find the answer elsewhere. I just want to display an applet in my GWT code. OS: Windows XP Java: JDK 1.6.0\_10 Other: GWT, GWT-Ext 2.0.5 Here is the applet (obviously simplified for testing): ``` package foo.applet; import javax.swing.JApplet; import java.awt...
Are you trying to GWT-compile your applet? This won't work, as GWT compilation (which is just translation from Java to Javascript) supports only handful of Java libraries and certainly not applets. Make sure that your applet is not on GWT source path (move it to another package). Reference: <http://code.google.com/...
406,966
<p>I have an application which had optional extras depending on if the user has the software installed.</p> <p>On Linux what is the best way to determine if something like python and PyUsb is installed?</p> <p>I am developing a C++ Qt application if that helps.</p>
[ { "answer_id": 406992, "author": "Kris Kumler", "author_id": 4281, "author_profile": "https://Stackoverflow.com/users/4281", "pm_score": 1, "selected": false, "text": "<p>You can require that they be in the path, etc. Check for the existence of the executable files you will require (usi...
2009/01/02
[ "https://Stackoverflow.com/questions/406966", "https://Stackoverflow.com", "https://Stackoverflow.com/users/24459/" ]
I have an application which had optional extras depending on if the user has the software installed. On Linux what is the best way to determine if something like python and PyUsb is installed? I am developing a C++ Qt application if that helps.
This is inefficient (requires forking and exec'ing */bin/sh*). There has to be a better way! But as a generic approach... There's always *system()*. (Remember to use *WEXITSTATUS()*! Watch out for making programs uninterruptable!) ``` #define SHOW(X) cout << # X " = " << (X) << endl int main() { int status; SH...
406,985
<p>I want to be able to predicate pattern matches on whether they occur after word characters or after non-word characters. In other words, I want to simulate the \b word break regex char at the beginning of the pattern which flex/lex does not support.</p> <p>Here's my attempt below (which does not work as desired):</...
[ { "answer_id": 408711, "author": "user49117", "author_id": 49117, "author_profile": "https://Stackoverflow.com/users/49117", "pm_score": 1, "selected": false, "text": "<pre><code>%%\n[a-zA-Z]+a[a-zA-Z]* {printf(\"a in word: %s\\n\", yytext);}\na[a-zA-Z]+ {printf(\"a in word: %s\\n\", yyt...
2009/01/02
[ "https://Stackoverflow.com/questions/406985", "https://Stackoverflow.com", "https://Stackoverflow.com/users/41613/" ]
I want to be able to predicate pattern matches on whether they occur after word characters or after non-word characters. In other words, I want to simulate the \b word break regex char at the beginning of the pattern which flex/lex does not support. Here's my attempt below (which does not work as desired): ``` %{ #in...
Here's what accomplished what I wanted: ``` %{ #include <stdio.h> %} WC [A-Za-z'] NW [^A-Za-z'] %start INW NIW {WC} { BEGIN INW; REJECT; } {NW} { BEGIN NIW; REJECT; } <INW>a { printf("'a' in word\n"); } <NIW>a { printf("'a' not in word\n"); } ``` This way I can do the equivalent of \B or \b at t...
407,026
<p>I am a little confused here.</p> <p>I would like to do something like this:</p> <ol> <li>create some kind of buffer I can write into</li> <li>clear the buffer</li> <li>use a printf()-like function several times to append a bunch of stuff into the buffer based on some complicated calculations I only want to do once...
[ { "answer_id": 407084, "author": "Jason S", "author_id": 44330, "author_profile": "https://Stackoverflow.com/users/44330", "pm_score": 3, "selected": true, "text": "<p>ah: I think I've got it. The <a href=\"http://java.sun.com/j2se/1.5.0/docs/api/java/util/Formatter.html\" rel=\"nofollow...
2009/01/02
[ "https://Stackoverflow.com/questions/407026", "https://Stackoverflow.com", "https://Stackoverflow.com/users/44330/" ]
I am a little confused here. I would like to do something like this: 1. create some kind of buffer I can write into 2. clear the buffer 3. use a printf()-like function several times to append a bunch of stuff into the buffer based on some complicated calculations I only want to do once 4. use the contents of the buff...
ah: I think I've got it. The [`Formatter`](http://java.sun.com/j2se/1.5.0/docs/api/java/util/Formatter.html) class has a `format()` method that's like `printf()`, and it can be constructed to wrap around any kind of object that implements `Appendable`. [`CharBuffer`](http://java.sun.com/j2se/1.5.0/docs/api/java/nio/Cha...
407,027
<p>We've a table with a <code>varchar2(100)</code> column, that occasionally contains carriage-return &amp; line-feeds. We should like to remove those characters in the SQL query. We're using:</p> <pre><code>REPLACE( col_name, CHR(10) ) </code></pre> <p>which has <strong>no effect</strong>, however replacing 'CHR(10...
[ { "answer_id": 407050, "author": "Cade Roux", "author_id": 18255, "author_profile": "https://Stackoverflow.com/users/18255", "pm_score": 4, "selected": false, "text": "<p>Are you sure your newline is not <code>CHR(13) + CHR(10)</code>, in which case, you are ending up with <code>CHR(13) ...
2009/01/02
[ "https://Stackoverflow.com/questions/407027", "https://Stackoverflow.com", "https://Stackoverflow.com/users/42429/" ]
We've a table with a `varchar2(100)` column, that occasionally contains carriage-return & line-feeds. We should like to remove those characters in the SQL query. We're using: ``` REPLACE( col_name, CHR(10) ) ``` which has **no effect**, however replacing 'CHR(10)' for a more conventional 'letter' character proves t...
Another way is to use [TRANSLATE](http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/functions196.htm#i1501659): ``` TRANSLATE (col_name, 'x'||CHR(10)||CHR(13), 'x') ``` The 'x' is any character that you don't want translated to null, because TRANSLATE doesn't work right if the 3rd parameter is null.
407,048
<p>I've heard from a variety of places that global variables are inherently nasty and evil, but when doing some non-object oriented Javascript, I can't see how to avoid them. Say I have a function which generates a number using a complex algorithm using random numbers and stuff, but I need to keep using that particular...
[ { "answer_id": 407071, "author": "Adam Peck", "author_id": 26658, "author_profile": "https://Stackoverflow.com/users/26658", "pm_score": 2, "selected": false, "text": "<p>If another function needs to use a variable you pass it to the function as an argument.</p>\n\n<p>Also global variabl...
2009/01/02
[ "https://Stackoverflow.com/questions/407048", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I've heard from a variety of places that global variables are inherently nasty and evil, but when doing some non-object oriented Javascript, I can't see how to avoid them. Say I have a function which generates a number using a complex algorithm using random numbers and stuff, but I need to keep using that particular nu...
To make a variable calculated in function A visible in function B, you have three choices: * make it a global, * make it an object property, or * pass it as a parameter when calling B from A. If your program is fairly small then globals are not so bad. Otherwise I would consider using the third method: ``` function ...
407,080
<p>I have read through the solutions to similar problems, but they all seem to involve scripts and extra tools. I'm hoping my problem simple enough to avoid that.</p> <p>So the user uploads a csv of next week's data. It gets inserted into the DB, no problem.</p> <p>BUT</p> <p>an hour later he gets feedback from ever...
[ { "answer_id": 407107, "author": "Josh Kelley", "author_id": 25507, "author_profile": "https://Stackoverflow.com/users/25507", "pm_score": 3, "selected": false, "text": "<p>We're using the output of <code>svnversion</code>, written to a header file and included. We omit the file from th...
2009/01/02
[ "https://Stackoverflow.com/questions/407080", "https://Stackoverflow.com", "https://Stackoverflow.com/users/49478/" ]
I have read through the solutions to similar problems, but they all seem to involve scripts and extra tools. I'm hoping my problem simple enough to avoid that. So the user uploads a csv of next week's data. It gets inserted into the DB, no problem. BUT an hour later he gets feedback from everyone, and must make upda...
We're using the output of `svnversion`, written to a header file and included. We omit the file from the repository and create it in a pre-build step; this has worked quite well for us. (I'm not sure why you object to using a pre-build step?) We're currently using a Perl script to convert `svnversion`'s output into a ...
407,100
<p>I need to call a const function from a non-const object. See example</p> <pre><code>struct IProcess { virtual bool doSomeWork() const = 0L; }; class Foo : public IProcess { virtual bool doSomeWork() const { ... } }; class Bar { public: const IProcess&amp; getProcess() const {return ...;} IProc...
[ { "answer_id": 407114, "author": "Judge Maygarden", "author_id": 1491, "author_profile": "https://Stackoverflow.com/users/1491", "pm_score": 1, "selected": false, "text": "<p>You don't have to do any casting trickery if the function is not overloaded. Calling a const method of a non-cons...
2009/01/02
[ "https://Stackoverflow.com/questions/407100", "https://Stackoverflow.com", "https://Stackoverflow.com/users/49145/" ]
I need to call a const function from a non-const object. See example ``` struct IProcess { virtual bool doSomeWork() const = 0L; }; class Foo : public IProcess { virtual bool doSomeWork() const { ... } }; class Bar { public: const IProcess& getProcess() const {return ...;} IProcess& getProcess() ...
Avoid the cast: assign this to a `const Bar *` or whatever and use that to call `getProcess()`. There are some pedantic reasons to do that, but it also makes it more obvious what you are doing without forcing the compiler to do something potentially unsafe. Granted, you may never hit those cases, but you might as well...
407,108
<p>This is the SP...</p> <pre><code>USE [EBDB] GO /****** Object: StoredProcedure [dbo].[delete_treatment_category] Script Date: 01/02/2009 15:18:12 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO /* RETURNS 0 FOR SUCESS 1 FOR NO DELETE AS HAS ITEMS 2 FOR DELETE ERROR */ ALTER PROCEDURE [...
[ { "answer_id": 407137, "author": "Mark Brackett", "author_id": 2199, "author_profile": "https://Stackoverflow.com/users/2199", "pm_score": 1, "selected": false, "text": "<p>When you added the Parameter, did you set the Direction to <a href=\"http://msdn.microsoft.com/en-us/library/system...
2009/01/02
[ "https://Stackoverflow.com/questions/407108", "https://Stackoverflow.com", "https://Stackoverflow.com/users/37381/" ]
This is the SP... ``` USE [EBDB] GO /****** Object: StoredProcedure [dbo].[delete_treatment_category] Script Date: 01/02/2009 15:18:12 ******/ SET ANSI_NULLS ON GO SET QUOTED_IDENTIFIER ON GO /* RETURNS 0 FOR SUCESS 1 FOR NO DELETE AS HAS ITEMS 2 FOR DELETE ERROR */ ALTER PROCEDURE [dbo].[delete_t...
I'm a little late to the game here, but for the sake of people who stumble upon this question... If you're using ExecuteReader in ADO.Net, the return value will not be populated until you close either the Reader or the underlying connection to the database. ([See here](http://dhenztm.spaces.live.com/blog/cns!761D77A7A...
407,115
<p>I have a combobox in WPF that I add items to at run-time (via a data binding to a List). I'd like to set the height of the dropdown box dynamically so that all (or most) of the items show. Unfortunately it seems that the height of the dropdown is set once and cannot be dynamically altered. It always seems to be t...
[ { "answer_id": 407439, "author": "w4g3n3r", "author_id": 36745, "author_profile": "https://Stackoverflow.com/users/36745", "pm_score": 4, "selected": false, "text": "<p>The property <code>MaxDropDownHeight</code> is a dependency property, on the combo box that controls the height of the ...
2009/01/02
[ "https://Stackoverflow.com/questions/407115", "https://Stackoverflow.com", "https://Stackoverflow.com/users/50932/" ]
I have a combobox in WPF that I add items to at run-time (via a data binding to a List). I'd like to set the height of the dropdown box dynamically so that all (or most) of the items show. Unfortunately it seems that the height of the dropdown is set once and cannot be dynamically altered. It always seems to be the sam...
The property `MaxDropDownHeight` is a dependency property, on the combo box that controls the height of the drop down list. Since it's a dependency property, it's value can be set dynamically. Have you tried setting this value? ``` MaxDropDownHeight="Auto" ```
407,130
<p>From a web service (WCF), I want an endpoint to take 10 seconds to finish.</p> <p>Is there a way I can do a <code>thread.sleep(10);</code> on the method?</p>
[ { "answer_id": 407148, "author": "JaredPar", "author_id": 23283, "author_profile": "https://Stackoverflow.com/users/23283", "pm_score": 4, "selected": true, "text": "<p>You could create a wrapper method which does the appropriate sleep.</p>\n\n<pre><code>Thread.Sleep(TimeSpan.FromSeconds...
2009/01/02
[ "https://Stackoverflow.com/questions/407130", "https://Stackoverflow.com", "https://Stackoverflow.com/users/39677/" ]
From a web service (WCF), I want an endpoint to take 10 seconds to finish. Is there a way I can do a `thread.sleep(10);` on the method?
You could create a wrapper method which does the appropriate sleep. ``` Thread.Sleep(TimeSpan.FromSeconds(10)) ```
407,154
<p>Not that it is seriously burdensome to type </p> <pre><code>:My_custom_foobar() </code></pre> <p>instead of just </p> <pre><code>:my_custom_foobar() </code></pre> <p>but it just feels odd considering how virtually every other aspect of Vim is so extensible. Some searching for an answer has not turned up much, bu...
[ { "answer_id": 407224, "author": "Yada", "author_id": 45066, "author_profile": "https://Stackoverflow.com/users/45066", "pm_score": 3, "selected": true, "text": "<p>Maybe try <a href=\"http://vim.wikia.com/wiki/Mapping_keys_in_Vim_-_Tutorial_(Part_3)\" rel=\"nofollow noreferrer\">mapping...
2009/01/02
[ "https://Stackoverflow.com/questions/407154", "https://Stackoverflow.com", "https://Stackoverflow.com/users/42223/" ]
Not that it is seriously burdensome to type ``` :My_custom_foobar() ``` instead of just ``` :my_custom_foobar() ``` but it just feels odd considering how virtually every other aspect of Vim is so extensible. Some searching for an answer has not turned up much, but I know it's got to be possible without having t...
Maybe try [mapping](http://vim.wikia.com/wiki/Mapping_keys_in_Vim_-_Tutorial_(Part_3)). ``` nnoremap <Leader>f :call My_custom_foobar()<CR> ``` You have to do it one function at a time. Not sure how you would go about doing it for all functions. I say stick to convention and type the capital letter for function name...
407,180
<p>I am working with an object which has sub objects within (see example below). I am attempting to bind a <code>List&lt;rootClass&gt;</code> to the datagrid. When I bind the <code>List&lt;&gt;</code>, in the cell that contains the <code>subObject</code>, I see the following value <code>... "namespace.subObject" ...</c...
[ { "answer_id": 407197, "author": "Lasse V. Karlsen", "author_id": 267, "author_profile": "https://Stackoverflow.com/users/267", "pm_score": 4, "selected": true, "text": "<p>If I'm not mistaken, it shows the result of calling .ToString() on your subObject, so you can override that to retu...
2009/01/02
[ "https://Stackoverflow.com/questions/407180", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I am working with an object which has sub objects within (see example below). I am attempting to bind a `List<rootClass>` to the datagrid. When I bind the `List<>`, in the cell that contains the `subObject`, I see the following value `... "namespace.subObject" ...` the string values display correctly. Ideally I would ...
If I'm not mistaken, it shows the result of calling .ToString() on your subObject, so you can override that to return the contents of Description. Have you tried just binding to Value1.Description? (I'm guessing it doesn't work). I have a class that can be used instead of List when binding, that will handle this, it ...
407,184
<p>I am writing a nightly build script in bash.<br> Everything is fine and dandy except for one little snag:</p> <pre><code> #!/bin/bash for file in "$PATH_TO_SOMEWHERE"; do if [ -d $file ] then # do something directory-ish else if [ "$file" == "*.txt" ] # this is ...
[ { "answer_id": 407208, "author": "Adam Peck", "author_id": 26658, "author_profile": "https://Stackoverflow.com/users/26658", "pm_score": 5, "selected": false, "text": "<p>You can use the \"file\" command if you actually want to find out information about the file rather than rely on the ...
2009/01/02
[ "https://Stackoverflow.com/questions/407184", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I am writing a nightly build script in bash. Everything is fine and dandy except for one little snag: ``` #!/bin/bash for file in "$PATH_TO_SOMEWHERE"; do if [ -d $file ] then # do something directory-ish else if [ "$file" == "*.txt" ] # this is the snag ...
I think you want to say "Are the last four characters of $file equal to `.txt`?" If so, you can use the following: ``` if [ "${file: -4}" == ".txt" ] ``` Note that the space between `file:` and `-4` is required, as the ':-' modifier means something different.
407,209
<p>I want to make Visual Studio move the autocompleted closing tag a word (or more) to the right. For example, given the following HTML:</p> <pre><code>&lt;p&gt;I need to emphasize some text.&lt;/p&gt; </code></pre> <p>If I type <code>&lt;em&gt;</code> before the word "emphasize", Visual Studio autocompletes like so:...
[ { "answer_id": 407270, "author": "Dirk Vollmar", "author_id": 40347, "author_profile": "https://Stackoverflow.com/users/40347", "pm_score": 2, "selected": false, "text": "<p>I don't think this is possible. However, you can configure which HTML tags will be closed automatically:</p>\n\n<p...
2009/01/02
[ "https://Stackoverflow.com/questions/407209", "https://Stackoverflow.com", "https://Stackoverflow.com/users/42685/" ]
I want to make Visual Studio move the autocompleted closing tag a word (or more) to the right. For example, given the following HTML: ``` <p>I need to emphasize some text.</p> ``` If I type `<em>` before the word "emphasize", Visual Studio autocompletes like so: ``` <p>I need to <em></em>emphasize some text.</p> `...
Your question got me thinking how cool it would be if this functionality existed. Luckily, it was pretty simple to implement as a macro in VS. Below is the code for the macro. You can easily bind this to CTRL+ALT+Right using the customization tool in VS. (**Note**: I just threw this together quickly being that it's Fr...
407,237
<p>Is it possible to determine if an ASP.NET page is a postback from javascript? So basically a javascript equivalent of C# Page.IsPostBack.</p> <p>Thanks.</p>
[ { "answer_id": 407246, "author": "Bob", "author_id": 45, "author_profile": "https://Stackoverflow.com/users/45", "pm_score": 5, "selected": true, "text": "<p>I would just put a render tag in the javascript</p>\n\n<pre><code>var isPostBack = &lt;%= Page.IsPostBack ? \"true\" : \"false\" %...
2009/01/02
[ "https://Stackoverflow.com/questions/407237", "https://Stackoverflow.com", "https://Stackoverflow.com/users/47036/" ]
Is it possible to determine if an ASP.NET page is a postback from javascript? So basically a javascript equivalent of C# Page.IsPostBack. Thanks.
I would just put a render tag in the javascript ``` var isPostBack = <%= Page.IsPostBack ? "true" : "false" %>; ``` Putting the "true" and "false" as strings should be done to eliminate any possible issues converting the type to a string as in C# true.ToString() is usually "True" which is an error in javascript.
407,238
<p>I have an <code>IDictionary&lt;TKey,TValue&gt;</code> implementation that internally holds n other <code>Dictionary&lt;TKey, TValue&gt;</code> and distributes that insertions by the HashCode of the key to the invidual sub-dictionaries. With 16 sub-dictionaries, the number of collisions is pretty low on a 4-core mach...
[ { "answer_id": 407267, "author": "Dmitri Nesteruk", "author_id": 9476, "author_profile": "https://Stackoverflow.com/users/9476", "pm_score": 0, "selected": false, "text": "<p>I'm no guru, but my guess is that RWLS is more geared towards heavy contention (e.g., hundreds of threads) wherea...
2009/01/02
[ "https://Stackoverflow.com/questions/407238", "https://Stackoverflow.com", "https://Stackoverflow.com/users/48722/" ]
I have an `IDictionary<TKey,TValue>` implementation that internally holds n other `Dictionary<TKey, TValue>` and distributes that insertions by the HashCode of the key to the invidual sub-dictionaries. With 16 sub-dictionaries, the number of collisions is pretty low on a 4-core machine. For parallel insertions, i lock...
For write-only load the Monitor is cheaper than ReaderWriterLockSlim, however, if you simulate read + write load where read is much greater than write, then ReaderWriterLockSlim should out perform Monitor.
407,255
<p>I have always wondered if, in general, declaring a throw-away variable before a loop, as opposed to repeatedly inside the loop, makes any (performance) difference? A <em>(quite pointless)</em> example in Java:</p> <p><strong>a)</strong> declaration before loop:</p> <pre><code>double intermediateResult; for(int i=...
[ { "answer_id": 407265, "author": "SquidScareMe", "author_id": 30921, "author_profile": "https://Stackoverflow.com/users/30921", "pm_score": 2, "selected": false, "text": "<p>I think it depends on the compiler and is hard to give a general answer.</p>\n" }, { "answer_id": 407277, ...
2009/01/02
[ "https://Stackoverflow.com/questions/407255", "https://Stackoverflow.com", "https://Stackoverflow.com/users/50899/" ]
I have always wondered if, in general, declaring a throw-away variable before a loop, as opposed to repeatedly inside the loop, makes any (performance) difference? A *(quite pointless)* example in Java: **a)** declaration before loop: ``` double intermediateResult; for(int i=0; i < 1000; i++){ intermediateResult...
Which is better, **a** or **b**? From a performance perspective, you'd have to measure it. (And in my opinion, if you can measure a difference, the compiler isn't very good). From a maintenance perspective, **b** is better. Declare and initialize variables in the same place, in the narrowest scope possible. Don't lea...
407,256
<p>I am using a simple regex to replace break tags with newlines:</p> <pre><code>br_regex = /&lt;br&gt;/; input_content = input_content.replace(br_regex, "\n"); </code></pre> <p>This only replaces the first instance of a break tag, but I need to replace all. <code>preg_match_all()</code> would do the trick in PHP, bu...
[ { "answer_id": 407264, "author": "annakata", "author_id": 13018, "author_profile": "https://Stackoverflow.com/users/13018", "pm_score": 8, "selected": true, "text": "<p>Use the global flag, <code>g</code>:</p>\n\n<pre><code>foo.replace(/&lt;br&gt;/g,\"\\n\")\n</code></pre>\n" }, { ...
2009/01/02
[ "https://Stackoverflow.com/questions/407256", "https://Stackoverflow.com", "https://Stackoverflow.com/users/74552/" ]
I am using a simple regex to replace break tags with newlines: ``` br_regex = /<br>/; input_content = input_content.replace(br_regex, "\n"); ``` This only replaces the first instance of a break tag, but I need to replace all. `preg_match_all()` would do the trick in PHP, but I'd like to know the JavaScript equivalen...
Use the global flag, `g`: ``` foo.replace(/<br>/g,"\n") ```
407,279
<p>I have a skeleton text file with placeholder strings:</p> <pre><code>blah blah blah blah $PLACEHOLDER_1$ blah $PLACEHOLDER_2$ </code></pre> <p>and so on. Specific "form" of placeholders does not matter -- I may change them to whatever most comfortable for specific implementation.</p> <p>I have a bash script where...
[ { "answer_id": 407311, "author": "Adam Peck", "author_id": 26658, "author_profile": "https://Stackoverflow.com/users/26658", "pm_score": 4, "selected": true, "text": "<p>You can still use sed to do the replace in a single pass. You just need to specify all the replacements in one comman...
2009/01/02
[ "https://Stackoverflow.com/questions/407279", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6236/" ]
I have a skeleton text file with placeholder strings: ``` blah blah blah blah $PLACEHOLDER_1$ blah $PLACEHOLDER_2$ ``` and so on. Specific "form" of placeholders does not matter -- I may change them to whatever most comfortable for specific implementation. I have a bash script where I know values for placeholders, ...
You can still use sed to do the replace in a single pass. You just need to specify all the replacements in one command. eg. ``` sed -i 's/PLACEHOLDER_1/string 1/g;s/PLACEHOLDER_2/string 2/g' <file> ```
407,287
<p>Title might be a bit confusing, so let me explain.</p> <p>I have a website that has a side-panel, which contains information about the user, things the user can do, etc. When the user is not logged in, this side-panel becomes the area for logging in or registration.</p> <p>The code for this is:</p> <pre><code>&lt...
[ { "answer_id": 407299, "author": "Salty", "author_id": 50548, "author_profile": "https://Stackoverflow.com/users/50548", "pm_score": 3, "selected": true, "text": "<p>You could load the page with an AJAX request and then strip out the data other than the side panel, but what would be the ...
2009/01/02
[ "https://Stackoverflow.com/questions/407287", "https://Stackoverflow.com", "https://Stackoverflow.com/users/29595/" ]
Title might be a bit confusing, so let me explain. I have a website that has a side-panel, which contains information about the user, things the user can do, etc. When the user is not logged in, this side-panel becomes the area for logging in or registration. The code for this is: ``` <?php if($user->loggedIn) { ?> ...
You could load the page with an AJAX request and then strip out the data other than the side panel, but what would be the point? Your best option would be to simply separate the side panel into its own file. Oh, and that would also be considered the proper way of doing it, so you can edit the sidebar without editing ...
407,314
<p>I want to create a quick application for people to resolve the name of a user stored in Active Directory from a set of credentials. Some applications only provide the user id and it is too much to expect an end user to fire up the Active Directory Users and Groups MMC snap-in.</p> <p>Input would be something like "...
[ { "answer_id": 407359, "author": "sfuqua", "author_id": 30384, "author_profile": "https://Stackoverflow.com/users/30384", "pm_score": 0, "selected": false, "text": "<p>See <a href=\"http://msdn.microsoft.com/en-us/library/system.directoryservices.directorysearcher.aspx\" rel=\"nofollow n...
2009/01/02
[ "https://Stackoverflow.com/questions/407314", "https://Stackoverflow.com", "https://Stackoverflow.com/users/636/" ]
I want to create a quick application for people to resolve the name of a user stored in Active Directory from a set of credentials. Some applications only provide the user id and it is too much to expect an end user to fire up the Active Directory Users and Groups MMC snap-in. Input would be something like "MYCORP\a\_...
Here's the code I use, taken from my authentication class: ``` string[] strUserName = username.Split("\\".ToCharArray()); using (var entry = new DirectoryEntry("LDAP://" + ADServer, ADServiceDomain + "\\" + ADServiceAccount, ADServicePassword)) using (var ds = new DirectorySearcher(entry, "sAMAccountName=" + strUserNa...
407,320
<p>I have a problem that seems like its a result of a deadlock-situation. Whe are now searching for the root of the problem but meantime we wanted to restart the server and get the customer going.</p> <p>And now everytime we start the program it just says "SqlConnection does not support parallel transactions". We hav...
[ { "answer_id": 407344, "author": "duffymo", "author_id": 37213, "author_profile": "https://Stackoverflow.com/users/37213", "pm_score": 2, "selected": false, "text": "<p>Yours doesn't appear to be an unusual problem. Google found a lot of hits when I pasted your error string into the que...
2009/01/02
[ "https://Stackoverflow.com/questions/407320", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19307/" ]
I have a problem that seems like its a result of a deadlock-situation. Whe are now searching for the root of the problem but meantime we wanted to restart the server and get the customer going. And now everytime we start the program it just says "SqlConnection does not support parallel transactions". We have not chan...
It seems to be that you are sharing connections and creating new transactions on the same open connection (this is the parallel part of the exception you are seeing). Your example seems to support this as you have no mention of how you acquire the connection in it. You should do a review of your code and make sure th...
407,337
<p>This is really stumping me today. I'm sure its not that hard, but I have a System.Reflection.PropertyInfo object. I want to set its value based on the result of a database lookup (think ORM, mapping a column back to a property).</p> <p>My problem is if the DB returned value is DBNull, I just want to set the proper...
[ { "answer_id": 407345, "author": "Darin Dimitrov", "author_id": 29407, "author_profile": "https://Stackoverflow.com/users/29407", "pm_score": 6, "selected": false, "text": "<pre><code>object defaultValue = type.IsValueType ? Activator.CreateInstance(type) : null;\n</code></pre>\n" }, ...
2009/01/02
[ "https://Stackoverflow.com/questions/407337", "https://Stackoverflow.com", "https://Stackoverflow.com/users/28278/" ]
This is really stumping me today. I'm sure its not that hard, but I have a System.Reflection.PropertyInfo object. I want to set its value based on the result of a database lookup (think ORM, mapping a column back to a property). My problem is if the DB returned value is DBNull, I just want to set the property value to...
I believe if you just do ``` prop.SetValue(obj,null,null); ``` If it's a valuetype, it'll set it to the default value, if it's a reference type, it'll set it to null.
407,362
<p>A beginner's question. </p> <p>I'm building a .swf with Flex Ant.</p> <p>To my .swf I link a file, <code>target.as</code>, which I generate from file <code>source.txt</code> with command </p> <pre><code>./tool.sh source.txt &gt; target.as </code></pre> <p>How can I add what is described in the above sentence to ...
[ { "answer_id": 407406, "author": "Adam Peck", "author_id": 26658, "author_profile": "https://Stackoverflow.com/users/26658", "pm_score": 2, "selected": false, "text": "<p>To run that command in Ant use the <a href=\"http://ant.apache.org/manual/Tasks/exec.html\" rel=\"nofollow noreferrer...
2009/01/02
[ "https://Stackoverflow.com/questions/407362", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6236/" ]
A beginner's question. I'm building a .swf with Flex Ant. To my .swf I link a file, `target.as`, which I generate from file `source.txt` with command ``` ./tool.sh source.txt > target.as ``` How can I add what is described in the above sentence to my ant build process?
[The exec task](http://ant.apache.org/manual/Tasks/exec.html) executes any external program: ``` <exec executable="${basedir}/tool.sh" dir="${basedir}" output="target.as"> <arg path="source.txt"/> </exec> ``` So if you use the mxmlc ant task to compile your swf, you can define your build task like this: ``` <ta...
407,367
<p>I have a couple of inline SQL in many of our reports on the report manager. Now I need to do some code change for all of them, is there a way to list all those reports based on the inline SQL and not any SP?</p> <p>Thanks,<br /> D</p>
[ { "answer_id": 407406, "author": "Adam Peck", "author_id": 26658, "author_profile": "https://Stackoverflow.com/users/26658", "pm_score": 2, "selected": false, "text": "<p>To run that command in Ant use the <a href=\"http://ant.apache.org/manual/Tasks/exec.html\" rel=\"nofollow noreferrer...
2009/01/02
[ "https://Stackoverflow.com/questions/407367", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I have a couple of inline SQL in many of our reports on the report manager. Now I need to do some code change for all of them, is there a way to list all those reports based on the inline SQL and not any SP? Thanks, D
[The exec task](http://ant.apache.org/manual/Tasks/exec.html) executes any external program: ``` <exec executable="${basedir}/tool.sh" dir="${basedir}" output="target.as"> <arg path="source.txt"/> </exec> ``` So if you use the mxmlc ant task to compile your swf, you can define your build task like this: ``` <ta...
407,370
<p>I recently participated a project that replaced a mainframe system with a web (asp.net 2.0, VS2005) system.<br/> The 3270-terminals are still much used and I respect the IMS/CICS/Cobol application designers for their work.<br/></p> <p>Users like the web application, but one thing they keep ask for is:<br/> Function...
[ { "answer_id": 407403, "author": "John Sheehan", "author_id": 1786, "author_profile": "https://Stackoverflow.com/users/1786", "pm_score": 3, "selected": true, "text": "<p>There is nothing specific to ASP.NET for this since you would need to handle it with JavaScript. The easiest way woul...
2009/01/02
[ "https://Stackoverflow.com/questions/407370", "https://Stackoverflow.com", "https://Stackoverflow.com/users/49544/" ]
I recently participated a project that replaced a mainframe system with a web (asp.net 2.0, VS2005) system. The 3270-terminals are still much used and I respect the IMS/CICS/Cobol application designers for their work. Users like the web application, but one thing they keep ask for is: Functionkeys and shortcut...
There is nothing specific to ASP.NET for this since you would need to handle it with JavaScript. The easiest way would be to use a jQuery plugin like [js-hotkeys](http://jshotkeys.googlepages.com/)
407,407
<p>What's the best way to read a fixed length record in Perl. I know to read a file like:</p> <pre><code>ABCDE 302 DEFGC 876 </code></pre> <p>I can do</p> <pre><code>while (&lt;FILE&gt;) { $key = substr($_, 0, 5); $value = substr($_, 7, 3); } </code></pre> <p>but isn't there a way to do this with read/unpack...
[ { "answer_id": 407422, "author": "Jonathan Leffler", "author_id": 15168, "author_profile": "https://Stackoverflow.com/users/15168", "pm_score": 4, "selected": false, "text": "<pre><code>my($key, $value) = unpack \"A5 A3\"; # Original, but slightly dubious\n</code></pre>\n\n<p>We both ...
2009/01/02
[ "https://Stackoverflow.com/questions/407407", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14167/" ]
What's the best way to read a fixed length record in Perl. I know to read a file like: ``` ABCDE 302 DEFGC 876 ``` I can do ``` while (<FILE>) { $key = substr($_, 0, 5); $value = substr($_, 7, 3); } ``` but isn't there a way to do this with read/unpack?
Update: For the definitive answer, see Jonathan Leffler's answer below. I wouldn't use this for just two fields (I'd use [pack](http://perldoc.perl.org/functions/pack.html)/[unpack](http://perldoc.perl.org/functions/unpack.html) directly), but for 20 or 50 or so fields I like to use [Parse::FixedLength](http://search....
407,420
<p>I understand that the goal of moving towards <code>&lt;div&gt;</code> tags from <code>&lt;table&gt;</code> makes sense since it is more semantic. However, I don't understand the benefit gained if you still need a clearing block to make column-based layouts work. For example:</p> <pre><code>&lt;!-- Note: location-in...
[ { "answer_id": 407421, "author": "annakata", "author_id": 13018, "author_profile": "https://Stackoverflow.com/users/13018", "pm_score": 6, "selected": true, "text": "<p>What if I told you <a href=\"http://www.sitepoint.com/simple-clearing-of-floats/\" rel=\"nofollow noreferrer\">you</a> ...
2009/01/02
[ "https://Stackoverflow.com/questions/407420", "https://Stackoverflow.com", "https://Stackoverflow.com/users/26/" ]
I understand that the goal of moving towards `<div>` tags from `<table>` makes sense since it is more semantic. However, I don't understand the benefit gained if you still need a clearing block to make column-based layouts work. For example: ``` <!-- Note: location-info & personal-info both float left. --> <div class=...
What if I told you [you](http://www.sitepoint.com/simple-clearing-of-floats/) [didn't](http://www.innovatingtomorrow.net/2008/03/24/how-clear-floats-css) [need](http://www.positioniseverything.net/easyclearing.html) a clearing block? ```css .clear-block:after { content: "."; display: block; height: 0; ...
407,428
<p>I'm trying to bind an ASP.net DropDownList to the results of an entity framework query, while still maintaining multi-tier separation. (i.e. I don't want my UI code to contain query details, nor my Data Layer code to have UI dependencies.) My code-behind in the Page_Load event handler looks like this:</p> <pre><c...
[ { "answer_id": 407441, "author": "M4N", "author_id": 19635, "author_profile": "https://Stackoverflow.com/users/19635", "pm_score": 3, "selected": true, "text": "<p>Don't you have to detach the objects from the context? E.g:</p>\n\n<pre><code>IEnumerable&lt;Lookup&gt; l = (from c in conte...
2009/01/02
[ "https://Stackoverflow.com/questions/407428", "https://Stackoverflow.com", "https://Stackoverflow.com/users/46731/" ]
I'm trying to bind an ASP.net DropDownList to the results of an entity framework query, while still maintaining multi-tier separation. (i.e. I don't want my UI code to contain query details, nor my Data Layer code to have UI dependencies.) My code-behind in the Page\_Load event handler looks like this: ``` IEn...
Don't you have to detach the objects from the context? E.g: ``` IEnumerable<Lookup> l = (from c in context.Lookup where c.LookupTypeID == LookupTypeID select c); foreach (Lookup lookup in l) context.Detach(lookup); return l; ```
407,460
<p>Can someone illustrate (or point me to a good tutorial) on how to add a Date Picker to a view programmatically (i.e., without using the interface editor)? </p>
[ { "answer_id": 407480, "author": "Marc Charbonneau", "author_id": 35136, "author_profile": "https://Stackoverflow.com/users/35136", "pm_score": 2, "selected": false, "text": "<p>Create it as you would a normal object, using UIView's <code>initWithFrame</code> method. Keep in mind that fr...
2009/01/02
[ "https://Stackoverflow.com/questions/407460", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
Can someone illustrate (or point me to a good tutorial) on how to add a Date Picker to a view programmatically (i.e., without using the interface editor)?
It's very easy man.You can do it in seconds. Just use the these methods in your.m file...all is ready ``` - (void)viewDidLoad { CGRect pickerFrame = CGRectMake(0,250,0,0); UIDatePicker *myPicker = [[UIDatePicker alloc] initWithFrame:pickerFrame]; [myPicker addTarget:self action:@selector(pickerChanged:)...
407,467
<p>When WSDL importer wizard generates the interfaces, all properties have the Index option, but reading the code and the InvokeRegistry unit, I can't found what is that for, anyone know if it is really necessary?</p> <p>Like this</p> <pre><code> Login = class(TRemotable) private [...] published propert...
[ { "answer_id": 408636, "author": "Wouter van Nifterick", "author_id": 38813, "author_profile": "https://Stackoverflow.com/users/38813", "pm_score": 2, "selected": false, "text": "<p>IS_OPTN is passed to GetUser and SetUser via the 'Index' parameter when you access the user property.</p>\...
2009/01/02
[ "https://Stackoverflow.com/questions/407467", "https://Stackoverflow.com", "https://Stackoverflow.com/users/36875/" ]
When WSDL importer wizard generates the interfaces, all properties have the Index option, but reading the code and the InvokeRegistry unit, I can't found what is that for, anyone know if it is really necessary? Like this ``` Login = class(TRemotable) private [...] published property User: string Index ...
I found a more detailed explanation for this question, **When using Indexes, several properties can share the same access methods.** A good example, from Delphi 2009 Help: ``` type TRectangle = class private FCoordinates: array[0..3] of Longint; function GetCoordinate(Index: Integer): Longi...
407,468
<p>I'm currently trying to initiate a file upload with urllib2 and the <a href="http://fabien.seisen.org/python/urllib2_multipart.html" rel="nofollow noreferrer">urllib2_file</a> library. Here's my code:</p> <pre><code>import sys import urllib2_file import urllib2 URL='http://aquate.us/upload.php' d = [('uploaded', o...
[ { "answer_id": 407545, "author": "Ben Blank", "author_id": 46387, "author_profile": "https://Stackoverflow.com/users/46387", "pm_score": 2, "selected": false, "text": "<p>If you're using Python 2.5 or newer, <code>urllib2_file</code> is both unnecessary and unsupported, so check which ve...
2009/01/02
[ "https://Stackoverflow.com/questions/407468", "https://Stackoverflow.com", "https://Stackoverflow.com/users/50548/" ]
I'm currently trying to initiate a file upload with urllib2 and the [urllib2\_file](http://fabien.seisen.org/python/urllib2_multipart.html) library. Here's my code: ``` import sys import urllib2_file import urllib2 URL='http://aquate.us/upload.php' d = [('uploaded', open(sys.argv[1:]))] req = urllib2.Request(URL, d) ...
If you're using Python 2.5 or newer, `urllib2_file` is both unnecessary and unsupported, so check which version you're using (and perhaps upgrade). If you're using Python 2.3 or 2.4 (the only versions supported by `urllib2_file`), try running [the sample code](http://fabien.seisen.org/python/test.py) and see if you ha...
407,491
<p>Take the example classes below. I want to display the customer and two addresses (from a LIST) on a form. Does the model binder in MVC beta support this or will I have to write my own custom binder? </p> <pre><code>public class Customer { public string FirstName { get; set; } public string LastName { get; ...
[ { "answer_id": 407509, "author": "Filip Ekberg", "author_id": 39106, "author_profile": "https://Stackoverflow.com/users/39106", "pm_score": 0, "selected": false, "text": "<p>You can pass an object list with ViewData like that, but you need to change some of the lines. Read more here:</p>...
2009/01/02
[ "https://Stackoverflow.com/questions/407491", "https://Stackoverflow.com", "https://Stackoverflow.com/users/50964/" ]
Take the example classes below. I want to display the customer and two addresses (from a LIST) on a form. Does the model binder in MVC beta support this or will I have to write my own custom binder? ``` public class Customer { public string FirstName { get; set; } public string LastName { get; set; } publ...
I've never tried it, but see [this](http://haacked.com/archive/2008/10/23/model-binding-to-a-list.aspx) post, it's about model binding to a list, maybe it can help you.
407,492
<p>I have a DAO implementation that uses a HibernateTransactionManager for transaction management and the application has 2 session factories. I am getting an exception at the transactionManager.commit() line below. <strong>Does performing Hibernate operations within a transaction manager related to a different session...
[ { "answer_id": 407502, "author": "duffymo", "author_id": 37213, "author_profile": "https://Stackoverflow.com/users/37213", "pm_score": 2, "selected": false, "text": "<p>Are you using XA drivers to connect to the two data sources involved in the transaction? Can't work otherwise.</p>\n" ...
2009/01/02
[ "https://Stackoverflow.com/questions/407492", "https://Stackoverflow.com", "https://Stackoverflow.com/users/23133/" ]
I have a DAO implementation that uses a HibernateTransactionManager for transaction management and the application has 2 session factories. I am getting an exception at the transactionManager.commit() line below. **Does performing Hibernate operations within a transaction manager related to a different session factory ...
Are you using XA drivers to connect to the two data sources involved in the transaction? Can't work otherwise.
407,518
<p>I recently posted <a href="https://stackoverflow.com/questions/406760/whats-your-most-controversial-programming-opinion#406948">one of my favourite interview whiteboard coding questions</a> in "<a href="https://stackoverflow.com/questions/406760/whats-your-most-controversial-programming-opinion">What's your more con...
[ { "answer_id": 407530, "author": "Greg Beech", "author_id": 13552, "author_profile": "https://Stackoverflow.com/users/13552", "pm_score": 2, "selected": false, "text": "<p>Here's a recursive answer using C#. It will only work using the x64 JIT in Release mode because that's the only JIT ...
2009/01/02
[ "https://Stackoverflow.com/questions/407518", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13552/" ]
I recently posted [one of my favourite interview whiteboard coding questions](https://stackoverflow.com/questions/406760/whats-your-most-controversial-programming-opinion#406948) in "[What's your more controversial programming opinion](https://stackoverflow.com/questions/406760/whats-your-most-controversial-programming...
**J, 14 chars** ``` 4*-/%>:+:i.1e6 ``` --- *Explanation* * `1e6` is number 1 followed by 6 zeroes (1000000). * `i.y` generates the first `y` non negative numbers. * `+:` is a function that doubles each element in the list argument. * `>:` is a function that increments by one each element in the list argument. So,...
407,523
<p>In my bash script I have an external (received from user) string, which I should use in sed pattern.</p> <pre><code>REPLACE="&lt;funny characters here&gt;" sed "s/KEYWORD/$REPLACE/g" </code></pre> <p>How can I escape the <code>$REPLACE</code> string so it would be safely accepted by <code>sed</code> as a literal r...
[ { "answer_id": 407563, "author": "Alex", "author_id": 30181, "author_profile": "https://Stackoverflow.com/users/30181", "pm_score": 0, "selected": false, "text": "<p>Here is an example of an AWK I used a while ago. It is an AWK that prints new AWKS. AWK and SED being similar it may be ...
2009/01/02
[ "https://Stackoverflow.com/questions/407523", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6236/" ]
In my bash script I have an external (received from user) string, which I should use in sed pattern. ``` REPLACE="<funny characters here>" sed "s/KEYWORD/$REPLACE/g" ``` How can I escape the `$REPLACE` string so it would be safely accepted by `sed` as a literal replacement? **NOTE:** The `KEYWORD` is a dumb substri...
**Warning**: This does *not* consider newlines. For a more in-depth answer, see [this SO-question](https://stackoverflow.com/questions/29613304/is-it-possible-to-escape-regex-metacharacters-reliably-with-sed "Is it possible to escape regex metacharacters reliably with sed") instead. (Thanks, [Ed Morton](https://stackov...
407,536
<h1>Question</h1> <p>Hello All,</p> <p>A little background on my issue... I currently have a site built for the ISP I work for that displays messages to users based on their billing status. When they are in Non-Pay I display a Non-Pay message and if they are in Abuse, I display an abuse message, etc. The traffic i...
[ { "answer_id": 407565, "author": "casperOne", "author_id": 50776, "author_profile": "https://Stackoverflow.com/users/50776", "pm_score": 2, "selected": false, "text": "<p>Well, you have to remember that the DataSet is going to be in memory, and to search over the DataSet, it's going to t...
2009/01/02
[ "https://Stackoverflow.com/questions/407536", "https://Stackoverflow.com", "https://Stackoverflow.com/users/23869/" ]
Question ======== Hello All, A little background on my issue... I currently have a site built for the ISP I work for that displays messages to users based on their billing status. When they are in Non-Pay I display a Non-Pay message and if they are in Abuse, I display an abuse message, etc. The traffic is generated b...
There are a couple things that I'd try: * The first thing I see is that you're calling the "DeleteOldEntries" sub every time this code is run, which causes it to do a scan through the entire DataTable on every pass. Is there another way you could limit this to only run at certain times? If not a timer that runs it eve...
407,550
<p>I have a PHP application that makes extensive use of Javascript on the client side. I have a simple system on the PHP side for providing translators an easy way to provide new languages. But there are cases where javascript needs to display language elements to the user (maybe an OK or cancel button or "loading" o...
[ { "answer_id": 407568, "author": "Pim Jager", "author_id": 35197, "author_profile": "https://Stackoverflow.com/users/35197", "pm_score": 5, "selected": true, "text": "<p>How about feeding the javascript from php? So instead of heaving:</p>\n\n<pre><code> &lt;script type='text/javascript...
2009/01/02
[ "https://Stackoverflow.com/questions/407550", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2494/" ]
I have a PHP application that makes extensive use of Javascript on the client side. I have a simple system on the PHP side for providing translators an easy way to provide new languages. But there are cases where javascript needs to display language elements to the user (maybe an OK or cancel button or "loading" or som...
How about feeding the javascript from php? So instead of heaving: ``` <script type='text/javascript' src='jsscript.js'></script> ``` do ``` <script type='text/javascript' src='jsscript.php'></script> ``` And then in the php file replace all outputted text with their associated constants. Be sure to output the...
407,579
<p>HI i did this code with help of Marc Gravell in </p> <p><a href="https://stackoverflow.com/questions/406791/">Why can&#39;t I find _left and _right in BinarySearchTree?</a><br> &amp;<br> <a href="https://stackoverflow.com/questions/406402/bst-c-code-with-errors">How do I correct an implicit conversion error in BST ...
[ { "answer_id": 407606, "author": "R. Martinho Fernandes", "author_id": 46642, "author_profile": "https://Stackoverflow.com/users/46642", "pm_score": 3, "selected": true, "text": "<p>If what you mean in <code>CountNodes</code> is to count all non-leaf nodes you must change this line:</p>\...
2009/01/02
[ "https://Stackoverflow.com/questions/407579", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
HI i did this code with help of Marc Gravell in [Why can't I find \_left and \_right in BinarySearchTree?](https://stackoverflow.com/questions/406791/) & [How do I correct an implicit conversion error in BST C# Code?](https://stackoverflow.com/questions/406402/bst-c-code-with-errors) , its Binary search tree ,...
If what you mean in `CountNodes` is to count all non-leaf nodes you must change this line: ``` int count=1; ``` to read this: ``` int count = (root._left == null && root._right == null) ? 0 : 1; ``` (the opposite of what is in `CountLeaves`). And this will get you the height of the tree: ``` public int Height(T...
407,586
<p>Can someone tell me what the code equivelant in VB.Net to this C# code is?</p> <pre><code>new {name="value"} </code></pre>
[ { "answer_id": 407591, "author": "Pervez Choudhury", "author_id": 41673, "author_profile": "https://Stackoverflow.com/users/41673", "pm_score": 0, "selected": false, "text": "<p>That feature is called an anonymous type.</p>\n" }, { "answer_id": 407594, "author": "BFree", ...
2009/01/02
[ "https://Stackoverflow.com/questions/407586", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13502/" ]
Can someone tell me what the code equivelant in VB.Net to this C# code is? ``` new {name="value"} ```
This is called Anonymous Types and the VB equivalent is : ``` New With {.Name = "value"} ```
407,587
<p>Few blob's have been duplicated in my database(oracle 11g), performed XOR operations on the blob using UTL_RAW.BIT_XOR. After that i wanted to count the number of set bits in the binary string, so wrote the code above.</p> <p>During a small experiment, i wanted to see what is the hex and the integer value produced...
[ { "answer_id": 407619, "author": "Alex", "author_id": 30181, "author_profile": "https://Stackoverflow.com/users/30181", "pm_score": 2, "selected": false, "text": "<p>What version of Python are you using?\nFirst off, Python uses white space not semicolon's, so to start it should look some...
2009/01/02
[ "https://Stackoverflow.com/questions/407587", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1636/" ]
Few blob's have been duplicated in my database(oracle 11g), performed XOR operations on the blob using UTL\_RAW.BIT\_XOR. After that i wanted to count the number of set bits in the binary string, so wrote the code above. During a small experiment, i wanted to see what is the hex and the integer value produced and wrot...
In Python 3.10+, there is [`int.bit_count()`](https://docs.python.org/3/library/stdtypes.html#int.bit_count): ``` >>> 123 .bit_count() 6 ``` Python 2.6 or 3.0: ``` def bitsoncount(x): return bin(x).count('1') ``` Example: ``` >>> x = 123 >>> bin(x) '0b1111011' >>> bitsoncount(x) 6 ``` Or [Matt Howells's ...
407,596
<p>Let's say I have the following jQuery AJAX call:</p> <pre><code>$.ajax({ type: "POST", url: "MyUrl", data: "val1=test", success: function(result){ // Do stuff } }); </code></pre> <p>Now, when this AJAX call is made I want the server-side code to run through a few error handling checks (e.g....
[ { "answer_id": 407608, "author": "rodbv", "author_id": 79101, "author_profile": "https://Stackoverflow.com/users/79101", "pm_score": 2, "selected": false, "text": "<p>Doesn't the jQuery ajax function accept one more parameter at the end, a callback for failed calls? If so, just add a <co...
2009/01/02
[ "https://Stackoverflow.com/questions/407596", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1574/" ]
Let's say I have the following jQuery AJAX call: ``` $.ajax({ type: "POST", url: "MyUrl", data: "val1=test", success: function(result){ // Do stuff } }); ``` Now, when this AJAX call is made I want the server-side code to run through a few error handling checks (e.g. is the user still logged ...
Personally, I have similar code to the following code in my library. ``` $.ajaxSetup({ error: function(xhr){ alert('Request Status: ' + xhr.status + ' Status Text: ' + xhr.statusText + ' ' + xhr.responseText); } }); ``` [jQuery docs Ajax/jQuery.ajaxSetup](http://docs.jquery.com/Ajax/jQuery.ajaxSetup#...
407,612
<p>I have a Java application that I run from a console which in turn executes an another Java process. I want to get a thread/heap dump of that child process.</p> <p>On Unix, I could do a <code>kill -3 &lt;pid&gt;</code> but on Windows AFAIK the only way to get a thread dump is Ctrl-Break in the console. But that only...
[ { "answer_id": 407625, "author": "krosenvold", "author_id": 23691, "author_profile": "https://Stackoverflow.com/users/23691", "pm_score": 3, "selected": false, "text": "<p>You can send the <code>kill -3 &lt;pid&gt;</code> from Cygwin. You have to use the Cygwin <code>ps</code> options to...
2009/01/02
[ "https://Stackoverflow.com/questions/407612", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I have a Java application that I run from a console which in turn executes an another Java process. I want to get a thread/heap dump of that child process. On Unix, I could do a `kill -3 <pid>` but on Windows AFAIK the only way to get a thread dump is Ctrl-Break in the console. But that only gives me the dump of the p...
You can use `jmap` to get a dump of any process running, assuming you know the `pid`. Use Task Manager or Resource Monitor to get the `pid`. Then ``` jmap -dump:format=b,file=heap.hprof <pid> ``` to get the heap for that process. For systems where `bash` and `pgrep` are installed and a single Java process is runni...
407,646
<p>Suppose I've got a table:</p> <pre><code>Role ---- person_id company_id financial_year </code></pre> <p>How can I tell the following:</p> <ol> <li>Whether each person_id occurs at most once per company_id per financial_year in this table</li> <li>If 1. is false, which person_id's and company_id's and financial_ye...
[ { "answer_id": 407660, "author": "Harper Shelby", "author_id": 21196, "author_profile": "https://Stackoverflow.com/users/21196", "pm_score": 0, "selected": false, "text": "<p>This should do what you need: </p>\n\n<pre><code>select left.person_id, left.company_id, left.financial_year, ...
2009/01/02
[ "https://Stackoverflow.com/questions/407646", "https://Stackoverflow.com", "https://Stackoverflow.com/users/41613/" ]
Suppose I've got a table: ``` Role ---- person_id company_id financial_year ``` How can I tell the following: 1. Whether each person\_id occurs at most once per company\_id per financial\_year in this table 2. If 1. is false, which person\_id's and company\_id's and financial\_year's co-occur more than once Edit 1...
For the first, it's generally a good idea to just have a grouping which you can then filter on if you want: ``` select r.company_id, r.person_id, r.financial_year, count(r.person_id) from Role as r group by r.company_id, r.person_id, r.financial_year ``` For the second, you can just modify the above like so:...
407,651
<p>This is related to my question on <a href="https://stackoverflow.com/questions/407596/how-do-you-handle-errors-from-ajax-calls">how to handle errors from jQuery AJAX calls</a>. Several responses suggested that I use the "error" callback to display any errors from a jQuery AJAX call. I was wondering how to do that ...
[ { "answer_id": 407665, "author": "John Sheehan", "author_id": 1786, "author_profile": "https://Stackoverflow.com/users/1786", "pm_score": 1, "selected": false, "text": "<p>I think that event is raised for any response that has a response code other than 200. I can't find proof of this in...
2009/01/02
[ "https://Stackoverflow.com/questions/407651", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1574/" ]
This is related to my question on [how to handle errors from jQuery AJAX calls](https://stackoverflow.com/questions/407596/how-do-you-handle-errors-from-ajax-calls). Several responses suggested that I use the "error" callback to display any errors from a jQuery AJAX call. I was wondering how to do that using ASP.NET MV...
NOTE: Hey, this was posted before ASP.Net MVC even hit 1.0, and I haven't even looked at the framework since then. You should probably stop upvoting this. --- Do something like this: ``` Response.StatusCode = (int)HttpStatusCode.BadRequest; actionResult = this.Content("Error message here"); ``` The status code sho...
407,658
<p>Situation: I entered several functions while working with REPL in Emacs. Problem: There is junk like "; Evaluation aborted" when I'm simply saving buffer. What I want: clear descriptions of all the functions I entered in their latest revision.</p> <p>Can I do that? Thanks.</p>
[ { "answer_id": 407696, "author": "fizzer", "author_id": 18167, "author_profile": "https://Stackoverflow.com/users/18167", "pm_score": 3, "selected": false, "text": "<p>I don't get it. Are you entering definitions at the REPL and expecting to recover them later? Just save a source file ...
2009/01/02
[ "https://Stackoverflow.com/questions/407658", "https://Stackoverflow.com", "https://Stackoverflow.com/users/47937/" ]
Situation: I entered several functions while working with REPL in Emacs. Problem: There is junk like "; Evaluation aborted" when I'm simply saving buffer. What I want: clear descriptions of all the functions I entered in their latest revision. Can I do that? Thanks.
I agree that the best work flow method is to write your code in a separate buffer and evaluate in that, rather than enter the functions in the repl. Assuming you have gone the repl way, I guess, C. Martin's solution to save the repl log and manually go through it are your only options. If you entered the functions an...
407,688
<p>I'm giving <a href="http://db.apache.org/derby/" rel="noreferrer">Apache Derby</a>, aka <a href="http://developers.sun.com/javadb/" rel="noreferrer">JavaDB</a> a spin. I can't seem to get around duplicate key issues when inserting records that may already exist. Is there a Derby equivalent to "<code>insert if not ...
[ { "answer_id": 430929, "author": "Snukker", "author_id": 44721, "author_profile": "https://Stackoverflow.com/users/44721", "pm_score": 4, "selected": false, "text": "<p>I've never used apache derby, but a general solution that is fairly database independent is as follows:</p>\n\n<p>To in...
2009/01/02
[ "https://Stackoverflow.com/questions/407688", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1274957/" ]
I'm giving [Apache Derby](http://db.apache.org/derby/), aka [JavaDB](http://developers.sun.com/javadb/) a spin. I can't seem to get around duplicate key issues when inserting records that may already exist. Is there a Derby equivalent to "`insert if not exists`", or "`merge`" ? Similarly, is there a way to do somethi...
I've never used apache derby, but a general solution that is fairly database independent is as follows: To insert the values 'a' and 'b' into table foo (with columns named A, B), but only where the values are not already there, try something like ``` INSERT INTO foo ( SELECT 'a' as A, 'b' as B FROM foo WHER...
407,712
<p>I am using the Entity framework to create a new order. The order contains a collection of contacts, a many to many relationship. I want to add a reference to an existing contact on the order on creation of the order. Both Order and Contact a Entity Objects.</p> <pre><code> Order order = new Order(); //set deta...
[ { "answer_id": 413516, "author": "Craig Stuntz", "author_id": 7714, "author_profile": "https://Stackoverflow.com/users/7714", "pm_score": 2, "selected": false, "text": "<p>If Order has a property Contact, then you can do:</p>\n\n<pre><code>order.Contact.Add(contact);\n</code></pre>\n\n<p...
2009/01/02
[ "https://Stackoverflow.com/questions/407712", "https://Stackoverflow.com", "https://Stackoverflow.com/users/46400/" ]
I am using the Entity framework to create a new order. The order contains a collection of contacts, a many to many relationship. I want to add a reference to an existing contact on the order on creation of the order. Both Order and Contact a Entity Objects. ``` Order order = new Order(); //set details on order Co...
"Attach" is not allowed because you haven't saved the order yet. Calling "Add" tells Entity Framework that you want to insert a new contact. So you are left with only one option. You need to load the contact. Here's the fastest way to do that: ``` OrderDetails context = new OrderDetails(); Contact contact = context.G...
407,720
<p>I'm using LINQ to SQL to update my database. I'm inserting a lot of records, and when I call SubmitChanges(), LINQ to SQL executes an insert and a select statement for each object. I don't really care to update my objects after they are inserted into the database.</p> <p>Do you know I can prevent LINQ to SQL from...
[ { "answer_id": 407760, "author": "leppie", "author_id": 15541, "author_profile": "https://Stackoverflow.com/users/15541", "pm_score": 0, "selected": false, "text": "<p>I cant recall the setting now, but in the designer, on a column's properties, you have some 'refresh' setting(s).</p>\n"...
2009/01/02
[ "https://Stackoverflow.com/questions/407720", "https://Stackoverflow.com", "https://Stackoverflow.com/users/571/" ]
I'm using LINQ to SQL to update my database. I'm inserting a lot of records, and when I call SubmitChanges(), LINQ to SQL executes an insert and a select statement for each object. I don't really care to update my objects after they are inserted into the database. Do you know I can prevent LINQ to SQL from issuing the...
You're looking for [ColumnAttribute.AutoSync](http://msdn.microsoft.com/en-us/library/system.data.linq.mapping.columnattribute.autosync.aspx). If you're using the designer, check each column for an Auto-Sync property and set it to Never. **Edit:** Ok, that didn't work for you. Brace yourself for some mapping hackery! ...
407,729
<p>Given two sets of values:</p> <pre><code>var subset = new[] { 2, 4, 6, 8 }; var superset = new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; </code></pre> <p>how do I determine if <code>superset</code> contains all elements of <code>subset</code>?</p> <p>I have come up with this:</p> <pre><code>superset.Intersect(subset)...
[ { "answer_id": 407741, "author": "leppie", "author_id": 15541, "author_profile": "https://Stackoverflow.com/users/15541", "pm_score": 2, "selected": false, "text": "<p>You could use Except and the resulting count should be 0.</p>\n\n<p>Read up on MSDN for details of the parameters.</p>\n...
2009/01/02
[ "https://Stackoverflow.com/questions/407729", "https://Stackoverflow.com", "https://Stackoverflow.com/users/37815/" ]
Given two sets of values: ``` var subset = new[] { 2, 4, 6, 8 }; var superset = new[] { 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 }; ``` how do I determine if `superset` contains all elements of `subset`? I have come up with this: ``` superset.Intersect(subset).Count() == subset.Count() ``` Is this the most logical and effi...
Count? How about Not Any? ``` bool contained = !subset.Except(superset).Any(); ```
407,731
<p>The problem statement:</p> <p>Given a set of integers that is known in advance, <strong>generate</strong> code to test if a single integer is in the set. The domain of the testing function is the integers in some consecutive range.</p> <hr> <p>Nothing in particular is known now about the range or the set to be te...
[ { "answer_id": 407741, "author": "leppie", "author_id": 15541, "author_profile": "https://Stackoverflow.com/users/15541", "pm_score": 2, "selected": false, "text": "<p>You could use Except and the resulting count should be 0.</p>\n\n<p>Read up on MSDN for details of the parameters.</p>\n...
2009/01/02
[ "https://Stackoverflow.com/questions/407731", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1343/" ]
The problem statement: Given a set of integers that is known in advance, **generate** code to test if a single integer is in the set. The domain of the testing function is the integers in some consecutive range. --- Nothing in particular is known now about the range or the set to be tested. The range could be small ...
Count? How about Not Any? ``` bool contained = !subset.Except(superset).Any(); ```
407,737
<p>I'm trying to build a query with hibernate criteria for the following scenario:</p> <ul> <li>Two entities: Indicator and report (each with their own tables, classes etc.)</li> <li>an indicator can be used in zero to many reports</li> <li>a report uses zero to many indicators</li> <li>therefore, I have an intersecti...
[ { "answer_id": 407779, "author": "zmf", "author_id": 13285, "author_profile": "https://Stackoverflow.com/users/13285", "pm_score": 3, "selected": true, "text": "<pre><code> Criteria c = session.createCriteria(Indicator.class);\n c.add(Restrictions.eq(\"someField\", myObject).createCr...
2009/01/02
[ "https://Stackoverflow.com/questions/407737", "https://Stackoverflow.com", "https://Stackoverflow.com/users/25320/" ]
I'm trying to build a query with hibernate criteria for the following scenario: * Two entities: Indicator and report (each with their own tables, classes etc.) * an indicator can be used in zero to many reports * a report uses zero to many indicators * therefore, I have an intersection table to store the relationship ...
``` Criteria c = session.createCriteria(Indicator.class); c.add(Restrictions.eq("someField", myObject).createCriteria("reports") .add(Restrictions.eq("reportName", name); c.list(); ``` You need to create a sub criteria to the entity that is being held in a collection on some other entity. ``` String[] ...
407,763
<p>Backdrop: There are two forms, the main application form and a form to edit various settings for the operations of main application.</p> <p>What would be the proper way to show the frmSettings form and how to dispose it once clicked OK or Cancel in the actual frmSettings form?</p>
[ { "answer_id": 407785, "author": "Austin Salonen", "author_id": 4068, "author_profile": "https://Stackoverflow.com/users/4068", "pm_score": 0, "selected": false, "text": "<pre><code>using (frmSettings s = new frmSettings() )\n{\n if( s.ShowDialog() == DialogResult.OK )\n {\n //...
2009/01/02
[ "https://Stackoverflow.com/questions/407763", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
Backdrop: There are two forms, the main application form and a form to edit various settings for the operations of main application. What would be the proper way to show the frmSettings form and how to dispose it once clicked OK or Cancel in the actual frmSettings form?
Perhaps a Dialog would be better suited to your Settings "form." There are subtle differences between a dialog and a form that would make the dialog easier to handle. A return code indicating the button that was clicked makes dialogs useful. Supposing that you used a dialog - a using statement could be used (off the t...
407,770
<p>I have an application where I need the user to be able to update or delete rows of data from the database. The rows are displayed to the user using a foreach loop in the .aspx file of my view. Each row will have two text fields (txtName, txtDesc), an update button, and a delete button. What I'm not sure of, is ho...
[ { "answer_id": 408006, "author": "rodbv", "author_id": 79101, "author_profile": "https://Stackoverflow.com/users/79101", "pm_score": 5, "selected": true, "text": "<p>You can use multiple forms, and set the action on the form to be like this:</p>\n\n<pre><code>&lt;form method=\"post\" act...
2009/01/02
[ "https://Stackoverflow.com/questions/407770", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14101/" ]
I have an application where I need the user to be able to update or delete rows of data from the database. The rows are displayed to the user using a foreach loop in the .aspx file of my view. Each row will have two text fields (txtName, txtDesc), an update button, and a delete button. What I'm not sure of, is how do I...
You can use multiple forms, and set the action on the form to be like this: ``` <form method="post" action="/YourController/YourAction/<%=rowId%>"> ``` So you will have `YourController/YourAction/1`, `YourController/YourAction/2` and so on. There is no need to give different names to the different textboxes, just ...
407,855
<p>Hopefully a simple question. Take for instance a Circularly-linked list:</p> <pre><code>class ListContainer { private listContainer next; &lt;..&gt; public void setNext(listContainer next) { this.next = next; } } class List { private listContainer entry; &lt;..&gt; } </code></pre> <p>Now since ...
[ { "answer_id": 407864, "author": "Dave L.", "author_id": 3093, "author_profile": "https://Stackoverflow.com/users/3093", "pm_score": 2, "selected": false, "text": "<p>Java collects any objects that are not reachable. If nothing else has a reference to the entry, then it will be collecte...
2009/01/02
[ "https://Stackoverflow.com/questions/407855", "https://Stackoverflow.com", "https://Stackoverflow.com/users/35685/" ]
Hopefully a simple question. Take for instance a Circularly-linked list: ``` class ListContainer { private listContainer next; <..> public void setNext(listContainer next) { this.next = next; } } class List { private listContainer entry; <..> } ``` Now since it's a circularly-linked list, when a ...
Garbage collectors which rely solely on reference counting are generally vulnerable to failing to collection self-referential structures such as this. These GCs rely on a count of the number of references to the object in order to calculate whether a given object is reachable. Non-reference counting approaches apply a...
407,858
<p>I have a Flex 3 app (player v9) which loads a Flash SWF (AS3, also player v9) and needs to dynamically pass it a collection of parameters which are known at run-time. These are parameters that are normally passed via the <code>flashvars</code> element in an HTML page. The embedded movie accesses these parameters via...
[ { "answer_id": 408859, "author": "Theo", "author_id": 1109, "author_profile": "https://Stackoverflow.com/users/1109", "pm_score": 0, "selected": false, "text": "<p>When embedding a SWF on a web page you can pass flashvars as parameters on the URL to the SWF, perhaps the same could work i...
2009/01/02
[ "https://Stackoverflow.com/questions/407858", "https://Stackoverflow.com", "https://Stackoverflow.com/users/26829/" ]
I have a Flex 3 app (player v9) which loads a Flash SWF (AS3, also player v9) and needs to dynamically pass it a collection of parameters which are known at run-time. These are parameters that are normally passed via the `flashvars` element in an HTML page. The embedded movie accesses these parameters via the `loaderIn...
Passing this params in URL won't help, because they're taken using javascript code in the html-wrapper. The 'flashVars' params are taken using the Application.application.parameters, so, you have to set these params manually in your case. If you are using SWFLoader to load another app, you should create the object, th...
407,881
<p>I often want to define new 'Exception' classes, but need to have an appropriate constructor defined because constructors aren't inherited. </p> <pre><code>class MyException : public Exception { public: MyException (const UString Msg) : Exception(Msg) { }; } </code></pre> <p>Typedefs don't work for this, be...
[ { "answer_id": 407949, "author": "Judge Maygarden", "author_id": 1491, "author_profile": "https://Stackoverflow.com/users/1491", "pm_score": 1, "selected": false, "text": "<p>You could parameterize your template class with an integer:</p>\n\n<pre><code>#include &lt;iostream&gt;\n#include...
2009/01/02
[ "https://Stackoverflow.com/questions/407881", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1737/" ]
I often want to define new 'Exception' classes, but need to have an appropriate constructor defined because constructors aren't inherited. ``` class MyException : public Exception { public: MyException (const UString Msg) : Exception(Msg) { }; } ``` Typedefs don't work for this, because they are simply alia...
If you really want to have new classes derived from Exception, as opposed to having a template parameterized by a parameter, there is no way around writing your own constructor that just delegates the arguments without using a macro. C++0x will have the ability what you need by using something like ``` class MyExcepti...
407,904
<p>I have a constantly growing database of keywords. I need to parse incoming text inputs (articles, feeds etc) and find which keywords from the database are present in the text. The database of keywords is much larger than the text.</p> <p>Since the database is constantly growing (users add more and more keywords to...
[ { "answer_id": 407972, "author": "ʞɔıu", "author_id": 41613, "author_profile": "https://Stackoverflow.com/users/41613", "pm_score": 0, "selected": false, "text": "<p>I'm not 100% clear on what you're asking, but maybe what you're looking for is an <a href=\"http://developer.apple.com/doc...
2009/01/02
[ "https://Stackoverflow.com/questions/407904", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10585/" ]
I have a constantly growing database of keywords. I need to parse incoming text inputs (articles, feeds etc) and find which keywords from the database are present in the text. The database of keywords is much larger than the text. Since the database is constantly growing (users add more and more keywords to watch for)...
The classic way of searching a text stream for multiple keywords is the [Aho-Corasick finite automaton](http://en.wikipedia.org/wiki/Aho-Corasick_algorithm), which uses time linear in the text to be searched. You'll want minor adaptations to recognize strings only on word boundaries, or perhaps it would be simpler just...
407,929
<p>By default <a href="http://en.wikipedia.org/wiki/Eclipse_%28software%29" rel="noreferrer">Eclipse</a> indents with a hard tab character. How do I change it to spaces?</p>
[ { "answer_id": 407933, "author": "Brian Deacon", "author_id": 409, "author_profile": "https://Stackoverflow.com/users/409", "pm_score": 5, "selected": false, "text": "<p>From <a href=\"http://blog.dotkam.com/2007/03/21/changing-tabs-to-spaces-in-eclipse/\" rel=\"nofollow noreferrer\">cha...
2009/01/02
[ "https://Stackoverflow.com/questions/407929", "https://Stackoverflow.com", "https://Stackoverflow.com/users/409/" ]
By default [Eclipse](http://en.wikipedia.org/wiki/Eclipse_%28software%29) indents with a hard tab character. How do I change it to spaces?
### Java Editor 1. Click **Window** » **Preferences** 2. Expand **Java** » **Code Style** 3. Click **Formatter** 4. Click the **Edit** button 5. Click the **Indentation** tab 6. Under **General Settings**, set **Tab policy** to: `Spaces only` 7. Click **OK** ad nauseam to apply the changes. [***Note***: If necessary ...
407,947
<p>I have seen different ways to retrieve a string field from SQL. Is there a "right" way, and what are the differences</p> <pre><code> SqlDataReader rdr; 1. String field = (String) rdr["field"]; 2. String field = rdr["field"].ToString(); 3. String field = rdr["field"] As String; </code></pre> <p>Thanks!</p...
[ { "answer_id": 407955, "author": "Otávio Décio", "author_id": 48684, "author_profile": "https://Stackoverflow.com/users/48684", "pm_score": 2, "selected": false, "text": "<ol>\n<li>May cause an exception if the type is not string</li>\n<li>Is definitely wrong because that could raise an ...
2009/01/02
[ "https://Stackoverflow.com/questions/407947", "https://Stackoverflow.com", "https://Stackoverflow.com/users/37955/" ]
I have seen different ways to retrieve a string field from SQL. Is there a "right" way, and what are the differences ``` SqlDataReader rdr; 1. String field = (String) rdr["field"]; 2. String field = rdr["field"].ToString(); 3. String field = rdr["field"] As String; ``` Thanks!
You could also use: ``` int ordinal=rdr.GetOrdinal("stringField"); if (rdr.IsDBNull(ordinal)) { return string.Empty; //Or null or however you want to handle it } else { rdr.GetString(ordinal); } ``` Which if you look at the definition for SQlDataReader["field"] looks like: ``` public override object this...
407,956
<p>I never touch <code>routes.rb</code> beyond calling <code>map.root</code> to set a default route. I've always been content to use URLs of the form...</p> <pre><code>/controller/action/perhaps_an_id </code></pre> <p>and it works fine.</p> <p>Does this make me a bad person? Am I missing out on something totally awe...
[ { "answer_id": 407993, "author": "allesklar", "author_id": 19893, "author_profile": "https://Stackoverflow.com/users/19893", "pm_score": 3, "selected": false, "text": "<p>Not having switched to RESTful design does not make you a bad person and if you feel no need to change keep writing y...
2009/01/02
[ "https://Stackoverflow.com/questions/407956", "https://Stackoverflow.com", "https://Stackoverflow.com/users/42595/" ]
I never touch `routes.rb` beyond calling `map.root` to set a default route. I've always been content to use URLs of the form... ``` /controller/action/perhaps_an_id ``` and it works fine. Does this make me a bad person? Am I missing out on something totally awesome? What if I try to adopt RESTful design? Would tha...
If you generate your resources with the default scaffolding then it will even include the restful routing for you in routes.rb. If you're not using the scaffolding then the reason that it's working is because of the default routes at the bottom by default: ``` map.connect ':controller/:action/:id' map.connect...
407,964
<p>I need to play an MP3 in the background while generating animation. The audio drives the animation timeline so I have to track MS from the start of the file to keep things in sync. In VB6 I used the MMControl which raised an event at certain intervals and could count the frames from the beginning to always determi...
[ { "answer_id": 407993, "author": "allesklar", "author_id": 19893, "author_profile": "https://Stackoverflow.com/users/19893", "pm_score": 3, "selected": false, "text": "<p>Not having switched to RESTful design does not make you a bad person and if you feel no need to change keep writing y...
2009/01/02
[ "https://Stackoverflow.com/questions/407964", "https://Stackoverflow.com", "https://Stackoverflow.com/users/38349/" ]
I need to play an MP3 in the background while generating animation. The audio drives the animation timeline so I have to track MS from the start of the file to keep things in sync. In VB6 I used the MMControl which raised an event at certain intervals and could count the frames from the beginning to always determine my...
If you generate your resources with the default scaffolding then it will even include the restful routing for you in routes.rb. If you're not using the scaffolding then the reason that it's working is because of the default routes at the bottom by default: ``` map.connect ':controller/:action/:id' map.connect...
407,977
<p>If you have an elliptic curve in the form of:</p> <pre><code>y^2 = x^3 + a*x + b (mod p) </code></pre> <p>Is there a good program to calculate the number of points on this curve?</p> <p>I have read about Schoof's and Schoof-Elkies-Atkin (SEA) algorithm, but I'm looking for open source implementations. Does anyon...
[ { "answer_id": 408645, "author": "Bobby Moretti", "author_id": 51100, "author_profile": "https://Stackoverflow.com/users/51100", "pm_score": 2, "selected": false, "text": "<p>Have you heard of <a href=\"http://sagemath.org/\" rel=\"nofollow noreferrer\">Sage</a>?</p>\n\n<p>Sage includes ...
2009/01/02
[ "https://Stackoverflow.com/questions/407977", "https://Stackoverflow.com", "https://Stackoverflow.com/users/51011/" ]
If you have an elliptic curve in the form of: ``` y^2 = x^3 + a*x + b (mod p) ``` Is there a good program to calculate the number of points on this curve? I have read about Schoof's and Schoof-Elkies-Atkin (SEA) algorithm, but I'm looking for open source implementations. Does anyone know a good program that can do...
There are some links here: [Implementations of portions of the P1363 draft](http://grouper.ieee.org/groups/1363/P1363/implementations.html) (wayback [backup link](https://web.archive.org/web/20170114091037/http://grouper.ieee.org/groups/1363/P1363/implementations.html) of this page).
407,980
<p>I'd like to implement database caching functionality in PHP based on reference counts. For example, code to access the record in table <code>foo</code> with an ID of 1 might look like:</p> <pre><code>$fooRecord = $fooTable-&gt;getRecord(1); </code></pre> <p>The first time this is called, <code>$fooTable</code> fe...
[ { "answer_id": 407995, "author": "Mark Davidson", "author_id": 50866, "author_profile": "https://Stackoverflow.com/users/50866", "pm_score": 0, "selected": false, "text": "<p>It sounds to me like your wanting some <a href=\"http://en.wikipedia.org/wiki/Object-relational_mapping\" rel=\"n...
2009/01/02
[ "https://Stackoverflow.com/questions/407980", "https://Stackoverflow.com", "https://Stackoverflow.com/users/25213/" ]
I'd like to implement database caching functionality in PHP based on reference counts. For example, code to access the record in table `foo` with an ID of 1 might look like: ``` $fooRecord = $fooTable->getRecord(1); ``` The first time this is called, `$fooTable` fetches the appropriate record from the database, stor...
For php5, just make use of the destructor in the record class. ``` class Table { /* [...] */ protected $record_cache = array(); public function getRecord($id) { if(isset($this->record_cache[$id]) return $this->record_cache[$id]; $r = $db->getRecord($id); if($r instanceof Record) { ...
407,983
<p>I am wondering why the C# 3.0 compiler is unable to infer the type of a method when it is passed as a parameter to a generic function when it can implicitly create a delegate for the same method.</p> <p>Here is an example:</p> <pre><code>class Test { static void foo(int x) { } static void bar&lt;T&gt;(Acti...
[ { "answer_id": 408008, "author": "Amy B", "author_id": 8155, "author_profile": "https://Stackoverflow.com/users/8155", "pm_score": 5, "selected": true, "text": "<p>Maybe this will make it clearer:</p>\n\n<pre><code>public class SomeClass\n{\n static void foo(int x) { }\n static voi...
2009/01/02
[ "https://Stackoverflow.com/questions/407983", "https://Stackoverflow.com", "https://Stackoverflow.com/users/34211/" ]
I am wondering why the C# 3.0 compiler is unable to infer the type of a method when it is passed as a parameter to a generic function when it can implicitly create a delegate for the same method. Here is an example: ``` class Test { static void foo(int x) { } static void bar<T>(Action<T> f) { } static vo...
Maybe this will make it clearer: ``` public class SomeClass { static void foo(int x) { } static void foo(string s) { } static void bar<T>(Action<T> f){} static void barz(Action<int> f) { } static void test() { Action<int> f = foo; bar(f); barz(foo); bar(foo); ...
408,002
<p>Inside VS2005, our whole programming staff gets this error message <strong>sporadically</strong> and it is always on the <strong>BeneControls</strong> project. This error message happens multiple times a day and it occurs when going into DESIGN mode for a control. Normally rebuilding the <strong>BeneControls</strong...
[ { "answer_id": 408043, "author": "Otávio Décio", "author_id": 48684, "author_profile": "https://Stackoverflow.com/users/48684", "pm_score": 4, "selected": true, "text": "<p>Version=1.0.3289.23008 - that tells me you version number is constantly changing, have you thought about fixing on ...
2009/01/02
[ "https://Stackoverflow.com/questions/408002", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4964/" ]
Inside VS2005, our whole programming staff gets this error message **sporadically** and it is always on the **BeneControls** project. This error message happens multiple times a day and it occurs when going into DESIGN mode for a control. Normally rebuilding the **BeneControls** fixes the problem but somtime the whole ...
Version=1.0.3289.23008 - that tells me you version number is constantly changing, have you thought about fixing on a version number during development? On AssemblyInfo.vb: Currently it is set to increment: ``` [assembly: AssemblyVersion("1.0.*.*")] ``` Change to: ``` [assembly: AssemblyVersion("1.0.0.0")] ``` A...
408,032
<p>I'm looking for a fast way to turn an associative array in to a string. Typical structure would be like a URL query string but with customizable separators so I can use '<code>&amp;amp;</code>' for xhtml links or '<code>&amp;</code>' otherwise.</p> <p>My first inclination is to use <code>foreach</code> but since my...
[ { "answer_id": 408040, "author": "Greg", "author_id": 24181, "author_profile": "https://Stackoverflow.com/users/24181", "pm_score": 9, "selected": true, "text": "<p>You can use <a href=\"http://www.php.net/http_build_query\" rel=\"noreferrer\"><code>http_build_query()</code></a> to do th...
2009/01/02
[ "https://Stackoverflow.com/questions/408032", "https://Stackoverflow.com", "https://Stackoverflow.com/users/51021/" ]
I'm looking for a fast way to turn an associative array in to a string. Typical structure would be like a URL query string but with customizable separators so I can use '`&amp;`' for xhtml links or '`&`' otherwise. My first inclination is to use `foreach` but since my method could be called many times in one request I...
You can use [`http_build_query()`](http://www.php.net/http_build_query) to do that. > > Generates a URL-encoded query string from the associative (or indexed) array provided. > > >
408,042
<p>We use iText to generate PDFs from Java (based partly on recommendations on this site). However, embedding a copy of our logo in an image format like GIF results in it looking a bit strange as people zoom in and out.</p> <p>Ideally we'd like to embed the image in a vector format, such as EPS, SVG or just a PDF temp...
[ { "answer_id": 408098, "author": "David Koelle", "author_id": 2197, "author_profile": "https://Stackoverflow.com/users/2197", "pm_score": 3, "selected": false, "text": "<p>I recently learned that you can send your Graphics2D object directly to iText, and the resulting PDF files are just ...
2009/01/02
[ "https://Stackoverflow.com/questions/408042", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1000/" ]
We use iText to generate PDFs from Java (based partly on recommendations on this site). However, embedding a copy of our logo in an image format like GIF results in it looking a bit strange as people zoom in and out. Ideally we'd like to embed the image in a vector format, such as EPS, SVG or just a PDF template. The ...
According to the [documentation](http://itextdocs.lowagie.com/tutorial/objects/images/index.php) iText supports the following image formats: JPEG, GIF, PNG, TIFF, BMP, WMF and EPS. I don't know if this might be of any help but I have successfully used [iTextSharp](http://itextsharp.sourceforge.net/) to embed vector [WM...
408,051
<p>So if my JPA query is like this: Select distinct p from Parent p left join fetch p.children order by p.someProperty</p> <p>I correctly get results back ordered by p.someProperty, and I correctly get my p.children collection eagerly fetched and populated. But I'd like to have my query be something like "order by p....
[ { "answer_id": 408522, "author": "Adeel Ansari", "author_id": 42769, "author_profile": "https://Stackoverflow.com/users/42769", "pm_score": 5, "selected": true, "text": "<p>For preserving order, use <a href=\"http://java.sun.com/javase/6/docs/api/java/util/TreeSet.html\" rel=\"noreferrer...
2009/01/02
[ "https://Stackoverflow.com/questions/408051", "https://Stackoverflow.com", "https://Stackoverflow.com/users/409/" ]
So if my JPA query is like this: Select distinct p from Parent p left join fetch p.children order by p.someProperty I correctly get results back ordered by p.someProperty, and I correctly get my p.children collection eagerly fetched and populated. But I'd like to have my query be something like "order by p.somePropert...
For preserving order, use [TreeSet](http://java.sun.com/javase/6/docs/api/java/util/TreeSet.html). As far as, sorting of a collection inside parent is concerned, just do it in your code using [Comparator](http://java.sun.com/javase/6/docs/api/java/util/Comparator.html). Well, try this on your collection definition in ...
408,055
<p>What would result from something like the following:</p> <pre><code>p(X,Y) :- q(X). p(X,Y) :- r(Y). q(a). r(b). </code></pre> <p>I don't have a Prolog compiler handy, so I can't test what would happen if you then asked <code>p(X,Y)</code>. Would the code even compile? Would <code>p</code> return two answers, eac...
[ { "answer_id": 408694, "author": "John Boker", "author_id": 2847, "author_profile": "https://Stackoverflow.com/users/2847", "pm_score": 1, "selected": false, "text": "<p>so.p contains:</p>\n\n<pre><code>p(X,Y) :- q(X).\np(X,Y) :- r(Y).\nq(a).\nr(b).\n</code></pre>\n\n<hr>\n\n<pre><code>$...
2009/01/02
[ "https://Stackoverflow.com/questions/408055", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18160/" ]
What would result from something like the following: ``` p(X,Y) :- q(X). p(X,Y) :- r(Y). q(a). r(b). ``` I don't have a Prolog compiler handy, so I can't test what would happen if you then asked `p(X,Y)`. Would the code even compile? Would `p` return two answers, each with one of the variables unbound? In a real wo...
*Would p return two answers, each with one of the variables unbound?* Yes. You need to type a ; to see further solutions: | ?- p(X,Y). X = a ? ; Y = b yes | ?- This agrees with the theory, where an unbound variable means that any value can be substituted for this variable.
408,079
<p>I want to do this: </p> <pre><code> findstr /s /c:some-symbol * </code></pre> <p>or the grep equivalent</p> <pre><code> grep -R some-symbol * </code></pre> <p>but I need the utility to autodetect files encoded in UTF-16 (and friends) and search them appropriately. My files even have the byte-ordering mark FFEE ...
[ { "answer_id": 408177, "author": "Mark A. Nicolosi", "author_id": 1103052, "author_profile": "https://Stackoverflow.com/users/1103052", "pm_score": 1, "selected": false, "text": "<p>According to this <a href=\"http://dcortesi.com/2008/07/16/unicode-grep/\" rel=\"nofollow noreferrer\">blo...
2009/01/02
[ "https://Stackoverflow.com/questions/408079", "https://Stackoverflow.com", "https://Stackoverflow.com/users/51029/" ]
I want to do this: ``` findstr /s /c:some-symbol * ``` or the grep equivalent ``` grep -R some-symbol * ``` but I need the utility to autodetect files encoded in UTF-16 (and friends) and search them appropriately. My files even have the byte-ordering mark FFEE in them so I'm not even looking for heroic autodet...
A workaround is to convert your UTF-16 to ASCII or ANSI ``` TYPE UTF-16.txt > ASCII.txt ``` Then you can use FINDSTR. ``` FINDSTR object ASCII.txt ```
408,080
<p>Is there a foreach structure in MATLAB? If so, what happens if the underlying data changes (i.e. if objects are added to the set)?</p>
[ { "answer_id": 408092, "author": "Jason S", "author_id": 44330, "author_profile": "https://Stackoverflow.com/users/44330", "pm_score": 4, "selected": false, "text": "<p>ooh! neat question.</p>\n\n<p>Matlab's for loop takes a matrix as input and iterates over its columns. Matlab also hand...
2009/01/02
[ "https://Stackoverflow.com/questions/408080", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18511/" ]
Is there a foreach structure in MATLAB? If so, what happens if the underlying data changes (i.e. if objects are added to the set)?
MATLAB's **FOR** loop is static in nature; you cannot modify the loop variable between iterations, unlike the **for(initialization;condition;increment)** loop structure in other languages. This means that the following code always prints 1, 2, 3, 4, 5 regardless of the value of B. ``` A = 1:5; for i = A A = B; ...
408,101
<p>In VB.NET, which is faster to use for method arguments, <code>ByVal</code> or <code>ByRef</code>?</p> <p>Also, which consumes more resources at runtime (RAM)? </p> <hr> <p>I read through <a href="https://stackoverflow.com/questions/290189/best-practice-byref-or-byval-in-net">this question</a>, but the answers are...
[ { "answer_id": 408107, "author": "Paul", "author_id": 37865, "author_profile": "https://Stackoverflow.com/users/37865", "pm_score": 1, "selected": false, "text": "<p><code>ByVal</code> creates a copy of the variable, whereas <code>ByRef</code> passes a pointer. I would therefore say that...
2009/01/02
[ "https://Stackoverflow.com/questions/408101", "https://Stackoverflow.com", "https://Stackoverflow.com/users/41021/" ]
In VB.NET, which is faster to use for method arguments, `ByVal` or `ByRef`? Also, which consumes more resources at runtime (RAM)? --- I read through [this question](https://stackoverflow.com/questions/290189/best-practice-byref-or-byval-in-net), but the answers are not applicable or specific enough.
Byval and ByRef arguments should be used based on requirements and knowledge of how they work *not* on speed. <http://www.developer.com/net/vb/article.php/3669066> *In response to a comment by Slough -* **Which consumes more resources at runtime?** Parameters are passed on the stack. The stack is very fast, because...
408,116
<p>I'm looking for an easy way to track time I work on a project using the command line. I do</p> <pre><code>echo "$(date) : Start" &gt;&gt;worktime.txt </code></pre> <p>When I start working and</p> <pre><code>echo "$(date) : End" &gt;&gt;worktime.txt </code></pre> <p>When I stop working. The result is a file of th...
[ { "answer_id": 408132, "author": "wilhelmtell", "author_id": 456, "author_profile": "https://Stackoverflow.com/users/456", "pm_score": 3, "selected": false, "text": "<p>Assuming you're using the GNU coreutils, run <code>date +%s</code> instead.</p>\n\n<pre><code>echo $(date +%s) : Start\...
2009/01/02
[ "https://Stackoverflow.com/questions/408116", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I'm looking for an easy way to track time I work on a project using the command line. I do ``` echo "$(date) : Start" >>worktime.txt ``` When I start working and ``` echo "$(date) : End" >>worktime.txt ``` When I stop working. The result is a file of the form: ``` kent@rat:~/work$ cat worktime.txt Fri Jan 2 19...
wilhelmtell has a great script, if you need to use a slightly modified version so that you can continue to use `$(date)` instead of `$(date +%s)` this will work in an identical fashion, just with an added line to reformat the times using `+%s` ``` #!/bin/bash total=0 while read LINE; do d1=$(echo $LINE |cut -c1-28);...