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 |
|---|---|---|---|---|---|---|
310,247 | <p>Whenever I create a method signature in VS 2008 (C#), I type the two braces:</p>
<p>public void Something() {}</p>
<p>This leaves the cursor to the right of the closing brace. Then I have to use the arrow keys to reposition the cursor in between the braces. Is there a better way to do this without using the arro... | [
{
"answer_id": 310260,
"author": "Kent Boogaart",
"author_id": 5380,
"author_profile": "https://Stackoverflow.com/users/5380",
"pm_score": 2,
"selected": false,
"text": "<p>I believe Resharper does this. Not sure if there is a free option.</p>\n"
},
{
"answer_id": 310280,
"au... | 2008/11/21 | [
"https://Stackoverflow.com/questions/310247",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | Whenever I create a method signature in VS 2008 (C#), I type the two braces:
public void Something() {}
This leaves the cursor to the right of the closing brace. Then I have to use the arrow keys to reposition the cursor in between the braces. Is there a better way to do this without using the arrow keys?
I'd expect... | I don't have vs2008 at the moment. Assuming VS2008 still supports this, you could use code snippets. Mess with below til you get what you need. (See Tools|Code Snippets Manager)
```xml
<?xml version="1.0" encoding="utf-8" ?>
<CodeSnippets xmlns="http://schemas.microsoft.com/VisualStudio/2005/CodeSnippet">
<CodeSn... |
310,271 | <p>I'm an end-user of one of my company's products. It is not very suitable for integration into Spring, however I am able to get a handle on the context and retrieve the required bean by name. However, I would still like to know if it was possible to inject a bean into this class, even though the class is not managed... | [
{
"answer_id": 312367,
"author": "Yonatan Maman",
"author_id": 20065,
"author_profile": "https://Stackoverflow.com/users/20065",
"pm_score": 2,
"selected": false,
"text": "<p>suppose that u have the following dependency chain:</p>\n\n<p>A --> B --> C --> x --> y -- > Z</p>\n\n<p>A, B, C ... | 2008/11/21 | [
"https://Stackoverflow.com/questions/310271",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8528/"
] | I'm an end-user of one of my company's products. It is not very suitable for integration into Spring, however I am able to get a handle on the context and retrieve the required bean by name. However, I would still like to know if it was possible to inject a bean into this class, even though the class is not managed by ... | You can do this:
```
ApplicationContext ctx = ...
YourClass someBeanNotCreatedBySpring = ...
ctx.getAutowireCapableBeanFactory().autowireBeanProperties(
someBeanNotCreatedBySpring,
AutowireCapableBeanFactory.AUTOWIRE_AUTODETECT, true);
```
You can use `@Autowired` and so on within `YourClass` to specify fiel... |
310,294 | <p>I'm using a regex that <a href="http://regexlib.com/REDetails.aspx?regexp_id=646" rel="nofollow noreferrer">strips the href tags out of an html doc</a> saved to a string. The following code is how I'm using it in my C# console app.</p>
<pre><code>Match m = Regex.Match(htmlSourceString, "href=[\\\"\\\'](http:\\/\\/|... | [
{
"answer_id": 310317,
"author": "arul",
"author_id": 15409,
"author_profile": "https://Stackoverflow.com/users/15409",
"pm_score": 4,
"selected": false,
"text": "<p><strong>Match</strong> method searches for the first occurence of the string, <strong>Matches</strong> method searches for... | 2008/11/21 | [
"https://Stackoverflow.com/questions/310294",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/557/"
] | I'm using a regex that [strips the href tags out of an html doc](http://regexlib.com/REDetails.aspx?regexp_id=646) saved to a string. The following code is how I'm using it in my C# console app.
```
Match m = Regex.Match(htmlSourceString, "href=[\\\"\\\'](http:\\/\\/|\\.\\/|\\/)?\\w+(\\.\\w+)*(\\/\\w+(\\.\\w+)?)*(\\/|... | If you use Match instead of Match**es** you need to use a loop to get all the matches calling m.NextMatch() at the end of each loop. For example:
```
Match m = Regex.Match(htmlSourceString, "href=[\\\"\\\'](http:\\/\\/|\\.\\/|\\/)?\\w+(\\.\\w+)*(\\/\\w+(\\.\\w+)?)*(\\/|\\?\\w*=\\w*(&\\w*=\\w*)*)?[\\\"\\\']");
... |
310,333 | <p>What's wrong with the following snippet ?</p>
<pre><code>#include <tr1/functional>
#include <functional>
#include <iostream>
using namespace std::tr1::placeholders;
struct abc
{
typedef void result_type;
void hello(int)
{ std::cout << __PRETTY_FUNCTION__ << std::endl; }
... | [
{
"answer_id": 310364,
"author": "John Zwinck",
"author_id": 4323,
"author_profile": "https://Stackoverflow.com/users/4323",
"pm_score": 3,
"selected": true,
"text": "<p>The lookup is done at a time when the constness of <code>this</code> is not known. You just have to give it a hint vi... | 2008/11/21 | [
"https://Stackoverflow.com/questions/310333",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19630/"
] | What's wrong with the following snippet ?
```
#include <tr1/functional>
#include <functional>
#include <iostream>
using namespace std::tr1::placeholders;
struct abc
{
typedef void result_type;
void hello(int)
{ std::cout << __PRETTY_FUNCTION__ << std::endl; }
void hello(int) const
{ std::cout <... | The lookup is done at a time when the constness of `this` is not known. You just have to give it a hint via casting. Try this:
```
typedef void (abc::*fptr)(int) const; // or remove const
std::tr1::bind((fptr)&abc::hello, x , _1)(a);
```
You may also notice here that removing the `const` still works. This is because... |
310,342 | <p>A quick search gave me this <a href="http://www.mail-archive.com/dbdi-dev@perl.org/msg00002.html" rel="nofollow noreferrer">announcement of Parrot DBDI</a> from January 2004 and a <a href="http://www.mail-archive.com/dbdi-dev@perl.org/" rel="nofollow noreferrer">dbdi-dev mailing list</a> which appears to be long dea... | [
{
"answer_id": 310364,
"author": "John Zwinck",
"author_id": 4323,
"author_profile": "https://Stackoverflow.com/users/4323",
"pm_score": 3,
"selected": true,
"text": "<p>The lookup is done at a time when the constness of <code>this</code> is not known. You just have to give it a hint vi... | 2008/11/21 | [
"https://Stackoverflow.com/questions/310342",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/311/"
] | A quick search gave me this [announcement of Parrot DBDI](http://www.mail-archive.com/dbdi-dev@perl.org/msg00002.html) from January 2004 and a [dbdi-dev mailing list](http://www.mail-archive.com/dbdi-dev@perl.org/) which appears to be long dead. Is Parrot DBDI still being developed? Is anyone working on a different dat... | The lookup is done at a time when the constness of `this` is not known. You just have to give it a hint via casting. Try this:
```
typedef void (abc::*fptr)(int) const; // or remove const
std::tr1::bind((fptr)&abc::hello, x , _1)(a);
```
You may also notice here that removing the `const` still works. This is because... |
310,363 | <p>I have a time represented as the number of seconds elapsed since midnight, January 1, 1970, UTC (the results of an earlier call to time()). How do I add one day to this time?</p>
<p>Adding 24 * 60 * 60 works in most cases, but fails if the daylight saving time comes on or off in between. In other words, I mostly wa... | [
{
"answer_id": 310372,
"author": "Toon Krijthe",
"author_id": 18061,
"author_profile": "https://Stackoverflow.com/users/18061",
"pm_score": 2,
"selected": false,
"text": "<p>I always had the best result with keeping the timestamps UTC and convert them to the specified timezone (including... | 2008/11/21 | [
"https://Stackoverflow.com/questions/310363",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13029/"
] | I have a time represented as the number of seconds elapsed since midnight, January 1, 1970, UTC (the results of an earlier call to time()). How do I add one day to this time?
Adding 24 \* 60 \* 60 works in most cases, but fails if the daylight saving time comes on or off in between. In other words, I mostly want to ad... | use *gmtime()* to convert the *time\_t* to a *struct tm*
add one to the day (*tm\_mday*)
use *mktime()* to convert the *struct tm* back to a *time\_t*
see [time.h](http://www.cplusplus.com/reference/clibrary/ctime/) for more info
Edit:
I just tried it, this works:
```
int main()
{
time_t base = 1142085600;
fo... |
310,408 | <p>Let's say we have a concrete <code>class Apple</code>. (Apple objects can be instantiated.)
Now, someone comes and derives an abstract <code>class Peach</code> from Apple. It's abstract because it introduces a new pure virtual function. The user of Peach is now forced to derive from it and define this new function. ... | [
{
"answer_id": 310417,
"author": "Bill K",
"author_id": 12943,
"author_profile": "https://Stackoverflow.com/users/12943",
"pm_score": 3,
"selected": false,
"text": "<p>It would seem to me like an indication of a bad design. Could be forced if you wanted to take a concrete definition fro... | 2008/11/21 | [
"https://Stackoverflow.com/questions/310408",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/22724/"
] | Let's say we have a concrete `class Apple`. (Apple objects can be instantiated.)
Now, someone comes and derives an abstract `class Peach` from Apple. It's abstract because it introduces a new pure virtual function. The user of Peach is now forced to derive from it and define this new function. Is this a common pattern?... | Re Peach from Apple:
* Don't do it if Apple is a value class
(i.e. has copy ctor, non-identical
instances can be equal, etc). See Meyers
More Effective C++ Item 33 for why.
* Don't do it if Apple has a public
nonvirtual destructor, otherwise you
invite undefined behaviour when your
users delete an Apple through a
poi... |
310,425 | <p>Currently I have a table that I search upon 4 fields, FirstName, LastName, MiddleName, And AKA's. I currently have a <strong>CONTAINSTABLE</strong> search for the rows and it works. Not well but it works. Now <strong>I want to make the First Name weighted higher and middle name lower.</strong></p>
<p>I found the co... | [
{
"answer_id": 322191,
"author": "Dave_H",
"author_id": 17109,
"author_profile": "https://Stackoverflow.com/users/17109",
"pm_score": 4,
"selected": true,
"text": "<p>The key to manipulating the rankings is to use a union. For each column you use a separate select statement. In that st... | 2008/11/21 | [
"https://Stackoverflow.com/questions/310425",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1925/"
] | Currently I have a table that I search upon 4 fields, FirstName, LastName, MiddleName, And AKA's. I currently have a **CONTAINSTABLE** search for the rows and it works. Not well but it works. Now **I want to make the First Name weighted higher and middle name lower.**
I found the command **ISABOUT** but that seems pre... | The key to manipulating the rankings is to use a union. For each column you use a separate select statement. In that statement, add an identifier that shows from which column each row was pulled then. Insert the results into a table variable, then you can manipulate the ranking by sorting on the identifier or multiplyi... |
310,426 | <p>To do the equivalent of Python list comprehensions, I'm doing the following:</p>
<pre><code>some_array.select{|x| x % 2 == 0 }.collect{|x| x * 3}
</code></pre>
<p>Is there a better way to do this...perhaps with one method call?</p>
| [
{
"answer_id": 310466,
"author": "Robert Gamble",
"author_id": 25222,
"author_profile": "https://Stackoverflow.com/users/25222",
"pm_score": 7,
"selected": true,
"text": "<p>If you really want to, you can create an Array#comprehend method like this:</p>\n\n<pre><code>class Array\n def c... | 2008/11/21 | [
"https://Stackoverflow.com/questions/310426",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4883/"
] | To do the equivalent of Python list comprehensions, I'm doing the following:
```
some_array.select{|x| x % 2 == 0 }.collect{|x| x * 3}
```
Is there a better way to do this...perhaps with one method call? | If you really want to, you can create an Array#comprehend method like this:
```
class Array
def comprehend(&block)
return self if block.nil?
self.collect(&block).compact
end
end
some_array = [1, 2, 3, 4, 5, 6]
new_array = some_array.comprehend {|x| x * 3 if x % 2 == 0}
puts new_array
```
Prints:
```
6
... |
310,458 | <p>In ASP.NET (not MVC), what is the best approach to programmatically setting styles on an unordered list used for navigation so the appropriate menu item is styled as the active item if that page is being viewed? </p>
<p>This would most likely be used in conjunction with a MasterPage.</p>
| [
{
"answer_id": 310477,
"author": "Frank V",
"author_id": 18196,
"author_profile": "https://Stackoverflow.com/users/18196",
"pm_score": 2,
"selected": true,
"text": "<p>The answer to your question depends a lot on how you have your list implemented {User control or not, etc}. How I would... | 2008/11/21 | [
"https://Stackoverflow.com/questions/310458",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/30552/"
] | In ASP.NET (not MVC), what is the best approach to programmatically setting styles on an unordered list used for navigation so the appropriate menu item is styled as the active item if that page is being viewed?
This would most likely be used in conjunction with a MasterPage. | The answer to your question depends a lot on how you have your list implemented {User control or not, etc}. How I would do it, is implement the list to be generated by a user control.
I'd have the UserControl tag each element with something like:
```
<{...} class="GeneratedMenuItem"> {...}
```
And I'd have the app... |
310,459 | <p>I'm trying to transform each element of a numpy array into an array itself (say, to interpret a greyscale image as a color image). In other words:</p>
<pre><code>>>> my_ar = numpy.array((0,5,10))
[0, 5, 10]
>>> transformed = my_fun(my_ar) # In reality, my_fun() would do something more useful
arra... | [
{
"answer_id": 310493,
"author": "Piotr Lesnicki",
"author_id": 38796,
"author_profile": "https://Stackoverflow.com/users/38796",
"pm_score": 1,
"selected": false,
"text": "<p>I propose:</p>\n\n<pre><code> numpy.resize(my_ar, (3,3)).transpose()\n</code></pre>\n\n<p>You can of course adap... | 2008/11/21 | [
"https://Stackoverflow.com/questions/310459",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12779/"
] | I'm trying to transform each element of a numpy array into an array itself (say, to interpret a greyscale image as a color image). In other words:
```
>>> my_ar = numpy.array((0,5,10))
[0, 5, 10]
>>> transformed = my_fun(my_ar) # In reality, my_fun() would do something more useful
array([
[ 0, 0, 0],
[ ... | Use map to apply your transformation function to each element in my\_ar:
```
import numpy
my_ar = numpy.array((0,5,10))
print my_ar
transformed = numpy.array(map(lambda x:numpy.array((x,x*2,x*3)), my_ar))
print transformed
print transformed.shape
``` |
310,469 | <p>I want a workflow that, when an entry is created in List A, will generate one entry in List B for each entry in List C. Is this possible? If so, how?</p>
| [
{
"answer_id": 310493,
"author": "Piotr Lesnicki",
"author_id": 38796,
"author_profile": "https://Stackoverflow.com/users/38796",
"pm_score": 1,
"selected": false,
"text": "<p>I propose:</p>\n\n<pre><code> numpy.resize(my_ar, (3,3)).transpose()\n</code></pre>\n\n<p>You can of course adap... | 2008/11/21 | [
"https://Stackoverflow.com/questions/310469",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | I want a workflow that, when an entry is created in List A, will generate one entry in List B for each entry in List C. Is this possible? If so, how? | Use map to apply your transformation function to each element in my\_ar:
```
import numpy
my_ar = numpy.array((0,5,10))
print my_ar
transformed = numpy.array(map(lambda x:numpy.array((x,x*2,x*3)), my_ar))
print transformed
print transformed.shape
``` |
310,479 | <p>I am developing a cocoa application that will be making heavy use of both web services and a standard dbms (most likely MySQL) and I am wondering if anyone has a good option for a database library or ORM solution they have used. CoreData is not an option due to the need to support a standard DBMS and to be able to ... | [
{
"answer_id": 310615,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 1,
"selected": false,
"text": "<p><a href=\"http://www.gnustep.org/resources/documentation/Developer/GDL2/GDL2.html\" rel=\"nofollow noreferrer\">GDL2</a> is... | 2008/11/21 | [
"https://Stackoverflow.com/questions/310479",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/39819/"
] | I am developing a cocoa application that will be making heavy use of both web services and a standard dbms (most likely MySQL) and I am wondering if anyone has a good option for a database library or ORM solution they have used. CoreData is not an option due to the need to support a standard DBMS and to be able to modi... | We faced a similar question when we first started work on [Checkout](http://checkoutapp.com), our solution was to code the entire app in Python, using PyObjC. Checkout 1 had an sqlite backend, Checkout 2 has a postgres backend.
There are a couple of really mature and powerful ORMs on the Pyton side, such as [SQLObjec... |
310,518 | <p>I'm digging into Reflection for the first time and I'm truely stuck. I've googled everything I can think of. I'm 90% where I wanna be now.</p>
<p>I'm trying to return the value of a Property in a custom class through Reflection.</p>
<p>Here's my class declaration:</p>
<pre><code>Public Class Class2
Private ne... | [
{
"answer_id": 310639,
"author": "tvanfosson",
"author_id": 12950,
"author_profile": "https://Stackoverflow.com/users/12950",
"pm_score": 5,
"selected": true,
"text": "<p><code>Me</code> refers to the <code>ObjectCompare</code> object, which is different than the class from which the <co... | 2008/11/21 | [
"https://Stackoverflow.com/questions/310518",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/38595/"
] | I'm digging into Reflection for the first time and I'm truely stuck. I've googled everything I can think of. I'm 90% where I wanna be now.
I'm trying to return the value of a Property in a custom class through Reflection.
Here's my class declaration:
```
Public Class Class2
Private newPropertyValue2 As String
... | `Me` refers to the `ObjectCompare` object, which is different than the class from which the `PropertyInfo` objects were derived (`Class2`). You need to also pass in an object of the type from which you retrieved the `PropertyInfo` objects.
```
Public Sub CompareObjects(ByVal It as Object)
Dim property_value As Obj... |
310,540 | <p>Are there any good references for best practices for storing postal addresses in an RDBMS? It seems there are lots of tradeoffs that can be made and lots of pros and cons to each to be evaluated -- surely this has been done time and time again? Maybe someone has at least written done some lessons learned somewhere... | [
{
"answer_id": 310570,
"author": "Jonathan Leffler",
"author_id": 15168,
"author_profile": "https://Stackoverflow.com/users/15168",
"pm_score": 3,
"selected": false,
"text": "<p>You should certainly consult \"<a href=\"https://stackoverflow.com/questions/307027\">Is this a good way to mo... | 2008/11/21 | [
"https://Stackoverflow.com/questions/310540",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2168/"
] | Are there any good references for best practices for storing postal addresses in an RDBMS? It seems there are lots of tradeoffs that can be made and lots of pros and cons to each to be evaluated -- surely this has been done time and time again? Maybe someone has at least written done some lessons learned somewhere?
Ex... | For more international use, one schema to consider is the one used by [Drupal Address Field](https://www.drupal.org/project/addressfield). It's based on the [xNAL standard](http://xml.coverpages.org/xnal.html), and seems to cover most international cases. A bit of digging into that module will reveal some nice pearls f... |
310,551 | <p>Omnicompletion is working, but it automatically inserts the first result.</p>
<p>What I'd like to do is open the omnicomplete menu, then be able to type to narrow down the results, then hit enter or tab or space or something to insert the selected menu item.</p>
<p>Is this possible?</p>
| [
{
"answer_id": 310560,
"author": "VonC",
"author_id": 6309,
"author_profile": "https://Stackoverflow.com/users/6309",
"pm_score": 0,
"selected": false,
"text": "<p>This plugin might do what you are after: <strong><a href=\"http://www.vim.org/scripts/script.php?script_id=1879\" rel=\"nofo... | 2008/11/21 | [
"https://Stackoverflow.com/questions/310551",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1367022/"
] | Omnicompletion is working, but it automatically inserts the first result.
What I'd like to do is open the omnicomplete menu, then be able to type to narrow down the results, then hit enter or tab or space or something to insert the selected menu item.
Is this possible? | The command you are looking for is:
```
:set completeopt+=longest
```
It will insert the longest common prefix of all the suggestions, then you can type and delete to narrow down or expand results. |
310,557 | <p>I am trying to declare and use a class B inside of a class A
and define B outside A.<br>
I know for a fact that this is possible because Bjarne Stroustrup<br>
uses this in his book "The C++ programming language"<br>
(page 293,for example the String and Srep classes).</p>
<p>So this is my minimal piece of code that ... | [
{
"answer_id": 310562,
"author": "CB Bailey",
"author_id": 19563,
"author_profile": "https://Stackoverflow.com/users/19563",
"pm_score": 4,
"selected": false,
"text": "<p>The expression <code>c->i</code> dereferences the pointer to <code>struct A::B</code> so a full definition must be... | 2008/11/21 | [
"https://Stackoverflow.com/questions/310557",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/34051/"
] | I am trying to declare and use a class B inside of a class A
and define B outside A.
I know for a fact that this is possible because Bjarne Stroustrup
uses this in his book "The C++ programming language"
(page 293,for example the String and Srep classes).
So this is my minimal piece of code that causes proble... | Define the constructor for A AFTER the definition of struct B. |
310,561 | <p>I'm looking at the MySQL docs <a href="http://dev.mysql.com/doc/refman/5.0/en/innodb-foreign-key-constraints.html" rel="noreferrer">here</a> and trying to sort out the distinction between FOREIGN KEYs and CONSTRAINTs. I thought an FK <strong>was</strong> a constraint, but the docs seem to talk about them like they'r... | [
{
"answer_id": 310573,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 1,
"selected": false,
"text": "<p>Can't answer for MySQL but FK's are constraints. Anything that forces your data into a certain condition is a constraint. T... | 2008/11/21 | [
"https://Stackoverflow.com/questions/310561",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | I'm looking at the MySQL docs [here](http://dev.mysql.com/doc/refman/5.0/en/innodb-foreign-key-constraints.html) and trying to sort out the distinction between FOREIGN KEYs and CONSTRAINTs. I thought an FK **was** a constraint, but the docs seem to talk about them like they're separate things.
The syntax for creating ... | Yes, a foreign key is a type of constraint. MySQL has uneven support for constraints:
* `PRIMARY KEY`: yes as table constraint and column constraint.
* `FOREIGN KEY`: yes as table constraint, but only with InnoDB and BDB storage engines; otherwise parsed but ignored.
* `CHECK`: parsed but ignored in all storage engine... |
310,576 | <p>What win32 calls can be used to detect key press events globally (not just for 1 window, I'd like to get a message EVERY time a key is pressed), from a windows service?</p>
| [
{
"answer_id": 310602,
"author": "Brian R. Bondy",
"author_id": 3153,
"author_profile": "https://Stackoverflow.com/users/3153",
"pm_score": 4,
"selected": true,
"text": "<p>You want to use Win32 Hooks. In particular a keyboard hook.</p>\n\n<p><a href=\"http://msdn.microsoft.com/en-us/li... | 2008/11/21 | [
"https://Stackoverflow.com/questions/310576",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3886/"
] | What win32 calls can be used to detect key press events globally (not just for 1 window, I'd like to get a message EVERY time a key is pressed), from a windows service? | You want to use Win32 Hooks. In particular a keyboard hook.
[You can read more about it here](http://msdn.microsoft.com/en-us/library/windows/desktop/ms644960(v=vs.85).aspx)
The type of hook you want is WH\_KEYBOARD and you can set it via the Win32 API SetWindowsHookEx.
Basically windows will call a function in a d... |
310,580 | <p>Is it possible to create a final route that catches all .. and bounces the user to a 404 view in ASP.NET MVC?</p>
<p>NOTE: I don't want to set this up in my IIS settings.</p>
| [
{
"answer_id": 310636,
"author": "Pure.Krome",
"author_id": 30674,
"author_profile": "https://Stackoverflow.com/users/30674",
"pm_score": 7,
"selected": true,
"text": "<p>Found the answer myself.</p>\n\n<p><a href=\"http://richarddingwall.name/2008/08/17/strategies-for-resource-based-404... | 2008/11/21 | [
"https://Stackoverflow.com/questions/310580",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/30674/"
] | Is it possible to create a final route that catches all .. and bounces the user to a 404 view in ASP.NET MVC?
NOTE: I don't want to set this up in my IIS settings. | Found the answer myself.
[Richard Dingwall](http://richarddingwall.name/2008/08/17/strategies-for-resource-based-404-errors-in-aspnet-mvc/ "Click to read Richard's MVC 404 strategies") has an excellent post going through various strategies. I particularly like the FilterAttribute solution. I'm not a fan of throwing ex... |
310,583 | <p>I'm sure there are different approaches to this problem, and I can think of some. But I'd like to hear other people's opinion on this. To be more specific I've built a widget that allows users to choose their location from a google maps map. This widget is displayed on demand and will probably be used every 1 out of... | [
{
"answer_id": 310588,
"author": "miceuz",
"author_id": 24443,
"author_profile": "https://Stackoverflow.com/users/24443",
"pm_score": -1,
"selected": false,
"text": "<p>you can load script dynamically by adding <code><script src=\"...\"></code> tag to DOM tree.</p>\n"
},
{
... | 2008/11/21 | [
"https://Stackoverflow.com/questions/310583",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7883/"
] | I'm sure there are different approaches to this problem, and I can think of some. But I'd like to hear other people's opinion on this. To be more specific I've built a widget that allows users to choose their location from a google maps map. This widget is displayed on demand and will probably be used every 1 out of 10... | ```
function loadJSInclude(scriptPath, callback)
{
var scriptNode = document.createElement('SCRIPT');
scriptNode.type = 'text/javascript';
scriptNode.src = scriptPath;
var headNode = document.getElementsByTagName('HEAD');
if (headNode[0] != null)
headNode[0].appendChild(scriptNode);
if... |
310,589 | <p>In our MOSS '07 site we have a page that contains just a Page Viewer web part in it that points to a site on another server. However, I've noticed that on that page (and any others that have a Page Viewer web part on it) our drop down menus and hover effects are <strong>super slow</strong> and completely max out th... | [
{
"answer_id": 310588,
"author": "miceuz",
"author_id": 24443,
"author_profile": "https://Stackoverflow.com/users/24443",
"pm_score": -1,
"selected": false,
"text": "<p>you can load script dynamically by adding <code><script src=\"...\"></code> tag to DOM tree.</p>\n"
},
{
... | 2008/11/22 | [
"https://Stackoverflow.com/questions/310589",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/30866/"
] | In our MOSS '07 site we have a page that contains just a Page Viewer web part in it that points to a site on another server. However, I've noticed that on that page (and any others that have a Page Viewer web part on it) our drop down menus and hover effects are **super slow** and completely max out the CPU on the visi... | ```
function loadJSInclude(scriptPath, callback)
{
var scriptNode = document.createElement('SCRIPT');
scriptNode.type = 'text/javascript';
scriptNode.src = scriptPath;
var headNode = document.getElementsByTagName('HEAD');
if (headNode[0] != null)
headNode[0].appendChild(scriptNode);
if... |
310,595 | <p>I need to test if a file is a shortcut. I'm still trying to figure out how stuff will be set up, but I might only have it's path, I might only have the actual contents of the file (as a byte[]) or I might have both.</p>
<p>A few complications include that I it could be in a zip file (in this cases the path will be ... | [
{
"answer_id": 310621,
"author": "user38123",
"author_id": 38123,
"author_profile": "https://Stackoverflow.com/users/38123",
"pm_score": 2,
"selected": false,
"text": "<p>You can simply check the extension and/or contents of this file. It contains a special GUID in the header.</p>\n<p>Re... | 2008/11/22 | [
"https://Stackoverflow.com/questions/310595",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1343/"
] | I need to test if a file is a shortcut. I'm still trying to figure out how stuff will be set up, but I might only have it's path, I might only have the actual contents of the file (as a byte[]) or I might have both.
A few complications include that I it could be in a zip file (in this cases the path will be an interna... | Shortcuts can be manipulated using the COM objects in SHELL32.DLL.
In your Visual Studio project, add a reference to the COM library "Microsoft Shell Controls And Automation" and then use the following:
```
/// <summary>
/// Returns whether the given path/file is a link
/// </summary>
/// <param name="shortcutFilena... |
310,599 | <p>It's simple enough to code up a class to store/validate something like <code>192.168.0.0/16</code>, but I was curious if a native type for this already existed in .NET? I would imagine it would work a lot like <code>IPAddress</code>:</p>
<pre><code>CIDR subnet = CIDR.Parse("192.168.0.0/16");
</code></pre>
<p>Basi... | [
{
"answer_id": 311393,
"author": "Baget",
"author_id": 34369,
"author_profile": "https://Stackoverflow.com/users/34369",
"pm_score": 3,
"selected": true,
"text": "<p>No there is such native type in .NET, you will need to develop one your self.</p>\n"
},
{
"answer_id": 2239906,
... | 2008/11/22 | [
"https://Stackoverflow.com/questions/310599",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9642/"
] | It's simple enough to code up a class to store/validate something like `192.168.0.0/16`, but I was curious if a native type for this already existed in .NET? I would imagine it would work a lot like `IPAddress`:
```
CIDR subnet = CIDR.Parse("192.168.0.0/16");
```
Basically it just needs to make sure you're working w... | No there is such native type in .NET, you will need to develop one your self. |
310,629 | <p>I need to write some methods for loading/saving some classes to and from a binary file. However I also want to be able to accept the binary data from other places, such as a binary string.</p>
<p>In c++ I could do this by simply making my class methods use std::istream and std::ostream which could be a file, a stri... | [
{
"answer_id": 310635,
"author": "Ned Batchelder",
"author_id": 14343,
"author_profile": "https://Stackoverflow.com/users/14343",
"pm_score": 4,
"selected": true,
"text": "<p>The Python way to do this is to accept an object that implements read() or write(). If you have a string, you ca... | 2008/11/22 | [
"https://Stackoverflow.com/questions/310629",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6266/"
] | I need to write some methods for loading/saving some classes to and from a binary file. However I also want to be able to accept the binary data from other places, such as a binary string.
In c++ I could do this by simply making my class methods use std::istream and std::ostream which could be a file, a stringstream, ... | The Python way to do this is to accept an object that implements read() or write(). If you have a string, you can make this happen with [StringIO](http://docs.python.org/library/stringio.html):
```
from cStringIO import StringIO
s = "My very long string I want to read like a file"
file_like_string = StringIO(s)
data ... |
310,634 | <p>PHP, for all its warts, is pretty good on this count. There's no difference between an array and a hash (maybe I'm naive, but this seems obviously right to me), and to iterate through either you just do</p>
<pre><code>foreach (array/hash as $key => $value)
</code></pre>
<p>In Ruby there are a bunch of ways to d... | [
{
"answer_id": 310638,
"author": "Robert Gamble",
"author_id": 25222,
"author_profile": "https://Stackoverflow.com/users/25222",
"pm_score": 10,
"selected": true,
"text": "<p>This will iterate through all the elements:</p>\n<pre class=\"lang-rb prettyprint-override\"><code>array = [1, 2,... | 2008/11/22 | [
"https://Stackoverflow.com/questions/310634",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/25068/"
] | PHP, for all its warts, is pretty good on this count. There's no difference between an array and a hash (maybe I'm naive, but this seems obviously right to me), and to iterate through either you just do
```
foreach (array/hash as $key => $value)
```
In Ruby there are a bunch of ways to do this sort of thing:
```
ar... | This will iterate through all the elements:
```rb
array = [1, 2, 3, 4, 5, 6]
array.each { |x| puts x }
# Output:
1
2
3
4
5
6
```
This will iterate through all the elements giving you the value and the index:
```rb
array = ["A", "B", "C"]
array.each_with_index {|val, index| puts "#{val} => #{index}" }
# Output:
... |
310,650 | <p>I'm retrieving a gzipped web page via curl, but when I output the retrieved content to the browser I just get the raw gzipped data. How can I decode the data in PHP?</p>
<p>One method I found was to write the content to a tmp file and then ...</p>
<pre><code>$f = gzopen($filename,"r");
$content = gzread($filename,... | [
{
"answer_id": 2849331,
"author": "Jonas Lejon",
"author_id": 117283,
"author_profile": "https://Stackoverflow.com/users/117283",
"pm_score": 8,
"selected": true,
"text": "<p>I use curl and:</p>\n<pre><code>curl_setopt($ch, CURLOPT_ENCODING , "gzip");\n</code></pre>\n"
},
{... | 2008/11/22 | [
"https://Stackoverflow.com/questions/310650",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/39539/"
] | I'm retrieving a gzipped web page via curl, but when I output the retrieved content to the browser I just get the raw gzipped data. How can I decode the data in PHP?
One method I found was to write the content to a tmp file and then ...
```
$f = gzopen($filename,"r");
$content = gzread($filename,250000);
gzclose($f);... | I use curl and:
```
curl_setopt($ch, CURLOPT_ENCODING , "gzip");
``` |
310,664 | <p>I'm having some trouble with ASP.NET MVC Beta, and the idea of making routes, controller actions, parameters on those controller actions and Html.ActionLinks all work together. I have an application that I'm working on where I have a model object called a Plot, and a corresponding PlotController. When a user creates... | [
{
"answer_id": 310709,
"author": "Timothy Khouri",
"author_id": 11917,
"author_profile": "https://Stackoverflow.com/users/11917",
"pm_score": 2,
"selected": true,
"text": "<p>The answer is pretty simple: You have to supply enough values in your \"ActionLink\" that will fulfill your Route... | 2008/11/22 | [
"https://Stackoverflow.com/questions/310664",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18831/"
] | I'm having some trouble with ASP.NET MVC Beta, and the idea of making routes, controller actions, parameters on those controller actions and Html.ActionLinks all work together. I have an application that I'm working on where I have a model object called a Plot, and a corresponding PlotController. When a user creates a ... | The answer is pretty simple: You have to supply enough values in your "ActionLink" that will fulfill your Route. Example:
```
<%= Html.ActionLink("Click Here", "ViewDetails", "Plot", new { name="my-plot-name" }, null)%>
```
If you leave out the "name=" part of the ActionLink method, then the RouteEngine won't see th... |
310,669 | <p>Does anyone have any idea why the following code sample fails with an XmlException "Data at the root level is invalid. Line 1, position 1."</p>
<pre><code>var body = "<?xml version="1.0" encoding="utf-16"?><Report> ......"
XmlDocument bodyDoc = new XmlDocument();
bodyDoc.LoadXml(body);
</cod... | [
{
"answer_id": 310708,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 3,
"selected": false,
"text": "<p>I figured it out. Read the MSDN documentation and it says to use .Load instead of LoadXml when reading from strings. Foun... | 2008/11/22 | [
"https://Stackoverflow.com/questions/310669",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | Does anyone have any idea why the following code sample fails with an XmlException "Data at the root level is invalid. Line 1, position 1."
```
var body = "<?xml version="1.0" encoding="utf-16"?><Report> ......"
XmlDocument bodyDoc = new XmlDocument();
bodyDoc.LoadXml(body);
``` | Background
----------
Although your question does have the encoding set as UTF-16, you don't have the string properly escaped so I wasn't sure if you did, in fact, accurately transpose the string into your question.
I ran into the same exception:
>
> System.Xml.XmlException: Data at the
> root level is invalid. L... |
310,691 | <p>can anyone provide/refer a proper OO type helper class for managing a singleton of the SessionFactory and then also for managing Sessions?</p>
| [
{
"answer_id": 310824,
"author": "George Stocker",
"author_id": 16587,
"author_profile": "https://Stackoverflow.com/users/16587",
"pm_score": 2,
"selected": false,
"text": "<p>Sure, this is what I used when I was getting started with NHibernate:</p>\n<p><strong>Session Factory</strong></... | 2008/11/22 | [
"https://Stackoverflow.com/questions/310691",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/38574/"
] | can anyone provide/refer a proper OO type helper class for managing a singleton of the SessionFactory and then also for managing Sessions? | Check out [Billy McCafferty's work](http://www.codeproject.com/KB/architecture/NHibernateBestPractices.aspx). His earlier version had some limitations, you'll need to correct the error handling around closing and flushing, and I'm not sure i have it right but I will post how I modified his stuff.
Billy is also working... |
310,729 | <p>For loading time considerations I am using a runtime css file in my Flex Application.</p>
<p>I am having a problem with a multi line text control :</p>
<pre><code><mx:Text id="txtDescription" selectable="false"
styleName="imageRolloverButtonTextDark" width="100%" textAlign="center"
text="{_rolloverText}"/>
<... | [
{
"answer_id": 311533,
"author": "defmeta",
"author_id": 10875,
"author_profile": "https://Stackoverflow.com/users/10875",
"pm_score": 0,
"selected": false,
"text": "<p>Could you use a fixed pixel width instead of 100%? I've had issues with 100% being wrongly calculated on dynamic text c... | 2008/11/22 | [
"https://Stackoverflow.com/questions/310729",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16940/"
] | For loading time considerations I am using a runtime css file in my Flex Application.
I am having a problem with a multi line text control :
```
<mx:Text id="txtDescription" selectable="false"
styleName="imageRolloverButtonTextDark" width="100%" textAlign="center"
text="{_rolloverText}"/>
```
When my CSS stylesheet... | For any one else who has this problem, The solution I found was to create a custom component extending the mx.controls.Text
and then override the styleChange() Method, and explicitly call the invalidateDisplayList() method for the text field once the style has been applied.
It should be called automatically when the ... |
310,732 | <p>Given a class:</p>
<pre><code>from django.db import models
class Person(models.Model):
name = models.CharField(max_length=20)
</code></pre>
<p>Is it possible, and if so how, to have a QuerySet that filters based on dynamic arguments? For example:</p>
<pre><code> # Instead of:
Person.objects.filter(name__st... | [
{
"answer_id": 310775,
"author": "S.Lott",
"author_id": 10661,
"author_profile": "https://Stackoverflow.com/users/10661",
"pm_score": -1,
"selected": false,
"text": "<p>A really complex search forms usually indicates that a simpler model is trying to dig it's way out.</p>\n\n<p>How, exac... | 2008/11/22 | [
"https://Stackoverflow.com/questions/310732",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19212/"
] | Given a class:
```
from django.db import models
class Person(models.Model):
name = models.CharField(max_length=20)
```
Is it possible, and if so how, to have a QuerySet that filters based on dynamic arguments? For example:
```
# Instead of:
Person.objects.filter(name__startswith='B')
# ... and:
Person.obje... | Python's argument expansion may be used to solve this problem:
```
kwargs = {
'{0}__{1}'.format('name', 'startswith'): 'A',
'{0}__{1}'.format('name', 'endswith'): 'Z'
}
Person.objects.filter(**kwargs)
```
This is a very common and useful Python idiom. |
310,749 | <p>I'm having a problem with the WPF Tab View control that I was hoping someone here might be able to help me with.</p>
<p>I want my tab view control to use rounded corners for the tab headers, because I think rounded tabs look better.</p>
<p>To do this I modified the default control template for the tab by using the... | [
{
"answer_id": 310764,
"author": "Geoff Cox",
"author_id": 30505,
"author_profile": "https://Stackoverflow.com/users/30505",
"pm_score": 0,
"selected": false,
"text": "<p>Add a simple style control to your window in Blend. This will add the SimpleStyles.xaml, including one for the tab c... | 2008/11/22 | [
"https://Stackoverflow.com/questions/310749",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1737192/"
] | I'm having a problem with the WPF Tab View control that I was hoping someone here might be able to help me with.
I want my tab view control to use rounded corners for the tab headers, because I think rounded tabs look better.
To do this I modified the default control template for the tab by using the "Edit Copy" comm... | There is no way to make rounded tab corners without creating a custom template for TabItem. Doing the "Edit Copy" in blend I believe creates default template based on the current theme of windows you have (I may be wrong however. I beleive that wehn you do a controltemplate dump it get's the current control template wh... |
310,770 | <p>This one is a bit tedious in as far as explaining, so here goes. I'm essentially populating a tableView on the iPhone with multiple sections, and potentially multiple rows per section. To my understanding, it's best to have an array of arrays so that you can simply determine how many sections one has by sending a me... | [
{
"answer_id": 310858,
"author": "wisequark",
"author_id": 33159,
"author_profile": "https://Stackoverflow.com/users/33159",
"pm_score": 2,
"selected": false,
"text": "<p>And NSDictionary <em>is</em> a hash table.</p>\n"
},
{
"answer_id": 310969,
"author": "e.James",
"aut... | 2008/11/22 | [
"https://Stackoverflow.com/questions/310770",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | This one is a bit tedious in as far as explaining, so here goes. I'm essentially populating a tableView on the iPhone with multiple sections, and potentially multiple rows per section. To my understanding, it's best to have an array of arrays so that you can simply determine how many sections one has by sending a messa... | The following code works: (**edit:** added my initialization code)
```
NSArray * arrayOfRecords = [NSArray arrayWithObjects:
[NSDictionary dictionaryWithObjectsAndKeys:
@"bob", @"name",
[NSNumber numberWithInt:3], @"location", nil],
[NSDictionary dictionaryWithObjectsAndKeys:
@"jane", @"name... |
310,786 | <p>Does anyone know how to change the color of a row (or row background) in the UIPickerView control from the iPhone SDK? Similiar to the below title for row, however I would also like to change the color of the row:</p>
<pre><code>- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forCompo... | [
{
"answer_id": 310800,
"author": "Noah Witherspoon",
"author_id": 30618,
"author_profile": "https://Stackoverflow.com/users/30618",
"pm_score": 4,
"selected": true,
"text": "<p>You can return an arbitrary view in the delegate's -pickerView:viewForRow:forComponent:reusingView: method, doc... | 2008/11/22 | [
"https://Stackoverflow.com/questions/310786",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/29941/"
] | Does anyone know how to change the color of a row (or row background) in the UIPickerView control from the iPhone SDK? Similiar to the below title for row, however I would also like to change the color of the row:
```
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSIntege... | You can return an arbitrary view in the delegate's -pickerView:viewForRow:forComponent:reusingView: method, documented [here](http://developer.apple.com/iphone/library/documentation/UIKit/Reference/UIPickerViewDelegate_Protocol/Reference/UIPickerViewDelegate.html#//apple_ref/occ/intfm/UIPickerViewDelegate/pickerView:vi... |
310,801 | <p>When using a subdomain and trying to view anything related to current_user. user is sent to a new session page, the page shows the session is created and gives the option to logout. I can use no subdomain and it works fine.</p>
| [
{
"answer_id": 310830,
"author": "Kevin H",
"author_id": 20116,
"author_profile": "https://Stackoverflow.com/users/20116",
"pm_score": 1,
"selected": false,
"text": "<p>Set it in your environment.rb (or environments/*.rb if you'll use different domains for each environment):</p>\n\n<pre>... | 2008/11/22 | [
"https://Stackoverflow.com/questions/310801",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | When using a subdomain and trying to view anything related to current\_user. user is sent to a new session page, the page shows the session is created and gives the option to logout. I can use no subdomain and it works fine. | Set it in your environment.rb (or environments/\*.rb if you'll use different domains for each environment):
```
ActionController::CgiRequest::DEFAULT_SESSION_OPTIONS.update( :session_domain => '.domain.com')
``` |
310,805 | <p>I've been knocking my head against this for some time now. I'm not really sure why it isn't working. I'm still pretty new to this whole WPF business. </p>
<p>Here's my XAML for the combobox</p>
<pre><code><ComboBox
SelectedValuePath="Type.FullName"
SelectedItem="{Binding Path=Type}"
Name="cmoBox" /... | [
{
"answer_id": 310812,
"author": "Timothy Khouri",
"author_id": 11917,
"author_profile": "https://Stackoverflow.com/users/11917",
"pm_score": 5,
"selected": true,
"text": "<p>In the XAML, set <code>ItemsSource=\"{Binding}\"</code> and (in the code behind) set the <code>DataContext</code>... | 2008/11/22 | [
"https://Stackoverflow.com/questions/310805",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13688/"
] | I've been knocking my head against this for some time now. I'm not really sure why it isn't working. I'm still pretty new to this whole WPF business.
Here's my XAML for the combobox
```
<ComboBox
SelectedValuePath="Type.FullName"
SelectedItem="{Binding Path=Type}"
Name="cmoBox" />
```
Here's what popu... | In the XAML, set `ItemsSource="{Binding}"` and (in the code behind) set the `DataContext` to `myAssembly.PossibleTypes`. |
310,820 | <p>I want to do this in Actionscript:</p>
<pre><code>typeof(control1) != typeof(control2)
</code></pre>
<p>to test if two objects are of the same type. This would work just fine in C#, but in Actionscript it doesnt. In fact it returns <code>'object'</code> for both <code>typeof()</code> expressions because thats the ... | [
{
"answer_id": 310879,
"author": "enobrev",
"author_id": 14651,
"author_profile": "https://Stackoverflow.com/users/14651",
"pm_score": 2,
"selected": false,
"text": "<p>You'll want to use the Object.prototype.constructor.</p>\n\n<p>From the <a href=\"http://livedocs.adobe.com/flash/9.0/A... | 2008/11/22 | [
"https://Stackoverflow.com/questions/310820",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16940/"
] | I want to do this in Actionscript:
```
typeof(control1) != typeof(control2)
```
to test if two objects are of the same type. This would work just fine in C#, but in Actionscript it doesnt. In fact it returns `'object'` for both `typeof()` expressions because thats the way Actionscript works.
I couldn't seem to find... | The best way is to use `flash.utils.getQualifiedClassName()`. Additionally, you can use `flash.utils.describeType()` to get an XML document the describes more about the class. |
310,833 | <p>In my views.py, i have a snippit of code like this:</p>
<pre><code>def clean_post_data(form):
for i in form.cleaned_data:
form.cleaned_data[i] = form.cleaned_data[i].rstrip()
def add_product(request):
form = ProductForm(request.POST, request.FILES or None)
image = Image.objects.all()
act... | [
{
"answer_id": 310900,
"author": "Sergey Golovchenko",
"author_id": 26592,
"author_profile": "https://Stackoverflow.com/users/26592",
"pm_score": 0,
"selected": false,
"text": "<p>Most likely you have several elements on your form with same name. When it is submitted one of the elements ... | 2008/11/22 | [
"https://Stackoverflow.com/questions/310833",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2592/"
] | In my views.py, i have a snippit of code like this:
```
def clean_post_data(form):
for i in form.cleaned_data:
form.cleaned_data[i] = form.cleaned_data[i].rstrip()
def add_product(request):
form = ProductForm(request.POST, request.FILES or None)
image = Image.objects.all()
action = "Add"
... | The `clean_post_data` shouldn't be a stand-alone function.
It should be a method in the form, named `clean`. See [Form and Field Validation](http://docs.djangoproject.com/en/dev/ref/forms/validation/#ref-forms-validation). |
310,870 | <p>What's the difference between</p>
<pre><code>var A = function () {
this.x = function () {
//do something
};
};
</code></pre>
<p>and</p>
<pre><code>var A = function () { };
A.prototype.x = function () {
//do something
};
</code></pre>
| [
{
"answer_id": 310874,
"author": "Glenn",
"author_id": 25191,
"author_profile": "https://Stackoverflow.com/users/25191",
"pm_score": 5,
"selected": false,
"text": "<p>The first example changes the interface for that object only. The second example changes the interface for all object of ... | 2008/11/22 | [
"https://Stackoverflow.com/questions/310870",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/39864/"
] | What's the difference between
```
var A = function () {
this.x = function () {
//do something
};
};
```
and
```
var A = function () { };
A.prototype.x = function () {
//do something
};
``` | The examples have very different outcomes.
Before looking at the differences, the following should be noted:
* A constructor's *prototype* provides a way to share methods and values among instances via the instance's private `[[Prototype]]` property.
* A function's *this* is set by how the function is called or by th... |
310,888 | <p>Today I ran XtUnit at a part of my unit testing framework to to rollback database changes created while running a test case. This is a skeleton of how I have used it. The Test case ran successfully but the database state changed as a result. </p>
<pre><code>using NUnit.Framework;
using TeamAgile.ApplicationBlocks.... | [
{
"answer_id": 354237,
"author": "Tom Lianza",
"author_id": 26624,
"author_profile": "https://Stackoverflow.com/users/26624",
"pm_score": 3,
"selected": true,
"text": "<p>I think your test fixture needs to extend <code>ExtensibleFixture</code>, not <code>InterceptableObject</code>. In t... | 2008/11/22 | [
"https://Stackoverflow.com/questions/310888",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/22039/"
] | Today I ran XtUnit at a part of my unit testing framework to to rollback database changes created while running a test case. This is a skeleton of how I have used it. The Test case ran successfully but the database state changed as a result.
```
using NUnit.Framework;
using TeamAgile.ApplicationBlocks.Interception;
u... | I think your test fixture needs to extend `ExtensibleFixture`, not `InterceptableObject`. In the XtUnit source, `ExtensibleFixture` itself inherits from `InterceptableObject`. The comments in ExtensibleFixture.cs state:
>
> This is the base class for all the test fixtures you will
>
> have in your project. You M... |
310,889 | <p>I am taking my first foray into PHP programming and need to configure the environment for the first time. Can I use PHP with the built in VS web server or do I need to (and I hope not) use IIS locally?</p>
<p>In addition, any pointers on pitfalls to be avoided would be great.</p>
<p>Many thanks.</p>
<p><b>Update:... | [
{
"answer_id": 310909,
"author": "UnkwnTech",
"author_id": 115,
"author_profile": "https://Stackoverflow.com/users/115",
"pm_score": 0,
"selected": false,
"text": "<p>PHP on IIS is a bit of a pitfall in itself, you can find some reference here: <a href=\"https://stackoverflow.com/questio... | 2008/11/22 | [
"https://Stackoverflow.com/questions/310889",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13139/"
] | I am taking my first foray into PHP programming and need to configure the environment for the first time. Can I use PHP with the built in VS web server or do I need to (and I hope not) use IIS locally?
In addition, any pointers on pitfalls to be avoided would be great.
Many thanks.
**Update:** I should have made the... | For what you're doing, you really shouldn't be using the PHP scripts from that example.
Instead, you should be pulling data from the Form variables posted to the server on your own self-made pages. I don't know the "proper" way to do this using the MVC framework. With the ASP Forms framework, you'd do something like t... |
310,911 | <p>Any good reason why $("p").html(0) makes all paragraphs empty as opposed to contain the character '0'?</p>
<p>Instead of assuming I found a bug in jQuery, it's probably a misunderstanding on my part.</p>
| [
{
"answer_id": 310918,
"author": "nickf",
"author_id": 9021,
"author_profile": "https://Stackoverflow.com/users/9021",
"pm_score": 0,
"selected": false,
"text": "<p>I guess that at some point, it checks <code>if (newContent == false)</code>, and doesn't continue with adding any content? ... | 2008/11/22 | [
"https://Stackoverflow.com/questions/310911",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2443/"
] | Any good reason why $("p").html(0) makes all paragraphs empty as opposed to contain the character '0'?
Instead of assuming I found a bug in jQuery, it's probably a misunderstanding on my part. | jQuery only accepts a string as an argument for the `val` parameter of the `html()` method. If you pass a number like you are it will call the `html()` method override that sets the contents of the element but the value of the argument will end up being null or an empty string.
Try this:
```
$("p").html((0).toString(... |
310,919 | <p>I've never liked wrapping the </p>
<pre><code>mysql_real_escape_string
</code></pre>
<p>function around input I expect to be integer for inclusion in a MySQL query.
Recently I came across the </p>
<pre><code>filter_var
</code></pre>
<p>function. Nice!</p>
<p>I'm currently using the code:</p>
<pre><code>if (i... | [
{
"answer_id": 310930,
"author": "Paige Ruten",
"author_id": 813,
"author_profile": "https://Stackoverflow.com/users/813",
"pm_score": 1,
"selected": false,
"text": "<p>A much simpler and easier-to-read method that I use is this:</p>\n\n<pre><code>$sql = 'SELECT * FROM TABLE_NAME WHERE i... | 2008/11/22 | [
"https://Stackoverflow.com/questions/310919",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10648/"
] | I've never liked wrapping the
```
mysql_real_escape_string
```
function around input I expect to be integer for inclusion in a MySQL query.
Recently I came across the
```
filter_var
```
function. Nice!
I'm currently using the code:
```
if (isset($idUserIN)
&& filter_var($idUserIN, FILTER_VALIDATE_INT) ... | I myself would create a function for that task, possibly in a static class somewhere,
```
public static function escape_int($i) {
$sanitised = intval($i);
if( '_' . $sanitised . '_' === '_' . $i . '_' && $sanitised > 0 ) {
return $sanitised;
}
throw new IntegerEscapeException( $i, $sanitised... |
310,946 | <p>I want to send an email from my iPhone application. I have heard that the iOS SDK doesn't have an email API. I don't want to use the following code because it will exit my application:</p>
<pre><code>NSString *url = [NSString stringWithString: @"mailto:foo@example.com?cc=bar@example.com&subject=Greetings%20from... | [
{
"answer_id": 388514,
"author": "Genericrich",
"author_id": 39932,
"author_profile": "https://Stackoverflow.com/users/39932",
"pm_score": 4,
"selected": false,
"text": "<p>If you want to send email from your application, the above code is the only way to do it unless you code your own m... | 2008/11/22 | [
"https://Stackoverflow.com/questions/310946",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/39599/"
] | I want to send an email from my iPhone application. I have heard that the iOS SDK doesn't have an email API. I don't want to use the following code because it will exit my application:
```
NSString *url = [NSString stringWithString: @"mailto:foo@example.com?cc=bar@example.com&subject=Greetings%20from%20Cupertino!&body... | On iOS 3.0 and later you should use the `MFMailComposeViewController` class, and the `MFMailComposeViewControllerDelegate` protocol, that is tucked away in the MessageUI framework.
First add the [framework](https://developer.apple.com/documentation/messageui) and import:
```
#import <MessageUI/MFMailComposeViewContro... |
310,964 | <p>I'm learning functional programming, and have tried to solve a couple problems in a functional style. One thing I experienced, while dividing up my problem into functions, was it seemed I had two options: use several disparate functions with similar parameter lists, or using nested functions which, as closures, can ... | [
{
"answer_id": 310971,
"author": "Kyle Cronin",
"author_id": 658,
"author_profile": "https://Stackoverflow.com/users/658",
"pm_score": 2,
"selected": false,
"text": "<p>Functional programming isn't all-or-nothing. If nesting the functions makes more sense, I'd go with that approach. Howe... | 2008/11/22 | [
"https://Stackoverflow.com/questions/310964",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/38803/"
] | I'm learning functional programming, and have tried to solve a couple problems in a functional style. One thing I experienced, while dividing up my problem into functions, was it seemed I had two options: use several disparate functions with similar parameter lists, or using nested functions which, as closures, can sim... | Nesting functions is an excellent way to divide up the labor in many functions. It's not really "side-effecty"; if it helps, think of the captured variables as implicit parameters.
One example where nested functions are useful is to replace loops. The parameters to the nested function can act as induction variables w... |
310,974 | <p>Very simply, what is tail-call optimization?</p>
<p>More specifically, what are some small code snippets where it could be applied, and where not, with an explanation of why?</p>
| [
{
"answer_id": 310977,
"author": "BobbyShaftoe",
"author_id": 38426,
"author_profile": "https://Stackoverflow.com/users/38426",
"pm_score": 3,
"selected": false,
"text": "<p>Look here:</p>\n\n<p><a href=\"http://tratt.net/laurie/tech_articles/articles/tail_call_optimization\" rel=\"noref... | 2008/11/22 | [
"https://Stackoverflow.com/questions/310974",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/38812/"
] | Very simply, what is tail-call optimization?
More specifically, what are some small code snippets where it could be applied, and where not, with an explanation of why? | Tail-call optimization is where you are able to avoid allocating a new stack frame for a function because the calling function will simply return the value that it gets from the called function. The most common use is tail-recursion, where a recursive function written to take advantage of tail-call optimization can use... |
310,981 | <p>I am working on lock free structure with g++ compiler. It seems that with -o1 switch, g++ will change the execution order of my code. How can I forbid g++'s optimization on certain part of my code while maintain the optimization to other part? I know I can split it to two files and link them, but it looks ugly.</p>
| [
{
"answer_id": 310977,
"author": "BobbyShaftoe",
"author_id": 38426,
"author_profile": "https://Stackoverflow.com/users/38426",
"pm_score": 3,
"selected": false,
"text": "<p>Look here:</p>\n\n<p><a href=\"http://tratt.net/laurie/tech_articles/articles/tail_call_optimization\" rel=\"noref... | 2008/11/22 | [
"https://Stackoverflow.com/questions/310981",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | I am working on lock free structure with g++ compiler. It seems that with -o1 switch, g++ will change the execution order of my code. How can I forbid g++'s optimization on certain part of my code while maintain the optimization to other part? I know I can split it to two files and link them, but it looks ugly. | Tail-call optimization is where you are able to avoid allocating a new stack frame for a function because the calling function will simply return the value that it gets from the called function. The most common use is tail-recursion, where a recursive function written to take advantage of tail-call optimization can use... |
310,996 | <p>I am calling a batch file from Javascript in this fashion:</p>
<pre><code>function runBatch(){
var exe = Components.classes['@mozilla.org/file/local;1'].createInstance(Components.interfaces.nsILocalFile);
exe.initWithPath("C:\\test.bat");
var run = Components.classes['@mozilla.org/process/util;1'].creat... | [
{
"answer_id": 311940,
"author": "ng.mangine",
"author_id": 37784,
"author_profile": "https://Stackoverflow.com/users/37784",
"pm_score": 1,
"selected": false,
"text": "<p>Did you try using the launch method of nsiLocalFile?</p>\n\n<pre><code>function runBatch(){\n var exe = Component... | 2008/11/22 | [
"https://Stackoverflow.com/questions/310996",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/525/"
] | I am calling a batch file from Javascript in this fashion:
```
function runBatch(){
var exe = Components.classes['@mozilla.org/file/local;1'].createInstance(Components.interfaces.nsILocalFile);
exe.initWithPath("C:\\test.bat");
var run = Components.classes['@mozilla.org/process/util;1'].createInstance(Comp... | The only solution I've heard so far (that should work, although I haven't done it yet, comes from Mook in the Mozilla xulrunner IRC channel:
*create* a temporary batch file, writing in the batch file to call and arguments to pass it. then execute the temporary batch file.
e.g psuedocode:
```
f = fopen("temp.bat");
... |
311,026 | <p>In SQLSERVER 2005, I'm using table-valued function as a convenient way to perform arbitrary aggregation on subset data from large table (passing date range or such parameters).</p>
<p>I'm using theses inside larger queries as joined computations and I'm wondering if the query plan optimizer work well with them in e... | [
{
"answer_id": 311163,
"author": "gbn",
"author_id": 27535,
"author_profile": "https://Stackoverflow.com/users/27535",
"pm_score": 4,
"selected": true,
"text": "<p>In this case, it's an \"inline table valued function\"\nThe optimiser simply expands (unnests) it if it's useful (or view).... | 2008/11/22 | [
"https://Stackoverflow.com/questions/311026",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17049/"
] | In SQLSERVER 2005, I'm using table-valued function as a convenient way to perform arbitrary aggregation on subset data from large table (passing date range or such parameters).
I'm using theses inside larger queries as joined computations and I'm wondering if the query plan optimizer work well with them in every condi... | In this case, it's an "inline table valued function"
The optimiser simply expands (unnests) it if it's useful (or view).
If the function is treated as "black box" by the outer query, the quickest way is to compare IO shown in SSMS vs IO in profiler.
Profler captures "black box" IO that SSMS does not.
[Blog post by Ad... |
311,043 | <blockquote>
<p><strong>Possible Duplicate:</strong><br>
<a href="https://stackoverflow.com/questions/311054/how-do-i-select-last-5-rows-in-a-table-without-sorting">How do I select last 5 rows in a table without sorting?</a> </p>
</blockquote>
<p>I want to select the top 10 records from a table in SQL Server wi... | [
{
"answer_id": 311056,
"author": "smoothdeveloper",
"author_id": 17049,
"author_profile": "https://Stackoverflow.com/users/17049",
"pm_score": 4,
"selected": false,
"text": "<p>if random order is needed, you can try</p>\n\n<pre><code>select top 10 * from [tablename] order by newid()\n</c... | 2008/11/22 | [
"https://Stackoverflow.com/questions/311043",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | >
> **Possible Duplicate:**
>
> [How do I select last 5 rows in a table without sorting?](https://stackoverflow.com/questions/311054/how-do-i-select-last-5-rows-in-a-table-without-sorting)
>
>
>
I want to select the top 10 records from a table in SQL Server without arranging the table in ascending or descendin... | if random order is needed, you can try
```
select top 10 * from [tablename] order by newid()
``` |
311,050 | <p>I have a scrolling div with Three linkbuttons and three differents divs. I need to apply CSS to active linkbutton as soon as button is clicked.The codes used by me are:</p>
<pre><code>protected void btnNetwork_Click(object sender, EventArgs e)
{
this.btnForecast.CssClass = "li_1";
this.btnBlog.... | [
{
"answer_id": 311233,
"author": "Pradeep Kumar Mishra",
"author_id": 22710,
"author_profile": "https://Stackoverflow.com/users/22710",
"pm_score": 2,
"selected": false,
"text": "<p>Instead of using server side event use client side javascript event. Try:</p>\n\n<pre><code>$get('btnId').... | 2008/11/22 | [
"https://Stackoverflow.com/questions/311050",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/39599/"
] | I have a scrolling div with Three linkbuttons and three differents divs. I need to apply CSS to active linkbutton as soon as button is clicked.The codes used by me are:
```
protected void btnNetwork_Click(object sender, EventArgs e)
{
this.btnForecast.CssClass = "li_1";
this.btnBlog.CssClass = "li_... | Instead of using server side event use client side javascript event. Try:
```
$get('btnId').setAttribute("class", "some_class_name");
``` |
311,051 | <p>I'm converting some Actionscript code from AS2 tp AS3, and I've eventually managed to get most of it to work again (it's allmost a totally different language, sharing just a little syntax similarity). One of the last things that still doesn't work, is the code for loading an external image.</p>
<p>Perhaps this has ... | [
{
"answer_id": 311157,
"author": "Stein G. Strindhaug",
"author_id": 26115,
"author_profile": "https://Stackoverflow.com/users/26115",
"pm_score": 0,
"selected": false,
"text": "<p>I discovered a soulution, myself.</p>\n\n<p>Initializing or unloading a list of images (actually instances ... | 2008/11/22 | [
"https://Stackoverflow.com/questions/311051",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/26115/"
] | I'm converting some Actionscript code from AS2 tp AS3, and I've eventually managed to get most of it to work again (it's allmost a totally different language, sharing just a little syntax similarity). One of the last things that still doesn't work, is the code for loading an external image.
Perhaps this has changed in... | I think you're making things a little too complicated - here's what you need to load a single image:
```
import flash.display.Loader;
import flash.event.Event;
import flash.net.URLRequest;
var imageLoader:Loader = new Loader();
imageLoader.contentLoaderInfo.addEventListener(Event.COMPLETE, function(e:Event){
// e.ta... |
311,052 | <p>I'm looking for a way to change the CSS rules for pseudo-class selectors (such as :link, :hover, etc.) from JavaScript.</p>
<p>So an analogue of the CSS code: <code>a:hover { color: red }</code> in JS.</p>
<p>I couldn't find the answer anywhere else; if anyone knows that this is something browsers do not support, ... | [
{
"answer_id": 311437,
"author": "bobince",
"author_id": 18936,
"author_profile": "https://Stackoverflow.com/users/18936",
"pm_score": 8,
"selected": false,
"text": "<p>You can't style a pseudo-class on a particular element alone, in the same way that you can't have a pseudo-class in an ... | 2008/11/22 | [
"https://Stackoverflow.com/questions/311052",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/39882/"
] | I'm looking for a way to change the CSS rules for pseudo-class selectors (such as :link, :hover, etc.) from JavaScript.
So an analogue of the CSS code: `a:hover { color: red }` in JS.
I couldn't find the answer anywhere else; if anyone knows that this is something browsers do not support, that would be a helpful resu... | You can't style a pseudo-class on a particular element alone, in the same way that you can't have a pseudo-class in an inline style="..." attribute (as there is no selector).
You can do it by altering the stylesheet, for example by adding the rule:
```
#elid:hover { background: red; }
```
assuming each element you ... |
311,054 | <p>I want to select the last 5 records from a table in SQL Server without arranging the table in ascending or descending order.</p>
| [
{
"answer_id": 311059,
"author": "Stefan Mai",
"author_id": 13257,
"author_profile": "https://Stackoverflow.com/users/13257",
"pm_score": 2,
"selected": false,
"text": "<p>Without an order, this is impossible. What defines the \"bottom\"? The following will select 5 rows according to h... | 2008/11/22 | [
"https://Stackoverflow.com/questions/311054",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | I want to select the last 5 records from a table in SQL Server without arranging the table in ascending or descending order. | This is just about the most bizarre query I've ever written, but I'm pretty sure it gets the "last 5" rows from a table without ordering:
```
select *
from issues
where issueid not in (
select top (
(select count(*) from issues) - 5
) issueid
from issues
)
```
Note that this makes use of SQL Ser... |
311,070 | <p>How to filter my datagridview by the value of my label.text on click event? That value is from my linq query:</p>
<pre><code>dataSet.Tables[0].AsEnumerable().Where(c => c.Field<int>("ageColumn") > 3 &&
c.Field<int>("ageColumn") < 5).Count();
</code></pre>
<p>Let's just say the abo... | [
{
"answer_id": 311139,
"author": "Rob Cooper",
"author_id": 832,
"author_profile": "https://Stackoverflow.com/users/832",
"pm_score": 0,
"selected": false,
"text": "<p>Now I do not use LINQ, but logic would suggest that whatever is retured by the expression</p>\n\n<pre><code>dataSet.Tabl... | 2008/11/22 | [
"https://Stackoverflow.com/questions/311070",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10385/"
] | How to filter my datagridview by the value of my label.text on click event? That value is from my linq query:
```
dataSet.Tables[0].AsEnumerable().Where(c => c.Field<int>("ageColumn") > 3 &&
c.Field<int>("ageColumn") < 5).Count();
```
Let's just say the above query gives me 12 (label.text = 12), now when I clic... | Do you need it to be dynamic? Perhaps store the query itself as a lambda in the Tag property of your label:
```
Predicate<DataColumn> clause = c => c.Field<int>("ageColumn") > 3
&& c.Field<int>("ageColumn") < 5;
label1.Tag = clause;
```
... then re-evaluate your query when the label is clicked:
```
var clause ... |
311,074 | <p>In my application I have a <code>Customer</code> class and an <code>Address</code> class. The <code>Customer</code> class has three instances of the <code>Address</code> class: <code>customerAddress</code>, <code>deliveryAddress</code>, <code>invoiceAddress</code>.</p>
<p><strong>Whats the best way to reflect this ... | [
{
"answer_id": 311081,
"author": "friol",
"author_id": 23034,
"author_profile": "https://Stackoverflow.com/users/23034",
"pm_score": 3,
"selected": false,
"text": "<p>I'd go (as database theory teaches) for two separate tables: Customer and Address.<br/><br/>\nThe idea of putting three f... | 2008/11/22 | [
"https://Stackoverflow.com/questions/311074",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/23368/"
] | In my application I have a `Customer` class and an `Address` class. The `Customer` class has three instances of the `Address` class: `customerAddress`, `deliveryAddress`, `invoiceAddress`.
**Whats the best way to reflect this structure in a database?**
* The straightforward way would be a customer table and a separat... | If you are 100% certain that a customer will only ever have the 3 addresses you described then this is OK:
```
CREATE TABLE Customer
(
ID int not null IDENTITY(1,1) PRIMARY KEY,
Name varchar(60) not null,
customerAddress int not null
CONSTRAINT FK_Address1_AddressID FOREIGN KEY References Address(I... |
311,094 | <p>Some background: In Germany (at least) invoice numbers have to follow certain rules:</p>
<ol>
<li>The have to be ordered</li>
<li>They have to be continuous (may not have gaps)</li>
</ol>
<p>Since a few months they are allowed to contain characters. Some customers want to use that possibility and customers don't k... | [
{
"answer_id": 311099,
"author": "friol",
"author_id": 23034,
"author_profile": "https://Stackoverflow.com/users/23034",
"pm_score": 1,
"selected": false,
"text": "<p>My two ideas:</p>\n\n<ol>\n<li>(without chars): a sequence, starting at 1, left-padded with zeroes (or beginning with ano... | 2008/11/22 | [
"https://Stackoverflow.com/questions/311094",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/23368/"
] | Some background: In Germany (at least) invoice numbers have to follow certain rules:
1. The have to be ordered
2. They have to be continuous (may not have gaps)
Since a few months they are allowed to contain characters. Some customers want to use that possibility and customers don't know that or are afraid and they i... | In order to avoid starting at 0 - just start at 10000. Forget about the zero-padding.
You have to consider when the number is going to be allocated.
If you allocate the number when the invoice is first opened for edit, for instance the number 10014 is allocated, and the user cancels the invoice then you have a gap, s... |
311,102 | <p>For a system I need to convert a pointer to a long then the long back to the pointer type. As you can guess this is very unsafe. What I wanted to do is use dynamic_cast to do the conversion so if I mixed them I'll get a null pointer. This page says <a href="http://publib.boulder.ibm.com/infocenter/lnxpcomp/v7v91/ind... | [
{
"answer_id": 311106,
"author": "amit kumar",
"author_id": 19501,
"author_profile": "https://Stackoverflow.com/users/19501",
"pm_score": 2,
"selected": false,
"text": "<p><code>dynamic_cast</code> can be used only between classes related through inheritance. For converting a pointer to ... | 2008/11/22 | [
"https://Stackoverflow.com/questions/311102",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | For a system I need to convert a pointer to a long then the long back to the pointer type. As you can guess this is very unsafe. What I wanted to do is use dynamic\_cast to do the conversion so if I mixed them I'll get a null pointer. This page says <http://publib.boulder.ibm.com/infocenter/lnxpcomp/v7v91/index.jsp?top... | I've had to do similar things when loading C++ DLLs in apps written in languages that only support a C interface. Here is a solution that will give you an immediate error if an unexpected object type was passed in. This can make things much easier to diagnose when something goes wrong.
The trick is that every class th... |
311,103 | <p>I need a map that has two keys, e.g.</p>
<pre><code>Map2<String /*ssn*/, String /*empId*/, Employee> _employees;
</code></pre>
<p>So that I can</p>
<pre><code>_employees.put(e.ssn(), e.empId(), e)
</code></pre>
<p>And later</p>
<pre><code>_employees.get1(someSsn);
_employees.get2(someImpId);
</code></pre>... | [
{
"answer_id": 311110,
"author": "Stefan Mai",
"author_id": 13257,
"author_profile": "https://Stackoverflow.com/users/13257",
"pm_score": 2,
"selected": false,
"text": "<p>My first thought was: the easiest way to do this, I think, would be two maps.</p>\n\n<pre><code>Map< String, Map&... | 2008/11/22 | [
"https://Stackoverflow.com/questions/311103",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18573/"
] | I need a map that has two keys, e.g.
```
Map2<String /*ssn*/, String /*empId*/, Employee> _employees;
```
So that I can
```
_employees.put(e.ssn(), e.empId(), e)
```
And later
```
_employees.get1(someSsn);
_employees.get2(someImpId);
```
Or even
```
_employees.remove1(someImpId);
```
I am not sure why I wan... | My first thought was: the easiest way to do this, I think, would be two maps.
```
Map< String, Map< String,Employee> > _employees;
```
But from what it looks like, you just want to be able to look up an employee by either SSN or ID. What's to stop you then from making two maps, or at worst a class that contains two ... |
311,117 | <p>I need a type which can contain a position of an object in a 3D environment - my house.</p>
<p>I need to know the floor it is on, and the x and Y coordinates on that floor.</p>
<p>The System.Windows.Point(int, int) only represent a two-dimensional space, but does .NET have a type for three-dimensional space?</p>
... | [
{
"answer_id": 311127,
"author": "Slav",
"author_id": 22680,
"author_profile": "https://Stackoverflow.com/users/22680",
"pm_score": 0,
"selected": false,
"text": "<p>I don't think there is built in functionality like that. </p>\n\n<p>But check out this CodeProject article <a href=\"http:... | 2008/11/22 | [
"https://Stackoverflow.com/questions/311117",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/33431/"
] | I need a type which can contain a position of an object in a 3D environment - my house.
I need to know the floor it is on, and the x and Y coordinates on that floor.
The System.Windows.Point(int, int) only represent a two-dimensional space, but does .NET have a type for three-dimensional space?
I realize that I coul... | In managed Direct3D there is a vector3 type that describes a point in space. It would be trivial to implement one yourself.
```
public struct Vector3
{
public float x;
public float y;
public float z;
}
``` |
311,131 | <p>I've written a WPF UserControl, and want to add one or more of it to my Window at runtime when I click a button. How can I do that?</p>
<p>Edit: Further specification
I want to add the usercontrols to a Canvas, and put in a absolute position. The canvas is a drawing of the floors in my house, and each usercontrol h... | [
{
"answer_id": 311136,
"author": "Jobi Joy",
"author_id": 8091,
"author_profile": "https://Stackoverflow.com/users/8091",
"pm_score": 2,
"selected": false,
"text": "<p>Add a StackPanel to the window and on each button click,</p>\n\n<pre><code> _stackPanel.Children.Add(new YourControl());... | 2008/11/22 | [
"https://Stackoverflow.com/questions/311131",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/33431/"
] | I've written a WPF UserControl, and want to add one or more of it to my Window at runtime when I click a button. How can I do that?
Edit: Further specification
I want to add the usercontrols to a Canvas, and put in a absolute position. The canvas is a drawing of the floors in my house, and each usercontrol has propert... | After you add the your control to the Canvas you need to specify the top and left co-ordinates using the Canvas.Top and Canvas.Left attached properties as follows.
```
var light = new LightUserControl(2);
HouseCanvas.Children.Add(light);
Canvas.SetLeft(light, 20);
Canvas.SetTop(light, 20);
``` |
311,154 | <p>I have a .fla file with some text that I want to get at. Is there a free app than you can use to open .fla files, or just a tool to dump strings and pics?</p>
| [
{
"answer_id": 311170,
"author": "PhiLho",
"author_id": 15459,
"author_profile": "https://Stackoverflow.com/users/15459",
"pm_score": 3,
"selected": false,
"text": "<p>With such question, I just experiment...</p>\n\n<p>I went to deviantART, went to the <a href=\"http://browse.deviantart.... | 2008/11/22 | [
"https://Stackoverflow.com/questions/311154",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2942/"
] | I have a .fla file with some text that I want to get at. Is there a free app than you can use to open .fla files, or just a tool to dump strings and pics? | With such question, I just experiment...
I went to deviantART, went to the [Flash .FLA Files](http://browse.deviantart.com/resources/applications/flash/ "Flash .FLA Files") gallery and downloaded one at random.
I got a .fla file of about 1MB.
I went to Sysinternals's site to get the latest version of [Strings](htt... |
311,165 | <p>How can you convert a byte array to a hexadecimal string and vice versa?</p>
| [
{
"answer_id": 311179,
"author": "Tomalak",
"author_id": 18771,
"author_profile": "https://Stackoverflow.com/users/18771",
"pm_score": 12,
"selected": true,
"text": "<p>You can use <a href=\"https://learn.microsoft.com/en-us/dotnet/api/system.convert.tohexstring\" rel=\"noreferrer\"><cod... | 2008/11/22 | [
"https://Stackoverflow.com/questions/311165",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19582/"
] | How can you convert a byte array to a hexadecimal string and vice versa? | You can use [`Convert.ToHexString`](https://learn.microsoft.com/en-us/dotnet/api/system.convert.tohexstring) starting with .NET 5.
There's also a method for the reverse operation: [`Convert.FromHexString`](https://learn.microsoft.com/en-us/dotnet/api/system.convert.fromhexstring).
---
For older versions of .NET y... |
311,166 | <p>When using the <a href="http://en.wikipedia.org/wiki/Pimpl_idiom" rel="nofollow noreferrer">pImpl idiom</a> is it preferable to use a <code>boost:shared_ptr</code> instead of a <code>std::auto_ptr</code>? I'm sure I once read that the boost version is more exception friendly?</p>
<pre><code>class Foo
{
public:
... | [
{
"answer_id": 311180,
"author": "Marco M.",
"author_id": 28375,
"author_profile": "https://Stackoverflow.com/users/28375",
"pm_score": -1,
"selected": false,
"text": "<p>Don't try so hard to shoot yourself in the foot, in C++ you have plenty of opportunities :)\nThere is no real need to... | 2008/11/22 | [
"https://Stackoverflow.com/questions/311166",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9236/"
] | When using the [pImpl idiom](http://en.wikipedia.org/wiki/Pimpl_idiom) is it preferable to use a `boost:shared_ptr` instead of a `std::auto_ptr`? I'm sure I once read that the boost version is more exception friendly?
```
class Foo
{
public:
Foo();
private:
struct impl;
std::auto_ptr<impl> impl_;
};
class... | You shouldn't really use std::auto\_ptr for this. The destructor won't be visible at the point you declare the std::auto\_ptr, so it might not be called properly. This is assuming that you are forward declaring your pImpl class, and creating the instance inside the constructor in another file.
If you use [boost::scope... |
311,184 | <p>I'm using Oracle 10g and I'm trying to "stack" the conditions in a CASE statement, like I would do in C++ :</p>
<pre><code>case 1:
case 2:
// instructions
break;
</code></pre>
<p>i.e. having the same code block executed for two different successful conditions.</p>
<p>I've tried :</p>
<pre><code>WHEN 1, 2... | [
{
"answer_id": 311208,
"author": "WW.",
"author_id": 14663,
"author_profile": "https://Stackoverflow.com/users/14663",
"pm_score": 6,
"selected": true,
"text": "<p>You need to use this format:</p>\n\n<pre><code>CASE\n WHEN v_n = 1 OR v_n = 2 THEN\n dbms_output.put_line('Case 1 or 2')... | 2008/11/22 | [
"https://Stackoverflow.com/questions/311184",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/77004/"
] | I'm using Oracle 10g and I'm trying to "stack" the conditions in a CASE statement, like I would do in C++ :
```
case 1:
case 2:
// instructions
break;
```
i.e. having the same code block executed for two different successful conditions.
I've tried :
```
WHEN 1, 2 THEN
WHEN 1 OR 2 THEN
```
... without luc... | You need to use this format:
```
CASE
WHEN v_n = 1 OR v_n = 2 THEN
dbms_output.put_line('Case 1 or 2');
WHEN v_n = 3 THEN
dbms_output.put_line('Case 3');
END CASE;
``` |
311,188 | <p>I am using django 1.0 and I have created my models using the example in the Django book. I am able to perform the basic function of adding data; now I need a way of retrieving that data, loading it into a form (change_form?! or something), <b>EDIT</b> it and save it back to the DB. Secondly how do I <b>DELETE</b> t... | [
{
"answer_id": 311191,
"author": "Vasil",
"author_id": 7883,
"author_profile": "https://Stackoverflow.com/users/7883",
"pm_score": 5,
"selected": false,
"text": "<p>Say you have a model Employee. To edit an entry with primary key emp_id you do:</p>\n\n<pre><code>emp = Employee.objects.ge... | 2008/11/22 | [
"https://Stackoverflow.com/questions/311188",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20894/"
] | I am using django 1.0 and I have created my models using the example in the Django book. I am able to perform the basic function of adding data; now I need a way of retrieving that data, loading it into a form (change\_form?! or something), **EDIT** it and save it back to the DB. Secondly how do I **DELETE** the data t... | Say you have a model Employee. To edit an entry with primary key emp\_id you do:
```
emp = Employee.objects.get(pk = emp_id)
emp.name = 'Somename'
emp.save()
```
to delete it just do:
```
emp.delete()
```
so a full view would be:
```
def update(request, id):
emp = Employee.objects.get(pk = id)
#you can do ... |
311,193 | <p>I am migrating an application from .NET 1.1 to .NET 2.0. Should I remove all uses of CollectionBase? If so, what is the best strategy for migration?</p>
| [
{
"answer_id": 311195,
"author": "Mark Ingram",
"author_id": 986,
"author_profile": "https://Stackoverflow.com/users/986",
"pm_score": 6,
"selected": true,
"text": "<p>Yes, the best classes to look at are in System.Collections.Generic.<br>\nI usually use List.</p>\n\n<p>There are two app... | 2008/11/22 | [
"https://Stackoverflow.com/questions/311193",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4653/"
] | I am migrating an application from .NET 1.1 to .NET 2.0. Should I remove all uses of CollectionBase? If so, what is the best strategy for migration? | Yes, the best classes to look at are in System.Collections.Generic.
I usually use List.
There are two approaches you can use either:
**A**
```
public class MyClass
{
public List<MyItem> Items;
}
```
**B**
```
public class MyItemCollection : List<MyItem>
{
}
public class MyClass
{
public MyItemCollection I... |
311,206 | <p>I have these 2 vectors:</p>
<pre><code>alpha =
1 1 1 1 1 1 1 1 1
f_uv =
193 193 194 192 193 193 190 189 191
</code></pre>
<p>And when I do this:</p>
<pre><code>alphaf_uv = alpha * f_uv'
</code></pre>
<p>I get the error message:</p>
<pre><code>"??? Error using ==> mtim... | [
{
"answer_id": 311209,
"author": "paxdiablo",
"author_id": 14860,
"author_profile": "https://Stackoverflow.com/users/14860",
"pm_score": 5,
"selected": true,
"text": "<p>Assuming they're both integer matrices to begin with, <code>f_uv'</code> may not be.</p>\n\n<p>Try:</p>\n\n<pre><code>... | 2008/11/22 | [
"https://Stackoverflow.com/questions/311206",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/38721/"
] | I have these 2 vectors:
```
alpha =
1 1 1 1 1 1 1 1 1
f_uv =
193 193 194 192 193 193 190 189 191
```
And when I do this:
```
alphaf_uv = alpha * f_uv'
```
I get the error message:
```
"??? Error using ==> mtimes
Integers can only be combined with integers of the same clas... | Assuming they're both integer matrices to begin with, `f_uv'` may not be.
Try:
```
alphaf_uv = double(alpha) * double(f_uv')
```
and let us know if it still occurs.
You may need to turn `alphaf_uv` back into an integer type afterwards, depending on your needs. |
311,221 | <p>If you had a 10 minute hands-on session to teach someone Emacs, what would you show them?</p>
<pre>
Start emacs: emacs
...
Quit emacs: C-x C-c
</pre>
<p>What else would you have them do between starting and quitting Emacs, while you stood behind them?</p>
| [
{
"answer_id": 311225,
"author": "Ulf Lindback",
"author_id": 30354,
"author_profile": "https://Stackoverflow.com/users/30354",
"pm_score": 4,
"selected": false,
"text": "<p>Show them how to start the tutorial: C-h t</p>\n"
},
{
"answer_id": 311226,
"author": "Johannes Schaub... | 2008/11/22 | [
"https://Stackoverflow.com/questions/311221",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | If you had a 10 minute hands-on session to teach someone Emacs, what would you show them?
```
Start emacs: emacs
...
Quit emacs: C-x C-c
```
What else would you have them do between starting and quitting Emacs, while you stood behind them? | If I had only 10 minutes, I would not teach them any shortcuts at all. All the common shortcuts are available next to the corresponding commands in the menus; those the users can discover for themselves.
The most important things to teach are those that will enable the users to discover/learn by themselves:
* That on... |
311,242 | <p>I'm new to PHP and I'm trying to do something that may be bad practise and may well be impossible. I'm basically just hacking something together to test my knowledge and see what PHP can do.</p>
<p>I have one webpage with a form that collects data. That is submited to a PHP script that does a bunch of processing - ... | [
{
"answer_id": 311265,
"author": "NiklasMM",
"author_id": 37758,
"author_profile": "https://Stackoverflow.com/users/37758",
"pm_score": -1,
"selected": false,
"text": "<p>I hope i got your qestion right.\nYou might try this:</p>\n\n<ol>\n<li>Adjust your form to look like this:</li>\n</ol... | 2008/11/22 | [
"https://Stackoverflow.com/questions/311242",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/39905/"
] | I'm new to PHP and I'm trying to do something that may be bad practise and may well be impossible. I'm basically just hacking something together to test my knowledge and see what PHP can do.
I have one webpage with a form that collects data. That is submited to a PHP script that does a bunch of processing - but doesn'... | Is it really necessary to call another page after the processing is done? I'd probably do the following:
```
<form method="post" action="display.php">
...
</form>
```
display.php:
```
if ($_POST) {
require_once(process.php);
process($_POST);
display_results;
}
```
with process.php containing the code ... |
311,243 | <p>I have a Java application and I would like to make it extensible. To create an extension, developers within our company will write a Java class that implements a certain interface. They may also wish to write associated helper classes. I would like to load these extensions into the application without an outage.<... | [
{
"answer_id": 311266,
"author": "mkoeller",
"author_id": 33433,
"author_profile": "https://Stackoverflow.com/users/33433",
"pm_score": 2,
"selected": false,
"text": "<p>I don't know the implementation details, but it seems what you have in mind comes close to what the <a href=\"http://t... | 2008/11/22 | [
"https://Stackoverflow.com/questions/311243",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14663/"
] | I have a Java application and I would like to make it extensible. To create an extension, developers within our company will write a Java class that implements a certain interface. They may also wish to write associated helper classes. I would like to load these extensions into the application without an outage.
I wou... | You don't need to look for anything exotic. Handling this scenario is a fundamental feature of the Java security architecture.
Every class has a "codebase", the location from which it was loaded. So if you package each extension in a separate JAR (or exploded in a separate directory), you'll be able tailor the permiss... |
311,247 | <p>In short: what is the best way to design and implement a factory+plugin mechanism, so that plugins can replace objects in the main application.</p>
<p>We have a code base from which we build our applications. The code base is fine for 70-95% of the applications, meaning that in each new application we need to chang... | [
{
"answer_id": 311373,
"author": "Baget",
"author_id": 34369,
"author_profile": "https://Stackoverflow.com/users/34369",
"pm_score": 1,
"selected": false,
"text": "<p>Did you look at CodeProject examples for plugins frameworks?\n<a href=\"https://secure.codeproject.com/KB/DLL/plugin.aspx... | 2008/11/22 | [
"https://Stackoverflow.com/questions/311247",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/33982/"
] | In short: what is the best way to design and implement a factory+plugin mechanism, so that plugins can replace objects in the main application.
We have a code base from which we build our applications. The code base is fine for 70-95% of the applications, meaning that in each new application we need to change 5-30% of... | There was an article a while back in Doctor Dobb's that discussed this exact problem. Here is [a link](http://www.ddj.com/cpp/204202899) to the article in question.
As an aside you may want to stick with a straight C interface for the plugins to your project. That way you can link code written in almost any language i... |
311,249 | <p>What are the hidden features of Maven2?</p>
| [
{
"answer_id": 311254,
"author": "Kuukage",
"author_id": 39907,
"author_profile": "https://Stackoverflow.com/users/39907",
"pm_score": 1,
"selected": false,
"text": "<p>With maven-dependency-plugin it's possible to resolve dependency conflicts and cyclic dependency problems. </p>\n\n<p>A... | 2008/11/22 | [
"https://Stackoverflow.com/questions/311249",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/39907/"
] | What are the hidden features of Maven2? | You can use the settings.xml to force ALL maven builds running on your local machine to also use a locally installed maven proxy. Saving yourself and the network time.
```
<settings xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://ma... |
311,250 | <p>Okay, I have a FormView with a couple of child controls in an InsertItemTemplate. One of them is a DropDownList, called DdlAssigned. I reference it in the Page's OnLoad method like so:</p>
<pre><code>protected void Page_Load(object sender, EventArgs e)
{
((DropDownList)FrmAdd.FindControl("DdlAssigned")).Selecte... | [
{
"answer_id": 312196,
"author": "Dusda",
"author_id": 36411,
"author_profile": "https://Stackoverflow.com/users/36411",
"pm_score": 3,
"selected": true,
"text": "<p>I figured it out. I'm still missing exactly why it doesn't work just on FormLoad, but performing the change in the FormVie... | 2008/11/22 | [
"https://Stackoverflow.com/questions/311250",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/36411/"
] | Okay, I have a FormView with a couple of child controls in an InsertItemTemplate. One of them is a DropDownList, called DdlAssigned. I reference it in the Page's OnLoad method like so:
```
protected void Page_Load(object sender, EventArgs e)
{
((DropDownList)FrmAdd.FindControl("DdlAssigned")).SelectedValue =
... | I figured it out. I'm still missing exactly why it doesn't work just on FormLoad, but performing the change in the FormView's DataBound event does the trick.
```
protected void FrmAdd_DataBound(object sender, EventArgs e)
{
// This is the same code as before, but done in the FormView's DataBound event.
((DropD... |
311,268 | <p>In short: I want to monitor selected calls from an application to a DLL.</p>
<p>We have an old VB6 application for which we lost the source code (the company wasn't using source control back then..). This application uses a 3rd party DLL.</p>
<p>I want to use this DLL in a new C++ application. Unfortunately the DL... | [
{
"answer_id": 311272,
"author": "VonC",
"author_id": 6309,
"author_profile": "https://Stackoverflow.com/users/6309",
"pm_score": 5,
"selected": false,
"text": "<p>A \"static\" solution (in the sense it can capture a stack trace on demand) would be <a href=\"http://technet.microsoft.com/... | 2008/11/22 | [
"https://Stackoverflow.com/questions/311268",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/33982/"
] | In short: I want to monitor selected calls from an application to a DLL.
We have an old VB6 application for which we lost the source code (the company wasn't using source control back then..). This application uses a 3rd party DLL.
I want to use this DLL in a new C++ application. Unfortunately the DLL API is only par... | Some more Google searching found what I was looking for: [WinAPIOverride32](http://jacquelin.potier.free.fr/winapioverride32/). It allows writing text files such as:
```
CustomApi.dll|void NameOfFunction(long param1, double& param2);
```
Later on, these files can be used inside the program to log all calls to `NameO... |
311,274 | <p>If have a set of classes that all implement an interface. </p>
<pre><code>interface IMyinterface<T>
{
int foo(T Bar);
}
</code></pre>
<p>I want to shove them all in a list and enumerate through them. </p>
<pre><code> List<IMyinterface> list
foreach(IMyinterface in list)
// etc...
</code></pre... | [
{
"answer_id": 311288,
"author": "AnthonyWJones",
"author_id": 17516,
"author_profile": "https://Stackoverflow.com/users/17516",
"pm_score": 4,
"selected": true,
"text": "<p>There is no IMyinterface type there is only a IMyinterface`1 type which will require a type argument. You could c... | 2008/11/22 | [
"https://Stackoverflow.com/questions/311274",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1116/"
] | If have a set of classes that all implement an interface.
```
interface IMyinterface<T>
{
int foo(T Bar);
}
```
I want to shove them all in a list and enumerate through them.
```
List<IMyinterface> list
foreach(IMyinterface in list)
// etc...
```
but the compiler wants to know what T is. Can I do this?... | There is no IMyinterface type there is only a IMyinterface`1 type which will require a type argument. You could create an IMyinterface type:-
```
interface IMyinterface { ... }
```
then inherit from it
```
interface IMyinterface<T> : IMyinterface { ... }
```
You would need to move any members you would like to us... |
311,276 | <p>Just could not get this one and googling did not help much either.. </p>
<p>First something that I know: Given a string and a regex, how to replace all the occurrences of strings that matches this regular expression by a replacement string ? Use the <a href="http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.... | [
{
"answer_id": 311286,
"author": "VonC",
"author_id": 6309,
"author_profile": "https://Stackoverflow.com/users/6309",
"pm_score": 4,
"selected": true,
"text": "<pre><code>[^a-zA-Z]+\n</code></pre>\n\n<p>Will do it nicely.</p>\n\n<p>You just need a <a href=\"http://www.regular-expressions... | 2008/11/22 | [
"https://Stackoverflow.com/questions/311276",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/27474/"
] | Just could not get this one and googling did not help much either..
First something that I know: Given a string and a regex, how to replace all the occurrences of strings that matches this regular expression by a replacement string ? Use the [replaceAll()](http://java.sun.com/j2se/1.5.0/docs/api/java/lang/String.html... | ```
[^a-zA-Z]+
```
Will do it nicely.
You just need a [greedy quantifier](http://www.regular-expressions.info/repeat.html) in order to match as many non-alphabetical characters you can, and replace the all match by one '+' (a - by default - greedy quantifier)
Note: `[^a-zA-Z]+?` would make the '+' quantifier lazy, ... |
311,299 | <p>I need to extract multiple text/dropdown list fields from an asp.net form and format appropriately ready for sending to recipient via email.</p>
<p>What's the best way of reading those fields without having to hard code each item such as: </p>
<pre><code>item1 = InputField1.Text;
item2 = InputField2.Text;
</code... | [
{
"answer_id": 311312,
"author": "Chris",
"author_id": 34942,
"author_profile": "https://Stackoverflow.com/users/34942",
"pm_score": 0,
"selected": false,
"text": "<p>Not sure why you're trying to do this - without more info it seems like you're probably taking an approach that is sub-op... | 2008/11/22 | [
"https://Stackoverflow.com/questions/311299",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/26809/"
] | I need to extract multiple text/dropdown list fields from an asp.net form and format appropriately ready for sending to recipient via email.
What's the best way of reading those fields without having to hard code each item such as:
```
item1 = InputField1.Text;
item2 = InputField2.Text;
```
I will have about 10 ... | @Chris has given you the basic idea -- copy out of the Request.Form collection. I would suggest that to make it easier, you give the inputs names that you can easily detect from the other fields on the page, some of which may be placed there for you by the framework. Perhaps use a naming scheme like "Email.FirstName", ... |
311,346 | <p>Is there any reason to start a GUI program (application for Windows) written in VB.NET in the Sub Main of a module rather than directly in a form?</p>
<p>EDIT: The program won't take any command line parameters and it will be executed as a GUI program always.</p>
| [
{
"answer_id": 311351,
"author": "Arvo",
"author_id": 35777,
"author_profile": "https://Stackoverflow.com/users/35777",
"pm_score": 0,
"selected": false,
"text": "<p>No, if you always want to show that form.<br>\nYes, if you sometimes want to use your app without GUI, just using command ... | 2008/11/22 | [
"https://Stackoverflow.com/questions/311346",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/38561/"
] | Is there any reason to start a GUI program (application for Windows) written in VB.NET in the Sub Main of a module rather than directly in a form?
EDIT: The program won't take any command line parameters and it will be executed as a GUI program always. | The primary reason for using Main() in VB .NET 1.x was for adding code that needed to run before any forms were loaded. For example, you might want to detect whether an instance of your Windows Forms app was already loaded. Or you might want to intercept any unhandled exception for the AppDomain:
```
AddHandler AppDom... |
311,389 | <p>I've created a login submit form in HTML but for some reason autocompletion does not work in firefox.</p>
<p>This is what happens in Firefox:
- I give username and password and click on the login button
- Firefox prompts me if I would like to remember the password. I press 'remember' and login works.
- I log out an... | [
{
"answer_id": 311541,
"author": "John Topley",
"author_id": 1450,
"author_profile": "https://Stackoverflow.com/users/1450",
"pm_score": 2,
"selected": false,
"text": "<p>Does your login URL include a session ID that changes each time?</p>\n"
},
{
"answer_id": 311582,
"author... | 2008/11/22 | [
"https://Stackoverflow.com/questions/311389",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | I've created a login submit form in HTML but for some reason autocompletion does not work in firefox.
This is what happens in Firefox:
- I give username and password and click on the login button
- Firefox prompts me if I would like to remember the password. I press 'remember' and login works.
- I log out and return t... | Does your login URL include a session ID that changes each time? |
311,399 | <p>Does anyone know where I can find an example of how to determine if the Maximize and/or Minimize buttons on a window are available and/or disabled?</p>
<p>The window will not be in the same process as my application. I have the hWnd and I have tried using GetMenuItemInfo, but I can't find any good samples for how ... | [
{
"answer_id": 311409,
"author": "Asher",
"author_id": 38265,
"author_profile": "https://Stackoverflow.com/users/38265",
"pm_score": 0,
"selected": false,
"text": "<p>Use the <a href=\"http://msdn.microsoft.com/en-us/library/ms633516(VS.85).aspx\" rel=\"nofollow noreferrer\">GetWindowInf... | 2008/11/22 | [
"https://Stackoverflow.com/questions/311399",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/39171/"
] | Does anyone know where I can find an example of how to determine if the Maximize and/or Minimize buttons on a window are available and/or disabled?
The window will not be in the same process as my application. I have the hWnd and I have tried using GetMenuItemInfo, but I can't find any good samples for how to do this.... | ```
bool has_maximize_btn = (GetWindowLong(hWnd, GWL_STYLE) & WS_MAXIMIZEBOX) != 0;
bool has_minimize_btn = (GetWindowLong(hWnd, GWL_STYLE) & WS_MINIMIZEBOX) != 0;
``` |
311,408 | <p>I'm using hibernate 3 and want to stop it from dumping all the startup messages to the console. I tried commenting out the stdout lines in log4j.properties but no luck. I've pasted my log file below. Also I'm using eclipse with the standard project structure and have a copy of log4j.properties in both the root of th... | [
{
"answer_id": 311445,
"author": "Juha Syrjälä",
"author_id": 1431,
"author_profile": "https://Stackoverflow.com/users/1431",
"pm_score": 7,
"selected": true,
"text": "<p>Try to set more reasonable logging level. Setting logging level to <code>info</code> means that only log event at <co... | 2008/11/22 | [
"https://Stackoverflow.com/questions/311408",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14744/"
] | I'm using hibernate 3 and want to stop it from dumping all the startup messages to the console. I tried commenting out the stdout lines in log4j.properties but no luck. I've pasted my log file below. Also I'm using eclipse with the standard project structure and have a copy of log4j.properties in both the root of the p... | Try to set more reasonable logging level. Setting logging level to `info` means that only log event at `info` or higher level (`warn`, `error` and `fatal`) are logged, that is `debug` logging events are ignored.
```
log4j.logger.org.hibernate=info
```
or in [XML version](http://wiki.apache.org/logging-log4j/Log4jXml... |
311,432 | <p>With generics, is there ever a reason to create specific derived EventArg classes</p>
<p>It seems like now you can simply use them on the fly with a generic implementation.</p>
<p>Should i go thorugh all of my examples and remove my eventArg classes (StringEventArgs, MyFooEventArgs, etc . .)</p>
<pre><code>public... | [
{
"answer_id": 311442,
"author": "Jonas Oberschweiber",
"author_id": 1522,
"author_profile": "https://Stackoverflow.com/users/1522",
"pm_score": 0,
"selected": false,
"text": "<p>As TcKs already said: Use <code>EventArgs<T></code> if you only need to pass one value, otherwise deriv... | 2008/11/22 | [
"https://Stackoverflow.com/questions/311432",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4653/"
] | With generics, is there ever a reason to create specific derived EventArg classes
It seems like now you can simply use them on the fly with a generic implementation.
Should i go thorugh all of my examples and remove my eventArg classes (StringEventArgs, MyFooEventArgs, etc . .)
```
public class EventArgs<T> : EventA... | What you are describing are essentially [tuples](http://en.wikipedia.org/wiki/Tuple), grouped values used for a particular purpose. They are a useful construct in [functional programming](http://en.wikipedia.org/wiki/Functional_programming) and support that style very well.
The downside is that their values are not na... |
311,438 | <p>I have a simple web app, with a few jsp pages, servlets and pojo's. I want to initialise the connection pool before any requests are made. What is the best way to do this? Can it be done when the app is first deployed or do you have to wait till the first request comes in?</p>
| [
{
"answer_id": 311453,
"author": "Nerdfest",
"author_id": 7855,
"author_profile": "https://Stackoverflow.com/users/7855",
"pm_score": 0,
"selected": false,
"text": "<p>What about a basic startup servlet to initialise the connection pool?</p>\n"
},
{
"answer_id": 311482,
"auth... | 2008/11/22 | [
"https://Stackoverflow.com/questions/311438",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16684/"
] | I have a simple web app, with a few jsp pages, servlets and pojo's. I want to initialise the connection pool before any requests are made. What is the best way to do this? Can it be done when the app is first deployed or do you have to wait till the first request comes in? | Use a ServletContextListener and declare it properly in web.xml. This way is preferable to a startup servlet. It is more organized, and your intent is obvious. It is also guaranteed to run before any request. It also gives you a shutdown hook to clear the pool.
Here is a snippet from my web.xml, for example:
```
<lis... |
311,439 | <p>I am making a Color class, and provide a standard constructor like</p>
<pre><code>Color(int red, int green, int blue)
</code></pre>
<p>And then I want to provide an easy way to get the most common colors, like
Color.Blue, Color.Red. I see two possible options:</p>
<pre><code>public static readonly Color Red = new... | [
{
"answer_id": 311452,
"author": "Joe",
"author_id": 13087,
"author_profile": "https://Stackoverflow.com/users/13087",
"pm_score": 2,
"selected": false,
"text": "<p>Your reasoning and identification of the trade-off seems sound. If you look at the System.Drawing.Color structure, you'll ... | 2008/11/22 | [
"https://Stackoverflow.com/questions/311439",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/364245/"
] | I am making a Color class, and provide a standard constructor like
```
Color(int red, int green, int blue)
```
And then I want to provide an easy way to get the most common colors, like
Color.Blue, Color.Red. I see two possible options:
```
public static readonly Color Red = new Color(255, 0, 0);
public static Col... | I'm guessing that you're probably already aware that the framework provides a `Color` struct. I'm guessing that you're creating a `Color` class just for practice.
You expressed uncertainty about the meaning of the `static` keyword, although you've used it correctly. When `static` is applied to a member of a class or s... |
311,454 | <p>How would you format/indent this piece of code?</p>
<pre><code>int ID = Blahs.Add( new Blah( -1, -2, -3) );
</code></pre>
<p>or</p>
<pre><code>int ID = Blahs.Add( new Blah(
1,2,3,55
)
);
</code></pre>
<hr />
<h3>Edit:</h3>
<p>My class has lots of parameters actually, so that might effect your response.</p... | [
{
"answer_id": 311459,
"author": "bugmagnet",
"author_id": 426,
"author_profile": "https://Stackoverflow.com/users/426",
"pm_score": 2,
"selected": false,
"text": "<p>or </p>\n\n<pre><code>int ID = Blahs.Add( \n new Blah( 1, 2, 3, 55 ) \n );\n</code></pre>\n\n... | 2008/11/22 | [
"https://Stackoverflow.com/questions/311454",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | How would you format/indent this piece of code?
```
int ID = Blahs.Add( new Blah( -1, -2, -3) );
```
or
```
int ID = Blahs.Add( new Blah(
1,2,3,55
)
);
```
---
### Edit:
My class has lots of parameters actually, so that might effect your response. | I agree with Patrick McElhaney; there is no need to nest it....
```
Blah aBlah = new Blah( 1, 2, 3, 55 );
int ID = Blahas.Add( aBlah );
```
There are a couple of small advantage here:
1. You can set a break point on the second line and inspect 'aBlah'.
2. Your diffs will be cleaner (changes more obvious) without ne... |
311,460 | <p>I'm trying to read data from a.csv file to ouput it on a webpage as text.</p>
<p>It's the first time I'm doing this and I've run into a nasty little problem.</p>
<p>My .csv file(which gets openened by Excel by default), has multiple rows and I read the entire thing as one long string.</p>
<p>like this:</p>
<pre>... | [
{
"answer_id": 311467,
"author": "Davide Gualano",
"author_id": 28582,
"author_profile": "https://Stackoverflow.com/users/28582",
"pm_score": 1,
"selected": false,
"text": "<p>The <a href=\"http://it.php.net/file\" rel=\"nofollow noreferrer\">file()</a> function reads a file in an array,... | 2008/11/22 | [
"https://Stackoverflow.com/questions/311460",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11795/"
] | I'm trying to read data from a.csv file to ouput it on a webpage as text.
It's the first time I'm doing this and I've run into a nasty little problem.
My .csv file(which gets openened by Excel by default), has multiple rows and I read the entire thing as one long string.
like this:
```
$contents = file_get_contents... | You are better off using [fgetcsv()](http://www.php.net/fgetcsv) which is aware of CSV file structure and has designated options for handling CSV files. Alternatively, you can use [str\_getcsv()](http://www.php.net/manual/en/function.str-getcsv.php) on the contents of the file instead. |
311,463 | <p>I can follow most of Apple's WiTap sample, but am sort of stumped on this bit in the send method:</p>
<pre><code>- (void) send:(const uint8_t)message
{
if (_outStream && [_outStream hasSpaceAvailable])
if([_outStream write:(const uint8_t *)&message maxLength:sizeof(const uint8_t)] == -1)
[se... | [
{
"answer_id": 311487,
"author": "Ben Gottlieb",
"author_id": 6694,
"author_profile": "https://Stackoverflow.com/users/6694",
"pm_score": 3,
"selected": true,
"text": "<p>Basically, <code>[view tag] | 0x80</code> is setting the high bit in that value (so 00010011 would become 10010011) a... | 2008/11/22 | [
"https://Stackoverflow.com/questions/311463",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/39932/"
] | I can follow most of Apple's WiTap sample, but am sort of stumped on this bit in the send method:
```
- (void) send:(const uint8_t)message
{
if (_outStream && [_outStream hasSpaceAvailable])
if([_outStream write:(const uint8_t *)&message maxLength:sizeof(const uint8_t)] == -1)
[self _showAlert:@"Failed sen... | Basically, `[view tag] | 0x80` is setting the high bit in that value (so 00010011 would become 10010011) and `[view tag] & 0x7f` is removing it (10010011 -> 00010011).
Take a look at the `[AppController stream:handleEvent:]` method. You'll see this code:
```
//We received a remote tap update, forward it to t... |
311,479 | <p>Is there a less resource intensive / faster way of performing this query (which is partly based upon: <a href="https://stackoverflow.com/questions/311390/mysql-a-search-a-select-of-multiple-rows-joining-and-all-in-one-query">This StackOverflow question</a> ). Currently it takes 0.008 seconds searching through only a... | [
{
"answer_id": 311506,
"author": "tvanfosson",
"author_id": 12950,
"author_profile": "https://Stackoverflow.com/users/12950",
"pm_score": 2,
"selected": false,
"text": "<p>I would hope that the query optimizer would do this for you, but you might want to try doing the select on tags by u... | 2008/11/22 | [
"https://Stackoverflow.com/questions/311479",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | Is there a less resource intensive / faster way of performing this query (which is partly based upon: [This StackOverflow question](https://stackoverflow.com/questions/311390/mysql-a-search-a-select-of-multiple-rows-joining-and-all-in-one-query) ). Currently it takes 0.008 seconds searching through only a dozen or so r... | I would hope that the query optimizer would do this for you, but you might want to try doing the select on tags by user\_id before doing the join just in case in the first subquery. This would reduce the number of rows that you would have to join across presumably. You also probably want to have indexes on auto\_id AND... |
311,496 | <p>Does anyone know how you setup new commands to launch an application from the Start->Run box?</p>
<p>ie. you can type "firefox", "winword" or "excel" into the Run box and those applications will open even though they're not in the system path, but others won't. For example, with Firefox, there's no files named fire... | [
{
"answer_id": 311500,
"author": "Kawa",
"author_id": 39926,
"author_profile": "https://Stackoverflow.com/users/39926",
"pm_score": 0,
"selected": false,
"text": "<p>Run works with search paths, which include the Path environment variable and some others. There might be more information ... | 2008/11/22 | [
"https://Stackoverflow.com/questions/311496",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/32795/"
] | Does anyone know how you setup new commands to launch an application from the Start->Run box?
ie. you can type "firefox", "winword" or "excel" into the Run box and those applications will open even though they're not in the system path, but others won't. For example, with Firefox, there's no files named firefox.\* in ... | From <http://commandwindows.com/runline.htm>:
>
> **Adding applications to the Path**
>
>
> Alternatively, the Registry can be
> edited to explicitly contain the path
> to the desired executable file or
> files. The Registry key involved
> isHKEY\_LOCAL\_MACHINE\Software\Microsoft\Windows\CurrentVersion\App
> Paths... |
311,501 | <p>If tan(x) = y and atan(y) = x why Math.Atan(Math.Tan(x)) != x?</p>
<p>I´m trying to calculate x in something like: </p>
<pre><code>tan(2/x +3) = 5
</code></pre>
<p>so </p>
<pre><code>atan(tan(2/x + 3) = atan(5)
</code></pre>
<p>and so on... but I´ve tried this: </p>
<pre><code>double d = Math.Atan(Math.Tan(10... | [
{
"answer_id": 311510,
"author": "flolo",
"author_id": 36472,
"author_profile": "https://Stackoverflow.com/users/36472",
"pm_score": 3,
"selected": false,
"text": "<p>I dont know any C#, but maths says that tan is not invertable, only in a small intervall.</p>\n\n<p>e.g. tan(pi) = 0 and ... | 2008/11/22 | [
"https://Stackoverflow.com/questions/311501",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | If tan(x) = y and atan(y) = x why Math.Atan(Math.Tan(x)) != x?
I´m trying to calculate x in something like:
```
tan(2/x +3) = 5
```
so
```
atan(tan(2/x + 3) = atan(5)
```
and so on... but I´ve tried this:
```
double d = Math.Atan(Math.Tan(10));
```
and d != 10. Why? | 1. The tangent function is periodic with period pi, and is invertible *only* if you restrict it to a subset of its domain over which it is injective. Usually the choice of such set is the open interval ]-pi/2, pi/2[, hence the arctan function will always return a point in that interval. In your case, 10 = 3\*pi + 0.575... |
311,504 | <p>In Firefox and Safari, pages that are centered move a few pixels when the page is long enough for the scrollbar to appear. If you navigate through a site that has long and short pages, the page seems to "jump" around.</p>
<p>IE7 tends to leave the scroll bar visible all of the time but disables it when the page is... | [
{
"answer_id": 311514,
"author": "Pim Jager",
"author_id": 35197,
"author_profile": "https://Stackoverflow.com/users/35197",
"pm_score": 5,
"selected": true,
"text": "<p>You could simply always enable the scrollbar:</p>\n\n<pre><code>html{\n overflow: scroll;\n}\n</code></pre>\n\n<p>but ... | 2008/11/22 | [
"https://Stackoverflow.com/questions/311504",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/30552/"
] | In Firefox and Safari, pages that are centered move a few pixels when the page is long enough for the scrollbar to appear. If you navigate through a site that has long and short pages, the page seems to "jump" around.
IE7 tends to leave the scroll bar visible all of the time but disables it when the page is not long e... | You could simply always enable the scrollbar:
```
html{
overflow: scroll;
}
```
but that would give you the horizontal scrollbar too, this is better:
```
html{
overflow-y:scroll;
overflow-x:auto;
}
```
That will give you only the vertical scroll and the horizontal when needed. |
311,543 | <p>Edit:</p>
<p>I don't know what this user originally wanted, and hopefully they'll edit their question to let us know, but otherwise, let's use this question to answer (or give links to) the following common console window issues:</p>
<ul>
<li>How do you capture the output of a console application in your program (... | [
{
"answer_id": 311548,
"author": "eswald",
"author_id": 21229,
"author_profile": "https://Stackoverflow.com/users/21229",
"pm_score": 0,
"selected": false,
"text": "<p>If it's a graphical application that happens to write messages to standard output, open your favorite terminal applicati... | 2008/11/22 | [
"https://Stackoverflow.com/questions/311543",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | Edit:
I don't know what this user originally wanted, and hopefully they'll edit their question to let us know, but otherwise, let's use this question to answer (or give links to) the following common console window issues:
* How do you capture the output of a console application in your program (for instance, running... | Keeping the console window open in for C++ in a standard's compliant way (not platform specific):
```
#include <iostream>
#include <limits>
int main() {
// Rest of the code
//Clean the stream and ask for input
std::cin.ignore ( std::numeric_limits<std::streamsize>::max(), '\n' );
std::cin.get();
retur... |
311,576 | <p>Given say 11/13/2008 - 12/11/2008 as the value posted back in TextBox, what would be the best way to parse out the start and end date using C#?</p>
<p>I know I could use:</p>
<pre><code>DateTime startDate = Convert.ToDateTime(TextBoxDateRange.Text.Substring(0, 10));
DateTime endDate = Convert.ToDateTime(TextBoxDat... | [
{
"answer_id": 311583,
"author": "Bryan Watts",
"author_id": 37815,
"author_profile": "https://Stackoverflow.com/users/37815",
"pm_score": 4,
"selected": true,
"text": "<pre><code>var dates = TextBoxDateRange.Text.Split(new char[] { '-' }, StringSplitOptions.RemoveEmptyEntries);\n\nvar s... | 2008/11/22 | [
"https://Stackoverflow.com/questions/311576",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/25335/"
] | Given say 11/13/2008 - 12/11/2008 as the value posted back in TextBox, what would be the best way to parse out the start and end date using C#?
I know I could use:
```
DateTime startDate = Convert.ToDateTime(TextBoxDateRange.Text.Substring(0, 10));
DateTime endDate = Convert.ToDateTime(TextBoxDateRange.Text.Substring... | ```
var dates = TextBoxDateRange.Text.Split(new char[] { '-' }, StringSplitOptions.RemoveEmptyEntries);
var startDate = DateTime.Parse(dates[0], CultureInfo.CurrentCulture);
var endDate = DateTime.Parse(dates[1], CultureInfo.CurrentCulture);
``` |
311,579 | <p>I have a web page with 3 forms on it. Not nested, just one after the other (they are almost identical, just one hidden variable that's different). A user will only fill in one form, and I'd like to validate/etc all the forms with only one JS script.</p>
<p>So how, when a user clicks the submit button of form#1, d... | [
{
"answer_id": 311589,
"author": "Eran Galperin",
"author_id": 10585,
"author_profile": "https://Stackoverflow.com/users/10585",
"pm_score": 9,
"selected": true,
"text": "<p>You can select the form like this:</p>\n\n<pre><code>$(\"#submit\").click(function(){\n var form = $(this).pare... | 2008/11/22 | [
"https://Stackoverflow.com/questions/311579",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | I have a web page with 3 forms on it. Not nested, just one after the other (they are almost identical, just one hidden variable that's different). A user will only fill in one form, and I'd like to validate/etc all the forms with only one JS script.
So how, when a user clicks the submit button of form#1, do I make my ... | You can select the form like this:
```
$("#submit").click(function(){
var form = $(this).parents('form:first');
...
});
```
However, it is generally better to attach the event to the submit event of the form itself, as it will trigger even when submitting by pressing the enter key from one of the fields:
``... |
311,588 | <p>List comprehensions can be useful in certain situations, but they can also be rather horrible to read.. As a slightly exaggerated example, how would you indent the following?</p>
<pre><code>allUuids = [x.id for x in self.db.query(schema.allPostsUuid).execute(timeout = 20) if x.type == "post" and x.deleted is not Fa... | [
{
"answer_id": 311590,
"author": "Eli Bendersky",
"author_id": 8206,
"author_profile": "https://Stackoverflow.com/users/8206",
"pm_score": 1,
"selected": false,
"text": "<p>How about:</p>\n\n<pre><code>allUuids = [x.id for x in self.db.query(schema.allPostsUuid).execute(timeout = 20) \n ... | 2008/11/22 | [
"https://Stackoverflow.com/questions/311588",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/745/"
] | List comprehensions can be useful in certain situations, but they can also be rather horrible to read.. As a slightly exaggerated example, how would you indent the following?
```
allUuids = [x.id for x in self.db.query(schema.allPostsUuid).execute(timeout = 20) if x.type == "post" and x.deleted is not False]
``` | It depends on how long they are. I tend to structure them like so:
```
[x.id for x
in self.db.query(schema.allPostsUuid).execute(timeout=20)
if x.type == 'post'
and x.deleted is not False
and ...
and ...]
```
That way every expression has its own line.
If any line becomes too big I like to extract it... |
311,601 | <p>I'm working in a windows environment (my laptop!) and I need a couple of scripts that run other programs, pretty much like a windows batch file.</p>
<p>how can I run a command from python such that the program when run, will replace the script? The program is interactive (for instance, unison) and keeps printing li... | [
{
"answer_id": 311613,
"author": "Piotr Lesnicki",
"author_id": 38796,
"author_profile": "https://Stackoverflow.com/users/38796",
"pm_score": 4,
"selected": false,
"text": "<p>You should create a new processess using the <a href=\"http://www.python.org/doc/2.5.2/lib/module-subprocess.htm... | 2008/11/22 | [
"https://Stackoverflow.com/questions/311601",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/35364/"
] | I'm working in a windows environment (my laptop!) and I need a couple of scripts that run other programs, pretty much like a windows batch file.
how can I run a command from python such that the program when run, will replace the script? The program is interactive (for instance, unison) and keeps printing lines and as... | I found out that os.system does what I want,
Thanks for all that tried to help.
```
os.system("dir")
```
runs the command just as if it was run from a batch file |
311,605 | <pre><code>var A = {
x : function () { }
};
var b = function (method) {
//want to know method's "parent" here
};
b(A.x);
</code></pre>
<p>I want to know that x is defined in A when I call the b(A.x). Is this possible?</p>
| [
{
"answer_id": 311617,
"author": "Kornel",
"author_id": 27009,
"author_profile": "https://Stackoverflow.com/users/27009",
"pm_score": 2,
"selected": false,
"text": "<p>There's no nice built-in way to do this, because actually there are no methods in Javascript. They are independent Funct... | 2008/11/22 | [
"https://Stackoverflow.com/questions/311605",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | ```
var A = {
x : function () { }
};
var b = function (method) {
//want to know method's "parent" here
};
b(A.x);
```
I want to know that x is defined in A when I call the b(A.x). Is this possible? | There's no nice built-in way to do this, because actually there are no methods in Javascript. They are independent Function objects that just happen to be assigned somewhere.
If you create new instance of function every time (e.g. closure) *[thanks Matthew Crumley for pointing that out]*, then you can modify the funct... |
311,626 | <p>I've been thinking lately, would it be a good form of syntactic sugar in languages like Java and C#, to include a "duck" type as a method parameter type? This would look as follows:</p>
<pre><code>void myFunction(duck foo) {
foo.doStuff();
}
</code></pre>
<p>This could be syntactic sugar for invoking doStuff()... | [
{
"answer_id": 311632,
"author": "Bryan Watts",
"author_id": 37815,
"author_profile": "https://Stackoverflow.com/users/37815",
"pm_score": 4,
"selected": true,
"text": "<p>The <code>dynamic</code> keyword supports these exact semantics and will be in C# 4.0.</p>\n\n<p>It is not just for ... | 2008/11/22 | [
"https://Stackoverflow.com/questions/311626",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/23903/"
] | I've been thinking lately, would it be a good form of syntactic sugar in languages like Java and C#, to include a "duck" type as a method parameter type? This would look as follows:
```
void myFunction(duck foo) {
foo.doStuff();
}
```
This could be syntactic sugar for invoking doStuff() via reflection, or it coul... | The `dynamic` keyword supports these exact semantics and will be in C# 4.0.
It is not just for reflection, though. It is an implementation of [dynamic dispatch](http://en.wikipedia.org/wiki/Dynamic_dispatch) which uses reflection only if no other mechanism is available.
[This question](https://stackoverflow.com/quest... |