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 |
|---|---|---|---|---|---|---|
37,731 | <p>I seem right now to be embroiled in a debate with another programmer on this project who thinks that views have no merits. He proposes a system that PHP looks something like this:</p>
<pre><code>$draw = new Draw;
$nav = $draw->wideHeaderBox().
$draw->left().
$draw->image().
Image::get($image,6... | [
{
"answer_id": 37733,
"author": "Mark Ingram",
"author_id": 986,
"author_profile": "https://Stackoverflow.com/users/986",
"pm_score": 1,
"selected": false,
"text": "<p>The argument he uses is the argument you need to <em>have</em> views. Both result in only changing it in one place. Howe... | 2008/09/01 | [
"https://Stackoverflow.com/questions/37731",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2594/"
] | I seem right now to be embroiled in a debate with another programmer on this project who thinks that views have no merits. He proposes a system that PHP looks something like this:
```
$draw = new Draw;
$nav = $draw->wideHeaderBox().
$draw->left().
$draw->image().
Image::get($image,60,array('id'=>'header_im... | HTML time-savers are useful, but they're only useful when they're intuitive and easy-to-understand. Having to instantiate a `new Draw` just doesn't sound very natural. Furthermore, `wideHeaderBox` and `left` will only have significance to someone who intimately knows the system. And what if there *is* a redesign, like ... |
37,732 | <p>What is the RegEx pattern for DateTime (2008-09-01 12:35:45 ) ?</p>
<p>I get this error:</p>
<blockquote>
<p>No ending delimiter '^' found</p>
</blockquote>
<p>Using:</p>
<pre><code>preg_match('(?n:^(?=\d)((?<day>31(?!(.0?[2469]|11))|30(?!.0?2)|29(?(.0?2)(?=.{3,4}(1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579... | [
{
"answer_id": 37742,
"author": "Espo",
"author_id": 2257,
"author_profile": "https://Stackoverflow.com/users/2257",
"pm_score": 3,
"selected": false,
"text": "<p><a href=\"http://regexlib.com/REDetails.aspx?regexp_id=610\" rel=\"noreferrer\">http://regexlib.com/REDetails.aspx?regexp_id=... | 2008/09/01 | [
"https://Stackoverflow.com/questions/37732",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4013/"
] | What is the RegEx pattern for DateTime (2008-09-01 12:35:45 ) ?
I get this error:
>
> No ending delimiter '^' found
>
>
>
Using:
```
preg_match('(?n:^(?=\d)((?<day>31(?!(.0?[2469]|11))|30(?!.0?2)|29(?(.0?2)(?=.{3,4}(1[6-9]|[2-9]\d)(0[48]|[2468][048]|[13579][26])|(16|[2468][048]|[3579][26])00))|0?[1-9]|1\d|2[0-8... | @Espo: I just have to say that regex is incredible. I'd hate to have to write the code that did something useful with the matches, such as if you wanted to actually find out what date and time the user typed.
It seems like Tom's solution would be more tenable, as it is about a zillion times simpler and with the additi... |
37,743 | <p>I'd like to find the different ways to solve a real life problem I had: imagine to have a contest, or a game, during which the users collect points. You have to build a query to show the list of users with the best "n" scores. </p>
<p>I'm making an example to clarify. Let's say that this is the Users table, with th... | [
{
"answer_id": 37750,
"author": "Espo",
"author_id": 2257,
"author_profile": "https://Stackoverflow.com/users/2257",
"pm_score": 5,
"selected": true,
"text": "<p>Untested, but should work:</p>\n\n<pre><code>select * from users where points in\n(select distinct top 3 points from users ord... | 2008/09/01 | [
"https://Stackoverflow.com/questions/37743",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1178/"
] | I'd like to find the different ways to solve a real life problem I had: imagine to have a contest, or a game, during which the users collect points. You have to build a query to show the list of users with the best "n" scores.
I'm making an example to clarify. Let's say that this is the Users table, with the points e... | Untested, but should work:
```
select * from users where points in
(select distinct top 3 points from users order by points desc)
``` |
37,759 | <p>I have the following code in a web.config file of the default IIS site.</p>
<pre><code><httpModules>
<add type="MDL.BexWebControls.Charts.ChartStreamHandler,Charts" name="ChartStreamHandler"/>
</httpModules>
</code></pre>
<p>Then when I setup and browse to a virtual directory I get this error... | [
{
"answer_id": 37762,
"author": "John Owen",
"author_id": 2471,
"author_profile": "https://Stackoverflow.com/users/2471",
"pm_score": 5,
"selected": true,
"text": "<p>I've found the answer. Wrap the HttpModule section in location tags and set the inheritInChildApplications attribute to ... | 2008/09/01 | [
"https://Stackoverflow.com/questions/37759",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2471/"
] | I have the following code in a web.config file of the default IIS site.
```
<httpModules>
<add type="MDL.BexWebControls.Charts.ChartStreamHandler,Charts" name="ChartStreamHandler"/>
</httpModules>
```
Then when I setup and browse to a virtual directory I get this error
Could not load file or assembly 'Charts' o... | I've found the answer. Wrap the HttpModule section in location tags and set the inheritInChildApplications attribute to false.
```
<location path="." inheritInChildApplications="false">
<system.web>
<httpModules>
<add type="MDL.BexWebControls.Charts.ChartStreamHandler,Charts" name="ChartStreamHandler"/>
... |
37,791 | <p>At the moment my code (PHP) has too many SQL queries in it. eg...</p>
<pre><code>// not a real example, but you get the idea...
$results = $db->GetResults("SELECT * FROM sometable WHERE iUser=$userid");
if ($results) {
// Do something
}
</code></pre>
<p>I am looking into using stored procedures to reduce th... | [
{
"answer_id": 37795,
"author": "Matthew Watson",
"author_id": 3839,
"author_profile": "https://Stackoverflow.com/users/3839",
"pm_score": 2,
"selected": false,
"text": "<p>Use a ORM package, any half decent package will allow you to</p>\n\n<ol>\n<li>Get simple result sets</li>\n<li>Keep... | 2008/09/01 | [
"https://Stackoverflow.com/questions/37791",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4012/"
] | At the moment my code (PHP) has too many SQL queries in it. eg...
```
// not a real example, but you get the idea...
$results = $db->GetResults("SELECT * FROM sometable WHERE iUser=$userid");
if ($results) {
// Do something
}
```
I am looking into using stored procedures to reduce this and make things a little m... | The best course of action for you will depend on how you are approaching your data access. There are three approaches you can take:
* Use stored procedures
* Keep the queries in the code (but put all your queries into functions and fix everything to use PDO for parameters, as mentioned earlier)
* Use an ORM tool
If y... |
37,805 | <p>I have a <code>List<int></code> and a <code>List<customObject></code>. The customObject class has an ID property. How can I get a <code>List<customObject></code> containing only the objects where the ID property is in the <code>List<int></code> using LINQ?</p>
<p><strong>Edit</strong>: I acc... | [
{
"answer_id": 37807,
"author": "Matt Hamilton",
"author_id": 615,
"author_profile": "https://Stackoverflow.com/users/615",
"pm_score": 3,
"selected": false,
"text": "<p>Untested, but it'll be something like this:</p>\n\n<pre><code>var matches = from o in objList \n join... | 2008/09/01 | [
"https://Stackoverflow.com/questions/37805",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2257/"
] | I have a `List<int>` and a `List<customObject>`. The customObject class has an ID property. How can I get a `List<customObject>` containing only the objects where the ID property is in the `List<int>` using LINQ?
**Edit**: I accepted Konrads answer because it is easier/more intuitive to read. | ```
var result = from o in objList where intList.Contains(o.ID) select o
``` |
37,809 | <p>How can I go about generating a Friendly URL in C#? Currently I simple replace spaces with an underscore, but how would I go about generating URL's like Stack Overflow?</p>
<p>For example how can I convert:</p>
<blockquote>
<p>How do I generate a Friendly URL in C#?</p>
</blockquote>
<p>Into</p>
<blockquote>
... | [
{
"answer_id": 37817,
"author": "Jeff Atwood",
"author_id": 1,
"author_profile": "https://Stackoverflow.com/users/1",
"pm_score": 4,
"selected": false,
"text": "<p>Here's how we do it. Note that there are probably more edge conditions than you realize at first glance..</p>\n\n<pre><code>... | 2008/09/01 | [
"https://Stackoverflow.com/questions/37809",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/383/"
] | How can I go about generating a Friendly URL in C#? Currently I simple replace spaces with an underscore, but how would I go about generating URL's like Stack Overflow?
For example how can I convert:
>
> How do I generate a Friendly URL in C#?
>
>
>
Into
>
> how-do-i-generate-a-friendly-url-in-C
>
>
> | There are several things that could be improved in Jeff's solution, though.
```
if (String.IsNullOrEmpty(title)) return "";
```
IMHO, not the place to test this. If the function gets passed an empty string, something went seriously wrong anyway. Throw an error or don't react at all.
```
// remove any leading or tra... |
37,822 | <p>I have read that the iPhone SDK (part of Xcode 3) is restricted to Mac's with the intel chipset. Does this restriction apply to only the simulator part of the SDK or the complete shebang?</p>
<p>I have a Powerbook G4 running Leopard and would very much like to do dev on it rather than fork out for a new machine.</p... | [
{
"answer_id": 38554,
"author": "Chris Hanson",
"author_id": 714,
"author_profile": "https://Stackoverflow.com/users/714",
"pm_score": 2,
"selected": false,
"text": "<p>The iPhone SDK is documented to require an Intel-based Mac. Even if some people may be able to have gotten it to run o... | 2008/09/01 | [
"https://Stackoverflow.com/questions/37822",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2438/"
] | I have read that the iPhone SDK (part of Xcode 3) is restricted to Mac's with the intel chipset. Does this restriction apply to only the simulator part of the SDK or the complete shebang?
I have a Powerbook G4 running Leopard and would very much like to do dev on it rather than fork out for a new machine.
It is also ... | As things have moved on since the original post on 3by9.com, here are the steps that I had to follow to get the environment working on my PowerBook G4.
**BTW, I would like to say that I realise that this is not a supported environment and I share this for purely pedagogic rea**sons.
1. Download and install the iPhone... |
37,830 | <p>I want to show a chromeless modal window with a close button in the upper right corner.
Is this possible?</p>
| [
{
"answer_id": 37878,
"author": "Matt Hamilton",
"author_id": 615,
"author_profile": "https://Stackoverflow.com/users/615",
"pm_score": 6,
"selected": true,
"text": "<p>You'll pretty much have to roll your own Close button, but you can hide the window chrome completely using the WindowSt... | 2008/09/01 | [
"https://Stackoverflow.com/questions/37830",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2374/"
] | I want to show a chromeless modal window with a close button in the upper right corner.
Is this possible? | You'll pretty much have to roll your own Close button, but you can hide the window chrome completely using the WindowStyle attribute, like this:
```
<Window WindowStyle="None">
```
That will still have a resize border. If you want to make the window non-resizable then add ResizeMode="NoResize" to the declaration. |
37,920 | <p>I have developed a COM component (dll) that implements an Edit() method displaying a WTL modal dialog.</p>
<p>The complete interface to this COM component corresponds to a software standard used in the chemical process industry (CAPE-OPEN) and as a result this COM component is supposed to be usable by a range of 3r... | [
{
"answer_id": 37943,
"author": "Mark Ingram",
"author_id": 986,
"author_profile": "https://Stackoverflow.com/users/986",
"pm_score": 1,
"selected": false,
"text": "<p>Are you using a parent for the Dialog? e.g.</p>\n\n<pre><code>MyDialog dialog(pParent);\ndialog.DoModal();\n</code></pre... | 2008/09/01 | [
"https://Stackoverflow.com/questions/37920",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3229/"
] | I have developed a COM component (dll) that implements an Edit() method displaying a WTL modal dialog.
The complete interface to this COM component corresponds to a software standard used in the chemical process industry (CAPE-OPEN) and as a result this COM component is supposed to be usable by a range of 3rd party ex... | Are you using a parent for the Dialog? e.g.
```
MyDialog dialog(pParent);
dialog.DoModal();
```
If you are, try removing the parent. Especially if the parent is the desktop window. |
37,956 | <p>I would like to open a small video file and map every frames in memory (to apply some custom filter). I don't want to handle the video codec, I would rather let the library handle that for me.</p>
<p>I've tried to use Direct Show with the SampleGrabber filter (using this sample <a href="http://msdn.microsoft.com/en... | [
{
"answer_id": 37980,
"author": "Chris de Vries",
"author_id": 3836,
"author_profile": "https://Stackoverflow.com/users/3836",
"pm_score": 2,
"selected": false,
"text": "<p>I have used <a href=\"http://sourceforge.net/projects/opencvlibrary/\" rel=\"nofollow noreferrer\">OpenCV</a> to lo... | 2008/09/01 | [
"https://Stackoverflow.com/questions/37956",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1578/"
] | I would like to open a small video file and map every frames in memory (to apply some custom filter). I don't want to handle the video codec, I would rather let the library handle that for me.
I've tried to use Direct Show with the SampleGrabber filter (using this sample <http://msdn.microsoft.com/en-us/library/ms7878... | Currently these are the most popular video frameworks available on Win32 platforms:
1. Video for Windows: old windows framework coming from the age of Win95 but still widely used because it is very simple to use. Unfortunately it supports only AVI files for which the proper VFW codec has been installed.
2. DirectShow:... |
37,976 | <p>By default IntelliJ IDEA 7.0.4 seems to use 4 spaces for indentation in XML files. The project I'm working on uses 2 spaces as indentation in all it's XML. Is there a way to configure the indentation in IntelliJ's editor?</p>
| [
{
"answer_id": 38224,
"author": "Huppie",
"author_id": 1830,
"author_profile": "https://Stackoverflow.com/users/1830",
"pm_score": 5,
"selected": true,
"text": "<p>Sure there is. This is all you need to do:</p>\n\n<ul>\n<li>Go to</li>\n</ul>\n\n<pre>File -> Settings -> Global Code Style ... | 2008/09/01 | [
"https://Stackoverflow.com/questions/37976",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1113/"
] | By default IntelliJ IDEA 7.0.4 seems to use 4 spaces for indentation in XML files. The project I'm working on uses 2 spaces as indentation in all it's XML. Is there a way to configure the indentation in IntelliJ's editor? | Sure there is. This is all you need to do:
* Go to
```
File -> Settings -> Global Code Style -> General
```
* Disable the checkbox next to 'Use same settings for all file types'
* The 'XML' tab should become enabled. Click it and set the 'tab' (and probably 'indent') size to 2. |
38,014 | <p>I am facing problem with an Oracle Query in a .net 2.0 based windows application. I am using <code>System.Data.OracleClient</code> to connect to oracle database. Name of database is <code>myDB</code>. Below the the connection string I am using:</p>
<pre><code>Data Source=(DESCRIPTION =(ADDRESS_LIST =(ADDRESS = (PRO... | [
{
"answer_id": 38022,
"author": "skolima",
"author_id": 3205,
"author_profile": "https://Stackoverflow.com/users/3205",
"pm_score": 0,
"selected": false,
"text": "<p>Try adding</p>\n\n<pre><code>CONNECT_DATA=(SID=myDB)(SERVICE_NAME=ORCL)\n</code></pre>\n\n<p>in the connection string.</p>... | 2008/09/01 | [
"https://Stackoverflow.com/questions/38014",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/191/"
] | I am facing problem with an Oracle Query in a .net 2.0 based windows application. I am using `System.Data.OracleClient` to connect to oracle database. Name of database is `myDB`. Below the the connection string I am using:
```
Data Source=(DESCRIPTION =(ADDRESS_LIST =(ADDRESS = (PROTOCOL = TCP)
(HOST = 172.16.0.24)(P... | This looks like an issue with name resolution, try creating a public synonym on the table:
CREATE PUBLIC SYNONYM *MyTempTable* for *MyTempTable*;
Also, what exactly do you mean by **wrong result**, incorrect data, error message?
---
Edit: What is the name of the schema that the required table belongs to? It sounds ... |
38,021 | <p>How can I find the origins of conflicting DNS records?</p>
| [
{
"answer_id": 38025,
"author": "Kyle Cronin",
"author_id": 658,
"author_profile": "https://Stackoverflow.com/users/658",
"pm_score": 1,
"selected": false,
"text": "<p>An easy way is to use an online domain tool. My favorite is <a href=\"http://whois.domaintools.com/stackoverflow.com\" r... | 2008/09/01 | [
"https://Stackoverflow.com/questions/38021",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/319/"
] | How can I find the origins of conflicting DNS records? | You'll want the SOA (Start of Authority) record for a given domain name, and this is how you accomplish it using the universally available **nslookup** command line tool:
```
command line> nslookup
> set querytype=soa
> stackoverflow.com
Server: 217.30.180.230
Address: 217.30.180.230#53
Non-authoritati... |
38,035 | <p>I'm building a basic search functionality, using LIKE (I'd be using fulltext but can't at the moment) and I'm wondering if MySQL can, on searching for a keyword (e.g. WHERE field LIKE '%word%') return 20 words either side of the keyword, as well?</p>
| [
{
"answer_id": 38063,
"author": "aryeh",
"author_id": 3288,
"author_profile": "https://Stackoverflow.com/users/3288",
"pm_score": 0,
"selected": false,
"text": "<p>Use the INSTR() function to find the position of the word in the string, and then use SUBSTRING() function to select a porti... | 2008/09/01 | [
"https://Stackoverflow.com/questions/38035",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/393028/"
] | I'm building a basic search functionality, using LIKE (I'd be using fulltext but can't at the moment) and I'm wondering if MySQL can, on searching for a keyword (e.g. WHERE field LIKE '%word%') return 20 words either side of the keyword, as well? | You can do it all in the query using SUBSTRING\_INDEX
```
CONCAT_WS(
' ',
-- 20 words before
TRIM(
SUBSTRING_INDEX(
SUBSTRING(field, 1, INSTR(field, 'word') - 1 ),
' ',
-20
)
),
-- your word
'word',
-- 20 words after
TRIM(
SUBSTRING_INDEX(
SUBSTRING(field, INSTR(field, 'word... |
38,037 | <p>In my C++ program I want to parse a small piece of XML, insert some nodes, then extract the new XML (preferably as a <code>std::string</code>).<br>
<a href="http://rapidxml.sourceforge.net/" rel="nofollow noreferrer">RapidXml</a> has been recommended to me, but I can't see how to retrieve the XML back as a text stri... | [
{
"answer_id": 38127,
"author": "Adam Tegen",
"author_id": 4066,
"author_profile": "https://Stackoverflow.com/users/4066",
"pm_score": 0,
"selected": false,
"text": "<p>If you aren't yet committed to Rapid XML, I can recommend some alternative libraries:</p>\n\n<ul>\n<li><p>Xerces - This... | 2008/09/01 | [
"https://Stackoverflow.com/questions/38037",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3590/"
] | In my C++ program I want to parse a small piece of XML, insert some nodes, then extract the new XML (preferably as a `std::string`).
[RapidXml](http://rapidxml.sourceforge.net/) has been recommended to me, but I can't see how to retrieve the XML back as a text string.
(I could iterate over the nodes and attribute... | Althoug the documentation is poor on this topic, I managed to get some working code by looking at the source. Although it is missing the xml header which normally contains important information. Here is a small example program that does what you are looking for using rapidxml:
```
#include <iostream>
#include <sstream... |
38,039 | <p>How do I find the start of the week (both Sunday and Monday) knowing just the current time in C#?</p>
<p>Something like:</p>
<pre><code>DateTime.Now.StartWeek(Monday);
</code></pre>
| [
{
"answer_id": 38049,
"author": "Skizz",
"author_id": 1898,
"author_profile": "https://Stackoverflow.com/users/1898",
"pm_score": 4,
"selected": false,
"text": "<p>This would give you the preceding Sunday (I think):</p>\n\n<pre><code>DateTime t = DateTime.Now;\nt -= new TimeSpan ((int) t... | 2008/09/01 | [
"https://Stackoverflow.com/questions/38039",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/383/"
] | How do I find the start of the week (both Sunday and Monday) knowing just the current time in C#?
Something like:
```
DateTime.Now.StartWeek(Monday);
``` | Use an extension method:
```
public static class DateTimeExtensions
{
public static DateTime StartOfWeek(this DateTime dt, DayOfWeek startOfWeek)
{
int diff = (7 + (dt.DayOfWeek - startOfWeek)) % 7;
return dt.AddDays(-1 * diff).Date;
}
}
```
Which can be used as follows:
```
DateTime dt ... |
38,056 | <p>The only <em>nice</em> way I've found is:</p>
<pre><code>import sys
import os
try:
os.kill(int(sys.argv[1]), 0)
print "Running"
except:
print "Not running"
</code></pre>
<p>(<a href="http://www.unix.com/unix-advanced-expert-users/79267-trick-bash-scripters-check-if-process-running.html" re... | [
{
"answer_id": 38071,
"author": "Mark Harrison",
"author_id": 116,
"author_profile": "https://Stackoverflow.com/users/116",
"pm_score": 5,
"selected": false,
"text": "<p>on linux, you can look in the directory /proc/$PID to get information about that process. In fact, if the directory e... | 2008/09/01 | [
"https://Stackoverflow.com/questions/38056",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1531/"
] | The only *nice* way I've found is:
```
import sys
import os
try:
os.kill(int(sys.argv[1]), 0)
print "Running"
except:
print "Not running"
```
([Source](http://www.unix.com/unix-advanced-expert-users/79267-trick-bash-scripters-check-if-process-running.html))
But is this reliable? Does it w... | Mark's answer is the way to go, after all, that's why the /proc file system is there. For something a little more copy/pasteable:
```
>>> import os.path
>>> os.path.exists("/proc/0")
False
>>> os.path.exists("/proc/12")
True
``` |
38,057 | <pre><code>@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
public class Problem {
@ManyToOne
private Person person;
}
@Entity
@DiscriminatorValue("UP")
public class UglyProblem extends Problem {}
@Entity
public class Person {
@OneToMany(mappedBy="person")
private List< UglyProblem >... | [
{
"answer_id": 38096,
"author": "Peter Hilton",
"author_id": 2670,
"author_profile": "https://Stackoverflow.com/users/2670",
"pm_score": 1,
"selected": false,
"text": "<p>I think you need to annotate your <em>Problem</em> super-class with <em><a href=\"http://java.sun.com/javaee/5/docs/a... | 2008/09/01 | [
"https://Stackoverflow.com/questions/38057",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4052/"
] | ```
@Entity
@Inheritance(strategy = InheritanceType.SINGLE_TABLE)
public class Problem {
@ManyToOne
private Person person;
}
@Entity
@DiscriminatorValue("UP")
public class UglyProblem extends Problem {}
@Entity
public class Person {
@OneToMany(mappedBy="person")
private List< UglyProblem > problems;
}... | I think it's a wise decision made by the Hibernate team. They could be less arrogante and make it clear why it was implemented this way, but that's just how Emmanuel, Chris and Gavin works. :)
Let's try to understand the problem. I think your concepts are "lying". First you say that many **Problem**s are associated to... |
38,068 | <p>Is there any shorthand way of defining and using generic definitions without having to keep repeating a particular generic description such that if there is a change I don't have to change all definitions/usages though out the codebase for example is something like this possible:</p>
<pre><code>Typedef myGenDef = &... | [
{
"answer_id": 38098,
"author": "Aaron Maenpaa",
"author_id": 2603,
"author_profile": "https://Stackoverflow.com/users/2603",
"pm_score": 1,
"selected": false,
"text": "<p>No. Though, groovy, a JVM language, is dynamically typed and would let you write:</p>\n\n<pre><code>def map = new Ha... | 2008/09/01 | [
"https://Stackoverflow.com/questions/38068",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | Is there any shorthand way of defining and using generic definitions without having to keep repeating a particular generic description such that if there is a change I don't have to change all definitions/usages though out the codebase for example is something like this possible:
```
Typedef myGenDef = < Object1, Obje... | There's the [pseudo-typedef antipattern](http://www.ibm.com/developerworks/java/library/j-jtp02216/index.html)...
```
class StringList extends ArrayList<String> { }
```
Good stuff, drink up! ;-)
As the article notes, this technique has some serious issues, primarily that this "typedef" is actually a separate class... |
38,074 | <p>If you create an Oracle dblink you cannot directly access LOB columns in the target tables.</p>
<p>For instance, you create a dblink with:</p>
<pre><code>create database link TEST_LINK
connect to TARGETUSER IDENTIFIED BY password using 'DATABASESID';
</code></pre>
<p>After this you can do stuff like:</p>
<pre... | [
{
"answer_id": 38142,
"author": "hamishmcn",
"author_id": 3590,
"author_profile": "https://Stackoverflow.com/users/3590",
"pm_score": 0,
"selected": false,
"text": "<p>Do you have a specific scenario in mind?\nFor example, if the LOB holds files, and you are on a company intranet, perhap... | 2008/09/01 | [
"https://Stackoverflow.com/questions/38074",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2846/"
] | If you create an Oracle dblink you cannot directly access LOB columns in the target tables.
For instance, you create a dblink with:
```
create database link TEST_LINK
connect to TARGETUSER IDENTIFIED BY password using 'DATABASESID';
```
After this you can do stuff like:
```
select column_a, column_b
from data_... | Yeah, it is messy, I can't think of a way to avoid it though.
You could hide some of the messiness from the client by putting the temporary table creation in a stored procedure (and using "execute immediate" to create they table)
One thing you will need to watch out for is left over temporary tables (should somet... |
38,160 | <p>Lets say I have a loop in Bash:</p>
<pre><code>for foo in `some-command`
do
do-something $foo
done
</code></pre>
<p><code>do-something</code> is cpu bound and I have a nice shiny 4 core processor. I'd like to be able to run up to 4 <code>do-something</code>'s at once.</p>
<p>The naive approach seems to be:</p>... | [
{
"answer_id": 38166,
"author": "skolima",
"author_id": 3205,
"author_profile": "https://Stackoverflow.com/users/3205",
"pm_score": 4,
"selected": false,
"text": "<p>Instead of a plain bash, use a Makefile, then specify number of simultaneous jobs with <code>make -jX</code> where X is th... | 2008/09/01 | [
"https://Stackoverflow.com/questions/38160",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/163/"
] | Lets say I have a loop in Bash:
```
for foo in `some-command`
do
do-something $foo
done
```
`do-something` is cpu bound and I have a nice shiny 4 core processor. I'd like to be able to run up to 4 `do-something`'s at once.
The naive approach seems to be:
```
for foo in `some-command`
do
do-something $foo &
d... | Depending on what you want to do xargs also can help (here: converting documents with pdf2ps):
```
cpus=$( ls -d /sys/devices/system/cpu/cpu[[:digit:]]* | wc -w )
find . -name \*.pdf | xargs --max-args=1 --max-procs=$cpus pdf2ps
```
From the docs:
```
--max-procs=max-procs
-P max-procs
Run up to max-procs ... |
38,288 | <p>Specifically, what commands do I run from the terminal?</p>
| [
{
"answer_id": 38289,
"author": "quackingduck",
"author_id": 3624,
"author_profile": "https://Stackoverflow.com/users/3624",
"pm_score": 8,
"selected": true,
"text": "<p>Without a home directory</p>\n\n<pre><code>sudo useradd myuser\n</code></pre>\n\n<p>With home directory</p>\n\n<pre><c... | 2008/09/01 | [
"https://Stackoverflow.com/questions/38288",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3624/"
] | Specifically, what commands do I run from the terminal? | Without a home directory
```
sudo useradd myuser
```
With home directory
```
sudo useradd -m myuser
```
Then set the password
```
sudo passwd myuser
```
Then set the shell
```
sudo usermod -s /bin/bash myuser
``` |
38,308 | <p>Drawing a parallelgram is nicely supported with Graphics.DrawImage:</p>
<pre><code>Bitmap destImage = new Bitmap(srcImage.Width, srcImage.Height);
using (Graphics gr = new Graphics.FromImage(destImage))
{
Point[] destPts = new Point[] { new PointF(x1, y1),
new PointF(x2, y2), new PointF(x4, y4)};
g... | [
{
"answer_id": 38403,
"author": "Adam Tegen",
"author_id": 4066,
"author_profile": "https://Stackoverflow.com/users/4066",
"pm_score": 1,
"selected": false,
"text": "<p>Normally you would do this with a 3x3 Matrix, but the Matrix class only lets you specify 6 values instead of 9. You mi... | 2008/09/01 | [
"https://Stackoverflow.com/questions/38308",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3798/"
] | Drawing a parallelgram is nicely supported with Graphics.DrawImage:
```
Bitmap destImage = new Bitmap(srcImage.Width, srcImage.Height);
using (Graphics gr = new Graphics.FromImage(destImage))
{
Point[] destPts = new Point[] { new PointF(x1, y1),
new PointF(x2, y2), new PointF(x4, y4)};
gr.DrawImage(sr... | Closest I can find is [this information](http://vckicks.110mb.com/image-distortion.html), which is extremely laggy. |
38,345 | <p>I recently "needed" a zip function in Perl 5 (while I was thinking about <a href="https://stackoverflow.com/questions/11/how-do-i-calculate-relative-time">How do I calculate relative time?</a>), i.e. a function that takes two lists and "zips" them together to one list, interleaving the elements.</p>
<p>(Pseudo)exam... | [
{
"answer_id": 38365,
"author": "Jason Navarrete",
"author_id": 3920,
"author_profile": "https://Stackoverflow.com/users/3920",
"pm_score": 5,
"selected": false,
"text": "<p>The <a href=\"http://search.cpan.org/perldoc?List::MoreUtils\" rel=\"noreferrer\">List::MoreUtils</a> module has a... | 2008/09/01 | [
"https://Stackoverflow.com/questions/38345",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2905/"
] | I recently "needed" a zip function in Perl 5 (while I was thinking about [How do I calculate relative time?](https://stackoverflow.com/questions/11/how-do-i-calculate-relative-time)), i.e. a function that takes two lists and "zips" them together to one list, interleaving the elements.
(Pseudo)example:
```
@a=(1, 2, ... | Assuming you have exactly two lists and they are exactly the same length, here is a solution originally by merlyn (Randal Schwartz), who called it perversely perlish:
```
sub zip2 {
my $p = @_ / 2;
return @_[ map { $_, $_ + $p } 0 .. $p - 1 ];
}
```
What happens here is that for a 10-element list, first, we... |
38,352 | <p>I need to store contact information for users. I want to present this data on the page as an <a href="http://en.wikipedia.org/wiki/Hcard" rel="nofollow noreferrer">hCard</a> and downloadable as a <a href="http://en.wikipedia.org/wiki/VCard" rel="nofollow noreferrer">vCard</a>. I'd also like to be able to search the ... | [
{
"answer_id": 38436,
"author": "palmsey",
"author_id": 521,
"author_profile": "https://Stackoverflow.com/users/521",
"pm_score": 1,
"selected": false,
"text": "<p>I'm aware of SQLite, but that doesn't really help - I'm talking about figuring out the best schema (regardless of the databa... | 2008/09/01 | [
"https://Stackoverflow.com/questions/38352",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/521/"
] | I need to store contact information for users. I want to present this data on the page as an [hCard](http://en.wikipedia.org/wiki/Hcard) and downloadable as a [vCard](http://en.wikipedia.org/wiki/VCard). I'd also like to be able to search the database by phone number, email, etc.
What do you think is the best way to ... | Consider two tables for People and their addresses:
```
People (pid, prefix, firstName, lastName, suffix, DOB, ... primaryAddressTag )
AddressBook (pid, tag, address1, address2, city, stateProv, postalCode, ... )
```
The Primary Key (that uniquely identifies each and every row) of People is `pid`. The PK of Addres... |
38,370 | <p>I've to admin a small website for my alumni group which is hosted by my ISV. The url is something like www.myIsv.com/myWebSite/ which is quite ugly and very forgetable. The main admin of the webserver has registered a domain name www.mysmallwebsite.com and put a index.html with this content:</p>
<pre><code><html... | [
{
"answer_id": 38382,
"author": "Alexandru Nedelcu",
"author_id": 3280,
"author_profile": "https://Stackoverflow.com/users/3280",
"pm_score": 0,
"selected": false,
"text": "<p>What do you mean?\nAre you saying that when you go from www.mysmallwebsite.com to www.myIsv.com/myWebSite/ then ... | 2008/09/01 | [
"https://Stackoverflow.com/questions/38370",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1578/"
] | I've to admin a small website for my alumni group which is hosted by my ISV. The url is something like www.myIsv.com/myWebSite/ which is quite ugly and very forgetable. The main admin of the webserver has registered a domain name www.mysmallwebsite.com and put a index.html with this content:
```
<html>
<head>
<title>w... | Sessions are tied to the server **AND** the domain. Using frameset across domain will cause all kind of breakage because that's just not how it was designed to do.
Try using apache mod rewrite to create a "passthrough redirection", the "**proxy**" flag ([P]) in the rule is the magic flag that you need
Documentation ... |
38,409 | <p>I would like to convert the following string into an array/nested array: </p>
<pre><code>str = "[[this, is],[a, nested],[array]]"
newarray = # this is what I need help with!
newarray.inspect # => [['this','is'],['a','nested'],['array']]
</code></pre>
| [
{
"answer_id": 38477,
"author": "Ben Childs",
"author_id": 2925,
"author_profile": "https://Stackoverflow.com/users/2925",
"pm_score": 0,
"selected": false,
"text": "<p>Looks like a basic parsing task. Generally the approach you are going to want to take is to create a recursive function... | 2008/09/01 | [
"https://Stackoverflow.com/questions/38409",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4082/"
] | I would like to convert the following string into an array/nested array:
```
str = "[[this, is],[a, nested],[array]]"
newarray = # this is what I need help with!
newarray.inspect # => [['this','is'],['a','nested'],['array']]
``` | You'll get what you want with YAML.
But there is a little problem with your string. YAML expects that there's a space behind the comma. So we need this
```
str = "[[this, is], [a, nested], [array]]"
```
Code:
```
require 'yaml'
str = "[[this, is],[a, nested],[array]]"
### transform your string in a valid YAML-Stri... |
38,431 | <p>Using MVC out of the box I found the generated URLs can be misleading and I wanted to know if this can be fixed or if my approach/understanding is wrong.</p>
<p>Suppose I have a CreateEgg page, which has a form on it, and once the form is filled in and submitted the user is taken to a ListEggs page with the new egg... | [
{
"answer_id": 38452,
"author": "Brad Wilson",
"author_id": 1554,
"author_profile": "https://Stackoverflow.com/users/1554",
"pm_score": 2,
"selected": false,
"text": "<p>The problem is your action does two things, violating the Single Responsibility Principle.</p>\n\n<p>If your Create ac... | 2008/09/01 | [
"https://Stackoverflow.com/questions/38431",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/230/"
] | Using MVC out of the box I found the generated URLs can be misleading and I wanted to know if this can be fixed or if my approach/understanding is wrong.
Suppose I have a CreateEgg page, which has a form on it, and once the form is filled in and submitted the user is taken to a ListEggs page with the new egg in it.
S... | The problem is your action does two things, violating the Single Responsibility Principle.
If your Create action redirects to the List action when it's done creating the item, then this problem disappears. |
38,435 | <p>Given an Oracle table created using the following:</p>
<pre><code>CREATE TABLE Log(WhenAdded TIMESTAMP(6) WITH TIME ZONE);
</code></pre>
<p>Using the Python ODBC module from its <a href="http://www.python.org/download/windows/" rel="nofollow noreferrer">Win32 extensions</a> (from the win32all package), I tried the... | [
{
"answer_id": 38442,
"author": "Jason Etheridge",
"author_id": 2193,
"author_profile": "https://Stackoverflow.com/users/2193",
"pm_score": 1,
"selected": false,
"text": "<p>My solution to this, that I hope can be bettered, is to use Oracle to explicitly convert the TIMESTAMP into a stri... | 2008/09/01 | [
"https://Stackoverflow.com/questions/38435",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2193/"
] | Given an Oracle table created using the following:
```
CREATE TABLE Log(WhenAdded TIMESTAMP(6) WITH TIME ZONE);
```
Using the Python ODBC module from its [Win32 extensions](http://www.python.org/download/windows/) (from the win32all package), I tried the following:
```
import dbi, odbc
connection = odbc.odbc("Driv... | I believe this is a bug in the Oracle ODBC driver. Basically, the Oracle ODBC driver does not support the `TIMESTAMP WITH (LOCAL) TIME ZONE` data types, only the `TIMESTAMP` data type. As you have discovered, one workaround is in fact to use the `TO_CHAR` method.
In your example you are not actually reading the time z... |
38,501 | <p>I'm trying to come up with a design for a thread pool with a lot of design requirements for my job. This is a real problem for working software, and it's a difficult task. I have a working implementation but I'd like to throw this out to SO and see what interesting ideas people can come up with, so that I can compa... | [
{
"answer_id": 38504,
"author": "DrPizza",
"author_id": 2131,
"author_profile": "https://Stackoverflow.com/users/2131",
"pm_score": 1,
"selected": false,
"text": "<blockquote>\n <p>It needs to run on Windows XP, Server 2003, Vista and Server 2008 (latest service packs).</p>\n</blockquot... | 2008/09/01 | [
"https://Stackoverflow.com/questions/38501",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3146/"
] | I'm trying to come up with a design for a thread pool with a lot of design requirements for my job. This is a real problem for working software, and it's a difficult task. I have a working implementation but I'd like to throw this out to SO and see what interesting ideas people can come up with, so that I can compare t... | So what are we going to pick as the basic building block for this. Windows has two building blocks that look promising :- I/O Completion Ports (IOCPs) and Asynchronous Procedure Calls (APCs). Both of these give us FIFO queuing without having to perform explicit locking, and with a certain amount of built-in OS support ... |
38,508 | <p>I have a function where I need to do something to a string. I need the function to return a boolean indicating whether or not the operation succeeded, and I also need to return the modified string. </p>
<p>In C#, I would use an out parameter for the string, but there is no equivalent in Python. I'm still very ne... | [
{
"answer_id": 38513,
"author": "Chris Upchurch",
"author_id": 2600,
"author_profile": "https://Stackoverflow.com/users/2600",
"pm_score": 3,
"selected": false,
"text": "<p>Returning a tuple is the usual way to do this in Python.</p>\n"
},
{
"answer_id": 38514,
"author": "rmm... | 2008/09/01 | [
"https://Stackoverflow.com/questions/38508",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3880/"
] | I have a function where I need to do something to a string. I need the function to return a boolean indicating whether or not the operation succeeded, and I also need to return the modified string.
In C#, I would use an out parameter for the string, but there is no equivalent in Python. I'm still very new to Python a... | ```
def f(in_str):
out_str = in_str.upper()
return True, out_str # Creates tuple automatically
succeeded, b = f("a") # Automatic tuple unpacking
``` |
38,549 | <p>Also, how do <code>LEFT OUTER JOIN</code>, <code>RIGHT OUTER JOIN</code>, and <code>FULL OUTER JOIN</code> fit in?</p>
| [
{
"answer_id": 38552,
"author": "1800 INFORMATION",
"author_id": 3146,
"author_profile": "https://Stackoverflow.com/users/3146",
"pm_score": 7,
"selected": false,
"text": "<p>A inner join only shows rows if there is a matching record on the other (right) side of the join.</p>\n\n<p>A (le... | 2008/09/01 | [
"https://Stackoverflow.com/questions/38549",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3836/"
] | Also, how do `LEFT OUTER JOIN`, `RIGHT OUTER JOIN`, and `FULL OUTER JOIN` fit in? | Assuming you're joining on columns with no duplicates, which is a very common case:
* An inner join of A and B gives the result of A intersect B, i.e. the inner part of a [Venn diagram](http://en.wikipedia.org/wiki/Venn_diagram) intersection.
* An outer join of A and B gives the results of A union B, i.e. the outer pa... |
38,561 | <p>The <code>printf</code> function takes an argument type, such as <code>%d</code> or <code>%i</code> for a <code>signed int</code>. However, I don't see anything for a <code>long</code> value.</p>
| [
{
"answer_id": 38566,
"author": "Rob Walker",
"author_id": 3631,
"author_profile": "https://Stackoverflow.com/users/3631",
"pm_score": 4,
"selected": false,
"text": "<p><code>%ld</code> see <a href=\"http://www.cplusplus.com/reference/clibrary/cstdio/printf.html\" rel=\"noreferrer\"><cod... | 2008/09/01 | [
"https://Stackoverflow.com/questions/38561",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/572/"
] | The `printf` function takes an argument type, such as `%d` or `%i` for a `signed int`. However, I don't see anything for a `long` value. | Put an `l` (lowercased letter L) directly before the specifier.
```
unsigned long n;
long m;
printf("%lu %ld", n, m);
``` |
38,571 | <p>I find myself doing this sort of thing all the time. I've been considering writing a macro/function to make this sort of thing easier, but it occurs to me that I'm probably reinventing the wheel.</p>
<p>Is there an existing function that will let me accomplish this same sort of thing more succinctly?</p>
<pre><co... | [
{
"answer_id": 38594,
"author": "Chris Hanson",
"author_id": 714,
"author_profile": "https://Stackoverflow.com/users/714",
"pm_score": -1,
"selected": false,
"text": "<p>There are a couple ways you can do this. First, and probably most easily, you can do it recursively.</p>\n\n<pre><cod... | 2008/09/01 | [
"https://Stackoverflow.com/questions/38571",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/56456/"
] | I find myself doing this sort of thing all the time. I've been considering writing a macro/function to make this sort of thing easier, but it occurs to me that I'm probably reinventing the wheel.
Is there an existing function that will let me accomplish this same sort of thing more succinctly?
```
(defun remove-low-w... | There are several built-in ways of doing this. One way would be:
```
(remove-if-not 'good-enough-score-p word-list)
```
And another:
```
(loop for word in word-list
when (good-enough-score-p word)
collect word)
```
And yet another:
```
(mapcan (lambda (word)
(when (good-enough-score-p wor... |
38,592 | <p>I'd like to be able to write a ruby program that can restart without dropping it's socket connections.</p>
| [
{
"answer_id": 38597,
"author": "wvdschel",
"author_id": 2018,
"author_profile": "https://Stackoverflow.com/users/2018",
"pm_score": 0,
"selected": false,
"text": "<p>You're talking about network sockets, not UNIX sockets I assume?</p>\n\n<p>I'm not sure this suits your needs, but the wa... | 2008/09/01 | [
"https://Stackoverflow.com/questions/38592",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/823/"
] | I'd like to be able to write a ruby program that can restart without dropping it's socket connections. | This program gets Google's homepage and then when you pass it SIG\_INT via `Ctrl`-`C` it restarts the program and reads the output of the homepage from the open socket with Google.
```
#!/usr/bin/ruby
#simple_connector.rb
require 'socket'
puts "Started."
if ARGV[0] == "restart"
sock = IO.open(ARGV[1].to_i)
puts ... |
38,601 | <p>How can I use the nifty JavaScript date and time widgets that the default admin uses with my custom view?</p>
<p>I have looked through <a href="https://docs.djangoproject.com/en/dev/topics/forms/" rel="noreferrer">the Django forms documentation</a>, and it briefly mentions django.contrib.admin.widgets, but I don't ... | [
{
"answer_id": 38916,
"author": "Carl Meyer",
"author_id": 3207,
"author_profile": "https://Stackoverflow.com/users/3207",
"pm_score": 8,
"selected": true,
"text": "<p>The growing complexity of this answer over time, and the many hacks required, probably ought to caution you against doin... | 2008/09/01 | [
"https://Stackoverflow.com/questions/38601",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2592/"
] | How can I use the nifty JavaScript date and time widgets that the default admin uses with my custom view?
I have looked through [the Django forms documentation](https://docs.djangoproject.com/en/dev/topics/forms/), and it briefly mentions django.contrib.admin.widgets, but I don't know how to use it?
Here is my templa... | The growing complexity of this answer over time, and the many hacks required, probably ought to caution you against doing this at all. It's relying on undocumented internal implementation details of the admin, is likely to break again in future versions of Django, and is no easier to implement than just finding another... |
38,602 | <p>I am attempting to set an asp.net textbox to a SQL 2005 money data type field, the initial result displayed to the user is 40.0000 instead of 40.00.
In my asp.net textbox control I would like to only display the first 2 numbers after the decimal point e.g. 40.00</p>
<p>What would be the best way to do this?
My code... | [
{
"answer_id": 38611,
"author": "YonahW",
"author_id": 3821,
"author_profile": "https://Stackoverflow.com/users/3821",
"pm_score": 3,
"selected": true,
"text": "<pre><code>this.txtPayment.Text = string.Format(\"{0:c}\", dr[Payment\"].ToString());\n</code></pre>\n"
},
{
"answer_id... | 2008/09/01 | [
"https://Stackoverflow.com/questions/38602",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4096/"
] | I am attempting to set an asp.net textbox to a SQL 2005 money data type field, the initial result displayed to the user is 40.0000 instead of 40.00.
In my asp.net textbox control I would like to only display the first 2 numbers after the decimal point e.g. 40.00
What would be the best way to do this?
My code is below:... | ```
this.txtPayment.Text = string.Format("{0:c}", dr[Payment"].ToString());
``` |
38,645 | <p>I want to combine two structures with differing fields names.</p>
<p>For example, starting with:</p>
<pre><code>A.field1 = 1;
A.field2 = 'a';
B.field3 = 2;
B.field4 = 'b';
</code></pre>
<p>I would like to have:</p>
<pre><code>C.field1 = 1;
C.field2 = 'a';
C.field3 = 2;
C.field4 = 'b';
</code></pre>
<p>Is there... | [
{
"answer_id": 38659,
"author": "pbh101",
"author_id": 1266,
"author_profile": "https://Stackoverflow.com/users/1266",
"pm_score": 2,
"selected": false,
"text": "<p>In C, a struct can have another struct as one of it's members. While this isn't exactly the same as what you're asking, yo... | 2008/09/02 | [
"https://Stackoverflow.com/questions/38645",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4135/"
] | I want to combine two structures with differing fields names.
For example, starting with:
```
A.field1 = 1;
A.field2 = 'a';
B.field3 = 2;
B.field4 = 'b';
```
I would like to have:
```
C.field1 = 1;
C.field2 = 'a';
C.field3 = 2;
C.field4 = 'b';
```
Is there a more efficient way than using "fieldnames" and a for ... | Without collisions, you can do
```
M = [fieldnames(A)' fieldnames(B)'; struct2cell(A)' struct2cell(B)'];
C=struct(M{:});
```
And this is reasonably efficient. However, `struct` errors on duplicate fieldnames, and pre-checking for them using `unique` kills performance to the point that a loop is better. But here's w... |
38,647 | <p><strong>When using the Entity Framework, does ESQL perform better than Linq to Entities?</strong> </p>
<p>I'd prefer to use Linq to Entities (mainly because of the strong-type checking), but some of my other team members are citing performance as a reason to use ESQL. I would like to get a full idea of the pro's/co... | [
{
"answer_id": 38689,
"author": "lomaxx",
"author_id": 493,
"author_profile": "https://Stackoverflow.com/users/493",
"pm_score": 1,
"selected": false,
"text": "<p>The more code you can cover with compile time checking for me is something that I'd place a higher premium on than performanc... | 2008/09/02 | [
"https://Stackoverflow.com/questions/38647",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/708/"
] | **When using the Entity Framework, does ESQL perform better than Linq to Entities?**
I'd prefer to use Linq to Entities (mainly because of the strong-type checking), but some of my other team members are citing performance as a reason to use ESQL. I would like to get a full idea of the pro's/con's of using either met... | The most obvious differences are:
Linq to Entities is strongly typed code including nice query comprehension syntax. The fact that the “from” comes before the “select” allows IntelliSense to help you.
Entity SQL uses traditional string based queries with a more familiar SQL like syntax where the SELECT statement come... |
38,651 | <p>Is there any way to have a binary compiled from an ActionScript 3 project print stuff to <em>stdout</em> when executed?</p>
<p>From what I've gathered, people have been going around this limitation by writing hacks that rely on local socket connections and AIR apps that write to files in the local filesystem, but t... | [
{
"answer_id": 38936,
"author": "Theo",
"author_id": 1109,
"author_profile": "https://Stackoverflow.com/users/1109",
"pm_score": 2,
"selected": false,
"text": "<p>As you say, there's no Adobe-created way to do this, but you might have better luck with <a href=\"http://www.multidmedia.com... | 2008/09/02 | [
"https://Stackoverflow.com/questions/38651",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4111/"
] | Is there any way to have a binary compiled from an ActionScript 3 project print stuff to *stdout* when executed?
From what I've gathered, people have been going around this limitation by writing hacks that rely on local socket connections and AIR apps that write to files in the local filesystem, but that's pretty much... | With AIR on Linux, it is easy to write to stdout, since the process can see its own file descriptors as files in /dev.
For stdout, open `/dev/fd/1` or `/dev/stdout` as a `FileStream`, then write to that.
Example:
```
var stdout : FileStream = new FileStream();
stdout.open(new File("/dev/fd/1"), FileMode.WRITE);
stdo... |
38,661 | <p>Is there any way in IIS to map requests to a particular URL with no extension to a given application.</p>
<p>For example, in trying to port something from a Java servlet, you might have a URL like this...</p>
<p><a href="http://[server]/MyApp/HomePage?some=parameter" rel="nofollow noreferrer">http://[server]/MyApp... | [
{
"answer_id": 38936,
"author": "Theo",
"author_id": 1109,
"author_profile": "https://Stackoverflow.com/users/1109",
"pm_score": 2,
"selected": false,
"text": "<p>As you say, there's no Adobe-created way to do this, but you might have better luck with <a href=\"http://www.multidmedia.com... | 2008/09/02 | [
"https://Stackoverflow.com/questions/38661",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/797/"
] | Is there any way in IIS to map requests to a particular URL with no extension to a given application.
For example, in trying to port something from a Java servlet, you might have a URL like this...
<http://[server]/MyApp/HomePage?some=parameter>
Ideally I'd like to be able to map everything under MyApp to a particul... | With AIR on Linux, it is easy to write to stdout, since the process can see its own file descriptors as files in /dev.
For stdout, open `/dev/fd/1` or `/dev/stdout` as a `FileStream`, then write to that.
Example:
```
var stdout : FileStream = new FileStream();
stdout.open(new File("/dev/fd/1"), FileMode.WRITE);
stdo... |
38,670 | <p>Ok, so, my visual studio is broken. I say this NOT prematurely, as it was my first response to see where I had messed up in my code. When I add controls to the page I can't reference all of them in the code behind. Some of them I can, it seems that the first few I put on a page work, then it just stops. </p>
<p>I f... | [
{
"answer_id": 38688,
"author": "Sean Lynch",
"author_id": 4043,
"author_profile": "https://Stackoverflow.com/users/4043",
"pm_score": 4,
"selected": false,
"text": "<p>Is the control that you are trying to reference inside of the repeater?</p>\n\n<p>If so then you need to look them up u... | 2008/09/02 | [
"https://Stackoverflow.com/questions/38670",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4140/"
] | Ok, so, my visual studio is broken. I say this NOT prematurely, as it was my first response to see where I had messed up in my code. When I add controls to the page I can't reference all of them in the code behind. Some of them I can, it seems that the first few I put on a page work, then it just stops.
I first thoug... | try clearing your local VS cache. find your project and delete the folder. the folder is created by VS for what reason I honestly don't understand. but I've had several occasions where clearing it and doing a re-build fixes things... hope this is all that you need as well.
here
```
%Temp%\VWDWebCache
```
and possib... |
38,691 | <p>Hey so what I want to do is snag the content for the first paragraph. The string <code>$blog_post</code> contains a lot of paragraphs in the following format:</p>
<pre><code><p>Paragraph 1</p><p>Paragraph 2</p><p>Paragraph 3</p>
</code></pre>
<p>The problem I'm running into is t... | [
{
"answer_id": 38696,
"author": "Paige Ruten",
"author_id": 813,
"author_profile": "https://Stackoverflow.com/users/813",
"pm_score": 1,
"selected": false,
"text": "<p>It would probably be easier and faster to use <a href=\"http://php.net/strpos\" rel=\"nofollow noreferrer\">strpos()</a>... | 2008/09/02 | [
"https://Stackoverflow.com/questions/38691",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/428190/"
] | Hey so what I want to do is snag the content for the first paragraph. The string `$blog_post` contains a lot of paragraphs in the following format:
```
<p>Paragraph 1</p><p>Paragraph 2</p><p>Paragraph 3</p>
```
The problem I'm running into is that I am writing a regex to grab everything between the first `<p>` tag a... | Well, sysrqb will let you match anything in the first paragraph assuming there's no other html in the paragraph. You might want something more like this
```
<p>.*?</p>
```
Placing the `?` after your `*` makes it non-greedy, meaning it will only match as little text as necessary before matching the `</p>`. |
38,713 | <p>I'm trying to pick up ruby by porting a medium-sized (non-OO) perl program. One of my personal idioms is to set options like this:</p>
<pre><code>use Getopt::Std;
our $opt_v; # be verbose
getopts('v');
# and later ...
$opt_v && print "something interesting\n";
</code></pre>
<p>In perl, I kind of grit my t... | [
{
"answer_id": 38741,
"author": "John",
"author_id": 2168,
"author_profile": "https://Stackoverflow.com/users/2168",
"pm_score": 1,
"selected": false,
"text": "<p>The <a href=\"http://www.rubyinside.com/trollop-command-line-option-parser-for-ruby-944.html\" rel=\"nofollow noreferrer\">fi... | 2008/09/02 | [
"https://Stackoverflow.com/questions/38713",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3979/"
] | I'm trying to pick up ruby by porting a medium-sized (non-OO) perl program. One of my personal idioms is to set options like this:
```
use Getopt::Std;
our $opt_v; # be verbose
getopts('v');
# and later ...
$opt_v && print "something interesting\n";
```
In perl, I kind of grit my teeth and let $opt\_v be (effective... | A while back I ran across [this blog post](http://blog.toddwerth.com/entries/5) (by Todd Werth) which presented a rather lengthy skeleton for command-line scripts in Ruby. His skeleton uses a hybrid approach in which the application code is encapsulated in an application class which is instantiated, then executed by ca... |
38,729 | <p>I decided to make a system for a client using <a href="https://web.archive.org/web/20080517021542/http://www.castleproject.org/activerecord/index.html" rel="nofollow noreferrer">Castle ActiveRecord</a>, everything went well until I found that the transactions do not work, for instance;</p>
<pre><code> ... | [
{
"answer_id": 38737,
"author": "Michael Haren",
"author_id": 29,
"author_profile": "https://Stackoverflow.com/users/29",
"pm_score": 3,
"selected": true,
"text": "<p>Ben's got it. That doc is a little confusing. Refer to the last block <a href=\"https://web.archive.org/web/2008041701414... | 2008/09/02 | [
"https://Stackoverflow.com/questions/38729",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1130097/"
] | I decided to make a system for a client using [Castle ActiveRecord](https://web.archive.org/web/20080517021542/http://www.castleproject.org/activerecord/index.html), everything went well until I found that the transactions do not work, for instance;
```
TransactionScope t = new TransactionScope();
... | Ben's got it. That doc is a little confusing. Refer to the last block [on the page](https://web.archive.org/web/20080417014143/http://www.castleproject.org/ActiveRecord/documentation/v1rc1/usersguide/scopes.html), "Nested transactions". |
38,746 | <p>Over at <a href="https://stackoverflow.com/questions/38664/can-you-modify-text-files-when-committing-to-subversion">Can you modify text files when committing to subversion?</a> <a href="https://stackoverflow.com/questions/38664/can-you-modify-text-files-when-committing-to-subversion#38666">Grant</a> suggested that I... | [
{
"answer_id": 39162,
"author": "bstark",
"author_id": 4056,
"author_profile": "https://Stackoverflow.com/users/4056",
"pm_score": 2,
"selected": false,
"text": "<p>You could use something like this as your pre-commit script:</p>\n\n<pre>\n#! /usr/bin/perl\n\nwhile (<>) {\n $las... | 2008/09/02 | [
"https://Stackoverflow.com/questions/38746",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/486/"
] | Over at [Can you modify text files when committing to subversion?](https://stackoverflow.com/questions/38664/can-you-modify-text-files-when-committing-to-subversion) [Grant](https://stackoverflow.com/questions/38664/can-you-modify-text-files-when-committing-to-subversion#38666) suggested that I block commits instead.
... | **[@Konrad](https://stackoverflow.com/questions/38746/how-to-detect-file-ends-in-newline#39185)**: tail does not return an empty line. I made a file that has some text that doesn't end in newline and a file that does. Here is the output from tail:
```none
$ cat test_no_newline.txt
this file doesn't end in newline$
$... |
38,756 | <p>I'm looking for a way of getting a <strong>concurrent collection</strong> in <strong>C#</strong> or at least a collection which supports a <strong>concurrent enumerator</strong>. Right now I'm getting an <code>InvalidOperationException</code> when the collection over which I'm iterating changes. </p>
<p>I could j... | [
{
"answer_id": 38765,
"author": "Damian",
"author_id": 3390,
"author_profile": "https://Stackoverflow.com/users/3390",
"pm_score": 4,
"selected": true,
"text": "<p>Other than doing a deep-copy your best bet might be to lock the collection:</p>\n\n<pre><code> List<string> theList ... | 2008/09/02 | [
"https://Stackoverflow.com/questions/38756",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/361/"
] | I'm looking for a way of getting a **concurrent collection** in **C#** or at least a collection which supports a **concurrent enumerator**. Right now I'm getting an `InvalidOperationException` when the collection over which I'm iterating changes.
I could just deep copy the collection and work with a private copy but ... | Other than doing a deep-copy your best bet might be to lock the collection:
```
List<string> theList = (List<String> )callingForm.Invoke(callingForm.delegateGetKillStrings);
lock(theList.SyncRoot) {
foreach(string s in theList) {
// Do some Jazz
}
}
``` |
38,791 | <p>Which Database table Schema is more efficient and why?</p>
<pre><code>"Users (UserID, UserName, CompamyId)"
"Companies (CompamyId, CompanyName)"
</code></pre>
<p>OR</p>
<pre><code>"Users (UserID, UserName)"
"Companies (CompamyId, CompanyName)"
"UserCompanies (UserID, CompamyId)"
</code></pre>
<p>Given the fact t... | [
{
"answer_id": 38793,
"author": "Vaibhav",
"author_id": 380,
"author_profile": "https://Stackoverflow.com/users/380",
"pm_score": 4,
"selected": true,
"text": "<p>For sure, the earlier one is more efficient given that constraint. For getting the same information, you will have less numbe... | 2008/09/02 | [
"https://Stackoverflow.com/questions/38791",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/191/"
] | Which Database table Schema is more efficient and why?
```
"Users (UserID, UserName, CompamyId)"
"Companies (CompamyId, CompanyName)"
```
OR
```
"Users (UserID, UserName)"
"Companies (CompamyId, CompanyName)"
"UserCompanies (UserID, CompamyId)"
```
Given the fact that user and company have one-to-one relation. | For sure, the earlier one is more efficient given that constraint. For getting the same information, you will have less number of joins in your queries. |
38,820 | <p>Which class design is better and why?</p>
<pre><code>public class User
{
public String UserName;
public String Password;
public String FirstName;
public String LastName;
}
public class Employee : User
{
public String EmployeeId;
public String EmployeeCode;
public String DepartmentId;
}
... | [
{
"answer_id": 38827,
"author": "Brad Wilson",
"author_id": 1554,
"author_profile": "https://Stackoverflow.com/users/1554",
"pm_score": 4,
"selected": false,
"text": "<p>I don't like either one. What happens when someone is both a member and an employee?</p>\n"
},
{
"answer_id": ... | 2008/09/02 | [
"https://Stackoverflow.com/questions/38820",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/191/"
] | Which class design is better and why?
```
public class User
{
public String UserName;
public String Password;
public String FirstName;
public String LastName;
}
public class Employee : User
{
public String EmployeeId;
public String EmployeeCode;
public String DepartmentId;
}
public class ... | The question is simply answered by recognising that inheritance models an "IS-A" relationship, while membership models a "HAS-A" relationship.
* An employee IS A user
* An employee HAS A userinfo
Which one is correct? This is your answer. |
38,842 | <p>I need to do a simple mail merge in OpenOffice using C++, VBScript, VB.Net or C# via OLE or native API. Are there any good examples available?</p>
| [
{
"answer_id": 38976,
"author": "Peter Stuifzand",
"author_id": 1633,
"author_profile": "https://Stackoverflow.com/users/1633",
"pm_score": 2,
"selected": false,
"text": "<p>You should take a look at <strong><a href=\"http://api.openoffice.org\" rel=\"nofollow noreferrer\">Apache OpenOff... | 2008/09/02 | [
"https://Stackoverflow.com/questions/38842",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3146/"
] | I need to do a simple mail merge in OpenOffice using C++, VBScript, VB.Net or C# via OLE or native API. Are there any good examples available? | I haven't come up with a solution I'm really happy with but here are some notes:
* Q. What is the OO API for mail merge?
A. <http://api.openoffice.org/docs/common/ref/com/sun/star/text/MailMerge.html>
* Q. What support groups?
A. <http://user.services.openoffice.org/en/forum/viewforum.php?f=20>
* Q. Sample code?
A.... |
38,875 | <p>My website was recently attacked by, what seemed to me as, an innocent code:</p>
<pre><code><?php
if ( isset( $ _GET['page'] ) ) {
include( $ _GET['page'] . ".php" );
} else {
include("home.php");
}
?>
</code></pre>
<p>There where no SQL calls, so I wasn't afraid for SQL Injection. But, apparen... | [
{
"answer_id": 38884,
"author": "Till",
"author_id": 2859,
"author_profile": "https://Stackoverflow.com/users/2859",
"pm_score": 2,
"selected": false,
"text": "<p>I'm assuming you deal with files in the same directory:</p>\n\n<pre><code><?php\nif (isset($_GET['page']) && !empt... | 2008/09/02 | [
"https://Stackoverflow.com/questions/38875",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2644/"
] | My website was recently attacked by, what seemed to me as, an innocent code:
```
<?php
if ( isset( $ _GET['page'] ) ) {
include( $ _GET['page'] . ".php" );
} else {
include("home.php");
}
?>
```
There where no SQL calls, so I wasn't afraid for SQL Injection. But, apparently, SQL isn't the only kind of ... | Use a whitelist and make sure the page is in the whitelist:
```
$whitelist = array('home', 'page');
if (in_array($_GET['page'], $whitelist)) {
include($_GET['page'].'.php');
} else {
include('home.php');
}
``` |
38,890 | <p>Is there a way to enforce constraint checking in MSSQL only when inserting new rows? I.e. allow the constraints to be violated when removing/updating rows?</p>
<p>Update: I mean FK constraint.</p>
| [
{
"answer_id": 38892,
"author": "Jon Limjap",
"author_id": 372,
"author_profile": "https://Stackoverflow.com/users/372",
"pm_score": 1,
"selected": false,
"text": "<p>I think your best bet is to remove the explicit constraint and add a <a href=\"http://msdn.microsoft.com/en-us/library/ms... | 2008/09/02 | [
"https://Stackoverflow.com/questions/38890",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3153/"
] | Is there a way to enforce constraint checking in MSSQL only when inserting new rows? I.e. allow the constraints to be violated when removing/updating rows?
Update: I mean FK constraint. | You could create an INSERT TRIGGER that checks that the conditions are met. That way all updates will go straight through.
```
CREATE TRIGGER employee_insupd
ON employee
FOR INSERT
AS
/* Get the range of level for this job type from the jobs table. */
DECLARE @min_lvl tinyint,
@max_lvl tinyint,
@emp_lvl tinyint,... |
38,920 | <p>I'm getting this problem:</p>
<pre><code>PHP Warning: mail() [function.mail]: SMTP server response: 550 5.7.1 Unable to relay for [email protected] in c:\inetpub\wwwroot\mailtest.php on line 12
</code></pre>
<p>from this script:</p>
<pre><code><?php
$to = "[email protected]";
$subject = "test";
$body ... | [
{
"answer_id": 38923,
"author": "Espo",
"author_id": 2257,
"author_profile": "https://Stackoverflow.com/users/2257",
"pm_score": 1,
"selected": false,
"text": "<p>You are using the wrong SMTP-server. If you you are only going to send emails to your gmail-account, have a look at my answer... | 2008/09/02 | [
"https://Stackoverflow.com/questions/38920",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/479/"
] | I'm getting this problem:
```
PHP Warning: mail() [function.mail]: SMTP server response: 550 5.7.1 Unable to relay for [email protected] in c:\inetpub\wwwroot\mailtest.php on line 12
```
from this script:
```
<?php
$to = "[email protected]";
$subject = "test";
$body = "this is a test";
if (mail($to, $subj... | Try removing the IP restrictions for Relaying in the SMTP server, and opening it up to all relays. If it works when this is set, then you know that the problem has to do with the original restrictions. In this case, it may be a DNS issue, or perhaps you had the wrong IP address listed. |
38,922 | <p>I have a rails application where each user has a separate database. (taking Joel Spolsky's advice on this). I want to run DB migrations from the rails application to create a new database and tables for this user. </p>
<p>What is the easiest way to do this? </p>
<p>Maybe the db migration is not the best for this t... | [
{
"answer_id": 38927,
"author": "roo",
"author_id": 716,
"author_profile": "https://Stackoverflow.com/users/716",
"pm_score": 1,
"selected": false,
"text": "<p>We use seperate configuration files for each user. So in the config/ dir we would have roo.database.yml which would connect to m... | 2008/09/02 | [
"https://Stackoverflow.com/questions/38922",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2737/"
] | I have a rails application where each user has a separate database. (taking Joel Spolsky's advice on this). I want to run DB migrations from the rails application to create a new database and tables for this user.
What is the easiest way to do this?
Maybe the db migration is not the best for this type of thing. Tha... | To answer part of your question, here's how you'd run a rake task from inside Rails code:
```
require 'rake'
load 'path/to/task.rake'
Rake::Task['foo:bar:baz'].invoke
```
Mind you, I have no idea how (or why) you could have one database per user. |
38,940 | <p>If I've got a table containing Field1 and Field2 can I generate a new field in the select statement? For example, a normal query would be:</p>
<pre><code>SELECT Field1, Field2 FROM Table
</code></pre>
<p>And I want to also create Field3 and have that returned in the resultset... something along the lines of this ... | [
{
"answer_id": 38942,
"author": "Josh",
"author_id": 257,
"author_profile": "https://Stackoverflow.com/users/257",
"pm_score": 5,
"selected": true,
"text": "<pre><code>SELECT Field1, Field2, 'Value' Field3 FROM Table\n</code></pre>\n\n<p>or for clarity</p>\n\n<pre><code>SELECT Field1, Fi... | 2008/09/02 | [
"https://Stackoverflow.com/questions/38940",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/393028/"
] | If I've got a table containing Field1 and Field2 can I generate a new field in the select statement? For example, a normal query would be:
```
SELECT Field1, Field2 FROM Table
```
And I want to also create Field3 and have that returned in the resultset... something along the lines of this would be ideal:
```
SELEC... | ```
SELECT Field1, Field2, 'Value' Field3 FROM Table
```
or for clarity
```
SELECT Field1, Field2, 'Value' AS Field3 FROM Table
``` |
38,948 | <p>Can I use <a href="http://struts.apache.org/" rel="nofollow noreferrer">Struts</a> as a backend and PHP as front end for a web application? If yes, what may be the implications.</p>
| [
{
"answer_id": 38972,
"author": "Doug Miller",
"author_id": 3431280,
"author_profile": "https://Stackoverflow.com/users/3431280",
"pm_score": 0,
"selected": false,
"text": "<p>What do you mean by backend and and frontend?</p>\n\n<p>If you mean using Java for the admin side of your site a... | 2008/09/02 | [
"https://Stackoverflow.com/questions/38948",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | Can I use [Struts](http://struts.apache.org/) as a backend and PHP as front end for a web application? If yes, what may be the implications. | The first thing to came to mind is [Quercus](http://www.caucho.com/resin-3.0/quercus/) (from the makers of the Resin servlet engine), as Jordi mentioned. It is a Java implementation of the PHP runtime and purportedly allows you to access Java objects directly from your PHP (part of me says "yay, at last").
On the othe... |
38,960 | <p>I would like to test a string containing a path to a file for existence of that file (something like the <code>-e</code> test in Perl or the <code>os.path.exists()</code> in Python) in C#.</p>
| [
{
"answer_id": 38962,
"author": "Daniel Jennings",
"author_id": 3641,
"author_profile": "https://Stackoverflow.com/users/3641",
"pm_score": 9,
"selected": true,
"text": "<p>Use:</p>\n\n<pre><code>File.Exists(path)\n</code></pre>\n\n<p>MSDN: <a href=\"http://msdn.microsoft.com/en-us/libra... | 2008/09/02 | [
"https://Stackoverflow.com/questions/38960",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2260/"
] | I would like to test a string containing a path to a file for existence of that file (something like the `-e` test in Perl or the `os.path.exists()` in Python) in C#. | Use:
```
File.Exists(path)
```
MSDN: <http://msdn.microsoft.com/en-us/library/system.io.file.exists.aspx>
Edit: In System.IO |
38,987 | <p>I want to merge two dictionaries into a new dictionary.</p>
<pre><code>x = {'a': 1, 'b': 2}
y = {'b': 3, 'c': 4}
z = merge(x, y)
>>> z
{'a': 1, 'b': 3, 'c': 4}
</code></pre>
<p>Whenever a key <code>k</code> is present in both dictionaries, only the value <code>y[k]</code> should be kept.</p>
| [
{
"answer_id": 38989,
"author": "Greg Hewgill",
"author_id": 893,
"author_profile": "https://Stackoverflow.com/users/893",
"pm_score": 7,
"selected": false,
"text": "<pre><code>x = {'a':1, 'b': 2}\ny = {'b':10, 'c': 11}\nz = dict(x.items() + y.items())\nprint z\n</code></pre>\n\n<p>For i... | 2008/09/02 | [
"https://Stackoverflow.com/questions/38987",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3207/"
] | I want to merge two dictionaries into a new dictionary.
```
x = {'a': 1, 'b': 2}
y = {'b': 3, 'c': 4}
z = merge(x, y)
>>> z
{'a': 1, 'b': 3, 'c': 4}
```
Whenever a key `k` is present in both dictionaries, only the value `y[k]` should be kept. | How can I merge two Python dictionaries in a single expression?
---------------------------------------------------------------
For dictionaries `x` and `y`, their shallowly-merged dictionary `z` takes values from `y`, replacing those from `x`.
* In Python 3.9.0 or greater (released 17 October 2020, [`PEP-584`](https... |
38,993 | <p>Here's a basic regex technique that I've never managed to remember. Let's say I'm using a fairly generic regex implementation (e.g., grep or grep -E). If I were to do a list of files and match any that end in either <code>.sty</code> or <code>.cls</code>, how would I do that?</p>
| [
{
"answer_id": 38994,
"author": "Peter Hoffmann",
"author_id": 720,
"author_profile": "https://Stackoverflow.com/users/720",
"pm_score": 2,
"selected": false,
"text": "<pre><code>egrep \"\\.sty$|\\.cls$\"\n</code></pre>\n"
},
{
"answer_id": 39000,
"author": "aku",
"author... | 2008/09/02 | [
"https://Stackoverflow.com/questions/38993",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4161/"
] | Here's a basic regex technique that I've never managed to remember. Let's say I'm using a fairly generic regex implementation (e.g., grep or grep -E). If I were to do a list of files and match any that end in either `.sty` or `.cls`, how would I do that? | ```
ls | grep -E "\.(sty|cls)$"
```
* `\.` matches literally a `"."` - an unescaped `.` matches any character
* `(sty|cls)` - match `"sty"` or `"cls"` - the | is an `or` and the brackets limit the expression.
* `$` forces the match to be at the end of the line
Note, you want `grep -E` or `egrep`, not `grep -e` as th... |
38,998 | <p>I'm an Information Architect and JavaScript developer by trade nowadays, but recently I've been getting back into back-end coding again. And, whilst trying to get an HTML prototype integrated and working with our C#-based CMS, I've come to blows with our programmers over the HTML ID attributes being arbitrarily rew... | [
{
"answer_id": 39012,
"author": "Serhat Ozgel",
"author_id": 31505,
"author_profile": "https://Stackoverflow.com/users/31505",
"pm_score": 2,
"selected": false,
"text": "<p>You can extend .net controls and make them return actual id's when related properties are called.</p>\n\n<p>ClientI... | 2008/09/02 | [
"https://Stackoverflow.com/questions/38998",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3212/"
] | I'm an Information Architect and JavaScript developer by trade nowadays, but recently I've been getting back into back-end coding again. And, whilst trying to get an HTML prototype integrated and working with our C#-based CMS, I've come to blows with our programmers over the HTML ID attributes being arbitrarily rewritt... | The short answer is no, with webforms the id can always be rewritten depending on the nesting of the element. You can get access to the id through the ClientID property, so you could set the ids into variables in a script at the end of the page/control then put them into jQuery.
something like this:
```
<asp:button ... |
39,003 | <p>If I have interface IFoo, and have several classes that implement it, what is the best/most elegant/cleverest way to test all those classes against the interface?</p>
<p>I'd like to reduce test code duplication, but still 'stay true' to the principles of Unit testing.</p>
<p>What would you consider best practice? ... | [
{
"answer_id": 39008,
"author": "graham.reeds",
"author_id": 342,
"author_profile": "https://Stackoverflow.com/users/342",
"pm_score": 0,
"selected": false,
"text": "<p>I don't use NUnit but I have tested C++ interfaces. I would first test a TestFoo class which is a basic implementation ... | 2008/09/02 | [
"https://Stackoverflow.com/questions/39003",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3024/"
] | If I have interface IFoo, and have several classes that implement it, what is the best/most elegant/cleverest way to test all those classes against the interface?
I'd like to reduce test code duplication, but still 'stay true' to the principles of Unit testing.
What would you consider best practice? I'm using NUnit, ... | If you have classes implement any one interface then they all need to implement the methods in that interface. In order to test these classes you need to create a unit test class for each of the classes.
Lets go with a smarter route instead; if your goal is to **avoid code and test code duplication** you might want to... |
39,006 | <p>I'm running WAMP v2.0 on WindowsXP and I've got a bunch of virtual hosts setup in the http-vhosts.conf file.</p>
<p>This was working, but in the last week whenever I try & start WAMP I get this error in the event logs:</p>
<blockquote>
<p>VirtualHost *:80 -- mixing * ports and
non-* ports with a NameVirtua... | [
{
"answer_id": 39287,
"author": "dguaraglia",
"author_id": 2384,
"author_profile": "https://Stackoverflow.com/users/2384",
"pm_score": 0,
"selected": false,
"text": "<p>Well, it seems the problem there is the way (and order) in which you assign the ports. </p>\n\n<p>Basically, *:80 means... | 2008/09/02 | [
"https://Stackoverflow.com/questions/39006",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2975/"
] | I'm running WAMP v2.0 on WindowsXP and I've got a bunch of virtual hosts setup in the http-vhosts.conf file.
This was working, but in the last week whenever I try & start WAMP I get this error in the event logs:
>
> VirtualHost \*:80 -- mixing \* ports and
> non-\* ports with a NameVirtualHost
> address is not sup... | >
> NameVirtualHost \*:80
>
>
> I get this error:
>
>
> Only one usage of each socket address (protocol/network address/port) is normally >permitted. : make\_sock: could not bind to address 0.0.0.0:80
>
>
>
I think this might be because you have somthing else listening to port 80. Do you have any other servers... |
39,053 | <p>I'm trying to access a data source that is defined within a web container (JBoss) from a fat client outside the container.</p>
<p>I've decided to look up the data source through JNDI. Actually, my persistence framework (Ibatis) does this.</p>
<p>When performing queries I always end up getting this error:</p>
<pre... | [
{
"answer_id": 39153,
"author": "brabster",
"author_id": 2362,
"author_profile": "https://Stackoverflow.com/users/2362",
"pm_score": 0,
"selected": false,
"text": "<p>I think the exception indicates that the SQLConnection object you're trying to retrieve doesn't implement the Serializabl... | 2008/09/02 | [
"https://Stackoverflow.com/questions/39053",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | I'm trying to access a data source that is defined within a web container (JBoss) from a fat client outside the container.
I've decided to look up the data source through JNDI. Actually, my persistence framework (Ibatis) does this.
When performing queries I always end up getting this error:
```
java.lang.IllegalAcce... | Not sure if this is the same issue?
[JBoss DataSource config](http://www.redhat.com/docs/manuals/jboss/jboss-eap-4.2/doc/Server_Configuration_Guide/Connectors_on_JBoss-Configuring_JDBC_DataSources.html)
>
> DataSource wrappers are not usable outside of the server VM
>
>
> |
39,061 | <p>I've convinced myself that they can't.</p>
<p>Take for example:</p>
<p>4 4 + 4 /</p>
<p>stack: 4
stack: 4 4
4 + 4 = 8
stack: 8
stack: 8 4
8 / 4 = 2
stack: 2</p>
<p>There are two ways that you could write the above expression with the
same operators and operands such that the operands all come first: "4
4 4 + /... | [
{
"answer_id": 39068,
"author": "Lasse V. Karlsen",
"author_id": 267,
"author_profile": "https://Stackoverflow.com/users/267",
"pm_score": 0,
"selected": false,
"text": "<p>It is enough to show one that can't in order to tell you the answer to this.</p>\n\n<p>If you can't reorder the sta... | 2008/09/02 | [
"https://Stackoverflow.com/questions/39061",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4175/"
] | I've convinced myself that they can't.
Take for example:
4 4 + 4 /
stack: 4
stack: 4 4
4 + 4 = 8
stack: 8
stack: 8 4
8 / 4 = 2
stack: 2
There are two ways that you could write the above expression with the
same operators and operands such that the operands all come first: "4
4 4 + /" and "4 4 4 / +", neither of w... | Consider the algebraic expression:
```
(a + b) * (c + d)
```
The obvious translation to RPN would be:
```
a b + c d + *
```
Even with a swap operation available, I don't think there is a way to collect all the operators on the right:
```
a b c d +
a b S
```
where S is the sum of c and d. At this point, you cou... |
39,064 | <p>I'm trying to call a 3rd party vendor's C DLL from vb.net 2005 and am getting <code>P/Invoke</code> errors. I'm successfully calling other methods but have hit a bottle-neck on one of the more complex. The structures involved are horrendous and in an attempt to simplify the troubleshooting I'd like to create a C++... | [
{
"answer_id": 39079,
"author": "Greg Hewgill",
"author_id": 893,
"author_profile": "https://Stackoverflow.com/users/893",
"pm_score": 2,
"selected": false,
"text": "<p>Try using the <a href=\"http://msdn.microsoft.com/en-us/library/3y1sfaz2.aspx\" rel=\"nofollow noreferrer\">__decspec(d... | 2008/09/02 | [
"https://Stackoverflow.com/questions/39064",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | I'm trying to call a 3rd party vendor's C DLL from vb.net 2005 and am getting `P/Invoke` errors. I'm successfully calling other methods but have hit a bottle-neck on one of the more complex. The structures involved are horrendous and in an attempt to simplify the troubleshooting I'd like to create a C++ DLL to replicat... | Try using the [\_\_decspec(dllexport)](http://msdn.microsoft.com/en-us/library/3y1sfaz2.aspx) magic pixie dust in your C++ function declaration. This declaration sets up several things that you need to successfully export a function from a DLL. You may also need to use WINAPI or something similar:
```
__declspec(dllex... |
39,070 | <p>We need to move off traditional FTP for security purposes (it transmits it's passwords unencrypted). I am hearing SSH touted as the obvious alternative. However I have been driving FTP from an ASP.NET program interface to automate my web-site development, which is now quite a highly web-enabled process. </p>
<p>Can... | [
{
"answer_id": 39074,
"author": "Galwegian",
"author_id": 3201,
"author_profile": "https://Stackoverflow.com/users/3201",
"pm_score": 1,
"selected": false,
"text": "<p>We have used a variation of <a href=\"http://www.jscape.com/articles/sftp_using_csharp.html\" rel=\"nofollow noreferrer\... | 2008/09/02 | [
"https://Stackoverflow.com/questions/39070",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4180/"
] | We need to move off traditional FTP for security purposes (it transmits it's passwords unencrypted). I am hearing SSH touted as the obvious alternative. However I have been driving FTP from an ASP.NET program interface to automate my web-site development, which is now quite a highly web-enabled process.
Can anyone re... | the question has three subquestions:
1) choosing the secure transfer protocol
The secure version of old FTP exists - it's called FTP/SSL (plain old FTP over SSL encrypted channel). Maybe you can still use your old deployment infrastructure - just check whether it supports the FTPS or FTP/SSL.
You can check details a... |
39,086 | <p>I want to loop over the contents of a text file and do a search and replace on some lines and write the result back to the file. I could first load the whole file in memory and then write it back, but that probably is not the best way to do it.</p>
<p>What is the best way to do this, within the following code?</p>
... | [
{
"answer_id": 39089,
"author": "Lasse V. Karlsen",
"author_id": 267,
"author_profile": "https://Stackoverflow.com/users/267",
"pm_score": 3,
"selected": false,
"text": "<p>Create a new file, copy lines from the old to the new, and do the replacing before you write the lines to the new f... | 2008/09/02 | [
"https://Stackoverflow.com/questions/39086",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4166/"
] | I want to loop over the contents of a text file and do a search and replace on some lines and write the result back to the file. I could first load the whole file in memory and then write it back, but that probably is not the best way to do it.
What is the best way to do this, within the following code?
```
f = open(... | I guess something like this should do it. It basically writes the content to a new file and replaces the old file with the new file:
```
from tempfile import mkstemp
from shutil import move, copymode
from os import fdopen, remove
def replace(file_path, pattern, subst):
#Create temp file
fh, abs_path = mkstemp... |
39,104 | <p>I've written a Python package that includes a bsddb database of pre-computed values for one of the more time-consuming computations. For simplicity, my setup script installs the database file in the same directory as the code which accesses the database (on Unix, something like /usr/lib/python2.5/site-packages/mypa... | [
{
"answer_id": 39295,
"author": "dguaraglia",
"author_id": 2384,
"author_profile": "https://Stackoverflow.com/users/2384",
"pm_score": 2,
"selected": false,
"text": "<p>That's probably the way to do it, without resorting to something more advanced like using setuptools to install the fil... | 2008/09/02 | [
"https://Stackoverflow.com/questions/39104",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4198/"
] | I've written a Python package that includes a bsddb database of pre-computed values for one of the more time-consuming computations. For simplicity, my setup script installs the database file in the same directory as the code which accesses the database (on Unix, something like /usr/lib/python2.5/site-packages/mypackag... | Try using pkg\_resources, which is part of setuptools (and available on all of the pythons I have access to right now):
```
>>> import pkg_resources
>>> pkg_resources.resource_filename(__name__, "foo.config")
'foo.config'
>>> pkg_resources.resource_filename('tempfile', "foo.config")
'/usr/lib/python2.4/foo.config'
``... |
39,108 | <p>What would be the best way to draw a simple animation just before showing a modal <a href="https://docs.oracle.com/javase/9/docs/api/javax/swing/JDialog.html" rel="nofollow noreferrer">JDialog</a>? (i.e. expanding borders from the mouse click point to the dialog location). I thought it would be possible to draw on t... | [
{
"answer_id": 39868,
"author": "rcreswick",
"author_id": 3446,
"author_profile": "https://Stackoverflow.com/users/3446",
"pm_score": 1,
"selected": false,
"text": "<p>Are you trying to show the JDialog indepentently of the annimation? In order to get the order set properly, you may need... | 2008/09/02 | [
"https://Stackoverflow.com/questions/39108",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3993/"
] | What would be the best way to draw a simple animation just before showing a modal [JDialog](https://docs.oracle.com/javase/9/docs/api/javax/swing/JDialog.html)? (i.e. expanding borders from the mouse click point to the dialog location). I thought it would be possible to draw on the glasspane of the parent frame on the ... | Are you trying to show the JDialog indepentently of the annimation? In order to get the order set properly, you may need to bundle those actions in a runnable that is passed to the EDT at once.
eg:
```
SwingUtilities.invokeLater(new Runnable(){
public void run(){
doAnnimation();
showDialog();
}
}
`... |
39,112 | <p>I know in certain circumstances, such as long running processes, it is important to lock ASP.NET cache in order to avoid subsequent requests by another user for that resource from executing the long process again instead of hitting the cache.</p>
<p>What is the best way in c# to implement cache locking in ASP.NET? ... | [
{
"answer_id": 39144,
"author": "khebbie",
"author_id": 4189,
"author_profile": "https://Stackoverflow.com/users/4189",
"pm_score": 2,
"selected": false,
"text": "<p>Craig Shoemaker has made an excellent show on asp.net caching:\n<a href=\"http://polymorphicpodcast.com/shows/webperforman... | 2008/09/02 | [
"https://Stackoverflow.com/questions/39112",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2471/"
] | I know in certain circumstances, such as long running processes, it is important to lock ASP.NET cache in order to avoid subsequent requests by another user for that resource from executing the long process again instead of hitting the cache.
What is the best way in c# to implement cache locking in ASP.NET? | Here's the basic pattern:
* Check the cache for the value, return if its available
* If the value is not in the cache, then implement a lock
* Inside the lock, check the cache again, you might have been blocked
* Perform the value look up and cache it
* Release the lock
In code, it looks like this:
```
private stati... |
39,240 | <p>I have lots of article store in MS SQL server 2005 database in a table called Articles-</p>
<pre><code>"Articles (ArticleID, ArticleTitle, ArticleContent)"
</code></pre>
<p>Now I want some SP or SQL query which could return me similar Article against any user's input (very much like "Similar Posts" in blogs OR "Re... | [
{
"answer_id": 39257,
"author": "aku",
"author_id": 1196,
"author_profile": "https://Stackoverflow.com/users/1196",
"pm_score": 0,
"selected": false,
"text": "<p>First of all you need to define what article similarity means.<br>\nFor example you can associate some meta information with a... | 2008/09/02 | [
"https://Stackoverflow.com/questions/39240",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/191/"
] | I have lots of article store in MS SQL server 2005 database in a table called Articles-
```
"Articles (ArticleID, ArticleTitle, ArticleContent)"
```
Now I want some SP or SQL query which could return me similar Article against any user's input (very much like "Similar Posts" in blogs OR "Related Questions" in stacko... | Something like this might work, a kind of ranking system. You would probably have to split the string in your application to build a SQL string, but I have used similar to build an effective site search.
```
Select
Top 10
ArticleID,
ArticleTitle,
ArticleContent
From
Articles
Order By
(Case When ArticleTitle = 'Article... |
39,243 | <p>Is there any query which can return me the number of revisions made to the structure of a database table?</p>
<p>Secondly, how can I determine the number of pages (in terms of size) present in mdf or ldf files?</p>
| [
{
"answer_id": 39269,
"author": "Christian Hagelid",
"author_id": 202,
"author_profile": "https://Stackoverflow.com/users/202",
"pm_score": 2,
"selected": false,
"text": "<p>I think you need to create a <code>trigger</code> and store all changes to the table in a separate table. You can ... | 2008/09/02 | [
"https://Stackoverflow.com/questions/39243",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4021/"
] | Is there any query which can return me the number of revisions made to the structure of a database table?
Secondly, how can I determine the number of pages (in terms of size) present in mdf or ldf files? | You can get last modify date or creation date of object in `SQL Server`.
For examle info on tables:
```
SELECT * FROM sys.objects WHERE type='U'
```
[More info on msdn](http://msdn.microsoft.com/en-us/library/ms190324.aspx)
Number of pages can be fetched from `sys.database_files`.
[Check documentation](http://msd... |
39,281 | <p>We have a requirement in project to store all the revisions(Change History) for the entities in the database. Currently we have 2 designed proposals for this:</p>
<p>e.g. for "Employee" Entity</p>
<p><strong>Design 1:</strong></p>
<pre><code>-- Holds Employee Entity
"Employees (EmployeeId, FirstName, LastName, De... | [
{
"answer_id": 39296,
"author": "Matthew Watson",
"author_id": 3839,
"author_profile": "https://Stackoverflow.com/users/3839",
"pm_score": 3,
"selected": false,
"text": "<p>The way that I've seen this done in the past is have</p>\n\n<pre><code>Employees (EmployeeId, DateModified, < Em... | 2008/09/02 | [
"https://Stackoverflow.com/questions/39281",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/191/"
] | We have a requirement in project to store all the revisions(Change History) for the entities in the database. Currently we have 2 designed proposals for this:
e.g. for "Employee" Entity
**Design 1:**
```
-- Holds Employee Entity
"Employees (EmployeeId, FirstName, LastName, DepartmentId, .., ..)"
-- Holds the Employ... | 1. Do **not** put it all in one table with an IsCurrent discriminator attribute. This just causes problems down the line, requires surrogate keys and all sorts of other problems.
2. Design 2 does have problems with schema changes. If you change the Employees table you have to change the EmployeeHistories table and all ... |
39,364 | <p>I have inherited a client site which crashes every 3 or 4 days. It is built using the zend-framework with which I have no knowledge.</p>
<p>The following code:</p>
<pre><code><?php
// Make sure classes are in the include path.
ini_set('include_path', ini_get('include_path') . PATH_SEPARATOR . 'lib' . PAT... | [
{
"answer_id": 39372,
"author": "Adam Wright",
"author_id": 1200,
"author_profile": "https://Stackoverflow.com/users/1200",
"pm_score": 1,
"selected": false,
"text": "<p>The fact that it only happens sporadically makes me think this is less of a programming issue, and more of a sysadmin ... | 2008/09/02 | [
"https://Stackoverflow.com/questions/39364",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/319/"
] | I have inherited a client site which crashes every 3 or 4 days. It is built using the zend-framework with which I have no knowledge.
The following code:
```
<?php
// Make sure classes are in the include path.
ini_set('include_path', ini_get('include_path') . PATH_SEPARATOR . 'lib' . PATH_SEPARATOR . 'app' . DI... | for a start I think your include path should maybe have a trailing slash. Here is an example of mine :
```
set_include_path('../library/ZendFramework-1.5.2/library/:../application/classes/:../application/classes/excpetions/:../application/forms/');
```
You bootstrap file will be included by another file (probab... |
39,391 | <p>If I create an HTTP <code>java.net.URL</code> and then call <code>openConnection()</code> on it, does it necessarily imply that an HTTP post is going to happen? I know that <code>openStream()</code> implies a GET. If so, how do you perform one of the other HTTP verbs without having to work with the raw socket laye... | [
{
"answer_id": 39431,
"author": "WMR",
"author_id": 2844,
"author_profile": "https://Stackoverflow.com/users/2844",
"pm_score": 2,
"selected": false,
"text": "<p>No it does not. But if the protocol of the URL is HTTP, you'll get a <a href=\"http://java.sun.com/javase/6/docs/api/java/net/... | 2008/09/02 | [
"https://Stackoverflow.com/questions/39391",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4223/"
] | If I create an HTTP `java.net.URL` and then call `openConnection()` on it, does it necessarily imply that an HTTP post is going to happen? I know that `openStream()` implies a GET. If so, how do you perform one of the other HTTP verbs without having to work with the raw socket layer? | If you retrieve the `URLConnection` object using `openConnection()` it doesn't actually start communicating with the server. That doesn't happen until you get the stream from the `URLConnection()`. When you first get the connection you can add/change headers and other connection properties before actually opening it.
... |
39,395 | <p>How can I calculate the value of PI using C#?</p>
<p>I was thinking it would be through a recursive function, if so, what would it look like and are there any math equations to back it up?</p>
<p>I'm not too fussy about performance, mainly how to go about it from a learning point of view.</p>
| [
{
"answer_id": 39401,
"author": "Niyaz",
"author_id": 184,
"author_profile": "https://Stackoverflow.com/users/184",
"pm_score": 1,
"selected": false,
"text": "<p>Calculate like this:</p>\n\n<pre><code>x = 1 - 1/3 + 1/5 - 1/7 + 1/9 (... etc as far as possible.)\nPI = x * 4\n</code></pre>... | 2008/09/02 | [
"https://Stackoverflow.com/questions/39395",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/383/"
] | How can I calculate the value of PI using C#?
I was thinking it would be through a recursive function, if so, what would it look like and are there any math equations to back it up?
I'm not too fussy about performance, mainly how to go about it from a learning point of view. | If you want recursion:
```
PI = 2 * (1 + 1/3 * (1 + 2/5 * (1 + 3/7 * (...))))
```
This would become, after some rewriting:
```
PI = 2 * F(1);
```
with F(i):
```
double F (int i) {
return 1 + i / (2.0 * i + 1) * F(i + 1);
}
```
Isaac Newton (you may have heard of him before ;) ) came up with this trick.
Not... |
39,399 | <p>I have a struts-based webapp, and I would like the default "welcome" page to be an action. The only solutions I have found to this seem to be variations on making the welcome page a JSP that contains a redirect to the action. For example, in <code>web.xml</code>:</p>
<pre><code><welcome-file-list>
<wel... | [
{
"answer_id": 39599,
"author": "bpapa",
"author_id": 543,
"author_profile": "https://Stackoverflow.com/users/543",
"pm_score": 1,
"selected": false,
"text": "<p>It appears that a popular solution will not work in all containers... <a href=\"http://www.theserverside.com/discussions/threa... | 2008/09/02 | [
"https://Stackoverflow.com/questions/39399",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3913/"
] | I have a struts-based webapp, and I would like the default "welcome" page to be an action. The only solutions I have found to this seem to be variations on making the welcome page a JSP that contains a redirect to the action. For example, in `web.xml`:
```
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>... | Personally, I'd keep the same setup you have now, but change the redirect for a forward. That avoids sending a header back to the client and having them make another request.
So, in particular, I'd replace the
```
<%
response.sendRedirect("/myproject/MyAction.action");
%>
```
in index.jsp with
```
<jsp:forward... |
39,447 | <p>I have a class property exposing an internal IList<> through</p>
<pre><code>System.Collections.ObjectModel.ReadOnlyCollection<>
</code></pre>
<p>How can I pass a part of this <code>ReadOnlyCollection<></code> without copying elements into a new array (I need a live view, and the target device is sho... | [
{
"answer_id": 39460,
"author": "Nir",
"author_id": 3509,
"author_profile": "https://Stackoverflow.com/users/3509",
"pm_score": 1,
"selected": false,
"text": "<p>You can always write a class that implements IList and forwards all calls to the original list (so it doesn't have it's own co... | 2008/09/02 | [
"https://Stackoverflow.com/questions/39447",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3205/"
] | I have a class property exposing an internal IList<> through
```
System.Collections.ObjectModel.ReadOnlyCollection<>
```
How can I pass a part of this `ReadOnlyCollection<>` without copying elements into a new array (I need a live view, and the target device is short on memory)? I'm targetting Compact Framework 2.0. | Try a method that returns an enumeration using yield:
```
IEnumerable<T> FilterCollection<T>( ReadOnlyCollection<T> input ) {
foreach ( T item in input )
if ( /* criterion is met */ )
yield return item;
}
``` |
39,468 | <p>I've got a Windows DLL that I wrote, written in C/C++ (all exported functions are 'C'). The DLL works fine for me in VC++. I've given the DLL to another company who do all their development in VB. They seem to be having a problem linking to the functions. I haven't used VB in ten years and I don't even have it insta... | [
{
"answer_id": 39478,
"author": "Konrad Rudolph",
"author_id": 1968,
"author_profile": "https://Stackoverflow.com/users/1968",
"pm_score": 3,
"selected": true,
"text": "<p>By using <code>__declspec</code> for export, the function name will get exported <em>mangled</em>, i.e. contain type... | 2008/09/02 | [
"https://Stackoverflow.com/questions/39468",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3685/"
] | I've got a Windows DLL that I wrote, written in C/C++ (all exported functions are 'C'). The DLL works fine for me in VC++. I've given the DLL to another company who do all their development in VB. They seem to be having a problem linking to the functions. I haven't used VB in ten years and I don't even have it installe... | By using `__declspec` for export, the function name will get exported *mangled*, i.e. contain type information to help the C++ compiler resolve overloads.
VB6 cannot handle mangled names. As a workaround, you have to de-mangle the names. The easiest solution is to link the DLL file using an [export definition](http://... |
39,475 | <p>Hello I have the following error by git-fsck, which cannot be cleaned by git-gc even in --aggressive mode. What can I do next to fix this repository error? </p>
<pre><code>$ git-fsck
bad sha1 file: .git/objects/55/tmp_obj_a07724
</code></pre>
| [
{
"answer_id": 39927,
"author": "Jordi Bunster",
"author_id": 4272,
"author_profile": "https://Stackoverflow.com/users/4272",
"pm_score": 4,
"selected": true,
"text": "<p>It's not a simple answer, sadly. But this might help:</p>\n\n<p><a href=\"http://schacon.github.com/git/user-manual.h... | 2008/09/02 | [
"https://Stackoverflow.com/questions/39475",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2313/"
] | Hello I have the following error by git-fsck, which cannot be cleaned by git-gc even in --aggressive mode. What can I do next to fix this repository error?
```
$ git-fsck
bad sha1 file: .git/objects/55/tmp_obj_a07724
``` | It's not a simple answer, sadly. But this might help:
[Recovering from repository corruption](http://schacon.github.com/git/user-manual.html#recovering-from-repository-corruption) (from the Git's user manual). |
39,476 | <p>In the <a href="https://stackoverflow.com/questions/39447/how-can-i-expose-only-a-fragment-of-ilist">How Can I Expose Only a Fragment of IList<></a> question one of the answers had the following code snippet:</p>
<pre><code>IEnumerable<object> FilteredList()
{
foreach(object item in FullList)
{
... | [
{
"answer_id": 39482,
"author": "Joel Coehoorn",
"author_id": 3043,
"author_profile": "https://Stackoverflow.com/users/3043",
"pm_score": 9,
"selected": false,
"text": "<p>Iteration. It creates a state machine \"under the covers\" that remembers where you were on each additional cycle o... | 2008/09/02 | [
"https://Stackoverflow.com/questions/39476",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1409/"
] | In the [How Can I Expose Only a Fragment of IList<>](https://stackoverflow.com/questions/39447/how-can-i-expose-only-a-fragment-of-ilist) question one of the answers had the following code snippet:
```
IEnumerable<object> FilteredList()
{
foreach(object item in FullList)
{
if(IsItemInPartialList(item))... | The `yield` contextual keyword actually does quite a lot here.
The function returns an object that implements the `IEnumerable<object>` interface. If a calling function starts `foreach`ing over this object, the function is called again until it "yields". This is syntactic sugar introduced in **C# 2.0**. In earlier ver... |
39,536 | <p>I have a fairly small MySQL database (a Textpattern install) on a server that I do not have SSH access to (I have FTP access only). I need to regularly download the live database to my local dev server on demand; i.e., I would like to either run a script and/or have a cron job running. What are some good ways of doi... | [
{
"answer_id": 39545,
"author": "Mark Biek",
"author_id": 305,
"author_profile": "https://Stackoverflow.com/users/305",
"pm_score": 1,
"selected": false,
"text": "<p>Is MySQL replication an option? You could even turn it on and off if you didn't want it constantly replicating.</p>\n\n<p... | 2008/09/02 | [
"https://Stackoverflow.com/questions/39536",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1944/"
] | I have a fairly small MySQL database (a Textpattern install) on a server that I do not have SSH access to (I have FTP access only). I need to regularly download the live database to my local dev server on demand; i.e., I would like to either run a script and/or have a cron job running. What are some good ways of doing ... | Since you can access your database remotely, you can use mysqldump from your windows machine to fetch the remote database. From commandline:
```
cd "into mysql directory"
mysqldump -u USERNAME -p -h YOUR_HOST_IP DATABASE_TO_MIRROR >c:\backup\database.sql
```
The program will ask you for the database password and the... |
39,541 | <p>Maybe I just don't know .NET well enough yet, but I have yet to see a satisfactory way to implement this simple VB6 code easily in .NET (assume this code is on a form with N CommandButtons in array Command1() and N TextBoxes in array Text1()):</p>
<pre><code>Private Sub Command1_Click(Index As Integer)
Text1(In... | [
{
"answer_id": 39544,
"author": "Lasse V. Karlsen",
"author_id": 267,
"author_profile": "https://Stackoverflow.com/users/267",
"pm_score": 0,
"selected": false,
"text": "<p>Make an array of controls.</p>\n\n<pre><code>TextBox[] textboxes = new TextBox[] {\n textBox1,\n textBox2,\n ... | 2008/09/02 | [
"https://Stackoverflow.com/questions/39541",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4228/"
] | Maybe I just don't know .NET well enough yet, but I have yet to see a satisfactory way to implement this simple VB6 code easily in .NET (assume this code is on a form with N CommandButtons in array Command1() and N TextBoxes in array Text1()):
```
Private Sub Command1_Click(Index As Integer)
Text1(Index).Text = Ti... | Make a generic list of textboxes:
```
var textBoxes = new List<TextBox>();
// Create 10 textboxes in the collection
for (int i = 0; i < 10; i++)
{
var textBox = new TextBox();
textBox.Text = "Textbox " + i;
textBoxes.Add(textBox);
}
// Loop through and set new values on textboxes in collection
for (int i... |
39,561 | <p>Trying to get my css / C# functions to look like this:</p>
<pre><code>body {
color:#222;
}
</code></pre>
<p>instead of this:</p>
<pre><code>body
{
color:#222;
}
</code></pre>
<p>when I auto-format the code.</p>
| [
{
"answer_id": 39573,
"author": "FlySwat",
"author_id": 1965,
"author_profile": "https://Stackoverflow.com/users/1965",
"pm_score": 5,
"selected": false,
"text": "<p>Tools -> Options -> Text Editor -> C# -> Formatting -> New Lines -> New Line Options for braces -> Uncheck all boxes.</p>\... | 2008/09/02 | [
"https://Stackoverflow.com/questions/39561",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/26/"
] | Trying to get my css / C# functions to look like this:
```
body {
color:#222;
}
```
instead of this:
```
body
{
color:#222;
}
```
when I auto-format the code. | **C#**
1. In the *Tools* Menu click *Options*
2. Click *Show all Parameters* (checkbox at the bottom left) (*Show all settings* in VS 2010)
3. Text Editor
4. C#
5. Formatting
6. New lines
And there check when you want new lines with brackets
**Css:**
*almost the same, but fewer options*
1. In the *Tools* Menu clic... |
39,562 | <p>A friend of mine is now building a web application with J2EE and Struts, and it's going to be prepared to display pages in several languages.</p>
<p>I was told that the best way to support a multi-language site is to use a properties file where you store all the strings of your pages, something like:</p>
<pre><cod... | [
{
"answer_id": 39587,
"author": "Espo",
"author_id": 2257,
"author_profile": "https://Stackoverflow.com/users/2257",
"pm_score": 4,
"selected": true,
"text": "<p>They way I have designed the database before is to have an News-table containing basic info like NewsID (int), NewsPubDate (da... | 2008/09/02 | [
"https://Stackoverflow.com/questions/39562",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1679/"
] | A friend of mine is now building a web application with J2EE and Struts, and it's going to be prepared to display pages in several languages.
I was told that the best way to support a multi-language site is to use a properties file where you store all the strings of your pages, something like:
```
welcome.english = "... | They way I have designed the database before is to have an News-table containing basic info like NewsID (int), NewsPubDate (datetime), NewsAuthor (varchar/int) and then have a linked table NewsText that has these columns: NewsID(int), NewsText(text), NewsLanguageID(int). And at last you have a Language-table that has L... |
39,567 | <p>In Ruby, given an array in one of the following forms...</p>
<pre><code>[apple, 1, banana, 2]
[[apple, 1], [banana, 2]]
</code></pre>
<p>...what is the best way to convert this into a hash in the form of...</p>
<pre><code>{apple => 1, banana => 2}
</code></pre>
| [
{
"answer_id": 39621,
"author": "John Topley",
"author_id": 1450,
"author_profile": "https://Stackoverflow.com/users/1450",
"pm_score": 7,
"selected": false,
"text": "<p>Simply use <code>Hash[*array_variable.flatten]</code></p>\n\n<p>For example:</p>\n\n<pre><code>a1 = ['apple', 1, 'bana... | 2008/09/02 | [
"https://Stackoverflow.com/questions/39567",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4142/"
] | In Ruby, given an array in one of the following forms...
```
[apple, 1, banana, 2]
[[apple, 1], [banana, 2]]
```
...what is the best way to convert this into a hash in the form of...
```
{apple => 1, banana => 2}
``` | **NOTE**: For a concise and efficient solution, please see [Marc-André Lafortune's answer](https://stackoverflow.com/a/20831486/332936) below.
This answer was originally offered as an alternative to approaches using flatten, which were the most highly upvoted at the time of writing. I should have clarified that I didn... |
39,576 | <p>I'm looking for a good way to perform multi-row inserts into an Oracle 9 database. The following works in MySQL but doesn't seem to be supported in Oracle.</p>
<pre><code>INSERT INTO TMP_DIM_EXCH_RT
(EXCH_WH_KEY,
EXCH_NAT_KEY,
EXCH_DATE, EXCH_RATE,
FROM_CURCY_CD,
TO_CURCY_CD,
EXCH_EFF_DATE,
EXCH_EFF_E... | [
{
"answer_id": 39602,
"author": "Espo",
"author_id": 2257,
"author_profile": "https://Stackoverflow.com/users/2257",
"pm_score": 9,
"selected": true,
"text": "<p>This works in Oracle:</p>\n<pre><code>insert into pager (PAG_ID,PAG_PARENT,PAG_NAME,PAG_ACTIVE)\n select 8000,0,'Mult... | 2008/09/02 | [
"https://Stackoverflow.com/questions/39576",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3734/"
] | I'm looking for a good way to perform multi-row inserts into an Oracle 9 database. The following works in MySQL but doesn't seem to be supported in Oracle.
```
INSERT INTO TMP_DIM_EXCH_RT
(EXCH_WH_KEY,
EXCH_NAT_KEY,
EXCH_DATE, EXCH_RATE,
FROM_CURCY_CD,
TO_CURCY_CD,
EXCH_EFF_DATE,
EXCH_EFF_END_DATE,
EXCH... | This works in Oracle:
```
insert into pager (PAG_ID,PAG_PARENT,PAG_NAME,PAG_ACTIVE)
select 8000,0,'Multi 8000',1 from dual
union all select 8001,0,'Multi 8001',1 from dual
```
The thing to remember here is to use the `from dual` statement. |
39,583 | <p>How much do you rely on database transactions? </p>
<p>Do you prefer small or large transaction scopes ? </p>
<p>Do you prefer client side transaction handling (e.g. TransactionScope in .NET) over server
side transactions or vice-versa? </p>
<p>What about nested transactions? </p>
<p>Do you have some tips... | [
{
"answer_id": 39594,
"author": "DevelopingChris",
"author_id": 1220,
"author_profile": "https://Stackoverflow.com/users/1220",
"pm_score": 2,
"selected": false,
"text": "<p>I use transactions on every write operation to the database.<br>\nSo there are quite a few small \"transactions\" ... | 2008/09/02 | [
"https://Stackoverflow.com/questions/39583",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1196/"
] | How much do you rely on database transactions?
Do you prefer small or large transaction scopes ?
Do you prefer client side transaction handling (e.g. TransactionScope in .NET) over server
side transactions or vice-versa?
What about nested transactions?
Do you have some tips&tricks related to transactions ?
An... | I always wrap a transaction in a using statement.
```
using(IDbTransaction transaction )
{
// logic goes here.
transaction.Commit();
}
```
Once the transaction moves out of scope, it is disposed. If the transaction is still active, it is rolled back. This behaviour fail-safes you from accidentally locking out the... |
39,615 | <p>I have a set of base filenames, for each name 'f' there are exactly two files, 'f.in' and 'f.out'. I want to write a batch file (in Windows XP) which goes through all the filenames, for each one it should:</p>
<ul>
<li>Display the base name 'f'</li>
<li>Perform an action on 'f.in'</li>
<li>Perform another action o... | [
{
"answer_id": 39636,
"author": "Nathan Fritz",
"author_id": 4142,
"author_profile": "https://Stackoverflow.com/users/4142",
"pm_score": 3,
"selected": false,
"text": "<p>Easiest way, as I see it, is to use a for loop that calls a second batch file for processing, passing that second fil... | 2008/09/02 | [
"https://Stackoverflow.com/questions/39615",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3974/"
] | I have a set of base filenames, for each name 'f' there are exactly two files, 'f.in' and 'f.out'. I want to write a batch file (in Windows XP) which goes through all the filenames, for each one it should:
* Display the base name 'f'
* Perform an action on 'f.in'
* Perform another action on 'f.out'
I don't have any w... | Assuming you have two programs that process the two files, process\_in.exe and process\_out.exe:
```
for %%f in (*.in) do (
echo %%~nf
process_in "%%~nf.in"
process_out "%%~nf.out"
)
```
%%~nf is a substitution modifier, that expands %f to a file name only.
See other modifiers in <https://technet.microso... |
39,639 | <p>My project is based on spring framework 2.5.4. And I try to add aspects for some controllers (I use aspectj 1.5.3).</p>
<p>I've enabled auto-proxy in application-servlet.xml, just pasted these lines to the end of the xml file:</p>
<pre><code><aop:aspectj-autoproxy />
<bean id="auditLogProcessor" class="co... | [
{
"answer_id": 39766,
"author": "bpapa",
"author_id": 543,
"author_profile": "https://Stackoverflow.com/users/543",
"pm_score": 1,
"selected": false,
"text": "<p>AspectJ doesn't work well with classes in the Spring Web MVC framework. <a href=\"http://static.springframework.org/spring/doc... | 2008/09/02 | [
"https://Stackoverflow.com/questions/39639",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1007/"
] | My project is based on spring framework 2.5.4. And I try to add aspects for some controllers (I use aspectj 1.5.3).
I've enabled auto-proxy in application-servlet.xml, just pasted these lines to the end of the xml file:
```
<aop:aspectj-autoproxy />
<bean id="auditLogProcessor" class="com.example.bg.web.utils.AuditLo... | Your breakpoints aren't being hit because you are using Spring's AOP Proxies. See [understanding-aop-proxies](http://static.springframework.org/spring/docs/2.5.x/reference/aop.html#aop-understanding-aop-proxies) for a description of how AOP Proxies are special.
Basically, the MVC framework is going to call the `handl... |
39,651 | <p>In a <a href="https://stackoverflow.com/questions/21848/switch-branch-names-in-git">previous Git question</a>, Daniel Benamy was talking about a workflow in Git:</p>
<blockquote>
<p>I was working on master and committed some stuff and then decided I wanted to put that work on hold. I backed up a few commits and t... | [
{
"answer_id": 39862,
"author": "Jordi Bunster",
"author_id": 4272,
"author_profile": "https://Stackoverflow.com/users/4272",
"pm_score": 8,
"selected": true,
"text": "<p>'stash' takes the uncommitted, \"<em>dirty</em>\" stuff on your working copy, and stashes it away, leaving you with a... | 2008/09/02 | [
"https://Stackoverflow.com/questions/39651",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4161/"
] | In a [previous Git question](https://stackoverflow.com/questions/21848/switch-branch-names-in-git), Daniel Benamy was talking about a workflow in Git:
>
> I was working on master and committed some stuff and then decided I wanted to put that work on hold. I backed up a few commits and then branched from before I star... | 'stash' takes the uncommitted, "*dirty*" stuff on your working copy, and stashes it away, leaving you with a clean working copy.
It doesn't really branch at all. You can then apply the stash on top of any other branch. Or, as of Git 1.6, you can do:
```
git stash branch <branchname> [<stash>]
```
to apply the stash... |
39,674 | <p>I have the following script. It replaces all instances of @lookFor with @replaceWith in all tables in a database. However it doesn't work with text fields only varchar etc. Could this be easily adapted?</p>
<pre><code>------------------------------------------------------------
-- Name: STRING REPLACER
-- Author: A... | [
{
"answer_id": 39699,
"author": "Espo",
"author_id": 2257,
"author_profile": "https://Stackoverflow.com/users/2257",
"pm_score": 1,
"selected": false,
"text": "<p>You can not use REPLACE on text-fields. There is a UPDATETEXT-command that works on text-fields, but it is very complicated t... | 2008/09/02 | [
"https://Stackoverflow.com/questions/39674",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/997/"
] | I have the following script. It replaces all instances of @lookFor with @replaceWith in all tables in a database. However it doesn't work with text fields only varchar etc. Could this be easily adapted?
```
------------------------------------------------------------
-- Name: STRING REPLACER
-- Author: ADUGGLEBY
-- Ve... | Yeah. What I ended up doing is I converted to varchar(max) on the fly, and the replace took care of the rest.
```
-- PREPARE
SET NOCOUNT ON
-- VARIABLES
DECLARE @tblName NVARCHAR(150)
DECLARE @colName NVARCHAR(150)
DECLARE @tblID int
DECLARE @first bit
DECLARE @lookFor nvarchar(250)
... |
39,704 | <p>I am trying to register to a "Device added/ Device removed" event using WMI. When I say device - I mean something in the lines of a Disk-On-Key or any other device that has files on it which I can access...</p>
<p>I am registering to the event, and the event is raised, but the EventType propery is different from th... | [
{
"answer_id": 40706,
"author": "dguaraglia",
"author_id": 2384,
"author_profile": "https://Stackoverflow.com/users/2384",
"pm_score": 0,
"selected": false,
"text": "<p>Oh! Yup, I've been through that, but using the raw Windows API calls some time ago, while developing an ActiveX control... | 2008/09/02 | [
"https://Stackoverflow.com/questions/39704",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | I am trying to register to a "Device added/ Device removed" event using WMI. When I say device - I mean something in the lines of a Disk-On-Key or any other device that has files on it which I can access...
I am registering to the event, and the event is raised, but the EventType propery is different from the one I am... | Well, I couldn't find the code. Tried on my old RAC account, nothing. Nothing in my old backups. Go figure. But I tried to work out how I did it, and I think this is the correct sequence (I based a lot of it on this [article](http://www.codeproject.com/KB/system/HwDetect.aspx)):
1. Get all drive letters and cache
them... |
39,727 | <p>What .NET namespace or class includes both Context.Handler and Server.Transfer?</p>
<p>I think one may include both and my hunt on MSDN returned null. </p>
| [
{
"answer_id": 39733,
"author": "FlySwat",
"author_id": 1965,
"author_profile": "https://Stackoverflow.com/users/1965",
"pm_score": 2,
"selected": false,
"text": "<p>System.Web.</p>\n\n<pre><code>HttpContext.Current.Handler\nHttpContext.Current.Request.Server.Transfer\n</code></pre>\n"
... | 2008/09/02 | [
"https://Stackoverflow.com/questions/39727",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4140/"
] | What .NET namespace or class includes both Context.Handler and Server.Transfer?
I think one may include both and my hunt on MSDN returned null. | System.Web.
```
HttpContext.Current.Handler
HttpContext.Current.Request.Server.Transfer
``` |
39,742 | <p>Browsing through the git documentation, I can't see anything analogous to SVN's commit hooks or the "propset" features that can, say, update a version number or copyright notice within a file whenever it is committed to the repository.</p>
<p>Are git users expected to write external scripts for this sort of functio... | [
{
"answer_id": 39751,
"author": "James A. Rosen",
"author_id": 1190,
"author_profile": "https://Stackoverflow.com/users/1190",
"pm_score": 1,
"selected": false,
"text": "<p>Perhaps the most common SVN property, 'svn:ignore' is done through the .gitignore file, rather than metadata. I'm ... | 2008/09/02 | [
"https://Stackoverflow.com/questions/39742",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4161/"
] | Browsing through the git documentation, I can't see anything analogous to SVN's commit hooks or the "propset" features that can, say, update a version number or copyright notice within a file whenever it is committed to the repository.
Are git users expected to write external scripts for this sort of functionality (wh... | Quoting from the [Git FAQ](https://git.wiki.kernel.org/index.php/GitFaq#Does_git_have_keyword_expansion.3F):
>
> Does git have keyword expansion?
>
>
> Not recommended. Keyword expansion causes all sorts of strange problems and
> isn't really useful anyway, especially within the context of an SCM. Outside
> git you... |
39,746 | <p>I installed TortoiseHg (Mercurial) in my Vista 64-bit and the context menu is not showing up when I right click a file or folder.
Is there any workaround for this problem?</p>
| [
{
"answer_id": 39764,
"author": "David Webb",
"author_id": 3171,
"author_profile": "https://Stackoverflow.com/users/3171",
"pm_score": 1,
"selected": false,
"text": "<p>According to the <a href=\"http://bitbucket.org/tortoisehg/stable/wiki/FAQ\" rel=\"nofollow noreferrer\">TortoiseHg FAQ... | 2008/09/02 | [
"https://Stackoverflow.com/questions/39746",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4264/"
] | I installed TortoiseHg (Mercurial) in my Vista 64-bit and the context menu is not showing up when I right click a file or folder.
Is there any workaround for this problem? | Update: TortoiseHg 0.8 (released 2009-07-01) now includes both 32 and 64 bit shell extensions in the installer, and also works with Windows 7. The workaround described below is no longer necessary.
---
A workaround to getting the context menus in Windows Explorer is buried in the TortoiseHg development mailing list a... |
39,792 | <p>I have an SQL query that takes the following form:</p>
<pre><code>UPDATE foo
SET flag=true
WHERE id=?
</code></pre>
<p>I also have a PHP array which has a list of IDs. What is the best way to accomplish this other than with parsing, as follows, ...</p>
<pre><code>foreach($list as $item){
$querycondition = $... | [
{
"answer_id": 39802,
"author": "matt b",
"author_id": 4249,
"author_profile": "https://Stackoverflow.com/users/4249",
"pm_score": 3,
"selected": false,
"text": "<p>You should be able to use the IN clause (assuming your database supports it):</p>\n\n<p><code>UPDATE foo\nSET flag=true\nWH... | 2008/09/02 | [
"https://Stackoverflow.com/questions/39792",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4224/"
] | I have an SQL query that takes the following form:
```
UPDATE foo
SET flag=true
WHERE id=?
```
I also have a PHP array which has a list of IDs. What is the best way to accomplish this other than with parsing, as follows, ...
```
foreach($list as $item){
$querycondition = $querycondition . " OR " . $item;
}
... | This would achieve the same thing, but probably won't yield much of a speed increase, but looks nicer.
```
mysql_query("UPDATE foo SET flag=true WHERE id IN (".implode(', ',$list).")");
``` |
39,824 | <p>I'm debugging a production application that has a rash of empty catch blocks <em>sigh</em>:</p>
<pre><code>try {*SOME CODE*}
catch{}
</code></pre>
<p>Is there a way of seeing what the exception is when the debugger hits the catch in the IDE?</p>
| [
{
"answer_id": 39827,
"author": "Johnno Nolan",
"author_id": 1116,
"author_profile": "https://Stackoverflow.com/users/1116",
"pm_score": 0,
"selected": false,
"text": "<p>Can't you just add an Exception at that point and inspect it?</p>\n"
},
{
"answer_id": 39831,
"author": "... | 2008/09/02 | [
"https://Stackoverflow.com/questions/39824",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4271/"
] | I'm debugging a production application that has a rash of empty catch blocks *sigh*:
```
try {*SOME CODE*}
catch{}
```
Is there a way of seeing what the exception is when the debugger hits the catch in the IDE? | In VS, if you look in the Locals area of your IDE while inside the catch block, you will have something to the effect of $EXCEPTION which will have all of the information for the exception that was just caught. |
39,843 | <p>I have decided that all my WPF pages need to register a routed event. Rather than include</p>
<pre><code>public static readonly RoutedEvent MyEvent= EventManager.RegisterRoutedEvent("MyEvent", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(BasePage));
</code></pre>
<p>on every page, I decided to creat... | [
{
"answer_id": 40330,
"author": "Daren Thomas",
"author_id": 2260,
"author_profile": "https://Stackoverflow.com/users/2260",
"pm_score": 2,
"selected": false,
"text": "<p>I'm not sure on this one, but looking at your error, I would try to define the base class with just c# (.cs) code - d... | 2008/09/02 | [
"https://Stackoverflow.com/questions/39843",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3047/"
] | I have decided that all my WPF pages need to register a routed event. Rather than include
```
public static readonly RoutedEvent MyEvent= EventManager.RegisterRoutedEvent("MyEvent", RoutingStrategy.Bubble, typeof(RoutedEventHandler), typeof(BasePage));
```
on every page, I decided to create a base page (named BasePa... | Here's how I've done this in my current project.
First I've defined a class (as @Daren Thomas said - just a plain old C# class, no associated XAML file), like this (and yes, this is a real class - best not to ask):
```
public class PigFinderPage : Page
{
/* add custom events and properties here */
}
```
Then I ... |