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
243,568
<p>I found in a bug in an old C++ MFC program we have that calculates an offset (in days) for a given date from a fixed base date. We were seeing results that were off by one for some reason, and I tracked it down to where the original programmer had used the CTimeSpan.GetDays() method. According to the <a href="http...
[ { "answer_id": 243841, "author": "Mark Ransom", "author_id": 5987, "author_profile": "https://Stackoverflow.com/users/5987", "pm_score": 3, "selected": true, "text": "<p>Your fix works fine to get the number of whole 24-hour periods between two times - as long as the events occur at the ...
2008/10/28
[ "https://Stackoverflow.com/questions/243568", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3043/" ]
I found in a bug in an old C++ MFC program we have that calculates an offset (in days) for a given date from a fixed base date. We were seeing results that were off by one for some reason, and I tracked it down to where the original programmer had used the CTimeSpan.GetDays() method. According to the [documentation](ht...
Your fix works fine to get the number of whole 24-hour periods between two times - as long as the events occur at the same time each day. Otherwise that "+1" in the expression could lead to an off-by-one error. Sometimes you don't care what time of day the event occured, you just want to know which day. In that case, ...
243,569
<p>consider this code block</p> <pre><code>public void ManageInstalledComponentsUpdate() { IUpdateView view = new UpdaterForm(); BackgroundWorker worker = new BackgroundWorker(); Update update = new Update(); worker.WorkerReportsProgress = true; worke...
[ { "answer_id": 243600, "author": "Marc Gravell", "author_id": 23354, "author_profile": "https://Stackoverflow.com/users/23354", "pm_score": 4, "selected": true, "text": "<p>Threads count as root objects; I don't know exactly how BackgroundWorker operates, but it seems likely that the pri...
2008/10/28
[ "https://Stackoverflow.com/questions/243569", "https://Stackoverflow.com", "https://Stackoverflow.com/users/30324/" ]
consider this code block ``` public void ManageInstalledComponentsUpdate() { IUpdateView view = new UpdaterForm(); BackgroundWorker worker = new BackgroundWorker(); Update update = new Update(); worker.WorkerReportsProgress = true; worker.WorkerSuppor...
Threads count as root objects; I don't know exactly how BackgroundWorker operates, but it seems likely that the primary thread method is going to access state on the worker instance; as such, the worker thread itself will keep the BackgroundWorker instance alive until (at least) the thread has exited. Of course; colle...
243,572
<p>I am configure log4net to use a composite RollingFileAppender so that the current file is always named <strong>logfile.log</strong> and all subsequent files are named <strong>logfile-YYYY.MM.dd.seq.log</strong> where <strong>seq</strong> is the sequence number if a log exceeds a certain size within a single day. Un...
[ { "answer_id": 243607, "author": "Leandro López", "author_id": 22695, "author_profile": "https://Stackoverflow.com/users/22695", "pm_score": 2, "selected": false, "text": "<p>According to log4net RollingFileAppender source code:</p>\n\n<pre class=\"lang-cs prettyprint-override\"><code>pr...
2008/10/28
[ "https://Stackoverflow.com/questions/243572", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19977/" ]
I am configure log4net to use a composite RollingFileAppender so that the current file is always named **logfile.log** and all subsequent files are named **logfile-YYYY.MM.dd.seq.log** where **seq** is the sequence number if a log exceeds a certain size within a single day. Unfortunately, I have had very little success...
We use the following (in Log4J): ``` <appender name="roller" class="org.apache.log4j.DailyRollingFileAppender"> <param name="File" value="Applog.log"/> <param name="DatePattern" value="'.'yyyy-MM-dd"/> <layout class="org.apache.log4j.PatternLayout"> <param name="ConversionPattern" value="[slf5s.sta...
243,617
<p>I have a Java based web-application and a new requirement to allow Users to place variables into text fields that are replaced when a document or other output is produced. How have others gone about this?</p> <p>I was thinking of having a pre-defined set of variables such as :<br> <code>@BOOKING_NUMBER@</code><br> ...
[ { "answer_id": 243649, "author": "Mitchel Sellers", "author_id": 13279, "author_profile": "https://Stackoverflow.com/users/13279", "pm_score": 0, "selected": false, "text": "<p>I have used a similiar replacement token system before. I personally like something like.</p>\n\n<p>[MYVALUE]<...
2008/10/28
[ "https://Stackoverflow.com/questions/243617", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2955/" ]
I have a Java based web-application and a new requirement to allow Users to place variables into text fields that are replaced when a document or other output is produced. How have others gone about this? I was thinking of having a pre-defined set of variables such as : `@BOOKING_NUMBER@` `@INVOICE_NUMBER@` Th...
Have a look at java.text.MessageFormat - particularly the format method - as this is designed for exactly what you are looking for. i.e. ``` MessageFormat.format("This is some text for booking {0} that is needed by me, for use with invoice {1}", bookingNumber, invoiceNumber); ``` You may even want to get the templa...
243,644
<p>I have currently more than 100 connections in Sleep state.</p> <p>Some connection must stay in Sleep state (and don't close) because it's permanent connection but some others (with a different user name) are from some php script and I want them to timeout very fast.</p> <p>Is it possible to setup a wait_timeout pe...
[ { "answer_id": 244291, "author": "Gary Richardson", "author_id": 2506, "author_profile": "https://Stackoverflow.com/users/2506", "pm_score": 0, "selected": false, "text": "<p>I checked the <code>mysql.user</code> table and it doesn't look like there is a setting there for it:</p>\n\n<pre...
2008/10/28
[ "https://Stackoverflow.com/questions/243644", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6605/" ]
I have currently more than 100 connections in Sleep state. Some connection must stay in Sleep state (and don't close) because it's permanent connection but some others (with a different user name) are from some php script and I want them to timeout very fast. Is it possible to setup a wait\_timeout per user? and if y...
There's no per-user timeout configuration, but you can set the `wait_timeout` value dynamically. That is, after you make a connection as a given user, you can issue a statement to change the timeout value to what you want it to be for that user's session. Try the following experiment in the mysql command-line client: ...
243,646
<p>I've got an <code>RSA</code> private key in <code>PEM</code> format, is there a straight forward way to read that from .NET and instantiate an <code>RSACryptoServiceProvider</code> to decrypt data encrypted with the corresponding public key?</p>
[ { "answer_id": 243685, "author": "wprl", "author_id": 17847, "author_profile": "https://Stackoverflow.com/users/17847", "pm_score": 5, "selected": false, "text": "<p>You might take a look at <a href=\"http://www.jensign.com/\" rel=\"noreferrer\">JavaScience's</a> source for <a href=\"htt...
2008/10/28
[ "https://Stackoverflow.com/questions/243646", "https://Stackoverflow.com", "https://Stackoverflow.com/users/32093/" ]
I've got an `RSA` private key in `PEM` format, is there a straight forward way to read that from .NET and instantiate an `RSACryptoServiceProvider` to decrypt data encrypted with the corresponding public key?
### Update 03/03/2021 .NET 5 now supports this out of the box. To try the code snippet below, generate a keypair and encrypt some text at <http://travistidwell.com/jsencrypt/demo/> ``` var privateKey = @"-----BEGIN RSA PRIVATE KEY----- { the full PEM private key } -----END RSA PRIVATE KEY-----"; var rsa = RSA.Crea...
243,683
<p>How do I extract the value of a property in a PropertyCollection?</p> <p>If I drill down on the 'Properties' in the line below is visual studion I can see the value but how do I read it?</p> <pre><code>foreach (string propertyName in result.Properties.PropertyNames) { MessageBox.Show(ProperyNames[0].Value.ToStri...
[ { "answer_id": 243690, "author": "dove", "author_id": 30913, "author_profile": "https://Stackoverflow.com/users/30913", "pm_score": 0, "selected": false, "text": "<p>is that propertynames meant to be upper case within function?</p>\n\n<p>Reading again, i have to admit to be a little conf...
2008/10/28
[ "https://Stackoverflow.com/questions/243683", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
How do I extract the value of a property in a PropertyCollection? If I drill down on the 'Properties' in the line below is visual studion I can see the value but how do I read it? ``` foreach (string propertyName in result.Properties.PropertyNames) { MessageBox.Show(ProperyNames[0].Value.ToString()); <--Wrong! } `...
Try this: ``` foreach (string propertyName in result.Properties.PropertyNames) { MessageBox.Show(result.Properties[propertyName].ToString()); } ``` Or this: ``` foreach (object prop in result.Properties) { MessageBox.Show(prop.ToString()); } ``` Also: there are a couple different PropertyCollections clas...
243,691
<p>[Error] WARNING. Duplicate resource(s): [Error] Type 2 (BITMAP), ID TWWDBRICHEDITMSWORD: [Error] File C:\Borland\Delphi7\ip4000vcl7\LIB\wwrichsp.RES resource kept; file C:\Borland\Delphi7\ip4000vcl7\LIB\wwrichsp.RES resource discarded. I have searched the code for same named objects, like objects. Can a...
[ { "answer_id": 243890, "author": "Lars Truijens", "author_id": 1242, "author_profile": "https://Stackoverflow.com/users/1242", "pm_score": 2, "selected": false, "text": "<p>Two units both using the same resource file. Probably looks like this:</p>\n\n<pre><code>{$R wwrichsp.RES}\n</code>...
2008/10/28
[ "https://Stackoverflow.com/questions/243691", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
[Error] WARNING. Duplicate resource(s): [Error] Type 2 (BITMAP), ID TWWDBRICHEDITMSWORD: [Error] File C:\Borland\Delphi7\ip4000vcl7\LIB\wwrichsp.RES resource kept; file C:\Borland\Delphi7\ip4000vcl7\LIB\wwrichsp.RES resource discarded. I have searched the code for same named objects, like objects. Can anyone give me ...
Two units both using the same resource file. Probably looks like this: ``` {$R wwrichsp.RES} ```
243,696
<p>MathWorks currently doesn't allow you to use <code>cout</code> from a mex file when the MATLAB desktop is open because they have redirected stdout. Their current workaround is providing a function, <a href="http://www.mathworks.com/support/tech-notes/1600/1605.html" rel="nofollow noreferrer">mexPrintf, that they re...
[ { "answer_id": 244286, "author": "Max Lybbert", "author_id": 10593, "author_profile": "https://Stackoverflow.com/users/10593", "pm_score": 0, "selected": false, "text": "<p><code>cout</code> is a particular character output stream. If you want a <code>cout</code> that writes to a file, ...
2008/10/28
[ "https://Stackoverflow.com/questions/243696", "https://Stackoverflow.com", "https://Stackoverflow.com/users/27315/" ]
MathWorks currently doesn't allow you to use `cout` from a mex file when the MATLAB desktop is open because they have redirected stdout. Their current workaround is providing a function, [mexPrintf, that they request you use instead](http://www.mathworks.com/support/tech-notes/1600/1605.html). After googling around a b...
You don't really want to overload `std::stringbuf`, you want to overload `std::streambuf` or `std::basic_streambuf` (if you want to support multiple character types), also you need to override the overflow method as well. But I also think you need to rethink your solution to your problem. `cout` is just an `ostream`,...
243,712
<p>Hey! I was looking at this code at <a href="http://www.gnu.org/software/m68hc11/examples/primes_8c-source.html" rel="noreferrer">http://www.gnu.org/software/m68hc11/examples/primes_8c-source.html</a></p> <p>I noticed that in some situations they used hex numbers, like in line 134:</p> <pre><code>for (j = 1; val &a...
[ { "answer_id": 243727, "author": "James Curran", "author_id": 12725, "author_profile": "https://Stackoverflow.com/users/12725", "pm_score": 8, "selected": true, "text": "<p>In both cases you cite, the bit pattern of the number is important, not the actual number.</p>\n<p>For example,\nIn...
2008/10/28
[ "https://Stackoverflow.com/questions/243712", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8715/" ]
Hey! I was looking at this code at <http://www.gnu.org/software/m68hc11/examples/primes_8c-source.html> I noticed that in some situations they used hex numbers, like in line 134: ``` for (j = 1; val && j <= 0x80; j <<= 1, q++) ``` Now why would they use the 0x80? I am not that good with hex but I found an online he...
In both cases you cite, the bit pattern of the number is important, not the actual number. For example, In the first case, `j` is going to be 1, then 2, 4, 8, 16, 32, 64 and finally 128 as the loop progresses. In binary, that is, `0000:0001`, `0000:0010`, `0000:0100`, `0000:1000`, `0001:0000`, `0010:0000`, `0100:000...
243,728
<p>I got dtd in file and I cant remove it. When i try to parse it in Java I get "Caused by: java.net.SocketException: Network is unreachable: connect", because its remote dtd. can I disable somehow dtd checking?</p>
[ { "answer_id": 243747, "author": "toolkit", "author_id": 3295, "author_profile": "https://Stackoverflow.com/users/3295", "pm_score": 5, "selected": true, "text": "<p>You should be able to specify your own EntityResolver, or use specific features of your parser? See <a href=\"https://stac...
2008/10/28
[ "https://Stackoverflow.com/questions/243728", "https://Stackoverflow.com", "https://Stackoverflow.com/users/30453/" ]
I got dtd in file and I cant remove it. When i try to parse it in Java I get "Caused by: java.net.SocketException: Network is unreachable: connect", because its remote dtd. can I disable somehow dtd checking?
You should be able to specify your own EntityResolver, or use specific features of your parser? See [here](https://stackoverflow.com/questions/155101/make-documentbuilderparse-ignore-dtd-references) for some approaches. A more complete example: ``` <?xml version="1.0"?> <!DOCTYPE foo PUBLIC "//FOO//" "foo.dtd"> <foo>...
243,750
<p>I've searched around a bit for similar questions, but other than running one command or perhaps a few command with items such as:</p> <pre><code>ssh user@host -t sudo su - </code></pre> <p>However, what if I essentially need to run a script on (let's say) 15 servers at once. Is this doable in bash? In a perfect wo...
[ { "answer_id": 243756, "author": "Darron", "author_id": 22704, "author_profile": "https://Stackoverflow.com/users/22704", "pm_score": 2, "selected": false, "text": "<p>To give you the structure, without actual code.</p>\n\n<ol>\n<li>Use scp to copy your install/setup script to the target...
2008/10/28
[ "https://Stackoverflow.com/questions/243750", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14838/" ]
I've searched around a bit for similar questions, but other than running one command or perhaps a few command with items such as: ``` ssh user@host -t sudo su - ``` However, what if I essentially need to run a script on (let's say) 15 servers at once. Is this doable in bash? In a perfect world I need to avoid instal...
Often, I'll just use the original Tcl version of Expect. You only need to have that on the local machine. If I'm inside a program using Perl, I do this with [Net::SSH::Expect](http://search.cpan.org/dist/Net-SSH-Expect/). Other languages have similar "expect" tools.
243,752
<p>Is there a way to do this without iterating through the List and adding the items to the ObservableCollection?</p>
[ { "answer_id": 243766, "author": "Nescio", "author_id": 14484, "author_profile": "https://Stackoverflow.com/users/14484", "pm_score": 6, "selected": true, "text": "<p>No, there is no way to directly convert the list to an observable collection. You must add each item to the collection. H...
2008/10/28
[ "https://Stackoverflow.com/questions/243752", "https://Stackoverflow.com", "https://Stackoverflow.com/users/132931/" ]
Is there a way to do this without iterating through the List and adding the items to the ObservableCollection?
No, there is no way to directly convert the list to an observable collection. You must add each item to the collection. However, below is a shortcut to allow the framework to enumerate the values and add them for you. ``` Dim list as new List(of string) ...some stuff to fill the list... Dim observable as new Observab...
243,782
<p>I'm trying to select a column from a single table (no joins) and I need the count of the number of rows, ideally before I begin retrieving the rows. I have come to two approaches that provide the information I need.</p> <p><strong>Approach 1:</strong></p> <pre><code>SELECT COUNT( my_table.my_col ) AS row_count ...
[ { "answer_id": 243793, "author": "jonnii", "author_id": 4590, "author_profile": "https://Stackoverflow.com/users/4590", "pm_score": 0, "selected": false, "text": "<p>Why don't you put your results into a vector? That way you don't have to know the size before hand.</p>\n" }, { "...
2008/10/28
[ "https://Stackoverflow.com/questions/243782", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1625/" ]
I'm trying to select a column from a single table (no joins) and I need the count of the number of rows, ideally before I begin retrieving the rows. I have come to two approaches that provide the information I need. **Approach 1:** ``` SELECT COUNT( my_table.my_col ) AS row_count FROM my_table WHERE my_table.foo =...
There are only two ways to be 100% certain that the `COUNT(*)` and the actual query will give consistent results: * Combined the `COUNT(*)` with the query, as in your Approach 2. I recommend the form you show in your example, not the correlated subquery form shown in the comment from kogus. * Use two queries, as in yo...
243,790
<p>I have this table in an Oracle DB which has a primary key defined on 3 of the data columns. I want to drop the primary key constraint to allow rows with duplicate data for those columns, and create a new column, 'id', to contain an auto-incrementing integer ID for these rows. I know how to create a sequence and trig...
[ { "answer_id": 243838, "author": "Steve", "author_id": 15470, "author_profile": "https://Stackoverflow.com/users/15470", "pm_score": 2, "selected": false, "text": "<p>If you're just using an integer for a sequence you could update the id with the rownum. e.g.</p>\n\n<pre><code>update\nt...
2008/10/28
[ "https://Stackoverflow.com/questions/243790", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3101/" ]
I have this table in an Oracle DB which has a primary key defined on 3 of the data columns. I want to drop the primary key constraint to allow rows with duplicate data for those columns, and create a new column, 'id', to contain an auto-incrementing integer ID for these rows. I know how to create a sequence and trigger...
Once you have created the sequence: ``` update mytable set id = mysequence.nextval; ```
243,794
<p>I'm using the latest version of the <a href="https://jqueryui.com/tabs/" rel="nofollow noreferrer">jQuery UI tabs</a>. I have tabs positioned toward the bottom of the page. </p> <p>Every time I click a tab, the screen jumps toward the top.</p> <p>How can I prevent this from happening?</p> <p>Please see this examp...
[ { "answer_id": 243832, "author": "changelog", "author_id": 5646, "author_profile": "https://Stackoverflow.com/users/5646", "pm_score": 4, "selected": false, "text": "<p>If you have something along these lines:</p>\n\n<pre><code>&lt;a href=\"#\" onclick=\"activateTab('tab1');\"&gt;Tab 1&l...
2008/10/28
[ "https://Stackoverflow.com/questions/243794", "https://Stackoverflow.com", "https://Stackoverflow.com/users/31869/" ]
I'm using the latest version of the [jQuery UI tabs](https://jqueryui.com/tabs/). I have tabs positioned toward the bottom of the page. Every time I click a tab, the screen jumps toward the top. How can I prevent this from happening? Please see this example: <http://5bosses.com/examples/tabs/sample_tabs.html>
If you're animating your tab transitions (ie. `.tabs({ fx: { opacity: 'toggle' } });`), then here's what's happening: In most cases, the jumping isn't caused by the browser following the '#' link. The page jumps because at the midpoint of the animation between the two tab panes, both tab panes are fully transparent an...
243,800
<p><strong>The Situation</strong></p> <p>I have an area of the screen that can be shown and hidden via JavaScript (something like "show/hide advanced search options"). Inside this area there are form elements (select, checkbox, etc). For users using assistive technology like a screen-reader (in this case JAWS), we nee...
[ { "answer_id": 245437, "author": "Gareth", "author_id": 31582, "author_profile": "https://Stackoverflow.com/users/31582", "pm_score": 1, "selected": false, "text": "<p>This definitely looks like a bug in JAWS as the spec definitively states that display:none should cause an element and i...
2008/10/28
[ "https://Stackoverflow.com/questions/243800", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9960/" ]
**The Situation** I have an area of the screen that can be shown and hidden via JavaScript (something like "show/hide advanced search options"). Inside this area there are form elements (select, checkbox, etc). For users using assistive technology like a screen-reader (in this case JAWS), we need to link these form el...
Give items the aria-hidden="true" attribute, and it should be hidden from the screenreader.
243,811
<p>Looking through some code I came across the following code</p> <pre><code>trTuDocPackTypdBd.update(TrTuDocPackTypeDto.class.cast(packDto)); </code></pre> <p>and I'd like to know if casting this way has any advantages over </p> <pre><code>trTuDocPackTypdBd.update((TrTuDocPackTypeDto)packDto); </code></pre> <p>I'v...
[ { "answer_id": 243825, "author": "Rontologist", "author_id": 13925, "author_profile": "https://Stackoverflow.com/users/13925", "pm_score": -1, "selected": false, "text": "<p>Both of these statements are identical. Pick whichever one you find more readable. The second method is more commo...
2008/10/28
[ "https://Stackoverflow.com/questions/243811", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4389/" ]
Looking through some code I came across the following code ``` trTuDocPackTypdBd.update(TrTuDocPackTypeDto.class.cast(packDto)); ``` and I'd like to know if casting this way has any advantages over ``` trTuDocPackTypdBd.update((TrTuDocPackTypeDto)packDto); ``` I've asked the developer responsible and he said he ...
These statements are not identical. The cast method is a normal method invocation (`invokevirtual` JVM instruction) while the other is a language construct (`checkcast` instruction). In the case you show above, you should use the second form: `(TrTuDocPackTypeDto) packDto` The `cast` method is used in reflective progr...
243,814
<p>I am attempting to deploy .NET 2.0 web services on IIS that has both 1.0 and 2.0 installed. This web server primarily serves a large .NET 1.0 application. </p> <p>I have copied by .NET 2.0 web service project to the server and have created a virtual directory to point to the necessary folder. </p> <p>When I set th...
[ { "answer_id": 243825, "author": "Rontologist", "author_id": 13925, "author_profile": "https://Stackoverflow.com/users/13925", "pm_score": -1, "selected": false, "text": "<p>Both of these statements are identical. Pick whichever one you find more readable. The second method is more commo...
2008/10/28
[ "https://Stackoverflow.com/questions/243814", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1638/" ]
I am attempting to deploy .NET 2.0 web services on IIS that has both 1.0 and 2.0 installed. This web server primarily serves a large .NET 1.0 application. I have copied by .NET 2.0 web service project to the server and have created a virtual directory to point to the necessary folder. When I set the ASP.NET version...
These statements are not identical. The cast method is a normal method invocation (`invokevirtual` JVM instruction) while the other is a language construct (`checkcast` instruction). In the case you show above, you should use the second form: `(TrTuDocPackTypeDto) packDto` The `cast` method is used in reflective progr...
243,831
<p>Is there a way to get the Unicode Block of a character in python? The <a href="http://www.python.org/doc/2.5.2/lib/module-unicodedata.html" rel="noreferrer">unicodedata</a> module doesn't seem to have what I need, and I couldn't find an external library for it.</p> <p>Basically, I need the same functionality as <a ...
[ { "answer_id": 245072, "author": "zaphod", "author_id": 13871, "author_profile": "https://Stackoverflow.com/users/13871", "pm_score": 5, "selected": true, "text": "<p>I couldn't find one either. Strange!</p>\n\n<p>Luckily, the number of Unicode blocks is quite manageably small.</p>\n\n<...
2008/10/28
[ "https://Stackoverflow.com/questions/243831", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7581/" ]
Is there a way to get the Unicode Block of a character in python? The [unicodedata](http://www.python.org/doc/2.5.2/lib/module-unicodedata.html) module doesn't seem to have what I need, and I couldn't find an external library for it. Basically, I need the same functionality as [`Character.UnicodeBlock.of()`](http://ja...
I couldn't find one either. Strange! Luckily, the number of Unicode blocks is quite manageably small. This implementation accepts a one-character Unicode string, just like the functions in `unicodedata`. If your inputs are mostly ASCII, this linear search might even be faster than binary search using `bisect` or what...
243,836
<p>Is there a library method to copy all the properties between two (already present) instances of the same class, in Python?</p> <p>I mean, something like Apache Commons' <code>PropertyUtilsBean.copyProperties()</code></p>
[ { "answer_id": 244116, "author": "Peter Hoffmann", "author_id": 720, "author_profile": "https://Stackoverflow.com/users/720", "pm_score": 7, "selected": true, "text": "<p>If your class does not modify <code>__getitem__</code> or <code>__setitem__</code> for special attribute access all y...
2008/10/28
[ "https://Stackoverflow.com/questions/243836", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3497/" ]
Is there a library method to copy all the properties between two (already present) instances of the same class, in Python? I mean, something like Apache Commons' `PropertyUtilsBean.copyProperties()`
If your class does not modify `__getitem__` or `__setitem__` for special attribute access all your attributes are stored in `__dict__` so you can do: ``` nobj.__dict__ = oobj.__dict__.copy() # just a shallow copy ``` If you use python properties you should look at `inspect.getmembers()` and filter out the ones y...
243,851
<p>I'm trying to unit test a piece of code that needs a currently logged in user in the test. Using the .Net 2.0 Membership Provider, how can I programmatically log in as a user for this test?</p>
[ { "answer_id": 244486, "author": "Craig Stuntz", "author_id": 7714, "author_profile": "https://Stackoverflow.com/users/7714", "pm_score": 1, "selected": false, "text": "<p>Does your code actually need a user logged in via ASP.NET, or does it just need a CurrentPrincipal? I don't think yo...
2008/10/28
[ "https://Stackoverflow.com/questions/243851", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16027/" ]
I'm trying to unit test a piece of code that needs a currently logged in user in the test. Using the .Net 2.0 Membership Provider, how can I programmatically log in as a user for this test?
``` if(Membership.ValidateUser("user1",P@ssw0rd)) { FormsAuthentication.SetAuthCookie("user1",true); } ```
243,864
<p>I want to create a list of integers from 1 to <code>n</code>. I can do this in Python using <code>range(1, n+1)</code>, and in Haskell using: <code>take n (iterate (1+) 1)</code>.</p> <p>What is the right OCaml idiom for this?</p>
[ { "answer_id": 244078, "author": "Thedric Walker", "author_id": 26166, "author_profile": "https://Stackoverflow.com/users/26166", "pm_score": 4, "selected": false, "text": "<p>Here you go:</p>\n<pre><code>let rec range i j = \n if i &gt; j then [] \n else i :: range (i+1) j\n</code></p...
2008/10/28
[ "https://Stackoverflow.com/questions/243864", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1386292/" ]
I want to create a list of integers from 1 to `n`. I can do this in Python using `range(1, n+1)`, and in Haskell using: `take n (iterate (1+) 1)`. What is the right OCaml idiom for this?
There is no idiom that I know of, but here is a fairly natural definition using an infix operator: ```ml # let (--) i j = let rec aux n acc = if n < i then acc else aux (n-1) (n :: acc) in aux j [] ;; val ( -- ) : int -> int -> int list = <fun> # 1--2;; - : int list = [1; 2] # 1--5;; - : int list = [1; ...
243,865
<p>I have two iterators, a <code>list</code> and an <code>itertools.count</code> object (i.e. an infinite value generator). I would like to merge these two into a resulting iterator that will alternate yield values between the two:</p> <pre><code>&gt;&gt;&gt; import itertools &gt;&gt;&gt; c = itertools.count(1) &gt;&g...
[ { "answer_id": 243892, "author": "Claudiu", "author_id": 15055, "author_profile": "https://Stackoverflow.com/users/15055", "pm_score": 4, "selected": false, "text": "<p>I'd do something like this. This will be most time and space efficient, since you won't have the overhead of zipping ob...
2008/10/28
[ "https://Stackoverflow.com/questions/243865", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18950/" ]
I have two iterators, a `list` and an `itertools.count` object (i.e. an infinite value generator). I would like to merge these two into a resulting iterator that will alternate yield values between the two: ``` >>> import itertools >>> c = itertools.count(1) >>> items = ['foo', 'bar'] >>> merged = imerge(items, c) # ...
A generator will solve your problem nicely. ``` def imerge(a, b): for i, j in itertools.izip(a,b): yield i yield j ```
243,878
<p><strong>Edit:</strong> This was accidentally posted twice. Original: <a href="https://stackoverflow.com/questions/243900/vb-net-importing-classes">VB.NET Importing Classes</a></p> <p>I've seen some code where a <em>Class</em> is imported, instead of a namespace, making all the static members/methods of that class a...
[ { "answer_id": 243948, "author": "willasaywhat", "author_id": 12234, "author_profile": "https://Stackoverflow.com/users/12234", "pm_score": 4, "selected": true, "text": "<p>Having written the MyBlogLog plugin (the original one, that is) I found that the Wordpress Hooks list (can't rememb...
2008/10/28
[ "https://Stackoverflow.com/questions/243878", "https://Stackoverflow.com", "https://Stackoverflow.com/users/40/" ]
**Edit:** This was accidentally posted twice. Original: [VB.NET Importing Classes](https://stackoverflow.com/questions/243900/vb-net-importing-classes) I've seen some code where a *Class* is imported, instead of a namespace, making all the static members/methods of that class available. Is this a feature of VB? Or do ...
Having written the MyBlogLog plugin (the original one, that is) I found that the Wordpress Hooks list (can't remember the link offhand) was incredibly useful, as was the sample code from the Codex and WP Install files. Reading through other developer's plugins is also a good way to learn, as you can see how they implem...
243,894
<p>Does the placement of a function have an effect on the performance of closures within scope? If so, where is the optimal place to put these functions? If not, is the implied association by closure enough reason to place a function in another place logically?</p> <p>For instance, if <strong>foo</strong> does not r...
[ { "answer_id": 243942, "author": "Darius Bacon", "author_id": 27024, "author_profile": "https://Stackoverflow.com/users/27024", "pm_score": 1, "selected": false, "text": "<p>The scope of a var or function declaration is the whole block it appears in, regardless of where in the block the ...
2008/10/28
[ "https://Stackoverflow.com/questions/243894", "https://Stackoverflow.com", "https://Stackoverflow.com/users/208/" ]
Does the placement of a function have an effect on the performance of closures within scope? If so, where is the optimal place to put these functions? If not, is the implied association by closure enough reason to place a function in another place logically? For instance, if **foo** does not rely on the value of **loc...
Every function in Javascript is a closure. The runtime to resolve a variable's value is only incurred if the variable is referenced by the function. For instance, in this example function y captures the value of x even though x is not referenced directly by y: ``` var x = 3; function y() eval("x"); y(); 3 ```
243,897
<p>I have a variable that is built in loop. Something like:</p> <pre><code>$str = ""; for($i = 0; $i &lt; 10; $i++) $str .= "something"; </code></pre> <p>If $str = "" is ommitted, I get undefined variable notice, but I thought php auto-declare a variable the first time it sees undeclared one?</p> <p>How do I do this...
[ { "answer_id": 243913, "author": "vIceBerg", "author_id": 17766, "author_profile": "https://Stackoverflow.com/users/17766", "pm_score": 5, "selected": true, "text": "<p>You get the undefined variable because you're concatenating the value of itself with another value.</p>\n\n<p>The equiv...
2008/10/28
[ "https://Stackoverflow.com/questions/243897", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15345/" ]
I have a variable that is built in loop. Something like: ``` $str = ""; for($i = 0; $i < 10; $i++) $str .= "something"; ``` If $str = "" is ommitted, I get undefined variable notice, but I thought php auto-declare a variable the first time it sees undeclared one? How do I do this right?
You get the undefined variable because you're concatenating the value of itself with another value. The equivalent of > > `$str = $str . "something";` > > > So, it can't say what's the initial value is. It's the equivalent of this: > > `$str = [undefined value] . "something";` > > > What's the result of a ...
243,900
<p>I've seen some code where a <em>Class</em> is imported, instead of a namespace, making all the static members/methods of that class available. Is this a feature of VB? Or do other languages do this as well?</p> <p>TestClass.vb</p> <pre><code>public class TestClass public shared function Somefunc() as Boolean...
[ { "answer_id": 243923, "author": "thismat", "author_id": 14045, "author_profile": "https://Stackoverflow.com/users/14045", "pm_score": 1, "selected": false, "text": "<p>Actually, that function is available because it's a <a href=\"http://msdn.microsoft.com/en-us/library/zc2b427x(VS.80).a...
2008/10/28
[ "https://Stackoverflow.com/questions/243900", "https://Stackoverflow.com", "https://Stackoverflow.com/users/40/" ]
I've seen some code where a *Class* is imported, instead of a namespace, making all the static members/methods of that class available. Is this a feature of VB? Or do other languages do this as well? TestClass.vb ``` public class TestClass public shared function Somefunc() as Boolean return true end f...
One of the reasons this feature is in place is to emulate Visual Basic 6.0's GlobalMultiUse Option for Instancing. Visual Basic 6.0 doesn't have the ability to make modules public across a DLL boundary. Instead you set the instancing property to `GlobalMultiUse`. It is used mainly for utility classes like a class that ...
243,912
<p>I have the following code below in my Servlet, but when IE hits the page, it returns a blank html page. If I use the response.getOutputStream() directly in the StreamResult constructor, the page loads fine. What am I missing?</p> <p><strong>response</strong> is an instance of HttpServletResponse and <strong>xsl</...
[ { "answer_id": 244269, "author": "jsight", "author_id": 1432, "author_profile": "https://Stackoverflow.com/users/1432", "pm_score": 1, "selected": false, "text": "<p>I'm going to guess that you aren't closing the gzipOut stream and therefore it isn't sending the \"footer\" information.</...
2008/10/28
[ "https://Stackoverflow.com/questions/243912", "https://Stackoverflow.com", "https://Stackoverflow.com/users/30381/" ]
I have the following code below in my Servlet, but when IE hits the page, it returns a blank html page. If I use the response.getOutputStream() directly in the StreamResult constructor, the page loads fine. What am I missing? **response** is an instance of HttpServletResponse and **xsl** is an instance of Transformer ...
I'm going to guess that you aren't closing the gzipOut stream and therefore it isn't sending the "footer" information.
243,929
<p>I have several arrays of arrays or arrays of dicts that I would like to store in my iPhone app. This lists are static and won't be modified by the app or users. Occasionally they may be displayed but more likely they'll be iterated over and compared to some input value. Would the best way to store these arrays be...
[ { "answer_id": 244030, "author": "Chris Lundie", "author_id": 20685, "author_profile": "https://Stackoverflow.com/users/20685", "pm_score": 3, "selected": false, "text": "<p>Use a property list file. Load it with NSDictionary +dictionaryWithContentsofFile:.</p>\n" }, { "answer_id...
2008/10/28
[ "https://Stackoverflow.com/questions/243929", "https://Stackoverflow.com", "https://Stackoverflow.com/users/29263/" ]
I have several arrays of arrays or arrays of dicts that I would like to store in my iPhone app. This lists are static and won't be modified by the app or users. Occasionally they may be displayed but more likely they'll be iterated over and compared to some input value. Would the best way to store these arrays be a Cor...
I would do the following: ``` @implementation DataSource + (NSArray *)someData { static NSArray *data = nil; if (!data) { data = [[NSArray arrayWithObjects:..., nil] retain]; } return data; } @end ``` Additional arrays or arrays of dicts would be added as class methods on that class.
243,945
<p>From wikipedia: </p> <blockquote> <p>the cross product is a binary operation on two vectors in a <strong>three-dimensional</strong> Euclidean space that results in another vector which is perpendicular to the plane containing the two input vectors.</p> </blockquote> <p>Given that the definition is only defined i...
[ { "answer_id": 243977, "author": "Drew Hall", "author_id": 23934, "author_profile": "https://Stackoverflow.com/users/23934", "pm_score": 8, "selected": true, "text": "<p>Implementation 1 returns the magnitude of the vector that would result from a regular 3D cross product of the input ve...
2008/10/28
[ "https://Stackoverflow.com/questions/243945", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18265/" ]
From wikipedia: > > the cross product is a binary operation on two vectors in a **three-dimensional** Euclidean space that results in another vector which is perpendicular to the plane containing the two input vectors. > > > Given that the definition is only defined in three ([or seven, one and zero](https://en....
Implementation 1 returns the magnitude of the vector that would result from a regular 3D cross product of the input vectors, taking their Z values implicitly as 0 (i.e. treating the 2D space as a plane in the 3D space). The 3D cross product will be perpendicular to that plane, and thus have 0 X & Y components (thus the...
243,956
<p>I currently have a silverlight application which rotates through several graphs of live data. Each page has two user controls though: one for an info box at the top and another for the graph to display. I have tried to add a background image to the master page that they are displayed on so that the image is behind e...
[ { "answer_id": 243975, "author": "MaxM", "author_id": 4226, "author_profile": "https://Stackoverflow.com/users/4226", "pm_score": 0, "selected": false, "text": "<p>There is surely something inside the user controls that has a white background, you could probably find it using Blend, or m...
2008/10/28
[ "https://Stackoverflow.com/questions/243956", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I currently have a silverlight application which rotates through several graphs of live data. Each page has two user controls though: one for an info box at the top and another for the graph to display. I have tried to add a background image to the master page that they are displayed on so that the image is behind ever...
You need to set the background to be transparent on the host control itself, not just in the xaml files that get loaded. If you're using the object tag you would do something like: ``` <object data="data:application/x-silverlight-2," type="application/x-silverlight-2" width="100%" height="100%"> <param name="sourc...
243,967
<p>Sometimes you need to skip execution of part of a method under certain non-critical error conditions. You can use <em>exceptions</em> for that, but exceptions generally are not recommended in normal application logic, only for abnormal situations.</p> <p>So I do a trick like this:</p> <pre><code>do { bool isGoo...
[ { "answer_id": 243972, "author": "EBGreen", "author_id": 1358, "author_profile": "https://Stackoverflow.com/users/1358", "pm_score": 0, "selected": false, "text": "<p>I think that there is nothing basically wrong with the technique. I think that I would make sure that the bool is named s...
2008/10/28
[ "https://Stackoverflow.com/questions/243967", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20390/" ]
Sometimes you need to skip execution of part of a method under certain non-critical error conditions. You can use *exceptions* for that, but exceptions generally are not recommended in normal application logic, only for abnormal situations. So I do a trick like this: ``` do { bool isGood = true; .... some code...
Bad practice, it depends. What I see in this code is a very creative way to write "goto" with less sulphur-smelling keywords. There are multiple alternatives to this code, which can or can not be better, depending on the situation. Your do/while solution ---------------------- Your solution is interesting if you ha...
243,992
<p>When I create a zip Archive via <code>java.util.zip.*</code>, is there a way to split the resulting archive in multiple volumes? </p> <p>Let's say my overall archive has a <code>filesize</code> of <code>24 MB</code> and I want to split it into 3 files on a limit of 10 MB per file.<br> Is there a zip API which has ...
[ { "answer_id": 244025, "author": "sakana", "author_id": 28921, "author_profile": "https://Stackoverflow.com/users/28921", "pm_score": 4, "selected": true, "text": "<p>Check: <a href=\"http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&amp;f=38&amp;t=004618\" rel=\"nofol...
2008/10/28
[ "https://Stackoverflow.com/questions/243992", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9688/" ]
When I create a zip Archive via `java.util.zip.*`, is there a way to split the resulting archive in multiple volumes? Let's say my overall archive has a `filesize` of `24 MB` and I want to split it into 3 files on a limit of 10 MB per file. Is there a zip API which has this feature? Or any other nice ways to achie...
Check: <http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&f=38&t=004618> *I am not aware of any public API that will help you do that. (Although if you do not want to do it programatically, there are utilities like WinSplitter that will do it)* *I have not tried it but, every ZipEntry while using Z...
243,995
<p>I am trying to set the permissions of a folder and all of it's children on a vista computer. The code I have so far is this.</p> <pre><code> public static void SetPermissions(string dir) { DirectoryInfo info = new DirectoryInfo(dir); DirectorySecurity ds = info.GetAccessControl(); ...
[ { "answer_id": 244036, "author": "Coderer", "author_id": 26286, "author_profile": "https://Stackoverflow.com/users/26286", "pm_score": 1, "selected": false, "text": "<p>This may be a dumb question, but have you tried performing the same action manually (e.g. using Explorer)? Vista has s...
2008/10/28
[ "https://Stackoverflow.com/questions/243995", "https://Stackoverflow.com", "https://Stackoverflow.com/users/22835/" ]
I am trying to set the permissions of a folder and all of it's children on a vista computer. The code I have so far is this. ``` public static void SetPermissions(string dir) { DirectoryInfo info = new DirectoryInfo(dir); DirectorySecurity ds = info.GetAccessControl(); ...
So the answer is two fold. First off a sub folder was being created before the permissions were set on the folder and I needed to or in one more flag on the permissions to make it so both folders and files inherited the permissions. ``` public static void SetPermissions(string dir) { DirectoryInfo ...
244,001
<p>I know that cursors are frowned upon and I try to avoid their use as much as possible, but there may be some legitimate reasons to use them. I have one and I am trying to use a pair of cursors: one for the primary table and one for the secondary table. The primary table cursor iterates through the primary table in a...
[ { "answer_id": 244024, "author": "Eduardo Campañó", "author_id": 12091, "author_profile": "https://Stackoverflow.com/users/12091", "pm_score": 0, "selected": false, "text": "<p>I'd try placing the</p>\n\n<pre><code>DECLARE curScores CURSOR\nFOR \n SELECT FName,Score \n FROM @Scores...
2008/10/28
[ "https://Stackoverflow.com/questions/244001", "https://Stackoverflow.com", "https://Stackoverflow.com/users/262613/" ]
I know that cursors are frowned upon and I try to avoid their use as much as possible, but there may be some legitimate reasons to use them. I have one and I am trying to use a pair of cursors: one for the primary table and one for the secondary table. The primary table cursor iterates through the primary table in an o...
The value of @fName is evaluated at :DECLARE curScores CURSOR and not in the primary loop. You must Declare and then deallocate the secon cursor in the primary loop.
244,009
<p>In my Rails controller, I'm creating multiple instances of the same model class. I want to add some RSpec expectations so I can test that it is creating the correct number with the correct parameters. So, here's what I have in my spec:</p> <pre> Bandmate.should_receive(:create).with(:band_id => @band.id, :user_id...
[ { "answer_id": 248742, "author": "James Baker", "author_id": 9365, "author_profile": "https://Stackoverflow.com/users/9365", "pm_score": 6, "selected": true, "text": "<p>Multiple expectations are not a problem at all. What you're running into are ordering problems, given your specific a...
2008/10/28
[ "https://Stackoverflow.com/questions/244009", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19964/" ]
In my Rails controller, I'm creating multiple instances of the same model class. I want to add some RSpec expectations so I can test that it is creating the correct number with the correct parameters. So, here's what I have in my spec: ``` Bandmate.should_receive(:create).with(:band_id => @band.id, :user_id => @user....
Multiple expectations are not a problem at all. What you're running into are ordering problems, given your specific args on unordered expectations. Check [this page](http://rspec.info/documentation/3.3/rspec-mocks/#Ordering) for details on ordering expectations. The short story is that you should add `.ordered` to the...
244,085
<p>Delphi 2009 complains with an E2283 error: [DCC Error] outputcode.pas(466): E2283 Too many local constants. Use shorter procedures</p> <p>Delphi 2007 compiles just fine. I can't find an abundance of local constants, it's a short (500 line) unit. Do you see any abundance of constants or literals I can address?</p> ...
[ { "answer_id": 244108, "author": "Ian Boyd", "author_id": 12597, "author_profile": "https://Stackoverflow.com/users/12597", "pm_score": 2, "selected": false, "text": "<p>Is Win32 defined, could the constants be from all the included units.</p>\n\n<p>i would do a binary search: keep teari...
2008/10/28
[ "https://Stackoverflow.com/questions/244085", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7893/" ]
Delphi 2009 complains with an E2283 error: [DCC Error] outputcode.pas(466): E2283 Too many local constants. Use shorter procedures Delphi 2007 compiles just fine. I can't find an abundance of local constants, it's a short (500 line) unit. Do you see any abundance of constants or literals I can address? ``` procedure ...
Is Win32 defined, could the constants be from all the included units. i would do a binary search: keep tearing half the unit out until it compiles, then add stuff back in. Yes it sucks, but that's one of the features of trying to debug BorlandCodeGaembarcadero's internal compiler errors.
244,087
<p>What are some things I can do to improve query performance of an oracle query without creating indexes?</p> <p>Here is the query I'm trying to run faster:</p> <pre><code>SELECT c.ClaimNumber, a.ItemDate, c.DTN, b.FilePath FROM items a, itempages b, keygroupdata c WHERE a.ItemType IN (112,115,189,241) AND a.ItemNum...
[ { "answer_id": 244101, "author": "EvilTeach", "author_id": 7734, "author_profile": "https://Stackoverflow.com/users/7734", "pm_score": -1, "selected": false, "text": "<p>Remove the ORDER BY</p>\n\n<p>perform the sort, after you pull the rows back to your application.</p>\n" }, { ...
2008/10/28
[ "https://Stackoverflow.com/questions/244087", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2849/" ]
What are some things I can do to improve query performance of an oracle query without creating indexes? Here is the query I'm trying to run faster: ``` SELECT c.ClaimNumber, a.ItemDate, c.DTN, b.FilePath FROM items a, itempages b, keygroupdata c WHERE a.ItemType IN (112,115,189,241) AND a.ItemNum = b.ItemNum AND b.It...
First I'd rewrite the query to be ANSI standard: ``` SELECT c.ClaimNumber, a.ItemDate, c.DTN, b.FilePath FROM items a INNER JOIN itempages b ON b.ItemNum = a.ItemNum INNER JOIN keygroupdata c ON c.ItemNum = b.ItemNum WHERE a.ItemType IN (112,115,189,241) ORDER BY a.DateStored DESC ``` This makes it easier to read an...
244,110
<p>Here's the code. Not much to it.</p> <pre><code>&lt;?php include(&quot;Spreadsheet/Excel/Writer.php&quot;); $xls = new Spreadsheet_Excel_Writer(); $sheet = $xls-&gt;addWorksheet('At a Glance'); $colNames = array('Foo', 'Bar'); $sheet-&gt;writeRow(0, 0, $colNames, $colHeadingFormat); for($i=1; $i&lt;=10; $i++) ...
[ { "answer_id": 244161, "author": "Greg", "author_id": 24181, "author_profile": "https://Stackoverflow.com/users/24181", "pm_score": 1, "selected": false, "text": "<p>Hmm I just installed it to test and didn't get an error - it said Foo like it should.</p>\n\n<p>The file generated was 3,5...
2008/10/28
[ "https://Stackoverflow.com/questions/244110", "https://Stackoverflow.com", "https://Stackoverflow.com/users/305/" ]
Here's the code. Not much to it. ``` <?php include("Spreadsheet/Excel/Writer.php"); $xls = new Spreadsheet_Excel_Writer(); $sheet = $xls->addWorksheet('At a Glance'); $colNames = array('Foo', 'Bar'); $sheet->writeRow(0, 0, $colNames, $colHeadingFormat); for($i=1; $i<=10; $i++) { $row = array( "foo $i", "bar $i...
The code in the question has a bug which causes the error. This line writes a bunch of column names to row 0 ``` $sheet->writeRow(0, 0, $colNames, $colHeadingFormat); ``` Then we have the loop which is supposed to write out the value rows. ``` for($i=1; $i<=10; $i++) { $row = array( "foo $i", "bar $i"); $...
244,113
<p>I'm working on a stored procedure in SQL Server 2000 with a temp table defined like this:</p> <pre>CREATE TABLE #MapTable (Category varchar(40), Code char(5))</pre> <p>After creating the table I want to insert some standard records (which will then be supplemented dynamically in the procedure). Each category (abo...
[ { "answer_id": 244158, "author": "DJ.", "author_id": 10492, "author_profile": "https://Stackoverflow.com/users/10492", "pm_score": 0, "selected": false, "text": "<p>This might work for you:</p>\n\n<pre><code>CREATE TABLE #MapTable (Category varchar(40), Code char(5))\n\nINSERT INTO #MapT...
2008/10/28
[ "https://Stackoverflow.com/questions/244113", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3043/" ]
I'm working on a stored procedure in SQL Server 2000 with a temp table defined like this: ``` CREATE TABLE #MapTable (Category varchar(40), Code char(5)) ``` After creating the table I want to insert some standard records (which will then be supplemented dynamically in the procedure). Each category (about 10) will ha...
``` insert into #maptable (category, code) select 'foo1', b.bar from ( select 'bar11' as bar union select 'bar12' union select 'bar13' ) b union select 'foo2', b.bar from ( select 'bar21' as bar union select 'bar22' union select 'bar23' ) b ```
244,115
<p>Just for my own purposes, I'm trying to build a tokenizer in Java where I can define a regular grammar and have it tokenize input based on that. The StringTokenizer class is deprecated, and I've found a couple functions in Scanner that hint towards what I want to do, but no luck yet. Anyone know a good way of going ...
[ { "answer_id": 244236, "author": "Balint Pato", "author_id": 19621, "author_profile": "https://Stackoverflow.com/users/19621", "pm_score": 2, "selected": false, "text": "<p>If I understand your question well then here are two example methods to tokenize a string. You do not even need the...
2008/10/28
[ "https://Stackoverflow.com/questions/244115", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1370/" ]
Just for my own purposes, I'm trying to build a tokenizer in Java where I can define a regular grammar and have it tokenize input based on that. The StringTokenizer class is deprecated, and I've found a couple functions in Scanner that hint towards what I want to do, but no luck yet. Anyone know a good way of going abo...
The name "Scanner" is a bit misleading, because the word is often used to mean a lexical analyzer, and that's not what Scanner is for. All it is is a substitute for the `scanf()` function you find in C, Perl, *et al*. Like StringTokenizer and `split()`, it's designed to scan ahead until it finds a match for a given pat...
244,119
<p>Can anoyne recommend a good library that will let me easily read/write private member fields of a class? I was looking through apache commons, but couldnt see it. I must be getting blind ?</p> <p>Edit: Asking questions on the border of legalities always give these questions of "why"? I am writing several javarebel ...
[ { "answer_id": 244146, "author": "Ken Gentle", "author_id": 8709, "author_profile": "https://Stackoverflow.com/users/8709", "pm_score": 1, "selected": false, "text": "<p>The <code>java.lang.reflect</code> package classes and methods allow this access, within certain limits.</p>\n\n<p>See...
2008/10/28
[ "https://Stackoverflow.com/questions/244119", "https://Stackoverflow.com", "https://Stackoverflow.com/users/23691/" ]
Can anoyne recommend a good library that will let me easily read/write private member fields of a class? I was looking through apache commons, but couldnt see it. I must be getting blind ? Edit: Asking questions on the border of legalities always give these questions of "why"? I am writing several javarebel plugins fo...
In most of the cases java [reflection](http://java.sun.com/j2se/1.5.0/docs/api/java/lang/reflect/package-summary.html) solves the problem: Example: ``` public class Foo { /** * Gets the name Field. * * @return the name */ public final String getName() { return name; } /*...
244,152
<p>I have a site that requires Windows Authentication the application obtains the credential from the Security.Prinicipal once the user is autenticated the problem is that my credentials on my local environment are different that the ones stored in the DB and the user preferences cannot be obtain. i am doing the follow...
[ { "answer_id": 244195, "author": "Brian Lee", "author_id": 4548, "author_profile": "https://Stackoverflow.com/users/4548", "pm_score": 0, "selected": false, "text": "<p>Have you looked into using Impersonation in Web.Config to set the id to your test credentials. I would presume that yo...
2008/10/28
[ "https://Stackoverflow.com/questions/244152", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14440/" ]
I have a site that requires Windows Authentication the application obtains the credential from the Security.Prinicipal once the user is autenticated the problem is that my credentials on my local environment are different that the ones stored in the DB and the user preferences cannot be obtain. i am doing the following...
While you could alter userBL, why wouldn't you instead alter the database records to reflect that they're in a different domain. I'm assuming you're not hitting the production database, so there should be no issues with a 'sanitizing' step that makes the database useable for dev/test. e.g. ``` UPDATE Users SET ...
244,157
<p>I am trying to read an XML-file from another server. However the the company that's hosting me seems to have turned of the file_get_contents function from retrieving files for files from other servers (and their support is not very bright and it takes forever for them to answer). So I need a work around in some way....
[ { "answer_id": 244163, "author": "Ross", "author_id": 2025, "author_profile": "https://Stackoverflow.com/users/2025", "pm_score": 0, "selected": false, "text": "<p>The ini var you're referring to is <code>allow_url_fopen</code>. To check, run this script:</p>\n\n<pre><code>var_dump(ini_g...
2008/10/28
[ "https://Stackoverflow.com/questions/244157", "https://Stackoverflow.com", "https://Stackoverflow.com/users/27943/" ]
I am trying to read an XML-file from another server. However the the company that's hosting me seems to have turned of the file\_get\_contents function from retrieving files for files from other servers (and their support is not very bright and it takes forever for them to answer). So I need a work around in some way. ...
You could use [cURL](http://www.php.net/curl) (if that's not been disabled). Something like this: ``` $c = curl_init($url); curl_setopt($c, CURLOPT_RETURNTRANSFER, true); $xmlstr = curl_exec($c); ```
244,164
<p>I need to resize PNG, JPEG and GIF files. How can I do this using Java?</p>
[ { "answer_id": 244177, "author": "Burkhard", "author_id": 12860, "author_profile": "https://Stackoverflow.com/users/12860", "pm_score": 8, "selected": true, "text": "<p>After loading the image you can try:</p>\n\n<pre><code>BufferedImage createResizedCopy(Image originalImage, \n ...
2008/10/28
[ "https://Stackoverflow.com/questions/244164", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2011/" ]
I need to resize PNG, JPEG and GIF files. How can I do this using Java?
After loading the image you can try: ``` BufferedImage createResizedCopy(Image originalImage, int scaledWidth, int scaledHeight, boolean preserveAlpha) { System.out.println("resizing..."); int imageType = preserveAlpha ? BufferedImage.TYPE_INT_RGB : BufferedImage.TYPE_INT_...
244,181
<p>I'm trying to use the VssGet task of the MSBuild Community Tasks, and the error message "File or project not found" is beating me with a stick. I can't figure out what in particular the error message is referring to. Here's the task:</p> <pre><code>&lt;LocalFilePath Include="C:\Documents and Settings\michaelc\My ...
[ { "answer_id": 244250, "author": "dpurrington", "author_id": 5573, "author_profile": "https://Stackoverflow.com/users/5573", "pm_score": 3, "selected": true, "text": "<p>Two thoughts. One, sometimes a type load exception manifests as a FNF - let's hope that's not it. But if the code is...
2008/10/28
[ "https://Stackoverflow.com/questions/244181", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16964/" ]
I'm trying to use the VssGet task of the MSBuild Community Tasks, and the error message "File or project not found" is beating me with a stick. I can't figure out what in particular the error message is referring to. Here's the task: ``` <LocalFilePath Include="C:\Documents and Settings\michaelc\My Documents\Visual St...
Two thoughts. One, sometimes a type load exception manifests as a FNF - let's hope that's not it. But if the code is actually being honest, you can track the problem using [Procmon](http://technet.microsoft.com/en-us/sysinternals/bb896645.aspx) or [Filemon](http://technet.microsoft.com/en-us/sysinternals/bb896642.aspx)...
244,183
<p>I'm working on a site which contains a whole bunch of mp3s and images, and I'd like to display a loading gif while all the content loads. </p> <p>I have no idea how to achieve this, but I do have the animated gif I want to use. </p> <p>Any suggestions?</p>
[ { "answer_id": 244190, "author": "mmattax", "author_id": 1638, "author_profile": "https://Stackoverflow.com/users/1638", "pm_score": 6, "selected": true, "text": "<p>Typically sites that do this by loading content via ajax and listening to the <code>readystatechanged</code> event to upda...
2008/10/28
[ "https://Stackoverflow.com/questions/244183", "https://Stackoverflow.com", "https://Stackoverflow.com/users/27171/" ]
I'm working on a site which contains a whole bunch of mp3s and images, and I'd like to display a loading gif while all the content loads. I have no idea how to achieve this, but I do have the animated gif I want to use. Any suggestions?
Typically sites that do this by loading content via ajax and listening to the `readystatechanged` event to update the DOM with a loading GIF or the content. How are you currently loading your content? The code would be similar to this: ```js function load(url) { // display loading image here... document.getE...
244,191
<p>For example:</p> <pre><code>public void doSomething() { final double MIN_INTEREST = 0.0; // ... } </code></pre> <p>Personally, I would rather see these substitution constants declared statically at the class level. I suppose I'm looking for an "industry viewpoint" on the matter.</p>
[ { "answer_id": 244213, "author": "chills42", "author_id": 23855, "author_profile": "https://Stackoverflow.com/users/23855", "pm_score": 5, "selected": false, "text": "<p>I would think that you should only put them at the class level if they are used by multiple methods. If it is only us...
2008/10/28
[ "https://Stackoverflow.com/questions/244191", "https://Stackoverflow.com", "https://Stackoverflow.com/users/32142/" ]
For example: ``` public void doSomething() { final double MIN_INTEREST = 0.0; // ... } ``` Personally, I would rather see these substitution constants declared statically at the class level. I suppose I'm looking for an "industry viewpoint" on the matter.
My starting position is that every variable or constant should be declared/initialized as close to its first use as possible/practical (i.e. don't break a logical block of code in half, just to declare a few lines closer), and scoped as tightly as possible. -- Unless you can give me a damn good reason why it should be ...
244,192
<p>I have a pattern to match with the string: string pattern = @"asc" I am checking the SQL SELECT query for right syntax, semantics, ... I need to say that in the end of the query string I can have "asc" or "desc". How can it be written in C#?</p>
[ { "answer_id": 244201, "author": "Jon Skeet", "author_id": 22656, "author_profile": "https://Stackoverflow.com/users/22656", "pm_score": 1, "selected": false, "text": "<p>You want the \"alternation\" operator, which is the pipe.</p>\n\n<p>For instance, I believe this would be represented...
2008/10/28
[ "https://Stackoverflow.com/questions/244192", "https://Stackoverflow.com", "https://Stackoverflow.com/users/28298/" ]
I have a pattern to match with the string: string pattern = @"asc" I am checking the SQL SELECT query for right syntax, semantics, ... I need to say that in the end of the query string I can have "asc" or "desc". How can it be written in C#?
That'd look like ``` new Regex("asc$|desc$").IsMatch(yourQuery) ``` assuming that you're mandating that asc/desc is the end of the query. You could also do `(?:asc|desc)$` which is a little cleaner with the single `$`, but less readable.
244,208
<p>I'm using MySQL 5.0.45 on CentOS 5.1.</p> <p><code>SELECT DISTINCT(email) FROM newsletter</code></p> <p>Returns 217259 rows</p> <p><code>SELECT COUNT(DISTINCT(email)) FROM newsletter</code></p> <p>Returns 180698 for the count.</p> <p><code>SELECT COUNT(*) FROM (SELECT DISTINCT(email) FROM newsletter) AS foo</co...
[ { "answer_id": 244225, "author": "John Boker", "author_id": 2847, "author_profile": "https://Stackoverflow.com/users/2847", "pm_score": 2, "selected": false, "text": "<p>could you possibly intersect the differing results to see what the extra rows are?</p>\n" }, { "answer_id": 24...
2008/10/28
[ "https://Stackoverflow.com/questions/244208", "https://Stackoverflow.com", "https://Stackoverflow.com/users/796/" ]
I'm using MySQL 5.0.45 on CentOS 5.1. `SELECT DISTINCT(email) FROM newsletter` Returns 217259 rows `SELECT COUNT(DISTINCT(email)) FROM newsletter` Returns 180698 for the count. `SELECT COUNT(*) FROM (SELECT DISTINCT(email) FROM newsletter) AS foo` Returns 180698 for the count. Shouldn't all 3 queries return the ...
could you possibly intersect the differing results to see what the extra rows are?
244,219
<p>In c# (3.0 or 3.5, so we can use lambdas), is there an elegant way of sorting a list of dates in descending order? I know I can do a straight sort and then reverse the whole thing, </p> <pre><code>docs.Sort((x, y) =&gt; x.StoredDate.CompareTo(y.StoredDate)); docs.Reverse(); </code></pre> <p>but is there a lambda e...
[ { "answer_id": 244221, "author": "jonnii", "author_id": 4590, "author_profile": "https://Stackoverflow.com/users/4590", "pm_score": 4, "selected": false, "text": "<pre><code>docs.Sort((x, y) =&gt; y.StoredDate.CompareTo(x.StoredDate));\n</code></pre>\n\n<p>Should do what you're looking f...
2008/10/28
[ "https://Stackoverflow.com/questions/244219", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2849/" ]
In c# (3.0 or 3.5, so we can use lambdas), is there an elegant way of sorting a list of dates in descending order? I know I can do a straight sort and then reverse the whole thing, ``` docs.Sort((x, y) => x.StoredDate.CompareTo(y.StoredDate)); docs.Reverse(); ``` but is there a lambda expression to do it one step? ...
Though it's untested... ``` docs.Sort((x, y) => y.StoredDate.CompareTo(x.StoredDate)); ``` should be the opposite of what you originally had.
244,222
<p>I have compression enabled within IIS7 and it works as expected on all responses except for those constructed by ASP.NET AJAX. I have a web service that provides data to the client. When the web service is called directly, it is properly compressed. However, when it is called via ASP.NET AJAX, the JSON response i...
[ { "answer_id": 248963, "author": "Keltex", "author_id": 28260, "author_profile": "https://Stackoverflow.com/users/28260", "pm_score": 1, "selected": false, "text": "<p>What browser are you using? There's a bug in IE 6 that causes errors in compression. So ASP.NET AJAX turns off compressi...
2008/10/28
[ "https://Stackoverflow.com/questions/244222", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I have compression enabled within IIS7 and it works as expected on all responses except for those constructed by ASP.NET AJAX. I have a web service that provides data to the client. When the web service is called directly, it is properly compressed. However, when it is called via ASP.NET AJAX, the JSON response is not ...
IIS7 uses the content-encoding to decide whether to compress the response (assuming of course that the browser can accept gzip). They're set in applicationHost.config, and by default the list is ``` <dynamicTypes> <add mimeType="text/*" enabled="true" /> <add mimeType="message/*" enabled="true" /> <add ...
244,243
<p>I ran into the problem that my primary key sequence is not in sync with my table rows. </p> <p>That is, when I insert a new row I get a duplicate key error because the sequence implied in the serial datatype returns a number that already exists.</p> <p>It seems to be caused by import/restores not maintaining the s...
[ { "answer_id": 244251, "author": "Hank Gay", "author_id": 4203, "author_profile": "https://Stackoverflow.com/users/4203", "pm_score": 0, "selected": false, "text": "<p>Try <a href=\"http://www.postgresql.org/docs/7.3/static/sql-reindex.html\" rel=\"nofollow noreferrer\">reindex</a>.</p>\...
2008/10/28
[ "https://Stackoverflow.com/questions/244243", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4196/" ]
I ran into the problem that my primary key sequence is not in sync with my table rows. That is, when I insert a new row I get a duplicate key error because the sequence implied in the serial datatype returns a number that already exists. It seems to be caused by import/restores not maintaining the sequence properly.
``` -- Login to psql and run the following -- What is the result? SELECT MAX(id) FROM your_table; -- Then run... -- This should be higher than the last result. SELECT nextval('your_table_id_seq'); -- If it's not higher... run this set the sequence last to your highest id. -- (wise to run a quick pg_dump first...) ...
244,246
<p>I want to create an alias for a class name. The following syntax would be perfect:</p> <pre><code>public class LongClassNameOrOneThatContainsVersionsOrDomainSpecificName { ... } public class MyName = LongClassNameOrOneThatContainsVersionOrDomainSpecificName; </code></pre> <p>but it won't compile.</p> <hr /> <h2>...
[ { "answer_id": 244255, "author": "Konrad Rudolph", "author_id": 1968, "author_profile": "https://Stackoverflow.com/users/1968", "pm_score": 7, "selected": false, "text": "<p><strong>You can’t</strong>. The next best thing you <em>can</em> do is have <code>using</code> declarations in the...
2008/10/28
[ "https://Stackoverflow.com/questions/244246", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12597/" ]
I want to create an alias for a class name. The following syntax would be perfect: ``` public class LongClassNameOrOneThatContainsVersionsOrDomainSpecificName { ... } public class MyName = LongClassNameOrOneThatContainsVersionOrDomainSpecificName; ``` but it won't compile. --- Example ------- **Note** This ex...
You cannot alias a class name in C#. There are things you can do that are not aliasing a class name in C#. But to answer the original question: you cannot alias a class name in C#. --- **Update:** People are confused why `using` doesn't work. Example: **Form1.cs** ``` private void button1_Click(object sender, Eve...
244,252
<p>I've been looking (without great luck) for the perfect reference card with all the basic sorting algos in C (or maybe in pseudo code). Wikipedia is a terrific source of info but this time I'm looking for something definitely more portable (pocket size if possible) and of course printable. Any suggestion would be muc...
[ { "answer_id": 244258, "author": "BoltBait", "author_id": 20848, "author_profile": "https://Stackoverflow.com/users/20848", "pm_score": 3, "selected": false, "text": "<p>What you need is a book called Algorithms in C by Robert Sedgewick.</p>\n\n<p><a href=\"https://rads.stackoverflow.com...
2008/10/28
[ "https://Stackoverflow.com/questions/244252", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6992/" ]
I've been looking (without great luck) for the perfect reference card with all the basic sorting algos in C (or maybe in pseudo code). Wikipedia is a terrific source of info but this time I'm looking for something definitely more portable (pocket size if possible) and of course printable. Any suggestion would be much a...
I made this for a friend of mine studying C, maybe you will find it helpful: ``` #include <stdlib.h> #include <string.h> static void swap(int *a, int *b) { if (a != b) { int c = *a; *a = *b; *b = c; } } void bubblesort(int *a, int l) { int i, j; for (i = l - 2; i >= 0; i--) ...
244,261
<p>I have a somewhat complicated branching structure at work (at least for me). It is something like this:</p> <pre> Main | 1 | 2 | \ 3 \ Ver2 | 1 | \ 2 \ | ProjectA 3 | 1 </pre> <p>There are 2 branches off of main. "Ver2" which has everyone's ...
[ { "answer_id": 244274, "author": "Konrad Rudolph", "author_id": 1968, "author_profile": "https://Stackoverflow.com/users/1968", "pm_score": 0, "selected": false, "text": "<p>Hmm … your request is a bit unspecific. While there are many recent developments in this general area, they're all...
2008/10/28
[ "https://Stackoverflow.com/questions/244261", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20605/" ]
I have a somewhat complicated branching structure at work (at least for me). It is something like this: ``` Main | 1 | 2 | \ 3 \ Ver2 | 1 | \ 2 \ | ProjectA 3 | 1 ``` There are 2 branches off of main. "Ver2" which has everyone's changes for the...
Mentioning the dragon book and antlr means you've answered your own question. If you're looking for other parser generators you could also check out boost::spirit (<http://spirit.sourceforge.net/>). Depending on what you're trying to achieve you might also want to consider a DSL, which you can either parse yourself o...
244,276
<p>A website I'm working on (using AS2 because it's oldschool) has a larger index .swf file that loads sub-swfs using <code>loadMovie("foo1.swf", placeToShowSwf)</code>. There's <code>foo1.swf</code> through 4, which is silly because the only thing that's different between them is a single number in the address of an x...
[ { "answer_id": 244308, "author": "Ady", "author_id": 31395, "author_profile": "https://Stackoverflow.com/users/31395", "pm_score": 0, "selected": false, "text": "<p>Your function is creating a new XML instance each time, and as a result you will need to define the onLoad function each ti...
2008/10/28
[ "https://Stackoverflow.com/questions/244276", "https://Stackoverflow.com", "https://Stackoverflow.com/users/32139/" ]
A website I'm working on (using AS2 because it's oldschool) has a larger index .swf file that loads sub-swfs using `loadMovie("foo1.swf", placeToShowSwf)`. There's `foo1.swf` through 4, which is silly because the only thing that's different between them is a single number in the address of an xml file that tells it wha...
Perhaps you should double-check that you have proper authorization in `crossdomain.xml`. If your crossdomain file is jacked, none of your requests will go through. <http://crossdomainxml.org/>
244,280
<p>I'm trying to implement a unit test for a function in a project that doesn't have unit tests and this function requires a System.Web.Caching.Cache object as a parameter. I've been trying to create this object by using code such as...</p> <pre><code>System.Web.Caching.Cache cache = new System.Web.Caching.Cache(); ca...
[ { "answer_id": 244293, "author": "chills42", "author_id": 23855, "author_profile": "https://Stackoverflow.com/users/23855", "pm_score": 2, "selected": false, "text": "<p>I think your best bet would be to use a mock object (look into Rhino Mocks).</p>\n" }, { "answer_id": 244331, ...
2008/10/28
[ "https://Stackoverflow.com/questions/244280", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1463/" ]
I'm trying to implement a unit test for a function in a project that doesn't have unit tests and this function requires a System.Web.Caching.Cache object as a parameter. I've been trying to create this object by using code such as... ``` System.Web.Caching.Cache cache = new System.Web.Caching.Cache(); cache.Add(...); ...
When I've been faced with this sort of problem (where the class in question doesn't implement an interface), I often end up writing a wrapper with associated interface around the class in question. Then I use my wrapper in my code. For unit tests, I hand mock the wrapper and insert my own mock object into it. Of cours...
244,285
<p>I've got to get a quick and dirty configuration editor up and running. The flow goes something like this:</p> <p>configuration (POCOs on server) are serialized to XML.<br> The XML is well formed at this point. The configuration is sent to the web server in XElements.<br> On the web server, the XML (Yes, ALL OF IT)...
[ { "answer_id": 244299, "author": "Konrad Rudolph", "author_id": 1968, "author_profile": "https://Stackoverflow.com/users/1968", "pm_score": 4, "selected": true, "text": "<p>Erm … <em>How</em> do you serialize? Usually, the XML serializer should never produce invalid XML.</p>\n\n<p>/EDIT ...
2008/10/28
[ "https://Stackoverflow.com/questions/244285", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I've got to get a quick and dirty configuration editor up and running. The flow goes something like this: configuration (POCOs on server) are serialized to XML. The XML is well formed at this point. The configuration is sent to the web server in XElements. On the web server, the XML (Yes, ALL OF IT) is dumped in...
Erm … *How* do you serialize? Usually, the XML serializer should never produce invalid XML. /EDIT in response to your update: Do **not** display invalid XML to your user to edit! Instead, display the properly escaped XML in the TextBox. Repairing broken XML isn't fun and I actually see no reason not to display/edit th...
244,326
<p>I was wondering if it is possible to do something like this:</p> <pre><code> &lt;uc1:TestControl ID="TestControl1" runat="server"&gt; &lt;div&gt;More random HTML, etc...&lt;/div&gt; &lt;/uc1:TestControl&gt; </code></pre> <p>I got an error of "Type 'System.Web.UI.UserControl' does not have a public p...
[ { "answer_id": 244353, "author": "Dave Ward", "author_id": 60, "author_profile": "https://Stackoverflow.com/users/60", "pm_score": 3, "selected": true, "text": "<p>In a server control, you would create <a href=\"http://msdn.microsoft.com/en-us/library/system.web.ui.itemplate.aspx\" rel=\...
2008/10/28
[ "https://Stackoverflow.com/questions/244326", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2470/" ]
I was wondering if it is possible to do something like this: ``` <uc1:TestControl ID="TestControl1" runat="server"> <div>More random HTML, etc...</div> </uc1:TestControl> ``` I got an error of "Type 'System.Web.UI.UserControl' does not have a public property named 'div'.". Doing a little research, I ...
In a server control, you would create [a property that implements ITemplate](http://msdn.microsoft.com/en-us/library/system.web.ui.itemplate.aspx) to contain that content. I'm not positive whether that is possible in a user control, but it may be.
244,329
<p>Something happened that I'm not sure should be possible. Obviously it is, because I've seen it, but I need to find the root cause &amp; I was hoping you all could help.</p> <p>We have a system that looks up latitude &amp; longitude for a zipcode. Rather than access it every time, we cache the results in a cheap i...
[ { "answer_id": 244352, "author": "David M. Karr", "author_id": 10508, "author_profile": "https://Stackoverflow.com/users/10508", "pm_score": 3, "selected": false, "text": "<p>Why it's happening is hard to tell. More code could help.</p>\n\n<p>You should probably just be using a Concurre...
2008/10/28
[ "https://Stackoverflow.com/questions/244329", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7773/" ]
Something happened that I'm not sure should be possible. Obviously it is, because I've seen it, but I need to find the root cause & I was hoping you all could help. We have a system that looks up latitude & longitude for a zipcode. Rather than access it every time, we cache the results in a cheap in-memory HashTable c...
Why it's happening is hard to tell. More code could help. You should probably just be using a ConcurrentHashMap anyway. This will be more efficient, in general, than a synchronized Map. You don't synchronize access to it, it handles it internally (more efficiently than you could).
244,340
<p>I am getting a DC for a window handle of an object in another program using win32gui.GetDC which returns an int/long. I need to blit this DC into a memory DC in python. The only thing I can't figure out how to do is get a wxDC derived object from the int/long that win32gui returns. None of the wxDC objects allow ...
[ { "answer_id": 253897, "author": "flxkid", "author_id": 13036, "author_profile": "https://Stackoverflow.com/users/13036", "pm_score": 0, "selected": false, "text": "<p>From what I can tell, DCs in python are abstracted due to platform variation. So a device context in python doesn't dir...
2008/10/28
[ "https://Stackoverflow.com/questions/244340", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13036/" ]
I am getting a DC for a window handle of an object in another program using win32gui.GetDC which returns an int/long. I need to blit this DC into a memory DC in python. The only thing I can't figure out how to do is get a wxDC derived object from the int/long that win32gui returns. None of the wxDC objects allow me to ...
I downloaded the wxWidgets source and dug around, and I think this will work. You need the handle (HWND) for the external window, not the DC. ``` window = wx.Frame(None, -1, '') window.AssociateHandle(hwnd) dc = wx.WindowDC(window) ```
244,345
<p>I was watching Rob Connerys webcasts on the MVCStoreFront App, and I noticed he was unit testing even the most mundane things, things like:</p> <pre><code>public Decimal DiscountPrice { get { return this.Price - this.Discount; } } </code></pre> <p>Would have a test like:</p> <pre><code>[TestMethod...
[ { "answer_id": 244349, "author": "Jason Cohen", "author_id": 4926, "author_profile": "https://Stackoverflow.com/users/4926", "pm_score": 7, "selected": true, "text": "<p>First, testing is like security -- you can never be 100% sure you've got it, but each layer adds more confidence and a...
2008/10/28
[ "https://Stackoverflow.com/questions/244345", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1965/" ]
I was watching Rob Connerys webcasts on the MVCStoreFront App, and I noticed he was unit testing even the most mundane things, things like: ``` public Decimal DiscountPrice { get { return this.Price - this.Discount; } } ``` Would have a test like: ``` [TestMethod] public void Test_DiscountPrice { ...
First, testing is like security -- you can never be 100% sure you've got it, but each layer adds more confidence and a framework for more easily fixing the problems that remain. Second, you can break tests into subroutines which themselves can then be tested. When you have 20 similar tests, making a (tested) subroutin...
244,367
<p>What is the correct way to setup a named pipe in C# across a network?</p> <p>Currently I have two machines, 'client' and 'server'.</p> <p>Server sets up its pipe in the following manner:</p> <pre><code>NamedPipeServerStream pipeServer = new NamedPipeServerStream( "pipe", PipeDirection.InOut, 10, P...
[ { "answer_id": 244391, "author": "Joel Coehoorn", "author_id": 3043, "author_profile": "https://Stackoverflow.com/users/3043", "pm_score": 0, "selected": false, "text": "<p>Look in the System.Runtime.Remoting namespace. IIRC, named pipes are one option for the protocol used by remoting ...
2008/10/28
[ "https://Stackoverflow.com/questions/244367", "https://Stackoverflow.com", "https://Stackoverflow.com/users/341413/" ]
What is the correct way to setup a named pipe in C# across a network? Currently I have two machines, 'client' and 'server'. Server sets up its pipe in the following manner: ``` NamedPipeServerStream pipeServer = new NamedPipeServerStream( "pipe", PipeDirection.InOut, 10, PipeTransmissionMode.Byte, ...
It is not possible to used named pipes between machines. "The WCF-NetNamedPipe adapter provides cross-process communication on the **same computer**" <http://msdn.microsoft.com/en-us/library/bb226493.aspx>
244,381
<p>We are using Hibernate Spring MVC with OpenSessionInView filter. Here is a problem we are running into (pseudo code)</p> <pre><code>transaction 1 load object foo transaction 1 end update foo's properties (not calling session.save or session.update but only foo's setters) validate foo (using hibernate validator) ...
[ { "answer_id": 244703, "author": "Elie", "author_id": 23249, "author_profile": "https://Stackoverflow.com/users/23249", "pm_score": 1, "selected": false, "text": "<p>You can run a get on foo to put it into the hibernate session, and then replace it with the object you created elsewhere. ...
2008/10/28
[ "https://Stackoverflow.com/questions/244381", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3332/" ]
We are using Hibernate Spring MVC with OpenSessionInView filter. Here is a problem we are running into (pseudo code) ``` transaction 1 load object foo transaction 1 end update foo's properties (not calling session.save or session.update but only foo's setters) validate foo (using hibernate validator) if validation ...
You can run a get on foo to put it into the hibernate session, and then replace it with the object you created elsewhere. But for this to work, you have to know all the ids for your objects so that the ids will look correct to Hibernate.
244,390
<p>Right now, I have </p> <pre><code>SELECT gp_id FROM gp.keywords WHERE keyword_id = 15 AND (SELECT practice_link FROM gp.practices WHERE practice_link IS NOT NULL AND id = gp_id) </code></pre> <p>This does not provide a syntax error, however for values where it should return row(s), it just returns 0 ...
[ { "answer_id": 244405, "author": "SquareCog", "author_id": 15962, "author_profile": "https://Stackoverflow.com/users/15962", "pm_score": 1, "selected": false, "text": "<p><pre><code>\nselect k.gp_id \nfrom gp.keywords as k,\n gp.practices as p\nwhere\nkeyword_id=15\nand practice_link...
2008/10/28
[ "https://Stackoverflow.com/questions/244390", "https://Stackoverflow.com", "https://Stackoverflow.com/users/572/" ]
Right now, I have ``` SELECT gp_id FROM gp.keywords WHERE keyword_id = 15 AND (SELECT practice_link FROM gp.practices WHERE practice_link IS NOT NULL AND id = gp_id) ``` This does not provide a syntax error, however for values where it should return row(s), it just returns 0 rows. What I'm trying to ...
I'm not even sure that is valid SQL, so I'm surprised it is working at all: ``` SELECT gp_id FROM gp.keywords WHERE keyword_id = 15 AND (SELECT practice_link FROM gp.practices WHERE practice_link IS NOT NULL AND id = gp_id) ``` How about this instead: ``` SELECT kw.gp_id, p.practice_link FROM gp.keywords AS kw ...
244,392
<p>Here's the quick and skinny of my issue:</p> <pre>$("a").toggle(function() { /*function A*/ }, function() { /*function B*/ });</pre> <p>Inside <code>function A</code> a form is displayed. If the user successfully completes the form, the form is hidden again (returning to it's original state).</p> <p>Inside <code...
[ { "answer_id": 244468, "author": "foxy", "author_id": 30119, "author_profile": "https://Stackoverflow.com/users/30119", "pm_score": 5, "selected": true, "text": "<p>jQuery has two <code>.toggle()</code> methods:</p>\n\n<p><a href=\"http://api.jquery.com/toggle/\" rel=\"nofollow noreferre...
2008/10/28
[ "https://Stackoverflow.com/questions/244392", "https://Stackoverflow.com", "https://Stackoverflow.com/users/32154/" ]
Here's the quick and skinny of my issue: ``` $("a").toggle(function() { /*function A*/ }, function() { /*function B*/ }); ``` Inside `function A` a form is displayed. If the user successfully completes the form, the form is hidden again (returning to it's original state). Inside `function B` the same form is hidden....
jQuery has two `.toggle()` methods: [`.toggle()`](http://api.jquery.com/toggle/) > > Toggles each of the set of matched > elements. If they are shown, toggle > makes them hidden. If they are hidden, > toggle makes them shown. > > > [`.toggle(even, odd)`](https://api.jquery.com/toggle-event/) > > Toggle betw...
244,408
<p>I've got two collections (generic Lists), let's call them ListA and ListB.</p> <p>In ListA I've got a few items of type A. In ListB I've got some items of type B that have the SAME ID (but not same type) as the items in ListA, plus many more. I want to remove all the items from ListB that have the same ID as the on...
[ { "answer_id": 244426, "author": "Elie", "author_id": 23249, "author_profile": "https://Stackoverflow.com/users/23249", "pm_score": 0, "selected": false, "text": "<p>simple loop:</p>\n\n<pre><code>for (item i: LISTA) {\n removeItem(i, LISTB);\n}\n\n\nmethod removeItem(Item, List) {\n ...
2008/10/28
[ "https://Stackoverflow.com/questions/244408", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3397/" ]
I've got two collections (generic Lists), let's call them ListA and ListB. In ListA I've got a few items of type A. In ListB I've got some items of type B that have the SAME ID (but not same type) as the items in ListA, plus many more. I want to remove all the items from ListB that have the same ID as the ones in List...
I discovered that lambda expressions was a perfect match. Instead of a long linq to objects method, I could do it in just a few lines with lambda: ``` foreach(TypeA objectA in listA){ listB.RemoveAll(objectB => objectB.Id == objectA.Id); } ```
244,431
<p>I have two assemblies with the same name in the Global Assembly cache, but with different version numbers. How do I tell my program which version to reference?</p> <p>For the record, this is a VB.Net page in an ASP.Net web site.</p>
[ { "answer_id": 244440, "author": "Joel Coehoorn", "author_id": 3043, "author_profile": "https://Stackoverflow.com/users/3043", "pm_score": 2, "selected": false, "text": "<p>To install an assembly in the GAC you have to give it a strong name. Strong names are never duplicated. So to spe...
2008/10/28
[ "https://Stackoverflow.com/questions/244431", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19074/" ]
I have two assemblies with the same name in the Global Assembly cache, but with different version numbers. How do I tell my program which version to reference? For the record, this is a VB.Net page in an ASP.Net web site.
As long as the version number is different (which would be required), you can specify the proper version through your web.config file. This is how I have things setup in one of my apps to reference the proper version of Crystal Reports, since we have multiple versions in the GAC: ``` <system.web> <compilation> ...
244,438
<p>Imagine I have these python lists:</p> <pre><code>keys = ['name', 'age'] values = ['Monty', 42, 'Matt', 28, 'Frank', 33] </code></pre> <p>Is there a direct or at least a simple way to produce the following list of dictionaries ?</p> <pre><code>[ {'name': 'Monty', 'age': 42}, {'name': 'Matt', 'age': 28}, ...
[ { "answer_id": 244455, "author": "Cheery", "author_id": 21711, "author_profile": "https://Stackoverflow.com/users/21711", "pm_score": 2, "selected": false, "text": "<p>Dumb way, but one that comes immediately to my mind:</p>\n\n<pre><code>def fields_from_list(keys, values):\n iterator...
2008/10/28
[ "https://Stackoverflow.com/questions/244438", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12388/" ]
Imagine I have these python lists: ``` keys = ['name', 'age'] values = ['Monty', 42, 'Matt', 28, 'Frank', 33] ``` Is there a direct or at least a simple way to produce the following list of dictionaries ? ``` [ {'name': 'Monty', 'age': 42}, {'name': 'Matt', 'age': 28}, {'name': 'Frank', 'age': 33} ] `...
Here is the zip way ``` def mapper(keys, values): n = len(keys) return [dict(zip(keys, values[i:i + n])) for i in range(0, len(values), n)] ```
244,452
<h1>My situation</h1> <ul> <li>Input: a set of rectangles </li> <li>each rect is comprised of 4 doubles like this: (x0,y0,x1,y1)</li> <li>they are not "rotated" at any angle, all they are "normal" rectangles that go "up/down" and "left/right" with respect to the screen</li> <li>they are randomly placed - they may be t...
[ { "answer_id": 244458, "author": "Toon Krijthe", "author_id": 18061, "author_profile": "https://Stackoverflow.com/users/18061", "pm_score": 0, "selected": false, "text": "<p>You can find the overlap on the x and on the y axis and multiply those. </p>\n\n<pre><code>int LineOverlap(int lin...
2008/10/28
[ "https://Stackoverflow.com/questions/244452", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13477/" ]
My situation ============ * Input: a set of rectangles * each rect is comprised of 4 doubles like this: (x0,y0,x1,y1) * they are not "rotated" at any angle, all they are "normal" rectangles that go "up/down" and "left/right" with respect to the screen * they are randomly placed - they may be touching at the edges, ove...
An efficient way of computing this area is to use a sweep algorithm. Let us assume that we sweep a vertical line L(x) through the union of rectangles U: * first of all, you need to build an event queue Q, which is, in this case, the ordered list of all x-coordinates (left and right) of the rectangles. * during the sw...
244,482
<p>Developing a heavily XML-based Java-application, I recently encountered an interesting problem on Ubuntu Linux.</p> <p>My application, using the <a href="http://jpf.sourceforge.net/" rel="noreferrer">Java Plugin Framework</a>, appears unable to convert a <a href="http://www.dom4j.org/" rel="noreferrer">dom4j</a>-cr...
[ { "answer_id": 244707, "author": "matt b", "author_id": 4249, "author_profile": "https://Stackoverflow.com/users/4249", "pm_score": 5, "selected": false, "text": "<p>Sounds like a classloader hierarchy problem. I can't tell what type of environment your application is deployed in, but so...
2008/10/28
[ "https://Stackoverflow.com/questions/244482", "https://Stackoverflow.com", "https://Stackoverflow.com/users/25141/" ]
Developing a heavily XML-based Java-application, I recently encountered an interesting problem on Ubuntu Linux. My application, using the [Java Plugin Framework](http://jpf.sourceforge.net/), appears unable to convert a [dom4j](http://www.dom4j.org/)-created XML document to [Batik's](http://xmlgraphics.apache.org/bati...
LinkageError is what you'll get in a classic case where you have a class C loaded by more than one classloader and those classes are being used together in the same code (compared, cast, etc). It doesn't matter if it is the same Class name or even if it's loaded from the identical jar - a Class from one classloader is ...
244,489
<p>I have a managed dll that calls into a native library. This native library generally returns IntPtrs. These can be passed in to other methods in the native library to do things, or to tell the library to free the instance associated with the IntPtr. But only some of the instances need to freed in this way, others...
[ { "answer_id": 244707, "author": "matt b", "author_id": 4249, "author_profile": "https://Stackoverflow.com/users/4249", "pm_score": 5, "selected": false, "text": "<p>Sounds like a classloader hierarchy problem. I can't tell what type of environment your application is deployed in, but so...
2008/10/28
[ "https://Stackoverflow.com/questions/244489", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I have a managed dll that calls into a native library. This native library generally returns IntPtrs. These can be passed in to other methods in the native library to do things, or to tell the library to free the instance associated with the IntPtr. But only some of the instances need to freed in this way, others are m...
LinkageError is what you'll get in a classic case where you have a class C loaded by more than one classloader and those classes are being used together in the same code (compared, cast, etc). It doesn't matter if it is the same Class name or even if it's loaded from the identical jar - a Class from one classloader is ...
244,506
<p>Given a list of urls, I would like to check that each url:</p> <ul> <li>Returns a 200 OK status code</li> <li>Returns a response within X amount of time</li> </ul> <p>The end goal is a system that is capable of flagging urls as potentially broken so that an administrator can review them.</p> <p>The script will be...
[ { "answer_id": 244513, "author": "Serge Wautier", "author_id": 12379, "author_profile": "https://Stackoverflow.com/users/12379", "pm_score": 2, "selected": false, "text": "<ol>\n<li>fopen() supports http URI.</li>\n<li>If you need more flexibility (such as timeout), look into the cURL ex...
2008/10/28
[ "https://Stackoverflow.com/questions/244506", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3238/" ]
Given a list of urls, I would like to check that each url: * Returns a 200 OK status code * Returns a response within X amount of time The end goal is a system that is capable of flagging urls as potentially broken so that an administrator can review them. The script will be written in PHP and will most likely run o...
Use the PHP cURL extension. Unlike fopen() it can also make HTTP HEAD requests which are sufficient to check the availability of a URL and save you a ton of bandwith as you don't have to download the entire body of the page to check. As a starting point you could use some function like this: ``` function is_available...
244,509
<p>I'm planning to make a very simple program using php and mySQL. The main page will take information and make a new row in the database with that information. However, I need a number to put in for the primary key. Unfortunately, I have no idea about the normal way to determine what umber to use. Preferably, if I del...
[ { "answer_id": 244514, "author": "Thomas Owens", "author_id": 572, "author_profile": "https://Stackoverflow.com/users/572", "pm_score": 2, "selected": false, "text": "<p>AUTOINCREMENT is what you want. As long as you don't change the table's settings, AUTOINCREMENT will continue to grow....
2008/10/28
[ "https://Stackoverflow.com/questions/244509", "https://Stackoverflow.com", "https://Stackoverflow.com/users/25680/" ]
I'm planning to make a very simple program using php and mySQL. The main page will take information and make a new row in the database with that information. However, I need a number to put in for the primary key. Unfortunately, I have no idea about the normal way to determine what umber to use. Preferably, if I delete...
In MySQL that's the [standard solution.](http://dev.mysql.com/doc/refman/5.0/en/example-auto-increment.html) ``` CREATE TABLE animals ( id MEDIUMINT NOT NULL AUTO_INCREMENT, name CHAR(30) NOT NULL, PRIMARY KEY (id) ); ```
244,517
<p>Where is a reliable registry key to find install location of Excel 2007?</p>
[ { "answer_id": 244578, "author": "Travis Collins", "author_id": 30460, "author_profile": "https://Stackoverflow.com/users/30460", "pm_score": 0, "selected": false, "text": "<p>HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Office\\12.0\\Excel\\InstallRoot\\</p>\n" }, { "answer_id": 244...
2008/10/28
[ "https://Stackoverflow.com/questions/244517", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16794/" ]
Where is a reliable registry key to find install location of Excel 2007?
How about: ``` [HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Office\X.0\Common\InstallRoot] ``` > > which contains a key named 'Path' with > the installation directory of that > version of Office. This is consistent > for Excel 8.0 through 12.0. If you > want to look for a specific product, > use Excel, Word, Access,...
244,522
<p>I am writing a web application that will run in kiosk mode on a touch screen. I am currently only targeting it for running on Firefox 3. A few of the use cases I have need to visit external sites. I wish to do so with an embedded browser, which I'm tackling with the help of an <code>&lt;iframe&gt;</code>. I need bac...
[ { "answer_id": 244742, "author": "davr", "author_id": 14569, "author_profile": "https://Stackoverflow.com/users/14569", "pm_score": 1, "selected": false, "text": "<p>You might want to take a look at <a href=\"http://www.adobe.com/products/air/develop/ajax/\" rel=\"nofollow noreferrer\">A...
2008/10/28
[ "https://Stackoverflow.com/questions/244522", "https://Stackoverflow.com", "https://Stackoverflow.com/users/27349/" ]
I am writing a web application that will run in kiosk mode on a touch screen. I am currently only targeting it for running on Firefox 3. A few of the use cases I have need to visit external sites. I wish to do so with an embedded browser, which I'm tackling with the help of an `<iframe>`. I need back/forward buttons fo...
Because there is only one history object shared within each tab this seems impossible. The proper way around it would be to test `window.history.current` or `window.history.previous` before calling back. Unfortunately, `window.history.current` is privileged and so not available to unsigned pages. Here's a rough sketch...
244,531
<p>I need to search a string and replace all occurrences of <code>%FirstName%</code> and <code>%PolicyAmount%</code> with a value pulled from a database. The problem is the capitalization of FirstName varies. That prevents me from using the <code>String.Replace()</code> method. I've seen web pages on the subject that s...
[ { "answer_id": 244539, "author": "Joel Coehoorn", "author_id": 3043, "author_profile": "https://Stackoverflow.com/users/3043", "pm_score": 0, "selected": false, "text": "<pre><code>Regex.Replace(strInput, strToken.Replace(\"$\", \"[$]\"), strReplaceWith, RegexOptions.IgnoreCase);\n</code...
2008/10/28
[ "https://Stackoverflow.com/questions/244531", "https://Stackoverflow.com", "https://Stackoverflow.com/users/21155/" ]
I need to search a string and replace all occurrences of `%FirstName%` and `%PolicyAmount%` with a value pulled from a database. The problem is the capitalization of FirstName varies. That prevents me from using the `String.Replace()` method. I've seen web pages on the subject that suggest ``` Regex.Replace(strInput, ...
[From MSDN](http://msdn.microsoft.com/en-us/library/ewy2t5e0.aspx) $0 - "Substitutes the last substring matched by group number number (decimal)." In .NET Regular expressions group 0 is always the entire match. For a literal $ you need to ``` string value = Regex.Replace("%PolicyAmount%", "%PolicyAmount%", @"$$0",...
244,588
<p>I was kind of scratching my head at this a week ago, and now with a little bit more Cocoa experience under my belt I feel like I have an inkling as to what might be going on. </p> <p>I'm making an application that is driven by a UINavigationController. In the AppDelegate, I create an instance of this class, using "...
[ { "answer_id": 244661, "author": "Louis Gerbarg", "author_id": 30506, "author_profile": "https://Stackoverflow.com/users/30506", "pm_score": 2, "selected": false, "text": "<p>There are a couple of ways you can handle this. The simplest is probably just to add a UIViewController property ...
2008/10/28
[ "https://Stackoverflow.com/questions/244588", "https://Stackoverflow.com", "https://Stackoverflow.com/users/543/" ]
I was kind of scratching my head at this a week ago, and now with a little bit more Cocoa experience under my belt I feel like I have an inkling as to what might be going on. I'm making an application that is driven by a UINavigationController. In the AppDelegate, I create an instance of this class, using "page 1" as...
I would recommend using the delegation pattern to solve your problem. Create a property ``` @property (nonatomic, assign) id <MyModalViewDelegate> delegate; ``` And a corresponding protocol ``` @protocol MyModalViewDelegate @optional - (void)myModalViewControllerDidFinish:(MyModalViewController *)aModalViewCont...
244,591
<p>This is baffling me, maybe somebody can shine the light of education on my ignorance. This is in a C# windows app. I am accessing the contents of a listbox from a thread. When I try to access it like this<pre><code>prgAll.Maximum = lbFolders.SelectedItems.Count;</code></pre> I get the error. However, here is the...
[ { "answer_id": 244604, "author": "arul", "author_id": 15409, "author_profile": "https://Stackoverflow.com/users/15409", "pm_score": 4, "selected": true, "text": "<pre><code>prgAll.Maximum = lbFolders.SelectedItems.Count;\n</code></pre>\n\n<p>On that line you perform an assignment (<stron...
2008/10/28
[ "https://Stackoverflow.com/questions/244591", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19038/" ]
This is baffling me, maybe somebody can shine the light of education on my ignorance. This is in a C# windows app. I am accessing the contents of a listbox from a thread. When I try to access it like this ``` prgAll.Maximum = lbFolders.SelectedItems.Count; ``` I get the error. However, here is the part I don't get. If...
``` prgAll.Maximum = lbFolders.SelectedItems.Count; ``` On that line you perform an assignment (**set/add**), which by default is not thread-safe. On the second line it's just a **get** operation, where thread-safety merely doesn't matter. EDIT: I don't mean access to the prgAll element. Accessing the Count proper...
244,601
<p>I have YAML data that looks sort of like this, but ~150k of it:</p> <pre><code>--- all: foo: 1025 bar: baz: 37628 quux: a: 179 b: 7 </code></pre> <p>...or the same thing in JSON:</p> <pre><code>{"all":{"bar":{"baz":"37628","quux":{"a":"179","b":"7"}},"foo":"1025"}} </code></pre> <p>I want...
[ { "answer_id": 245117, "author": "user32225", "author_id": 32225, "author_profile": "https://Stackoverflow.com/users/32225", "pm_score": 1, "selected": false, "text": "<p>Version 2.6 of YUI's TreeView now does take a JavaScript object but not in this format and won't sort it automaticall...
2008/10/28
[ "https://Stackoverflow.com/questions/244601", "https://Stackoverflow.com", "https://Stackoverflow.com/users/31100/" ]
I have YAML data that looks sort of like this, but ~150k of it: ``` --- all: foo: 1025 bar: baz: 37628 quux: a: 179 b: 7 ``` ...or the same thing in JSON: ``` {"all":{"bar":{"baz":"37628","quux":{"a":"179","b":"7"}},"foo":"1025"}} ``` I want to present this content in an expandable JavaScr...
I finally came up with a super-elegant way to do this in about 5 lines of code, based on the fact that the simple [YAML](http://en.wikipedia.org/wiki/YAML) looks a lot like [Markdown](http://en.wikipedia.org/wiki/Markdown). We're starting off with this: ``` --- all: foo: 1025 bar: baz: 37628 quux: a...
244,639
<p>I have a medium size Java file. Everytime I make a change to one of my files, BuildTable.java, Git reports it as a massive change, even if is only a line or two. BuildTable.java is about 200 lines and the change in this commit only changed a single line.</p> <p>git-diff ouputs this:</p> <pre><code>--- a/src/BuildT...
[ { "answer_id": 244713, "author": "ddaa", "author_id": 11549, "author_profile": "https://Stackoverflow.com/users/11549", "pm_score": 5, "selected": false, "text": "<p>Clearly, git does not like your mac-style line endings (CR only). Its diff algorithm uses LF as the line separator.</p>\n\...
2008/10/28
[ "https://Stackoverflow.com/questions/244639", "https://Stackoverflow.com", "https://Stackoverflow.com/users/85/" ]
I have a medium size Java file. Everytime I make a change to one of my files, BuildTable.java, Git reports it as a massive change, even if is only a line or two. BuildTable.java is about 200 lines and the change in this commit only changed a single line. git-diff ouputs this: ``` --- a/src/BuildTable.java +++ b/src/B...
To fix this, I didn't need to change any of the core git settings, as the default line endings being generated were fine, it was just that this particular file was mangled. To fix it I opened vim and executed the following command ``` :%s/^M/\r/g ``` Note that to type the "^M" you have to type ctrl-V and then ctrl-M...
244,640
<p>I am having difficulty refreshing windows forms controls that are using a BindingSource object. We have a CAB/MVP/SCSF client that I (actually “we” since it is a team effort) are developing that will interact with WCF services running on a remote server. (This is our first attempt at this, so we are in a learning m...
[ { "answer_id": 244983, "author": "Alan", "author_id": 31223, "author_profile": "https://Stackoverflow.com/users/31223", "pm_score": 0, "selected": false, "text": "<p>Failing all else, you can reassign the DataSource every time you receive a new dataset, doing something like this:</p>\n\n...
2008/10/28
[ "https://Stackoverflow.com/questions/244640", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I am having difficulty refreshing windows forms controls that are using a BindingSource object. We have a CAB/MVP/SCSF client that I (actually “we” since it is a team effort) are developing that will interact with WCF services running on a remote server. (This is our first attempt at this, so we are in a learning mode)...
I was having a similar issue today and found this works. ``` private void btnCancel_Click(object sender, EventArgs e) { this.MyTable.RejectChanges(); this.txtMyBoundTextBox.DataBindings[0].ReadValue(); this.EditState = EditStates.NotEditting; } ```
244,646
<p>I'm looking for the equivalent in Qt to <code>GetTickCount()</code></p> <p>Something that will allow me to measure the time it takes for a segment of code to run as in:</p> <pre><code>uint start = GetTickCount(); // do something.. uint timeItTook = GetTickCount() - start; </code></pre> <p>any suggestions?</p>
[ { "answer_id": 244676, "author": "Dusty Campbell", "author_id": 2174, "author_profile": "https://Stackoverflow.com/users/2174", "pm_score": 8, "selected": true, "text": "<p>How about <a href=\"http://doc.qt.io/qt-5/qtime.html\" rel=\"noreferrer\"><code>QTime</code></a>? Depending on you...
2008/10/28
[ "https://Stackoverflow.com/questions/244646", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9611/" ]
I'm looking for the equivalent in Qt to `GetTickCount()` Something that will allow me to measure the time it takes for a segment of code to run as in: ``` uint start = GetTickCount(); // do something.. uint timeItTook = GetTickCount() - start; ``` any suggestions?
How about [`QTime`](http://doc.qt.io/qt-5/qtime.html)? Depending on your platform it should have 1 millisecond accuracy. Code would look something like this: ``` QTime myTimer; myTimer.start(); // do something.. int nMilliseconds = myTimer.elapsed(); ```
244,665
<p>This is the css for setting the color for h1 text that is linked:</p> <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"> <div class="snippet-code"> <pre class="snippet-code-css lang-css prettyprint-override"><code>.nav-left h1 a, a:visited { color: #055830; }</co...
[ { "answer_id": 244670, "author": "Toon Krijthe", "author_id": 18061, "author_profile": "https://Stackoverflow.com/users/18061", "pm_score": 4, "selected": true, "text": "<p>What about:</p>\n\n<pre><code>.nav-left h1 a:visited{\n color:#055830;\n}\n</code></pre>\n" }, { "answer...
2008/10/28
[ "https://Stackoverflow.com/questions/244665", "https://Stackoverflow.com", "https://Stackoverflow.com/users/26130/" ]
This is the css for setting the color for h1 text that is linked: ```css .nav-left h1 a, a:visited { color: #055830; } ``` ```html <div class="nav-left"> <h1><a href="/index.php/housing/">Housing</a></h1> </div> ``` It does not look like it is working appropriately, any help is appreciated.
What about: ``` .nav-left h1 a:visited{ color:#055830; } ```
244,671
<p>I'm looking for an UPDATE statement where it will update a single duplicate row only and remain the rest (duplicate rows) intact as is, using ROWID or something else or other elements to utilize in Oracle SQL or PL/SQL?</p> <p>Here is an example duptest table to work with:</p> <pre><code>CREATE TABLE duptest (ID ...
[ { "answer_id": 244757, "author": "Brian Schmitt", "author_id": 30492, "author_profile": "https://Stackoverflow.com/users/30492", "pm_score": 4, "selected": false, "text": "<p>Will this work for you:</p>\n\n<pre><code>update duptest \nset nonid = 'c'\nWHERE ROWID IN (SELECT MIN (ROWID)\...
2008/10/28
[ "https://Stackoverflow.com/questions/244671", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I'm looking for an UPDATE statement where it will update a single duplicate row only and remain the rest (duplicate rows) intact as is, using ROWID or something else or other elements to utilize in Oracle SQL or PL/SQL? Here is an example duptest table to work with: ``` CREATE TABLE duptest (ID VARCHAR2(5), NONID VA...
Will this work for you: ``` update duptest set nonid = 'c' WHERE ROWID IN (SELECT MIN (ROWID) FROM duptest GROUP BY id, nonid) ```
244,677
<p>Can it be known in general whether or not placing a case within a for loop will result in bad assembly. I'm interested mainly in Delphi, but this is an interesting programming question, both in terms of style and performance. </p> <p>Here are my codez!</p> <pre> case ResultList.CompareType of TextCompareType: ...
[ { "answer_id": 244687, "author": "Toon Krijthe", "author_id": 18061, "author_profile": "https://Stackoverflow.com/users/18061", "pm_score": 3, "selected": true, "text": "<p>Why not using subclasses? </p>\n\n<p>This saves the use of the case statement.</p>\n\n<pre><code>TComparer = class ...
2008/10/28
[ "https://Stackoverflow.com/questions/244677", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1765/" ]
Can it be known in general whether or not placing a case within a for loop will result in bad assembly. I'm interested mainly in Delphi, but this is an interesting programming question, both in terms of style and performance. Here are my codez! ``` case ResultList.CompareType of TextCompareType: begin ...
Why not using subclasses? This saves the use of the case statement. ``` TComparer = class protected function Compare(const AItem1, AItem2: TItem): Boolean; virtual; abstract; public procedure DoCompare(ResultList: ...); end; TTextComparer = class (TComparer) protected function Compare(const AItem1, AItem2: T...
244,680
<p>Can someone explain what this means?</p> <pre><code>int (*data[2])[2]; </code></pre>
[ { "answer_id": 244692, "author": "Brian R. Bondy", "author_id": 3153, "author_profile": "https://Stackoverflow.com/users/3153", "pm_score": 7, "selected": true, "text": "<p><strong>What are the parentheses for?</strong></p>\n\n<p>In C brackets [] have a higher precedence than the asteris...
2008/10/28
[ "https://Stackoverflow.com/questions/244680", "https://Stackoverflow.com", "https://Stackoverflow.com/users/32185/" ]
Can someone explain what this means? ``` int (*data[2])[2]; ```
**What are the parentheses for?** In C brackets [] have a higher precedence than the asterisk \* **Good explanation from Wikipedia:** > > To declare a variable as being a > pointer to an array, we must make use > of parentheses. This is because in C > brackets ([]) have higher precedence > than the asterisk (\*...
244,695
<p>The structures of my Git repositories look like this:</p> <pre><code>A-B-C-D-E-F # master branch in separate repo1 A-B-C-D-E-G-H # master branch in separate repo2 </code></pre> <p>A-H are simple commits. As you can see the repositories are related (repo2 is a fork of repo1). I'm trying to combine these two repos...
[ { "answer_id": 244710, "author": "Jim Puls", "author_id": 6010, "author_profile": "https://Stackoverflow.com/users/6010", "pm_score": 3, "selected": false, "text": "<p>Your picture suggests that you don't really want to \"combine the two repositories\" so much as merge commits G and H in...
2008/10/28
[ "https://Stackoverflow.com/questions/244695", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20467/" ]
The structures of my Git repositories look like this: ``` A-B-C-D-E-F # master branch in separate repo1 A-B-C-D-E-G-H # master branch in separate repo2 ``` A-H are simple commits. As you can see the repositories are related (repo2 is a fork of repo1). I'm trying to combine these two repositories in one. Afterward...
You can treat another git repository on the same filesystem as a remote repo. In the first, do the following: ``` git remote add <name> /path/to/other/repo/.git git fetch <name> git branch <name> <name>/master #optional ``` Now they're both branches in a single repository. You can switch between them with git check...
244,715
<p>I'm debating the best way to propagate fairly complex permissions from the server to an AJAX application, and I'm not sure the best approach to take.</p> <p>Essentially, I want my permissions to be defined so I can request a whole set of permissions in one shot, and adjust the UI as appropriate (the UI changes can ...
[ { "answer_id": 244814, "author": "Diodeus - James MacFarlane", "author_id": 12579, "author_profile": "https://Stackoverflow.com/users/12579", "pm_score": -1, "selected": false, "text": "<p>Encode them as <a href=\"http://json.org\" rel=\"nofollow noreferrer\">JSON</a>.</p>\n" }, { ...
2008/10/28
[ "https://Stackoverflow.com/questions/244715", "https://Stackoverflow.com", "https://Stackoverflow.com/users/25330/" ]
I'm debating the best way to propagate fairly complex permissions from the server to an AJAX application, and I'm not sure the best approach to take. Essentially, I want my permissions to be defined so I can request a whole set of permissions in one shot, and adjust the UI as appropriate (the UI changes can be as low ...
If you have a clear set of permissions, like a "user level" or "user type", you could just pass the value down in a hidden field and access the value through the DOM. You could still do this if your permissions were more granular, but you would either have a lot of hidden fields or you would have to encode the informat...
244,719
<p>I'm trying to get a bare-bones example of logging going in my ASP.NET application. I would like to use the My.Log functionality to write out error log messages to a text log file. I have tried several things via Google but none of them seem to work. In general, when I use any of the properties of My.Log.DefaultFileW...
[ { "answer_id": 244740, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 3, "selected": true, "text": "<p><a href=\"https://learn.microsoft.com/en-us/dotnet/visual-basic/developing-apps/programming/log-info/walkthrough-changing-wh...
2008/10/28
[ "https://Stackoverflow.com/questions/244719", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1607294/" ]
I'm trying to get a bare-bones example of logging going in my ASP.NET application. I would like to use the My.Log functionality to write out error log messages to a text log file. I have tried several things via Google but none of them seem to work. In general, when I use any of the properties of My.Log.DefaultFileWrit...
[Walkthrough: Changing Where My.Application.Log Writes Information](https://learn.microsoft.com/en-us/dotnet/visual-basic/developing-apps/programming/log-info/walkthrough-changing-where-my-application-log-writes-information)
244,720
<p>Because I need to display a <a href="http://codeflow.org/ubuntu.png" rel="nofollow noreferrer">huge number of labels</a> that <a href="http://www.youtube.com/watch?v=A_ah-SE-cNY" rel="nofollow noreferrer">move independently</a>, I need to render a label in <a href="http://pyglet.org" rel="nofollow noreferrer">pyglet...
[ { "answer_id": 246962, "author": "unwind", "author_id": 28169, "author_profile": "https://Stackoverflow.com/users/28169", "pm_score": 0, "selected": false, "text": "<p>Isn't that when you use decaling, through <code><a href=\"http://www.opengl.org/documentation/specs/man_pages/hardcopy/G...
2008/10/28
[ "https://Stackoverflow.com/questions/244720", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19435/" ]
Because I need to display a [huge number of labels](http://codeflow.org/ubuntu.png) that [move independently](http://www.youtube.com/watch?v=A_ah-SE-cNY), I need to render a label in [pyglet](http://pyglet.org) to a texture (otherwise updating the vertex list for each glyph is too slow). I have a solution to do this, ...
You want to set `glEnable(GL_COLOR_MATERIAL)`. This makes the texture color mix with the current OpenGL color. You can also use the `glColorMaterial` function to specify whether the front/back/both of each polygon should be affected. Docs [here](http://www.glprogramming.com/blue/ch05.html#id37922).
244,758
<p>So this might be really simple, but I haven't been able to find any examples to learn off of yet, so please bear with me. ;) </p> <p>Here's basically what I want to do:</p> <pre><code>&lt;div&gt;Lots of content! Lots of content! Lots of content! ...&lt;/div&gt; .... $("div").html("Itsy-bitsy bit of content!"); ...
[ { "answer_id": 244847, "author": "lucas", "author_id": 31172, "author_profile": "https://Stackoverflow.com/users/31172", "pm_score": 3, "selected": false, "text": "<p>maybe something like this?</p>\n\n<pre><code>$(\".testLink\").click(function(event) {\n event.preventDefault();\n $...
2008/10/28
[ "https://Stackoverflow.com/questions/244758", "https://Stackoverflow.com", "https://Stackoverflow.com/users/32154/" ]
So this might be really simple, but I haven't been able to find any examples to learn off of yet, so please bear with me. ;) Here's basically what I want to do: ``` <div>Lots of content! Lots of content! Lots of content! ...</div> .... $("div").html("Itsy-bitsy bit of content!"); ``` I want to smoothly animate ...
Try this jQuery plugin: ``` // Animates the dimensional changes resulting from altering element contents // Usage examples: // $("#myElement").showHtml("new HTML contents"); // $("div").showHtml("new HTML contents", 400); // $(".className").showHtml("new HTML contents", 400, // function()...
244,772
<p>I'm creating a series of builders to clean up the syntax which creates domain classes for my mocks as part of improving our overall unit tests. My builders essentially populate a domain class (such as a <code>Schedule</code>) with some values determined by invoking the appropriate <code>WithXXX</code> and chaining ...
[ { "answer_id": 244805, "author": "Jon Skeet", "author_id": 22656, "author_profile": "https://Stackoverflow.com/users/22656", "pm_score": 5, "selected": true, "text": "<p>All I can say is that if there <em>is</em> a way of doing it, I want to know about it too - I use <em>exactly</em> thi...
2008/10/28
[ "https://Stackoverflow.com/questions/244772", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5645/" ]
I'm creating a series of builders to clean up the syntax which creates domain classes for my mocks as part of improving our overall unit tests. My builders essentially populate a domain class (such as a `Schedule`) with some values determined by invoking the appropriate `WithXXX` and chaining them together. I've encou...
All I can say is that if there *is* a way of doing it, I want to know about it too - I use *exactly* this pattern in my [Protocol Buffers port](http://github.com/jskeet/dotnet-protobufs/tree/master). In fact, I'm glad to see that someone else has resorted to it - it means we're at least somewhat likely to be right!
244,777
<p>Can I use comments inside a <a href="https://en.wikipedia.org/wiki/JSON" rel="noreferrer">JSON</a> file? If so, how?</p>
[ { "answer_id": 244795, "author": "Cheery", "author_id": 21711, "author_profile": "https://Stackoverflow.com/users/21711", "pm_score": 7, "selected": false, "text": "<p>You can't. At least that's my experience from a quick glance at <a href=\"http://json.org\" rel=\"noreferrer\">json.org<...
2008/10/28
[ "https://Stackoverflow.com/questions/244777", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4105/" ]
Can I use comments inside a [JSON](https://en.wikipedia.org/wiki/JSON) file? If so, how?
No. JSON is data-only. If you include a comment, then it must be data too. You could have a designated data element called `"_comment"` (or something) that should be ignored by apps that use the JSON data. You would probably be better having the comment in the processes that generates/receives the JSON, as they are ...
244,779
<p>I have the following <code>before_filter</code>:</p> <pre><code> def find_current_membership respond_to do |wants| wants.html { @current_membership = @group.memberships.for(@current_user) } wants.rss {} wants.js { @current_membership = @group.memberships.for(@current_user) } end end ...
[ { "answer_id": 244831, "author": "jonnii", "author_id": 4590, "author_profile": "https://Stackoverflow.com/users/4590", "pm_score": 2, "selected": false, "text": "<p>In this case you could probably do something like:</p>\n\n<pre><code>before_filter :only =&gt; :find_current_membership do...
2008/10/28
[ "https://Stackoverflow.com/questions/244779", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14895/" ]
I have the following `before_filter`: ``` def find_current_membership respond_to do |wants| wants.html { @current_membership = @group.memberships.for(@current_user) } wants.rss {} wants.js { @current_membership = @group.memberships.for(@current_user) } end end ``` I would like to sha...
If I'm reading this right, it looks like `find_current_membership` is your `before_filter` method, is that right? eg: ``` class SomeController < ApplicationController before_filter :find_current_membership ... ``` I think it's a bit non-standard to use `respond_to` inside a `before_filter`, they are meant to jus...
244,807
<p>I have a c# site which makes use of a lot of images with embedded english text. </p> <p>How can I use a standard resource file to swap out images depending on the language?</p> <p>I have a resx file in my App_GlobalResources directory, but I can't seem to get it plugged into an asp:image control for the imageurl ...
[ { "answer_id": 244830, "author": "Oscar Cabrero", "author_id": 14440, "author_profile": "https://Stackoverflow.com/users/14440", "pm_score": 4, "selected": true, "text": "<p>you can store the url of the image in your resource file and use the following inline code in the control </p>\n\n...
2008/10/28
[ "https://Stackoverflow.com/questions/244807", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2424/" ]
I have a c# site which makes use of a lot of images with embedded english text. How can I use a standard resource file to swap out images depending on the language? I have a resx file in my App\_GlobalResources directory, but I can't seem to get it plugged into an asp:image control for the imageurl correctly. Ideas...
you can store the url of the image in your resource file and use the following inline code in the control ``` <asp:Image ImageUrl="<%$resources:Image1 %>" /> ``` ### Update this [link](http://aspalliance.com/726) could be helpful on what you are trying to accomplish or you can also try to stored the resource as...
244,812
<p>I have an existing database with the table Transactions in it. I have added a new table called TransactionSequence where each transaction will ultimately have only one record. We are using the sequence table to count transactions for a given account. I have mapped this as a one-to-one mapping where TransactionSequen...
[ { "answer_id": 244871, "author": "jonnii", "author_id": 4590, "author_profile": "https://Stackoverflow.com/users/4590", "pm_score": 5, "selected": true, "text": "<p>One to one mapping in nhibernate doesn't work the way you think it does. It's designed so that you have two classes, which...
2008/10/28
[ "https://Stackoverflow.com/questions/244812", "https://Stackoverflow.com", "https://Stackoverflow.com/users/32196/" ]
I have an existing database with the table Transactions in it. I have added a new table called TransactionSequence where each transaction will ultimately have only one record. We are using the sequence table to count transactions for a given account. I have mapped this as a one-to-one mapping where TransactionSequence ...
One to one mapping in nhibernate doesn't work the way you think it does. It's designed so that you have two classes, which when persisted to their corresponding tables have the same primary keys. However you can make it work, but it's not pretty. I'll show you how then offer up some alternatives: In your Transaction ...
244,826
<p>I'm stuck with .Net 1.1 application (i.e. I can not use the generics goodies from 2.0 for now), and I was trying to optimize some parts of the code. As it deals a lot with runtime callable wrappers, which need to be released, I ended up to create a utility method which loops until all references are released. The si...
[ { "answer_id": 244838, "author": "Jon Skeet", "author_id": 22656, "author_profile": "https://Stackoverflow.com/users/22656", "pm_score": 3, "selected": true, "text": "<p>Why is it better to call a method than to just set the variable to null? They're both single line calls, and the latte...
2008/10/28
[ "https://Stackoverflow.com/questions/244826", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8220/" ]
I'm stuck with .Net 1.1 application (i.e. I can not use the generics goodies from 2.0 for now), and I was trying to optimize some parts of the code. As it deals a lot with runtime callable wrappers, which need to be released, I ended up to create a utility method which loops until all references are released. The signa...
Why is it better to call a method than to just set the variable to null? They're both single line calls, and the latter is a lot simpler. It does sound very odd that you need to set them to null in the first place though. Are these static variables, or instance variables whose values need to be released earlier than t...