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 |
|---|---|---|---|---|---|---|
443,152 | <p>I have a class with some methods. It's supersekret but I've reproduced what I can here.</p>
<pre><code>Class RayGun
# flashes red light
# requires confirmation
# makes "zowowowowowow" sound
def stun!
# ...
end
# flashes blue light
# does not require confirmation
# makes "trrrtrtrtrrtrtrtrtrtrtr... | [
{
"answer_id": 443784,
"author": "krusty.ar",
"author_id": 43981,
"author_profile": "https://Stackoverflow.com/users/43981",
"pm_score": 2,
"selected": false,
"text": "<p>Just a little beautyfication:</p>\n\n<pre><code>class RayGun\n cattr_accessor :metadata\n def self.register_method(... | 2009/01/14 | [
"https://Stackoverflow.com/questions/443152",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9474/"
] | I have a class with some methods. It's supersekret but I've reproduced what I can here.
```
Class RayGun
# flashes red light
# requires confirmation
# makes "zowowowowowow" sound
def stun!
# ...
end
# flashes blue light
# does not require confirmation
# makes "trrrtrtrtrrtrtrtrtrtrtr" sound
def ... | I found another strategy poking around <http://github.com/wycats/thor/tree>. Thor lets you write stuff like this:
```
Class RayGun < Thor
desc "Flashes red light and makes zowowowowow sound"
method_options :confirmation => :required
def stun!
# ...
end
end
```
It manages this by using the (undocumented) ... |
443,170 | <p>I am manually creating the equivalent lambda:</p>
<pre><code>var function = p => p.Child.Any(c => c.Field == "value");
</code></pre>
<p>I have a MethodInfo reference to the "Any" method used with Expressions built in code.</p>
<pre><code>MethodInfo method = typeof(Queryable).GetMethods()
.Where(m =&... | [
{
"answer_id": 443203,
"author": "Jon Skeet",
"author_id": 22656,
"author_profile": "https://Stackoverflow.com/users/22656",
"pm_score": 3,
"selected": true,
"text": "<p><code>EntityCollection<T></code> doesn't implement <code>IQueryable<T></code> so it's not surprising that ... | 2009/01/14 | [
"https://Stackoverflow.com/questions/443170",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/54612/"
] | I am manually creating the equivalent lambda:
```
var function = p => p.Child.Any(c => c.Field == "value");
```
I have a MethodInfo reference to the "Any" method used with Expressions built in code.
```
MethodInfo method = typeof(Queryable).GetMethods()
.Where(m => m.Name == "Any" && m.GetParameters().Lengt... | `EntityCollection<T>` doesn't implement `IQueryable<T>` so it's not surprising that this doesn't work, IMO.
Could you give more explanation of what you're trying to do? If you're expecting the query to be run on the database, my guess is that it's really not going to support that (given that `EntityCollection<T>` does... |
443,185 | <p>I am writing a shell script to, among other things, determine the last time a branch was made in a subversion repository. The following code works:</p>
<pre>
<code>
DEV='http://some/svn/server/'
BRANCH='some/repos/branches/'
LAST_UPDATE=`svn list http://$DEV$BRANCH | sort -r`
LAST_U... | [
{
"answer_id": 443196,
"author": "Ben",
"author_id": 11522,
"author_profile": "https://Stackoverflow.com/users/11522",
"pm_score": 3,
"selected": true,
"text": "<p>How about:</p>\n\n<pre><code> LAST_UPDATE=`svn list http://$DEV$BRANCH | sort -r | awk -F\\/ '{print $1}'`\n</code></pre>... | 2009/01/14 | [
"https://Stackoverflow.com/questions/443185",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | I am writing a shell script to, among other things, determine the last time a branch was made in a subversion repository. The following code works:
```
DEV='http://some/svn/server/'
BRANCH='some/repos/branches/'
LAST_UPDATE=`svn list http://$DEV$BRANCH | sort -r`
LAST_UPDATE=${LAST_UPD... | How about:
```
LAST_UPDATE=`svn list http://$DEV$BRANCH | sort -r | awk -F\/ '{print $1}'`
```
I've not tested it, and I'm not sure if the quotes inside the back-ticks will cause any problems, but otherwise I can't see why it wouldn't work...
Ben |
443,187 | <p>I have a Rails app that uses STI to handle different types of Users, such as:</p>
<pre><code>class Admin < User
...
end
</code></pre>
<p>I want to use memcached, but I keep getting the dreaded "unknown class/module" error. I've tried pre-loading <em>all</em> of my ActiveRecord models to no avail. The first re... | [
{
"answer_id": 443212,
"author": "DanSingerman",
"author_id": 43965,
"author_profile": "https://Stackoverflow.com/users/43965",
"pm_score": 2,
"selected": true,
"text": "<p>I think this is due to <a href=\"http://en.wikipedia.org/wiki/Lazy_loading\" rel=\"nofollow noreferrer\">lazy loadi... | 2009/01/14 | [
"https://Stackoverflow.com/questions/443187",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/52283/"
] | I have a Rails app that uses STI to handle different types of Users, such as:
```
class Admin < User
...
end
```
I want to use memcached, but I keep getting the dreaded "unknown class/module" error. I've tried pre-loading *all* of my ActiveRecord models to no avail. The first request works as normal, but the first... | I think this is due to [lazy loading](http://en.wikipedia.org/wiki/Lazy_loading) of the classes. When you call it from memcached the class definition isn't loaded, and then you get the error.
The workaround I use is:
```
Admin #lazily load the class definition
# do whatever that has cached Admins
``` |
443,188 | <p>I am looking for a MSBuild task that will tell me the version of a specific dll. Is there a task available for this? </p>
<p>In my case the dll is a .Net assembly, so I'm actually looking for Assembly.FullName.</p>
| [
{
"answer_id": 443211,
"author": "Julien Hoarau",
"author_id": 12248,
"author_profile": "https://Stackoverflow.com/users/12248",
"pm_score": 5,
"selected": false,
"text": "<p><a href=\"http://msdn.microsoft.com/en-us/library/ms164296.aspx\" rel=\"noreferrer\">GetAssemblyIdentity</a> is y... | 2009/01/14 | [
"https://Stackoverflow.com/questions/443188",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4231/"
] | I am looking for a MSBuild task that will tell me the version of a specific dll. Is there a task available for this?
In my case the dll is a .Net assembly, so I'm actually looking for Assembly.FullName. | Thanks madgnome! I thought I would share the working code.
```
<Target Name="UpdateWebConfigVersion">
<GetAssemblyIdentity AssemblyFiles="lib\foo.dll">
<Output TaskParameter="Assemblies" ItemName="fooAssemblyInfo"/>
</GetAssemblyIdentity>
<XmlUpdate XmlFileName="src\Web\ServiceModel.Extensions.conf... |
443,193 | <p>In looking at samples of ASP.NET MVC sites, I'm seeing quite a bit of examples with embedded logic in the views, e.g.:</p>
<pre><code><% if (customerIsAllowed)
{ %>
<p>nnn</p>
<p>nnn</p>
<p>nnn</p>
<p>nnn</p>
<p>nnn</p>
<% } e... | [
{
"answer_id": 443213,
"author": "tvanfosson",
"author_id": 12950,
"author_profile": "https://Stackoverflow.com/users/12950",
"pm_score": 6,
"selected": true,
"text": "<p>It depends on the reason for the logic. If the logic is choosing an alternate presentation based on some property pa... | 2009/01/14 | [
"https://Stackoverflow.com/questions/443193",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4639/"
] | In looking at samples of ASP.NET MVC sites, I'm seeing quite a bit of examples with embedded logic in the views, e.g.:
```
<% if (customerIsAllowed)
{ %>
<p>nnn</p>
<p>nnn</p>
<p>nnn</p>
<p>nnn</p>
<p>nnn</p>
<% } else {%>
<p>nnn</p>
<p>nnn</p>
<p>nnn</p>
<p>nnn</p>
<p>nnn</p>
<% ... | It depends on the reason for the logic. If the logic is choosing an alternate presentation based on some property passed to it by the controller, it is probably ok. This allows you some view reuse. Instead of having to recreate (and repeat) an entire view for each custom privilege, you can pass in some data that allows... |
443,204 | <p>There is a .csv file we would like to distribute to our customers, it contains multiline entries (i.e. entries with newlines). Depending on the language settings of the customers, the file may or may not be correctly imported into Excel. Normally, we would suggest to use to Import the file, but there seems to be som... | [
{
"answer_id": 814136,
"author": "Mike Lewis",
"author_id": 99121,
"author_profile": "https://Stackoverflow.com/users/99121",
"pm_score": 1,
"selected": false,
"text": "<p>Your question is not quite clear, but I think this is what you want:\nNote: For some reason the error catching part ... | 2009/01/14 | [
"https://Stackoverflow.com/questions/443204",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/46665/"
] | There is a .csv file we would like to distribute to our customers, it contains multiline entries (i.e. entries with newlines). Depending on the language settings of the customers, the file may or may not be correctly imported into Excel. Normally, we would suggest to use to Import the file, but there seems to be some b... | You will probably find it opens fine in openoffice. I did.
In which case, you can save it as an excell sheet, and distribute both files to your clients. |
443,235 | <p>In my winform app, I am trying to add a userSetting, although the error is occuring with appSettings too. When the setting is added I get an exeption thrown that says: "Configuration system failed to initialize" with a Inner Exception "Unrecognized configuration section userSetting"</p>
<p>Exception Details:</p>
<... | [
{
"answer_id": 443246,
"author": "Marc Gravell",
"author_id": 23354,
"author_profile": "https://Stackoverflow.com/users/23354",
"pm_score": 6,
"selected": true,
"text": "<p>Try checking that the app.config (myapp.exe.config once deployed) file exists and has at the top (possibly with oth... | 2009/01/14 | [
"https://Stackoverflow.com/questions/443235",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/805/"
] | In my winform app, I am trying to add a userSetting, although the error is occuring with appSettings too. When the setting is added I get an exeption thrown that says: "Configuration system failed to initialize" with a Inner Exception "Unrecognized configuration section userSetting"
Exception Details:
```
System.Conf... | Try checking that the app.config (myapp.exe.config once deployed) file exists and has at the top (possibly with other bits)
```
<?xml version="1.0" encoding="utf-8" ?>
<configuration>
<configSections>
<sectionGroup name="userSettings"
type="System.Configuration.UserSettingsGroup, System, Version=2.0.0.0, Culture=n... |
443,237 | <p>This is probably quite basic, so bear with me (on the other hand there's probably a nice shiny cut-and-dried answer!).</p>
<p>I'm diagnosing a deadlocking problem at the moment, and indeed I can see that one of my sessions is being blocked by another. (The other end of the deadlock are Java threads waiting on each... | [
{
"answer_id": 443269,
"author": "Thuglife",
"author_id": 41612,
"author_profile": "https://Stackoverflow.com/users/41612",
"pm_score": 1,
"selected": false,
"text": "<p>Try this</p>\n\n<pre><code>dbcc inputbuffer(spid)\n</code></pre>\n"
},
{
"answer_id": 448533,
"author": "r... | 2009/01/14 | [
"https://Stackoverflow.com/questions/443237",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/45664/"
] | This is probably quite basic, so bear with me (on the other hand there's probably a nice shiny cut-and-dried answer!).
I'm diagnosing a deadlocking problem at the moment, and indeed I can see that one of my sessions is being blocked by another. (The other end of the deadlock are Java threads waiting on each other in t... | Try this
```
dbcc inputbuffer(spid)
``` |
443,245 | <p>In order to open a modal dialog, you need to pass a parent window, and pass the necessary flags for the dialog to be modal of course.</p>
<p>Depending on where you are in the eclipse infrastructure, finding this parent window is not always easy.</p>
<p>How can the parent window be accessed?</p>
| [
{
"answer_id": 443263,
"author": "Tirno",
"author_id": 9886,
"author_profile": "https://Stackoverflow.com/users/9886",
"pm_score": 6,
"selected": true,
"text": "<p>From a view or an editor (this part is easy):</p>\n\n<pre><code>this.getSite().getWorkbenchWindow().getShell()\n</code></pre... | 2009/01/14 | [
"https://Stackoverflow.com/questions/443245",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9886/"
] | In order to open a modal dialog, you need to pass a parent window, and pass the necessary flags for the dialog to be modal of course.
Depending on where you are in the eclipse infrastructure, finding this parent window is not always easy.
How can the parent window be accessed? | From a view or an editor (this part is easy):
```
this.getSite().getWorkbenchWindow().getShell()
```
From elsewhere, access a view or editor and same as above.
If you find yourself in a class where you don't have access to a view or editor, you probably don't want to be calling any UI code, but if you really want ... |
443,250 | <p>We were given a sample document, and need to be able to reproduce the structure of the document exactly for a vendor. However, I'm a little lost with how C# handles namespaces. Here's a sample of the document:</p>
<pre><code><?xml version="1.0" encoding="UTF-8"?>
<Doc1 xmlns="http://www.sample.com/file" ... | [
{
"answer_id": 443306,
"author": "Dimi Takis",
"author_id": 52039,
"author_profile": "https://Stackoverflow.com/users/52039",
"pm_score": 6,
"selected": true,
"text": "<p>You should try it that way</p>\n\n<pre><code> XmlDocument doc = new XmlDocument(); \n\n XmlSchema schema = new Xml... | 2009/01/14 | [
"https://Stackoverflow.com/questions/443250",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8173/"
] | We were given a sample document, and need to be able to reproduce the structure of the document exactly for a vendor. However, I'm a little lost with how C# handles namespaces. Here's a sample of the document:
```
<?xml version="1.0" encoding="UTF-8"?>
<Doc1 xmlns="http://www.sample.com/file" xmlns:xsi="http://www.w3.... | You should try it that way
```
XmlDocument doc = new XmlDocument();
XmlSchema schema = new XmlSchema();
schema.Namespaces.Add("xmlns", "http://www.sample.com/file");
doc.Schemas.Add(schema);
```
Do not forget to include the following namespaces:
```
using System.Xml.Schema;
using System.Xml;
``` |
443,261 | <p>I'll try to better explain my problem.
Using Eclipse and MTJ (Mobile Tools for Java) plugin you can set some directives for the preprocessor in order to create different builds of your code, like in C/C++.
My problem is that i'm unable to use this feature. I mean, when i build my sources, the resulting output contai... | [
{
"answer_id": 443765,
"author": "Matt Darby",
"author_id": 52283,
"author_profile": "https://Stackoverflow.com/users/52283",
"pm_score": 0,
"selected": false,
"text": "<p>I recommend using <a href=\"https://rpm.newrelic.com\" rel=\"nofollow noreferrer\">New Relic's RPM service</a>. It h... | 2009/01/14 | [
"https://Stackoverflow.com/questions/443261",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/49209/"
] | I'll try to better explain my problem.
Using Eclipse and MTJ (Mobile Tools for Java) plugin you can set some directives for the preprocessor in order to create different builds of your code, like in C/C++.
My problem is that i'm unable to use this feature. I mean, when i build my sources, the resulting output contains ... | When things are mysterious.... profilers are your friend!
a profiler will draw up statistics of which methods are being called the most and how long is being spent in each method call.
[ruby-prof](http://ruby-prof.rubyforge.org/) does the trick for me when I'm in RubyLand, and it will produce a nice call-graph (in ht... |
443,264 | <p>If I reference the <a href="http://trac-hg.assembla.com/snakeyaml/wiki" rel="nofollow noreferrer" title="The Trac wiki for SnakeYAML">SnakeYAML</a> jar directly from a test program (see bottom), everything works. If I'm inside my Maven-created project, I get the following output from my unit tests:</p>
<pre><code>j... | [
{
"answer_id": 443348,
"author": "Olivier",
"author_id": 53369,
"author_profile": "https://Stackoverflow.com/users/53369",
"pm_score": 3,
"selected": true,
"text": "<p>Seems like a JDK version issue: <code>LinkedList#push</code> was <a href=\"http://java.sun.com/javase/6/docs/api/java/ut... | 2009/01/14 | [
"https://Stackoverflow.com/questions/443264",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4203/"
] | If I reference the [SnakeYAML](http://trac-hg.assembla.com/snakeyaml/wiki "The Trac wiki for SnakeYAML") jar directly from a test program (see bottom), everything works. If I'm inside my Maven-created project, I get the following output from my unit tests:
```
java.lang.NoSuchMethodError: java.util.LinkedList.push(Lja... | Seems like a JDK version issue: `LinkedList#push` was [introduced in Java 6](http://java.sun.com/javase/6/docs/api/java/util/LinkedList.html#push(E)).
Try setting `JAVA_HOME` to the correct version before running Maven. |
443,265 | <p>I have looked at <em><a href="https://stackoverflow.com/questions/141525/absolute-beginners-guide-to-bit-shifting">What are bitwise shift (bit-shift) operators and how do they work?</a></em>, but I still find the concept of bit shifting difficult to understand.</p>
<p>Can someone point me in the direction of a more... | [
{
"answer_id": 443292,
"author": "Frederick The Fool",
"author_id": 32688,
"author_profile": "https://Stackoverflow.com/users/32688",
"pm_score": 3,
"selected": false,
"text": "<p>Bit shifting is nothing but what it <em>literally</em> means: shifting all bits in a given sequence left or ... | 2009/01/14 | [
"https://Stackoverflow.com/questions/443265",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | I have looked at *[What are bitwise shift (bit-shift) operators and how do they work?](https://stackoverflow.com/questions/141525/absolute-beginners-guide-to-bit-shifting)*, but I still find the concept of bit shifting difficult to understand.
Can someone point me in the direction of a more basic guide to bit shifting... | Bit shifting is nothing but what it *literally* means: shifting all bits in a given sequence left or right.
All you have to remember is that every decimal number (like 6, 7, 3, 2) is represented as a sequence of bits in the memory of the computer. So if you find something like this in a piece of C code:
```
(7 >> 1... |
443,268 | <p>Consider the 2 following methods of reading a string from a file:</p>
<pre><code>NSString *path = [[NSBundle mainBundle] pathForResource:@"foo" ofType:@"txt"];
NSString *string = [NSString stringWithContentsOfFile:path encoding:NSASCIIStringEncoding error:NULL];
</code></pre>
<hr>
<pre><code>NSString *path = [[NS... | [
{
"answer_id": 443304,
"author": "Pedro Henriques",
"author_id": 51164,
"author_profile": "https://Stackoverflow.com/users/51164",
"pm_score": 1,
"selected": false,
"text": "<p>When you create a String with a Class method generally it is added to the top most autorelease pool. At the end... | 2009/01/14 | [
"https://Stackoverflow.com/questions/443268",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/50335/"
] | Consider the 2 following methods of reading a string from a file:
```
NSString *path = [[NSBundle mainBundle] pathForResource:@"foo" ofType:@"txt"];
NSString *string = [NSString stringWithContentsOfFile:path encoding:NSASCIIStringEncoding error:NULL];
```
---
```
NSString *path = [[NSBundle mainBundle] pathForResou... | In Cocoa, you only own an object if you create it by using `alloc`, `new`, `copy` or `retain`. Whenever you don't own an object, you have no guarantees about that object outside the local scope in which you use it. In your example, since you didn't create the new string with any of the above mentioned methods, you have... |
443,276 | <p>I'm wondering how can I submit a form via Ajax (using prototype framework) and display the server response in a "result" div.
The html looks like this :</p>
<pre><code><form id="myForm" action="/getResults">
[...]
<input type="submit" value="submit" />
</form>
<div id="result"></d... | [
{
"answer_id": 443299,
"author": "krosenvold",
"author_id": 23691,
"author_profile": "https://Stackoverflow.com/users/23691",
"pm_score": 2,
"selected": false,
"text": "<p>You need to return the value false from the ajax function, which blocks the standard form submit.</p>\n\n<pre><code>... | 2009/01/14 | [
"https://Stackoverflow.com/questions/443276",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/26859/"
] | I'm wondering how can I submit a form via Ajax (using prototype framework) and display the server response in a "result" div.
The html looks like this :
```
<form id="myForm" action="/getResults">
[...]
<input type="submit" value="submit" />
</form>
<div id="result"></div>
```
I tried to attach a javascript ... | Check out Prototype API's pages on [`Form.Request`](http://www.prototypejs.org/api/form/request) and [`Event`](http://www.prototypejs.org/api/event) handling.
Basically, if you have this:
```
<form id='myForm'>
.... fields ....
<input type='submit' value='Go'>
</form>
<div id='result'></div>
```
Your js would be, m... |
443,280 | <p>When I do SELECT statements in PHP code I always select named columns, like:</p>
<pre><code>SELECT id, name from users;
</code></pre>
<p>rather than using:</p>
<pre><code>SELECT * from users;
</code></pre>
<p>This has the advantage of being more informative and readable, and also avoids problems later if new col... | [
{
"answer_id": 443285,
"author": "Josh Mein",
"author_id": 2486,
"author_profile": "https://Stackoverflow.com/users/2486",
"pm_score": 5,
"selected": false,
"text": "<pre><code>INSERT INTO table_name (column1, column2, column3,...)\nVALUES (value1, value2, value3,...)\n\nINSERT INTO peop... | 2009/01/14 | [
"https://Stackoverflow.com/questions/443280",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11522/"
] | When I do SELECT statements in PHP code I always select named columns, like:
```
SELECT id, name from users;
```
rather than using:
```
SELECT * from users;
```
This has the advantage of being more informative and readable, and also avoids problems later if new columns are added to the table.
What I'm wondering ... | That's syntax is possible with MySQL only. Afaik, other RDBMS doesn't allow that. Here's the syntax:
```
INSERT INTO games SET yr = 2012, city = 'London';
```
I wish PostgreSQL facilitated this kind of insert syntax
Standard ANSI syntax, however, would be
INSERT into people (yr, city) values (2012, 'London'); |
443,295 | <p>as explained before, I'm currently working on a small linear algebra library to use in a personal project. Matrices are implemented as C++ vectors and element assignment ( a(i,j) = v; ) is delegated to the assignment to the vector's elements. For my project I'll need to solve tons of square equation systems and, in ... | [
{
"answer_id": 443316,
"author": "duffymo",
"author_id": 37213,
"author_profile": "https://Stackoverflow.com/users/37213",
"pm_score": 0,
"selected": false,
"text": "<p>Your description makes it sound like you're doing the LU decomposition in-place. That's certainly more efficient from ... | 2009/01/14 | [
"https://Stackoverflow.com/questions/443295",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/25418/"
] | as explained before, I'm currently working on a small linear algebra library to use in a personal project. Matrices are implemented as C++ vectors and element assignment ( a(i,j) = v; ) is delegated to the assignment to the vector's elements. For my project I'll need to solve tons of square equation systems and, in ord... | ```
template<class T>
class matrix {
public:
class accessor {
public:
accessor(T& dest, matrix& parent) : dest(dest), parent(parent) { }
operator T const& () const { return dest; }
accessor& operator=(T const& t) { dest = t; parent.invalidate_cache(); return *this; }
private:
... |
443,305 | <p>I am using JAXP to generate and parse an XML document from which some fields are loaded from a database.</p>
<p>Code to serialize the XML:</p>
<pre><code>DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document doc = builder.newDocument();
Element root = doc.createElement("test... | [
{
"answer_id": 443361,
"author": "kdgregory",
"author_id": 42126,
"author_profile": "https://Stackoverflow.com/users/42126",
"pm_score": 6,
"selected": true,
"text": "<p>Use a FileOutputStream rather than a FileWriter.</p>\n\n<p>The latter applies its own encoding, which is almost certai... | 2009/01/14 | [
"https://Stackoverflow.com/questions/443305",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13956/"
] | I am using JAXP to generate and parse an XML document from which some fields are loaded from a database.
Code to serialize the XML:
```
DocumentBuilder builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
Document doc = builder.newDocument();
Element root = doc.createElement("test");
root.setAttribute... | Use a FileOutputStream rather than a FileWriter.
The latter applies its own encoding, which is almost certainly not UTF-8 (depending on your platform, it's probably Windows-1252 or IS-8859-1).
Edit (now that I have some time):
An XML document without a prologue is permitted to be encoded as UTF-8 or UTF-16. With a p... |
443,310 | <p>I'd like for a subclass of a certain superclass with certain constructor parameters to load an XML file containing information that I'd then like to pass to the superconstructor. Is this impossible to achieve?</p>
| [
{
"answer_id": 443321,
"author": "Tim Frey",
"author_id": 1471,
"author_profile": "https://Stackoverflow.com/users/1471",
"pm_score": 5,
"selected": true,
"text": "<p>How about using a factory method instead? Maybe something like:</p>\n\n<pre><code>private MyObject(ComplexData data)\n{\... | 2009/01/14 | [
"https://Stackoverflow.com/questions/443310",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/50844/"
] | I'd like for a subclass of a certain superclass with certain constructor parameters to load an XML file containing information that I'd then like to pass to the superconstructor. Is this impossible to achieve? | How about using a factory method instead? Maybe something like:
```
private MyObject(ComplexData data)
{
super(data);
}
public static MyObject createMyObject(String someParameter)
{
ComplexData data = XMLParser.createData(someParameter);
return new MyObject(data);
}
``` |
443,375 | <p>It appears that I can escape command line arguments using single or double quotes:</p>
<pre><code>PS C:\> echo Hello World
Hello
World
PS C:\> echo 'Hello World'
Hello World
PS C:\> echo "Hello World"
Hello World
</code></pre>
<p>But there's still something I can't figure out, which is when you wish to ru... | [
{
"answer_id": 443394,
"author": "EBGreen",
"author_id": 1358,
"author_profile": "https://Stackoverflow.com/users/1358",
"pm_score": 5,
"selected": true,
"text": "<p>Use this:</p>\n\n<pre><code>. \"c:\\program files\\test.exe\"\n</code></pre>\n\n<p>Actually an even better solution would ... | 2009/01/14 | [
"https://Stackoverflow.com/questions/443375",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/34685/"
] | It appears that I can escape command line arguments using single or double quotes:
```
PS C:\> echo Hello World
Hello
World
PS C:\> echo 'Hello World'
Hello World
PS C:\> echo "Hello World"
Hello World
```
But there's still something I can't figure out, which is when you wish to run an executable from a directory th... | Use this:
```
. "c:\program files\test.exe"
```
Actually an even better solution would be:
```
Invoke-Item "c:\program files\test.exe"
```
or using the alias:
```
ii "c:\program files\test.exe"
```
Using Invoke-Item means that the proper Windows file handler would be used. So for an EXE file it would run it. F... |
443,378 | <p>How would I refactor this to get it to return a string not a dataset? </p>
<pre><code>[WebMethod]
public DataSet GetPONumber(string Database)
{
SqlConnection sqlConn = new SqlConnection();
sqlConn.ConnectionString = GetConnString(Database);
// build query
string strSQL = @" A SELECT QUERY!!!!... | [
{
"answer_id": 443426,
"author": "Otávio Décio",
"author_id": 48684,
"author_profile": "https://Stackoverflow.com/users/48684",
"pm_score": 1,
"selected": false,
"text": "<p>You could transform the dataset into its JSON string representation. This way it can be easily consumed by basical... | 2009/01/14 | [
"https://Stackoverflow.com/questions/443378",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/49971/"
] | How would I refactor this to get it to return a string not a dataset?
```
[WebMethod]
public DataSet GetPONumber(string Database)
{
SqlConnection sqlConn = new SqlConnection();
sqlConn.ConnectionString = GetConnString(Database);
// build query
string strSQL = @" A SELECT QUERY!!!!! ";
SqlDataAd... | This is what I finnished with and is working, thank you for your input:
```
[WebMethod]
public String GetPONumber(string Database)
{
//Create Object ready for Value
object po = "";
//Set Connection
SqlConnection Connection = new SqlConnection(GetConnString(Database));
... |
443,385 | <p>I have a map for my game, I have a script that on a click displays an alert of the mouse coordinates on the map.</p>
<p>The map scale is 1 map unit to 2.5 pixels and the map starts at -600, 600 and goes down to 600, 1700. Thus I can't simply throw out the pixels of the mouse.</p>
<p>I got it working (and was prett... | [
{
"answer_id": 443406,
"author": "Crescent Fresh",
"author_id": 45433,
"author_profile": "https://Stackoverflow.com/users/45433",
"pm_score": 3,
"selected": true,
"text": "<p>Try:</p>\n\n<pre><code>tempX = event.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft);... | 2009/01/14 | [
"https://Stackoverflow.com/questions/443385",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1384652/"
] | I have a map for my game, I have a script that on a click displays an alert of the mouse coordinates on the map.
The map scale is 1 map unit to 2.5 pixels and the map starts at -600, 600 and goes down to 600, 1700. Thus I can't simply throw out the pixels of the mouse.
I got it working (and was pretty happy about it)... | Try:
```
tempX = event.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft);
tempY = event.clientY + (document.documentElement.scrollTop || document.body.scrollTop);
```
Checked your page, and the DOCTYPE is putting IE in standards mode, so the `scrollXXX` properties you want are actually in `... |
443,387 | <p>Put the following into a file <strong>hello.py</strong> (and <code>easy_install paramiko</code> if you haven't got it):</p>
<pre><code>hostname,username,password='fill','these','in'
import paramiko
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
c.connect(hostname=hostname, username... | [
{
"answer_id": 450895,
"author": "JimB",
"author_id": 32880,
"author_profile": "https://Stackoverflow.com/users/32880",
"pm_score": 5,
"selected": true,
"text": "<p>Paramiko uses separate threads for the underlying transport.\nYou should <em>never</em> have a module that spawns a thread ... | 2009/01/14 | [
"https://Stackoverflow.com/questions/443387",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4105/"
] | Put the following into a file **hello.py** (and `easy_install paramiko` if you haven't got it):
```
hostname,username,password='fill','these','in'
import paramiko
c = paramiko.SSHClient()
c.set_missing_host_key_policy(paramiko.AutoAddPolicy())
c.connect(hostname=hostname, username=username, password=password)
i,o,e = ... | Paramiko uses separate threads for the underlying transport.
You should *never* have a module that spawns a thread as a side effect of importing. As I understand it, there is a single import lock available, so when a child thread from your module attempts another import, it can block indefinitely, because your main thr... |
443,389 | <p>When opening a Word document a macro should start and it did for a while.
But then I saved the document when the macro was activated and after that I get the error message:</p>
<pre><code>The macros in this project have been disabled
</code></pre>
<p>when I open the document.</p>
<p>I have tried different securi... | [
{
"answer_id": 443415,
"author": "Fionnuala",
"author_id": 2548,
"author_profile": "https://Stackoverflow.com/users/2548",
"pm_score": 0,
"selected": false,
"text": "<p>In Word: Tools->Macro_>security and set to, say, medium. Alternatives include Trusted Locations and Self-Certified proj... | 2009/01/14 | [
"https://Stackoverflow.com/questions/443389",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/55046/"
] | When opening a Word document a macro should start and it did for a while.
But then I saved the document when the macro was activated and after that I get the error message:
```
The macros in this project have been disabled
```
when I open the document.
I have tried different security settings.
Any idea what might... | If error in your macro has blocked macros in project, it usually takes long time to search for a solution, as MS seems not approving wide usage of macros.
In Word :
The solution about enabling macros in File -> Options -> Advanced is NOT enough.
Just go to:
Developer -> Protect -> Restrict Editing -> opens up right ... |
443,430 | <p>I have a very simple greasemonkey script that I want to call an already existing javascript function on the page. I've read the documentation and nothing seems to work</p>
<pre><code>window.setTimeout(function() {
alert('test') // This alert works, but nothing after it does
myFunction() // undefined
wi... | [
{
"answer_id": 443473,
"author": "Maiku Mori",
"author_id": 54091,
"author_profile": "https://Stackoverflow.com/users/54091",
"pm_score": 6,
"selected": true,
"text": "<p>Try using:\nunsafeWindow.myFunction();</p>\n\n<p>More details and info - <a href=\"http://wiki.greasespot.net/UnsafeW... | 2009/01/14 | [
"https://Stackoverflow.com/questions/443430",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/35247/"
] | I have a very simple greasemonkey script that I want to call an already existing javascript function on the page. I've read the documentation and nothing seems to work
```
window.setTimeout(function() {
alert('test') // This alert works, but nothing after it does
myFunction() // undefined
window.myFunctio... | Try using:
unsafeWindow.myFunction();
More details and info - <http://wiki.greasespot.net/UnsafeWindow> |
443,466 | <p>Typically, when I use lambdas, I just use "a, b, c, d..." as variable names as the types are easily inferred, and I find short names to be easier to read. Here is an example:</p>
<pre><code>var someEnumerable = GetSomeEnumerable();
var somethingElseList = someEnumerable.Select(a => a.SomeProperty)
... | [
{
"answer_id": 443485,
"author": "Jon Skeet",
"author_id": 22656,
"author_profile": "https://Stackoverflow.com/users/22656",
"pm_score": 4,
"selected": false,
"text": "<p>I try to use single-word but meaningful names. So I would <em>tend</em> to use \"person\" rather than \"p\" but would... | 2009/01/14 | [
"https://Stackoverflow.com/questions/443466",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18941/"
] | Typically, when I use lambdas, I just use "a, b, c, d..." as variable names as the types are easily inferred, and I find short names to be easier to read. Here is an example:
```
var someEnumerable = GetSomeEnumerable();
var somethingElseList = someEnumerable.Select(a => a.SomeProperty)
... | The way I usualy do it depends on the collection you're enumerating over. If the name of the collection implies what type the lambda parameter will be, then I just go with the single letter, however if the collection isn't as descriptive, then I'll use a word.
IE:
```
myCollection.Where(person =>....); //non descript... |
443,467 | <p>I am using SQL Server 2005. I am trying to join 2 tables together, but only when a column value in the main table is true. Like this:</p>
<pre><code>select * from T1
join T2 on T1.value = T2.value
where T2.value2 = 'variable2'
and T2.value3 = 'variable3'
</code></pre>
<p>There is a column value in T1 which says if... | [
{
"answer_id": 443480,
"author": "Dave Markle",
"author_id": 24995,
"author_profile": "https://Stackoverflow.com/users/24995",
"pm_score": 2,
"selected": false,
"text": "<pre><code>select * \nfrom T1\njoin T2 \n on T1.value = T2.value\n and T1.booleancolumn = 1\nwhere T2.value2 = 'var... | 2009/01/14 | [
"https://Stackoverflow.com/questions/443467",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/55055/"
] | I am using SQL Server 2005. I am trying to join 2 tables together, but only when a column value in the main table is true. Like this:
```
select * from T1
join T2 on T1.value = T2.value
where T2.value2 = 'variable2'
and T2.value3 = 'variable3'
```
There is a column value in T1 which says if I have to use the values ... | Dave Marke is right, but more generaly...
conditional join is answer to your question, try find some resources on web for example
<http://weblogs.sqlteam.com/jeffs/archive/2007/04/03/Conditional-Joins.aspx>
<http://bytes.com/groups/ms-sql/641690-difference-condition-join-where>
it is very powerful technique to mak... |
443,499 | <p>What is the best way to convert a JSON code as this:</p>
<pre><code>{
"data" :
{
"field1" : "value1",
"field2" : "value2"
}
}
</code></pre>
<p>in a Java Map in which one the keys are (field1, field2) and the values for those fields are (value1, value2).</p>
<p>Any ideas? Should I u... | [
{
"answer_id": 548871,
"author": "Bruno Ranschaert",
"author_id": 4900,
"author_profile": "https://Stackoverflow.com/users/4900",
"pm_score": 2,
"selected": false,
"text": "<p>The JsonTools library is very complete. It can be found at <a href=\"https://github.com/branscha/lib-jsontools\"... | 2009/01/14 | [
"https://Stackoverflow.com/questions/443499",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/24097/"
] | What is the best way to convert a JSON code as this:
```
{
"data" :
{
"field1" : "value1",
"field2" : "value2"
}
}
```
in a Java Map in which one the keys are (field1, field2) and the values for those fields are (value1, value2).
Any ideas? Should I use Json-lib for that? Or better i... | I hope you were joking about writing your own parser. :-)
For such a simple mapping, most tools from <http://json.org> (section java) would work.
For one of them (Jackson <https://github.com/FasterXML/jackson-databind/#5-minute-tutorial-streaming-parser-generator>), you'd do:
```
Map<String,Object> result =
n... |
443,500 | <p>Inspired by this question: <a href="https://stackoverflow.com/questions/443423/in-complexity-analysis-why-is-considered-to-be-2-operations">In Complexity Analysis why is ++ considered to be 2 operations?</a></p>
<p>Take the following psuedo code:</p>
<pre><code>class test
{
int _counter;
void Increment()
... | [
{
"answer_id": 443528,
"author": "Michael Burr",
"author_id": 12711,
"author_profile": "https://Stackoverflow.com/users/12711",
"pm_score": 4,
"selected": false,
"text": "<p>In a word, no.</p>\n\n<p>You can use something like <code>InterlockedIncrement()</code> depending on your platform... | 2009/01/14 | [
"https://Stackoverflow.com/questions/443500",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/26160/"
] | Inspired by this question: [In Complexity Analysis why is ++ considered to be 2 operations?](https://stackoverflow.com/questions/443423/in-complexity-analysis-why-is-considered-to-be-2-operations)
Take the following psuedo code:
```
class test
{
int _counter;
void Increment()
{
_counter++;
}
}
```
... | No, incrementing is not thread-safe. Neither are the `INC` and `DEC` instructions. They all require a load and a store, and a thread running on another CPU could do its own load or store on the same memory location interleaved between those operations.
Some languages have built-in support for thread synchronization, b... |
443,516 | <p>in my application I have 2 layers. The first layer is a C legacy exposing cdecl functions that use the "..." syntax for a varying parameter list. The only way I found to call these functions from my .Net layer (the second one) is using the DllImport technics. For example the C function below:</p>
<pre><code>int myF... | [
{
"answer_id": 443664,
"author": "Rob Kennedy",
"author_id": 33732,
"author_profile": "https://Stackoverflow.com/users/33732",
"pm_score": 2,
"selected": false,
"text": "<p>How does the C function know which one is the last parameter? It cannot know <em>a priori</em> how many parameters ... | 2009/01/14 | [
"https://Stackoverflow.com/questions/443516",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | in my application I have 2 layers. The first layer is a C legacy exposing cdecl functions that use the "..." syntax for a varying parameter list. The only way I found to call these functions from my .Net layer (the second one) is using the DllImport technics. For example the C function below:
```
int myFunc(char* name... | How does the C function know which one is the last parameter? It cannot know *a priori* how many parameters there are. It needs additional information. One common way for functions get the information they need is by parsing the included string parameter to count format specifiers, as in `printf`. In that case, if the ... |
443,522 | <p>I have this P/Invoke RegSetValueExW that sets the value to the registry key. in C#</p>
<pre><code>[DllImport("coredll.dll", EntryPoint = "RegSetValueExW")]
public static extern int RegSetValueExW(uint hKey, string lpValueName,
uint lpReserved,
uint lpType,
byte[] lpData,
... | [
{
"answer_id": 443611,
"author": "Stephen Martin",
"author_id": 12845,
"author_profile": "https://Stackoverflow.com/users/12845",
"pm_score": 3,
"selected": true,
"text": "<p>I've got to start by asking why you are using PInvoke here when there is already a method for setting registry va... | 2009/01/14 | [
"https://Stackoverflow.com/questions/443522",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/54890/"
] | I have this P/Invoke RegSetValueExW that sets the value to the registry key. in C#
```
[DllImport("coredll.dll", EntryPoint = "RegSetValueExW")]
public static extern int RegSetValueExW(uint hKey, string lpValueName,
uint lpReserved,
uint lpType,
byte[] lpData,
uint lpcbD... | I've got to start by asking why you are using PInvoke here when there is already a method for setting registry values in the Microsoft.Win32.RegistryKey class? Or are you stuck using an old version of the Compact Framework?
Assuming you have a good reason for the PInvoke, the easiest answer is just to overload the PIn... |
443,531 | <p>I have a stored procedure that does a lot more reads when the NOLOCK hint is added to the query. I'm baffled - does anyone know why, please?</p>
<p>Details:
The query is: </p>
<pre><code>SELECT * FROM dbo.<table-name> WITH (NOLOCK).
</code></pre>
<p>It was doing 40,000 reads and there are less than 2,000 ro... | [
{
"answer_id": 443544,
"author": "Charles Bretana",
"author_id": 32632,
"author_profile": "https://Stackoverflow.com/users/32632",
"pm_score": 0,
"selected": false,
"text": "<p>Maybe the read count includes page reads to read the locks? </p>\n"
},
{
"answer_id": 443625,
"auth... | 2009/01/14 | [
"https://Stackoverflow.com/questions/443531",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/43631/"
] | I have a stored procedure that does a lot more reads when the NOLOCK hint is added to the query. I'm baffled - does anyone know why, please?
Details:
The query is:
```
SELECT * FROM dbo.<table-name> WITH (NOLOCK).
```
It was doing 40,000 reads and there are less than 2,000 rows. I established that most of these re... | NOLOCK reads data from transactions that have not been committed.
**EDIT**
Demo of NOLOCK read of uncommitted data.
```
create table table1 (id int, val int)
go
select * from table1 with ( NoLock)
begin tran
insert into table1 values (1,1)
--Switch to new query window
select * from table1 with ( NoLock)
--switch... |
443,542 | <p>From the documentation:</p>
<p><strong>SortField () constructor</strong></p>
<pre><code>public function SortField(name:String = null, caseInsensitive:Boolean = false, descending:Boolean = false, numeric:Object = null)
</code></pre>
<p>I'm confused on the last part - <code>numeric:Object = null</code>.</p>
<p>Her... | [
{
"answer_id": 443757,
"author": "Christian Nunciato",
"author_id": 32129,
"author_profile": "https://Stackoverflow.com/users/32129",
"pm_score": 1,
"selected": false,
"text": "<p>Have a look here for an example of sorting an XMLListCollection:</p>\n\n<p><a href=\"http://blog.flexexample... | 2009/01/14 | [
"https://Stackoverflow.com/questions/443542",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/24563/"
] | From the documentation:
**SortField () constructor**
```
public function SortField(name:String = null, caseInsensitive:Boolean = false, descending:Boolean = false, numeric:Object = null)
```
I'm confused on the last part - `numeric:Object = null`.
Here is my function:
```
private function createXMLDataProvider():... | Have a look here for an example of sorting an XMLListCollection:
<http://blog.flexexamples.com/2007/08/05/sorting-an-arraycollection-using-the-sortfield-and-sort-classes/>
If you scroll down to Vivek's comment, there's an example and a follow-up comment from Peter deHaan. It looks like he's just omitting the caseInse... |
443,569 | <p>In WinForms 2.0, a ComboBox has an Auto-Complete feature, that displays a custom Drop-Down list with only the values that start with the entered text.</p>
<p>However, if I want to limit valid values to only those that appear in the ComboBox's list of items, I can do that by setting the <code>DropDownStyle</code> to... | [
{
"answer_id": 443598,
"author": "Aaron Smith",
"author_id": 12969,
"author_profile": "https://Stackoverflow.com/users/12969",
"pm_score": 0,
"selected": false,
"text": "<p>The way I've done this is to check the value against the list of possible values when they leave the box and don't ... | 2009/01/14 | [
"https://Stackoverflow.com/questions/443569",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8363/"
] | In WinForms 2.0, a ComboBox has an Auto-Complete feature, that displays a custom Drop-Down list with only the values that start with the entered text.
However, if I want to limit valid values to only those that appear in the ComboBox's list of items, I can do that by setting the `DropDownStyle` to `DropDownList`, whic... | This solution worked for me:
```
Private Sub myComboBox_Validating(sender As System.Object, e As System.ComponentModel.CancelEventArgs) Handles myComboBox.Validating
If Not myComboBox.Items.Contains(myComboBox.Text) Then
MsgBox("Please select a value from the list", MsgBoxStyle.Exclamation, "Value not avai... |
443,586 | <p>Say I have the following code snippet in c#</p>
<pre><code>static const bool DO_PERFORMANCE_CODE = false;
if (DO_PERFORMANCE_CODE)
{
// performance monitoring code goes here
}
</code></pre>
<p>Will that code get removed by the compiler? This is the functionality I'd like. Basically I want to mimic the conditio... | [
{
"answer_id": 443615,
"author": "scottm",
"author_id": 53007,
"author_profile": "https://Stackoverflow.com/users/53007",
"pm_score": 4,
"selected": true,
"text": "<p>When you build in \"debug\" the preprocessor variable DEBUG is defined. So, you can do this:</p>\n\n<pre><code>public vo... | 2009/01/14 | [
"https://Stackoverflow.com/questions/443586",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18927/"
] | Say I have the following code snippet in c#
```
static const bool DO_PERFORMANCE_CODE = false;
if (DO_PERFORMANCE_CODE)
{
// performance monitoring code goes here
}
```
Will that code get removed by the compiler? This is the functionality I'd like. Basically I want to mimic the conditional compilation stuff in C... | When you build in "debug" the preprocessor variable DEBUG is defined. So, you can do this:
```
public void MyFunc()
{
//do release stuff
#if DEBUG
//do performance testing
#endif
//finish release stuff
}
```
and it will be ignored by the compiler when you switch to Release mode.
Alternatively, you can define your o... |
443,588 | <p>How can i count the number of stored procedures in my database and is it a bad practice to have too many stored procedures?</p>
| [
{
"answer_id": 443606,
"author": "Jason Punyon",
"author_id": 6212,
"author_profile": "https://Stackoverflow.com/users/6212",
"pm_score": 5,
"selected": true,
"text": "<pre><code>Select count(*) from sysobjects where xtype = 'P'\n</code></pre>\n"
},
{
"answer_id": 443608,
"au... | 2009/01/14 | [
"https://Stackoverflow.com/questions/443588",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/28647/"
] | How can i count the number of stored procedures in my database and is it a bad practice to have too many stored procedures? | ```
Select count(*) from sysobjects where xtype = 'P'
``` |
443,605 | <p>I am running a machine with SunOS and NO graphical enviroment. Does someone know how to change the keyboard layout from the console??</p>
<p>Thanks</p>
| [
{
"answer_id": 443686,
"author": "howlingmadhowie",
"author_id": 53971,
"author_profile": "https://Stackoverflow.com/users/53971",
"pm_score": 1,
"selected": false,
"text": "<p>have a look at the loadkeys command</p>\n"
},
{
"answer_id": 464306,
"author": "alanc",
"author... | 2009/01/14 | [
"https://Stackoverflow.com/questions/443605",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/366094/"
] | I am running a machine with SunOS and NO graphical enviroment. Does someone know how to change the keyboard layout from the console??
Thanks | Select your layout
==================
Type the following command to select your layout from a list:
```
kbd -s
```
If your language isn't in the list, have a look at this [blog post on how to create your own layout](http://iks.cs.ovgu.de/~elkner/keyboard/kbdhowto.html "blog post on how to create your own layout"). ... |
443,640 | <p>Running this code as a regular user throws HttpListenerException (access denied). Snippet runs ok as an administator</p>
<pre><code>class Program
{
static void Main(string[] args)
{
HttpListener listener = new HttpListener();
listener.Prefixes.Add("http://myip:8080/app/");
listener.... | [
{
"answer_id": 443793,
"author": "BQ.",
"author_id": 4632,
"author_profile": "https://Stackoverflow.com/users/4632",
"pm_score": 0,
"selected": false,
"text": "<p>Is that URI already registered on the system?</p>\n\n<p><a href=\"http://msdn.microsoft.com/en-us/library/system.net.httplist... | 2009/01/14 | [
"https://Stackoverflow.com/questions/443640",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14074/"
] | Running this code as a regular user throws HttpListenerException (access denied). Snippet runs ok as an administator
```
class Program
{
static void Main(string[] args)
{
HttpListener listener = new HttpListener();
listener.Prefixes.Add("http://myip:8080/app/");
listener.Start();
... | I do not understand why but here it is. It seems that the cause is that my network card is configured with 2 IPs.
if in the code i specify one of the ips (like i did in question above)
```
listener.Prefixes.Add("http://myip1:8080/app/");
```
then to avoid exception i need to register it with IP-bound weak wildcard
... |
443,642 | <p>I am going to start implementing some unit tests for a codebase that is a mix of managed and unmanaged C++. Can NUnit hack it with unmanaged code? Is there a better alternative?</p>
| [
{
"answer_id": 443715,
"author": "okutane",
"author_id": 53481,
"author_profile": "https://Stackoverflow.com/users/53481",
"pm_score": 4,
"selected": true,
"text": "<p>It's possible to use NUnit to test unmanaged code, example:</p>\n\n<pre><code>// Tests.h\n\n#pragma once\n\n#include <... | 2009/01/14 | [
"https://Stackoverflow.com/questions/443642",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2831/"
] | I am going to start implementing some unit tests for a codebase that is a mix of managed and unmanaged C++. Can NUnit hack it with unmanaged code? Is there a better alternative? | It's possible to use NUnit to test unmanaged code, example:
```
// Tests.h
#pragma once
#include <cmath>
using namespace System;
using namespace NUnit::Framework;
namespace Tests {
[TestFixture]
public ref class UnitTest
{
public:
UnitTest(void) {}
[Test]
void TestCos()
... |
443,648 | <p>I need to generate a list of sequential numbers. I know Ruby you can do 1..10 or PHP you can do range(1, 10). Anything like that in .Net already, or do I have to write it? Thanks.</p>
| [
{
"answer_id": 443678,
"author": "scottm",
"author_id": 53007,
"author_profile": "https://Stackoverflow.com/users/53007",
"pm_score": 1,
"selected": false,
"text": "<p>Would this work for you?</p>\n\n<pre><code>public List<int> Range(int start, int finish)\n{\n List<int> ret... | 2009/01/14 | [
"https://Stackoverflow.com/questions/443648",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/40/"
] | I need to generate a list of sequential numbers. I know Ruby you can do 1..10 or PHP you can do range(1, 10). Anything like that in .Net already, or do I have to write it? Thanks. | In C# (with .NET 3.0 or higher) this should do the job:
```
IEnumerable<int> myRange = Enumerable.Range(1, 10);
``` |
443,650 | <p>So, I have a decimalfield that can be 3 different values. In my view,
I pass in a dictionary of values that contains the appropriate decimal
values as keys.</p>
<pre><code>{% for item in booklist %}
{% for key, value in numvec.items %}
{{item.number}}
{% ifequals item.number {{key}} %}
... | [
{
"answer_id": 444142,
"author": "bchhun",
"author_id": 48500,
"author_profile": "https://Stackoverflow.com/users/48500",
"pm_score": 3,
"selected": true,
"text": "<p>According to <a href=\"http://docs.djangoproject.com/en/dev/ref/templates/builtins/#ifequal\" rel=\"nofollow noreferrer\"... | 2009/01/14 | [
"https://Stackoverflow.com/questions/443650",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | So, I have a decimalfield that can be 3 different values. In my view,
I pass in a dictionary of values that contains the appropriate decimal
values as keys.
```
{% for item in booklist %}
{% for key, value in numvec.items %}
{{item.number}}
{% ifequals item.number {{key}} %}
{{v... | According to [this](http://docs.djangoproject.com/en/dev/ref/templates/builtins/#ifequal), it seems you can only compare strings. I'd make my own [template tag](http://www.mechanicalgirl.com/view/custom-template-tags-in-django/) if I were you. |
443,662 | <p>Got a bit of a mind freeze at the moment.
I have the following syntax:-</p>
<pre><code> string[] repname = Thread.CurrentPrincipal.Identity.ToString().Split('\');
</code></pre>
<p>and I get an error on the split character. Can anyone advise on how I can do the split using the \ character as the delimiter?</... | [
{
"answer_id": 443674,
"author": "Maiku Mori",
"author_id": 54091,
"author_profile": "https://Stackoverflow.com/users/54091",
"pm_score": 5,
"selected": true,
"text": "<p>Use</p>\n\n<pre><code>Split('\\\\')\n</code></pre>\n\n<p>\"\\\" is an <a href=\"http://en.wikipedia.org/wiki/Escape_c... | 2009/01/14 | [
"https://Stackoverflow.com/questions/443662",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/35441/"
] | Got a bit of a mind freeze at the moment.
I have the following syntax:-
```
string[] repname = Thread.CurrentPrincipal.Identity.ToString().Split('\');
```
and I get an error on the split character. Can anyone advise on how I can do the split using the \ character as the delimiter?
Cheers | Use
```
Split('\\')
```
"\" is an [escape character](http://en.wikipedia.org/wiki/Escape_character). |
443,683 | <p>For example I have a simple class like</p>
<pre><code>public class Person{
public int Age {get;set;}
public string Name {get;set;}
}
</code></pre>
<p>I need to make a method that takes any class and spits out values of properties set in the object as a string in format "Age:35;Name:John Doe;"</p>
<p>I a... | [
{
"answer_id": 443728,
"author": "Tom Anderson",
"author_id": 13502,
"author_profile": "https://Stackoverflow.com/users/13502",
"pm_score": 2,
"selected": false,
"text": "<p>Here is a quick implementation.</p>\n\n<pre><code> public static string SplitNameValuePairs(object value)\n ... | 2009/01/14 | [
"https://Stackoverflow.com/questions/443683",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/37494/"
] | For example I have a simple class like
```
public class Person{
public int Age {get;set;}
public string Name {get;set;}
}
```
I need to make a method that takes any class and spits out values of properties set in the object as a string in format "Age:35;Name:John Doe;"
I am looking for a method signature o... | That have protection from crashes when property have an indexer defined and also it output only instance properties (no static).
```
private static string SplitNameValuePairs<T>(T value)
{
StringBuilder sb = new StringBuilder();
foreach (PropertyInfo property in typeof(T).GetProperties(Binding... |
443,695 | <p>I have a tree that consists of several objects, where each object has a name (<code>string</code>), id (<code>int</code>) and possibly an array of children that are of the same type. How do I go through the entire tree and print out all of the ids and names?</p>
<p>I'm new to programming and frankly, I'm having tro... | [
{
"answer_id": 443707,
"author": "ChrisW",
"author_id": 49942,
"author_profile": "https://Stackoverflow.com/users/49942",
"pm_score": 7,
"selected": true,
"text": "<p>An algorithm which uses recursion goes like this:</p>\n\n<pre><code>printNode(Node node)\n{\n printTitle(node.title)\n ... | 2009/01/14 | [
"https://Stackoverflow.com/questions/443695",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/55072/"
] | I have a tree that consists of several objects, where each object has a name (`string`), id (`int`) and possibly an array of children that are of the same type. How do I go through the entire tree and print out all of the ids and names?
I'm new to programming and frankly, I'm having trouble wrapping my head around thi... | An algorithm which uses recursion goes like this:
```
printNode(Node node)
{
printTitle(node.title)
foreach (Node child in node.children)
{
printNode(child); //<-- recursive
}
}
```
Here's a version which also keeps track of how deeply nested the recursion is (i.e. whether we're printing children of the ... |
443,700 | <p>I have a fixed width DIV containing a table with many columns, and need to allow the user to scroll the table horizontally within the DIV.</p>
<p>This needs to work on IE6 and IE7 only (internal client application).</p>
<p>The following works in IE7:</p>
<pre><code>overflow-x: scroll;
</code></pre>
<p>Can anyone... | [
{
"answer_id": 443720,
"author": "Sampson",
"author_id": 54680,
"author_profile": "https://Stackoverflow.com/users/54680",
"pm_score": 9,
"selected": true,
"text": "<p>The solution is fairly straight forward. To ensure that we don't impact the width of the cells in the table, we'll turn ... | 2009/01/14 | [
"https://Stackoverflow.com/questions/443700",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/39709/"
] | I have a fixed width DIV containing a table with many columns, and need to allow the user to scroll the table horizontally within the DIV.
This needs to work on IE6 and IE7 only (internal client application).
The following works in IE7:
```
overflow-x: scroll;
```
Can anyone help with a solution that works in IE6 ... | The solution is fairly straight forward. To ensure that we don't impact the width of the cells in the table, we'll turn off *white-space*. To ensure we get a horizontal scroll bar, we'll turn on *overflow-x*. And that's pretty much it:
```css
.container {
width: 30em;
overflow-x: auto;
white-space: nowrap;... |
443,708 | <p>Is there a way to pass a call back function in a Java method?</p>
<p>The behavior I'm trying to mimic is a .Net Delegate being passed to a function.</p>
<p>I've seen people suggesting creating a separate object but that seems overkill, however I am aware that sometimes overkill is the only way to do things.</p>
| [
{
"answer_id": 443741,
"author": "Gant",
"author_id": 12460,
"author_profile": "https://Stackoverflow.com/users/12460",
"pm_score": 8,
"selected": true,
"text": "<p>If you mean somthing like .NET anonymous delegate, I think Java's anonymous class can be used as well. </p>\n\n<pre><code>p... | 2009/01/14 | [
"https://Stackoverflow.com/questions/443708",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20400/"
] | Is there a way to pass a call back function in a Java method?
The behavior I'm trying to mimic is a .Net Delegate being passed to a function.
I've seen people suggesting creating a separate object but that seems overkill, however I am aware that sometimes overkill is the only way to do things. | If you mean somthing like .NET anonymous delegate, I think Java's anonymous class can be used as well.
```
public class Main {
public interface Visitor{
int doJob(int a, int b);
}
public static void main(String[] args) {
Visitor adder = new Visitor(){
public int doJob(int a, ... |
443,712 | <p>I'm looking for an algorithm which can take two sets of integers (both positive and negative) and find subsets within each that have the same sum.</p>
<p>The problem is similar to the <a href="http://en.wikipedia.org/wiki/Subset-sum_problem" rel="nofollow noreferrer">subset sum problem</a> except that I'm looking f... | [
{
"answer_id": 443739,
"author": "Meidan Alon",
"author_id": 19956,
"author_profile": "https://Stackoverflow.com/users/19956",
"pm_score": 0,
"selected": false,
"text": "<p>subset sum is Np-complete and you can polynomially reduce your problem to it, so your problem is NP-complete too.</... | 2009/01/14 | [
"https://Stackoverflow.com/questions/443712",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/55074/"
] | I'm looking for an algorithm which can take two sets of integers (both positive and negative) and find subsets within each that have the same sum.
The problem is similar to the [subset sum problem](http://en.wikipedia.org/wiki/Subset-sum_problem) except that I'm looking for subsets on both sides.
Here's an example:
... | What others have said is true:
1. This problem is NP-complete. An easy reduction is to usual subset-sum. You can show this by noting that a subset of A sums to a subset of B (not both empty) only if a non-empty subset of A union (-B) sums to zero.
2. This problem is only weakly NP-complete, in that it's polynomial in ... |
443,724 | <p>I am trying to get some xpath from xsl variable using xsl ver 1.0 .
That’s my variable:</p>
<pre><code> <xsl:variable name ="myVar">
<RefData RefTag="test1" bbb="false" />
<RefData RefTag="test2" bbb="false" />
<RefData RefTag="test3" bbb="false" />
<RefD... | [
{
"answer_id": 444125,
"author": "Azat Razetdinov",
"author_id": 9649,
"author_profile": "https://Stackoverflow.com/users/9649",
"pm_score": 1,
"selected": false,
"text": "<pre><code><xsl:variable name=\"myVariable\" select=\"msxsl:node-set($myVar)\"/>\n</code></pre>\n\n<p>You can ... | 2009/01/14 | [
"https://Stackoverflow.com/questions/443724",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/50435/"
] | I am trying to get some xpath from xsl variable using xsl ver 1.0 .
That’s my variable:
```
<xsl:variable name ="myVar">
<RefData RefTag="test1" bbb="false" />
<RefData RefTag="test2" bbb="false" />
<RefData RefTag="test3" bbb="false" />
<RefData RefTag="test4" bbb="true" />
... | **One solution that doesn't need the xxx:node-set() extension** is the following:
```
<xsl:stylesheet version="1.0"
xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:output method="text"/>
<!-- -->
<xsl:variable name ="myVar">
<RefData RefTag="test1" bbb="f... |
443,730 | <p>I was writing a toString() for a class in Java the other day by manually writing out each element of the class to a String and it occurred to me that using reflection it might be possible to create a generic toString() method that could work on ALL classes. I.E. it would figure out the field names and values and sen... | [
{
"answer_id": 443768,
"author": "krosenvold",
"author_id": 23691,
"author_profile": "https://Stackoverflow.com/users/23691",
"pm_score": 8,
"selected": true,
"text": "<p>Apache commons-lang <a href=\"http://commons.apache.org/proper/commons-lang//apidocs/org/apache/commons/lang3/builder... | 2009/01/14 | [
"https://Stackoverflow.com/questions/443730",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20774/"
] | I was writing a toString() for a class in Java the other day by manually writing out each element of the class to a String and it occurred to me that using reflection it might be possible to create a generic toString() method that could work on ALL classes. I.E. it would figure out the field names and values and send t... | Apache commons-lang [ReflectionToStringBuilder](http://commons.apache.org/proper/commons-lang//apidocs/org/apache/commons/lang3/builder/ReflectionToStringBuilder.html) does this for you.
```
import org.apache.commons.lang3.builder.ReflectionToStringBuilder
// your code goes here
public String toString() {
return... |
443,737 | <p>I have a file called <strong>hellowf.cs</strong></p>
<pre><code>class MyFirstApp {
static void Main() {
System.Windows.Forms.MessageBox.Show("Hello, Mono+WinForms!");
}
}
</code></pre>
<p>On Ubuntu 8.10, I do the following</p>
<pre><code>gmcs hellowf.cs -r:System.Drawing.dll -r:System.Windows.Forms.dll
mo... | [
{
"answer_id": 443758,
"author": "Tom Anderson",
"author_id": 13502,
"author_profile": "https://Stackoverflow.com/users/13502",
"pm_score": 0,
"selected": false,
"text": "<p>stick an @ in front of the \"Hello, Mono+WinForms!\" and see if it still happens.</p>\n"
},
{
"answer_id":... | 2009/01/14 | [
"https://Stackoverflow.com/questions/443737",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/48486/"
] | I have a file called **hellowf.cs**
```
class MyFirstApp {
static void Main() {
System.Windows.Forms.MessageBox.Show("Hello, Mono+WinForms!");
}
}
```
On Ubuntu 8.10, I do the following
```
gmcs hellowf.cs -r:System.Drawing.dll -r:System.Windows.Forms.dll
mono hellowf.exe
```
... and it looks like this:
... | Finally I have found a workaround. This seems to be a bug in Mono related to font rendering. It happens when "**Full**" hinting is turned on. I usually have it that way. Changing it to "**Slight**" or "**Medium**" in `System->Preferences->Appearance->Fonts->Details` fixes the problem. Thanks for the help! |
443,745 | <p>Git has a much-touted(?) octopus-merge capability that can merge many heads into one.</p>
<p>But is there something that would do just the opposite, make several simultaneous branches out of one node?</p>
<p>Let's assume that I have a bunch of code for a project, and I just started using Git. Some of the features ... | [
{
"answer_id": 444053,
"author": "Paul",
"author_id": 23356,
"author_profile": "https://Stackoverflow.com/users/23356",
"pm_score": 1,
"selected": false,
"text": "<p>Since you just started using Git, it would be easier to start again and only commit your 'complete' code to the Master bra... | 2009/01/14 | [
"https://Stackoverflow.com/questions/443745",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2238/"
] | Git has a much-touted(?) octopus-merge capability that can merge many heads into one.
But is there something that would do just the opposite, make several simultaneous branches out of one node?
Let's assume that I have a bunch of code for a project, and I just started using Git. Some of the features are complete in t... | **Side note:** the *octopus merge* and the *octopus branchpoint* scenarios are very different. Please remember that pointers in DAG (directed acyclic graph) of commits point from child (newer commit) to parent or parents. So in the case of octopus *merge* you have commit (commit object) which has more than two parents;... |
443,775 | <p>I am doing something like this:</p>
<pre><code>class Class(object):
def __init__(self):
self.var=#new instance name string#
</code></pre>
<p>How do I make the __ init __ method of my instance to use the instance name string for 'c'? Say in case:</p>
<pre><code>c=Class()
</code></pre>
<p>I want c.v... | [
{
"answer_id": 443833,
"author": "Douglas Leeder",
"author_id": 3978,
"author_profile": "https://Stackoverflow.com/users/3978",
"pm_score": 0,
"selected": false,
"text": "<p>That isn't possible. You seem to be confusing variables and objects.</p>\n\n<p>In any case there may well not be a... | 2009/01/14 | [
"https://Stackoverflow.com/questions/443775",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/85185/"
] | I am doing something like this:
```
class Class(object):
def __init__(self):
self.var=#new instance name string#
```
How do I make the \_\_ init \_\_ method of my instance to use the instance name string for 'c'? Say in case:
```
c=Class()
```
I want c.var equal to 'c'.
Thanks for your replies, I ... | To persist data objects you need to use the database record's unique ID.
**pesudo code because I don't know what database module you're using**
```
import db # assume this is your db module
class Class(object):
def __init__(self):
self.id = None
self.name = None
def get_by_id(self, id):
... |
443,813 | <p>I've got some code which draws data from an xml file but it seems to have randomly starting throwing;</p>
<pre><code>Traceback (most recent call last):
File "C:\Users\mike\Documents\python\arl xml\turn 24 reader", line 52, in <module>
unitCount = getText(evoNode.getElementsByTagName("count")[0].childN... | [
{
"answer_id": 443845,
"author": "gimel",
"author_id": 6491,
"author_profile": "https://Stackoverflow.com/users/6491",
"pm_score": 3,
"selected": true,
"text": "<p>A simple idea: check if <code>evoNode.getElementsByTagName(\"count\")</code> returns a non-empty list:</p>\n\n<pre><code>cou... | 2009/01/14 | [
"https://Stackoverflow.com/questions/443813",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/33061/"
] | I've got some code which draws data from an xml file but it seems to have randomly starting throwing;
```
Traceback (most recent call last):
File "C:\Users\mike\Documents\python\arl xml\turn 24 reader", line 52, in <module>
unitCount = getText(evoNode.getElementsByTagName("count")[0].childNodes)
IndexError: li... | A simple idea: check if `evoNode.getElementsByTagName("count")` returns a non-empty list:
```
counts = evoNode.getElementsByTagName("count")
if counts:
unitCount = getText(counts[0].childNodes)
```
Of course, the check should be applied to all the lists retrieved by your code.
One Other thing, you iterate using... |
443,830 | <p>I have the folowing scenario:</p>
<p>www.somedomain.com -> this points to a folder on a shared host, say /MyFolder1
www.otherdomain.com -> this points to another folder on the same shared host, say /MyFolder2</p>
<p>With asp.net mvc my urls get mapped to:</p>
<p>www.somedomain.com/MyFolder1/Action
www.somedomain.... | [
{
"answer_id": 444205,
"author": "Trevor de Koekkoek",
"author_id": 41783,
"author_profile": "https://Stackoverflow.com/users/41783",
"pm_score": 1,
"selected": false,
"text": "<p>The best way to handle this IMO is to use rewriting at the IIS level. I just did this on a site using IIS 7... | 2009/01/14 | [
"https://Stackoverflow.com/questions/443830",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | I have the folowing scenario:
www.somedomain.com -> this points to a folder on a shared host, say /MyFolder1
www.otherdomain.com -> this points to another folder on the same shared host, say /MyFolder2
With asp.net mvc my urls get mapped to:
www.somedomain.com/MyFolder1/Action
www.somedomain.com/MyFolder2/Action
I ... | The best way to handle this IMO is to use rewriting at the IIS level. I just did this on a site using IIS 7 URL Rewrite. If you don't have this module installed on your host provider, you can try to use one of the other URL rewriting tools. But, for example on DiscountASP you can use IIS 7 URL rewrite.
First you need ... |
443,854 | <p>I'm working with a WebView. If I place this call in my <code>-awakeFromNib</code>:</p>
<pre><code>[myWebView setMainFrameURL:@"http://www.google.com"];
</code></pre>
<p>I get the behavior I want. Google's homepage displays in my WebView. But, I need to set the main frame's URL in another method from a mutable arra... | [
{
"answer_id": 443947,
"author": "Marc Charbonneau",
"author_id": 35136,
"author_profile": "https://Stackoverflow.com/users/35136",
"pm_score": 0,
"selected": false,
"text": "<p>Have you tried setting a breakpoint on your action method to check that both <code>myWebView</code> and <code>... | 2009/01/14 | [
"https://Stackoverflow.com/questions/443854",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/34386/"
] | I'm working with a WebView. If I place this call in my `-awakeFromNib`:
```
[myWebView setMainFrameURL:@"http://www.google.com"];
```
I get the behavior I want. Google's homepage displays in my WebView. But, I need to set the main frame's URL in another method from a mutable array containing NSStrings.
This method ... | I figured out the problem. The WebView is an IBOutlet. I was doing the method call that was giving me problems before -awakeFromNib. Moved that one line to -awakeFromNib and it's sorted now. Thanks for the input. +1 to my list of newbie posts. |
443,863 | <p>I have a set of data that needs to be displayed as a crosstab in Cognos. Example data includes</p>
<pre>
ID, Month, Year, State
1, 10, 2008, 25
2, 10, 2008, 26
</pre>
<p>The problem is that in the crosstab, the month column is duplicated for each row instead of using the same column for the month.</p>
... | [
{
"answer_id": 528762,
"author": "jason saldo",
"author_id": 1293,
"author_profile": "https://Stackoverflow.com/users/1293",
"pm_score": 0,
"selected": false,
"text": "<p>I'm not a Cognos guy but it sounds like your detail is not wrapped in an aggregate function like SUM(x).</p>\n"
},
... | 2009/01/14 | [
"https://Stackoverflow.com/questions/443863",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6013/"
] | I have a set of data that needs to be displayed as a crosstab in Cognos. Example data includes
```
ID, Month, Year, State
1, 10, 2008, 25
2, 10, 2008, 26
```
The problem is that in the crosstab, the month column is duplicated for each row instead of using the same column for the month.
Example:
```
I... | Reworked the report after working on the view to keep the problem from occurring again. |
443,883 | <p>Is the any difference between writing</p>
<pre>
{$_GET['id']}
</pre>
<p>and</p>
<p>
'".$_GET['id']."'
<p>in a sql statement? both works the same</p>
| [
{
"answer_id": 443900,
"author": "okoman",
"author_id": 35903,
"author_profile": "https://Stackoverflow.com/users/35903",
"pm_score": -1,
"selected": false,
"text": "<p>If you use a variable - especially an associative array - in a string, you can be quite sure that it will lead to error... | 2009/01/14 | [
"https://Stackoverflow.com/questions/443883",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | Is the any difference between writing
```
{$_GET['id']}
```
and
'".$\_GET['id']."'
in a sql statement? both works the same | Using either of these directly in a SQL statement is a VERY BAD IDEA. It allows for SQL injections. Be sure to sanitize your inputs using something like `mysql_real_escape_string`.
The main difference between the two is that the top can only be used inside a string that uses double quotes. The bottom, however, can be ... |
443,885 | <p>Just want to know what's the common way to react on events in python. There are several ways in other languages like callback functions, delegates, listener-structures and so on.
Is there a common way? Which default language concepts or additional modules are there and which can you recommend?</p>
| [
{
"answer_id": 443934,
"author": "David Locke",
"author_id": 1447,
"author_profile": "https://Stackoverflow.com/users/1447",
"pm_score": 0,
"selected": false,
"text": "<p>Personally, I've only seen callbacks used. However, I haven't seen that much event driven python code so YMMV.</p>\n... | 2009/01/14 | [
"https://Stackoverflow.com/questions/443885",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/35903/"
] | Just want to know what's the common way to react on events in python. There are several ways in other languages like callback functions, delegates, listener-structures and so on.
Is there a common way? Which default language concepts or additional modules are there and which can you recommend? | Personally I don't see a difference between callbacks, listeners, and delegates.
The [observer pattern](http://en.wikipedia.org/wiki/Observer_pattern) (a.k.a listeners, a.k.a "multiple callbacks") is easy to implement - just hold a list of observers, and add or remove callables from it. These callables can be function... |
443,895 | <p>I'm using Zend Framework 1.7.2, MySQL and the MySQLi PDO adapter. I would like to call multiple stored procedures during a given action. I've found that on Windows there is a problem calling multiple stored procedures. If you try it you get the following error message:</p>
<blockquote>
<p>SQLSTATE[HY000]: Gene... | [
{
"answer_id": 472577,
"author": "waney",
"author_id": 58123,
"author_profile": "https://Stackoverflow.com/users/58123",
"pm_score": 3,
"selected": true,
"text": "<p>I has same errors when called queries like this(variables to use in next query)</p>\n\n<pre><code>$db->query(\"SET @cur... | 2009/01/14 | [
"https://Stackoverflow.com/questions/443895",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/43816/"
] | I'm using Zend Framework 1.7.2, MySQL and the MySQLi PDO adapter. I would like to call multiple stored procedures during a given action. I've found that on Windows there is a problem calling multiple stored procedures. If you try it you get the following error message:
>
> SQLSTATE[HY000]: General error: 2014
> Cann... | I has same errors when called queries like this(variables to use in next query)
```
$db->query("SET @curr = 0.0;");
```
To fix this I've changed my config file to
```
'database' => array(
'adapter' => 'mysqli',
``` |
443,909 | <p>I am having a few issues when people are trying to access a MySQL database and they are trying to update tables with the same information.</p>
<p>I have a webpage written using PHP. In this webpage is a query to check if certain data has been entered into the database. If the data hasn't, then i proceed to insert i... | [
{
"answer_id": 443919,
"author": "Ross",
"author_id": 2025,
"author_profile": "https://Stackoverflow.com/users/2025",
"pm_score": 3,
"selected": true,
"text": "<p>You're looking for <code>LOCK</code>.</p>\n\n<p><a href=\"http://dev.mysql.com/doc/refman/5.0/en/lock-tables.html\" rel=\"nof... | 2009/01/14 | [
"https://Stackoverflow.com/questions/443909",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13227/"
] | I am having a few issues when people are trying to access a MySQL database and they are trying to update tables with the same information.
I have a webpage written using PHP. In this webpage is a query to check if certain data has been entered into the database. If the data hasn't, then i proceed to insert it. The tro... | You're looking for `LOCK`.
<http://dev.mysql.com/doc/refman/5.0/en/lock-tables.html>
This can be run as a simple `mysql_query` (or `MySQLi::query/prepare`).
I'd say it's better to lock specific tables (although you can probably try `LOCK TABLES *`) that need to be locked rather than the whole database - as nothing w... |
443,914 | <p>What conventions (if any) do you use for indenting XSL code?</p>
<ul>
<li>how do you deal with really long, complicated XPaths</li>
<li>can you plug them into your XML editor of choice?</li>
<li>is there some open source code that does the job well?</li>
</ul>
<p>For some background, I use nxml-mode in Emacs. For... | [
{
"answer_id": 443925,
"author": "Andrzej Doyle",
"author_id": 45664,
"author_profile": "https://Stackoverflow.com/users/45664",
"pm_score": 1,
"selected": false,
"text": "<p>The concept of having tests, according to TDD, is that you test the way things are meant to work <em>now</em>. W... | 2009/01/14 | [
"https://Stackoverflow.com/questions/443914",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/48641/"
] | What conventions (if any) do you use for indenting XSL code?
* how do you deal with really long, complicated XPaths
* can you plug them into your XML editor of choice?
* is there some open source code that does the job well?
For some background, I use nxml-mode in Emacs. For the most part its OK and you can configure... | I write tests that call my dal code and after I check if the inserts/updates/deletes actually occurred, so called state tests. These are pr definition not Units test but rather integration tests, but they have actually helped me many times doing database changes. Over the time I have more and better tests and even bigg... |
443,921 | <p>I have a Winforms project with a bunch of User controls. I'd like the user control to move itself to be at the 1,1 position relative to its container (whether it's a form or a Panel control). And resize itself to be able to fit half the container.</p>
<p>What event can I respond to in the UserControl to be able t... | [
{
"answer_id": 444083,
"author": "aranasaurus",
"author_id": 52561,
"author_profile": "https://Stackoverflow.com/users/52561",
"pm_score": 0,
"selected": false,
"text": "<p>The Paint event should work, unless I'm missing something.</p>\n"
},
{
"answer_id": 444357,
"author": "... | 2009/01/14 | [
"https://Stackoverflow.com/questions/443921",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9382/"
] | I have a Winforms project with a bunch of User controls. I'd like the user control to move itself to be at the 1,1 position relative to its container (whether it's a form or a Panel control). And resize itself to be able to fit half the container.
What event can I respond to in the UserControl to be able to do this wi... | You could use the basic `Load` event.
The code could be like this:
```
private void UserControl1_Load(object sender, EventArgs e)
{
Control parent = this.Parent;
if (parent != null)
{
this.Location = new Point(1, 1);
this.Width = (parent.Width / 2);
this.Height = (parent.Height / 2... |
443,929 | <p>I have a log in page where I valid my users and based on this validation I store their user info in a session variable so I can access it at any time. To do this I am trying to store an instance of one of my dbml generated classes "UserInfo". So I populate the class and then store it in a session variable I call "... | [
{
"answer_id": 443960,
"author": "Chris Simpson",
"author_id": 28896,
"author_profile": "https://Stackoverflow.com/users/28896",
"pm_score": 2,
"selected": true,
"text": "<p>Sounds more like an issue with the DAL than the session object. Can you verify that the userID passed each time is... | 2009/01/14 | [
"https://Stackoverflow.com/questions/443929",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20748/"
] | I have a log in page where I valid my users and based on this validation I store their user info in a session variable so I can access it at any time. To do this I am trying to store an instance of one of my dbml generated classes "UserInfo". So I populate the class and then store it in a session variable I call "user"... | Sounds more like an issue with the DAL than the session object. Can you verify that the userID passed each time is different and the RetrieveUser function is using the passed value and not a static one? |
443,931 | <p>in delphi7 i have a function that i need to return a array as a result type b</p>
<p>"function createsbox(key:tkey):array[0..255] of byte;" this is not allowed it is expecting a "identifyer expected but array found" is the error throw up. seems to work fine if i declare a record type of array but it seems pointless... | [
{
"answer_id": 443957,
"author": "Rob Kennedy",
"author_id": 33732,
"author_profile": "https://Stackoverflow.com/users/33732",
"pm_score": 5,
"selected": true,
"text": "<p>The issue is that you're not allowed to create a new type in a function declaration. But that's what you're doing wh... | 2009/01/14 | [
"https://Stackoverflow.com/questions/443931",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/53915/"
] | in delphi7 i have a function that i need to return a array as a result type b
"function createsbox(key:tkey):array[0..255] of byte;" this is not allowed it is expecting a "identifyer expected but array found" is the error throw up. seems to work fine if i declare a record type of array but it seems pointless to do thi... | The issue is that you're not allowed to create a new type in a function declaration. But that's what you're doing when you specify the return type as `array[0..255] of Byte`. Instead, declare a named type, and then use it for the return type:
```
type
TSBox = array[0..255] of Byte;
function CreateSBox(const Key: TK... |
443,935 | <p>I have a lot of fixed-size collections of numbers where each entry can be accessed with a constant. Naturally this seems to point to arrays and enums:</p>
<pre><code>enum StatType {
Foo = 0,
Bar
// ...
}
float[] stats = new float[...];
stats[StatType.Foo] = 1.23f;
</code></pre>
<p>The problem with thi... | [
{
"answer_id": 443983,
"author": "Steven Behnke",
"author_id": 42588,
"author_profile": "https://Stackoverflow.com/users/42588",
"pm_score": 0,
"selected": false,
"text": "<p>I don't believe there is any way to add an implicit conversion operator to an enum, unfortunately. So you'll hav... | 2009/01/14 | [
"https://Stackoverflow.com/questions/443935",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/54825/"
] | I have a lot of fixed-size collections of numbers where each entry can be accessed with a constant. Naturally this seems to point to arrays and enums:
```
enum StatType {
Foo = 0,
Bar
// ...
}
float[] stats = new float[...];
stats[StatType.Foo] = 1.23f;
```
The problem with this is of course that you ca... | I suspect you *may* be able to make it a bit faster by compiling a delegate to do the conversion for you, such that it doesn't require boxing and unboxing. An expression tree may well be the simplest way of doing that if you're using .NET 3.5. (You'd use that in your EnumArray example.)
Personally I'd be very tempted ... |
443,936 | <p>That's pretty much the whole question. I've installed Visual C# 2008 Express on a clean Windows XP Pro SP3 machine, started a new Windows Forms project, double-clicked the form to create a Form1_Load method, then typed:</p>
<pre><code>StringBuilder SB;
SB = new StringBuilder("test");
SB.Chars
</code></pre>
<p>but ... | [
{
"answer_id": 443956,
"author": "Jon Skeet",
"author_id": 22656,
"author_profile": "https://Stackoverflow.com/users/22656",
"pm_score": 3,
"selected": true,
"text": "<p>It's the indexer, which you reference with <code>foo[bar]</code> syntax instead of <code>foo.Chars(bar)</code>:</p>\n\... | 2009/01/14 | [
"https://Stackoverflow.com/questions/443936",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/42905/"
] | That's pretty much the whole question. I've installed Visual C# 2008 Express on a clean Windows XP Pro SP3 machine, started a new Windows Forms project, double-clicked the form to create a Form1\_Load method, then typed:
```
StringBuilder SB;
SB = new StringBuilder("test");
SB.Chars
```
but Chars doesn't appear on t... | It's the indexer, which you reference with `foo[bar]` syntax instead of `foo.Chars(bar)`:
```
StringBuilder sb = new StringBuilder("Hello");
char c = sb[1]; // c='e'
```
C# doesn't use the names of indexers, nor can it use multiple indexers with the same parameters which are named differently (created in a different... |
443,955 | <p>Is it possible to use NGen with ClickOnce deployment?</p>
| [
{
"answer_id": 443993,
"author": "liggett78",
"author_id": 19762,
"author_profile": "https://Stackoverflow.com/users/19762",
"pm_score": 2,
"selected": false,
"text": "<p>No, you can not. See <a href=\"http://social.msdn.microsoft.com/Forums/en-US/clr/thread/a41b62c5-bdee-4bd5-9811-15a35... | 2009/01/14 | [
"https://Stackoverflow.com/questions/443955",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5362/"
] | Is it possible to use NGen with ClickOnce deployment? | Actually you can use NGEN and clickone, but you are going to need to run the NGEN after the clickonce installation has happened, since NGEN is part of the .NET installation (for 3.5 you should refer to the 2.0 installation).
Here is an example, I think it is generic enough for you to use it without changing or doing v... |
443,967 | <p>I have a long sequence of hex digits in a string, such as </p>
<blockquote>
<p>000000000000484240FA063DE5D0B744ADBED63A81FAEA390000C8428640A43D5005BD44</p>
</blockquote>
<p>only much longer, several kilobytes. Is there a builtin way to convert this to a bytes object in python 2.6/3?</p>
| [
{
"answer_id": 443985,
"author": "Crescent Fresh",
"author_id": 45433,
"author_profile": "https://Stackoverflow.com/users/45433",
"pm_score": 5,
"selected": false,
"text": "<p>Try the <a href=\"http://doc.astro-wise.org/binascii.html#-unhexlify\" rel=\"noreferrer\">binascii module</a></p... | 2009/01/14 | [
"https://Stackoverflow.com/questions/443967",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/44743/"
] | I have a long sequence of hex digits in a string, such as
>
> 000000000000484240FA063DE5D0B744ADBED63A81FAEA390000C8428640A43D5005BD44
>
>
>
only much longer, several kilobytes. Is there a builtin way to convert this to a bytes object in python 2.6/3? | ```
result = bytes.fromhex(some_hex_string)
``` |
443,980 | <p>Why can't enum's constructor access static fields and methods? This is perfectly valid with a class, but is not allowed with an enum.</p>
<p>What I'm trying to do is store my enum instances in a static Map. Consider this example code which allows lookup by abbreivation:</p>
<pre><code>public enum Day {
Sunday(... | [
{
"answer_id": 444000,
"author": "Jon Skeet",
"author_id": 22656,
"author_profile": "https://Stackoverflow.com/users/22656",
"pm_score": 8,
"selected": true,
"text": "<p>The constructor is called before the static fields have all been initialized, because the static fields (including tho... | 2009/01/14 | [
"https://Stackoverflow.com/questions/443980",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/24396/"
] | Why can't enum's constructor access static fields and methods? This is perfectly valid with a class, but is not allowed with an enum.
What I'm trying to do is store my enum instances in a static Map. Consider this example code which allows lookup by abbreivation:
```
public enum Day {
Sunday("Sun"), Monday("Mon")... | The constructor is called before the static fields have all been initialized, because the static fields (including those representing the enum values) are initialized in textual order, and the enum values always come before the other fields. Note that in your class example you haven't shown where ABBREV\_MAP is initial... |
443,991 | <p>I'd like to parse rss feeds and download <a href="https://blog.stackoverflow.com/category/podcasts/">podcasts</a> on my ReadyNas which is running 24/7 anyway.</p>
<p>So I'm thinking about having a shell script checking periodically the feeds and spawning wget to download the files.</p>
<p>What is the best way to do ... | [
{
"answer_id": 443998,
"author": "Oli",
"author_id": 15296,
"author_profile": "https://Stackoverflow.com/users/15296",
"pm_score": 1,
"selected": false,
"text": "<p>I read about <a href=\"http://xmlstar.sourceforge.net/\" rel=\"nofollow noreferrer\">XMLStartlet</a> <a href=\"http://codes... | 2009/01/14 | [
"https://Stackoverflow.com/questions/443991",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/15296/"
] | I'd like to parse rss feeds and download [podcasts](https://blog.stackoverflow.com/category/podcasts/) on my ReadyNas which is running 24/7 anyway.
So I'm thinking about having a shell script checking periodically the feeds and spawning wget to download the files.
What is the best way to do the parsing?
Thanks! | Sometimes a simple one liner with shell standard commands can be enough for this:
```
wget -q -O- "http://www.rss-specifications.com/rss-podcast.xml" | grep -o '<enclosure url="[^"]*' | grep -o '[^"]*$' | xargs wget -c
```
Sure this does not work in every case, but it's often good enough. |
443,996 | <p>I have scanned 'the Google' and have not found the definitive answer on whether the Iron* languages (any or all) will end up with Attribute support..</p>
<p>Anyone?</p>
<p>Thanks - Jon</p>
| [
{
"answer_id": 443998,
"author": "Oli",
"author_id": 15296,
"author_profile": "https://Stackoverflow.com/users/15296",
"pm_score": 1,
"selected": false,
"text": "<p>I read about <a href=\"http://xmlstar.sourceforge.net/\" rel=\"nofollow noreferrer\">XMLStartlet</a> <a href=\"http://codes... | 2009/01/14 | [
"https://Stackoverflow.com/questions/443996",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13117/"
] | I have scanned 'the Google' and have not found the definitive answer on whether the Iron\* languages (any or all) will end up with Attribute support..
Anyone?
Thanks - Jon | Sometimes a simple one liner with shell standard commands can be enough for this:
```
wget -q -O- "http://www.rss-specifications.com/rss-podcast.xml" | grep -o '<enclosure url="[^"]*' | grep -o '[^"]*$' | xargs wget -c
```
Sure this does not work in every case, but it's often good enough. |
444,010 | <p>I've got some RESTful services running in a pure WCF context (i.e. ASP.NET compatibility is not enabled, and thus there is no <code>HttpContext.Current</code> object available).</p>
<p>The URLs to the services are rewritten at the start of the request using an <code>IHttpModule</code> (which at that point does have... | [
{
"answer_id": 517405,
"author": "christophercotton",
"author_id": 62984,
"author_profile": "https://Stackoverflow.com/users/62984",
"pm_score": 6,
"selected": true,
"text": "<p>You can get the endpoint currently targeted and the Uri for it by doing:</p>\n\n<pre><code>OperationContext.Cu... | 2009/01/14 | [
"https://Stackoverflow.com/questions/444010",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13552/"
] | I've got some RESTful services running in a pure WCF context (i.e. ASP.NET compatibility is not enabled, and thus there is no `HttpContext.Current` object available).
The URLs to the services are rewritten at the start of the request using an `IHttpModule` (which at that point does have an `HttpContext` and rewrites i... | You can get the endpoint currently targeted and the Uri for it by doing:
```
OperationContext.Current.RequestContext.RequestMessage.Headers.To
```
which I think is the same thing as:
```
OperationContext.Current.IncomingMessageHeaders.To
```
This is a `System.Uri` object, and I believe you can just get the `Origi... |
444,012 | <p>I'm trying to run the get-service command on a remote machine in powershell. After doing some research, it appears this is only possilbe n powershell 2 CTP, which I cannot use as I need to use the version of powershell installed with exchange, which is usualy 1. It seems the -computerName switch is only availible in... | [
{
"answer_id": 444047,
"author": "EBGreen",
"author_id": 1358,
"author_profile": "https://Stackoverflow.com/users/1358",
"pm_score": 4,
"selected": true,
"text": "<p>Well, you can go directly to WMI the get the service information.</p>\n\n<pre><code>gwmi Win32_Service -computername FOO\n... | 2009/01/14 | [
"https://Stackoverflow.com/questions/444012",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8768/"
] | I'm trying to run the get-service command on a remote machine in powershell. After doing some research, it appears this is only possilbe n powershell 2 CTP, which I cannot use as I need to use the version of powershell installed with exchange, which is usualy 1. It seems the -computerName switch is only availible in ge... | Well, you can go directly to WMI the get the service information.
```
gwmi Win32_Service -computername FOO
``` |
444,016 | <p>I'm currently working with some developers who like to set up Ant tasks that define environment specific variables rather than using properties files. It seems they prefer to do this because it's easier to type:</p>
<pre><code>ant <environment task> dist
</code></pre>
<p>Than it is to type:</p>
<pre><code>... | [
{
"answer_id": 444067,
"author": "Rob Hruska",
"author_id": 29995,
"author_profile": "https://Stackoverflow.com/users/29995",
"pm_score": 5,
"selected": true,
"text": "<p>Properties tasks tightly couple the build file to environments. If your fellow developers are arguing that they \"hav... | 2009/01/14 | [
"https://Stackoverflow.com/questions/444016",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8252/"
] | I'm currently working with some developers who like to set up Ant tasks that define environment specific variables rather than using properties files. It seems they prefer to do this because it's easier to type:
```
ant <environment task> dist
```
Than it is to type:
```
ant -propertyfile <environment property file... | Properties tasks tightly couple the build file to environments. If your fellow developers are arguing that they "have to change their ant script" with your suggestions, why aren't they arguing about changing it every time they have to deploy to a new environment? :)
Perhaps you can convince them to allow both properti... |
444,018 | <p>I am building a site in asp.net and have multiple subdomains. For example,
one.cookies.com
two.cookies.com</p>
<p>I want my users to be able to login at either subdomain and be logged in for both websites. In addition, I'd like the <strong>sessions and cookies</strong> to be in sync. So far I haven't found a reliab... | [
{
"answer_id": 444035,
"author": "John Hoven",
"author_id": 1907,
"author_profile": "https://Stackoverflow.com/users/1907",
"pm_score": 0,
"selected": false,
"text": "<p>I beleive make the cookie for <a href=\"http://cookies.com\" rel=\"nofollow noreferrer\">http://cookies.com</a>. (No ... | 2009/01/14 | [
"https://Stackoverflow.com/questions/444018",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | I am building a site in asp.net and have multiple subdomains. For example,
one.cookies.com
two.cookies.com
I want my users to be able to login at either subdomain and be logged in for both websites. In addition, I'd like the **sessions and cookies** to be in sync. So far I haven't found a reliable way to do this. | When you create the cookie you can set the domain:
```
HttpCookie cookie = new HttpCookie("name", "value");
cookie.Domain = "cookies.com";
```
This will allow your cookie to be accessible from all subdomains of cookies.com.
If you are using FormsAuthentication then you can set the domain for the auth cookie in web.... |
444,058 | <p>This is probably a kinda commonly asked question but I could do with help on this. I have a list of class objects and I'm trying to figure out how to make it print an item from that class but rather than desplaying in the;</p>
<pre><code><__main__.evolutions instance at 0x01B8EA08>
</code></pre>
<p>but inste... | [
{
"answer_id": 444070,
"author": "Peter Rowell",
"author_id": 17017,
"author_profile": "https://Stackoverflow.com/users/17017",
"pm_score": 2,
"selected": false,
"text": "<p>Checkout the __str__() and __repr__() methods.</p>\n\n<p>See <a href=\"http://docs.python.org/reference/datamodel.... | 2009/01/14 | [
"https://Stackoverflow.com/questions/444058",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/33061/"
] | This is probably a kinda commonly asked question but I could do with help on this. I have a list of class objects and I'm trying to figure out how to make it print an item from that class but rather than desplaying in the;
```
<__main__.evolutions instance at 0x01B8EA08>
```
but instead to show a selected attribute ... | If you want to just display a particular attribute of each class instance, you can do
```
print([obj.attr for obj in my_list_of_objs])
```
Which will print out the `attr` attribute of each object in the list `my_list_of_objs`. Alternatively, you can define the `__str__()` method for your class, which specifies how t... |
444,085 | <p>How do I initialize a <a href="http://library.gnome.org/devel/gtk/stable/GtkScrolledWindow.html" rel="nofollow noreferrer">GtkScrolledWindow</a> to avoid scrollbars by growing as much as possible?</p>
<p>By default it seems to be as small as possible.</p>
<p>Demo code (Quit with <code>SIGINT</code>):</p>
<pre><co... | [
{
"answer_id": 446171,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 0,
"selected": false,
"text": "<p>I'm not sure what the proper way to do this is, but I've found that what works best for me is to set the size of the window... | 2009/01/14 | [
"https://Stackoverflow.com/questions/444085",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/35070/"
] | How do I initialize a [GtkScrolledWindow](http://library.gnome.org/devel/gtk/stable/GtkScrolledWindow.html) to avoid scrollbars by growing as much as possible?
By default it seems to be as small as possible.
Demo code (Quit with `SIGINT`):
```
#include <gtk/gtk.h>
int main(int argc, char *argv[]) {
GtkWidget* w... | I think this both works and is not an ugly hack (much):
```
int main(int argc, char *argv[]) {
GtkWidget* window;
GtkWidget* content;
GtkWidget* sw;
GtkRequisition size;
GtkWidget* viewport;
gtk_init(&argc, &argv);
window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
sw = gtk_scrolled_windo... |
444,111 | <p>I need to dump the certain things into a text file and same has needs to be displayed on screen. (I'm telling about a C program utiltiy)
The menu option looks like following,</p>
<pre>
1. display AA parameters
2. display BB parameters
3. display CC parameters
4. dump all
5. Exit
Select option >
</pre>
<p>If they s... | [
{
"answer_id": 444144,
"author": "Sean Bright",
"author_id": 21926,
"author_profile": "https://Stackoverflow.com/users/21926",
"pm_score": 0,
"selected": false,
"text": "<pre><code>#define ARRAY_LEN(x) (sizeof(x) / sizeof(x[0]))\n\nFILE *f = fopen(\"somefile.txt\", \"a+\");\nFILE *fp[] =... | 2009/01/14 | [
"https://Stackoverflow.com/questions/444111",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/51529/"
] | I need to dump the certain things into a text file and same has needs to be displayed on screen. (I'm telling about a C program utiltiy)
The menu option looks like following,
```
1. display AA parameters
2. display BB parameters
3. display CC parameters
4. dump all
5. Exit
Select option >
```
If they select 1/2/3, ... | I'd go more radical than what people have suggested so far, but maybe it is too much for you. (The 'inline' keyword is C99; you can omit it without much consequence if you code to C89.)
```
/*
** These could be omitted - unless you get still more radical and create
** the format strings at run-time, so you can adapt t... |
444,139 | <p>I'm using ms sql 2008 and trying to create a database name that references another database. For example 'Dev', 'Test', 'Demo' would be database names that i could reference from my multiple config files, but each name would point to another database such as 'db20080101' or 'db20080114'. </p>
<p>[Edit]Some of the c... | [
{
"answer_id": 444146,
"author": "SQLMenace",
"author_id": 740,
"author_profile": "https://Stackoverflow.com/users/740",
"pm_score": 2,
"selected": false,
"text": "<p>use 3 part notation and alias up to the table, example</p>\n\n<pre><code>select * from tempdb.dbo.sysobjects a\njoin mast... | 2009/01/14 | [
"https://Stackoverflow.com/questions/444139",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/55112/"
] | I'm using ms sql 2008 and trying to create a database name that references another database. For example 'Dev', 'Test', 'Demo' would be database names that i could reference from my multiple config files, but each name would point to another database such as 'db20080101' or 'db20080114'.
[Edit]Some of the configs are... | use 3 part notation and alias up to the table, example
```
select * from tempdb.dbo.sysobjects a
join master.dbo.sysobjects b on a.id = b.id
``` |
444,151 | <p>I'm attempting to do something which should be relatively simple. I'm using a ListView to show a number of items, using the ItemTemplate. Inside the ItemTemplate I have a div surrounding the full item, so that I can highlight on a hover event, (being handled already by jQuery).</p>
<p>What I would like to do is h... | [
{
"answer_id": 444226,
"author": "bdukes",
"author_id": 2688,
"author_profile": "https://Stackoverflow.com/users/2688",
"pm_score": 3,
"selected": true,
"text": "<p>Wire up a method to the <a href=\"http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.listview.itemdatabound.... | 2009/01/14 | [
"https://Stackoverflow.com/questions/444151",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/34314/"
] | I'm attempting to do something which should be relatively simple. I'm using a ListView to show a number of items, using the ItemTemplate. Inside the ItemTemplate I have a div surrounding the full item, so that I can highlight on a hover event, (being handled already by jQuery).
What I would like to do is have the clic... | Wire up a method to the [ItemDataBound](http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.listview.itemdatabound.aspx) event of your ListView. In there, you can use [FindControl](http://msdn.microsoft.com/en-us/library/system.web.ui.webcontrols.listviewitem.findcontrol.aspx) method on the [Item](http://... |
444,152 | <p>I need a Regex Statement (run in c#) that will take a string containing a Sql Update statement as input, and will return a list of columns to be updated. It should be able to handle columns surrounded by brackets or not. </p>
<pre><code>// Example Sql Statement
Update Employees
Set FirstName = 'Jim', [LastName] = '... | [
{
"answer_id": 444168,
"author": "Andru Luvisi",
"author_id": 5922,
"author_profile": "https://Stackoverflow.com/users/5922",
"pm_score": 3,
"selected": true,
"text": "<p>You're doing it backwards. Store the data in a broken out form, with the table to be updated, the column names, and ... | 2009/01/14 | [
"https://Stackoverflow.com/questions/444152",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/51/"
] | I need a Regex Statement (run in c#) that will take a string containing a Sql Update statement as input, and will return a list of columns to be updated. It should be able to handle columns surrounded by brackets or not.
```
// Example Sql Statement
Update Employees
Set FirstName = 'Jim', [LastName] = 'Smith', CodeNu... | You're doing it backwards. Store the data in a broken out form, with the table to be updated, the column names, and the expressions to generate the new values all separate. From this canonical representation, generate both the SQL (when you need it) and the list of columns being updated (when you need that instead).
I... |
444,163 | <p>I'm sure I must be doing something wrong. But can't for the life of me figure out what is going on.</p>
<p>I have a problem where it seems that the HttpWebRequest class in the framework is not correctly parsing the cookies from a web response.</p>
<p>I'm using Fiddler to see what is going on and after making a req... | [
{
"answer_id": 444173,
"author": "Darin Dimitrov",
"author_id": 29407,
"author_profile": "https://Stackoverflow.com/users/29407",
"pm_score": 0,
"selected": false,
"text": "<p>It seems that the server sends incorrect cookie values. IMHO commas are not allowed in cookie values. They need ... | 2009/01/14 | [
"https://Stackoverflow.com/questions/444163",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1088682/"
] | I'm sure I must be doing something wrong. But can't for the life of me figure out what is going on.
I have a problem where it seems that the HttpWebRequest class in the framework is not correctly parsing the cookies from a web response.
I'm using Fiddler to see what is going on and after making a request, the headers... | Commas in cookie values are to be avoided - you may need to encode them differently.
The original [netscape spec](http://cgi.netscape.com/newsref/std/cookie_spec.html) for cookies was a little vague on this issue, stating
>
> NAME=VALUE :
> This string is a sequence of characters excluding semi-colon, comma
> an... |
444,170 | <p>I've been using javascript for a while, but have never learned the language past the basics. I am reading John Resig's "Pro Javascript Techniques" - I'm coming up with some questions, but I'm not finding the answers to them in the book or on google, etc.</p>
<p>John gives this example in his book:<br />
<strong>Fu... | [
{
"answer_id": 444195,
"author": "Andru Luvisi",
"author_id": 5922,
"author_profile": "https://Stackoverflow.com/users/5922",
"pm_score": 6,
"selected": true,
"text": "<p>Every time a function() {} is evaluated, it creates a new function object. Therefore, in #1 all of the User objects ... | 2009/01/14 | [
"https://Stackoverflow.com/questions/444170",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/40619/"
] | I've been using javascript for a while, but have never learned the language past the basics. I am reading John Resig's "Pro Javascript Techniques" - I'm coming up with some questions, but I'm not finding the answers to them in the book or on google, etc.
John gives this example in his book:
**Function #1**
```
fun... | Every time a function() {} is evaluated, it creates a new function object. Therefore, in #1 all of the User objects are sharing the same getName and getAge functions, but in #2 and #3, each object has its own copy of getName and getAge. All of the different getName functions all behave exactly the same, so you can't se... |
444,179 | <p>According to <a href="https://stackoverflow.com/questions/259311/configuration-manager-only-shows-debug">an earlier question about Visual Studio configurations</a>, there's no way to use Visual Studio's configuration manager to create different configurations for an ASP.net web site project. </p>
<p>For normal pro... | [
{
"answer_id": 444199,
"author": "JB King",
"author_id": 8745,
"author_profile": "https://Stackoverflow.com/users/8745",
"pm_score": 2,
"selected": true,
"text": "<p>Perhaps a Web Deployment project that does some swapping in the web.config may be of some help? Another thought would be ... | 2009/01/14 | [
"https://Stackoverflow.com/questions/444179",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5062/"
] | According to [an earlier question about Visual Studio configurations](https://stackoverflow.com/questions/259311/configuration-manager-only-shows-debug), there's no way to use Visual Studio's configuration manager to create different configurations for an ASP.net web site project.
For normal projects, we have #if dir... | Perhaps a Web Deployment project that does some swapping in the web.config may be of some help? Another thought would be to have a connection string in the web.config that pulls various values from a pre-specified database that can exist in each environment to allow for easy changes to the settings without needing to t... |
444,191 | <p>The following C# class is used in a multithreaded enviroment. I removed very much of the actual code. The problem occurs when calling MethodA and MethodB almost simultaneously. The order of the lock in the IsDepleted property doesn't solves the problem. Removing lock(WaitingQueue) from the IsDepleted property solves... | [
{
"answer_id": 444201,
"author": "Ana Betts",
"author_id": 5728,
"author_profile": "https://Stackoverflow.com/users/5728",
"pm_score": 2,
"selected": false,
"text": "<p>Take the Processing lock in method A and the WaitingQueue lock in method B (in other words, make it look like the first... | 2009/01/14 | [
"https://Stackoverflow.com/questions/444191",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/48465/"
] | The following C# class is used in a multithreaded enviroment. I removed very much of the actual code. The problem occurs when calling MethodA and MethodB almost simultaneously. The order of the lock in the IsDepleted property doesn't solves the problem. Removing lock(WaitingQueue) from the IsDepleted property solves th... | It depends if you want a quick fix or a rigorous fix.
A quick fix would be just to use one lock object in all cases.
e.g. `private readonly object _lock = new object();`
And then just lock on that. However, depending on your situation, that may impact performance more than you can accept.
I.e. your code would becom... |
444,192 | <p>I have created two DirectShow graphs. One captures from a Hauppauge HD-PVR and stores it in a StreamBufferSink. The second one uses a <code>StreamBufferSource</code>, sends the output to an MPEG-2 Demultiplexer, sending the video to the ArcSoft Video Decoder and on to a Video Mixing Renderer 9 set up in windowless... | [
{
"answer_id": 444201,
"author": "Ana Betts",
"author_id": 5728,
"author_profile": "https://Stackoverflow.com/users/5728",
"pm_score": 2,
"selected": false,
"text": "<p>Take the Processing lock in method A and the WaitingQueue lock in method B (in other words, make it look like the first... | 2009/01/14 | [
"https://Stackoverflow.com/questions/444192",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] | I have created two DirectShow graphs. One captures from a Hauppauge HD-PVR and stores it in a StreamBufferSink. The second one uses a `StreamBufferSource`, sends the output to an MPEG-2 Demultiplexer, sending the video to the ArcSoft Video Decoder and on to a Video Mixing Renderer 9 set up in windowless mode.
This all... | It depends if you want a quick fix or a rigorous fix.
A quick fix would be just to use one lock object in all cases.
e.g. `private readonly object _lock = new object();`
And then just lock on that. However, depending on your situation, that may impact performance more than you can accept.
I.e. your code would becom... |
444,198 | <p>Are there O/R mapping tools for ASP (not ASP.NET) and are these useful in ASP?</p>
<p>Lieven Cardoen</p>
| [
{
"answer_id": 444201,
"author": "Ana Betts",
"author_id": 5728,
"author_profile": "https://Stackoverflow.com/users/5728",
"pm_score": 2,
"selected": false,
"text": "<p>Take the Processing lock in method A and the WaitingQueue lock in method B (in other words, make it look like the first... | 2009/01/14 | [
"https://Stackoverflow.com/questions/444198",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/26521/"
] | Are there O/R mapping tools for ASP (not ASP.NET) and are these useful in ASP?
Lieven Cardoen | It depends if you want a quick fix or a rigorous fix.
A quick fix would be just to use one lock object in all cases.
e.g. `private readonly object _lock = new object();`
And then just lock on that. However, depending on your situation, that may impact performance more than you can accept.
I.e. your code would becom... |
444,204 | <p>Can I tell, using javascript, whether a user has clicked on the "X" icon on a browser dialog, or the "OK"/"Cancel" buttons? I have code I need to run when the window closes, but it will only run when OK or Cancel are clicked.</p>
<p>I currently capture the onunload event of the window. How can i accomplish this?</p... | [
{
"answer_id": 444219,
"author": "rmeador",
"author_id": 10861,
"author_profile": "https://Stackoverflow.com/users/10861",
"pm_score": 4,
"selected": true,
"text": "<p>Why do you want to do this? We can probably help you come up with a different design that doesn't require this if you t... | 2009/01/14 | [
"https://Stackoverflow.com/questions/444204",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/47645/"
] | Can I tell, using javascript, whether a user has clicked on the "X" icon on a browser dialog, or the "OK"/"Cancel" buttons? I have code I need to run when the window closes, but it will only run when OK or Cancel are clicked.
I currently capture the onunload event of the window. How can i accomplish this?
```
window.... | Why do you want to do this? We can probably help you come up with a different design that doesn't require this if you tell us what you're trying to do.
However, to answer your question: it's not possible to catch that event in all cases. You cannot prevent the user from closing the browser or guarantee that your code ... |
444,208 | <p>In Unix, I need to be able to archive log files into monthly folders, labelled accordingly. How do I do this in Perl?</p>
| [
{
"answer_id": 444249,
"author": "Bill Karwin",
"author_id": 20860,
"author_profile": "https://Stackoverflow.com/users/20860",
"pm_score": 2,
"selected": false,
"text": "<p>When I have had this task, I use <a href=\"http://cronolog.org/usage.html\" rel=\"nofollow noreferrer\">cronolog</a... | 2009/01/14 | [
"https://Stackoverflow.com/questions/444208",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/55119/"
] | In Unix, I need to be able to archive log files into monthly folders, labelled accordingly. How do I do this in Perl? | Let's provide an actual Perl idea, since that's what was asked for:
```
use File::Path qw<mkpath>;
use File::Spec;
use POSIX qw<strftime>;
use Smart::Comments;
my $directory
= File::Spec->catfile( $BASE_LOG_DIRECTORY
, strftime( "%Y-%B", localtime ) #2009-January
);
### $directory
u... |
444,210 | <p>I am able to send emails using the typical C# SMTP code across Exchange 2007 as long as both the from and to addresses are within my domain.</p>
<p>As soon as I try to send emails outside the domain I get:</p>
<p>Exception Details: System.Net.Mail.SmtpFailedRecipientException: Mailbox unavailable. The server respo... | [
{
"answer_id": 444254,
"author": "AlexCuse",
"author_id": 794,
"author_profile": "https://Stackoverflow.com/users/794",
"pm_score": 1,
"selected": false,
"text": "<p>You'll need to get your exchange admin to configure exchange to allow sending outside the domain. In my experience they'v... | 2009/01/14 | [
"https://Stackoverflow.com/questions/444210",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2285/"
] | I am able to send emails using the typical C# SMTP code across Exchange 2007 as long as both the from and to addresses are within my domain.
As soon as I try to send emails outside the domain I get:
Exception Details: System.Net.Mail.SmtpFailedRecipientException: Mailbox unavailable. The server response was: 5.7.1 Un... | Try #2... How about using a [Exchange Pickup Folder](http://www.msexchange.org/articles_tutorials/exchange-server-2007/management-administration/exchange-pickup-folder.html) instead? They are a faster way to send emails through Exchange because it just creates the email and drops it in the folder, no waiting to connect... |
444,213 | <p>BACKGROUND:
I have the following XUL fragment</p>
<pre><code><tree id="treeToChange" flex="1">
<treecols>
<treecol label = "First Column" id="c1" flex="1"/>
<treecol label = "Second Column" id="c2" flex="1"/>
</treecols>
<treechildren>
<treeitem>
<... | [
{
"answer_id": 444224,
"author": "Eran Galperin",
"author_id": 10585,
"author_profile": "https://Stackoverflow.com/users/10585",
"pm_score": 2,
"selected": false,
"text": "<p>The style property of a DOM element contains all the CSS declarations for that element. The naming scheme is slig... | 2009/01/14 | [
"https://Stackoverflow.com/questions/444213",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12113/"
] | BACKGROUND:
I have the following XUL fragment
```
<tree id="treeToChange" flex="1">
<treecols>
<treecol label = "First Column" id="c1" flex="1"/>
<treecol label = "Second Column" id="c2" flex="1"/>
</treecols>
<treechildren>
<treeitem>
<treerow>
<treecell label="Data for Column 1"/>
... | It turns out that the element.style.color only effects the column headings, and that within firefox, the cells in a tree structure can only be affected by coding the dataview.
code snippets follow:
```
// DatabaseTreeView: Create a custom nsITreeView
DatabaseTreeView: function(aTableData, aColumns) {
this.getCellPr... |
444,231 | <p>I am using Django's RSS capabilities to build an RSS feed. The <code><description></code> of the RSS feed items contains HTML markup. Currently, I am just injecting the HTML markup into the feed using the following template:</p>
<pre><code>{{ obj.post }}
</code></pre>
<p>Django, of course, translates special... | [
{
"answer_id": 446156,
"author": "Oli",
"author_id": 12870,
"author_profile": "https://Stackoverflow.com/users/12870",
"pm_score": 2,
"selected": false,
"text": "<p>When I run into issues like this with Django my first instinct is to run off and find a normal Python lib that does what I ... | 2009/01/14 | [
"https://Stackoverflow.com/questions/444231",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/28804/"
] | I am using Django's RSS capabilities to build an RSS feed. The `<description>` of the RSS feed items contains HTML markup. Currently, I am just injecting the HTML markup into the feed using the following template:
```
{{ obj.post }}
```
Django, of course, translates special characters (`<`, `>`, `&`, etc.) to their ... | When I run into issues like this with Django my first instinct is to run off and find a normal Python lib that does what I want. In this case [PyRSS2Gen](http://www.dalkescientific.com/Python/PyRSS2Gen.html) might be your saviour.
It'll probably require a bit more fannying around (because it'll be unaware of what Djan... |
444,245 | <p>I'm at a point in my development learning where I feel like I must learn more about interfaces.</p>
<p>I frequently read about them but it just seems like I cannot grasp them.</p>
<p>I've read examples like: Animal base class, with IAnimal interface for things like 'Walk', 'Run', 'GetLegs', etc - but I've never be... | [
{
"answer_id": 444253,
"author": "Larsenal",
"author_id": 337,
"author_profile": "https://Stackoverflow.com/users/337",
"pm_score": 5,
"selected": false,
"text": "<p>Think of an interface like a Contract. It's a way to say, \"These classes should follow these set of rules.\"</p>\n\n<p>S... | 2009/01/14 | [
"https://Stackoverflow.com/questions/444245",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/53885/"
] | I'm at a point in my development learning where I feel like I must learn more about interfaces.
I frequently read about them but it just seems like I cannot grasp them.
I've read examples like: Animal base class, with IAnimal interface for things like 'Walk', 'Run', 'GetLegs', etc - but I've never been working on som... | it solves this concrete problem:
you have a, b, c, d of 4 different types. all over your code you have something like:
```
a.Process();
b.Process();
c.Process();
d.Process();
```
why not have them implement IProcessable, and then do
```
List<IProcessable> list;
foreach(IProcessable p in list)
p.Process();
``... |
444,251 | <p>I would like to store an object <strong>FOO</strong> in a database.
Lets say FOO contains three integers and a list of "<em>Fruits</em>".</p>
<p>The list can have any length, the only thing I know is that the all the fruits allowed are stored in another table.</p>
<p>Can I store the fruit list in a column? </p>
| [
{
"answer_id": 444268,
"author": "mmx",
"author_id": 33708,
"author_profile": "https://Stackoverflow.com/users/33708",
"pm_score": 8,
"selected": true,
"text": "<p>In a normalized relational database, such a situation is unacceptable. You should have a junction table that stores one row ... | 2009/01/14 | [
"https://Stackoverflow.com/questions/444251",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/17413/"
] | I would like to store an object **FOO** in a database.
Lets say FOO contains three integers and a list of "*Fruits*".
The list can have any length, the only thing I know is that the all the fruits allowed are stored in another table.
Can I store the fruit list in a column? | In a normalized relational database, such a situation is unacceptable. You should have a junction table that stores one row for each distinct ID of the FOO object and the ID of the Fruit. Existence of such a row means the fruit is in that list for the FOO.
```
CREATE TABLE FOO (
id int primary key not null,
int1 ... |
444,265 | <p>I want to instantly update a status line indicating the number of checked checkboxes across all pages of an asp.net gridview. Right now I am only ably to count the number of checkboxes that are checked on the current gridview page.</p>
<p>Here is my code:</p>
<pre><code>$(document).ready(initAll);
function initA... | [
{
"answer_id": 719260,
"author": "Employed Russian",
"author_id": 50617,
"author_profile": "https://Stackoverflow.com/users/50617",
"pm_score": 1,
"selected": false,
"text": "<p>In general, you don't need to upgrade binutils unless you run into some bug fixed in a later binutils version,... | 2009/01/14 | [
"https://Stackoverflow.com/questions/444265",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/55124/"
] | I want to instantly update a status line indicating the number of checked checkboxes across all pages of an asp.net gridview. Right now I am only ably to count the number of checkboxes that are checked on the current gridview page.
Here is my code:
```
$(document).ready(initAll);
function initAll(){
countChecked(... | `binutils` 2.19 has a new ELF linker called [`gold`](http://sourceware.org/ml/binutils/2008-03/msg00162.html) which is multi-threaded, written in modern C++, and quite a bit faster than the usual `ld` linker. I'm not sure however about the work involved to adapt it.
Other than that, well new versions always are a goo... |
444,285 | <p>I'm trying to wrap my head around functional programming in ruby and there doesn't seem to be much good documentation out there.</p>
<p>Essentially, I'm trying to write a combine function that would have a Haskell type signature of:</p>
<pre><code>[a] -> [a] -> (a -> a -> a) -> [a]
</code></pre>
<p... | [
{
"answer_id": 444318,
"author": "krusty.ar",
"author_id": 43981,
"author_profile": "https://Stackoverflow.com/users/43981",
"pm_score": 2,
"selected": false,
"text": "<p>A very naive aproach:</p>\n\n<pre><code>def combine(a1, a2)\n i = 0\n result = []\n while a1[i] && a2[i]\n... | 2009/01/14 | [
"https://Stackoverflow.com/questions/444285",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14559/"
] | I'm trying to wrap my head around functional programming in ruby and there doesn't seem to be much good documentation out there.
Essentially, I'm trying to write a combine function that would have a Haskell type signature of:
```
[a] -> [a] -> (a -> a -> a) -> [a]
```
So
```
combine([1,2,3], [2,3,4], plus_func) =... | Well, you said you know about zip and map so this probably isn't helpful.
But I'll post just in case.
```
def combine a, b
a.zip(b).map { |i| yield i[0], i[1] }
end
puts combine([1,2,3], [2,3,4]) { |i, j| i+j }
```
No, I don't find it beautiful either.
**edit -** #ruby-lang @ irc.freenode.net suggests this:
`... |
444,296 | <p>I have a bunch of objects in a flat structure. These objects have an <code>ID</code> and a <code>ParentID</code> property so they can be arranged in trees. They are in no particular order.
Each <code>ParentID</code> property does not necessarily matches with an <code>ID</code> in the structure. Therefore their could... | [
{
"answer_id": 444303,
"author": "mmx",
"author_id": 33708,
"author_profile": "https://Stackoverflow.com/users/33708",
"pm_score": 8,
"selected": true,
"text": "<p>Store IDs of the objects in a hash table mapping to the specific object. Enumerate through all the objects and find their pa... | 2009/01/14 | [
"https://Stackoverflow.com/questions/444296",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1130/"
] | I have a bunch of objects in a flat structure. These objects have an `ID` and a `ParentID` property so they can be arranged in trees. They are in no particular order.
Each `ParentID` property does not necessarily matches with an `ID` in the structure. Therefore their could be several trees emerging from these objects.
... | Store IDs of the objects in a hash table mapping to the specific object. Enumerate through all the objects and find their parent if it exists and update its parent pointer accordingly.
```cs
class MyObject
{ // The actual object
public int ParentID { get; set; }
public int ID { get; set; }
}
class Node
{
... |
444,309 | <p>I need to concatenate 3 files using C#. A header file, content, and a footer file, but I want to do this as cool as it can be done.</p>
<p>Cool = really small code or really fast (non-assembly code).</p>
| [
{
"answer_id": 444312,
"author": "Jimmy",
"author_id": 4435,
"author_profile": "https://Stackoverflow.com/users/4435",
"pm_score": 3,
"selected": false,
"text": "<p>If your files are text and not large, there's something to be said for dead-simple, obvious code. I'd use the following.</p... | 2009/01/14 | [
"https://Stackoverflow.com/questions/444309",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/49276/"
] | I need to concatenate 3 files using C#. A header file, content, and a footer file, but I want to do this as cool as it can be done.
Cool = really small code or really fast (non-assembly code). | ```
void CopyStream(Stream destination, Stream source) {
int count;
byte[] buffer = new byte[BUFFER_SIZE];
while( (count = source.Read(buffer, 0, buffer.Length)) > 0)
destination.Write(buffer, 0, count);
}
CopyStream(outputFileStream, fileStream1);
CopyStream(outputFileStream, fileStream2);
CopyStream(... |
444,319 | <p>Our web page is only available internally in our company and we am very intrested in being able to offer interactive .net usercontrols on our departments website in the<b> .Net 2.0</b> enviorment. I have been successful with embeding the object as so:</p>
<pre><code><object id="Object1" classid="http:EmbedTest1... | [
{
"answer_id": 444333,
"author": "DavGarcia",
"author_id": 40161,
"author_profile": "https://Stackoverflow.com/users/40161",
"pm_score": 1,
"selected": false,
"text": "<p>If the things that you are doing with the Windows Controls could be done with ASP.NET web controls instead, I recomme... | 2009/01/14 | [
"https://Stackoverflow.com/questions/444319",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/54009/"
] | Our web page is only available internally in our company and we am very intrested in being able to offer interactive .net usercontrols on our departments website in the **.Net 2.0** enviorment. I have been successful with embeding the object as so:
```
<object id="Object1" classid="http:EmbedTest1.dll#EmbedTest1.UserC... | 1. Not out-dated so much as rarely used, and IE-only. If you want web-like deployment for desktop apps, use ClickOnce. If you want C# code that runs in the browser without security issues, use Silverlight. You could also look at XBAPs, which are sandboxed WPF apps that run in the browser, works on IE and Firefox, but r... |