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 |
|---|---|---|---|---|---|---|
315,362 | <p>tldr: Can someone show me how to properly format this Python iMAP example so it works?</p>
<p>from
<a href="https://docs.python.org/2.4/lib/imap4-example.html" rel="nofollow noreferrer">https://docs.python.org/2.4/lib/imap4-example.html</a></p>
<blockquote>
<pre><code>import getpass, imaplib
M = imaplib.IMAP4()... | [
{
"answer_id": 315387,
"author": "ayaz",
"author_id": 23191,
"author_profile": "https://Stackoverflow.com/users/23191",
"pm_score": 2,
"selected": false,
"text": "<p>Did you forget to specify the IMAP host and port? Use something to the effect of:</p>\n\n<pre><code>M = imaplib.IMAP4_SSL(... | 2008/11/24 | [
"https://Stackoverflow.com/questions/315362",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | tldr: Can someone show me how to properly format this Python iMAP example so it works?
from
<https://docs.python.org/2.4/lib/imap4-example.html>
>
>
> ```
> import getpass, imaplib
>
> M = imaplib.IMAP4()
> M.login(getpass.getuser(), getpass.getpass())
> M.select()
> typ, data = M.search(None, 'ALL')
> for num in... | ```
import imaplib
# you want to connect to a server; specify which server
server= imaplib.IMAP4_SSL('imap.googlemail.com')
# after connecting, tell the server who you are
server.login('email@gmail.com', 'password')
# this will show you a list of available folders
# possibly your Inbox is called INBOX, but check the l... |
315,381 | <p>I am having some difficulty writing a function that will search through a directory for a file that matches a specific regular expression (which I have compiled using 're.compile'). So my question is: How do I search through a directory (I plan to use os.walk) for a file that matches a specific regular expression? A... | [
{
"answer_id": 315404,
"author": "S.Lott",
"author_id": 10661,
"author_profile": "https://Stackoverflow.com/users/10661",
"pm_score": 2,
"selected": false,
"text": "<ol>\n<li><p>Read about the <a href=\"http://www.python.org/doc/2.5.2/lib/module-re.html\" rel=\"nofollow noreferrer\">RE</... | 2008/11/24 | [
"https://Stackoverflow.com/questions/315381",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/37804/"
] | I am having some difficulty writing a function that will search through a directory for a file that matches a specific regular expression (which I have compiled using 're.compile'). So my question is: How do I search through a directory (I plan to use os.walk) for a file that matches a specific regular expression? An e... | This will find all files starting with two digits and ending in gif, you can add the files into a global list, if you wish:
```
import re
import os
r = re.compile(r'\d{2}.+gif$')
for root, dirs, files in os.walk('/home/vinko'):
l = [os.path.join(root,x) for x in files if r.match(x)]
if l: print l #Or append to a g... |
315,393 | <p>I have a KMainWindow:</p>
<pre><code>//file.h
class MainWindow: public KMainWindow {
public:
MainWindow(QWidget *parent = 0);
...
...
...
private slots:
void removeClick();
//file.cpp
MainWindow::MainWindow(QWidget *parent) :
KMainWindow(parent) {}
void MainWindow::removeClick()
{
std::cout <... | [
{
"answer_id": 317230,
"author": "JuanDeLosMuertos",
"author_id": 39339,
"author_profile": "https://Stackoverflow.com/users/39339",
"pm_score": 0,
"selected": false,
"text": "<p>solved using KXmlGuiWindow instead of KMainWindow and the Q_OBJECT macro</p>\n"
},
{
"answer_id": 3207... | 2008/11/24 | [
"https://Stackoverflow.com/questions/315393",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/39339/"
] | I have a KMainWindow:
```
//file.h
class MainWindow: public KMainWindow {
public:
MainWindow(QWidget *parent = 0);
...
...
...
private slots:
void removeClick();
//file.cpp
MainWindow::MainWindow(QWidget *parent) :
KMainWindow(parent) {}
void MainWindow::removeClick()
{
std::cout << "Remove" << std... | You forgot the Q\_OBJECT macro.
```
class MainWindow: public KMainWindow
{
Q_OBJECT
public:
// [snip]
}
``` |
315,403 | <p>I am using windows authentication within an ASP.NET application. I am wondering how to best get the objectGuid from the currently logged in user?</p>
<p>Regards, Egil.</p>
| [
{
"answer_id": 316721,
"author": "PhilPursglove",
"author_id": 1738,
"author_profile": "https://Stackoverflow.com/users/1738",
"pm_score": 3,
"selected": true,
"text": "<p>You can do this with the System.DirectoryServices namespace. </p>\n\n<pre><code>Dim entry As DirectoryServices.Direc... | 2008/11/24 | [
"https://Stackoverflow.com/questions/315403",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/32809/"
] | I am using windows authentication within an ASP.NET application. I am wondering how to best get the objectGuid from the currently logged in user?
Regards, Egil. | You can do this with the System.DirectoryServices namespace.
```
Dim entry As DirectoryServices.DirectoryEntry
Dim mySearcher As System.DirectoryServices.DirectorySearcher
Dim result As System.DirectoryServices.SearchResult
Dim myEntry As DirectoryEntry
Dim domainName As String
Dim userId As String
Dim objectGuid As ... |
315,435 | <p>I am trying to write Reversi game in Python. Can anyone give me some basic ideas and strategy which are simple, good and easy to use?</p>
<p>I would appreciate for any help because I've gone to a little far but is stucked between codes and it became more complex too. I think I overdid in some part that should be fa... | [
{
"answer_id": 315454,
"author": "FlySwat",
"author_id": 1965,
"author_profile": "https://Stackoverflow.com/users/1965",
"pm_score": 2,
"selected": false,
"text": "<p>Reversi is an elegantly simple game. I'm going to use a psuedo C#/Java langauge to explain some concepts, but you can tra... | 2008/11/24 | [
"https://Stackoverflow.com/questions/315435",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | I am trying to write Reversi game in Python. Can anyone give me some basic ideas and strategy which are simple, good and easy to use?
I would appreciate for any help because I've gone to a little far but is stucked between codes and it became more complex too. I think I overdid in some part that should be fairly simpl... | Reversi is an elegantly simple game. I'm going to use a psuedo C#/Java langauge to explain some concepts, but you can transpose them to Python.
To break it down into its most simple compnents, you have two basic things:
A 2 dimensional array that represents the game board:
```
gameBoard[10,10]
```
And some form of... |
315,437 | <p>Is there some way to detect file handle leaks at program termination? </p>
<p>In particular I would like to make sure that all of my handles that get created are being freed in code. </p>
<p>For example, I may have a CreateFile() somewhere, and at program termination I want to detect and ensure that all of them a... | [
{
"answer_id": 315445,
"author": "Tim",
"author_id": 10755,
"author_profile": "https://Stackoverflow.com/users/10755",
"pm_score": 1,
"selected": false,
"text": "<p>BoundsChecker or other similar programs will do that. I also thought that running under the debugger in VC6 and above woul... | 2008/11/24 | [
"https://Stackoverflow.com/questions/315437",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3153/"
] | Is there some way to detect file handle leaks at program termination?
In particular I would like to make sure that all of my handles that get created are being freed in code.
For example, I may have a CreateFile() somewhere, and at program termination I want to detect and ensure that all of them are closed. | I have used !htrace command of windbg.
```
!htrace -enable
!htrace -snapshot
!htrace -diff
```
Allow you to compare the handle situation of two execution point and help you the locate the point where the leaked handle have been allocated.
It worked well for me. |
315,459 | <p>I will have around 200,000 images as part of my website. Each image will be stored 3 times: full size, thumbnail, larger thumbnail. Full size images are around 50Kb to 500Kb.</p>
<p>Normal tech: Linux, Apache, MySQL, PHP on a VPS.</p>
<p>What is the optimum way to store these for fast retrieval and display via a b... | [
{
"answer_id": 315480,
"author": "Paul Sonier",
"author_id": 28053,
"author_profile": "https://Stackoverflow.com/users/28053",
"pm_score": 0,
"selected": false,
"text": "<p>Depends on how you're indexing them, for how to retrieve them.</p>\n\n<p>There's nothing particularly against stori... | 2008/11/24 | [
"https://Stackoverflow.com/questions/315459",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | I will have around 200,000 images as part of my website. Each image will be stored 3 times: full size, thumbnail, larger thumbnail. Full size images are around 50Kb to 500Kb.
Normal tech: Linux, Apache, MySQL, PHP on a VPS.
What is the optimum way to store these for fast retrieval and display via a browser??
Should ... | I'd use a split directory structure, three or four levels deep, the idea being split all the files evenly across many directories, to enable mainly easy maintenance and fast access.
How to do it? There are various alternatives:
* Taking the first characters of the images names
* Taking the first characters of a hash ... |
315,464 | <p>Consider the following dialog with the command-line interface to the kernel:</p>
<pre><code>$ math
Mathematica 6.0 for Linux x86 (32-bit)
In[1]:= p = Plot[x^2, {x,-1,1}]
Out[1]= -Graphics-
In[2]:= Export["foo.png", p]
Out[2]= foo.png
</code></pre>
<p>That works fine on a machine with <code>$Version = 6.0 for Lin... | [
{
"answer_id": 317287,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 2,
"selected": false,
"text": "<p>Exporting graphics requires the front end in version 6, too. In turn, the front end might require X (after all even some o... | 2008/11/24 | [
"https://Stackoverflow.com/questions/315464",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4234/"
] | Consider the following dialog with the command-line interface to the kernel:
```
$ math
Mathematica 6.0 for Linux x86 (32-bit)
In[1]:= p = Plot[x^2, {x,-1,1}]
Out[1]= -Graphics-
In[2]:= Export["foo.png", p]
Out[2]= foo.png
```
That works fine on a machine with `$Version = 6.0 for Linux x86 (32-bit) (June 2, 2008)`... | You need a front end to export graphics from the MathKernel. The rendering of graphics are entirely covered by the frontend. Without a Front End you do not have graphics to export. There is no workaround.
What you can do, if you have a working front end, is to use:
`UseFrontEnd[Export[filename,graphics]]`
This will ... |
315,475 | <p>is there an easy way to solve the following problem.</p>
<p>Let's say I fetch a IList with some books in my controller from my model. Now I want to enrich the output and fetch a preview from Amazon with another model from an outside framework and get another IList.</p>
<p>Now I put both ILists into a property bag.... | [
{
"answer_id": 315594,
"author": "Ris Adams",
"author_id": 15683,
"author_profile": "https://Stackoverflow.com/users/15683",
"pm_score": 2,
"selected": true,
"text": "<p>There may be a simpler solution, but I would create a third class like such</p>\n\n<pre><code>class BookList{\n ... | 2008/11/24 | [
"https://Stackoverflow.com/questions/315475",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/25233/"
] | is there an easy way to solve the following problem.
Let's say I fetch a IList with some books in my controller from my model. Now I want to enrich the output and fetch a preview from Amazon with another model from an outside framework and get another IList.
Now I put both ILists into a property bag.
In NVelocity I ... | There may be a simpler solution, but I would create a third class like such
```
class BookList{
MyBookObject a;
AmazonBookObject b;
}
```
a list of this third class could be passed to your view at once. |
315,495 | <p>I am currently using SQL Server Management Studio (Ver 9.00.3042.00) and click the "New Query" and wrote the following code:</p>
<pre><code>Select
colA,
colB,
colC
colD
From
table1
</code></pre>
<p>When I click the parse (checkbox) button to validate the SQL statement, it says "Command(s) comp... | [
{
"answer_id": 315510,
"author": "Jeromy Irvine",
"author_id": 8223,
"author_profile": "https://Stackoverflow.com/users/8223",
"pm_score": 5,
"selected": true,
"text": "<p>That's because that is valid SQL. You're effectively aliasing colC with the name colD. It's the same as typing:</p>\... | 2008/11/24 | [
"https://Stackoverflow.com/questions/315495",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/26327/"
] | I am currently using SQL Server Management Studio (Ver 9.00.3042.00) and click the "New Query" and wrote the following code:
```
Select
colA,
colB,
colC
colD
From
table1
```
When I click the parse (checkbox) button to validate the SQL statement, it says "Command(s) completed successfully". Isn't... | That's because that is valid SQL. You're effectively aliasing colC with the name colD. It's the same as typing:
```
colC as colD
```
Edit: For what it's worth, this is one of the reasons why people will argue that you should put the commas at the beginning of the line in cases like this. It's a lot easier to spot go... |
315,507 | <p>For some reason, I am having trouble thinking of a good way to rewrite this function so it uses constant stack space. Most online discussions of tree recursion cheat by using the Fibonacci function and exploiting the properties of that particular problem. Does anyone have any ideas for this "real-world" (well, more ... | [
{
"answer_id": 315694,
"author": "Javier",
"author_id": 11649,
"author_profile": "https://Stackoverflow.com/users/11649",
"pm_score": 2,
"selected": false,
"text": "<p>The main hurdle to easily transforming your algorithm is that it doesn't result in a sequence of calls to the same funct... | 2008/11/24 | [
"https://Stackoverflow.com/questions/315507",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/28604/"
] | For some reason, I am having trouble thinking of a good way to rewrite this function so it uses constant stack space. Most online discussions of tree recursion cheat by using the Fibonacci function and exploiting the properties of that particular problem. Does anyone have any ideas for this "real-world" (well, more rea... | This may look ugly but it's a way to do it in trampoline-style (no system stack overflow), and without using gotos.
```
push x,1 on homemade stack
while stack length > 1
n = pop
if (n==1)
x = pop
if (type(x)==NIL || type(x)==TEXT)
push x // this is the "return value"
else if (type(x)==CONCAT)
... |
315,513 | <p>I want to be able to take still images with a web cam, via .NET 2.0 (or 3.5 if necessary). I know I can use DirectShow but that seems like a very large learning curve.</p>
<p>Is there a simple to use OCX, or library that can work with most standard webcams?</p>
| [
{
"answer_id": 315694,
"author": "Javier",
"author_id": 11649,
"author_profile": "https://Stackoverflow.com/users/11649",
"pm_score": 2,
"selected": false,
"text": "<p>The main hurdle to easily transforming your algorithm is that it doesn't result in a sequence of calls to the same funct... | 2008/11/24 | [
"https://Stackoverflow.com/questions/315513",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16794/"
] | I want to be able to take still images with a web cam, via .NET 2.0 (or 3.5 if necessary). I know I can use DirectShow but that seems like a very large learning curve.
Is there a simple to use OCX, or library that can work with most standard webcams? | This may look ugly but it's a way to do it in trampoline-style (no system stack overflow), and without using gotos.
```
push x,1 on homemade stack
while stack length > 1
n = pop
if (n==1)
x = pop
if (type(x)==NIL || type(x)==TEXT)
push x // this is the "return value"
else if (type(x)==CONCAT)
... |
315,517 | <p>Here is the code currently used.</p>
<pre><code>public String getStringFromDoc(org.w3c.dom.Document doc) {
try
{
DOMSource domSource = new DOMSource(doc);
StringWriter writer = new StringWriter();
StreamResult result = new StreamResult(writer);
Transfor... | [
{
"answer_id": 315569,
"author": "Fernando Miguélez",
"author_id": 34880,
"author_profile": "https://Stackoverflow.com/users/34880",
"pm_score": 4,
"selected": false,
"text": "<p>The transformer API is the only XML-standard way to transform from a DOM object to a serialized form (String ... | 2008/11/24 | [
"https://Stackoverflow.com/questions/315517",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/700/"
] | Here is the code currently used.
```
public String getStringFromDoc(org.w3c.dom.Document doc) {
try
{
DOMSource domSource = new DOMSource(doc);
StringWriter writer = new StringWriter();
StreamResult result = new StreamResult(writer);
TransformerFactory tf ... | Relies on [DOM Level3 Load/Save](http://www.w3.org/TR/DOM-Level-3-LS/load-save.html):
```
public String getStringFromDoc(org.w3c.dom.Document doc) {
DOMImplementationLS domImplementation = (DOMImplementationLS) doc.getImplementation();
LSSerializer lsSerializer = domImplementation.createLSSerializer();
... |
315,518 | <p>I just recently found out that exchange server2007 will no longer be supporting WMI, namely the service which uses <code>\ROOT\MicrosoftExchangeV2</code>.</p>
<p>The old script I wrote output the ServerName, StorageGroupName, Storename, MailboxDisplayName, Size, TotalItems, DeletedMessageSizeExtended fields to a CSV... | [
{
"answer_id": 315568,
"author": "Don Jones",
"author_id": 40405,
"author_profile": "https://Stackoverflow.com/users/40405",
"pm_score": 0,
"selected": false,
"text": "<p>The Quest PowerShell cmdlets (quest.com/powershell) are probably the best way. You can use Get-QADUser -IncludeAllPro... | 2008/11/24 | [
"https://Stackoverflow.com/questions/315518",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18853/"
] | I just recently found out that exchange server2007 will no longer be supporting WMI, namely the service which uses `\ROOT\MicrosoftExchangeV2`.
The old script I wrote output the ServerName, StorageGroupName, Storename, MailboxDisplayName, Size, TotalItems, DeletedMessageSizeExtended fields to a CSV text file.
How wou... | And BTW... depending on how you want to format this information it might be better to write a function which gets the user info, then the Exchange info, and then combines that together into a custom object. PowerShell can then take care of outputting and formatting it for you in various ways. My PowerShell column at <h... |
315,519 | <p>Which is better in general in terms of the ordering? Do you put the fault condition at the top or bottom?</p>
<pre><code>if (noProblems == true) {
// do stuff
} else {
// deal with problem
}
</code></pre>
<p>OR</p>
<pre><code>if (noProblems == false) {
// deal with problem
} else {
// do stuff
}
... | [
{
"answer_id": 315523,
"author": "Steven A. Lowe",
"author_id": 9345,
"author_profile": "https://Stackoverflow.com/users/9345",
"pm_score": 7,
"selected": true,
"text": "<p>i like to eliminate error cases first - and return from the function early so that the 'happy path' remains un-nest... | 2008/11/24 | [
"https://Stackoverflow.com/questions/315519",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/337/"
] | Which is better in general in terms of the ordering? Do you put the fault condition at the top or bottom?
```
if (noProblems == true) {
// do stuff
} else {
// deal with problem
}
```
OR
```
if (noProblems == false) {
// deal with problem
} else {
// do stuff
}
``` | i like to eliminate error cases first - and return from the function early so that the 'happy path' remains un-nested, e.g.
```
if (some error condition)
{
//handle it
return;
}
//implicit else for happy path
...
```
if it is easy to identify the conditions leading to the happy path, then by all means put th... |
315,527 | <p>I am trying to use <a href="http://msdn.microsoft.com/en-us/library/bb762153(VS.85).aspx" rel="nofollow noreferrer">ShellExecute</a> to open a file in Excel. I was reading about the function on MSDN forums, and I found the folowing information about the handle, which is the first parameter: </p>
<p>"hwnd [in] A han... | [
{
"answer_id": 315554,
"author": "VonC",
"author_id": 6309,
"author_profile": "https://Stackoverflow.com/users/6309",
"pm_score": 3,
"selected": true,
"text": "<p>It is <a href=\"http://www.oehive.org/node/521\" rel=\"nofollow noreferrer\">usually 0</a></p>\n\n<blockquote>\n <p>hwnd : p... | 2008/11/24 | [
"https://Stackoverflow.com/questions/315527",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/23970/"
] | I am trying to use [ShellExecute](http://msdn.microsoft.com/en-us/library/bb762153(VS.85).aspx) to open a file in Excel. I was reading about the function on MSDN forums, and I found the folowing information about the handle, which is the first parameter:
"hwnd [in] A handle to the owner window used for displaying a u... | It is [usually 0](http://www.oehive.org/node/521)
>
> hwnd : parent window that will receive a possible messagebox. This parameter is usually 0.
>
>
>
It refers to the top-level window: the window you are opening does not have any parent, and is the main window for the application being executed.
When you are sw... |
315,546 | <p>I like the idea of having only one <code>return</code> statement per method.</p>
<p>What do you do in this situation though?</p>
<pre><code>public static string ChopText(string Text)
{
if (String.IsNullOrEmpty(Text))
{
// return here ?????
}
}
</code></pre>
<p>The only alternative I can think of is... | [
{
"answer_id": 315560,
"author": "Darron",
"author_id": 22704,
"author_profile": "https://Stackoverflow.com/users/22704",
"pm_score": 5,
"selected": false,
"text": "<p>Frankly, situations like this are why overly rigid rules are bad.</p>\n\n<p>The point of rules like this is to make code... | 2008/11/24 | [
"https://Stackoverflow.com/questions/315546",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/39677/"
] | I like the idea of having only one `return` statement per method.
What do you do in this situation though?
```
public static string ChopText(string Text)
{
if (String.IsNullOrEmpty(Text))
{
// return here ?????
}
}
```
The only alternative I can think of is setting a flag, and then checking for the f... | It is OK to [replace nested conditional with guard clauses](http://martinfowler.com/refactoring/catalog/replaceNestedConditionalWithGuardClauses.html). |
315,552 | <p>Working on big, high loaded project I got the problem that already described in billion of topics on forums and blog, but there is no solution that will help in my case. Here is the story.</p>
<p>I have the HTML code of banner, I don't know what is the code. Sometimes it's plain HTML, but sometimes it's <code><s... | [
{
"answer_id": 315577,
"author": "netadictos",
"author_id": 31791,
"author_profile": "https://Stackoverflow.com/users/31791",
"pm_score": 0,
"selected": false,
"text": "<p>perhaps you could use the property innerHTML:\ndocument.getElementById(\"x\").innerHTML=\".................\";</p>\n... | 2008/11/24 | [
"https://Stackoverflow.com/questions/315552",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15752/"
] | Working on big, high loaded project I got the problem that already described in billion of topics on forums and blog, but there is no solution that will help in my case. Here is the story.
I have the HTML code of banner, I don't know what is the code. Sometimes it's plain HTML, but sometimes it's `<script>` tag with d... | You need [writeCapture.js](http://github.com/iamnoah/writeCapture) (full disclosure: I'm the author.) All bets are off with 3rd party scripts. Today they use `document.write` to generate some specific HTML, but tomorrow they could change it and any simple hacks based on replacing `document.write` will need to be update... |
315,590 | <p>I want to load 52 images (deck of cards) in gif format from my recourse folder into an Image[] in c#. Any ideas?</p>
<p>Thanks,
Jon</p>
| [
{
"answer_id": 315611,
"author": "Rob Prouse",
"author_id": 30827,
"author_profile": "https://Stackoverflow.com/users/30827",
"pm_score": 3,
"selected": true,
"text": "<p>You can read a Bitmap from a file like this;</p>\n\n<pre><code> public static Bitmap GetBitmap( string filename )\n ... | 2008/11/24 | [
"https://Stackoverflow.com/questions/315590",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/40399/"
] | I want to load 52 images (deck of cards) in gif format from my recourse folder into an Image[] in c#. Any ideas?
Thanks,
Jon | You can read a Bitmap from a file like this;
```
public static Bitmap GetBitmap( string filename )
{
Bitmap retBitmap = null;
string path = String.Concat( BitmapDir, filename );
if ( File.Exists( path ) )
{
try
{
retBitmap = new Bitmap( path, true );
}
... |
315,591 | <p>I am working on an object factory to keep track of a small collection of objects. The objects can be of different types, but they will all respond to <code>createInstance</code> and <code>reset</code>. The objects can not be derived from a common base class because some of them will have to derive from built-in coco... | [
{
"answer_id": 315641,
"author": "Michael Tsai",
"author_id": 6311,
"author_profile": "https://Stackoverflow.com/users/6311",
"pm_score": 2,
"selected": false,
"text": "<p>It sounds like you want something like:</p>\n\n<pre><code>- (id)makeObjectOfClassNamed:(NSString *)className\n{\n ... | 2008/11/24 | [
"https://Stackoverflow.com/questions/315591",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/33686/"
] | I am working on an object factory to keep track of a small collection of objects. The objects can be of different types, but they will all respond to `createInstance` and `reset`. The objects can not be derived from a common base class because some of them will have to derive from built-in cocoa classes like `NSView` a... | You can convert a string to a class using the function: NSClassFromString
```
Class classFromString = NSClassFromString(@"MyClass");
```
In your case though, you'd be better off using the Class objects directly.
```
MyClass * variable = [factory makeObjectOfClass:[MyClass class]];
- (id)makeObjectOfClass:(Class)aC... |
315,618 | <p>How do I extract a tar (or tar.gz, or tar.bz2) file in Java?</p>
| [
{
"answer_id": 315640,
"author": "Fernando Miguélez",
"author_id": 34880,
"author_profile": "https://Stackoverflow.com/users/34880",
"pm_score": 2,
"selected": false,
"text": "<p>What about using this <a href=\"http://www.trustice.com/java/tar/\" rel=\"nofollow noreferrer\">API</a> for t... | 2008/11/24 | [
"https://Stackoverflow.com/questions/315618",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18103/"
] | How do I extract a tar (or tar.gz, or tar.bz2) file in Java? | *Note:* This functionality was later published through a separate project, Apache Commons Compress, as [described in another answer.](https://stackoverflow.com/a/7556307/3474) This answer is out of date.
---
I haven't used a tar API directly, but tar and bzip2 are implemented in Ant; you could borrow their implementa... |
315,621 | <p>I have a table with N rows, and I wanna select N-1 rows. </p>
<p>Suggestions on how to do this in one query, if it's possible..?</p>
| [
{
"answer_id": 315631,
"author": "Joshua Carmody",
"author_id": 8409,
"author_profile": "https://Stackoverflow.com/users/8409",
"pm_score": 6,
"selected": true,
"text": "<p>Does the last row have the highest ID? If so, I think this would work:</p>\n\n<pre><code>SELECT * FROM TABLE WHERE ... | 2008/11/24 | [
"https://Stackoverflow.com/questions/315621",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/33232/"
] | I have a table with N rows, and I wanna select N-1 rows.
Suggestions on how to do this in one query, if it's possible..? | Does the last row have the highest ID? If so, I think this would work:
```
SELECT * FROM TABLE WHERE ID != (SELECT MAX(ID) FROM TABLE)
```
MySQL does allow subselects in the current version, right?
However, in most cases, it'd probably perform better if you selected all the rows and then filtered the unwanted data ... |
315,667 | <p>I'm a non-computer science student doing a history thesis that involves determining the frequency of specific terms in a number of texts and then plotting these frequencies over time to determine changes and trends. While I have figured out how to determine word frequencies for a given text file, I am dealing with a... | [
{
"answer_id": 315688,
"author": "Ben",
"author_id": 11522,
"author_profile": "https://Stackoverflow.com/users/11522",
"pm_score": 1,
"selected": false,
"text": "<p>I'm guessing that new files get introduced over time, and that's how things change?</p>\n\n<p>I reckon your best bet would ... | 2008/11/24 | [
"https://Stackoverflow.com/questions/315667",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/40414/"
] | I'm a non-computer science student doing a history thesis that involves determining the frequency of specific terms in a number of texts and then plotting these frequencies over time to determine changes and trends. While I have figured out how to determine word frequencies for a given text file, I am dealing with a (r... | I would go with the second idea. Here is a simple Perl program that will read a list of words from the first file provided and print a count of each word in the list from the second file provided in tab-separated format. The list of words in the first file should be provided one per line.
```
#!/usr/bin/perl
use stri... |
315,672 | <p>Does anyone know if there's a way to automatically expand a list in Python, separated by commas? I'm writing some Python code that uses the MySQLdb library, and I'm trying to dynamically update a list of rows in a MySQL database with certain key values.</p>
<p>For instance, in the code below, I'd like to have the ... | [
{
"answer_id": 315684,
"author": "hasen",
"author_id": 35364,
"author_profile": "https://Stackoverflow.com/users/35364",
"pm_score": 5,
"selected": true,
"text": "<p>try:</p>\n\n<pre><code>\",\".join( map(str, record_ids) )\n</code></pre>\n\n<p><code>\",\".join( list_of_strings )</code> ... | 2008/11/24 | [
"https://Stackoverflow.com/questions/315672",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/31319/"
] | Does anyone know if there's a way to automatically expand a list in Python, separated by commas? I'm writing some Python code that uses the MySQLdb library, and I'm trying to dynamically update a list of rows in a MySQL database with certain key values.
For instance, in the code below, I'd like to have the numeric val... | try:
```
",".join( map(str, record_ids) )
```
`",".join( list_of_strings )` joins a list of string by separating them with commas
if you have a list of numbers, `map( str, list )` will convert it to a list of strings |
315,678 | <p>I have a web application that uses Ext-JS 2.2. In a certain component, we have an empty toolbar that we are trying to add a button to using </p>
<pre><code>myPanel.getTopToolbar().insertButton(0, [...array of buttons...]);
</code></pre>
<p>However, in IE6/7 this fails because of lines 20241-20242 in ext-all-debug.... | [
{
"answer_id": 316155,
"author": "cwhite",
"author_id": 4923,
"author_profile": "https://Stackoverflow.com/users/4923",
"pm_score": 1,
"selected": false,
"text": "<p>If all you are doing is adding to a empty panel </p>\n\n<pre><code> myPanel.getTopToolbar().add(buttons etc);\n</code></pr... | 2008/11/24 | [
"https://Stackoverflow.com/questions/315678",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/25066/"
] | I have a web application that uses Ext-JS 2.2. In a certain component, we have an empty toolbar that we are trying to add a button to using
```
myPanel.getTopToolbar().insertButton(0, [...array of buttons...]);
```
However, in IE6/7 this fails because of lines 20241-20242 in ext-all-debug.js:
```
var td = document... | I didn't think there was a CSS-only solution.
For the record, I ended up injecting javascript into the page that overrides the Ext.Toolbar prototype for the insertButton() function to check for the existance of "this.tr.childNodes([0])" and default to addButton() if it didn't exist. |
315,706 | <p>When reading from a <a href="http://search.cpan.org/dist/IO" rel="nofollow noreferrer">IO::Socket::INET</a> filehandle it can not be assumed that there will always be data available on the stream. What techniques are available to either peek at the stream to check if data is available or when doing the read take no ... | [
{
"answer_id": 315751,
"author": "Robert Gamble",
"author_id": 25222,
"author_profile": "https://Stackoverflow.com/users/25222",
"pm_score": 4,
"selected": true,
"text": "<p>Set the <code>Blocking</code> option to <code>0</code> when creating the socket:</p>\n\n<pre><code>$sock = IO::Soc... | 2008/11/24 | [
"https://Stackoverflow.com/questions/315706",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12251/"
] | When reading from a [IO::Socket::INET](http://search.cpan.org/dist/IO) filehandle it can not be assumed that there will always be data available on the stream. What techniques are available to either peek at the stream to check if data is available or when doing the read take no data without a valid line termination an... | Set the `Blocking` option to `0` when creating the socket:
```
$sock = IO::Socket::INET->new(Blocking => 0, ...);
``` |
315,708 | <p>Is there any good way to convert strings like "xlSum", "xlAverage", and "xlCount" into the value they have under Microsoft.Office.Interop.Excel.XlConsolidationFunction?</p>
<p>I guess reflection would be slow (if its possible). There are about 10 of these constant values. I was trying to avoid a large switch statem... | [
{
"answer_id": 315715,
"author": "Dror Helper",
"author_id": 11361,
"author_profile": "https://Stackoverflow.com/users/11361",
"pm_score": 0,
"selected": false,
"text": "<p>Instead of switch you can always use a <code>Dictionary<string, ...></code> and fill it once when the applica... | 2008/11/24 | [
"https://Stackoverflow.com/questions/315708",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/36590/"
] | Is there any good way to convert strings like "xlSum", "xlAverage", and "xlCount" into the value they have under Microsoft.Office.Interop.Excel.XlConsolidationFunction?
I guess reflection would be slow (if its possible). There are about 10 of these constant values. I was trying to avoid a large switch statement if pos... | This is an enum so you should be able to use
```
using Microsoft.Office.Interop.Excel;
XlConslidationFunction func = (XlConsolidationFunction)
Enum.Parse( typeof(XlConsolidationFunction),
stringVal );
``` |
315,712 | <p>I have a three-step process that is entirely reliant upon JavaScript and Ajax to load data and animate the process from one step to the next. To further complicate matters, the transition (forward and backward) between steps is animated :-(. As user's progress through the process anchor's appear showing the current ... | [
{
"answer_id": 315756,
"author": "ScottKoon",
"author_id": 1538,
"author_profile": "https://Stackoverflow.com/users/1538",
"pm_score": 0,
"selected": false,
"text": "<p>First, remember your execution scope in the click event. The <em>this</em> keyword in that context refers to the elemen... | 2008/11/24 | [
"https://Stackoverflow.com/questions/315712",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20178/"
] | I have a three-step process that is entirely reliant upon JavaScript and Ajax to load data and animate the process from one step to the next. To further complicate matters, the transition (forward and backward) between steps is animated :-(. As user's progress through the process anchor's appear showing the current ste... | Your closure scope chain is causing your problems. By declaring the handler function inline, you've created a closure. Obviously you did this to take advantage of the loop.
However, since you have created a closure, you're playing by closure scoping rules. Those rules state that the local variables within the parent f... |
315,716 | <p>I am looking for a way to periodically send some data over all clients connected to a TCP port. I am looking at twisted python and I am aware of reactor.callLater. But how do I use it to send some data to all connected clients periodically ? The data sending logic is in Protocol class and it is instantiated by the r... | [
{
"answer_id": 315855,
"author": "Dustin",
"author_id": 39975,
"author_profile": "https://Stackoverflow.com/users/39975",
"pm_score": 2,
"selected": false,
"text": "<p>I'd imagine the easiest way to do that is to manage a list of clients in the protocol with connectionMade and connection... | 2008/11/24 | [
"https://Stackoverflow.com/questions/315716",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/29120/"
] | I am looking for a way to periodically send some data over all clients connected to a TCP port. I am looking at twisted python and I am aware of reactor.callLater. But how do I use it to send some data to all connected clients periodically ? The data sending logic is in Protocol class and it is instantiated by the reac... | You would probably want to do this in the Factory for the connections. The Factory is not automatically notified of every time a connection is made and lost, so you can notify it from the Protocol.
Here is a complete example of how to use twisted.internet.task.LoopingCall in conjunction with a customised basic Factory... |
315,717 | <p>I need to know this since this is a pre-req for .NET 3.5 and if I'm including the .NET bootstrapper, I should also see if Windows Installer 3.1 is needed.</p>
<p>Right now I'm checking for the registry key:</p>
<pre><code>HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Updates\Windows XP\SP3\KB893803v2
</code></pre>
<p>Whi... | [
{
"answer_id": 315811,
"author": "Martin v. Löwis",
"author_id": 33006,
"author_profile": "https://Stackoverflow.com/users/33006",
"pm_score": 1,
"selected": false,
"text": "<p>If this is inside the MSI file itself, you can check for the <a href=\"http://msdn.microsoft.com/en-us/library/... | 2008/11/24 | [
"https://Stackoverflow.com/questions/315717",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/23822/"
] | I need to know this since this is a pre-req for .NET 3.5 and if I'm including the .NET bootstrapper, I should also see if Windows Installer 3.1 is needed.
Right now I'm checking for the registry key:
```
HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Updates\Windows XP\SP3\KB893803v2
```
Which will check for Windows Install... | locate the installer msi.dll with this registry path:
HKEY\_LOCAL\_MACHINE\Software\Microsoft\Windows\CurrentVersion\Installer
value: InstallerLocation
then get the version information from that file.
update:
the way above is old!
new way to detect the version is documented here:
<http://msdn.microsoft.com/en-us/lib... |
315,719 | <p>I'm trying to convert a character code to a character with chr(), but VBScript isn't giving me the value I expect. According to VBScript, character code 199 is:</p>
<pre><code>�
</code></pre>
<p>However, when using something like Javascript's String.fromCharCode, 199 is:</p>
<pre><code>Ç
</code></pre>
<p>The s... | [
{
"answer_id": 315723,
"author": "strager",
"author_id": 39992,
"author_profile": "https://Stackoverflow.com/users/39992",
"pm_score": 0,
"selected": false,
"text": "<p>Encoding is the problem. Javascript may be interpreting as latin-1; VBScript may be using a different encoding and get... | 2008/11/24 | [
"https://Stackoverflow.com/questions/315719",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/31516/"
] | I'm trying to convert a character code to a character with chr(), but VBScript isn't giving me the value I expect. According to VBScript, character code 199 is:
```
�
```
However, when using something like Javascript's String.fromCharCode, 199 is:
```
Ç
```
The second result is what I need to get out of VBScrip... | **Edited to reflect comments**
`Chr(199)` returns a 2-byte character, which is being interpreted as 2 separate characters.
* use `ChrW(199)` to return a `Unicode` string.
* use `ChrB(199)` to return it as a single-byte character |
315,724 | <p>I have an after_save filter which I dont want to trigger in a specific instance. Is there a way to do this similar to save_without_validation?</p>
<p>Thanks,</p>
| [
{
"answer_id": 316162,
"author": "Michael Sepcot",
"author_id": 6033,
"author_profile": "https://Stackoverflow.com/users/6033",
"pm_score": 0,
"selected": false,
"text": "<p>There is a good example of extending ActiveRecord to provide callback skipping here: <a href=\"http://weareintegru... | 2008/11/24 | [
"https://Stackoverflow.com/questions/315724",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | I have an after\_save filter which I dont want to trigger in a specific instance. Is there a way to do this similar to save\_without\_validation?
Thanks, | When using rails 2, you can invoke the private method `create_without_callbacks` by doing:
```
@my_obj.send(:create_without_callbacks)
``` |
315,729 | <p>I am facing a problem.
I would like to localize my action names in my project so french people can have clean urls with french names.</p>
<p><a href="http://www.test.com/Home" rel="nofollow noreferrer">http://www.test.com/Home</a> should be <a href="http://www.test.com/Accueil" rel="nofollow noreferrer">http://www.... | [
{
"answer_id": 315737,
"author": "Kyle West",
"author_id": 34133,
"author_profile": "https://Stackoverflow.com/users/34133",
"pm_score": 3,
"selected": true,
"text": "<p>you can do this when you register the routes in global.asax.</p>\n\n<p>if normally you have this:</p>\n\n<pre><code>ro... | 2008/11/24 | [
"https://Stackoverflow.com/questions/315729",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1195872/"
] | I am facing a problem.
I would like to localize my action names in my project so french people can have clean urls with french names.
<http://www.test.com/Home> should be <http://www.test.com/Accueil>
It is a good thing too for google indexing.
Moreover I would like to be Restful on the application, so I would like t... | you can do this when you register the routes in global.asax.
if normally you have this:
```
routes.MapRoute("Catalog-Brands", "catalog/brand/", new {controller = "Brand", action = "Index", isActive = true});
```
you could make this one too (I don't know french, sorry)
```
routes.MapRoute("Catalog-Brands-French", "... |
315,738 | <p>I have a very simple html. The red div is inside the blue div and has a 10 px top margin. On non-ie browsers, the blue box is 10 px apart from the top of viewport and the red div is at the very top of the blue div. What I expect is the ie behavior: red div must be 10 px apart from the top of the blue div. Why does n... | [
{
"answer_id": 315759,
"author": "strager",
"author_id": 39992,
"author_profile": "https://Stackoverflow.com/users/39992",
"pm_score": 2,
"selected": false,
"text": "<p>The margins are being merged. The output produced by IE is probably incorrect.</p>\n\n<p>In the specifications (which ... | 2008/11/24 | [
"https://Stackoverflow.com/questions/315738",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/31505/"
] | I have a very simple html. The red div is inside the blue div and has a 10 px top margin. On non-ie browsers, the blue box is 10 px apart from the top of viewport and the red div is at the very top of the blue div. What I expect is the ie behavior: red div must be 10 px apart from the top of the blue div. Why does non-... | As much as [strager's answer](https://stackoverflow.com/questions/315738/unexpected-margin-with-very-simple-html#315759) already explains about as much as you need to know as to why it happens – namely that it happens the way it does in browsers other than IE because the specs say so – I think he picked the wrong quote... |
315,739 | <p>I have a problem when assigning functions to the click event of a button in IE 7 with jQuery. Something like the following works fine in Opera but produces an infinite loop in IE:</p>
<pre><code>function updateIndputFields(index, id) {
$("#reloadBtn").click(function(){ updateIndputFields(index, id) });
}
</code>... | [
{
"answer_id": 315757,
"author": "strager",
"author_id": 39992,
"author_profile": "https://Stackoverflow.com/users/39992",
"pm_score": 0,
"selected": false,
"text": "<p>Try unbinding the event before binding it.</p>\n"
},
{
"answer_id": 315789,
"author": "ringmaster",
"au... | 2008/11/24 | [
"https://Stackoverflow.com/questions/315739",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4055/"
] | I have a problem when assigning functions to the click event of a button in IE 7 with jQuery. Something like the following works fine in Opera but produces an infinite loop in IE:
```
function updateIndputFields(index, id) {
$("#reloadBtn").click(function(){ updateIndputFields(index, id) });
}
```
As I understand... | I think the key to your answer is in unbinding the event that you have already bound to the click event. I used this on IE and, if I understand what you're trying to do, it seems to do what you need:
```
<script type="text/javascript">
function updateIndputFields(index, id) {
$('#output').append('<p>' + index + ' : ' ... |
315,745 | <p>I want to use this pure HTML/CSS template for my ASP.NET website:</p>
<p><a href="http://sub3.tanguay.de" rel="nofollow noreferrer">http://sub3.tanguay.de</a></p>
<p>I copy it inside my Default.aspx page, inside the FORM element, but the form messes up the layout:</p>
<p><a href="http://sub2.tanguay.de" rel="nofo... | [
{
"answer_id": 315774,
"author": "devio",
"author_id": 21336,
"author_profile": "https://Stackoverflow.com/users/21336",
"pm_score": 2,
"selected": true,
"text": "<p>1) try removing the background-color attribute from the form class:</p>\n\n<pre><code>form {\n margin:10px; padding: 0;... | 2008/11/24 | [
"https://Stackoverflow.com/questions/315745",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4639/"
] | I want to use this pure HTML/CSS template for my ASP.NET website:
<http://sub3.tanguay.de>
I copy it inside my Default.aspx page, inside the FORM element, but the form messes up the layout:
<http://sub2.tanguay.de>
**UPDATE: this now displays correctly, thanks to Devio.**
I tried altering the style of the form tag... | 1) try removing the background-color attribute from the form class:
```
form {
margin:10px; padding: 0;
border: 1px solid #f2f2f2;
background-color: #FAFAFA; /* remove this */
}
```
2) you cannot nest forms, but the searchform is contained inside the ASP.Net form, and ASP.Net requires exactly one form t... |
315,760 | <p>I've been using this function but I'd like to know what's the most efficient and accurate way to get it.</p>
<pre><code>function daysInMonth(iMonth, iYear) {
return 32 - new Date(iYear, iMonth, 32).getDate();
}
</code></pre>
| [
{
"answer_id": 315767,
"author": "FlySwat",
"author_id": 1965,
"author_profile": "https://Stackoverflow.com/users/1965",
"pm_score": 9,
"selected": true,
"text": "<p><div class=\"snippet\" data-lang=\"js\" data-hide=\"false\" data-console=\"true\" data-babel=\"false\">\r\n<div class=\"sn... | 2008/11/24 | [
"https://Stackoverflow.com/questions/315760",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/39203/"
] | I've been using this function but I'd like to know what's the most efficient and accurate way to get it.
```
function daysInMonth(iMonth, iYear) {
return 32 - new Date(iYear, iMonth, 32).getDate();
}
``` | ```js
function daysInMonth (month, year) { // Use 1 for January, 2 for February, etc.
return new Date(year, month, 0).getDate();
}
console.log(daysInMonth(2, 1999)); // February in a non-leap year.
console.log(daysInMonth(2, 2000)); // February in a leap year.
```
Day 0 is the last day in the previous month. Becaus... |
315,787 | <p>I' trying to use a Linq query to find and set the selected value in a drop down list control.</p>
<pre><code> Dim qry = From i In ddlOutcome.Items _
Where i.Text.Contains(value)
Dim selectedItem As ListItem = qry.First
ddlOutcome.SelectedValue = selectedItem.Value
</code></pre>
<p>Even though the d... | [
{
"answer_id": 315878,
"author": "x0n",
"author_id": 6920,
"author_profile": "https://Stackoverflow.com/users/6920",
"pm_score": 1,
"selected": false,
"text": "<p>My vb.net is shaky, (c# guy) but try:</p>\n\n<pre><code>Dim qry = From DirectCast(i, ListItem) In ddlOutcome.Items ...\n</cod... | 2008/11/24 | [
"https://Stackoverflow.com/questions/315787",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/25121/"
] | I' trying to use a Linq query to find and set the selected value in a drop down list control.
```
Dim qry = From i In ddlOutcome.Items _
Where i.Text.Contains(value)
Dim selectedItem As ListItem = qry.First
ddlOutcome.SelectedValue = selectedItem.Value
```
Even though the documentation says that the ... | Thank you for the suggestions, they were both helpful in leading me to a workable solution. While I agree that using the methods of the drop list itself should be the way to go, I don't have an exact match on the text of the items in the list so I needed another way.
```
Dim qry = From i In ddlOutcome.Items.Cast(O... |
315,792 | <p>How can I achieve the following? I have two models (blogs and readers) and a JOIN table that will allow me to have an N:M relationship between them:</p>
<pre><code>class Blog < ActiveRecord::Base
has_many :blogs_readers, :dependent => :destroy
has_many :readers, :through => :blogs_readers
end
class Re... | [
{
"answer_id": 315821,
"author": "Mike Breen",
"author_id": 22346,
"author_profile": "https://Stackoverflow.com/users/22346",
"pm_score": 5,
"selected": false,
"text": "<p>This should take care of your first question:</p>\n\n<pre><code>class BlogsReaders < ActiveRecord::Base\n belong... | 2008/11/24 | [
"https://Stackoverflow.com/questions/315792",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/29909/"
] | How can I achieve the following? I have two models (blogs and readers) and a JOIN table that will allow me to have an N:M relationship between them:
```
class Blog < ActiveRecord::Base
has_many :blogs_readers, :dependent => :destroy
has_many :readers, :through => :blogs_readers
end
class Reader < ActiveRecord::Ba... | What about:
```
Blog.find(:all,
:conditions => ['id NOT IN (?)', the_reader.blog_ids])
```
Rails takes care of the collection of ids for us with association methods! :)
<http://api.rubyonrails.org/classes/ActiveRecord/Associations/ClassMethods.html> |
315,799 | <p>I have some code that reads 10 registry keys, sometimes the values are not present sometimes the keys are not present, sometimes the value isn't boolean etc etc. How should I add error handling to this, currently it is placed in one big try{} catch{} but if the second value I read fails then the rest are not read as... | [
{
"answer_id": 315806,
"author": "Ed Marty",
"author_id": 36007,
"author_profile": "https://Stackoverflow.com/users/36007",
"pm_score": 0,
"selected": false,
"text": "<p>Refactor the code that reads the values into its own function that handles the errors how you want them to be handled.... | 2008/11/24 | [
"https://Stackoverflow.com/questions/315799",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | I have some code that reads 10 registry keys, sometimes the values are not present sometimes the keys are not present, sometimes the value isn't boolean etc etc. How should I add error handling to this, currently it is placed in one big try{} catch{} but if the second value I read fails then the rest are not read as th... | First, swallowing exceptions is *generally* a bad idea - could you not write a method that checks the keys etc for existance, and returns the value if one?
If that *absolutely, positively* isn't possible, you can refactor the code into multiple calls to a single method that (for each) does a try/catch (swallow):
```
... |
315,803 | <p>I get the following error while building OpenCV on OS X 10.5 (intel):</p>
<pre><code>ld: warning in .libs/_cv_la-_cv.o, file is not of required architecture
ld: warning in .libs/_cv_la-error.o, file is not of required architecture
ld: warning in .libs/_cv_la-pyhelpers.o, file is not of required architecture
ld: war... | [
{
"answer_id": 320245,
"author": "Carlos Villela",
"author_id": 16944,
"author_profile": "https://Stackoverflow.com/users/16944",
"pm_score": 1,
"selected": false,
"text": "<p>It seems a little weird that it is warning about different architectures when looking for /Developer/SDKs/MacOSX... | 2008/11/24 | [
"https://Stackoverflow.com/questions/315803",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/40431/"
] | I get the following error while building OpenCV on OS X 10.5 (intel):
```
ld: warning in .libs/_cv_la-_cv.o, file is not of required architecture
ld: warning in .libs/_cv_la-error.o, file is not of required architecture
ld: warning in .libs/_cv_la-pyhelpers.o, file is not of required architecture
ld: warning in .libs/... | Ok, I kind of worked it out
It needs to be compiled with python from macports or whatever. Then I need to run `/System/Library/Frameworks/Python.framework/Versions/2.5/bin/python2.5` (this is my previous python version) and there OpenCV just works. |
315,804 | <p>In my JSF/Facelets app, here's a simplified version of part of my form:</p>
<pre><code><h:form id="myform">
<h:inputSecret value="#{createNewPassword.newPassword1}" id="newPassword1" />
<h:message class="error" for="newPassword1" />
<h:inputSecret value="#{createNewPassword.newPassword2}"... | [
{
"answer_id": 315825,
"author": "kevindaub",
"author_id": 27669,
"author_profile": "https://Stackoverflow.com/users/27669",
"pm_score": 1,
"selected": false,
"text": "<p>Found <a href=\"http://www.jsf-faq.com/faqs/faces-messages.html\" rel=\"nofollow noreferrer\">this</a> while Googling... | 2008/11/24 | [
"https://Stackoverflow.com/questions/315804",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/27515/"
] | In my JSF/Facelets app, here's a simplified version of part of my form:
```
<h:form id="myform">
<h:inputSecret value="#{createNewPassword.newPassword1}" id="newPassword1" />
<h:message class="error" for="newPassword1" />
<h:inputSecret value="#{createNewPassword.newPassword2}" id="newPassword2" />
<h:message ... | In case anyone was curious, I was able to figure this out based on all of your responses combined!
This is in the Facelet:
```
<h:form id="myform">
<h:inputSecret value="#{createNewPassword.newPassword1}" id="newPassword1" />
<h:message class="error" for="newPassword1" id="newPassword1Error" />
<h:inputSecret v... |
315,829 | <p>Suppose you create a generic Object variable and assign it to a specific instance. If you do GetType(), will it get type Object or the type of the original class?</p>
| [
{
"answer_id": 315835,
"author": "Alan",
"author_id": 37843,
"author_profile": "https://Stackoverflow.com/users/37843",
"pm_score": 3,
"selected": true,
"text": "<p>Yes.</p>\n\n<p>You can also do:</p>\n\n<pre><code>object c = new FooBar();\nif(c is FooBar)\n Console.WriteLine(\"FOOBA... | 2008/11/24 | [
"https://Stackoverflow.com/questions/315829",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/109/"
] | Suppose you create a generic Object variable and assign it to a specific instance. If you do GetType(), will it get type Object or the type of the original class? | Yes.
You can also do:
```
object c = new FooBar();
if(c is FooBar)
Console.WriteLine("FOOBAR!!!");
``` |
315,846 | <p>When and why would somebody do the following:</p>
<pre><code>doSomething( (MyClass) null );
</code></pre>
<p>Have you ever done this? Could you please share your experience?</p>
| [
{
"answer_id": 315853,
"author": "Johannes Schaub - litb",
"author_id": 34509,
"author_profile": "https://Stackoverflow.com/users/34509",
"pm_score": 8,
"selected": true,
"text": "<p>If <code>doSomething</code> is overloaded, you need to cast the null explicitly to <code>MyClass</code> s... | 2008/11/24 | [
"https://Stackoverflow.com/questions/315846",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2644/"
] | When and why would somebody do the following:
```
doSomething( (MyClass) null );
```
Have you ever done this? Could you please share your experience? | If `doSomething` is overloaded, you need to cast the null explicitly to `MyClass` so the right overload is chosen:
```
public void doSomething(MyClass c) {
// ...
}
public void doSomething(MyOtherClass c) {
// ...
}
```
A non-contrived situation where you need to cast is when you call a varargs function:
`... |
315,887 | <p>How do I mask the address of another site using HTML?</p>
<p>For example, I'd like:</p>
<p><a href="http://www.example.com/source.html" rel="nofollow noreferrer">http://www.example.com/source.html</a></p>
<p>To point to another page:</p>
<p><a href="http://www.example.com/dest.html" rel="nofollow noreferrer">htt... | [
{
"answer_id": 315906,
"author": "DOK",
"author_id": 27637,
"author_profile": "https://Stackoverflow.com/users/27637",
"pm_score": 2,
"selected": false,
"text": "<p>There's plenty of people who would assert that your objective is to mislead the user, that it is unethical. However, if you... | 2008/11/24 | [
"https://Stackoverflow.com/questions/315887",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/40440/"
] | How do I mask the address of another site using HTML?
For example, I'd like:
<http://www.example.com/source.html>
To point to another page:
<http://www.example.com/dest.html>
Note that the destination page could be on another domain. | A frameset seems to be what I was looking for:
```
<frameset rows="100%">
<frame src="http://www.example.com/dest.html"/>
</frameset>
``` |
315,893 | <p>Writing a ton of web applications leveraging JSON/AJAX, I find myself returning tons literal javascript objects (JSON). For example, I may be request all the Cats from GetCats.asp. It would return:</p>
<pre>
[
{ 'id': 0, 'name': 'Persian' },
{ 'id': 1, 'name': 'Calico' },
{ 'id': 2, 'name': 'Tabby' }
]
</pr... | [
{
"answer_id": 315927,
"author": "Benry",
"author_id": 28408,
"author_profile": "https://Stackoverflow.com/users/28408",
"pm_score": 2,
"selected": false,
"text": "<p>There's no getting around the fact that you will have to iterate through all of your simple objects and change them to a ... | 2008/11/24 | [
"https://Stackoverflow.com/questions/315893",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | Writing a ton of web applications leveraging JSON/AJAX, I find myself returning tons literal javascript objects (JSON). For example, I may be request all the Cats from GetCats.asp. It would return:
```
[
{ 'id': 0, 'name': 'Persian' },
{ 'id': 1, 'name': 'Calico' },
{ 'id': 2, 'name': 'Tabby' }
]
```
Now, the... | There's no getting around the fact that you will have to iterate through all of your simple objects and change them to a different kind of object. You cannot avoid the loop. That being said you could create a constructor that takes a simple object like this and copies those values into the new instance.
Like this:
``... |
315,911 | <p>Ok, after seeing <a href="https://stackoverflow.com/questions/315911/git-for-beginners-the-definitive-practical-guide/2678236#2678236">this post by PJ Hyett</a>, I have decided to skip to the end and go with <a href="http://en.wikipedia.org/wiki/Git_(software)" rel="nofollow noreferrer">Git</a>.</p>
<p>So what I ne... | [
{
"answer_id": 316030,
"author": "Pat Notz",
"author_id": 825,
"author_profile": "https://Stackoverflow.com/users/825",
"pm_score": 6,
"selected": false,
"text": "<p>Well, despite the fact that you asked that we not \"simply\" link to other resources, it's pretty foolish when there alrea... | 2008/11/24 | [
"https://Stackoverflow.com/questions/315911",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2915/"
] | Ok, after seeing [this post by PJ Hyett](https://stackoverflow.com/questions/315911/git-for-beginners-the-definitive-practical-guide/2678236#2678236), I have decided to skip to the end and go with [Git](http://en.wikipedia.org/wiki/Git_(software)).
So what I need is a beginner's **practical** guide to Git. "Beginner" ... | How do you create a new project/repository?
===========================================
A git repository is simply a directory containing a special `.git` directory.
This is different from "centralised" version-control systems (like subversion), where a "repository" is hosted on a remote server, which you `checkout` ... |
315,915 | <p>I have a SUM array formula that has multiple nested IF statements, making it very inefficient. My formula spans over 500 rows, but here is a simple version of it:</p>
<pre><code>{=SUM(IF(IF(A1:A5>A7:A11,A1:A5,A7:A11)-A13:A17>0,
IF(A1:A5>A7:A11,A1:A5,A7:A11)-A13:A17,0))}
</code></pre>
<p>As you can see, th... | [
{
"answer_id": 316024,
"author": "Jimmy",
"author_id": 4435,
"author_profile": "https://Stackoverflow.com/users/4435",
"pm_score": 2,
"selected": false,
"text": "<pre><code>=MAX( MAX( sum(A1:A5), sum(A7:A11) ) - sum(A13:A17), 0)\n</code></pre>\n"
},
{
"answer_id": 316396,
"au... | 2008/11/24 | [
"https://Stackoverflow.com/questions/315915",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/40432/"
] | I have a SUM array formula that has multiple nested IF statements, making it very inefficient. My formula spans over 500 rows, but here is a simple version of it:
```
{=SUM(IF(IF(A1:A5>A7:A11,A1:A5,A7:A11)-A13:A17>0,
IF(A1:A5>A7:A11,A1:A5,A7:A11)-A13:A17,0))}
```
As you can see, the first half of the formula checks ... | ```
=MAX( MAX( sum(A1:A5), sum(A7:A11) ) - sum(A13:A17), 0)
``` |
315,946 | <p>I have a table User which has an identity column <code>UserID</code>, now what is the correct Linq to Entity line of code that would return me the max <code>UserID</code>?</p>
<p>I've tried:</p>
<pre><code>using (MyDBEntities db = new MyDBEntities())
{
var User = db.Users.Last();
// or
var User = db.Us... | [
{
"answer_id": 315950,
"author": "Jonas Kongslund",
"author_id": 37548,
"author_profile": "https://Stackoverflow.com/users/37548",
"pm_score": 8,
"selected": true,
"text": "<p>Do that like this</p>\n\n<pre><code>db.Users.OrderByDescending(u => u.UserId).FirstOrDefault();\n</code></pre... | 2008/11/25 | [
"https://Stackoverflow.com/questions/315946",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/32240/"
] | I have a table User which has an identity column `UserID`, now what is the correct Linq to Entity line of code that would return me the max `UserID`?
I've tried:
```
using (MyDBEntities db = new MyDBEntities())
{
var User = db.Users.Last();
// or
var User = db.Users.Max();
return user.UserID;
}
```
... | Do that like this
```
db.Users.OrderByDescending(u => u.UserId).FirstOrDefault();
``` |
315,948 | <p>Is there a c++ equivalent of Java's</p>
<pre><code>try {
...
}
catch (Throwable t) {
...
}
</code></pre>
<p>I am trying to debug Java/jni code that calls native windows functions and the virtual machine keeps crashing. The native code appears fine in unit testing and only seems to crash when called throug... | [
{
"answer_id": 315957,
"author": "Greg Hewgill",
"author_id": 893,
"author_profile": "https://Stackoverflow.com/users/893",
"pm_score": 6,
"selected": false,
"text": "<pre><code>try {\n // ...\n} catch (...) {\n // ...\n}\n</code></pre>\n\n<p>Note that the <code>...</code> inside the... | 2008/11/25 | [
"https://Stackoverflow.com/questions/315948",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/23120/"
] | Is there a c++ equivalent of Java's
```
try {
...
}
catch (Throwable t) {
...
}
```
I am trying to debug Java/jni code that calls native windows functions and the virtual machine keeps crashing. The native code appears fine in unit testing and only seems to crash when called through jni. A generic exception ... | ```
try{
// ...
} catch (...) {
// ...
}
```
will catch all C++ exceptions, but it should be considered bad design. You can use c++11's new current\_exception mechanism, but if you don't have the ability to use c++11 (legacy code systems requiring a rewrite), then you have no named exception pointer to use to... |
315,963 | <p>I am currently working in C#, and I need to insert a new record into one table, get the new primary key value, and then use that as a foreign key reference in inserting several more records. The Database is MS SQL Server 2003. All help is appreciated!</p>
| [
{
"answer_id": 315974,
"author": "Duncan",
"author_id": 25035,
"author_profile": "https://Stackoverflow.com/users/25035",
"pm_score": 2,
"selected": false,
"text": "<p>The best way of doing this is the use SCOPE_IDENTITY() function in TSQL. This should be executed as part of the insert ... | 2008/11/25 | [
"https://Stackoverflow.com/questions/315963",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/40459/"
] | I am currently working in C#, and I need to insert a new record into one table, get the new primary key value, and then use that as a foreign key reference in inserting several more records. The Database is MS SQL Server 2003. All help is appreciated! | The way to get the identity of the inserted row is with the `SCOPE_IDENTITY()` function. If you're using stored procedures then this would look something like the following to return the row identity as an output parameter.
```
CREATE PROCEDURE dbo.MyProcedure
(
@RowId INT = NULL OUTPUT
)
AS
INSERT INTO MyTable
(... |
315,964 | <p>I'm relatively familiar with the concepts of DI/IOC containers having worked on projects previously where their use were already in place. However, for this new project, there is no existing framework and I'm having to pick one.</p>
<p>Long story short, there are some scenarios where we'll be configuring several i... | [
{
"answer_id": 316048,
"author": "bakasan",
"author_id": 2228,
"author_profile": "https://Stackoverflow.com/users/2228",
"pm_score": 0,
"selected": false,
"text": "<p>So I somehow missed this my first pass looking through Unity somehow...but I'll answer my own question.</p>\n\n<p>Unity h... | 2008/11/25 | [
"https://Stackoverflow.com/questions/315964",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2228/"
] | I'm relatively familiar with the concepts of DI/IOC containers having worked on projects previously where their use were already in place. However, for this new project, there is no existing framework and I'm having to pick one.
Long story short, there are some scenarios where we'll be configuring several implementati... | One thing that caught me the first time I was trying to resolve all implementations of a registered type was that un-named (default) type registrations will *not* be returned when you call ResolveAll(). Only named instances are returned.
So:
```
IUnityContainer container = new UnityContainer();
container.RegisterType... |
315,965 | <p>In have a many-to-many linking table and I'm trying to set up two foreign keys on it. I run these two statements:</p>
<pre><code>ALTER TABLE address_list_memberships
ADD CONSTRAINT fk_address_list_memberships_address_id
FOREIGN KEY index_address_id (address_id)
REFERENCES addresses (id);
ALTER TABLE address_list_m... | [
{
"answer_id": 316054,
"author": "Bill Karwin",
"author_id": 20860,
"author_profile": "https://Stackoverflow.com/users/20860",
"pm_score": 2,
"selected": false,
"text": "<p>I just tried it and it works fine for me. I copied and pasted the <code>ALTER</code> statements you wrote and here... | 2008/11/25 | [
"https://Stackoverflow.com/questions/315965",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | In have a many-to-many linking table and I'm trying to set up two foreign keys on it. I run these two statements:
```
ALTER TABLE address_list_memberships
ADD CONSTRAINT fk_address_list_memberships_address_id
FOREIGN KEY index_address_id (address_id)
REFERENCES addresses (id);
ALTER TABLE address_list_memberships
ADD... | I just tried it and it works fine for me. I copied and pasted the `ALTER` statements you wrote and here is what I get:
```
mysql> show create table address_list_memberships;
CREATE TABLE `address_list_memberships` (
`address_id` bigint(20) unsigned NOT NULL,
`list_id` bigint(20) unsigned NOT NULL,
KEY `index_ad... |
315,966 | <p>I'm new to using LINQ to Entities (or Entity Framework whatever they're calling it) and I'm writing a lot of code like this:</p>
<pre><code>var item = (from InventoryItem item in db.Inventory
where item.ID == id
select item).First<InventoryItem>();
</code></pre>
<p>and then calling me... | [
{
"answer_id": 315985,
"author": "Robert Wagner",
"author_id": 10784,
"author_profile": "https://Stackoverflow.com/users/10784",
"pm_score": 7,
"selected": true,
"text": "<p>You want to use the .Include(string) method references in this <a href=\"http://msdn.microsoft.com/en-us/library/b... | 2008/11/25 | [
"https://Stackoverflow.com/questions/315966",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4541/"
] | I'm new to using LINQ to Entities (or Entity Framework whatever they're calling it) and I'm writing a lot of code like this:
```
var item = (from InventoryItem item in db.Inventory
where item.ID == id
select item).First<InventoryItem>();
```
and then calling methods on that object like this:
... | You want to use the .Include(string) method references in this ["Shaping query results"](http://msdn.microsoft.com/en-us/library/bb896272.aspx) article.
```
var item = from InventoryItem item in
db.Inventory.Include("ItemTypeReference").Include("OrderLineItems")
where item.ID == id
... |
315,968 | <p>I have a Gridview boundfield where i set ReadOnly to true because i don't want user to change its value. However on the objectdatasource control's update method that boundfield became null when i try to use it as parameter in update method. Is there a way to set that value during updating?</p>
| [
{
"answer_id": 316138,
"author": "tvanfosson",
"author_id": 12950,
"author_profile": "https://Stackoverflow.com/users/12950",
"pm_score": 3,
"selected": true,
"text": "<p>When you mark a field as read-only on the GridView it renders on the page as a span element, not an input. Therefore... | 2008/11/25 | [
"https://Stackoverflow.com/questions/315968",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/28647/"
] | I have a Gridview boundfield where i set ReadOnly to true because i don't want user to change its value. However on the objectdatasource control's update method that boundfield became null when i try to use it as parameter in update method. Is there a way to set that value during updating? | When you mark a field as read-only on the GridView it renders on the page as a span element, not an input. Therefore the value is not available on PostBack. If you can construct the update statement so that it doesn't expect this field, that would be the best way to deal with this. If the update statement is autogenera... |
315,987 | <p>There are a few things that I almost always do when I put a class together in C++.</p>
<p>1) Virtual Destructor
2) Copy constructor and assignment operator (I either implement them in terms of a private function called Copy(), or declare them private and thus explicitly disallow the compiler to auto generate them).... | [
{
"answer_id": 315999,
"author": "Federico A. Ramponi",
"author_id": 18770,
"author_profile": "https://Stackoverflow.com/users/18770",
"pm_score": 2,
"selected": false,
"text": "<p>Often,</p>\n\n<pre><code>operator string () const;\n</code></pre>\n\n<p>or</p>\n\n<pre><code>friend ostream... | 2008/11/25 | [
"https://Stackoverflow.com/questions/315987",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3886/"
] | There are a few things that I almost always do when I put a class together in C++.
1) Virtual Destructor
2) Copy constructor and assignment operator (I either implement them in terms of a private function called Copy(), or declare them private and thus explicitly disallow the compiler to auto generate them).
What thi... | I find turning on the gcc flags `-Wall`, `-Werror`, and (this is the fun one) `-Weffc++` help catch a lot of potential problems. From the gcc man page:
>
>
> ```
> -Weffc++ (C++ only)
> Warn about violations of the following style guidelines from Scott
> Meyers’ Effective C++ book:
>
> · Item ... |
315,991 | <p>I need a command to replace the hosts file on my machine. Seems pretty straight forward but I cannot get the command to work with xcopy. Any obvious flaws in the command?</p>
<p>luaexec -w -f "XCOPY" "%ScriptPath%/ModifiedHosts/vista/hosts"
"%windir%/system32/drivers/etc/hosts" /H</p>
<p>The /R flag does not seem... | [
{
"answer_id": 316000,
"author": "Scott Evernden",
"author_id": 11397,
"author_profile": "https://Stackoverflow.com/users/11397",
"pm_score": 0,
"selected": false,
"text": "<p>is the hosts file write protected? it probably is.. add a /R to your commandline</p>\n"
},
{
"answer_id... | 2008/11/25 | [
"https://Stackoverflow.com/questions/315991",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15059/"
] | I need a command to replace the hosts file on my machine. Seems pretty straight forward but I cannot get the command to work with xcopy. Any obvious flaws in the command?
luaexec -w -f "XCOPY" "%ScriptPath%/ModifiedHosts/vista/hosts"
"%windir%/system32/drivers/etc/hosts" /H
The /R flag does not seem to help and the ... | Did you get any error?
Try this:
```
luaexec -w -f "XCOPY %ScriptPath%/ModifiedHosts/vista/hosts %windir%/system32/drivers/etc/hosts" /H
```
Also, you can try robocopy. |
316,007 | <p>I'm wondering if there is a better/inbuilt way, other than using a byte buffer and looping, to read from one stream and write it to another (in .NET). Generally this is done to apply a transform to a stream and move it on.</p>
<p>In this instance, what I am loading a file, putting it through a deflate stream and wr... | [
{
"answer_id": 316025,
"author": "Matt Hamilton",
"author_id": 615,
"author_profile": "https://Stackoverflow.com/users/615",
"pm_score": 1,
"selected": false,
"text": "<p>Now that I think about it, I haven't ever seen any built-in support for piping the results of an input stream directl... | 2008/11/25 | [
"https://Stackoverflow.com/questions/316007",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10784/"
] | I'm wondering if there is a better/inbuilt way, other than using a byte buffer and looping, to read from one stream and write it to another (in .NET). Generally this is done to apply a transform to a stream and move it on.
In this instance, what I am loading a file, putting it through a deflate stream and writing it o... | There's not really a better way than that, though I tend to put the looping part into a `CopyTo` extension method, e.g.
```
public static void CopyTo(this Stream source, Stream destination)
{
var buffer = new byte[0x1000];
int bytesInBuffer;
while ((bytesInBuffer = source.Read(buffer, 0, buffer.Length)) > ... |
316,008 | <p>I'm trying to import some data from Excel to SQL Server, I have a TEXT column with some numbers in it, some of the numbers go over just fine, and some turn into scientific form.</p>
<p>Column in Excel is "text" type, column in the target sql table is varchar(255)</p>
<p>Here are some examples: </p>
<p>Excel [text... | [
{
"answer_id": 316025,
"author": "Matt Hamilton",
"author_id": 615,
"author_profile": "https://Stackoverflow.com/users/615",
"pm_score": 1,
"selected": false,
"text": "<p>Now that I think about it, I haven't ever seen any built-in support for piping the results of an input stream directl... | 2008/11/25 | [
"https://Stackoverflow.com/questions/316008",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3661/"
] | I'm trying to import some data from Excel to SQL Server, I have a TEXT column with some numbers in it, some of the numbers go over just fine, and some turn into scientific form.
Column in Excel is "text" type, column in the target sql table is varchar(255)
Here are some examples:
Excel [text] -> SQL Server [varchar... | There's not really a better way than that, though I tend to put the looping part into a `CopyTo` extension method, e.g.
```
public static void CopyTo(this Stream source, Stream destination)
{
var buffer = new byte[0x1000];
int bytesInBuffer;
while ((bytesInBuffer = source.Read(buffer, 0, buffer.Length)) > ... |
316,009 | <p>I'm working on something that requires traversing through the file system and for any given path, I need to know how 'deep' I am in the folder structure. Here's what I'm currently using:</p>
<pre><code>int folderDepth = 0;
string tmpPath = startPath;
while (Directory.GetParent(tmpPath) != null)
{
folderDepth+... | [
{
"answer_id": 316016,
"author": "Paul Sonier",
"author_id": 28053,
"author_profile": "https://Stackoverflow.com/users/28053",
"pm_score": 5,
"selected": true,
"text": "<p>Off the top of my head:</p>\n\n<pre><code>Directory.GetFullPath().Split(\"\\\\\").Length;\n</code></pre>\n"
},
{... | 2008/11/25 | [
"https://Stackoverflow.com/questions/316009",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1354/"
] | I'm working on something that requires traversing through the file system and for any given path, I need to know how 'deep' I am in the folder structure. Here's what I'm currently using:
```
int folderDepth = 0;
string tmpPath = startPath;
while (Directory.GetParent(tmpPath) != null)
{
folderDepth++;
tmpPath... | Off the top of my head:
```
Directory.GetFullPath().Split("\\").Length;
``` |
316,017 | <p>Here's the code I have in the html file to "include" the file "vmenu.php"</p>
<pre><code> <div id="apDivVistaMenus">
<?php
include 'vmenu.php';
?>
<!-- Begin Vista-Buttons.com -->
<!-- End Vista-Buttons.com -->
</div>
</code></pre>
<p>The menus used to be between the commen... | [
{
"answer_id": 316032,
"author": "Kamran",
"author_id": 40036,
"author_profile": "https://Stackoverflow.com/users/40036",
"pm_score": 3,
"selected": false,
"text": "<p>Note that, in order for PHP includes to work, the file must be parsed by the PHP engine. By default, major web servers l... | 2008/11/25 | [
"https://Stackoverflow.com/questions/316017",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/40091/"
] | Here's the code I have in the html file to "include" the file "vmenu.php"
```
<div id="apDivVistaMenus">
<?php
include 'vmenu.php';
?>
<!-- Begin Vista-Buttons.com -->
<!-- End Vista-Buttons.com -->
</div>
```
The menus used to be between the comments below the php include request. But I save that code i... | Note that, in order for PHP includes to work, the file must be parsed by the PHP engine. By default, major web servers like Apache do not run .html files through the PHP interpreter, so you must either specify in your web server's configuration that you want to parse .html files as PHP files, or rename the .html file t... |
316,078 | <p>I saw the following interesting usage of tar in a co-worker's Bash scripts:</p>
<pre><code>`tar cf - * | (cd <dest> ; tar xf - )`
</code></pre>
<p>Apparently it works much like rsync -av does, but faster. The question arises, how?</p>
<p>-m</p>
<hr>
<p><strong>EDIT</strong>: Can anyone explain <em>why</e... | [
{
"answer_id": 316083,
"author": "tvanfosson",
"author_id": 12950,
"author_profile": "https://Stackoverflow.com/users/12950",
"pm_score": 4,
"selected": false,
"text": "<p>It writes the archive to standard output, then pipes it to a subprocess -- wrapped by the parentheses -- that change... | 2008/11/25 | [
"https://Stackoverflow.com/questions/316078",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/31295/"
] | I saw the following interesting usage of tar in a co-worker's Bash scripts:
```
`tar cf - * | (cd <dest> ; tar xf - )`
```
Apparently it works much like rsync -av does, but faster. The question arises, how?
-m
---
**EDIT**: Can anyone explain *why* should this solution be preferable over the following?
```
cp -... | On the difference between cp and tar to copy the directory hierarchies, a simple experiment can be conducted to show the difference:
```
alastair box:~/hack/cptest [1134]% mkdir src
alastair box:~/hack/cptest [1135]% cd src
alastair box:~/hack/cptest/src [1136]% touch foo
alastair box:~/hack/cptest/src [1137]% ln -s f... |
316,099 | <p>I have a site that connects using cURL (latest version) to a secure gateway for payment.</p>
<p>The problem is cURL always returns 0 length content. I get headers only. And only when I set cURL to return headers. I have the following flags in place.</p>
<pre><code>curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
... | [
{
"answer_id": 316185,
"author": "too much php",
"author_id": 28835,
"author_profile": "https://Stackoverflow.com/users/28835",
"pm_score": -1,
"selected": false,
"text": "<p>You are using POST method, but are you providing an array of data? E.g.</p>\n\n<pre><code>curl_setopt($ch, CURLOP... | 2008/11/25 | [
"https://Stackoverflow.com/questions/316099",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/31671/"
] | I have a site that connects using cURL (latest version) to a secure gateway for payment.
The problem is cURL always returns 0 length content. I get headers only. And only when I set cURL to return headers. I have the following flags in place.
```
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
curl_setopt($ch, CURL... | You should also try checking the error messages in curl\_error(). You might need to do this once after each curl\_\* function.
<http://www.php.net/curl_error> |
316,100 | <p>The following code works for 90+ % of global security groups, but for one very large global security group, it returns an enumerator, but no member objects of the group, even though the group has many thousands.</p>
<pre><code>DirectoryEntry group = groupResult.GetDirectoryEntry();
filter = "member;range=0-20";
gro... | [
{
"answer_id": 316841,
"author": "Bevan",
"author_id": 30280,
"author_profile": "https://Stackoverflow.com/users/30280",
"pm_score": 2,
"selected": true,
"text": "<p>The problem may not be with your code, but with access security in your directory - you may not have rights to enumerate t... | 2008/11/25 | [
"https://Stackoverflow.com/questions/316100",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18313/"
] | The following code works for 90+ % of global security groups, but for one very large global security group, it returns an enumerator, but no member objects of the group, even though the group has many thousands.
```
DirectoryEntry group = groupResult.GetDirectoryEntry();
filter = "member;range=0-20";
group.RefreshCach... | The problem may not be with your code, but with access security in your directory - you may not have rights to enumerate the members of that group. |
316,131 | <p>Given a linux kernel oops, how do you go about diagnosing the problem? In the output I can see a stack trace which seems to give some clues. Are there any tools that would help find the problem? What basic procedures do you follow to track it down?</p>
<pre><code>
Unable to handle kernel paging request for data ... | [
{
"answer_id": 316363,
"author": "Ana Betts",
"author_id": 5728,
"author_profile": "https://Stackoverflow.com/users/5728",
"pm_score": 1,
"selected": false,
"text": "<p><a href=\"http://oss.sgi.com/projects/kdb/\" rel=\"nofollow noreferrer\">http://oss.sgi.com/projects/kdb/</a></p>\n\n<p... | 2008/11/25 | [
"https://Stackoverflow.com/questions/316131",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20889/"
] | Given a linux kernel oops, how do you go about diagnosing the problem? In the output I can see a stack trace which seems to give some clues. Are there any tools that would help find the problem? What basic procedures do you follow to track it down?
```
Unable to handle kernel paging request for data at address 0x3334... | An Oops gives a bunch of information useful in diagnosing a crash. It starts with the address of the crash, the reason ("access of bad area") and the contents of the registers. The call trace answers the question "how did we get here". The first item in the list happened most recently. Working backwards, an interrupt h... |
316,147 | <p>How do I hide the <strong>prev/today/next</strong> navigation in jQuery DatePicker?</p>
<p>I'm happy with just the Month and Year drop down boxes.</p>
<p>Also how do I disable the animations?</p>
<p><a href="https://stackoverflow.com/questions/316147/how-do-i-hide-the-nexttodayprevious-navigation-in-jquery-datepi... | [
{
"answer_id": 316153,
"author": "tvanfosson",
"author_id": 12950,
"author_profile": "https://Stackoverflow.com/users/12950",
"pm_score": 3,
"selected": false,
"text": "<p>You can find the options for the DatePicker control at <a href=\"http://docs.jquery.com/UI/Datepicker/datepicker#opt... | 2008/11/25 | [
"https://Stackoverflow.com/questions/316147",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/419/"
] | How do I hide the **prev/today/next** navigation in jQuery DatePicker?
I'm happy with just the Month and Year drop down boxes.
Also how do I disable the animations?
[@tvanfosson](https://stackoverflow.com/questions/316147/how-do-i-hide-the-nexttodayprevious-navigation-in-jquery-datepicker-and-turn-of#316153) - I alr... | You can find the options for the DatePicker control at <http://docs.jquery.com/UI/Datepicker/datepicker#options>. Specifically, I think you want to set hideIfNoPrevNext to true and set duration to ''.
```
$('#cal').datepicker( { hideIfNoPrevNext: true, duration: '' } );
``` |
316,157 | <p>I have an nmake-based project which in turn calls the asp compiler, which can throw an error, which nmake seems to recognize:</p>
<pre><code>NMAKE : fatal error U1077: 'C:\Windows\Microsoft.NET\Framework\v2.0.50727\aspnet_compiler.exe' : return code '0x1'
</code></pre>
<p>However, when I call nmake from within a b... | [
{
"answer_id": 1327920,
"author": "Jay",
"author_id": 151152,
"author_profile": "https://Stackoverflow.com/users/151152",
"pm_score": 1,
"selected": false,
"text": "<p>First thing, please post your batch file so we can see how you trap the error.<br>\nAlso comment this post so I can read... | 2008/11/25 | [
"https://Stackoverflow.com/questions/316157",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/26624/"
] | I have an nmake-based project which in turn calls the asp compiler, which can throw an error, which nmake seems to recognize:
```
NMAKE : fatal error U1077: 'C:\Windows\Microsoft.NET\Framework\v2.0.50727\aspnet_compiler.exe' : return code '0x1'
```
However, when I call nmake from within a batch file, the environment... | First thing, please post your batch file so we can see how you trap the error.
Also comment this post so I can read it again.
As a first git, i'd guess something like:
**nmakebatch.cmd** *usual nmake arguments, without /NOLOGO*
```
@echo off
rem Args[x]: nmake arguments
echo.>> %~n0.log
echo %date% %time%>> %~... |
316,166 | <p>VBScript doesn't appear to have a way to include a common file of functions.</p>
<p>Is there a way to achieve this?</p>
| [
{
"answer_id": 316169,
"author": "paxdiablo",
"author_id": 14860,
"author_profile": "https://Stackoverflow.com/users/14860",
"pm_score": 6,
"selected": false,
"text": "<p>You can create a (relatively) small function in each file that you want to include other files into, as follows:</p>\... | 2008/11/25 | [
"https://Stackoverflow.com/questions/316166",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14860/"
] | VBScript doesn't appear to have a way to include a common file of functions.
Is there a way to achieve this? | The "Windows Script Host" framework (if ya want to call it that), offers an XML wrapper document that adds functionality over regular vbs files. One of which is the ability to include external script files of both the VBscript and Jscript flavors. I never got very deep into it, but I think it would do what you're wanti... |
316,172 | <p>I'm trying to increase the timeout on all sessions. The site is hosted with Godaddy, and it is written in Flash (client side of course) and asp.net on the backend. I've added this to my web.config, </p>
<pre><code><sessionState timeout="720">
</sessionState>
</code></pre>
<p>Is that really all that ... | [
{
"answer_id": 316188,
"author": "Thomas Hansen",
"author_id": 29746,
"author_profile": "https://Stackoverflow.com/users/29746",
"pm_score": 4,
"selected": true,
"text": "<p>Yup!\nAs in; Yes, that's the only thing you need to do...</p>\n\n<p>To get \"never ending timeouts\" you'd have to... | 2008/11/25 | [
"https://Stackoverflow.com/questions/316172",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/232/"
] | I'm trying to increase the timeout on all sessions. The site is hosted with Godaddy, and it is written in Flash (client side of course) and asp.net on the backend. I've added this to my web.config,
```
<sessionState timeout="720">
</sessionState>
```
Is that really all that I need to do? I'd prefer to not let sess... | Yup!
As in; Yes, that's the only thing you need to do...
To get "never ending timeouts" you'd have to create a background HTTP request (which will transmit the session cookie) back to the server every 719 minute though. Though theoretically then you'd also have to have "Out of Process" sessions using e.g. some sort of... |
316,178 | <p>Profiling LINQ queries and their execution plans is especially important due to the crazy SQL that can sometimes be created. </p>
<p>I often find that I need to track a specific query and have a hard time finding in query analyzer. I often do this on a database which has a lot of running transactions (sometimes pro... | [
{
"answer_id": 316207,
"author": "FlySwat",
"author_id": 1965,
"author_profile": "https://Stackoverflow.com/users/1965",
"pm_score": 1,
"selected": false,
"text": "<p>You can have your datacontext log out the raw SQL, which you could then search for in the profiler to examine performance... | 2008/11/25 | [
"https://Stackoverflow.com/questions/316178",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16940/"
] | Profiling LINQ queries and their execution plans is especially important due to the crazy SQL that can sometimes be created.
I often find that I need to track a specific query and have a hard time finding in query analyzer. I often do this on a database which has a lot of running transactions (sometimes production se... | Messing with the where clause is maybe not the best thing to do since it can and will affect the execution plans for your queries.
Do something funky with projection into anonymous classes instead - use a unique static column name or something that will not affect the execution plan. (That way you can leave it intact ... |
316,181 | <p>Having recently introduced an overload of a method the application started to fail.
Finally tracking it down, the new method is being called where I did not expect it to be.</p>
<p>We had</p>
<pre><code>setValue( const std::wstring& name, const std::wstring& value );
std::wstring avalue( func() );
setValu... | [
{
"answer_id": 316199,
"author": "John Zwinck",
"author_id": 4323,
"author_profile": "https://Stackoverflow.com/users/4323",
"pm_score": 0,
"selected": false,
"text": "<p>You could make the new function take some other type than bool--maybe just a proxy for bool--which is not convertible... | 2008/11/25 | [
"https://Stackoverflow.com/questions/316181",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/37558/"
] | Having recently introduced an overload of a method the application started to fail.
Finally tracking it down, the new method is being called where I did not expect it to be.
We had
```
setValue( const std::wstring& name, const std::wstring& value );
std::wstring avalue( func() );
setValue( L"string", avalue );
std::... | First, the cause of this issue: C++ Standard [`[over.ics.rank]/2.1`](http://eel.is/c++draft/over.ics.rank#2.1)1 defines an order for conversion sequences. It says that a user defined conversion sequence is worse than a standard conversion sequence. What happens in your case is that the string literal undergoes a boolea... |
316,193 | <p>I have <strong>CustomForm</strong> inherited from <strong>Form</strong> which implements a boolean property named <strong>Prop</strong>. The forms I'll be using will inherit from <strong>CustomForm</strong>. This property will do some painting and changes (if it's enabled) to the form. However, this is not working a... | [
{
"answer_id": 316428,
"author": "BFree",
"author_id": 15861,
"author_profile": "https://Stackoverflow.com/users/15861",
"pm_score": 2,
"selected": false,
"text": "<p>All you need to do is add this Attribute to your property:</p>\n\n<pre><code> [Description(\"Description of your property... | 2008/11/25 | [
"https://Stackoverflow.com/questions/316193",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/40480/"
] | I have **CustomForm** inherited from **Form** which implements a boolean property named **Prop**. The forms I'll be using will inherit from **CustomForm**. This property will do some painting and changes (if it's enabled) to the form. However, this is not working as it should, the VS IDE designed is not being refresh t... | Someone else helped me out and to fix the problem. I just call **ReCreateHandle()** when the user sets **EnableSkin** to false. Problem solved :)
Thanks everyone though :) |
316,194 | <p>I am trying to understand the process of declaration and assignment of a primitive type at the back stage.</p>
<ol>
<li><code>int i;</code></li>
<li><code>i = 3;</code></li>
</ol>
<p>For 1), on the memory stack, it assigns a space for storing an int type value named i
For 2), it assigns the value 3 to the space ... | [
{
"answer_id": 316201,
"author": "Kyle Cronin",
"author_id": 658,
"author_profile": "https://Stackoverflow.com/users/658",
"pm_score": 1,
"selected": false,
"text": "<p>Assuming you're talking about C or C++ (I can't tell), yes. You can access the address like so:</p>\n\n<pre><code>int i... | 2008/11/25 | [
"https://Stackoverflow.com/questions/316194",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/36064/"
] | I am trying to understand the process of declaration and assignment of a primitive type at the back stage.
1. `int i;`
2. `i = 3;`
For 1), on the memory stack, it assigns a space for storing an int type value named i
For 2), it assigns the value 3 to the space preserved above
Is there a memory address there?
From my... | There are not always addresses involved. The compiler can put variables into registers if it finds that their address is never taken by the programmer. So you wouldn't need any access to the main memory. For example in your code above, what the compiler could generate could be as simple as
```
add $2, $0, 3
```
to ... |
316,204 | <p>There's an executable file generated from my program in MFC and I want to use it as the default program to open the <code>.jpg</code> files. That is to say, each time I double click a <code>.jpg</code> file, my program will run. </p>
<p>I tried to add some registry entries linking <code>.jpg</code> files with my pr... | [
{
"answer_id": 316279,
"author": "Charlie",
"author_id": 18529,
"author_profile": "https://Stackoverflow.com/users/18529",
"pm_score": 2,
"selected": false,
"text": "<p>The more typical/standard way for doing this is to set the default value of the \".jpg\" key to a name that identifies ... | 2008/11/25 | [
"https://Stackoverflow.com/questions/316204",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/26404/"
] | There's an executable file generated from my program in MFC and I want to use it as the default program to open the `.jpg` files. That is to say, each time I double click a `.jpg` file, my program will run.
I tried to add some registry entries linking `.jpg` files with my program, such as `HKEY_CLASSES_ROOT\.jpg\shel... | The more typical/standard way for doing this is to set the default value of the ".jpg" key to a name that identifies the file type more clearly, and then setup the various associated actions there. So for jpgs, you might do this:
```
HKCR\.jpg
@default = MyApp.JpegImage
HKCR\MyApp.JpegImage\shell\open\command
@d... |
316,210 | <p>I'm kind of new to ASP.NET MVC and to the MVC pattern in general but I'm really digging the concept and the rapidity with which I can compose an app. One thing that I'm struggling with is how to expose more than one object to a view. I use a lot of strongly typed views, which works well but what if my view relies ... | [
{
"answer_id": 316216,
"author": "tvanfosson",
"author_id": 12950,
"author_profile": "https://Stackoverflow.com/users/12950",
"pm_score": 3,
"selected": true,
"text": "<p>You can simply store each object in the ViewData then cast the appropriate object type in your View.</p>\n\n<p>Contro... | 2008/11/25 | [
"https://Stackoverflow.com/questions/316210",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4541/"
] | I'm kind of new to ASP.NET MVC and to the MVC pattern in general but I'm really digging the concept and the rapidity with which I can compose an app. One thing that I'm struggling with is how to expose more than one object to a view. I use a lot of strongly typed views, which works well but what if my view relies on mo... | You can simply store each object in the ViewData then cast the appropriate object type in your View.
Controller:
```
ViewData["ObjectA"] = objectA;
ViewData["ObjectB"] = objectB;
```
View:
```
<%= ((ObjectA)ViewData["ObjectA"]).PropertyA %>
<%= ((ObjectB)ViewData["ObjectB")).PropertyB %>
```
or better yet,
... |
316,211 | <p>I have a query that selects all appropriate record in a table 'hotels' and then for each hotel looks for booked room of certain type in table 'booked_rooms' and all of that for certain period.
So first I'm taking out all hotel_ids from 'hotel_table', based on the location provided from the search form, and for each... | [
{
"answer_id": 316235,
"author": "Codewerks",
"author_id": 17729,
"author_profile": "https://Stackoverflow.com/users/17729",
"pm_score": 3,
"selected": false,
"text": "<p>Not knowing PHP, can you do it in one query?</p>\n\n<pre><code>SELECT booked_rooms.*, hotels.* FROM 'hotels' \nJOIN '... | 2008/11/25 | [
"https://Stackoverflow.com/questions/316211",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/432217/"
] | I have a query that selects all appropriate record in a table 'hotels' and then for each hotel looks for booked room of certain type in table 'booked\_rooms' and all of that for certain period.
So first I'm taking out all hotel\_ids from 'hotel\_table', based on the location provided from the search form, and for each ... | Not knowing PHP, can you do it in one query?
```
SELECT booked_rooms.*, hotels.* FROM 'hotels'
JOIN 'booked_rooms' ON hotels.hotel_id = booked_rooms.hotel_id
WHERE
hotels.city='$city" AND
(
booked_rooms.arrival_date BETWEEN '$arrival_date' AND '$departure_date' OR
booked_rooms.departure_date BETWEEN '... |
316,222 | <p>How can I use a database and PHP sessions to store a user's shopping cart? I am using CodeIgniter, if that helps.</p>
<p>Example code would also be nice.</p>
| [
{
"answer_id": 316287,
"author": "Noah Goodrich",
"author_id": 20178,
"author_profile": "https://Stackoverflow.com/users/20178",
"pm_score": 2,
"selected": false,
"text": "<p>I would recommend that you look at <a href=\"http://codeigniter.com/user_guide/libraries/sessions.html\" rel=\"no... | 2008/11/25 | [
"https://Stackoverflow.com/questions/316222",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | How can I use a database and PHP sessions to store a user's shopping cart? I am using CodeIgniter, if that helps.
Example code would also be nice. | I would write an add to basket function like this:
```
function AddToBasket(){
if(is_numeric($_GET["ID"])){
$ProductID=(int)$_GET["ID"];
$_SESSION["Basket"][]=$ProductID;
$sOut.=ShowBasketDetail();
return $sOut;
}
}
```
In this shopping basket function we save Product IDs in ... |
316,236 | <p>I want to load some images into my application from the file system. There's 2 easy ways to do this:</p>
<pre><code>[UIImage imageNamed:fullFileName]
</code></pre>
<p>or:</p>
<pre><code>NSString *fileLocation = [[NSBundle mainBundle] pathForResource:fileName ofType:extension];
NSData *imageData = [NSData dataWith... | [
{
"answer_id": 316258,
"author": "Marc Charbonneau",
"author_id": 35136,
"author_profile": "https://Stackoverflow.com/users/35136",
"pm_score": 8,
"selected": true,
"text": "<p>It depends on what you're doing with the image. The <code>imageNamed:</code> method does cache the image, but i... | 2008/11/25 | [
"https://Stackoverflow.com/questions/316236",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6044/"
] | I want to load some images into my application from the file system. There's 2 easy ways to do this:
```
[UIImage imageNamed:fullFileName]
```
or:
```
NSString *fileLocation = [[NSBundle mainBundle] pathForResource:fileName ofType:extension];
NSData *imageData = [NSData dataWithContentsOfFile:fileLocation];
[UIIma... | It depends on what you're doing with the image. The `imageNamed:` method does cache the image, but in many cases that's going to help with memory use. For example, if you load an image 10 times to display along with some text in a table view, UIImage will only keep a single representation of that image in memory instea... |
316,238 | <p>Python Decimal doesn't support being constructed from float; it expects that you have to convert float to a string first.</p>
<p>This is very inconvenient since standard string formatters for float require that you specify number of decimal places rather than significant places. So if you have a number that could h... | [
{
"answer_id": 316248,
"author": "Federico A. Ramponi",
"author_id": 18770,
"author_profile": "https://Stackoverflow.com/users/18770",
"pm_score": 2,
"selected": false,
"text": "<p>The \"official\" string representation of a float is given by the repr() built-in:</p>\n\n<pre><code>>&g... | 2008/11/25 | [
"https://Stackoverflow.com/questions/316238",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/52490/"
] | Python Decimal doesn't support being constructed from float; it expects that you have to convert float to a string first.
This is very inconvenient since standard string formatters for float require that you specify number of decimal places rather than significant places. So if you have a number that could have as man... | ### Python <2.7
```
"%.15g" % f
```
Or in Python 3.0:
```
format(f, ".15g")
```
### Python 2.7+, 3.2+
Just pass the float to `Decimal` constructor directly, like this:
```
from decimal import Decimal
Decimal(f)
``` |
316,265 | <p><strong>How can you make the experience with Eclipse faster?</strong> </p>
<p>For instance: <em>I disable all the plugins I don't need (Mylyn, Subclipse, …).</em></p>
<p>Instead of using a plugin for <a href="http://en.wikipedia.org/wiki/Mercurial" rel="noreferrer">Mercurial</a>, I configure <a href="https... | [
{
"answer_id": 316270,
"author": "Tim Howland",
"author_id": 4276,
"author_profile": "https://Stackoverflow.com/users/4276",
"pm_score": 5,
"selected": false,
"text": "<p>I give it a ton of memory (add a <code>-Xmx</code> switch to the command that starts it) and try to avoid quitting an... | 2008/11/25 | [
"https://Stackoverflow.com/questions/316265",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1356709/"
] | **How can you make the experience with Eclipse faster?**
For instance: *I disable all the plugins I don't need (Mylyn, Subclipse, …).*
Instead of using a plugin for [Mercurial](http://en.wikipedia.org/wiki/Mercurial), I configure [TortoiseHG](https://en.wikipedia.org/wiki/TortoiseHg) as an external tool. | The three most influential factors for Eclipse speed are:
* Using the **latest version of Eclipse** (2020-06 as on 26 June 2020)
Note that [David Balažic](https://stackoverflow.com/users/822870/david-bala%C5%BEic)'s [comment](https://stackoverflow.com/questions/316265/how-can-you-speed-up-eclipse/316535#comment3865... |
316,267 | <p>I'm storing a tree in a DB using nested sets. The table's fields are id, lft, rgt, and name. </p>
<p>Given a node ID, I need to find all of its direct children(not grandchildren) that are themselves leaf nodes.</p>
| [
{
"answer_id": 316280,
"author": "nickf",
"author_id": 9021,
"author_profile": "https://Stackoverflow.com/users/9021",
"pm_score": 3,
"selected": false,
"text": "<p>The article <a href=\"http://mikehillyer.com/articles/managing-hierarchical-data-in-mysql/\" rel=\"nofollow noreferrer\">Ma... | 2008/11/25 | [
"https://Stackoverflow.com/questions/316267",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | I'm storing a tree in a DB using nested sets. The table's fields are id, lft, rgt, and name.
Given a node ID, I need to find all of its direct children(not grandchildren) that are themselves leaf nodes. | The article [Managing Hierarchical Data in MySQL](http://mikehillyer.com/articles/managing-hierarchical-data-in-mysql/) gives a great example of how to use Nested Sets, and gives examples of many common queries, including this one.
here's how to find the immediate children of a node:
```
SELECT node.name, (COUNT(pare... |
316,278 | <p>I am trying to have an element fade in, then in 5000 ms fade back out again. I know I can do something like:</p>
<pre><code>setTimeout(function () { $(".notice").fadeOut(); }, 5000);
</code></pre>
<p>But that will only control the fade out, would I add the above on the callback?</p>
| [
{
"answer_id": 316281,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 5,
"selected": false,
"text": "<p>I just figured it out below:</p>\n\n<pre><code>$(\".notice\")\n .fadeIn( function() \n {\n setTimeout( function()\... | 2008/11/25 | [
"https://Stackoverflow.com/questions/316278",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | I am trying to have an element fade in, then in 5000 ms fade back out again. I know I can do something like:
```
setTimeout(function () { $(".notice").fadeOut(); }, 5000);
```
But that will only control the fade out, would I add the above on the callback? | **Update:** As of jQuery 1.4 you can use the `.delay( n )` method. <http://api.jquery.com/delay/>
```
$('.notice').fadeIn().delay(2000).fadeOut('slow');
```
**Note**: `$.show()` and `$.hide()` by default are not queued, so if you want to use `$.delay()` with them, you need to configure them that way:
```
$('.notic... |
316,285 | <p>I have long considered the design of a database that involves shared table purposes to be somewhat a trait of smelly code, and progressively increasing proliferation of smelly-code related problems.</p>
<p>By this I mean, people over-normalizing, using 1 table where 2 tables could be more logical, people who've jus... | [
{
"answer_id": 316314,
"author": "tvanfosson",
"author_id": 12950,
"author_profile": "https://Stackoverflow.com/users/12950",
"pm_score": 2,
"selected": false,
"text": "<p>I think that from the perspective of SO, both questions and responses are the same thing -- user posts. They just h... | 2008/11/25 | [
"https://Stackoverflow.com/questions/316285",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15614/"
] | I have long considered the design of a database that involves shared table purposes to be somewhat a trait of smelly code, and progressively increasing proliferation of smelly-code related problems.
By this I mean, people over-normalizing, using 1 table where 2 tables could be more logical, people who've just discover... | I think that from the perspective of SO, both questions and responses are the same thing -- user posts. They just happen to be related. If a post has no parent, then it's a question. If a post does have a parent, then it's an answer. I find this perfectly reasonable though I'm not sure I would make the same choice sinc... |
316,294 | <pre><code>class A
def initialize
@x = do_something
end
def do_something
42
end
end
</code></pre>
<p>How can I stub <code>do_something</code> in rspec, before the original implementation is called (thus assigning 42 to <code>@x</code>)? And without changing the implementation, of course.</p>
| [
{
"answer_id": 316318,
"author": "Dustin",
"author_id": 39975,
"author_profile": "https://Stackoverflow.com/users/39975",
"pm_score": 4,
"selected": false,
"text": "<p>I don't know how to do that in spec's mock framework, but you can easily swap it out for mocha to do the following:</p>\... | 2008/11/25 | [
"https://Stackoverflow.com/questions/316294",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16882/"
] | ```
class A
def initialize
@x = do_something
end
def do_something
42
end
end
```
How can I stub `do_something` in rspec, before the original implementation is called (thus assigning 42 to `@x`)? And without changing the implementation, of course. | [Here's the commit which adds the feature to rspec](http://github.com/dchelimsky/rspec/commit/45a68378bf0cde18a5cc3ec64c93388a392f514a#diff-0) - This was on May 25 2008. With this you can do
```
A.any_instance.stub(do_something: 23)
```
However, the latest gem version of rspec (1.1.11, October 2008) doesn't have th... |
316,295 | <p>I have a function that exports a table to CSV and in the query I set which fields will export.</p>
<p>Here is the query:</p>
<pre><code>SELECT lname, fname, email, address1, address2, city,
state, zip, venue_id, dtelephone, etelephone, tshirt FROM volunteers_2009
</code></pre>
<p>The field venue_id is the the id... | [
{
"answer_id": 316303,
"author": "paxdiablo",
"author_id": 14860,
"author_profile": "https://Stackoverflow.com/users/14860",
"pm_score": 0,
"selected": false,
"text": "<p>Standard SQL query for this is (assuming you want both ID and name for the venue):</p>\n\n<pre><code>SELECT a.lname a... | 2008/11/25 | [
"https://Stackoverflow.com/questions/316295",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/26130/"
] | I have a function that exports a table to CSV and in the query I set which fields will export.
Here is the query:
```
SELECT lname, fname, email, address1, address2, city,
state, zip, venue_id, dtelephone, etelephone, tshirt FROM volunteers_2009
```
The field venue\_id is the the id of the venue which is referred ... | ```
SELECT a.lname, a.fname,a. email, a.address1,a. address2, a.city,
a.state, a.zip, a.venue_id, a.dtelephone, a.etelephone, a.tshirt,
COALESCE(b.venue_name,'') AS VenueName
FROM volunteers_2009 a
LEFT JOIN venues b ON b.id=a.venue_id
``` |
316,312 | <p>From the help for the Overflow Error in VBA, there's the following examples:</p>
<pre><code>Dim x As Long
x = 2000 * 365 ' gives an error
Dim x As Long
x = CLng(2000) * 365 ' fine
</code></pre>
<p>I would have thought that, since the Long data type is supposed to be able to hold 32-bit numbers, that the first exa... | [
{
"answer_id": 316331,
"author": "Robert Gamble",
"author_id": 25222,
"author_profile": "https://Stackoverflow.com/users/25222",
"pm_score": 5,
"selected": true,
"text": "<p>2000 and 365 are Integer values. In VBA, Integers are 16-bit signed types, when you perform arithmetic on 2 integ... | 2008/11/25 | [
"https://Stackoverflow.com/questions/316312",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10439/"
] | From the help for the Overflow Error in VBA, there's the following examples:
```
Dim x As Long
x = 2000 * 365 ' gives an error
Dim x As Long
x = CLng(2000) * 365 ' fine
```
I would have thought that, since the Long data type is supposed to be able to hold 32-bit numbers, that the first example would work fine.
I a... | 2000 and 365 are Integer values. In VBA, Integers are 16-bit signed types, when you perform arithmetic on 2 integers the arithmetic is carried out in 16-bits. Since the result of multiplying these two numbers exceeds the value that can be represented with 16 bits you get an exception. The second example works because t... |
316,315 | <p>Is it possible to determine whether a particular youtube video is encoded with H.264 or FLV through the YouTube data API? If so, how? </p>
<p>I can start a file download and check how the video stream was encoded (programmatically, of course), but I'd like to use the YouTube data API to avoid all that overhead.</p>... | [
{
"answer_id": 316331,
"author": "Robert Gamble",
"author_id": 25222,
"author_profile": "https://Stackoverflow.com/users/25222",
"pm_score": 5,
"selected": true,
"text": "<p>2000 and 365 are Integer values. In VBA, Integers are 16-bit signed types, when you perform arithmetic on 2 integ... | 2008/11/25 | [
"https://Stackoverflow.com/questions/316315",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/25164/"
] | Is it possible to determine whether a particular youtube video is encoded with H.264 or FLV through the YouTube data API? If so, how?
I can start a file download and check how the video stream was encoded (programmatically, of course), but I'd like to use the YouTube data API to avoid all that overhead. | 2000 and 365 are Integer values. In VBA, Integers are 16-bit signed types, when you perform arithmetic on 2 integers the arithmetic is carried out in 16-bits. Since the result of multiplying these two numbers exceeds the value that can be represented with 16 bits you get an exception. The second example works because t... |
316,320 | <p>I ran into this bug where an element of an array, if its index is the string "0", is inaccessible. </p>
<p>It's not a bug with unserialize, either, as this occurred in my code without invoking it.</p>
<pre><code>$arr = unserialize('a:1:{s:1:"0";i:5;}');
var_dump($arr["0"]); //should be 5, but is NULL
var_dump($arr... | [
{
"answer_id": 316336,
"author": "Draemon",
"author_id": 26334,
"author_profile": "https://Stackoverflow.com/users/26334",
"pm_score": 0,
"selected": false,
"text": "<p>Actually, the code in your question yields</p>\n\n<pre><code>int(5)\n</code></pre>\n"
},
{
"answer_id": 316342,... | 2008/11/25 | [
"https://Stackoverflow.com/questions/316320",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | I ran into this bug where an element of an array, if its index is the string "0", is inaccessible.
It's not a bug with unserialize, either, as this occurred in my code without invoking it.
```
$arr = unserialize('a:1:{s:1:"0";i:5;}');
var_dump($arr["0"]); //should be 5, but is NULL
var_dump($arr[0]); //maybe this ... | Yes, it looks as though it is a bug, related to PHPs automatic conversion of strings to integers. More information is available here: <http://bugs.php.net/bug.php?id=43614>
```
var_dump( $arr ); // => array(1) { ["0"]=> int(5) }
$arr2["0"]=5;
var_dump($arr2); // => array(1) { [0]=> int(5) }
print serialize($arr2);... |
316,325 | <p>I downloaded and installed this version of <a href="http://en.wikipedia.org/wiki/WxPython" rel="nofollow noreferrer">wxPython</a> for use with my Python 2.6 installation:</p>
<p><a href="http://downloads.sourceforge.net/wxpython/wxPython2.8-win32-unicode-2.8.9.1-py26.exe" rel="nofollow noreferrer">http://downloads.... | [
{
"answer_id": 316466,
"author": "Brian C. Lane",
"author_id": 27461,
"author_profile": "https://Stackoverflow.com/users/27461",
"pm_score": 1,
"selected": false,
"text": "<p>Try the ANSI version instead of the Unicode one. IIRC it needs to match the Python 2.6 install to work properly.<... | 2008/11/25 | [
"https://Stackoverflow.com/questions/316325",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/40495/"
] | I downloaded and installed this version of [wxPython](http://en.wikipedia.org/wiki/WxPython) for use with my Python 2.6 installation:
<http://downloads.sourceforge.net/wxpython/wxPython2.8-win32-unicode-2.8.9.1-py26.exe>
When I run Python and try to import wx, I get the following error:
```
C:\Program Files\Console2... | I was getting the same error.
After some googling found this link to [MSVC++ 2008 Redestributable](http://www.microsoft.com/downloads/details.aspx?familyid=9B2DA534-3E03-4391-8A4D-074B9F2BC1BF&displaylang=en) and installed it.
That solved the problem. |
316,341 | <p>Hopefully this is a really quick one ;) I have written a lexer / parser specification in ANTLR3, and am targeting the CSharp2 target. The generated code works correctly, but I can't get ANTLR to put the C# output into a namespace.</p>
<p>The relevant section of the Grammar file is as follows:</p>
<pre><code>gram... | [
{
"answer_id": 316858,
"author": "Fionn",
"author_id": 21566,
"author_profile": "https://Stackoverflow.com/users/21566",
"pm_score": 4,
"selected": true,
"text": "<p>I use this for a combined lexer and parser (and it generates the namespace correctly):</p>\n\n<pre><code>grammar Test;\n\n... | 2008/11/25 | [
"https://Stackoverflow.com/questions/316341",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/691/"
] | Hopefully this is a really quick one ;) I have written a lexer / parser specification in ANTLR3, and am targeting the CSharp2 target. The generated code works correctly, but I can't get ANTLR to put the C# output into a namespace.
The relevant section of the Grammar file is as follows:
```
grammar MyGrammar;
options... | I use this for a combined lexer and parser (and it generates the namespace correctly):
```
grammar Test;
options
{
language=CSharp2;
}
@lexer::namespace {
My.Name.Space
}
@parser::namespace {
My.Name.Space
}
DIGIT : '0'..'9';
simple : DIGIT EOF;
```
So i wonder why your version didn't work -... |
316,352 | <p>In Java, you can qualify local variables and method parameters with the final keyword.</p>
<pre><code>public static void foo(final int x) {
final String qwerty = "bar";
}
</code></pre>
<p>Doing so results in not being able to reassign x and qwerty in the body of the method.</p>
<p>This practice nudges your cod... | [
{
"answer_id": 316357,
"author": "SCdF",
"author_id": 1666,
"author_profile": "https://Stackoverflow.com/users/1666",
"pm_score": 5,
"selected": false,
"text": "<p>My personal opinion is that it is a waste of time. I believe that the visual clutter and added verbosity is not worth it.</p... | 2008/11/25 | [
"https://Stackoverflow.com/questions/316352",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/32174/"
] | In Java, you can qualify local variables and method parameters with the final keyword.
```
public static void foo(final int x) {
final String qwerty = "bar";
}
```
Doing so results in not being able to reassign x and qwerty in the body of the method.
This practice nudges your code in the direction of immutabilit... | You should try to do this, whenever it is appropriate. Besides serving to warn you when you "accidentally" try to modify a value, it provides information to the compiler that can lead to better optimization of the class file. This is one of the points in the book, "Hardcore Java" by Robert Simmons, Jr. In fact, the boo... |
316,367 | <p>In a comment on a previous question, someone said that the following sql statement opens me up to sql injection:</p>
<pre><code>select
ss.*,
se.name as engine,
ss.last_run_at + interval ss.refresh_frequency day as next_run_at,
se.logo_name
from
searches ss join search_engines se on ss.engin... | [
{
"answer_id": 316372,
"author": "Vinko Vrsalovic",
"author_id": 5190,
"author_profile": "https://Stackoverflow.com/users/5190",
"pm_score": 4,
"selected": true,
"text": "<p>Assuming it is properly escaped, it doesn't make you vulnerable. The thing is that escaping properly is harder tha... | 2008/11/25 | [
"https://Stackoverflow.com/questions/316367",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/39539/"
] | In a comment on a previous question, someone said that the following sql statement opens me up to sql injection:
```
select
ss.*,
se.name as engine,
ss.last_run_at + interval ss.refresh_frequency day as next_run_at,
se.logo_name
from
searches ss join search_engines se on ss.engine_id = se.id
w... | Assuming it is properly escaped, it doesn't make you vulnerable. The thing is that escaping properly is harder than it looks at first sight, and you condemn yourself to escape properly every time you do a query like that. If possible, avoid all that trouble and use prepared statements (or binded parameters or parameter... |
316,383 | <p>i need a C# library about strict HTML validation and filtering </p>
| [
{
"answer_id": 316372,
"author": "Vinko Vrsalovic",
"author_id": 5190,
"author_profile": "https://Stackoverflow.com/users/5190",
"pm_score": 4,
"selected": true,
"text": "<p>Assuming it is properly escaped, it doesn't make you vulnerable. The thing is that escaping properly is harder tha... | 2008/11/25 | [
"https://Stackoverflow.com/questions/316383",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/441493/"
] | i need a C# library about strict HTML validation and filtering | Assuming it is properly escaped, it doesn't make you vulnerable. The thing is that escaping properly is harder than it looks at first sight, and you condemn yourself to escape properly every time you do a query like that. If possible, avoid all that trouble and use prepared statements (or binded parameters or parameter... |
316,384 | <p>How do you go about checking that an IIS website is successfully using Kerberos and not falling back on NTLM?</p>
| [
{
"answer_id": 316402,
"author": "Alan",
"author_id": 37843,
"author_profile": "https://Stackoverflow.com/users/37843",
"pm_score": 2,
"selected": false,
"text": "<p>The easiest way that I can think of is to use wireshark to watch the network packets and verify that your IIS server is re... | 2008/11/25 | [
"https://Stackoverflow.com/questions/316384",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11829/"
] | How do you go about checking that an IIS website is successfully using Kerberos and not falling back on NTLM? | One way I found to test in code that you are using Kerberos is that that the HTTP\_AUTHORIZATION header for NTLM always starts with the following:
```
Negotiate TlRMTVNTUA
```
If the header doesn't start with text then the browser is authenticating using Kerberos. |
316,409 | <p>I'm trying out PHPTAL and I want to render a table with zebra stripes. I'm looping through a simple php assoc array ($_SERVER).</p>
<p>Note that I don't want to use jQuery or anything like that, I'm trying to learn PHPTAL usage!</p>
<p>Currently I have it working like this (too verbose for my liking):</p>
<pre><c... | [
{
"answer_id": 316420,
"author": "starmonkey",
"author_id": 29854,
"author_profile": "https://Stackoverflow.com/users/29854",
"pm_score": 2,
"selected": false,
"text": "<p>Well, it seems like I have my own answer, though I still think this is rather ugly:</p>\n\n<pre><code><tr tal:rep... | 2008/11/25 | [
"https://Stackoverflow.com/questions/316409",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/29854/"
] | I'm trying out PHPTAL and I want to render a table with zebra stripes. I'm looping through a simple php assoc array ($\_SERVER).
Note that I don't want to use jQuery or anything like that, I'm trying to learn PHPTAL usage!
Currently I have it working like this (too verbose for my liking):
```
<tr tal:repeat="item se... | You could create expression modifier by writing `phptal_tales_evenodd()` function (see `phptal_tales()` in manual):
```
<td tal:attributes="class evenodd:repeat/item/odd">
``` |
316,422 | <p>I've built a entity framework model against a 2008 database. All works ok against the 2008 database. When I try to update the entity on a 2005 database I get this error. </p>
<pre>The version of SQL Server in use does not support datatype 'datetime2</pre>
<p>I specifically did not use any 2008 features when I b... | [
{
"answer_id": 316506,
"author": "Richard Harrison",
"author_id": 19624,
"author_profile": "https://Stackoverflow.com/users/19624",
"pm_score": 9,
"selected": true,
"text": "<p>A quick google points me to what looks like the <a href=\"http://alexduggleby.com/2008/08/11/entity-data-model-... | 2008/11/25 | [
"https://Stackoverflow.com/questions/316422",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1351/"
] | I've built a entity framework model against a 2008 database. All works ok against the 2008 database. When I try to update the entity on a 2005 database I get this error.
```
The version of SQL Server in use does not support datatype 'datetime2
```
I specifically did not use any 2008 features when I built the databas... | A quick google points me to what looks like the [solution](http://alexduggleby.com/2008/08/11/entity-data-model-generated-against-sql-2008-used-against-sql-2005/).
Open your EDMX in a file editor (or “open with…” in Visual Studio and select XML Editor). At the top you will find the storage model and it has an attribut... |
316,454 | <p>My current problem is that I have a JFrame with a 2x2 GridLayout. And inside one of the squares, I have a JPanel that is to display a grid. I am having a field day with the java swing library... take a look</p>
<p><a href="http://img114.imageshack.us/img114/9683/frameow2.jpg" rel="nofollow noreferrer">Image</a></p>... | [
{
"answer_id": 316460,
"author": "javamonkey79",
"author_id": 27657,
"author_profile": "https://Stackoverflow.com/users/27657",
"pm_score": 1,
"selected": false,
"text": "<p>If you can <code>setResizeable( false )</code> on the top level frame you can then set your layout manager to null... | 2008/11/25 | [
"https://Stackoverflow.com/questions/316454",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/29326/"
] | My current problem is that I have a JFrame with a 2x2 GridLayout. And inside one of the squares, I have a JPanel that is to display a grid. I am having a field day with the java swing library... take a look
[Image](http://img114.imageshack.us/img114/9683/frameow2.jpg)
Java is automatically expanding each JLabel to fi... | If you want the two checkerboards to stay the same size, then you'll need to have them each contained in their own `JPanel`. Set each of those parent JPanel's to have a layout type of `GridBagLayout`. Set the preferedSize for each checkerboard component and then add them to their respective containers. GridBagLayout sh... |
316,463 | <p>How would I go upon detecting input for a console application in C#?</p>
<p>Let's say for example I want the console application to start up by writing:
Welcome To Food Hut
(cursor to type stuff here after the first line)</p>
<p>I would want the console application to detect two commands:</p>
<p>1: /help - which ... | [
{
"answer_id": 316471,
"author": "Ana Betts",
"author_id": 5728,
"author_profile": "https://Stackoverflow.com/users/5728",
"pm_score": 0,
"selected": false,
"text": "<p>Look into String.Contains</p>\n"
},
{
"answer_id": 316482,
"author": "Juliet",
"author_id": 40516,
... | 2008/11/25 | [
"https://Stackoverflow.com/questions/316463",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | How would I go upon detecting input for a console application in C#?
Let's say for example I want the console application to start up by writing:
Welcome To Food Hut
(cursor to type stuff here after the first line)
I would want the console application to detect two commands:
1: /help - which will display some help g... | I recommend [Richard Lopes' Command Line Arguments Parser](http://www.codeproject.com/KB/recipes/command_line.aspx). It is powerful and very simple to use. Also, it accepts various ways of specifying the arguments, for example:
* /name=Stefan
* --name=Stefan
* --name="Multiple words"
* -name 'Stefan'
**Example Code:*... |
316,485 | <p>How can I rename a schema using SQL Server? </p>
| [
{
"answer_id": 316769,
"author": "Ray Lu",
"author_id": 11413,
"author_profile": "https://Stackoverflow.com/users/11413",
"pm_score": 5,
"selected": false,
"text": "<p>You move individual objects from one schema to another via:</p>\n\n<pre><code>ALTER SCHEMA NewSchema TRANSFER OldSchema.... | 2008/11/25 | [
"https://Stackoverflow.com/questions/316485",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | How can I rename a schema using SQL Server? | If you have a large number of objects in a schema, you can use something like this to generate all the changes automatically (it only does tables and views, so before you run it, you might need to expand it to SPs, UDFs, etc.)
```
USE SandBox
DECLARE @OldSchema AS varchar(255)
DECLARE @NewSchema AS varchar(255)
DECLA... |
316,486 | <p>I have been looking at using TDD and implementing proper testing (only just started to learn how much better it makes your life) in any of my projects that I create in the future. So for the last couple of days I have been floating around on SO trying to learn about how to design your application for testability, b... | [
{
"answer_id": 316497,
"author": "Robert Gould",
"author_id": 15124,
"author_profile": "https://Stackoverflow.com/users/15124",
"pm_score": 0,
"selected": false,
"text": "<p>You are right with the Mocking part, if you actually are doing what you said. </p>\n\n<p>As for the interfaces, my... | 2008/11/25 | [
"https://Stackoverflow.com/questions/316486",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6335/"
] | I have been looking at using TDD and implementing proper testing (only just started to learn how much better it makes your life) in any of my projects that I create in the future. So for the last couple of days I have been floating around on SO trying to learn about how to design your application for testability, but I... | I think you have the right idea, but I think you are making this into a bigger deal than it is. If you start doing TDD, your first reaction will probably be 'is this it?'. And then later, you should hopefully say 'aha'!
The main thing is that you get nUnit, learn the tutorial, and then make sure you write a test for e... |