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 |
|---|---|---|---|---|---|---|
499,562 | <p>I've been working on a problem which I thought people might find interesting (and perhaps someone is aware of a pre-existing solution).</p>
<p>I have a large dataset consisting of a long list of pairs of pointers to objects, something like this:</p>
<pre><code>[
(a8576, b3295),
(a7856, b2365),
(a3566, b546... | [
{
"answer_id": 499624,
"author": "SoapBox",
"author_id": 36384,
"author_profile": "https://Stackoverflow.com/users/36384",
"pm_score": 0,
"selected": false,
"text": "<p>I think the answer to this question is going to depend very heavily on exactly the access pattern of the pair of object... | 2009/01/31 | [
"https://Stackoverflow.com/questions/499562",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16050/"
] | I've been working on a problem which I thought people might find interesting (and perhaps someone is aware of a pre-existing solution).
I have a large dataset consisting of a long list of pairs of pointers to objects, something like this:
```
[
(a8576, b3295),
(a7856, b2365),
(a3566, b5464),
...
]
```
The... | Your problem is related to a similar one for computer graphics hardware:
When rendering indexed vertices in a triangle mesh, typically the hardware has a cache of most recently transformed vertices (~128 the last time I had to worry about it, but suspect the number is larger these days). Vertices not cached need a rel... |
499,565 | <p>I'm a web developer focused on UI.</p>
<p>Many interface features in my web application are based on double-clicking.</p>
<p>In IE, this brings up that new annoying <strong>"accelerators" icon which interferes with my user interface</strong>. Is it possible to disable "accelerators" on my pages? Maybe with some ne... | [
{
"answer_id": 499891,
"author": "scunliffe",
"author_id": 6144,
"author_profile": "https://Stackoverflow.com/users/6144",
"pm_score": 3,
"selected": false,
"text": "<p>Although I feel for you (I don't think there is any way to disable them in code) I would advise against using double-cl... | 2009/01/31 | [
"https://Stackoverflow.com/questions/499565",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | I'm a web developer focused on UI.
Many interface features in my web application are based on double-clicking.
In IE, this brings up that new annoying **"accelerators" icon which interferes with my user interface**. Is it possible to disable "accelerators" on my pages? Maybe with some new stupid IE-specific **meta ta... | Although I feel for you (I don't think there is any way to disable them in code) I would advise against using double-click for a lot of your user interface as it goes against the paradigm of the Web.
Many users are told on sites to not double-click to avoid duplicate transactions etc.
The only thing I can really thin... |
499,578 | <p>I'm having a hard time understanding how I can form a LINQ query to do the following:</p>
<p>I have a table CallLogs and I want to get back a single result which represents the call that has the longest duration.</p>
<p>The row looks like this:</p>
<blockquote>
<p>[ID] [RemoteParty] [Duration]</p>
</blockquote>
<p>T... | [
{
"answer_id": 499614,
"author": "tvanfosson",
"author_id": 12950,
"author_profile": "https://Stackoverflow.com/users/12950",
"pm_score": 5,
"selected": false,
"text": "<p>Order the result and return the first one.</p>\n\n<pre><code>var callStats = (from c in database.CallLogs\n ... | 2009/01/31 | [
"https://Stackoverflow.com/questions/499578",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | I'm having a hard time understanding how I can form a LINQ query to do the following:
I have a table CallLogs and I want to get back a single result which represents the call that has the longest duration.
The row looks like this:
>
> [ID] [RemoteParty] [Duration]
>
>
>
There can be multiple rows for the same R... | Order the result and return the first one.
```
var callStats = (from c in database.CallLogs
group c by c.RemoteParty into d
select new
{
RemoteParty = d.Key,
TotalDuration = d.Sum(x => x.Duration)
});
callS... |
499,609 | <p>I have a site that has a simple HTML button in a form. All browsers show this button correctly. However, in Firefox 2 and Seamonkey it appears just as a solid grey square that cannot be clicked on and that has no text.</p>
<pre><code><input id="getaudiobutton" type="button" value="Get Audio" onclick="convert()" ... | [
{
"answer_id": 499625,
"author": "jamesmillerio",
"author_id": 3552,
"author_profile": "https://Stackoverflow.com/users/3552",
"pm_score": 3,
"selected": true,
"text": "<p>From what I can see just by viewing it in Seamonkey and looking at the contents of the page and your CSS, you may wa... | 2009/01/31 | [
"https://Stackoverflow.com/questions/499609",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/51649/"
] | I have a site that has a simple HTML button in a form. All browsers show this button correctly. However, in Firefox 2 and Seamonkey it appears just as a solid grey square that cannot be clicked on and that has no text.
```
<input id="getaudiobutton" type="button" value="Get Audio" onclick="convert()" />
```
For thos... | From what I can see just by viewing it in Seamonkey and looking at the contents of the page and your CSS, you may want to check the style for the div that the button is contained in. I can see the button in Seamoney, but it is cut off at the very top, only allowing about 1-3 pixels to show. I can click it as well.
My ... |
499,621 | <p>How do I add a second item to order by with this?
I want to order by a goalsScored element too. </p>
<pre><code>var theteams =
(from teams in xdoc.Descendants("team")
orderby (int)teams.Element("points") descending
select
new Team(teams.Element("teamID").Valu... | [
{
"answer_id": 499626,
"author": "tsilb",
"author_id": 11112,
"author_profile": "https://Stackoverflow.com/users/11112",
"pm_score": 5,
"selected": true,
"text": "<pre><code>var theteams = \n (from teams in xdoc.Descendants(\"team\")\n orderby (int)teams.Element(\"points\") des... | 2009/01/31 | [
"https://Stackoverflow.com/questions/499621",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1116/"
] | How do I add a second item to order by with this?
I want to order by a goalsScored element too.
```
var theteams =
(from teams in xdoc.Descendants("team")
orderby (int)teams.Element("points") descending
select
new Team(teams.Element("teamID").Value,
... | ```
var theteams =
(from teams in xdoc.Descendants("team")
orderby (int)teams.Element("points") descending, OtherField1, OtherField2
select new Team(teams.Element("teamID").Value,
(int)teams.Element("points"))).Take(3);
``` |
499,636 | <p>Okay, <code>mkstemp</code> is the preferred way to create a temp file in POSIX. </p>
<p>But it opens the file and returns an <code>int</code>, which is a file descriptor. From that I can only create a FILE*, but not an <code>std::ofstream</code>, which I would prefer in C++. (Apparently, on AIX and some other syste... | [
{
"answer_id": 499654,
"author": "f3lix",
"author_id": 60617,
"author_profile": "https://Stackoverflow.com/users/60617",
"pm_score": 5,
"selected": true,
"text": "<p>I think this should work:</p>\n\n<pre><code> char *tmpname = strdup(\"/tmp/tmpfileXXXXXX\");\n ofstream f;\n int ... | 2009/01/31 | [
"https://Stackoverflow.com/questions/499636",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/60628/"
] | Okay, `mkstemp` is the preferred way to create a temp file in POSIX.
But it opens the file and returns an `int`, which is a file descriptor. From that I can only create a FILE\*, but not an `std::ofstream`, which I would prefer in C++. (Apparently, on AIX and some other systems, you can create an `std::ofstream` from... | I think this should work:
```
char *tmpname = strdup("/tmp/tmpfileXXXXXX");
ofstream f;
int fd = mkstemp(tmpname);
f.attach(fd);
```
**EDIT:** Well, this might not be portable. If you can't use attach and can't create a ofstream directly from a file descriptor, then you have to do this:
```
char *tm... |
499,637 | <p>When I setup IIS6 to develop projects locally I have to enable "Integrated Windows Authentication" under directory security in order for my CSS & Images to show up. (Note: I have double checked that network service has rights to all directories in my web application)</p>
<p>However this often causes my browser ... | [
{
"answer_id": 499654,
"author": "f3lix",
"author_id": 60617,
"author_profile": "https://Stackoverflow.com/users/60617",
"pm_score": 5,
"selected": true,
"text": "<p>I think this should work:</p>\n\n<pre><code> char *tmpname = strdup(\"/tmp/tmpfileXXXXXX\");\n ofstream f;\n int ... | 2009/01/31 | [
"https://Stackoverflow.com/questions/499637",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/50970/"
] | When I setup IIS6 to develop projects locally I have to enable "Integrated Windows Authentication" under directory security in order for my CSS & Images to show up. (Note: I have double checked that network service has rights to all directories in my web application)
However this often causes my browser to prompt me f... | I think this should work:
```
char *tmpname = strdup("/tmp/tmpfileXXXXXX");
ofstream f;
int fd = mkstemp(tmpname);
f.attach(fd);
```
**EDIT:** Well, this might not be portable. If you can't use attach and can't create a ofstream directly from a file descriptor, then you have to do this:
```
char *tm... |
499,645 | <p>By default, ASP.NET records all uncaught exceptions to system Event Log. I’m aware of the fact that one should have a proper logging facility in place, but this is better than nothing and it serves well as a temporary solution.</p>
<p>I would like to be able to filter efficiently the events in the log. I learned th... | [
{
"answer_id": 499660,
"author": "davogones",
"author_id": 59631,
"author_profile": "https://Stackoverflow.com/users/59631",
"pm_score": 0,
"selected": false,
"text": "<p>You may want to handle uncaught exceptions in your global.asax, and then log the Exception programmatically as so:</p... | 2009/01/31 | [
"https://Stackoverflow.com/questions/499645",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15716/"
] | By default, ASP.NET records all uncaught exceptions to system Event Log. I’m aware of the fact that one should have a proper logging facility in place, but this is better than nothing and it serves well as a temporary solution.
I would like to be able to filter efficiently the events in the log. I learned that, when l... | Your best bet is to use the source property as intended, but use an installer class in your installer to set up the registry at install time (under Admin), eg.:
```
using System;
using System.Collections;
using System.Collections.Generic;
using System.ComponentModel;
using System.Configuration.Install;
using System.D... |
499,673 | <p>For some crazy reason I can't find a way to get a list of files with a glob for a given directory.</p>
<p>I'm currently stuck with something along the lines of:</p>
<pre><code>NSString *bundleRoot = [[NSBundle mainBundle] bundlePath];
NSArray *dirContents = [[NSFileManager defaultManager]
... | [
{
"answer_id": 499685,
"author": "Sean Bright",
"author_id": 21926,
"author_profile": "https://Stackoverflow.com/users/21926",
"pm_score": 2,
"selected": false,
"text": "<p>I won't pretend to be an expert on the topic, but you should have access to both the <code>glob</code> and <code>wo... | 2009/01/31 | [
"https://Stackoverflow.com/questions/499673",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/50276/"
] | For some crazy reason I can't find a way to get a list of files with a glob for a given directory.
I'm currently stuck with something along the lines of:
```
NSString *bundleRoot = [[NSBundle mainBundle] bundlePath];
NSArray *dirContents = [[NSFileManager defaultManager]
directoryContentsAtPa... | You can achieve this pretty easily with the help of NSPredicate, like so:
```
NSString *bundleRoot = [[NSBundle mainBundle] bundlePath];
NSFileManager *fm = [NSFileManager defaultManager];
NSArray *dirContents = [fm contentsOfDirectoryAtPath:bundleRoot error:nil];
NSPredicate *fltr = [NSPredicate predicateWithFormat:@... |
499,694 | <p>I'm looking into ways of changing the time zone of my databases as my userbase is UK based, but my domain is US based. I've researched a number of options including php, PEAR time class, and MySQL functions. To me the simplest (largly because it starts and ends with MySQL) involves changing MySQL's time_zone paramet... | [
{
"answer_id": 574488,
"author": "Shalom Craimer",
"author_id": 54491,
"author_profile": "https://Stackoverflow.com/users/54491",
"pm_score": 0,
"selected": false,
"text": "<p>The standard practice is to store any date/times you want to display in UTC (i.e. GMT) and either automatically ... | 2009/01/31 | [
"https://Stackoverflow.com/questions/499694",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | I'm looking into ways of changing the time zone of my databases as my userbase is UK based, but my domain is US based. I've researched a number of options including php, PEAR time class, and MySQL functions. To me the simplest (largly because it starts and ends with MySQL) involves changing MySQL's time\_zone parameter... | There are 2 keys to dealing with timezones:
1. Store all of your date/times in the same timezone (can be any timezone, but using UTC does simplify things.)
2. Decide where in your application date/times will be converted to/from the storage timezone to the user display timezone. This can be done in the database abstra... |
499,705 | <p>I use the following snippet to drop into a Python shell mid-program. This works fine, but I only get the standard console. Is there a way to do the same but using the <a href="http://ipython.scipy.org/" rel="noreferrer">IPython</a> shell?</p>
<pre><code>import code
class EmbeddedConsole(code.InteractiveConsole):
... | [
{
"answer_id": 499718,
"author": "f3lix",
"author_id": 60617,
"author_profile": "https://Stackoverflow.com/users/60617",
"pm_score": 2,
"selected": false,
"text": "<p><a href=\"http://www.ifi.uio.no/~inf3330/scripting/doc/python/ipython/node9.html\" rel=\"nofollow noreferrer\">Embedding ... | 2009/01/31 | [
"https://Stackoverflow.com/questions/499705",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/42974/"
] | I use the following snippet to drop into a Python shell mid-program. This works fine, but I only get the standard console. Is there a way to do the same but using the [IPython](http://ipython.scipy.org/) shell?
```
import code
class EmbeddedConsole(code.InteractiveConsole):
def start(self):
try:
... | The answer by f3lix is no longer valid it seems, I was able to find this however:
At the top of your python script:
```
from IPython import embed
```
Wherever you want to spin up a console:
```
embed()
``` |
499,739 | <p>I'm using garbage collection in Objective-C 2.0. Do I need to retain properties? Eg.</p>
<pre><code>@property (nonatomic, retain) NSMutableArray *myArray;
</code></pre>
<p>Or is this enough:</p>
<pre><code>@property (nonatomic) NSMutableArray *myArray;
</code></pre>
<p>I initialize the array like this:</p>
<pre... | [
{
"answer_id": 499830,
"author": "Georg Schölly",
"author_id": 24587,
"author_profile": "https://Stackoverflow.com/users/24587",
"pm_score": 3,
"selected": true,
"text": "<p>Using the garbage collector you don't have to care about retaining and releasing if you don't write code that shou... | 2009/01/31 | [
"https://Stackoverflow.com/questions/499739",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3740/"
] | I'm using garbage collection in Objective-C 2.0. Do I need to retain properties? Eg.
```
@property (nonatomic, retain) NSMutableArray *myArray;
```
Or is this enough:
```
@property (nonatomic) NSMutableArray *myArray;
```
I initialize the array like this:
```
self.myArray = [NSMutableArray array];
``` | Using the garbage collector you don't have to care about retaining and releasing if you don't write code that should be compatible with legacy objective-c.
`-(void)retain` and `-(void)release` are empty functions when the GC is on, they don't change the retain count.
This means leaving it out is fine. |
499,743 | <p>The Web browser's Window.External object is always null!</p>
<p>To reproduce drop a web browser on a new winform and type:</p>
<pre><code>Option Strict Off
Public Class Form1
Private Sub Form1_Load()
Handles MyBase.LoadMe.WebBrowser1.Document.Window.DomWindow.External.AddFavorite("http://www.google.co... | [
{
"answer_id": 499830,
"author": "Georg Schölly",
"author_id": 24587,
"author_profile": "https://Stackoverflow.com/users/24587",
"pm_score": 3,
"selected": true,
"text": "<p>Using the garbage collector you don't have to care about retaining and releasing if you don't write code that shou... | 2009/01/31 | [
"https://Stackoverflow.com/questions/499743",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | The Web browser's Window.External object is always null!
To reproduce drop a web browser on a new winform and type:
```
Option Strict Off
Public Class Form1
Private Sub Form1_Load()
Handles MyBase.LoadMe.WebBrowser1.Document.Window.DomWindow.External.AddFavorite("http://www.google.com")
End Sub
End C... | Using the garbage collector you don't have to care about retaining and releasing if you don't write code that should be compatible with legacy objective-c.
`-(void)retain` and `-(void)release` are empty functions when the GC is on, they don't change the retain count.
This means leaving it out is fine. |
499,754 | <p>How can I underline an ListBoxItem in WPF? I'm using the following but the underline does not appear. </p>
<pre><code><DataTemplate x:Key="Phrase_List">
<ListBoxItem IsSelected="{Binding IsDefault}">
<TextBlock Text="{Binding Path=Phrase}" Tag="{Binding Path=ID}" TextDecorations="Underlin... | [
{
"answer_id": 499770,
"author": "Remco Eissing",
"author_id": 53104,
"author_profile": "https://Stackoverflow.com/users/53104",
"pm_score": 1,
"selected": false,
"text": "<p>I don't know what code you are trying to use. Please try to complete your question. I've used the following code ... | 2009/01/31 | [
"https://Stackoverflow.com/questions/499754",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | How can I underline an ListBoxItem in WPF? I'm using the following but the underline does not appear.
```
<DataTemplate x:Key="Phrase_List">
<ListBoxItem IsSelected="{Binding IsDefault}">
<TextBlock Text="{Binding Path=Phrase}" Tag="{Binding Path=ID}" TextDecorations="Underline" />
</ListBoxItem>
</D... | I don't know what code you are trying to use. Please try to complete your question. I've used the following code to underline the 'World' item in my little ListBox.
```
<ListBox>
<ListBoxItem>Hello</ListBoxItem>
<ListBoxItem>
<Underline>World</Underline>
</ListBoxItem>
</Lis... |
499,767 | <p>I have a <code>Mail</code> model with the following schema:</p>
<pre><code>t.string "mail"
t.integer "country"
t.boolean "validated"
t.datetime "created_at"
t.datetime "updated_at"
</code></pre>
<p>And I want to find the top 5 countries in the database, so i go ahead and type</p>
<pre><code>@top5 = Mail.find(... | [
{
"answer_id": 500098,
"author": "airportyh",
"author_id": 5304,
"author_profile": "https://Stackoverflow.com/users/5304",
"pm_score": 5,
"selected": true,
"text": "<pre>\nMail.find(\n :all, \n :select => 'count(*) count, country', \n :group => 'country', \n :conditions => ['... | 2009/01/31 | [
"https://Stackoverflow.com/questions/499767",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/47846/"
] | I have a `Mail` model with the following schema:
```
t.string "mail"
t.integer "country"
t.boolean "validated"
t.datetime "created_at"
t.datetime "updated_at"
```
And I want to find the top 5 countries in the database, so i go ahead and type
```
@top5 = Mail.find(:all,:group => 'country',:conditions => [ "vali... | ```
Mail.find(
:all,
:select => 'count(*) count, country',
:group => 'country',
:conditions => ['validated = ?', 't' ],
:order => 'count DESC',
:limit => 5)
```
This should give you records that have a country attribute and a count attribute. |
499,777 | <p>In a current project I need to support finding a User by login credentials and also by email address. I know that in RESTful design you use a GET to find resources. In Rails...</p>
<pre><code>GET /users # => UsersController.index -- find all the users
GET /users/1 # => UsersController.show -- find a part... | [
{
"answer_id": 499801,
"author": "cletus",
"author_id": 18393,
"author_profile": "https://Stackoverflow.com/users/18393",
"pm_score": 2,
"selected": false,
"text": "<p>The first thing you can do is make your GETs as smart as possible. In your example, this can be handled programmaticall... | 2009/01/31 | [
"https://Stackoverflow.com/questions/499777",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/42595/"
] | In a current project I need to support finding a User by login credentials and also by email address. I know that in RESTful design you use a GET to find resources. In Rails...
```
GET /users # => UsersController.index -- find all the users
GET /users/1 # => UsersController.show -- find a particular user
```
Bu... | I don't know how much of this is convention, but this is what I would do. I
would add another action, as long as it's specifically related to that
resource. In your example, show is a find by userid, so it makes sense as
another action on UsersController. You can turn it into a sentence that makes
sense, "get me the us... |
499,795 | <p>Not unlike a clap detector ("Clap on! <em>clap clap</em> Clap off! <em>clap clap</em> Clap on, clap off, the Clapper! <em>clap clap</em> ") I need to detect when a door closes. This is in a vehicle, which is easier than a room or household door:</p>
<p>Listen: <a href="http://ubasics.com/so/van_driver_door_closin... | [
{
"answer_id": 499820,
"author": "Szundi",
"author_id": 22631,
"author_profile": "https://Stackoverflow.com/users/22631",
"pm_score": 0,
"selected": false,
"text": "<p>Maybe you should try to detect significant instant rise in air pressure that should mark a door close. You can pair it w... | 2009/01/31 | [
"https://Stackoverflow.com/questions/499795",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2915/"
] | Not unlike a clap detector ("Clap on! *clap clap* Clap off! *clap clap* Clap on, clap off, the Clapper! *clap clap* ") I need to detect when a door closes. This is in a vehicle, which is easier than a room or household door:
Listen: <http://ubasics.com/so/van_driver_door_closing.wav>
Look:
[ of the samples to find out the "energy" of the wave at a specific time.
A rough algorithm would be:
1. Divide the samples... |
499,803 | <p>If have a problem on my site that users can post empty messages if they use space.</p>
<h3>Code:</h3>
<pre><code>if (isset($_POST['submit'])) {
// check for empty fields
if (empty($_POST['headline']) || empty($_POST['text']) ||
empty($_POST['forum_id'])) {
header("Refresh: 2; url=/add-thread&qu... | [
{
"answer_id": 499806,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 3,
"selected": false,
"text": "<p><code>trim()</code> the text inputs. You can do that easily like this:</p>\n\n<pre><code>// get input vars and trim space\n... | 2009/01/31 | [
"https://Stackoverflow.com/questions/499803",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | If have a problem on my site that users can post empty messages if they use space.
### Code:
```
if (isset($_POST['submit'])) {
// check for empty fields
if (empty($_POST['headline']) || empty($_POST['text']) ||
empty($_POST['forum_id'])) {
header("Refresh: 2; url=/add-thread");
die('You must ... | `trim()` the text inputs. You can do that easily like this:
```
// get input vars and trim space
$callback = array('filter' => FILTER_CALLBACK, 'options' => 'trim');
$fields = filter_input_array(INPUT_POST, array(
'headline' => $callback,
'text' => $callback,
'forum_id' => $callback,
));
// check for ... |
499,814 | <p>I came across a javascript puzzle asking:
Write a one-line piece of JavaScript code that concatenates all strings passed into a function:<br /></p>
<pre>
<code>
function concatenate(/*any number of strings*/) {
var string = /*your one line here*/
return string;
}
</code>
</pre>
<p>@ <a href="htt... | [
{
"answer_id": 499828,
"author": "Nosredna",
"author_id": 61027,
"author_profile": "https://Stackoverflow.com/users/61027",
"pm_score": 1,
"selected": false,
"text": "<p>The arguments list is not a genuine array. I think you can borrow the array methods and use them on arguments with \"c... | 2009/01/31 | [
"https://Stackoverflow.com/questions/499814",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | I came across a javascript puzzle asking:
Write a one-line piece of JavaScript code that concatenates all strings passed into a function:
```
function concatenate(/*any number of strings*/) {
var string = /*your one line here*/
return string;
}
```
@ [meebo](http://www.meebo.com/jobs/openings... | `arguments` [is said to be](http://developer.mozilla.org/En/Core_JavaScript_1.5_Reference/Functions_and_function_scope/arguments) an Array-like object. As you already saw you may access its elements by index, but you don't have all the Array methods at your disposal. Other examples of Array-like objects are HTML collec... |
499,817 | <p>If given the route:</p>
<p><strong>{FeedName}/{ItemPermalink}</strong></p>
<p>ex: /Blog/Hello-World</p>
<p>If the item doesn't exist, I want to return a 404. What is the right way to do this in ASP.NET MVC?</p>
| [
{
"answer_id": 499840,
"author": "yfeldblum",
"author_id": 12349,
"author_profile": "https://Stackoverflow.com/users/12349",
"pm_score": 4,
"selected": false,
"text": "<pre><code>throw new HttpException(404, \"Are you sure you're in the right place?\");\n</code></pre>\n"
},
{
"an... | 2009/01/31 | [
"https://Stackoverflow.com/questions/499817",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2596/"
] | If given the route:
**{FeedName}/{ItemPermalink}**
ex: /Blog/Hello-World
If the item doesn't exist, I want to return a 404. What is the right way to do this in ASP.NET MVC? | Shooting from the hip (cowboy coding ;-)), I'd suggest something like this:
**Controller:**
```
public class HomeController : Controller
{
public ActionResult Index()
{
return new HttpNotFoundResult("This doesn't exist");
}
}
```
---
**HttpNotFoundResult:**
```
using System;
using System.Net;
... |
499,829 | <p>Every time I try to do something seemingly-simple in CSS, it doesn't work.</p>
<p>I have a content div that contains a 460x160 image. All I want to do is position the image at the bottom-right corner and wrap my text around it.</p>
<pre><code><div id="contents">
<img src="..." />
text text text... | [
{
"answer_id": 499881,
"author": "user58670",
"author_id": 58670,
"author_profile": "https://Stackoverflow.com/users/58670",
"pm_score": -1,
"selected": false,
"text": "<p>The solution I found involves that you have a div whose width does not changes, nor does the amount of text. Then yo... | 2009/01/31 | [
"https://Stackoverflow.com/questions/499829",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/28278/"
] | Every time I try to do something seemingly-simple in CSS, it doesn't work.
I have a content div that contains a 460x160 image. All I want to do is position the image at the bottom-right corner and wrap my text around it.
```
<div id="contents">
<img src="..." />
text text text text text text ...
</div>
```
... | It sure seems to have been asked [before (2003)](http://archivist.incutio.com/viewlist/css-discuss/72206), and [before (2002)](http://archivist.incutio.com/viewlist/css-discuss/12645), or [before (2005)](http://archivist.incutio.com/viewlist/css-discuss/57221)
The last link actually suggest a [javascript-based solutio... |
499,834 | <p>This is somewhat related to <a href="https://stackoverflow.com/questions/39691/javascript-best-practices">this question</a>, but I'm not asking for resources about best practices in JavaScript, but your actual advise.</p>
<p>I'll start with my own list. You may either post an answer or directly edit the question if... | [
{
"answer_id": 499844,
"author": "Nosredna",
"author_id": 61027,
"author_profile": "https://Stackoverflow.com/users/61027",
"pm_score": 0,
"selected": false,
"text": "<blockquote>\n <blockquote>\n <p>use explicit casts for primitives, e.g. Number(), String(), Boolean()</p>\n </block... | 2009/02/01 | [
"https://Stackoverflow.com/questions/499834",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/48015/"
] | This is somewhat related to [this question](https://stackoverflow.com/questions/39691/javascript-best-practices), but I'm not asking for resources about best practices in JavaScript, but your actual advise.
I'll start with my own list. You may either post an answer or directly edit the question if you're sure the advi... | Don't meddle with core types. Never stick something onto Array.prototype -- you don't know who else is doing that, and how such things might interact.
Only check explicit types when it matters. Duck typing is a good concept.
I want to second using anonymous functions to avoid pollution of the global scope. Especially... |
499,838 | <p>I've been using Javascript's Date for a project, but noticed today that my code that previously worked is no longer working correctly. Instead of producing Feb as expected, the code below produces March. </p>
<p>My code looks something like this: </p>
<pre><code>current = new Date();
current.setMonth(current.getMo... | [
{
"answer_id": 499846,
"author": "paxdiablo",
"author_id": 14860,
"author_profile": "https://Stackoverflow.com/users/14860",
"pm_score": 7,
"selected": true,
"text": "<p>You'll probably find you're setting the date to Feb 31, 2009 (if today is Jan 31) and Javascript automagically rolls t... | 2009/02/01 | [
"https://Stackoverflow.com/questions/499838",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | I've been using Javascript's Date for a project, but noticed today that my code that previously worked is no longer working correctly. Instead of producing Feb as expected, the code below produces March.
My code looks something like this:
```
current = new Date();
current.setMonth(current.getMonth()+1); //If today ... | You'll probably find you're setting the date to Feb 31, 2009 (if today is Jan 31) and Javascript automagically rolls that into the early part of March.
Check the day of the month, I'd expect it to be 1, 2 or 3. If it's not the same as before you added a month, roll back by one day until the month changes again.
That ... |
499,842 | <p>GCC compiles (using <code>gcc --omit-frame-pointer -s</code>):</p>
<pre><code> int the_answer() { return 42; }
</code></pre>
<p>into</p>
<pre><code> .Text
.globl _the_answer
_the_answer:
subl $12, %esp
movl $42, %eax
addl $12, %esp
ret
.subsect... | [
{
"answer_id": 499854,
"author": "paxdiablo",
"author_id": 14860,
"author_profile": "https://Stackoverflow.com/users/14860",
"pm_score": 4,
"selected": true,
"text": "<p>Short answer: stack frames.</p>\n\n<p>Long answer: when you call a function, compilers will manipulate the stack point... | 2009/02/01 | [
"https://Stackoverflow.com/questions/499842",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/26667/"
] | GCC compiles (using `gcc --omit-frame-pointer -s`):
```
int the_answer() { return 42; }
```
into
```
.Text
.globl _the_answer
_the_answer:
subl $12, %esp
movl $42, %eax
addl $12, %esp
ret
.subsections_via_symbols
```
What is the '$12' constan... | Short answer: stack frames.
Long answer: when you call a function, compilers will manipulate the stack pointer to allow for local data such as function variables. Since your code is changing `esp`, the stack pointer, that's what I assume is happening here. I would have thought GCC smart enough to optimize this away wh... |
499,872 | <p>I have a page that there is a list of "tags", just like here in SO, and when the mouse is over it, it gets darker.</p>
<p>It works great with Ie7, 8, FF, Chrome, Safari etc... but IE6 has a bug that when a:hover is triggered.</p>
<p>The bug is that the div that those (ul li a) are contained, gets a height's increa... | [
{
"answer_id": 499935,
"author": "Shalom Craimer",
"author_id": 54491,
"author_profile": "https://Stackoverflow.com/users/54491",
"pm_score": 0,
"selected": false,
"text": "<p>I think I ran into this once, and what was happening was that the borders were being modified (or was it the mar... | 2009/02/01 | [
"https://Stackoverflow.com/questions/499872",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17648/"
] | I have a page that there is a list of "tags", just like here in SO, and when the mouse is over it, it gets darker.
It works great with Ie7, 8, FF, Chrome, Safari etc... but IE6 has a bug that when a:hover is triggered.
The bug is that the div that those (ul li a) are contained, gets a height's increase.
the css I ha... | just fixed it! :D
what I had before was:
```
<div class="options clearfix">
<!--content here-->
</div>
```
and I replaced for:
```
<div class="options">
<div class="clearfix">
<!--content here-->
</div>
</div>
```
Now IE6 is happy, and I'm happy as well...
Thank you everybody for your help! |
499,879 | <p>I've coded a program in C that sends messages to the stdout using printf and I'm having trouble redirecting the output to a file (running from bash). </p>
<p>I've tried:</p>
<pre><code>./program argument >> program.out
./program argument > program.out
./program >> program.out argument
./program >... | [
{
"answer_id": 499895,
"author": "gclj5",
"author_id": 21651,
"author_profile": "https://Stackoverflow.com/users/21651",
"pm_score": 5,
"selected": true,
"text": "<p>Flushing after newlines only works when printing to a terminal, but not necessarily when printing to a file. A quick Googl... | 2009/02/01 | [
"https://Stackoverflow.com/questions/499879",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/26699/"
] | I've coded a program in C that sends messages to the stdout using printf and I'm having trouble redirecting the output to a file (running from bash).
I've tried:
```
./program argument >> program.out
./program argument > program.out
./program >> program.out argument
./program > program.out argument
```
In each cas... | Flushing after newlines only works when printing to a terminal, but not necessarily when printing to a file. A quick Google search revealed this page with further information: <http://www.pixelbeat.org/programming/stdio_buffering/>
See the section titled "Default Buffering modes".
You might have to add some calls to ... |
499,887 | <p>I'm working on a Rails app that will serve as an authentication system for other Rails apps through Rails's ActiveResource functionality.</p>
<p>The authentication app has an ActiveRecord model called <code>User</code>. The client app has an ActiveResource model called <code>User</code>. I know that in the client a... | [
{
"answer_id": 501257,
"author": "Otto",
"author_id": 9594,
"author_profile": "https://Stackoverflow.com/users/9594",
"pm_score": 4,
"selected": true,
"text": "<p>Short answer: no. The classes involved in <code>has_many</code>, <code>belongs_to</code>, <code>has_and_belongs_to_many</cod... | 2009/02/01 | [
"https://Stackoverflow.com/questions/499887",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/42595/"
] | I'm working on a Rails app that will serve as an authentication system for other Rails apps through Rails's ActiveResource functionality.
The authentication app has an ActiveRecord model called `User`. The client app has an ActiveResource model called `User`. I know that in the client app I can do stuff like `user.sav... | Short answer: no. The classes involved in `has_many`, `belongs_to`, `has_and_belongs_to_many` live in ActiveRecord and build SQL queries to make the associations work.
That said, you can make it look like there is an association, you just have to write your own methods. Which was the up-voted answer on that question y... |
499,897 | <p>Imagine an CoreData entity (e.g. named <code>searchEngine</code>).<br>
<code>NSManagedObjectContext</code> manages some "instances" of this entity.<br>
The end-user is going to be able to select his <code>"standard searchEngine"</code> with a <code>NSPopupButton</code>.<br>
The <code>selected object</code> of NSPopu... | [
{
"answer_id": 499985,
"author": "Jason Coco",
"author_id": 34218,
"author_profile": "https://Stackoverflow.com/users/34218",
"pm_score": 4,
"selected": true,
"text": "<p>You wouldn't want to try and archive a core data entity and store it. Instead, you would store the key or some other ... | 2009/02/01 | [
"https://Stackoverflow.com/questions/499897",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/59518/"
] | Imagine an CoreData entity (e.g. named `searchEngine`).
`NSManagedObjectContext` manages some "instances" of this entity.
The end-user is going to be able to select his `"standard searchEngine"` with a `NSPopupButton`.
The `selected object` of NSPopupButton should be binded to the NSUserDefaults.
The proble... | You wouldn't want to try and archive a core data entity and store it. Instead, you would store the key or some other known attribute and use it to fetch the entity when the application starts up.
Some example code (slightly modified from the example posted in the [Core Data Programming Guide](http://developer.apple.co... |
499,909 | <p>I'm trying to update an object, but I'm getting: "primary key must be unique"... The model for Entry:</p>
<pre><code> class Entry(models.Model):
title = models.CharField(max_length=250)
author = models.ForeignKey(User, editable=False)
status = models.IntegerField(choices=data_types.STATUS_CHOIC... | [
{
"answer_id": 500075,
"author": "defrex",
"author_id": 6007,
"author_profile": "https://Stackoverflow.com/users/6007",
"pm_score": 0,
"selected": false,
"text": "<p>Why do you have form.save() twice? Perhaps that is the problem.</p>\n"
},
{
"answer_id": 503603,
"author": "Co... | 2009/02/01 | [
"https://Stackoverflow.com/questions/499909",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | I'm trying to update an object, but I'm getting: "primary key must be unique"... The model for Entry:
```
class Entry(models.Model):
title = models.CharField(max_length=250)
author = models.ForeignKey(User, editable=False)
status = models.IntegerField(choices=data_types.STATUS_CHOICES,
defa... | Well maybe in the line
form = EntryForm(request.POST, instance=entry)
you dont specify an intance parameter, because this is for update an existing model.... |
499,939 | <p>How can we extract the decimal part of a floating point number and store the decimal part and the integer part into two separate integer variables?</p>
| [
{
"answer_id": 499943,
"author": "Johannes Schaub - litb",
"author_id": 34509,
"author_profile": "https://Stackoverflow.com/users/34509",
"pm_score": 7,
"selected": false,
"text": "<p>You use the <code>modf</code> function:</p>\n\n<pre><code>double integral;\ndouble fractional = modf(som... | 2009/02/01 | [
"https://Stackoverflow.com/questions/499939",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/61096/"
] | How can we extract the decimal part of a floating point number and store the decimal part and the integer part into two separate integer variables? | You use the `modf` function:
```
double integral;
double fractional = modf(some_double, &integral);
```
You can also cast it to an integer, but be warned you may overflow the integer. The result is not predictable then. |
499,949 | <p>While investigating a reported problem with my site loading slowly, I came across an issue where I noticed (via firebug) that my flash file was loading twice.</p>
<p>After a bit of investigation I tracked it down to a <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=438830" rel="nofollow noreferrer">firefox bu... | [
{
"answer_id": 499968,
"author": "Jason Livesay",
"author_id": 61082,
"author_profile": "https://Stackoverflow.com/users/61082",
"pm_score": 3,
"selected": true,
"text": "<pre><code><script>\n function loadswf()\n {\n swfobject.registerObject(\"myobj\", \"9.0.0\");\n }\n fu... | 2009/02/01 | [
"https://Stackoverflow.com/questions/499949",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/46782/"
] | While investigating a reported problem with my site loading slowly, I came across an issue where I noticed (via firebug) that my flash file was loading twice.
After a bit of investigation I tracked it down to a [firefox bug](https://bugzilla.mozilla.org/show_bug.cgi?id=438830) combined with the usage of SWFObject 2.0.... | ```
<script>
function loadswf()
{
swfobject.registerObject("myobj", "9.0.0");
}
function init()
{
window.setTimeout("loadswf()", 0);
}
</script>
<body onload="init()">
<object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" width="778" height="198" id="myobj">
<param name="movie" value... |
499,955 | <p>I'm creating a simple composite control that has AJAX functionality. When trying to implement a MaskedEditValidator, the DisplayMoney property doesn't work. The MaskedEdit renders, without the dollar sign attached. Any ideas? Here's my code:</p>
<pre><code>protected override void OnInit(EventArgs e)
{
base.OnIn... | [
{
"answer_id": 500011,
"author": "jyotishka bora",
"author_id": 53055,
"author_profile": "https://Stackoverflow.com/users/53055",
"pm_score": 0,
"selected": false,
"text": "<p>\n\n </p>\n\n<pre><code><script src=\"jquery-1.3.1.js\" type=\"text/javascript\"></script>\n\n<... | 2009/02/01 | [
"https://Stackoverflow.com/questions/499955",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/53599/"
] | I'm creating a simple composite control that has AJAX functionality. When trying to implement a MaskedEditValidator, the DisplayMoney property doesn't work. The MaskedEdit renders, without the dollar sign attached. Any ideas? Here's my code:
```
protected override void OnInit(EventArgs e)
{
base.OnInit(e);
pri... | It sounds like something in your EventHandlerKeyPress() function is raising a blur. |
499,967 | <p>As per the title, I'm trying to find a way to programmatically determine the longest portion of similarity between several strings.</p>
<p>Example:</p>
<ul>
<li><code>file:///home/gms8994/Music/t.A.T.u./</code></li>
<li><code>file:///home/gms8994/Music/nina%20sky/</code></li>
<li><code>file:///home/gms8994/Music/A... | [
{
"answer_id": 499988,
"author": "Brett Daniel",
"author_id": 48495,
"author_profile": "https://Stackoverflow.com/users/48495",
"pm_score": 2,
"selected": false,
"text": "<p>It sounds like you want the <a href=\"http://en.wikipedia.org/wiki/Longest_common_substring_problem\" rel=\"nofoll... | 2009/02/01 | [
"https://Stackoverflow.com/questions/499967",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16645/"
] | As per the title, I'm trying to find a way to programmatically determine the longest portion of similarity between several strings.
Example:
* `file:///home/gms8994/Music/t.A.T.u./`
* `file:///home/gms8994/Music/nina%20sky/`
* `file:///home/gms8994/Music/A%20Perfect%20Circle/`
Ideally, I'd get back `file:///home/gms... | **Edit:** I'm sorry for mistake. My pity that I overseen that using `my` variable inside `countit(x, q{})` is big mistake. This string is evaluated inside Benchmark module and @str was empty there. This solution is not as fast as I presented. See correction below. I'm sorry again.
Perl can be fast:
```
use strict;
us... |
499,970 | <p><a href="https://stackoverflow.com/questions/180007/how-do-configure-optional-or-extraneous-urls">I only recently found out about URL rewriting</a>, so I've still got a lot to learn.</p>
<p>While following the <a href="http://www.easymodrewrite.com/" rel="nofollow noreferrer">Easy Mod Rewrite</a> tutorial, the resu... | [
{
"answer_id": 499988,
"author": "Brett Daniel",
"author_id": 48495,
"author_profile": "https://Stackoverflow.com/users/48495",
"pm_score": 2,
"selected": false,
"text": "<p>It sounds like you want the <a href=\"http://en.wikipedia.org/wiki/Longest_common_substring_problem\" rel=\"nofoll... | 2009/02/01 | [
"https://Stackoverflow.com/questions/499970",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15031/"
] | [I only recently found out about URL rewriting](https://stackoverflow.com/questions/180007/how-do-configure-optional-or-extraneous-urls), so I've still got a lot to learn.
While following the [Easy Mod Rewrite](http://www.easymodrewrite.com/) tutorial, the results of one of their examples is really confusing me.
```
... | **Edit:** I'm sorry for mistake. My pity that I overseen that using `my` variable inside `countit(x, q{})` is big mistake. This string is evaluated inside Benchmark module and @str was empty there. This solution is not as fast as I presented. See correction below. I'm sorry again.
Perl can be fast:
```
use strict;
us... |
499,974 | <p>I want to do some housekeeping before executing any external console applications (setting some environment vars).</p>
<p>In my web research, it looks like overriding NotifyBeginApplication() in $host might do the trick. Unfortunately, I can't figure out how to do that.</p>
<p>Here's essentially what I want to do.... | [
{
"answer_id": 504437,
"author": "Marco Shaw",
"author_id": 26478,
"author_profile": "https://Stackoverflow.com/users/26478",
"pm_score": -1,
"selected": true,
"text": "<p>I also agree with your (unfortunate) conclusion that you will need to create your own custom host to handle this.</p... | 2009/02/01 | [
"https://Stackoverflow.com/questions/499974",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/43774/"
] | I want to do some housekeeping before executing any external console applications (setting some environment vars).
In my web research, it looks like overriding NotifyBeginApplication() in $host might do the trick. Unfortunately, I can't figure out how to do that.
Here's essentially what I want to do...
```
$host = $... | I also agree with your (unfortunate) conclusion that you will need to create your own custom host to handle this.
You can create additional runspaces easily enough via scripting, but this method isn't accessible in your currently running host (the default console). |
499,995 | <p>I read on here of an exercise in interviews known as validating a binary search tree.</p>
<p>How exactly does this work? What would one be looking for in validating a binary search tree? I have written a basic search tree, but never heard of this concept.</p>
| [
{
"answer_id": 500001,
"author": "wj32",
"author_id": 60940,
"author_profile": "https://Stackoverflow.com/users/60940",
"pm_score": 4,
"selected": false,
"text": "<p>\"Validating\" a binary search tree means that you check that it does indeed have all smaller items on the left and large ... | 2009/02/01 | [
"https://Stackoverflow.com/questions/499995",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/32484/"
] | I read on here of an exercise in interviews known as validating a binary search tree.
How exactly does this work? What would one be looking for in validating a binary search tree? I have written a basic search tree, but never heard of this concept. | Actually that is the mistake everybody does in an interview.
Leftchild must be checked against (minLimitof node,node.value)
Rightchild must be checked against (node.value,MaxLimit of node)
```
IsValidBST(root,-infinity,infinity);
bool IsValidBST(BinaryNode node, int MIN, int MAX)
{
if(node == null)
... |
499,997 | <p>This MVC stuff is fun but every step along the way theres another little hurdle.</p>
<p>I'm just using <a href="https://stackoverflow.com/questions/289108/is-there-a-request-ismvcajaxrequest-equivalent-for-jquery/498658#498658">Request.IsAjaxRequest</a> for the first time today in conjunction with Microsoft's AJAX ... | [
{
"answer_id": 500092,
"author": "Simon_Weaver",
"author_id": 16940,
"author_profile": "https://Stackoverflow.com/users/16940",
"pm_score": 0,
"selected": false,
"text": "<p>I'm still not sure if this is a bug or not - can anyone confirm?? Remember I'm talking about the new RC1 Refresh, ... | 2009/02/01 | [
"https://Stackoverflow.com/questions/499997",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16940/"
] | This MVC stuff is fun but every step along the way theres another little hurdle.
I'm just using [Request.IsAjaxRequest](https://stackoverflow.com/questions/289108/is-there-a-request-ismvcajaxrequest-equivalent-for-jquery/498658#498658) for the first time today in conjunction with Microsoft's AJAX library. I am NOT yet... | Thanks to Phil for [telling me I had to update the .js file](http://www.haacked.com/archive/2009/01/30/aspnetmvc-refresh.aspx) MicrosoftMvcAjax.js. Even though it didn't actually tell me in the release notes that I need to update them.
Phil: If you want the points for the correct answer you have 2 days until i can acc... |
500,006 | <p>What is the purpose of anonymous { } blocks in C style languages (C, C++, C#)</p>
<p>Example -</p>
<pre><code>
void function()
{
{
int i = 0;
i = i + 1;
}
{
int k = 0;
k = k + 1;
}
}
</code></pre>
<p><strong>Edit</strong> - Thanks for all of the excellent answers!</p>
| [
{
"answer_id": 500008,
"author": "17 of 26",
"author_id": 2284,
"author_profile": "https://Stackoverflow.com/users/2284",
"pm_score": 7,
"selected": true,
"text": "<p>It limits the scope of variables to the block inside the { }.</p>\n"
},
{
"answer_id": 500009,
"author": "Nol... | 2009/02/01 | [
"https://Stackoverflow.com/questions/500006",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/61106/"
] | What is the purpose of anonymous { } blocks in C style languages (C, C++, C#)
Example -
```
void function()
{
{
int i = 0;
i = i + 1;
}
{
int k = 0;
k = k + 1;
}
}
```
**Edit** - Thanks for all of the excellent answers! | It limits the scope of variables to the block inside the { }. |
500,023 | <p>Edit: Matt, that does indeed solves some (most) of my problems, thank you. Now the only lingering issue of how do I do this in WPF? I have a custom part based off of a <code>UserControl</code> but there is no way in WPF to do :</p>
<pre><code>[Import]<my:SomeCustomControl>
</code></pre>
<p>so the cascade d... | [
{
"answer_id": 500049,
"author": "Matt Hamilton",
"author_id": 615,
"author_profile": "https://Stackoverflow.com/users/615",
"pm_score": 2,
"selected": false,
"text": "<p>I think the trick is to make use of the fact that MEF will cascade its imports. So if you import your Helper instance... | 2009/02/01 | [
"https://Stackoverflow.com/questions/500023",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/43778/"
] | Edit: Matt, that does indeed solves some (most) of my problems, thank you. Now the only lingering issue of how do I do this in WPF? I have a custom part based off of a `UserControl` but there is no way in WPF to do :
```
[Import]<my:SomeCustomControl>
```
so the cascade doesn't work in this instance.
/Edit
---
I ... | No you can't do that. You could look into using attached properties though for this. With an attached property you can have the container compose the element that the attached property is added to. Another option would be markup extensions.
Glenn |
500,030 | <p>I'm teaching myself Objective-C and I noticed in a lot of books and examples the use of 'k' and camel-casing in constant definition, e.g. </p>
<pre><code>#define kMyConstant 0
</code></pre>
<p>What is the significance of the 'k'?
Is this unique to Objective-C style, or common to C in general?
Why the deviation fr... | [
{
"answer_id": 500034,
"author": "Michael Burr",
"author_id": 12711,
"author_profile": "https://Stackoverflow.com/users/12711",
"pm_score": 2,
"selected": false,
"text": "<p>All caps (as in <code>K_MY_CONSTANT</code>) normally denotes a macro - not necessarily a constant. It's generally... | 2009/02/01 | [
"https://Stackoverflow.com/questions/500030",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/53653/"
] | I'm teaching myself Objective-C and I noticed in a lot of books and examples the use of 'k' and camel-casing in constant definition, e.g.
```
#define kMyConstant 0
```
What is the significance of the 'k'?
Is this unique to Objective-C style, or common to C in general?
Why the deviation from (what I've always thoug... | It was mentioned once before in the SO question, [Lower case "k" in Cocoa](https://stackoverflow.com/questions/472103/lower-case-k-in-cocoa).
>
> It is a general programming notation
> not specific to Objective-C (i.e.
> Hungarian Notation) and the "k" stands for "constant".
>
>
>
If you look at the [Google cache... |
500,031 | <p>I would like to split the example string:</p>
<blockquote>
<p>~Peter~Lois~Chris~Meg~Stewie</p>
</blockquote>
<p>on the character <code>~</code> and have the result be</p>
<blockquote>
<p>Peter<br>
Lois<br>
Chris<br>
Meg<br>
Stewie </p>
</blockquote>
<p>Using a standard string split function in javas... | [
{
"answer_id": 500040,
"author": "Jay Bazuzi",
"author_id": 5314,
"author_profile": "https://Stackoverflow.com/users/5314",
"pm_score": 1,
"selected": false,
"text": "<p>In C#, this seems to get what you want:</p>\n\n<pre><code>\"~Peter~Lois~Chris~Meg~Stewie\".Split(\"~\".ToCharArray(), ... | 2009/02/01 | [
"https://Stackoverflow.com/questions/500031",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20651/"
] | I would like to split the example string:
>
> ~Peter~Lois~Chris~Meg~Stewie
>
>
>
on the character `~` and have the result be
>
> Peter
>
> Lois
>
> Chris
>
> Meg
>
> Stewie
>
>
>
Using a standard string split function in javascript or C# the first result is of course an empty string.
I'd li... | For your requirements, I see two options:
(1) Remove the initial prefix character, if present.
(2) Use a full regular expression to separate the string.
Both are illustrated in this code:
```
using System;
using System.Linq;
using System.Text.RegularExpressions;
class APP { static void Main() {
string s = "~Peter... |
500,036 | <p>The included script references, in particular jQuery, are being rendered after viewstate. Is there a way to get this in the < head>?</p>
<pre><code>Page.ClientScript.RegisterClientScriptInclude("jQuery", "/scripts/jquery.js");
</code></pre>
<p>I am trying to register jquery.js in a user control's page load.</p... | [
{
"answer_id": 500042,
"author": "Kyle Trauberman",
"author_id": 21461,
"author_profile": "https://Stackoverflow.com/users/21461",
"pm_score": 3,
"selected": false,
"text": "<p>I had this problem a while back, and I ended up not using RegisterClientScriptInclude. </p>\n\n<p>I placed a p... | 2009/02/01 | [
"https://Stackoverflow.com/questions/500036",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/51275/"
] | The included script references, in particular jQuery, are being rendered after viewstate. Is there a way to get this in the < head>?
```
Page.ClientScript.RegisterClientScriptInclude("jQuery", "/scripts/jquery.js");
```
I am trying to register jquery.js in a user control's page load.
Thanks in advance!
P.S. If it ... | to directly inlcude it in the HEAD:
```
HtmlGenericControl Include = new HtmlGenericControl("script");
Include.Attributes.Add("type", "text/javascript");
Include.Attributes.Add("src", sInclude);
this.Page.Header.Controls.Add(Include);
```
you would want to check to make sure its not there already before adding i... |
500,057 | <p><em>quoting <a href="http://en.wikipedia.org/wiki/Binary_heap#Heap_implementation" rel="noreferrer">Wikipedia</a>:</em></p>
<blockquote>
<p>It is perfectly acceptable to use a
traditional binary tree data structure
to implement a binary heap. There is
an issue with finding the adjacent
element on the las... | [
{
"answer_id": 500238,
"author": "Zach Scrivena",
"author_id": 20029,
"author_profile": "https://Stackoverflow.com/users/20029",
"pm_score": 1,
"selected": false,
"text": "<p>How about performing a <a href=\"http://en.wikipedia.org/wiki/Depth_first_search\" rel=\"nofollow noreferrer\">de... | 2009/02/01 | [
"https://Stackoverflow.com/questions/500057",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | *quoting [Wikipedia](http://en.wikipedia.org/wiki/Binary_heap#Heap_implementation):*
>
> It is perfectly acceptable to use a
> traditional binary tree data structure
> to implement a binary heap. There is
> an issue with finding the adjacent
> element on the last level on the
> binary heap when adding an element... | Basically, the statement quoted refers to the problem of resolving the location for insertion and deletion of data elements into and from the heap. In order to maintain "the shape property" of a binary heap, the lowest level of the heap must always be filled from left to right leaving no empty nodes. To maintain the av... |
500,059 | <p>I want to be able to validate the image is exactly a certain with or a certain height, or if it's square.</p>
<p>In the validation block of the model that <code>has_attachment</code>, when I try to access <code>image_size</code>, <code>width</code>, or <code>height</code>, it always comes out as null.</p>
<p>I als... | [
{
"answer_id": 500088,
"author": "Joe Soul-bringer",
"author_id": 56279,
"author_profile": "https://Stackoverflow.com/users/56279",
"pm_score": 0,
"selected": false,
"text": "<p>You haven't specified what language and system you're working on. </p>\n\n<p>Still, for most web frameworks, I... | 2009/02/01 | [
"https://Stackoverflow.com/questions/500059",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/61018/"
] | I want to be able to validate the image is exactly a certain with or a certain height, or if it's square.
In the validation block of the model that `has_attachment`, when I try to access `image_size`, `width`, or `height`, it always comes out as null.
I also asked the question [here](http://oss.techno-weenie.net/disc... | Yea, you need to hack a bit in order to get it to work, but not so much. Adapting from attachment\_fu's own image processor:
```
validate :validate_image_size
private
def validate_image_size
w, h = width, height
unless w or h
with_image do |img|
w, h = img.columns, img.rows
end
... |
500,061 | <p>using asp.net and c# membership provider how to check if the user is registered or not?
I want to handle this in code not by using "login status"?</p>
| [
{
"answer_id": 500073,
"author": "Glennular",
"author_id": 14753,
"author_profile": "https://Stackoverflow.com/users/14753",
"pm_score": 6,
"selected": true,
"text": "<p>Not sure if you want to know if they are a \"registered\" user or have logged in (as the Login status would indicate)<... | 2009/02/01 | [
"https://Stackoverflow.com/questions/500061",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/459737/"
] | using asp.net and c# membership provider how to check if the user is registered or not?
I want to handle this in code not by using "login status"? | Not sure if you want to know if they are a "registered" user or have logged in (as the Login status would indicate)
Here's to know if they are logged in (what the Login status uses):
```
System.Web.HttpContext.Current.User.Identity.IsAuthenticated;
``` |
500,069 | <p>I am looking for a solution for <strong>detecting edge whitespace</strong> of c# bitmap, from the c# managed GDI+ library. </p>
<p>The images would be either <strong>transparent</strong> or <strong>white</strong>, most of the 400x pictures are 8000x8000px with about 2000px whitespace around the edges. </p>
<p>What... | [
{
"answer_id": 500095,
"author": "Patrick Klug",
"author_id": 10779,
"author_profile": "https://Stackoverflow.com/users/10779",
"pm_score": 4,
"selected": true,
"text": "<p>A great GDI+ resource is <a href=\"https://web.archive.org/web/20141230145656/http://bobpowell.net/faqmain.aspx\" r... | 2009/02/01 | [
"https://Stackoverflow.com/questions/500069",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/53238/"
] | I am looking for a solution for **detecting edge whitespace** of c# bitmap, from the c# managed GDI+ library.
The images would be either **transparent** or **white**, most of the 400x pictures are 8000x8000px with about 2000px whitespace around the edges.
What would be the most efficient way of finding out the edge... | A great GDI+ resource is [Bob Powell's GDI+ FAQ](https://web.archive.org/web/20141230145656/http://bobpowell.net/faqmain.aspx)!
You didn't say how you accessed the pixels in the image so I will assume that you used the slow GetPixel methods. You can use pointers and LockBits to access pixels in a faster way: [see Bob ... |
500,096 | <p>Does C# have anything like Python's <code>__getattr__</code>?</p>
<p>I have a class with many properties, and they all share the same accessor code. I would like to be able to drop the individual accessors entirely, just like in Python.</p>
<p>Here's what my code looks like now:</p>
<pre><code>class Foo
{
pro... | [
{
"answer_id": 500123,
"author": "Joe Erickson",
"author_id": 56710,
"author_profile": "https://Stackoverflow.com/users/56710",
"pm_score": 0,
"selected": false,
"text": "<p>This is not the same as what you get in Python with dynamic property names, but you might find it useful:</p>\n\n<... | 2009/02/01 | [
"https://Stackoverflow.com/questions/500096",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2119/"
] | Does C# have anything like Python's `__getattr__`?
I have a class with many properties, and they all share the same accessor code. I would like to be able to drop the individual accessors entirely, just like in Python.
Here's what my code looks like now:
```
class Foo
{
protected bool Get(string name, bool def)
... | No. Although C# supports reflection, it is read-only (for loaded assemblies). That means you can't change any methods, properties, or any other metadata. Although you could [create a dynamic property](http://msdn.microsoft.com/en-us/library/h1zby21a.aspx), calling it wouldn't be very convenient - it would be even worse... |
500,161 | <p>Let's say I have a database table "widgets"</p>
<p>Should there be an index.php with a big switch statement for different actions, like "list_widgets", "edit_widget", "new_widget", "delete_widget"... and then each of those actions in a separate file?</p>
<p>Or, should there be list_widgets.php, edit_widget.php, d... | [
{
"answer_id": 500164,
"author": "Mark Biek",
"author_id": 305,
"author_profile": "https://Stackoverflow.com/users/305",
"pm_score": 1,
"selected": false,
"text": "<p>I'd create a Widget class and give it edit(), new(), and delete() methods. Then you could have a list() function somewhe... | 2009/02/01 | [
"https://Stackoverflow.com/questions/500161",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9328/"
] | Let's say I have a database table "widgets"
Should there be an index.php with a big switch statement for different actions, like "list\_widgets", "edit\_widget", "new\_widget", "delete\_widget"... and then each of those actions in a separate file?
Or, should there be list\_widgets.php, edit\_widget.php, delete\_widge... | I'd create a Widget class and give it edit(), new(), and delete() methods. Then you could have a list() function somewhere that builds an array of Widget instances. I'd probably go ahead and create a WidgetList class (**WidgetList.php**), even if it's just a wrapper around an array initially.
Initially, I'd just have ... |
500,182 | <p>I have a header file in a library (alibrary.lib). The library is a static library (.lib) and it links properly to exe. </p>
<p>Now, I have a class: Vector3d.</p>
<pre><code>class Vector3d
{
void amethod()
{
blah
}
};
Vector3d cross(const Vector3d &v0, const Vector3d &v1)
{
floa... | [
{
"answer_id": 500188,
"author": "paxdiablo",
"author_id": 14860,
"author_profile": "https://Stackoverflow.com/users/14860",
"pm_score": 1,
"selected": false,
"text": "<p>The most likely explanation is that you've got code (specifically the definition of cross) in your include file and y... | 2009/02/01 | [
"https://Stackoverflow.com/questions/500182",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/29505/"
] | I have a header file in a library (alibrary.lib). The library is a static library (.lib) and it links properly to exe.
Now, I have a class: Vector3d.
```
class Vector3d
{
void amethod()
{
blah
}
};
Vector3d cross(const Vector3d &v0, const Vector3d &v1)
{
float x,y,z;
x = v0.y*v1.z... | If you define a free (not a member of a class) function, it has to be defined in a .cpp file separately compiled, or in a header and marked inline. So in your case, you can get away making it compile by this:
```
inline Vector3d cross(const Vector3d &v0, const Vector3d &v1) {
float x,y,z;
x = v0.y*v1.z-v0... |
500,187 | <p>I am trying to pass an href id to load() in JQuery, I can see from the alert the returned id# 960, so I know the id value is getting past I just don't know how to append the load url, well the $("#refreshme_"+add_id) is the important part, I use that to refresh the unique div id in the page assigned by the database ... | [
{
"answer_id": 500316,
"author": "pedalpete",
"author_id": 48067,
"author_profile": "https://Stackoverflow.com/users/48067",
"pm_score": 0,
"selected": false,
"text": "<p>This is a bit confusing, are you have 'add_to_favorites' as your trigger, and then add_to_cars in the html element. <... | 2009/02/01 | [
"https://Stackoverflow.com/questions/500187",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/60461/"
] | I am trying to pass an href id to load() in JQuery, I can see from the alert the returned id# 960, so I know the id value is getting past I just don't know how to append the load url, well the $("#refreshme\_"+add\_id) is the important part, I use that to refresh the unique div id in the page assigned by the database p... | You are using append() in this line
```
$('#favorite-listings').append(response);
```
Which is why you get new results added after the old ones. Change that line to
```
$('#favorite-listings').html(response);
``` |
500,214 | <p>I've finished making a site in django called 'kazbah', and I'm trying to deploy.</p>
<p>All the code for the kazbah site is in /home/git/DjangoProjects/kazbah and my httpd.conf looks like: </p>
<pre><code><Location "/">
SetHandler python-program
PythonHandler django.core.handlers.modpython
SetEnv... | [
{
"answer_id": 500303,
"author": "Louis Sayers",
"author_id": 66731,
"author_profile": "https://Stackoverflow.com/users/66731",
"pm_score": 0,
"selected": false,
"text": "<p>I'm pretty sure you can do the sys.path thing - it's in the django documentation.</p>\n\n<p>I might go over the dj... | 2009/02/01 | [
"https://Stackoverflow.com/questions/500214",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/66731/"
] | I've finished making a site in django called 'kazbah', and I'm trying to deploy.
All the code for the kazbah site is in /home/git/DjangoProjects/kazbah and my httpd.conf looks like:
```
<Location "/">
SetHandler python-program
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE kaz... | For a project resting under `/var/www/bbb` (called, "bbb"), I have the following set in the configuration file:
```
<Location "/">
SetHandler python-program
PythonHandler django.core.handlers.modpython
SetEnv DJANGO_SETTINGS_MODULE bbb.settings
PythonPath "['/var/www/', '/var/www/bbb/']... |
500,228 | <p>Does anybody know of a good (hopefully free) class to replace the .net SerialPort class? It is causing me issues and I need one that is slightly more flexible.</p>
<p><a href="https://stackoverflow.com/questions/496415/error-opening-serial-port">See my other thread about my issues</a>, but essentially I need to su... | [
{
"answer_id": 500250,
"author": "Rex Logan",
"author_id": 32958,
"author_profile": "https://Stackoverflow.com/users/32958",
"pm_score": 3,
"selected": true,
"text": "<p>Several years ago I used <a href=\"http://www.opennetcf.com/downloads/agreement.aspx?s=OpenNETCF.IO.Serial\" rel=\"nof... | 2009/02/01 | [
"https://Stackoverflow.com/questions/500228",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9266/"
] | Does anybody know of a good (hopefully free) class to replace the .net SerialPort class? It is causing me issues and I need one that is slightly more flexible.
[See my other thread about my issues](https://stackoverflow.com/questions/496415/error-opening-serial-port), but essentially I need to suppress the IOCTL\_SERI... | Several years ago I used [OpenNETCF.IO.Serial](http://www.opennetcf.com/downloads/agreement.aspx?s=OpenNETCF.IO.Serial) before serial support was added to .net. It is for the compact framework but I used it for both compact devices and regular windows apps. You get the source code so you can modify it yourself which is... |
500,237 | <p>How come App_Code is not a choice in the Add ASP.NET Folder submenu in the VS solution explorer? I realize you can create one yourself manually by just renaming a New Folder, but what is the rational here? Is this not where you are supposed to put "utility" or "service layer" type classes?</p>
<p>On a MVC project s... | [
{
"answer_id": 500242,
"author": "David Brown",
"author_id": 31516,
"author_profile": "https://Stackoverflow.com/users/31516",
"pm_score": 3,
"selected": false,
"text": "<p>Generally, I place \"service layer\" and \"utility\" classes in a separate project and add it as a reference to my ... | 2009/02/01 | [
"https://Stackoverflow.com/questions/500237",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/36590/"
] | How come App\_Code is not a choice in the Add ASP.NET Folder submenu in the VS solution explorer? I realize you can create one yourself manually by just renaming a New Folder, but what is the rational here? Is this not where you are supposed to put "utility" or "service layer" type classes?
On a MVC project side note.... | The real answer is because Microsoft wants you to buy in that you need VS to do MVC. However, to convert the project to pure JIT which is way easier to work with...
You can do it pretty straight forward.
(1) Move all folders containing class files to `App_Code` (leave Views folder where it is)
(2) Make `Global.asa... |
500,244 | <p>Been doing Java for number of years so haven't been tracking C++. Has <strong><em>finally</em></strong> clause been added to C++ exception handling in the language definition?</p>
<p>Is there a favored idiom that mimics Java's try/finally?</p>
<p>Am also bothered that C++ doesn't have an ultimate super type for al... | [
{
"answer_id": 500251,
"author": "Jason Baker",
"author_id": 2147,
"author_profile": "https://Stackoverflow.com/users/2147",
"pm_score": 6,
"selected": true,
"text": "<p>By making effective use of destructors. When an exception is thrown in a try block, any object created within it will... | 2009/02/01 | [
"https://Stackoverflow.com/questions/500244",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/48048/"
] | Been doing Java for number of years so haven't been tracking C++. Has ***finally*** clause been added to C++ exception handling in the language definition?
Is there a favored idiom that mimics Java's try/finally?
Am also bothered that C++ doesn't have an ultimate super type for all possible exceptions that could be t... | By making effective use of destructors. When an exception is thrown in a try block, any object created within it will be destroyed immediately (and hence its destructor called).
This is different from Java where you have no idea when an object's finalizer will be called.
**UPDATE**: Straight from the horse's mouth: [... |
500,246 | <p>I have a jQuery selector, which has a chained function.</p>
<p>Inside the function I want to get access to the TEXT representing the expression for the selector.</p>
<pre><code>$("cat dog").function() {
// how do I get access to the "cat dog" string from inside THIS function ?
};
</code></pre>
<p>I've over s... | [
{
"answer_id": 500249,
"author": "Luca Matteis",
"author_id": 50394,
"author_profile": "https://Stackoverflow.com/users/50394",
"pm_score": 2,
"selected": false,
"text": "<p>If you're using firebug you could <code>console.log(this)</code> inside the function and see if the selector strin... | 2009/02/01 | [
"https://Stackoverflow.com/questions/500246",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16940/"
] | I have a jQuery selector, which has a chained function.
Inside the function I want to get access to the TEXT representing the expression for the selector.
```
$("cat dog").function() {
// how do I get access to the "cat dog" string from inside THIS function ?
};
```
I've over simplified in this code sample wha... | There is a 'selector' attribute in the jQuery object, but I'm not sure it's always available. |
500,263 | <p>What is the best way to stop bots, malicious users, etc. from executing php scripts too fast? Is it ok if I use the <code>usleep()</code> or <code>sleep()</code> functions to simply do "nothing" for a while (just before the desired code executes), or is that plain stupid and there are better ways for this?</p>
<p>E... | [
{
"answer_id": 500291,
"author": "davogones",
"author_id": 59631,
"author_profile": "https://Stackoverflow.com/users/59631",
"pm_score": 1,
"selected": false,
"text": "<p>Your suggested method will force ALL users to wait unnecessarily before logging in.</p>\n\n<p>Most LAMP servers (and ... | 2009/02/01 | [
"https://Stackoverflow.com/questions/500263",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/59351/"
] | What is the best way to stop bots, malicious users, etc. from executing php scripts too fast? Is it ok if I use the `usleep()` or `sleep()` functions to simply do "nothing" for a while (just before the desired code executes), or is that plain stupid and there are better ways for this?
Example:
```
function login() {
... | The way most web servers work (Apache for example) is to maintain a collection of worker threads. When a PHP script is executed, one thread runs the PHP script.
When your script does `sleep(100)`, the script takes 100 seconds to execute.. That means your worker thread is tied up for 100 seconds.
The problem is, you h... |
500,278 | <p>I'm novice with both JS and jQuery, and I'm a little bit confused about what situations would require you to pass <code>event</code> as an argument into the function, and what situations you would <strong>not</strong> need to.</p>
<p>For example:</p>
<pre><code> $(document).ready(function() {
$('#foo... | [
{
"answer_id": 500282,
"author": "Nosredna",
"author_id": 61027,
"author_profile": "https://Stackoverflow.com/users/61027",
"pm_score": 2,
"selected": false,
"text": "<p>You only need the event if you're going to use it in the body of the handler.</p>\n"
},
{
"answer_id": 500296,... | 2009/02/01 | [
"https://Stackoverflow.com/questions/500278",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/55619/"
] | I'm novice with both JS and jQuery, and I'm a little bit confused about what situations would require you to pass `event` as an argument into the function, and what situations you would **not** need to.
For example:
```
$(document).ready(function() {
$('#foo').click(function() {
// Do somethin... | The `event` argument has a few uses. You only need to specify it as an argument to your handler if you're actually going to make use of it -- JavaScript handles variable numbers of arguments without complaint.
The most common use you'll see is to prevent the default behavior of the action that triggered the event. So:... |
500,283 | <p>I would like to know some of the strategy/practice you deal with to handle unhandled exceptions in ASP.NET MVC.</p>
<p>In short I want to avoid the yellow screen whenever any error happens and show a error consistent error message to the visitor.</p>
<p>I mean do you write a controller for this which shows the app... | [
{
"answer_id": 500332,
"author": "davogones",
"author_id": 59631,
"author_profile": "https://Stackoverflow.com/users/59631",
"pm_score": 2,
"selected": false,
"text": "<p>Try the <a href=\"http://www.pnpguidance.net/post/ASPNETMVCFrameworkPreview4HandleErrorAuthorizeOutputCacheActionFilt... | 2009/02/01 | [
"https://Stackoverflow.com/questions/500283",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/34644/"
] | I would like to know some of the strategy/practice you deal with to handle unhandled exceptions in ASP.NET MVC.
In short I want to avoid the yellow screen whenever any error happens and show a error consistent error message to the visitor.
I mean do you write a controller for this which shows the appropriate error pa... | Using the HandleError attribute is the way to go. Here is a small sample which I use to handle Ajax calls from JQuery, ExtJs, and others.
On your controller
```
public class DataController : Controller
{
[HandleError(ExceptionType = typeof(ArgumentException), View = "ErrorAjax")]
public void Foo(string x,... |
500,288 | <p>I've searched through google (maybe I didn't look hard enough) but I could not find how to turn Math.sqrt into an int.</p>
<p>I want to use Math.sqrt for a <i>for</i> loop and I guess I need it as an int but I can't seem to figure out how to cast the result to an int. So how do I do it?</p>
<p>I tried something s... | [
{
"answer_id": 500289,
"author": "Chris Ballance",
"author_id": 1551,
"author_profile": "https://Stackoverflow.com/users/1551",
"pm_score": 6,
"selected": true,
"text": "<p>Use <code>Math.round</code>, <code>Math.ceil</code>, or <code>Math.floor</code> depending on your specific rounding... | 2009/02/01 | [
"https://Stackoverflow.com/questions/500288",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/41718/"
] | I've searched through google (maybe I didn't look hard enough) but I could not find how to turn Math.sqrt into an int.
I want to use Math.sqrt for a *for* loop and I guess I need it as an int but I can't seem to figure out how to cast the result to an int. So how do I do it?
I tried something similar to Java:
```
(i... | Use `Math.round`, `Math.ceil`, or `Math.floor` depending on your specific rounding needs.
*"For rounding numbers to integers one of Math.round, Math.ceil and Math.floor are preferable, and for a desired result that can be expressed as a 32 bit signed integer the bitwise operation described below might also suit."*
-<... |
500,312 | <blockquote>
<p><strong>Possible Duplicate:</strong><br>
<a href="https://stackoverflow.com/questions/5611724/a-riddle-in-c">A riddle (in C)</a> </p>
</blockquote>
<p>1.</p>
<pre><code>main()
{
if(-1<(unsigned char)1)
printf("-1 is less than (unsigned char)1:ANSI semantics");
else
printf("-1 NO... | [
{
"answer_id": 500331,
"author": "starblue",
"author_id": 49246,
"author_profile": "https://Stackoverflow.com/users/49246",
"pm_score": 2,
"selected": false,
"text": "<p>For the first one the right-hand side is an unsigned char, and all unsigned char values fit into a signed int, so it i... | 2009/02/01 | [
"https://Stackoverflow.com/questions/500312",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/52913/"
] | >
> **Possible Duplicate:**
>
> [A riddle (in C)](https://stackoverflow.com/questions/5611724/a-riddle-in-c)
>
>
>
1.
```
main()
{
if(-1<(unsigned char)1)
printf("-1 is less than (unsigned char)1:ANSI semantics");
else
printf("-1 NOT less than (unsigned char)1:K&R semantics");
}
```
2.
```
int... | For the first one the right-hand side is an unsigned char, and all unsigned char values fit into a signed int, so it is converted to signed int.
For the second one the right-hand side is an unsigned int, so the left-hand side is converted from signed int to unsigned int.
See also [this CERT document on integer conver... |
500,328 | <p>Is there an existing function in numpy that will tell me if a value is either a numeric type or a numpy array? I'm writing some data-processing code which needs to handle numbers in several different representations (by "number" I mean any representation of a numeric quantity which can be manipulated using the stand... | [
{
"answer_id": 500392,
"author": "jfs",
"author_id": 4279,
"author_profile": "https://Stackoverflow.com/users/4279",
"pm_score": 1,
"selected": false,
"text": "<p>Your <code>is_numeric</code> is ill-defined. See my comments to your question.</p>\n\n<p>Other numerical types could be: <cod... | 2009/02/01 | [
"https://Stackoverflow.com/questions/500328",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/56541/"
] | Is there an existing function in numpy that will tell me if a value is either a numeric type or a numpy array? I'm writing some data-processing code which needs to handle numbers in several different representations (by "number" I mean any representation of a numeric quantity which can be manipulated using the standard... | As others have answered, there could be other numeric types besides the ones you mention.
One approach would be to check explicitly for the capabilities you want, with something like
```
# Python 2
def is_numeric(obj):
attrs = ['__add__', '__sub__', '__mul__', '__div__', '__pow__']
return all(hasattr(obj, attr... |
500,336 | <p>I have done the following code in JavaScript to put focus on the particular element (branch1 is a element),</p>
<pre><code>document.location.href="#branch1";
</code></pre>
<p>But as I am also using jQuery in my web app, so I want to do the above code in jQuery. I have tried but don't know why its not working,</p>... | [
{
"answer_id": 500341,
"author": "Luca Matteis",
"author_id": 50394,
"author_profile": "https://Stackoverflow.com/users/50394",
"pm_score": 1,
"selected": false,
"text": "<p>I think you might be looking for an \"anchor\" given the example you have.</p>\n\n<pre><code><a href=\"#jump\"&... | 2009/02/01 | [
"https://Stackoverflow.com/questions/500336",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/45261/"
] | I have done the following code in JavaScript to put focus on the particular element (branch1 is a element),
```
document.location.href="#branch1";
```
But as I am also using jQuery in my web app, so I want to do the above code in jQuery. I have tried but don't know why its not working,
```
$("#branch1").focus();
`... | Check [jQuery.ScrollTo](https://github.com/flesler/jquery.scrollTo), I think that's the behavior that you want, check the [demo](http://demos.flesler.com/jquery/scrollTo/). |
500,366 | <p>I want to change the font characteristics for buttons in the toolbar of the RichTextEditor, but I want them to be different than other buttons in my application. <strong>Is there any way to do this with just CSS?</strong> I know that I can do it with setStyle if necessary...</p>
| [
{
"answer_id": 501564,
"author": "Christian Nunciato",
"author_id": 32129,
"author_profile": "https://Stackoverflow.com/users/32129",
"pm_score": 2,
"selected": true,
"text": "<p>One way to do it, since the RichTextEditor's sub-components are declared in MXML and are therefore publicly a... | 2009/02/01 | [
"https://Stackoverflow.com/questions/500366",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8047/"
] | I want to change the font characteristics for buttons in the toolbar of the RichTextEditor, but I want them to be different than other buttons in my application. **Is there any way to do this with just CSS?** I know that I can do it with setStyle if necessary... | One way to do it, since the RichTextEditor's sub-components are declared in MXML and are therefore publicly accessible, is to assign their `styleName` properties individually at runtime (after the container's `creationComplete` event fires, to be sure the editor and all its children have been created), like so:
```
<m... |
500,374 | <p>I'm talking about the groove style of the text on focussed title bars, or safari's bookmarks bar for example. Is there an easy way to reproduce this style when using:</p>
<pre><code>[string drawAtPoint:... withAttributes:...];
</code></pre>
| [
{
"answer_id": 500402,
"author": "Peter Hosey",
"author_id": 30461,
"author_profile": "https://Stackoverflow.com/users/30461",
"pm_score": 2,
"selected": false,
"text": "<p>Draw it with an un-shadow below it. Use a shadow with color white, opacity 50% or so, blur 0, offset 1 pt down.</p>... | 2009/02/01 | [
"https://Stackoverflow.com/questions/500374",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/22424/"
] | I'm talking about the groove style of the text on focussed title bars, or safari's bookmarks bar for example. Is there an easy way to reproduce this style when using:
```
[string drawAtPoint:... withAttributes:...];
``` | If you want it to look perfect, you'll need to draw the text twice.
As you can see when zooming in on labels below toolbar items in any app, or for instance the bookmarks bar in Safari (Control+scroll up, control+option+\ to toggle smoothing of the zoomed in image), the text is rendered with sub-pixel anti-aliasing, a... |
500,376 | <p>I have the following class objects:</p>
<pre><code> public class VacancyCategory
{
public int ID { get; set; }
public string Text { get; set; }
public IList<VacancySubCategory> SubCategories { get; set; }
}
public class VacancySubCategory
{
public int ID { get; set; }
public string... | [
{
"answer_id": 500385,
"author": "Matt Hamilton",
"author_id": 615,
"author_profile": "https://Stackoverflow.com/users/615",
"pm_score": 4,
"selected": true,
"text": "<p>Try:</p>\n\n<pre><code>return this._categories.SelectMany(c => c.SubCategories);\n</code></pre>\n"
},
{
"an... | 2009/02/01 | [
"https://Stackoverflow.com/questions/500376",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/56145/"
] | I have the following class objects:
```
public class VacancyCategory
{
public int ID { get; set; }
public string Text { get; set; }
public IList<VacancySubCategory> SubCategories { get; set; }
}
public class VacancySubCategory
{
public int ID { get; set; }
public string Text { get; set; }
... | Try:
```
return this._categories.SelectMany(c => c.SubCategories);
``` |
500,431 | <p>What is the scope of variables in javascript? Do they have the same scope inside as opposed to outside a function? Or does it even matter? Also, where are the variables stored if they are defined globally?</p>
| [
{
"answer_id": 500435,
"author": "Jon Skeet",
"author_id": 22656,
"author_profile": "https://Stackoverflow.com/users/22656",
"pm_score": 7,
"selected": false,
"text": "<p>Variables declared globally have a global scope. Variables declared within a function are scoped to that function, an... | 2009/02/01 | [
"https://Stackoverflow.com/questions/500431",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/60102/"
] | What is the scope of variables in javascript? Do they have the same scope inside as opposed to outside a function? Or does it even matter? Also, where are the variables stored if they are defined globally? | TLDR
----
JavaScript has lexical (also called static) scoping and closures. This means you can tell the scope of an identifier by looking at the source code.
The four scopes are:
1. Global - visible by everything
2. Function - visible within a function (and its sub-functions and blocks)
3. Block - visible within a b... |
500,436 | <p>I have a situation where an object A has a reference to object B. B also has a reference back to A. For the sake of simplicity, let's say that A and B are of the same type. How do I ensure that when I update the reference on A, that the update will be reflected on B as well (and vice versa)?</p>
<p>An example of... | [
{
"answer_id": 500447,
"author": "Soviut",
"author_id": 46914,
"author_profile": "https://Stackoverflow.com/users/46914",
"pm_score": 0,
"selected": false,
"text": "<p>You have to explicitly set:</p>\n\n<pre><code>A.To = B;\nB.From = A;\n</code></pre>\n\n<p>As far as this being possible,... | 2009/02/01 | [
"https://Stackoverflow.com/questions/500436",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/26054/"
] | I have a situation where an object A has a reference to object B. B also has a reference back to A. For the sake of simplicity, let's say that A and B are of the same type. How do I ensure that when I update the reference on A, that the update will be reflected on B as well (and vice versa)?
An example of an interface... | ```
IGraphNode From
{
get { return from; }
set
{
from = value;
if (value.To != this) {
value.To = this;
}
}
}
IGraphNode To
{
get { return to; }
set
{
to = value;
if (value.From != this) {
value.From = this;
}
}
}... |
500,477 | <p>Is there a built-in method in Python to execute a system command without displaying the output? I only want to grab the return value.</p>
<p>It is important that it be cross-platform, so just redirecting the output to /dev/null won't work on Windows, and the other way around. I know I can just check os.platform and... | [
{
"answer_id": 500483,
"author": "vava",
"author_id": 6258,
"author_profile": "https://Stackoverflow.com/users/6258",
"pm_score": 2,
"selected": false,
"text": "<p>You can redirect output into temp file and delete it afterward. But there's also a method called popen that redirects output... | 2009/02/01 | [
"https://Stackoverflow.com/questions/500477",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11515/"
] | Is there a built-in method in Python to execute a system command without displaying the output? I only want to grab the return value.
It is important that it be cross-platform, so just redirecting the output to /dev/null won't work on Windows, and the other way around. I know I can just check os.platform and build the... | ```
import os
import subprocess
subprocess.call(["ls", "-l"], stdout=open(os.devnull, "w"), stderr=subprocess.STDOUT)
``` |
500,493 | <p>What is the preferred method to achieve the C++ equivalent of java's <code>instanceof</code>?</p>
| [
{
"answer_id": 500495,
"author": "Laserallan",
"author_id": 11758,
"author_profile": "https://Stackoverflow.com/users/11758",
"pm_score": 9,
"selected": true,
"text": "<p>Try using:</p>\n\n<pre><code>if(NewType* v = dynamic_cast<NewType*>(old)) {\n // old was safely casted to New... | 2009/02/01 | [
"https://Stackoverflow.com/questions/500493",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/24545/"
] | What is the preferred method to achieve the C++ equivalent of java's `instanceof`? | Try using:
```
if(NewType* v = dynamic_cast<NewType*>(old)) {
// old was safely casted to NewType
v->doSomething();
}
```
This requires your compiler to have rtti support enabled.
EDIT:
I've had some good comments on this answer!
Every time you need to use a dynamic\_cast (or instanceof) you'd better ask you... |
500,504 | <p>I've been told not to use <code>for...in</code> with arrays in JavaScript. Why not?</p>
| [
{
"answer_id": 500509,
"author": "vava",
"author_id": 6258,
"author_profile": "https://Stackoverflow.com/users/6258",
"pm_score": 4,
"selected": false,
"text": "<p>Because it enumerates through object fields, not indexes. You can get value with index \"length\" and I doubt you want this.... | 2009/02/01 | [
"https://Stackoverflow.com/questions/500504",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/60102/"
] | I've been told not to use `for...in` with arrays in JavaScript. Why not? | The reason is that one construct:
```js
var a = []; // Create a new empty array.
a[5] = 5; // Perfectly legal JavaScript that resizes the array.
for (var i = 0; i < a.length; i++) {
// Iterate over numeric indexes from 0 to 5, as everyone expects.
console.log(a[i]);
}
/* Will display:
undefined
... |
500,507 | <p>I just noticed while creating a RESTful WCF service that the Method parameter on the <code>WebInvoke</code> attribute is case sensitive (CAPS required).</p>
<p>So,</p>
<pre><code>[WebInvoke(Method = "Delete")]
</code></pre>
<p>is not equal to</p>
<pre><code>[WebInvoke(Method = "DELETE")]
</code></pre>
<p>This m... | [
{
"answer_id": 500516,
"author": "Marc Gravell",
"author_id": 23354,
"author_profile": "https://Stackoverflow.com/users/23354",
"pm_score": 5,
"selected": true,
"text": "<p>A bit indirect, but there are <code>System.Net.WebRequestMethods.Http</code> constants:</p>\n\n<pre><code>public co... | 2009/02/01 | [
"https://Stackoverflow.com/questions/500507",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3957/"
] | I just noticed while creating a RESTful WCF service that the Method parameter on the `WebInvoke` attribute is case sensitive (CAPS required).
So,
```
[WebInvoke(Method = "Delete")]
```
is not equal to
```
[WebInvoke(Method = "DELETE")]
```
This mistake was causing a `ProtocolException`:
>
> System.ServiceModel... | A bit indirect, but there are `System.Net.WebRequestMethods.Http` constants:
```
public const string Connect = "CONNECT";
public const string Get = "GET";
public const string Head = "HEAD";
public const string MkCol = "MKCOL";
public const string Post = "POST";
public const string Put = "PUT";
```
but no "DELETE" - ... |
500,508 | <p>I can't understand where the <code>final</code> keyword is <em>really</em> handy when it is used on method parameters. </p>
<p>If we exclude the usage of anonymous classes, readability and intent declaration then it seems almost worthless to me. </p>
<p>Enforcing that some data remains constant is not as strong a... | [
{
"answer_id": 500517,
"author": "Jon Skeet",
"author_id": 22656,
"author_profile": "https://Stackoverflow.com/users/22656",
"pm_score": 7,
"selected": false,
"text": "<p>Yes, excluding anonymous classes, readability and intent declaration it's almost worthless. Are those three things wo... | 2009/02/01 | [
"https://Stackoverflow.com/questions/500508",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | I can't understand where the `final` keyword is *really* handy when it is used on method parameters.
If we exclude the usage of anonymous classes, readability and intent declaration then it seems almost worthless to me.
Enforcing that some data remains constant is not as strong as it seems.
* If the parameter is ... | Sometimes it's nice to be explicit (for readability) that the variable doesn't change. Here's a simple example where using `final` can save some possible headaches:
```
public void setTest(String test) {
test = test;
}
```
If you forget the 'this' keyword on a setter, then the variable you want to set doesn't ge... |
500,551 | <p>I've been doing a lot of research on how best to write "correct" network code in C#.</p>
<p>I've seen a number of examples using the "using" statement of C#, and I think this is a good approach, however i've seen inconsistent use of it with various expressions.</p>
<p>For instance, suppose I have some code like th... | [
{
"answer_id": 500563,
"author": "Marc Gravell",
"author_id": 23354,
"author_profile": "https://Stackoverflow.com/users/23354",
"pm_score": 5,
"selected": true,
"text": "<p>Generally, objects should internally handle multiple <code>Dispose()</code> calls, and only do the main code once; ... | 2009/02/01 | [
"https://Stackoverflow.com/questions/500551",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/61164/"
] | I've been doing a lot of research on how best to write "correct" network code in C#.
I've seen a number of examples using the "using" statement of C#, and I think this is a good approach, however i've seen inconsistent use of it with various expressions.
For instance, suppose I have some code like this:
```
TcpClien... | Generally, objects should internally handle multiple `Dispose()` calls, and only do the main code once; so a stream getting `Dispose()`d multiple times is not usually a problem. Personally, I would use lots of `using` there; note that you don't need to indent/nest, though (unless different levels have different life-ti... |
500,569 | <p>I wrote some CSS in my HTML code to create rollover buttons. Then i tried to run it with IE 7 and surprise! it doesn't run. In fact it shows both the button and underlying rollover. How can i get around IE's inability to cache background images? Preferably using CSS but javascript 'will' be tried.</p>
<p>Sample CSS... | [
{
"answer_id": 500630,
"author": "Marius",
"author_id": 1585,
"author_profile": "https://Stackoverflow.com/users/1585",
"pm_score": 0,
"selected": false,
"text": "<p>if you are using the :hover pseudo-selector, then it won't work in IE unless it is an anchor tag. Try changing the button ... | 2009/02/01 | [
"https://Stackoverflow.com/questions/500569",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/60102/"
] | I wrote some CSS in my HTML code to create rollover buttons. Then i tried to run it with IE 7 and surprise! it doesn't run. In fact it shows both the button and underlying rollover. How can i get around IE's inability to cache background images? Preferably using CSS but javascript 'will' be tried.
Sample CSS:
```
#M... | Well firstly you are giving conflicting instructions ...
```
background: url("img/menu.png") top left no-repeat;
background-position: -123px 0;
```
... the background is already positioned using shorthand.
I assume that your regular and hover states both share the same image, so why not do both with shorthand? Remo... |
500,578 | <p>I have a generator and I would like to know if I can use it without having to worry about StopIteration , and I would like to use it without the <strong><code>for item in generator</code></strong> . I would like to use it with a while statement for example ( or other constructs ). How could I do that ?</p>
| [
{
"answer_id": 500609,
"author": "SilentGhost",
"author_id": 12855,
"author_profile": "https://Stackoverflow.com/users/12855",
"pm_score": 4,
"selected": false,
"text": "<p>built-in function</p>\n\n<blockquote>\n <p>next(iterator[, default])<br>\n Retrieve the next item from the ite... | 2009/02/01 | [
"https://Stackoverflow.com/questions/500578",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/31610/"
] | I have a generator and I would like to know if I can use it without having to worry about StopIteration , and I would like to use it without the **`for item in generator`** . I would like to use it with a while statement for example ( or other constructs ). How could I do that ? | Use this to wrap your generator:
```
class GeneratorWrap(object):
def __init__(self, generator):
self.generator = generator
def __iter__(self):
return self
def next(self):
for o in self.generator:
return o
raise StopIteration # If you don't car... |
500,580 | <p>I was reading Ivor Horton's Beginning Visual C++ 2008 and many of its CLR examples have this definition for main:</p>
<pre><code>int main(array<System::String ^> ^args)
</code></pre>
<p>I went back, page by page, to the beginning of the book to find the first such instance with an explanation what it really ... | [
{
"answer_id": 500585,
"author": "ng5000",
"author_id": 36860,
"author_profile": "https://Stackoverflow.com/users/36860",
"pm_score": 0,
"selected": false,
"text": "<p>See this for full discussion: <a href=\"http://msdn.microsoft.com/de-de/library/yk97tc08.aspx\" rel=\"nofollow noreferre... | 2009/02/01 | [
"https://Stackoverflow.com/questions/500580",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/40657/"
] | I was reading Ivor Horton's Beginning Visual C++ 2008 and many of its CLR examples have this definition for main:
```
int main(array<System::String ^> ^args)
```
I went back, page by page, to the beginning of the book to find the first such instance with an explanation what it really means, but couldn't find one.
O... | It's a managed pointer - while \* marks a pointer to an object that is unmanaged, ^ points to a garbage collected object (handled by the framework). Read [this](http://msdn.microsoft.com/en-us/library/cxx6f46y.aspx) for more information about the way pointers are handled in .NET. |
500,582 | <p>I wonder if anyone has any idea on how to implement the nice and clean UI from <a href="http://www.mightyseek.com/podpress/" rel="nofollow noreferrer">PodPress</a> (a Wordpress plugin) into .NET just like you find in the <a href="http://blog.stackoverflow.com">StackOverflow Blog</a> when PodCasts are available.</p>
... | [
{
"answer_id": 511517,
"author": "Pete Michaud",
"author_id": 15915,
"author_profile": "https://Stackoverflow.com/users/15915",
"pm_score": 0,
"selected": false,
"text": "<p>The magic happens inside the flash player, so all you'd need to do to get the same effect is place that flash play... | 2009/02/01 | [
"https://Stackoverflow.com/questions/500582",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/28004/"
] | I wonder if anyone has any idea on how to implement the nice and clean UI from [PodPress](http://www.mightyseek.com/podpress/) (a Wordpress plugin) into .NET just like you find in the [StackOverflow Blog](http://blog.stackoverflow.com) when PodCasts are available.
[](htt... | >
> I wonder if anyone has any idea on how
> to implement the nice and clean UI
> from PodPress (a Wordpress plugin)
> into .NET just like you find in the
> StackOverflow Blog when PodCasts are
> available.
>
> I'm searching for the entire bottle of magic, iTunes integration, Stats, etc... Shouldn't Jeff give... |
500,606 | <p>What is the difference between using <a href="https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Operators/delete" rel="noreferrer">the <code>delete</code> operator</a> on the array element as opposed to using <a href="https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array/spli... | [
{
"answer_id": 500613,
"author": "andynormancx",
"author_id": 46354,
"author_profile": "https://Stackoverflow.com/users/46354",
"pm_score": 7,
"selected": false,
"text": "<p>Because delete only removes the object from the element in the array, the length of the array won't change. Splice... | 2009/02/01 | [
"https://Stackoverflow.com/questions/500606",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/60102/"
] | What is the difference between using [the `delete` operator](https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Operators/delete) on the array element as opposed to using [the `Array.splice` method](https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array/splice)?
For example:
``... | `delete` will delete the object property, but will not reindex the array or update its length. This makes it appears as if it is undefined:
```
> myArray = ['a', 'b', 'c', 'd']
["a", "b", "c", "d"]
> delete myArray[0]
true
> myArray[0]
undefined
```
Note that it is not in fact set to the value `undefined`, rat... |
500,637 | <p>This might be a naive question. I'm currently learning the Spring framework and <i>dependency injection</i>. While the basic principle of DI is rather easy to grasp, it's not immediately obvious why you need an elaborate framework to implement it.</p>
<p>Consider the following:</p>
<pre><code>public abstract class... | [
{
"answer_id": 500641,
"author": "Mnementh",
"author_id": 21005,
"author_profile": "https://Stackoverflow.com/users/21005",
"pm_score": 2,
"selected": false,
"text": "<p>If you hard-code the inserted class, you need that class be available at compile-time. With a configuration-file you c... | 2009/02/01 | [
"https://Stackoverflow.com/questions/500637",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/50572/"
] | This might be a naive question. I'm currently learning the Spring framework and *dependency injection*. While the basic principle of DI is rather easy to grasp, it's not immediately obvious why you need an elaborate framework to implement it.
Consider the following:
```
public abstract class Saw
{
public abstract... | I've had the exact same question, and it was answered by this:
Granted, you could do what you've described in "Then you could simply do:..." (let's call that "class A"). However, that would couple class A to HandSaw, or to all dependencies needed from class SawMill. Why should A be coupled to HandSaw - or, if you ta... |
500,650 | <p>First of all,I'm not into web programming. I bumped into django and read a bit about models. I was intrigued by the following code ( from djangoproject.com ) :</p>
<pre><code>
class Person(models.Model):
first_name = models.CharField(max_length=50)
last_name = models.CharField(max_length=50)
def __str_... | [
{
"answer_id": 500678,
"author": "Andy Hume",
"author_id": 46460,
"author_profile": "https://Stackoverflow.com/users/46460",
"pm_score": 4,
"selected": true,
"text": "<p>Yes, first_name and last_name are class variables. They define fields that will be created in a database table. There ... | 2009/02/01 | [
"https://Stackoverflow.com/questions/500650",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/31610/"
] | First of all,I'm not into web programming. I bumped into django and read a bit about models. I was intrigued by the following code ( from djangoproject.com ) :
```
class Person(models.Model):
first_name = models.CharField(max_length=50)
last_name = models.CharField(max_length=50)
def __str__(self):
... | Yes, first\_name and last\_name are class variables. They define fields that will be created in a database table. There is a Person table that has first\_name and last\_name columns, so it makes sense for them to be at Class level at this point.
For more on models, see:
<http://docs.djangoproject.com/en/dev/topics/db/... |
500,656 | <p>Just wanted opinions on a design question. If you have a C++ class than owns other objects, would you use smart pointers to achieve this?</p>
<pre><code>class Example {
public:
// ...
private:
boost::scoped_ptr<Owned> data;
};
</code></pre>
<p>The 'Owned' object can't be stored by value because it may ... | [
{
"answer_id": 500670,
"author": "CB Bailey",
"author_id": 19563,
"author_profile": "https://Stackoverflow.com/users/19563",
"pm_score": 3,
"selected": false,
"text": "<p>It's not overkill at all, it's a good idea.</p>\n\n<p>It does require your class clients to know about boost, though.... | 2009/02/01 | [
"https://Stackoverflow.com/questions/500656",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/49643/"
] | Just wanted opinions on a design question. If you have a C++ class than owns other objects, would you use smart pointers to achieve this?
```
class Example {
public:
// ...
private:
boost::scoped_ptr<Owned> data;
};
```
The 'Owned' object can't be stored by value because it may change through the lifetime of t... | It's a good idea. It helps simplify your code, and ensure that when you do change the Owned object during the lifetime of the object, the previous one gets destroyed properly.
You have to remember that scoped\_ptr is noncopyable, though, which makes your class noncopyable by default until/unless you add your own copy ... |
500,666 | <p>(Was: ASP.Net codebehind not finding controls on the web page)</p>
<p>I'm using VS 2008.</p>
<p>I don't know what secret switch I need to flip, or what trip wire I accidentally tripped over, but the last form I created in my project is misbehaving very seriously: the codebehind is apparently unable to find any of ... | [
{
"answer_id": 500681,
"author": "Marc Gravell",
"author_id": 23354,
"author_profile": "https://Stackoverflow.com/users/23354",
"pm_score": 1,
"selected": false,
"text": "<p>Have you renamed it? Changed the base/project namespace? In particular look at <code>EEI_App.UserSignature</code> ... | 2009/02/01 | [
"https://Stackoverflow.com/questions/500666",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7850/"
] | (Was: ASP.Net codebehind not finding controls on the web page)
I'm using VS 2008.
I don't know what secret switch I need to flip, or what trip wire I accidentally tripped over, but the last form I created in my project is misbehaving very seriously: the codebehind is apparently unable to find any of the controls that... | OK, I found my own answer:
Commit all working code to source control, blow away the dev tree, get latest version.
Suddenly everything is working again. And it also solved [my other problem of today](https://stackoverflow.com/questions/500957/unable-to-launch-the-asp-net-development-server-because-port-1900-is-in-use)... |
500,668 | <p>I want to execute an SQL query like:</p>
<pre>
select 'tb1'.'f1','tb1'.'f2','tb2'.'f1' from 'tb1','tb2';
</pre>
<p>Now the problem is that i want to put it into an array in PHP like:</p>
<pre>
$result['tb1']['f1'], $result['tb1']['f2'], $result['tb2']['f1']...
</pre>
<p>Any idea how to achieve the above? Afaik ... | [
{
"answer_id": 500694,
"author": "benlumley",
"author_id": 39161,
"author_profile": "https://Stackoverflow.com/users/39161",
"pm_score": 3,
"selected": true,
"text": "<p>You'll need to select the data as you are already doing, and then loop over it getting it into the format required, an... | 2009/02/01 | [
"https://Stackoverflow.com/questions/500668",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/426996/"
] | I want to execute an SQL query like:
```
select 'tb1'.'f1','tb1'.'f2','tb2'.'f1' from 'tb1','tb2';
```
Now the problem is that i want to put it into an array in PHP like:
```
$result['tb1']['f1'], $result['tb1']['f2'], $result['tb2']['f1']...
```
Any idea how to achieve the above? Afaik there is no function wh... | You'll need to select the data as you are already doing, and then loop over it getting it into the format required, and because the fields have the same names, its easiest to use aliases or they'll just overwrite each other in the returned data (but you could use mysql\_fetch\_row instead, which returns a numerically i... |
500,676 | <p>How would the following sql statement translate to a linq query?</p>
<pre><code>select ID,
Price,
dbo.fGetText(DescriptionID, defaultLanguage, currentUserLanguage)
from Products
</code></pre>
<p>The UDF fGetText is quite substantial and used throughout the code base, so it needs to be encapsulated... | [
{
"answer_id": 500688,
"author": "Espo",
"author_id": 2257,
"author_profile": "https://Stackoverflow.com/users/2257",
"pm_score": 3,
"selected": true,
"text": "<p>Here is the MSDN article:</p>\n\n<p><a href=\"http://msdn.microsoft.com/en-us/library/bb399416.aspx\" rel=\"nofollow noreferr... | 2009/02/01 | [
"https://Stackoverflow.com/questions/500676",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/58864/"
] | How would the following sql statement translate to a linq query?
```
select ID,
Price,
dbo.fGetText(DescriptionID, defaultLanguage, currentUserLanguage)
from Products
```
The UDF fGetText is quite substantial and used throughout the code base, so it needs to be encapsulated (as a UDF or otherwise, p... | Here is the MSDN article:
[How to: Call User-Defined Functions Inline (LINQ to SQL)](http://msdn.microsoft.com/en-us/library/bb399416.aspx)
A note from the same page:
>
> Although you can call user-defined
> functions inline, functions that are
> included in a query whose execution is
> deferred are not executed... |
500,696 | <ul>
<li>Upgraded from MVC Beta to MVC RC1.</li>
<li>Re-pointed all references in the project to point to the new assemblies</li>
<li>Rebooted</li>
<li>Everything compiles (and runs!)</li>
<li>But...</li>
</ul>
<p>Opening a view (.aspx) in VS and she just disappears!
Event Viewer gives:</p>
<pre><code>NET Runtime ver... | [
{
"answer_id": 500732,
"author": "Christian Dalager",
"author_id": 11239,
"author_profile": "https://Stackoverflow.com/users/11239",
"pm_score": 2,
"selected": false,
"text": "<p>I've had problems like that before. It was the webform editor. If you right-click the aspx file and choose \"... | 2009/02/01 | [
"https://Stackoverflow.com/questions/500696",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/193/"
] | * Upgraded from MVC Beta to MVC RC1.
* Re-pointed all references in the project to point to the new assemblies
* Rebooted
* Everything compiles (and runs!)
* But...
Opening a view (.aspx) in VS and she just disappears!
Event Viewer gives:
```
NET Runtime version 2.0.50727.3053 - Fatal Execution Engine Error (6E075E00... | Try removing all bin/obj directories, and clearing your Temporary ASP.NET Files and %TEMP% directories. Then issue the following commands from a VS2008 command prompt:
```
ngen /delete System.Web.Mvc
ngen /delete System.Web.Abstractions
ngen update
```
Also ensure that all your references (MvcContrib, anything else ... |
500,701 | <p>I'm having some trouble installing and configuring qt on my vista laptop.</p>
<p>I'm trying to setup a development environment on my laptop where I compile from the command line, because that's how the environment is setup on my university's linux machines, so I don't want to tie myself to some IDE .. (plus, <em>re... | [
{
"answer_id": 500949,
"author": "Jacek Ławrynowicz",
"author_id": 43399,
"author_profile": "https://Stackoverflow.com/users/43399",
"pm_score": 0,
"selected": false,
"text": "<p>Qmake generates Makefile from *.pro file located in current directory. It has qt path compiled in. Type \"qma... | 2009/02/01 | [
"https://Stackoverflow.com/questions/500701",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/35364/"
] | I'm having some trouble installing and configuring qt on my vista laptop.
I'm trying to setup a development environment on my laptop where I compile from the command line, because that's how the environment is setup on my university's linux machines, so I don't want to tie myself to some IDE .. (plus, *real* programme... | If you want to stay with the command line anyway (plus use it on a linux box later / parallel) I'd suggest at least trying out the MinGW version of Qt. I'm using it regularly, and besides of the non-existance of a GUI it works pretty well. Using MinGW also has the advantage that you can simply download and install the ... |
500,703 | <p>I wrote an install program with Wix and it worked fine to install my program.
Now I need to update it, so I bumped up the version number but when I go to install the new program over the old one it complains that an older version is already installed and tells me to uninstall it first.</p>
<p>How do I get it to upd... | [
{
"answer_id": 500997,
"author": "coding Bott",
"author_id": 44462,
"author_profile": "https://Stackoverflow.com/users/44462",
"pm_score": 3,
"selected": false,
"text": "<p>You need to use the upgrade table:</p>\n\n<pre><code><Upgrade Id='15E2DAFB-35C5-4043-974B-0E342C25D76A'>\n ... | 2009/02/01 | [
"https://Stackoverflow.com/questions/500703",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/41630/"
] | I wrote an install program with Wix and it worked fine to install my program.
Now I need to update it, so I bumped up the version number but when I go to install the new program over the old one it complains that an older version is already installed and tells me to uninstall it first.
How do I get it to update or aut... | I feel that none of the provided answers are complete or self-contained, so after digging my way through this swamp, here's the steps I think are necessary to get the (utterly self-evident) requirement of an update to work:
1. Make sure your Product Id changes every time you build. If you don't, you'll always get the ... |
500,711 | <pre><code>namespace ThPool
{
class Program
{
private static long val = 0;
private static string obj = string.Empty;
static void Main(string[] args)
{
Thread objThread1 = new Thread(new ThreadStart(IncrementValue));
objThread1.Start();
Thread ... | [
{
"answer_id": 500723,
"author": "tuinstoel",
"author_id": 43901,
"author_profile": "https://Stackoverflow.com/users/43901",
"pm_score": 0,
"selected": false,
"text": "<p>You can use <code>BeginInvoke</code>, <code>EndInvoke</code>. It uses the threadpool behind the scenes but it is easi... | 2009/02/01 | [
"https://Stackoverflow.com/questions/500711",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/60930/"
] | ```
namespace ThPool
{
class Program
{
private static long val = 0;
private static string obj = string.Empty;
static void Main(string[] args)
{
Thread objThread1 = new Thread(new ThreadStart(IncrementValue));
objThread1.Start();
Thread objThre... | ```
EventWaitHandle[] waitHandles = new EventWaitHandle[2];
for(int i = 0; i < 2; i++)
{
waitHandles[i] = new AutoResetEvent(false);
ThreadPool.QueueUserWorkItem(state =>
{
EventWaitHandle handle = state as EventWaitHandle;
for(int j = 0; j < 10000000; j++)
{
Interlocked... |
500,712 | <p>what is the memory overhead on the stack and heap of A versus B</p>
<p>A:</p>
<pre><code>private string TestA()
{
string a = _builder.Build();
return a;
}
</code></pre>
<p>B:</p>
<pre><code>private string TestB()
{
return _builder.Build();
}
</code></pre>
| [
{
"answer_id": 500718,
"author": "Ray Hidayat",
"author_id": 49643,
"author_profile": "https://Stackoverflow.com/users/49643",
"pm_score": 1,
"selected": false,
"text": "<p>They both get optimised to the same thing.</p>\n\n<p>In answer to the question in your title \"do all local variabl... | 2009/02/01 | [
"https://Stackoverflow.com/questions/500712",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4653/"
] | what is the memory overhead on the stack and heap of A versus B
A:
```
private string TestA()
{
string a = _builder.Build();
return a;
}
```
B:
```
private string TestB()
{
return _builder.Build();
}
``` | re the efficiency question; the two are identical, and in release mode will be reduced to the same thing. Either way, `string` is a reference-type, so the `string` itself is always on the heap. The only thing on the stack would be the reference to the `string` - a few bytes (no matter the string length).
"do all local... |
500,728 | <p>I am building a asp.net webforms (3.5 sp1) application, using jquery where I can to animate the UI, change its state. It has worked great until I started doing postbacks, where the UI obviously resets itself to its initial state.</p>
<p>So my question is, what are the best practices for saving and restoring jquery/... | [
{
"answer_id": 500745,
"author": "flesh",
"author_id": 27805,
"author_profile": "https://Stackoverflow.com/users/27805",
"pm_score": 2,
"selected": false,
"text": "<p>You have two options:</p>\n\n<ul>\n<li>Client side cookie</li>\n<li>Store UI settings server side via postback or webmeth... | 2009/02/01 | [
"https://Stackoverflow.com/questions/500728",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/32809/"
] | I am building a asp.net webforms (3.5 sp1) application, using jquery where I can to animate the UI, change its state. It has worked great until I started doing postbacks, where the UI obviously resets itself to its initial state.
So my question is, what are the best practices for saving and restoring jquery/UI state b... | I typically store things like menu state or filter (set of inputs in a div) visibility, etc. server-side in the session via AJAX. When a menu expands or a filter is shown, the click handler will fire an AJAX event to a web service that will record the state of the menu or filter visibility in the user's session. On a p... |
500,730 | <p>K... I'm doing something obviously wrong. I have a simple page with a file input control on and a submit button. I'm trying out the new "File" ActionResult that was released with the Mvc RC...</p>
<p>All, I want to happen is when the submit button is clicked the selected file is uploaded to the database. This all w... | [
{
"answer_id": 500751,
"author": "Erik van Brakel",
"author_id": 909,
"author_profile": "https://Stackoverflow.com/users/909",
"pm_score": 2,
"selected": false,
"text": "<p>I think it's pretty simple: the src attribute of your img tag requires an URL. What you're doing here is just putti... | 2009/02/01 | [
"https://Stackoverflow.com/questions/500730",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/55862/"
] | K... I'm doing something obviously wrong. I have a simple page with a file input control on and a submit button. I'm trying out the new "File" ActionResult that was released with the Mvc RC...
All, I want to happen is when the submit button is clicked the selected file is uploaded to the database. This all works fine.... | FileResult returns the ASCII or binary contents of the file. When you say do the following:
```
<img src="<%=Model.FileContent.FileContents %>" />
```
You are attempting to push the binary image data into the `src` attribute. That will never work, because the `src` must a URL or a path to an image.
There are severa... |
500,731 | <p>My question is related to HTML, and PURE html. I am working on a new design for my front page on a social network called kwick, and I want to create a kind of space for my favorite Video at the moment.</p>
<p>Now my problem is, how do I realize something like this:</p>
<p>I take a picture of my ipod like that(just... | [
{
"answer_id": 500738,
"author": "jacobangel",
"author_id": 31318,
"author_profile": "https://Stackoverflow.com/users/31318",
"pm_score": 0,
"selected": false,
"text": "<p>Your biggest hurdle will be ensuring that your <strong>WMODE = transparent</strong>. Setting WMODE to transparent wi... | 2009/02/01 | [
"https://Stackoverflow.com/questions/500731",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | My question is related to HTML, and PURE html. I am working on a new design for my front page on a social network called kwick, and I want to create a kind of space for my favorite Video at the moment.
Now my problem is, how do I realize something like this:
I take a picture of my ipod like that(just an example, its ... | You don't need to cut the image at all. Make a div that has enough space for the whole picture of the ipod and use CSS to make it the background image (can be inline styles if you can't add your own CSS files).
```
<div style="background:url(ipod.jpg); width:300px; height:400px;">
<iframe src="..." style="margin: ... |
500,736 | <p>These Codes really boring. And Tostring() give me error !!! Can you rearrange these codes ?</p>
<pre><code>
class Program
{
static void Main(string[] args)
{
string[] arraystr = { "yusuf", "mehmet" };
Ilist myitems = new Ilist(arraystr);
SelectedItemsList s... | [
{
"answer_id": 500739,
"author": "Neil Barnwell",
"author_id": 26414,
"author_profile": "https://Stackoverflow.com/users/26414",
"pm_score": 2,
"selected": false,
"text": "<p>Rename <code>Ilist.ToString()</code> to <code>ToStringArray()</code>. All objects have a <code>ToString()</code>... | 2009/02/01 | [
"https://Stackoverflow.com/questions/500736",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/52420/"
] | These Codes really boring. And Tostring() give me error !!! Can you rearrange these codes ?
```
class Program
{
static void Main(string[] args)
{
string[] arraystr = { "yusuf", "mehmet" };
Ilist myitems = new Ilist(arraystr);
SelectedItemsList slist = new Sel... | Rename `Ilist.ToString()` to `ToStringArray()`. All objects have a `ToString()` method but you're overriding it with a function with a different return type, causing your error.
IList isn't a good name for a class, because convention dicates that names starting with "I" should be interfaces. I recommend Ilist should l... |
500,748 | <p>I've heard of <a href="http://msdn.microsoft.com/en-us/library/c36yw7x9(VS.80).aspx" rel="nofollow noreferrer"><strong>static_cast operator</strong></a></p>
<p>Recently I've come across <strong>static_case</strong>, for instance:</p>
<pre><code>*ppv = static_case<IUnknown>
</code></pre>
<p>What does this me... | [
{
"answer_id": 500750,
"author": "Nazgob",
"author_id": 3579,
"author_profile": "https://Stackoverflow.com/users/3579",
"pm_score": 0,
"selected": false,
"text": "<p>Its good old C cast with a new C++ syntax similar to other C++ cast like dynamic_cast. The only advantage I know is just b... | 2009/02/01 | [
"https://Stackoverflow.com/questions/500748",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/51078/"
] | I've heard of [**static\_cast operator**](http://msdn.microsoft.com/en-us/library/c36yw7x9(VS.80).aspx)
Recently I've come across **static\_case**, for instance:
```
*ppv = static_case<IUnknown>
```
What does this mean? | It's a typo : **there is no static\_case**, [only static\_cast, dynamic\_cast, const\_cast and reinterpret\_cast](http://www.cplusplus.com/doc/tutorial/typecasting.html).
You can see [on google](http://www.google.fr/search?rlz=1C1GGLS_frFR299FR303&sourceid=chrome&ie=UTF-8&q=c%2B%2B+static_case) that the docs where you... |
500,761 | <p>Does anyone know how to stop a UIWebView from bouncing vertically? I mean when a user touches their iphone screen, drags their finger downwards, and the webview shows a blank spot above the web page I had loaded?</p>
<p>I've looked at the following possible solutions, but none of them worked for me:</p>
<p><a href... | [
{
"answer_id": 503169,
"author": "rpetrich",
"author_id": 4007,
"author_profile": "https://Stackoverflow.com/users/4007",
"pm_score": 0,
"selected": false,
"text": "<p>One of the subviews of <code>UIWebView</code> should be a <code>UIScrollView</code>. Set its <code>scrollEnabled</code> ... | 2009/02/01 | [
"https://Stackoverflow.com/questions/500761",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/26510/"
] | Does anyone know how to stop a UIWebView from bouncing vertically? I mean when a user touches their iphone screen, drags their finger downwards, and the webview shows a blank spot above the web page I had loaded?
I've looked at the following possible solutions, but none of them worked for me:
<http://www.iphonedevsdk... | ```
for (id subview in webView.subviews)
if ([[subview class] isSubclassOfClass: [UIScrollView class]])
((UIScrollView *)subview).bounces = NO;
```
...seems to work fine.
It'll be accepted to App Store as well.
**Update**: in iOS 5.x+ there's an easier way - `UIWebView` has `scrollView` property, so your code... |
500,762 | <p>How can I change values in string from 0,00 to 0.00? - only numeric values, not all chars "," to "."</p>
<p>FROM</p>
<pre><code>string myInputString = "<?xml version=\"1.0\"?>\n<List xmlns:Table=\"urn:www.navision.com/Formats/Table\"><Row><HostelMST>12,0000</HostelMST><PublicMST>... | [
{
"answer_id": 500773,
"author": "flq",
"author_id": 51428,
"author_profile": "https://Stackoverflow.com/users/51428",
"pm_score": 1,
"selected": false,
"text": "<pre><code>string newStr = myInputString.Replace(\"0,00\", \"0.00\");\n</code></pre>\n"
},
{
"answer_id": 500777,
... | 2009/02/01 | [
"https://Stackoverflow.com/questions/500762",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/61186/"
] | How can I change values in string from 0,00 to 0.00? - only numeric values, not all chars "," to "."
FROM
```
string myInputString = "<?xml version=\"1.0\"?>\n<List xmlns:Table=\"urn:www.navision.com/Formats/Table\"><Row><HostelMST>12,0000</HostelMST><PublicMST>0,0000</PublicMST><TaxiMST>0,0000</TaxiMST><ParkMST>0,00... | I strongly recommend joel.neely's regex approach or the one below:
1. Use XmlReader to read all nodes
2. Use double.TryParse with the formatter = a NumberFormatInfo that uses a comma as decimal separator, to identify numbers
3. Use XmlWriter to write a new XML
4. Use CultureInfo.InvariantCulture to write the numbers ... |
500,819 | <p>Don't get me wrong: Boost's <code>bind()</code> is great.</p>
<p>But I do hate to write&read code with it, and I've given up hope my coworkers will ever grok/use it.</p>
<p>I end up with code like this:</p>
<pre><code>btn.clicked.connect(bind(&BetBar::placeBet, this, bet_id));
animator.eachFrame.connect(b... | [
{
"answer_id": 501327,
"author": "gimpf",
"author_id": 15529,
"author_profile": "https://Stackoverflow.com/users/15529",
"pm_score": 2,
"selected": false,
"text": "<p>I doubt you can get any better then this on pre-0x C++. Boost.Lambda or Phoenix provide their own binding mechanisms, but... | 2009/02/01 | [
"https://Stackoverflow.com/questions/500819",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | Don't get me wrong: Boost's `bind()` is great.
But I do hate to write&read code with it, and I've given up hope my coworkers will ever grok/use it.
I end up with code like this:
```
btn.clicked.connect(bind(&BetBar::placeBet, this, bet_id));
animator.eachFrame.connect(bind(&Widget::move, buttons[bet_id]));
```
Whi... | I doubt you can get any better then this on pre-0x C++. Boost.Lambda or Phoenix provide their own binding mechanisms, but for such cases it won't get any more readable, really.
If you could think of how to program such a DSL within the current C++ using boost::proto (are there any other alternatives?), well, then you ... |
500,826 | <p>I have a MySQL table with utf8 general ci collation. In the table, I can see two entries:</p>
<p>abad<br>
abád</p>
<p>I am using a query that looks like this:</p>
<pre><code>SELECT * FROM `words` WHERE `word` = 'abád'
</code></pre>
<p>The query result gives both words:</p>
<p>abad<br>
abád</p>
<p>Is there a w... | [
{
"answer_id": 500841,
"author": "cjk",
"author_id": 52201,
"author_profile": "https://Stackoverflow.com/users/52201",
"pm_score": 0,
"selected": false,
"text": "<pre><code>SELECT * FROM `words` WHERE column = 'abád' collate latin1_General_CS \n</code></pre>\n\n<p>(or your collation inc... | 2009/02/01 | [
"https://Stackoverflow.com/questions/500826",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/61195/"
] | I have a MySQL table with utf8 general ci collation. In the table, I can see two entries:
abad
abád
I am using a query that looks like this:
```
SELECT * FROM `words` WHERE `word` = 'abád'
```
The query result gives both words:
abad
abád
Is there a way to indicate that I only want MySQL to find the accent... | If your searches on that field are always going to be accent-sensitive, then declare the collation of the field as utf8\_bin (that'll compare for equality the utf8-encoded bytes) or use a language specific collation that distinguish between the accented and un-accented characters.
```
col_name varchar(10) collate utf8... |
500,839 | <p>I have had the need to use regular expressions only a few times in the work that I have done. However, in those few times I discovered a very powerful form of expression that would enable me to do some extremely useful things.</p>
<p>The problem is that the language used for regular expressions is wrong - full stop... | [
{
"answer_id": 500865,
"author": "innaM",
"author_id": 7498,
"author_profile": "https://Stackoverflow.com/users/7498",
"pm_score": 3,
"selected": false,
"text": "<p>I never stumbled across something like that. And I don't think that something like that would be useful.</p>\n\n<p>That hig... | 2009/02/01 | [
"https://Stackoverflow.com/questions/500839",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | I have had the need to use regular expressions only a few times in the work that I have done. However, in those few times I discovered a very powerful form of expression that would enable me to do some extremely useful things.
The problem is that the language used for regular expressions is wrong - full stop.
It is w... | **1)** Perl permits the `/x` switch on regular expressions to enable comments and whitespace to be included inside the regex itself. This makes it possible to spread a complex regex over several lines, using indentation to indicate block structure.
**2)** If you don't like the line-noise-resembling symbols themselves,... |
500,863 | <p>I want a textblock that has blue text on a yellow background.
I can set the blue text with the "Foreground" attribute.
But "Background" doesn't work (that would be too easy I guess).</p>
<p>So what is the best way to do this, wrap it in a Rectangle or Canvas that has a background color?</p>
<p>And, is there anythi... | [
{
"answer_id": 500914,
"author": "Steven Robbins",
"author_id": 26507,
"author_profile": "https://Stackoverflow.com/users/26507",
"pm_score": 3,
"selected": false,
"text": "<p>It's not in Silverlight for some reason, although it is in WPF. Just wrap a Border round it (it will resize to t... | 2009/02/01 | [
"https://Stackoverflow.com/questions/500863",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4639/"
] | I want a textblock that has blue text on a yellow background.
I can set the blue text with the "Foreground" attribute.
But "Background" doesn't work (that would be too easy I guess).
So what is the best way to do this, wrap it in a Rectangle or Canvas that has a background color?
And, is there anything we should know... | [TextBlock](http://msdn.microsoft.com/en-us/library/system.windows.controls.textblock(VS.95).aspx) is derived from [FrameworkElement](http://msdn.microsoft.com/en-us/library/system.windows.frameworkelement(VS.95).aspx). [TextBox](http://msdn.microsoft.com/en-us/library/system.windows.controls.textbox(VS.95).aspx) is de... |