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
516,003
<p>I want to achieve the following functionality using LINQ.</p> <p>Case 1:</p> <pre><code>listOfStrings = {"C:","D:","E:"} myString = "C:\Files" Output: True </code></pre> <p>Case 2:</p> <pre><code>listOfStrings = {"C:","D:","E:"} myString = "F:\Files" Output: False </code></pre>
[ { "answer_id": 516020, "author": "Marc Gravell", "author_id": 23354, "author_profile": "https://Stackoverflow.com/users/23354", "pm_score": 4, "selected": true, "text": "<pre><code>bool b = listOfStrings.Any(myString.StartsWith);\n</code></pre>\n\n<p>or slightly more verbose (but easier ...
2009/02/05
[ "https://Stackoverflow.com/questions/516003", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I want to achieve the following functionality using LINQ. Case 1: ``` listOfStrings = {"C:","D:","E:"} myString = "C:\Files" Output: True ``` Case 2: ``` listOfStrings = {"C:","D:","E:"} myString = "F:\Files" Output: False ```
``` bool b = listOfStrings.Any(myString.StartsWith); ``` or slightly more verbose (but easier to understand): ``` bool b = listOfStrings.Any(s => myString.StartsWith(s)); ```
516,005
<p>I have to write some batch/dos script in windows which will put the files in UNIX box. But the path and filenames are getting changed every year and month respectively in windows.</p> <p>Suppose a directory in windows at path C:/2009MICS which will hold the files for whole year( 12 files). My batch will run monthly...
[ { "answer_id": 516171, "author": "Phil Reif", "author_id": 20244, "author_profile": "https://Stackoverflow.com/users/20244", "pm_score": 1, "selected": false, "text": "<pre><code>copy \"%date:~6%.txt\" \"\\path\\to\\destination\"\n</code></pre>\n\n<p>would copy 2009.txt to the destinatio...
2009/02/05
[ "https://Stackoverflow.com/questions/516005", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I have to write some batch/dos script in windows which will put the files in UNIX box. But the path and filenames are getting changed every year and month respectively in windows. Suppose a directory in windows at path C:/2009MICS which will hold the files for whole year( 12 files). My batch will run monthly and shoul...
``` copy "%date:~6%.txt" "\path\to\destination" ``` would copy 2009.txt to the destination path. To include the month, use ``` copy "%date:~3%.txt" "\path\to\destination" ``` Disclaimer - I tested that on a German edition of Win Vista, hope it works with the International editions as well.
516,007
<pre><code>std::map&lt;std::string, std::string&gt; myMap; std::map&lt;std::string, std::string&gt;::iterator i = m_myMap.find(some_key_string); if(i == m_imagesMap.end()) return NULL; string *p = &amp;i-&gt;first; </code></pre> <p>Is the last line valid? I want to store this pointer p somewhere else, will it b...
[ { "answer_id": 516041, "author": "PierreBdR", "author_id": 7136, "author_profile": "https://Stackoverflow.com/users/7136", "pm_score": 5, "selected": true, "text": "<p>First, maps are guaranteed to be stable; i.e. the iterators are not invalidated by element insertion or deletion (except...
2009/02/05
[ "https://Stackoverflow.com/questions/516007", "https://Stackoverflow.com", "https://Stackoverflow.com/users/31207/" ]
``` std::map<std::string, std::string> myMap; std::map<std::string, std::string>::iterator i = m_myMap.find(some_key_string); if(i == m_imagesMap.end()) return NULL; string *p = &i->first; ``` Is the last line valid? I want to store this pointer p somewhere else, will it be valid for the whole program life? B...
First, maps are guaranteed to be stable; i.e. the iterators are not invalidated by element insertion or deletion (except the element being deleted of course). However, stability of iterator does not guarantee stability of pointers! Although it usually happens that most implementations use pointers - at least at some l...
516,032
<p>QCombobox set Item delegate not painting for current Item..</p> <p>I am trying to create a combo box showing different line types (Solid, Dotted, Dash etc). Currently i am setting item delegate for its content so as to draw/paint line type instead of displaying names. All line types are drawing currectly but as soo...
[ { "answer_id": 592894, "author": "David Boddie", "author_id": 61047, "author_profile": "https://Stackoverflow.com/users/61047", "pm_score": 0, "selected": false, "text": "<p>I think I've encountered this problem before, having a delegate that displays the line correctly in the drop-down ...
2009/02/05
[ "https://Stackoverflow.com/questions/516032", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
QCombobox set Item delegate not painting for current Item.. I am trying to create a combo box showing different line types (Solid, Dotted, Dash etc). Currently i am setting item delegate for its content so as to draw/paint line type instead of displaying names. All line types are drawing currectly but as soon as i am ...
Delegate to paint items in combo popup: ``` class LineStyleDelegate(QtGui.QItemDelegate): def __init__(self, object, parent = None): QtGui.QItemDelegate.__init__(self, parent) def paint(self, painter, option, index): data = index.model().data(index, QtCore.Qt.UserRole) if data.isValid...
516,039
<p>What I'm looking for is the best way to say, 'If this list is too short, lengthen it to 9 elements and add 'Choice 4', 'Choice 5', etc, as the additional elements. Also, replace any 'None' elements with 'Choice x'.' It is ok to replace "" and 0 too.</p> <p>An example transformation would be</p> <pre><code>['a','b'...
[ { "answer_id": 516070, "author": "Douglas Leeder", "author_id": 3978, "author_profile": "https://Stackoverflow.com/users/3978", "pm_score": 2, "selected": false, "text": "<p>I think I'd do something pretty much like that, but with a few tidy ups:</p>\n\n<pre><code>for i in range(0,10):\n...
2009/02/05
[ "https://Stackoverflow.com/questions/516039", "https://Stackoverflow.com", "https://Stackoverflow.com/users/62398/" ]
What I'm looking for is the best way to say, 'If this list is too short, lengthen it to 9 elements and add 'Choice 4', 'Choice 5', etc, as the additional elements. Also, replace any 'None' elements with 'Choice x'.' It is ok to replace "" and 0 too. An example transformation would be ``` ['a','b',None,'c'] ``` to ...
Unlike `zip`, Python's `map` automatically extends shorter sequences with `None`. ``` map(lambda a, b: b if a is None else a, choicesTxt, ['Choice %i' % n for n in range(1, 10)]) ``` You could simplify the lambda to ``` map(lambda a, b: a or b, choicesTxt, ['Choice %i' % n for n in range(1, 10)]) `...
516,049
<p>I'm a Java rookie and I was wondering, if I have the following typical Java code</p> <pre><code>public class MyApp { public static void main(String[] args) { try { // do stuff } catch { // handle errors } finally { // clean up connections etc. } } } </code></pre> <p>does the J...
[ { "answer_id": 516059, "author": "Rob Grant", "author_id": 61938, "author_profile": "https://Stackoverflow.com/users/61938", "pm_score": 0, "selected": false, "text": "<p>Erm, yep :) Whether your code enters a catch or not, the finally will run. It's a good place to put code that cleans ...
2009/02/05
[ "https://Stackoverflow.com/questions/516049", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2077/" ]
I'm a Java rookie and I was wondering, if I have the following typical Java code ``` public class MyApp { public static void main(String[] args) { try { // do stuff } catch { // handle errors } finally { // clean up connections etc. } } } ``` does the JVM guarantee that the fina...
Basically yes, except for the note [listed here](http://docs.oracle.com/javase/tutorial/essential/exceptions/finally.html) (emphasis mine): > > If the JVM exits while the try or catch code is being executed, > then the finally block **may not** execute. Likewise, if the thread > executing the try or catch code is i...
516,051
<p>I am relatively new to MVC, so this is likely a novice question.</p> <p>I am trying to understand the best practices for how to maintain clear separation of concerns in a few scenarios that don't appear straightfoward.</p> <p>There are two scenarios I am looking at right now. Imagine a very basic app that lets us...
[ { "answer_id": 516096, "author": "tvanfosson", "author_id": 12950, "author_profile": "https://Stackoverflow.com/users/12950", "pm_score": 3, "selected": true, "text": "<p>For your scenario I pass along another parameter in the ViewData, ViewData[\"AllowEdit\"] which is set to true if the...
2009/02/05
[ "https://Stackoverflow.com/questions/516051", "https://Stackoverflow.com", "https://Stackoverflow.com/users/31910/" ]
I am relatively new to MVC, so this is likely a novice question. I am trying to understand the best practices for how to maintain clear separation of concerns in a few scenarios that don't appear straightfoward. There are two scenarios I am looking at right now. Imagine a very basic app that lets users view and edit ...
For your scenario I pass along another parameter in the ViewData, ViewData["AllowEdit"] which is set to true if the View should show the edit link. I prefer this to cloning the model into a view-specific model to add this single attribute. I do sometimes create view specific models -- for instance I have Grid ViewUserC...
516,065
<p>I'm a student and as a part of the yearly project I'm developing eclipse plug-in.<br> I've encountered a weird problem and trying to fix it for 2 days now: </p> <p>I've added 3 new types of markers in the <code>plugin.xml</code>.<br> For every marker I added <code>annotationTypes</code> and for every <code>annotat...
[ { "answer_id": 4200672, "author": "vocaro", "author_id": 118403, "author_profile": "https://Stackoverflow.com/users/118403", "pm_score": 0, "selected": false, "text": "<p>Are you sure you're specifying different marker ID type strings when creating them in your plugin's Java code? Just a...
2009/02/05
[ "https://Stackoverflow.com/questions/516065", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I'm a student and as a part of the yearly project I'm developing eclipse plug-in. I've encountered a weird problem and trying to fix it for 2 days now: I've added 3 new types of markers in the `plugin.xml`. For every marker I added `annotationTypes` and for every `annotationType` I've added `markerAnnotationSpe...
The colorPreferenceKey should be unique for each of your markerAnnotation specification. That should solve your problem.
516,073
<p>I want to select a sharepoint list item which has the Maximum value for a particular column. How can I do this using CAML queries?</p>
[ { "answer_id": 518169, "author": "jaloplo", "author_id": 444077, "author_profile": "https://Stackoverflow.com/users/444077", "pm_score": 2, "selected": false, "text": "<p>This can be done ordering by this field in descending way and taking the first element of the collection returned.</p...
2009/02/05
[ "https://Stackoverflow.com/questions/516073", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1909/" ]
I want to select a sharepoint list item which has the Maximum value for a particular column. How can I do this using CAML queries?
``` <Query> <OrderBy> <FieldRef Name="particularcolumn" Ascending="FALSE" /> </OrderBy> </Query> ```
516,082
<p>I've been trying to figure this one our for a while now.</p> <pre><code>(defn is-decimal [astr] (if (. astr (indexOf (int \.))) (Double/parseDouble astr) (Integer/parseInt astr))) </code></pre> <p>That is the function I wrote. <code>is-decimal</code> is either passed something such as "2.5" or "5" or som...
[ { "answer_id": 516104, "author": "Josh Mein", "author_id": 2486, "author_profile": "https://Stackoverflow.com/users/2486", "pm_score": 2, "selected": false, "text": "<p>well if it does return -1 if it fails then check for the -1 and return false if it is</p>\n" }, { "answer_id": ...
2009/02/05
[ "https://Stackoverflow.com/questions/516082", "https://Stackoverflow.com", "https://Stackoverflow.com/users/21734/" ]
I've been trying to figure this one our for a while now. ``` (defn is-decimal [astr] (if (. astr (indexOf (int \.))) (Double/parseDouble astr) (Integer/parseInt astr))) ``` That is the function I wrote. `is-decimal` is either passed something such as "2.5" or "5" or something of the sort, but it always use...
If you want to test whether a string contains a character, you can use a regex: ``` (re-find #"\." astr) ``` Or: ``` (some #(= \. %) astr) ``` Or: ``` (contains? (into #{} astr) \.) ``` Or you can use `includes?` from [clojure.contrib.seq-utils](https://github.com/clojure) which does this too. Clojure already...
516,088
<p>Source texts (7):</p> <ol> <li>give 4 cars</li> <li>ga 5 cars</li> <li>GA 5 Cars @mustang six exhausts are necessary</li> <li>Give -1 Cars @mustang </li> <li>Give Cars @mustang </li> <li>Give 3 Cars @ford</li> <li>Give 5 Cars @cobra_gt</li> </ol> <p>The ones which should be successful ate 1,2,3,6,7</p> <p>preg_ma...
[ { "answer_id": 516113, "author": "Staale", "author_id": 3355, "author_profile": "https://Stackoverflow.com/users/3355", "pm_score": 2, "selected": false, "text": "<p>1 and 2 are missing @\n4 has -1 (this doesn't match \\d)\n5 is missing the number</p>\n\n<p>you could change \" @\" to \"(...
2009/02/05
[ "https://Stackoverflow.com/questions/516088", "https://Stackoverflow.com", "https://Stackoverflow.com/users/61602/" ]
Source texts (7): 1. give 4 cars 2. ga 5 cars 3. GA 5 Cars @mustang six exhausts are necessary 4. Give -1 Cars @mustang 5. Give Cars @mustang 6. Give 3 Cars @ford 7. Give 5 Cars @cobra\_gt The ones which should be successful ate 1,2,3,6,7 preg\_match('/Give (\d+) Cars @(\w+)|GA (\d+) Cars @(\w+)/i', $a->text, $outpu...
Given the input: 1. give 4 cars 2. ga 5 cars 3. GA 5 Cars @mustang six exhausts are necessary 4. Give -1 Cars @mustang 5. Give Cars @mustang 6. Give 3 Cars @ford 7. Give 5 Cars @cobra\_gt And the expression: ``` /Give (\d+) Cars @(\w+)|GA (\d+) Cars @(\w+)/i ``` 1. Does not match because you are only matching agai...
516,091
<p>I have a SQL Server 2000 DB with a lot of PK/FK relationships changes in a specific time frame. Is there any way I can retrieve all the relationship changes or additions to a Database?</p> <p>I tried this query which returns all the ForeignKeys.</p> <pre><code>SELECT f.constid, OBJECT_NAME(f.fkeyid) AS 'FKTable', ...
[ { "answer_id": 516095, "author": "Mitch Wheat", "author_id": 16076, "author_profile": "https://Stackoverflow.com/users/16076", "pm_score": 3, "selected": true, "text": "<p>No, not unless you have a replica somewhere and a tool like Redgate's Compare.</p>\n" }, { "answer_id": 5160...
2009/02/05
[ "https://Stackoverflow.com/questions/516091", "https://Stackoverflow.com", "https://Stackoverflow.com/users/37742/" ]
I have a SQL Server 2000 DB with a lot of PK/FK relationships changes in a specific time frame. Is there any way I can retrieve all the relationship changes or additions to a Database? I tried this query which returns all the ForeignKeys. ``` SELECT f.constid, OBJECT_NAME(f.fkeyid) AS 'FKTable', c1.[name] AS 'FKColum...
No, not unless you have a replica somewhere and a tool like Redgate's Compare.
516,099
<p>I'm developing a service invoking script that looks like:</p> <pre><code>&lt;cfinvoke webservice="#ServiceURL#" method="AddCustomer" returnvariable="ResponseData" argumentcollection="#stAguments#"&gt; &lt;cfinvokeargument name="api_key" value="#ServiceKey#" /&gt; &lt;/cfinvoke&gt; </code></pre> <p><strong>stAg...
[ { "answer_id": 516381, "author": "rip747", "author_id": 31278, "author_profile": "https://Stackoverflow.com/users/31278", "pm_score": 0, "selected": false, "text": "<p>your headache is stemming from just accepting the values that are passed into your method without validating that the in...
2009/02/05
[ "https://Stackoverflow.com/questions/516099", "https://Stackoverflow.com", "https://Stackoverflow.com/users/56604/" ]
I'm developing a service invoking script that looks like: ``` <cfinvoke webservice="#ServiceURL#" method="AddCustomer" returnvariable="ResponseData" argumentcollection="#stAguments#"> <cfinvokeargument name="api_key" value="#ServiceKey#" /> </cfinvoke> ``` **stAguments** structure filled before this call, obviou...
Finally I've finished with writing additional code to help me testing my service. Also, I needed to provide my API users with examples in CFML and combined these tasks. Would like to share code samples, maybe someone else will find them useful. I've used validating structures method (but a bit simplified it by remov...
516,110
<p>I've seen some jquery code where people extend the main object like:</p> <pre><code> $('someId').myCustomObject(); </code></pre> <p>Is this possible or am I mistaken? (if yes, how?)</p>
[ { "answer_id": 516122, "author": "Rich", "author_id": 53501, "author_profile": "https://Stackoverflow.com/users/53501", "pm_score": 0, "selected": false, "text": "<p>I believe what you're looking for is jQuery.fn.extend:</p>\n\n<p><a href=\"http://docs.jquery.com/Core/jQuery.fn.extend\" ...
2009/02/05
[ "https://Stackoverflow.com/questions/516110", "https://Stackoverflow.com", "https://Stackoverflow.com/users/39677/" ]
I've seen some jquery code where people extend the main object like: ``` $('someId').myCustomObject(); ``` Is this possible or am I mistaken? (if yes, how?)
Yes it's easily possible. The standard pattern for building extensions is: ``` (function($) { $.fn.myCustomObject = function(options) { var defaults = { ... }; var opts = $.extend(defaults, options); this.each(function(i) { ... // Act on each item, $(this). ... // Use opts.blah to read mer...
516,119
<p>How can I fire a trigger BEFORE a delete in T-SQL 2005? The FOR actually fires AFTER an event and they seems no BEFORE argument in the TRIGGER function. The INSTEAD OF is not what I want. I need to fire before I delete a record. Any ideas?</p>
[ { "answer_id": 516137, "author": "Mitch Wheat", "author_id": 16076, "author_profile": "https://Stackoverflow.com/users/16076", "pm_score": 3, "selected": false, "text": "<p>You can't. But you can perform a rollback in an AFTER DELETE trigger.</p>\n" }, { "answer_id": 516141, ...
2009/02/05
[ "https://Stackoverflow.com/questions/516119", "https://Stackoverflow.com", "https://Stackoverflow.com/users/425282/" ]
How can I fire a trigger BEFORE a delete in T-SQL 2005? The FOR actually fires AFTER an event and they seems no BEFORE argument in the TRIGGER function. The INSTEAD OF is not what I want. I need to fire before I delete a record. Any ideas?
You can use the INSTEAD OF option, just explicitly delete the rows at the end. For example: ``` CREATE TRIGGER dbo.My_Table_Delete_Instead_Of_Trigger ON dbo.My_Table INSTEAD OF DELETE AS BEGIN -- Do some stuff here DELETE T FROM DELETED D INNER JOIN dbo.My_Table T ON T.PK_1 = D.PK_1 AND T.PK_2 = ...
516,142
<p>My specific question has to do with JMX as used in JDK 1.6: if I am running a Java process using JRE 1.6 with </p> <pre><code>com.sun.management.jmxremote </code></pre> <p>in the command line, does Java pick a default port for remote JMX connections?</p> <p>Backstory: I am currently trying to develop a procedure ...
[ { "answer_id": 516306, "author": "David Grant", "author_id": 40581, "author_profile": "https://Stackoverflow.com/users/40581", "pm_score": 2, "selected": false, "text": "<p>The <a href=\"http://java.sun.com/javase/6/docs/technotes/guides/management/agent.html\" rel=\"nofollow noreferrer\...
2009/02/05
[ "https://Stackoverflow.com/questions/516142", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5812/" ]
My specific question has to do with JMX as used in JDK 1.6: if I am running a Java process using JRE 1.6 with ``` com.sun.management.jmxremote ``` in the command line, does Java pick a default port for remote JMX connections? Backstory: I am currently trying to develop a procedure to give to a customer that will e...
The [documentation](http://java.sun.com/javase/6/docs/technotes/guides/management/agent.html) suggests that the JMX agent uses a **local** port -- something unreachable from outside the machine -- unless you specify the following property: `com.sun.management.jmxremote.port=portNum` This is for security reasons, as w...
516,148
<p>What is the argument against declaring protected-access members on interfaces? This, for example, is invalid:</p> <pre><code>public interface IOrange { public OrangePeel Peel { get; } protected OrangePips Seeds { get; } } </code></pre> <p>In this example, the interface <code>IOrange</code> would guarantee ...
[ { "answer_id": 516163, "author": "Gerrie Schenck", "author_id": 57036, "author_profile": "https://Stackoverflow.com/users/57036", "pm_score": 0, "selected": false, "text": "<p>An interface is all about what a certain object can do, so when using a class which implements that interface th...
2009/02/05
[ "https://Stackoverflow.com/questions/516148", "https://Stackoverflow.com", "https://Stackoverflow.com/users/62891/" ]
What is the argument against declaring protected-access members on interfaces? This, for example, is invalid: ``` public interface IOrange { public OrangePeel Peel { get; } protected OrangePips Seeds { get; } } ``` In this example, the interface `IOrange` would guarantee that implementors *at least* provide ...
I think everyone hammered the point of an interface having only public members, no implementation details. What you are looking for is an [abstract class](http://msdn.microsoft.com/en-us/library/ms173150.aspx). ``` public interface IOrange { OrangePeel Peel { get; } } public abstract class OrangeBase : IOrange {...
516,152
<p>How can you select an element that has current focus?</p> <p>There is no <code>:focus</code> filter in jQuery, that is why we can use something like this:</p> <pre><code>$('input:focus').someFunction(); </code></pre>
[ { "answer_id": 516172, "author": "Mike_G", "author_id": 52051, "author_profile": "https://Stackoverflow.com/users/52051", "pm_score": 6, "selected": true, "text": "<p>Really the best way to do it is to setup a handler for the onFocus event, and then set a variable to the ID of the elemen...
2009/02/05
[ "https://Stackoverflow.com/questions/516152", "https://Stackoverflow.com", "https://Stackoverflow.com/users/49200/" ]
How can you select an element that has current focus? There is no `:focus` filter in jQuery, that is why we can use something like this: ``` $('input:focus').someFunction(); ```
Really the best way to do it is to setup a handler for the onFocus event, and then set a variable to the ID of the element that has focus. something like this: ``` var id; $(":input").focus(function () { id = this.id; }); ```
516,174
<p>I'm making a post httpwebrequst, but in the HttpWebResponse im getting an error code 403 forbidden. Now that error isnt very use full to me.</p> <p>I then tried a testprogram (that i do not have the source code to :() and used it to make the same post, and it returned with a code 403 forbidden but also told me tha...
[ { "answer_id": 516207, "author": "Mitch Wheat", "author_id": 16076, "author_profile": "https://Stackoverflow.com/users/16076", "pm_score": 3, "selected": true, "text": "<p>If a WebException is thrown because of a protocol error, its Response\nproperty will contain the actual response rec...
2009/02/05
[ "https://Stackoverflow.com/questions/516174", "https://Stackoverflow.com", "https://Stackoverflow.com/users/36476/" ]
I'm making a post httpwebrequst, but in the HttpWebResponse im getting an error code 403 forbidden. Now that error isnt very use full to me. I then tried a testprogram (that i do not have the source code to :() and used it to make the same post, and it returned with a code 403 forbidden but also told me tha SSL was ne...
If a WebException is thrown because of a protocol error, its Response property will contain the actual response received from the web server. ``` try { // Do WebRequest } catch (WebException ex) { if (ex.Status == WebExceptionStatus.ProtocolError) { HttpWebResponse response = ex.Response as Htt...
516,188
<p>I have a winform application that uses some referenced web services to get data. The data returned is an array of objects that I loop through and add to a dataSet.</p> <p>When I call the service, it can often take 2 or 3 minutes to get all the data.</p> <p>If the user exits the program and comes back later, I don...
[ { "answer_id": 516211, "author": "Marc Gravell", "author_id": 23354, "author_profile": "https://Stackoverflow.com/users/23354", "pm_score": 3, "selected": true, "text": "<p>A .NET object has no persistance unless you write it yourself - for example by serializing to a file in the user's ...
2009/02/05
[ "https://Stackoverflow.com/questions/516188", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20153/" ]
I have a winform application that uses some referenced web services to get data. The data returned is an array of objects that I loop through and add to a dataSet. When I call the service, it can often take 2 or 3 minutes to get all the data. If the user exits the program and comes back later, I don't want them to ha...
A .NET object has no persistance unless you write it yourself - for example by serializing to a file in the user's profile (or [isolated storage](https://stackoverflow.com/questions/202013/clickonce-and-isolatedstorage) for ClickOnce). Note: personally, I wouldn't use `DataSet` at all in this scenario; if you are down...
516,196
<p>How do you configure JBoss to debug an application in Eclipse?</p>
[ { "answer_id": 516214, "author": "VonC", "author_id": 6309, "author_profile": "https://Stackoverflow.com/users/6309", "pm_score": 8, "selected": true, "text": "<p>You mean <a href=\"http://jmdesp.free.fr/billeterie/?p=95\" rel=\"noreferrer\">remote debug JBoss</a> from Eclipse ?</p>\n\n<...
2009/02/05
[ "https://Stackoverflow.com/questions/516196", "https://Stackoverflow.com", "https://Stackoverflow.com/users/61628/" ]
How do you configure JBoss to debug an application in Eclipse?
You mean [remote debug JBoss](http://jmdesp.free.fr/billeterie/?p=95) from Eclipse ? From [Configuring Eclipse for Remote Debugging](http://www.onjava.com/pub/a/onjava/2005/08/31/eclipse-jboss-remote-debug.html?page=6): > > Set the JAVA\_OPTS variable as follows: > > > ``` set JAVA_OPTS= -Xdebug -Xnoagent -X...
516,200
<p>There are numerous post over the net that detail how relative paths don't work in Xcode. I do have an Xcode template that I downloaded where the relative paths DO work, however I have not been able to figure out why nor replicate it in other projects.</p> <p>Firstly, I am using C++ in Xcode 3.1. I am not using Obje...
[ { "answer_id": 519164, "author": "cdespinosa", "author_id": 25972, "author_profile": "https://Stackoverflow.com/users/25972", "pm_score": 4, "selected": false, "text": "<p>Do not depend on the current working directory in binary code. Just don't. You cannot trust the operating system o...
2009/02/05
[ "https://Stackoverflow.com/questions/516200", "https://Stackoverflow.com", "https://Stackoverflow.com/users/40002/" ]
There are numerous post over the net that detail how relative paths don't work in Xcode. I do have an Xcode template that I downloaded where the relative paths DO work, however I have not been able to figure out why nor replicate it in other projects. Firstly, I am using C++ in Xcode 3.1. I am not using Objective-C, n...
Took me about 5 hours of Google and trying different things to FINALLY find the answer! ``` #ifdef __APPLE__ #include "CoreFoundation/CoreFoundation.h" #endif // ---------------------------------------------------------------------------- // This makes relative paths work in C++ in Xcode by changing directory to the ...
516,201
<p>I have a C# 2.0 windows service (100% managed code) and <em>occasionally</em> when it is started/restarted it causes the entire machine (Windows Server 2003) to hang indefinitely. When I click “Start the service” the service control progress bar gets halfway then the machine becomes completely unresponsive at the l...
[ { "answer_id": 519164, "author": "cdespinosa", "author_id": 25972, "author_profile": "https://Stackoverflow.com/users/25972", "pm_score": 4, "selected": false, "text": "<p>Do not depend on the current working directory in binary code. Just don't. You cannot trust the operating system o...
2009/02/05
[ "https://Stackoverflow.com/questions/516201", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I have a C# 2.0 windows service (100% managed code) and *occasionally* when it is started/restarted it causes the entire machine (Windows Server 2003) to hang indefinitely. When I click “Start the service” the service control progress bar gets halfway then the machine becomes completely unresponsive at the local termin...
Took me about 5 hours of Google and trying different things to FINALLY find the answer! ``` #ifdef __APPLE__ #include "CoreFoundation/CoreFoundation.h" #endif // ---------------------------------------------------------------------------- // This makes relative paths work in C++ in Xcode by changing directory to the ...
516,203
<p>I have an ItemsControl bound to an ObservableCollection. When the observable collection changes, I have an event handler that looks at the children of the ItemsControl. Unfortunately, the ItemsControl hasn't yet added a new item at that time (which is understandable). How can I know when an ItemsControl has finished...
[ { "answer_id": 519164, "author": "cdespinosa", "author_id": 25972, "author_profile": "https://Stackoverflow.com/users/25972", "pm_score": 4, "selected": false, "text": "<p>Do not depend on the current working directory in binary code. Just don't. You cannot trust the operating system o...
2009/02/05
[ "https://Stackoverflow.com/questions/516203", "https://Stackoverflow.com", "https://Stackoverflow.com/users/23837/" ]
I have an ItemsControl bound to an ObservableCollection. When the observable collection changes, I have an event handler that looks at the children of the ItemsControl. Unfortunately, the ItemsControl hasn't yet added a new item at that time (which is understandable). How can I know when an ItemsControl has finished ad...
Took me about 5 hours of Google and trying different things to FINALLY find the answer! ``` #ifdef __APPLE__ #include "CoreFoundation/CoreFoundation.h" #endif // ---------------------------------------------------------------------------- // This makes relative paths work in C++ in Xcode by changing directory to the ...
516,210
<p>I have a control with a DependencyProperty with a CoerceValueCallback. This property is bound to a property on a model object.</p> <p>When setting the control property to a value that causes coercion the Binding pushes the <strong>uncoerced</strong> value to the model object. The property value on the control is co...
[ { "answer_id": 667060, "author": "Steven", "author_id": 80566, "author_profile": "https://Stackoverflow.com/users/80566", "pm_score": 2, "selected": true, "text": "<p>I don't think the coerce callback is meant to be a two-way street. One workaround would be to update the model's value in...
2009/02/05
[ "https://Stackoverflow.com/questions/516210", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1260066/" ]
I have a control with a DependencyProperty with a CoerceValueCallback. This property is bound to a property on a model object. When setting the control property to a value that causes coercion the Binding pushes the **uncoerced** value to the model object. The property value on the control is coerced correctly. How d...
I don't think the coerce callback is meant to be a two-way street. One workaround would be to update the model's value inside of the coerce callback.
516,215
<p>I want to know whether I can access the directory where my application is installed. Also I want to create a sub directory in the same directory to store all the images I capture in my application. I further want to view the images using iPhone's default image viewer. Can this be done?</p>
[ { "answer_id": 516278, "author": "August", "author_id": 30966, "author_profile": "https://Stackoverflow.com/users/30966", "pm_score": -1, "selected": false, "text": "<p>C'mon, this is all in the sample code and documentation. In fact, it's even one of the Frequently Asked Questions in th...
2009/02/05
[ "https://Stackoverflow.com/questions/516215", "https://Stackoverflow.com", "https://Stackoverflow.com/users/44878/" ]
I want to know whether I can access the directory where my application is installed. Also I want to create a sub directory in the same directory to store all the images I capture in my application. I further want to view the images using iPhone's default image viewer. Can this be done?
``` NSString *appFolderPath = [[NSBundle mainBundle] resourcePath]; NSFileManager *fileManager = [NSFileManager defaultManager]; NSLog(@"App Directory is: %@", appFolderPath); NSLog(@"Directory Contents:\n%@", [fileManager directoryContentsAtPath: appFolderPath]); ```
516,217
<p>How can we make our build process (Dev Studio 2005) for a .NET project completely independent of what is installed on the GAC on the particular machine that it is running on.</p> <p>Here's the problem we're trying to solve: Depending on what assemblies happen to have been installed into the GAC, our build process g...
[ { "answer_id": 516232, "author": "Marc Gravell", "author_id": 23354, "author_profile": "https://Stackoverflow.com/users/23354", "pm_score": 0, "selected": false, "text": "<p>The simplest answer is to be explicit: add a reference to B.dll and set it how you want it.</p>\n" }, { "a...
2009/02/05
[ "https://Stackoverflow.com/questions/516217", "https://Stackoverflow.com", "https://Stackoverflow.com/users/34685/" ]
How can we make our build process (Dev Studio 2005) for a .NET project completely independent of what is installed on the GAC on the particular machine that it is running on. Here's the problem we're trying to solve: Depending on what assemblies happen to have been installed into the GAC, our build process generates d...
Like Marc suggested, the only way to do it was to add the dependent references and setting CopyLocal=True. But I'm coming to agree with Danny's answer - don't use Dev Studio for your deployment, because you can't get sufficient control over the build process. Why? There's some "defaulting" logic going on with the Dev...
516,227
<p>I have a post-build target in MSBuild to copy some build outputs.</p> <p>This is linked in as a dependency to the <code>AfterBuild</code> target (exposed by <code>Microsoft.CSharp.targets</code>):</p> <pre><code>&lt;Target Name="AfterBuild" DependsOnTargets="InstallUtil;CopyPostBuildFiles" /&gt; </code></pre> <p>...
[ { "answer_id": 516333, "author": "Julien Hoarau", "author_id": 12248, "author_profile": "https://Stackoverflow.com/users/12248", "pm_score": 0, "selected": false, "text": "<p>Build target definition is:</p>\n\n<pre><code>&lt;Target Name = \"Build\" DependsOnTargets=\"BeforeBuild;CoreBuil...
2009/02/05
[ "https://Stackoverflow.com/questions/516227", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5975/" ]
I have a post-build target in MSBuild to copy some build outputs. This is linked in as a dependency to the `AfterBuild` target (exposed by `Microsoft.CSharp.targets`): ``` <Target Name="AfterBuild" DependsOnTargets="InstallUtil;CopyPostBuildFiles" /> ``` Is there any way to avoid the files being copied if the build...
Since you are overriding the AfterBuild target it will always execute after the build occurs. This is the case for a rebuild or a normal build. If you want to perform some actions after the rebuild (and not build) then you should extend the dependency property for the Rebuild target. So in your case to inject the targe...
516,228
<p>I'm trying to write a VBScript function that collects the value of a cell ("E1") across all tabs of an Excel document into an array (Reviewers).</p> <p>I wrote the following code, but the data is not being stored into the array, can someone please tell me what I'm doing wrong?</p> <p>This is the code:</p> <p><img...
[ { "answer_id": 516290, "author": "Patrick McDonald", "author_id": 61989, "author_profile": "https://Stackoverflow.com/users/61989", "pm_score": 1, "selected": false, "text": "<p>I can't see your code as my company has blocked access to imageshack.</p>\n\n<p>Have you tried something like ...
2009/02/05
[ "https://Stackoverflow.com/questions/516228", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I'm trying to write a VBScript function that collects the value of a cell ("E1") across all tabs of an Excel document into an array (Reviewers). I wrote the following code, but the data is not being stored into the array, can someone please tell me what I'm doing wrong? This is the code: ![vba screenshot](https://i....
I can't see your code as my company has blocked access to imageshack. Have you tried something like the following? ``` Dim i As Long Dim reviewers() As String ReDim reviewers(0 To Worksheets.Count - 1) For i = 0 To Worksheets.Count - 1 reviewers(i) = Worksheets(i + 1).Cells(1, 5).Value Next ```
516,233
<p>I am starting out with unit testing, I have a method that uses the web.config for a connection string.</p> <p>I was hoping to be able to use</p> <pre><code>[DeploymentItem("web.config")] </code></pre> <p>to get the web config file, this still leaves me with null reference exceptions (that'd be what I write my nex...
[ { "answer_id": 516245, "author": "Gerrie Schenck", "author_id": 57036, "author_profile": "https://Stackoverflow.com/users/57036", "pm_score": 8, "selected": true, "text": "<p>Unit test projects should have their own config file.</p>\n\n<p>On a test project you can choose Add, New Item, A...
2009/02/05
[ "https://Stackoverflow.com/questions/516233", "https://Stackoverflow.com", "https://Stackoverflow.com/users/48886/" ]
I am starting out with unit testing, I have a method that uses the web.config for a connection string. I was hoping to be able to use ``` [DeploymentItem("web.config")] ``` to get the web config file, this still leaves me with null reference exceptions (that'd be what I write my next test for). How do I use the co...
Unit test projects should have their own config file. On a test project you can choose Add, New Item, Application Configuration File. This file will behave exactly like a web.config, but then for your unit tests.
516,237
<p>In my years of C++ (MFC) programming in I never felt the need to use <code>typedef</code>, so I don't really know what is it used for. Where should I use it? Are there any real situations where the use of <code>typedef</code> is preferred? Or is this really more a C-specific keyword?</p>
[ { "answer_id": 516251, "author": "moonshadow", "author_id": 11834, "author_profile": "https://Stackoverflow.com/users/11834", "pm_score": 2, "selected": false, "text": "<p>Real-world uses of typedef:</p>\n\n<ul>\n<li>providing friendly aliases for long-winded templated types</li>\n<li>pr...
2009/02/05
[ "https://Stackoverflow.com/questions/516237", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4880/" ]
In my years of C++ (MFC) programming in I never felt the need to use `typedef`, so I don't really know what is it used for. Where should I use it? Are there any real situations where the use of `typedef` is preferred? Or is this really more a C-specific keyword?
Template Metaprogramming ------------------------ `typedef` is *necessary* for many [template metaprogramming](http://en.wikipedia.org/wiki/Template_metaprogramming) tasks -- whenever a class is treated as a "compile-time type function", a `typedef` is used as a "compile-time type value" to obtain the resulting type. ...
516,248
<p>I have a web application which uses a session cookie to keep users logged on. When they log on, the system generates a GUID which it associates with the User record in the database. The GUID which is then stored in a cookie so it can be then read on each page load and checked against the database entry.</p> <p>The ...
[ { "answer_id": 516415, "author": "user61405", "author_id": 61405, "author_profile": "https://Stackoverflow.com/users/61405", "pm_score": 2, "selected": false, "text": "<p>Are all clients using the same version of IE? I've also seen on Windows anti-virus software clearing cookies.</p>\n" ...
2009/02/05
[ "https://Stackoverflow.com/questions/516248", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7585/" ]
I have a web application which uses a session cookie to keep users logged on. When they log on, the system generates a GUID which it associates with the User record in the database. The GUID which is then stored in a cookie so it can be then read on each page load and checked against the database entry. The code to se...
Are all clients using the same version of IE? I've also seen on Windows anti-virus software clearing cookies.
516,255
<p>I'm working on a Wicket-based web application. In the application there are buttons that not every user is authorized to use. These buttons are actually simple links, e.g.</p> <pre><code>&lt;a wicket:id="publishButton" title="Publish" class="rightPanel_publish"&gt;&lt;wicket:message key="publish"/&gt;&lt;/a&gt; </c...
[ { "answer_id": 516271, "author": "Justin Yost", "author_id": 657, "author_profile": "https://Stackoverflow.com/users/657", "pm_score": 3, "selected": true, "text": "<p>Unfortunately I don't know of a way to change a button's page without JS. CSS, Java and everything else runs while the p...
2009/02/05
[ "https://Stackoverflow.com/questions/516255", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2819/" ]
I'm working on a Wicket-based web application. In the application there are buttons that not every user is authorized to use. These buttons are actually simple links, e.g. ``` <a wicket:id="publishButton" title="Publish" class="rightPanel_publish"><wicket:message key="publish"/></a> ``` with a CSS class (from an ext...
Unfortunately I don't know of a way to change a button's page without JS. CSS, Java and everything else runs while the page is loading, after the page has loaded the only way to interact with the page is via JS. However here is the JS that works in any browser (IE 6+, Safari, Opera, FF, etc), ``` if(document.getEle...
516,263
<p>Leading on from my previous questions I am going to try and clarify one of the problems I am facing.</p> <p>I am trying to create a multiplayer version of PacMan. </p> <p>A simple overview of how i've made my application is that I have a server which has a ServerSocket which is constantly listening on a specific p...
[ { "answer_id": 516358, "author": "mafu", "author_id": 39590, "author_profile": "https://Stackoverflow.com/users/39590", "pm_score": 2, "selected": true, "text": "<p>Multithreading needs synchronisation. Are you using a synced stream (or syncing the access to the stream yourself)?</p>\n\n...
2009/02/05
[ "https://Stackoverflow.com/questions/516263", "https://Stackoverflow.com", "https://Stackoverflow.com/users/50913/" ]
Leading on from my previous questions I am going to try and clarify one of the problems I am facing. I am trying to create a multiplayer version of PacMan. A simple overview of how i've made my application is that I have a server which has a ServerSocket which is constantly listening on a specific port. Once a clien...
Multithreading needs synchronisation. Are you using a synced stream (or syncing the access to the stream yourself)? **Update:** The code sample given may very well be called from multiple threads. If multiple threads access the same stream, errors like the ones you are experiencing may very well occur. I suggest havi...
516,265
<p>Does anybody know how to unbind set of event handlers, but memorize them in order to bind them again later? Any suggestions?</p>
[ { "answer_id": 516344, "author": "meouw", "author_id": 12161, "author_profile": "https://Stackoverflow.com/users/12161", "pm_score": 0, "selected": false, "text": "<p>In order to unbind an event handler you need to pass the handler function into unbind(). So you already have the handler ...
2009/02/05
[ "https://Stackoverflow.com/questions/516265", "https://Stackoverflow.com", "https://Stackoverflow.com/users/59692/" ]
Does anybody know how to unbind set of event handlers, but memorize them in order to bind them again later? Any suggestions?
There is a events element in the data of the item. This should get your started, you can read your elements and store the handlers in an array before unbinding. Comment if you need more help. I got this idea from reading the $.fn.clone method so take a look at that as well. ``` $(document).ready(function() { $('#t...
516,283
<p>Hey i have this div that shows as a popup:</p> <pre><code>&lt;div class="popup"&gt; &lt;/div&gt; </code></pre> <p>Then with jquery i add another class to it to give it with the css associated to that class, position, size, color and transparency:</p> <pre><code>.show { position: absolute; color: #F4F5F6; ...
[ { "answer_id": 516293, "author": "Marko", "author_id": 31141, "author_profile": "https://Stackoverflow.com/users/31141", "pm_score": 0, "selected": false, "text": "<p>You can't execute server side java code in client browser.</p>\n\n<p>What you can do is to perform new http request that ...
2009/02/05
[ "https://Stackoverflow.com/questions/516283", "https://Stackoverflow.com", "https://Stackoverflow.com/users/26004/" ]
Hey i have this div that shows as a popup: ``` <div class="popup"> </div> ``` Then with jquery i add another class to it to give it with the css associated to that class, position, size, color and transparency: ``` .show { position: absolute; color: #F4F5F6; width: 600px; margin-left: -300px; he...
What you want to do is have javascript fire off an AJAX request when the said element is clicked. This AJAX request will go to the server which can then invoke any java code you want. Now you can build this all yourself or you could use one of the many off the shelf solutions. I would recommend Googling around for a J...
516,291
<p>If I write the following class:</p> <pre><code>public class Example { int j; int k; public Example(int j, int k) { j = j; k = k; } public static void main(String[] args) { Example exm = new Example(1,2); System.out.println(exm.j); ...
[ { "answer_id": 516308, "author": "Rob Grant", "author_id": 61938, "author_profile": "https://Stackoverflow.com/users/61938", "pm_score": 3, "selected": false, "text": "<p>If you don't write this, then you assign the argument to itself; the argument variables shadow the instance variables...
2009/02/05
[ "https://Stackoverflow.com/questions/516291", "https://Stackoverflow.com", "https://Stackoverflow.com/users/42155/" ]
If I write the following class: ``` public class Example { int j; int k; public Example(int j, int k) { j = j; k = k; } public static void main(String[] args) { Example exm = new Example(1,2); System.out.println(exm.j); System.out....
If you don't write "this.variable" in your constructor, and if you have a local variable (including the function parameter) with the same name as your field variable in the constructor, then the local variable will be considered; the local variable shadows the field (aka class variable). One place where "this" is the ...
516,305
<p>I have a Makefile where most of my targets are created generically through a canned sequence. It seems that bash completion only suggests completions for normal targets, e.g.</p> <pre><code>target_name: #$@ </code></pre> <p>and not for generic targets. Is there any way to make bash completion complete all ...
[ { "answer_id": 516548, "author": "Quassnoi", "author_id": 55159, "author_profile": "https://Stackoverflow.com/users/55159", "pm_score": 1, "selected": false, "text": "<p>There is no working solution, AFAIK.</p>\n\n<p>This command:</p>\n\n<pre><code>make -qsp 2&gt;/dev/null | egrep '^[^#%...
2009/02/05
[ "https://Stackoverflow.com/questions/516305", "https://Stackoverflow.com", "https://Stackoverflow.com/users/51634/" ]
I have a Makefile where most of my targets are created generically through a canned sequence. It seems that bash completion only suggests completions for normal targets, e.g. ``` target_name: #$@ ``` and not for generic targets. Is there any way to make bash completion complete all the targets, even though t...
``` $ make -qp | grep '^[^.#].*: ' all: bin1 bin2 bin3 bin1: obj1.o obj2.o obj3.o obj1.o: obj1.c obj1.h ... $ make -qp | sed -n -e 's/^\([^.#[:space:]][^:[:space:]]*\): .*/\1/p' all bin1 obj1.o ... ``` The `-q` prevents Make from actually running anything, and the `-p` asks it to dump its database. Then all you need ...
516,346
<p>I'm hitting a road block and I'm wondering if the brilliant collective minds here can help. In ObjC CocoaTouch I'm trying to mock an object that takes struct parameters and returns a struct. OCMock is coughing up a hair-ball so I tried wrapping with a Hamcrest matcher. No die. The function/method I'm testing looks s...
[ { "answer_id": 2032271, "author": "Jon Reid", "author_id": 246895, "author_profile": "https://Stackoverflow.com/users/246895", "pm_score": 0, "selected": false, "text": "<p>Sometimes a hand-coded mock is easier than trying to coerce a mock object framework outside of its normal use patte...
2009/02/05
[ "https://Stackoverflow.com/questions/516346", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10631/" ]
I'm hitting a road block and I'm wondering if the brilliant collective minds here can help. In ObjC CocoaTouch I'm trying to mock an object that takes struct parameters and returns a struct. OCMock is coughing up a hair-ball so I tried wrapping with a Hamcrest matcher. No die. The function/method I'm testing looks some...
You're very close. Your #define should be: ``` #define OCMOCK_STRUCT(atype, variable) [NSValue valueWithBytes:&variable withObjCType:@encode(atype)] ```
516,353
<p>I'm looking for some pros and cons of creating one operation per wdsl against bundling operations in a single wdsl</p> <p>Small example below:</p> <pre><code> &lt;operation name="Divide"&gt; &lt;input message="y:DivideMessage"/&gt; &lt;output message="y:DivideResponseMessage"/&gt; &lt;/operation&gt; <...
[ { "answer_id": 2032271, "author": "Jon Reid", "author_id": 246895, "author_profile": "https://Stackoverflow.com/users/246895", "pm_score": 0, "selected": false, "text": "<p>Sometimes a hand-coded mock is easier than trying to coerce a mock object framework outside of its normal use patte...
2009/02/05
[ "https://Stackoverflow.com/questions/516353", "https://Stackoverflow.com", "https://Stackoverflow.com/users/57004/" ]
I'm looking for some pros and cons of creating one operation per wdsl against bundling operations in a single wdsl Small example below: ``` <operation name="Divide"> <input message="y:DivideMessage"/> <output message="y:DivideResponseMessage"/> </operation> ``` instead of being divide and this were mo...
You're very close. Your #define should be: ``` #define OCMOCK_STRUCT(atype, variable) [NSValue valueWithBytes:&variable withObjCType:@encode(atype)] ```
516,355
<p>There was an interesting question in a practice test that I did not understand the answer to. What is the output of the following code:</p> <pre><code>&lt;?php class Foo { public $name = 'Andrew'; public function getName() { echo $this-&gt;name; } } class Bar extends Foo { public $name = '...
[ { "answer_id": 516371, "author": "Ulf", "author_id": 51208, "author_profile": "https://Stackoverflow.com/users/51208", "pm_score": 2, "selected": false, "text": "<p>If you call the static method bound to the other object, the method is executed in the context of the current object. Which...
2009/02/05
[ "https://Stackoverflow.com/questions/516355", "https://Stackoverflow.com", "https://Stackoverflow.com/users/46675/" ]
There was an interesting question in a practice test that I did not understand the answer to. What is the output of the following code: ``` <?php class Foo { public $name = 'Andrew'; public function getName() { echo $this->name; } } class Bar extends Foo { public $name = 'John'; public f...
$this to the object in whose context the method was called. So: $this is $a->getName() is $a. $this in $fooInstance->getName() would be $fooInstance. In the case that $this is set (in an object $a's method call) and we call a static method, $this remains assigned to $a. Seems like quite a lot of confusion could come o...
516,356
<p>Lets say I have an entity Foo, and it contains a list of another entity Bar. Should Bar have a direct reference to Foo? i.e...</p> <pre><code>public class Foo { public int Id {get; set;} public IList&lt;Bar&gt; Bars {get; set;} } public class Bar { public int Id {get; set;} public Foo parentFoo {get;...
[ { "answer_id": 516388, "author": "AnthonyWJones", "author_id": 17516, "author_profile": "https://Stackoverflow.com/users/17516", "pm_score": 3, "selected": true, "text": "<p>The correct approach is to ask the question \"Does Bar need to reference Foo for some reason?\" Don't just place ...
2009/02/05
[ "https://Stackoverflow.com/questions/516356", "https://Stackoverflow.com", "https://Stackoverflow.com/users/46780/" ]
Lets say I have an entity Foo, and it contains a list of another entity Bar. Should Bar have a direct reference to Foo? i.e... ``` public class Foo { public int Id {get; set;} public IList<Bar> Bars {get; set;} } public class Bar { public int Id {get; set;} public Foo parentFoo {get; set; //this will be ...
The correct approach is to ask the question "Does Bar need to reference Foo for some reason?" Don't just place the reference there if Bar has no need to do anything with it.
516,367
<p>I know this may be a noob question, but it's bugging the heck out of me.</p> <p>Let's say I have a user control that I reference in my .aspx page:</p> <pre><code>&lt;uc:somecontrol runat="server" id="uc1" property1="red" /&gt; </code></pre> <p>how do I make it so when in VS05 the intellisense will show options li...
[ { "answer_id": 516377, "author": "Rex M", "author_id": 67, "author_profile": "https://Stackoverflow.com/users/67", "pm_score": 5, "selected": true, "text": "<p>Make your property an enum instead of a string.</p>\n\n<pre><code>Enum ControlColor\nRed = 1\nBlue = 2\nGreen = 3\nEnd Enum\n</c...
2009/02/05
[ "https://Stackoverflow.com/questions/516367", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7173/" ]
I know this may be a noob question, but it's bugging the heck out of me. Let's say I have a user control that I reference in my .aspx page: ``` <uc:somecontrol runat="server" id="uc1" property1="red" /> ``` how do I make it so when in VS05 the intellisense will show options like "red", "green", "blue" for property1...
Make your property an enum instead of a string. ``` Enum ControlColor Red = 1 Blue = 2 Green = 3 End Enum ``` and ``` Public Property MyProperty As ControlColor ```
516,395
<p>I encountered some code reading</p> <pre><code>typedef enum eEnum { c1, c2 } tagEnum; typedef struct { int i; double d; } tagMyStruct; </code></pre> <p>I heard rumours that these constructs date from C. In C++ you can easily write</p> <pre><code>enum eEnum { c1, c2 }; struct MyStruct { int i; double d; }; </cod...
[ { "answer_id": 516412, "author": "Philip Reynolds", "author_id": 1087, "author_profile": "https://Stackoverflow.com/users/1087", "pm_score": 1, "selected": false, "text": "<p>It's just shorthand.</p>\n\n<p>In the second instance, to declare the struct you'd do so with:</p>\n\n<pre><code>...
2009/02/05
[ "https://Stackoverflow.com/questions/516395", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6610/" ]
I encountered some code reading ``` typedef enum eEnum { c1, c2 } tagEnum; typedef struct { int i; double d; } tagMyStruct; ``` I heard rumours that these constructs date from C. In C++ you can easily write ``` enum eEnum { c1, c2 }; struct MyStruct { int i; double d; }; ``` Is that true? When do you need the fi...
First, both declarations are legal in both C and C++. However, in C, they have slightly different semantics. (In particular, the way you refer to the struct later varies). The key concept to understand is that in C, structs exist in a separate namespace. All built-in types, as well as typedefs exist in the "default" n...
516,411
<p>I need to bind a method into a function-callback, except this snippet is not legal as discussed in <a href="https://stackoverflow.com/questions/282372/demote-boostfunction-to-a-plain-function-pointer/512189#512189">demote-boostfunction-to-a-plain-function-pointer</a>.</p> <p>What's the simplest way to get this beha...
[ { "answer_id": 516462, "author": "Eclipse", "author_id": 8701, "author_profile": "https://Stackoverflow.com/users/8701", "pm_score": 2, "selected": false, "text": "<p>Either you can shove that bound parameter into a global variable and create a static function that can pick up the value ...
2009/02/05
[ "https://Stackoverflow.com/questions/516411", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20003/" ]
I need to bind a method into a function-callback, except this snippet is not legal as discussed in [demote-boostfunction-to-a-plain-function-pointer](https://stackoverflow.com/questions/282372/demote-boostfunction-to-a-plain-function-pointer/512189#512189). What's the simplest way to get this behavior? ``` struct C {...
You can make your own class to do the same thing as the boost bind function. All the class has to do is accept the function type and a pointer to the object that contains the function. For example, this is a void return and void param delegate: ``` template<typename owner> class VoidDelegate : public IDelegate { publi...
516,431
<p>For some reason the integrated debugger is <strong>causing</strong> an error as soon as I make reference to a third party vendor's dll class. This same code runs when it is built and ran as a release, stand alone. The two properties for debug and release should be the same as I have not really altered them. I added ...
[ { "answer_id": 516444, "author": "TheSmurf", "author_id": 1975282, "author_profile": "https://Stackoverflow.com/users/1975282", "pm_score": 1, "selected": false, "text": "<p><em>engaging psychic debugging</em></p>\n\n<p>The fact that it runs in release mode fine and crashes in debug mode...
2009/02/05
[ "https://Stackoverflow.com/questions/516431", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17675/" ]
For some reason the integrated debugger is **causing** an error as soon as I make reference to a third party vendor's dll class. This same code runs when it is built and ran as a release, stand alone. The two properties for debug and release should be the same as I have not really altered them. I added the lib file to ...
Looking at the atltls.cpp file from my VC9 install, the crash is occurring here: ``` inline void* CThreadSlotData::GetThreadValue(int nSlot) { EnterCriticalSection(&m_sect); ASSERT(nSlot != 0 && nSlot < m_nMax); ASSERT(m_pSlotData != NULL); ASSERT(m_pSlotData[nSlot].dwFlags & SLOT_USED); // <== crash...
516,443
<p>I found this wonderful NSManagedObjectID. This would be very good for referencing an Entity/NSManagedObject/NSEntityDescription, right?<br> Let's get an ID from an entity:</p> <pre><code>NSEntityDescription *entity = [self newEntity]; NSManagedObjectID *objID = [entity objectID]; </code></pre> <p>So... any id...
[ { "answer_id": 516664, "author": "Peter Hosey", "author_id": 30461, "author_profile": "https://Stackoverflow.com/users/30461", "pm_score": 2, "selected": false, "text": "<p>Did you look at <a href=\"http://developer.apple.com/documentation/Cocoa/Reference/CoreDataFramework/Classes/NSMana...
2009/02/05
[ "https://Stackoverflow.com/questions/516443", "https://Stackoverflow.com", "https://Stackoverflow.com/users/59518/" ]
I found this wonderful NSManagedObjectID. This would be very good for referencing an Entity/NSManagedObject/NSEntityDescription, right? Let's get an ID from an entity: ``` NSEntityDescription *entity = [self newEntity]; NSManagedObjectID *objID = [entity objectID]; ``` So... any idea how to get this `objID` ...
To get an archived URI corresponding to a `NSManagedObject`'s `objectID`: ``` NSManagedObject* myMO; ... NSURL *uri = [[myMO objectID] URIRepresentation]; NSData *uriData = [NSKeyedArchiver archivedDataWithRootObject:uri]; ``` In order to get back to an instance of the original managed object, you need a CoreData st...
516,451
<p>I'm trying to add a space before every capital letter, except the first one.</p> <p>Here's what I have so far, and the output I'm getting:</p> <pre><code>&gt;&gt;&gt; tex = "ThisFileName.txt" &gt;&gt;&gt; re.sub('[A-Z].', ' ', tex) ' his ile ame.txt' </code></pre> <p>I want: 'This File Name.txt'</p> <p>(It'd ...
[ { "answer_id": 516486, "author": "Kenan Banks", "author_id": 43089, "author_profile": "https://Stackoverflow.com/users/43089", "pm_score": 4, "selected": true, "text": "<p>Key concept here is backreferences in regular expressions:</p>\n\n<pre><code>import re\ntext = \"ThisFileName.txt\"\...
2009/02/05
[ "https://Stackoverflow.com/questions/516451", "https://Stackoverflow.com", "https://Stackoverflow.com/users/681/" ]
I'm trying to add a space before every capital letter, except the first one. Here's what I have so far, and the output I'm getting: ``` >>> tex = "ThisFileName.txt" >>> re.sub('[A-Z].', ' ', tex) ' his ile ame.txt' ``` I want: 'This File Name.txt' (It'd be nice if I could also get rid of .txt, but I can do that i...
Key concept here is backreferences in regular expressions: ``` import re text = "ThisFileName.txt" print re.sub('([a-z])([A-Z])', r'\1 \2', text) # Prints: "This File Name.txt" ``` For pulling off the '.txt' in a reliable way, I recommend `os.path.splitext()` ``` import os filename = "ThisFileName.txt" print os.pat...
516,453
<p>I'm working on a web project that will (hopefully) be available in several languages one day (I say "hopefully" because while we only have an English language site planned today, other products of my company are multilingual and I am hoping we are successful enough to need that too).</p> <p>I understand that the be...
[ { "answer_id": 516576, "author": "Ryan Doherty", "author_id": 956, "author_profile": "https://Stackoverflow.com/users/956", "pm_score": 2, "selected": false, "text": "<p>First off, <strong>don't</strong> split up your strings. This makes it much harder for localizers to translate text be...
2009/02/05
[ "https://Stackoverflow.com/questions/516453", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4249/" ]
I'm working on a web project that will (hopefully) be available in several languages one day (I say "hopefully" because while we only have an English language site planned today, other products of my company are multilingual and I am hoping we are successful enough to need that too). I understand that the best practic...
Typically if you use a template engine such as [Sitemesh](http://www.opensymphony.com/sitemesh/) or [Velocity](http://velocity.apache.org/tools/devel) you can manage these smaller HTML building blocks as subtemplates more effectively. By so doing, you can incrementally boil down the strings which are the purely intern...
516,463
<p>Given the following class definitions:</p> <pre><code>public class BaseClass { public string SomeProp1 { get; set; } } public class DerivedClass : BaseClass { public string SomeProp2 { get; set; } } </code></pre> <p>How can I take a <code>List&lt;BaseClass&gt;</code> and convert it to a <code>List&lt;Deri...
[ { "answer_id": 516475, "author": "Peter Morris", "author_id": 61311, "author_profile": "https://Stackoverflow.com/users/61311", "pm_score": 6, "selected": true, "text": "<pre><code>List&lt;DerivedClass&gt; result = \n listBaseClass.ConvertAll(instance =&gt; (DerivedClass)instance);\n<...
2009/02/05
[ "https://Stackoverflow.com/questions/516463", "https://Stackoverflow.com", "https://Stackoverflow.com/users/39709/" ]
Given the following class definitions: ``` public class BaseClass { public string SomeProp1 { get; set; } } public class DerivedClass : BaseClass { public string SomeProp2 { get; set; } } ``` How can I take a `List<BaseClass>` and convert it to a `List<DerivedClass>`? In my real-world scenario `BaseClass` ...
``` List<DerivedClass> result = listBaseClass.ConvertAll(instance => (DerivedClass)instance); ``` Actually ConvertAll is good when you need to create new objects based on the original, when you just need to cast you can use the following ``` List<DerivedClass> result = listBaseClass.Cast<DerivedClass>().To...
516,469
<p>We are developing a web application that will be sold to many clients. There is already one client (a bank) which has decided that it will buy the product once it is ready. Unfortunately due to some miscommunication it came out rather late that the only browser they use is IE6. The application was already started wi...
[ { "answer_id": 516511, "author": "Luca Matteis", "author_id": 50394, "author_profile": "https://Stackoverflow.com/users/50394", "pm_score": 4, "selected": true, "text": "<p><a href=\"https://developer.yahoo.com/blogs/ydn/high-performance-sites-rule-7-avoid-css-expressions-7202.html\" rel...
2009/02/05
[ "https://Stackoverflow.com/questions/516469", "https://Stackoverflow.com", "https://Stackoverflow.com/users/41360/" ]
We are developing a web application that will be sold to many clients. There is already one client (a bank) which has decided that it will buy the product once it is ready. Unfortunately due to some miscommunication it came out rather late that the only browser they use is IE6. The application was already started with ...
<https://developer.yahoo.com/blogs/ydn/high-performance-sites-rule-7-avoid-css-expressions-7202.html> Turns out you might want to avoid using these, they are dangerous.
516,481
<p>I need to regularly send a collection of log files that can grow quite large, so I would like to only send the last <em>n</em> lines of the each of the files. </p> <p>for example:</p> <pre><code>/usr/local/data_store1/file.txt (500 lines) /usr/local/data_store2/file.txt (800 lines) </code></pre> <p>Given a file w...
[ { "answer_id": 516510, "author": "Johannes Weiss", "author_id": 55925, "author_profile": "https://Stackoverflow.com/users/55925", "pm_score": 1, "selected": false, "text": "<p>You could try</p>\n\n<pre><code>tail -n 10 your_file.txt | while read line; do zip /tmp/a.zip $line; done\n</cod...
2009/02/05
[ "https://Stackoverflow.com/questions/516481", "https://Stackoverflow.com", "https://Stackoverflow.com/users/50924/" ]
I need to regularly send a collection of log files that can grow quite large, so I would like to only send the last *n* lines of the each of the files. for example: ``` /usr/local/data_store1/file.txt (500 lines) /usr/local/data_store2/file.txt (800 lines) ``` Given a file with a list of needed files named `files....
You could try ``` tail -n 10 your_file.txt | while read line; do zip /tmp/a.zip $line; done ``` where `a.zip` is the zip file and 10 is `n` or ``` tail -n 10 your_file.txt | xargs tar -czvf test.tar.gz -- ``` for tar.gz
516,494
<p>Is it possible to create a cursor from an image and have it be semi-transparent? </p> <p>I'm currently taking a custom image and overylaying the mouse cursor image. It would be great if I could make this semi-transparent, but not necessary. The sales guys love shiny.</p> <p>Currently doing something like this:</p>...
[ { "answer_id": 1381681, "author": "Daniel Mošmondor", "author_id": 166251, "author_profile": "https://Stackoverflow.com/users/166251", "pm_score": 0, "selected": false, "text": "<p>On the top of my head (I would try that first):</p>\n\n<ol>\n<li>create new bitmap with same size as origin...
2009/02/05
[ "https://Stackoverflow.com/questions/516494", "https://Stackoverflow.com", "https://Stackoverflow.com/users/54617/" ]
Is it possible to create a cursor from an image and have it be semi-transparent? I'm currently taking a custom image and overylaying the mouse cursor image. It would be great if I could make this semi-transparent, but not necessary. The sales guys love shiny. Currently doing something like this: ``` Image cursorIma...
I've tried following example, and it was working fine... ``` public struct IconInfo { public bool fIcon; public int xHotspot; public int yHotspot; public IntPtr hbmMask; public IntPtr hbmColor; } [DllImport("user32.dll")] [return: MarshalAs(UnmanagedType.Boo...
516,500
<p>I find that I frequently end up writing a function that I always call "<code>clamp()</code>", that is kind of a combination of <code>min()</code> and <code>max()</code>. Is there a standard, "canonical" name for this function?</p> <p>It always looks something like this:</p> <pre><code>function clamp($val, $lower,...
[ { "answer_id": 516515, "author": "tehvan", "author_id": 61848, "author_profile": "https://Stackoverflow.com/users/61848", "pm_score": 0, "selected": false, "text": "<p>I'd just go for a function name \"rangeCheck\"</p>\n" }, { "answer_id": 516526, "author": "Niyaz", "auth...
2009/02/05
[ "https://Stackoverflow.com/questions/516500", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18511/" ]
I find that I frequently end up writing a function that I always call "`clamp()`", that is kind of a combination of `min()` and `max()`. Is there a standard, "canonical" name for this function? It always looks something like this: ``` function clamp($val, $lower, $upper) { if ($val < $lower) return $lower; el...
**clamp** is a good name. Let us make it the standard.
516,501
<p>I realize there's a way in Vim to hide/fold lines, but what I'm looking for is a way to select a block of text and have Vim wrap lines at or near column 80. </p> <p>Mostly I want to use this on comments in situations where I'm adding some text to an existing comment that pushes it over 80 characters. It would als...
[ { "answer_id": 516536, "author": "Philip Reynolds", "author_id": 1087, "author_profile": "https://Stackoverflow.com/users/1087", "pm_score": 5, "selected": true, "text": "<pre><code>gq\n</code></pre>\n\n<p>It's controlled by the textwidth option, see <code>\":help gq\"</code> for more in...
2009/02/05
[ "https://Stackoverflow.com/questions/516501", "https://Stackoverflow.com", "https://Stackoverflow.com/users/48837/" ]
I realize there's a way in Vim to hide/fold lines, but what I'm looking for is a way to select a block of text and have Vim wrap lines at or near column 80. Mostly I want to use this on comments in situations where I'm adding some text to an existing comment that pushes it over 80 characters. It would also be nice if...
``` gq ``` It's controlled by the textwidth option, see `":help gq"` for more info. `gq` will work on the current line by default, but you can highlight a visual block with `Ctrl`+`V` and format multiple lines / paragraphs like that. `gqap` does the current "paragraph" of text.
516,508
<p>I am working on a C# project which must be built for more than one platform (.Net and CF.Net) and from past experiences I have found that the best approach that works for me is to have multiple parallel solutions present side by side in the same folder corresponding to each platform. All the code files, resources et...
[ { "answer_id": 516536, "author": "Philip Reynolds", "author_id": 1087, "author_profile": "https://Stackoverflow.com/users/1087", "pm_score": 5, "selected": true, "text": "<pre><code>gq\n</code></pre>\n\n<p>It's controlled by the textwidth option, see <code>\":help gq\"</code> for more in...
2009/02/05
[ "https://Stackoverflow.com/questions/516508", "https://Stackoverflow.com", "https://Stackoverflow.com/users/39648/" ]
I am working on a C# project which must be built for more than one platform (.Net and CF.Net) and from past experiences I have found that the best approach that works for me is to have multiple parallel solutions present side by side in the same folder corresponding to each platform. All the code files, resources etc a...
``` gq ``` It's controlled by the textwidth option, see `":help gq"` for more info. `gq` will work on the current line by default, but you can highlight a visual block with `Ctrl`+`V` and format multiple lines / paragraphs like that. `gqap` does the current "paragraph" of text.
516,521
<p>I've moved a WebBBS board from one server to another. Ever since the board doesn't work. I'm getting an Apache error whenever I try to access the board. Don't even know where to start the debugging, I'm not a Perl person. The file paths remained the same and there isn't any DB involved.</p> <p><a href="http://gammo...
[ { "answer_id": 516566, "author": "Andrew Taylor", "author_id": 1776, "author_profile": "https://Stackoverflow.com/users/1776", "pm_score": 1, "selected": false, "text": "<p>This is caused by Apache config errors. Set LogLevel debug and tail -f the error log. It will probably be something...
2009/02/05
[ "https://Stackoverflow.com/questions/516521", "https://Stackoverflow.com", "https://Stackoverflow.com/users/59361/" ]
I've moved a WebBBS board from one server to another. Ever since the board doesn't work. I'm getting an Apache error whenever I try to access the board. Don't even know where to start the debugging, I'm not a Perl person. The file paths remained the same and there isn't any DB involved. <http://gammonline.com/members/...
> > More information about this error may be available in the server error log. > > > Says it all. You will have to find the error log and look at it. If you are using CGI, the first step is to check you have given it the right permissions so it is an executable script at all. ``` chmod 755 index.cgi ```
516,542
<p>I'm trying to integrate Redmine with TortoiseSVN, but I was not able to do that because TSVN always gives me this error:</p> <blockquote> <p>"There are no issue-tracker providers available."</p> </blockquote> <p>I followed these steps:</p> <ul> <li>In my project folder properties, I added 'bugtraq:url -> <code>...
[ { "answer_id": 516904, "author": "Stefan", "author_id": 48003, "author_profile": "https://Stackoverflow.com/users/48003", "pm_score": 3, "selected": false, "text": "<p>Please read the <a href=\"http://tortoisesvn.net/docs/release/TortoiseSVN_en/tsvn-dug-bugtracker.html\" rel=\"noreferrer...
2009/02/05
[ "https://Stackoverflow.com/questions/516542", "https://Stackoverflow.com", "https://Stackoverflow.com/users/24462/" ]
I'm trying to integrate Redmine with TortoiseSVN, but I was not able to do that because TSVN always gives me this error: > > "There are no issue-tracker providers available." > > > I followed these steps: * In my project folder properties, I added 'bugtraq:url -> `http://myweb/../issues/show/%BUGID%`' * In Redmi...
Slightly more detail on Stefan's post: With what you're trying to do, setting the bugtraq:url alone isn't enough. You need to either set the 'bugtraq:message' property or the 'bugtraq:logregex' property as well. As an example, on our redmine setup we allow the following items in the commit message: * **References**: ...
516,549
<h2>The Back Story</h2> <p>I have some decimal values which I am displaying as strings on a web page as part of a larger string. I started off using a Standard Numeric Format String to output this. E.g.</p> <pre><code>myDecimal.ToString("P0") </code></pre> <p>The <code>0</code> after the <code>P</code> tells it I wa...
[ { "answer_id": 516648, "author": "Aleris", "author_id": 20417, "author_profile": "https://Stackoverflow.com/users/20417", "pm_score": 4, "selected": true, "text": "<p>Looking at <a href=\"http://www.nasdaq.com/\" rel=\"noreferrer\">http://www.nasdaq.com/</a> or <a href=\"http://finance.y...
2009/02/05
[ "https://Stackoverflow.com/questions/516549", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16005/" ]
The Back Story -------------- I have some decimal values which I am displaying as strings on a web page as part of a larger string. I started off using a Standard Numeric Format String to output this. E.g. ``` myDecimal.ToString("P0") ``` The `0` after the `P` tells it I want no decimal places. This works as far as...
Looking at <http://www.nasdaq.com/> or <http://finance.yahoo.com/> it seems that the percentage sign right after the number with no space inbetween is common :) Have a look at <http://msdn.microsoft.com/en-us/library/system.globalization.numberformatinfo.percentpositivepattern.aspx> It probably depends on culture, th...
516,565
<p>I have a list of strings on my server which I am trying to get to the client in the form of an array. The code I am attempting to use is the following:</p> <p>Within the jsp I have a <code>List&lt;String&gt;</code> column</p> <p>I am attempting the following code:</p> <pre><code>&lt;%int j = 0; %&gt; for(var i = ...
[ { "answer_id": 516612, "author": "Michael Borgwardt", "author_id": 16883, "author_profile": "https://Stackoverflow.com/users/16883", "pm_score": 5, "selected": true, "text": "<p>You're getting the JSP code that is executed on the server mixed up with the JavaScript code that's executed o...
2009/02/05
[ "https://Stackoverflow.com/questions/516565", "https://Stackoverflow.com", "https://Stackoverflow.com/users/62610/" ]
I have a list of strings on my server which I am trying to get to the client in the form of an array. The code I am attempting to use is the following: Within the jsp I have a `List<String>` column I am attempting the following code: ``` <%int j = 0; %> for(var i = 0; i < <%=columns.size()%>; i++) { colArray[i] = ...
You're getting the JSP code that is executed on the server mixed up with the JavaScript code that's executed on the client. The snippet `<%=columns.get(j++)%>` is executed once, on the server, and the JavaScript loop around it is irrelevant at this point. When it arrives the the client, the loop's body just says `colAr...
516,569
<pre><code>public delegate T GetObject&lt;T&gt;(SqlDataReader reader); public delegate KeyValuePair&lt;TKey, TValue&gt; GetObject&lt;TKey, TValue&gt;(SqlDataReader reader); </code></pre> <p>Is it possible for removing that 2nd line (the two lines are on consecutive lines) to ever make any difference at all, superficia...
[ { "answer_id": 516612, "author": "Michael Borgwardt", "author_id": 16883, "author_profile": "https://Stackoverflow.com/users/16883", "pm_score": 5, "selected": true, "text": "<p>You're getting the JSP code that is executed on the server mixed up with the JavaScript code that's executed o...
2009/02/05
[ "https://Stackoverflow.com/questions/516569", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18192/" ]
``` public delegate T GetObject<T>(SqlDataReader reader); public delegate KeyValuePair<TKey, TValue> GetObject<TKey, TValue>(SqlDataReader reader); ``` Is it possible for removing that 2nd line (the two lines are on consecutive lines) to ever make any difference at all, superficial or not?
You're getting the JSP code that is executed on the server mixed up with the JavaScript code that's executed on the client. The snippet `<%=columns.get(j++)%>` is executed once, on the server, and the JavaScript loop around it is irrelevant at this point. When it arrives the the client, the loop's body just says `colAr...
516,571
<p>The SWT-Gui looks very nice. Is there an easy way to use it in Jython ?</p>
[ { "answer_id": 516663, "author": "Torsten Marek", "author_id": 9567, "author_profile": "https://Stackoverflow.com/users/9567", "pm_score": 5, "selected": true, "text": "<p>Given that you can use all Java classes from within Jython, it is also possible to use SWT.</p>\n\n<p>For the exampl...
2009/02/05
[ "https://Stackoverflow.com/questions/516571", "https://Stackoverflow.com", "https://Stackoverflow.com/users/62943/" ]
The SWT-Gui looks very nice. Is there an easy way to use it in Jython ?
Given that you can use all Java classes from within Jython, it is also possible to use SWT. For the example, adapted from an [SWT snippet](http://dev.eclipse.org/viewcvs/index.cgi/org.eclipse.swt.snippets/src/org/eclipse/swt/snippets/Snippet63.java?view=co), make sure you have the SWT jar on your CLASSPATH: ``` impor...
516,574
<p>I'm working with a large set of points represented by latitude/longitude pairs (the points are not necessarily unique, there could be several points in the set that are at the same location). The points are stored in a database.</p> <p>What I need to do is figure out a way to efficiently perform a search to get the...
[ { "answer_id": 516597, "author": "starblue", "author_id": 49246, "author_profile": "https://Stackoverflow.com/users/49246", "pm_score": 2, "selected": false, "text": "<p>Use some kind of search tree for spatial data, e.g. a <a href=\"http://en.wikipedia.org/wiki/Quadtree\" rel=\"nofollow...
2009/02/05
[ "https://Stackoverflow.com/questions/516574", "https://Stackoverflow.com", "https://Stackoverflow.com/users/59438/" ]
I'm working with a large set of points represented by latitude/longitude pairs (the points are not necessarily unique, there could be several points in the set that are at the same location). The points are stored in a database. What I need to do is figure out a way to efficiently perform a search to get the number of...
***I don't think you should use this solution. Having randomly thought about it a few days ago, I think that measuring the distance from a specific point the grid squares' locations will be based on circles rather than a uniformed grid. The further away from 0,0 you are the less accurate this will be!*** What I did wa...
516,579
<p>Is there a way that you can get a collection of all of the Models in your Rails app?</p> <p>Basically, can I do the likes of: -</p> <pre><code>Models.each do |model| puts model.class.name end </code></pre>
[ { "answer_id": 516605, "author": "Vincent Robert", "author_id": 268, "author_profile": "https://Stackoverflow.com/users/268", "pm_score": 8, "selected": true, "text": "<p><strong>EDIT: Look at the comments and other answers. There are smarter answers than this one! Or try to improve this...
2009/02/05
[ "https://Stackoverflow.com/questions/516579", "https://Stackoverflow.com", "https://Stackoverflow.com/users/22687/" ]
Is there a way that you can get a collection of all of the Models in your Rails app? Basically, can I do the likes of: - ``` Models.each do |model| puts model.class.name end ```
**EDIT: Look at the comments and other answers. There are smarter answers than this one! Or try to improve this one as community wiki.** Models do not register themselves to a master object, so no, Rails does not have the list of models. But you could still look in the content of the models directory of your applicat...
516,586
<pre><code>@search_results = Array.new duplicates = Set.new results.each { |result| @search_results.push(result) unless duplicates.add?(result[:url]) } </code></pre> <p>This piece of code is garbling the order of elements in the array @search_results. Why would inserting the same element in a set and an array chang...
[ { "answer_id": 516979, "author": "Lolindrath", "author_id": 7985, "author_profile": "https://Stackoverflow.com/users/7985", "pm_score": 3, "selected": true, "text": "<p>The order of elements in a Hash is not guaranteed. You'll have to sort the keys if you want a guaranteed order.</p>\n\n...
2009/02/05
[ "https://Stackoverflow.com/questions/516586", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17494/" ]
``` @search_results = Array.new duplicates = Set.new results.each { |result| @search_results.push(result) unless duplicates.add?(result[:url]) } ``` This piece of code is garbling the order of elements in the array @search\_results. Why would inserting the same element in a set and an array change the insertion or...
The order of elements in a Hash is not guaranteed. You'll have to sort the keys if you want a guaranteed order. This is supposedly fixed in Ruby 1.9 I believe. **Edit:** I'm assuming your results in an Array, if its a Hash then order isn't guaranteed and you'll have to sort the keys, here's what my test looks like: ...
516,593
<p>can you increment a hex value in Java? i.e. "hex value" = "hex value"++</p>
[ { "answer_id": 516602, "author": "Joachim Sauer", "author_id": 40342, "author_profile": "https://Stackoverflow.com/users/40342", "pm_score": 3, "selected": false, "text": "<p>What do you mean with \"hex value\"? In what data type is your value stored?</p>\n\n<p>Note that int/short/char/....
2009/02/05
[ "https://Stackoverflow.com/questions/516593", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
can you increment a hex value in Java? i.e. "hex value" = "hex value"++
It depends how the hex value is stored. If you've got the hex value in a string, convert it to an Integer, increment and convert it back. ``` int value = Integer.parseInt(hex, 16); value++; String incHex = Integer.toHexString(value); ```
516,609
<p>I have a simplified ajay script, from which I have removed all nonrelevant code. The problem I am having is first with my columns array and the subsequent foreach loop. I want to go through each element and change the corresponding element to YES if true and NO if false, I don't see why it isn't working.</p> <p>If ...
[ { "answer_id": 516652, "author": "Greg", "author_id": 24181, "author_profile": "https://Stackoverflow.com/users/24181", "pm_score": 0, "selected": false, "text": "<p><code>$columns[$column]</code> doesn't exist - I can't imagine what you're trying to do, but that's a mistake.</p>\n" },...
2009/02/05
[ "https://Stackoverflow.com/questions/516609", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1246613/" ]
I have a simplified ajay script, from which I have removed all nonrelevant code. The problem I am having is first with my columns array and the subsequent foreach loop. I want to go through each element and change the corresponding element to YES if true and NO if false, I don't see why it isn't working. If there are ...
Your loop is wrong - $columns['EGGS'] doesn't exist: ``` $columns = array('EGGS', 'SALAD', 'TREES', 'REVISED'); foreach($columns as $column) { $$column = $columns[$column] ? 'YES' : 'NO'; } ``` it should be: ``` $columns = array('EGGS', 'SALAD', 'TREES', 'REVISED'); foreach($columns as $column) { $$column =...
516,615
<p>How do you deal with validation on complex aggregates in a domain driven design? Are you consolidating your business rules/validation logic?</p> <p>I understand argument validation and I understand property validation which can be attached to the models themselves and do things like check that an email address or zi...
[ { "answer_id": 522454, "author": "thinkbeforecoding", "author_id": 47001, "author_profile": "https://Stackoverflow.com/users/47001", "pm_score": 3, "selected": false, "text": "<p>I usualy use a specification class,\nit provides a method (this is C# but you can translate it in any languag...
2009/02/05
[ "https://Stackoverflow.com/questions/516615", "https://Stackoverflow.com", "https://Stackoverflow.com/users/31624/" ]
How do you deal with validation on complex aggregates in a domain driven design? Are you consolidating your business rules/validation logic? I understand argument validation and I understand property validation which can be attached to the models themselves and do things like check that an email address or zipcode is ...
I like Jimmy Bogard's solution to this problem. He has a post on his blog titled ["Entity validation with visitors and extension methods"](http://www.lostechies.com/blogs/jimmy_bogard/archive/2007/10/24/entity-validation-with-visitors-and-extension-methods.aspx) in which he presents a very elegant approach to entity va...
516,637
<p>When accessing values from an <strong>SqlDataReader</strong> is there a performance difference between these two:</p> <pre><code>string key = reader.GetString("Key"); </code></pre> <p>or</p> <pre><code>string key = reader["Key"].ToString(); </code></pre> <p>In this code sample:</p> <pre><code>string key; using...
[ { "answer_id": 516655, "author": "Jon Skeet", "author_id": 22656, "author_profile": "https://Stackoverflow.com/users/22656", "pm_score": 1, "selected": false, "text": "<p>Even if there is, it's unlikely to be significant in the slightest compared with the cost of getting the data from th...
2009/02/05
[ "https://Stackoverflow.com/questions/516637", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19471/" ]
When accessing values from an **SqlDataReader** is there a performance difference between these two: ``` string key = reader.GetString("Key"); ``` or ``` string key = reader["Key"].ToString(); ``` In this code sample: ``` string key; using (SqlDataReader reader = cmd.ExecuteReader()) { while (reader.Read())...
I’ve just peeked into the .NET source code, and the two access methods are essentially the same. The only difference is that the second does an additional boxing. So the first one corresponds to something like (in case of elementary types): ``` int key = GetInternalSQLDataAsInt32("Key"); ``` while the second one wou...
516,646
<p>I want to create light object data-package to pass between client and server applications.</p> <p>It is a so simple task, that I can control with only 1 byte, so each bit in a byte will have a different meaning, </p> <p>Using only the bit</p> <pre><code>0 = False 1 = True </code></pre> <p>Itens I need now:</p> ...
[ { "answer_id": 516693, "author": "Scott W", "author_id": 3032, "author_profile": "https://Stackoverflow.com/users/3032", "pm_score": 1, "selected": false, "text": "<p><a href=\"http://library.thinkquest.org/C006657/delphi/operators_in_delphi.htm\" rel=\"nofollow noreferrer\">This page</a...
2009/02/05
[ "https://Stackoverflow.com/questions/516646", "https://Stackoverflow.com", "https://Stackoverflow.com/users/36875/" ]
I want to create light object data-package to pass between client and server applications. It is a so simple task, that I can control with only 1 byte, so each bit in a byte will have a different meaning, Using only the bit ``` 0 = False 1 = True ``` Itens I need now: ``` 1 - Loaded from database 2 - Persisted...
I'd really use a set for this. However, I see you really want a byte. Use sets everywhere then typecast to a byte in the end. This solution will require much less typing, has support for standard delphi operators and really carries no performance penalty as Barry Kelly has pointed out. ``` procedure Test; type TSet...
516,657
<p>I have a year 2009, a month 11 and a day 12. All of these are being passed to me as integers. What I want to do is create a date from these. I want to use these as part of my where statement.</p> <p>What is the best way to do it from either a clean code and most importantly a speed point of view?</p> <p>I personal...
[ { "answer_id": 516667, "author": "HLGEM", "author_id": 9034, "author_profile": "https://Stackoverflow.com/users/9034", "pm_score": 0, "selected": false, "text": "<p>Are you talking about combining them to store in a database or you have them stored that way and want to combine them in a ...
2009/02/05
[ "https://Stackoverflow.com/questions/516657", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3168/" ]
I have a year 2009, a month 11 and a day 12. All of these are being passed to me as integers. What I want to do is create a date from these. I want to use these as part of my where statement. What is the best way to do it from either a clean code and most importantly a speed point of view? I personally am using MS SQ...
Assuming that your `INT`s are called `@d`, `@m` and `@y`: ``` DATEADD(month, ((@y - 1900) * 12) + @m - 1, @d - 1) ``` **EDIT** Please note that this technique isn't "canonical" in any way, it relies on manipulating SQL Server's implementation of `DATETIME`. If you pass invalid values for `@d`, `@m` or `@y` then yo...
516,662
<p>I have a map defined like this</p> <pre><code>std::map&lt;some_key_type, std::string::iterator&gt; mIteratorMap; </code></pre> <p>And a huge string named "mHugeString". Then I walk trough the string collecting iterators like this:</p> <pre><code>std::string::iterator It=mHugeString.begin(); std::string::iterator ...
[ { "answer_id": 516690, "author": "ChrisW", "author_id": 49942, "author_profile": "https://Stackoverflow.com/users/49942", "pm_score": 3, "selected": true, "text": "<p>I haven't tried it but I would have expected that, of course you <strong>can</strong> store iterator values as values in ...
2009/02/05
[ "https://Stackoverflow.com/questions/516662", "https://Stackoverflow.com", "https://Stackoverflow.com/users/25459/" ]
I have a map defined like this ``` std::map<some_key_type, std::string::iterator> mIteratorMap; ``` And a huge string named "mHugeString". Then I walk trough the string collecting iterators like this: ``` std::string::iterator It=mHugeString.begin(); std::string::iterator EndIt=mHugeString.end(); for(;It!=EndIt;++I...
I haven't tried it but I would have expected that, of course you **can** store iterator values as values in a map. Do you know that if you change the contents of `mHugeString` then any iterators into it which you have previously stored are now invalid? You might choose to store the index into the string, instead of t...
516,689
<p>I have a base class which is non-generic with a derived generic class. The AbstractRepository and ILoggingManager are provided by the IoC framework.</p> <p><strong>Base Class</strong></p> <pre><code>public abstract class EventHandlerBase : AbstractDataProvider , IEventHandler { public EventHandlerBase(...
[ { "answer_id": 516699, "author": "ChrisW", "author_id": 49942, "author_profile": "https://Stackoverflow.com/users/49942", "pm_score": 2, "selected": false, "text": "<p>Dynamic linking is a kind of self-modification (patching absolute and/or relative jump locations) ... that's normally do...
2009/02/05
[ "https://Stackoverflow.com/questions/516689", "https://Stackoverflow.com", "https://Stackoverflow.com/users/62951/" ]
I have a base class which is non-generic with a derived generic class. The AbstractRepository and ILoggingManager are provided by the IoC framework. **Base Class** ``` public abstract class EventHandlerBase : AbstractDataProvider , IEventHandler { public EventHandlerBase( AbstractRepository data, ...
Turns out that the Wikipedia entry on "[self-modifying code](http://en.wikipedia.org/wiki/Self-modifying_code)" has a great list: > > 1. **Semi-automatic optimization** of a state dependent loop. > 2. **Runtime code generation**, or specialization of an algorithm in > runtime or loadtime (which is popular, > for ex...
516,704
<p>I have built a simple Eclipse plugin where a user may use a <code>TableViewer</code> of database resources to open an editor on any of those resources. </p> <p>Users may therefore have zero upwards instances of the editor running.</p> <p>Is there an API available to get a list of those editor instances?</p>
[ { "answer_id": 516766, "author": "Fabian Steeg", "author_id": 18154, "author_profile": "https://Stackoverflow.com/users/18154", "pm_score": 4, "selected": true, "text": "<p>You can get references to all open editors with:</p>\n\n<pre><code>PlatformUI.getWorkbench().getActiveWorkbenchWind...
2009/02/05
[ "https://Stackoverflow.com/questions/516704", "https://Stackoverflow.com", "https://Stackoverflow.com/users/42429/" ]
I have built a simple Eclipse plugin where a user may use a `TableViewer` of database resources to open an editor on any of those resources. Users may therefore have zero upwards instances of the editor running. Is there an API available to get a list of those editor instances?
You can get references to all open editors with: ``` PlatformUI.getWorkbench().getActiveWorkbenchWindow() .getActivePage().getEditorReferences(); ``` And then check these to select the ones that reference instances of your editor type.
516,754
<p>I have a JSON result that contains numerous records. I'd like to show the first one, but have a next button to view the second, and so on. I don't want the page to refresh which is why I'm hoping a combination of JavaScript, jQuery, and even a third party AJAX library can help.</p> <p>Any suggestions?</p>
[ { "answer_id": 516799, "author": "Clinton Pierce", "author_id": 8173, "author_profile": "https://Stackoverflow.com/users/8173", "pm_score": 2, "selected": false, "text": "<p>I use jqgrid for just this purpose. Works like a charm.</p>\n\n<p><a href=\"http://www.trirand.com/blog/\" rel=\"...
2009/02/05
[ "https://Stackoverflow.com/questions/516754", "https://Stackoverflow.com", "https://Stackoverflow.com/users/21318/" ]
I have a JSON result that contains numerous records. I'd like to show the first one, but have a next button to view the second, and so on. I don't want the page to refresh which is why I'm hoping a combination of JavaScript, jQuery, and even a third party AJAX library can help. Any suggestions?
Hope this helps: ``` var noName = { data: null ,currentIndex : 0 ,init: function(data) { this.data = data; this.show(this.data.length - 1); // show last } ,show: function(index) { var jsonObj = this.data[index]; if(!jsonObj) { alert("No more data"); ...
516,763
<p>We've got some old serial code which checks whether a serial port is available simply by opening it and then closing it. Now we are adding network support to the app I want to reuse the function by supplying the ip address as a string.</p> <pre><code>/** * So far I have tried: * A passed in portPath normally look...
[ { "answer_id": 517448, "author": "Nick", "author_id": 26240, "author_profile": "https://Stackoverflow.com/users/26240", "pm_score": 0, "selected": false, "text": "<p>I don't believe you can manipulate sockets with <code>CreateFile()</code>. Sockets are an abstraction imported from BSD (i...
2009/02/05
[ "https://Stackoverflow.com/questions/516763", "https://Stackoverflow.com", "https://Stackoverflow.com/users/342/" ]
We've got some old serial code which checks whether a serial port is available simply by opening it and then closing it. Now we are adding network support to the app I want to reuse the function by supplying the ip address as a string. ``` /** * So far I have tried: * A passed in portPath normally looks like: \\?\ac...
You can not create a socket via CreateFile. You should use the windows [socket API](http://msdn.microsoft.com/en-us/library/ms741394(VS.85).aspx) for this purpose. For creating the SOCKET handle, you use [WSASocket](http://msdn.microsoft.com/en-us/library/ms742212(VS.85).aspx). Note that the SOCKET returned by this fun...
516,768
<p>what about using "this" with methods in Java? Is it optional or there are situations when one needs to use it obligatory?</p> <p>The only situation I have encountered is when in the class you invoke a method within a method. But it is optional. Here is a silly example just to show what I mean:</p> <pre><code>publi...
[ { "answer_id": 516780, "author": "Yes - that Jake.", "author_id": 5287, "author_profile": "https://Stackoverflow.com/users/5287", "pm_score": 2, "selected": false, "text": "<p>I use \"this\" to clarify code, often as a hint that I'm calling an instance method rather than accessing a clas...
2009/02/05
[ "https://Stackoverflow.com/questions/516768", "https://Stackoverflow.com", "https://Stackoverflow.com/users/42155/" ]
what about using "this" with methods in Java? Is it optional or there are situations when one needs to use it obligatory? The only situation I have encountered is when in the class you invoke a method within a method. But it is optional. Here is a silly example just to show what I mean: ``` public class Test { S...
Three obvious situations where you need it: * Calling another constructor in the same class as the first part of your constructor * Differentiating between a local variable and an instance variable (whether in the constructor or any other method) * Passing a reference to the current object to another method Here's an...
516,771
<p>I have a standalone enum type defined, something like this:</p> <pre><code>package my.pkg.types; public enum MyEnumType { TYPE1, TYPE2 } </code></pre> <p>Now, I want to inject a value of that type into a bean property:</p> <pre class="lang-xml prettyprint-override"><code>&lt;bean name="someName" class="m...
[ { "answer_id": 516899, "author": "krosenvold", "author_id": 23691, "author_profile": "https://Stackoverflow.com/users/23691", "pm_score": 8, "selected": true, "text": "<p>Have you tried just \"TYPE1\"? I suppose Spring uses reflection to determine the type of \"type\" anyway, so the full...
2009/02/05
[ "https://Stackoverflow.com/questions/516771", "https://Stackoverflow.com", "https://Stackoverflow.com/users/35520/" ]
I have a standalone enum type defined, something like this: ``` package my.pkg.types; public enum MyEnumType { TYPE1, TYPE2 } ``` Now, I want to inject a value of that type into a bean property: ```xml <bean name="someName" class="my.pkg.classes"> <property name="type" value="my.pkg.types.MyEnumType.TYP...
Have you tried just "TYPE1"? I suppose Spring uses reflection to determine the type of "type" anyway, so the fully qualified name is redundant. Spring generally doesn't subscribe to redundancy!
516,776
<p>I have written a custom ErrorProvider which adds some functionality to the existing ErrorProvider (sets control BackColor, ErrorCount etc). This was working find but now for some reason it falls over on the constructor:</p> <pre><code>_LoginErrorProvider = New ErrorLogErrorProvider(Me.components) </code></pre> <p>...
[ { "answer_id": 516837, "author": "Simon", "author_id": 20048, "author_profile": "https://Stackoverflow.com/users/20048", "pm_score": 0, "selected": false, "text": "<p>Solved it, adding another component to the form seems to fix the problem, it's a bit of a cludge but works. I suppose the...
2009/02/05
[ "https://Stackoverflow.com/questions/516776", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20048/" ]
I have written a custom ErrorProvider which adds some functionality to the existing ErrorProvider (sets control BackColor, ErrorCount etc). This was working find but now for some reason it falls over on the constructor: ``` _LoginErrorProvider = New ErrorLogErrorProvider(Me.components) ``` The error is a NullReferen...
when you add a component to the design surface it adds this in the InitializeComponent function ``` me.components = new System.ComponentModel.Container() ``` so just add this in your self. or your ``` _LoginErrorProvider = New ErrorLogErrorProvider(Me.components) ``` is being called before InitializeComponent
516,778
<p>I'm using OpenGL in a QT application. At some point I'm rendering to a QGLPixelBuffer. I need to get the depth buffer of the image, what I'd normally accomplish with glReadPixels(..., GL_DEPTH_COMPONENT, ...); I tried making the QGLPixelBuffer current and then using glReadPixels() but all I get is a white image.</p>...
[ { "answer_id": 517381, "author": "Ketan", "author_id": 62056, "author_profile": "https://Stackoverflow.com/users/62056", "pm_score": 0, "selected": false, "text": "<p>I have never used QImage directly, but I would try to answer or look into following areas:</p>\n\n<ol>\n<li>Are you calli...
2009/02/05
[ "https://Stackoverflow.com/questions/516778", "https://Stackoverflow.com", "https://Stackoverflow.com/users/39301/" ]
I'm using OpenGL in a QT application. At some point I'm rendering to a QGLPixelBuffer. I need to get the depth buffer of the image, what I'd normally accomplish with glReadPixels(..., GL\_DEPTH\_COMPONENT, ...); I tried making the QGLPixelBuffer current and then using glReadPixels() but all I get is a white image. Her...
Well, there is no guarantee that the underlying pixel data stored in QImage (and obtained via its QImage::bits() function) is compatible to what OpenGL's glReadPixels() function writes. Since you are using QGLPixelBuffer, what is wrong with [QGLPixelBuffer::toImage()](http://doc.trolltech.com/4.5/qglpixelbuffer.html#t...
516,788
<p>Is there a method in C# that returns the UTC (GMT) time zone? Not based on the system's time.</p> <p>Basically I want to get the correct UTC time even if my system time is not right.</p>
[ { "answer_id": 516812, "author": "Jon Skeet", "author_id": 22656, "author_profile": "https://Stackoverflow.com/users/22656", "pm_score": 4, "selected": false, "text": "<p>Not based on the system's time? You'd need to make a call to a network time service or something similar. You could w...
2009/02/05
[ "https://Stackoverflow.com/questions/516788", "https://Stackoverflow.com", "https://Stackoverflow.com/users/62958/" ]
Is there a method in C# that returns the UTC (GMT) time zone? Not based on the system's time. Basically I want to get the correct UTC time even if my system time is not right.
Instead of calling ``` DateTime.Now.ToUniversalTime() ``` you can call ``` DateTime.UtcNow ``` Same thing but shorter :) Documentation [here](http://msdn.microsoft.com/en-us/library/system.datetime.utcnow.aspx).
516,794
<p>I am new to ADO.net. I actually created a sample database and a sample stored procedure. I am very new to this concept. I am not sure of how to make the connection to the database from a C# windows application. Please guide me with some help or sample to do the same.</p>
[ { "answer_id": 516815, "author": "Andrew Hare", "author_id": 34211, "author_profile": "https://Stackoverflow.com/users/34211", "pm_score": 2, "selected": false, "text": "<p>It sounds like you are looking for a tutorial on ADO.NET.</p>\n\n<p><a href=\"http://www.csharp-station.com/Tutoria...
2009/02/05
[ "https://Stackoverflow.com/questions/516794", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20951/" ]
I am new to ADO.net. I actually created a sample database and a sample stored procedure. I am very new to this concept. I am not sure of how to make the connection to the database from a C# windows application. Please guide me with some help or sample to do the same.
Something like this... (assuming you'll be passing in a Person object) ``` public int Insert(Person person) { SqlConnection conn = new SqlConnection(connStr); conn.Open(); SqlCommand dCmd = new SqlCommand("InsertData", conn); dCmd.CommandType = CommandType.StoredProcedure; try { dCmd.Parameters.AddWithValue("@firstNam...
516,798
<p>We are running a large project with several different languages: Java, Python, PHP, SQL and Perl. </p> <p>Until now people have been working in their own private repositories, but now we want to merge the entire project in a single repository. The question now is: how should the directory structure look? Should we ...
[ { "answer_id": 516827, "author": "Jared", "author_id": 44757, "author_profile": "https://Stackoverflow.com/users/44757", "pm_score": 4, "selected": true, "text": "<p>My experience indicates that this kind of layout is best:</p>\n\n<pre><code>mylib/\n src/\n java/\n python/...
2009/02/05
[ "https://Stackoverflow.com/questions/516798", "https://Stackoverflow.com", "https://Stackoverflow.com/users/51647/" ]
We are running a large project with several different languages: Java, Python, PHP, SQL and Perl. Until now people have been working in their own private repositories, but now we want to merge the entire project in a single repository. The question now is: how should the directory structure look? Should we have separ...
My experience indicates that this kind of layout is best: ``` mylib/ src/ java/ python/ perl/ .../ bin/ java/ python/ perl/ stage/ dist/ ``` `src` is your source, and is the only thing checked in. `bin` is where "compilation" occurs to during the buil...
516,820
<p>I don't know if my mind is not working today or if this is actually harder than I think it should be.</p> <p>I've got a DataGridView with a DataGridViewComboBoxColumn bound to a generic IList of CustomObjects. Here's a rough code sample of how I setup the column.</p> <pre><code>DataGridViewComboBoxColumn location...
[ { "answer_id": 516885, "author": "lc.", "author_id": 44853, "author_profile": "https://Stackoverflow.com/users/44853", "pm_score": 2, "selected": true, "text": "<p>You could use an <code>IList</code> of <code>KeyValuePair</code>s of \"Name\" and your custom object. The idea is you need <...
2009/02/05
[ "https://Stackoverflow.com/questions/516820", "https://Stackoverflow.com", "https://Stackoverflow.com/users/21807/" ]
I don't know if my mind is not working today or if this is actually harder than I think it should be. I've got a DataGridView with a DataGridViewComboBoxColumn bound to a generic IList of CustomObjects. Here's a rough code sample of how I setup the column. ``` DataGridViewComboBoxColumn location = new DataGridViewCom...
You could use an `IList` of `KeyValuePair`s of "Name" and your custom object. The idea is you need `ValueMember` to point to a reference of your object. I remember having similar issues for a while with `ComboBox`es. Something like the following ought to do the trick (off the top of my head and untested): ``` IList<K...
516,823
<p>What would be the safest way to include pages with $_GET without puttingt allowed pages in an array/use switch etc. I have many pages so no thank you.</p> <pre> $content = addslashes($_GET['content']); if (file_exists(PAGE_PATH."$content.html")) { include(PAGE_PATH."$content.html"); } </pre> <p>How safe is that?...
[ { "answer_id": 516840, "author": "FA.", "author_id": 33281, "author_profile": "https://Stackoverflow.com/users/33281", "pm_score": -1, "selected": false, "text": "<p>You should use at least something like that to prevent XSS attacks.</p>\n\n<pre><code>$content = htmlentities($_GET['page'...
2009/02/05
[ "https://Stackoverflow.com/questions/516823", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
What would be the safest way to include pages with $\_GET without puttingt allowed pages in an array/use switch etc. I have many pages so no thank you. ``` $content = addslashes($_GET['content']); if (file_exists(PAGE_PATH."$content.html")) { include(PAGE_PATH."$content.html"); } ``` How safe is that? Thanks.
You'll sleep safer if you check the input for a valid pattern. e.g. suppose you know the included files never have a subdirectory and are always alphanumeric ``` if (preg_match('/^[a-z0-9]+$/', $_GET['page'])) { $file=PAGE_PATH.$_GET['page'].".html"; if (file_exists($file)) { readfile($file); ...
516,829
<p><a href="https://stackoverflow.com/questions/352130/sql-reporting-services-restrict-export-formats">This question</a> asks how to restrict for a whole server. I just want to do so for a single report. I found a code snippet but it doesn't provide any clues on how to implement:</p> <pre><code> foreach (RenderingExte...
[ { "answer_id": 519967, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 2, "selected": true, "text": "<p>Incidentally I found <a href=\"http://mikemason.ca/blog/?p=4\" rel=\"nofollow noreferrer\">this blog entry</a> which clarifi...
2009/02/05
[ "https://Stackoverflow.com/questions/516829", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
[This question](https://stackoverflow.com/questions/352130/sql-reporting-services-restrict-export-formats) asks how to restrict for a whole server. I just want to do so for a single report. I found a code snippet but it doesn't provide any clues on how to implement: ``` foreach (RenderingExtension extension in this.r...
Incidentally I found [this blog entry](http://mikemason.ca/blog/?p=4) which clarifies the above code a little. Turns out we're talking about using a reportviewer component to limit the export options. Apparently this requires a dirty, dirty hack and besides it's not how we want to run our reporting function. So unless...
516,844
<p>Can someone give me 1 good reason why in C# the chained constructor is always called before any of the constructor body?</p> <p>.NET allows you to call the chained constructor at any point within the constructor, so why does C# force you to do it before your constructor body executes?</p> <p>I once wrote to Anders...
[ { "answer_id": 516881, "author": "ChrisW", "author_id": 49942, "author_profile": "https://Stackoverflow.com/users/49942", "pm_score": 0, "selected": false, "text": "<p>Since you say \"subjective\" I suppose you're not asking for the historical reason; so:</p>\n\n<ol>\n<li>This is how C++...
2009/02/05
[ "https://Stackoverflow.com/questions/516844", "https://Stackoverflow.com", "https://Stackoverflow.com/users/61311/" ]
Can someone give me 1 good reason why in C# the chained constructor is always called before any of the constructor body? .NET allows you to call the chained constructor at any point within the constructor, so why does C# force you to do it before your constructor body executes? I once wrote to Anders H and asked him ...
If there were a genuine reason why this ability should not be provided then it wouldn't be supported by the CLR or other .NET languages. I can only conclude that the answer is one of those "Because it's always been this way" ones, and the restriction was probably just copied from C++ or something.
516,849
<p>Premise: I've started to study javascript and the DOM and I have this HTML fragment:</p> <pre><code>&lt;body&gt; &lt;div id="Area_T10" class="abAdArea"&gt; &lt;script src="http://ad.dc2.adtech.de/addyn/3.0/831/***1644116***/0/744/ADTECH;" language="javascript1.1" type="text/javascript"&gt;&lt;/script&gt...
[ { "answer_id": 516880, "author": "Rob", "author_id": 3542, "author_profile": "https://Stackoverflow.com/users/3542", "pm_score": 0, "selected": false, "text": "<ul>\n<li>Extract the URL from the attribute using whichever DOM manipulation technique you prefer (perhaps a library)</li>\n<li...
2009/02/05
[ "https://Stackoverflow.com/questions/516849", "https://Stackoverflow.com", "https://Stackoverflow.com/users/56606/" ]
Premise: I've started to study javascript and the DOM and I have this HTML fragment: ``` <body> <div id="Area_T10" class="abAdArea"> <script src="http://ad.dc2.adtech.de/addyn/3.0/831/***1644116***/0/744/ADTECH;" language="javascript1.1" type="text/javascript"></script> <script> ** -- M...
I am assuming you want to extract the number from the script source URL. First step, get the script source value: ``` var src = document.getElementsByTagName('script')[0].src; ``` Then, if you're familiar with regular expressions, you should be able to create a pattern to extract that value.
516,862
<p>I have a file containing UNICODE-16 strings that I would like to read into a Linux program. The strings were written raw from Windows' internal WCHAR format. (Does Windows always use UTF-16? e.g. in Japanese versions)</p> <p>I believe that I can read them using raw reads and the converting with wcstombs_l. However,...
[ { "answer_id": 516908, "author": "Adam Rosenfield", "author_id": 9530, "author_profile": "https://Stackoverflow.com/users/9530", "pm_score": 1, "selected": false, "text": "<p>I would strongly recommend using a Unicode encoding as your program's internal representation. Use either UTF-16...
2009/02/05
[ "https://Stackoverflow.com/questions/516862", "https://Stackoverflow.com", "https://Stackoverflow.com/users/47078/" ]
I have a file containing UNICODE-16 strings that I would like to read into a Linux program. The strings were written raw from Windows' internal WCHAR format. (Does Windows always use UTF-16? e.g. in Japanese versions) I believe that I can read them using raw reads and the converting with wcstombs\_l. However, I cannot...
> > (Does Windows always use UTF-16? e.g. in Japanese versions) > > > Yes, NT's WCHAR is always UTF-16LE. (The ‘system codepage’, which for Japanese installs is indeed cp932/Shift-JIS, still exists in NT for the benefit of the many, many applications that aren't Unicode-native, FAT32 paths, and so on.) However, ...
516,863
<p>Suppose I have a variable "counter", and there are several threads accessing and setting the value of "counter" by using Interlocked, i.e.:</p> <pre><code>int value = Interlocked.Increment(ref counter); </code></pre> <p>and</p> <pre><code>int value = Interlocked.Decrement(ref counter); </code></pre> <p>Can I ass...
[ { "answer_id": 516868, "author": "Peter Morris", "author_id": 61311, "author_profile": "https://Stackoverflow.com/users/61311", "pm_score": 1, "selected": false, "text": "<p>Interlocked ensures that only 1 thread at a time can update the value. To ensure that other threads can read the ...
2009/02/05
[ "https://Stackoverflow.com/questions/516863", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2398110/" ]
Suppose I have a variable "counter", and there are several threads accessing and setting the value of "counter" by using Interlocked, i.e.: ``` int value = Interlocked.Increment(ref counter); ``` and ``` int value = Interlocked.Decrement(ref counter); ``` Can I assume that, the change made by Interlocked will be ...
InterlockedIncrement/Decrement on x86 CPUs (x86's lock add/dec) are automatically creating *memory barrier* which gives visibility to all threads (i.e., all threads can see its update as in-order, like sequential memory consistency). Memory barrier makes all pending memory loads/stores to be completed. `volatile` is no...
516,869
<p>I have a simple page that consists of a table with three <code>jQuery UI progressbars</code> and an ajax call. </p> <p>The ajax calls out to an empty php file and on success I destroy and recreate my progressbars. </p> <p>It seems simple but running it caused memory leaks in both <code>IE7</code> and <code>Chrom...
[ { "answer_id": 516868, "author": "Peter Morris", "author_id": 61311, "author_profile": "https://Stackoverflow.com/users/61311", "pm_score": 1, "selected": false, "text": "<p>Interlocked ensures that only 1 thread at a time can update the value. To ensure that other threads can read the ...
2009/02/05
[ "https://Stackoverflow.com/questions/516869", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I have a simple page that consists of a table with three `jQuery UI progressbars` and an ajax call. The ajax calls out to an empty php file and on success I destroy and recreate my progressbars. It seems simple but running it caused memory leaks in both `IE7` and `Chrome` (although Chrome handled it much more grace...
InterlockedIncrement/Decrement on x86 CPUs (x86's lock add/dec) are automatically creating *memory barrier* which gives visibility to all threads (i.e., all threads can see its update as in-order, like sequential memory consistency). Memory barrier makes all pending memory loads/stores to be completed. `volatile` is no...
516,873
<p>I'm using Linq2Entity for most of my database operations. However for database creation, table creation and initial data insertion I use plain SQL files. Therefore I need both an SqlConnection and an EntityConnection. Unfortunately the Entity Framework starts complaining that the Sql Server is not listening on the o...
[ { "answer_id": 517035, "author": "Craig Stuntz", "author_id": 7714, "author_profile": "https://Stackoverflow.com/users/7714", "pm_score": 1, "selected": false, "text": "<p>I don't agree that you need a plain SQL connection and Entity connection for this task, at least as you've described...
2009/02/05
[ "https://Stackoverflow.com/questions/516873", "https://Stackoverflow.com", "https://Stackoverflow.com/users/62857/" ]
I'm using Linq2Entity for most of my database operations. However for database creation, table creation and initial data insertion I use plain SQL files. Therefore I need both an SqlConnection and an EntityConnection. Unfortunately the Entity Framework starts complaining that the Sql Server is not listening on the othe...
Have you tried creating a SqlConnection which you then pass to the constructor for your EntityConnection? One of the overloads for EntityConnection takes a MetadataWorkspace and a DbConnection (from which SqlConnection derives.) The slight drawback of this is that you must create your MetadataWorkspace manually, which ...
516,879
<p>I'm trying to attach an entity in LINQ to SQL but it throws the following exceptionL: </p> <p><strong>An attempt has been made to Attach or Add an entity that is not new, perhaps having been loaded from another DataContext. This is not supported.</strong></p> <pre><code>&lt;Table Name="dbo.Products" Member="Produ...
[ { "answer_id": 516909, "author": "Jason Punyon", "author_id": 6212, "author_profile": "https://Stackoverflow.com/users/6212", "pm_score": 3, "selected": true, "text": "<p>You can attach an entity to a DataContext different from the one from which it was created only if it has been serial...
2009/02/05
[ "https://Stackoverflow.com/questions/516879", "https://Stackoverflow.com", "https://Stackoverflow.com/users/34623/" ]
I'm trying to attach an entity in LINQ to SQL but it throws the following exceptionL: **An attempt has been made to Attach or Add an entity that is not new, perhaps having been loaded from another DataContext. This is not supported.** ``` <Table Name="dbo.Products" Member="Products"> <Type Name="Product"> ...
You can attach an entity to a DataContext different from the one from which it was created only if it has been serialized and deserialized first (Say sending it to the client and having it come back). See [here](http://blogs.msdn.com/dinesh.kulkarni/archive/2007/10/08/attach-if-you-have-something-detached.aspx) for mo...
516,882
<p>Any succinct explanations?</p> <p>Also Answered in: <a href="https://stackoverflow.com/questions/135234/difference-between-ref-and-out-parameters-in-net">Difference between ref and out parameters in .NET</a></p>
[ { "answer_id": 516888, "author": "Alex Fort", "author_id": 12624, "author_profile": "https://Stackoverflow.com/users/12624", "pm_score": 2, "selected": false, "text": "<p>See <a href=\"http://msdn.microsoft.com/en-us/vcsharp/aa336814.aspx\" rel=\"nofollow noreferrer\">this</a> article on...
2009/02/05
[ "https://Stackoverflow.com/questions/516882", "https://Stackoverflow.com", "https://Stackoverflow.com/users/49881/" ]
Any succinct explanations? Also Answered in: [Difference between ref and out parameters in .NET](https://stackoverflow.com/questions/135234/difference-between-ref-and-out-parameters-in-net)
For the caller: * For a ref parameter, the variable has to be definitely assigned already * For an out parameter, the variable doesn't have to be definitely assigned, but will be after the method returns For the method: * A ref parameter starts off definitely assigned, and you don't *have* to assign any value to it ...
516,892
<p>I've got an interface:</p> <pre><code>IRepository&lt;T&gt; where T : IEntity </code></pre> <p>while im knocking up my UI im using some fake repository implementations that just return any old data.</p> <p>They look like this:</p> <pre><code>public class FakeClientRepository : IRepository&lt;Client&gt; </code></p...
[ { "answer_id": 516955, "author": "Chris Marisic", "author_id": 37055, "author_profile": "https://Stackoverflow.com/users/37055", "pm_score": 2, "selected": false, "text": "<p>Take a look at this discussion from the StructureMap users group: <a href=\"http://groups.google.com/group/struct...
2009/02/05
[ "https://Stackoverflow.com/questions/516892", "https://Stackoverflow.com", "https://Stackoverflow.com/users/28543/" ]
I've got an interface: ``` IRepository<T> where T : IEntity ``` while im knocking up my UI im using some fake repository implementations that just return any old data. They look like this: ``` public class FakeClientRepository : IRepository<Client> ``` At the moment im doing this: ``` ForRequestedType<IReposito...
There is an easier way to do this. Please see this blog posting for details: [Advanced StructureMap: connecting implementations to open generic types](http://lostechies.com/jimmybogard/2009/12/18/advanced-structuremap-connecting-implementations-to-open-generic-types/) ``` public class HandlerRegistry : Registry { ...
516,906
<p>To validate data I am receiving I need to make sure that the length is not going to exceeded a database column length. Now all the length information is stored in the Hibernate mapping files, is there anyway to access this information programmatically?</p>
[ { "answer_id": 518808, "author": "Brian Deterling", "author_id": 14619, "author_profile": "https://Stackoverflow.com/users/14619", "pm_score": 4, "selected": true, "text": "<p>You can get to it but it's not easy. You might want to do something like below at startup and store a static ca...
2009/02/05
[ "https://Stackoverflow.com/questions/516906", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20774/" ]
To validate data I am receiving I need to make sure that the length is not going to exceeded a database column length. Now all the length information is stored in the Hibernate mapping files, is there anyway to access this information programmatically?
You can get to it but it's not easy. You might want to do something like below at startup and store a static cache of the values. There are a lot of special cases to deal with (inheritance, etc), but it should work for simple single-column mappings. I might have left out some instanceof and null checks. ``` for (Itera...
516,912
<p>I'm having issues passing arguments through "run" to the windows side</p> <p>To demonstrate, it looks something like this:</p> <pre><code>run C:\foo.exe /BUILD </code></pre> <p>The '/BUILD' parameter is never passed to the executable. Anyone know of a way to get around this?</p> <p>Thanks!</p>
[ { "answer_id": 516942, "author": "JMD", "author_id": 56793, "author_profile": "https://Stackoverflow.com/users/56793", "pm_score": 0, "selected": false, "text": "<p>I don't use Cygwin a lot, but possibly:</p>\n\n<p><code>run 'c:\\foo.exe /BUILD'</code></p>\n\n<p>(if not single- then mayb...
2009/02/05
[ "https://Stackoverflow.com/questions/516912", "https://Stackoverflow.com", "https://Stackoverflow.com/users/40843/" ]
I'm having issues passing arguments through "run" to the windows side To demonstrate, it looks something like this: ``` run C:\foo.exe /BUILD ``` The '/BUILD' parameter is never passed to the executable. Anyone know of a way to get around this? Thanks!
The correct answer, after lots of research was to pass this through a batch file - forcing 'run' to only execute a single cmd, passing all execution off to the batch file.
516,917
<p>I try to write a simple Markdown parser in JavaScript. Therefore I want to check for the <code>[link content][link id]</code> syntax. I use the following code:</p> <pre><code>data = data.replace( /\[(.*?)\][ ]*\[([0-9]+)\]/g, '&lt;a href="$2"&gt;$1&lt;/a&gt;' ); </code></pre> <p>It works well, but now I want to do...
[ { "answer_id": 516925, "author": "Sean Bright", "author_id": 21926, "author_profile": "https://Stackoverflow.com/users/21926", "pm_score": 5, "selected": true, "text": "<p>Because the first argument of the RegExp constructor is a string, not a pattern literal, you have to escape the back...
2009/02/05
[ "https://Stackoverflow.com/questions/516917", "https://Stackoverflow.com", "https://Stackoverflow.com/users/35903/" ]
I try to write a simple Markdown parser in JavaScript. Therefore I want to check for the `[link content][link id]` syntax. I use the following code: ``` data = data.replace( /\[(.*?)\][ ]*\[([0-9]+)\]/g, '<a href="$2">$1</a>' ); ``` It works well, but now I want to do this with a RegExp object. So I set up the follo...
Because the first argument of the RegExp constructor is a string, not a pattern literal, you have to escape the backslashes, since you want literal backslashes in the pattern: ``` var r = new RegExp( '\\[(.*?)\\][ ]*\\[([0-9]+)\\]', 'g' ); ```
516,934
<p>I'm trying to create a tool that can generate XSDs for the XAML produced by serializing a type in .NET, but this is not specifically .NET related.</p> <p>Let's say I have a type. This type has properties and is a collection. </p> <pre><code>public class MyType : Collection&lt;CollectedType&gt; { public PType1 ...
[ { "answer_id": 516925, "author": "Sean Bright", "author_id": 21926, "author_profile": "https://Stackoverflow.com/users/21926", "pm_score": 5, "selected": true, "text": "<p>Because the first argument of the RegExp constructor is a string, not a pattern literal, you have to escape the back...
2009/02/05
[ "https://Stackoverflow.com/questions/516934", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I'm trying to create a tool that can generate XSDs for the XAML produced by serializing a type in .NET, but this is not specifically .NET related. Let's say I have a type. This type has properties and is a collection. ``` public class MyType : Collection<CollectedType> { public PType1 PropertyOne {get;set;} publ...
Because the first argument of the RegExp constructor is a string, not a pattern literal, you have to escape the backslashes, since you want literal backslashes in the pattern: ``` var r = new RegExp( '\\[(.*?)\\][ ]*\\[([0-9]+)\\]', 'g' ); ```
516,935
<p>Using basemap it's easy to plot a set of coordinates, like so:</p> <pre><code>x, y = m(lons, lats) m.plot(x, y, 'go') </code></pre> <p>but would it be possible to use an image instead of the green circle ('go')? I didn't find a direct way of doing this from the documentation.</p> <p>So, let's clarify this a b...
[ { "answer_id": 517320, "author": "joeforker", "author_id": 36330, "author_profile": "https://Stackoverflow.com/users/36330", "pm_score": 4, "selected": true, "text": "<p>If you want to draw <code>.png</code> images then you should try <a href=\"http://matplotlib.sourceforge.net/api/pyplo...
2009/02/05
[ "https://Stackoverflow.com/questions/516935", "https://Stackoverflow.com", "https://Stackoverflow.com/users/21716/" ]
Using basemap it's easy to plot a set of coordinates, like so: ``` x, y = m(lons, lats) m.plot(x, y, 'go') ``` but would it be possible to use an image instead of the green circle ('go')? I didn't find a direct way of doing this from the documentation. So, let's clarify this a bit: I'm using a map generated wit...
If you want to draw `.png` images then you should try <http://matplotlib.sourceforge.net/api/pyplot_api.html#matplotlib.pyplot.imshow> You might also be interested in the Matplotlib Basemap toolkit. <http://matplotlib.sourceforge.net/basemap/doc/html/>