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 |
|---|---|---|---|---|---|---|
477,135 | <p>I am playing with Google App Engine and Python and I cannot list the files of a static directory. Below is the code I currently use.</p>
<p><strong>app.yaml</strong></p>
<pre><code>- url: /data
static_dir: data
</code></pre>
<p><strong>Python code to list the files</strong></p>
<pre><code>myFiles = []
for root... | [
{
"answer_id": 477887,
"author": "David",
"author_id": 9908,
"author_profile": "https://Stackoverflow.com/users/9908",
"pm_score": 4,
"selected": true,
"text": "<p><a href=\"https://developers.google.com/appengine/docs/python/config/appconfig#Python_app_yaml_Static_file_handlers\" rel=\"... | 2009/01/25 | [
"https://Stackoverflow.com/questions/477135",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/42024/"
] | I am playing with Google App Engine and Python and I cannot list the files of a static directory. Below is the code I currently use.
**app.yaml**
```
- url: /data
static_dir: data
```
**Python code to list the files**
```
myFiles = []
for root, dirs, files in os.walk(os.path.join(os.path.dirname(__file__), 'data... | <https://developers.google.com/appengine/docs/python/config/appconfig#Python_app_yaml_Static_file_handlers>
They're not where you think they are, GAE puts static content into GoogleFS which is equivalent of a CDN. The idea is that static content is meant to be served directly to your users and not act as a file store ... |
477,157 | <p>I've got four <code>div</code> elements floated to the left. The third <code>div</code> is cleared.<br />
In Firefox and Chrome the elements are positioned as expected: The first and second <code>div</code>s are adjacent to each other and are above the third and fourth <code>div</code>s which are also adjacent to ea... | [
{
"answer_id": 477170,
"author": "GregD",
"author_id": 38317,
"author_profile": "https://Stackoverflow.com/users/38317",
"pm_score": 0,
"selected": false,
"text": "<p>Try adding:</p>\n\n<pre><code>display:inline-block;\n</code></pre>\n\n<p>in #divtwo. If that works, I would of course ad... | 2009/01/25 | [
"https://Stackoverflow.com/questions/477157",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/22417/"
] | I've got four `div` elements floated to the left. The third `div` is cleared.
In Firefox and Chrome the elements are positioned as expected: The first and second `div`s are adjacent to each other and are above the third and fourth `div`s which are also adjacent to each other.
IE7 on the other hand places the four... | Several months later...
I gave up on trying to solve this problem with CSS alone. This is an IE7 bug that you cannot avoid without touching your HTML.
The ultimate application of this floating pattern was in a form, where two of the `div`s were input elements and the other two `div`s were their corresponding labels. ... |
477,191 | <p>I am using jQuery and JavaScript, I need to call the jQuery function inside my JavaScript code.</p>
<p>My jQuery code:</p>
<pre><code>function display(id){
$.ajax({
type:'POST',
url: 'ajax.php',
data:'id='+id ,
success: function(data){
$("#response").html(data);
... | [
{
"answer_id": 477240,
"author": "jacobangel",
"author_id": 31318,
"author_profile": "https://Stackoverflow.com/users/31318",
"pm_score": 0,
"selected": false,
"text": "<p>You call showName from the anonymous function you assigned to the key 'success' in the Ajax request. The anonymous f... | 2009/01/25 | [
"https://Stackoverflow.com/questions/477191",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/44984/"
] | I am using jQuery and JavaScript, I need to call the jQuery function inside my JavaScript code.
My jQuery code:
```
function display(id){
$.ajax({
type:'POST',
url: 'ajax.php',
data:'id='+id ,
success: function(data){
$("#response").html(data);
}//success
}... | I really think you need to separate both things:
1. A function to trigger the [Ajax](http://en.wikipedia.org/wiki/Ajax_%28programming%29) call.
2. A function that receive the result from the Ajax call and do whatever you need.
Like:
```
function display(id){
$.ajax({
type:'POST',
url: 'ajax.php',
data:... |
477,193 | <p>Yesterday I made a simulation using Python. I had a few difficulties with <strong>variables and debugging</strong>.</p>
<p>Is there any software for Python, which provides a decent debugger?</p>
<p>Related question: <a href="https://stackoverflow.com/questions/299704/what-is-the-best-way-to-debug-my-python-code">W... | [
{
"answer_id": 477195,
"author": "sykora",
"author_id": 53850,
"author_profile": "https://Stackoverflow.com/users/53850",
"pm_score": 4,
"selected": false,
"text": "<p>You can check out the python debugger pdb, which is included in the standard library: <a href=\"http://docs.python.org/l... | 2009/01/25 | [
"https://Stackoverflow.com/questions/477193",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/54964/"
] | Yesterday I made a simulation using Python. I had a few difficulties with **variables and debugging**.
Is there any software for Python, which provides a decent debugger?
Related question: [What is the best way to debug my Python code?](https://stackoverflow.com/questions/299704/what-is-the-best-way-to-debug-my-pytho... | Don't forget about post-mortem debugging! After an exception is thrown, the stack frame with all of the locals is contained within `sys.last_traceback`. You can do `pdb.pm()` to go to the stack frame where the exception was thrown then p(retty)p(rint) the `locals()`.
Here is a function that uses this information to ex... |
477,204 | <p>I am trying to get key-value-observing to work for an NSMutableArray. Below is the .h file for MyObservee, the observed class:</p>
<pre><code>@interface MyObservee : NSObject {
@private int someValue;
@private NSMutableArray *someArray;
}
@property (readwrite,assign) int someValue;
- (NSMutableArray *)some... | [
{
"answer_id": 477244,
"author": "Jason Coco",
"author_id": 34218,
"author_profile": "https://Stackoverflow.com/users/34218",
"pm_score": 2,
"selected": false,
"text": "<p>Unfortunately, The NSArray classes are note KVO compliant. They are KVC compliant, but you can't observe them direct... | 2009/01/25 | [
"https://Stackoverflow.com/questions/477204",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/53839/"
] | I am trying to get key-value-observing to work for an NSMutableArray. Below is the .h file for MyObservee, the observed class:
```
@interface MyObservee : NSObject {
@private int someValue;
@private NSMutableArray *someArray;
}
@property (readwrite,assign) int someValue;
- (NSMutableArray *)someArray;
@end
`... | You need to implement the indexed array accessors as defined in the [KVC programming guide](https://developer.apple.com/library/ios/documentation/Cocoa/Conceptual/KeyValueCoding/Articles/Compliant.html). Then you must use those accessors to access the array and the KVO triggering will work. You can also call [-mutableA... |
477,237 | <p>In unbiased coin flip H or T occurs 50% of times.</p>
<p>But I want to simulate coin which gives H with probability 'p' and T with probability '(1-p)'.</p>
<p>something like this:</p>
<pre><code>def flip(p):
'''this function return H with probability p'''
# do something
return result
>> [flip(0.8... | [
{
"answer_id": 477239,
"author": "David Z",
"author_id": 56541,
"author_profile": "https://Stackoverflow.com/users/56541",
"pm_score": 3,
"selected": false,
"text": "<pre><code>import random\ndef flip(p):\n return (random.random() < p)\n</code></pre>\n\n<p>That returns a boolean wh... | 2009/01/25 | [
"https://Stackoverflow.com/questions/477237",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/58737/"
] | In unbiased coin flip H or T occurs 50% of times.
But I want to simulate coin which gives H with probability 'p' and T with probability '(1-p)'.
something like this:
```
def flip(p):
'''this function return H with probability p'''
# do something
return result
>> [flip(0.8) for i in xrange(10)]
[H,H,T,H,H,H... | `random.random()` returns a *uniformly distributed* pseudo-random floating point number in the range [0, 1). This number is less than a given number `p` in the range [0,1) with probability `p`. Thus:
```
def flip(p):
return 'H' if random.random() < p else 'T'
```
Some experiments:
```
>>> N = 100
>>> flips = [f... |
477,259 | <p>So i have a design problem. I have a mouse class that has delegates and events. ie MouseButtonPressed, MouseMoved. and such that are getting called by a state engine. </p>
<p>What i want to have happen is to create an interface like IClickable or IDraggable or somthing and have events inside those interfaces that g... | [
{
"answer_id": 477312,
"author": "Igor Zelaya",
"author_id": 22769,
"author_profile": "https://Stackoverflow.com/users/22769",
"pm_score": 2,
"selected": false,
"text": "<p>You mean something like this?</p>\n\n<pre><code>public class MouseDevice {\n public delegate void ButtonClickedH... | 2009/01/25 | [
"https://Stackoverflow.com/questions/477259",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | So i have a design problem. I have a mouse class that has delegates and events. ie MouseButtonPressed, MouseMoved. and such that are getting called by a state engine.
What i want to have happen is to create an interface like IClickable or IDraggable or somthing and have events inside those interfaces that get called ... | You mean something like this?
```
public class MouseDevice {
public delegate void ButtonClickedHandler<O, E>(O sender, E e);
}
public interface IClickable<O,E> {
event MouseDevice.ButtonClickedHandler<O,E> Clicked;
}
public class StateMachine : IClickable<Control,MouseEventArgs>
{
public event MouseDevi... |
477,325 | <p>I have a UIView with a UITableView for a subview. The UIView has an image applied to its background via setBackGroundColor, and I have applied a background to the UITableView in the same manner. Both images are PNGs, and the the background for the UITableView has levels of transparency in it that don't appear to b... | [
{
"answer_id": 477723,
"author": "August",
"author_id": 30966,
"author_profile": "https://Stackoverflow.com/users/30966",
"pm_score": 3,
"selected": true,
"text": "<p>You need to make sure your table view is not opaque.</p>\n\n<p>In Interface Builder, uncheck your table view's 'Opaque' s... | 2009/01/25 | [
"https://Stackoverflow.com/questions/477325",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/21804/"
] | I have a UIView with a UITableView for a subview. The UIView has an image applied to its background via setBackGroundColor, and I have applied a background to the UITableView in the same manner. Both images are PNGs, and the the background for the UITableView has levels of transparency in it that don't appear to be wor... | You need to make sure your table view is not opaque.
In Interface Builder, uncheck your table view's 'Opaque' setting. Or, in code,
```
tableView.opaque = NO;
```
Keep in mind that any sort of transparency in regard to table views will slow performance dramatically. If you only have a few rows, you'll probably be O... |
477,331 | <p>Say we've got:</p>
<pre><code>struct IsEven {
bool operator() (int i) { return i % 2 == 0; }
};
</code></pre>
<p>Then:</p>
<pre><code>vector<int> V; // fill with ints
vector<int>::iterator new_end = remove_if(V.begin(), V.end(), IsEven());
V.erase(new_end, V.end());
</code></pre>
<p>works fine (it... | [
{
"answer_id": 477344,
"author": "jalf",
"author_id": 33213,
"author_profile": "https://Stackoverflow.com/users/33213",
"pm_score": 2,
"selected": false,
"text": "<p>I suppose the point is that the function is called <code>remove_if</code> for a reason. It removes elements. It doesn't mo... | 2009/01/25 | [
"https://Stackoverflow.com/questions/477331",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/112/"
] | Say we've got:
```
struct IsEven {
bool operator() (int i) { return i % 2 == 0; }
};
```
Then:
```
vector<int> V; // fill with ints
vector<int>::iterator new_end = remove_if(V.begin(), V.end(), IsEven());
V.erase(new_end, V.end());
```
works fine (it leaves `V` with only the odd integers). But it seems that th... | It sounds like you want to use `partition()` to partition the vector into groups of odd values at the start and even values at the end. `partition()` will return an iterator to the first element of the second grouping.
As for the WTF, I'm not sure why you would expect a remove operation to preserve the elements you wa... |
477,348 | <p><strong>Edit:</strong> This is a confirmed bug in jQuery 1.3.1. It is fixed in jQuery 1.3.2.</p>
<hr>
<p>I have a YUI menu control exactly like <a href="http://developer.yahoo.com/yui/examples/menu/topnavfrommarkup_source.html" rel="nofollow noreferrer">this sample</a> with sub menus along the top.</p>
<p>I tried... | [
{
"answer_id": 477432,
"author": "BBetances",
"author_id": 53599,
"author_profile": "https://Stackoverflow.com/users/53599",
"pm_score": 0,
"selected": false,
"text": "<p>for jQuery you should do this:</p>\n\n<pre><code> $(document).ready(function(){\n\n\n var oMenuBar = new YA... | 2009/01/25 | [
"https://Stackoverflow.com/questions/477348",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16940/"
] | **Edit:** This is a confirmed bug in jQuery 1.3.1. It is fixed in jQuery 1.3.2.
---
I have a YUI menu control exactly like [this sample](http://developer.yahoo.com/yui/examples/menu/topnavfrommarkup_source.html) with sub menus along the top.
I tried using Yahoo's code to initialize the menu :
```
YAHOO.util.Event.o... | Yahoo's onContentReady(...) seems to wait for images to load for some reason so I've stopped using that.
In addition there appears to be a JQuery bug in how $(function() { }); works
See [this post](https://stackoverflow.com/questions/477463) by me trying to get more specifics on the issue. |
477,351 | <p>The documentation of <code>System.Threading.Timer</code> says that I should keep a live reference for it to avoid it being garbage collected. But where should I do that? My <code>main</code> is very simple that I don't know where to keep the reference:</p>
<pre><code>class Program {
static void Main() {
... | [
{
"answer_id": 477355,
"author": "Jon Skeet",
"author_id": 22656,
"author_profile": "https://Stackoverflow.com/users/22656",
"pm_score": 4,
"selected": false,
"text": "<p>EDIT: My original answer is rubbish. Really rubbish. I've kept it here to explain <em>why</em> it's rubbish though - ... | 2009/01/25 | [
"https://Stackoverflow.com/questions/477351",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/41283/"
] | The documentation of `System.Threading.Timer` says that I should keep a live reference for it to avoid it being garbage collected. But where should I do that? My `main` is very simple that I don't know where to keep the reference:
```
class Program {
static void Main() {
new System.Threading.Thread(myThrea... | If your Timer is an application-level object there's nothing wrong with making it a private static member of your Main class. That's what I would do, anyway. |
477,398 | <p>I think the basic principle of a PHP templating system is string replacing, right?
So can I just use a string to hold my html template code like </p>
<pre><code>$str_template = "<html><head><title>{the_title}</title><body>{the_content}</body></html>"
</code></pre>
<p>and i... | [
{
"answer_id": 477412,
"author": "Greg Hewgill",
"author_id": 893,
"author_profile": "https://Stackoverflow.com/users/893",
"pm_score": 3,
"selected": true,
"text": "<p>That is generally the basic idea for a templating system. Real templating systems have many more capabilities, but at t... | 2009/01/25 | [
"https://Stackoverflow.com/questions/477398",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/58743/"
] | I think the basic principle of a PHP templating system is string replacing, right?
So can I just use a string to hold my html template code like
```
$str_template = "<html><head><title>{the_title}</title><body>{the_content}</body></html>"
```
and in the following code simply do a str\_replace to push the data into ... | That is generally the basic idea for a templating system. Real templating systems have many more capabilities, but at the core this is what they do.
You ask whether this will "make the whole variable passing process a bit faster". Faster than what? Are you running into performance problems with something you're doing ... |
477,408 | <p>how do i detect and move to the next line using std::ifstream?</p>
<pre><code>void readData(ifstream& in)
{
string sz;
getline(in, sz);
cout << sz <<endl;
int v;
for(int i=0; in.good(); i++)
{
in >> v;
if (in.good())
cout << v << ... | [
{
"answer_id": 477415,
"author": "sth",
"author_id": 56338,
"author_profile": "https://Stackoverflow.com/users/56338",
"pm_score": 2,
"selected": false,
"text": "<p>You should clear the error state of the stream with <code>in.clear();</code> after the loop, then the stream will work agai... | 2009/01/25 | [
"https://Stackoverflow.com/questions/477408",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | how do i detect and move to the next line using std::ifstream?
```
void readData(ifstream& in)
{
string sz;
getline(in, sz);
cout << sz <<endl;
int v;
for(int i=0; in.good(); i++)
{
in >> v;
if (in.good())
cout << v << " ";
}
in.seekg(0, ios::beg);
sz.cle... | Use ignore() to ignore everything until the next line:
```
in.ignore(std::numeric_limits<std::streamsize>::max(), '\n')
```
If you must do it manually just check othe character to see if is '\n'
```
char next;
while(in.get(next))
{
if (next == '\n') // If the file has been opened in
{ break; // ... |
477,416 | <p>What's the prefered way to store binary data in .NET? </p>
<p>I've tried this:</p>
<pre><code>byte data __gc [] = __gc new byte [100];
</code></pre>
<p>And got this error:</p>
<pre><code>error C2726: '__gc new' may only be used to create an object with managed type
</code></pre>
<p>Is there a way to have manage... | [
{
"answer_id": 477417,
"author": "aku",
"author_id": 1196,
"author_profile": "https://Stackoverflow.com/users/1196",
"pm_score": 2,
"selected": false,
"text": "<p>CodeProject: <a href=\"http://www.codeproject.com/KB/mcpp/cppcliarrays.aspx\" rel=\"nofollow noreferrer\">Arrays in C++/CLI</... | 2009/01/25 | [
"https://Stackoverflow.com/questions/477416",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | What's the prefered way to store binary data in .NET?
I've tried this:
```
byte data __gc [] = __gc new byte [100];
```
And got this error:
```
error C2726: '__gc new' may only be used to create an object with managed type
```
Is there a way to have managed array of bytes? | CodeProject: [Arrays in C++/CLI](http://www.codeproject.com/KB/mcpp/cppcliarrays.aspx)
As far as I know '\_\_gc new' syntax is deprecated, try following:
```
cli::array<byte>^ data = gcnew cli::array<byte>(100);
```
I noted that you're having problems with cli namespace. Read about this [namespace on MSDN](http://m... |
477,427 | <p>I have this function to read in all ints from the file.
The problem is when i read letters i trigger a new line and i always seek by 1 and not to the end of line. How can i write this function better?</p>
<pre><code>int v;
while (!in.eof())
{
while (in >> v)
cout << v <<... | [
{
"answer_id": 477436,
"author": "CB Bailey",
"author_id": 19563,
"author_profile": "https://Stackoverflow.com/users/19563",
"pm_score": 3,
"selected": true,
"text": "<p>If your file consists of just ints separated by whitespace (including) newlines then this should be sufficient.</p>\n\... | 2009/01/25 | [
"https://Stackoverflow.com/questions/477427",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | I have this function to read in all ints from the file.
The problem is when i read letters i trigger a new line and i always seek by 1 and not to the end of line. How can i write this function better?
```
int v;
while (!in.eof())
{
while (in >> v)
cout << v << " ";
cout << endl;
... | If your file consists of just ints separated by whitespace (including) newlines then this should be sufficient.
```
while( in >> v )
{
// do something with v
}
```
After the file, if in.fail() is false and in.eof() is true, then you reached the end of the file without a formatting error. Otherwise an error readi... |
477,446 | <p>I frequently use HTML output in applications, up to now I've used some simple routines to build an HTML string. I want to try something different now:</p>
<p>I want to serialize the data to XML, and provide some XSLT templates to generate the HTML for the webbrowser control. I get that to work statically (slowly di... | [
{
"answer_id": 477451,
"author": "aku",
"author_id": 1196,
"author_profile": "https://Stackoverflow.com/users/1196",
"pm_score": 1,
"selected": false,
"text": "<p>I don't know how your application looks like, so I wouldn't say whether it is a good or bad idea.</p>\n\n<p>Regarding your ot... | 2009/01/25 | [
"https://Stackoverflow.com/questions/477446",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/31317/"
] | I frequently use HTML output in applications, up to now I've used some simple routines to build an HTML string. I want to try something different now:
I want to serialize the data to XML, and provide some XSLT templates to generate the HTML for the webbrowser control. I get that to work statically (slowly digging thro... | Usually the way to go is to provide parameters to the transform at runtime and writing the transform so that its behavior is controlled by the parameters.
Usually when I do this, I only pass in one parameter - an XML document - and make the templates query it to determine what they should do. So you'll see stuff like:... |
477,452 | <p>I'm writing this question with reference to <a href="https://stackoverflow.com/questions/475888/will-this-lead-to-a-memory-leak-in-c">this one</a> which I wrote yesterday. After a little documentation, it seems clear to me that what I wanted to do (and what I believed to be possible) is nearly impossible if not impo... | [
{
"answer_id": 477481,
"author": "j_random_hacker",
"author_id": 47984,
"author_profile": "https://Stackoverflow.com/users/47984",
"pm_score": 4,
"selected": true,
"text": "<p>The problem you are having is that the expression <code>a * b</code> creates a <em>temporary</em> object, and in... | 2009/01/25 | [
"https://Stackoverflow.com/questions/477452",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/25418/"
] | I'm writing this question with reference to [this one](https://stackoverflow.com/questions/475888/will-this-lead-to-a-memory-leak-in-c) which I wrote yesterday. After a little documentation, it seems clear to me that what I wanted to do (and what I believed to be possible) is nearly impossible if not impossible at all.... | The problem you are having is that the expression `a * b` creates a *temporary* object, and in C++, a temporary is not allowed to bind to a non-constant reference, which is what your `Matrix& operator=(Matrix& m)` takes. If you change it to:
```
Matrix& operator=(Matrix const& m);
```
The code should now compile. As... |
477,461 | <p>In Visual C++ , when I build a dll , the output files are .dll and .lib.</p>
<p>Is the name of the dll built into the .lib file . </p>
<p>The reasson I ask this question is : When I built my exe by importing this dll and run the exe , the exe tries to locate the dll to load it in the process address space . </p>
... | [
{
"answer_id": 477466,
"author": "Roger Lipscombe",
"author_id": 8446,
"author_profile": "https://Stackoverflow.com/users/8446",
"pm_score": 5,
"selected": true,
"text": "<p>The LIB file is turned into an import table in the EXE. This <em>does</em> contain the name of the DLL.</p>\n\n<p>... | 2009/01/25 | [
"https://Stackoverflow.com/questions/477461",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | In Visual C++ , when I build a dll , the output files are .dll and .lib.
Is the name of the dll built into the .lib file .
The reasson I ask this question is : When I built my exe by importing this dll and run the exe , the exe tries to locate the dll to load it in the process address space .
As we just specify th... | The LIB file is turned into an import table in the EXE. This *does* contain the name of the DLL.
You can see this if you run `dumpbin /all MyDLL.lib`. Note that `dumpbin MyDll.lib` by itself doesn't show anything useful: you should use `/all`.
This shows all of the sections defined in the .LIB file. You can ignore an... |
477,463 | <p><b>Update:</b>
This bug has been confirmed by at least two others. Even if you dont read my full post - if you're reading this and using JQuery 1.3.1 then <strong>stop using it</strong> if you're relying on any handlers that you want to execute when the DOM is complete but before the page's images have loaded.</p>
... | [
{
"answer_id": 477626,
"author": "Crescent Fresh",
"author_id": 45433,
"author_profile": "https://Stackoverflow.com/users/45433",
"pm_score": 2,
"selected": false,
"text": "<p>There are some things that just can't be unit tested. Just confirmed in IE6+7 and 1.3.1. Holy hell, what a huge ... | 2009/01/25 | [
"https://Stackoverflow.com/questions/477463",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16940/"
] | **Update:**
This bug has been confirmed by at least two others. Even if you dont read my full post - if you're reading this and using JQuery 1.3.1 then **stop using it** if you're relying on any handlers that you want to execute when the DOM is complete but before the page's images have loaded.
**Update2**: Thanks to ... | This was due to jQuery bugs #[2614](http://dev.jquery.com/ticket/2614) and #[3880](http://dev.jquery.com/ticket/3880) - there were definite problems with the ready code in IE in 1.2.6 and in 1.3 - and now a different set of problems in 1.3.1.
A larger discussion can be found here:
[<http://groups.google.com/group/j... |
477,468 | <pre><code>int n = 5;
for(int i = 0;i!=n;i++)//condition !=
{
//executing 5times
}
int n = 5;
for(int i = 0;i<n;i++)//condition <
{
//executing 5times
}
</code></pre>
<p>Which one is preferred?</p>
<blockquote>
<p>This was example from "Accelerated C++
: practical programming by example /
Andrew Koenig,... | [
{
"answer_id": 477476,
"author": "karlis",
"author_id": 49034,
"author_profile": "https://Stackoverflow.com/users/49034",
"pm_score": 1,
"selected": false,
"text": "<p><code><n</code> is the most used (my opinion) </p>\n"
},
{
"answer_id": 477477,
"author": "benlumley",
... | 2009/01/25 | [
"https://Stackoverflow.com/questions/477468",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/22076/"
] | ```
int n = 5;
for(int i = 0;i!=n;i++)//condition !=
{
//executing 5times
}
int n = 5;
for(int i = 0;i<n;i++)//condition <
{
//executing 5times
}
```
Which one is preferred?
>
> This was example from "Accelerated C++
> : practical programming by example /
> Andrew Koenig, Barbara E. Moo." Just
> wanted to know... | The second. For two reasons
1. The less than (or sometimes <=) is the usual way that most coder write these, and it's better to stick to convention if possible - the != will probably make most coders look twice to check if there's something odd in the loop whereas the < will be instantly understood.
2. The != depends ... |
477,486 | <p>How do I iterate between 0 and 1 by a step of 0.1?</p>
<p>This says that the step argument cannot be zero:</p>
<pre><code>for i in range(0, 1, 0.1):
print(i)
</code></pre>
| [
{
"answer_id": 477506,
"author": "cmsjr",
"author_id": 23114,
"author_profile": "https://Stackoverflow.com/users/23114",
"pm_score": 5,
"selected": false,
"text": "<p>Increase the magnitude of <code>i</code> for the loop and then reduce it when you need it.</p>\n\n<pre><code>for i * 100 ... | 2009/01/25 | [
"https://Stackoverflow.com/questions/477486",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/49701/"
] | How do I iterate between 0 and 1 by a step of 0.1?
This says that the step argument cannot be zero:
```
for i in range(0, 1, 0.1):
print(i)
``` | Rather than using a decimal step directly, it's much safer to express this in terms of how many points you want. Otherwise, floating-point rounding error is likely to give you a wrong result.
Use the [`linspace`](https://docs.scipy.org/doc/numpy/reference/generated/numpy.linspace.html) function from the [NumPy](http:/... |
477,503 | <p>Hi I am trying to mount as a drive in vista I am using the following code from msdn example,</p>
<pre><code> BOOL bFlag;
TCHAR Buf[BUFSIZE]; // temporary buffer for volume name
if( argc != 3 )
{
_tprintf( TEXT("Usage: %s <mount_point> <volume>\n"), argv[0] );
_tprintf( TEX... | [
{
"answer_id": 477514,
"author": "Chris",
"author_id": 43960,
"author_profile": "https://Stackoverflow.com/users/43960",
"pm_score": 1,
"selected": false,
"text": "<p>You need to be more specific! Where exactly in the code do you get that error?</p>\n\n<p>You could try and execute the fo... | 2009/01/25 | [
"https://Stackoverflow.com/questions/477503",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/51390/"
] | Hi I am trying to mount as a drive in vista I am using the following code from msdn example,
```
BOOL bFlag;
TCHAR Buf[BUFSIZE]; // temporary buffer for volume name
if( argc != 3 )
{
_tprintf( TEXT("Usage: %s <mount_point> <volume>\n"), argv[0] );
_tprintf( TEXT("For example, \"%s c:\\m... | `SetVolumeMountPoint` is for mounting a volume on a drive letter or in a folder. It does not allow you to mount a folder on a drive letter. This is the opposite of what you want.
To make a folder available as a drive letter, you want to do the equivalent of the `SUBST` utility. This uses `DefineDosDevice`, something l... |
477,509 | <p>How can I draw a <code>NSString</code> centered within a <code>NSRect</code>?</p>
<p>I've started off with: (an extract from the drawRect method of my custom view)</p>
<pre><code>NSString* theString = ...
[theString drawInRect:theRect withAttributes:0];
[theString release];
</code></pre>
<p>Now I'm assuming I nee... | [
{
"answer_id": 477606,
"author": "Joel Levin",
"author_id": 55743,
"author_profile": "https://Stackoverflow.com/users/55743",
"pm_score": 2,
"selected": false,
"text": "<p>Well, drawInRect is only good for basic text drawing (in other words, the system decides where to position your text... | 2009/01/25 | [
"https://Stackoverflow.com/questions/477509",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/48659/"
] | How can I draw a `NSString` centered within a `NSRect`?
I've started off with: (an extract from the drawRect method of my custom view)
```
NSString* theString = ...
[theString drawInRect:theRect withAttributes:0];
[theString release];
```
Now I'm assuming I need to set up some attributes. I've had a look through Ap... | Vertical alignment you'll have to do yourself ((height of view + height of string)/2). Horizontal alignment you can do with:
```
NSMutableParagraphStyle *style = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
style.alignment = NSTextAlignmentCenter;
NSDictionary *attr = [NSDictionary dictionaryWithObject:styl... |
477,525 | <p>I'm writing some excel-like C++ console app for homework.
My app should be able to accept formulas for it's cells, for example it should evaluate something like this:</p>
<pre><code>Sum(tablename\fieldname[recordnumber], fieldname[recordnumber], ...)
tablename\fieldname[recordnumber] points to a cell in another ta... | [
{
"answer_id": 477555,
"author": "EricSchaefer",
"author_id": 8976,
"author_profile": "https://Stackoverflow.com/users/8976",
"pm_score": 0,
"selected": false,
"text": "<p>I guess you cannot use yacc/lex (or the like) so you have to parse \"manually\":<br>\nIterate over the string and di... | 2009/01/25 | [
"https://Stackoverflow.com/questions/477525",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | I'm writing some excel-like C++ console app for homework.
My app should be able to accept formulas for it's cells, for example it should evaluate something like this:
```
Sum(tablename\fieldname[recordnumber], fieldname[recordnumber], ...)
tablename\fieldname[recordnumber] points to a cell in another table,
fieldnam... | Ok, nice homework question by the way.
It really depends on how heavy you want this to be. You can create a full expression parser (which is fun but also time consuming).
In order to do that, you need to describe the full grammar and write a frontend (have a look at lex and yacc or flexx and bison.
But as I see you... |
477,537 | <p>I am using jQuery. How do I extract list data effectively?</p>
<p>My list has:</p>
<pre><code><li class="add"><a href="#">Data1</a></li>
<li class="add"><a href="#">Data2</a> </li>
...
</code></pre>
<p>My jQuery has:</p>
<pre><code>$(".add").click(function(e){
... | [
{
"answer_id": 477564,
"author": "Ferdinand Beyer",
"author_id": 34855,
"author_profile": "https://Stackoverflow.com/users/34855",
"pm_score": 1,
"selected": false,
"text": "<p>You can try the following:</p>\n\n<pre><code>$('.add').click(function(e) {\n e.preventDefault();\n\n // Initi... | 2009/01/25 | [
"https://Stackoverflow.com/questions/477537",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/44984/"
] | I am using jQuery. How do I extract list data effectively?
My list has:
```
<li class="add"><a href="#">Data1</a></li>
<li class="add"><a href="#">Data2</a> </li>
...
```
My jQuery has:
```
$(".add").click(function(e){
e.preventDefault();
// Here is to get the value of Data1 and Data2...
// How do I a... | or just
```
$('li.add a').each(function() {
data.push($(this).text());
});
``` |
477,550 | <p>Is there a way in Java's for-each loop</p>
<pre><code>for(String s : stringArray) {
doSomethingWith(s);
}
</code></pre>
<p>to find out how often the loop has already been processed?</p>
<p>Aside from using the old and well-known <code>for(int i=0; i < boundary; i++)</code> - loop, is the construct</p>
<pre>... | [
{
"answer_id": 477563,
"author": "EricSchaefer",
"author_id": 8976,
"author_profile": "https://Stackoverflow.com/users/8976",
"pm_score": 2,
"selected": false,
"text": "<p>If you need a counter in an for-each loop you have to count yourself. There is no built in counter as far as I know.... | 2009/01/25 | [
"https://Stackoverflow.com/questions/477550",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/57601/"
] | Is there a way in Java's for-each loop
```
for(String s : stringArray) {
doSomethingWith(s);
}
```
to find out how often the loop has already been processed?
Aside from using the old and well-known `for(int i=0; i < boundary; i++)` - loop, is the construct
```
int i = 0;
for(String s : stringArray) {
doSomethi... | No, but you can provide your own counter.
The reason for this is that the for-each loop internally does not *have* a counter; it is based on the [Iterable](http://java.sun.com/j2se/1.5.0/docs/api/java/lang/Iterable.html) interface, i.e. it uses an `Iterator` to loop through the "collection" - which may not be a collec... |
477,572 | <p>I have a <code>ListView</code> with a couple of image buttons on each row. When the user clicks the list row, it launches a new activity. I have had to build my own tabs because of an issue with the camera layout. The activity that gets launched for the result is a map. If I click on my button to launch the image pr... | [
{
"answer_id": 552403,
"author": "Chrispix",
"author_id": 393258,
"author_profile": "https://Stackoverflow.com/users/393258",
"pm_score": 6,
"selected": false,
"text": "<p>I did the following to take the image and resize it on the fly. Hope this helps</p>\n\n<pre><code>Bitmap bm;\nbm = B... | 2009/01/25 | [
"https://Stackoverflow.com/questions/477572",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/393258/"
] | I have a `ListView` with a couple of image buttons on each row. When the user clicks the list row, it launches a new activity. I have had to build my own tabs because of an issue with the camera layout. The activity that gets launched for the result is a map. If I click on my button to launch the image preview (load an... | The [Android Training](http://developer.android.com/training/index.html) class, "[Displaying Bitmaps Efficiently](http://developer.android.com/training/displaying-bitmaps/index.html)", offers some great information for understanding and dealing with the exception `java.lang.OutOfMemoryError: bitmap size exceeds VM budg... |
477,573 | <p>I have an install of python 2.5 that fink placed in /sw/bin/. I use the easy install command</p>
<pre><code>sudo /sw/bin/easy_install wxPython
</code></pre>
<p>to try to install wxpython and I get an error while trying to process wxPython-src-2.8.9.1.tab.bz2 that there is not setup script. Easy-install has worked ... | [
{
"answer_id": 478200,
"author": "Martin v. Löwis",
"author_id": 33006,
"author_profile": "https://Stackoverflow.com/users/33006",
"pm_score": 4,
"selected": true,
"text": "<p>There is a simple reason why it's busting: there just is no setup.py in wxPython; wxPython does not use distutil... | 2009/01/25 | [
"https://Stackoverflow.com/questions/477573",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/51532/"
] | I have an install of python 2.5 that fink placed in /sw/bin/. I use the easy install command
```
sudo /sw/bin/easy_install wxPython
```
to try to install wxpython and I get an error while trying to process wxPython-src-2.8.9.1.tab.bz2 that there is not setup script. Easy-install has worked for several other installa... | There is a simple reason why it's busting: there just is no setup.py in wxPython; wxPython does not use distutils for installation.
Instead, read the file README.1st.txt in source distribution for instruction on how to install wxPython. |
477,591 | <p>Im looking for an algorithm to be used in a racing game Im making. The map/level/track is randomly generated so I need to find two locations, start and goal, that makes use of the most of the map.</p>
<ul>
<li>The algorithm is to work inside a two dimensional space</li>
<li>From each point, one can only traverse to... | [
{
"answer_id": 477614,
"author": "Yuval F",
"author_id": 1702,
"author_profile": "https://Stackoverflow.com/users/1702",
"pm_score": 0,
"selected": false,
"text": "<p>Your description sounds to me like a <a href=\"http://foghorn.cadlab.lafayette.edu/cadapplets/MazeRouter.html\" rel=\"nof... | 2009/01/25 | [
"https://Stackoverflow.com/questions/477591",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/56763/"
] | Im looking for an algorithm to be used in a racing game Im making. The map/level/track is randomly generated so I need to find two locations, start and goal, that makes use of the most of the map.
* The algorithm is to work inside a two dimensional space
* From each point, one can only traverse to the next point in fo... | Assuming the map is rectangular, you can loop over all border points, and start a flood fill to find the most distant point from the starting point:
```
bestSolution = { start: (0,0), end: (0,0), distance: 0 };
for each point p on the border
flood-fill all points in the map to find the most distant point
if ne... |
477,603 | <p>I am trying to use the ASP.NET (3.5) "Routing Module" functionality to create custom pages based on the contents of the URL.</p>
<p>Various articles explain how to use ASP.NET Routing to branch to existing pages on the web server.</p>
<p>What I would like to do is create the page on-the-fly using code.</p>
<p>My ... | [
{
"answer_id": 477640,
"author": "tvanfosson",
"author_id": 12950,
"author_profile": "https://Stackoverflow.com/users/12950",
"pm_score": 1,
"selected": false,
"text": "<p>Instead of trying to write directly to the response, you might want to simply add controls to the page. Since the p... | 2009/01/25 | [
"https://Stackoverflow.com/questions/477603",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/31802/"
] | I am trying to use the ASP.NET (3.5) "Routing Module" functionality to create custom pages based on the contents of the URL.
Various articles explain how to use ASP.NET Routing to branch to existing pages on the web server.
What I would like to do is create the page on-the-fly using code.
My first attempt looks like... | You can't write to the response from an `IRouteHandler` - it's way too early during the request life cycle. You should only write to the response from within the `IHttpHandler`, which is what the `Page` is.
As is shown in other examples, you'll have to get a page instance from somewhere that has all the necessary cont... |
477,607 | <p>I am working with asp.net website project that some of pages need authentication. I am using asp.net membership. </p>
<p>I read some answers. e.g. make all of those pages in folder and create inner web.config that describe the privilege. This is one way solve the problem but I need way that is more fixable and eff... | [
{
"answer_id": 477621,
"author": "Zhaph - Ben Duguid",
"author_id": 33051,
"author_profile": "https://Stackoverflow.com/users/33051",
"pm_score": 5,
"selected": true,
"text": "<p>If you don't want to hard code this in web.config(s) you will need to implement a \"Base Page\" type control.... | 2009/01/25 | [
"https://Stackoverflow.com/questions/477607",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/36446/"
] | I am working with asp.net website project that some of pages need authentication. I am using asp.net membership.
I read some answers. e.g. make all of those pages in folder and create inner web.config that describe the privilege. This is one way solve the problem but I need way that is more fixable and effective. | If you don't want to hard code this in web.config(s) you will need to implement a "Base Page" type control.
Your base page class should inherit from System.Web.UI.Page, and would need to have a method you could call to say "User must be logged in" or "User must be in role x", and if the user isn't in that role, redire... |
477,609 | <p>I'm using callables quite often , and I've stubled upon a question that irritates me: </p>
<p>Lets say that to run function foo() , one needs to do a couple of checks first. </p>
<p>Should you
1. Insert the checks as part of the Callable : </p>
<pre><code>class A implements Callable<Long> {
...
public Long... | [
{
"answer_id": 477629,
"author": "Peter Lawrey",
"author_id": 57695,
"author_profile": "https://Stackoverflow.com/users/57695",
"pm_score": 1,
"selected": false,
"text": "<p>Which do you feel is simpler or clearer?\nI suggest you do that.</p>\n"
},
{
"answer_id": 477647,
"aut... | 2009/01/25 | [
"https://Stackoverflow.com/questions/477609",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4038/"
] | I'm using callables quite often , and I've stubled upon a question that irritates me:
Lets say that to run function foo() , one needs to do a couple of checks first.
Should you
1. Insert the checks as part of the Callable :
```
class A implements Callable<Long> {
...
public Long call() {
check1();
check2... | My general advice when implementing callback [Java keyword] interfaces is concentrate on making the [non-Java keyword] interface appropriate for the called type. There generally shouldn't be that much in the anonymous inner class (or whatever), but more than just forwarding call.
Also, it's generally not good to have ... |
477,613 | <p>I have built a logic that if i enter duplicate value i should get Message like:"UserName already exists,try another name"
but i am getting different message:"Violation of UNIQUE KEY constraint 'UserName'. Cannot insert duplicate key in object 'Login'. The statement has been terminated." In table Login UserName set ... | [
{
"answer_id": 477617,
"author": "gkrogers",
"author_id": 54501,
"author_profile": "https://Stackoverflow.com/users/54501",
"pm_score": 0,
"selected": false,
"text": "<p>Your database is (correctly) catching and preventing the attempt to add a duplicate user because the Username is set a... | 2009/01/25 | [
"https://Stackoverflow.com/questions/477613",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/42532/"
] | I have built a logic that if i enter duplicate value i should get Message like:"UserName already exists,try another name"
but i am getting different message:"Violation of UNIQUE KEY constraint 'UserName'. Cannot insert duplicate key in object 'Login'. The statement has been terminated." In table Login UserName set as ... | You get the exception because you are trying to insert user with same login. You've got two options:
a. before inserting data explicitly check if the user exists (additional select query)
b. catch the exception "Violation of UNIQUE KEY constraint" and then display your custom message |
477,616 | <p>I am having major problems getting a scheduled task to run. The task is created fine using the ITaskScheduler interface provided by Microsoft. The task is set to run only if a user is logged on.</p>
<p>The problem is that the task does NOT run and the log file SchedLgU.txt cites the reason as being:</p>
<pre><code... | [
{
"answer_id": 477682,
"author": "Stephen Martin",
"author_id": 12845,
"author_profile": "https://Stackoverflow.com/users/12845",
"pm_score": 2,
"selected": false,
"text": "<p>As far as I know, and the documentation backs this up, an account is required for a scheduled task. If you set t... | 2009/01/25 | [
"https://Stackoverflow.com/questions/477616",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | I am having major problems getting a scheduled task to run. The task is created fine using the ITaskScheduler interface provided by Microsoft. The task is set to run only if a user is logged on.
The problem is that the task does NOT run and the log file SchedLgU.txt cites the reason as being:
```
"The attempt to retr... | The GoogleUpdateTaskMachine Task uses the "NT AUTHORITY\SYSTEM" to Run the task. You can do this by using schtasks command and the /ru switch with "System" or "" as the parameter. Like this:
```
schtasks /create /tn "My App" /tr c:\apps\myapp.exe /sc monthly /d 15 /ru "System"
```
It does not prompt for a password.
... |
477,646 | <p>Looking at some code I'm maintaining in System Verilog I see some signals that are defined like this:</p>
<pre><code>node [range_hi:range_lo]x;
</code></pre>
<p>and others that are defined like this:</p>
<pre><code>node y[range_hi:range_lo];
</code></pre>
<p>I understand that <code>x</code> is defined as packed,... | [
{
"answer_id": 477664,
"author": "empi",
"author_id": 49048,
"author_profile": "https://Stackoverflow.com/users/49048",
"pm_score": 5,
"selected": true,
"text": "<p>This article gives more details about this issue:\n<a href=\"http://electrosofts.com/systemverilog/arrays.html\" rel=\"nore... | 2009/01/25 | [
"https://Stackoverflow.com/questions/477646",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1084/"
] | Looking at some code I'm maintaining in System Verilog I see some signals that are defined like this:
```
node [range_hi:range_lo]x;
```
and others that are defined like this:
```
node y[range_hi:range_lo];
```
I understand that `x` is defined as packed, while `y` is defined as unpacked. However, I have no idea w... | This article gives more details about this issue:
<http://electrosofts.com/systemverilog/arrays.html>, especially section 5.2.
>
> A packed array is a mechanism for subdividing a vector into subfields which can be conveniently accessed as array elements. Consequently, a packed array is guaranteed to be represented a... |
477,663 | <p>Is it somehow possible on Swing to set a TitledBorder transparent so that a background image shines through?</p>
| [
{
"answer_id": 477685,
"author": "Kosi2801",
"author_id": 57601,
"author_profile": "https://Stackoverflow.com/users/57601",
"pm_score": 3,
"selected": true,
"text": "<p>Found the answer.</p>\n\n<p>Use the method </p>\n\n<pre><code>setOpaque(false) \n</code></pre>\n\n<p>on the underlying ... | 2009/01/25 | [
"https://Stackoverflow.com/questions/477663",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/57601/"
] | Is it somehow possible on Swing to set a TitledBorder transparent so that a background image shines through? | Found the answer.
Use the method
```
setOpaque(false)
```
on the underlying panel. |
477,667 | <p>I'm using jQuery and I want to check the existence of an element in my page. I have written following code, but it's not working:</p>
<pre><code>if($("#btext" + i) != null) {
//alert($("#btext" + i).text());
$("#btext" + i).text("Branch " + i);
}
</code></pre>
<p>How do I check the existence of the element... | [
{
"answer_id": 477671,
"author": "tvanfosson",
"author_id": 12950,
"author_profile": "https://Stackoverflow.com/users/12950",
"pm_score": 4,
"selected": false,
"text": "<p>The lookup function returns an array of matching elements. You could check if the length is zero. Note the change ... | 2009/01/25 | [
"https://Stackoverflow.com/questions/477667",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/45261/"
] | I'm using jQuery and I want to check the existence of an element in my page. I have written following code, but it's not working:
```
if($("#btext" + i) != null) {
//alert($("#btext" + i).text());
$("#btext" + i).text("Branch " + i);
}
```
How do I check the existence of the element? | Check the [jQuery FAQ](http://learn.jquery.com/using-jquery-core/faq/how-do-i-test-whether-an-element-exists/)...
You can use the length property of the jQuery collection returned by your selector:
```
if ( $('#myDiv').length ){}
``` |
477,676 | <p>In a software system a one-to-one relationship must be modeled between two objects where an active status exists for the relationship. </p>
<p>In other words, ObjectA has a one-to-one relationship to ObjectB (without a back pointer) where the relationship can be either active or inactive. There might also be additi... | [
{
"answer_id": 477678,
"author": "Otávio Décio",
"author_id": 48684,
"author_profile": "https://Stackoverflow.com/users/48684",
"pm_score": 2,
"selected": false,
"text": "<p>ObjectA containing an instance of ObjectB. Inactive is represented by it being null, active otherwise.</p>\n"
},... | 2009/01/25 | [
"https://Stackoverflow.com/questions/477676",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/31770/"
] | In a software system a one-to-one relationship must be modeled between two objects where an active status exists for the relationship.
In other words, ObjectA has a one-to-one relationship to ObjectB (without a back pointer) where the relationship can be either active or inactive. There might also be additional attri... | It depends if the activation of a relationship is part of the behavior of the system you want to model.
>
> "There might also be additional attributes associated with the relationship."
>
>
>
So that sounds like you would want to model more than just a reference.
The a containing instance of b will work in simple... |
477,691 | <p>Well I am trying to submit a form by pressing enter but not displaying a submit button. I don't want to get into JavaScript if possible since I want everything to work on all browsers (the only JS way I know is with events).</p>
<p>Right now the form looks like this:</p>
<pre><code><form name="loginBox" target=... | [
{
"answer_id": 477697,
"author": "Noldorin",
"author_id": 44389,
"author_profile": "https://Stackoverflow.com/users/44389",
"pm_score": 3,
"selected": false,
"text": "<p>Instead of the hack you currently use to hide the button, it would be much simpler to set <code>visibility: collapse;<... | 2009/01/25 | [
"https://Stackoverflow.com/questions/477691",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | Well I am trying to submit a form by pressing enter but not displaying a submit button. I don't want to get into JavaScript if possible since I want everything to work on all browsers (the only JS way I know is with events).
Right now the form looks like this:
```
<form name="loginBox" target="#here" method="post">
... | **Update 2022: Use this instead**
```
<input type="submit" hidden />
```
---
| Notice - Outdated answer |
| --- |
| Please do not use `position: absolute` in the year 2021+. It's recommended to use the `hidden` attribute instead. Otherwise, look down below and pick a better, more modern, answer. |
Try:
```
<input... |
477,692 | <p>I'm working on a web application (with ASP.NET 2.0 (C#) and jQuery)</p>
<p>In my application we have an interface using which our employees are able to enter records of a comany. We provided the interface with basic fields, Company Name, Contact Person, phone, etc. Now as you know some companies have thier branches... | [
{
"answer_id": 477755,
"author": "Scott Evernden",
"author_id": 11397,
"author_profile": "https://Stackoverflow.com/users/11397",
"pm_score": 0,
"selected": false,
"text": "<p>maybe this is a clue? in submit do ....</p>\n\n<pre><code>$('#branches').each( function (i) { this.id = 'branch'... | 2009/01/25 | [
"https://Stackoverflow.com/questions/477692",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/45261/"
] | I'm working on a web application (with ASP.NET 2.0 (C#) and jQuery)
In my application we have an interface using which our employees are able to enter records of a comany. We provided the interface with basic fields, Company Name, Contact Person, phone, etc. Now as you know some companies have thier branches, some hav... | Get rid of the hidden counter variable, and just iterate through Request.Form.Keys looking for branch\*. Then, you'll just process any form variables that start with branch.
```
class Branch { public string Name; public string Title; }
void OnLoad(EventArgs e) {
base.OnLoad(e);
var branches = new Dictionary<in... |
477,713 | <p>I want to display items as follows,</p>
<pre><code><td1> <td2> <td3> <td4>
1 7 13 19
2 8 14 20
3 9 15 21
4 10 16 22
5 11 17 23
6 12 18
</c... | [
{
"answer_id": 477733,
"author": "Riho",
"author_id": 44715,
"author_profile": "https://Stackoverflow.com/users/44715",
"pm_score": 2,
"selected": false,
"text": "<p>In pseudocode (didn't test it):</p>\n\n<pre><code>int recordnum=....; //get the total number of records\nint col_length=re... | 2009/01/25 | [
"https://Stackoverflow.com/questions/477713",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/45261/"
] | I want to display items as follows,
```
<td1> <td2> <td3> <td4>
1 7 13 19
2 8 14 20
3 9 15 21
4 10 16 22
5 11 17 23
6 12 18
```
I am getting data (from 1......23) ... | OK, here's a corrected version of Riho's loop:
```
int records = ... ; /* the number of records */
int cols = 4; /* the number of columns */
int rows = (records + cols - 1) / cols; /* nb: assumes integer math */
for (int row = 0; row < rows; ++row) {
print "<tr>";
... |
477,750 | <p>I have a question about the primitive type <code>short</code> in Java. I am using JDK 1.6. </p>
<p>If I have the following: </p>
<pre><code>short a = 2;
short b = 3;
short c = a + b;
</code></pre>
<p>the compiler does not want to compile - it says that it "cannot convert from int to short" and suggests that I mak... | [
{
"answer_id": 477765,
"author": "Darron",
"author_id": 22704,
"author_profile": "https://Stackoverflow.com/users/22704",
"pm_score": 3,
"selected": false,
"text": "<p>What language are you using?</p>\n\n<p>Many C based languages have a rule that any mathematical expression is performed ... | 2009/01/25 | [
"https://Stackoverflow.com/questions/477750",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/42155/"
] | I have a question about the primitive type `short` in Java. I am using JDK 1.6.
If I have the following:
```
short a = 2;
short b = 3;
short c = a + b;
```
the compiler does not want to compile - it says that it "cannot convert from int to short" and suggests that I make a cast to `short`, so this:
```
short c =... | As explained in [short C#](http://msdn.microsoft.com/en-us/library/ybs77ex4(VS.71).aspx) (but also for other language compilers as well, like Java)
There is a predefined implicit conversion from short to int, long, float, double, or decimal.
You cannot implicitly convert nonliteral numeric types of larger storage siz... |
477,754 | <p>I have the following code:</p>
<pre><code>var tempIdx = document.getElementById('cityBuild').selectedIndex;
var tempBuilding = document.getElementById('cityBuild').options[tempIdx].value;
// Do stuff with tempBuilding
</code></pre>
<p>I spent some time trying to do it in jQuery under the assumption it'd be easier... | [
{
"answer_id": 477786,
"author": "Eran Galperin",
"author_id": 10585,
"author_profile": "https://Stackoverflow.com/users/10585",
"pm_score": 4,
"selected": true,
"text": "<p>jQuery knows how to work with select elements. You can get the value as any other input:</p>\n\n<pre><code>var val... | 2009/01/25 | [
"https://Stackoverflow.com/questions/477754",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1384652/"
] | I have the following code:
```
var tempIdx = document.getElementById('cityBuild').selectedIndex;
var tempBuilding = document.getElementById('cityBuild').options[tempIdx].value;
// Do stuff with tempBuilding
```
I spent some time trying to do it in jQuery under the assumption it'd be easier, it wasn't. I tried what ... | jQuery knows how to work with select elements. You can get the value as any other input:
```
var value = $('#cityBuild').val();
``` |
477,787 | <p>I'm porting a small C++ console application from windows to linux, GCC 4.3.2. When compiling I get strange error that I'm unable to solve.</p>
<pre><code>Labels.cpp: In function ‘void DumpSymbols()’:
Labels.cpp:68: error: invalid conversion from ‘int’ to ‘std::_Ios_Openmode’
Labels.cpp:68: error: initializing arg... | [
{
"answer_id": 477826,
"author": "Laserallan",
"author_id": 11758,
"author_profile": "https://Stackoverflow.com/users/11758",
"pm_score": 1,
"selected": false,
"text": "<p>Is ios::beg really a valid value for the mode parameter of the ofstream constructor?</p>\n\n<p>According to <a href=... | 2009/01/25 | [
"https://Stackoverflow.com/questions/477787",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | I'm porting a small C++ console application from windows to linux, GCC 4.3.2. When compiling I get strange error that I'm unable to solve.
```
Labels.cpp: In function ‘void DumpSymbols()’:
Labels.cpp:68: error: invalid conversion from ‘int’ to ‘std::_Ios_Openmode’
Labels.cpp:68: error: initializing argument 2 of ‘st... | Just remove "|ios::beg":
ofstream mapfile("symbols.map", ios::out);
It's type is ios\_base::seekdir, which is not an opening mode; it's for seeking to a position. You'll automatically be at the beginning anyway. |
477,793 | <p>So the final menu will look something like this:</p>
<pre><code>Item B
Item B-1
Item B-1-2
Item B-1-1
Item A
SubItem A-1
SubItem A-2
Item C
</code></pre>
<p>Based on the following DB records:</p>
<pre><code>id menu_title parent_menu_id menu_level weight
1 ... | [
{
"answer_id": 477803,
"author": "cletus",
"author_id": 18393,
"author_profile": "https://Stackoverflow.com/users/18393",
"pm_score": 3,
"selected": false,
"text": "<p>Hierarchical data is somewhat annoying in a relationsal database (excluding Oracle, which has operators in <code>START W... | 2009/01/25 | [
"https://Stackoverflow.com/questions/477793",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/32881/"
] | So the final menu will look something like this:
```
Item B
Item B-1
Item B-1-2
Item B-1-1
Item A
SubItem A-1
SubItem A-2
Item C
```
Based on the following DB records:
```
id menu_title parent_menu_id menu_level weight
1 Item A 0 ... | Dealing with the data structure as you have it will often involve recursion or multiple queries to build the tree.
Have you considered other ways of storing a hierarchy? Check out modified pre-order traversal - here's a nice [PHP based article about this](http://www.sitepoint.com/article/hierarchical-data-database/). |
477,816 | <p>There are many "standards" for the <a href="http://en.wikipedia.org/wiki/JSON" rel="noreferrer">JSON</a> content type:</p>
<pre class="lang-none prettyprint-override"><code>application/json
application/x-javascript
text/javascript
text/x-javascript
text/x-json
</code></pre>
<p>Which one do I use, and where... | [
{
"answer_id": 477819,
"author": "Gumbo",
"author_id": 53114,
"author_profile": "https://Stackoverflow.com/users/53114",
"pm_score": 14,
"selected": true,
"text": "<p>For JSON text:</p>\n<pre><code>application/json\n</code></pre>\n<blockquote>\n<p>The MIME media type for JSON text is <co... | 2009/01/25 | [
"https://Stackoverflow.com/questions/477816",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12870/"
] | There are many "standards" for the [JSON](http://en.wikipedia.org/wiki/JSON) content type:
```none
application/json
application/x-javascript
text/javascript
text/x-javascript
text/x-json
```
Which one do I use, and where? I assume security and browser support issues are a factor.
Related: [What MIME type if JSON is... | For JSON text:
```
application/json
```
>
> The MIME media type for JSON text is `application/json`. The default encoding is UTF-8. (Source: [RFC 4627](http://www.ietf.org/rfc/rfc4627.txt))
>
>
>
For [JSONP](http://en.wikipedia.org/wiki/JSONP) (runnable JavaScript) with callback:
```
application/javascript
``... |
477,820 | <p><a href="http://docs.djangoproject.com/en/dev/ref/templates/builtins/#regroup" rel="noreferrer">http://docs.djangoproject.com/en/dev/ref/templates/builtins/#regroup</a></p>
<p>I can think of a few ways of doing it with loops but I'd particularly like to know if there is a neat one-liner.</p>
| [
{
"answer_id": 477839,
"author": "Jouni K. Seppänen",
"author_id": 26575,
"author_profile": "https://Stackoverflow.com/users/26575",
"pm_score": 6,
"selected": true,
"text": "<p>Combine <a href=\"http://docs.python.org/library/itertools.html#itertools.groupby\" rel=\"noreferrer\"><code>i... | 2009/01/25 | [
"https://Stackoverflow.com/questions/477820",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/45955/"
] | <http://docs.djangoproject.com/en/dev/ref/templates/builtins/#regroup>
I can think of a few ways of doing it with loops but I'd particularly like to know if there is a neat one-liner. | Combine [`itertools.groupby`](http://docs.python.org/library/itertools.html#itertools.groupby) with [`operator.itemgetter`](http://docs.python.org/library/operator.html#operator.itemgetter) to get a pretty nice solution:
```
from operator import itemgetter
from itertools import groupby
key = itemgetter('gender')
iter... |
477,842 | <p>I created the following code to calculate the duration between two timestamps which can come in two different formats:</p>
<pre><code>public class dummyTime {
public static void main(String[] args) {
try {
convertDuration("2008-01-01 01:00 pm - 01:56 pm");
convertDuration("2008-01-01 8:30 pm - 2... | [
{
"answer_id": 477860,
"author": "Tom Hawtin - tackline",
"author_id": 4725,
"author_profile": "https://Stackoverflow.com/users/4725",
"pm_score": 2,
"selected": false,
"text": "<p>You are formatting time of day, not number of hours and minutes. As you are in the CET timezone [Central Eu... | 2009/01/25 | [
"https://Stackoverflow.com/questions/477842",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/33429/"
] | I created the following code to calculate the duration between two timestamps which can come in two different formats:
```
public class dummyTime {
public static void main(String[] args) {
try {
convertDuration("2008-01-01 01:00 pm - 01:56 pm");
convertDuration("2008-01-01 8:30 pm - 2008-01-02 09:3... | 1. At my computer this is off by 2 hours, because I'm at GMT+2, and you're probably at GMT+1. Note that `formatNew.format(end.getTime() - beg.getTime());` receives date, i.e. treats your 56 minutes as 1970-01-01-00:56:00 GMT+1. To fix this quickly, call `formatNew.setTimeZone( TimeZone.getTimeZone( "GMT" ) );`
2. For t... |
477,871 | <p>actually i and my friend are trying to learn and use eclipse 3.4 and we are having some heap memory issue while working, and my friend suggested to increase the memory allocation to eclipse ide as he has 4GB RAM and he wants to allocate enough heap, allocate decent perm size, and enable parallel garbage collection t... | [
{
"answer_id": 477875,
"author": "EricSchaefer",
"author_id": 8976,
"author_profile": "https://Stackoverflow.com/users/8976",
"pm_score": 3,
"selected": false,
"text": "<p>Put this line into your eclipse.ini:</p>\n\n<blockquote>\n <p>-Xmx1024m</p>\n</blockquote>\n"
},
{
"answer_... | 2009/01/25 | [
"https://Stackoverflow.com/questions/477871",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/45972/"
] | actually i and my friend are trying to learn and use eclipse 3.4 and we are having some heap memory issue while working, and my friend suggested to increase the memory allocation to eclipse ide as he has 4GB RAM and he wants to allocate enough heap, allocate decent perm size, and enable parallel garbage collection to t... | Just for reference: as Carsten said, the `eclipse.ini` file is quite picky about the order and format of its lines. [Here](http://wiki.eclipse.org/Eclipse.ini)'s their Wiki page, with some example configurations.
As they say, remember that:
>
> 1. Each option and each argument to an option must be on its own line.
... |
477,880 | <p>In C++, I have a few functions that need to write to a temp directory. Ideally, only one temp directory gets created that they all write to (to minimize I/O overhead). That directory should be automagically removed when the program exits.</p>
<p>However, I don't want to deal with creation and removal of the temp di... | [
{
"answer_id": 477895,
"author": "Calmarius",
"author_id": 58805,
"author_profile": "https://Stackoverflow.com/users/58805",
"pm_score": 0,
"selected": false,
"text": "<p>There is no way to do any cleanup if your process gets killed (eg. from the task manager).</p>\n\n<p>Other process sh... | 2009/01/25 | [
"https://Stackoverflow.com/questions/477880",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | In C++, I have a few functions that need to write to a temp directory. Ideally, only one temp directory gets created that they all write to (to minimize I/O overhead). That directory should be automagically removed when the program exits.
However, I don't want to deal with creation and removal of the temp directory in... | Using popen() to execute things like "rm -r" or "mktemp -p /tmp" is a recipe for disaster. In my opinion it is extremely bad style.
UNIX Specific: If you want temporary files to disappear even if your application terminates abnormally then the best way to go is to immediately unlink temp files after opening them. Your... |
477,892 | <p>This is what I have right now: </p>
<pre><code>$("#number").val(parseFloat($("#number").val()).toFixed(2));
</code></pre>
<p>It looks messy to me. I don't think I'm chaining the functions correctly. Do I have to call it for each textbox, or can I create a separate function?</p>
| [
{
"answer_id": 477928,
"author": "Svante Svenson",
"author_id": 19707,
"author_profile": "https://Stackoverflow.com/users/19707",
"pm_score": 6,
"selected": false,
"text": "<p>Maybe something like this, where you could select more than one element if you'd like?</p>\n\n<pre class=\"lang-... | 2009/01/25 | [
"https://Stackoverflow.com/questions/477892",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1122/"
] | This is what I have right now:
```
$("#number").val(parseFloat($("#number").val()).toFixed(2));
```
It looks messy to me. I don't think I'm chaining the functions correctly. Do I have to call it for each textbox, or can I create a separate function? | If you're doing this to several fields, or doing it quite often, then perhaps a plugin is the answer.
Here's the beginnings of a jQuery plugin that formats the value of a field to two decimal places.
It is triggered by the onchange event of the field. You may want something different.
```
<script type="text/java... |
477,908 | <p>This works great:</p>
<pre><code><my:DatePicker IsTodayHighlighted="True" Width="200">
</my:DatePicker>
</code></pre>
<p>But I want to format the date, something like this:</p>
<pre><code><my:DatePicker IsTodayHighlighted="True" Width="200" Format="yyyy-mm-dd">
</my:DatePicker>
</code></... | [
{
"answer_id": 578846,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 0,
"selected": false,
"text": "<p>The Silverlight DatePicker has a SelectedDateFormat Property on it, this may be what you are looking for.</p>\n"
},
{
... | 2009/01/25 | [
"https://Stackoverflow.com/questions/477908",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4639/"
] | This works great:
```
<my:DatePicker IsTodayHighlighted="True" Width="200">
</my:DatePicker>
```
But I want to format the date, something like this:
```
<my:DatePicker IsTodayHighlighted="True" Width="200" Format="yyyy-mm-dd">
</my:DatePicker>
```
Anyone know the syntax for this? | Unfortunately the DatePicker control currently does not support free DateTime formats.
If this is something you're interested in seeing up support in future version of DatePicker, please create a codeplex feature request that suggests that.
<http://silverlight.codeplex.com/WorkItem/Create.aspx>
Just to point out that... |
477,924 |
<p>OK, I know there has been a lot of confusion over the new AAA syntax in Rhino Mocks, but I have to be honest, from what I have seen so far, I like. It reads better, and saves on some keystrokes.</p>
<p>Basically, I am testing a <code>ListController</code> which is going to basically be in charge of some lists of ... | [
{
"answer_id": 492635,
"author": "Simon Laroche",
"author_id": 33318,
"author_profile": "https://Stackoverflow.com/users/33318",
"pm_score": 1,
"selected": false,
"text": "<p>I think it has to do with what your manager.ListCount() is doing with the return value.</p>\n\n<p>If it is not us... | 2009/01/25 | [
"https://Stackoverflow.com/questions/477924",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/832/"
] | OK, I know there has been a lot of confusion over the new AAA syntax in Rhino Mocks, but I have to be honest, from what I have seen so far, I like. It reads better, and saves on some keystrokes.
Basically, I am testing a `ListController` which is going to basically be in charge of some lists of things :) I have create... | **What is your test trying to achieve?**
What behaviour or state are you verifying? Specifically, are you verifying that the collaborator (data) is having its `ListCount` method called (interaction based testing), or do you just want to make `ListCount` return a canned value to drive the class under test while verify... |
477,962 | <p>I'm trying to use <code>System.Xml.Linq</code> to create XHTML documents. Thus, the vast majority of the nodes in my trees ought to use this namespace:</p>
<pre><code>http://www.w3.org/1999/xhtml
</code></pre>
<p>I can create <code>XElement</code> nodes scoped to this namespace easily enough, using an <code>XNames... | [
{
"answer_id": 477997,
"author": "AnthonyWJones",
"author_id": 17516,
"author_profile": "https://Stackoverflow.com/users/17516",
"pm_score": 1,
"selected": false,
"text": "<p>The problem is the the XName used to create the XElement needs to specify the correct namespace. What I would be... | 2009/01/25 | [
"https://Stackoverflow.com/questions/477962",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3712/"
] | I'm trying to use `System.Xml.Linq` to create XHTML documents. Thus, the vast majority of the nodes in my trees ought to use this namespace:
```
http://www.w3.org/1999/xhtml
```
I can create `XElement` nodes scoped to this namespace easily enough, using an `XNamespace`, like this:
```
XNamespace xhtml = "http://www... | I've decided to use a static class called `XHtml`, that looks like this:
```
public static class XHtml
{
static XHtml()
{
Namespace = "http://www.w3.org/1999/xhtml";
}
public static XNamespace Namespace { get; private set; }
public static XElement Element(string name)
{
return... |
477,980 | <p>I checked out <a href="https://stackoverflow.com/questions/361161/rails-form-validation">both </a> of <a href="https://stackoverflow.com/questions/423160/rails-form-validation-conditional-bypass">these</a> previously-asked questions, and they're a help but not a full solution for my case.</p>
<p>Essentially I need ... | [
{
"answer_id": 478238,
"author": "August Lilleaas",
"author_id": 26051,
"author_profile": "https://Stackoverflow.com/users/26051",
"pm_score": 3,
"selected": true,
"text": "<p>FYI, you don't have to pass an array to <code>validates_format_of</code>. Ruby will do arrays automagically (Rai... | 2009/01/25 | [
"https://Stackoverflow.com/questions/477980",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2293/"
] | I checked out [both](https://stackoverflow.com/questions/361161/rails-form-validation) of [these](https://stackoverflow.com/questions/423160/rails-form-validation-conditional-bypass) previously-asked questions, and they're a help but not a full solution for my case.
Essentially I need to validate a user-submitted URL... | FYI, you don't have to pass an array to `validates_format_of`. Ruby will do arrays automagically (Rails parses the output of `*args`).
So, for your question, I'd go for something like this:
```
class Link < ActiveRecord::Base
validate :proper_link_format
private
def proper_link_format
[:link1, :link2, :li... |
477,998 | <p>I have the following code:</p>
<pre><code><td colspan="7"height=200 valign="top">
<iframe id="myframe" name="myframe" src="index.php?page=1" width=810 height="100" marginheight="0" marginwidth="0" frameborder="1" scrolling="auto"></iframe>
</td>
</code></pre>
<p>I have don't see any scoll ... | [
{
"answer_id": 478008,
"author": "Chris Ballance",
"author_id": 1551,
"author_profile": "https://Stackoverflow.com/users/1551",
"pm_score": 0,
"selected": false,
"text": "<p>This renders a horizontal and vertical scrollbar for me in IE7:</p>\n\n<pre><code><html>\n<body>\n<... | 2009/01/25 | [
"https://Stackoverflow.com/questions/477998",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/29505/"
] | I have the following code:
```
<td colspan="7"height=200 valign="top">
<iframe id="myframe" name="myframe" src="index.php?page=1" width=810 height="100" marginheight="0" marginwidth="0" frameborder="1" scrolling="auto"></iframe>
</td>
```
I have don't see any scoll bar, either vertically or horizontally.
Any idea... | You should only see a scrollbar in the iFrame if the page you are opening in the iFrame is bigger than the size of the iFrame. Therefore, if 'index.php?page=1' will fit on a 810x100 window than the iFrame won't have any scrollbars. If you are expecting to see a scrollbar in the td that holds the iFrame you would need t... |
478,002 | <p>Okay this is not a question of "how to get all uniques" or "How to remove duplicates from my array in php". This is a question about the time complexity.</p>
<p>I figured that the <code>array_unique</code> is somewhat O(n^2 - n) and here's my implementation:</p>
<pre><code>function array_unique2($array)
{
$t... | [
{
"answer_id": 478032,
"author": "Noah Goodrich",
"author_id": 20178,
"author_profile": "https://Stackoverflow.com/users/20178",
"pm_score": 5,
"selected": true,
"text": "<p>While I can't speak for the native array_unique function, I can tell you that your friends algorithm is faster bec... | 2009/01/25 | [
"https://Stackoverflow.com/questions/478002",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/39106/"
] | Okay this is not a question of "how to get all uniques" or "How to remove duplicates from my array in php". This is a question about the time complexity.
I figured that the `array_unique` is somewhat O(n^2 - n) and here's my implementation:
```
function array_unique2($array)
{
$to_return = array();
$curren... | While I can't speak for the native array\_unique function, I can tell you that your friends algorithm is faster because:
1. He uses a single foreach loop as opposed to your double for() loop.
2. Foreach loops tend to perform faster than for loops in PHP.
3. He used a single if(! ) comparison while you used two if() s... |
478,006 | <p>Ok, here is the code and then the discussion follows:</p>
<pre><code>public class FlatArrayList {
private static ArrayList<TestWrapperObject> probModel = new ArrayList<TestWrapperObject>();
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generat... | [
{
"answer_id": 478010,
"author": "Greg Hewgill",
"author_id": 893,
"author_profile": "https://Stackoverflow.com/users/893",
"pm_score": 4,
"selected": true,
"text": "<p>You are only creating one instance of the <code>currentRow</code> array. Move that inside the row loop and it should be... | 2009/01/25 | [
"https://Stackoverflow.com/questions/478006",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/46609/"
] | Ok, here is the code and then the discussion follows:
```
public class FlatArrayList {
private static ArrayList<TestWrapperObject> probModel = new ArrayList<TestWrapperObject>();
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
in... | You are only creating one instance of the `currentRow` array. Move that inside the row loop and it should behave more like you expect.
Specifically, the assignment in `setCurrentRow` does not create a *copy* of the object, but only assigns the reference. So each copy of your wrapper object will hold a reference to the... |
478,013 | <p>I have created a function that takes a SQL command and produces output that can then be used to fill a List of class instances. The code works great. I've included a slightly simplified version without exception handling here just for reference - skip this code if you want to jump right the problem. If you have su... | [
{
"answer_id": 478020,
"author": "Dave Markle",
"author_id": 24995,
"author_profile": "https://Stackoverflow.com/users/24995",
"pm_score": 1,
"selected": false,
"text": "<p>Question #2: </p>\n\n<p>I don't really know, but I would tend to use Activator.CreateObject() instead of FormatterS... | 2009/01/25 | [
"https://Stackoverflow.com/questions/478013",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15592/"
] | I have created a function that takes a SQL command and produces output that can then be used to fill a List of class instances. The code works great. I've included a slightly simplified version without exception handling here just for reference - skip this code if you want to jump right the problem. If you have suggest... | Anonymous types encapsulate a set of *read-only* properties. This explains
1. Why `Type.GetFields` returns an empty array when called on your anonymous type: anonymous types do not have public fields.
2. The public properties on an anonymous type are read-only and can not have their value set by a call to `PropertyInf... |
478,017 | <p>When I run my Silverlight app, this code doesn't play a video at all:</p>
<pre><code> <MediaElement
Source="winvideo-201DataGridPreview.wmv"
AutoPlay="True"
AudioStreamIndex="2"
Margin="10"
Height="200"
Width="200"/>
</code></pre>
<p>From all of the examples... | [
{
"answer_id": 478036,
"author": "texmex5",
"author_id": 54814,
"author_profile": "https://Stackoverflow.com/users/54814",
"pm_score": 1,
"selected": false,
"text": "<p>It might be the case of unsupported mediafile.</p>\n\n<p>These are supported (source: <a href=\"http://msdn.microsoft.c... | 2009/01/25 | [
"https://Stackoverflow.com/questions/478017",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4639/"
] | When I run my Silverlight app, this code doesn't play a video at all:
```
<MediaElement
Source="winvideo-201DataGridPreview.wmv"
AutoPlay="True"
AudioStreamIndex="2"
Margin="10"
Height="200"
Width="200"/>
```
From all of the examples I can find of MediaElement, it ... | Edward, based on your XAML check: 1) that the WMV file is in the appropriate encoding format, 2) that the WMV file is located alongside where your XAP file is (I'd actually check this first). |
478,049 | <p>I just started Data Structures and Algorithms which is taught in Java. So far I've only learned C++ in my life so I'm still VERY new to using java.</p>
<p>Anyways I have a homework problem I'm a little stuck on:</p>
<p>Write a recursive method that returns the number of 1's in the binary representation of N. Use t... | [
{
"answer_id": 478060,
"author": "Stefan Arentz",
"author_id": 56837,
"author_profile": "https://Stackoverflow.com/users/56837",
"pm_score": 4,
"selected": false,
"text": "<p>This is not a hard problem to solve. What you need to do is stop writing code and first solve the problem on pape... | 2009/01/25 | [
"https://Stackoverflow.com/questions/478049",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/58837/"
] | I just started Data Structures and Algorithms which is taught in Java. So far I've only learned C++ in my life so I'm still VERY new to using java.
Anyways I have a homework problem I'm a little stuck on:
Write a recursive method that returns the number of 1's in the binary representation of N. Use the fact that this... | This is not a hard problem to solve. What you need to do is stop writing code and first solve the problem on paper. Then convert your algorithm to code. |
478,050 | <p>I'd like to accomplish something like this: Call a method, say "turn", and then have "turn" applied differently to different data types, e.g., calling "turn" with a "screwdriver" object/param uses the "turnScrewdriver" method, calling "turn" with a "steeringWheel" object/param uses the "turnSteeringWheel" method, et... | [
{
"answer_id": 478055,
"author": "Filip Ekberg",
"author_id": 39106,
"author_profile": "https://Stackoverflow.com/users/39106",
"pm_score": 0,
"selected": false,
"text": "<p>You need to check the PHP Manual for instructions <a href=\"http://se2.php.net/overload\" rel=\"nofollow noreferre... | 2009/01/25 | [
"https://Stackoverflow.com/questions/478050",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/49529/"
] | I'd like to accomplish something like this: Call a method, say "turn", and then have "turn" applied differently to different data types, e.g., calling "turn" with a "screwdriver" object/param uses the "turnScrewdriver" method, calling "turn" with a "steeringWheel" object/param uses the "turnSteeringWheel" method, etc. ... | I read davethegr8's solution but it seems one could do the same thing with stronger typing:
```
<?php
interface Turnable
{
public function turn();
}
class Screwdriver implements Turnable
{
public function turn() {
print "to turning sir!\n";
}
}
class SteeringWheel implements Turnable
{
public function t... |
478,065 | <p>I'm building a PHP application using CodeIgniter. It is similar to <code>Let Me Google That For You</code> where you write a sentence into a text input box, click submit, and you are taken to a URL that displays the result. I wanted the URL to be human-editable, and relatively simple. I've gotten around the CodeIgni... | [
{
"answer_id": 478236,
"author": "waney",
"author_id": 58123,
"author_profile": "https://Stackoverflow.com/users/58123",
"pm_score": 0,
"selected": false,
"text": "<p>I usually do human readable urls like this</p>\n\n<pre><code>$humanReadableUrl= implode(\"_\",preg_split('/\\W+/', trim($... | 2009/01/25 | [
"https://Stackoverflow.com/questions/478065",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | I'm building a PHP application using CodeIgniter. It is similar to `Let Me Google That For You` where you write a sentence into a text input box, click submit, and you are taken to a URL that displays the result. I wanted the URL to be human-editable, and relatively simple. I've gotten around the CodeIgniter URL routin... | If your’re using Apache 2.2 and later, you can use the [B flag](http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html#rewriteflags) to force the backreference to be escaped:
```
RewriteCond %{QUERY_STRING} ^q=.*
RewriteRule ^ /index.php/app/create/%0? [L,B]
``` |
478,071 | <p>When we have a RichEdit control and send it an <code>EM_AUTOURLDETECT</code> message with WPARAM set to TRUE, it nicely hightlights the detected URLs and sends the <code>EN_LINK</code> notifications.
But it does this only for text that is entered into the control. I haven't found the way to do it for text that's loa... | [
{
"answer_id": 478334,
"author": "Kevin Loney",
"author_id": 13834,
"author_profile": "https://Stackoverflow.com/users/13834",
"pm_score": 0,
"selected": false,
"text": "<p>Without knowing the format of the text you are trying to add to the control with SetWindowText and EM_STREAMIN I'm ... | 2009/01/25 | [
"https://Stackoverflow.com/questions/478071",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/22046/"
] | When we have a RichEdit control and send it an `EM_AUTOURLDETECT` message with WPARAM set to TRUE, it nicely hightlights the detected URLs and sends the `EN_LINK` notifications.
But it does this only for text that is entered into the control. I haven't found the way to do it for text that's loaded into the control with... | I just knocked up a basic WTL dialog based app containing a riched20 control and the following works fine:
```
CRichEditCtrl richedit = GetDlgItem(IDC_RICHEDIT);
richedit.SetAutoURLDetect(TRUE);
richedit.SetWindowText(_T("http://www.stackoverflow.com"));
```
I have some old MFC code that does something similar, albe... |
478,075 | <p>I want to create a file using C++, but I have no idea how to do it. For example I want to create a text file named <code>Hello.txt</code>. </p>
<p>Can anyone help me?</p>
| [
{
"answer_id": 478088,
"author": "James Thompson",
"author_id": 57458,
"author_profile": "https://Stackoverflow.com/users/57458",
"pm_score": 8,
"selected": true,
"text": "<p>One way to do this is to create an instance of the ofstream class, and use it to write to your file. Here's a lin... | 2009/01/25 | [
"https://Stackoverflow.com/questions/478075",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/58839/"
] | I want to create a file using C++, but I have no idea how to do it. For example I want to create a text file named `Hello.txt`.
Can anyone help me? | One way to do this is to create an instance of the ofstream class, and use it to write to your file. Here's a link to a website that has some example code, and some more information about the standard tools available with most implementations of C++:
[ofstream reference](http://en.cppreference.com/w/cpp/io/basic_ofstr... |
478,078 | <p>I'm trying to get access to a form and its elements. The form is within an iframe and the javascript code that is accessing the form is within the main document. </p>
<p>I'm not sure what else I should put into the question, so please let me know if I need to add something else.</p>
<p>(form and main page are in t... | [
{
"answer_id": 478111,
"author": "geowa4",
"author_id": 50214,
"author_profile": "https://Stackoverflow.com/users/50214",
"pm_score": 5,
"selected": true,
"text": "<pre><code>var ifr = document.getElementById( yourIframeId );\nvar ifrDoc = ifr.contentDocument || ifr.contentWindow.documen... | 2009/01/25 | [
"https://Stackoverflow.com/questions/478078",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/29505/"
] | I'm trying to get access to a form and its elements. The form is within an iframe and the javascript code that is accessing the form is within the main document.
I'm not sure what else I should put into the question, so please let me know if I need to add something else.
(form and main page are in the same domain)
... | ```
var ifr = document.getElementById( yourIframeId );
var ifrDoc = ifr.contentDocument || ifr.contentWindow.document;
var theForm = ifrDoc.getElementById( yourFormId );
```
Or you could have some code in the frame that sets a variable in `parent` to the form, but I wouldn't trust that method. |
478,114 | <p>I am using the vim editor and I wanted to empty out all methods in the class, for instance </p>
<pre><code>class A {
public:
int getNumber() const {
return number;
}
void setNumber(int num) {
number = num;
}
};
</code></pre>
<p>I wanted to have a r... | [
{
"answer_id": 478133,
"author": "Peter Severin",
"author_id": 22716,
"author_profile": "https://Stackoverflow.com/users/22716",
"pm_score": 0,
"selected": false,
"text": "<p>I think this is something that is best done using recorded macros and not regexes. Sorry I don't have time to cre... | 2009/01/25 | [
"https://Stackoverflow.com/questions/478114",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/43756/"
] | I am using the vim editor and I wanted to empty out all methods in the class, for instance
```
class A {
public:
int getNumber() const {
return number;
}
void setNumber(int num) {
number = num;
}
};
```
I wanted to have a regex where I could substitu... | Since braces may of course nest within your functions, it's unfortunately impossible to create a regular expression which could match the corresponding ending brace.
Fortunately, VIM does have the move-to-corresponding (which will move forward to the next brace/bracket/etc. and jump to the corresponding opening/closin... |
478,121 | <pre><code>function foldersize($path) {
$total_size = 0;
$files = scandir($path);
foreach($files as $t) {
if (is_dir(rtrim($path, '/') . '/' . $t)) {
if ($t<>"." && $t<>"..") {
$size = foldersize(rtrim($path, '/') . '/' . $t);
$total_size += $size;
}
}... | [
{
"answer_id": 478156,
"author": "Douglas Leeder",
"author_id": 3978,
"author_profile": "https://Stackoverflow.com/users/3978",
"pm_score": 2,
"selected": false,
"text": "<p>There are several things you could do to optimise the script - but maximum success would make it IO-bound rather t... | 2009/01/25 | [
"https://Stackoverflow.com/questions/478121",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | ```
function foldersize($path) {
$total_size = 0;
$files = scandir($path);
foreach($files as $t) {
if (is_dir(rtrim($path, '/') . '/' . $t)) {
if ($t<>"." && $t<>"..") {
$size = foldersize(rtrim($path, '/') . '/' . $t);
$total_size += $size;
}
} else {
$size = files... | The following are other solutions [offered elsewhere](http://forums.devshed.com/showpost.php?p=1527717&postcount=4):
If on a Windows Host:
```
<?
$f = 'f:/www/docs';
$obj = new COM ( 'scripting.filesystemobject' );
if ( is_object ( $obj ) )
{
$ref = $obj->getfolder ( $f );
echo 'Direct... |
478,126 | <p>My company is planning to implement SAP HR in our organsization. We already have the other modules running. We plan to offer ESS/MSS to approximatly 200 000 users. Our current configuration is one machine with a Central Instance and 3 machines with Dialogue Instances. The DB is on the Central Instance machine. Enter... | [
{
"answer_id": 478156,
"author": "Douglas Leeder",
"author_id": 3978,
"author_profile": "https://Stackoverflow.com/users/3978",
"pm_score": 2,
"selected": false,
"text": "<p>There are several things you could do to optimise the script - but maximum success would make it IO-bound rather t... | 2009/01/25 | [
"https://Stackoverflow.com/questions/478126",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/87645/"
] | My company is planning to implement SAP HR in our organsization. We already have the other modules running. We plan to offer ESS/MSS to approximatly 200 000 users. Our current configuration is one machine with a Central Instance and 3 machines with Dialogue Instances. The DB is on the Central Instance machine. Enterpri... | The following are other solutions [offered elsewhere](http://forums.devshed.com/showpost.php?p=1527717&postcount=4):
If on a Windows Host:
```
<?
$f = 'f:/www/docs';
$obj = new COM ( 'scripting.filesystemobject' );
if ( is_object ( $obj ) )
{
$ref = $obj->getfolder ( $f );
echo 'Direct... |
478,135 | <p>Every so often, I'm done modifying a piece of code and I would like to "lock" or make a region of code "read only". That way, the only way I can modify the code is if I unlock it first. Is there any way to do this? </p>
| [
{
"answer_id": 478141,
"author": "Douglas Leeder",
"author_id": 3978,
"author_profile": "https://Stackoverflow.com/users/3978",
"pm_score": 1,
"selected": false,
"text": "<p>Split up the code into separate files and then check into a source control system?</p>\n"
},
{
"answer_id"... | 2009/01/25 | [
"https://Stackoverflow.com/questions/478135",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/10352/"
] | Every so often, I'm done modifying a piece of code and I would like to "lock" or make a region of code "read only". That way, the only way I can modify the code is if I unlock it first. Is there any way to do this? | The easiest way which would work in many cases is to make it a *partial type* - i.e. a single class whose source code is spread across multiple files. You could then make one file read-only and the other writable.
To declare a partial type, you just use the `partial` contextual keyword in the declaration:
```
// MyCl... |
478,148 | <p>The following code was known to be working three weeks ago. In the interim we have installed IE 7 and a bunch of security patches. The ultimate question will be, does anyone know how to restore the old behavior?</p>
<p><strong>Scenario</strong></p>
<p>We have the following JavaScript code in web page 1 (let's call... | [
{
"answer_id": 478164,
"author": "John Boker",
"author_id": 2847,
"author_profile": "https://Stackoverflow.com/users/2847",
"pm_score": 1,
"selected": false,
"text": "<p>it might be a typo but there's a missing \" after the bar.aspx in the sample code.</p>\n"
},
{
"answer_id": 47... | 2009/01/25 | [
"https://Stackoverflow.com/questions/478148",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/58842/"
] | The following code was known to be working three weeks ago. In the interim we have installed IE 7 and a bunch of security patches. The ultimate question will be, does anyone know how to restore the old behavior?
**Scenario**
We have the following JavaScript code in web page 1 (let's call it foo.aspx), that is invoked... | it might be a typo but there's a missing " after the bar.aspx in the sample code. |
478,165 | <p>I want to create a really easy to use 2D Grid. Each cell in the grid needs to be able to store a load of data. Ideally I would like to be able to traverse through the grid one cell at a time, as well as obtain the immediate neighbours of any of the grid cells.</p>
<p>My first thought was to store a vector of pointe... | [
{
"answer_id": 478197,
"author": "Jacek Ławrynowicz",
"author_id": 43399,
"author_profile": "https://Stackoverflow.com/users/43399",
"pm_score": 2,
"selected": false,
"text": "<p>I would go for Boost.MultiArray</p>\n"
},
{
"answer_id": 478220,
"author": "strager",
"author... | 2009/01/25 | [
"https://Stackoverflow.com/questions/478165",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18909/"
] | I want to create a really easy to use 2D Grid. Each cell in the grid needs to be able to store a load of data. Ideally I would like to be able to traverse through the grid one cell at a time, as well as obtain the immediate neighbours of any of the grid cells.
My first thought was to store a vector of pointers to a Ce... | If you want a four-direction iterator, make your own:
```
template<typename T, int width, int height>
class Grid {
public:
T data[width * height];
iterator begin() {
return iterator(data);
}
iterator end() {
return iterator(data + width * height);
}... |
478,201 | <p>Encoding issues are among the one topic that have bitten me most often during development. Every platform insists on its own encoding, most likely some non-UTF-8 defaults are in the game. (I'm usually working on Linux, defaulting to UTF-8, my colleagues mostly work on german Windows, defaulting to ISO-8859-1 or some... | [
{
"answer_id": 478227,
"author": "Stefan Arentz",
"author_id": 56837,
"author_profile": "https://Stackoverflow.com/users/56837",
"pm_score": 2,
"selected": false,
"text": "<p>Localization is pretty tough.</p>\n\n<p>I think you are really asking two questions. One of them, how do you get ... | 2009/01/25 | [
"https://Stackoverflow.com/questions/478201",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13447/"
] | Encoding issues are among the one topic that have bitten me most often during development. Every platform insists on its own encoding, most likely some non-UTF-8 defaults are in the game. (I'm usually working on Linux, defaulting to UTF-8, my colleagues mostly work on german Windows, defaulting to ISO-8859-1 or some si... | There is a [regular expression to test if a string is valid UTF-8](http://www.w3.org/International/questions/qa-forms-utf-8):
```
$field =~
m/\A(
[\x09\x0A\x0D\x20-\x7E] # ASCII
| [\xC2-\xDF][\x80-\xBF] # non-overlong 2-byte
| \xE0[\xA0-\xBF][\x80-\xBF] # excluding overlongs... |
478,202 | <p>My problem is simple, but I cannot find a way to solve it :(</p>
<p>When the user clicks a specific button, I need to open a new aspx page (in a new window) so that he is able to select something that needs to be returned to the original page.
I was able to open the new page with window.open, however, I'm not able ... | [
{
"answer_id": 478203,
"author": "Adam Ralph",
"author_id": 49241,
"author_profile": "https://Stackoverflow.com/users/49241",
"pm_score": 0,
"selected": false,
"text": "<p>Perhaps instead of opening a seperate page in a new window you should show an element in the current window and use ... | 2009/01/25 | [
"https://Stackoverflow.com/questions/478202",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/51500/"
] | My problem is simple, but I cannot find a way to solve it :(
When the user clicks a specific button, I need to open a new aspx page (in a new window) so that he is able to select something that needs to be returned to the original page.
I was able to open the new page with window.open, however, I'm not able to set the... | If you use something like [jquery](http://jquery.com), which, by the way, is highly recommended instead of using basic DOM functions, you can try this:
```
window.opener.$("[id$=txtValue]").val(valueToSet);
```
which should do the following:
* `window.opener.$` if the query function from the opener window
* ("[id$... |
478,208 | <p>I wanted to remap (for normal mode) <kbd>Ctrl</kbd>+<kbd>a</kbd> to <kbd>Ctrl</kbd>+<kbd>=</kbd> and <kbd>Ctrl</kbd>+<kbd>x</kbd> to <kbd>Ctrl</kbd>+<kbd>-</kbd> but it didn't work.</p>
<p>Is there another way to write this?</p>
| [
{
"answer_id": 478293,
"author": "Dave Ray",
"author_id": 40310,
"author_profile": "https://Stackoverflow.com/users/40310",
"pm_score": 0,
"selected": false,
"text": "<p>I'm not sure about <kbd>Ctrl</kbd>+<kbd>=</kbd>, but for <kbd>Ctrl</kbd>+<kbd>-</kbd>, try <kbd>Ctrl</kbd>+<kbd>_</kbd... | 2009/01/25 | [
"https://Stackoverflow.com/questions/478208",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | I wanted to remap (for normal mode) `Ctrl`+`a` to `Ctrl`+`=` and `Ctrl`+`x` to `Ctrl`+`-` but it didn't work.
Is there another way to write this? | I had a problem using and because my shell uses those to resize my window and font size. I was able to map '+' and '-' to the commands so pressing them in normal mode incremented and decremented values.
```
map + <C-a>
map - <C-x>
```
Is that what you were trying to accomplish? I don't know if that will work for yo... |
478,209 | <p>I have a canvas with user controls arranged on it. When a tooltip is assigned to the usercontrol or one of its children, that tooltip does not show (open event does not get fired either). I do not explicitly disable any of them.</p>
<p>I've placed plenty of tooltips elsewhere in the application and they all show, e... | [
{
"answer_id": 478607,
"author": "Dominic Hopton",
"author_id": 9475,
"author_profile": "https://Stackoverflow.com/users/9475",
"pm_score": 2,
"selected": false,
"text": "<p>If the background of the Usercontrol is x:Null, then the mouse events will fall through to the underlying content... | 2009/01/25 | [
"https://Stackoverflow.com/questions/478209",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | I have a canvas with user controls arranged on it. When a tooltip is assigned to the usercontrol or one of its children, that tooltip does not show (open event does not get fired either). I do not explicitly disable any of them.
I've placed plenty of tooltips elsewhere in the application and they all show, except the ... | I finally figured it out.
On my canvas, I was drawing pointer lines (horizontal and vertical to show on the grid where I am and the values on the left/bottom), it turns out that when the hit test was being performed, it was hitting those lines and stopping. By setting IsHitTestVisible to false on all unrelevant geometr... |
478,251 | <pre><code><?php
session_start();
include("connect.php");
$timeout = 60 * 30;
$fingerprint = md5($_SERVER['REMOTE_ADDR'] . $_SERVER['HTTP_USER_AGENT']);
if(isset($_POST['userName']))
{
$user = mysql_real_escape_string($_POST['userName']);
$password = mysql_real_escape_string($_POST['password']);
$matc... | [
{
"answer_id": 478256,
"author": "stesch",
"author_id": 41860,
"author_profile": "https://Stackoverflow.com/users/41860",
"pm_score": 1,
"selected": false,
"text": "<p><code>$_SERVER['REMOTE_ADDR']</code> could change if the user is behind a proxy.</p>\n"
},
{
"answer_id": 478260... | 2009/01/25 | [
"https://Stackoverflow.com/questions/478251",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/53467/"
] | ```
<?php
session_start();
include("connect.php");
$timeout = 60 * 30;
$fingerprint = md5($_SERVER['REMOTE_ADDR'] . $_SERVER['HTTP_USER_AGENT']);
if(isset($_POST['userName']))
{
$user = mysql_real_escape_string($_POST['userName']);
$password = mysql_real_escape_string($_POST['password']);
$matchingUser =... | When you log out, first, you are *queuing* the destruction of the cookie (it will occur after the response is sent), then immediately after, rendering your page. The browser has no chance to delete the cookie before rendering, and your `$_SESSION` variables are still alive.
PHP docs say about `session_destroy`:
>
> ... |
478,258 | <p>I've singled out a failure on my program that prevents me from assigning a value to the variable <code>addAntonymAnswer1</code>. I've tried running <code>cin.clear()</code> before the statement to get the thing read my <code>yes/no</code> answer, but the code just won't respond. </p>
<p>The program bit that's faili... | [
{
"answer_id": 478267,
"author": "1800 INFORMATION",
"author_id": 3146,
"author_profile": "https://Stackoverflow.com/users/3146",
"pm_score": 1,
"selected": false,
"text": "<p>It is \"stuck\" because it is waiting for input. cin is attached to the standard input handle for the program, y... | 2009/01/25 | [
"https://Stackoverflow.com/questions/478258",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/45963/"
] | I've singled out a failure on my program that prevents me from assigning a value to the variable `addAntonymAnswer1`. I've tried running `cin.clear()` before the statement to get the thing read my `yes/no` answer, but the code just won't respond.
The program bit that's failing is located inside `void dictionaryMenu(v... | `cin.clear()` doesn't clear the standard input. What it does is clearing error bits, like `eofbit`, `failbit` and others, and sets the stream into a good state. Maybe you expected it to clear out anything in it? If the user typed
```
yes no
```
Just before, and you
```
cin >> someStringVariable;
```
It will read... |
478,269 | <p>I just came across the question - is the access of an object safely possible across threads in C#.</p>
<p>E.g. with the code</p>
<pre><code>//Somewhere long ago
MyClass myVar = new MyClass("First Instance");
//Then later, happening at the same time
//In thread one
myVar = new MyClass("Second Instance");
//In thr... | [
{
"answer_id": 478292,
"author": "Raymond Roestenburg",
"author_id": 50142,
"author_profile": "https://Stackoverflow.com/users/50142",
"pm_score": 0,
"selected": false,
"text": "<p>The code example in your question is thread-safe. Obviously depending on what you do inside that constructo... | 2009/01/25 | [
"https://Stackoverflow.com/questions/478269",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/21566/"
] | I just came across the question - is the access of an object safely possible across threads in C#.
E.g. with the code
```
//Somewhere long ago
MyClass myVar = new MyClass("First Instance");
//Then later, happening at the same time
//In thread one
myVar = new MyClass("Second Instance");
//In thread two
myVar.PrintNa... | To your first. Its almost certainly safe but I would lock it none the less.
As to your cache question what cache are you talking about, the only ones I can think of are the CPU caches, if we had worry about whether these we're dirty and needed flushing we'd all be in a lot of trouble.
**Edit:**
From your comment I s... |
478,278 | <p>I am buidling a user control. Currently it consists of a textbox and a button - as a learning experience. This will be used as a basis for a more useful control.</p>
<p>I want to add a DataSource, display member and ValueMember.<br>
Here is my code for the datasource. It will display in the Properties editor, bu... | [
{
"answer_id": 478466,
"author": "Marc Gravell",
"author_id": 23354,
"author_profile": "https://Stackoverflow.com/users/23354",
"pm_score": 4,
"selected": true,
"text": "<p>An easier option may be to use an attribute provider instead:</p>\n\n<pre><code>[AttributeProvider(typeof(IListSour... | 2009/01/25 | [
"https://Stackoverflow.com/questions/478278",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/55520/"
] | I am buidling a user control. Currently it consists of a textbox and a button - as a learning experience. This will be used as a basis for a more useful control.
I want to add a DataSource, display member and ValueMember.
Here is my code for the datasource. It will display in the Properties editor, but is disabled ... | An easier option may be to use an attribute provider instead:
```
[AttributeProvider(typeof(IListSource))]
```
You could try using the assembly-qualified name? and specifying the editor?
```
[TypeConverter("System.Windows.Forms.Design.DataSourceConverter, System.Design, Version=2.0.0.0, Culture=neutral, PublicKeyTo... |
478,296 | <p>How do you go about changing the subtype of a row in NHibernate? For example if I have a Customer entity and a subclass of TierOneCustomer, I have a case where I need to change a Customer to a TierOneCustomer but the TierOneCustomer should have the same Id (PK) as the original Customer entity.</p>
<p>The mapping lo... | [
{
"answer_id": 478524,
"author": "David Crow",
"author_id": 2783,
"author_profile": "https://Stackoverflow.com/users/2783",
"pm_score": 5,
"selected": true,
"text": "<p>Short answer is yes, you can change the discriminator value for the particular row(s) using <a href=\"http://www.hibern... | 2009/01/25 | [
"https://Stackoverflow.com/questions/478296",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4805/"
] | How do you go about changing the subtype of a row in NHibernate? For example if I have a Customer entity and a subclass of TierOneCustomer, I have a case where I need to change a Customer to a TierOneCustomer but the TierOneCustomer should have the same Id (PK) as the original Customer entity.
The mapping looks someth... | Short answer is yes, you can change the discriminator value for the particular row(s) using [native SQL](http://www.hibernate.org/hib_docs/nhibernate/1.2/reference/en/html/querysql.html).
However, I don't think NHibernate is intended to work this way, since the discriminator is generally "invisible" to the Java layer,... |
478,382 | <p>I have m2m field, lets say it have name 'relations', so i want to allow user to send as many relations as he wants. I add new input to html with javascript with same name, like so</p>
<pre><code><input type='text' name='relations' value='a' />
<input type='text' name='relations' value='b' />
</code></pr... | [
{
"answer_id": 478406,
"author": "Tiago",
"author_id": 55283,
"author_profile": "https://Stackoverflow.com/users/55283",
"pm_score": 6,
"selected": true,
"text": "<p>I don't know how to do that with Forms, but if you want to grab the values in the raw way, here's how I'd do:</p>\n\n<pre>... | 2009/01/25 | [
"https://Stackoverflow.com/questions/478382",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20955/"
] | I have m2m field, lets say it have name 'relations', so i want to allow user to send as many relations as he wants. I add new input to html with javascript with same name, like so
```
<input type='text' name='relations' value='a' />
<input type='text' name='relations' value='b' />
```
in cleaned\_data i receive only... | I don't know how to do that with Forms, but if you want to grab the values in the raw way, here's how I'd do:
```
relations = request.POST.getlist('relations')
``` |
478,387 | <p>I have a business need to be able to customize the UserAgent for an embedded UIWebView. (For instance, I'd like the server to respond differently if, say, a user is using one version of the app versus another.)</p>
<p>Is it possible to customize the UserAgent in the existing UIWebView control the way it is, say, f... | [
{
"answer_id": 558754,
"author": "Dshutsi",
"author_id": 67547,
"author_profile": "https://Stackoverflow.com/users/67547",
"pm_score": 4,
"selected": false,
"text": "<p>It should work with an NSMutableURLRequest as Kuso has written.</p>\n\n<pre><code>NSMutableURLRequest *urlRequest = [[N... | 2009/01/25 | [
"https://Stackoverflow.com/questions/478387",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | I have a business need to be able to customize the UserAgent for an embedded UIWebView. (For instance, I'd like the server to respond differently if, say, a user is using one version of the app versus another.)
Is it possible to customize the UserAgent in the existing UIWebView control the way it is, say, for an embed... | ### Modern Swift
Here's a suggestion for Swift 3+ projects from StackOverflow users PassKit and Kheldar:
```
UserDefaults.standard.register(defaults: ["UserAgent" : "Custom Agent"])
```
Source: <https://stackoverflow.com/a/27330998/128579>
### Earlier Objective-C Answer
With iOS 5 changes, I recommend the followi... |
478,410 | <p>Given three tables Dates(date aDate, doUse boolean), Days(rangeId int, day int, qty int) and Range(rangeId int, startDate date) in Oracle</p>
<p>I want to join these so that Range is joined with Dates from aDate = startDate where doUse = 1 whith each day in Days.</p>
<p>Given a single range it might be done someth... | [
{
"answer_id": 478443,
"author": "John Nilsson",
"author_id": 24243,
"author_profile": "https://Stackoverflow.com/users/24243",
"pm_score": 1,
"selected": false,
"text": "<p>Ok, so maybe I've found a way. Someting like this:</p>\n\n<pre><code>SELECT irangeId, aDate + sum(case when doUse ... | 2009/01/25 | [
"https://Stackoverflow.com/questions/478410",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/24243/"
] | Given three tables Dates(date aDate, doUse boolean), Days(rangeId int, day int, qty int) and Range(rangeId int, startDate date) in Oracle
I want to join these so that Range is joined with Dates from aDate = startDate where doUse = 1 whith each day in Days.
Given a single range it might be done something like this
``... | Try this:
```
SELECT rt.rangeId, aDate, CASE WHEN doUse = 1 THEN qty ELSE 0 END AS qty
FROM (
SELECT *
FROM (
SELECT r.*, t.*, SUM(doUse) OVER (PARTITION BY rangeId ORDER BY aDate) AS span
FROM (
SELECT r.rangeId, startDate, MAX(day) AS dm
FROM Range r, D... |
478,422 | <p>A very simple ?: operator in C#, combined with a simple array and LINQ (to Objects) call to Reverse() is apparently enough to cause the exception "System.Security.VerificationException: Operation could destabilize the runtime." when run on an ASP.NET web site running with "High" trust (note that "Full" is the defaul... | [
{
"answer_id": 478515,
"author": "John Fisher",
"author_id": 50358,
"author_profile": "https://Stackoverflow.com/users/50358",
"pm_score": 2,
"selected": true,
"text": "<p>This line does not have the issue:</p>\n\n<pre><code>return test ? widgets.AsEnumerable() : widgets.Reverse();\n</co... | 2009/01/25 | [
"https://Stackoverflow.com/questions/478422",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/46926/"
] | A very simple ?: operator in C#, combined with a simple array and LINQ (to Objects) call to Reverse() is apparently enough to cause the exception "System.Security.VerificationException: Operation could destabilize the runtime." when run on an ASP.NET web site running with "High" trust (note that "Full" is the default)
... | This line does not have the issue:
```
return test ? widgets.AsEnumerable() : widgets.Reverse();
``` |
478,434 | <p>In Matlab, I recall being able to declare an array and initialize it and it resides in memory during the entire Matlab session. I could copy it, modify it, and run it through tests. Is this option available in Ruby? Basically I want to create and populate an array of 12 million 32-bit integers. Then I want to ru... | [
{
"answer_id": 478450,
"author": "Daniel",
"author_id": 6852,
"author_profile": "https://Stackoverflow.com/users/6852",
"pm_score": 2,
"selected": false,
"text": "<p>If you are using the interactive ruby console (irb) then you can declare a global variable which contains your data.</p>\n... | 2009/01/25 | [
"https://Stackoverflow.com/questions/478434",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/38593/"
] | In Matlab, I recall being able to declare an array and initialize it and it resides in memory during the entire Matlab session. I could copy it, modify it, and run it through tests. Is this option available in Ruby? Basically I want to create and populate an array of 12 million 32-bit integers. Then I want to run code ... | The global variable is one way but a bit cumbersome I'd say.
That means you want persistence of objects as you want it to be available across modifications of your code. You then need to initialize your data and save it in a file. You have several possibilities, something like [YAML](http://www.yaml.org/)/[JSON](http:... |
478,448 | <p>I'm triying to combine a TabBar + Navigation app.</p>
<p>I have 5 tab bars, 4 are listing of stuff and drill down to details views.</p>
<p>I try to follow this tutorial:</p>
<p><a href="http://www.iphonedevforums.com/forum/iphone-sdk-development/124-view-controller-problem.html" rel="noreferrer">http://www.iphone... | [
{
"answer_id": 753437,
"author": "bentford",
"author_id": 946,
"author_profile": "https://Stackoverflow.com/users/946",
"pm_score": 1,
"selected": false,
"text": "<p>Here is an <a href=\"http://twilloapp.blogspot.com/2009/03/how-to-embed-navigation-controller.html\" rel=\"nofollow norefe... | 2009/01/25 | [
"https://Stackoverflow.com/questions/478448",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/53185/"
] | I'm triying to combine a TabBar + Navigation app.
I have 5 tab bars, 4 are listing of stuff and drill down to details views.
I try to follow this tutorial:
<http://www.iphonedevforums.com/forum/iphone-sdk-development/124-view-controller-problem.html>
But always get a blank view.
This is what I do, with a clean pro... | First, you never want to subclass UINavigationController or UITabBarController.
Second, I did not quite get what you did, but a correct sequence to create a navigation controller inside a tab bar controller is something like this:
```
// in MyAppDelegate.h
UINavigationController *nc1, *nc2;
FirstTabRootViewController... |
478,454 | <p>I am writing a little game in which the user is asked for their race and class.
There are five possible races of string[5] and four possible classes of string[9].</p>
<p>How do I program pascal to 1. define the five races and four classes as constants, 2. check the user input to see whether the input is within the... | [
{
"answer_id": 478491,
"author": "Steve",
"author_id": 22712,
"author_profile": "https://Stackoverflow.com/users/22712",
"pm_score": 2,
"selected": false,
"text": "<p>Since your input is strictly defined, my first question is, must you use strings as the user input? Can you not give the ... | 2009/01/25 | [
"https://Stackoverflow.com/questions/478454",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | I am writing a little game in which the user is asked for their race and class.
There are five possible races of string[5] and four possible classes of string[9].
How do I program pascal to 1. define the five races and four classes as constants, 2. check the user input to see whether the input is within the possible r... | Since your input is strictly defined, my first question is, must you use strings as the user input? Can you not give the user a choice? Say a drop down? Then you can map each choice to an enumeration.
```
type
race = (rcRace0, rcRace1, rcRace2 rcRace3, rcRace4);
case race(Input) of //input is an integer, index of ... |
478,458 | <p>Is there any way to beat the 100-group limit for regular expressions in Python? Also, could someone explain why there is a limit.</p>
| [
{
"answer_id": 478470,
"author": "Keltia",
"author_id": 16143,
"author_profile": "https://Stackoverflow.com/users/16143",
"pm_score": 3,
"selected": false,
"text": "<p>There is a limit because it would take too much memory to store the complete state machine efficiently. I'd say that if... | 2009/01/25 | [
"https://Stackoverflow.com/questions/478458",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/49701/"
] | Is there any way to beat the 100-group limit for regular expressions in Python? Also, could someone explain why there is a limit. | I'm not sure what you're doing exactly, but try using a single group, with a lot of OR clauses inside... so (this)|(that) becomes (this|that). You can do clever things with the results by passing a function that does something with the particular word that is matched:
```
newContents, num = cregex.subn(lambda m: repl... |
478,469 | <p>I wonder if you think that there is a need to refactor this class.( regarding separation of concern)</p>
<pre><code>publi class CSVLIstMapping<T>
{
void ReadMappingFromAttirbutes();
void GetDataFromList();
}
</code></pre>
<p>ReadMappingFromAttributes - Reads the mapping from the type T and stores it in the... | [
{
"answer_id": 478489,
"author": "duffymo",
"author_id": 37213,
"author_profile": "https://Stackoverflow.com/users/37213",
"pm_score": 1,
"selected": false,
"text": "<p>Sounds like two concerns to me: parsing and mapping/binding. I'd separate them. CSV parsing should be a well-defined ... | 2009/01/25 | [
"https://Stackoverflow.com/questions/478469",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | I wonder if you think that there is a need to refactor this class.( regarding separation of concern)
```
publi class CSVLIstMapping<T>
{
void ReadMappingFromAttirbutes();
void GetDataFromList();
}
```
ReadMappingFromAttributes - Reads the mapping from the type T and stores it in the class. Has a name of the list t... | Sounds like two concerns to me: parsing and mapping/binding. I'd separate them. CSV parsing should be a well-defined problem. And you should care about more than mere mapping. What about validation? If you parse a date string, don't you want to make sure that it's valid before you bind it to an object attribute? I thin... |
478,474 | <p>What's going on?! Subtraction works fine until I get to 0.1 - 0.1. I'm in visual c# 2008 using the nonoba.com API.</p>
<pre><code>Console.WriteLine("hit! " + Users[targetNum].character.health + " : " + player.character.profile.attackPower);
Users[targetNum].character.health -= player.character.profile.attackPower;... | [
{
"answer_id": 478477,
"author": "Marc Gravell",
"author_id": 23354,
"author_profile": "https://Stackoverflow.com/users/23354",
"pm_score": 5,
"selected": true,
"text": "<p>That seems pretty normal for floating point math... you always have to check against a small delta to account for i... | 2009/01/25 | [
"https://Stackoverflow.com/questions/478474",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11911/"
] | What's going on?! Subtraction works fine until I get to 0.1 - 0.1. I'm in visual c# 2008 using the nonoba.com API.
```
Console.WriteLine("hit! " + Users[targetNum].character.health + " : " + player.character.profile.attackPower);
Users[targetNum].character.health -= player.character.profile.attackPower;
Console.Writ... | That seems pretty normal for floating point math... you always have to check against a small delta to account for imperceptible rounding differences. Depending on the scenario, `decimal` might be what you want.
Basically, unless you can be sure that it is **exactly** the same 0.1 in both cases (i.e. nothing has been d... |
478,498 | <p>I have a remote server that hosts my subversion repository on a non-standard ssh port. I want to use Eclipse's subclipse plugin as my client end to access the SVN repository. I can access the repository fine by using svn+specialssh://... where specialssh is a tunnel profile setup in my ~/.subversion/config.</p>
<... | [
{
"answer_id": 478512,
"author": "orip",
"author_id": 37020,
"author_profile": "https://Stackoverflow.com/users/37020",
"pm_score": 2,
"selected": false,
"text": "<p>Something I used to do is have a shell script wrap my access to SSH, something like:</p>\n\n<pre><code>#!ssh1234.sh\nssh -... | 2009/01/25 | [
"https://Stackoverflow.com/questions/478498",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/36680/"
] | I have a remote server that hosts my subversion repository on a non-standard ssh port. I want to use Eclipse's subclipse plugin as my client end to access the SVN repository. I can access the repository fine by using svn+specialssh://... where specialssh is a tunnel profile setup in my ~/.subversion/config.
In subclip... | First, I set up my tunnel to my repository, which lives behind the firewall on my home network:
```
ssh -L 9000:10.5.128.5:3690 root@<mypublicallyexposedaddress>
```
10.5.128.5 is the internal address of my repository host. Port 3690 is where svn listens.
Then in Eclipse, I configure the repository:
```
svn://loca... |
478,523 | <p>I would like to avoid to specify manually maxlength attributes for all form input
elements, and instead to use size information from the Data Model if possible:</p>
<p>e.g.</p>
<pre><code><%= Html.TextBox("Titel", ViewData.Model.Titel, (object)new { @maxlength = "10" })%>
</code></pre>
<p>would it be pos... | [
{
"answer_id": 478586,
"author": "mamcx",
"author_id": 53185,
"author_profile": "https://Stackoverflow.com/users/53185",
"pm_score": 4,
"selected": false,
"text": "<p>Your are asking for the best and rulling out the #1 ;).</p>\n\n<p>For the tree the \"best\" is <a href=\"http://www.soft-... | 2009/01/25 | [
"https://Stackoverflow.com/questions/478523",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/55390/"
] | I would like to avoid to specify manually maxlength attributes for all form input
elements, and instead to use size information from the Data Model if possible:
e.g.
```
<%= Html.TextBox("Titel", ViewData.Model.Titel, (object)new { @maxlength = "10" })%>
```
would it be possible "translate" the DbType Attribute ... | Well, I have the DevExpress VCL subscription, and although the initial price seems high it is good value and the renewal is sensible. The grid will do all you ever want (and more) though you do have to spend some time learning it so you can understand where the features are controlled. The advantage of the subscription... |
478,531 | <p>I am playing around with F# and C#, and would like to call F# code from C#. </p>
<p>I managed to get it to work the other way around in Visual Studio by having two projects in the same solution, and adding a reference of the C# code to the F# project. After doing this, I could call C# code and even step through i... | [
{
"answer_id": 478549,
"author": "Chris Bunch",
"author_id": 422,
"author_profile": "https://Stackoverflow.com/users/422",
"pm_score": 3,
"selected": false,
"text": "<p>From <a href=\"https://web.archive.org/web/20090425153149/http://cs.hubfs.net:80/forums/thread/6967.aspx\" rel=\"nofoll... | 2009/01/25 | [
"https://Stackoverflow.com/questions/478531",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/58444/"
] | I am playing around with F# and C#, and would like to call F# code from C#.
I managed to get it to work the other way around in Visual Studio by having two projects in the same solution, and adding a reference of the C# code to the F# project. After doing this, I could call C# code and even step through it while debu... | Below is a working example of calling F# from C#.
As you encountered, I was not able to add a reference by selecting from the "Add Reference ... Projects" tab. Instead I did have to do it manually, by browsing to the F# assembly in the "Add Reference ... Browse" tab.
------ F# MODULE -----
```
// First implement a f... |
478,543 | <p>I know the title doesn't explain my question very well (if someone can come up with a better title then please edit it). Here's what I want to do, say I have the following table:</p>
<pre><code>id | a | b | c
------------------
1 | 3 | 3 | 3
2 | 20 | 40 | 30
3 | 40 | 30 | 10
4 | 30 | 10 | 15
5 | 10 | 15 |... | [
{
"answer_id": 478566,
"author": "Mitch Wheat",
"author_id": 16076,
"author_profile": "https://Stackoverflow.com/users/16076",
"pm_score": 1,
"selected": false,
"text": "<p>I'm not familiar with the MySQL TSQL dialect but you would have to first SELECT the row with the highest 'A' value,... | 2009/01/25 | [
"https://Stackoverflow.com/questions/478543",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6432/"
] | I know the title doesn't explain my question very well (if someone can come up with a better title then please edit it). Here's what I want to do, say I have the following table:
```
id | a | b | c
------------------
1 | 3 | 3 | 3
2 | 20 | 40 | 30
3 | 40 | 30 | 10
4 | 30 | 10 | 15
5 | 10 | 15 | 6
6 | 15 | 6... | I'm not familiar with the MySQL TSQL dialect but you would have to first SELECT the row with the highest 'A' value, perform a UNION ALL (i.e. no distinct via sorting) with the row with the highest 'B' value, perform a UNION ALL with the row with the highest 'C' value and then a UNION ALL with the remaining rows ordered... |
478,546 | <p>I am attempting to learn oCaml and am having an issue as to why the below program is invalid.</p>
<pre><code>class myClass2 =
object
method doSomething = Printf.printf "%s\n" "Doing something"
end;;
class myClass foo =
object
val dMember = foo
method doIt = dMember#doSomething
end;;
let mc2 = new myClass2;;
le... | [
{
"answer_id": 478565,
"author": "Jules",
"author_id": 40078,
"author_profile": "https://Stackoverflow.com/users/40078",
"pm_score": 2,
"selected": true,
"text": "<p>Declare the type:</p>\n\n<pre><code>class myClass (foo:myClass2) =\n</code></pre>\n"
},
{
"answer_id": 478893,
... | 2009/01/25 | [
"https://Stackoverflow.com/questions/478546",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/25985/"
] | I am attempting to learn oCaml and am having an issue as to why the below program is invalid.
```
class myClass2 =
object
method doSomething = Printf.printf "%s\n" "Doing something"
end;;
class myClass foo =
object
val dMember = foo
method doIt = dMember#doSomething
end;;
let mc2 = new myClass2;;
let mc = new myC... | Declare the type:
```
class myClass (foo:myClass2) =
``` |
478,555 | <p>I need to write a simple program: There will be a Parent and a few programs [children] (started via <code>execl</code> in Parent). Children communicate to one another in this way: Child I sens to Parent number J, Parent sends a message (something like -- "there is a message to you") to J, J send to Parent number K e... | [
{
"answer_id": 479249,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 0,
"selected": false,
"text": "<p>About ./ucz -- it takes 4 parameters -- 1st -- number of players, 2nd -- player number, 3rd -- number of descriptor to read... | 2009/01/25 | [
"https://Stackoverflow.com/questions/478555",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | I need to write a simple program: There will be a Parent and a few programs [children] (started via `execl` in Parent). Children communicate to one another in this way: Child I sens to Parent number J, Parent sends a message (something like -- "there is a message to you") to J, J send to Parent number K etc. etc.
And ... | Besides the fact that you do not end your cases with a `break` (as noted by strager), the main problem is the statement `l = k;`. Note that `k` is a `char[20]` and, when assigned to a `int`, you don't assign any of the contents of `k` to `l`. Instead `l` will contain (the value of) the pointer to the array. You will ha... |
478,559 | <p>For a RoR installation, is there any way to run <code>rake</code> commands without root access? </p>
<p>To put it another way, is there any way to get <code>db:create</code> and <code>db:migrate</code> to be run without root access (perhaps automatically or something)? Or can I run <code>rake</code> commands from a... | [
{
"answer_id": 478580,
"author": "Keltia",
"author_id": 16143,
"author_profile": "https://Stackoverflow.com/users/16143",
"pm_score": 0,
"selected": false,
"text": "<p>Well, it is a bit of a chicken-egg problem, you may be able to start your RoR instance without the database created but ... | 2009/01/25 | [
"https://Stackoverflow.com/questions/478559",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8047/"
] | For a RoR installation, is there any way to run `rake` commands without root access?
To put it another way, is there any way to get `db:create` and `db:migrate` to be run without root access (perhaps automatically or something)? Or can I run `rake` commands from a RoR `controller`? | Take a look at `rails-2.X.X/lib/tasks/databases.rake` and you can see the code called to create, drop, and migrate your database.
Once a `rails` environment is initialized, you can use the code inside the rake task file to create, drop, and migrate.
I do not know if you can do this at the controller level before it e... |
478,562 | <p>I'm using C# 2005 and the CSVreader class, all works well apart from when the CSV file contains an empty row at the end:</p>
<p>Example:</p>
<pre><code>1,2,3,4,5
2,3,5,6,7
,,,,
</code></pre>
<p>My program errors as there are no values here, the problem is that not all columns are contain a value so the 2 rows bel... | [
{
"answer_id": 478567,
"author": "Mitch Wheat",
"author_id": 16076,
"author_profile": "https://Stackoverflow.com/users/16076",
"pm_score": 0,
"selected": false,
"text": "<p>Read the entire line and work backwards.</p>\n"
},
{
"answer_id": 478610,
"author": "Spence",
"auth... | 2009/01/26 | [
"https://Stackoverflow.com/questions/478562",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | I'm using C# 2005 and the CSVreader class, all works well apart from when the CSV file contains an empty row at the end:
Example:
```
1,2,3,4,5
2,3,5,6,7
,,,,
```
My program errors as there are no values here, the problem is that not all columns are contain a value so the 2 rows below would be valid.
```
1,2,,4,5
... | This particular CSVReader looks to have some good handling of missing fields:
[A Fast CSV Reader](http://www.codeproject.com/KB/database/CsvReader.aspx)
You can handle an empty row by using some code like this before invoking the reader:
```
csv.MissingFieldAction = MissingFieldAction.ReplaceByNull;
```
or replace... |
478,563 | <p>Mac OS X is a beautiful system, from the mach kernel up to finder and spotlight and speaking of spotlight, it truly blew me away when I just needed to execute this command to get all unix executables and ONLY unix executales:</p>
<pre><code>mdfind "kMDItemKind == 'Unix Executable'"
</code></pre>
<p>Amazing!!! Real... | [
{
"answer_id": 478584,
"author": "Keltia",
"author_id": 16143,
"author_profile": "https://Stackoverflow.com/users/16143",
"pm_score": 2,
"selected": false,
"text": "<p>Not really, none of the other UNIX system have an indexer builtin the file system (except BeOS but it is not a UNIX syst... | 2009/01/26 | [
"https://Stackoverflow.com/questions/478563",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/58160/"
] | Mac OS X is a beautiful system, from the mach kernel up to finder and spotlight and speaking of spotlight, it truly blew me away when I just needed to execute this command to get all unix executables and ONLY unix executales:
```
mdfind "kMDItemKind == 'Unix Executable'"
```
Amazing!!! Really!!!
Now, the question i... | [Beagle](http://www.beagle-project.org/), [MetaTracker](http://projects.gnome.org/tracker/), [Strigi](http://strigi.sourceforge.net/), and even [Google Desktop](http://desktop.google.com/) are all desktop indexers for Linux. What's there by default depends on your distribution (some may have none at all), and they all ... |