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
411,476
<p>I have a controller with two actions:</p> <pre><code>[AcceptVerbs("GET")] public ActionResult Add() { PrepareViewDataForAddAction(); return View(); } [AcceptVerbs("POST")] public ActionResult Add([GigBinderAttribute]Gig gig, FormCollection formCollection) { if (ViewData...
[ { "answer_id": 416654, "author": "Dominic Betts", "author_id": 50911, "author_profile": "https://Stackoverflow.com/users/50911", "pm_score": 1, "selected": false, "text": "<p>Could you do this in your PrepareViewDataForAddAction method?..</p>\n\n<pre><code>if (!ViewData.ModelState.IsVali...
2009/01/04
[ "https://Stackoverflow.com/questions/411476", "https://Stackoverflow.com", "https://Stackoverflow.com/users/46616/" ]
I have a controller with two actions: ``` [AcceptVerbs("GET")] public ActionResult Add() { PrepareViewDataForAddAction(); return View(); } [AcceptVerbs("POST")] public ActionResult Add([GigBinderAttribute]Gig gig, FormCollection formCollection) { if (ViewData.ModelState.IsV...
I think the problem is that your ViewModel does not match closely enough with your View. It's really important in MVC that your ViewModel matches your View as closely as possible. In your ViewModel you're assuming an integer, but in your View you're using a TextBox to render the property, which will allow any kind of ...
411,478
<p>This method returns some strange results, and was wondering if someone could explain why this is happening, and possibly a solution to get my desired results.</p> <p>Results:</p> <p>FileName = what I'd expect</p> <p>FileSize = what I'd expect</p> <p>Buffer = all bytes = 0</p> <p>BytesRead = 0</p> <p>BlobString...
[ { "answer_id": 411490, "author": "Jon Skeet", "author_id": 22656, "author_profile": "https://Stackoverflow.com/users/22656", "pm_score": 0, "selected": false, "text": "<p>Is the field type in the database definitely a BLOB rather than a CLOB? It certainly <em>looks</em> as if it's treati...
2009/01/04
[ "https://Stackoverflow.com/questions/411478", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
This method returns some strange results, and was wondering if someone could explain why this is happening, and possibly a solution to get my desired results. Results: FileName = what I'd expect FileSize = what I'd expect Buffer = all bytes = 0 BytesRead = 0 BlobString = string of binary data FieldType = BLOB (w...
I created the field as a BLOB. However, seeing the results of your suggestion of GetFieldType being a System.String, I'm not sure. I'm using the SQLite Manager FireFox addon to manager, and it's reporting *content* as a BLOB. .NET and the SQLite manager seem to be conflicting. I can save the file properly out of the ...
411,495
<p>In bash one can escape arguments that contain whitespace.</p> <pre><code>foo "a string" </code></pre> <p>This also works for arguments to a command or function:</p> <pre><code>bar() { foo "$@" } bar "a string" </code></pre> <p>So far so good, but what if I want to manipulate the arguments before calling <co...
[ { "answer_id": 411565, "author": "JesperE", "author_id": 13051, "author_profile": "https://Stackoverflow.com/users/13051", "pm_score": 1, "selected": false, "text": "<p>Use <a href=\"http://tldp.org/LDP/abs/html/arrays.html\" rel=\"nofollow noreferrer\">arrays</a> (one of the <a href=\"h...
2009/01/04
[ "https://Stackoverflow.com/questions/411495", "https://Stackoverflow.com", "https://Stackoverflow.com/users/51019/" ]
In bash one can escape arguments that contain whitespace. ``` foo "a string" ``` This also works for arguments to a command or function: ``` bar() { foo "$@" } bar "a string" ``` So far so good, but what if I want to manipulate the arguments before calling `foo`? This does not work: ``` bar() { for arg...
There are (at least) two ways to do this: 1. Use an array and expand it using `"${array[@]}"`: ``` bar() { local i=0 args=() for arg in "$@" do args[$i]="prefix $arg" ((++i)) done foo "${args[@]}" } ``` So, what have we learned? `"${array[@]}"` is to `${array[*]}` what `"$@"` is...
411,499
<p>Please take a look on the following pseudo-code:</p> <pre><code>boolean blocked[2]; int turn; void P(int id) { while(true) { blocked[id] = true; while(turn != id) { while(blocked[1-id]) /* do nothing */; turn = id; ...
[ { "answer_id": 411521, "author": "starblue", "author_id": 49246, "author_profile": "https://Stackoverflow.com/users/49246", "pm_score": -1, "selected": false, "text": "<p>Maybe you need to declare blocked and turn as volatile, but without specifying the programming language there is no w...
2009/01/04
[ "https://Stackoverflow.com/questions/411499", "https://Stackoverflow.com", "https://Stackoverflow.com/users/43960/" ]
Please take a look on the following pseudo-code: ``` boolean blocked[2]; int turn; void P(int id) { while(true) { blocked[id] = true; while(turn != id) { while(blocked[1-id]) /* do nothing */; turn = id; } ...
Mutual Exclusion is in this exemple not guaranteed because of the following: We begin with the following situation: ``` blocked = {false, false}; turn = 0; ``` P1 is now executes, and skips ``` blocked[id] = false; // Not yet executed. ``` The situation is now: ``` blocked {false, true} turn = 0; ``` Now P0...
411,512
<p>I've got a PHP script on a shared webhost that selects from ~300 'feeds' the 40 that haven't been updated in the last half hour, makes a cURL request and then delivers it to the user.</p> <pre><code>SELECT * FROM table WHERE latest_scan &lt; NOW() - INTERVAL 30 MINUTE ORDER BY latest_scan ASC LIMIT 0, 40; // Make c...
[ { "answer_id": 411520, "author": "DFectuoso", "author_id": 47846, "author_profile": "https://Stackoverflow.com/users/47846", "pm_score": 2, "selected": true, "text": "<p>It would be a good thing to \"rate\" how often each feed actually changes so if something has an average time of 24 ho...
2009/01/04
[ "https://Stackoverflow.com/questions/411512", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6305/" ]
I've got a PHP script on a shared webhost that selects from ~300 'feeds' the 40 that haven't been updated in the last half hour, makes a cURL request and then delivers it to the user. ``` SELECT * FROM table WHERE latest_scan < NOW() - INTERVAL 30 MINUTE ORDER BY latest_scan ASC LIMIT 0, 40; // Make cURL request and p...
It would be a good thing to "rate" how often each feed actually changes so if something has an average time of 24 hours per change, then you just fetch is every 12 hours. Just store #changes and #try's and pick the ones you need to check... you can run the script every minute and let some statistics do the rest!
411,515
<p>Is there an automatic way to add base classes to Linq2Sql entities?</p> <p>I know I can define a partial and implement that but there has to be an automated way, right?</p>
[ { "answer_id": 411527, "author": "Jon Skeet", "author_id": 22656, "author_profile": "https://Stackoverflow.com/users/22656", "pm_score": 2, "selected": false, "text": "<p>EDIT: <a href=\"https://stackoverflow.com/questions/411515/way-to-automatically-add-a-linqtosql-base-class-to-entitie...
2009/01/04
[ "https://Stackoverflow.com/questions/411515", "https://Stackoverflow.com", "https://Stackoverflow.com/users/25300/" ]
Is there an automatic way to add base classes to Linq2Sql entities? I know I can define a partial and implement that but there has to be an automated way, right?
The LINQ-to-SQL code-generator supports this directly. The base-class for the data-context can be set in the designer, as the `Base Class` property. Alternatively, edit the dbml directly: right click, "Edit With...", "XML Editor" To change the base class for the entities, set the type: ``` <Database EntityBase="Some...
411,544
<p>I am attempting to port one of my hobby project to linux. Preferrably to Mono since it is written in C#. But I am looking into Python as well.</p> <p>One of the feature of the application is that it needs to associate with a custom protocol so the application is invoked when the user clicks links like this on the a...
[ { "answer_id": 411564, "author": "Charlie Martin", "author_id": 35092, "author_profile": "https://Stackoverflow.com/users/35092", "pm_score": 1, "selected": false, "text": "<p>There's not going to be a single answer, because that will be happening at the X window manager level at best. ...
2009/01/04
[ "https://Stackoverflow.com/questions/411544", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3055/" ]
I am attempting to port one of my hobby project to linux. Preferrably to Mono since it is written in C#. But I am looking into Python as well. One of the feature of the application is that it needs to associate with a custom protocol so the application is invoked when the user clicks links like this on the app's websi...
In the ideal situation, this sort of thing is handled by the desktop environment (KDE, GNOME, XFCE), and Firefox respects those settings---it should do so on Ubuntu, Fedora, and OpenSUSE, at least. YMMV: [Integrating a new URIs Scheme Handler to GNOME and Firefox](http://people.w3.org/~dom/archives/2005/09/integrating...
411,571
<p>I've created </p> <pre><code> DataTable dt = new DataTable(); dt.Columns.Add("Type"); dt.Columns.Add("Address1"); dt.Columns.Add("Address2"); dt.Columns.Add("PostalCode"); dt.Columns.Add("Country"); DataRow drow = dt.NewRow(); drow["Type"] = ddlAddre...
[ { "answer_id": 414667, "author": "Aaron", "author_id": 50539, "author_profile": "https://Stackoverflow.com/users/50539", "pm_score": 0, "selected": false, "text": "<p>In the definition of your GridView make sure that you have your defined if you have AutoGenerateColumns set to false.</p...
2009/01/04
[ "https://Stackoverflow.com/questions/411571", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I've created ``` DataTable dt = new DataTable(); dt.Columns.Add("Type"); dt.Columns.Add("Address1"); dt.Columns.Add("Address2"); dt.Columns.Add("PostalCode"); dt.Columns.Add("Country"); DataRow drow = dt.NewRow(); drow["Type"] = ddlAddressType.Selecte...
Sounds to me like you need to set AutoGenerateColumns="false" and then specify the columns to show in the gridview: ``` <asp:GridView ID="AddressGridView" runat="server" AutoGenerateColumns="false"> <Columns> <asp:BoundField HeaderText="Type" DataField="Type" /> <asp:BoundField HeaderText="Address1" DataField=...
411,572
<p>Given a method <code>DoSomething</code> that takes a (parameterless) function and handles it in some way. Is there a better way to create the "overloads" for functions with parameters than the snippet below?</p> <pre><code>public static TResult DoSomething&lt;TResult&gt;(Func&lt;TResult&gt; func) { //call func(...
[ { "answer_id": 411586, "author": "Jon Skeet", "author_id": 22656, "author_profile": "https://Stackoverflow.com/users/22656", "pm_score": 6, "selected": true, "text": "<p>EDIT: As noted in comments, this is partial application rather than currying. I wrote a <a href=\"http://codeblog.jons...
2009/01/04
[ "https://Stackoverflow.com/questions/411572", "https://Stackoverflow.com", "https://Stackoverflow.com/users/48722/" ]
Given a method `DoSomething` that takes a (parameterless) function and handles it in some way. Is there a better way to create the "overloads" for functions with parameters than the snippet below? ``` public static TResult DoSomething<TResult>(Func<TResult> func) { //call func() and do something else } public sta...
EDIT: As noted in comments, this is partial application rather than currying. I wrote a [blog post on my understanding of the difference](http://codeblog.jonskeet.uk/2012/01/30/currying-vs-partial-function-application/), which folks may find interesting. Well, it's not particularly different - but I'd separate out the...
411,575
<p>Given a table such as:</p> <pre><code>CREATE TABLE dbo.MyTestData (testdata varchar(50) NOT NULL) ALTER TABLE dbo.MyTestData WITH NOCHECK ADD CONSTRAINT [PK_MyTestData] PRIMARY KEY CLUSTERED (testdata) </code></pre> <p>And given that we want a unique list of 'testdata' when we are done gathering items to be ad...
[ { "answer_id": 411608, "author": "alex", "author_id": 50564, "author_profile": "https://Stackoverflow.com/users/50564", "pm_score": 0, "selected": false, "text": "<p>I think most programmers would suggest avoiding the exception. I'm not sure from a performance standpoint in T-SQL, but in...
2009/01/04
[ "https://Stackoverflow.com/questions/411575", "https://Stackoverflow.com", "https://Stackoverflow.com/users/35696/" ]
Given a table such as: ``` CREATE TABLE dbo.MyTestData (testdata varchar(50) NOT NULL) ALTER TABLE dbo.MyTestData WITH NOCHECK ADD CONSTRAINT [PK_MyTestData] PRIMARY KEY CLUSTERED (testdata) ``` And given that we want a unique list of 'testdata' when we are done gathering items to be added from a list of externa...
I always do it in one statement: ``` INSERT INTO dbo.MyTestData (testdata ) VALUES (@ptestdata) WHERE NOT EXISTS(SELECT 1 FROM dbo.MyTestData WHERE testdata=@ptestdata) ```
411,579
<p>Take the method System.Windows.Forms.Control.Invoke(Delegate method)</p> <p>Why does this give a compile time error:</p> <pre><code>string str = "woop"; Invoke(() =&gt; this.Text = str); // Error: Cannot convert lambda expression to type 'System.Delegate' // because it is not a delegate type </code></pre> <p>Yet ...
[ { "answer_id": 411597, "author": "Jon Skeet", "author_id": 22656, "author_profile": "https://Stackoverflow.com/users/22656", "pm_score": 8, "selected": true, "text": "<p>A lambda expression can either be converted to a delegate type or an expression tree - but it has to know <em>which</e...
2009/01/04
[ "https://Stackoverflow.com/questions/411579", "https://Stackoverflow.com", "https://Stackoverflow.com/users/82/" ]
Take the method System.Windows.Forms.Control.Invoke(Delegate method) Why does this give a compile time error: ``` string str = "woop"; Invoke(() => this.Text = str); // Error: Cannot convert lambda expression to type 'System.Delegate' // because it is not a delegate type ``` Yet this works fine: ``` string str = "...
A lambda expression can either be converted to a delegate type or an expression tree - but it has to know *which* delegate type. Just knowing the signature isn't enough. For instance, suppose I have: ``` public delegate void Action1(); public delegate void Action2(); ... Delegate x = () => Console.WriteLine("hi"); ...
411,592
<p>I have a <code>StreamReader</code> object that I initialized with a stream, now I want to save this stream to disk (the stream may be a <code>.gif</code> or <code>.jpg</code> or <code>.pdf</code>).</p> <p>Existing Code:</p> <pre><code>StreamReader sr = new StreamReader(myOtherObject.InputStream); </code></pre> <o...
[ { "answer_id": 411605, "author": "Jon Skeet", "author_id": 22656, "author_profile": "https://Stackoverflow.com/users/22656", "pm_score": 9, "selected": false, "text": "<p>You <em>must not</em> use <code>StreamReader</code> for binary files (like gifs or jpgs). <code>StreamReader</code> i...
2009/01/04
[ "https://Stackoverflow.com/questions/411592", "https://Stackoverflow.com", "https://Stackoverflow.com/users/50700/" ]
I have a `StreamReader` object that I initialized with a stream, now I want to save this stream to disk (the stream may be a `.gif` or `.jpg` or `.pdf`). Existing Code: ``` StreamReader sr = new StreamReader(myOtherObject.InputStream); ``` 1. I need to save this to disk (I have the filename). 2. In the future I may...
As highlighted by Tilendor in Jon Skeet's answer, streams have a `CopyTo` method since .NET 4. ``` var fileStream = File.Create("C:\\Path\\To\\File"); myOtherObject.InputStream.Seek(0, SeekOrigin.Begin); myOtherObject.InputStream.CopyTo(fileStream); fileStream.Close(); ``` Or with the `using` syntax: ``` using (var...
411,628
<p>I am trying to learn ASP.NET MVC and I hit this problem: I have a "view product details" form that I want to reuse as an add/edit form. (When you look at the product details, if you have the rights to do it an Edit link should appear; it should redisplay the same form, but with the textbox fields enabled this time.)...
[ { "answer_id": 411665, "author": "Todd Smith", "author_id": 31624, "author_profile": "https://Stackoverflow.com/users/31624", "pm_score": 4, "selected": true, "text": "<p>You can always pass in a value indicating what mode you're in or what privileges you have:</p>\n\n<pre><code>ViewData...
2009/01/04
[ "https://Stackoverflow.com/questions/411628", "https://Stackoverflow.com", "https://Stackoverflow.com/users/31793/" ]
I am trying to learn ASP.NET MVC and I hit this problem: I have a "view product details" form that I want to reuse as an add/edit form. (When you look at the product details, if you have the rights to do it an Edit link should appear; it should redisplay the same form, but with the textbox fields enabled this time.) R...
You can always pass in a value indicating what mode you're in or what privileges you have: ``` ViewData.Model.CanEdit ``` So you might want to create a composite class for your model instead of just using Product ``` public class ProductViewData { public Product Product {get; set;} public bool CanEdit {get;...
411,631
<p>I've got a bunch of <a href="http://www.unicode.org/charts/PDF/U1F000.pdf" rel="nofollow noreferrer">unicode characters</a> from U1F000 and upwards, and I'm wondering how to represent them in Java. A Java unicode escape is on the form "\uXXXX" and the Java language specification says that "Representing supplementary...
[ { "answer_id": 411638, "author": "Jon Skeet", "author_id": 22656, "author_profile": "https://Stackoverflow.com/users/22656", "pm_score": 1, "selected": false, "text": "<p>You'd need to work out the appropriate surrogate pair if you want it in a string literal. (In C# you could write \"\\...
2009/01/04
[ "https://Stackoverflow.com/questions/411631", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13051/" ]
I've got a bunch of [unicode characters](http://www.unicode.org/charts/PDF/U1F000.pdf) from U1F000 and upwards, and I'm wondering how to represent them in Java. A Java unicode escape is on the form "\uXXXX" and the Java language specification says that "Representing supplementary characters requires two consecutive Uni...
Jon's answer should work, but you can also use the `appendCodePoint` method in StringBuilder or StringBuffer. ``` StringBuilder sb = new StringBuilder(); sb.appendCodePoint(0x1f000); ``` Both techniques do the conversion to surrogate pairs for you. It sounds like your problem now is getting the characters to displa...
411,632
<p>OS X 10.5.6.</p> <p>My Eclipse 3.4 is going crazy lately. </p> <p>After innocent operations like typing text or moving some files in Navigator view or saving, it sometimes starts "waiting on background operation", and eats one CPU core, shuffling back and forth tens of megabytes of memory.</p> <p>I suspect some o...
[ { "answer_id": 411638, "author": "Jon Skeet", "author_id": 22656, "author_profile": "https://Stackoverflow.com/users/22656", "pm_score": 1, "selected": false, "text": "<p>You'd need to work out the appropriate surrogate pair if you want it in a string literal. (In C# you could write \"\\...
2009/01/04
[ "https://Stackoverflow.com/questions/411632", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6236/" ]
OS X 10.5.6. My Eclipse 3.4 is going crazy lately. After innocent operations like typing text or moving some files in Navigator view or saving, it sometimes starts "waiting on background operation", and eats one CPU core, shuffling back and forth tens of megabytes of memory. I suspect some of plug-ins went rogue. ...
Jon's answer should work, but you can also use the `appendCodePoint` method in StringBuilder or StringBuffer. ``` StringBuilder sb = new StringBuilder(); sb.appendCodePoint(0x1f000); ``` Both techniques do the conversion to surrogate pairs for you. It sounds like your problem now is getting the characters to displa...
411,646
<p>I've been reading a lot lately about how joins in DB queries slow things down. Evidently Google App Engine doesn't even allow them.</p> <p>I'm wondering how people design an app with no joins though. For example I'm working on an app that has <code>contacts</code> and <code>organizations</code>. A contact can be in...
[ { "answer_id": 411655, "author": "Robert Gamble", "author_id": 25222, "author_profile": "https://Stackoverflow.com/users/25222", "pm_score": 2, "selected": false, "text": "<p>You use the <code>db.ReferenceProperty</code> to link objects, see <a href=\"http://blog.arbingersys.com/2008/04/...
2009/01/04
[ "https://Stackoverflow.com/questions/411646", "https://Stackoverflow.com", "https://Stackoverflow.com/users/42595/" ]
I've been reading a lot lately about how joins in DB queries slow things down. Evidently Google App Engine doesn't even allow them. I'm wondering how people design an app with no joins though. For example I'm working on an app that has `contacts` and `organizations`. A contact can be in many organizations and an organ...
Usually when you are talking about databases not allowing joins, you are talking about very large databases that don't necessarily fit on one server. The recent examples being the cloud databases like [Amazon's SimpleDB](http://aws.amazon.com/simpledb/), [Microsoft's SQL Data Services](http://www.microsoft.com/azure/da...
411,653
<p>Whenever I make a new file in xcode, it puts something like this at the top of the file:</p> <pre><code>// Copyright __MyCompanyName__ 2008. All rights reserved. </code></pre> <p>How can I change that to something useful?</p> <p>Update: <a href="https://stackoverflow.com/questions/33720/change-templates-in-xcod...
[ { "answer_id": 411662, "author": "Chuck", "author_id": 50742, "author_profile": "https://Stackoverflow.com/users/50742", "pm_score": 5, "selected": true, "text": "<p>As of Xcode 3, it will use the \"company\" field from your Address Book card.</p>\n" }, { "answer_id": 28443175, ...
2009/01/04
[ "https://Stackoverflow.com/questions/411653", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13009/" ]
Whenever I make a new file in xcode, it puts something like this at the top of the file: ``` // Copyright __MyCompanyName__ 2008. All rights reserved. ``` How can I change that to something useful? Update: [found the answer here](https://stackoverflow.com/questions/33720/change-templates-in-xcode#33789).
As of Xcode 3, it will use the "company" field from your Address Book card.
411,660
<p>What's pros and cons of using Enterprise Library Unity vs other IoC containers (Windsor, Spring.Net, Autofac ..)?</p>
[ { "answer_id": 411704, "author": "rodbv", "author_id": 79101, "author_profile": "https://Stackoverflow.com/users/79101", "pm_score": 3, "selected": false, "text": "<p>As far as I've seen they are pretty much the same, except for a few implementation details here and there. The biggest ad...
2009/01/04
[ "https://Stackoverflow.com/questions/411660", "https://Stackoverflow.com", "https://Stackoverflow.com/users/50974/" ]
What's pros and cons of using Enterprise Library Unity vs other IoC containers (Windsor, Spring.Net, Autofac ..)?
I am preparing a presentation for a usergroup. As such I just went through a bunch of them. Namely: AutoFac, MEF, Ninject, Spring.Net, StructureMap, Unity, and Windsor. I wanted to show off the 90% case (constructor injection, which is mainly what people use an IOC for anyway). [You can check out the solution here (VS...
411,688
<p>I am looking to extend jQuery so I can easily retrieve the tagName of the first element in a jQuery object. This is what I have come up with, but it doesn't seem to work:</p> <pre><code>$.fn.tagName = function() { return this.each(function() { return this.tagName; }); } alert($('#testElement').tagNa...
[ { "answer_id": 411692, "author": "Dan Herbert", "author_id": 392, "author_profile": "https://Stackoverflow.com/users/392", "pm_score": 6, "selected": true, "text": "<p>Try this instead:</p>\n\n<pre><code>$.fn.tagName = function() {\n return this.get(0).tagName;\n}\nalert($('#testEleme...
2009/01/04
[ "https://Stackoverflow.com/questions/411688", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5441/" ]
I am looking to extend jQuery so I can easily retrieve the tagName of the first element in a jQuery object. This is what I have come up with, but it doesn't seem to work: ``` $.fn.tagName = function() { return this.each(function() { return this.tagName; }); } alert($('#testElement').tagName()); ``` A...
Try this instead: ``` $.fn.tagName = function() { return this.get(0).tagName; } alert($('#testElement').tagName()); ``` To explain a little bit more of why your original example didn't work, the `each()` method will always return the original jQuery object (unless the jQuery object itself was modified). To see w...
411,709
<p>How do you replicate this in F#?</p> <pre><code>interface IMarker { // No members here } class MyClass : IMarker { // can contain code } </code></pre> <p>Update: The following code does define marker interface, but none of the answers so far manages to producde class that implements this marker interface (see...
[ { "answer_id": 411731, "author": "Pete OHanlon", "author_id": 43635, "author_profile": "https://Stackoverflow.com/users/43635", "pm_score": -1, "selected": false, "text": "<p>Off the top of my head (without firing up Visual Studio):</p>\n\n<pre><code>type IMarker ;\n\ntype MyClass =\n i...
2009/01/04
[ "https://Stackoverflow.com/questions/411709", "https://Stackoverflow.com", "https://Stackoverflow.com/users/28912/" ]
How do you replicate this in F#? ``` interface IMarker { // No members here } class MyClass : IMarker { // can contain code } ``` Update: The following code does define marker interface, but none of the answers so far manages to producde class that implements this marker interface (see MyClass above) ``` type ...
``` type IMarker = interface end type MyClass = interface IMarker ``` (Update) F# always defines interfaces implicitly , you need to cast to the interface in order to use it. [Why F# interface differs greatly from C#](http://cs.hubfs.net/forums/thread/7523.aspx)
411,724
<p>I have a parts database that I am going to be constantly querying for a quoting system. The parts database has 1,400,000+ records in it. The users are just going to start typing part numbers, which they expect the system to be able to find after only a few characters, so I need to be able to do a wildcard search, ...
[ { "answer_id": 411732, "author": "Jonathan Leffler", "author_id": 15168, "author_profile": "https://Stackoverflow.com/users/15168", "pm_score": 2, "selected": false, "text": "<p>Most (good) optimizers will make a stab at using an index for a LIKE clause where the wild card is not appeari...
2009/01/04
[ "https://Stackoverflow.com/questions/411724", "https://Stackoverflow.com", "https://Stackoverflow.com/users/50356/" ]
I have a parts database that I am going to be constantly querying for a quoting system. The parts database has 1,400,000+ records in it. The users are just going to start typing part numbers, which they expect the system to be able to find after only a few characters, so I need to be able to do a wildcard search, somet...
Most (good) optimizers will make a stab at using an index for a LIKE clause where the wild card is not appearing first. If the pattern starts with a wild card, there is much less that they can do. If the index is a B-Tree index, as opposed to a hash index (ISAM systems usually use B-Trees), then the leading characters...
411,726
<p>On a program of me, the <a href="http://www.splint.org/" rel="nofollow noreferrer">splint</a> checker warns:</p> <pre><code>expat-test.c:23:1: Function exported but not used outside expat-test: start A declaration is exported, but not used outside this module. Declaration can use static qualifier. (Use -exportl...
[ { "answer_id": 411742, "author": "Christoph", "author_id": 48015, "author_profile": "https://Stackoverflow.com/users/48015", "pm_score": 3, "selected": true, "text": "<p>Do you call <code>XML_SetElementHandler()</code> in the same translation unit (normally the .c source file) in which <...
2009/01/04
[ "https://Stackoverflow.com/questions/411726", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15625/" ]
On a program of me, the [splint](http://www.splint.org/) checker warns: ``` expat-test.c:23:1: Function exported but not used outside expat-test: start A declaration is exported, but not used outside this module. Declaration can use static qualifier. (Use -exportlocal to inhibit warning) expat-test.c:38:1: Defi...
Do you call `XML_SetElementHandler()` in the same translation unit (normally the .c source file) in which `start()` is defined? If so, the warning might be correct: Add `static` to the function definition and check if your application still links without errors.
411,738
<p>I am trying to write a static function to Or two expressions, but recieve the following error:</p> <blockquote> <p>The parameter 'item' is not in scope.</p> <p>Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more informatio...
[ { "answer_id": 411799, "author": "Jb Evain", "author_id": 36702, "author_profile": "https://Stackoverflow.com/users/36702", "pm_score": 4, "selected": true, "text": "<p>The issue is that the Expression you're creating in the method OrExpressions reuses the body of the two expressions. Th...
2009/01/04
[ "https://Stackoverflow.com/questions/411738", "https://Stackoverflow.com", "https://Stackoverflow.com/users/51275/" ]
I am trying to write a static function to Or two expressions, but recieve the following error: > > The parameter 'item' is not in scope. > > > Description: An unhandled exception > occurred during the execution of the > current web request. Please review the > stack trace for more information about > the error ...
The issue is that the Expression you're creating in the method OrExpressions reuses the body of the two expressions. Those bodies will contain references to their own ParameterExpression that has been defined in FilterExpression. A fix would be to rewrite the left and right parts to use the new ParameterExpression. Or...
411,740
<p>I've used the <a href="http://perldoc.perl.org/functions/localtime.html" rel="noreferrer">localtime</a> function in Perl to get the current date and time but need to parse in existing dates. I have a GMT date in the following format: "20090103 12:00" I'd like to parse it into a date object I can work with and then c...
[ { "answer_id": 411794, "author": "Jonathan Leffler", "author_id": 15168, "author_profile": "https://Stackoverflow.com/users/15168", "pm_score": 2, "selected": false, "text": "<p>Take your pick:</p>\n\n<ul>\n<li><a href=\"http://search.cpan.org/perldoc?DateTime\" rel=\"nofollow noreferrer...
2009/01/04
[ "https://Stackoverflow.com/questions/411740", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14744/" ]
I've used the [localtime](http://perldoc.perl.org/functions/localtime.html) function in Perl to get the current date and time but need to parse in existing dates. I have a GMT date in the following format: "20090103 12:00" I'd like to parse it into a date object I can work with and then convert the GMT time/date into m...
Because the Perl built in date handling interfaces are kind of clunky and you wind up passing around a half dozen variables, the better way is to use either [DateTime](http://search.cpan.org/perldoc?DateTime) or [Time::Piece](http://search.cpan.org/perldoc?Time::Piece). DateTime is the all-singing, all-dancing Perl dat...
411,746
<p>In a Rails 2.2 project, I'm having users put together a list of projects into a portfolio object (i.e.: <code>PortfolioHasManyProjects</code>). On the page is a Rails form for regular text, titles etc., as well as 2 sortable lists; the lists are used for dragging projects from the global-project-list into your portf...
[ { "answer_id": 423971, "author": "Silviu Postavaru", "author_id": 3718, "author_profile": "https://Stackoverflow.com/users/3718", "pm_score": 2, "selected": false, "text": "<p>This is a <a href=\"http://henrik.nyh.se/2008/11/rails-jquery-sortables\" rel=\"nofollow noreferrer\">nice solut...
2009/01/04
[ "https://Stackoverflow.com/questions/411746", "https://Stackoverflow.com", "https://Stackoverflow.com/users/51446/" ]
In a Rails 2.2 project, I'm having users put together a list of projects into a portfolio object (i.e.: `PortfolioHasManyProjects`). On the page is a Rails form for regular text, titles etc., as well as 2 sortable lists; the lists are used for dragging projects from the global-project-list into your portfolio-project-l...
This is a [nice solution](http://henrik.nyh.se/2008/11/rails-jquery-sortables) if you are using jQuery. From the linked blog: > > I just wrote some sortable code for a Rails/jQuery app and figured I would blog just how little code it takes, and also the single MySQL query I used on the backend. > > >
411,752
<p>What is the best way to generate a string of <code>\t</code>'s in C#</p> <p>I am learning C# and experimenting with different ways of saying the same thing.</p> <p><code>Tabs(uint t)</code> is a function that returns a <code>string</code> with <code>t</code> amount of <code>\t</code>'s</p> <p>For example <code>Tabs(...
[ { "answer_id": 411762, "author": "Christian C. Salvadó", "author_id": 5445, "author_profile": "https://Stackoverflow.com/users/5445", "pm_score": 12, "selected": true, "text": "<p>What about this:</p>\n<pre><code>string tabs = new string('\\t', n);\n</code></pre>\n<p>Where <code>n</code>...
2009/01/04
[ "https://Stackoverflow.com/questions/411752", "https://Stackoverflow.com", "https://Stackoverflow.com/users/47630/" ]
What is the best way to generate a string of `\t`'s in C# I am learning C# and experimenting with different ways of saying the same thing. `Tabs(uint t)` is a function that returns a `string` with `t` amount of `\t`'s For example `Tabs(3)` returns `"\t\t\t"` Which of these three ways of implementing `Tabs(uint numT...
What about this: ``` string tabs = new string('\t', n); ``` Where `n` is the number of times you want to repeat the string. Or better: ``` static string Tabs(int n) { return new string('\t', n); } ```
411,758
<p>I'm not sure if this is the right place to post these kind of questions, if it's not so, please (politely) let me know... :-)</p> <p>I need to save files greater than 16MB on a mysql database from a php site...</p> <p>I've already changed the c:\xampp\mysql\bin\my.cnf</p> <p>and set max_allowed_packet to 16 MB, a...
[ { "answer_id": 411863, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 1, "selected": false, "text": "<p>I have come across this issue in the past with PHP and MySQL.</p>\n\n<p>I remember that my solution broke the binary up int...
2009/01/04
[ "https://Stackoverflow.com/questions/411758", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I'm not sure if this is the right place to post these kind of questions, if it's not so, please (politely) let me know... :-) I need to save files greater than 16MB on a mysql database from a php site... I've already changed the c:\xampp\mysql\bin\my.cnf and set max\_allowed\_packet to 16 MB, and everything worked f...
**Edit: my original answer is incorrect.** The version of the mysql client library php was linked against was (significantly) older than the mysql server version, which made it appear that what I wrote was true; however it now seems not to be the case. When I recompile php against the correct mysql client libraries up...
411,761
<p>Is it possible to have a variable number of fields using django forms?</p> <p>The specific application is this:</p> <p>A user can upload as many pictures as they want on the image upload form. Once the pictures are uploaded they are taken to a page where they can give the pictures a name and description. The numbe...
[ { "answer_id": 411852, "author": "Alcides", "author_id": 28516, "author_profile": "https://Stackoverflow.com/users/28516", "pm_score": 3, "selected": false, "text": "<p>If you run</p>\n\n<pre><code>python manage.py shell\n</code></pre>\n\n<p>and type:</p>\n\n<pre><code>from app.forms imp...
2009/01/04
[ "https://Stackoverflow.com/questions/411761", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2908/" ]
Is it possible to have a variable number of fields using django forms? The specific application is this: A user can upload as many pictures as they want on the image upload form. Once the pictures are uploaded they are taken to a page where they can give the pictures a name and description. The number of pictures wil...
Yes, it's possible to create forms dynamically in Django. You can even mix and match dynamic fields with normal fields. ``` class EligibilityForm(forms.Form): def __init__(self, *args, **kwargs): super(EligibilityForm, self).__init__(*args, **kwargs) # dynamic fields here ... self.fields['p...
411,810
<p>Without having the full module path of a Django model, is it possible to do something like:</p> <pre><code>model = 'User' [in Django namespace] model.objects.all() </code></pre> <p>...as opposed to:</p> <pre><code>User.objects.all(). </code></pre> <p>EDIT: I am trying to make this call based on command-line inpu...
[ { "answer_id": 411814, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 1, "selected": false, "text": "<pre><code>from django.authx.models import User\nmodel = User\nmodel.objects.all()\n</code></pre>\n" }, { "answer_id":...
2009/01/04
[ "https://Stackoverflow.com/questions/411810", "https://Stackoverflow.com", "https://Stackoverflow.com/users/44440/" ]
Without having the full module path of a Django model, is it possible to do something like: ``` model = 'User' [in Django namespace] model.objects.all() ``` ...as opposed to: ``` User.objects.all(). ``` EDIT: I am trying to make this call based on command-line input. Is it possible to avoid the import statement, ...
I think you're looking for this: ``` from django.db.models.loading import get_model model = get_model('app_name', 'model_name') ``` There are other methods, of course, but this is the way I'd handle it if you don't know what models file you need to import into your namespace. (Note there's really no way to safely ge...
411,823
<p>I'm just learning Qt with C++. I have successfully implemented signals and slots to trap standard events like <code>ButtonPushed()</code>, etc. However, I want to have a function called when I mouse over and mouse out of a <code>QLabel</code>. It looks like <a href="http://doc.qt.io/qt-4.8/qhoverevent.html" rel="nof...
[ { "answer_id": 411849, "author": "shoosh", "author_id": 9611, "author_profile": "https://Stackoverflow.com/users/9611", "pm_score": 4, "selected": false, "text": "<p>According to the document link you give you're only going to get this QHoverEvent if your widget has the <code>Qt::WA_Hove...
2009/01/04
[ "https://Stackoverflow.com/questions/411823", "https://Stackoverflow.com", "https://Stackoverflow.com/users/48923/" ]
I'm just learning Qt with C++. I have successfully implemented signals and slots to trap standard events like `ButtonPushed()`, etc. However, I want to have a function called when I mouse over and mouse out of a `QLabel`. It looks like [QHoverEvent](http://doc.qt.io/qt-4.8/qhoverevent.html) will do what I need, but I c...
Using signals and slots for this purpose isn't going to work. `mouseMoveEvent()` is not a signal or meta-method and cannot be connected to a slot. Subclassing the widget class and overriding `mouseMoveEvent()` will allow you to get mouse-move-events, but that is a very heavyweight way to accomplish this (and adds one...
411,825
<p>I've have just been stumped with this problem for an hour and I annoyingly found the problem eventually.</p> <p><strong>THE CIRCUMSTANCES</strong></p> <p>I have a table which users a string as a primary key, this table has various many to one and many to many relationships all off this primary key.</p> <p>When se...
[ { "answer_id": 447145, "author": "Mark Struzinski", "author_id": 1284, "author_profile": "https://Stackoverflow.com/users/1284", "pm_score": 2, "selected": false, "text": "<p>I have the exact same situation on a ref table in my DB. I mapped the schema file the same way you did. In code, ...
2009/01/04
[ "https://Stackoverflow.com/questions/411825", "https://Stackoverflow.com", "https://Stackoverflow.com/users/26081/" ]
I've have just been stumped with this problem for an hour and I annoyingly found the problem eventually. **THE CIRCUMSTANCES** I have a table which users a string as a primary key, this table has various many to one and many to many relationships all off this primary key. When searching for multiple items from the t...
I have the exact same situation on a ref table in my DB. I mapped the schema file the same way you did. In code, when I query for the record by Primary Key, I do the following using an instance of the NHibernate ISession: ``` return session.Get<T>(id); ``` In this statement, T is the type you are querying for, and i...
411,837
<p>This is in continuation with the question posted here: <a href="https://stackoverflow.com/questions/408358/finding-the-center-of-mass-on-a-2d-bitmap">Finding the center of mass on a 2D bitmap</a> which talked about finding the center of mass in a boolean matrix, as the example was given.</p> <p>Suppose now we expan...
[ { "answer_id": 411855, "author": "PEZ", "author_id": 44639, "author_profile": "https://Stackoverflow.com/users/44639", "pm_score": 3, "selected": true, "text": "<p>I think I would check each point in the matrix and figure out it's mass based on it's neighbours. The mass for points would ...
2009/01/04
[ "https://Stackoverflow.com/questions/411837", "https://Stackoverflow.com", "https://Stackoverflow.com/users/24545/" ]
This is in continuation with the question posted here: [Finding the center of mass on a 2D bitmap](https://stackoverflow.com/questions/408358/finding-the-center-of-mass-on-a-2d-bitmap) which talked about finding the center of mass in a boolean matrix, as the example was given. Suppose now we expand the matrix to this ...
I think I would check each point in the matrix and figure out it's mass based on it's neighbours. The mass for points would fall with say the square of the distance. You could then pick the top four points with a minimum distance from each other. Here's some Python code I whipped together to try to illustrate the appr...
411,841
<p>Adding source files more than one directory away (e.g. ../../source.cpp or ../../../somewhere_else/source.cpp, vs. just source.cpp or ../source.cpp) to the SOURCES= declaration in a WDK/DDK build yields the following error:</p> <pre><code>Ignoring invalid directory prefix in SOURCES= entry </code></pre> <p>Is it p...
[ { "answer_id": 411854, "author": "jrk", "author_id": 3815, "author_profile": "https://Stackoverflow.com/users/3815", "pm_score": 4, "selected": true, "text": "<p>It is not possible to do this directly. <code>build</code> is explicitly designed only to deal with\nsource code in the same o...
2009/01/04
[ "https://Stackoverflow.com/questions/411841", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3815/" ]
Adding source files more than one directory away (e.g. ../../source.cpp or ../../../somewhere\_else/source.cpp, vs. just source.cpp or ../source.cpp) to the SOURCES= declaration in a WDK/DDK build yields the following error: ``` Ignoring invalid directory prefix in SOURCES= entry ``` Is it possible to include remote...
It is not possible to do this directly. `build` is explicitly designed only to deal with source code in the same or parent directory of the `sources` file. It cannot use source files from arbitrary locations. In particular, its dependency-tracking system seems unable to parse and track remote files, and therefore it ex...
411,843
<p>I am currently writing a simple password generator (C#). For that I need some random numbers.</p> <p>Is it OK to simply use the <a href="http://msdn.microsoft.com/en-us/library/system.random.aspx" rel="nofollow noreferrer">Random</a> class that ships with .NET or are there any known problems with that? </p>
[ { "answer_id": 411850, "author": "Michael Haren", "author_id": 29, "author_profile": "https://Stackoverflow.com/users/29", "pm_score": 4, "selected": false, "text": "<p>There is nothing wrong with it -- it's good enough to generate simple passwords. A simple example (<a href=\"https://we...
2009/01/04
[ "https://Stackoverflow.com/questions/411843", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I am currently writing a simple password generator (C#). For that I need some random numbers. Is it OK to simply use the [Random](http://msdn.microsoft.com/en-us/library/system.random.aspx) class that ships with .NET or are there any known problems with that?
There is nothing wrong with it -- it's good enough to generate simple passwords. A simple example ([source](https://web.archive.org/web/20110926062531/http://authors.aspalliance.com:80/brettb/RandomNumbersInCSharp.asp)): ``` Random RandomClass = new Random(); int RandomNumber = RandomClass.Next(); // Random number bet...
411,857
<p>This is an erlang problem, it seems. I have this code to test the client sending data, written in Actionscript 3:</p> <pre><code>var socket:Socket=new Socket("localhost", 2345); socket.addEventListener(Event.CONNECT, connected); private function connected(event:Event):void { socket.writeInt(12); //packet lengt...
[ { "answer_id": 413197, "author": "Alexey Romanov", "author_id": 9204, "author_profile": "https://Stackoverflow.com/users/9204", "pm_score": 2, "selected": false, "text": "<p>Try not closing <code>Listen</code> before receiving data.</p>\n" }, { "answer_id": 413368, "author": ...
2009/01/04
[ "https://Stackoverflow.com/questions/411857", "https://Stackoverflow.com", "https://Stackoverflow.com/users/49018/" ]
This is an erlang problem, it seems. I have this code to test the client sending data, written in Actionscript 3: ``` var socket:Socket=new Socket("localhost", 2345); socket.addEventListener(Event.CONNECT, connected); private function connected(event:Event):void { socket.writeInt(12); //packet length, should be c...
I am about to answer my own question in case anyone wants to know the answer. Using a packet sniffer, I was able to find out that Flash was indeed sending the wrong packet. Although I don't know the significance of what the packet data actually was, I know what the problem was. I guess it was because I opened the Flas...
411,876
<p>I'm converting an algorithm I wrote in Java to Objective-C. In java the BigDecimal class handles base-10 numbers and can take the primitive double as a constructor arg. In Cocoa's NSDecimalNumber class, however, there is no direct way to construct an instance using a primitive double.</p> <p>Currently I'm using t...
[ { "answer_id": 411891, "author": "Chuck", "author_id": 50742, "author_profile": "https://Stackoverflow.com/users/50742", "pm_score": 5, "selected": true, "text": "<p>NSNumber, the superclass of NSDecimalNumber, has a +numberWithDouble: method. That's what you want.</p>\n" }, { "a...
2009/01/04
[ "https://Stackoverflow.com/questions/411876", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4897/" ]
I'm converting an algorithm I wrote in Java to Objective-C. In java the BigDecimal class handles base-10 numbers and can take the primitive double as a constructor arg. In Cocoa's NSDecimalNumber class, however, there is no direct way to construct an instance using a primitive double. Currently I'm using this (smelly)...
NSNumber, the superclass of NSDecimalNumber, has a +numberWithDouble: method. That's what you want.
411,877
<p>I'm trying to implement a "Popular Products" feature. Basically, every time a Product is viewed, I want to log to the database the number of views of that product. Where do I put the hooks for something like this? I have seen things that are based on building some sort of traffic analytics, but I am looking for idea...
[ { "answer_id": 411920, "author": "eelco", "author_id": 8293, "author_profile": "https://Stackoverflow.com/users/8293", "pm_score": 2, "selected": false, "text": "<p>I assume there is a 'view' method in the controller, doing something like</p>\n\n<pre><code>@product = Product.find(params[...
2009/01/04
[ "https://Stackoverflow.com/questions/411877", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I'm trying to implement a "Popular Products" feature. Basically, every time a Product is viewed, I want to log to the database the number of views of that product. Where do I put the hooks for something like this? I have seen things that are based on building some sort of traffic analytics, but I am looking for ideas t...
I assume there is a 'view' method in the controller, doing something like ``` @product = Product.find(params[:id]) ``` If the product has a 'views' field, you can do something like ``` @product.views = @product.views + 1 @product.save ```
411,896
<p>I'm trying to solve the problem of passing a 2-dimensional table into JavaScript AJAX application through SOAP web services. I'm trying to pass data into JavaScript web page through ASP.NET web service declared with following attributes:</p> <pre><code>[WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] [...
[ { "answer_id": 411920, "author": "eelco", "author_id": 8293, "author_profile": "https://Stackoverflow.com/users/8293", "pm_score": 2, "selected": false, "text": "<p>I assume there is a 'view' method in the controller, doing something like</p>\n\n<pre><code>@product = Product.find(params[...
2009/01/04
[ "https://Stackoverflow.com/questions/411896", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14395/" ]
I'm trying to solve the problem of passing a 2-dimensional table into JavaScript AJAX application through SOAP web services. I'm trying to pass data into JavaScript web page through ASP.NET web service declared with following attributes: ``` [WebServiceBinding(ConformsTo = WsiProfiles.BasicProfile1_1)] [System.Web.Scr...
I assume there is a 'view' method in the controller, doing something like ``` @product = Product.find(params[:id]) ``` If the product has a 'views' field, you can do something like ``` @product.views = @product.views + 1 @product.save ```
411,902
<p>I am trying to port my first Django 1.0.2 application to run on OSX/Leopard with Apache + mod_python 3.3.1 + python 2.6.1 (all running in 64-bit mode) and I am experiencing an occasional error when uploading a file that was not present when testing with the Django development server. </p> <p>The code for the upload...
[ { "answer_id": 411971, "author": "Dana the Sane", "author_id": 2567, "author_profile": "https://Stackoverflow.com/users/2567", "pm_score": 0, "selected": false, "text": "<p>How large is the file? It may take long enough to upload that the upload script times out, so try increasing the ex...
2009/01/04
[ "https://Stackoverflow.com/questions/411902", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I am trying to port my first Django 1.0.2 application to run on OSX/Leopard with Apache + mod\_python 3.3.1 + python 2.6.1 (all running in 64-bit mode) and I am experiencing an occasional error when uploading a file that was not present when testing with the Django development server. The code for the upload is simil...
Using mod\_wsgi made the problem go away for Firefox. Limiting my research to an interaction problem between Apache and Safari, I stumbled upon this bug report for Apache <https://bugs.webkit.org/show_bug.cgi?id=5760> that describes something very similar to what is happening and it is apparently still open. Reading ...
411,918
<p>We're getting a number of warnings in the Application Event Viewer on our IIS installation. We have an AppPool set up which contains two websites (both ColdFusion sites, not .NET).</p> <p>The Event Viewer shows the following warning:</p> <pre><code>A process serving application pool 'HighPriorityApps' exceeded tim...
[ { "answer_id": 411965, "author": "olle", "author_id": 48383, "author_profile": "https://Stackoverflow.com/users/48383", "pm_score": 0, "selected": false, "text": "<p>Each app pool has a recycle time set for the workerproces. This message basically means the worker process couldn't gracef...
2009/01/04
[ "https://Stackoverflow.com/questions/411918", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2136/" ]
We're getting a number of warnings in the Application Event Viewer on our IIS installation. We have an AppPool set up which contains two websites (both ColdFusion sites, not .NET). The Event Viewer shows the following warning: ``` A process serving application pool 'HighPriorityApps' exceeded time limits during shut...
We fixed a similar problem with config alone. A great book to help here is Microsoft IIS 6.0 Administrator's Pocket Cunsultant by William R Stanek. I'll try to help here. I've seen this before. At my company we always split the separate sites into separate Application pools with ColdFusion running on them For each...
411,921
<p>This is probably one of the most common tasks / problems when programming; You need to store the configuration of your application somewhere.</p> <p>While I'm trying to create a webserver or other applications, I'd like to keep the code as clean as possible since my main interest in programming is architecture. Thi...
[ { "answer_id": 411958, "author": "Charlie Martin", "author_id": 35092, "author_profile": "https://Stackoverflow.com/users/35092", "pm_score": 3, "selected": false, "text": "<p>There are a number of ways. You <em>don't</em> need to use fgetc. You should probably read the stdio man page,...
2009/01/04
[ "https://Stackoverflow.com/questions/411921", "https://Stackoverflow.com", "https://Stackoverflow.com/users/39106/" ]
This is probably one of the most common tasks / problems when programming; You need to store the configuration of your application somewhere. While I'm trying to create a webserver or other applications, I'd like to keep the code as clean as possible since my main interest in programming is architecture. This results ...
Okay, so let's hit the other part. You need to think about what you'd like to have as your "language". In the UNIX world, the sort of canonical version is probably whitespace-delimited text (think `/etc/hosts`) or ":" delimited text (like `/etc/passwd`). You have a couple of options, the simplest in some sense being t...
411,974
<p>My objective is to retry an asynchronous HttpWebRequest when it fails.</p> <p>When I <a href="http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.abort.aspx" rel="nofollow noreferrer">Abort()</a> an HttpWebRequest, I cannot BeginGetResponse() again. So the only way to request again probably is recreat...
[ { "answer_id": 412135, "author": "casperOne", "author_id": 50776, "author_profile": "https://Stackoverflow.com/users/50776", "pm_score": 2, "selected": false, "text": "<p>Where are you trying to serialize the request? It might be a good idea to serialize the request <em>before</em> you ...
2009/01/05
[ "https://Stackoverflow.com/questions/411974", "https://Stackoverflow.com", "https://Stackoverflow.com/users/48465/" ]
My objective is to retry an asynchronous HttpWebRequest when it fails. When I [Abort()](http://msdn.microsoft.com/en-us/library/system.net.httpwebrequest.abort.aspx) an HttpWebRequest, I cannot BeginGetResponse() again. So the only way to request again probably is recreate the HttpWebRequest object. It seems to requir...
### It's possible! You just need to create a new `HttpWebRequest` and copy all of the properties over to it from the old object via reflection. Here's an **extension method** that does this: ``` /// <summary> /// Clones a HttpWebRequest for retrying a failed HTTP request. /// </summary> /// <param name="original"></...
411,982
<p>For my Swing project, I need to support both <strong>Java 5</strong> and <strong>Java 6</strong>. I have defined a custom <code>JComponent</code> (call it <code>Picture</code>) and, after embedding it in a <code>JScrollPane</code>, I put it in a <code>JPanel</code> that uses DesignGridLayout manager. </p> <p>Design...
[ { "answer_id": 412002, "author": "Lawrence Dol", "author_id": 8946, "author_profile": "https://Stackoverflow.com/users/8946", "pm_score": 0, "selected": false, "text": "<p>You can use reflection to try to get the CONSTANT_ASCENT return value by name. If it can't be reflected, you are J5...
2009/01/05
[ "https://Stackoverflow.com/questions/411982", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1440720/" ]
For my Swing project, I need to support both **Java 5** and **Java 6**. I have defined a custom `JComponent` (call it `Picture`) and, after embedding it in a `JScrollPane`, I put it in a `JPanel` that uses DesignGridLayout manager. DesignGridLayout supports baseline alignment thanks to **swing-layout** open source li...
I would make a subclass of Picture, perhaps called PictureJava6, which implemented the getBaselineResizeBehaviour(), and when creating instances of Picture, do: ``` public Component pictureFactory() { if(javaVersion > "1.6") { return new PictureJava6(); } else { return new Picture(); } } `...
412,014
<p>I'm trying to make a form invisible for x amount of time in c#. Any ideas?</p> <p>Thanks, Jon</p>
[ { "answer_id": 412029, "author": "BFree", "author_id": 15861, "author_profile": "https://Stackoverflow.com/users/15861", "pm_score": 2, "selected": false, "text": "<p>At the class level do something like this:</p>\n\n<pre><code>Timer timer = new Timer();\nprivate int counter = 0;\n</code...
2009/01/05
[ "https://Stackoverflow.com/questions/412014", "https://Stackoverflow.com", "https://Stackoverflow.com/users/40399/" ]
I'm trying to make a form invisible for x amount of time in c#. Any ideas? Thanks, Jon
BFree has posted similar code in the time it took me to test this, but here's my attempt: ``` this.Hide(); var t = new System.Windows.Forms.Timer { Interval = 3000 // however long you want to hide for }; t.Tick += (x, y) => { t.Enabled = false; this.Show(); }; t.Enabled = true; ```
412,019
<p>I've been profiling an application all day long and, having optimized a couple bits of code, I'm left with this on my todo list. It's the activation function for a neural network, which gets called over a 100 million times. According to dotTrace, it amounts to about 60% of the overall function time.</p> <p>How woul...
[ { "answer_id": 412023, "author": "Vilx-", "author_id": 41360, "author_profile": "https://Stackoverflow.com/users/41360", "pm_score": 2, "selected": false, "text": "<p>Idea: Perhaps you can make a (large) lookup table with the values pre-calculated?</p>\n" }, { "answer_id": 412027...
2009/01/05
[ "https://Stackoverflow.com/questions/412019", "https://Stackoverflow.com", "https://Stackoverflow.com/users/40164/" ]
I've been profiling an application all day long and, having optimized a couple bits of code, I'm left with this on my todo list. It's the activation function for a neural network, which gets called over a 100 million times. According to dotTrace, it amounts to about 60% of the overall function time. How would you opti...
Try: ``` public static float Sigmoid(double value) { return 1.0f / (1.0f + (float) Math.Exp(-value)); } ``` **EDIT:** I did a quick benchmark. On my machine, the above code is about 43% faster than your method, and this mathematically-equivalent code is the teeniest bit faster (46% faster than the original): ``...
412,022
<p>I have a stored procedure in my database that calculates the distance between two lat/long pairs. This stored procedure is called "DistanceBetween". I have a SQL statement allows a user to search for all items in the Items table ordered by the distance to a supplied lat/long coordinate. The SQL statement is as follo...
[ { "answer_id": 423176, "author": "Sam", "author_id": 47636, "author_profile": "https://Stackoverflow.com/users/47636", "pm_score": 1, "selected": false, "text": "<p>You could try: </p>\n\n<pre><code>session.CreateSqlQuery(@\"SELECT {item.*}, dbo.DistanceBetween(:lat1, :lat2, {item}.Latit...
2009/01/05
[ "https://Stackoverflow.com/questions/412022", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1574/" ]
I have a stored procedure in my database that calculates the distance between two lat/long pairs. This stored procedure is called "DistanceBetween". I have a SQL statement allows a user to search for all items in the Items table ordered by the distance to a supplied lat/long coordinate. The SQL statement is as follows:...
There are basically three approaches that can be used, some of which have already been discussed: 1. Use an HQL query or `CreateCriteria`/`ICriteria` query; *downsides:* it is not part of the entities/DAL; *upsides:* it is flexible; 2. Use a property mapping with a `formula`; *downsides:* it is not always feasible or ...
412,101
<p>Let's say I have a table <em>tbl</em> with columns <em>id</em> and <em>title</em>. I need to change all values of title column:</p> <ol> <li>from 'a-1' to 'a1',</li> <li>from 'a.1' to 'a1',</li> <li>from 'b-1' to 'b1',</li> <li>from 'b.1' to 'b1'.</li> </ol> <p>Right now, I'm performing two UPDATE statements:</p> ...
[ { "answer_id": 412115, "author": "Matt Hamilton", "author_id": 615, "author_profile": "https://Stackoverflow.com/users/615", "pm_score": 2, "selected": false, "text": "<p>If the transformations are as simple as your examples, you could do the update with a little bit of string manipulati...
2009/01/05
[ "https://Stackoverflow.com/questions/412101", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1353085/" ]
Let's say I have a table *tbl* with columns *id* and *title*. I need to change all values of title column: 1. from 'a-1' to 'a1', 2. from 'a.1' to 'a1', 3. from 'b-1' to 'b1', 4. from 'b.1' to 'b1'. Right now, I'm performing two UPDATE statements: ``` UPDATE tbl SET title='a1' WHERE title IN ('a-1', 'a.1') UPDATE tb...
In a more general case, where there could be many hundreds of mappings to each of the new values, you would create a separate table of the old and new values, and then use that in the UPDATE statement. In one dialect of SQL: ``` CREATE TEMP TABLE mapper (old_val CHAR(5) NOT NULL, new_val CHAR(5) NOT NULL); ...multiple...
412,124
<p>I just did a clean build and reinstall of lighttpd 1.4.20 on Mac OS X 10.5 and I can't find the configuration file.</p> <p>My goal was to install lighty to a single directory instead of being spread around, so I used the following commands successfully:</p> <pre><code>./configure --prefix="/usr/local/lighttpd" sud...
[ { "answer_id": 412107, "author": "Lily Ballard", "author_id": 582, "author_profile": "https://Stackoverflow.com/users/582", "pm_score": 0, "selected": false, "text": "<p>No there's not. Is there a particular reason you want every single file in your Unit Test target? This would include m...
2009/01/05
[ "https://Stackoverflow.com/questions/412124", "https://Stackoverflow.com", "https://Stackoverflow.com/users/68788/" ]
I just did a clean build and reinstall of lighttpd 1.4.20 on Mac OS X 10.5 and I can't find the configuration file. My goal was to install lighty to a single directory instead of being spread around, so I used the following commands successfully: ``` ./configure --prefix="/usr/local/lighttpd" sudo make clean sudo mak...
In Xcode, you can create targets which have direct dependencies on each other. There are a number of non-product building targets that can help with this in the *Other* category when adding a new target, depending on how simple or complicated your set-up is. Creating specific targets for running unit tests with a direc...
412,151
<pre><code>public void test() { List&lt;int&gt; list = new List&lt;int&gt;(); list.Add(1); list.Add(2); list.Add(3); for (int i = 1; i &lt;= list.Count; i++) { textBx.Text = list[i].ToString(); // I want it to be textBx1.Text = list[1].ToStrin...
[ { "answer_id": 412160, "author": "Matt Hamilton", "author_id": 615, "author_profile": "https://Stackoverflow.com/users/615", "pm_score": 4, "selected": true, "text": "<p>Sounds like a job for Controls.Find(). You could dynamically build your string and search for the TextBox with that na...
2009/01/05
[ "https://Stackoverflow.com/questions/412151", "https://Stackoverflow.com", "https://Stackoverflow.com/users/42564/" ]
``` public void test() { List<int> list = new List<int>(); list.Add(1); list.Add(2); list.Add(3); for (int i = 1; i <= list.Count; i++) { textBx.Text = list[i].ToString(); // I want it to be textBx1.Text = list[1].ToString(); ...
Sounds like a job for Controls.Find(). You could dynamically build your string and search for the TextBox with that name: ``` var textBox = this.Controls.Find("textBx" + i, true) as TextBox; textBox.Text = list[i].ToString(); ``` This is a bit ugly as it's predicated on your naming convention for the TextBoxes. Pe...
412,165
<p>I've been learning C++, coming from C#, where I've gotten used to using service providers: basically a Dictionary&lt;Type, object&gt;. Unfortunately, I can't figure out how to do this in C++. So the questions are basically:</p> <ol> <li><p>How would I make a dictionary in C++.</p></li> <li><p>How would I use 'Type'...
[ { "answer_id": 412168, "author": "duffymo", "author_id": 37213, "author_profile": "https://Stackoverflow.com/users/37213", "pm_score": 0, "selected": false, "text": "<p>A dictionary sounds like an STL map to me: <code>std::map&lt;K, T&gt;</code>. Have a look at the Standard Template Lib...
2009/01/05
[ "https://Stackoverflow.com/questions/412165", "https://Stackoverflow.com", "https://Stackoverflow.com/users/51071/" ]
I've been learning C++, coming from C#, where I've gotten used to using service providers: basically a Dictionary<Type, object>. Unfortunately, I can't figure out how to do this in C++. So the questions are basically: 1. How would I make a dictionary in C++. 2. How would I use 'Type' with it, as far as I know there is...
I'm assuming that you're trying to map a type to a single object instance. You could try something along these lines: ``` #include <typeinfo> #include <map> #include <string> using namespace std; class SomeClass { public: virtual ~SomeClass() {} // virtual function to get a v-table }; struct type_info_less { ...
412,169
<p>How do I find an item in array which has the most occurrences?</p> <pre><code>[1, 1, 1, 2, 3].mode =&gt; 1 ['cat', 'dog', 'snake', 'dog'].mode =&gt; dog </code></pre>
[ { "answer_id": 412177, "author": "Sophie Alpert", "author_id": 49485, "author_profile": "https://Stackoverflow.com/users/49485", "pm_score": 7, "selected": true, "text": "<p>First build a hash mapping each value in the array to its frequency…</p>\n\n<pre><code>arr = [1, 1, 1, 2, 3]\n\nfr...
2009/01/05
[ "https://Stackoverflow.com/questions/412169", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
How do I find an item in array which has the most occurrences? ``` [1, 1, 1, 2, 3].mode => 1 ['cat', 'dog', 'snake', 'dog'].mode => dog ```
First build a hash mapping each value in the array to its frequency… ``` arr = [1, 1, 1, 2, 3] freq = arr.inject(Hash.new(0)) { |h,v| h[v] += 1; h } #=> {1=>3, 2=>1, 3=>1} ``` … then use the frequency table to find the element with the highest frequency: ``` arr.max_by { |v| freq[v] } #=> 1 ```
412,174
<p>In debugging a game that is full screen (on one of my two monitors) when it crashes and the debugger (on the other monitor, not captured) displays the crash location, the cursor is still hidden. Is there any way to force the cursor to reappear? I can click around blindly and it works, but it's not terrible accurate....
[ { "answer_id": 412177, "author": "Sophie Alpert", "author_id": 49485, "author_profile": "https://Stackoverflow.com/users/49485", "pm_score": 7, "selected": true, "text": "<p>First build a hash mapping each value in the array to its frequency…</p>\n\n<pre><code>arr = [1, 1, 1, 2, 3]\n\nfr...
2009/01/05
[ "https://Stackoverflow.com/questions/412174", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
In debugging a game that is full screen (on one of my two monitors) when it crashes and the debugger (on the other monitor, not captured) displays the crash location, the cursor is still hidden. Is there any way to force the cursor to reappear? I can click around blindly and it works, but it's not terrible accurate.
First build a hash mapping each value in the array to its frequency… ``` arr = [1, 1, 1, 2, 3] freq = arr.inject(Hash.new(0)) { |h,v| h[v] += 1; h } #=> {1=>3, 2=>1, 3=>1} ``` … then use the frequency table to find the element with the highest frequency: ``` arr.max_by { |v| freq[v] } #=> 1 ```
412,178
<pre><code>int[] mylist = { 2, 4, 5 }; IEnumerable&lt;int&gt; list1 = mylist; list1.ToList().Add(1); // why 1 does not get addedto list1?? </code></pre>
[ { "answer_id": 412185, "author": "ctacke", "author_id": 13154, "author_profile": "https://Stackoverflow.com/users/13154", "pm_score": 5, "selected": true, "text": "<p>Why would it? ToList() generates a new List and the value '1' gets added to it. Since you don't store the return, the n...
2009/01/05
[ "https://Stackoverflow.com/questions/412178", "https://Stackoverflow.com", "https://Stackoverflow.com/users/42564/" ]
``` int[] mylist = { 2, 4, 5 }; IEnumerable<int> list1 = mylist; list1.ToList().Add(1); // why 1 does not get addedto list1?? ```
Why would it? ToList() generates a new List and the value '1' gets added to it. Since you don't store the return, the new list then gets tossed when it's out of scope. ToList() doesn't change the original IEnumerable object list1 or give a new representation (it would be called AsList() if it did).
412,183
<p>I want to convert function object to function.</p> <p>I wrote this code, but it doesn't work.</p> <pre><code>#include &lt;iostream&gt; typedef int (*int_to_int)(int); struct adder { int n_; adder (int n) : n_(n) {} int operator() (int x) { return x + n_; } operator int_to_int () { return ...
[ { "answer_id": 412196, "author": "Henrik Gustafsson", "author_id": 2010, "author_profile": "https://Stackoverflow.com/users/2010", "pm_score": 1, "selected": false, "text": "<p>Instance method pointers are a bit tricky and are completely different beasts compared to 'normal' function poi...
2009/01/05
[ "https://Stackoverflow.com/questions/412183", "https://Stackoverflow.com", "https://Stackoverflow.com/users/28720/" ]
I want to convert function object to function. I wrote this code, but it doesn't work. ``` #include <iostream> typedef int (*int_to_int)(int); struct adder { int n_; adder (int n) : n_(n) {} int operator() (int x) { return x + n_; } operator int_to_int () { return this->*&adder::operator(); ...
**Update**: You told us what you want. I found this question here on SO: [Best method for storing this pointer for use in WndProc](https://stackoverflow.com/questions/117792/best-method-for-storing-this-pointer-for-use-in-wndproc) . I'm not a Windows Programmer, but the Adam Rosenfield guy seem to be right in using Set...
412,184
<p>Back in the ITAR era, there was a <a href="http://www.cypherspace.org/adam/rsa/perl-dh.html" rel="nofollow noreferrer">popular sig that performed Diffie-Hellman key exchange</a>:</p> <pre><code>#!/usr/bin/perl -- -export-a-crypto-system-sig Diffie-Hellman-2-lines ($g,$e,$m)=@ARGV,$m||die"$0 gen exp mod\n";print`ech...
[ { "answer_id": 412254, "author": "ShreevatsaR", "author_id": 4958, "author_profile": "https://Stackoverflow.com/users/4958", "pm_score": 4, "selected": true, "text": "<p>For those unfamiliar with Diffie-Hellman or <code>dc</code> (or Perl): all the program does, if you run it as &quot;<c...
2009/01/05
[ "https://Stackoverflow.com/questions/412184", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14105/" ]
Back in the ITAR era, there was a [popular sig that performed Diffie-Hellman key exchange](http://www.cypherspace.org/adam/rsa/perl-dh.html): ``` #!/usr/bin/perl -- -export-a-crypto-system-sig Diffie-Hellman-2-lines ($g,$e,$m)=@ARGV,$m||die"$0 gen exp mod\n";print`echo "16dio1[d2%Sa2/d0<X+d *La1=z\U$m%0]SX$e"[$g*]\Esz...
For those unfamiliar with Diffie-Hellman or `dc` (or Perl): all the program does, if you run it as "`program g x m`", is output gx(mod m), where g, x, and m are given in hexadecimal. E.g. ``` ./dh.pl 10 2 9 4 ``` because 10 is sixteen and 102 is two-hundred-and-fifty-six, which is 4 mod 9. And the `dc` command `16d...
412,187
<p>I'm trying to implement the Media Player custom field control described in this MSDN article: <a href="http://msdn.microsoft.com/en-us/library/aa981226.aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/aa981226.aspx</a></p> <p>I created a custom site column (of type Link) in a custom content t...
[ { "answer_id": 414512, "author": "George Durzi", "author_id": 36057, "author_profile": "https://Stackoverflow.com/users/36057", "pm_score": 2, "selected": true, "text": "<p>Figured this out ... </p>\n\n<p>I had added the SafeControl entry manually at first to my web.config, and for some ...
2009/01/05
[ "https://Stackoverflow.com/questions/412187", "https://Stackoverflow.com", "https://Stackoverflow.com/users/36057/" ]
I'm trying to implement the Media Player custom field control described in this MSDN article: <http://msdn.microsoft.com/en-us/library/aa981226.aspx> I created a custom site column (of type Link) in a custom content type and followed all the instructions to deploy the solution into SharePoint and add the control to a ...
Figured this out ... I had added the SafeControl entry manually at first to my web.config, and for some reason that didn't work. I'm now including it in manifest.xml like this: ``` <Assembly DeploymentTarget="GlobalAssemblyCache" Location="MyControlAssembly.dll"> <SafeControls> <SafeControl Assembly="MyControl...
412,218
<p>I'm currently a .NET developer, but I'm starting to work with Flex a little bit and I've found the community to be great. There are a lot of great resources out there, but one of the issues I'm running into conceptually is how to organize a flex project. Coming from the standpoint of a "traditional" ASP.NET web ap...
[ { "answer_id": 412247, "author": "ForYourOwnGood", "author_id": 48728, "author_profile": "https://Stackoverflow.com/users/48728", "pm_score": 3, "selected": true, "text": "<p>This is a rough outline, but when I do a FLEX application the structure always looking something like:</p>\n\n<pr...
2009/01/05
[ "https://Stackoverflow.com/questions/412218", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4541/" ]
I'm currently a .NET developer, but I'm starting to work with Flex a little bit and I've found the community to be great. There are a lot of great resources out there, but one of the issues I'm running into conceptually is how to organize a flex project. Coming from the standpoint of a "traditional" ASP.NET web applica...
This is a rough outline, but when I do a FLEX application the structure always looking something like: ``` src | - components | | - containers | | | - actionscript | | | - mxml | | - visual | | - actionscript | | - mxml | | - pag...
412,227
<p>You always hear that functional code is inherently easier to parallelize than non-functional code, so I decided to write a function which does the following:</p> <p>Given a input of strings, total up the number of unique characters for each string. So, given the input <code>[ "aaaaa"; "bbb"; "ccccccc"; "abbbc" ]</c...
[ { "answer_id": 412272, "author": "Charlie Martin", "author_id": 35092, "author_profile": "https://Stackoverflow.com/users/35092", "pm_score": 0, "selected": false, "text": "<p>I don't speak F# at all well, but I can address this. Think about using map/reduce:</p>\n\n<p>let <em>n</em> = ...
2009/01/05
[ "https://Stackoverflow.com/questions/412227", "https://Stackoverflow.com", "https://Stackoverflow.com/users/40516/" ]
You always hear that functional code is inherently easier to parallelize than non-functional code, so I decided to write a function which does the following: Given a input of strings, total up the number of unique characters for each string. So, given the input `[ "aaaaa"; "bbb"; "ccccccc"; "abbbc" ]`, our method will...
As already pointed out, there's update contention if you try to have different threads process different input strings, since each thread can increment the count of every letter. You can have each thread produce its own Map, and then 'add up all the Maps', but that final step may be expensive (and is not as well-suited...
412,230
<p>I'm working on a new project and I'm using the repository pattern, I have my repository that pulls the data from the database and a "service" class which uses the repository and does all the business logic.</p> <p>something similar to the following;</p> <pre><code>public class UserRepository : IUserRepository { ...
[ { "answer_id": 412237, "author": "thetacom", "author_id": 51323, "author_profile": "https://Stackoverflow.com/users/51323", "pm_score": 1, "selected": false, "text": "<p>You should test them both. Having tested the repository, it will be easier and more reliable when you go to test the ...
2009/01/05
[ "https://Stackoverflow.com/questions/412230", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17176/" ]
I'm working on a new project and I'm using the repository pattern, I have my repository that pulls the data from the database and a "service" class which uses the repository and does all the business logic. something similar to the following; ``` public class UserRepository : IUserRepository { public IQueryable<U...
You should test them both, because it's possible that someday there will be other clients of UserRepository than UserService, and those clients may use UserRepository differently than UserService.
412,300
<p>Smashed my head against this a bit too long. How do I prevent a user from browsing a site's pages after they have been logged out using FormsAuthentication.SignOut? I would expect this to do it:</p> <pre><code>FormsAuthentication.SignOut(); Session.Abandon(); FormsAuthentication.RedirectToLoginPage(); </code></pre>...
[ { "answer_id": 412310, "author": "Abram Simon", "author_id": 46204, "author_profile": "https://Stackoverflow.com/users/46204", "pm_score": 2, "selected": false, "text": "<p>The code you posted looks like it should correctly remove the forms authentication token, so it is possible that th...
2009/01/05
[ "https://Stackoverflow.com/questions/412300", "https://Stackoverflow.com", "https://Stackoverflow.com/users/38398/" ]
Smashed my head against this a bit too long. How do I prevent a user from browsing a site's pages after they have been logged out using FormsAuthentication.SignOut? I would expect this to do it: ``` FormsAuthentication.SignOut(); Session.Abandon(); FormsAuthentication.RedirectToLoginPage(); ``` But it doesn't. If I ...
Users can still browse your website because cookies are not cleared when you call `FormsAuthentication.SignOut()` and they are authenticated on every new request. In MS documentation is says that cookie will be cleared but they don't, bug? Its exactly the same with `Session.Abandon()`, cookie is still there. You shoul...
412,305
<p>If I create a TcpChannel using port zero i.e. allowing .Net Remoting to allocate an available port, is there anyway to then determine which port number has been allocated? </p> <p>I know that I can specify the port number when creating the channel, however I don't want to do this as I want to run multiple instance...
[ { "answer_id": 412320, "author": "Marc Gravell", "author_id": 23354, "author_profile": "https://Stackoverflow.com/users/23354", "pm_score": 3, "selected": false, "text": "<p>I don't know much about this, but browsing at MSDN it states that post zero usage returns a <code>TcpServerChannel...
2009/01/05
[ "https://Stackoverflow.com/questions/412305", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10135/" ]
If I create a TcpChannel using port zero i.e. allowing .Net Remoting to allocate an available port, is there anyway to then determine which port number has been allocated? I know that I can specify the port number when creating the channel, however I don't want to do this as I want to run multiple instances of the li...
My solution was as follows: * Use the following code to identify an unused port for each instance of the client application: ``` IPEndPoint endPoint = new IPEndPoint(IPAddress.Any, 0); using (Socket socket = new Socket( AddressFamily.InterNetwork, SocketType.Stream, ProtocolT...
412,331
<p>I am trying to pass an XML list to a view but I am having trouble once I get to the view.</p> <p>My controller:</p> <pre><code> public ActionResult Search(int isbdn) { ViewData["ISBN"] = isbdn; string pathToXml= "http://isbndb.com/api/books.xml?access_key=DWD3TC34&amp;index1=isbn&amp;value1="; ...
[ { "answer_id": 412334, "author": "Glenn Slaven", "author_id": 2975, "author_profile": "https://Stackoverflow.com/users/2975", "pm_score": 0, "selected": false, "text": "<p>I'm guessing you've missed some code because you're not assigning to items to the ViewData at any point in this code...
2009/01/05
[ "https://Stackoverflow.com/questions/412331", "https://Stackoverflow.com", "https://Stackoverflow.com/users/67445/" ]
I am trying to pass an XML list to a view but I am having trouble once I get to the view. My controller: ``` public ActionResult Search(int isbdn) { ViewData["ISBN"] = isbdn; string pathToXml= "http://isbndb.com/api/books.xml?access_key=DWD3TC34&index1=isbn&value1="; pathToXml += isbdn; ...
first.. you have to return the data to the view modal... ``` public ActionResult Search(int isbdn) { ViewData["ISBN"] = isbdn; string pathToXml= "http://isbndb.com/api/books.xml?access_key=DWD3TC34&index1=isbn&value1="; pathToXml += isbdn; var doc = XDocument.Load(pathToXml); ...
412,344
<p>I know downcasting like this won't work. I need a method that WILL work. Here's my problem: I've got several different derived classes all from a base class. My first try was to make an array of base class. The program has to select (more or less at random) different derived classes. I had tried casting from a base ...
[ { "answer_id": 412351, "author": "yfeldblum", "author_id": 12349, "author_profile": "https://Stackoverflow.com/users/12349", "pm_score": 1, "selected": false, "text": "<p>Use an array of <code>BaseClass*</code>, not an array of <code>BaseClass</code>. (Or pick a smart-pointer library to ...
2009/01/05
[ "https://Stackoverflow.com/questions/412344", "https://Stackoverflow.com", "https://Stackoverflow.com/users/48957/" ]
I know downcasting like this won't work. I need a method that WILL work. Here's my problem: I've got several different derived classes all from a base class. My first try was to make an array of base class. The program has to select (more or less at random) different derived classes. I had tried casting from a base cla...
Not sure what you mean. Sounds like you store the objects by value, and you you have an array of `Base`. That won't work, because as soon as you assign a Derived, that object will be converted to a Base, and the Derived part of the object is sliced away. But i think you want to have a array of pointers to base: ``` Ba...
412,378
<p>I come from a C++ background where I can use template mixins to write code that refers to FinalClass which is a template parameter that is passed in. This allows reusable functions to be "mixed-in" to any derived class, by simply inheriting from ReusableMixin with a template paramter of MyFinalClass. This all gets...
[ { "answer_id": 412402, "author": "Daniel O", "author_id": 697, "author_profile": "https://Stackoverflow.com/users/697", "pm_score": 0, "selected": false, "text": "<p>Would extension methods help in your scenario?</p>\n" }, { "answer_id": 412549, "author": "Community", "au...
2009/01/05
[ "https://Stackoverflow.com/questions/412378", "https://Stackoverflow.com", "https://Stackoverflow.com/users/43058/" ]
I come from a C++ background where I can use template mixins to write code that refers to FinalClass which is a template parameter that is passed in. This allows reusable functions to be "mixed-in" to any derived class, by simply inheriting from ReusableMixin with a template paramter of MyFinalClass. This all gets inli...
In C#, the closest you get to C++ style mixins is adding the mixins as fields of a class and add a bunch of forwarding methods to the class: ``` public class MyClass { private readonly Mixin1 mixin1 = new Mixin1(); private readonly Mixin2 mixin2 = new Mixin2(); public int Property1 { get { ret...
412,380
<p>Is there a Java equivalent for <a href="http://msdn.microsoft.com/en-us/library/system.io.path.combine.aspx" rel="noreferrer"><code>System.IO.Path.Combine()</code></a> in C#/.NET? Or any code to accomplish this?</p> <p>This static method combines one or more strings into a path.</p>
[ { "answer_id": 412495, "author": "Jon Skeet", "author_id": 22656, "author_profile": "https://Stackoverflow.com/users/22656", "pm_score": 9, "selected": false, "text": "<p>Rather than keeping everything string-based, you should use a class which is designed to represent a file system path...
2009/01/05
[ "https://Stackoverflow.com/questions/412380", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
Is there a Java equivalent for [`System.IO.Path.Combine()`](http://msdn.microsoft.com/en-us/library/system.io.path.combine.aspx) in C#/.NET? Or any code to accomplish this? This static method combines one or more strings into a path.
Rather than keeping everything string-based, you should use a class which is designed to represent a file system path. If you're using Java 7 or Java 8, you should strongly consider using [`java.nio.file.Path`](http://docs.oracle.com/javase/8/docs/api/java/nio/file/Path.html); `Path.resolve` can be used to combine one...
412,385
<p>I am including Javascript code that is used to pop up a calendar. The problem with the code is that I want a '0' to be inserted in front of the month or day if the month lies between 1--9 and days between 1--9 in the calendar. The following is the script. Can anybody guide me to the modifications?</p> <pre><code...
[ { "answer_id": 412441, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 2, "selected": false, "text": "<p>I don't think the way you are writing the script that it is ever going to work as intended. Try looking on google for a pre...
2009/01/05
[ "https://Stackoverflow.com/questions/412385", "https://Stackoverflow.com", "https://Stackoverflow.com/users/48094/" ]
I am including Javascript code that is used to pop up a calendar. The problem with the code is that I want a '0' to be inserted in front of the month or day if the month lies between 1--9 and days between 1--9 in the calendar. The following is the script. Can anybody guide me to the modifications? ``` <!DOCTYPE HTML P...
I don't think the way you are writing the script that it is ever going to work as intended. Try looking on google for a pre-made solution. There is no shame in that. <https://engineering.purdue.edu/ECN/Support/KB/Docs/JavascriptCalendar> <http://www.google.com/search?source=ig&hl=en&rlz=1G1GGLQ_ENUS302&=&q=javascript...
412,386
<p>Is there a way to determine if a specific type has been configured in StructureMap? </p> <p>I want to return a generic type if it has not be specifically configured in StructureMap.</p>
[ { "answer_id": 415812, "author": "Jon Cahill", "author_id": 10830, "author_profile": "https://Stackoverflow.com/users/10830", "pm_score": 2, "selected": false, "text": "<p>From StructureMap version 2.5.1 there is a <code>TryGetInstance&lt;T&gt;()</code> and <code>TryGetNamedInstance&lt;T...
2009/01/05
[ "https://Stackoverflow.com/questions/412386", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10830/" ]
Is there a way to determine if a specific type has been configured in StructureMap? I want to return a generic type if it has not be specifically configured in StructureMap.
In v2.6 you want: ``` IContainer.Model.HasImplementationsFor(serviceType) ```
412,387
<p>The problem with the below code is that Select All options works very well in Mozilla and not in Internet Explorer. </p> <pre><code>&lt;!-- Document : DG Created on : Sep 11, 2008, 12:48:37 PM Author : padmaja --&gt; &lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"&gt; &lt;html&gt; &lt;head&...
[ { "answer_id": 412400, "author": "Christian C. Salvadó", "author_id": 5445, "author_profile": "https://Stackoverflow.com/users/5445", "pm_score": 3, "selected": false, "text": "<p>Your code is using document.all everywhere please <em>don't use it</em>, you should instead use document.get...
2009/01/05
[ "https://Stackoverflow.com/questions/412387", "https://Stackoverflow.com", "https://Stackoverflow.com/users/48094/" ]
The problem with the below code is that Select All options works very well in Mozilla and not in Internet Explorer. ``` <!-- Document : DG Created on : Sep 11, 2008, 12:48:37 PM Author : padmaja --> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <script type="text/javascript"...
Your code is using document.all everywhere please *don't use it*, you should instead use document.getElementById IE 4 introduced the document.all DOM. Soon after that the standard DOM method getElementById was introduced and is therefore available in *all* modern browsers. For example: ``` document.all.calendar.styl...
412,409
<p>I wonder if it is a good practice to use JUnit's @Ignore. And how people are using it? </p> <p>I came up with the following use case: Let's say I am developing a class and writing a JUnit test for it, which doesn't pass, because I'm not quite done with the class. Is it a good practice to mark it with @Ignore? </p> ...
[ { "answer_id": 412418, "author": "Adeel Ansari", "author_id": 42769, "author_profile": "https://Stackoverflow.com/users/42769", "pm_score": 6, "selected": true, "text": "<p>Thats pretty much fine, I suppose.</p>\n\n<p>The <a href=\"https://github.com/junit-team/junit/wiki/Ignoring-tests\...
2009/01/05
[ "https://Stackoverflow.com/questions/412409", "https://Stackoverflow.com", "https://Stackoverflow.com/users/198/" ]
I wonder if it is a good practice to use JUnit's @Ignore. And how people are using it? I came up with the following use case: Let's say I am developing a class and writing a JUnit test for it, which doesn't pass, because I'm not quite done with the class. Is it a good practice to mark it with @Ignore? I'm a little ...
Thats pretty much fine, I suppose. The [docs](https://github.com/junit-team/junit/wiki/Ignoring-tests) says, > > Test runners will report the number of ignored tests, along with the number of tests > that ran and the number of tests that failed. > > > Hence, it means even if you forget to remove that afterwards...
412,410
<p>I'm trying to compile GNUstep on a linux box but gnustep-gui-0.16.0 package is failing. I downloaded GNUstep Startup stable 0.20.1 (<a href="http://wwwmain.gnustep.org/resources/downloads.php" rel="nofollow noreferrer">http://wwwmain.gnustep.org/resources/downloads.php</a>)and follow instructions about how to compil...
[ { "answer_id": 437130, "author": "stefanB", "author_id": 45654, "author_profile": "https://Stackoverflow.com/users/45654", "pm_score": 1, "selected": true, "text": "<p>When I compiled with --verbose (or --debug ?) I noticed that the gnustep is looking into it's ~/GNUstep/System/Library/L...
2009/01/05
[ "https://Stackoverflow.com/questions/412410", "https://Stackoverflow.com", "https://Stackoverflow.com/users/45654/" ]
I'm trying to compile GNUstep on a linux box but gnustep-gui-0.16.0 package is failing. I downloaded GNUstep Startup stable 0.20.1 (<http://wwwmain.gnustep.org/resources/downloads.php>)and follow instructions about how to compile (./configure && make). I'm getting this error: `libgnustep-gui.so: undefined reference to...
When I compiled with --verbose (or --debug ?) I noticed that the gnustep is looking into it's ~/GNUstep/System/Library/Libraries and Headers (among other places) so I moved a copy of libpng, that I've just recompiled, into that area and it all compiled without problems.
412,412
<p>I'm using the MVC beta to write a simple application to understand ASP.Net MVC. The application is a simple photo/video sharing site with tagging. I'm working off the MVC skeleton project. I added some Html.ActionLink()'s to the navigation bar, but I'm having a problem with one of the Html.ActionLink()'s that I adde...
[ { "answer_id": 412822, "author": "Dan Atkinson", "author_id": 31532, "author_profile": "https://Stackoverflow.com/users/31532", "pm_score": 3, "selected": true, "text": "<p>I think you need to handle an instance of yoursite.com/Tags/, as you're only handling one with a tag in.</p>\n\n<p>...
2009/01/05
[ "https://Stackoverflow.com/questions/412412", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1880/" ]
I'm using the MVC beta to write a simple application to understand ASP.Net MVC. The application is a simple photo/video sharing site with tagging. I'm working off the MVC skeleton project. I added some Html.ActionLink()'s to the navigation bar, but I'm having a problem with one of the Html.ActionLink()'s that I added i...
I think you need to handle an instance of yoursite.com/Tags/, as you're only handling one with a tag in. I would create another route: ``` routes.MapRoute( "TagsIndex", //Called something different to prevent a conflict with your other route "Tags/", new { controller = "Tags", action = "Index" } ); routes.MapR...
412,427
<p>We always write code like this formal:</p> <pre><code>void main(){ if(){ if() } </code></pre> <p><img src="https://i.stack.imgur.com/dPV7i.jpg" alt="Alt text"></p> <p>But when I use <a href="http://en.wikipedia.org/wiki/Notepad%2B%2B" rel="noreferrer">Notepad++</a>, the display is:</p> <pre><code>void ...
[ { "answer_id": 412449, "author": "Jonathan Lonowski", "author_id": 15031, "author_profile": "https://Stackoverflow.com/users/15031", "pm_score": 5, "selected": false, "text": "<p>In the latest version (at least), you can find it through:</p>\n\n<ul>\n<li><strong>Settings</strong> (menu)<...
2009/01/05
[ "https://Stackoverflow.com/questions/412427", "https://Stackoverflow.com", "https://Stackoverflow.com/users/51539/" ]
We always write code like this formal: ``` void main(){ if(){ if() } ``` ![Alt text](https://i.stack.imgur.com/dPV7i.jpg) But when I use [Notepad++](http://en.wikipedia.org/wiki/Notepad%2B%2B), the display is: ``` void main(){ if(){ if() } ``` ![Alt text](https://i.stack.imgur.com/1T37o.jpg) How do I ...
Notepad++ will only auto-insert subsequent indents if you manually indent the first line in a block; otherwise you can re-indent your code after the fact using `TextFX > TextFX Edit > Reindent C++ code`.
412,435
<p>I want to read a date in the format YYYY-MM-DD. </p> <p>But if I enter date say for example 2008-1-1, I want to read it as 2008-01-01.</p> <p>Can anybody help me? Thanks in advance</p>
[ { "answer_id": 412439, "author": "Adeel Ansari", "author_id": 42769, "author_profile": "https://Stackoverflow.com/users/42769", "pm_score": 3, "selected": false, "text": "<p>Use <a href=\"http://java.sun.com/javase/6/docs/api/java/text/SimpleDateFormat.html\" rel=\"nofollow noreferrer\">...
2009/01/05
[ "https://Stackoverflow.com/questions/412435", "https://Stackoverflow.com", "https://Stackoverflow.com/users/48094/" ]
I want to read a date in the format YYYY-MM-DD. But if I enter date say for example 2008-1-1, I want to read it as 2008-01-01. Can anybody help me? Thanks in advance
Or use the much better [Joda Time](http://joda-time.sourceforge.net/) lib. ``` DateTime dt = new DateTime(); System.out.println(dt.toString("yyyy-MM-dd")); // The ISO standard format for date is 'yyyy-MM-dd' DateTimeFormatter formatter = ISODateTimeFormat.date(); System.out.println(dt.toString(for...
412,438
<p>Is there a way to undefine the += on strings and wstrings for chars and wchar_t?</p> <p>Basically I want to avoid bugs like the following:</p> <pre><code>int age = 27; std::wstring str = std::wstring(L"User's age is: "); str += age; std::string str2 = std::string("User's age is: "); str2 += age; </code></pre> <...
[ { "answer_id": 412458, "author": "Frederick The Fool", "author_id": 32688, "author_profile": "https://Stackoverflow.com/users/32688", "pm_score": 2, "selected": false, "text": "<p>1) Create a string class of your own that inherits/contains the <code>std::string</code>.</p>\n\n<p>2) In th...
2009/01/05
[ "https://Stackoverflow.com/questions/412438", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3153/" ]
Is there a way to undefine the += on strings and wstrings for chars and wchar\_t? Basically I want to avoid bugs like the following: ``` int age = 27; std::wstring str = std::wstring(L"User's age is: "); str += age; std::string str2 = std::string("User's age is: "); str2 += age; ``` The above code will add the as...
**You cannot deactivate a specific function** of a class (here std::basic\_string) as it is it's interface that clearly (and officially) allow that manipulation. Trying to overload the operator will only mess things up. Now, **you can "wrap" std::basic\_string in another class**, using private inheritance or compositi...
412,440
<p>What are the best practices for implementing temporary transaction password feature for website?</p> <p>For e.g in banking/finance scenarios like - While transfering funds from one account to another, a transaction password is required - While commiting a trade, a transaction password is required - etc.</p> <p>The...
[ { "answer_id": 412458, "author": "Frederick The Fool", "author_id": 32688, "author_profile": "https://Stackoverflow.com/users/32688", "pm_score": 2, "selected": false, "text": "<p>1) Create a string class of your own that inherits/contains the <code>std::string</code>.</p>\n\n<p>2) In th...
2009/01/05
[ "https://Stackoverflow.com/questions/412440", "https://Stackoverflow.com", "https://Stackoverflow.com/users/34644/" ]
What are the best practices for implementing temporary transaction password feature for website? For e.g in banking/finance scenarios like - While transfering funds from one account to another, a transaction password is required - While commiting a trade, a transaction password is required - etc. The password should ...
**You cannot deactivate a specific function** of a class (here std::basic\_string) as it is it's interface that clearly (and officially) allow that manipulation. Trying to overload the operator will only mess things up. Now, **you can "wrap" std::basic\_string in another class**, using private inheritance or compositi...
412,447
<p>I have this code:</p> <pre><code>&lt;script&gt; function toggle(source) { checkboxes = document.getElementsByName('DG1'); for each(var checkbox in checkboxes) checkbox.checked = source.checked; checkboxes = document.getElementsByName('DG2'); for each(var checkbox in checkboxes) checkbox.checked = ...
[ { "answer_id": 412469, "author": "Matthew Crumley", "author_id": 2214, "author_profile": "https://Stackoverflow.com/users/2214", "pm_score": 6, "selected": false, "text": "<p>Note that Firefox no longer supports for each loops, so this applies to <em>every</em> browser, not just Internet...
2009/01/05
[ "https://Stackoverflow.com/questions/412447", "https://Stackoverflow.com", "https://Stackoverflow.com/users/48094/" ]
I have this code: ``` <script> function toggle(source) { checkboxes = document.getElementsByName('DG1'); for each(var checkbox in checkboxes) checkbox.checked = source.checked; checkboxes = document.getElementsByName('DG2'); for each(var checkbox in checkboxes) checkbox.checked = source.checked; c...
Note that Firefox no longer supports for each loops, so this applies to *every* browser, not just Internet Explorer. [See this MDN article for alternatives](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors/For-each-in_loops_are_deprecated). --- Internet Explorer doesn't support "for each" loop...
412,459
<p>I've got some data manipulation code which spits out csv at the end.</p> <p>I started upgrading it to add units of measure everywhere, but I now have a problem with my csv function:</p> <pre><code>val WriteCSV : string -&gt; 'a list array -&gt; 'b list -&gt; string -&gt; unit </code></pre> <p>(the parameters are ...
[ { "answer_id": 412523, "author": "leen", "author_id": 26462, "author_profile": "https://Stackoverflow.com/users/26462", "pm_score": 4, "selected": true, "text": "<p>If I got your Problem right, casting it to \"pure\" float removes the Unit.\nFor Example:</p>\n\n<pre><code>[&lt;Measure&gt...
2009/01/05
[ "https://Stackoverflow.com/questions/412459", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11410/" ]
I've got some data manipulation code which spits out csv at the end. I started upgrading it to add units of measure everywhere, but I now have a problem with my csv function: ``` val WriteCSV : string -> 'a list array -> 'b list -> string -> unit ``` (the parameters are fileName, column array, column headers, separ...
If I got your Problem right, casting it to "pure" float removes the Unit. For Example: ``` [<Measure>] type m [<Measure>] type km let removeUnit (x:float<_>) = float x let foo = removeUnit 2.6<m> let foo2 = removeUnit 2.1<km> ``` > > val removeUnit : float<'u> -> float > > >
412,467
<p>Can anyone give me an idea how can we <em>show</em> or embed a YouTube video if we just have the URL or the Embed code?</p>
[ { "answer_id": 412476, "author": "Christian C. Salvadó", "author_id": 5445, "author_profile": "https://Stackoverflow.com/users/5445", "pm_score": 2, "selected": false, "text": "<p>If you want to upload videos programatically, check the <a href=\"http://code.google.com/apis/youtube/overvi...
2009/01/05
[ "https://Stackoverflow.com/questions/412467", "https://Stackoverflow.com", "https://Stackoverflow.com/users/455847/" ]
Can anyone give me an idea how can we *show* or embed a YouTube video if we just have the URL or the Embed code?
You have to ask users to store the 11 character code from the youtube video. For e.g. <http://www.youtube.com/watch?v=Ahg6qcgoay4> The eleven character code is : Ahg6qcgoay4 You then take this code and place it in your database. Then wherever you want to place the youtube video in your page, load the character from ...
412,472
<p>I have code that looks like this:</p> <pre><code>import xmlrpclib class Base(object): def __init__(self, server): self.conn = xmlrpclib.ServerProxy(server) def foo(self): return self.conn.do_something() class Derived(Base): def foo(self): if Base.foo(): return self...
[ { "answer_id": 412580, "author": "Ryan Ginstrom", "author_id": 10658, "author_profile": "https://Stackoverflow.com/users/10658", "pm_score": 2, "selected": false, "text": "<p>You could create a fake ServerProxy class, and substitute that for testing.</p>\n\n<p>Something like this:</p>\n\...
2009/01/05
[ "https://Stackoverflow.com/questions/412472", "https://Stackoverflow.com", "https://Stackoverflow.com/users/50773/" ]
I have code that looks like this: ``` import xmlrpclib class Base(object): def __init__(self, server): self.conn = xmlrpclib.ServerProxy(server) def foo(self): return self.conn.do_something() class Derived(Base): def foo(self): if Base.foo(): return self.conn.do_somet...
You could create a fake ServerProxy class, and substitute that for testing. Something like this: ``` class FakeServerProxy(object): def __init__(self, server): self.server = server def do_something(self): pass def do_something_else(self): pass def test_derived(): xmlrpclib.Ser...
412,498
<p>In my Apache webserver I put this:</p> <pre><code>&lt;Directory /var/www/MYDOMAIN.com/htdocs&gt; SetHandler mod_python PythonHandler mod_python.publisher PythonDebug On &lt;/Directory&gt; </code></pre> <p>Then I have a handler.py file with an index function.</p> <p>When I go to MYDOMAIN.com/handler.py...
[ { "answer_id": 412567, "author": "Vinko Vrsalovic", "author_id": 5190, "author_profile": "https://Stackoverflow.com/users/5190", "pm_score": 0, "selected": false, "text": "<p>Try creating an empty file called index (or whatever) in the directory and then use</p>\n\n<pre><code>DirectoryIn...
2009/01/05
[ "https://Stackoverflow.com/questions/412498", "https://Stackoverflow.com", "https://Stackoverflow.com/users/51540/" ]
In my Apache webserver I put this: ``` <Directory /var/www/MYDOMAIN.com/htdocs> SetHandler mod_python PythonHandler mod_python.publisher PythonDebug On </Directory> ``` Then I have a handler.py file with an index function. When I go to MYDOMAIN.com/handler.py, I see a web page produced by the index func...
Yes, but you need to create your own handler. You currently use publisher, it just checks the URI and loads given python module. To create your own handler you need to create a module like this (just a minimalistic example): ``` from mod_python import apache def requesthandler(req): req.content_type = "text/plai...
412,517
<p>I am developing a PHP/MySQL application using vertrigoserver. I need to enter the German text in tables. The problem is when I read the tables from PHP, some of character didn't show the exact typed one. Do I need additional steps to display all characters effectively?</p>
[ { "answer_id": 412529, "author": "Pim Jager", "author_id": 35197, "author_profile": "https://Stackoverflow.com/users/35197", "pm_score": 0, "selected": false, "text": "<p>Did you set the correct character set on the tables when you created them?</p>\n\n<p>You should set them to a charact...
2009/01/05
[ "https://Stackoverflow.com/questions/412517", "https://Stackoverflow.com", "https://Stackoverflow.com/users/44984/" ]
I am developing a PHP/MySQL application using vertrigoserver. I need to enter the German text in tables. The problem is when I read the tables from PHP, some of character didn't show the exact typed one. Do I need additional steps to display all characters effectively?
You should set your database fields to `utf8_general` and therefore force your MySQL connection to use [UTF-8](http://en.wikipedia.org/wiki/UTF-8). ``` mysql_connect(); mysql_query("SET NAMES 'utf8'"); ``` While displaying your results through (x)html, you also have to set the headers correctly.
412,562
<p>How can I execute a terminal command (like <code>grep</code>) from my Objective-C Cocoa application?</p>
[ { "answer_id": 412573, "author": "Gordon Wilson", "author_id": 23071, "author_profile": "https://Stackoverflow.com/users/23071", "pm_score": 9, "selected": true, "text": "<p>You can use <code><a href=\"http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSTask_Cla...
2009/01/05
[ "https://Stackoverflow.com/questions/412562", "https://Stackoverflow.com", "https://Stackoverflow.com/users/46297/" ]
How can I execute a terminal command (like `grep`) from my Objective-C Cocoa application?
You can use `[NSTask](http://developer.apple.com/documentation/Cocoa/Reference/Foundation/Classes/NSTask_Class/Reference/Reference.html)`. Here's an example that would run '`/usr/bin/grep foo bar.txt`'. ``` int pid = [[NSProcessInfo processInfo] processIdentifier]; NSPipe *pipe = [NSPipe pipe]; NSFileHandle *file = p...
412,590
<p>I have a table containing hundreds of entries and I am trying to delete a small range. It is taking a long time, in fact it is not being executed.</p> <p>I monitored the query from the activity monitor and its status is "Suspended"</p> <p>Is there anyone knows what may cause this problem?</p>
[ { "answer_id": 412595, "author": "Steven Robbins", "author_id": 26507, "author_profile": "https://Stackoverflow.com/users/26507", "pm_score": 2, "selected": true, "text": "<p>What's the SQL you're running? Any triggers on the table, or any cascaded deletes to tables that have triggers on...
2009/01/05
[ "https://Stackoverflow.com/questions/412590", "https://Stackoverflow.com", "https://Stackoverflow.com/users/44973/" ]
I have a table containing hundreds of entries and I am trying to delete a small range. It is taking a long time, in fact it is not being executed. I monitored the query from the activity monitor and its status is "Suspended" Is there anyone knows what may cause this problem?
What's the SQL you're running? Any triggers on the table, or any cascaded deletes to tables that have triggers on? Anything in the "Blocked By" column or Wait Type? Try executing the following in management studio (on the database in question): ``` dbcc checkdb dbcc checkcatalog ```
412,611
<p>I have the following use case, a struct with some boolean and int variables</p> <pre><code>struct a { int field1; bool field2; bool field3; }; </code></pre> <p>I am refactoring this code, and writing a constructor for the struct , the problem is the default initialization of fields.</p> <p>I am not...
[ { "answer_id": 412614, "author": "Johannes Schaub - litb", "author_id": 34509, "author_profile": "https://Stackoverflow.com/users/34509", "pm_score": 4, "selected": true, "text": "<p>You can do </p>\n\n<pre><code>struct a {\n a():field1(), field2(), field3() { }\n int field1;\n ...
2009/01/05
[ "https://Stackoverflow.com/questions/412611", "https://Stackoverflow.com", "https://Stackoverflow.com/users/43756/" ]
I have the following use case, a struct with some boolean and int variables ``` struct a { int field1; bool field2; bool field3; }; ``` I am refactoring this code, and writing a constructor for the struct , the problem is the default initialization of fields. I am not criticizing any language construc...
You can do ``` struct a { a():field1(), field2(), field3() { } int field1; bool field2; bool field3; }; ``` And all fields will be zero and false respectively. If you want to say that the fields have an indeterminate value, i'm afraid you have to use other techniques. One is to use [`boost::optional...
412,613
<p>We have a HEAD branch, and a feature branch that was created off the HEAD branch. I develop on the feature branch, and constantly merge changes from HEAD to my branch.</p> <p>When I'm finished with the feature, I try to merge it back to HEAD. This is supposed to be a 0-pain operation, as all conflicts were already ...
[ { "answer_id": 412614, "author": "Johannes Schaub - litb", "author_id": 34509, "author_profile": "https://Stackoverflow.com/users/34509", "pm_score": 4, "selected": true, "text": "<p>You can do </p>\n\n<pre><code>struct a {\n a():field1(), field2(), field3() { }\n int field1;\n ...
2009/01/05
[ "https://Stackoverflow.com/questions/412613", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11236/" ]
We have a HEAD branch, and a feature branch that was created off the HEAD branch. I develop on the feature branch, and constantly merge changes from HEAD to my branch. When I'm finished with the feature, I try to merge it back to HEAD. This is supposed to be a 0-pain operation, as all conflicts were already resolved o...
You can do ``` struct a { a():field1(), field2(), field3() { } int field1; bool field2; bool field3; }; ``` And all fields will be zero and false respectively. If you want to say that the fields have an indeterminate value, i'm afraid you have to use other techniques. One is to use [`boost::optional...
412,626
<p>I have created a own installer for my application(c#). During the installation process, i will ask the end-user for the install location. My problem is how to pass that install location(user input) to the installer. The installer always trying to install at c:\progam files[mfr name][product name].</p> <p>please hel...
[ { "answer_id": 412638, "author": "Neil Barnwell", "author_id": 26414, "author_profile": "https://Stackoverflow.com/users/26414", "pm_score": 2, "selected": false, "text": "<p>The installer will ask for the install location, and put it in a installer variable called %TARGETDIR%. You can ...
2009/01/05
[ "https://Stackoverflow.com/questions/412626", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I have created a own installer for my application(c#). During the installation process, i will ask the end-user for the install location. My problem is how to pass that install location(user input) to the installer. The installer always trying to install at c:\progam files[mfr name][product name]. please help me
The installer will ask for the install location, and put it in a installer variable called %TARGETDIR%. You can supply this as a custom argument to your custom actions so they can use it to perform other duties. Goto the custom actions viewer, and select the properties for your custom action. Enter the following as t...
412,632
<p>I would like to access information on the logical drives on my computer using C#. How should I accomplish this? Thanks!</p>
[ { "answer_id": 412644, "author": "Vinko Vrsalovic", "author_id": 5190, "author_profile": "https://Stackoverflow.com/users/5190", "pm_score": 7, "selected": true, "text": "<p>For most information, you can use the <a href=\"http://msdn.microsoft.com/en-us/library/system.io.driveinfo.aspx\"...
2009/01/05
[ "https://Stackoverflow.com/questions/412632", "https://Stackoverflow.com", "https://Stackoverflow.com/users/51578/" ]
I would like to access information on the logical drives on my computer using C#. How should I accomplish this? Thanks!
For most information, you can use the [DriveInfo](http://msdn.microsoft.com/en-us/library/system.io.driveinfo.aspx) class. ``` using System; using System.IO; class Info { public static void Main() { DriveInfo[] drives = DriveInfo.GetDrives(); foreach (DriveInfo drive in drives) { //The...
412,634
<p>I've browsed through the CreateFile documentation... still wondering how should I use P/Invoke to call CreateFile and to read the boot sector, to display out the .MBR?</p> <p>Any reference code for this portion? Thank you in advance!</p>
[ { "answer_id": 412658, "author": "Baget", "author_id": 34369, "author_profile": "https://Stackoverflow.com/users/34369", "pm_score": 1, "selected": false, "text": "<p>Maybe this <a href=\"https://stackoverflow.com/questions/39503/modifying-the-mbr-of-windows\">question</a> will help you<...
2009/01/05
[ "https://Stackoverflow.com/questions/412634", "https://Stackoverflow.com", "https://Stackoverflow.com/users/51579/" ]
I've browsed through the CreateFile documentation... still wondering how should I use P/Invoke to call CreateFile and to read the boot sector, to display out the .MBR? Any reference code for this portion? Thank you in advance!
To expand on Baget's answer, you can call `CreateFile` like this: ``` hFile = CreateFile("\\\\.\\physicaldrive0", GENERIC_READ | FILE_SHARE_READ, 0, OPEN_EXISTING, 0, 0); ```
412,649
<p>I'm trying to test the performance of our webapp with JMeter. The login procedure includes some external dependencies that can't be reproduced during the test, so I've programmed an alternate login. As this alternate login request is not part of the normal workflow I would like to exclude the login request from the ...
[ { "answer_id": 808131, "author": "BlackGaff", "author_id": 98711, "author_profile": "https://Stackoverflow.com/users/98711", "pm_score": 5, "selected": true, "text": "<p>TO my knowledge, there is not an easy way to exclude. However, by changing your structure, you can get what you want....
2009/01/05
[ "https://Stackoverflow.com/questions/412649", "https://Stackoverflow.com", "https://Stackoverflow.com/users/34009/" ]
I'm trying to test the performance of our webapp with JMeter. The login procedure includes some external dependencies that can't be reproduced during the test, so I've programmed an alternate login. As this alternate login request is not part of the normal workflow I would like to exclude the login request from the JMe...
TO my knowledge, there is not an easy way to exclude. However, by changing your structure, you can get what you want. The Listeners tune into all children levels. Thus, if you have the listener as a direct child to the "test plan", all thread groups will be grabbed by the listener. If you have multiple threadgroups, ...
412,653
<p>I have a DependencyObject in C# that is used in an array. Example shown below:</p> <pre><code>private KeywordTag[] tags = new KeywordTag[] { new KeywordTag { Tag = "test", IncidenceCount = 2076 }, new KeywordTag { Tag = "oi", IncidenceCount = 2052 }, new KeywordTag { Tag = "hmm", IncidenceCount = 1887 ...
[ { "answer_id": 412669, "author": "Steven Robbins", "author_id": 26507, "author_profile": "https://Stackoverflow.com/users/26507", "pm_score": 2, "selected": false, "text": "<p>Something like:</p>\n\n<pre><code>Private tags() As KeywordTag = { New KeywordTag { Tag = \"test\", IncidenceCou...
2009/01/05
[ "https://Stackoverflow.com/questions/412653", "https://Stackoverflow.com", "https://Stackoverflow.com/users/46304/" ]
I have a DependencyObject in C# that is used in an array. Example shown below: ``` private KeywordTag[] tags = new KeywordTag[] { new KeywordTag { Tag = "test", IncidenceCount = 2076 }, new KeywordTag { Tag = "oi", IncidenceCount = 2052 }, new KeywordTag { Tag = "hmm", IncidenceCount = 1887 }, new Keyw...
dummy's response was almost right, VB.Net's syntax has a "WITH" after the constructors. ``` Private tags() As KeywordTag = { _ New KeywordTag() WITH {.Tag = test", .IncidentCount = 2076}, _ New KeywordTag() WITH {.Tag = "oi", .IncidentCount = 2052}, _ New KeywordTag() WITH {.Tag = "hmm", .IncidentCount = 1...
412,655
<p>I am using:</p> <pre><code>[ajax.ajaxmethod()] public void fnName() </code></pre> <p>containing: </p> <pre><code>response.redirect("sample.aspx"); </code></pre> <p>or:</p> <pre><code>server.transfer("sample.aspx"); </code></pre> <p>both are not working... what is the solution?</p> <p>in that block, I tried...
[ { "answer_id": 412781, "author": "annakata", "author_id": 13018, "author_profile": "https://Stackoverflow.com/users/13018", "pm_score": 0, "selected": false, "text": "<p>You need to provide way more detail, but I'm going to wildly guess you expect your ajax request to become redirect the...
2009/01/05
[ "https://Stackoverflow.com/questions/412655", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I am using: ``` [ajax.ajaxmethod()] public void fnName() ``` containing: ``` response.redirect("sample.aspx"); ``` or: ``` server.transfer("sample.aspx"); ``` both are not working... what is the solution? in that block, I tried to call javascript function as ``` scriptmanager.registerstartupscript(page,gett...
I don't know how you do this with ASP.NET AJAX, but in [Ra-Ajax](http://ra-ajax.org) you would use something like this; ``` AjaxManager.Instance.WriterAtBack.Write("window.location='foo.aspx';"); ``` My guess is that also ASP.NET AJAX have some sort of method to append JavaScript back in Ajax Callbacks like Ra-Ajax ...
412,687
<p>I have an xml that has text within "word" elements e.g</p> <pre><code>&lt;word&gt;Police&lt;/word&gt; &lt;word&gt;confirmed&lt;/word&gt; &lt;word&gt;they are&lt;/word&gt; &lt;word&gt;questioning&lt;/word&gt; &lt;word&gt;a&lt;/word&gt; &lt;word&gt;man&lt;/word&gt; </code></pre> <p>The problem is when I apply the xs...
[ { "answer_id": 412707, "author": "rravuri", "author_id": 1794940, "author_profile": "https://Stackoverflow.com/users/1794940", "pm_score": 0, "selected": false, "text": "<p>try this adding &npsp; after valueof tag</p>\n" }, { "answer_id": 412727, "author": "aku", "author_...
2009/01/05
[ "https://Stackoverflow.com/questions/412687", "https://Stackoverflow.com", "https://Stackoverflow.com/users/44649/" ]
I have an xml that has text within "word" elements e.g ``` <word>Police</word> <word>confirmed</word> <word>they are</word> <word>questioning</word> <word>a</word> <word>man</word> ``` The problem is when I apply the xslt the text appears like "Policeconfirmedthey arequestioningaman". Here is the xslt snippet that ...
Add a space character. Simple way: ``` <Paragraph> <xsl:for-each select="./speaker/segment"> <xsl:value-of select="./nbest"/>&#160; </xsl:for-each> </Paragraph> ``` Slightly more complex way to effectively trim the string: ``` <Paragraph> <xsl:for-each select="./speaker/segment"> <xsl:if test="not(positio...
412,691
<p>I'm going to generate an <code>asp:CheckBoxList</code> using this code </p> <pre><code>&lt;% System.Collections.Generic.List&lt;QuizzEngine.Common.Question&gt; qList = (System.Collections.Generic.List&lt;QuizzEngine.Common.Question&gt;)Session[QuizzEngine.Common.SessionKeys.QuesionsList]; int navigator = (int)Ses...
[ { "answer_id": 412796, "author": "karlis", "author_id": 49034, "author_profile": "https://Stackoverflow.com/users/49034", "pm_score": -1, "selected": false, "text": "<p>i'm sure you don't need this:</p>\n\n<pre><code>i.Attributes.Add(\"runat\", \"server\");\n</code></pre>\n" }, { ...
2009/01/05
[ "https://Stackoverflow.com/questions/412691", "https://Stackoverflow.com", "https://Stackoverflow.com/users/32718/" ]
I'm going to generate an `asp:CheckBoxList` using this code ``` <% System.Collections.Generic.List<QuizzEngine.Common.Question> qList = (System.Collections.Generic.List<QuizzEngine.Common.Question>)Session[QuizzEngine.Common.SessionKeys.QuesionsList]; int navigator = (int)Session[QuizzEngine.Common.SessionKeys.Navi...
**I Done It** Just Like reversing **Server-Side-Code to generate items** with **CheckBoxList tag**, the reason is when executing in my first case adding items to the control comming after rendering it, and this is wrong, First add items to the control then write its tag to render. **I'm mixing my server-side-code with...
412,717
<p>I want to use <strong><a href="http://testng.org/" rel="noreferrer">testng</a></strong> with the <a href="http://maven.apache.org/plugins/maven-surefire-plugin/" rel="noreferrer">Surefire plug-in</a> of <a href="http://en.wikipedia.org/wiki/Apache_Maven" rel="noreferrer">Maven</a>. The idea is to tag some tests with...
[ { "answer_id": 415858, "author": "Arne Burmeister", "author_id": 12890, "author_profile": "https://Stackoverflow.com/users/12890", "pm_score": 5, "selected": true, "text": "<p>I got it - irritating configuration implementation!</p>\n\n<p><code>&lt;excludedGroups/&gt;</code> does not over...
2009/01/05
[ "https://Stackoverflow.com/questions/412717", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12890/" ]
I want to use **[testng](http://testng.org/)** with the [Surefire plug-in](http://maven.apache.org/plugins/maven-surefire-plugin/) of [Maven](http://en.wikipedia.org/wiki/Apache_Maven). The idea is to tag some tests with a group `integrationTest` and run the plug-in twice: for goal `test` excluding the group `integrati...
I got it - irritating configuration implementation! `<excludedGroups/>` does not override `<excludedGroups>integrationTest</excludedGroups>`. You need to specify any (unknown) group instead, `<excludedGroups>none</excludedGroups>` for example.
412,725
<p>Does anyone have any ideas on how to read the MSDTC configuration on the current machine? I am specifically trying to check that the user has performed the following steps:</p> <ol> <li><p>Open Component Management (Start > All Programs > Administrative Tools > Component Services) </p></li> <li><p>Double-click on C...
[ { "answer_id": 412974, "author": "Magnus Johansson", "author_id": 3584, "author_profile": "https://Stackoverflow.com/users/3584", "pm_score": 1, "selected": true, "text": "<p>I'm not sure if you can do this programmatically from any API, or WMI.\nAt least you can check the registry infor...
2009/01/05
[ "https://Stackoverflow.com/questions/412725", "https://Stackoverflow.com", "https://Stackoverflow.com/users/24064/" ]
Does anyone have any ideas on how to read the MSDTC configuration on the current machine? I am specifically trying to check that the user has performed the following steps: 1. Open Component Management (Start > All Programs > Administrative Tools > Component Services) 2. Double-click on Component Services, then expand...
I'm not sure if you can do this programmatically from any API, or WMI. At least you can check the registry information at: ``` HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSDTC\Security ```
412,734
<p>I am using country and state dropdowns in my form. Whenever the user selects the country in the dropdown, the respective states of the country will populate in the states dropdown. I am populating the states in the dropdown using AJAX call. The problem is that the states get populated in Mozilla but it doesn't work...
[ { "answer_id": 412758, "author": "Kieron", "author_id": 5791, "author_profile": "https://Stackoverflow.com/users/5791", "pm_score": 4, "selected": false, "text": "<p>Try using <strong>append</strong> instead of the <strong>html</strong> method as detailed in this <a href=\"https://stacko...
2009/01/05
[ "https://Stackoverflow.com/questions/412734", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I am using country and state dropdowns in my form. Whenever the user selects the country in the dropdown, the respective states of the country will populate in the states dropdown. I am populating the states in the dropdown using AJAX call. The problem is that the states get populated in Mozilla but it doesn't work in ...
Try using **append** instead of the **html** method as detailed in this [post](https://stackoverflow.com/questions/317095/how-do-i-add-options-to-a-dropdownlist-using-jquery). **edit** Actually, I've just run into this problem myself. For me the answer was to call [empty](http://docs.jquery.com/Manipulation/empty) fi...
412,740
<p>I'm trying to mimic the following Java code:</p> <pre><code>int[][] multi; // DIMENSIONS ARE UNKNOWN AT CREATION TIME // LATER ON... multi = new int[10][]; multi[5] = new int[20]; multi[5][11] = 66; // LATER ON... multi = null; // PROPER WAY OF FREEING EVERYTHING </code></pre> <p>I've came out with the following O...
[ { "answer_id": 412749, "author": "Sophie Alpert", "author_id": 49485, "author_profile": "https://Stackoverflow.com/users/49485", "pm_score": 0, "selected": false, "text": "<p>You can make a one-dimensional array and then use an index based off of your two values. That way will have less ...
2009/01/05
[ "https://Stackoverflow.com/questions/412740", "https://Stackoverflow.com", "https://Stackoverflow.com/users/50335/" ]
I'm trying to mimic the following Java code: ``` int[][] multi; // DIMENSIONS ARE UNKNOWN AT CREATION TIME // LATER ON... multi = new int[10][]; multi[5] = new int[20]; multi[5][11] = 66; // LATER ON... multi = null; // PROPER WAY OF FREEING EVERYTHING ``` I've came out with the following Objective-C version: ``` i...
Free doesn't zero out the memory address in the pointer, it just invalidates it. So, if you're running this loop more than once, you will get exceptions when you try to free memory that has already been invalidated. You can use an NSPointerArray or wrap your integers in objects and use an NSMutableArray for your purpos...
412,750
<p>I have to make column charts in Excel using VBA only (no user input).</p> <p>I want to format the labels of the x-axis so that the alignment for every label becomes -270 degrees. This can be done manually by changing the "Custom angle" property in the "Alignment" tab of the "Format Axis" Dialog.</p> <p>I recorded ...
[ { "answer_id": 412762, "author": "Artelius", "author_id": 31945, "author_profile": "https://Stackoverflow.com/users/31945", "pm_score": 3, "selected": true, "text": "<p>If you are using Excel 2007, try using an earlier version because 2007's macro recorder is a bit crippled.</p>\n\n<p>Th...
2009/01/05
[ "https://Stackoverflow.com/questions/412750", "https://Stackoverflow.com", "https://Stackoverflow.com/users/51590/" ]
I have to make column charts in Excel using VBA only (no user input). I want to format the labels of the x-axis so that the alignment for every label becomes -270 degrees. This can be done manually by changing the "Custom angle" property in the "Alignment" tab of the "Format Axis" Dialog. I recorded a macro but Excel...
If you are using Excel 2007, try using an earlier version because 2007's macro recorder is a bit crippled. This is what I got: ``` ActiveSheet.ChartObjects("Chart 1").Activate ActiveChart.Axes(xlCategory).Select Selection.TickLabels.Orientation = xlUpward ```
412,760
<p>There's something I'm just not getting about .NET remoting. Well, two things actually:</p> <ol> <li><p>Why is the emphasis back on classes that inherit from MarshalByRef instead of interfaces ala the original COM style (which I liked)?</p></li> <li><p>Why is it that .NET remoting always forces you to effectively cr...
[ { "answer_id": 412792, "author": "nickd", "author_id": 2373, "author_profile": "https://Stackoverflow.com/users/2373", "pm_score": 0, "selected": false, "text": "<p>I can't really address points 1 and 2 as I have no experience of COM and I don't understand 2, but to answer your specific ...
2009/01/05
[ "https://Stackoverflow.com/questions/412760", "https://Stackoverflow.com", "https://Stackoverflow.com/users/34685/" ]
There's something I'm just not getting about .NET remoting. Well, two things actually: 1. Why is the emphasis back on classes that inherit from MarshalByRef instead of interfaces ala the original COM style (which I liked)? 2. Why is it that .NET remoting always forces you to effectively create some sort of object pool...
The problem with Nickd's answer: I wanted to know how to associate an already created instance with a URL, rather than how to get .NET remoting to do this for me (some instance that I have created that does not have a default constructor, for example). I was hoping there'd be some epic response explaining the "philoso...
412,771
<p>I seem to run into this very often. I need to build a Hash from an array using an attribute of each object in the array as the key.</p> <p>Lets say I need a hash of example uses ActiveRecord objecs keyed by their ids Common way:</p> <pre><code>ary = [collection of ActiveRecord objects] hash = ary.inject({}) {|has...
[ { "answer_id": 412904, "author": "ewalshe", "author_id": 47429, "author_profile": "https://Stackoverflow.com/users/47429", "pm_score": 3, "selected": false, "text": "<p>You can add to_hash to Array yourself.</p>\n\n<pre><code>class Array\n def to_hash(&amp;block)\n Hash[*self.map {|e...
2009/01/05
[ "https://Stackoverflow.com/questions/412771", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13216/" ]
I seem to run into this very often. I need to build a Hash from an array using an attribute of each object in the array as the key. Lets say I need a hash of example uses ActiveRecord objecs keyed by their ids Common way: ``` ary = [collection of ActiveRecord objects] hash = ary.inject({}) {|hash, obj| hash[obj.id] =...
There is already a method in ActiveSupport that does this. ``` ['an array', 'of active record', 'objects'].index_by(&:id) ``` And just for the record, here's the implementation: ``` def index_by inject({}) do |accum, elem| accum[yield(elem)] = elem accum end end ``` Which could have been refactored in...