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 |
|---|---|---|---|---|---|---|
326,233 | <p>I have a GridView populated from an ObjectDataSource with two items in its DataKeyNames field. One is the primary key, ID, the other is a category field (the category field is used to add header rows to delineate categories).</p>
<p>Displaying works fine, but I'm trying to create a Delete action. The object's del... | [
{
"answer_id": 326274,
"author": "Liwen",
"author_id": 33449,
"author_profile": "https://Stackoverflow.com/users/33449",
"pm_score": 0,
"selected": false,
"text": "<p>When using the default declarative delete method, GridView will pass both values to the ObjectDataSource. </p>\n\n<p>If y... | 2008/11/28 | [
"https://Stackoverflow.com/questions/326233",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7856/"
] | I have a GridView populated from an ObjectDataSource with two items in its DataKeyNames field. One is the primary key, ID, the other is a category field (the category field is used to add header rows to delineate categories).
Displaying works fine, but I'm trying to create a Delete action. The object's delete method o... | All of the DataKey values will always be passed to the Delete method because the fields named by [DataKeyNames](http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.gridview.datakeynames.aspx) are intended to be the field or fields that uniquely identify that item in the GridView. They're often used for mo... |
326,277 | <p>I'm trying to verify that a parameter is an instance of a specific class in Rails:</p>
<pre><code>def schedule(action, *args)
if arg.is_a? Aircraft
...
end
end
</code></pre>
<p>I'm doing this in a library class (the file is in <em>lib/</em>) and I get an <strong>uninitialized constant Aircraft</strong> err... | [
{
"answer_id": 326395,
"author": "Mike Breen",
"author_id": 22346,
"author_profile": "https://Stackoverflow.com/users/22346",
"pm_score": 2,
"selected": false,
"text": "<p>This will give you access to the Aircraft model: </p>\n\n<pre><code>require File.dirname(__FILE__) + \"/../app/mo... | 2008/11/28 | [
"https://Stackoverflow.com/questions/326277",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/341/"
] | I'm trying to verify that a parameter is an instance of a specific class in Rails:
```
def schedule(action, *args)
if arg.is_a? Aircraft
...
end
end
```
I'm doing this in a library class (the file is in *lib/*) and I get an **uninitialized constant Aircraft** error. Aircraft is a model class, with a correspo... | This will give you access to the Aircraft model:
```
require File.dirname(__FILE__) + "/../app/models/aircraft"
```
[edit]
Daniel brings up a good point about the context. If you're using a rake task make sure you load the environment:
```
task :my_task => :environment do
# something happens...
end
``` |
326,309 | <pre><code>abstract class Foo
{
private List<Object> container;
private bool update;
Foo Foo()
{
container = new List<object>();
update = false;
}
public abstract Bar CreateBar();
public void BeginUpdate()
{
if (!update)
{
Thread... | [
{
"answer_id": 326317,
"author": "SoapBox",
"author_id": 36384,
"author_profile": "https://Stackoverflow.com/users/36384",
"pm_score": 1,
"selected": false,
"text": "<p>You can think of lock scope similar to function scope. Doing a lock inside of your accessor method will only lock betw... | 2008/11/28 | [
"https://Stackoverflow.com/questions/326309",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | ```
abstract class Foo
{
private List<Object> container;
private bool update;
Foo Foo()
{
container = new List<object>();
update = false;
}
public abstract Bar CreateBar();
public void BeginUpdate()
{
if (!update)
{
Thread update_thread = ne... | Your code does not do what you think it does. This method
```
public List<Object> Objects
{
get
{
lock (container)
{
return this.container;
}
}
}
```
Does not hold the lock after it has returned the value. So your loop is not locked.
You cannot return the container in... |
326,321 | <p>I am trying to create an expression tree that represents the following:</p>
<pre><code>myObject.childObjectCollection.Any(i => i.Name == "name");
</code></pre>
<p>Shortened for clarity, I have the following:</p>
<pre><code>//'myObject.childObjectCollection' is represented here by 'propertyExp'
//'i => i.Nam... | [
{
"answer_id": 326496,
"author": "Barry Kelly",
"author_id": 3712,
"author_profile": "https://Stackoverflow.com/users/3712",
"pm_score": 7,
"selected": true,
"text": "<p>There are several things wrong with how you're going about it.</p>\n\n<ol>\n<li><p>You're mixing abstraction levels. T... | 2008/11/28 | [
"https://Stackoverflow.com/questions/326321",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/27805/"
] | I am trying to create an expression tree that represents the following:
```
myObject.childObjectCollection.Any(i => i.Name == "name");
```
Shortened for clarity, I have the following:
```
//'myObject.childObjectCollection' is represented here by 'propertyExp'
//'i => i.Name == "name"' is represented here by 'predic... | There are several things wrong with how you're going about it.
1. You're mixing abstraction levels. The T parameter to `GetAnyExpression<T>` could be different to the type parameter used to instantiate `propertyExp.Type`. The T type parameter is one step closer in the abstraction stack to compile time - unless you're ... |
326,335 | <p>Simple case:</p>
<p>i put a DataTable in Cache</p>
<pre><code>DataTable table = SomeClass.GetTable();
Cache["test"] = table;
then in later calls i use
DataTable table = (DataTable)Cache["test"];
</code></pre>
<p>now the question is: should i call table.dispose() on each call, though its stored in the Cache? Mean... | [
{
"answer_id": 326342,
"author": "Steven A. Lowe",
"author_id": 9345,
"author_profile": "https://Stackoverflow.com/users/9345",
"pm_score": 0,
"selected": false,
"text": "<p>i believe that you should only call Dispose once when you are completely done with the datatable; calling Dispose ... | 2008/11/28 | [
"https://Stackoverflow.com/questions/326335",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | Simple case:
i put a DataTable in Cache
```
DataTable table = SomeClass.GetTable();
Cache["test"] = table;
then in later calls i use
DataTable table = (DataTable)Cache["test"];
```
now the question is: should i call table.dispose() on each call, though its stored in the Cache? Means the object is always the same? ... | All you are doing is storing a pointer in cache... The actual "table" is still on the heap, where all .Net reference types are stored... You are not making a copy of it...
The variable in cache just acts to stop the garbage collector from erasing the object on the heap...
and no, you don't want to call dispose until... |
326,350 | <p>I want to do a simple role authentication in .NET - but am lost in the profusion of apis...</p>
<p>I would like to have a web.config per directory with role access like:</p>
<pre><code><authorization>
<allow roles="admin"/>
<deny users="*"/>
</authorization>
</code></pre>
<p>And in... | [
{
"answer_id": 326435,
"author": "Mitchel Sellers",
"author_id": 13279,
"author_profile": "https://Stackoverflow.com/users/13279",
"pm_score": -1,
"selected": false,
"text": "<p>Personally if you are going to use the role management, and user functionality already presented in ASP.NET wh... | 2008/11/28 | [
"https://Stackoverflow.com/questions/326350",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/37955/"
] | I want to do a simple role authentication in .NET - but am lost in the profusion of apis...
I would like to have a web.config per directory with role access like:
```
<authorization>
<allow roles="admin"/>
<deny users="*"/>
</authorization>
```
And in my login page, where I do FormsAuthentication.RedirectFr... | Here is a link on a very simple Forms Authentication implementation with roles. I believe this is the most basic Forms Authentication implementation:
<http://www.codeproject.com/KB/web-security/formsroleauth.aspx>
Here is one on the membership provider:
<http://www.asp.net/learn/moving-to-asp.net-2.0/module-08.aspx>
Y... |
326,352 | <p>I'm using some meta-programming to generate a bunch of methods in ruby like so:</p>
<pre><code>class EmotionalObject
def self.mood( name, *details )
define_method(name) do
# ...
end
end
mood :happy, #...
mood :sad, #...
mood :ebuillent, #...
#...
end
</code></pre>
<p>I know that I can p... | [
{
"answer_id": 326435,
"author": "Mitchel Sellers",
"author_id": 13279,
"author_profile": "https://Stackoverflow.com/users/13279",
"pm_score": -1,
"selected": false,
"text": "<p>Personally if you are going to use the role management, and user functionality already presented in ASP.NET wh... | 2008/11/28 | [
"https://Stackoverflow.com/questions/326352",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9859/"
] | I'm using some meta-programming to generate a bunch of methods in ruby like so:
```
class EmotionalObject
def self.mood( name, *details )
define_method(name) do
# ...
end
end
mood :happy, #...
mood :sad, #...
mood :ebuillent, #...
#...
end
```
I know that I can pass `rdoc` '-A mood' to ge... | Here is a link on a very simple Forms Authentication implementation with roles. I believe this is the most basic Forms Authentication implementation:
<http://www.codeproject.com/KB/web-security/formsroleauth.aspx>
Here is one on the membership provider:
<http://www.asp.net/learn/moving-to-asp.net-2.0/module-08.aspx>
Y... |
326,387 | <p>I'm watching Stephen A Bohlen's excellent <a href="http://www.summerofnhibernate.com/" rel="nofollow noreferrer">Summer of NHibernate</a> series, and have been watching him interact with CodeRush. I've recently installed ReSharper (I'm a ReSharper newbie), and I'm trying to find some of the ReSharper productivity e... | [
{
"answer_id": 326728,
"author": "Mindaugas Mozūras",
"author_id": 26408,
"author_profile": "https://Stackoverflow.com/users/26408",
"pm_score": 4,
"selected": false,
"text": "<p>Resharper offers this capability. If your class implements IDisposable, just hit Alt-Enter:</p>\n\n<p><em>(re... | 2008/11/28 | [
"https://Stackoverflow.com/questions/326387",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7961/"
] | I'm watching Stephen A Bohlen's excellent [Summer of NHibernate](http://www.summerofnhibernate.com/) series, and have been watching him interact with CodeRush. I've recently installed ReSharper (I'm a ReSharper newbie), and I'm trying to find some of the ReSharper productivity equivalents that Stephen is demonstrating ... | Resharper offers this capability. If your class implements IDisposable, just hit Alt-Enter:
*(removed image dead link "Before")*
*(removed image dead link "After")*
You also have to have your cursor on variable name. Like this: [SShot1](http://img204.imageshack.us/img204/3872/sshot1dd8.jpg) [SShot2](http://img99.i... |
326,390 | <p>I've been using the idiom below for some time now. And it seems to be the most wide-spread, at least on the sites I've visited.</p>
<p>Is there a better/different way to read a file into a string in Java?</p>
<pre><code>private String readFile(String file) throws IOException {
BufferedReader reader = new Buffe... | [
{
"answer_id": 326413,
"author": "DaWilli",
"author_id": 33974,
"author_profile": "https://Stackoverflow.com/users/33974",
"pm_score": 9,
"selected": false,
"text": "<p>If you're willing to use an external library, check out <a href=\"https://commons.apache.org/proper/commons-io/\" rel=\... | 2008/11/28 | [
"https://Stackoverflow.com/questions/326390",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20654/"
] | I've been using the idiom below for some time now. And it seems to be the most wide-spread, at least on the sites I've visited.
Is there a better/different way to read a file into a string in Java?
```
private String readFile(String file) throws IOException {
BufferedReader reader = new BufferedReader(new FileRea... | Read all text from a file
-------------------------
Java 11 added the [readString()](https://docs.oracle.com/en/java/javase/11/docs/api/java.base/java/nio/file/Files.html#readString(java.nio.file.Path,java.nio.charset.Charset)) method to read small files as a `String`, preserving line terminators:
```
String content ... |
326,393 | <p>Can someone show me how to fix the width of a column in a datatable with JSF?</p>
<p>My code currently reads:</p>
<pre><code><h:column>
<f:facet name="header">
<h:outputText value="Data Field 1" />
</f:facet>
<h:commandLink id="dataLink" action="#{pc_SearchResultsFrag... | [
{
"answer_id": 326565,
"author": "Grant Wagner",
"author_id": 9254,
"author_profile": "https://Stackoverflow.com/users/9254",
"pm_score": -1,
"selected": true,
"text": "<pre><code><h:column>\n <f:facet name=\"header\">\n <h:outputText value=\"Data Field 1\" />... | 2008/11/28 | [
"https://Stackoverflow.com/questions/326393",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/23249/"
] | Can someone show me how to fix the width of a column in a datatable with JSF?
My code currently reads:
```
<h:column>
<f:facet name="header">
<h:outputText value="Data Field 1" />
</f:facet>
<h:commandLink id="dataLink" action="#{pc_SearchResultsFragment.setField1}">
<h:outputText value="#... | ```
<h:column>
<f:facet name="header">
<h:outputText value="Data Field 1" />
</f:facet>
<h:commandLink id="dataLink" action="#{pc_SearchResultsFragment.setField1}">
<h:outputText value="#{(qi.data1 != null) ? '' : qi.data1}"/>
</h:commandLink>
<%-- <f:attribute n... |
326,396 | <p>I am working with:</p>
<pre><code>#top ul li.corner span.right-corner:hover
{
background-image:url("images/corner-right-over.gif");
width:4px;
height:15px;
float:left;
}
#top ul li.corner span.left-corner:hover
{
background-image:url("images/corner-left-over.gif");
float:left;
width:4px... | [
{
"answer_id": 326415,
"author": "Claudio",
"author_id": 27958,
"author_profile": "https://Stackoverflow.com/users/27958",
"pm_score": 0,
"selected": false,
"text": "<p>As the commenter noted, \"top\" is not a valid selector. It should be \"#top\" or \".top\"</p>\n"
},
{
"answer_... | 2008/11/28 | [
"https://Stackoverflow.com/questions/326396",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | I am working with:
```
#top ul li.corner span.right-corner:hover
{
background-image:url("images/corner-right-over.gif");
width:4px;
height:15px;
float:left;
}
#top ul li.corner span.left-corner:hover
{
background-image:url("images/corner-left-over.gif");
float:left;
width:4px;
height:1... | I believe the problem is that SPAN elements display inline by default - meaning they have no height and width. Try explicitly making them block level elements by adding:
```
#top ul li.corner span.right-corner, #top ul li.corner span.left-corner
{
display: block;
}
``` |
326,405 | <p>I have an abstract base class and derived class:</p>
<pre><code>type TInterfaceMethod = class
public
destructor Destroy; virtual; abstract;
procedure Calculate; virtual; abstract;
procedure PrepareForWork; virtual; abstract;
end;
type ConcreteMethod = class(TInterfaceMethod)
private
matrix: TMin... | [
{
"answer_id": 326456,
"author": "gabr",
"author_id": 4997,
"author_profile": "https://Stackoverflow.com/users/4997",
"pm_score": 3,
"selected": true,
"text": "<p>Override is correct - you are redefining a virtual method.</p>\n\n<p>If you really want TInterfaceMethod's destructor to thro... | 2008/11/28 | [
"https://Stackoverflow.com/questions/326405",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/28298/"
] | I have an abstract base class and derived class:
```
type TInterfaceMethod = class
public
destructor Destroy; virtual; abstract;
procedure Calculate; virtual; abstract;
procedure PrepareForWork; virtual; abstract;
end;
type ConcreteMethod = class(TInterfaceMethod)
private
matrix: TMinMatrix;
publ... | Override is correct - you are redefining a virtual method.
If you really want TInterfaceMethod's destructor to throw EAbstractError, you'll have to mark it as 'override; abstract;'. (I'm surprised that it works, but I tested with D2007 and it does.) But why would you want to do that?
BTW, there is no need to use sepa... |
326,425 | <p>I have a problem with formatting the data when doing an query to an Oracle database.</p>
<p>What I want to do is to export some data into the formatbelow into a textfile;</p>
<pre><code> 1IN20071001 40005601054910101200 1 65
</code></pre>
<ul>
<li>First number (1 above) = Company number (posi... | [
{
"answer_id": 326459,
"author": "hamishmcn",
"author_id": 3590,
"author_profile": "https://Stackoverflow.com/users/3590",
"pm_score": 2,
"selected": false,
"text": "<p>if t.clockindatetime is an oracle DATE then why not use:<br>\n<code>TO_CHAR(t.clockindatetime, 'YYYYMMDD')</code> for t... | 2008/11/28 | [
"https://Stackoverflow.com/questions/326425",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | I have a problem with formatting the data when doing an query to an Oracle database.
What I want to do is to export some data into the formatbelow into a textfile;
```
1IN20071001 40005601054910101200 1 65
```
* First number (1 above) = Company number (position 1-5, blanks infront)
* IN or UT ... | if t.clockindatetime is an oracle DATE then why not use:
`TO_CHAR(t.clockindatetime, 'YYYYMMDD')` for the date part and
`TO_CHAR(t.clockindatetime, 'HHMISS')` for the time part (if you want the hours to be in 24hr format use `TO_CHAR(t.clockindatetime, 'HH24MISS')` (the hours will still only take up 2 characters)) |
326,454 | <p>In this abbreviated code, the inline event works - the "event" is passed to the testKeyPress function </p>
<pre><code><textarea id="source"
onkeydown= "showCursPos(this);
var tf=testKeyPress(event);
document.onkeypress=function(){return tf};
document.onkeydown=function(){return tf}; " ></... | [
{
"answer_id": 326473,
"author": "Dennis C",
"author_id": 40214,
"author_profile": "https://Stackoverflow.com/users/40214",
"pm_score": 3,
"selected": true,
"text": "<p>Yes, there is an event object as arguments.</p>\n\n<p>You can get it by </p>\n\n<pre><code>var e=arguments[0] || event;... | 2008/11/28 | [
"https://Stackoverflow.com/questions/326454",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | In this abbreviated code, the inline event works - the "event" is passed to the testKeyPress function
```
<textarea id="source"
onkeydown= "showCursPos(this);
var tf=testKeyPress(event);
document.onkeypress=function(){return tf};
document.onkeydown=function(){return tf}; " ></textarea>
function test... | Yes, there is an event object as arguments.
You can get it by
```
var e=arguments[0] || event; // Firefox via the argument, but IE don't
```
I don't know if they exact the same, but I read `<xxx onkeydown="func(event);">` as `xxx.ononkeydown=function(event){func(event);};`
Reference [event @ Mozilla.org](https://... |
326,460 | <p>I am looking to make a web control where I can register client startup scripts inline with my aspx because I hate registering in the codebehind!</p>
<p>An example of what I have so far:</p>
<pre><code><Ben:StartupScript runat="server">
var form = document.getElementById("<% =form1.Client... | [
{
"answer_id": 326542,
"author": "Steven A. Lowe",
"author_id": 9345,
"author_profile": "https://Stackoverflow.com/users/9345",
"pm_score": 1,
"selected": false,
"text": "<p>it sounds like a good idea, but if you spend too much time fighting the inherited/default behaviors then it may be... | 2008/11/28 | [
"https://Stackoverflow.com/questions/326460",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | I am looking to make a web control where I can register client startup scripts inline with my aspx because I hate registering in the codebehind!
An example of what I have so far:
```
<Ben:StartupScript runat="server">
var form = document.getElementById("<% =form1.ClientID %>");
</Ben:StartupScript>
```
Curren... | it sounds like a good idea, but if you spend too much time fighting the inherited/default behaviors then it may be more trouble than it's worth
if this is a one-shot issue, a cheap-hack solution is to just directly embed your scripts in the header of a master page ;-)
on the other hand, allowing developers to embed t... |
326,463 | <p>A remote site is supplying a data structure in a js file.</p>
<p>I can include this file in my page to access the data and display it in my page.</p>
<pre><code><head>
<script type="text/javascript" src="http://www.example.co.uk/includes/js/data.js"></script>
</head>
</code></pre>
<p>D... | [
{
"answer_id": 326469,
"author": "Vinko Vrsalovic",
"author_id": 5190,
"author_profile": "https://Stackoverflow.com/users/5190",
"pm_score": 3,
"selected": true,
"text": "<p>You should GET that file directly, via, for example, <a href=\"http://php.net/curl\" rel=\"nofollow noreferrer\">C... | 2008/11/28 | [
"https://Stackoverflow.com/questions/326463",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/33167/"
] | A remote site is supplying a data structure in a js file.
I can include this file in my page to access the data and display it in my page.
```
<head>
<script type="text/javascript" src="http://www.example.co.uk/includes/js/data.js"></script>
</head>
```
Does anyone know how I use PHP to take this data and store... | You should GET that file directly, via, for example, [CURL](http://php.net/curl). Then parse it, if it comes in JSON, you can use [json-decode](http://es.php.net/manual/en/function.json-decode.php).
Simple example (slightly modified version of code found [here](http://es.php.net/manual/en/function.curl-exec.php#87015)... |
326,476 | <p>Given numbers like 499, 73433, 2348 what VBA can I use to round to the nearest 5 or 10? or an arbitrary number?</p>
<p>By 5:</p>
<pre><code> 499 -> 500
2348 -> 2350
7343 -> 7345
</code></pre>
<p>By 10:</p>
<pre><code> 499 -> 500
2348 -> 2350
7343 -> 7340
</code></pre>
<p>etc.</p>
| [
{
"answer_id": 326485,
"author": "Vilx-",
"author_id": 41360,
"author_profile": "https://Stackoverflow.com/users/41360",
"pm_score": 7,
"selected": false,
"text": "<p>It's simple math. Given a number X and a rounding factor N, the formula would be:</p>\n\n<p>round(X / N)*N</p>\n"
},
... | 2008/11/28 | [
"https://Stackoverflow.com/questions/326476",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14420/"
] | Given numbers like 499, 73433, 2348 what VBA can I use to round to the nearest 5 or 10? or an arbitrary number?
By 5:
```
499 -> 500
2348 -> 2350
7343 -> 7345
```
By 10:
```
499 -> 500
2348 -> 2350
7343 -> 7340
```
etc. | **Integrated Answer**
```
X = 1234 'number to round
N = 5 'rounding factor
round(X/N)*N 'result is 1235
```
For floating point to integer, 1234.564 to 1235, (this is VB specific, most other languages simply truncate) do:
```
int(1234.564) 'result is 1235
```
*Beware:* VB uses [Bankers Rounding](http://wiki... |
326,487 | <p>I am working on a program which manipulates images of different sizes. Many of these manipulations read pixel data from an input and write to a separate output (e.g. blur). This is done on a per-pixel basis.</p>
<p>Such image mapulations are very stressful on the CPU. I would like to use multithreading to speed ... | [
{
"answer_id": 326493,
"author": "Johannes Schaub - litb",
"author_id": 34509,
"author_profile": "https://Stackoverflow.com/users/34509",
"pm_score": 3,
"selected": false,
"text": "<p>I would recommend <code>boost::thread</code> and <code>boost::gil</code> (generic image libray). Because... | 2008/11/28 | [
"https://Stackoverflow.com/questions/326487",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/39992/"
] | I am working on a program which manipulates images of different sizes. Many of these manipulations read pixel data from an input and write to a separate output (e.g. blur). This is done on a per-pixel basis.
Such image mapulations are very stressful on the CPU. I would like to use multithreading to speed things up. Ho... | If your compiler supports [OpenMP](http://openmp.org/wp/) (I know [VC++ 8.0 and 9.0](http://msdn.microsoft.com/en-us/library/tt15eb9t(VS.80).aspx) do, as does gcc), it can make things like this much easier to do.
You don't just want to make a lot of threads - there's a point of diminishing returns where adding new th... |
326,558 | <p>If I have srand(2) declared in my main of my driver file,
do I need to declare srand(2) in my code file which is being linked with my driver?</p>
<p>Thanks.</p>
<p><strong>edit</strong></p>
<p>(from user's comment below)</p>
<p>If I do,</p>
<pre><code>srand(2);
srand(2);
</code></pre>
<p>will I get the seed as... | [
{
"answer_id": 326564,
"author": "Eclipse",
"author_id": 8701,
"author_profile": "https://Stackoverflow.com/users/8701",
"pm_score": 1,
"selected": false,
"text": "<p>I think you'll have to clarify your question a bit more, but in general, you have to declare (but not define) every funct... | 2008/11/28 | [
"https://Stackoverflow.com/questions/326558",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | If I have srand(2) declared in my main of my driver file,
do I need to declare srand(2) in my code file which is being linked with my driver?
Thanks.
**edit**
(from user's comment below)
If I do,
```
srand(2);
srand(2);
```
will I get the seed as 2? or something else? | [srand](http://www.cplusplus.com/reference/clibrary/cstdlib/srand.html)(2) sets the seed of the random number generator to 2. Calling it again with the same parameter sets the seed to 2 again, and will cause the random generator to create the same output.
FYI, If the driver uses it's own copy of srand (i.e. it's a DL... |
326,571 | <p>I have a string with a length that is a multiple of 8 that contains only 0's and 1's. I want to convert the string into a byte array suitable for writing to a file. For instance, if I have the string "0010011010011101", I want to get the byte array [0x26, 0x9d], which, when written to file, will give 0x269d as the... | [
{
"answer_id": 326587,
"author": "Greg Hewgill",
"author_id": 893,
"author_profile": "https://Stackoverflow.com/users/893",
"pm_score": 3,
"selected": false,
"text": "<p>You could do something like this:</p>\n\n<pre><code>>>> s = \"0010011010011101\"\n>>> [int(s[x:x+8],... | 2008/11/28 | [
"https://Stackoverflow.com/questions/326571",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5624/"
] | I have a string with a length that is a multiple of 8 that contains only 0's and 1's. I want to convert the string into a byte array suitable for writing to a file. For instance, if I have the string "0010011010011101", I want to get the byte array [0x26, 0x9d], which, when written to file, will give 0x269d as the bina... | ```
py> data = "0010011010011101"
py> data = [data[8*i:8*(i+1)] for i in range(len(data)/8)]
py> data
['00100110', '10011101']
py> data = [int(i, 2) for i in data]
py> data
[38, 157]
py> data = ''.join(chr(i) for i in data)
py> data
'&\x9d'
``` |
326,580 | <p>I am using the following jquery code:</p>
<pre><code>$("#top ul li.corner").mouseover(function(){
$("span.left-corner").addClass("left-corner-hover");
$("span.right-corner").addClass("right-corner-hover");
$("span.content").addClass("content-hover");
}).mouseout(function(){
$("span.left-corner").rem... | [
{
"answer_id": 326587,
"author": "Greg Hewgill",
"author_id": 893,
"author_profile": "https://Stackoverflow.com/users/893",
"pm_score": 3,
"selected": false,
"text": "<p>You could do something like this:</p>\n\n<pre><code>>>> s = \"0010011010011101\"\n>>> [int(s[x:x+8],... | 2008/11/28 | [
"https://Stackoverflow.com/questions/326580",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | I am using the following jquery code:
```
$("#top ul li.corner").mouseover(function(){
$("span.left-corner").addClass("left-corner-hover");
$("span.right-corner").addClass("right-corner-hover");
$("span.content").addClass("content-hover");
}).mouseout(function(){
$("span.left-corner").removeClass("left... | ```
py> data = "0010011010011101"
py> data = [data[8*i:8*(i+1)] for i in range(len(data)/8)]
py> data
['00100110', '10011101']
py> data = [int(i, 2) for i in data]
py> data
[38, 157]
py> data = ''.join(chr(i) for i in data)
py> data
'&\x9d'
``` |
326,596 | <p>I'm writing a global error handling "module" for one of my applications.</p>
<p>One of the features I want to have is to be able to easily wrap a function with a <code>try{} catch{}</code> block, so that all calls to that function will automatically have the error handling code that'll call my global logging method... | [
{
"answer_id": 326693,
"author": "Eugene Lazutkin",
"author_id": 26394,
"author_profile": "https://Stackoverflow.com/users/26394",
"pm_score": 7,
"selected": true,
"text": "<p>Personally instead of polluting builtin objects I would go with a decorator technique:</p>\n\n<pre><code>var mak... | 2008/11/28 | [
"https://Stackoverflow.com/questions/326596",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3314/"
] | I'm writing a global error handling "module" for one of my applications.
One of the features I want to have is to be able to easily wrap a function with a `try{} catch{}` block, so that all calls to that function will automatically have the error handling code that'll call my global logging method. (To avoid polluting... | Personally instead of polluting builtin objects I would go with a decorator technique:
```
var makeSafe = function(fn){
return function(){
try{
return fn.apply(this, arguments);
}catch(ex){
ErrorHandler.Exception(ex);
}
};
};
```
You can use it like that:
```
function fnOriginal(a){
co... |
326,628 | <p>What is prefered way of setting html title (in head) for view when using master pages?</p>
<p>One way is by using Page.Title in .aspx file, but that requires in master page which can mess with HTML code. So, lets assume no server side controls, only pure html. Any better ideas? </p>
<p>UPDATE: I would like to set... | [
{
"answer_id": 326640,
"author": "sliderhouserules",
"author_id": 31385,
"author_profile": "https://Stackoverflow.com/users/31385",
"pm_score": -1,
"selected": false,
"text": "<p>There is a Title property of the @Page directive for content pages.</p>\n"
},
{
"answer_id": 326848,
... | 2008/11/28 | [
"https://Stackoverflow.com/questions/326628",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/28912/"
] | What is prefered way of setting html title (in head) for view when using master pages?
One way is by using Page.Title in .aspx file, but that requires in master page which can mess with HTML code. So, lets assume no server side controls, only pure html. Any better ideas?
UPDATE: I would like to set title in view NOT... | We ended up with
```
<head runat=server visible=false>
```
in master page.
This way we can read from Page.Title (Page.Title requires head element to exist, otherwise it throws an exception, checked that with reflector). We then use our own head element - MVC way. |
326,650 | <p>The line-height property usually takes care of vertical alignment, but not with inputs. Is there a way to automatically center text without playing around with padding?</p>
| [
{
"answer_id": 327509,
"author": "Chris Hawes",
"author_id": 22776,
"author_profile": "https://Stackoverflow.com/users/22776",
"pm_score": 6,
"selected": false,
"text": "<p>I've not tried this myself, but try setting:</p>\n\n<pre><code>height : 36px; //for other browsers\nline-height: 36... | 2008/11/28 | [
"https://Stackoverflow.com/questions/326650",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/29595/"
] | The line-height property usually takes care of vertical alignment, but not with inputs. Is there a way to automatically center text without playing around with padding? | In Opera 9.62, Mozilla 3.0.4, Safari 3.2 (for Windows) it helps, if you put some text or at least a whitespace within the same line as the input field.
```
<div style="line-height: 60px; height: 60px; border: 1px solid black;">
<input type="text" value="foo" />
</div>
```
(imagine an   after the input-... |
326,672 | <p>I'm trying to use System.IO.File.Replace to update a file, and it's throwing System.IOException if the destination file is on a NAS.</p>
<p>According to <a href="http://msdn.microsoft.com/en-us/library/9d9h163f(VS.80).aspx" rel="nofollow noreferrer">MSDN</a>, if the destination file is on a different volume, this m... | [
{
"answer_id": 326681,
"author": "ctacke",
"author_id": 13154,
"author_profile": "https://Stackoverflow.com/users/13154",
"pm_score": 0,
"selected": false,
"text": "<p>If you have a chance that the files will be on separate volumes, it's best to write your own simple copy routine that re... | 2008/11/28 | [
"https://Stackoverflow.com/questions/326672",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/22437/"
] | I'm trying to use System.IO.File.Replace to update a file, and it's throwing System.IOException if the destination file is on a NAS.
According to [MSDN](http://msdn.microsoft.com/en-us/library/9d9h163f(VS.80).aspx), if the destination file is on a different volume, this method throws an exception. It's right, but how ... | You could ensure the replace is always on the same volume by using Copy, then Replace.
Or just catch the error and try it.
```
catch IOException
File.Copy( src,dest+".tmp", true )
File.Replace( dest+".tmp", dest, dest_backup )
``` |
326,679 | <p>I'm writing a bit of code to display a bar (or line) graph in our software. Everything's going fine. The thing that's got me stumped is labeling the Y axis.</p>
<p>The caller can tell me how finely they want the Y scale labeled, but I seem to be stuck on exactly what to label them in an "attractive" kind of way. ... | [
{
"answer_id": 326734,
"author": "Pyrolistical",
"author_id": 21838,
"author_profile": "https://Stackoverflow.com/users/21838",
"pm_score": 3,
"selected": false,
"text": "<p>Sounds like the caller doesn't tell you the ranges it wants.</p>\n\n<p>So you are free to changed the end points u... | 2008/11/28 | [
"https://Stackoverflow.com/questions/326679",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8173/"
] | I'm writing a bit of code to display a bar (or line) graph in our software. Everything's going fine. The thing that's got me stumped is labeling the Y axis.
The caller can tell me how finely they want the Y scale labeled, but I seem to be stuck on exactly what to label them in an "attractive" kind of way. I can't desc... | A long time ago I have written a graph module that covered this nicely. Digging in the grey mass gets the following:
* Determine lower and upper bound of the data. (Beware of the special case where lower bound = upper bound!
* Divide range into the required amount of ticks.
* Round the tick range up into nice amounts.... |
326,757 | <p>I'm trying to update a hashtable in a loop but getting an error: System.InvalidOperationException: Collection was modified; enumeration operation may not execute.</p>
<pre><code>private Hashtable htSettings_m = new Hashtable();
htSettings_m.Add("SizeWidth", "728");
htSettings_m.Add("SizeHeight", "450");
string sKey... | [
{
"answer_id": 326767,
"author": "Rob Walker",
"author_id": 3631,
"author_profile": "https://Stackoverflow.com/users/3631",
"pm_score": 1,
"selected": false,
"text": "<p>You cannot change the set of items stored in a collection while you are enumerating over it, since that makes life ver... | 2008/11/28 | [
"https://Stackoverflow.com/questions/326757",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/28098/"
] | I'm trying to update a hashtable in a loop but getting an error: System.InvalidOperationException: Collection was modified; enumeration operation may not execute.
```
private Hashtable htSettings_m = new Hashtable();
htSettings_m.Add("SizeWidth", "728");
htSettings_m.Add("SizeHeight", "450");
string sKey = "";
string ... | you could read the collection of keys into another IEnumerable instance first, then foreach over that list
```
System.Collections.Hashtable ht = new System.Collections.Hashtable();
ht.Add("test1", "test2");
ht.Add("test3", "test4");
List<string> keys = new List<string>();
fore... |
326,764 | <p>Is there a shortcut for giving a limit and order when accessing a has_many relation in an ActiveRecord model?</p>
<p>For example, here's what I'd like to express:</p>
<pre><code>@user.posts(:limit => 5, :order => "title")
</code></pre>
<p>As opposed to the longer version:</p>
<pre><code>Post.find(:all, :li... | [
{
"answer_id": 326795,
"author": "Dustin",
"author_id": 39975,
"author_profile": "https://Stackoverflow.com/users/39975",
"pm_score": 3,
"selected": false,
"text": "<p>I have something similar in a blog model:</p>\n\n<pre><code> has_many :posts, :class_name => \"BlogPost\", :foreign_... | 2008/11/28 | [
"https://Stackoverflow.com/questions/326764",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19964/"
] | Is there a shortcut for giving a limit and order when accessing a has\_many relation in an ActiveRecord model?
For example, here's what I'd like to express:
```
@user.posts(:limit => 5, :order => "title")
```
As opposed to the longer version:
```
Post.find(:all, :limit => 5, :order => "title", :conditions => ['use... | I have something similar in a blog model:
```
has_many :posts, :class_name => "BlogPost", :foreign_key => "owner_id",
:order => "items.published_at desc", :include => [:creator] do
def recent(limit=3)
find(:all, :limit => limit, :order => "items.published_at desc")
end
end
```
Usage:
```... |
326,770 | <p>I have a python module that defines a number of classes:</p>
<pre><code>class A(object):
def __call__(self):
print "ran a"
class B(object):
def __call__(self):
print "ran b"
class C(object):
def __call__(self):
print "ran c"
</code></pre>
<p>From within the module, how might I... | [
{
"answer_id": 326789,
"author": "Igal Serban",
"author_id": 25737,
"author_profile": "https://Stackoverflow.com/users/25737",
"pm_score": 4,
"selected": true,
"text": "<pre><code>import sys\ngetattr(sys.modules[__name__], 'A')\n</code></pre>\n"
},
{
"answer_id": 326796,
"aut... | 2008/11/28 | [
"https://Stackoverflow.com/questions/326770",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/39975/"
] | I have a python module that defines a number of classes:
```
class A(object):
def __call__(self):
print "ran a"
class B(object):
def __call__(self):
print "ran b"
class C(object):
def __call__(self):
print "ran c"
```
From within the module, how might I add an attribute that giv... | ```
import sys
getattr(sys.modules[__name__], 'A')
``` |
326,778 | <p>OK,</p>
<p>Here is my problem, I have a master page with a HEAD section that contains my JS includes. I have one JS include </p>
<pre><code><script src="Includes/js/browser.js" language="javascript" type="text/javascript"></script>
</code></pre>
<p>In my page i consume it like this:</p>
<pre><code>&... | [
{
"answer_id": 326791,
"author": "Vilx-",
"author_id": 41360,
"author_profile": "https://Stackoverflow.com/users/41360",
"pm_score": 2,
"selected": false,
"text": "<p>As you wish.</p>\n\n<blockquote>\n <p>You just missed something and it's a stupid mistake.</p>\n</blockquote>\n\n<p>:)</... | 2008/11/28 | [
"https://Stackoverflow.com/questions/326778",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/36269/"
] | OK,
Here is my problem, I have a master page with a HEAD section that contains my JS includes. I have one JS include
```
<script src="Includes/js/browser.js" language="javascript" type="text/javascript"></script>
```
In my page i consume it like this:
```
<body>
<form id="form1" runat="server">
<div>
....
<script... | If you can use Firefox, I would highly recommend installing and enabling the Firebug addon.
Otherwise, see some of the following for tools that might help:
* [Javascript troubleshooting tools in IE](https://stackoverflow.com/questions/3404/javascript-troubleshooting-tools-in-ie)
* [Is there any good or reliable way t... |
326,802 | <p>For those who like a good WPF binding challenge:</p>
<p>I have a nearly functional example of two-way binding a <code>CheckBox</code> to an individual bit of a flags enumeration (thanks Ian Oakes, <a href="http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/c05b7e7e-25cd-4a41-8bf5-e35d2caff797/" rel="nofollow ... | [
{
"answer_id": 327273,
"author": "Jobi Joy",
"author_id": 8091,
"author_profile": "https://Stackoverflow.com/users/8091",
"pm_score": 1,
"selected": false,
"text": "<p>Check your DataObject which binds to the CheckBoxes contains Department property has an INotifyPropertyChnaged.PropertyC... | 2008/11/28 | [
"https://Stackoverflow.com/questions/326802",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/41693/"
] | For those who like a good WPF binding challenge:
I have a nearly functional example of two-way binding a `CheckBox` to an individual bit of a flags enumeration (thanks Ian Oakes, [original MSDN post](http://social.msdn.microsoft.com/Forums/en-US/wpf/thread/c05b7e7e-25cd-4a41-8bf5-e35d2caff797/)). The problem though is... | You could use a value converter. Here's a very specific implementation for the target `Enum`, but would not be hard to see how to make the converter more generic:
```
[Flags]
public enum Department
{
None = 0,
A = 1,
B = 2,
C = 4,
D = 8
}
public partial class Window1 : Window
{
public Window1(... |
326,818 | <p>I want to validate a set of credentials against the domain controller. e.g.:</p>
<pre><code>Username: STACKOVERFLOW\joel
Password: splotchy
</code></pre>
<h2>Method 1. Query Active Directory with Impersonation</h2>
<p>A lot of people suggest querying the Active Directory for something. If an exception is thrown, ... | [
{
"answer_id": 327073,
"author": "tvanfosson",
"author_id": 12950,
"author_profile": "https://Stackoverflow.com/users/12950",
"pm_score": 8,
"selected": true,
"text": "<p>C# in .NET 3.5 using <a href=\"http://msdn.microsoft.com/en-us/library/system.directoryservices.accountmanagement.asp... | 2008/11/28 | [
"https://Stackoverflow.com/questions/326818",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12597/"
] | I want to validate a set of credentials against the domain controller. e.g.:
```
Username: STACKOVERFLOW\joel
Password: splotchy
```
Method 1. Query Active Directory with Impersonation
---------------------------------------------------
A lot of people suggest querying the Active Directory for something. If an exce... | C# in .NET 3.5 using [System.DirectoryServices.AccountManagement](http://msdn.microsoft.com/en-us/library/system.directoryservices.accountmanagement.aspx).
```
bool valid = false;
using (PrincipalContext context = new PrincipalContext(ContextType.Domain))
{
valid = context.ValidateCredentials( username, passwo... |
326,820 | <p>I know that you cannot return anonymous types from methods but I am wondering how the Select extension method returns an anonymous type. Is it just a compiler trick?</p>
<p>Edit</p>
<p>Suppose L is a List. How does this work?</p>
<pre><code>L.Select(s => new { Name = s })
</code></pre>
<p>The return type is I... | [
{
"answer_id": 326831,
"author": "Jon Skeet",
"author_id": 22656,
"author_profile": "https://Stackoverflow.com/users/22656",
"pm_score": 3,
"selected": false,
"text": "<p>Well, it's normal type inference for generic method type arguments. For instance:</p>\n\n<pre><code>List<string>... | 2008/11/28 | [
"https://Stackoverflow.com/questions/326820",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3927/"
] | I know that you cannot return anonymous types from methods but I am wondering how the Select extension method returns an anonymous type. Is it just a compiler trick?
Edit
Suppose L is a List. How does this work?
```
L.Select(s => new { Name = s })
```
The return type is IEnumerable<'a> where 'a = new {String Name} | The type is actually defined by *the caller*, so it's in the scope of the calling function - neatly avoiding the issue of "returning" an anonymous type.
This is accomplished by generic type inference. The signature for [Select](http://msdn.microsoft.com/en-us/library/bb548891.aspx) is `Select<Tsource, TResult>(IEnumer... |
326,821 | <p>Everyone in my office uses Macs and therefore most use Safari. </p>
<p>We have a page that has 30 checkboxes on it, I didn't even do the HTML myself but no matter if I use the html input checkbox with a label or an asp:Checkbox usig the text property for the label my boss is irritated because the checkbox is a litt... | [
{
"answer_id": 326837,
"author": "Owen",
"author_id": 4853,
"author_profile": "https://Stackoverflow.com/users/4853",
"pm_score": 3,
"selected": true,
"text": "<p>wow i didn't even really notice the box was slightly lower than the text until you mentioned it. you can work around that in ... | 2008/11/28 | [
"https://Stackoverflow.com/questions/326821",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4140/"
] | Everyone in my office uses Macs and therefore most use Safari.
We have a page that has 30 checkboxes on it, I didn't even do the HTML myself but no matter if I use the html input checkbox with a label or an asp:Checkbox usig the text property for the label my boss is irritated because the checkbox is a little below c... | wow i didn't even really notice the box was slightly lower than the text until you mentioned it. you can work around that in CSS though:
```
label {
vertical-align: bottom;
}
```
aligns the text to the checkboxes for me (Safari 3.2.1) |
326,822 | <p>I want to serialize the following Xml structure:</p>
<pre><code> <XmlRootElement>
<Company name="Acme Widgets LLC">
<DbApplication name="ApplicationA" vendor="oracle">
<ConnSpec environment="DEV"
server="DBOraDev1201"
database... | [
{
"answer_id": 328778,
"author": "Darin Dimitrov",
"author_id": 29407,
"author_profile": "https://Stackoverflow.com/users/29407",
"pm_score": 3,
"selected": true,
"text": "<p>If you are using <a href=\"http://msdn.microsoft.com/en-us/library/system.xml.serialization.xmlserializer.aspx\" ... | 2008/11/28 | [
"https://Stackoverflow.com/questions/326822",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/32632/"
] | I want to serialize the following Xml structure:
```
<XmlRootElement>
<Company name="Acme Widgets LLC">
<DbApplication name="ApplicationA" vendor="oracle">
<ConnSpec environment="DEV"
server="DBOraDev1201"
database="AppA"
userI... | If you are using [XmlSerializer](http://msdn.microsoft.com/en-us/library/system.xml.serialization.xmlserializer.aspx) you need to indicate it how to serialize your collections:
```
public class XmlRootElement
{
[XmlElement(ElementName="Company")]
public Company[] Company { get; set; }
// Other properties ... |
326,825 | <p>How can I pass a variable number of args to a yield.
I don't want to pass an array (as the following code does), I'd actually like to pass them as a programmatic number of args to the block.</p>
<pre><code>def each_with_attributes(attributes, &block)
results[:matches].each_with_index do |match, index|
yie... | [
{
"answer_id": 326836,
"author": "Dustin",
"author_id": 39975,
"author_profile": "https://Stackoverflow.com/users/39975",
"pm_score": 2,
"selected": false,
"text": "<p>Asterisk will expand an array to individual arguments in ruby:</p>\n\n<pre><code>def test(a, b)\n puts \"#{a} + #{b} = ... | 2008/11/28 | [
"https://Stackoverflow.com/questions/326825",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6705/"
] | How can I pass a variable number of args to a yield.
I don't want to pass an array (as the following code does), I'd actually like to pass them as a programmatic number of args to the block.
```
def each_with_attributes(attributes, &block)
results[:matches].each_with_index do |match, index|
yield self[index], at... | Use the splat-operator `*` to turn the array into arguments.
```
block.call(*array)
```
or
```
yield *array
``` |
326,853 | <p>I have an asp.net mvc app running on a local iis website that is failing to send mail using SmtpClient from System.Net.Mail. I am trying to send a mail to my hotmail address and I get a socket exception. Any idea what the problem might be?</p>
<pre><code>using(var message = new MailMessage())
{
... | [
{
"answer_id": 326957,
"author": "Mitchel Sellers",
"author_id": 13279,
"author_profile": "https://Stackoverflow.com/users/13279",
"pm_score": 0,
"selected": false,
"text": "<p>Rather than trying to setup SMTP locally, why don't you just configure the SMTP connection to send directly via... | 2008/11/28 | [
"https://Stackoverflow.com/questions/326853",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15059/"
] | I have an asp.net mvc app running on a local iis website that is failing to send mail using SmtpClient from System.Net.Mail. I am trying to send a mail to my hotmail address and I get a socket exception. Any idea what the problem might be?
```
using(var message = new MailMessage())
{
messag... | Based on your answers to my comments above Joe, you don't have SMTP enabled on your local machine. Vista does not come with SMTP.
As such, you'll either have to install a 3rd party SMTP app that will run on Vista, or use another app to send via, in this case, your Hotmail account may allow you to send outgoing via it... |
326,857 | <p>Problem:</p>
<pre><code>edited files on windows, using git-bash, to fix IE7 problems
committed, pushed to github repo
booted back into linux
pulled from repo
merge conflict in dozens of files
used 'git reset --hard'
</code></pre>
<p>What can I do to get back on track?</p>
<p>UPDATE: please look at the follow... | [
{
"answer_id": 326863,
"author": "Greg Hewgill",
"author_id": 893,
"author_profile": "https://Stackoverflow.com/users/893",
"pm_score": 4,
"selected": true,
"text": "<p>It sounds like you need to set the line ending options in Windows:</p>\n\n<pre><code>git config core.autocrlf true\n</c... | 2008/11/28 | [
"https://Stackoverflow.com/questions/326857",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/33287/"
] | Problem:
```
edited files on windows, using git-bash, to fix IE7 problems
committed, pushed to github repo
booted back into linux
pulled from repo
merge conflict in dozens of files
used 'git reset --hard'
```
What can I do to get back on track?
UPDATE: please look at the following for a clearer picture (no iro... | It sounds like you need to set the line ending options in Windows:
```
git config core.autocrlf true
```
This will convert the line endings from LF to CRLF on Windows and back again on `git add`. Without this, git thinks that you changed the whole file's line endings from LF to CRLF, which is likely to cause merge c... |
326,868 | <p>I'm working with JInternalFrame's under Mac OS X Java 5 and when maximizing a JInternalFrame within a JDesktopPane the window doesn't fully maximize, but the property to allow maximizing is definitely set to true. This is the result I'm getting when maximized:</p>
<p><a href="http://www.kieransenior.co.uk/pics/jin... | [
{
"answer_id": 327432,
"author": "Zarkonnen",
"author_id": 15255,
"author_profile": "https://Stackoverflow.com/users/15255",
"pm_score": 2,
"selected": true,
"text": "<p>Swing may be respecting the fact that you can't fully maximize a window on the Mac. As in, if you maximize a real wind... | 2008/11/28 | [
"https://Stackoverflow.com/questions/326868",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/39693/"
] | I'm working with JInternalFrame's under Mac OS X Java 5 and when maximizing a JInternalFrame within a JDesktopPane the window doesn't fully maximize, but the property to allow maximizing is definitely set to true. This is the result I'm getting when maximized:
[Seeing as though the image previews didn't work.](http://... | Swing may be respecting the fact that you can't fully maximize a window on the Mac. As in, if you maximize a real window, it will simply become big, but not fill the entire screen. The desktop pane may be emulating this behaviour.
You may be able to override this by listening for maximize events and manually setting t... |
326,885 | <p>I want to create the 26 neighbors of a cubic-voxel-node in 3-d space. The inputs are the x,y,z position of the node and the size of the cube side . I am trying to do this using a for loop but haven't managed yet. I am quite newbie in programming please help me.</p>
| [
{
"answer_id": 326889,
"author": "Matt Cruikshank",
"author_id": 8643,
"author_profile": "https://Stackoverflow.com/users/8643",
"pm_score": 3,
"selected": false,
"text": "<pre><code>for (int dz = z - 1; dz <= z + 1; ++dz)\n{\n for (int dy = y - 1; dy <= y + 1; ++dy)\n {\n for... | 2008/11/28 | [
"https://Stackoverflow.com/questions/326885",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/41706/"
] | I want to create the 26 neighbors of a cubic-voxel-node in 3-d space. The inputs are the x,y,z position of the node and the size of the cube side . I am trying to do this using a for loop but haven't managed yet. I am quite newbie in programming please help me. | ```
for (int dz = z - 1; dz <= z + 1; ++dz)
{
for (int dy = y - 1; dy <= y + 1; ++dy)
{
for (int dx = x - 1; dx <= x + 1; ++dx)
{
// all 27
if ((dx != x) || (dy != y) || (dz != z))
{
// just the 26 neighbors
}
}
}
}
``` |
326,891 | <p>Is there an easy way to parse the user's HTTP_ACCEPT_LANGUAGE and set the locale in PHP?</p>
<p>I know the Zend framework has a method to do this, but I'd rather not install the whole framework just to use that one bit of functionality.</p>
<p>The PEAR I18Nv2 package is in beta and hasn't been changed for almost t... | [
{
"answer_id": 327042,
"author": "Kornel",
"author_id": 27009,
"author_profile": "https://Stackoverflow.com/users/27009",
"pm_score": 3,
"selected": true,
"text": "<p>Nice solution is <a href=\"http://php.net/manual/en/locale.acceptfromhttp.php\" rel=\"nofollow noreferrer\">on its way</a... | 2008/11/28 | [
"https://Stackoverflow.com/questions/326891",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/29394/"
] | Is there an easy way to parse the user's HTTP\_ACCEPT\_LANGUAGE and set the locale in PHP?
I know the Zend framework has a method to do this, but I'd rather not install the whole framework just to use that one bit of functionality.
The PEAR I18Nv2 package is in beta and hasn't been changed for almost three years, so ... | Nice solution is [on its way](http://php.net/manual/en/locale.acceptfromhttp.php).
Without that you'll need to parse that header. It's a comma-separated list of semicolon-separated locales and attributes.
It can look like this:
```
en_US, en;q=0.8, fr_CA;q=0.2, *;q=0.1
```
and then try each locale until `setlocale... |
326,905 | <p>I'm using the following code to retrieve a message from the database and then write it out to a html page: </p>
<pre><code>Dim strDSN, cnn, cmd
strDSN = "Driver={SQL Server};" & "Server=(local)\sql2k5;" & ...
set cnn = Server.CreateObject("ADODB.Connection")
cnn.ConnectionString = strDSN
cnn.CursorLocation ... | [
{
"answer_id": 326934,
"author": "Mitchel Sellers",
"author_id": 13279,
"author_profile": "https://Stackoverflow.com/users/13279",
"pm_score": 0,
"selected": false,
"text": "<p>You might try using the <a href=\"http://msdn2.microsoft.com/en-us/library/ms130978.aspx\" rel=\"nofollow noref... | 2008/11/28 | [
"https://Stackoverflow.com/questions/326905",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/80/"
] | I'm using the following code to retrieve a message from the database and then write it out to a html page:
```
Dim strDSN, cnn, cmd
strDSN = "Driver={SQL Server};" & "Server=(local)\sql2k5;" & ...
set cnn = Server.CreateObject("ADODB.Connection")
cnn.ConnectionString = strDSN
cnn.CursorLocation = adUseClient
cnn.Open... | Solution:
Man, this was a weird one. The problem was that the actual ASP file was encoded in ANSI. Apparently this is what encoding is used when the file is passed to the client (kinda makes sense if you remember that an asp file is just a file being passed to the client that is modified slightly by the asp engine). Th... |
326,910 | <p>I come from the Java world, where you can hide variables and functions and then run unit tests against them using reflection. I have used nested functions to hide implementation details of my classes so that only the public API is visible. I am trying to write unit tests against these nested functions to make sure... | [
{
"answer_id": 326912,
"author": "Dustin",
"author_id": 39975,
"author_profile": "https://Stackoverflow.com/users/39975",
"pm_score": 4,
"selected": false,
"text": "<p>inner doesn't exist until outer makes it. You should either move inner up to a toplevel function for testability, or ha... | 2008/11/28 | [
"https://Stackoverflow.com/questions/326910",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5624/"
] | I come from the Java world, where you can hide variables and functions and then run unit tests against them using reflection. I have used nested functions to hide implementation details of my classes so that only the public API is visible. I am trying to write unit tests against these nested functions to make sure that... | The Python convention is to name "private" functions and methods with a leading underscore. When you see a leading underscore, you know not to try and use it.
Remember, [Python is not Java](http://dirtsimple.org/2004/12/python-is-not-java.html). |
326,919 | <p>I have a row of buttons, which all create a pdf file which I want to open in a new tab.
This way the button page stays on top, and the pdf's open to get printed. To prevent clicking a button twice I disable the button, like this (I use python):</p>
<pre><code><input type='submit' value='Factureren' name='submitb... | [
{
"answer_id": 326923,
"author": "netadictos",
"author_id": 31791,
"author_profile": "https://Stackoverflow.com/users/31791",
"pm_score": 3,
"selected": false,
"text": "<p>It is easier to do:</p>\n\n<pre><code> <input type='submit' value='Factureren' name='submitbutton' id='%s' \no... | 2008/11/28 | [
"https://Stackoverflow.com/questions/326919",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/37986/"
] | I have a row of buttons, which all create a pdf file which I want to open in a new tab.
This way the button page stays on top, and the pdf's open to get printed. To prevent clicking a button twice I disable the button, like this (I use python):
```
<input type='submit' value='Factureren' name='submitbutton' id='%s'
on... | It is easy: a disabled submit button do not submit a form in IE. Consider to restructure your code:
* Use a regular button, disable it, and call form.submit() from its handler.
* Do not disable the button in its "onclick", but save it, and do it in form's onsubmit. |
326,937 | <p>I have been using TortoiseSVN, svn, and subclipse and I think I understand the basics, but there's one thing that's been bugging me for a while: Merging introduces unwanted code. Here's the steps.</p>
<p><code>trunk/test.txt@r2</code>. A test file was created with 'A' and a return:</p>
<pre><code>A
[EOF]
</code></... | [
{
"answer_id": 326945,
"author": "orip",
"author_id": 37020,
"author_profile": "https://Stackoverflow.com/users/37020",
"pm_score": 5,
"selected": false,
"text": "<p>Merging only revisions 4,7, and 11-15 with <a href=\"http://www.orcaware.com/svn/wiki/Svnmerge.py\" rel=\"noreferrer\">svn... | 2008/11/29 | [
"https://Stackoverflow.com/questions/326937",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3827/"
] | I have been using TortoiseSVN, svn, and subclipse and I think I understand the basics, but there's one thing that's been bugging me for a while: Merging introduces unwanted code. Here's the steps.
`trunk/test.txt@r2`. A test file was created with 'A' and a return:
```
A
[EOF]
```
`branches/TRY-XX-Foo/test.txt@r3`. ... | The problem is that both svn
```
A
<<<<<<< .working
=======
B (unwanted change)
C (important bug fix)
>>>>>>> .merge-right.r341
```
and TortoiseSVN is treating the situation as 2-way merge. I've heard of the term 3-way merge, so I gave [Beyond Compare](http://www.scootersoftware.com/) a shot. With quick set up with ... |
326,942 | <p>My bash script doesn't work the way I want it to:</p>
<pre><code>#!/bin/bash
total="0"
count="0"
#FILE="$1" This is the easier way
for FILE in $*
do
# Start processing all processable files
while read line
do
if [[ "$line" =~ ^Total ]];
then
tmp=$(echo $line | cut -d':' -f2)... | [
{
"answer_id": 326964,
"author": "Dustin",
"author_id": 39975,
"author_profile": "https://Stackoverflow.com/users/39975",
"pm_score": 1,
"selected": false,
"text": "<p>If you define a function, it'll receive the argument as $1. Why is $1 more valuable to you than $FILE, though?</p>\n\n<... | 2008/11/29 | [
"https://Stackoverflow.com/questions/326942",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/40120/"
] | My bash script doesn't work the way I want it to:
```
#!/bin/bash
total="0"
count="0"
#FILE="$1" This is the easier way
for FILE in $*
do
# Start processing all processable files
while read line
do
if [[ "$line" =~ ^Total ]];
then
tmp=$(echo $line | cut -d':' -f2)
c... | It looks like you are trying to add up the totals from the lines labelled 'Total:' in the files provided. It is always a good idea to state what you're trying to do - as well as how you're trying to do it (see [How to Ask Questions the Smart Way](http://www.catb.org/~esr/faqs/smart-questions.html)).
If so, then you're... |
326,960 | <p>Here's my problem.I have 2 xmlfiles with identical structure, with the second xml containing only few node compared to first.</p>
<p>File1</p>
<pre><code> <root>
<alpha>111</alpha>
<beta>22</beta>
<gamma></gamma>
<delta></delta>
</root>... | [
{
"answer_id": 326963,
"author": "Pyrolistical",
"author_id": 21838,
"author_profile": "https://Stackoverflow.com/users/21838",
"pm_score": 1,
"selected": false,
"text": "<p>This merge seems very specific.</p>\n\n<p>If that is the case, just write some code to load both xml files and app... | 2008/11/29 | [
"https://Stackoverflow.com/questions/326960",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/28773/"
] | Here's my problem.I have 2 xmlfiles with identical structure, with the second xml containing only few node compared to first.
File1
```
<root>
<alpha>111</alpha>
<beta>22</beta>
<gamma></gamma>
<delta></delta>
</root>
```
**File2**
```
<root>
<beta>XX</beta>
<delta>XX</delta>
</root>
... | Here is a little bit simpler and more efficient solution that that proposed by Alastair (see my comment to his solution).
This transformation:
```
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform" >
<xsl:output omit-xml-declaration="yes" indent="yes"/>
<xsl:variable name="vFile2... |
326,987 | <p>I am trying to find out how to use usercontrols in asp.net mvc. I know how to add a usercontrol to a view and how to pass data to it. What I haven't been able to figure out is how do you do this without having to retrieve and pass the data in every single controller?</p>
<p>For example, if I have a user control t... | [
{
"answer_id": 327057,
"author": "tvanfosson",
"author_id": 12950,
"author_profile": "https://Stackoverflow.com/users/12950",
"pm_score": 0,
"selected": false,
"text": "<p>Refactor the code that obtains the view data for this user control into it's own method, maybe even it's own model (... | 2008/11/29 | [
"https://Stackoverflow.com/questions/326987",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/32892/"
] | I am trying to find out how to use usercontrols in asp.net mvc. I know how to add a usercontrol to a view and how to pass data to it. What I haven't been able to figure out is how do you do this without having to retrieve and pass the data in every single controller?
For example, if I have a user control that displays... | There are multiple ways to do it.
The basic approach is
* Populate the data for the view in the BaseController (OnActionExecuting event)
* Writing a custom action filter
* Writing an Application Controller (the eg. is in the below links).
An example of OnActionExecuting will be
```
[HandleError]
public cl... |
326,991 | <p>What's the best way to get a function like the following to work:</p>
<pre><code>def getNearest(zipCode, miles):
</code></pre>
<p>That is, given a zipcode (07024) and a radius, return all zipcodes which are within that radius?</p>
| [
{
"answer_id": 327003,
"author": "Patrick Harrington",
"author_id": 41165,
"author_profile": "https://Stackoverflow.com/users/41165",
"pm_score": 4,
"selected": true,
"text": "<p>There is a project on SourceForge that could assist with this:</p>\n\n<p><a href=\"http://sourceforge.net/pro... | 2008/11/29 | [
"https://Stackoverflow.com/questions/326991",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15055/"
] | What's the best way to get a function like the following to work:
```
def getNearest(zipCode, miles):
```
That is, given a zipcode (07024) and a radius, return all zipcodes which are within that radius? | There is a project on SourceForge that could assist with this:
<http://sourceforge.net/projects/zips/>
It gives you a database with zip codes and their latitude / longitude, as well as coding examples of how to calculate the distance between two sets of coordinates. There is probably a better way to do it, but you co... |
327,002 | <p>I've been wondering this for some time. As the title say, which is faster, the actual function or simply raising to the half power?</p>
<p><b>UPDATE</b></p>
<p>This is not a matter of premature optimization. This is simply a question of how the underlying code actually works. What is the theory of how Python code ... | [
{
"answer_id": 327005,
"author": "strager",
"author_id": 39992,
"author_profile": "https://Stackoverflow.com/users/39992",
"pm_score": 2,
"selected": false,
"text": "<p>Most likely math.sqrt(x), because it's optimized for square rooting.</p>\n\n<p>Benchmarks will provide you the answer y... | 2008/11/29 | [
"https://Stackoverflow.com/questions/327002",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/41718/"
] | I've been wondering this for some time. As the title say, which is faster, the actual function or simply raising to the half power?
**UPDATE**
This is not a matter of premature optimization. This is simply a question of how the underlying code actually works. What is the theory of how Python code works?
I sent Guido... | **`math.sqrt(x)` is significantly faster than `x**0.5`.**
```
import math
N = 1000000
```
```
%%timeit
for i in range(N):
z=i**.5
```
>
> 10 loops, best of 3: 156 ms per loop
>
>
>
```
%%timeit
for i in range(N):
z=math.sqrt(i)
```
>
> 10 loops, best of 3: 91.1 ms per loop
>
>
>
Using Python 3.... |
327,010 | <p>A problem that we need to solve regularly at my workplace is how to build sql statements based on user supplied table/column names. The issue I am trying to address is the commas between column names. </p>
<p>One technique looks something like this.</p>
<pre><code>selectSql = "SELECT ";
for (z = 0; z < colu... | [
{
"answer_id": 327022,
"author": "Jonathan Leffler",
"author_id": 15168,
"author_profile": "https://Stackoverflow.com/users/15168",
"pm_score": 1,
"selected": false,
"text": "<p>The way I build up statements is usually:</p>\n\n<pre><code>pad = \"\"\nstmt = \"SELECT \"\n\nfor (i = 0; i &l... | 2008/11/29 | [
"https://Stackoverflow.com/questions/327010",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7734/"
] | A problem that we need to solve regularly at my workplace is how to build sql statements based on user supplied table/column names. The issue I am trying to address is the commas between column names.
One technique looks something like this.
```
selectSql = "SELECT ";
for (z = 0; z < columns.size(); z++)
{
sel... | In your case it is probably safe to assume that there is at least one column since otherwise there is no point in doing the select. In that case you could do:
```
selectSql = "SELECT ";
selectSql += columns[0]._name;
for (z = 1; z < columns.size(); z++) {
selectSql += ", ";
selectSql += columns[z]._name;
}
se... |
327,026 | <p>I use something like this:
screen.addstr(text, color_pair(1) | A_BOLD), but it doesn't seem to work..
However, A_REVERSE and all others attribute does work! </p>
<p>In fact, I'm trying to print something in white, but the COLOR_WHITE prints it gray.. and after a while of searching, it seems that printing it gray +... | [
{
"answer_id": 327072,
"author": "jfs",
"author_id": 4279,
"author_profile": "https://Stackoverflow.com/users/4279",
"pm_score": 3,
"selected": false,
"text": "<p>Here's an example code (Python 2.6, Linux):</p>\n\n<pre><code>#!/usr/bin/env python\nfrom itertools import cycle\nimport curs... | 2008/11/29 | [
"https://Stackoverflow.com/questions/327026",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/41722/"
] | I use something like this:
screen.addstr(text, color\_pair(1) | A\_BOLD), but it doesn't seem to work..
However, A\_REVERSE and all others attribute does work!
In fact, I'm trying to print something in white, but the COLOR\_WHITE prints it gray.. and after a while of searching, it seems that printing it gray + BOLD ... | Here's an example code (Python 2.6, Linux):
```
#!/usr/bin/env python
from itertools import cycle
import curses, contextlib, time
@contextlib.contextmanager
def curses_screen():
"""Contextmanager's version of curses.wrapper()."""
try:
stdscr=curses.initscr()
curses.noecho()
curses.cbre... |
327,043 | <p>I can find tutorials about mapping textures to polygons specifying vertices etc. but nothing regarding how to apply a texture to a cube (or other stuff) drawn with glut (glutSolidCube).</p>
<p>I am doing something like:</p>
<pre><code>glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, decal);
glTexParameterfv(GL_TEXT... | [
{
"answer_id": 327075,
"author": "strager",
"author_id": 39992,
"author_profile": "https://Stackoverflow.com/users/39992",
"pm_score": 2,
"selected": false,
"text": "<p>According to the <a href=\"http://www.opengl.org/documentation/specs/glut/spec3/node80.html\" rel=\"nofollow noreferrer... | 2008/11/29 | [
"https://Stackoverflow.com/questions/327043",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1311500/"
] | I can find tutorials about mapping textures to polygons specifying vertices etc. but nothing regarding how to apply a texture to a cube (or other stuff) drawn with glut (glutSolidCube).
I am doing something like:
```
glTexEnvfv(GL_TEXTURE_ENV, GL_TEXTURE_ENV_MODE, decal);
glTexParameterfv(GL_TEXTURE_2D, GL_TEXTURE_WR... | No, since `glutSolidCube()` does not generate texture coordinates. Fortunately, though, `glutSolidCube()` is easy to implement yourself and add texture coordinates. Here's the source code to `glutSolidCube()` and associated functions, from [<http://www.opengl.org/resources/libraries/glut/>](http://www.opengl.org/resour... |
327,047 | <p>Recently I've been doing a lot of modal window pop-ups and what not, for which I used jQuery. The method that I used to create the new elements on the page has overwhelmingly been along the lines of: </p>
<pre><code>$("<div></div>");
</code></pre>
<p>However, I'm getting the feeling that this isn't the... | [
{
"answer_id": 327061,
"author": "tvanfosson",
"author_id": 12950,
"author_profile": "https://Stackoverflow.com/users/12950",
"pm_score": 4,
"selected": false,
"text": "<p>I think you're using the best method, though you could optimize it to:</p>\n\n<pre><code> $(\"<div/>\");\n</co... | 2008/11/29 | [
"https://Stackoverflow.com/questions/327047",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/32943/"
] | Recently I've been doing a lot of modal window pop-ups and what not, for which I used jQuery. The method that I used to create the new elements on the page has overwhelmingly been along the lines of:
```
$("<div></div>");
```
However, I'm getting the feeling that this isn't the best or the most efficient method of ... | I use `$(document.createElement('div'));` [Benchmarking shows](http://jsperf.com/jquery-vs-createelement) this technique is the fastest. I speculate this is because jQuery doesn't have to identify it as an element and create the element itself.
You should really run benchmarks with different Javascript engines and wei... |
327,052 | <p>I'm working on a CakePHP 1.2 application. I have a model "User" defined with a few HABTM relationships with other tables through a join table.</p>
<p>I'm now tasked with finding User information based on the data stored in one of these HABTM tables. Unfortunately, when the query executes, my condition is rejected w... | [
{
"answer_id": 327412,
"author": "J Cooper",
"author_id": 38803,
"author_profile": "https://Stackoverflow.com/users/38803",
"pm_score": 0,
"selected": false,
"text": "<p>FWIW, your join tables do appear to be \"oddly named\" insofar as they don't follow the convention described here:</p>... | 2008/11/29 | [
"https://Stackoverflow.com/questions/327052",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | I'm working on a CakePHP 1.2 application. I have a model "User" defined with a few HABTM relationships with other tables through a join table.
I'm now tasked with finding User information based on the data stored in one of these HABTM tables. Unfortunately, when the query executes, my condition is rejected with an err... | Turn your debug level up to 2 and look at the SQL output. Find the query that your code is generating and you'll notice there are several. The ORM layer in CakePHP doesn't join HABTM related tables in the first query. It gets the results from the first select, then separately fetches the HABTM data for each item. Becau... |
327,066 | <p>I have a custom XML schema defined for page display that puts elements on the page by evaluating XML elements on the page. This is currently implemented using the preg regex functions, primarily the excellent preg_replace_callback function, eg:</p>
<pre><code>...
$s = preg_replace_callback("!<field>(.*?)<... | [
{
"answer_id": 327083,
"author": "Klathzazt",
"author_id": 35223,
"author_profile": "https://Stackoverflow.com/users/35223",
"pm_score": 2,
"selected": false,
"text": "<p>You can use XSL to do this - just match the inner patterns first. </p>\n\n<p>Here is a good starting point for learni... | 2008/11/29 | [
"https://Stackoverflow.com/questions/327066",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18393/"
] | I have a custom XML schema defined for page display that puts elements on the page by evaluating XML elements on the page. This is currently implemented using the preg regex functions, primarily the excellent preg\_replace\_callback function, eg:
```
...
$s = preg_replace_callback("!<field>(.*?)</field>!", replace_fie... | PHP's [`XSLTProcessor`](http://de2.php.net/manual/en/class.xsltprocessor.php) class ([ext/xsl](http://de2.php.net/manual/en/book.xsl.php) - PHP 5 includes the XSL extension by default and can be enabled by adding the argument `--with-xsl[=DIR]` to your configure line) is quite sophisticated and allows among other thing... |
327,082 | <p>When deploying the application to the device, the program will quit after a few cycles with the following error:</p>
<pre><code>Program received signal: "EXC_BAD_ACCESS".
</code></pre>
<p>The program runs without any issue on the iPhone simulator, it will also debug and run as long as I step through the instructio... | [
{
"answer_id": 327147,
"author": "Adam Rosenfield",
"author_id": 9530,
"author_profile": "https://Stackoverflow.com/users/9530",
"pm_score": 4,
"selected": false,
"text": "<p>An EXC_BAD_ACCESS signal is the result of passing an invalid pointer to a system call. I got one just earlier to... | 2008/11/29 | [
"https://Stackoverflow.com/questions/327082",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19617/"
] | When deploying the application to the device, the program will quit after a few cycles with the following error:
```
Program received signal: "EXC_BAD_ACCESS".
```
The program runs without any issue on the iPhone simulator, it will also debug and run as long as I step through the instructions one at a time. As soon ... | From your description I suspect the most likely explanation is that you have some error in your memory management. You said you've been working on iPhone development for a few weeks, but not whether you are experienced with Objective C in general. If you've come from another background it can take a little while before... |
327,095 | <p>Say I have a controller with an Index Method and a Update Method. After the Update is done I want to redirect to Index(). Should I use return RedirectToAction("Index") or can I just call return Index()? Is there a difference?</p>
<pre><code>public ActionResult Index()
{
return View("Index", viewdata);
}
public A... | [
{
"answer_id": 327108,
"author": "tvanfosson",
"author_id": 12950,
"author_profile": "https://Stackoverflow.com/users/12950",
"pm_score": 6,
"selected": true,
"text": "<p>Use the redirect otherwise the URL on the client will remain the same as the posted URL instead of the URL that corre... | 2008/11/29 | [
"https://Stackoverflow.com/questions/327095",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/29519/"
] | Say I have a controller with an Index Method and a Update Method. After the Update is done I want to redirect to Index(). Should I use return RedirectToAction("Index") or can I just call return Index()? Is there a difference?
```
public ActionResult Index()
{
return View("Index", viewdata);
}
public ActionResult Up... | Use the redirect otherwise the URL on the client will remain the same as the posted URL instead of the URL that corresponds to the Index action. |
327,100 | <p>I have been attempting to create a new directory for my apache server. As I tried to access the new directory, I type:</p>
<p>sudo /etc/init.d/apache2 restart</p>
<p>But I obtain this error in the Ubuntu Terminal:</p>
<p>Syntax Error on line 1 of /etc/apache2/conf.d/fqdn.save:
ServerName takes one argument, the H... | [
{
"answer_id": 327117,
"author": "Gustavo Rubio",
"author_id": 14533,
"author_profile": "https://Stackoverflow.com/users/14533",
"pm_score": 0,
"selected": false,
"text": "<p>You need to be inside the group that has permissons to write that file and that would be probably apache and root... | 2008/11/29 | [
"https://Stackoverflow.com/questions/327100",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | I have been attempting to create a new directory for my apache server. As I tried to access the new directory, I type:
sudo /etc/init.d/apache2 restart
But I obtain this error in the Ubuntu Terminal:
Syntax Error on line 1 of /etc/apache2/conf.d/fqdn.save:
ServerName takes one argument, the Hostname and port of the ... | You've got sudo; I'm going to assume that's the standard Ubuntu "blanket" sudo that lets you do anything.
Check out what's in the file by doing:
```
sudo cat /etc/apache2/conf.d/fqdn.save
```
Make a backup of the file, just in case:
```
sudo cp /etc/apache2/conf.d/fqdn.save /tmp
```
Remove the file:
```
sudo rm... |
327,105 | <p>Given </p>
<pre><code>@interface Canvas:NSView {
NSNumber * currentToolType;
...
}
</code></pre>
<p>declared in my .h file
and in the .m file</p>
<pre><code>- (id)initWithFrame:(NSRect)frame {
self = [super initWithFrame:frame];
if (self) {
currentToolType=[[NSNumber alloc]initWit... | [
{
"answer_id": 327110,
"author": "Jim Puls",
"author_id": 6010,
"author_profile": "https://Stackoverflow.com/users/6010",
"pm_score": 0,
"selected": false,
"text": "<p>You've probably run in to a special case: NSNumber could have cached instances to represent commonly-used numbers.</p>\n... | 2008/11/29 | [
"https://Stackoverflow.com/questions/327105",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | Given
```
@interface Canvas:NSView {
NSNumber * currentToolType;
...
}
```
declared in my .h file
and in the .m file
```
- (id)initWithFrame:(NSRect)frame {
self = [super initWithFrame:frame];
if (self) {
currentToolType=[[NSNumber alloc]initWithInt:1];
}
return self;
}
``... | You mention that initWithFrame: is called twice. Your initWithFrame: should only be called once (unless you happen to have two Canvas views).
Is it possible you have the Canvas view in your nib/xib file and are also creating another in code (with alloc/initWithFrame:)?
In which case you have two Canvas objects. You ... |
327,122 | <p>Using Morph Labs' Appspace to deploy a site means no automated way to redirect 'myapp.com' to 'www.myapp.com' (and no access to .htacess).</p>
<p>Is there an in-rails way to do this? Would I need a plugin like <a href="http://github.com/mbleigh/subdomain-fu/tree/master" rel="nofollow noreferrer">subdomain-fu</a>?</... | [
{
"answer_id": 327127,
"author": "Stepan Mazurov",
"author_id": 40786,
"author_profile": "https://Stackoverflow.com/users/40786",
"pm_score": 0,
"selected": false,
"text": "<p>Here is a couple of different ways:</p>\n\n<pre><code> head :moved_permanently, :location => ‘http://www.newd... | 2008/11/29 | [
"https://Stackoverflow.com/questions/327122",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19527/"
] | Using Morph Labs' Appspace to deploy a site means no automated way to redirect 'myapp.com' to 'www.myapp.com' (and no access to .htacess).
Is there an in-rails way to do this? Would I need a plugin like [subdomain-fu](http://github.com/mbleigh/subdomain-fu/tree/master)?
More specifically, I'm trying to do something l... | Maybe something like this would do the trick:
```
class ApplicationController < ActionController::Base
before_filter :check_uri
def check_uri
redirect_to request.protocol + "www." + request.host_with_port + request.request_uri if !/^www/.match(request.host)
end
end
``` |
327,151 | <p>I have an ASP.NET page that uses a repeater nested within another repeater to generate a listing of data. It's to the effect of the following:</p>
<pre><code><asp:Repeater>
<ItemTemplate>
<span><%#Eval("Data1") %></span>
<!-- and many more -->
<asp:... | [
{
"answer_id": 327153,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 0,
"selected": false,
"text": "<p>When you get your LINQ query executed, check its Count property (providing its a list of some sort). If its 0, then just tu... | 2008/11/29 | [
"https://Stackoverflow.com/questions/327151",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11912/"
] | I have an ASP.NET page that uses a repeater nested within another repeater to generate a listing of data. It's to the effect of the following:
```
<asp:Repeater>
<ItemTemplate>
<span><%#Eval("Data1") %></span>
<!-- and many more -->
<asp:Repeater DataSource='<%#Eval("Data2")%>'>
... | This won't **hide** the repeater completely, but you can subclass the Repeater control so that it includes a GridView-like empty data template:
```
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
public class EmptyCapableRepeater : Repeater
{
public ITemplate EmptyDataTemplate { get; set; }
... |
327,162 | <p>I have been trying to encrypt soap message and send to the server, so that the server can decrypt, process the message, encrypt the response again and send back to the client...</p>
<p>I short i want to implement security in ASMX web services....</p>
<p>Please help me</p>
<p>Thanks
Sandeep</p>
| [
{
"answer_id": 327166,
"author": "Roger Lipscombe",
"author_id": 8446,
"author_profile": "https://Stackoverflow.com/users/8446",
"pm_score": 2,
"selected": false,
"text": "<p>What's wrong with using HTTPS?</p>\n"
},
{
"answer_id": 327167,
"author": "Steven A. Lowe",
"auth... | 2008/11/29 | [
"https://Stackoverflow.com/questions/327162",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/41740/"
] | I have been trying to encrypt soap message and send to the server, so that the server can decrypt, process the message, encrypt the response again and send back to the client...
I short i want to implement security in ASMX web services....
Please help me
Thanks
Sandeep | https and soap extensions are good solutions; you can always 'roll your own' by encryting the inputs and outputs directly
```
[WebMethod]
public string SecureMethodX(string secureInput)
{
string plainText = decrypt(secureInput);
//do something...
string encryptedResult = encrypt(someResult);
return enc... |
327,191 | <p>The list <code>sort()</code> method is a modifier function that returns <code>None</code>.</p>
<p>So if I want to iterate through all of the keys in a dictionary I cannot do:</p>
<pre><code>for k in somedictionary.keys().sort():
dosomething()
</code></pre>
<p>Instead, I must:</p>
<pre><code>keys = somedictio... | [
{
"answer_id": 327195,
"author": "Hugh",
"author_id": 31060,
"author_profile": "https://Stackoverflow.com/users/31060",
"pm_score": 3,
"selected": false,
"text": "<p>Can I answer my own question?</p>\n\n<p>I have just discovered the handy function \"sorted\" which does exactly what I was... | 2008/11/29 | [
"https://Stackoverflow.com/questions/327191",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/31060/"
] | The list `sort()` method is a modifier function that returns `None`.
So if I want to iterate through all of the keys in a dictionary I cannot do:
```
for k in somedictionary.keys().sort():
dosomething()
```
Instead, I must:
```
keys = somedictionary.keys()
keys.sort()
for k in keys:
dosomething()
```
Is ... | ```
for k in sorted(somedictionary.keys()):
doSomething(k)
```
Note that you can also get all of the keys and values sorted by keys like this:
```
for k, v in sorted(somedictionary.iteritems()):
doSomething(k, v)
``` |
327,216 | <p><a href="http://thedailywtf.com/Articles/nice_num,-mean_programmer.aspx" rel="nofollow noreferrer">The Daily WTF</a> for 2008-11-28 pillories the following code:</p>
<pre><code>static char *nice_num(long n)
{
int neg = 0, d = 3;
char *buffer = prtbuf;
int bufsize = 20;
if (n < 0)
{
n... | [
{
"answer_id": 327240,
"author": "Adam Rosenfield",
"author_id": 9530,
"author_profile": "https://Stackoverflow.com/users/9530",
"pm_score": 5,
"selected": true,
"text": "<p>If you're a seasoned C programmer, you'll realize this code isn't actually that bad. It's relatively straightforw... | 2008/11/29 | [
"https://Stackoverflow.com/questions/327216",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15168/"
] | [The Daily WTF](http://thedailywtf.com/Articles/nice_num,-mean_programmer.aspx) for 2008-11-28 pillories the following code:
```
static char *nice_num(long n)
{
int neg = 0, d = 3;
char *buffer = prtbuf;
int bufsize = 20;
if (n < 0)
{
neg = 1;
n = -n;
}
buffer += bufsize;
... | If you're a seasoned C programmer, you'll realize this code isn't actually that bad. It's relatively straightforward (for C), and it's blazingly fast. It has three problems:
1. It fails on the edge case of LONG\_MIN (-2,147,483,648), since negating this number produces itself in twos-complement
* It assumes 32-bit in... |
327,223 | <p>In one of my current side projects, I am scanning through some text looking at the frequency of word triplets. In my first go at it, I used the default dictionary three levels deep. In other words, <code>topDict[word1][word2][word3]</code> returns the number of times these words appear in the text, <code>topDict[w... | [
{
"answer_id": 327254,
"author": "user39307",
"author_id": 39307,
"author_profile": "https://Stackoverflow.com/users/39307",
"pm_score": 1,
"selected": false,
"text": "<p>You could try to use same dictionary, only one level deep.</p>\n\n<pre><code>topDictionary[word1+delimiter+word2+deli... | 2008/11/29 | [
"https://Stackoverflow.com/questions/327223",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/121/"
] | In one of my current side projects, I am scanning through some text looking at the frequency of word triplets. In my first go at it, I used the default dictionary three levels deep. In other words, `topDict[word1][word2][word3]` returns the number of times these words appear in the text, `topDict[word1][word2]` returns... | Some measurements. I took 10MB of free e-book text and computed trigram frequencies, producing a 24MB file. Storing it in different simple Python data structures took this much space in kB, measured as RSS from running ps, where d is a dict, keys and freqs are lists, and a,b,c,freq are the fields of a trigram record:
... |
327,231 | <p>i am trying to find the best way to display results on my page via an Ajax call using jQuery, do you think the best way is to pass it as JSON or plain text? I have worked with ajax calls before, but not sure which is preferred over the other and for the JSON version what is the best way to read from a JSON file gene... | [
{
"answer_id": 327276,
"author": "braindead",
"author_id": 38636,
"author_profile": "https://Stackoverflow.com/users/38636",
"pm_score": 4,
"selected": false,
"text": "<p>JQuery has an inbuilt json data type for Ajax and converts the data into a object. PHP% also has inbuilt json_encode ... | 2008/11/29 | [
"https://Stackoverflow.com/questions/327231",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | i am trying to find the best way to display results on my page via an Ajax call using jQuery, do you think the best way is to pass it as JSON or plain text? I have worked with ajax calls before, but not sure which is preferred over the other and for the JSON version what is the best way to read from a JSON file generat... | Something like this:
```
$.getJSON("http://mywebsite.com/json/get.php?cid=15",
function(data){
$.each(data.products, function(i,product){
content = '<p>' + product.product_title + '</p>';
content += '<p>' + product.product_short_description + '</p>';
content += '<i... |
327,249 | <p>I'm thinking of asking my students to use git for pair programming. Because student work has to be secret, a public repo is out of the question. Instead, each student will have a private repo they maintain themselves, and they will need to exchange patches using git-format-patch. I've read the man page but I'm a ... | [
{
"answer_id": 327258,
"author": "Dustin",
"author_id": 39975,
"author_profile": "https://Stackoverflow.com/users/39975",
"pm_score": 5,
"selected": true,
"text": "<p>It works best if they can see each other's git repos. git itself is managed this way (there's a public repo people can r... | 2008/11/29 | [
"https://Stackoverflow.com/questions/327249",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/41661/"
] | I'm thinking of asking my students to use git for pair programming. Because student work has to be secret, a public repo is out of the question. Instead, each student will have a private repo they maintain themselves, and they will need to exchange patches using git-format-patch. I've read the man page but I'm a little... | It works best if they can see each other's git repos. git itself is managed this way (there's a public repo people can reference, and then they format-patch from there). If people *never* see each other's repos, things are a bit more difficult...
One thing they may do is maintain a reference to the last time they did ... |
327,251 | <p>The documentation of the Python <a href="http://www.python.org/doc/2.5.2/lib/module-readline.html" rel="noreferrer"><code>readline</code></a> module says "Availability: Unix". However, it doesn't appear to be available on OS X, although other modules marked as Unix are available. Here is what I'm using:</p>
<pre>
$... | [
{
"answer_id": 327262,
"author": "Dustin",
"author_id": 39975,
"author_profile": "https://Stackoverflow.com/users/39975",
"pm_score": 2,
"selected": false,
"text": "<p>It's not shipped in OS X because of licensing issues (restrictions brought to you by the GPL).</p>\n\n<p>Macports python... | 2008/11/29 | [
"https://Stackoverflow.com/questions/327251",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/893/"
] | The documentation of the Python [`readline`](http://www.python.org/doc/2.5.2/lib/module-readline.html) module says "Availability: Unix". However, it doesn't appear to be available on OS X, although other modules marked as Unix are available. Here is what I'm using:
```
$ uname -a
Darwin greg.local 8.11.1 Darwin Kerne... | Have you tried to install the `py-readline` (or `py25-readline` for Python 2.5) port?
Also, in the snippet above, you are NOT using the MacPort python, but rather the Apple Python.
The MacPort version should be located in the `/opt/local` directory structure. You should check your path. |
327,274 | <p>How would you write a prepared MySQL statement in PHP that takes a differing number of arguments each time? An example such query is:</p>
<pre class="lang-sql prettyprint-override"><code>SELECT `age`, `name` FROM `people` WHERE id IN (12, 45, 65, 33)
</code></pre>
<p>The <code>IN</code> clause will have a differen... | [
{
"answer_id": 327384,
"author": "Zoredache",
"author_id": 20267,
"author_profile": "https://Stackoverflow.com/users/20267",
"pm_score": 6,
"selected": true,
"text": "<p>I can think of a couple solutions.</p>\n\n<p>One solution might be to create a temporary table. Do an insert into the... | 2008/11/29 | [
"https://Stackoverflow.com/questions/327274",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/41757/"
] | How would you write a prepared MySQL statement in PHP that takes a differing number of arguments each time? An example such query is:
```sql
SELECT `age`, `name` FROM `people` WHERE id IN (12, 45, 65, 33)
```
The `IN` clause will have a different number of `id`s each time it is run.
I have two possible solutions in... | I can think of a couple solutions.
One solution might be to create a temporary table. Do an insert into the table for each parameter that you would have in the in clause. Then do a simple join against your temporary table.
Another method might be to do something like this.
```
$dbh=new PDO($dbConnect, $dbUser, $dbPa... |
327,286 | <p>I have a huge dictionary of blank values in a variable called current like so:</p>
<pre><code>struct movieuser {blah blah blah}
Dictionary<movieuser, float> questions = new Dictionary<movieuser, float>();
</code></pre>
<p>So I am looping through this dictionary and need to fill in the "answers", like s... | [
{
"answer_id": 327291,
"author": "Matt Campbell",
"author_id": 41110,
"author_profile": "https://Stackoverflow.com/users/41110",
"pm_score": 2,
"selected": false,
"text": "<p>Is there any reason you can't just populate the dictionary with both keys and values at the same time?</p>\n\n<pr... | 2008/11/29 | [
"https://Stackoverflow.com/questions/327286",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2504/"
] | I have a huge dictionary of blank values in a variable called current like so:
```
struct movieuser {blah blah blah}
Dictionary<movieuser, float> questions = new Dictionary<movieuser, float>();
```
So I am looping through this dictionary and need to fill in the "answers", like so:
```
for(var k = questions.Keys.Get... | Matt's answer, getting the keys first, separately is the right way to go. Yes, there'll be some redundancy - but it will work. I'd take a working program which is easy to debug and maintain over an efficient program which either won't work or is hard to maintain any day.
Don't forget that if you make `MovieUser` a re... |
327,310 | <p>In Visual c# Express Edition, is it possible to make some (but not all) items in a ListBox bold? I can't find any sort of option for this in the API.</p>
| [
{
"answer_id": 327320,
"author": "Mindaugas Mozūras",
"author_id": 26408,
"author_profile": "https://Stackoverflow.com/users/26408",
"pm_score": 6,
"selected": true,
"text": "<p>You need to change listbox's DrawMode to DrawMode.OwnerDrawFixed. Check out these articles on msdn:<br>\n<a hr... | 2008/11/29 | [
"https://Stackoverflow.com/questions/327310",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13877/"
] | In Visual c# Express Edition, is it possible to make some (but not all) items in a ListBox bold? I can't find any sort of option for this in the API. | You need to change listbox's DrawMode to DrawMode.OwnerDrawFixed. Check out these articles on msdn:
[DrawMode Enumeration](http://msdn.microsoft.com/en-us/library/system.windows.forms.drawmode.aspx)
[ListBox.DrawItem Event](http://msdn.microsoft.com/en-us/library/system.windows.forms.listbox.drawitem.aspx)
[Gr... |
327,311 | <p>Does anyone know how the built in dictionary type for python is implemented? My understanding is that it is some sort of hash table, but I haven't been able to find any sort of definitive answer.</p>
| [
{
"answer_id": 2996689,
"author": "u0b34a0f6ae",
"author_id": 137317,
"author_profile": "https://Stackoverflow.com/users/137317",
"pm_score": 6,
"selected": false,
"text": "<p>Python Dictionaries use <a href=\"http://en.wikipedia.org/wiki/Hash_table#Open_addressing\" rel=\"noreferrer\">O... | 2008/11/29 | [
"https://Stackoverflow.com/questions/327311",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/121/"
] | Does anyone know how the built in dictionary type for python is implemented? My understanding is that it is some sort of hash table, but I haven't been able to find any sort of definitive answer. | Here is everything about Python dicts that I was able to put together (probably more than anyone would like to know; but the answer is comprehensive).
* Python dictionaries are implemented as **hash tables**.
* Hash tables must allow for **hash collisions** i.e. even if two distinct keys have the same hash value, the ... |
327,314 | <p>Say we have a TestClass with the 2 methods, <code>-getSomeString</code> and <code>-getAnotherString</code>, and we are editing the following code and the cursor is in the location shown:</p>
<pre><code>NSString *aString = [TestClass get<cursorIsHere>SomeString];
</code></pre>
<p>Say I want to change it to us... | [
{
"answer_id": 371801,
"author": "adam",
"author_id": 33604,
"author_profile": "https://Stackoverflow.com/users/33604",
"pm_score": 0,
"selected": false,
"text": "<p>I don't think so. I have always used the following</p>\n\n<ul>\n<li>double click on getSomeString</li>\n<li>press Escape (... | 2008/11/29 | [
"https://Stackoverflow.com/questions/327314",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/36510/"
] | Say we have a TestClass with the 2 methods, `-getSomeString` and `-getAnotherString`, and we are editing the following code and the cursor is in the location shown:
```
NSString *aString = [TestClass get<cursorIsHere>SomeString];
```
Say I want to change it to use `-getAnotherString`. If I bring up the auto-completi... | I don't think that there is a one step operation to achieve this. My suggestion would be similar to Thomas Templemann, but rather than two steps of forward word select and then Delete, I would expand to the desired autocomplete, by bouncing on **Control + .** and then hit **Option + forward delete**, which kills to the... |
327,324 | <p>I'm using Junit 4.4 and Ant 1.7. If a test case fails with an error (for example because a method threw an unexpected exception) I don't get any details about what the error was.</p>
<p>My build.xml looks like this:</p>
<pre><code><target name="test" depends="compile">
<junit printsummary="withOutAndErr"... | [
{
"answer_id": 327334,
"author": "user41762",
"author_id": 41762,
"author_profile": "https://Stackoverflow.com/users/41762",
"pm_score": 5,
"selected": false,
"text": "<p>Figured it out :)</p>\n\n<p>I needed to add a \"formatter\" inside the junit block.</p>\n\n<pre><code><formatter t... | 2008/11/29 | [
"https://Stackoverflow.com/questions/327324",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/41762/"
] | I'm using Junit 4.4 and Ant 1.7. If a test case fails with an error (for example because a method threw an unexpected exception) I don't get any details about what the error was.
My build.xml looks like this:
```
<target name="test" depends="compile">
<junit printsummary="withOutAndErr" filtertrace="no" fork="yes" ha... | Figured it out :)
I needed to add a "formatter" inside the junit block.
```
<formatter type="plain" usefile="false" />
```
What a PITA.
-Dan |
327,326 | <p>I have a problem redrawing a custom view in simple cocoa application. Drawing is based on one parameter that is being changed by a simple NSSlider. However, although i implement -setParameter: and -parameter methods and bind slider's value to that parameter in interface builder i cannot seem to make a custom view to... | [
{
"answer_id": 327338,
"author": "e.James",
"author_id": 33686,
"author_profile": "https://Stackoverflow.com/users/33686",
"pm_score": 4,
"selected": true,
"text": "<p>The usual syntax is: <code>[self setNeedsDisplay:YES]</code>, although I would assume that that means the same thing. Ar... | 2008/11/29 | [
"https://Stackoverflow.com/questions/327326",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/41761/"
] | I have a problem redrawing a custom view in simple cocoa application. Drawing is based on one parameter that is being changed by a simple NSSlider. However, although i implement -setParameter: and -parameter methods and bind slider's value to that parameter in interface builder i cannot seem to make a custom view to re... | The usual syntax is: `[self setNeedsDisplay:YES]`, although I would assume that that means the same thing. Are you implementing the `- (void)drawRect:(NSRect)rect` method, or using the `drawRect:` method of your superclass? |
327,337 | <pre><code>mysql> desc categories;
+-------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| name | varchar(80) | YE... | [
{
"answer_id": 327574,
"author": "François Beausoleil",
"author_id": 7355,
"author_profile": "https://Stackoverflow.com/users/7355",
"pm_score": 2,
"selected": false,
"text": "<pre><code>Expense.find(:all,\n :select => \"categories.name name, sum(amount) total_amount\",\n :joins =&g... | 2008/11/29 | [
"https://Stackoverflow.com/questions/327337",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1695/"
] | ```
mysql> desc categories;
+-------+-------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+----------------+
| id | int(11) | NO | PRI | NULL | auto_increment |
| name | varchar(80) | YES | |... | ```
Expense.find(:all,
:select => "categories.name name, sum(amount) total_amount",
:joins => "categories on category_id = categories.id",
:group => "category_id",
:order => "total_amount desc")
```
Hope that helps! |
327,366 | <p>I have two tables with the same columns, and I need to copy one table's rows to the other table's rows to create one big table with all the values from both tables. Right now I am doing this query to return the same thing:</p>
<pre><code>SELECT col1, col2, col3 from Table1
union
SELECT col1, col2, col3 from Table2... | [
{
"answer_id": 327369,
"author": "Tommy",
"author_id": 1270,
"author_profile": "https://Stackoverflow.com/users/1270",
"pm_score": 5,
"selected": true,
"text": "<p>May it work to just do:</p>\n\n<pre><code>SELECT col1, col2, col3 \nINTO Table1\nFROM Table2 \n</code></pre>\n"
},
{
... | 2008/11/29 | [
"https://Stackoverflow.com/questions/327366",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2504/"
] | I have two tables with the same columns, and I need to copy one table's rows to the other table's rows to create one big table with all the values from both tables. Right now I am doing this query to return the same thing:
```
SELECT col1, col2, col3 from Table1
union
SELECT col1, col2, col3 from Table2
```
However,... | May it work to just do:
```
SELECT col1, col2, col3
INTO Table1
FROM Table2
``` |
327,401 | <p>What is the difference between <code>find-grep</code> and <code>grep-find</code> in Emacs?</p>
| [
{
"answer_id": 327405,
"author": "Andrew Cox",
"author_id": 27907,
"author_profile": "https://Stackoverflow.com/users/27907",
"pm_score": 3,
"selected": false,
"text": "<p>They seem the same. See <a href=\"http://www.impernix.org/Manuals/emacs/Grep-Searching.html\" rel=\"nofollow norefe... | 2008/11/29 | [
"https://Stackoverflow.com/questions/327401",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6068/"
] | What is the difference between `find-grep` and `grep-find` in Emacs? | You can use `M-x describe-function` (or `C-h f` with default keybindings) to answer this question, here's the output for `find-grep`:
```
find-grep is an alias for `grep-find' in `progmodes/grep.el'.
(find-grep COMMAND-ARGS)
...
``` |
327,404 | <p>I'm attempting to write a couple of NAnt tasks for interacting with Microsoft Virtual Server 2005 R2 SP1, and I've lifted the code found on "Virtual PC Guy's WebLog", in the <a href="http://blogs.msdn.com/virtual_pc_guy/archive/2006/06/13/630165.aspx" rel="nofollow noreferrer">"Controlling Virtual Server through Pow... | [
{
"answer_id": 327405,
"author": "Andrew Cox",
"author_id": 27907,
"author_profile": "https://Stackoverflow.com/users/27907",
"pm_score": 3,
"selected": false,
"text": "<p>They seem the same. See <a href=\"http://www.impernix.org/Manuals/emacs/Grep-Searching.html\" rel=\"nofollow norefe... | 2008/11/29 | [
"https://Stackoverflow.com/questions/327404",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8446/"
] | I'm attempting to write a couple of NAnt tasks for interacting with Microsoft Virtual Server 2005 R2 SP1, and I've lifted the code found on "Virtual PC Guy's WebLog", in the ["Controlling Virtual Server through PowerShell"](http://blogs.msdn.com/virtual_pc_guy/archive/2006/06/13/630165.aspx) post.
It doesn't work: I a... | You can use `M-x describe-function` (or `C-h f` with default keybindings) to answer this question, here's the output for `find-grep`:
```
find-grep is an alias for `grep-find' in `progmodes/grep.el'.
(find-grep COMMAND-ARGS)
...
``` |
327,408 | <p>I'm trying to run dot net console application via Java:</p>
<pre><code>process = Runtime.getRuntime().exec(commandLine);
</code></pre>
<p>I get the following output:</p>
<pre><code>Detecting
The handle is invalid.
</code></pre>
<p>when running it directly via the console (windows) there is no problem:</p>
<pre>... | [
{
"answer_id": 327428,
"author": "Marc Gravell",
"author_id": 23354,
"author_profile": "https://Stackoverflow.com/users/23354",
"pm_score": 0,
"selected": false,
"text": "<p>Hard to diagnose without more detail - perhaps permissions... a little bit of exception handling (perhaps writing ... | 2008/11/29 | [
"https://Stackoverflow.com/questions/327408",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | I'm trying to run dot net console application via Java:
```
process = Runtime.getRuntime().exec(commandLine);
```
I get the following output:
```
Detecting
The handle is invalid.
```
when running it directly via the console (windows) there is no problem:
```
Detecting
100%
Done.
100%
```
I'm running more appli... | The console application is trying to set the cursor position for a console. This isn't possible, since there is in fact no console. All operations which don't result in a simple read or write are likely to cause errors when there is no console (since most of them require a console output buffer to work).
It is a bad i... |
327,411 | <p>I've tried <a href="http://www.vim.org/scripts/script.php?script_id=159" rel="noreferrer">MiniBufExplorer</a>, but I usually end up with several windows showing it or close it altogether. What I'd like is something like <a href="http://www.vim.org/scripts/script.php?script_id=2050" rel="noreferrer">LustyJuggler</a> ... | [
{
"answer_id": 327416,
"author": "Eimantas",
"author_id": 41761,
"author_profile": "https://Stackoverflow.com/users/41761",
"pm_score": 0,
"selected": false,
"text": "<p>i use simple :vsplit with ^W+w/^W+r and :tabnew with Ctrl+Alt+PgUp/PgDown key combinations.</p>\n"
},
{
"answe... | 2008/11/29 | [
"https://Stackoverflow.com/questions/327411",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9204/"
] | I've tried [MiniBufExplorer](http://www.vim.org/scripts/script.php?script_id=159), but I usually end up with several windows showing it or close it altogether. What I'd like is something like [LustyJuggler](http://www.vim.org/scripts/script.php?script_id=2050) with incremental search, the way I switch between buffers i... | I have been using Wincent Colaiuta's [Command-T vim plugin](https://wincent.com/products/command-t/) for a couple months now. Wincent wrote the parts of it that need to be fast in C, and I must say that it is! And, I think its file pattern matching logic is even better than Textmate's Command-T. Check out the [screenca... |
327,415 | <p>Using Windows key as Meta is very useful in Emacs, is there the way to do it in Vim?</p>
| [
{
"answer_id": 327435,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 0,
"selected": false,
"text": "<p>Not quite sure, but the <kbd>Ctrl</kbd>+<kbd>Esc</kbd> key combo is a windows only key mapping. It won't help with vim</p>... | 2008/11/29 | [
"https://Stackoverflow.com/questions/327415",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9204/"
] | Using Windows key as Meta is very useful in Emacs, is there the way to do it in Vim? | You can use [AutoHotkey to map](http://www.autohotkey.com/docs/misc/Remap.htm) the windows key to a different key. Only activate the mapping when vim is active:
```
#IfWinActive ahk_class GVIM
RWin::Alt
LWin::Alt
#IfWinActive ; This puts subsequent remappings and hotkeys in effect for all windows.
``` |
327,417 | <p>How would I go about this?</p>
<p>I have a mostly static site, which is being hosted on a cheap web-host, which only allows FTP access to the hosting. The site is tracked in git. I am using OS X.</p>
<p>I would like to upload a new version of the site by simply doing <code>cap deploy</code></p>
| [
{
"answer_id": 327441,
"author": "Peter Coulton",
"author_id": 117,
"author_profile": "https://Stackoverflow.com/users/117",
"pm_score": 5,
"selected": true,
"text": "<p>We use capistrano to deploy our site which is written in PHP.</p>\n\n<p>From memory (I'm not at work right now) we ove... | 2008/11/29 | [
"https://Stackoverflow.com/questions/327417",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/745/"
] | How would I go about this?
I have a mostly static site, which is being hosted on a cheap web-host, which only allows FTP access to the hosting. The site is tracked in git. I am using OS X.
I would like to upload a new version of the site by simply doing `cap deploy` | We use capistrano to deploy our site which is written in PHP.
From memory (I'm not at work right now) we overload deploy and used rsync to sync over sftp. Something like this:
```rb
desc "Sync"
namespace :deploy do
desc "Sync remote by default"
task :default do
remote.default
end
namespace :remote do
... |
327,429 | <p>I doing a function in Javascript like the VisualBasic DateDiff.</p>
<p>You give two dates and the returning time interval (Seconds, Minutes, Days, etc...)</p>
<pre><code>DateDiff(ByVal Interval As Microsoft.VisualBasic.DateInterval, _
ByVal Date1 As Date, ByVal Date2 As Date) as Long
</code></pre>
<p>So what's ... | [
{
"answer_id": 327433,
"author": "VonC",
"author_id": 6309,
"author_profile": "https://Stackoverflow.com/users/6309",
"pm_score": 3,
"selected": false,
"text": "<p>If you follow this <a href=\"http://www.javascriptkit.com/javatutors/datedifference.shtml\" rel=\"nofollow noreferrer\">tuto... | 2008/11/29 | [
"https://Stackoverflow.com/questions/327429",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/41385/"
] | I doing a function in Javascript like the VisualBasic DateDiff.
You give two dates and the returning time interval (Seconds, Minutes, Days, etc...)
```
DateDiff(ByVal Interval As Microsoft.VisualBasic.DateInterval, _
ByVal Date1 As Date, ByVal Date2 As Date) as Long
```
So what's the best way to calculate the dif... | Use the [Date object](http://w3schools.com/jsref/jsref_obj_date.asp) like so:
```
function DateDiff(var /*Date*/ date1, var /*Date*/ date2) {
return date1.getTime() - date2.getTime();
}
```
This will return the number of milliseconds difference between the two dates. Converting it to seconds, minutes, hours etc.... |
327,438 | <p>I'm writing a service that has five different methods that can take between 5 seconds and 5 minutes to run.</p>
<p>The service will schedule these different methods to run at different intervals.</p>
<p>I don't want any of the methods to run concurrently, so how do I have the methods check to see if another method... | [
{
"answer_id": 327442,
"author": "Anand",
"author_id": 12649,
"author_profile": "https://Stackoverflow.com/users/12649",
"pm_score": 1,
"selected": false,
"text": "<p>If you are using java, you can make the methods <a href=\"http://java.sun.com/docs/books/tutorial/essential/concurrency/s... | 2008/11/29 | [
"https://Stackoverflow.com/questions/327438",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/366/"
] | I'm writing a service that has five different methods that can take between 5 seconds and 5 minutes to run.
The service will schedule these different methods to run at different intervals.
I don't want any of the methods to run concurrently, so how do I have the methods check to see if another method is running and q... | If you want *simple*, and all the methods are in the same class, ou can just use `[MethodImpl]`:
```
[MethodImpl(MethodImplOptions.Synchronized)]
public void Foo() {...}
[MethodImpl(MethodImplOptions.Synchronized)]
public void Bar() {...}
```
For instance methods, this locks on `this`; for static methods, this lock... |
327,454 | <p>I need to have some information about the Scoping issue in Javascript. I know that it spports lexical(static) scoping, but, does not it support dynamic scoping as well?
If you know anything about the scoping in Javascript, would you please share them with me ?</p>
<p>Thanks</p>
| [
{
"answer_id": 327485,
"author": "Piotr Lesnicki",
"author_id": 38796,
"author_profile": "https://Stackoverflow.com/users/38796",
"pm_score": 4,
"selected": true,
"text": "<p>I think you're confused because Javascript uses static scoping but at function-level, not at block level like usu... | 2008/11/29 | [
"https://Stackoverflow.com/questions/327454",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/41777/"
] | I need to have some information about the Scoping issue in Javascript. I know that it spports lexical(static) scoping, but, does not it support dynamic scoping as well?
If you know anything about the scoping in Javascript, would you please share them with me ?
Thanks | I think you're confused because Javascript uses static scoping but at function-level, not at block level like usual structured languages.
```
var foo = "old";
if (true) {var foo = "new";}
alert (foo == "new")
```
So be careful, blocks don't make scope!
That's why you sometimes see loops with functions inside just to... |
327,476 | <p>Here is the problem, I have written an event loop to detect keydown and keyup events. The problem I am running into is that a keydown event is generating a keydown and a keyup event when the key is pressed and held down. I am using the arrow keys to move an object and then to stop moving when the key is released(k... | [
{
"answer_id": 327462,
"author": "Jon Skeet",
"author_id": 22656,
"author_profile": "https://Stackoverflow.com/users/22656",
"pm_score": 4,
"selected": true,
"text": "<p>Heck no - logging is <em>incredibly</em> important for web applications. If you log appropriately, it makes troublesho... | 2008/11/29 | [
"https://Stackoverflow.com/questions/327476",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | Here is the problem, I have written an event loop to detect keydown and keyup events. The problem I am running into is that a keydown event is generating a keydown and a keyup event when the key is pressed and held down. I am using the arrow keys to move an object and then to stop moving when the key is released(keyup)... | Heck no - logging is *incredibly* important for web applications. If you log appropriately, it makes troubleshooting *so* much easier.
Log4Net is probably a good bet as a framework. You might also want a way of gathering logs together from multiple servers - and even if you don't use more than one server at the moment... |
327,483 | <p>I'm trying to do the following in python:</p>
<p>In a file called foo.py:</p>
<pre><code># simple function that does something:
def myFunction(a,b,c):
print "call to myFunction:",a,b,c
# class used to store some data:
class data:
fn = None
# assign function to the class for storage.
data.fn = myFunction
</co... | [
{
"answer_id": 327488,
"author": "André",
"author_id": 9683,
"author_profile": "https://Stackoverflow.com/users/9683",
"pm_score": 6,
"selected": true,
"text": "<pre><code>data.fn = staticmethod(myFunction)\n</code></pre>\n\n<p>should do the trick.</p>\n"
},
{
"answer_id": 327530... | 2008/11/29 | [
"https://Stackoverflow.com/questions/327483",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1304/"
] | I'm trying to do the following in python:
In a file called foo.py:
```
# simple function that does something:
def myFunction(a,b,c):
print "call to myFunction:",a,b,c
# class used to store some data:
class data:
fn = None
# assign function to the class for storage.
data.fn = myFunction
```
And then in a file ... | ```
data.fn = staticmethod(myFunction)
```
should do the trick. |
327,486 | <p>I need to stop the execution Is there any procedures for using terminate and suspend activity</p>
| [
{
"answer_id": 355468,
"author": "Binoj Antony",
"author_id": 33015,
"author_profile": "https://Stackoverflow.com/users/33015",
"pm_score": 2,
"selected": false,
"text": "<p>This sample at the microsoft website should help you with the suspend and terminate Activity</p>\n\n<p><a href=\"h... | 2008/11/29 | [
"https://Stackoverflow.com/questions/327486",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/22162/"
] | I need to stop the execution Is there any procedures for using terminate and suspend activity | It depends exactly what you want to do. There is a Terminate Activity will terminate the workflow instance that is running and has reached that activity. Once terminated, that workflow instance will be dead and will never be restartable.
Suspend is something you can call on a WorkflowInstance e.g.
```
WorkflowInstanc... |
327,487 | <p>i have problem i want to </p>
<p>select name_magazine from magazine</p>
<p>and i already import all library needed</p>
<p>and </p>
<blockquote>
<p>Query q = EntityManger.createQuery ("SELECT name_magazine FROM Magazine");</p>
<p>List results = (List) q.getResultList ();</p>
<p>For(Sting s : result)</... | [
{
"answer_id": 327497,
"author": "Vincent Ramdhanie",
"author_id": 27439,
"author_profile": "https://Stackoverflow.com/users/27439",
"pm_score": 2,
"selected": false,
"text": "<p>You probably should say what the error is exactly.</p>\n\n<p>However, assuming that you have an entity Magazi... | 2008/11/29 | [
"https://Stackoverflow.com/questions/327487",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/41780/"
] | i have problem i want to
select name\_magazine from magazine
and i already import all library needed
and
>
> Query q = EntityManger.createQuery ("SELECT name\_magazine FROM Magazine");
>
>
> List results = (List) q.getResultList ();
>
>
> For(Sting s : result)
>
>
> System.out.println(s);
>
>
>
but whe... | You probably should say what the error is exactly.
However, assuming that you have an entity Magazine then the query should be:
```
select m from Magazine m
```
If you want all magazines. |
327,500 | <p>I have a file with n lines. (n above 100 millions)</p>
<p>I want to output a file with only 1 of 10 lines, I can't split the file in ten part and keep only one part, as it must be a little more random. later I have to do a statistical analysis I can't afford to create a strong bias in the data).</p>
<p>I was think... | [
{
"answer_id": 327510,
"author": "The Archetypal Paul",
"author_id": 21755,
"author_profile": "https://Stackoverflow.com/users/21755",
"pm_score": 4,
"selected": true,
"text": "<p>Ok, I think I've cracked it:</p>\n\n<pre><code>findstr/N . path-to-log-file | findstr ^[0-9]*0:\n</code></pr... | 2008/11/29 | [
"https://Stackoverflow.com/questions/327500",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/24334/"
] | I have a file with n lines. (n above 100 millions)
I want to output a file with only 1 of 10 lines, I can't split the file in ten part and keep only one part, as it must be a little more random. later I have to do a statistical analysis I can't afford to create a strong bias in the data).
I was thinking of reading th... | Ok, I think I've cracked it:
```
findstr/N . path-to-log-file | findstr ^[0-9]*0:
```
(use findstr to add the line number to the beginning of the line, then again to print only lines with a line number ending in zero)
So you'll get one line in 10, but with the linenumber and colon prepended to each line
If I can t... |
327,506 | <p>I've a HTML page with several Div's that will show the time difference between now and each given date.</p>
<pre><code><div class="dated" onEvent="calculateHTML(this, 'Sat Jun 09 2007 17:46:21')">
30 Minutes Ago</div>
</code></pre>
<p>I want that time difference to be dynamic (calculated to all element... | [
{
"answer_id": 327515,
"author": "HUAGHAGUAH",
"author_id": 27233,
"author_profile": "https://Stackoverflow.com/users/27233",
"pm_score": 2,
"selected": true,
"text": "<p>Using innerHTML works most (all?) of the time and may frequently be faster than generating a bunch of HTML (i.e. not ... | 2008/11/29 | [
"https://Stackoverflow.com/questions/327506",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/41385/"
] | I've a HTML page with several Div's that will show the time difference between now and each given date.
```
<div class="dated" onEvent="calculateHTML(this, 'Sat Jun 09 2007 17:46:21')">
30 Minutes Ago</div>
```
I want that time difference to be dynamic (calculated to all elements when the page loads and also within ... | Using innerHTML works most (all?) of the time and may frequently be faster than generating a bunch of HTML (i.e. not in this case).
I always prefer using standard methods as shown below, because I know they should never break. [Note that I don't check the 'class' attribute directly, since an element may have multiple ... |
327,512 | <p>I've created a login submit form in HTML but for some reason user/password autocompletion does not work like I expect in firefox.</p>
<p>This is what happens in Firefox:</p>
<ul>
<li>I give username and password and click on the login button</li>
<li>Firefox prompts me if I would like to remember the password. I p... | [
{
"answer_id": 327514,
"author": "Pim Jager",
"author_id": 35197,
"author_profile": "https://Stackoverflow.com/users/35197",
"pm_score": 1,
"selected": false,
"text": "<p>Are the urls static or dynamic, auto completion doesn't work with dynamic urls,\n say your url is:</p>\n\n<pre>\nhttp... | 2008/11/29 | [
"https://Stackoverflow.com/questions/327512",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/40323/"
] | I've created a login submit form in HTML but for some reason user/password autocompletion does not work like I expect in firefox.
This is what happens in Firefox:
* I give username and password and click on the login button
* Firefox prompts me if I would like to remember the password. I press 'remember' and login wo... | I found out why it doesn't work. I use ajax to paste the example html in a container div. Apperently firefox is very sensitive about this because (as mentioned before) my code does work in IE. |
327,525 | <p>I would like to show some links only to authenticated users in an asp.net mvc web application.</p>
<ul>
<li>I use the template for an asp.net mvc web application in Visual Studio 2008 that came with the beta release of asp.net mvc.</li>
<li>I use forms authentication.</li>
<li>I would like to add something like the... | [
{
"answer_id": 327539,
"author": "tvanfosson",
"author_id": 12950,
"author_profile": "https://Stackoverflow.com/users/12950",
"pm_score": 3,
"selected": true,
"text": "<p>The following should work. You'll also need to do something similar in the controller action for this in case the us... | 2008/11/29 | [
"https://Stackoverflow.com/questions/327525",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/41094/"
] | I would like to show some links only to authenticated users in an asp.net mvc web application.
* I use the template for an asp.net mvc web application in Visual Studio 2008 that came with the beta release of asp.net mvc.
* I use forms authentication.
* I would like to add something like the following to an existing vi... | The following should work. You'll also need to do something similar in the controller action for this in case the user inputs the URL by hand in their browser. Or, as you say, you could restrict access to the action in the web.config.
```
<% if (HttpContext.Current.Request.IsAuthenticated) { %>
<a href="/Account/... |
327,531 | <p>i made another post</p>
<p><a href="https://stackoverflow.com/questions/326885/a-loop-to-create-neighbor-nodes-in-3d-space">here</a> where I asked how to create the 26 neighbors of a cubic-voxel-node in 3-d space. I got a very good answer and implemented it. </p>
<p>To that I added some MIN MAX Position checking.<... | [
{
"answer_id": 327547,
"author": "Johannes Schaub - litb",
"author_id": 34509,
"author_profile": "https://Stackoverflow.com/users/34509",
"pm_score": 2,
"selected": false,
"text": "<ul>\n<li><p>From a language point of view, you can improve performance by reserving 26 (or 27 depending on... | 2008/11/29 | [
"https://Stackoverflow.com/questions/327531",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/41706/"
] | i made another post
[here](https://stackoverflow.com/questions/326885/a-loop-to-create-neighbor-nodes-in-3d-space) where I asked how to create the 26 neighbors of a cubic-voxel-node in 3-d space. I got a very good answer and implemented it.
To that I added some MIN MAX Position checking.
I would like to know if the... | First, get rid of the if statements. There's no need for them. You can merge them into the loop condition. Second, avoid recomputing the loop condition every iteration. Yes, the compiler may optimize it away, but it's generally very conservative with floating-point optimizations (and it may treat fp values read from me... |
327,534 | <p>I have a list of data that looks like the following:</p>
<pre><code>// timestep,x_position,y_position
0,4,7
0,2,7
0,9,5
0,6,7
1,2,5
1,4,7
1,9,0
1,6,8
</code></pre>
<p>... and I want to make this look like:</p>
<pre><code>0, (4,7), (2,7), (9,5), (6,7)
1, (2,5), (4,7), (9,0), (6.8)
</code></pre>
<p>My plan was to ... | [
{
"answer_id": 327548,
"author": "S.Lott",
"author_id": 10661,
"author_profile": "https://Stackoverflow.com/users/10661",
"pm_score": 7,
"selected": true,
"text": "<p>Let's look at</p>\n\n<pre><code>d[t].append(c)\n</code></pre>\n\n<p>What is the value of <code>d[t]</code>? Try it.</p>\... | 2008/11/29 | [
"https://Stackoverflow.com/questions/327534",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/41121/"
] | I have a list of data that looks like the following:
```
// timestep,x_position,y_position
0,4,7
0,2,7
0,9,5
0,6,7
1,2,5
1,4,7
1,9,0
1,6,8
```
... and I want to make this look like:
```
0, (4,7), (2,7), (9,5), (6,7)
1, (2,5), (4,7), (9,0), (6.8)
```
My plan was to use a dictionary, where the value of t is the key... | Let's look at
```
d[t].append(c)
```
What is the value of `d[t]`? Try it.
```
d = {}
t = 0
d[t]
```
What do you get? Oh. There's nothing in `d` that has a key of `t`.
Now try this.
```
d[t] = []
d[t]
```
Ahh. Now there's something in `d` with a key of `t`.
There are several things you can do.
1. Use exampl... |
327,544 | <p>In my program I have one array with 25 double values 0.04
When I try to sum these values in a loop I get following results:</p>
<pre><code>0.0 + 0.04 = 0.04
0.04 + 0.04 = 0.08
0.08 + 0.04 = 0.12
0.12 + 0.04 = 0.16
0.16 + 0.04 = 0.2
0.2 + 0.04 = 0.24000000000000002
0.24000000000000002 + 0.04 = 0.28
0.28 + 0.04 = 0.3... | [
{
"answer_id": 327551,
"author": "Barry Kelly",
"author_id": 3712,
"author_profile": "https://Stackoverflow.com/users/3712",
"pm_score": 6,
"selected": true,
"text": "<p>The most common storage for floating-point values in programming languages - <a href=\"http://en.wikipedia.org/wiki/IE... | 2008/11/29 | [
"https://Stackoverflow.com/questions/327544",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/35594/"
] | In my program I have one array with 25 double values 0.04
When I try to sum these values in a loop I get following results:
```
0.0 + 0.04 = 0.04
0.04 + 0.04 = 0.08
0.08 + 0.04 = 0.12
0.12 + 0.04 = 0.16
0.16 + 0.04 = 0.2
0.2 + 0.04 = 0.24000000000000002
0.24000000000000002 + 0.04 = 0.28
0.28 + 0.04 = 0.32
0.32 + 0.04 ... | The most common storage for floating-point values in programming languages - [IEEE singles and doubles](http://en.wikipedia.org/wiki/IEEE_754) - does not have exact representations for most decimal fractions.
The reason is that they store values in binary floating-point format, rather than decimal floating-point forma... |
327,562 | <p>I use codes below to see a result like picture 1, but a result like picture 2 is coming. What should be done to solve it?</p>
<p>aspx code:</p>
<pre><code><asp:datalist id="dtlUrun" runat="server" RepeatDirection="Horizontal">
<ItemTemplate>
<table class="dtlTable">
... | [
{
"answer_id": 327577,
"author": "Mitchel Sellers",
"author_id": 13279,
"author_profile": "https://Stackoverflow.com/users/13279",
"pm_score": 2,
"selected": false,
"text": "<p>From what I can tell in the code the first datalist is bound with the two header items, then inside that you ha... | 2008/11/29 | [
"https://Stackoverflow.com/questions/327562",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/439507/"
] | I use codes below to see a result like picture 1, but a result like picture 2 is coming. What should be done to solve it?
aspx code:
```
<asp:datalist id="dtlUrun" runat="server" RepeatDirection="Horizontal">
<ItemTemplate>
<table class="dtlTable">
<tr>
... | From what I can tell in the code the first datalist is bound with the two header items, then inside that you have the individual elements. Your template creates a table for each section, but by default tables are going to be block level elements. My guess is that you could fix that with CSS, but I'd have to check. I pe... |
327,573 | <p>If I have a function that needs to work with a <code>shared_ptr</code>, wouldn't it be more efficient to pass it a reference to it (so to avoid copying the <code>shared_ptr</code> object)?
What are the possible bad side effects?
I envision two possible cases:</p>
<p>1) inside the function a copy is made of the argu... | [
{
"answer_id": 327581,
"author": "Johannes Schaub - litb",
"author_id": 34509,
"author_profile": "https://Stackoverflow.com/users/34509",
"pm_score": 4,
"selected": false,
"text": "<p>Yes, taking a reference is fine there. You don't intend to give the method shared ownership; it only wan... | 2008/11/29 | [
"https://Stackoverflow.com/questions/327573",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/41789/"
] | If I have a function that needs to work with a `shared_ptr`, wouldn't it be more efficient to pass it a reference to it (so to avoid copying the `shared_ptr` object)?
What are the possible bad side effects?
I envision two possible cases:
1) inside the function a copy is made of the argument, like in
```
ClassA::take_... | The point of a distinct `shared_ptr` instance is to guarantee (as far as possible) that as long as this `shared_ptr` is in scope, the object it points to will still exist, because its reference count will be at least 1.
```
Class::only_work_with_sp(boost::shared_ptr<foo> sp)
{
// sp points to an object that cannot... |