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 |
|---|---|---|---|---|---|---|
557,159 | <p>In a normal loop you can break out of a loop using break. Can the same be done using an anonymous delegate?</p>
<p>Example
inputString and result are both declared outside the delegate.</p>
<pre><code>blackList.ForEach(new Action<string>(
delegate(string item)
{
if(inputString.Contains(item)... | [
{
"answer_id": 557172,
"author": "JaredPar",
"author_id": 23283,
"author_profile": "https://Stackoverflow.com/users/23283",
"pm_score": 2,
"selected": false,
"text": "<p>The only way to \"exit\" the loop is to throw an exception. There is no \"break\" style way of exiting the .ForEach m... | 2009/02/17 | [
"https://Stackoverflow.com/questions/557159",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2720/"
] | In a normal loop you can break out of a loop using break. Can the same be done using an anonymous delegate?
Example
inputString and result are both declared outside the delegate.
```
blackList.ForEach(new Action<string>(
delegate(string item)
{
if(inputString.Contains(item)==true)
{
... | As others have posted, you can't exit the loop in ForEach.
Are you able to use LINQ? If so, you could easily combine TakeWhile and a custom ForEach extension method (which just about every project seems to have these days).
In your example, however, [`List<T>.FindIndex`](http://msdn.microsoft.com/en-us/library/x1xzf2... |
557,169 | <p>I'm currently trying to tune my Eclipse installation and bumped into the "-vm" option. Other posts on SO mentioned that it's good to always use the latest JVM available because they keep getting better in terms of performance, so I'm likely to do that. I was wondering though how you could find out what JVM Eclipse r... | [
{
"answer_id": 557239,
"author": "dw.mackie",
"author_id": 59084,
"author_profile": "https://Stackoverflow.com/users/59084",
"pm_score": -1,
"selected": false,
"text": "<p>I think if you do:<br>\nWindow->Preferences->Java->Installed JREs<br> you'll see a list of JREs on your machine.\nTh... | 2009/02/17 | [
"https://Stackoverflow.com/questions/557169",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17255/"
] | I'm currently trying to tune my Eclipse installation and bumped into the "-vm" option. Other posts on SO mentioned that it's good to always use the latest JVM available because they keep getting better in terms of performance, so I'm likely to do that. I was wondering though how you could find out what JVM Eclipse runs... | Actually, Windows->Preferences->Java->installed doesn't show you the one Eclipse runs under, but only the default JRE that it runs things under.
To see the one Eclipse is runing under, go to Help->About Eclipse Platform->Configuration Details, and look for the property eclipse.vm.
For example:
```
eclipse.vm=C:\Prog... |
557,170 | <p>The following string of mine tried to find difference between two strings.
But it's horribly slow as it iterate the length of string:</p>
<pre><code>#include <string>
#include <vector>
#include <iostream>
using namespace std;
int hd(string s1, string s2) {
// hd stands for "Hamming Distance"... | [
{
"answer_id": 557189,
"author": "unwind",
"author_id": 28169,
"author_profile": "https://Stackoverflow.com/users/28169",
"pm_score": 2,
"selected": false,
"text": "<p>Some obvious points that might make it faster:</p>\n\n<ol>\n<li>Pass the strings as const references, not by value</li>\... | 2009/02/17 | [
"https://Stackoverflow.com/questions/557170",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/67405/"
] | The following string of mine tried to find difference between two strings.
But it's horribly slow as it iterate the length of string:
```
#include <string>
#include <vector>
#include <iostream>
using namespace std;
int hd(string s1, string s2) {
// hd stands for "Hamming Distance"
int dif = 0;
for (unsig... | Fun with the STL:
```
#include <numeric> //inner_product
#include <functional> //plus, equal_to, not2
#include <string>
#include <stdexcept>
unsigned int
hd(const std::string& s1, const std::string& s2)
{
// TODO: What should we do if s1.size() != s2.size()?
if (s1.size() != s2.size()){
throw std... |
557,180 | <p>I am populating this mysql table with data from a php (via post and using filter_input).
The database is utf8 but when I have a user that inputs words with ^,',',~ like Não I get this -> Não</p>
<p>What do I have to do to make it show the correct values. Or should I try to make some correction when I retrieve the ... | [
{
"answer_id": 557215,
"author": "RVeur23",
"author_id": 66997,
"author_profile": "https://Stackoverflow.com/users/66997",
"pm_score": 1,
"selected": false,
"text": "<p>First, make sure your page is utf-8</p>\n\n<pre><code><meta http-equiv=\"Content-type\" content=\"text/html; charset... | 2009/02/17 | [
"https://Stackoverflow.com/questions/557180",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8715/"
] | I am populating this mysql table with data from a php (via post and using filter\_input).
The database is utf8 but when I have a user that inputs words with ^,',',~ like Não I get this -> Não
What do I have to do to make it show the correct values. Or should I try to make some correction when I retrieve the data??
U... | First, make sure your page is utf-8
```
<meta http-equiv="Content-type" content="text/html; charset=UTF-8"/>
```
next, if your on Apache, make sur your in UTF-8 in config file :
```
AddDefaultCharset UTF-8
```
or your can do it in a .php file like this :
```
header('Content-type: text/html; charset=UTF-8');
... |
557,200 | <p>I have three strings:</p>
<p>$str1 = "abc";
$str2 = "def";
$str3 = "ghi";</p>
<p>I can get the value of all of them like this:</p>
<p>echo "$str1$str2$str3";</p>
<p>But I heard there is a way to join them together, so I can echo all of them without quotes.</p>
| [
{
"answer_id": 557205,
"author": "carbin",
"author_id": 66613,
"author_profile": "https://Stackoverflow.com/users/66613",
"pm_score": 4,
"selected": true,
"text": "<p>You're looking for string concantation.</p>\n\n<p>It's</p>\n\n<pre><code>echo $str1 . $str2 . $str3;\n</code></pre>\n\n<p... | 2009/02/17 | [
"https://Stackoverflow.com/questions/557200",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/67404/"
] | I have three strings:
$str1 = "abc";
$str2 = "def";
$str3 = "ghi";
I can get the value of all of them like this:
echo "$str1$str2$str3";
But I heard there is a way to join them together, so I can echo all of them without quotes. | You're looking for string concantation.
It's
```
echo $str1 . $str2 . $str3;
```
See <http://nz2.php.net/language.operators.string> for more information. |
557,208 | <p>This one is very weird:</p>
<p>My app works just fine, but suddenly the damn ListView control's events are not raised any more. It just comes and goes without any clear reason. (Obviously) I've set the AllowDrop property to True and handled the DragEnter, DragOver and DragDrop events as follows:</p>
<pre><code>Pri... | [
{
"answer_id": 557220,
"author": "Judah Gabriel Himango",
"author_id": 536,
"author_profile": "https://Stackoverflow.com/users/536",
"pm_score": 1,
"selected": false,
"text": "<p>Does the form itself have its AllowDrop property set to true?</p>\n"
},
{
"answer_id": 557273,
"a... | 2009/02/17 | [
"https://Stackoverflow.com/questions/557208",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/41389/"
] | This one is very weird:
My app works just fine, but suddenly the damn ListView control's events are not raised any more. It just comes and goes without any clear reason. (Obviously) I've set the AllowDrop property to True and handled the DragEnter, DragOver and DragDrop events as follows:
```
Private Sub lstApplicati... | I just had hours of misery with a similar problem. three mandatory requirements for drag and drop to work:
1. Make sure your target UI Element has `AllowDrop="True"`, you don't need this for the entire App, just the element you want want to enable.
2. Some elements do not receive certain mouse events (including d&d) i... |
557,213 | <p>How can I make python's unittest module show output for every assertion, rather than failing at the first one per test case? It would be much easier to debug if I could see the complete pattern of failures rather than just the first one.</p>
<p>In my case the assertions are based on a couple loops over an array con... | [
{
"answer_id": 557386,
"author": "S.Lott",
"author_id": 10661,
"author_profile": "https://Stackoverflow.com/users/10661",
"pm_score": 2,
"selected": false,
"text": "<pre><code>import unittest\nimport get_nodes\n\nclass TestSuper(unittest.TestCase):\n def setUp( self ):\n self.r... | 2009/02/17 | [
"https://Stackoverflow.com/questions/557213",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/41613/"
] | How can I make python's unittest module show output for every assertion, rather than failing at the first one per test case? It would be much easier to debug if I could see the complete pattern of failures rather than just the first one.
In my case the assertions are based on a couple loops over an array containing an... | I was able to do it by making new TestCase classes dynamically using the builtin type() factory:
```
root = get_nodes.mmnode_plus.factory('somenodes.xml')
tests = [
(root, {'skip_traversal': False, 'skip_as_child': True, 'skip_as_parent': False, 'is_leaf': False}),
(root[0], {'skip_traversal': False, 'skip_as... |
557,224 | <p>I'm building a controller that other controllers can inherit (provide base functionality across site without repeating code):</p>
<pre><code>public abstract class ApplicationController : Controller
{
protected ApplicationController()
{
//site logic goes here
//what is the value of agentID from... | [
{
"answer_id": 557286,
"author": "swilliams",
"author_id": 736,
"author_profile": "https://Stackoverflow.com/users/736",
"pm_score": 0,
"selected": false,
"text": "<p>There is, though you need to override the <code>ControllerFactory</code>. In your <code>RegisterRoutes</code> method in g... | 2009/02/17 | [
"https://Stackoverflow.com/questions/557224",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1215/"
] | I'm building a controller that other controllers can inherit (provide base functionality across site without repeating code):
```
public abstract class ApplicationController : Controller
{
protected ApplicationController()
{
//site logic goes here
//what is the value of agentID from the Action be... | I figured out how to do it ... very similar to Craig Stuntz's answer, but the difference is in how you reach the RouteData.
Using ControllerContext.RouteData.Values does not work in a regular method used this way (it does from the original controller, but not from a base one like I built), but I did get to the RouteDa... |
557,229 | <p>How can I make such a conditional search in Bash like in Google</p>
<pre><code>"python" imag
</code></pre>
<p>The word <strong>python</strong> must be in the search, while the word <strong>imag</strong> aims to match at least image and imaging.</p>
<p>I want to search a python module for images, perhaps in apt-ge... | [
{
"answer_id": 557280,
"author": "Jérôme",
"author_id": 49850,
"author_profile": "https://Stackoverflow.com/users/49850",
"pm_score": 1,
"selected": false,
"text": "<p>A dirty method should be use spaces. When you're looking exact words, they are likely to be between spaces. eg for apt:<... | 2009/02/17 | [
"https://Stackoverflow.com/questions/557229",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/54964/"
] | How can I make such a conditional search in Bash like in Google
```
"python" imag
```
The word **python** must be in the search, while the word **imag** aims to match at least image and imaging.
I want to search a python module for images, perhaps in apt-get. | The grep option for searching a word is -w:
```
grep -w python | grep imag
``` |
557,240 | <p>Out of interest when working with SQL statements should I always use the fully qualifed column name (tablename.columnname) even if only working with one table e.g.</p>
<pre><code>SELECT table.column1, table.column2 FROM table
</code></pre>
| [
{
"answer_id": 557252,
"author": "Adam Davis",
"author_id": 2915,
"author_profile": "https://Stackoverflow.com/users/2915",
"pm_score": 5,
"selected": true,
"text": "<p>It's better if you do - it doesn't add any complexity, and it can prevent errors in the future.</p>\n\n<p>But in a well... | 2009/02/17 | [
"https://Stackoverflow.com/questions/557240",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12918/"
] | Out of interest when working with SQL statements should I always use the fully qualifed column name (tablename.columnname) even if only working with one table e.g.
```
SELECT table.column1, table.column2 FROM table
``` | It's better if you do - it doesn't add any complexity, and it can prevent errors in the future.
But in a well-defined system, you shouldn't *have* to - it's like namespaces in programming languages. The ideal is not to have conflicts, but it can clutter the code with the superfluous use of explicit names.
-Adam |
557,271 | <p>Perl's system() starts a process, but breaks the parent/child relationship?</p>
<p>test.pl:</p>
<pre><code>use POSIX;
system("./test.sh &");
my $pid = `ps -C test.sh -o pid=`;
print "pid: -$pid-\n";
waitpid($pid, 0);
</code></pre>
<p>test.sh:</p>
<pre><code>while true
do
sleep 1
done
</code></pre>
<... | [
{
"answer_id": 557293,
"author": "Liudvikas Bukys",
"author_id": 5845,
"author_profile": "https://Stackoverflow.com/users/5845",
"pm_score": 5,
"selected": true,
"text": "<p>The test.sh process is not your child process. The <code>system()</code> forked a shell (which is your child), th... | 2009/02/17 | [
"https://Stackoverflow.com/questions/557271",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/23420/"
] | Perl's system() starts a process, but breaks the parent/child relationship?
test.pl:
```
use POSIX;
system("./test.sh &");
my $pid = `ps -C test.sh -o pid=`;
print "pid: -$pid-\n";
waitpid($pid, 0);
```
test.sh:
```
while true
do
sleep 1
done
```
When I run test.pl, it finds and prints a correct pid of t... | The test.sh process is not your child process. The `system()` forked a shell (which is your child), that shell forked a child that ran the test.sh program. The shell that was your child exited. |
557,282 | <p><strong>EDIT:</strong> I understand there is keyboard-quit (which is normally bound to C-g); but I'm more interested to know about how one deals with editing functions that come with Emacs (like in this case). I run into this kind of situations from time to time when I want to change just a little bit of some build-... | [
{
"answer_id": 557326,
"author": "Brian Postow",
"author_id": 53491,
"author_profile": "https://Stackoverflow.com/users/53491",
"pm_score": 3,
"selected": false,
"text": "<p>I usually find that 'keyboard-quit (C-g) works to get out of all of those situations.</p>\n\n<p>However, if you re... | 2009/02/17 | [
"https://Stackoverflow.com/questions/557282",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/45383/"
] | **EDIT:** I understand there is keyboard-quit (which is normally bound to C-g); but I'm more interested to know about how one deals with editing functions that come with Emacs (like in this case). I run into this kind of situations from time to time when I want to change just a little bit of some build-in functions.
I... | You could use around advice and redefine the offending function to do what you want (i.e. one-window-p should always return t):
```
(defadvice keyboard-escape-quit (around my-keyboard-escape-quit activate)
(let (orig-one-window-p)
(fset 'orig-one-window-p (symbol-function 'one-window-p))
(fset 'one-window-p ... |
557,306 | <p>I have the following code:</p>
<pre><code>while ($row = mysql_fetch_array($result, MYSQL_NUM))
{
for ($i=0; $i<count($row); $i++)
{
(DO THING HERE)
$row[$i] = str_replace("\n", " ", $row[$i]);
$row[$i] = str_replace("\r", " ", $row[$i]);
}
}
<... | [
{
"answer_id": 557322,
"author": "ryeguy",
"author_id": 49018,
"author_profile": "https://Stackoverflow.com/users/49018",
"pm_score": 0,
"selected": false,
"text": "<p>I'm not sure if this is exactly what you want but:</p>\n\n<pre><code>$row['email'].='@gmail.com';\n</code></pre>\n\n<p>T... | 2009/02/17 | [
"https://Stackoverflow.com/questions/557306",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/49887/"
] | I have the following code:
```
while ($row = mysql_fetch_array($result, MYSQL_NUM))
{
for ($i=0; $i<count($row); $i++)
{
(DO THING HERE)
$row[$i] = str_replace("\n", " ", $row[$i]);
$row[$i] = str_replace("\r", " ", $row[$i]);
}
}
```
I basically ... | See the `MYSQL_NUM` you have there? [That is going to return your data using the column indexes as keys (ie 0, 1, 2, etc)](http://www.php.net/manual/en/function.mysql-fetch-array.php).
You must either
a) find out which column index the `email` field is and do:
```
while ($row = mysql_fetch_array($result, MYSQL_NUM))... |
557,317 | <p>Probably a simple question but I only have Linux to test this code on where __declspec(dllexport) is not needed. In the current code __declspec(dllexport) is in front of all files in the .h file but just in front of like 50% of the functions in the cpp file so I am wondering if they are really needed in the cpp file... | [
{
"answer_id": 557331,
"author": "Doug T.",
"author_id": 8123,
"author_profile": "https://Stackoverflow.com/users/8123",
"pm_score": 5,
"selected": true,
"text": "<p>No, its only needed in the header.</p>\n<p>Here's a <a href=\"https://web.archive.org/web/20120628222847/http://msdn.micro... | 2009/02/17 | [
"https://Stackoverflow.com/questions/557317",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11722/"
] | Probably a simple question but I only have Linux to test this code on where \_\_declspec(dllexport) is not needed. In the current code \_\_declspec(dllexport) is in front of all files in the .h file but just in front of like 50% of the functions in the cpp file so I am wondering if they are really needed in the cpp fil... | No, its only needed in the header.
Here's a [link](https://web.archive.org/web/20120628222847/http://msdn.microsoft.com/en-us/library/a90k134d(VS.80).aspx) with more info.
Expanding on what Vinay was saying, I've often seen a macro defined
```
#if defined(MODULENAME_IMPORT)
#define EXPORTED __declspec(dllimport)
#el... |
557,323 | <p>I'm struggling to define a class method that populates and returns a collection of instances. The issue I don't know how to get around is that I have private attributes to populate.</p>
<p>Let's use the example of a Book class. I don't want the code to directly set (say) the availability of a book. I want the co... | [
{
"answer_id": 557358,
"author": "Fabian Vilers",
"author_id": 66973,
"author_profile": "https://Stackoverflow.com/users/66973",
"pm_score": 0,
"selected": false,
"text": "<p>Why don't you check the availability of the book at database side using a SQL where statement?</p>\n"
},
{
... | 2009/02/17 | [
"https://Stackoverflow.com/questions/557323",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/25538/"
] | I'm struggling to define a class method that populates and returns a collection of instances. The issue I don't know how to get around is that I have private attributes to populate.
Let's use the example of a Book class. I don't want the code to directly set (say) the availability of a book. I want the code to have to... | You could create a protected constructor which populates the private properties directly. |
557,340 | <p>Let's say I have a generic member in a class or method, like so:</p>
<pre><code>public class Foo<T>
{
public List<T> Bar { get; set; }
public void Baz()
{
// get type of T
}
}
</code></pre>
<p>When I instantiate the class, the <code>T</code> becomes <code>MyTypeObject1</co... | [
{
"answer_id": 557349,
"author": "Marc Gravell",
"author_id": 23354,
"author_profile": "https://Stackoverflow.com/users/23354",
"pm_score": 9,
"selected": false,
"text": "<p>(note: I'm assuming that all you know is <code>object</code> or <code>IList</code> or similar, and that the list c... | 2009/02/17 | [
"https://Stackoverflow.com/questions/557340",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13913/"
] | Let's say I have a generic member in a class or method, like so:
```
public class Foo<T>
{
public List<T> Bar { get; set; }
public void Baz()
{
// get type of T
}
}
```
When I instantiate the class, the `T` becomes `MyTypeObject1`, so the class has a generic list property: `List<MyTypeObj... | If I understand correctly, your list has the same type parameter as the container class itself. If this is the case, then:
```
Type typeParameterType = typeof(T);
```
If you are in the lucky situation of having `object` as a type parameter, see [Marc's answer](https://stackoverflow.com/a/557349/3649914). |
557,344 | <p>How I can show any message before the main form is loaded in Windows CE??
(I work in WinCE)</p>
| [
{
"answer_id": 557378,
"author": "Powerlord",
"author_id": 15880,
"author_profile": "https://Stackoverflow.com/users/15880",
"pm_score": 0,
"selected": false,
"text": "<p>The standard way of doing it would be to add a delegate for the form's Load event and do a <a href=\"http://msdn.micr... | 2009/02/17 | [
"https://Stackoverflow.com/questions/557344",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/43907/"
] | How I can show any message before the main form is loaded in Windows CE??
(I work in WinCE) | In your main function in program.cs, before the main form is created, you could call a message box with MessageBox.show, specifically: (this example if from a winforms app, so the Application.EnableVisualStyles() probably doesn't apply, but it should work the same)
```
static void main()
{
Application.EnableVisu... |
557,359 | <p>I am trying to build a slide show with jQuery cycle plug in.</p>
<p>In the slide show there are contents and inside the contents there is basic image gallery.</p>
<p>Timeout of cycle which image gallery uses is fewer than the contents timeout. So content waits for 15 second and the image gallery will have 5 pics w... | [
{
"answer_id": 557721,
"author": "Jab",
"author_id": 29676,
"author_profile": "https://Stackoverflow.com/users/29676",
"pm_score": 3,
"selected": false,
"text": "<p>If I'm getting your concept this should work. One thing you will need to do to make it look right is to have a fixed width... | 2009/02/17 | [
"https://Stackoverflow.com/questions/557359",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/51734/"
] | I am trying to build a slide show with jQuery cycle plug in.
In the slide show there are contents and inside the contents there is basic image gallery.
Timeout of cycle which image gallery uses is fewer than the contents timeout. So content waits for 15 second and the image gallery will have 5 pics with 3 seconds tim... | If I'm getting your concept this should work. One thing you will need to do to make it look right is to have a fixed width and height of `cycleContent` with `overflow:hidden`.
**Edit** I changed the second jquery selector to use the class. So the markup no longer has cycleImages as an id. Since you will be repeating i... |
557,377 | <p>here's my problem:
I want to check if a user insert a real name and surname by checking if they have only letters (of any alphabet) and ' or - in PHP.
I've found a solution here (but I don't remember the link) on how to check if a string has only letters:</p>
<pre><code>preg_match('/^[\p{L} ]+$/u',$name)
</code></p... | [
{
"answer_id": 557388,
"author": "Tomer Gabel",
"author_id": 11558,
"author_profile": "https://Stackoverflow.com/users/11558",
"pm_score": 4,
"selected": true,
"text": "<p>Looks like you just need to modify the regex: [\\p{L}' -]+</p>\n"
},
{
"answer_id": 557400,
"author": "J... | 2009/02/17 | [
"https://Stackoverflow.com/questions/557377",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/67423/"
] | here's my problem:
I want to check if a user insert a real name and surname by checking if they have only letters (of any alphabet) and ' or - in PHP.
I've found a solution here (but I don't remember the link) on how to check if a string has only letters:
```
preg_match('/^[\p{L} ]+$/u',$name)
```
but I'd like to ad... | Looks like you just need to modify the regex: [\p{L}' -]+ |
557,381 | <p>I have interface in service layer with several methods starting with Get and FxCop's <strong>Use properties where appropriate</strong> rule complains that I should consider using properties instead.</p>
<p>I tried to use SuppressMessageAttribute but when it's defined on interface it has no effect on member methods.... | [
{
"answer_id": 557392,
"author": "Sesh",
"author_id": 38212,
"author_profile": "https://Stackoverflow.com/users/38212",
"pm_score": 3,
"selected": true,
"text": "<p>You will have to add the attribute for each method.</p>\n"
},
{
"answer_id": 557398,
"author": "casperOne",
... | 2009/02/17 | [
"https://Stackoverflow.com/questions/557381",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/67420/"
] | I have interface in service layer with several methods starting with Get and FxCop's **Use properties where appropriate** rule complains that I should consider using properties instead.
I tried to use SuppressMessageAttribute but when it's defined on interface it has no effect on member methods. Do I need to put Suppr... | You will have to add the attribute for each method. |
557,382 | <p>I'm writing a subroutine for DBI updates, and are having some trouble figuring out how to add placeholder and stuff...</p>
<p>I have this: </p>
<pre><code>sub row_update {
my $table = shift;
my %updates = @_;
my $placeholders = ...
$dbh->do("UPDATE $table SET (foo) WHERE (bar)") etc...
}
</code></pre>
... | [
{
"answer_id": 557821,
"author": "jrockway",
"author_id": 8457,
"author_profile": "https://Stackoverflow.com/users/8457",
"pm_score": 2,
"selected": false,
"text": "<p>Something like this might be Good Enough:</p>\n\n<pre><code>sub update {\n my ($dbh, $args) = @_;\n\n my $table ... | 2009/02/17 | [
"https://Stackoverflow.com/questions/557382",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | I'm writing a subroutine for DBI updates, and are having some trouble figuring out how to add placeholder and stuff...
I have this:
```
sub row_update {
my $table = shift;
my %updates = @_;
my $placeholders = ...
$dbh->do("UPDATE $table SET (foo) WHERE (bar)") etc...
}
```
Any ideas?
I just want a simple... | If I understand the question correctly, it sounds like you're after [SQL::Abstract](http://search.cpan.org/perldoc?SQL::Abstract). First, we create an `SQL::Abstract` object:
```
use SQL::Abstract;
my $sql = SQL::Abstract->new;
```
Now, as an example, we'll use it to insert some data into a table:
```
my %record = ... |
557,425 | <p>Consider the following 2 tables:</p>
<pre><code>Table A:
id
event_time
Table B
id
start_time
end_time
</code></pre>
<p>Every record in table A is mapped to exactly 1 record in table B. This means table B has no overlapping periods. Many records from table A can be mapped to the same record in table B.</p>
<p>I n... | [
{
"answer_id": 557443,
"author": "Fabian Vilers",
"author_id": 66973,
"author_profile": "https://Stackoverflow.com/users/66973",
"pm_score": 0,
"selected": false,
"text": "<p>Give a try using standard comparison operator (< and >).</p>\n"
},
{
"answer_id": 557447,
"author"... | 2009/02/17 | [
"https://Stackoverflow.com/questions/557425",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6346/"
] | Consider the following 2 tables:
```
Table A:
id
event_time
Table B
id
start_time
end_time
```
Every record in table A is mapped to exactly 1 record in table B. This means table B has no overlapping periods. Many records from table A can be mapped to the same record in table B.
I need a query that returns all A.id... | You may want to try something like this
```
Select A.ID,
(SELECT B.ID FROM B
WHERE A.EventTime BETWEEN B.start_time AND B.end_time LIMIT 1) AS B_ID
FROM A
```
If you have an index on the Start\_Time,End\_Time fields for B, then this should work quite well. |
557,432 | <p>Is there any way, using the scripting available to Excel 2007 to display a Google Earth map inside a sheet?</p>
<p>I've used Excel to house the data that I've then gone and generated a KML file to load into Google Earth, but now they want to see a pretty little cell with a client address mapped out in Excel directl... | [
{
"answer_id": 557476,
"author": "Sesh",
"author_id": 38212,
"author_profile": "https://Stackoverflow.com/users/38212",
"pm_score": 0,
"selected": false,
"text": "<p>Google maps will require some kind of browser control on which to render the markup coming from a maps query. There is no ... | 2009/02/17 | [
"https://Stackoverflow.com/questions/557432",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17632/"
] | Is there any way, using the scripting available to Excel 2007 to display a Google Earth map inside a sheet?
I've used Excel to house the data that I've then gone and generated a KML file to load into Google Earth, but now they want to see a pretty little cell with a client address mapped out in Excel directly to prett... | Microsoft does have an ActiveX webbrowser control that I've used in the past and as Panji explains[how to create a web browser control in excel](http://www.eggheadcafe.com/community/aspnet/66/10077917/webbrowser-control.aspx)
Panji Tengkorak
If what you're looking for is to display the html table as it is without the... |
557,452 | <p>I would like to use tooltip in a web page with the following constraints:</p>
<ul>
<li>Tooltip should work with simple texts, not only with anchors.</li>
<li>I do not want to use javascript, only css.</li>
<li>I would like to make it work at least in Firefox and Internet Explorer.</li>
</ul>
<p>A promising candida... | [
{
"answer_id": 557503,
"author": "Rex M",
"author_id": 67,
"author_profile": "https://Stackoverflow.com/users/67",
"pm_score": 3,
"selected": false,
"text": "<p>A solution that meets all your requirements is not possible. IE's respect for <code>:hover</code> is limited - Eric Meyer's sol... | 2009/02/17 | [
"https://Stackoverflow.com/questions/557452",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/21047/"
] | I would like to use tooltip in a web page with the following constraints:
* Tooltip should work with simple texts, not only with anchors.
* I do not want to use javascript, only css.
* I would like to make it work at least in Firefox and Internet Explorer.
A promising candidate is Eric Meyer's [solution](http://meyer... | As others have said, your requirements are unrealistic. In environments where Javascript may be disabled, I typically will use the `title` attribute to get simple browser tooltips as a fallback, and then enable better looking tooltips via Javascript reading the title attributes (using a framework such as jQuery, or for... |
557,459 | <p>Often seen it and often used it, wonder if it has a name?</p>
<p>C# version:</p>
<pre><code>public class Register
{
protected Register()
{
Register.registry.Add(this);
}
public static ReadOnlyCollection<Register> Instances
{
get { return new ReadOnlyCollection<Register&g... | [
{
"answer_id": 557468,
"author": "Robert",
"author_id": 17864,
"author_profile": "https://Stackoverflow.com/users/17864",
"pm_score": 3,
"selected": false,
"text": "<p>A memory leak? No instances of Register will ever be collected, unless you provide a way to explicitly remove them from ... | 2009/02/17 | [
"https://Stackoverflow.com/questions/557459",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13018/"
] | Often seen it and often used it, wonder if it has a name?
C# version:
```
public class Register
{
protected Register()
{
Register.registry.Add(this);
}
public static ReadOnlyCollection<Register> Instances
{
get { return new ReadOnlyCollection<Register>(registry); }
}
privat... | A memory leak? No instances of Register will ever be collected, unless you provide a way to explicitly remove them from the static list "registry". |
557,460 | <p>Alright, this is probably a really silly question but I am new to Python/Django so I can't really wrap my head around its scoping concepts just yet. Right now I am writing a <a href="http://docs.djangoproject.com/en/dev/topics/http/middleware/#topics-http-middleware" rel="noreferrer">middleware</a> class to handle s... | [
{
"answer_id": 557524,
"author": "Joe Holloway",
"author_id": 48837,
"author_profile": "https://Stackoverflow.com/users/48837",
"pm_score": 2,
"selected": false,
"text": "<p>1) If you modify 'settings', this is truly going to be global even across requests. In other words, concurrent re... | 2009/02/17 | [
"https://Stackoverflow.com/questions/557460",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16417/"
] | Alright, this is probably a really silly question but I am new to Python/Django so I can't really wrap my head around its scoping concepts just yet. Right now I am writing a [middleware](http://docs.djangoproject.com/en/dev/topics/http/middleware/#topics-http-middleware) class to handle some stuff, and I want to set 'g... | 1. It's not the best way. You could set my\_var on the request rather than on the settings. Settings are global and apply to the whole site. You don't want to modify it for every request. There could be concurrency issues with multiple request updating/reading the variable at the same time.
2. To access request.my\_var... |
557,484 | <p>Currently, when I right-click on .DMP (or .MDMP) files, the "Open With" popup has Visual Studio 2005 and 2008 on it. How can I add WinDbg to this list, without removing either of the Visual Studio options?</p>
<p>I've used the "Choose a program" option, and this adds WinDbg to the list. Unfortunately, WinDbg needs ... | [
{
"answer_id": 557489,
"author": "Drew Noakes",
"author_id": 24874,
"author_profile": "https://Stackoverflow.com/users/24874",
"pm_score": 2,
"selected": false,
"text": "<p>On Windows XP, select 'Choose a program...' and navigate to the <code>.exe</code>. Once you've done that, it'll ap... | 2009/02/17 | [
"https://Stackoverflow.com/questions/557484",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8446/"
] | Currently, when I right-click on .DMP (or .MDMP) files, the "Open With" popup has Visual Studio 2005 and 2008 on it. How can I add WinDbg to this list, without removing either of the Visual Studio options?
I've used the "Choose a program" option, and this adds WinDbg to the list. Unfortunately, WinDbg needs some comma... | Try adding (or modifying) the registry entry:
```
HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\FileExts\.dmp\OpenWithList
```
It would need to have the 'windbg.exe. program specified in a value with a single letter name, and with that letter listed in an `MRUList` value also under that key (l... |
557,496 | <p>I was looking around the internet and couldn't find a perfect algorithm for this particular problem:</p>
<p>Our customer have a set of points and weight data along with each point as can be demonstrated by this image:</p>
<p><a href="http://chakrit.net/files/stackoverflow/so_heightmap_points.png" rel="noreferrer">... | [
{
"answer_id": 557573,
"author": "Adam Davis",
"author_id": 2915,
"author_profile": "https://Stackoverflow.com/users/2915",
"pm_score": 2,
"selected": false,
"text": "<blockquote>\n <p>is the algorithm to calculate the\n original function in that picture in\n the first place, provided... | 2009/02/17 | [
"https://Stackoverflow.com/questions/557496",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3055/"
] | I was looking around the internet and couldn't find a perfect algorithm for this particular problem:
Our customer have a set of points and weight data along with each point as can be demonstrated by this image:
[weighted points http://chakrit.net/files/stackoverflow/so\_heightmap\_points.png](http://chakrit.net/files... | What you are looking for is Surface Interpolation.
Some products exist to do this (here's [one](http://www.rockware.com/product/featuresLobby.php?id=193&category=431))
The resulting function/spline/other mathematical construct can then be interrogated at the required resolution to supply the height map.
Your interpo... |
557,523 | <p>I currently have the following lua code:</p>
<pre><code> g = engine.CGeometry()
vertexes = {}
vertexes[1] = 0
vertexes[2] = 0
vertexes[3] = 0
vertexes[4] = 0
vertexes[5] = -1
vertexes[6] = 0
vertexes[7] = -1
vertexes[8] = 0
vertexes[9] = 0
print "adding vertexes"
... | [
{
"answer_id": 557620,
"author": "David Hanak",
"author_id": 42136,
"author_profile": "https://Stackoverflow.com/users/42136",
"pm_score": 1,
"selected": false,
"text": "<p>Try writing:</p>\n\n<pre><code>void CGeometry::SetVertexes(double vertexes[]);\n</code></pre>\n\n<p>in the interfac... | 2009/02/17 | [
"https://Stackoverflow.com/questions/557523",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/57482/"
] | I currently have the following lua code:
```
g = engine.CGeometry()
vertexes = {}
vertexes[1] = 0
vertexes[2] = 0
vertexes[3] = 0
vertexes[4] = 0
vertexes[5] = -1
vertexes[6] = 0
vertexes[7] = -1
vertexes[8] = 0
vertexes[9] = 0
print "adding vertexes"
g:SetVerte... | Try writing:
```
void CGeometry::SetVertexes(double vertexes[]);
```
in the interface defintion. Judging from the documentation, SWIG makes a difference between pointers and arrays. |
557,527 | <p>I am struggling with a sensible logic loop for stripping out nodes from an XML file too large to use with XPath supporting .NET classes.</p>
<p>I am attempting to replace the single line of code I had (that called SelectNodes with an XPath query string) with code that does the same but uses an XmTextReader.</p>
<p... | [
{
"answer_id": 557550,
"author": "Joel Coehoorn",
"author_id": 3043,
"author_profile": "https://Stackoverflow.com/users/3043",
"pm_score": 2,
"selected": false,
"text": "<p>Try loading the file into a dataset:</p>\n\n<pre><code>DataSet ds = new Dataset();\nds.ReadXml(\"C:\\MyXmlFile.xml\... | 2009/02/17 | [
"https://Stackoverflow.com/questions/557527",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/67441/"
] | I am struggling with a sensible logic loop for stripping out nodes from an XML file too large to use with XPath supporting .NET classes.
I am attempting to replace the single line of code I had (that called SelectNodes with an XPath query string) with code that does the same but uses an XmTextReader.
I have to go sev... | I'm adding this as the issue is now dead but the selected solution doesn't match anything listed so far.
Our technical architect took this issue over and decided that we should never have implemented Xml in the first place. This decision was partly due to this issue but also due to some complaints about the level of d... |
557,533 | <p>I am confused as to when I can use the DOM properties and when I could use the Jquery methods on a Jquery object. Say, I use a selector </p>
<pre><code>var $elemSel = $('#myDiv').find('[id *= \'select\']')
</code></pre>
<p>At this point, $elemSel is a jquery object which I understand to be a wrapper around the arr... | [
{
"answer_id": 557539,
"author": "Sampson",
"author_id": 54680,
"author_profile": "https://Stackoverflow.com/users/54680",
"pm_score": 6,
"selected": true,
"text": "<p>You'll need to .get(0) the result to get the DOM-ready object.</p>\n\n<pre><code>var myBox = $(\"div#myBox\");\nalert(my... | 2009/02/17 | [
"https://Stackoverflow.com/questions/557533",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | I am confused as to when I can use the DOM properties and when I could use the Jquery methods on a Jquery object. Say, I use a selector
```
var $elemSel = $('#myDiv').find('[id *= \'select\']')
```
At this point, $elemSel is a jquery object which I understand to be a wrapper around the array of DOM elements. I coul... | You'll need to .get(0) the result to get the DOM-ready object.
```
var myBox = $("div#myBox");
alert(myBox.get(0).id); // "myBox"
```
Read "[Peeling Away the jQuery Wrapper and Finding an Array](http://www.learningjquery.com/2008/12/peeling-away-the-jquery-wrapper)" by Cody Lindley
---
**Re: Edit:** `.is()` is not... |
557,548 | <p>And how do I restore from my dump back to the db?</p>
| [
{
"answer_id": 557557,
"author": "claf",
"author_id": 61838,
"author_profile": "https://Stackoverflow.com/users/61838",
"pm_score": 6,
"selected": true,
"text": "<p>You should have a look at the <a href=\"https://www.postgresql.org/docs/current/app-pgdump.html\" rel=\"nofollow noreferrer... | 2009/02/17 | [
"https://Stackoverflow.com/questions/557548",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/63051/"
] | And how do I restore from my dump back to the db? | You should have a look at the [pg\_dump](https://www.postgresql.org/docs/current/app-pgdump.html) and [pg\_restore](https://www.postgresql.org/docs/current/app-pgrestore.html) commands.
```
pg_dump - extract a PostgreSQL database into a script file or other archive file.
pg_restore - restore a PostgreSQL database fro... |
557,553 | <p>Is there a method/pattern/library to do something like that (in pseudo-code):</p>
<pre><code>task_queue.push_back(ObjectType object1, method1);
task_queue.push_back(OtherObjectType object2, method2);
</code></pre>
<p>so that I could do the <em>something</em> like:</p>
<pre><code>for(int i=0; i<task_queue.size(... | [
{
"answer_id": 557569,
"author": "Doug T.",
"author_id": 8123,
"author_profile": "https://Stackoverflow.com/users/8123",
"pm_score": 4,
"selected": true,
"text": "<p>Yes you would want to combine <a href=\"http://www.boost.org/doc/libs/1_38_0/libs/bind/bind.html\" rel=\"nofollow noreferr... | 2009/02/17 | [
"https://Stackoverflow.com/questions/557553",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/37141/"
] | Is there a method/pattern/library to do something like that (in pseudo-code):
```
task_queue.push_back(ObjectType object1, method1);
task_queue.push_back(OtherObjectType object2, method2);
```
so that I could do the *something* like:
```
for(int i=0; i<task_queue.size(); i++) {
task_queue[i].object -> method();... | Yes you would want to combine [boost::bind](http://www.boost.org/doc/libs/1_38_0/libs/bind/bind.html) and [boost::functions](http://www.boost.org/doc/libs/1_38_0/doc/html/function.html) its very powerful stuff.
**This version now compiles, thanks to Slava!**
```
#include <boost/function.hpp>
#include <boost/bind.hpp>... |
557,555 | <p>In python-mode (for emacs), hitting Control-C\Control-C will execute the current buffer. However, when execution is finished, the output buffer springs up and splits my editing window in half. This is a <em>complete</em> pain, especially given that there's generally no output in the buffer anyway!</p>
<p>Is there... | [
{
"answer_id": 557605,
"author": "Jason Coon",
"author_id": 59753,
"author_profile": "https://Stackoverflow.com/users/59753",
"pm_score": 2,
"selected": false,
"text": "<p>Sorry that I can't help you with emacs, but as for your second question, a modified aluminum keyboard from Apple may... | 2009/02/17 | [
"https://Stackoverflow.com/questions/557555",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/52513/"
] | In python-mode (for emacs), hitting Control-C\Control-C will execute the current buffer. However, when execution is finished, the output buffer springs up and splits my editing window in half. This is a *complete* pain, especially given that there's generally no output in the buffer anyway!
Is there a way to stop the ... | What python-mode are you using? Unfortunately, there are *several*.
Type C-h k and then C-c C-c .. what does it say in the modeline? Does it say "py-execute-buffer" or does it say "python-send-buffer", the first kind indicates you're using Tim Peters' python-mode, while the second indicates you're using Dave Love's py... |
557,559 | <p>I need to draw an image on a panel, containing some child controls. I dont want to let it hide behind those controls, which is the case right now when I'm drawing the image in the <code>Paint</code> event.</p>
<p>Here is the code I used to override the <code>OnPaint</code> method of my panel:</p>
<pre><code>protec... | [
{
"answer_id": 557590,
"author": "casperOne",
"author_id": 50776,
"author_profile": "https://Stackoverflow.com/users/50776",
"pm_score": 2,
"selected": true,
"text": "<p>The <a href=\"http://msdn.microsoft.com/en-us/library/system.windows.forms.control.paint.aspx\" rel=\"nofollow norefer... | 2009/02/17 | [
"https://Stackoverflow.com/questions/557559",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/31159/"
] | I need to draw an image on a panel, containing some child controls. I dont want to let it hide behind those controls, which is the case right now when I'm drawing the image in the `Paint` event.
Here is the code I used to override the `OnPaint` method of my panel:
```
protected override void OnPaint(PaintEventArgs e)... | The [`Paint` event](http://msdn.microsoft.com/en-us/library/system.windows.forms.control.paint.aspx) (or an override of the [`OnPaint` method](http://msdn.microsoft.com/en-us/library/system.windows.forms.control.onpaint.aspx)) is the wrong place to do this kind of thing, because you need to make sure that your painting... |
557,562 | <p>I wrote a PHP extension, and I'm trying to get it running on Mac's Apache server. </p>
<p>It runs fine via the command line, for example:</p>
<pre><code>$ php -r 'dl("mylib.dylib");
</code></pre>
<p>I also tried building Apache from source, and it works perfectly when I run that (I set it up to use the same PHP a... | [
{
"answer_id": 557658,
"author": "Chuck",
"author_id": 50742,
"author_profile": "https://Stackoverflow.com/users/50742",
"pm_score": 3,
"selected": true,
"text": "<p>This sounds like the sort of error that would be caused by architecture differences. Try doing a <code>file /usr/lib/php/e... | 2009/02/17 | [
"https://Stackoverflow.com/questions/557562",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4243/"
] | I wrote a PHP extension, and I'm trying to get it running on Mac's Apache server.
It runs fine via the command line, for example:
```
$ php -r 'dl("mylib.dylib");
```
I also tried building Apache from source, and it works perfectly when I run that (I set it up to use the same PHP as Mac's built-in Apache, too, so ... | This sounds like the sort of error that would be caused by architecture differences. Try doing a `file /usr/lib/php/extensions/mylib.dylib` and see which architectures are included in the binary. IIRC, Apache runs as 64-bit on Leopard, so you'll need to make sure that your library includes code for the 64-bit version o... |
557,570 | <p>I have a requirement to build 'versioning' into an application and was wondering how best to approach it. </p>
<p>I have this general pattern:</p>
<p>Model A has many B's</p>
<p>Where on update the attributes of A need to be versioned and its associated objects (B's) also need to be versioned. So the application ... | [
{
"answer_id": 557595,
"author": "Kosi2801",
"author_id": 57601,
"author_profile": "https://Stackoverflow.com/users/57601",
"pm_score": 1,
"selected": false,
"text": "<p>A combination of the <a href=\"http://en.wikipedia.org/wiki/Memento_pattern\" rel=\"nofollow noreferrer\">Memento patt... | 2009/02/17 | [
"https://Stackoverflow.com/questions/557570",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/21596/"
] | I have a requirement to build 'versioning' into an application and was wondering how best to approach it.
I have this general pattern:
Model A has many B's
Where on update the attributes of A need to be versioned and its associated objects (B's) also need to be versioned. So the application will display the current... | I don't think there is no specific GoF design pattern per se for versioning because there exists many implementations of it.
The most simple implementation of versioning is a linked list of objects. Where each node in the list is a new revision of whatever the versionable object is. To save space you also implement s... |
557,574 | <p>If we look at the Java Object class then we can find some of the methods like:</p>
<pre><code>public native int hashCode()
protected native Object clone()
</code></pre>
<p>What are these natives and how do these methods work?</p>
| [
{
"answer_id": 557591,
"author": "Sunlight",
"author_id": 33650,
"author_profile": "https://Stackoverflow.com/users/33650",
"pm_score": 0,
"selected": false,
"text": "<p>Native methods in Java are implemented using the '<a href=\"http://java.sun.com/docs/books/jni/\" rel=\"nofollow noref... | 2009/02/17 | [
"https://Stackoverflow.com/questions/557574",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13240/"
] | If we look at the Java Object class then we can find some of the methods like:
```
public native int hashCode()
protected native Object clone()
```
What are these natives and how do these methods work? | These methods are either *Intrinsic* or written outside Java in "native" code, that is, specific to the given machine.
The ones you mention are *Intrinsic* and part of the JDK but you can also write native methods yourself using the [Java Native Interface](http://java.sun.com/docs/books/jni/) (JNI). This would normal... |
557,582 | <p>In <code>observeValueForKeyPath:ofObject:change:context:</code> - why do the docs use <code>NULL</code> instead of <code>nil</code> when not specifying a context pointer?</p>
| [
{
"answer_id": 557607,
"author": "Marc Charbonneau",
"author_id": 35136,
"author_profile": "https://Stackoverflow.com/users/35136",
"pm_score": 6,
"selected": false,
"text": "<p>They're technically the same thing (0), but nil is usually used for an Objective-C object type, while NULL is ... | 2009/02/17 | [
"https://Stackoverflow.com/questions/557582",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18278/"
] | In `observeValueForKeyPath:ofObject:change:context:` - why do the docs use `NULL` instead of `nil` when not specifying a context pointer? | `nil` should only be used in place of an `id`, what we Java and C++ programmers would think of as a pointer to an object. Use `NULL` for non-object pointers.
Look at the declaration of that method:
```
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object
change:(NSDictionary *)change context:(vo... |
557,596 | <p>I am creating a web application that acts as a priority list, allowing a user to re-arrange a set of items in a list and storing that arrangement in a MySQL database via a PHP backend.</p>
<p>At the moment, when the user has finished arranging their items and saves the configuration, I am calling a seperate UPDATE ... | [
{
"answer_id": 557607,
"author": "Marc Charbonneau",
"author_id": 35136,
"author_profile": "https://Stackoverflow.com/users/35136",
"pm_score": 6,
"selected": false,
"text": "<p>They're technically the same thing (0), but nil is usually used for an Objective-C object type, while NULL is ... | 2009/02/17 | [
"https://Stackoverflow.com/questions/557596",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/67446/"
] | I am creating a web application that acts as a priority list, allowing a user to re-arrange a set of items in a list and storing that arrangement in a MySQL database via a PHP backend.
At the moment, when the user has finished arranging their items and saves the configuration, I am calling a seperate UPDATE statement ... | `nil` should only be used in place of an `id`, what we Java and C++ programmers would think of as a pointer to an object. Use `NULL` for non-object pointers.
Look at the declaration of that method:
```
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object
change:(NSDictionary *)change context:(vo... |
557,598 | <p>I use <a href="http://simplehtmldom.sourceforge.net/" rel="nofollow noreferrer">Simple HTML DOM</a> to scrape a page for the latest news, and then generate an RSS feed using this <a href="http://www.phpclasses.org/browse/package/4427.html" rel="nofollow noreferrer">PHP class</a>.</p>
<p>This what I have now:</p>
<... | [
{
"answer_id": 557638,
"author": "Parrots",
"author_id": 65763,
"author_profile": "https://Stackoverflow.com/users/65763",
"pm_score": 3,
"selected": true,
"text": "<p>Well for just a simple combination of the two loops you could create the feed as your parse through the HTML:</p>\n\n<pr... | 2009/02/17 | [
"https://Stackoverflow.com/questions/557598",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/64949/"
] | I use [Simple HTML DOM](http://simplehtmldom.sourceforge.net/) to scrape a page for the latest news, and then generate an RSS feed using this [PHP class](http://www.phpclasses.org/browse/package/4427.html).
This what I have now:
```
<?php
// This is a minimum example of using the class
include("FeedWriter.php");
... | Well for just a simple combination of the two loops you could create the feed as your parse through the HTML:
```
<?php
include("FeedWriter.php");
include('simple_html_dom.php');
$html = file_get_html('http://www.website.com');
//Creating an instance of FeedWriter class.
$TestFeed = new FeedWriter(RSS2);
$TestFeed-... |
557,621 | <p>Is there any way to have a map's placemark call a javascript method on the page that contains the map.</p>
<p>For example:
Say we have a google map that has pins for our customers. If the sales operator clicks on the pin of CompanyA, could the containing page use javascript to identify that ConpanyA's pin had been ... | [
{
"answer_id": 557625,
"author": "Jared Updike",
"author_id": 2543,
"author_profile": "https://Stackoverflow.com/users/2543",
"pm_score": 0,
"selected": false,
"text": "<p>I believe you put arbitrary HTML into the pin's popup with the Google Maps AJAX API. I know I can put an anchor tag ... | 2009/02/17 | [
"https://Stackoverflow.com/questions/557621",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15710/"
] | Is there any way to have a map's placemark call a javascript method on the page that contains the map.
For example:
Say we have a google map that has pins for our customers. If the sales operator clicks on the pin of CompanyA, could the containing page use javascript to identify that ConpanyA's pin had been clicked. A... | Yes, you can hook up an event to the marker (I use the Marker Manager).
```
GEvent.addListener(marker,'click',function(){..your code..})
```
See the api doc here: <http://code.google.com/apis/maps/documentation/reference.html#GMarker> (scroll down to the "Events" section). |
557,626 | <p>The solution to this is probably very simple, but I'm not sure what I'm missing. Here's what I have, and <code>PropertyPlaceholderConfigurer</code> won't replace the <code>${...}</code>.</p>
<pre><code>/* ---- org/company/springtest/Test.java: ---- */
package org.company.springtest;
import org.springframework.bea... | [
{
"answer_id": 557633,
"author": "cliff.meyers",
"author_id": 41754,
"author_profile": "https://Stackoverflow.com/users/41754",
"pm_score": 4,
"selected": true,
"text": "<p>Perhaps try using an <code>ApplicationContext</code> instead of a <code>BeanFactory</code>?</p>\n"
},
{
"an... | 2009/02/17 | [
"https://Stackoverflow.com/questions/557626",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10675/"
] | The solution to this is probably very simple, but I'm not sure what I'm missing. Here's what I have, and `PropertyPlaceholderConfigurer` won't replace the `${...}`.
```
/* ---- org/company/springtest/Test.java: ---- */
package org.company.springtest;
import org.springframework.beans.factory.xml.XmlBeanFactory;
import... | Perhaps try using an `ApplicationContext` instead of a `BeanFactory`? |
557,643 | <p>So I have a PropertyBag class that is intended to implement INotifyPropertyChanged. In order to make this code work as cleanly as possible and to avoid user error, I am using the stack to get the property name. See, if the property name doesn't match the actual property exactly, then you will have a failure and I ... | [
{
"answer_id": 557665,
"author": "Marc Gravell",
"author_id": 23354,
"author_profile": "https://Stackoverflow.com/users/23354",
"pm_score": 5,
"selected": true,
"text": "<p>Using the stack here is slow and unnecessary; I would simply use:</p>\n\n<pre><code>get { return GetProperty<int... | 2009/02/17 | [
"https://Stackoverflow.com/questions/557643",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/36687/"
] | So I have a PropertyBag class that is intended to implement INotifyPropertyChanged. In order to make this code work as cleanly as possible and to avoid user error, I am using the stack to get the property name. See, if the property name doesn't match the actual property exactly, then you will have a failure and I am tr... | Using the stack here is slow and unnecessary; I would simply use:
```
get { return GetProperty<int>("Foo"); }
set { SetProperty("Foo", value); }
```
(hint: I've done a lot of work with custom property models; I know that this works well...)
Another alternative is an object key (use reference equality to compare) - ... |
557,653 | <p>I'm running a cronjob which needs to write data to a cache. I wanted to put this cronjob in my private folder, however, even after CHMODding the cache folder in the private folder, it's not getting writing rights. This seems to be somekind of plesk feature.</p>
<p>So, now I've placed the cronjob in the public folde... | [
{
"answer_id": 557678,
"author": "jonstjohn",
"author_id": 67009,
"author_profile": "https://Stackoverflow.com/users/67009",
"pm_score": 2,
"selected": false,
"text": "<p>First, I would keep the executable PHP script in a private directory that can only be executed by the privileged user... | 2009/02/17 | [
"https://Stackoverflow.com/questions/557653",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/45974/"
] | I'm running a cronjob which needs to write data to a cache. I wanted to put this cronjob in my private folder, however, even after CHMODding the cache folder in the private folder, it's not getting writing rights. This seems to be somekind of plesk feature.
So, now I've placed the cronjob in the public folder. However... | Execute the script via the console, not the web server.
The cron could look like this:
```
*/5 * * * * php -f /path/to/cron.php
```
Then the file could do this:
```
cron.php:
<?php
if ( array_key_exists('REMOTE_ADDR', $_SERVER) )
die("Can only be run from the command line!");
```
That will guarantee it's on... |
557,661 | <p>I'm working on a VS2008 Smart Device app that includes a Smart Device CAB Project for deployment. I was surprised to find out that this installer project doesn't install the .NET Compact Framework if necessary. Can it be made to do so?</p>
| [
{
"answer_id": 557678,
"author": "jonstjohn",
"author_id": 67009,
"author_profile": "https://Stackoverflow.com/users/67009",
"pm_score": 2,
"selected": false,
"text": "<p>First, I would keep the executable PHP script in a private directory that can only be executed by the privileged user... | 2009/02/17 | [
"https://Stackoverflow.com/questions/557661",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4228/"
] | I'm working on a VS2008 Smart Device app that includes a Smart Device CAB Project for deployment. I was surprised to find out that this installer project doesn't install the .NET Compact Framework if necessary. Can it be made to do so? | Execute the script via the console, not the web server.
The cron could look like this:
```
*/5 * * * * php -f /path/to/cron.php
```
Then the file could do this:
```
cron.php:
<?php
if ( array_key_exists('REMOTE_ADDR', $_SERVER) )
die("Can only be run from the command line!");
```
That will guarantee it's on... |
557,663 | <p>Given 2 interfaces:</p>
<pre><code>public interface BaseInterface<T> { }
public interface ExtendedInterface<T0, T1> extends BaseInterface<T0> {}
</code></pre>
<p>and a concrete class:</p>
<pre><code>public class MyClass implements ExtendedInterface<String, Object> { }
</code></pre>
<p>How... | [
{
"answer_id": 557794,
"author": "Rob Di Marco",
"author_id": 24195,
"author_profile": "https://Stackoverflow.com/users/24195",
"pm_score": 0,
"selected": false,
"text": "<p>I don't think you can as these are really instance specific not class specific. Consider the following:</p>\n\n<p... | 2009/02/17 | [
"https://Stackoverflow.com/questions/557663",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/45062/"
] | Given 2 interfaces:
```
public interface BaseInterface<T> { }
public interface ExtendedInterface<T0, T1> extends BaseInterface<T0> {}
```
and a concrete class:
```
public class MyClass implements ExtendedInterface<String, Object> { }
```
How do I find out the type parameter passed to the BaseInterface interface?
... | This problem is not easy to fully solve in general. For example, you also have to take type parameters of the containing class into account if it's an inner class,...
Because reflection over generic types is so hard using just what Java itself provides, I wrote a library that does the hard work: gentyref. See <http://... |
557,664 | <p>In Asp.Net Combobox, there is a useful property, <code>AppendDataBoundItems</code>, that causes whatever items are bound to the control to be actually appended to whatever "statically" added ad design time. This is useful for "default" values that the user can specify when no item in the available ones meet the crit... | [
{
"answer_id": 557794,
"author": "Rob Di Marco",
"author_id": 24195,
"author_profile": "https://Stackoverflow.com/users/24195",
"pm_score": 0,
"selected": false,
"text": "<p>I don't think you can as these are really instance specific not class specific. Consider the following:</p>\n\n<p... | 2009/02/17 | [
"https://Stackoverflow.com/questions/557664",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | In Asp.Net Combobox, there is a useful property, `AppendDataBoundItems`, that causes whatever items are bound to the control to be actually appended to whatever "statically" added ad design time. This is useful for "default" values that the user can specify when no item in the available ones meet the criteria, or to sp... | This problem is not easy to fully solve in general. For example, you also have to take type parameters of the containing class into account if it's an inner class,...
Because reflection over generic types is so hard using just what Java itself provides, I wrote a library that does the hard work: gentyref. See <http://... |
557,676 | <p>In Objective-C, you can change an object's dynamic type at runtime by assigning to it's <code>isa</code> member variable:</p>
<pre><code>id object = ...;
object->isa = [SomeClass class];
</code></pre>
<p>Is this undefined behavior? I'm currently doing this as a kludge for something else, and it appears to be w... | [
{
"answer_id": 557725,
"author": "Darron",
"author_id": 22704,
"author_profile": "https://Stackoverflow.com/users/22704",
"pm_score": 1,
"selected": false,
"text": "<p>I think this is, as you say, dirty.</p>\n\n<p>I suspect it will work if:</p>\n\n<ul>\n<li>The newly assigned class is a ... | 2009/02/17 | [
"https://Stackoverflow.com/questions/557676",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9530/"
] | In Objective-C, you can change an object's dynamic type at runtime by assigning to it's `isa` member variable:
```
id object = ...;
object->isa = [SomeClass class];
```
Is this undefined behavior? I'm currently doing this as a kludge for something else, and it appears to be working, but I feel so dirty doing it this... | I think this is, as you say, dirty.
I suspect it will work if:
* The newly assigned class is a subclass of the real class.
* The new class doesn't add any member variables.
But I'll admit I don't know the nuts-and-bolts implementation of your Objective-C runtime system. I just know what makes sense to me for an impl... |
557,682 | <p>I'm trying to search a document for data on a specific column. I am trying to use:</p>
<pre><code>^.{x}[data to find]
</code></pre>
<p>where x is the number of columns I want - 1.</p>
<p>I'm not sure if I am doing something wrong, or if my regex engine does not support that syntax. I am trying to use Notepad++, i... | [
{
"answer_id": 557706,
"author": "Welbog",
"author_id": 52443,
"author_profile": "https://Stackoverflow.com/users/52443",
"pm_score": 0,
"selected": false,
"text": "<p>Awk is much more suited to this kind of task if you have access to it.</p>\n\n<p>It doesn't look like notepad++ has a {x... | 2009/02/17 | [
"https://Stackoverflow.com/questions/557682",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2871/"
] | I'm trying to search a document for data on a specific column. I am trying to use:
```
^.{x}[data to find]
```
where x is the number of columns I want - 1.
I'm not sure if I am doing something wrong, or if my regex engine does not support that syntax. I am trying to use Notepad++, if that is helpful. | Update 2013-2014 (4-5 years later)
As mentioned by [Alan Moore](https://stackoverflow.com/users/20938/alan-moore) in [the comments](https://stackoverflow.com/questions/557682/regex-to-find-data-in-specific-column-of-a-line/557975?noredirect=1#comment35837800_557975)
>
> [Notepad++ v6.x](http://notepad-plus-plus.org/... |
557,695 | <p>Does anybody have a regular expression that would work to limit the number of words in a response? For instance, I'd like to use it with jQuery validate so I can restrict a textbox/textarea to have say 250 words. The boxes will be plain-text.</p>
<p>I've done some Googling but none of the ones I've found were very ... | [
{
"answer_id": 557712,
"author": "Jay Kominek",
"author_id": 32878,
"author_profile": "https://Stackoverflow.com/users/32878",
"pm_score": 2,
"selected": false,
"text": "<p>How about splitting the text with a regex (say \"\\s+\") and then counting the length of the resulting list? That w... | 2009/02/17 | [
"https://Stackoverflow.com/questions/557695",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/62686/"
] | Does anybody have a regular expression that would work to limit the number of words in a response? For instance, I'd like to use it with jQuery validate so I can restrict a textbox/textarea to have say 250 words. The boxes will be plain-text.
I've done some Googling but none of the ones I've found were very good. They... | Could you try:
```
^(?:\b\w+\b[\s\r\n]*){1,250}$
```
That would limit to 250 words over multiple lines.
I am afraid that the Alan's initial proposition:
```
/^\w+(?:\s+\w+){0,249}$/
```
might be a case of [**catastrophic backtracking**](http://www.regular-expressions.info/catastrophic.html)
>
> When nesting re... |
557,713 | <p>I've developed a .net 3.0 application, which is deployed using clickonce.</p>
<p>I'd like to move from full trust to partial trust to ease deployment.</p>
<p>I've tried the "Calculate Permissions" tool in the "Security" tab of my project under visual studio, and the answer is quite clear :</p>
<pre><code>--------... | [
{
"answer_id": 557723,
"author": "Jeffrey Cameron",
"author_id": 61344,
"author_profile": "https://Stackoverflow.com/users/61344",
"pm_score": 0,
"selected": false,
"text": "<p>Hrm, just a guess, but is it running off of a network share? .NET seems to assign trust based on the location t... | 2009/02/17 | [
"https://Stackoverflow.com/questions/557713",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/47341/"
] | I've developed a .net 3.0 application, which is deployed using clickonce.
I'd like to move from full trust to partial trust to ease deployment.
I've tried the "Calculate Permissions" tool in the "Security" tab of my project under visual studio, and the answer is quite clear :
```
---------------------------
Microsof... | Adding the requirePermission='false' attribute in the app.config's configsections helps a lot :
```
<sectionGroup name="system.net" type="System.Net.Configuration.NetSectionGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section requirePermission="false" name="defaultProxy" t... |
557,728 | <p>I'm using Classic ASP and a bit of AJAX to post the contents of a form back to the page on which the AJAX form lives. Upon AJAX POST the page saves one of those fields (email, to be specific) into a Session variable. The user then goes about their business - perhaps requesting the page again via normal HTTP.</p>
<p... | [
{
"answer_id": 557723,
"author": "Jeffrey Cameron",
"author_id": 61344,
"author_profile": "https://Stackoverflow.com/users/61344",
"pm_score": 0,
"selected": false,
"text": "<p>Hrm, just a guess, but is it running off of a network share? .NET seems to assign trust based on the location t... | 2009/02/17 | [
"https://Stackoverflow.com/questions/557728",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/67457/"
] | I'm using Classic ASP and a bit of AJAX to post the contents of a form back to the page on which the AJAX form lives. Upon AJAX POST the page saves one of those fields (email, to be specific) into a Session variable. The user then goes about their business - perhaps requesting the page again via normal HTTP.
However, ... | Adding the requirePermission='false' attribute in the app.config's configsections helps a lot :
```
<sectionGroup name="system.net" type="System.Net.Configuration.NetSectionGroup, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<section requirePermission="false" name="defaultProxy" t... |
557,730 | <p>I am currently deploying my application built using RC of MVC ASP.NET on the production server which is showing nothing now.
The routes in my global.ascx are typical i.e. </p>
<pre><code>routes.MapRoute(
"Default", // Route name
"{controller}.asp... | [
{
"answer_id": 557772,
"author": "Jason",
"author_id": 1338,
"author_profile": "https://Stackoverflow.com/users/1338",
"pm_score": 0,
"selected": false,
"text": "<p>What's the server environment? If it's not IIS7/Server 2008 there are other tweaks you have to do to get the routing to wo... | 2009/02/17 | [
"https://Stackoverflow.com/questions/557730",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17519/"
] | I am currently deploying my application built using RC of MVC ASP.NET on the production server which is showing nothing now.
The routes in my global.ascx are typical i.e.
```
routes.MapRoute(
"Default", // Route name
"{controller}.aspx/{action}/{id... | I solved the issue, the major issue was the different versions of MVC framework. Production Server was having MVC Beta while i have installed MVC RC1. So as soon as i installed the RC1 on the server as well as run the mvc extension registeration scripts, everything worked Thanks for your help guys |
557,734 | <p>I'm building this report in a system for a Billboard company.
They have a table that stores all their billboards, and among other data, billboards have a Start Date and a Finish Date (both can be null).<br>
If for some reason a billboard has to stop beeing used, they set a finish date and it will become unnavaiable ... | [
{
"answer_id": 557807,
"author": "Barry",
"author_id": 62895,
"author_profile": "https://Stackoverflow.com/users/62895",
"pm_score": 3,
"selected": true,
"text": "<p>Don't know if this is what you're looking for, but could be a step in the right direction.</p>\n\n<pre><code>SELECT \n S... | 2009/02/17 | [
"https://Stackoverflow.com/questions/557734",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9835/"
] | I'm building this report in a system for a Billboard company.
They have a table that stores all their billboards, and among other data, billboards have a Start Date and a Finish Date (both can be null).
If for some reason a billboard has to stop beeing used, they set a finish date and it will become unnavaiable to b... | Don't know if this is what you're looking for, but could be a step in the right direction.
```
SELECT
SUM(CASE WHEN
(StartDate IS NULL OR StartDate <= '2009-01-05 00:00:00')
AND (FinishDate IS NULL OR FinishDate >= '2009-01-05 00:00:00')
THEN 1
ELSE 0 END)) Week1Count,
SUM(CASE WHEN
(Star... |
557,767 | <p>I have noticed a few times when working on legacy code, that you can do left and right outer joins in sql by using the </p>
<pre><code>=*
</code></pre>
<p>as kind of shorthand for "right outer join" and</p>
<pre><code>*=
</code></pre>
<p>as kind of shorthand for "left outer join" in statements like this:</p>
<p... | [
{
"answer_id": 557789,
"author": "James",
"author_id": 56753,
"author_profile": "https://Stackoverflow.com/users/56753",
"pm_score": 5,
"selected": true,
"text": "<p>The =* and *= are not complaint with current SQL standards, I believe these operators will be deprecated soon you should a... | 2009/02/17 | [
"https://Stackoverflow.com/questions/557767",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/57855/"
] | I have noticed a few times when working on legacy code, that you can do left and right outer joins in sql by using the
```
=*
```
as kind of shorthand for "right outer join" and
```
*=
```
as kind of shorthand for "left outer join" in statements like this:
```
select table1.firstname, table2.lastname
from table... | The =\* and \*= are not complaint with current SQL standards, I believe these operators will be deprecated soon you should always use the standard join syntax. The other operators that you mention are confusing and need to go away, I cringe when I see these in database objects. |
557,778 | <p>I have an index.php with the following js function:</p>
<pre><code>function returnImageString() {
return "<?php include 'inc/image.functions.php'; echo getRandomImages(7); ?>"; //This isn't dynamic; this will always return the same images. How do I fix this?
}
</code></pre>
<p>However, when the p... | [
{
"answer_id": 557786,
"author": "troelskn",
"author_id": 18180,
"author_profile": "https://Stackoverflow.com/users/18180",
"pm_score": -1,
"selected": false,
"text": "<p>That is commonly known as Ajax. Google for it.</p>\n"
},
{
"answer_id": 557793,
"author": "nickohrn",
... | 2009/02/17 | [
"https://Stackoverflow.com/questions/557778",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/67183/"
] | I have an index.php with the following js function:
```
function returnImageString() {
return "<?php include 'inc/image.functions.php'; echo getRandomImages(7); ?>"; //This isn't dynamic; this will always return the same images. How do I fix this?
}
```
However, when the page loads, the php script is cal... | This is not possible because you're mixing client-side behavior with server-side behavior. What you need to do is create an AJAX request to the server.
If you were using a library like [jQuery](http://www.jquery.com) (which you really want to, because it makes AJAX a breeze) you would do something like this:
PHP Code... |
557,785 | <p>I am adding "Tagging" functionality in my web app. My applications table structures are as following;</p>
<p><code>Tag:</code> </p>
<pre><code>(TagId INT IDENTITY, TagName VARCHAR(60))
</code></pre>
<p><code>TaggedRecords:</code></p>
<pre><code>(TaggedId INT IDENTITY, TagId, TaggedRecordId)
</code></pre>
<p>Now... | [
{
"answer_id": 557814,
"author": "shahkalpesh",
"author_id": 23574,
"author_profile": "https://Stackoverflow.com/users/23574",
"pm_score": 0,
"selected": false,
"text": "<p>May I ask why? Is there a limit on if/else? :)</p>\n\n<p>Looking at your case, it doesn't look like it will need mo... | 2009/02/17 | [
"https://Stackoverflow.com/questions/557785",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/45261/"
] | I am adding "Tagging" functionality in my web app. My applications table structures are as following;
`Tag:`
```
(TagId INT IDENTITY, TagName VARCHAR(60))
```
`TaggedRecords:`
```
(TaggedId INT IDENTITY, TagId, TaggedRecordId)
```
Now, I want when anyone adds a tag to any record then following action should be ... | How about this...
```
CREATE PROC TagMe(@TagName VARCHAR(100),@TaggedRecordId INT)
AS
DECLARE @TagId INT
SET @TagId = SELECT TagId FROM Tag WHERE TagName = @TagName
IF @TagId IS NOT NULL
BEGIN
--Tag exists
INSERT INTO TaggedRecords (TagId, TaggedRecordId) VALUES(@TagId,@TaggedRecordId)
RETURN
... |
557,800 | <p>I want to be able to determine the output folder based on the platform name: AS3, AS4, AS5, SUN. </p>
<p>I couldn't figure out how to extract the platform name from the system. I experimented with:</p>
<pre><code>uname -a
file /bin/bash
</code></pre>
<p>Thanks</p>
<p><strong>Solution</strong></p>
<p>./lsb_rele... | [
{
"answer_id": 557837,
"author": "David Grant",
"author_id": 40581,
"author_profile": "https://Stackoverflow.com/users/40581",
"pm_score": 2,
"selected": false,
"text": "<p>I think you'll have to look in a specific file for each OS. For example, on SunOS, you can type:</p>\n\n<pre><code... | 2009/02/17 | [
"https://Stackoverflow.com/questions/557800",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | I want to be able to determine the output folder based on the platform name: AS3, AS4, AS5, SUN.
I couldn't figure out how to extract the platform name from the system. I experimented with:
```
uname -a
file /bin/bash
```
Thanks
**Solution**
./lsb\_release -a
Kudos to Paul Dixon | Some linux systems will have support for [lsb\_release](http://refspecs.freestandards.org/LSB_3.1.0/LSB-Core-generic/LSB-Core-generic/lsbrelease.html) |
557,811 | <p>I'm trying to read a Paradox 7.x .db file in a .Net 3.5 app and I'm not being successful on that.</p>
<p>First of all, when I'm registering the odbc, as a user or system dsn, the Microsoft Paradox ODBC Driver only display versions up to 5.x, so it looks like that it does not support Paradox version 7.x.</p>
<p>At ... | [
{
"answer_id": 557831,
"author": "casperOne",
"author_id": 50776,
"author_profile": "https://Stackoverflow.com/users/50776",
"pm_score": 0,
"selected": false,
"text": "<p>Curious, why not use the OLEDB provider and then use the classes in the System.Data.OleDb namepsace?</p>\n"
},
{
... | 2009/02/17 | [
"https://Stackoverflow.com/questions/557811",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11099/"
] | I'm trying to read a Paradox 7.x .db file in a .Net 3.5 app and I'm not being successful on that.
First of all, when I'm registering the odbc, as a user or system dsn, the Microsoft Paradox ODBC Driver only display versions up to 5.x, so it looks like that it does not support Paradox version 7.x.
At [connectionsstrin... | <http://www.progware.org/Blog/post/Connecting-to-a-PARADOX-DB-with-C-%28Vista-XP%29.aspx>
and
```
ConnectionString.Append(@"Provider=Microsoft.Jet.OLEDB.4.0;");
ConnectionString.Append(@"Extended Properties=Paradox 7.x;");
ConnectionString.Append(@"Data Source=Z:\Dane;");
//ConnectionString.Append(@"Mode=ReadWrite;")... |
557,819 | <p>I'm trying to build some code for dynamically sorting a Linq IQueryable<>.</p>
<p>The obvious way is here, which sorts a list using a string for the field name<br>
<a href="http://dvanderboom.wordpress.com/2008/12/19/dynamically-composing-linq-orderby-clauses/" rel="noreferrer">http://dvanderboom.wordpress.com/2... | [
{
"answer_id": 560161,
"author": "David Wengier",
"author_id": 489,
"author_profile": "https://Stackoverflow.com/users/489",
"pm_score": 5,
"selected": true,
"text": "<p>The easiest way to do this would be to have your AddSort() function take an Expression<Func<Movie>> instead of j... | 2009/02/17 | [
"https://Stackoverflow.com/questions/557819",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/67468/"
] | I'm trying to build some code for dynamically sorting a Linq IQueryable<>.
The obvious way is here, which sorts a list using a string for the field name
<http://dvanderboom.wordpress.com/2008/12/19/dynamically-composing-linq-orderby-clauses/>
However I want one change - compile time checking of field names, and th... | The easiest way to do this would be to have your AddSort() function take an Expression<Func<Movie>> instead of just a Func. This allows your sort method to inspect the Expression to extract out the name of the property that you want to sort on. You can then store this name internally as a string, so storing is very eas... |
557,836 | <p>In my project I have a number of pages. Each page is a panel with a number of usercontrols contained within. I would like to have a thumbnail image of the yet to be displayed panel and it's contents. How do I go about doing this.</p>
<p>Thanks</p>
| [
{
"answer_id": 557867,
"author": "Adam Haile",
"author_id": 194,
"author_profile": "https://Stackoverflow.com/users/194",
"pm_score": 0,
"selected": false,
"text": "<p>Not sure exactly how to get the image, but you can still update controls (or a form) without the them being visible. Bu... | 2009/02/17 | [
"https://Stackoverflow.com/questions/557836",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/54009/"
] | In my project I have a number of pages. Each page is a panel with a number of usercontrols contained within. I would like to have a thumbnail image of the yet to be displayed panel and it's contents. How do I go about doing this.
Thanks | Perhaps the DrawToBitmap function of the panel would work for this purpose.
Something to the effect of:
```
Bitmap bmp = new Bitmap(panel.Bounds.Width, panel.Bounds.Height);
panel.DrawToBitmap(bmp, panel.ClientRectangle);
bmp.Save("c:\\test.bmp");
bmp.Dispose();
```
**Edit** - Updated to more appropriate sample co... |
557,844 | <p>I'm wondering what techniques and/or library to use to implement the functionality of the linux command "tail -f ". I'm essentially looking for a drop in add-on/replacement for <code>java.io.FileReader</code>. Client code could look something like this:</p>
<pre><code>TailFileReader lft = new TailFileReader("appl... | [
{
"answer_id": 558262,
"author": "matt b",
"author_id": 4249,
"author_profile": "https://Stackoverflow.com/users/4249",
"pm_score": 6,
"selected": true,
"text": "<p>The ability to continue to read a file, and wait around until the file has some more updates for you shouldn't be that hard... | 2009/02/17 | [
"https://Stackoverflow.com/questions/557844",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/52563/"
] | I'm wondering what techniques and/or library to use to implement the functionality of the linux command "tail -f ". I'm essentially looking for a drop in add-on/replacement for `java.io.FileReader`. Client code could look something like this:
```
TailFileReader lft = new TailFileReader("application.log");
BufferedRead... | The ability to continue to read a file, and wait around until the file has some more updates for you shouldn't be that hard to accomplish in code yourself. Here's some pseudo-code:
```
BufferedReader br = new BufferedReader(...);
String line;
while (keepReading) {
line = reader.readLine();
if (line == null) {
... |
557,898 | <p>I plan to create a method that would format a Time in a specific way (specialized formatting in Russian).</p>
<p>I would like to reuse this helper method in multiple models, controllers and possibly views. Also I would like to call this helper method on instance of Time class like follows:</p>
<pre><code>t=Time.no... | [
{
"answer_id": 557910,
"author": "Alex Wayne",
"author_id": 62076,
"author_profile": "https://Stackoverflow.com/users/62076",
"pm_score": 4,
"selected": true,
"text": "<p>I would add a file to <code>lib/time_extensions.rb</code></p>\n\n<pre><code>class Time\n def my_shiny_helper\n ..... | 2009/02/17 | [
"https://Stackoverflow.com/questions/557898",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/430254/"
] | I plan to create a method that would format a Time in a specific way (specialized formatting in Russian).
I would like to reuse this helper method in multiple models, controllers and possibly views. Also I would like to call this helper method on instance of Time class like follows:
```
t=Time.now
t.my_super_shiny_he... | I would add a file to `lib/time_extensions.rb`
```
class Time
def my_shiny_helper
...
end
end
```
And in an initializer file in `config/intitializers`
```
require 'time_extensions'
```
If the extensions grow a bit and are something you want to reuse think of putting it into a plugin for easy inclusion. Or... |
557,903 | <p>I am using the following code to play a sound file using the java sound API.</p>
<pre><code> Clip clip = AudioSystem.getClip();
AudioInputStream inputStream = AudioSystem.getAudioInputStream(stream);
clip.open(inputStream);
clip.start();
</code></pre>
<p>The method call to the Clip.start() method re... | [
{
"answer_id": 557951,
"author": "Uri",
"author_id": 23072,
"author_profile": "https://Stackoverflow.com/users/23072",
"pm_score": 4,
"selected": true,
"text": "<p>A sound clip is a type or Line and therefore supports Line listeners.</p>\n\n<p>If you use addLineListener, you should get e... | 2009/02/17 | [
"https://Stackoverflow.com/questions/557903",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19331/"
] | I am using the following code to play a sound file using the java sound API.
```
Clip clip = AudioSystem.getClip();
AudioInputStream inputStream = AudioSystem.getAudioInputStream(stream);
clip.open(inputStream);
clip.start();
```
The method call to the Clip.start() method returns immediately, and the... | A sound clip is a type or Line and therefore supports Line listeners.
If you use addLineListener, you should get events when play starts and stops; if you're not in a loop, you should get a stop when the clip ends. However, as with any events, there might be a lag before the actual end of playback and the stopping.
M... |
557,906 | <p>I have a pretty usual requirement with procmail but I am unable to get the results somehow. I have procmailrc file with this content:</p>
<pre><code>:0
* ^To.*@myhost
| /usr/bin/python /work/scripts/privilege_emails_forward.py
</code></pre>
<p>Wherein my custom python script(privilege_emails_forward.py) will be sc... | [
{
"answer_id": 557932,
"author": "Johannes Weiss",
"author_id": 55925,
"author_profile": "https://Stackoverflow.com/users/55925",
"pm_score": 5,
"selected": true,
"text": "<p>That is just fine, just put <code>fw</code> after <code>:0</code> (<code>:0 fw</code>). Your python program will ... | 2009/02/17 | [
"https://Stackoverflow.com/questions/557906",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/45629/"
] | I have a pretty usual requirement with procmail but I am unable to get the results somehow. I have procmailrc file with this content:
```
:0
* ^To.*@myhost
| /usr/bin/python /work/scripts/privilege_emails_forward.py
```
Wherein my custom python script(privilege\_emails\_forward.py) will be scanning through the email... | That is just fine, just put `fw` after `:0` (`:0 fw`). Your python program will receive the mail on `stdin`. You have to 'echo' the possibly transformed mail on `stdout`.
`fw` means:
* `f` Consider the pipe as a filter.
* `w` Wait for the filter or program to finish and check its exitcode (normally ignored); if the f... |
557,909 | <p>I´m trying to break a number into an array of numbers (in php) in the way that for example:</p>
<ul>
<li>25 becomes (16, 8, 1)</li>
<li>8 becomes (8)</li>
<li>11 becomes (8, 2, 1)</li>
</ul>
<p>I don´t know what the correct term is, but I think the idea is clear.</p>
<p>My solution with a loop is pretty straightf... | [
{
"answer_id": 557919,
"author": "Brendan",
"author_id": 199,
"author_profile": "https://Stackoverflow.com/users/199",
"pm_score": 3,
"selected": false,
"text": "<p>You could just get the binary representation of the number - a 1 means include that power of 2, a zero means don't</p>\n\n<... | 2009/02/17 | [
"https://Stackoverflow.com/questions/557909",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/42139/"
] | I´m trying to break a number into an array of numbers (in php) in the way that for example:
* 25 becomes (16, 8, 1)
* 8 becomes (8)
* 11 becomes (8, 2, 1)
I don´t know what the correct term is, but I think the idea is clear.
My solution with a loop is pretty straightforward:
```
$number = rand(0, 128);
$n... | You can check each bit of the input number with the following (untested) function.
```
function checkBit($var, $pos)
{
return ($var & (1 << $pos));
}
```
It checks the bit at position $pos in the variable $var by using a bitwise AND function. I'll show you with 4-bit numbers for brevity.
* 1 = 0001
* 2 = 0010
*... |
557,911 | <p>First of all, I do know about the Fisher-Yates shuffle. But lets say for arguments sake that I want to allow the user to pick a sort option from a Dropdown list. This list would include a "Random" option. Based on the result of their selection I just want to substitute in an IComparer instance for my sort. What ... | [
{
"answer_id": 558000,
"author": "James Curran",
"author_id": 12725,
"author_profile": "https://Stackoverflow.com/users/12725",
"pm_score": 0,
"selected": false,
"text": "<p>How 'bout sorting based on a hidden field, which is pre-assigned a random value?</p>\n"
},
{
"answer_id": ... | 2009/02/17 | [
"https://Stackoverflow.com/questions/557911",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3043/"
] | First of all, I do know about the Fisher-Yates shuffle. But lets say for arguments sake that I want to allow the user to pick a sort option from a Dropdown list. This list would include a "Random" option. Based on the result of their selection I just want to substitute in an IComparer instance for my sort. What would t... | One suggestion I got elsewhere was to create a separate IArranger interface that describes a single operation to **Arrange** a collection. This can work where IComparer/IComparable cannot because it operates on an entire collection, instead of individual items. It might look something like this:
```
public interface I... |
557,914 | <p>I'm trying to figure out if it's possible using Javascript to highlight a specific range of data in a text field.</p>
<pre><code>textfield.select();
</code></pre>
<p>That ^^ works to select the entire text, but for all my googling I haven't stumbled upon a way to select, for example, characters 2 through 10 of the... | [
{
"answer_id": 557953,
"author": "bobwienholt",
"author_id": 24257,
"author_profile": "https://Stackoverflow.com/users/24257",
"pm_score": 1,
"selected": false,
"text": "<p>I think there is a very IE-specific way to do it that involves TextRange objects. </p>\n\n<p><a href=\"http://msdn... | 2009/02/17 | [
"https://Stackoverflow.com/questions/557914",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/420/"
] | I'm trying to figure out if it's possible using Javascript to highlight a specific range of data in a text field.
```
textfield.select();
```
That ^^ works to select the entire text, but for all my googling I haven't stumbled upon a way to select, for example, characters 2 through 10 of the entered text. Is this pos... | This object will let you get, set & modify the selected region of a text box.
```
function SelectedText(input) {
// Replace the currently selected text with the given value.
this.replace = function(text) {
var selection = this.get();
var pre = input.value.substring(0, selection.start);
var post = inpu... |
557,918 | <p>On a web page, I am calling a third party who does not allow me to set timeout programatically. I call BeginInvoke and use the AsyncWaitHandle.WaitOne to wait a specified amount of time.</p>
<p>If the call times out, I move on and forget about the thread call I began. My question is, do I still have to call EndIn... | [
{
"answer_id": 558018,
"author": "Gishu",
"author_id": 1695,
"author_profile": "https://Stackoverflow.com/users/1695",
"pm_score": 1,
"selected": false,
"text": "<p><strong>Update:</strong><br>\nSeems like you need to <a href=\"http://blogs.msdn.com/cbrumme/archive/2003/05/06/51385.aspx\... | 2009/02/17 | [
"https://Stackoverflow.com/questions/557918",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/44698/"
] | On a web page, I am calling a third party who does not allow me to set timeout programatically. I call BeginInvoke and use the AsyncWaitHandle.WaitOne to wait a specified amount of time.
If the call times out, I move on and forget about the thread call I began. My question is, do I still have to call EndInvoke somehow... | Well, I couldn't ignore the advice I saw everywhere that if I did not make sure to call EndInvoke, I MIGHT leak some resources, so I had to try to get that in to sleep at night and not worry I was approaching a cliff.
The solution I found used an async callback function. If the call returned in time, I call EndInvoke... |
557,922 | <p>Each product in my database can have at least three and sometimes four or five different prices, and which one is displayed is based on several factors. How should I attempt to tackle this scenario?</p>
<p>Each product can have the following prices:</p>
<ul>
<li>List Price (MSRP)</li>
<li>Cost (what we pay for it... | [
{
"answer_id": 557944,
"author": "Quassnoi",
"author_id": 55159,
"author_profile": "https://Stackoverflow.com/users/55159",
"pm_score": 1,
"selected": false,
"text": "<p>In <code>MS SQL</code> or <code>Oracle</code>:</p>\n\n<p>Create a table <code>prices</code>:</p>\n\n<pre><code>CREATE ... | 2009/02/17 | [
"https://Stackoverflow.com/questions/557922",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/40667/"
] | Each product in my database can have at least three and sometimes four or five different prices, and which one is displayed is based on several factors. How should I attempt to tackle this scenario?
Each product can have the following prices:
* List Price (MSRP)
* Cost (what we pay for it)
* Retail Price - shown on "... | * My first question is, can all of the
prices be calculated from one of the
prices? If yes and the rules are the
same across products, we're in a
somewhat easier place.
* Do any of the prices change
independently of other prices? You
have hinted that the Sale Price is
valid for 1 month and then extended -
does the pric... |
557,956 | <p>I've created a class MyClass that intends to output a large amount of text to a JSP. Rather than having the MyClass object return a string to be displayed on the page, I figured it would be a better idea for the MyClass object to use the page's output stream. Is this a good/possible idea?</p>
<p>In testing possible... | [
{
"answer_id": 557992,
"author": "Akbar ibrahim",
"author_id": 39540,
"author_profile": "https://Stackoverflow.com/users/39540",
"pm_score": 1,
"selected": false,
"text": "<p>Have the class return you an iterator that generates the text one small chunk at a time. You could then iterate t... | 2009/02/17 | [
"https://Stackoverflow.com/questions/557956",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19147/"
] | I've created a class MyClass that intends to output a large amount of text to a JSP. Rather than having the MyClass object return a string to be displayed on the page, I figured it would be a better idea for the MyClass object to use the page's output stream. Is this a good/possible idea?
In testing possible ways to d... | `response.getWriter()` will give you different writer than one used in JSP. If you want to write to same writer as JSP page is using, you need to use `out` variable from JSP page. Difference is that JSP uses buffering on top of standard `response.getWriter()`. That's why you see your data written to `response.getWriter... |
557,959 | <p>I Have a string that is equal to a date, represented as the number of milliseconds since the Unix epoch.</p>
<p>I am trying to output it into d-m-Y.</p>
<p>The string I was given was "1227643821310", and I am told that the result should be equal to <em>2-12-2008</em>, but I keep getting a result of <em>25-11-2008<... | [
{
"answer_id": 557982,
"author": "Patrick Glandien",
"author_id": 66760,
"author_profile": "https://Stackoverflow.com/users/66760",
"pm_score": 7,
"selected": true,
"text": "<p>You are already doing it right, 1227643821 is simply not 02-12-2008, it is indeed 25-11-2008.</p>\n"
},
{
... | 2009/02/17 | [
"https://Stackoverflow.com/questions/557959",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1306/"
] | I Have a string that is equal to a date, represented as the number of milliseconds since the Unix epoch.
I am trying to output it into d-m-Y.
The string I was given was "1227643821310", and I am told that the result should be equal to *2-12-2008*, but I keep getting a result of *25-11-2008*
My code is as follows:
`... | You are already doing it right, 1227643821 is simply not 02-12-2008, it is indeed 25-11-2008. |
557,971 | <p>How do I select any node <strong>a</strong> that has node <strong>b</strong> anywhere inside it?</p>
<p>Given the following three XML documents:</p>
<pre><code><a>
<b></b>
</a>
</code></pre>
<p>or</p>
<pre><code> <a>
<c>
<b></b>
</c>
</... | [
{
"answer_id": 557991,
"author": "Jeff Yates",
"author_id": 23234,
"author_profile": "https://Stackoverflow.com/users/23234",
"pm_score": 4,
"selected": true,
"text": "<p>You should try:</p>\n\n<p><code>//a[.//b]</code></p>\n"
},
{
"answer_id": 560226,
"author": "Azat Razetdi... | 2009/02/17 | [
"https://Stackoverflow.com/questions/557971",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/67473/"
] | How do I select any node **a** that has node **b** anywhere inside it?
Given the following three XML documents:
```
<a>
<b></b>
</a>
```
or
```
<a>
<c>
<b></b>
</c>
</a>
```
or
```
<a/>
```
I want the **a** element in the first two documents to be selected.
Apparently, **a[//b]** is n... | You should try:
`//a[.//b]` |
557,997 | <p>What is the memory overhead of having an empty vector vs having a pointer to a vector?</p>
<p>Option A:</p>
<pre><code>std::vector<int> v;
</code></pre>
<p>Option B:</p>
<pre><code>std::vector<int> *v = NULL;
</code></pre>
<p>I believe that option B takes 1 32 bit pointer (assuming 32 bit here)
How ... | [
{
"answer_id": 558014,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 0,
"selected": false,
"text": "<p>Implementation dependant, probably a pointer and two integers for current size and capacity.</p>\n"
},
{
"answer_id... | 2009/02/17 | [
"https://Stackoverflow.com/questions/557997",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | What is the memory overhead of having an empty vector vs having a pointer to a vector?
Option A:
```
std::vector<int> v;
```
Option B:
```
std::vector<int> *v = NULL;
```
I believe that option B takes 1 32 bit pointer (assuming 32 bit here)
How much memory does the empty 'v' take up? | As for the question as asked: It depends on the implementation. With MSVC 7.1 this:
```
std:: cout << sizeof(std::vector<int>) << std::endl;
```
gives me 16 (bytes). (3 pointers: begin, end, and end of capacity, plus an allocator)
**However** it should be noted that the pointer-to-vector gives it a larger overhead:... |
558,009 | <p>I've been Googling around with no luck. I'm looking for a way to do getc() or gets() or whatever that does not echo to the terminal. I saw kbhit() but this doesn't appear to be part of ANSI. Ideally, I'd like code that looks like</p>
<pre><code>char s[100];
no_echo_gets(s); /* Won't echo to screen while being ty... | [
{
"answer_id": 558044,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 0,
"selected": false,
"text": "<p>There isn't one; neither ANSI C nor ISO C++ have such a thing.</p>\n"
},
{
"answer_id": 558071,
"author": "dwc"... | 2009/02/17 | [
"https://Stackoverflow.com/questions/558009",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/67491/"
] | I've been Googling around with no luck. I'm looking for a way to do getc() or gets() or whatever that does not echo to the terminal. I saw kbhit() but this doesn't appear to be part of ANSI. Ideally, I'd like code that looks like
```
char s[100];
no_echo_gets(s); /* Won't echo to screen while being typed */
printf("%s... | You can't do it in a cross-platform manner using ANSI C. You'll have to use some OS-specific code, or use a library such as [ncurses](http://www.gnu.org/software/ncurses/). |
558,010 | <p>I often find myself doing:</p>
<pre><code>foo = foo ?? x;
</code></pre>
<p>Why can't I do:</p>
<pre><code>foo ??= x;
</code></pre>
<p><strong>Edit</strong>: I know it's not part of the language... My question is "why not"? I find the necessity to repeat "foo" to be unpleasing and potentially error-prone. It lo... | [
{
"answer_id": 558025,
"author": "AnthonyWJones",
"author_id": 17516,
"author_profile": "https://Stackoverflow.com/users/17516",
"pm_score": -1,
"selected": false,
"text": "<p>Because there is no such ??= operator in C#.</p>\n\n<p>Whilst += may seem like two operators represented with di... | 2009/02/17 | [
"https://Stackoverflow.com/questions/558010",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16012/"
] | I often find myself doing:
```
foo = foo ?? x;
```
Why can't I do:
```
foo ??= x;
```
**Edit**: I know it's not part of the language... My question is "why not"? I find the necessity to repeat "foo" to be unpleasing and potentially error-prone. It looks just as ugly as:
```
foo = foo + x;
``` | The null-coalescing assignment operator `??=` was introduced in C# 8.0
<https://learn.microsoft.com/en-us/dotnet/csharp/whats-new/csharp-8#null-coalescing-assignment> |
558,033 | <p>In PHP, if I create a string like this: </p>
<pre>
$str = "bla bla here is my string";
</pre>
<p>Will I then be able to use the mbstring functions to operate on that string as UTF8? </p>
<pre>
// Will this work?
$str = mb_strlen($str);
</pre>
<p>Further, if I then have another string that I <em>know</em> is UTF... | [
{
"answer_id": 558125,
"author": "chazomaticus",
"author_id": 30497,
"author_profile": "https://Stackoverflow.com/users/30497",
"pm_score": 4,
"selected": true,
"text": "<p><strong>First question: it depends on what exactly goes in the string.</strong></p>\n\n<p>In PHP (up to PHP5, anywa... | 2009/02/17 | [
"https://Stackoverflow.com/questions/558033",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/26133/"
] | In PHP, if I create a string like this:
```
$str = "bla bla here is my string";
```
Will I then be able to use the mbstring functions to operate on that string as UTF8?
```
// Will this work?
$str = mb_strlen($str);
```
Further, if I then have another string that I *know* is UTF-8 (say it was a POSTed form v... | **First question: it depends on what exactly goes in the string.**
In PHP (up to PHP5, anyway), strings are just sequences of bytes. There is no implied or explicit character set associated with them; that's something the programmer must keep track of. So, if you only put valid UTF-8 bytes between the quotes (fairly e... |
558,046 | <p>Im breaking my head against the table right now. I have a flash batch uploader, which puts every file through upload.php which thumbnails the images, and moves them to appropriate directories. When I upload in IE, it functions perfectly (never thought I'd say this), but in Firefox, when flash executes upload.php it ... | [
{
"answer_id": 558179,
"author": "Mike B",
"author_id": 46675,
"author_profile": "https://Stackoverflow.com/users/46675",
"pm_score": -1,
"selected": true,
"text": "<p>If the php file is being executed via some form of ajax, and not directly from the browser, I believe the session is not... | 2009/02/17 | [
"https://Stackoverflow.com/questions/558046",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | Im breaking my head against the table right now. I have a flash batch uploader, which puts every file through upload.php which thumbnails the images, and moves them to appropriate directories. When I upload in IE, it functions perfectly (never thought I'd say this), but in Firefox, when flash executes upload.php it has... | If the php file is being executed via some form of ajax, and not directly from the browser, I believe the session is not persistant. IICRC Firefox treats ajax calls as new browser sessions.
If this sounds like it could be the case, I usually fix these problems by manually attaching the PHPSESSID to the end of the aja... |
558,054 | <p>I need to select the rows of a table where a column value is numeric, any Help?</p>
<p>EDIT: I have a varchar column and I need to select the ones that are numbers and the ones that are not.</p>
<p>EDIT 2: Integer.TryParse cannot be use because it cannot be translate to SQL.</p>
| [
{
"answer_id": 558081,
"author": "Ian P",
"author_id": 10853,
"author_profile": "https://Stackoverflow.com/users/10853",
"pm_score": 0,
"selected": false,
"text": "<p>Look into Int32.TryParse ... That may work for you.</p>\n\n<p>Ian</p>\n"
},
{
"answer_id": 558097,
"author": ... | 2009/02/17 | [
"https://Stackoverflow.com/questions/558054",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1154/"
] | I need to select the rows of a table where a column value is numeric, any Help?
EDIT: I have a varchar column and I need to select the ones that are numbers and the ones that are not.
EDIT 2: Integer.TryParse cannot be use because it cannot be translate to SQL. | I don't know if there is a mapping for int.TryParse() in LinqToSQL, but you could probably do it in two steps by performing the query, casting to a List, then selecting out of the list with LinqToObjects.
```
int i;
var query = context.Table.ToList();
var intQuery = query.Where( t => int.TryParse( t.Column, out i ) );... |
558,090 | <p>I have a visual brush which is a group of shapes, the main colour of which is a dynamic resource itself - so the shape is for example MyShape and the Colour, MyColour which is referenced by the Shape object.<br>
My problem is when I update the colour for this - it only happens the first time the shape is loaded (the... | [
{
"answer_id": 558249,
"author": "MojoFilter",
"author_id": 93,
"author_profile": "https://Stackoverflow.com/users/93",
"pm_score": 4,
"selected": true,
"text": "<p>Unless I misunderstand the situation, exactly what you're talking about works pretty well. I just tried it out with this X... | 2009/02/17 | [
"https://Stackoverflow.com/questions/558090",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/61529/"
] | I have a visual brush which is a group of shapes, the main colour of which is a dynamic resource itself - so the shape is for example MyShape and the Colour, MyColour which is referenced by the Shape object.
My problem is when I update the colour for this - it only happens the first time the shape is loaded (the col... | Unless I misunderstand the situation, exactly what you're talking about works pretty well. I just tried it out with this Xaml:
```
<Window x:Class="ConditionalTest.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window... |
558,105 | <p>I have a string in the format:</p>
<pre><code>t='@abc @def Hello this part is text'
</code></pre>
<p>I want to get this:</p>
<pre><code>l=["abc", "def"]
s='Hello this part is text'
</code></pre>
<p>I did this:</p>
<pre><code>a=t[t.find(' ',t.rfind('@')):].strip()
s=t[:t.find(' ',t.rfind('@'))].strip()
b=a.spli... | [
{
"answer_id": 558181,
"author": "SilentGhost",
"author_id": 12855,
"author_profile": "https://Stackoverflow.com/users/12855",
"pm_score": 2,
"selected": false,
"text": "<pre><code> [i.strip('@') for i in t.split(' ', 2)[:2]] # for a fixed number of @def\n a = [i.strip('@') for i in ... | 2009/02/17 | [
"https://Stackoverflow.com/questions/558105",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/55562/"
] | I have a string in the format:
```
t='@abc @def Hello this part is text'
```
I want to get this:
```
l=["abc", "def"]
s='Hello this part is text'
```
I did this:
```
a=t[t.find(' ',t.rfind('@')):].strip()
s=t[:t.find(' ',t.rfind('@'))].strip()
b=a.split('@')
l=[i.strip() for i in b][1:]
```
It works for the m... | Building unashamedly on MrTopf's effort:
```
import re
rx = re.compile("((?:@\w+ +)+)(.*)")
t='@abc @def @xyz Hello this part is text and my email is foo@ba.r'
a,s = rx.match(t).groups()
l = re.split('[@ ]+',a)[1:-1]
print l
print s
```
prints:
>
> ['abc', 'def', 'xyz']
>
> Hello this part is text and my em... |
558,147 | <p>Delphi 2009 uses <strong>build configurations</strong>. When you create a new project you have two default build configurations "Debug" and "Release".</p>
<p>Now I asked myself how to automate builds using MSBuild (which is supported by Delphi since version 2007).</p>
<p>You can start the "msbuild" command in the ... | [
{
"answer_id": 558367,
"author": "Craig Stuntz",
"author_id": 7714,
"author_profile": "https://Stackoverflow.com/users/7714",
"pm_score": 6,
"selected": true,
"text": "<p>Now, if you want to change the build configuration you have to add the parameter<br>\n<strong>/p:config=<code><BUI... | 2009/02/17 | [
"https://Stackoverflow.com/questions/558147",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/50890/"
] | Delphi 2009 uses **build configurations**. When you create a new project you have two default build configurations "Debug" and "Release".
Now I asked myself how to automate builds using MSBuild (which is supported by Delphi since version 2007).
You can start the "msbuild" command in the "RAD Studio Command Prompt" in... | Now, if you want to change the build configuration you have to add the parameter
**/p:config=`<BUILD_CONFIG_NAME`>**
For example:
```
C:\Projects\TestDelphiApp001>msbuild /target:Build /p:config=Release
```
or
```
C:\Projects\TestDelphiApp001>msbuild /target:Build /p:config=Debug
```
---
*Copied from original ... |
558,152 | <p>I'm building a decent sized application in ASP.NET/VB.NET with various objects... I've never used interfaces before, and a fellow programmer balked when I mentioned this to him. Can anyone give me a quick overview on how they're used, what they're used for, and why I would use them? Maybe I don't need to use them fo... | [
{
"answer_id": 558162,
"author": "Andrew Hare",
"author_id": 34211,
"author_profile": "https://Stackoverflow.com/users/34211",
"pm_score": 2,
"selected": false,
"text": "<p>Interfaces basically allow you to define a type's contract without specifying its implementation.</p>\n\n<p>The ide... | 2009/02/17 | [
"https://Stackoverflow.com/questions/558152",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7173/"
] | I'm building a decent sized application in ASP.NET/VB.NET with various objects... I've never used interfaces before, and a fellow programmer balked when I mentioned this to him. Can anyone give me a quick overview on how they're used, what they're used for, and why I would use them? Maybe I don't need to use them for t... | Once you "get" interfaces, OOP really falls into place. To put it simply, an interface defines a set of public method signatures, you create a class which implements those methods. This allows you generalize functions for any class which implements a particular interface (i.e. classes which have the same methods), even... |
558,176 | <p>We have a legacy, homegrown timesheet system (ASP, microsoft sql server 2005) that I need to clone to another computer for backup purposes. (I know very little about this stuff, so pleas be gentle)</p>
<p>I've got most of the pieces in place (IIS, Sql Server, table import / creation). But, the ASP page to access th... | [
{
"answer_id": 558215,
"author": "Craig Bovis",
"author_id": 62037,
"author_profile": "https://Stackoverflow.com/users/62037",
"pm_score": 1,
"selected": false,
"text": "<p>To create a new user and assign it to a database you'll need to do the following,</p>\n\n<blockquote>\n <ol>\n <l... | 2009/02/17 | [
"https://Stackoverflow.com/questions/558176",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | We have a legacy, homegrown timesheet system (ASP, microsoft sql server 2005) that I need to clone to another computer for backup purposes. (I know very little about this stuff, so pleas be gentle)
I've got most of the pieces in place (IIS, Sql Server, table import / creation). But, the ASP page to access the timeshee... | To create a new user and assign it to a database you'll need to do the following,
>
> 1. In SQL Server Management Studio, open Object Explorer and expand the
> folder of the server instance in which
> to create the new login.
> 2. Right-click the Security folder, point to New, and then click Login.
> 3. On the Gene... |
558,208 | <p>I have a situation where I require to consult different objects in PHP via different methods to find some data.</p>
<p>The question regards more about formatting the code than an actual programming issue. What I am trying to do is not using several <code>if</code>'s to gather this data like:</p>
<pre><code>$data =... | [
{
"answer_id": 558236,
"author": "Assaf Lavie",
"author_id": 11208,
"author_profile": "https://Stackoverflow.com/users/11208",
"pm_score": 0,
"selected": false,
"text": "<ol>\n<li>It doesn't look too bad the way it is. </li>\n<li><p>It could be a bit more efficient if the if's were neste... | 2009/02/17 | [
"https://Stackoverflow.com/questions/558208",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2274/"
] | I have a situation where I require to consult different objects in PHP via different methods to find some data.
The question regards more about formatting the code than an actual programming issue. What I am trying to do is not using several `if`'s to gather this data like:
```
$data = obj->getData();
if (!isset($dat... | You can make an array of the possible objects you want to try, then run a loop. Might be more maintainable. This code can be modified to include parameters and use call\_user\_func\_array instead.
```
$dataCallback = array(
array($othObj, 'getData'),
array($othObj, 'getThisData'),
array($anothObj, 'getTheD... |
558,216 | <p>I have been asked to test a library provided by a 3rd party. The library is known to be accurate to <em>n</em> significant figures. Any less-significant errors can safely be ignored. I want to write a function to help me compare the results:</p>
<pre><code>def nearlyequal( a, b, sigfig=5 ):
</code></pre>
<p>The pu... | [
{
"answer_id": 558289,
"author": "Kenan Banks",
"author_id": 43089,
"author_profile": "https://Stackoverflow.com/users/43089",
"pm_score": 3,
"selected": false,
"text": "<p>Here's a take.</p>\n\n<pre><code>def nearly_equal(a,b,sig_fig=5):\n return ( a==b or \n int(a*10**si... | 2009/02/17 | [
"https://Stackoverflow.com/questions/558216",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/46411/"
] | I have been asked to test a library provided by a 3rd party. The library is known to be accurate to *n* significant figures. Any less-significant errors can safely be ignored. I want to write a function to help me compare the results:
```
def nearlyequal( a, b, sigfig=5 ):
```
The purpose of this function is to dete... | There is a function `assert_approx_equal` in `numpy.testing` (source [here)](https://github.com/numpy/numpy/blob/1225aef37298ec82048d0828f6cb7e0be8ed58cc/numpy/testing/utils.py#L513) which may be a good starting point.
```
def assert_approx_equal(actual,desired,significant=7,err_msg='',verbose=True):
"""
Rais... |
558,223 | <p><a href="https://stackoverflow.com/questions/69738/c-how-to-get-fprintf-results-as-a-stdstring-w-o-sprintf#69911">A previous question</a> showed a nice way of printing to a string. The answer involved va_copy:</p>
<pre><code>std::string format (const char *fmt, ...);
{
va_list ap;
va_start (ap, fmt);
std::... | [
{
"answer_id": 558259,
"author": "Adam Rosenfield",
"author_id": 9530,
"author_profile": "https://Stackoverflow.com/users/9530",
"pm_score": 5,
"selected": true,
"text": "<p>You should be able to get away with just doing a regular assignment:</p>\n\n<pre><code>va_list apcopy = ap;\n</cod... | 2009/02/17 | [
"https://Stackoverflow.com/questions/558223",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/48956/"
] | [A previous question](https://stackoverflow.com/questions/69738/c-how-to-get-fprintf-results-as-a-stdstring-w-o-sprintf#69911) showed a nice way of printing to a string. The answer involved va\_copy:
```
std::string format (const char *fmt, ...);
{
va_list ap;
va_start (ap, fmt);
std::string buf = vformat (fm... | You should be able to get away with just doing a regular assignment:
```
va_list apcopy = ap;
```
It's technically non-portable and undefined behavior, but it will work with most compilers and architectures. In the x86 calling convention, `va_list`s are just pointers into the stack and are safe to copy. |
558,247 | <p>Let's say you have a *SQL* buffer already open in Emacs that is connected to a specific server and database. Now, your intention is to connect to a different server and database while keeping your other SQL buffer process active. </p>
<p>How exactly can you create a new *SQL* buffer process without killing your or... | [
{
"answer_id": 558382,
"author": "Sean Bright",
"author_id": 21926,
"author_profile": "https://Stackoverflow.com/users/21926",
"pm_score": 4,
"selected": true,
"text": "<p>Running:</p>\n\n<pre><code>M-x sql-rename-buffer\n</code></pre>\n\n<p>On a connected <code>*SQL*</code> buffer will ... | 2009/02/17 | [
"https://Stackoverflow.com/questions/558247",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4872/"
] | Let's say you have a \*SQL\* buffer already open in Emacs that is connected to a specific server and database. Now, your intention is to connect to a different server and database while keeping your other SQL buffer process active.
How exactly can you create a new \*SQL\* buffer process without killing your original ... | Running:
```
M-x sql-rename-buffer
```
On a connected `*SQL*` buffer will rename the current buffer after the current connection. So:
```
*SQL*
```
Becomes:
```
*SQL user/database*
```
You can then do:
```
M-x sql-mysql
```
Or whatever your flavor of DB is to create another SQL buffer. |
558,267 | <p>I have the following code...</p>
<pre><code>if (Price_Foreign != Double.NaN)
{
output.Append(spacer);
output.Append(String.Format("{0,-10:C} USD",Price_Foreign));
}
</code></pre>
<p>Which outputs: </p>
<pre><code>NaN USD
</code></pre>
<p>What gives?</p>
<p>I'm using Double.NaN to indicate that the value d... | [
{
"answer_id": 558282,
"author": "Andrew Hare",
"author_id": 34211,
"author_profile": "https://Stackoverflow.com/users/34211",
"pm_score": 7,
"selected": true,
"text": "<p>Perhaps you are looking for the <code>IsNaN</code> static function?</p>\n\n<p>Try something like this:</p>\n\n<pre><... | 2009/02/17 | [
"https://Stackoverflow.com/questions/558267",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18907/"
] | I have the following code...
```
if (Price_Foreign != Double.NaN)
{
output.Append(spacer);
output.Append(String.Format("{0,-10:C} USD",Price_Foreign));
}
```
Which outputs:
```
NaN USD
```
What gives?
I'm using Double.NaN to indicate that the value doesn't exist, and shouldn't be output. | Perhaps you are looking for the `IsNaN` static function?
Try something like this:
```
if (!Double.IsNaN(Price_Foreign))
{
output.Append(spacer);
output.Append(String.Format("{0,-10:C} USD",Price_Foreign));
}
``` |
558,273 | <p>Let's say I have a list of objects of the same type. I want to iterate over that list of objects and execute a "dangerous" method on each of them. If an exception occurs in that method, is it bad practice to have the method itself catch the exception and set an error property on the object? </p>
<p>Here's a quic... | [
{
"answer_id": 558288,
"author": "casperOne",
"author_id": 50776,
"author_profile": "https://Stackoverflow.com/users/50776",
"pm_score": 3,
"selected": true,
"text": "<p>I would say absolutely, because this is only a provision for a single call. What happens if you make other call on th... | 2009/02/17 | [
"https://Stackoverflow.com/questions/558273",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/132931/"
] | Let's say I have a list of objects of the same type. I want to iterate over that list of objects and execute a "dangerous" method on each of them. If an exception occurs in that method, is it bad practice to have the method itself catch the exception and set an error property on the object?
Here's a quick example whe... | I would say absolutely, because this is only a provision for a single call. What happens if you make other call on the object and it throws an exception as well? The property value is overridden and then you aren't really sure what the state of the object is.
You are better off capturing exception information in a try... |
558,274 | <p>I am having a problem with logging to output from an automated build.</p>
<p>The build is done with a Makefile and the makefile utility.</p>
<p>The problem is that normal output like compiler command lines go to stdout and compile errors go to stderr.</p>
<p>I want to get the output from the build as it would sho... | [
{
"answer_id": 558286,
"author": "S.Lott",
"author_id": 10661,
"author_profile": "https://Stackoverflow.com/users/10661",
"pm_score": 3,
"selected": false,
"text": "<p>Try this</p>\n\n<pre><code>make -k > build.log 2>&1\n</code></pre>\n"
},
{
"answer_id": 558302,
"a... | 2009/02/17 | [
"https://Stackoverflow.com/questions/558274",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7743/"
] | I am having a problem with logging to output from an automated build.
The build is done with a Makefile and the makefile utility.
The problem is that normal output like compiler command lines go to stdout and compile errors go to stderr.
I want to get the output from the build as it would show on the screen. So some... | ```
make -k > build.log 2>&1
```
This should work better for you because it is not redirecting stderr and stdout separately, but redirecting stderr to stdout, which should make the buffering sync up.
If you want to log it to a file as well as print it to the console:
```
make -k 2>&1 | tee build.log
``` |
558,283 | <p>So I have an address table that is shared among various other tables, such as schools, parks, churches, etc. Schools, parks, etc all foreign key to a row in address. </p>
<p>What I'm wondering is, if I have a specific row in the address table, is there a way to find out which row in which table points to it. So b... | [
{
"answer_id": 558310,
"author": "J.T. Grimes",
"author_id": 1676,
"author_profile": "https://Stackoverflow.com/users/1676",
"pm_score": 4,
"selected": true,
"text": "<p>You're going to have to query each of the other tables.</p>\n\n<p>I would do it as a UNION query:</p>\n\n<pre><code> ... | 2009/02/17 | [
"https://Stackoverflow.com/questions/558283",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4915/"
] | So I have an address table that is shared among various other tables, such as schools, parks, churches, etc. Schools, parks, etc all foreign key to a row in address.
What I'm wondering is, if I have a specific row in the address table, is there a way to find out which row in which table points to it. So basically jus... | You're going to have to query each of the other tables.
I would do it as a UNION query:
```
SELECT id, "schools" as whichTable from schools where address_id=1
UNION
SELECT id, "parks" as whichTable from parks where address_id=1
UNION
...
```
so that you only have to run one query and get back the results ... |
558,292 | <p>I've just thought about best way to store comments in database with appropriate numbers according to the article.</p>
<p>The idea is to store comments with composite primary key (commentId, articleId) where commentId is generated according to the given articleId. The system of generating should has same principle a... | [
{
"answer_id": 558325,
"author": "Osama Al-Maadeed",
"author_id": 25544,
"author_profile": "https://Stackoverflow.com/users/25544",
"pm_score": 1,
"selected": false,
"text": "<p>I would use an identity column as the key for the comments, why do you need a numbering for the comments store... | 2009/02/17 | [
"https://Stackoverflow.com/questions/558292",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | I've just thought about best way to store comments in database with appropriate numbers according to the article.
The idea is to store comments with composite primary key (commentId, articleId) where commentId is generated according to the given articleId. The system of generating should has same principle as IDENTITY... | Thank you for responses, I wanted something with numbered comments because of referencing in the text of comments. I did not want to make reaction by names, sometimes one person reacts more times, so with this system, I will know to which one the person is replying.
So today I made up this INSTEAD OF INSERT trigger:
... |
558,300 | <pre><code>[MenuItemFont setFontSize:20];
[MenuItemFont setFontName:@"Helvetica"];
//I'm trying to change the color of start (below item)
MenuItem *start = [MenuItemFont itemFromString:@"Start Game"
target:self
selector:@selector(startGame:... | [
{
"answer_id": 648112,
"author": "JustinB",
"author_id": 66288,
"author_profile": "https://Stackoverflow.com/users/66288",
"pm_score": 4,
"selected": true,
"text": "<pre><code>MenuItemFont *start = [MenuItemFont itemFromString:@\"Start Game\" \n ... | 2009/02/17 | [
"https://Stackoverflow.com/questions/558300",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/67524/"
] | ```
[MenuItemFont setFontSize:20];
[MenuItemFont setFontName:@"Helvetica"];
//I'm trying to change the color of start (below item)
MenuItem *start = [MenuItemFont itemFromString:@"Start Game"
target:self
selector:@selector(startGame:)];
Men... | ```
MenuItemFont *start = [MenuItemFont itemFromString:@"Start Game"
target:self
selector:@selector(startGame:)];
[start.label setRGB:0 :0 :0]; // Black menu item
```
Label is a property of MenuItemFont, a subclass of MenuItem... |
558,304 | <p>Can anyone explain <code>IEnumerable</code> and <code>IEnumerator</code> to me?</p>
<p>For example, when to use it over foreach? what's the difference between <code>IEnumerable</code> and <code>IEnumerator</code>? Why do we need to use it?</p>
| [
{
"answer_id": 558309,
"author": "Neil Barnwell",
"author_id": 26414,
"author_profile": "https://Stackoverflow.com/users/26414",
"pm_score": 4,
"selected": false,
"text": "<p>Implementing IEnumerable enables you to get an IEnumerator for a list.</p>\n\n<p>IEnumerator allows foreach style... | 2009/02/17 | [
"https://Stackoverflow.com/questions/558304",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4786/"
] | Can anyone explain `IEnumerable` and `IEnumerator` to me?
For example, when to use it over foreach? what's the difference between `IEnumerable` and `IEnumerator`? Why do we need to use it? | >
> for example, when to use it over foreach?
>
>
>
You don't use `IEnumerable` "over" `foreach`. Implementing `IEnumerable` makes using `foreach` *possible*.
When you write code like:
```
foreach (Foo bar in baz)
{
...
}
```
it's functionally equivalent to writing:
```
IEnumerator bat = baz.GetEnumerator(... |
558,308 | <p>Background: I'm rewriting a VB6 app that used MS Access for data storage to one that uses VB.NET and MS SQL Server. </p>
<p>I'm curious as to the best way to pass a connection among the different forms in my application that need a connection to the database. Right now I've built a class to manage the connection ... | [
{
"answer_id": 558337,
"author": "casperOne",
"author_id": 50776,
"author_profile": "https://Stackoverflow.com/users/50776",
"pm_score": 4,
"selected": true,
"text": "<p>You <strong><em>should NOT</em></strong> pass the connection object among forms. Basically, the pattern when using a ... | 2009/02/17 | [
"https://Stackoverflow.com/questions/558308",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | Background: I'm rewriting a VB6 app that used MS Access for data storage to one that uses VB.NET and MS SQL Server.
I'm curious as to the best way to pass a connection among the different forms in my application that need a connection to the database. Right now I've built a class to manage the connection string to pa... | You ***should NOT*** pass the connection object among forms. Basically, the pattern when using a connection to SQL Server is to create the connection, open it, perform your operation, then close the connection.
To that end, you should have a public static method somewhere which will generate your SqlConnection which y... |
558,311 | <p>I was talking to someone today about picking a design pattern for how to handle logic in their WPF program and hoping that the SO community can help with further advice to make the decision easier. <strong>What factors in favour of commands outweigh the inconvenience?</strong></p>
<p>I prepared a full <a href="http... | [
{
"answer_id": 558429,
"author": "Mike Chaliy",
"author_id": 38975,
"author_profile": "https://Stackoverflow.com/users/38975",
"pm_score": 2,
"selected": false,
"text": "<p>The only reason is to have well know registry of commands. Means that events are likely to be private methods and I... | 2009/02/17 | [
"https://Stackoverflow.com/questions/558311",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/53870/"
] | I was talking to someone today about picking a design pattern for how to handle logic in their WPF program and hoping that the SO community can help with further advice to make the decision easier. **What factors in favour of commands outweigh the inconvenience?**
I prepared a full [sample](http://www.aussiedesignedso... | Commands their advantages and disadvantages, you have to choose based on your situation,
I highly recommend you make that choice on a case basis, don't choose "the one true way" for the entire project.
For some cases the separation between sender and receiver and the ability to send commands using only XAML is a big a... |
558,315 | <p>Assume that you have an idCollection <code>IList<long></code> and you have a method to get 4 unique ids.Every time you call it, it gives you random 4 unique ids ?</p>
<pre><code>var idCollec = new[] {1,2,3,4,5,6,7,8,9,10,11,12}.ToList();
For example {2,6,11,12}
{3,4,7,8}
{5,8,10,12}
... | [
{
"answer_id": 558354,
"author": "Mike_G",
"author_id": 52051,
"author_profile": "https://Stackoverflow.com/users/52051",
"pm_score": 1,
"selected": false,
"text": "<p>If the IList<code><long></code> is populated with non unique values, you could use LINQ's Distinct() in combinatio... | 2009/02/17 | [
"https://Stackoverflow.com/questions/558315",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/51734/"
] | Assume that you have an idCollection `IList<long>` and you have a method to get 4 unique ids.Every time you call it, it gives you random 4 unique ids ?
```
var idCollec = new[] {1,2,3,4,5,6,7,8,9,10,11,12}.ToList();
For example {2,6,11,12}
{3,4,7,8}
{5,8,10,12}
...
..
... | Seems like easiest way would be to have something like:
```
if(idCollection.Count <4)
{
throw new ArgumentException("Source array not long enough");
}
List<long> FourUniqueIds = new List<long>(4);
while(FourUniqueIds.Count <4)
{
long temp = idCollection[random.Next(idCollection.Count)];
if(!FourUniqueIds.C... |
558,316 | <p>The following query returns a single row, as desired. The 'contracts' table has 6 fields, each with a different username in it, for which I want to retrieve first/last names from a separate 'users' table. This works fine, but is there something more concise? I'm think the solution must be something using GROUP BY... | [
{
"answer_id": 558333,
"author": "dotjoe",
"author_id": 40822,
"author_profile": "https://Stackoverflow.com/users/40822",
"pm_score": 3,
"selected": false,
"text": "<p>Why not join to the users table 6 times?</p>\n"
},
{
"answer_id": 558356,
"author": "Russ Cam",
"author_... | 2009/02/17 | [
"https://Stackoverflow.com/questions/558316",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/26848/"
] | The following query returns a single row, as desired. The 'contracts' table has 6 fields, each with a different username in it, for which I want to retrieve first/last names from a separate 'users' table. This works fine, but is there something more concise? I'm think the solution must be something using GROUP BY contr... | ```
SELECT contracts.field1, contracts.field2,
sp1.first_name,
sp1.last_name
sp2.first_name,
sp2.last_name,
/* etc, etc */
FROM
contracts
INNER JOIN
users sp1
ON
contracts.id = sp1.id
AND sp1.username = service_provider_1
INNER JOIN
users sp2
ON contracts.id = sp2.id
AND sp2.username = service_provider_2
INNER JOIN ... |