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
224,009
<p>Session variables are normally keept in the web server RAM memory.</p> <p>In a cluster, each request made by a client can be handled by a different cluster node. right?!</p> <p>So, in this case... </p> <ul> <li>What happens with session variables? Aren't they stored in the nodes RAM memory? </li> <li>How the oth...
[ { "answer_id": 224012, "author": "Chris Roberts", "author_id": 475, "author_profile": "https://Stackoverflow.com/users/475", "pm_score": 0, "selected": false, "text": "<p>In ASP.NET you can persist session data to an SQL Server database which is common to all web servers in the cluster.<...
2008/10/22
[ "https://Stackoverflow.com/questions/224009", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1100/" ]
Session variables are normally keept in the web server RAM memory. In a cluster, each request made by a client can be handled by a different cluster node. right?! So, in this case... * What happens with session variables? Aren't they stored in the nodes RAM memory? * How the other nodes will handled my request corr...
There are 3 ways to store session state in ASP.NET. The first is in process, where the variables are stored in memory. The second is to use a session state service by putting the following in your web.config file: ``` <sessionState mode="StateServer" stateConnectionString="tcpip=127.0.0.1:42424" sqlConnect...
224,026
<p>I've started to use constructs like these:</p> <pre><code>class DictObj(object): def __init__(self): self.d = {} def __getattr__(self, m): return self.d.get(m, None) def __setattr__(self, m, v): super.__setattr__(self, m, v) </code></pre> <p>Update: based on this thread, I've re...
[ { "answer_id": 224051, "author": "Smashery", "author_id": 14902, "author_profile": "https://Stackoverflow.com/users/14902", "pm_score": 2, "selected": false, "text": "<p>As far as I know, Python classes use dictionaries to store their attributes anyway (that's hidden from the programmer)...
2008/10/22
[ "https://Stackoverflow.com/questions/224026", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13055/" ]
I've started to use constructs like these: ``` class DictObj(object): def __init__(self): self.d = {} def __getattr__(self, m): return self.d.get(m, None) def __setattr__(self, m, v): super.__setattr__(self, m, v) ``` Update: based on this thread, I've revised the DictObj implemen...
This is a simpler version of your DictObj class: ``` class DictObj(object): def __getattr__(self, attr): return self.__dict__.get(attr) >>> d = DictObj() >>> d.something = 'one' >>> print d.something one >>> print d.somethingelse None >>> ```
224,038
<p>My $SHELL is tcsh. I want to run a C shell script that will call a program many times with some arguments changed each time. The program I need to call is in Fortran. I do not want to edit it. The program only takes arguments once it is executed, but not on the command line. Upon calling the program in the script, t...
[ { "answer_id": 224045, "author": "freespace", "author_id": 8297, "author_profile": "https://Stackoverflow.com/users/8297", "pm_score": 0, "selected": false, "text": "<p>Not a <code>tcsh</code> user, but if the program runs then reads in commands via <code>stdin</code> then you can use sh...
2008/10/22
[ "https://Stackoverflow.com/questions/224038", "https://Stackoverflow.com", "https://Stackoverflow.com/users/30181/" ]
My $SHELL is tcsh. I want to run a C shell script that will call a program many times with some arguments changed each time. The program I need to call is in Fortran. I do not want to edit it. The program only takes arguments once it is executed, but not on the command line. Upon calling the program in the script, the ...
To add to what @Toybuilder said, you can use a "here document". I.e. your script could have ``` ./myfortranprogram << EOF first line of input second line of input EOF ``` Everything between the "`<<EOF`" and the "`EOF`" will be fed to the program's standard input (does Fortran still use "read (5,\*)" to read from st...
224,040
<p>What is the most elegant way to calculate the previous business day in shell ksh script ?</p> <p>What I got until now is :</p> <pre><code>#!/bin/ksh set -x DAY_DIFF=1 case `date '+%a'` in "Sun") DAY_DIFF=2 ;; "Mon") DAY_DIFF=3 ;; esac PREV_DT=`perl -e '($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$...
[ { "answer_id": 224428, "author": "Jonathan Leffler", "author_id": 15168, "author_profile": "https://Stackoverflow.com/users/15168", "pm_score": 0, "selected": false, "text": "<p>Well, if running Perl counts as part of the script, then develop the answer in Perl. The next question is - w...
2008/10/22
[ "https://Stackoverflow.com/questions/224040", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
What is the most elegant way to calculate the previous business day in shell ksh script ? What I got until now is : ``` #!/bin/ksh set -x DAY_DIFF=1 case `date '+%a'` in "Sun") DAY_DIFF=2 ;; "Mon") DAY_DIFF=3 ;; esac PREV_DT=`perl -e '($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst)=localtime(time...
Here is a solution that doesn't use Perl. It works both with `ksh` and `sh`. ``` #!/bin/ksh diff=-1 [ `date +%u` == 1 ] && diff=-3 seconds=$((`date +%s` + $diff * 24 * 3600)) format=+%Y-%m-%d if date --help 2>/dev/null | grep -q -- -d ; then # GNU date (e.g., Linux) date -d "1970-01-01 00:00 UTC + $seconds ...
224,059
<p>When I was taking CS in college (mid 80's), one of the ideas that was constantly repeated was to always write loops which test at the top (while...) rather than at the bottom (do ... while) of the loop. These notions were often backed up with references to studies which showed that loops which tested at the top were...
[ { "answer_id": 224074, "author": "Chris Bunch", "author_id": 422, "author_profile": "https://Stackoverflow.com/users/422", "pm_score": 1, "selected": false, "text": "<p>I write mine pretty much exclusively testing at the top. It's less code, so for me at least, it's less potential to scr...
2008/10/22
[ "https://Stackoverflow.com/questions/224059", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4086/" ]
When I was taking CS in college (mid 80's), one of the ideas that was constantly repeated was to always write loops which test at the top (while...) rather than at the bottom (do ... while) of the loop. These notions were often backed up with references to studies which showed that loops which tested at the top were st...
I always follow the rule that if it should run zero or more times, test at the beginning, if it must run *once* or more, test at the end. I do not see any logical reason to use the code you listed in your example. It only adds complexity.
224,078
<p>I am trying to hide some divs before the user prints this giant form, then display the divs again afterward. Thus I want to ignore the rest of the page, and only print the form itself.</p> <p>Sure I <em>could</em> open a separate page when the user clicks the print button. The only thing is that the form is really ...
[ { "answer_id": 224084, "author": "Micky McQuade", "author_id": 12908, "author_profile": "https://Stackoverflow.com/users/12908", "pm_score": 5, "selected": false, "text": "<h2>First, The Ok Way:</h2>\n\n<p>Take a look at window.onbeforeprint and window.onafterprint (the original question...
2008/10/22
[ "https://Stackoverflow.com/questions/224078", "https://Stackoverflow.com", "https://Stackoverflow.com/users/131/" ]
I am trying to hide some divs before the user prints this giant form, then display the divs again afterward. Thus I want to ignore the rest of the page, and only print the form itself. Sure I *could* open a separate page when the user clicks the print button. The only thing is that the form is really long and it would...
IE supports `onbeforeprint` and `onafterprint`, but what you really want is a print stylesheet. ``` <link rel="stylesheet" type="text/css" media="print" href="print.css"> ``` See also: [this answer](https://stackoverflow.com/questions/224078/how-to-print-only-parts-of-a-page#224084)
224,106
<p>How do I extend my parent's options array for child classes in PHP?</p> <p>I have something like this:</p> <pre><code>class ParentClass { public $options = array( 'option1'=&gt;'setting1' ); //The rest of the functions would follow } </code></pre> <p>I would like to append to that optio...
[ { "answer_id": 224121, "author": "Czimi", "author_id": 3906, "author_profile": "https://Stackoverflow.com/users/3906", "pm_score": 4, "selected": true, "text": "<p>I think it is better practice to initialize this property in the constructor and then you can extend the value in any descen...
2008/10/22
[ "https://Stackoverflow.com/questions/224106", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13281/" ]
How do I extend my parent's options array for child classes in PHP? I have something like this: ``` class ParentClass { public $options = array( 'option1'=>'setting1' ); //The rest of the functions would follow } ``` I would like to append to that options array in a child class without er...
I think it is better practice to initialize this property in the constructor and then you can extend the value in any descendant class: ``` <?php class ParentClass { public $options; public function __construct() { $this->options = array( 'option1'=>'setting1' ); } //The re...
224,128
<p>Currently, if I want to apply a method to a group of ActiveRecord objects, I have to structure the call like so:</p> <pre><code>messages = Message.find(:all) csv = Message.to_csv(messages) </code></pre> <p>How can I define the method so it's structured like so?</p> <pre><code>messages = Message.find(:all) csv = m...
[ { "answer_id": 224140, "author": "mwilliams", "author_id": 23909, "author_profile": "https://Stackoverflow.com/users/23909", "pm_score": 0, "selected": false, "text": "<p>You could create a method on your Message class to do something along the lines of...</p>\n\n<p>In your controller......
2008/10/22
[ "https://Stackoverflow.com/questions/224128", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
Currently, if I want to apply a method to a group of ActiveRecord objects, I have to structure the call like so: ``` messages = Message.find(:all) csv = Message.to_csv(messages) ``` How can I define the method so it's structured like so? ``` messages = Message.find(:all) csv = messages.to_csv ``` This is the curr...
The following will call to\_csv on all instances included in the messages array. ``` messages = Message.find(:all) csv = messages.map { |message| message.to_csv } ``` In Rails, in Ruby 1.9 or with Symbol#to\_proc available through other means, you can also shorten it to: ``` csv = messages.map(&:to_csv) ``` The l...
224,130
<p>I'm sure this is going to be a long shot, but I need help with a query involving QuickBooks Items.</p> <p>I need to query for all QuickBooks Items that are linked to an Income account. Is there an easy way to do this, or do I need to make 2 queries (one for items ans one for accounts) and then check the account ref...
[ { "answer_id": 337047, "author": "Keith Palmer Jr.", "author_id": 26133, "author_profile": "https://Stackoverflow.com/users/26133", "pm_score": 1, "selected": false, "text": "<p>You need to use at least two queries. You'll need to fetch a list of accounts, and then compare the items Acco...
2008/10/22
[ "https://Stackoverflow.com/questions/224130", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1638/" ]
I'm sure this is going to be a long shot, but I need help with a query involving QuickBooks Items. I need to query for all QuickBooks Items that are linked to an Income account. Is there an easy way to do this, or do I need to make 2 queries (one for items ans one for accounts) and then check the account reference? a...
You need to use at least two queries. You'll need to fetch a list of accounts, and then compare the items AccountRef FullName to the income accounts in the list.
224,138
<p>In the spirit of questions like <a href="https://stackoverflow.com/questions/224059/do-your-loops-test-at-the-top-or-bottom">Do your loops test at the top or bottom?</a>:</p> <p>Which style do you use for an <em>infinite</em> loop, and why?</p> <ul> <li>while (true) { }</li> <li>do { } while (true);</li> <li>for (...
[ { "answer_id": 224142, "author": "JPrescottSanders", "author_id": 19444, "author_profile": "https://Stackoverflow.com/users/19444", "pm_score": 5, "selected": false, "text": "<pre><code>while(true) {}\n</code></pre>\n\n<p>It seems to convey the meaning of the loop most effectively.</p>\n...
2008/10/22
[ "https://Stackoverflow.com/questions/224138", "https://Stackoverflow.com", "https://Stackoverflow.com/users/28258/" ]
In the spirit of questions like [Do your loops test at the top or bottom?](https://stackoverflow.com/questions/224059/do-your-loops-test-at-the-top-or-bottom): Which style do you use for an *infinite* loop, and why? * while (true) { } * do { } while (true); * for (;;) { } * label: ... goto label;
``` while(true) {} ``` It seems to convey the meaning of the loop most effectively.
224,155
<p>I have something here that is really catching me off guard.</p> <p>I have an ObservableCollection of T that is filled with items. I also have an event handler attached to the CollectionChanged event.</p> <p>When you <strong>Clear</strong> the collection it causes an CollectionChanged event with e.Action set to Not...
[ { "answer_id": 224169, "author": "tvanfosson", "author_id": 12950, "author_profile": "https://Stackoverflow.com/users/12950", "pm_score": 2, "selected": false, "text": "<p>Looking at the <a href=\"http://msdn.microsoft.com/en-us/library/system.collections.specialized.notifycollectionchan...
2008/10/22
[ "https://Stackoverflow.com/questions/224155", "https://Stackoverflow.com", "https://Stackoverflow.com/users/22294/" ]
I have something here that is really catching me off guard. I have an ObservableCollection of T that is filled with items. I also have an event handler attached to the CollectionChanged event. When you **Clear** the collection it causes an CollectionChanged event with e.Action set to NotifyCollectionChangedAction.Res...
Ok, even though I still wish that ObservableCollection behaved as I wished ... the code below is what I ended up doing. Basically, I created a new collection of T called TrulyObservableCollection and overrided the ClearItems method which I then used to raise a Clearing event. In the code that uses this TrulyObservable...
224,163
<p>I currently capture MiniDumps of unhandled exceptions using <Code>SetUnhandledExceptionFilter</Code> however at times I am getting "R6025: pure virtual function".</p> <p>I understand how a pure virtual function call happens I am just wondering if it is possible to capture them so I can create a MiniDump at that poi...
[ { "answer_id": 224176, "author": "1800 INFORMATION", "author_id": 3146, "author_profile": "https://Stackoverflow.com/users/3146", "pm_score": 4, "selected": false, "text": "<p>See <a href=\"https://stackoverflow.com/questions/99552/where-do-pure-virtual-function-call-crashes-come-from#10...
2008/10/22
[ "https://Stackoverflow.com/questions/224163", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1675/" ]
I currently capture MiniDumps of unhandled exceptions using `SetUnhandledExceptionFilter` however at times I am getting "R6025: pure virtual function". I understand how a pure virtual function call happens I am just wondering if it is possible to capture them so I can create a MiniDump at that point.
If you want to catch all crashes you have to do more than just: SetUnhandledExceptionFilter I would also set the abort handler, the purecall handler, unexpected, terminate, and invalid parameter handler. ``` #include <signal.h> inline void signal_handler(int) { terminator(); } inline void terminator() { in...
224,181
<p>When I add a reference to <strong>Microsoft.Office.Interop.Excel</strong> on my computer, Visual Studio adds this to the project file:</p> <pre><code>&lt;COMReference Include="Excel"&gt; &lt;Guid&gt;{00020813-0000-0000-C000-000000000046}&lt;/Guid&gt; &lt;VersionMajor&gt;1&lt;/VersionMajor&gt; &lt;VersionMinor...
[ { "answer_id": 224203, "author": "Charles Graham", "author_id": 7705, "author_profile": "https://Stackoverflow.com/users/7705", "pm_score": 0, "selected": false, "text": "<p>I've used Excel automation way more than I would like to admitt, and I have never referenced Interop.Excel.dll. I...
2008/10/22
[ "https://Stackoverflow.com/questions/224181", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10786/" ]
When I add a reference to **Microsoft.Office.Interop.Excel** on my computer, Visual Studio adds this to the project file: ``` <COMReference Include="Excel"> <Guid>{00020813-0000-0000-C000-000000000046}</Guid> <VersionMajor>1</VersionMajor> <VersionMinor>5</VersionMinor> <Lcid>0</Lcid> <WrapperTool>primary</W...
I don't see a problem with your approach either. Typically VS will generate an interop assembly for COM components automatically when you add a reference to the component. However, when you add a reference to one of the Office components (XP or any later version), a reference to the pregenerated (and optimized) prima...
224,185
<p>I'm experimenting with a personal finance application, and I'm thinking about what approach to take to update running balances when entering a transaction in an account.</p> <p>Currently the way I'm using involves retrieving all records more recent than the inserted/modified one, and go one by one incrementing thei...
[ { "answer_id": 224199, "author": "Scott Bennett-McLeish", "author_id": 1915, "author_profile": "https://Stackoverflow.com/users/1915", "pm_score": 2, "selected": false, "text": "<p>Some sort of Identity / Auto-increment columnn in there would be wise as well, purely for the transaction o...
2008/10/22
[ "https://Stackoverflow.com/questions/224185", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16957/" ]
I'm experimenting with a personal finance application, and I'm thinking about what approach to take to update running balances when entering a transaction in an account. Currently the way I'm using involves retrieving all records more recent than the inserted/modified one, and go one by one incrementing their running ...
I think this might work: I was using both the date and the id to order the transactions, but now I'm going to store both the date and the id on one column, and use that for ordering. So, using comparisons (like >) should always work as expected, right? (as opposed to the situation I describe earlier where two columns ...
224,200
<p>Thanks a million everyone for everyone's response. Unfortunately, none of the solutions appear to be working on my end, and my guess is that the example I've provided is messed up.</p> <p>So let me try again.</p> <p>My table looks like this:</p> <pre><code> contract project activity row1 1000 8000 ...
[ { "answer_id": 224210, "author": "vfilby", "author_id": 24279, "author_profile": "https://Stackoverflow.com/users/24279", "pm_score": 4, "selected": false, "text": "<p><strong>Updated to use your newly provided data:</strong></p>\n\n<p>The solutions using the original data may be found a...
2008/10/22
[ "https://Stackoverflow.com/questions/224200", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
Thanks a million everyone for everyone's response. Unfortunately, none of the solutions appear to be working on my end, and my guess is that the example I've provided is messed up. So let me try again. My table looks like this: ``` contract project activity row1 1000 8000 10 row2 1000 8000 2...
**Updated to use your newly provided data:** The solutions using the original data may be found at the end of this answer. Using your new data: ``` DECLARE @T TABLE( [contract] INT, project INT, activity INT ) INSERT INTO @T VALUES( 1000, 8000, 10 ) INSERT INTO @T VALUES( 1000, 8000, 20 ) INSERT INTO @T...
224,204
<p>Another poster asked about <a href="https://stackoverflow.com/questions/224138/infinite-loops-top-or-bottom">preferred syntax for infinite loops</a>.</p> <p>A follow-up question: <i>Why</i> do you use infinite loops in your code? I typically see a construct like this:</p> <pre><code>for (;;) { int scoped_variabl...
[ { "answer_id": 224209, "author": "AShelly", "author_id": 10396, "author_profile": "https://Stackoverflow.com/users/10396", "pm_score": 4, "selected": false, "text": "<p>I use an infinite loop for the body of my embedded control code, since it is designed to run forever once it is started...
2008/10/22
[ "https://Stackoverflow.com/questions/224204", "https://Stackoverflow.com", "https://Stackoverflow.com/users/23786/" ]
Another poster asked about [preferred syntax for infinite loops](https://stackoverflow.com/questions/224138/infinite-loops-top-or-bottom). A follow-up question: *Why* do you use infinite loops in your code? I typically see a construct like this: ``` for (;;) { int scoped_variable = getSomeValue(); if (scoped_vari...
A loop like: ``` while (true) { // do something if (something else) break; // do more } ``` lets you break out of the loop in the middle, rather than at the start (while/for) or end (do-while). If you've got a complex condition, you might also want to use this style to make the code clearer.
224,225
<p>How would you program a C/C++ application that could run without opening a window or console? </p>
[ { "answer_id": 224226, "author": "Brian R. Bondy", "author_id": 3153, "author_profile": "https://Stackoverflow.com/users/3153", "pm_score": 4, "selected": false, "text": "<p><strong>In windows:</strong></p>\n\n<pre><code>#include &lt;windows.h&gt;\n\nint APIENTRY WinMain(HINSTANCE hInsta...
2008/10/22
[ "https://Stackoverflow.com/questions/224225", "https://Stackoverflow.com", "https://Stackoverflow.com/users/27211/" ]
How would you program a C/C++ application that could run without opening a window or console?
When you write a WinMain program, you automatically get the /SUBSYSTEM option to be windows in the compiler. (Assuming you use Visual Studio). For any other compiler a similar option might be present but the flag name might be different. This causes the compiler to create an entry in the executable file format ([PE f...
224,234
<p>I'm using an istream which could be stringstream, ifstream or a user-defined stream type and I need to know if, in the case of an ifstream, it was not opened in binary mode (so I can throw an exception). I have tried the following method:</p> <pre><code>if ((_is.flags() &amp; ios::binary) == 0) throw exception(...
[ { "answer_id": 224258, "author": "C. Broadbent", "author_id": 28859, "author_profile": "https://Stackoverflow.com/users/28859", "pm_score": 3, "selected": false, "text": "<p>Nope, there is no way to test this.</p>\n" }, { "answer_id": 224259, "author": "Greg Rogers", "aut...
2008/10/22
[ "https://Stackoverflow.com/questions/224234", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4086/" ]
I'm using an istream which could be stringstream, ifstream or a user-defined stream type and I need to know if, in the case of an ifstream, it was not opened in binary mode (so I can throw an exception). I have tried the following method: ``` if ((_is.flags() & ios::binary) == 0) throw exception(...) ``` but no ...
flags() returns [ios\_base::fmtflags](http://www.cplusplus.com/reference/iostream/ios_base/fmtflags.html) which is formatting flags, whereas binary is an [ios\_base::openmode](http://www.cplusplus.com/reference/iostream/ios_base/openmode.html) flag. I'm not sure if there is a way to find these out once the stream is al...
224,236
<p>I have a string.</p> <pre><code>string strToProcess = "fkdfdsfdflkdkfk@dfsdfjk72388389@kdkfkdfkkl@jkdjkfjd@jjjk@"; </code></pre> <p>I need to add a newline after every occurence of "@" symbol in the string.</p> <p>My Output should be like this</p> <pre><code>fkdfdsfdflkdkfk@ dfsdfjk72388389@ kdkfkdfkkl@ jkdjkfjd...
[ { "answer_id": 224244, "author": "Christian C. Salvadó", "author_id": 5445, "author_profile": "https://Stackoverflow.com/users/5445", "pm_score": 10, "selected": true, "text": "<p>Use <code>Environment.NewLine</code> whenever you want in any string. An example:</p>\n\n<pre><code>string t...
2008/10/22
[ "https://Stackoverflow.com/questions/224236", "https://Stackoverflow.com", "https://Stackoverflow.com/users/22162/" ]
I have a string. ``` string strToProcess = "fkdfdsfdflkdkfk@dfsdfjk72388389@kdkfkdfkkl@jkdjkfjd@jjjk@"; ``` I need to add a newline after every occurence of "@" symbol in the string. My Output should be like this ``` fkdfdsfdflkdkfk@ dfsdfjk72388389@ kdkfkdfkkl@ jkdjkfjd@ jjjk@ ```
Use `Environment.NewLine` whenever you want in any string. An example: ``` string text = "fkdfdsfdflkdkfk@dfsdfjk72388389@kdkfkdfkkl@jkdjkfjd@jjjk@"; text = text.Replace("@", "@" + System.Environment.NewLine); ```
224,239
<p>I have an array of shorts (short[]) that I need to write out to a file. What's the quickest way to do this?</p>
[ { "answer_id": 224251, "author": "Jon B", "author_id": 27414, "author_profile": "https://Stackoverflow.com/users/27414", "pm_score": 5, "selected": true, "text": "<p>Use the BinaryWriter</p>\n\n<pre><code> static void WriteShorts(short[] values, string path)\n {\n using (Fil...
2008/10/22
[ "https://Stackoverflow.com/questions/224239", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14606/" ]
I have an array of shorts (short[]) that I need to write out to a file. What's the quickest way to do this?
Use the BinaryWriter ``` static void WriteShorts(short[] values, string path) { using (FileStream fs = new FileStream(path, FileMode.OpenOrCreate, FileAccess.Write)) { using (BinaryWriter bw = new BinaryWriter(fs)) { foreach (short value in values) ...
224,253
<p>I want to change the order of XML using XDocument</p> <pre><code>&lt;root&gt; &lt;one&gt;1&lt;/one&gt; &lt;two&gt;2&lt;/two&gt; &lt;/root&gt; </code></pre> <p>I want to change the order so that 2 appears before 1. Is this capability baked in or do I have to do it myself. For example, remove then AddBeforeSe...
[ { "answer_id": 224299, "author": "smaclell", "author_id": 22914, "author_profile": "https://Stackoverflow.com/users/22914", "pm_score": 1, "selected": false, "text": "<p>This should do the trick. It order the child nodes of the root based on their content and then changes their order in ...
2008/10/22
[ "https://Stackoverflow.com/questions/224253", "https://Stackoverflow.com", "https://Stackoverflow.com/users/30210/" ]
I want to change the order of XML using XDocument ``` <root> <one>1</one> <two>2</two> </root> ``` I want to change the order so that 2 appears before 1. Is this capability baked in or do I have to do it myself. For example, remove then AddBeforeSelf()? Thanks
Similar to above, but wrapping it in an extension method. In my case this works fine for me as I just want to ensure a certain element order is applied in my document before the user saves the xml. ``` public static class XElementExtensions { public static void OrderElements(this XElement parent, params string[] o...
224,295
<p>I have two tables, one that contains volunteers, and one that contains venues. <strong>Volunteers are assigned one venue each</strong>.</p> <p>The id of the venues table (venues.id) is placed within the volunteers table in the venue_id column (volunteers.venue_id).</p> <p>I know I could get a count of how many mat...
[ { "answer_id": 224304, "author": "Ignacio Vazquez-Abrams", "author_id": 20862, "author_profile": "https://Stackoverflow.com/users/20862", "pm_score": 1, "selected": false, "text": "<pre><code>SELECT venues.venue_name, COUNT(volunteers.*) AS cvolun\n FROM venues\n INNER JOIN volunteers\...
2008/10/22
[ "https://Stackoverflow.com/questions/224295", "https://Stackoverflow.com", "https://Stackoverflow.com/users/26130/" ]
I have two tables, one that contains volunteers, and one that contains venues. **Volunteers are assigned one venue each**. The id of the venues table (venues.id) is placed within the volunteers table in the venue\_id column (volunteers.venue\_id). I know I could get a count of how many matching values are in the volu...
This will give you all of the venues, with those having no volunteers showing up with a 0 volunteer\_count ``` select venues.venue_name, count(*) as volunteer_count from venues left outer join volunteers on venues.id = volunteers.venue_id group by venues.venue_name ``` [EDIT] I just realized you asked for MySQL. ...
224,297
<p>I have the following models.</p> <pre><code># app/models/domain/domain_object.rb class Domain::DomainObject &lt; ActiveRecord::Base has_many :links_from, :class_name =&gt; "Link", :as =&gt; :from, :dependent =&gt; :destroy end # app/models/link.rb class Link &lt; ActiveRecord::Base belongs_to :from, :polymorph...
[ { "answer_id": 231901, "author": "hoyhoy", "author_id": 3499, "author_profile": "https://Stackoverflow.com/users/3499", "pm_score": 4, "selected": true, "text": "<p>To fix this, I did a <code>include Domain</code> in the <code>DomainObject</code> model and set <code>ActiveRecord::Base.st...
2008/10/22
[ "https://Stackoverflow.com/questions/224297", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3499/" ]
I have the following models. ``` # app/models/domain/domain_object.rb class Domain::DomainObject < ActiveRecord::Base has_many :links_from, :class_name => "Link", :as => :from, :dependent => :destroy end # app/models/link.rb class Link < ActiveRecord::Base belongs_to :from, :polymorphic => true belongs_to :obj...
To fix this, I did a `include Domain` in the `DomainObject` model and set `ActiveRecord::Base.store_full_sti_class = true` in `config/environment.rb`.
224,311
<p>Is there a better way to negate a boolean in Java than a simple if-else?</p> <pre><code>if (theBoolean) { theBoolean = false; } else { theBoolean = true; } </code></pre>
[ { "answer_id": 224314, "author": "Aaron Maenpaa", "author_id": 2603, "author_profile": "https://Stackoverflow.com/users/2603", "pm_score": 10, "selected": true, "text": "<pre><code>theBoolean = !theBoolean;\n</code></pre>\n" }, { "answer_id": 224380, "author": "Community", ...
2008/10/22
[ "https://Stackoverflow.com/questions/224311", "https://Stackoverflow.com", "https://Stackoverflow.com/users/26237/" ]
Is there a better way to negate a boolean in Java than a simple if-else? ``` if (theBoolean) { theBoolean = false; } else { theBoolean = true; } ```
``` theBoolean = !theBoolean; ```
224,337
<p>I'm making a program that fits the wizard concept ideally; the user is walked through the steps to create a character for a game.</p> <p>However, I'm realizing that the limitations of the wizard are making it difficult to design "elegant" logic flow. For example, because all pages of the wizard are initalized at th...
[ { "answer_id": 224800, "author": "Toni Ruža", "author_id": 6267, "author_profile": "https://Stackoverflow.com/users/6267", "pm_score": 4, "selected": true, "text": "<p>Here is a simple example. This way you can make your \"wizard\" work like a finite state machine where states are differ...
2008/10/22
[ "https://Stackoverflow.com/questions/224337", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18676/" ]
I'm making a program that fits the wizard concept ideally; the user is walked through the steps to create a character for a game. However, I'm realizing that the limitations of the wizard are making it difficult to design "elegant" logic flow. For example, because all pages of the wizard are initalized at the same tim...
Here is a simple example. This way you can make your "wizard" work like a finite state machine where states are different pages that are initialized on demand. Also, the data is shared between pages. ``` import wx import wx.lib.newevent (PageChangeEvent, EVT_PAGE_CHANGE) = wx.lib.newevent.NewEvent() class Data: ...
224,359
<p>What is the best way to delete a database record using LINQ when I have the primary key? </p>
[ { "answer_id": 224363, "author": "Mark Cidade", "author_id": 1659, "author_profile": "https://Stackoverflow.com/users/1659", "pm_score": 0, "selected": false, "text": "<p>You can map a stored procedure to a method on the DataContext that deletes a record with a given value for the primar...
2008/10/22
[ "https://Stackoverflow.com/questions/224359", "https://Stackoverflow.com", "https://Stackoverflow.com/users/361/" ]
What is the best way to delete a database record using LINQ when I have the primary key?
If you set **update checks** on all your columns to **never** or **when changed**, you can simply attach an instance with the primary key and delete the row without a load. ``` public void DeleteCustomer(int CustomerID) { NorthwindContext c = new NorthwindContext c; Customer target = new Customer(){CustomerID ...
224,379
<p>I see this all the time in Ruby:</p> <pre><code>require File.dirname(__FILE__) + "/../../config/environment" </code></pre> <p>What does <code>__FILE__</code> mean?</p>
[ { "answer_id": 224383, "author": "Geoff", "author_id": 10427, "author_profile": "https://Stackoverflow.com/users/10427", "pm_score": 8, "selected": true, "text": "<p>It is a reference to the current file name. In the file <code>foo.rb</code>, <code>__FILE__</code> would be interpreted as...
2008/10/22
[ "https://Stackoverflow.com/questions/224379", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5004/" ]
I see this all the time in Ruby: ``` require File.dirname(__FILE__) + "/../../config/environment" ``` What does `__FILE__` mean?
It is a reference to the current file name. In the file `foo.rb`, `__FILE__` would be interpreted as `"foo.rb"`. **Edit:** Ruby 1.9.2 and 1.9.3 appear to behave a little differently from what Luke Bayes said in [his comment](https://stackoverflow.com/questions/224379/what-does-file-mean-in-ruby#comment1243516_224383)....
224,397
<p>I was taking a look through some open-source C++ code and I noticed a lot of double underscores used within in the code, mainly at the start of variable names.</p> <pre><code>return __CYGWIN__; </code></pre> <p>Just wondering: Is there a reason for this, or is it just some people's code styles? I would think that i...
[ { "answer_id": 224404, "author": "Menkboy", "author_id": 29539, "author_profile": "https://Stackoverflow.com/users/29539", "pm_score": 3, "selected": false, "text": "<p>It's something you're not meant to do in 'normal' code. This ensures that compilers and system libraries can define sym...
2008/10/22
[ "https://Stackoverflow.com/questions/224397", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6335/" ]
I was taking a look through some open-source C++ code and I noticed a lot of double underscores used within in the code, mainly at the start of variable names. ``` return __CYGWIN__; ``` Just wondering: Is there a reason for this, or is it just some people's code styles? I would think that it makes it hard to read.
From [Programming in C++, Rules and Recommendations](http://www.doc.ic.ac.uk/lab/cplus/c++.rules/chap5.html) : > > The use of two underscores (`\_\_') in identifiers is reserved for the compiler's internal use according to the ANSI-C standard. > > > Underscores (`\_') are often used in names of library functions (s...
224,408
<p>Is there a better/simpler way to find the number of images in a directory and output them to a variable?</p> <pre><code>function dirCount($dir) { $x = 0; while (($file = readdir($dir)) !== false) { if (isImage($file)) {$x = $x + 1} } return $x; } </code></pre> <p>This seems like such a long way of doin...
[ { "answer_id": 224439, "author": "bbxbby", "author_id": 29230, "author_profile": "https://Stackoverflow.com/users/29230", "pm_score": 6, "selected": true, "text": "<p>Check out the Standard PHP Library (aka SPL) for DirectoryIterator:</p>\n\n<pre><code>$dir = new DirectoryIterator('/path...
2008/10/22
[ "https://Stackoverflow.com/questions/224408", "https://Stackoverflow.com", "https://Stackoverflow.com/users/27025/" ]
Is there a better/simpler way to find the number of images in a directory and output them to a variable? ``` function dirCount($dir) { $x = 0; while (($file = readdir($dir)) !== false) { if (isImage($file)) {$x = $x + 1} } return $x; } ``` This seems like such a long way of doing this, is there no simple...
Check out the Standard PHP Library (aka SPL) for DirectoryIterator: ``` $dir = new DirectoryIterator('/path/to/dir'); foreach($dir as $file ){ $x += (isImage($file)) ? 1 : 0; } ``` (FYI there is an undocumented function called iterator\_count() but probably best not to rely on it for now I would imagine. And you'd...
224,410
<p>I'm having some trouble getting log4net to work from ASP.NET 3.5. This is the first time I've tried to use log4net, I feel like I'm missing a piece of the puzzle.</p> <p>My project references the log4net assembly, and as far as I can tell, it is being deployed successfully on my server.</p> <p>My web.config contai...
[ { "answer_id": 224423, "author": "CVertex", "author_id": 209, "author_profile": "https://Stackoverflow.com/users/209", "pm_score": 5, "selected": true, "text": "<p>The root logger is mandatory I think. I suspect configuration is failing because the root doesn't exist.</p>\n\n<p>Another p...
2008/10/22
[ "https://Stackoverflow.com/questions/224410", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18505/" ]
I'm having some trouble getting log4net to work from ASP.NET 3.5. This is the first time I've tried to use log4net, I feel like I'm missing a piece of the puzzle. My project references the log4net assembly, and as far as I can tell, it is being deployed successfully on my server. My web.config contains the following:...
The root logger is mandatory I think. I suspect configuration is failing because the root doesn't exist. Another potential problem is that Configure isn't being pointed to the Web.config. Try Configure(Server.MapPath("~/web.config")) instead.
224,421
<p>In a <a href="https://stackoverflow.com/questions/224138/infinite-loops-top-or-bottom">coding style question about infinite loops</a>, some people mentioned they prefer the for(;;) style because the while(true) style gives warning messages on MSVC about a conditional expression being constant.</p> <p>This surprised...
[ { "answer_id": 224427, "author": "James Curran", "author_id": 12725, "author_profile": "https://Stackoverflow.com/users/12725", "pm_score": 2, "selected": false, "text": "<p>I believe it's to catch things like </p>\n\n<pre><code> if( x=0 )\n</code></pre>\n\n<p>when you meant </p>\n\n<pre...
2008/10/22
[ "https://Stackoverflow.com/questions/224421", "https://Stackoverflow.com", "https://Stackoverflow.com/users/28258/" ]
In a [coding style question about infinite loops](https://stackoverflow.com/questions/224138/infinite-loops-top-or-bottom), some people mentioned they prefer the for(;;) style because the while(true) style gives warning messages on MSVC about a conditional expression being constant. This surprised me greatly, since th...
A warning doesn't automatically mean that code is *bad*, just suspicious-looking. Personally I start from a position of enabling all the warnings I can, then turn off any that prove more annoying than useful. That one that fires anytime you cast anything to a bool is usually the first to go.
224,453
<p>I have a string encrypted in PHP that I would like to decrypt in C#. I used the tutorial below to do the encryption, but am having problems decrypting. Can anyone post an example on how to do this? </p> <p><a href="http://www.sanity-free.org/131/triple_des_between_php_and_csharp.html" rel="noreferrer">http://www...
[ { "answer_id": 224524, "author": "deepcode.co.uk", "author_id": 20524, "author_profile": "https://Stackoverflow.com/users/20524", "pm_score": 5, "selected": true, "text": "<p>Hope this helps:</p>\n\n<pre><code>class Program\n{\n static void Main(string[] args)\n {\n Console....
2008/10/22
[ "https://Stackoverflow.com/questions/224453", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3291/" ]
I have a string encrypted in PHP that I would like to decrypt in C#. I used the tutorial below to do the encryption, but am having problems decrypting. Can anyone post an example on how to do this? <http://www.sanity-free.org/131/triple_des_between_php_and_csharp.html>
Hope this helps: ``` class Program { static void Main(string[] args) { Console.WriteLine(Decrypt("47794945c0230c3d")); } static string Decrypt(string input) { TripleDES tripleDes = TripleDES.Create(); tripleDes.IV = Encoding.ASCII.GetBytes("password"); tripleDes.Key...
224,467
<p>I'm using Microsoft WebTest and want to be able to do something similar to NUnit's <code>Assert.Fail()</code>. The best i have come up with is to <code>throw new webTestException()</code> but this shows in the test results as an <code>Error</code> rather than a <code>Failure</code>. </p> <p>Other than reflecting on...
[ { "answer_id": 224472, "author": "Mark Cidade", "author_id": 1659, "author_profile": "https://Stackoverflow.com/users/1659", "pm_score": 2, "selected": false, "text": "<p>Set the <a href=\"http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.testtools.webtesting.webtest.outcome...
2008/10/22
[ "https://Stackoverflow.com/questions/224467", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18590/" ]
I'm using Microsoft WebTest and want to be able to do something similar to NUnit's `Assert.Fail()`. The best i have come up with is to `throw new webTestException()` but this shows in the test results as an `Error` rather than a `Failure`. Other than reflecting on the `WebTest` to set a private member variable to ind...
Set the [Outcome property](http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.testtools.webtesting.webtest.outcome.aspx) to *Fail*: ``` Outcome = Outcome.Fail; ``` There's also an [`Assert.Fail()`](http://msdn.microsoft.com/en-us/library/microsoft.visualstudio.testtools.unittesting.assert.fail.aspx) in t...
224,471
<p>Uhm I'm not sure if anyone has encountered this problem <br> a brief description is on IE6 any <code>&lt;select&gt;</code> objects get displayed over any other item, even div's... meaning if you have a fancy javascript effect that displays a div that's supposed to be on top of everything (e.g: lightbox, multibox etc...
[ { "answer_id": 224571, "author": "Hafthor", "author_id": 4489, "author_profile": "https://Stackoverflow.com/users/4489", "pm_score": 1, "selected": false, "text": "<p>Prior to IE7 the drop down list was a \"windowed\" control meaning that it was rendered as a control directly by Windows ...
2008/10/22
[ "https://Stackoverflow.com/questions/224471", "https://Stackoverflow.com", "https://Stackoverflow.com/users/24744/" ]
Uhm I'm not sure if anyone has encountered this problem a brief description is on IE6 any `<select>` objects get displayed over any other item, even div's... meaning if you have a fancy javascript effect that displays a div that's supposed to be on top of everything (e.g: lightbox, multibox etc..) onclick of a cert...
You don't have to hide every `select` using a loop. All you need is a CSS rule like: ``` * html .hideSelects select { visibility: hidden; } ``` And the following JavaScript: ``` //hide: document.body.className +=' hideSelects' //show: document.body.className = document.body.className.replace(' hideSelects', ''); ...
224,473
<p>I am new to creating Java web applications and came across this problem when trying to interact with my database (called ccdb) through my application:</p> <p><code>java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost/ccdb/</code></p> <p>My application runs on JBoss and uses Hibernate to inter...
[ { "answer_id": 224571, "author": "Hafthor", "author_id": 4489, "author_profile": "https://Stackoverflow.com/users/4489", "pm_score": 1, "selected": false, "text": "<p>Prior to IE7 the drop down list was a \"windowed\" control meaning that it was rendered as a control directly by Windows ...
2008/10/22
[ "https://Stackoverflow.com/questions/224473", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20177/" ]
I am new to creating Java web applications and came across this problem when trying to interact with my database (called ccdb) through my application: `java.sql.SQLException: No suitable driver found for jdbc:mysql://localhost/ccdb/` My application runs on JBoss and uses Hibernate to interact with the MySQL database....
You don't have to hide every `select` using a loop. All you need is a CSS rule like: ``` * html .hideSelects select { visibility: hidden; } ``` And the following JavaScript: ``` //hide: document.body.className +=' hideSelects' //show: document.body.className = document.body.className.replace(' hideSelects', ''); ...
224,475
<p>I wonder if is possible to use FTS with LINQ using .NET Framework 3.5. I'm searching around the documentation that I didn't find anything useful yet.</p> <p>Does anyone have any experience on this?</p>
[ { "answer_id": 224483, "author": "Glenn Slaven", "author_id": 2975, "author_profile": "https://Stackoverflow.com/users/2975", "pm_score": 3, "selected": false, "text": "<p>I don't believe so. You can use 'contains' on a field, but it only generates a <code>LIKE</code> query. If you wan...
2008/10/22
[ "https://Stackoverflow.com/questions/224475", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18623/" ]
I wonder if is possible to use FTS with LINQ using .NET Framework 3.5. I'm searching around the documentation that I didn't find anything useful yet. Does anyone have any experience on this?
Yes. However you have to create SQL server function first and call that as by default LINQ will use a like. This [blog post](http://sqlblogcasts.com/blogs/simons/archive/2008/12/18/LINQ-to-SQL---Enabling-Fulltext-searching.aspx) which will explain the detail but this is the extract: > > To get it working you need to...
224,481
<p>I am creating a custom UserType in Hibernate for a project. It has been relatively straightforward until I came to the isMutable method. I am trying to figure out what this method means, contract-wise. </p> <p>Does it mean the class I am creating the UserType for is immutable or does it mean the object that holds a...
[ { "answer_id": 224880, "author": "jmcd", "author_id": 2285, "author_profile": "https://Stackoverflow.com/users/2285", "pm_score": 2, "selected": false, "text": "<p>The typical example here is the String class - it is Immutable, i.e. once the string is created you cannot change its conten...
2008/10/22
[ "https://Stackoverflow.com/questions/224481", "https://Stackoverflow.com", "https://Stackoverflow.com/users/24290/" ]
I am creating a custom UserType in Hibernate for a project. It has been relatively straightforward until I came to the isMutable method. I am trying to figure out what this method means, contract-wise. Does it mean the class I am creating the UserType for is immutable or does it mean the object that holds a reference...
Hibernate will treat types marked as "mutable" as though they could change (i.e. require an UPDATE) *without* pointing to a new reference. If you assign a new reference to a Hibernate-loaded property Hibernate will recognize this even if the type is immutable - this happens all the time with, for instance, String field...
224,484
<p>On an ASP.NET MVC (Beta) site that I am developing sometimes calls to ActionLink will return to me URLs containing querying strings. I have isolated the circumstances that produce this behavior, but I still do not understand why, instead of producing a clean URL, it decides to using a query string parameter. I know ...
[ { "answer_id": 224519, "author": "Schotime", "author_id": 29376, "author_profile": "https://Stackoverflow.com/users/29376", "pm_score": 0, "selected": false, "text": "<p>I think it is picking up your first Route. It too has the action All. And because the sortby is not specified it is ex...
2008/10/22
[ "https://Stackoverflow.com/questions/224484", "https://Stackoverflow.com", "https://Stackoverflow.com/users/27860/" ]
On an ASP.NET MVC (Beta) site that I am developing sometimes calls to ActionLink will return to me URLs containing querying strings. I have isolated the circumstances that produce this behavior, but I still do not understand why, instead of producing a clean URL, it decides to using a query string parameter. I know tha...
Not sure why different views are producing different URLs. But you can get rid of that sortBy param by assigning a default value to the first route. new { sortBy = "" } During generation, if sortBy matches the default, the route engine will skip that parameter (if it's in the query string).
224,485
<p>I am using a Cursor in my stored procedure. It works on a database that has a huge number of data. for every item in the cursor i do a update operation. This is taking a huge amount of time to complete. Almost 25min. :( .. Is there anyway i can reduce the time consumed for this?</p>
[ { "answer_id": 224490, "author": "knightpfhor", "author_id": 17089, "author_profile": "https://Stackoverflow.com/users/17089", "pm_score": 3, "selected": false, "text": "<p>The quick answer is not to use a cursor. The most efficient way to update lots of records is to use an update stat...
2008/10/22
[ "https://Stackoverflow.com/questions/224485", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20951/" ]
I am using a Cursor in my stored procedure. It works on a database that has a huge number of data. for every item in the cursor i do a update operation. This is taking a huge amount of time to complete. Almost 25min. :( .. Is there anyway i can reduce the time consumed for this?
When you need to do a more complex operation to each row than what a simple update would allow you, you can try: * Write a User Defined Function and use that in the update (probably still slow) * Put data in a temporary table and use that in an UPDATE ... FROM: Did you know about the UPDATE ... FROM syntax? It is qui...
224,499
<p>There are some good examples on how to calculate word frequencies in C#, but none of them are comprehensive and I really need one in VB.NET.</p> <p>My current approach is limited to one word per frequency count. What is the best way to change this so that I can get a completely accurate word frequency listing?</p> ...
[ { "answer_id": 224510, "author": "Christian C. Salvadó", "author_id": 5445, "author_profile": "https://Stackoverflow.com/users/5445", "pm_score": 1, "selected": false, "text": "<p>This might be helpful:</p>\n\n<p><a href=\"https://stackoverflow.com/questions/90580/word-frequency-algorith...
2008/10/22
[ "https://Stackoverflow.com/questions/224499", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4965/" ]
There are some good examples on how to calculate word frequencies in C#, but none of them are comprehensive and I really need one in VB.NET. My current approach is limited to one word per frequency count. What is the best way to change this so that I can get a completely accurate word frequency listing? ``` wordFreq ...
``` Public Class CountWords Public Function WordCount(ByVal str As String) As Dictionary(Of String, Integer) Dim ret As Dictionary(Of String, Integer) = New Dictionary(Of String, Integer) Dim word As String = "" Dim add As Boolean = True Dim ch As Char str = str.ToLower ...
224,503
<p>Short of putting a UIWebView as the back-most layer in my nib file, how can I add a repeating background image to an iPhone app (like the corduroy look in the background of a grouped UITableView)?</p> <p>Do I need to create an image that's the size of the iPhone's screen and manually repeat it using copy and paste?...
[ { "answer_id": 224513, "author": "Frank Schmitt", "author_id": 27951, "author_profile": "https://Stackoverflow.com/users/27951", "pm_score": 8, "selected": true, "text": "<p>Apparently a UIColor is not necessarily a single color, but can be a pattern as well. Confusingly, this is not sup...
2008/10/22
[ "https://Stackoverflow.com/questions/224503", "https://Stackoverflow.com", "https://Stackoverflow.com/users/27951/" ]
Short of putting a UIWebView as the back-most layer in my nib file, how can I add a repeating background image to an iPhone app (like the corduroy look in the background of a grouped UITableView)? Do I need to create an image that's the size of the iPhone's screen and manually repeat it using copy and paste?
Apparently a UIColor is not necessarily a single color, but can be a pattern as well. Confusingly, this is not supported in Interface Builder. Instead you set the backgroundColor of the view (say, in -viewDidLoad) with the convenience method +colorWithPatternImage: and pass it a UI Image. For Instance: ``` - (void)v...
224,504
<p>Ok, so I have a Rails app set up on DreamHost and I had it working a while ago and now it's broken. I don't know a lot about deployment environments or anything like that so please forgive my ignorance. Anyway, it looks like the app is crashing at this line in config/environment.rb:</p> <pre><code>require File.jo...
[ { "answer_id": 226189, "author": "Otto", "author_id": 9594, "author_profile": "https://Stackoverflow.com/users/9594", "pm_score": 1, "selected": false, "text": "<p>My guess would be that you're breaking because of a newer version of the Rails gems on Dreamhost. At least, that's been my ...
2008/10/22
[ "https://Stackoverflow.com/questions/224504", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12448/" ]
Ok, so I have a Rails app set up on DreamHost and I had it working a while ago and now it's broken. I don't know a lot about deployment environments or anything like that so please forgive my ignorance. Anyway, it looks like the app is crashing at this line in config/environment.rb: ``` require File.join(File.dirname(...
I had the same problem on DreamHost. Freezing rails and unpacking all gems got me past it. ``` rake rails:freeze:gems rake gems:unpack:dependencies ```
224,512
<p>I am working on creating a daemon in Ruby using the daemons gem. I want to add output from the daemon into a log file. I am wondering what is the easiest way to redirect <code>puts</code> from the console to a log file.</p>
[ { "answer_id": 224523, "author": "Pistos", "author_id": 28558, "author_profile": "https://Stackoverflow.com/users/28558", "pm_score": 4, "selected": false, "text": "<p>Try</p>\n\n<pre><code>$stdout = File.new( '/tmp/output', 'w' )\n</code></pre>\n\n<p>To restore:</p>\n\n<pre><code>$stdou...
2008/10/22
[ "https://Stackoverflow.com/questions/224512", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5004/" ]
I am working on creating a daemon in Ruby using the daemons gem. I want to add output from the daemon into a log file. I am wondering what is the easiest way to redirect `puts` from the console to a log file.
I should recommend to use ruby logger, it is better than puts, you can have multiple log levels that you can turn on/off: debug, warn, info,error, etc. ``` logger = Logger.new(STDOUT) logger = Logger.new("/var/log/my-daemon.log") ``` I use runit package to manage ruby services, it has svlogd than will redirect dae...
224,553
<p>I want to know how events are used in embedded system code.</p> <p>Main intention is to know how exactly event flags are set/reset in code. and how to identify which task is using which event flag and which bits of the flag are getting set/reset by each task.</p> <p>Please put your suggestion or comments about it....
[ { "answer_id": 224565, "author": "Bill Forster", "author_id": 3955, "author_profile": "https://Stackoverflow.com/users/3955", "pm_score": 1, "selected": false, "text": "<p>This question needs to provide more context. Embedded systems can be created using a wide range of languages, operat...
2008/10/22
[ "https://Stackoverflow.com/questions/224553", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I want to know how events are used in embedded system code. Main intention is to know how exactly event flags are set/reset in code. and how to identify which task is using which event flag and which bits of the flag are getting set/reset by each task. Please put your suggestion or comments about it. Thanks in advan...
Many embedded systems use Interrupt Service Routines (ISR) to handle events. You would define an ISR for a given "flag" and reset that flag after you handle the event. For instance say you have a device performing Analog to Digital Conversions (ADC). On the device you could have an ISR that fires each time the ADC com...
224,562
<p>I am reading over the K&amp;R book, and am a little stuck.</p> <p>What is wrong with the following?</p> <pre><code>void getInput(int* output) { int c, i; for(i=0; (c = getchar()) != '\n'; i++) output[i] = c; // printf("%c", c) prints the c value as expected output[++i] = '\0'; } </code></pre> <p>Whe...
[ { "answer_id": 224575, "author": "jjnguy", "author_id": 2598, "author_profile": "https://Stackoverflow.com/users/2598", "pm_score": 1, "selected": false, "text": "<p>It looks correct to me as written except that you don't need to increment i outside of the loop. The i gets incremented r...
2008/10/22
[ "https://Stackoverflow.com/questions/224562", "https://Stackoverflow.com", "https://Stackoverflow.com/users/26849/" ]
I am reading over the K&R book, and am a little stuck. What is wrong with the following? ``` void getInput(int* output) { int c, i; for(i=0; (c = getchar()) != '\n'; i++) output[i] = c; // printf("%c", c) prints the c value as expected output[++i] = '\0'; } ``` When I run the program it never gets out...
> > What is wrong with the following? > > > ``` 1. void getInput(int* output) { ``` Why is the input argument an int\* when what you want to store in an array of characters? Probably ``` void getInput(char* output) { ``` is better. Also, how do you know that the output pointer is pointing somewhere where ...
224,583
<p>Do you bother initialising java bean values? Say, for example:</p> <p>([g|s]etters omitted)</p> <pre><code>public class SomeClass { private String foo; private Date bar; private Baz someObject; } </code></pre> <p>(Yes, this is a POJO being used as a bean rather than a Java Bean in the strictest se...
[ { "answer_id": 224607, "author": "Maxim Ananyev", "author_id": 404206, "author_profile": "https://Stackoverflow.com/users/404206", "pm_score": 2, "selected": true, "text": "<p>It depends on the use case.</p>\n\n<p>If I use properties as service dependencies, they should be initialized to...
2008/10/22
[ "https://Stackoverflow.com/questions/224583", "https://Stackoverflow.com", "https://Stackoverflow.com/users/27708/" ]
Do you bother initialising java bean values? Say, for example: ([g|s]etters omitted) ``` public class SomeClass { private String foo; private Date bar; private Baz someObject; } ``` (Yes, this is a POJO being used as a bean rather than a Java Bean in the strictest sense) In the empty constructor, d...
It depends on the use case. If I use properties as service dependencies, they should be initialized to operate properly (btw, Spring DI has handy way to do it). If I use bean as part of domain model, it is usually illegal state to have some null property. It may not be initialized at startup, but I bother throwing I...
224,602
<p>Given this HTML:</p> <pre><code>&lt;div&gt;foo&lt;/div&gt;&lt;div&gt;bar&lt;/div&gt;&lt;div&gt;baz&lt;/div&gt; </code></pre> <p>How do you make them display inline like this:</p> <blockquote> <p>foo bar baz</p> </blockquote> <p>not like this:</p> <blockquote> <p>foo<br> bar<br> baz </p> </blockquote>
[ { "answer_id": 224612, "author": "Randy Sugianto 'Yuku'", "author_id": 11238, "author_profile": "https://Stackoverflow.com/users/11238", "pm_score": 8, "selected": false, "text": "<p>Try writing it like this:</p>\n\n<p><div class=\"snippet\" data-lang=\"js\" data-hide=\"false\" data-cons...
2008/10/22
[ "https://Stackoverflow.com/questions/224602", "https://Stackoverflow.com", "https://Stackoverflow.com/users/21559/" ]
Given this HTML: ``` <div>foo</div><div>bar</div><div>baz</div> ``` How do you make them display inline like this: > > foo bar baz > > > not like this: > > foo > > bar > > baz > > >
That's something else then: ```css div.inline { float:left; } .clearBoth { clear:both; } ``` ```html <div class="inline">1<br />2<br />3</div> <div class="inline">1<br />2<br />3</div> <div class="inline">1<br />2<br />3</div> <br class="clearBoth" /><!-- you may or may not need this --> ```
224,617
<p>i have a 3 column datafile and i wanted to use splot to plot the same. But what i want is that gnuplot plots first row (in some colour, say red) and then pauses for say 0.3 secs and then moves on to plotting next row (in other colour, not in red, say in green), pauses for 0.3 secs and then proceeds to next row....so...
[ { "answer_id": 224680, "author": "ADEpt", "author_id": 10105, "author_profile": "https://Stackoverflow.com/users/10105", "pm_score": 2, "selected": false, "text": "<p>If you want to produce an animation, you better use specialized tools for it (like mplayer).</p>\n\n<p>Use gnuplot to pre...
2008/10/22
[ "https://Stackoverflow.com/questions/224617", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
i have a 3 column datafile and i wanted to use splot to plot the same. But what i want is that gnuplot plots first row (in some colour, say red) and then pauses for say 0.3 secs and then moves on to plotting next row (in other colour, not in red, say in green), pauses for 0.3 secs and then proceeds to next row....so on...
If you want to produce an animation, you better use specialized tools for it (like mplayer). Use gnuplot to prepare all source images (first one with single row plotted, second - with two lines, etc), then use mplayer or convert (from imagemagic) to produce avi or animated GIF out of source files. You can use the fol...
224,624
<p>This error comes out whenever I click the datagrid.</p> <p>The program does fill the datagrid every time data was selected in the combobox.</p> <p>For example, I choose data1 which has four records in datagrid, and then I click row index no 1. No problem, it will be shown, but when I choose another data again in c...
[ { "answer_id": 224632, "author": "Windows programmer", "author_id": 23705, "author_profile": "https://Stackoverflow.com/users/23705", "pm_score": 1, "selected": false, "text": "<p>If the selected row index is larger than the largest index (number of rows minus one) in the new data, then ...
2008/10/22
[ "https://Stackoverflow.com/questions/224624", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
This error comes out whenever I click the datagrid. The program does fill the datagrid every time data was selected in the combobox. For example, I choose data1 which has four records in datagrid, and then I click row index no 1. No problem, it will be shown, but when I choose another data again in combobox, for exam...
If the selected row index is larger than the largest index (number of rows minus one) in the new data, then decrease the row index as necessary before doing the fill? Or check the reason for the exception and decrease the row index instead of displaying the error message?
224,635
<p>I'm trying to program ARM using Eclipse + CDT + yagarto (gnu toolchain) + OpenOCD. In several sample projects (from yagarto site for example) I found linker scripts (*.ld) where a lot of linking information specified (along with sections definitions). Actually I haven't faced this files before (IAR doesn't need them...
[ { "answer_id": 264564, "author": "kgiannakakis", "author_id": 24054, "author_profile": "https://Stackoverflow.com/users/24054", "pm_score": 0, "selected": false, "text": "<p>There is not a universal linker script. These scripts are very important, since they define where in memory (RAM o...
2008/10/22
[ "https://Stackoverflow.com/questions/224635", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14535/" ]
I'm trying to program ARM using Eclipse + CDT + yagarto (gnu toolchain) + OpenOCD. In several sample projects (from yagarto site for example) I found linker scripts (\*.ld) where a lot of linking information specified (along with sections definitions). Actually I haven't faced this files before (IAR doesn't need them),...
My guess is every third person has a different script or solution. There are a number of problems that have to be solved, different linkers are going to solve those in different ways. I think GNU has made it way too difficult if not black magic. For an embedded system you are often going to have a flash or eeprom or s...
224,637
<p>I'm trying to use multiple attributes in my custom tag, e.g.:</p> <pre><code>&lt;mytaglib:mytag firstname="Thadeus" lastname="Jones" /&gt; </code></pre> <p>How can I access the attributes in the TagHandler code?</p>
[ { "answer_id": 224649, "author": "Chris Kimpton", "author_id": 48310, "author_profile": "https://Stackoverflow.com/users/48310", "pm_score": 1, "selected": true, "text": "<p>Not really the answer to what you asked, but I hate (ie have never written) TagHandler's but I love <a href=\"http...
2008/10/22
[ "https://Stackoverflow.com/questions/224637", "https://Stackoverflow.com", "https://Stackoverflow.com/users/28557/" ]
I'm trying to use multiple attributes in my custom tag, e.g.: ``` <mytaglib:mytag firstname="Thadeus" lastname="Jones" /> ``` How can I access the attributes in the TagHandler code?
Not really the answer to what you asked, but I hate (ie have never written) TagHandler's but I love [tag files](http://java.sun.com/j2ee/1.4/docs/tutorial/doc/JSPTags5.html). Lets you write custom tags using jsp files. You probably know about them and are not available/applicable - but thought I'd mention them just in ...
224,646
<pre><code>Double out = otherTypes.someMethod(c, c2); assertEquals((Double)-1.0D, out); </code></pre> <p>I get error "Double cannot be resolved" (the Double in assertEquals), is there any way to hack around it except extracting variable?</p> <p>Is this bug in Java or just very usefull feature that wont be fix?</p>
[ { "answer_id": 224685, "author": "Johann Zacharee", "author_id": 24290, "author_profile": "https://Stackoverflow.com/users/24290", "pm_score": 2, "selected": false, "text": "<p>My variation is similar to jjnguy's</p>\n\n<pre><code>assertEquals(Double.valueOf(-1.0D), out)\n</code></pre>\n...
2008/10/22
[ "https://Stackoverflow.com/questions/224646", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
``` Double out = otherTypes.someMethod(c, c2); assertEquals((Double)-1.0D, out); ``` I get error "Double cannot be resolved" (the Double in assertEquals), is there any way to hack around it except extracting variable? Is this bug in Java or just very usefull feature that wont be fix?
One important note: Because of the way floating point numbers work, you should never compare two doubles (or floating point numbers generally spoken) for equality directly, always compare if their difference is within a specified delta: `abs(double1 - double2) < delta`. JUnit has an `assertEquals(double expected, dou...
224,648
<p>What is an external and internal iterator in Java ?</p>
[ { "answer_id": 224657, "author": "VonC", "author_id": 6309, "author_profile": "https://Stackoverflow.com/users/6309", "pm_score": 2, "selected": false, "text": "<p>It is about <a href=\"http://gafter.blogspot.com/2007/07/internal-versus-external-iterators.html\" rel=\"nofollow noreferrer...
2008/10/22
[ "https://Stackoverflow.com/questions/224648", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
What is an external and internal iterator in Java ?
External Iterator ================= When you get an iterator and step over it, that is an external iterator ``` for (Iterator iter = var.iterator(); iter.hasNext(); ) { Object obj = iter.next(); // Operate on obj } ``` Internal Iterator ================= When you pass a function object to a method to run over ...
224,658
<p>I implemented a small OOP library in Lua, and two things are not quite right yet. I need your advice!</p> <h2>How to call super()?</h2> <p>I need to make a choice. The three arguments I need to resolve a call to super() are:</p> <ul> <li>The class from where the call is being made (CallerClass)</li> <li>The instance...
[ { "answer_id": 224682, "author": "Chris Kimpton", "author_id": 48310, "author_profile": "https://Stackoverflow.com/users/48310", "pm_score": 2, "selected": true, "text": "<pre><code>--# Python style, which is nice too:\nsuper(CallerClass, self):method()\n</code></pre>\n" }, { "an...
2008/10/22
[ "https://Stackoverflow.com/questions/224658", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2797/" ]
I implemented a small OOP library in Lua, and two things are not quite right yet. I need your advice! How to call super()? -------------------- I need to make a choice. The three arguments I need to resolve a call to super() are: * The class from where the call is being made (CallerClass) * The instance to be passed...
``` --# Python style, which is nice too: super(CallerClass, self):method() ```
224,660
<p>Hi Guys could you please help me refactor this so that it is sensibly pythonic.</p> <pre><code>import sys import poplib import string import StringIO, rfc822 import datetime import logging def _dump_pop_emails(self): self.logger.info("open pop account %s with username: %s" % (self.account[0], self.account[1]))...
[ { "answer_id": 224713, "author": "John Millikin", "author_id": 3560, "author_profile": "https://Stackoverflow.com/users/3560", "pm_score": 2, "selected": false, "text": "<p>I don't see anything significant wrong with that code -- is it behaving incorrectly, or are you just looking for ge...
2008/10/22
[ "https://Stackoverflow.com/questions/224660", "https://Stackoverflow.com", "https://Stackoverflow.com/users/21537/" ]
Hi Guys could you please help me refactor this so that it is sensibly pythonic. ``` import sys import poplib import string import StringIO, rfc822 import datetime import logging def _dump_pop_emails(self): self.logger.info("open pop account %s with username: %s" % (self.account[0], self.account[1])) self.popi...
This isn't refactoring (it doesn't need refactoring as far as I can see), but some suggestions: You should use the email package rather than rfc822. Replace rfc822.Message with email.Message, and use email.Utils.parseaddr(msg["From"]) to get the name and email address, and msg["Subject"] to get the subject. Use os.pa...
224,662
<p>I have a composite control that adds a TextBox and a Label control to its Controls collection. When i try to set the Label's AssociatedControlID to the ClientID of the Textbox i get this error</p> <pre><code>Unable to find control with id 'ctl00_MainContentPlaceholder_MatrixSetControl_mec50_tb' that is associated ...
[ { "answer_id": 224710, "author": "splattne", "author_id": 6461, "author_profile": "https://Stackoverflow.com/users/6461", "pm_score": 4, "selected": true, "text": "<p>I think you <strong>mustn't use the ClientID</strong> property of the ElementTextBox, but the <strong>ID</strong>. Client...
2008/10/22
[ "https://Stackoverflow.com/questions/224662", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11619/" ]
I have a composite control that adds a TextBox and a Label control to its Controls collection. When i try to set the Label's AssociatedControlID to the ClientID of the Textbox i get this error ``` Unable to find control with id 'ctl00_MainContentPlaceholder_MatrixSetControl_mec50_tb' that is associated with the Label...
I think you **mustn't use the ClientID** property of the ElementTextBox, but the **ID**. ClientID is the page-unique ID you'd have to use in Javascript, e.g. in the document.getElementyById and is not the same as the server-side ID - especially if you have a masterpage and/or controls in controls etc. So it should be:...
224,665
<p>i want to get datetime for 2days before. i.e) how to subtract 2 days from datetime.now</p>
[ { "answer_id": 224667, "author": "DocMax", "author_id": 6234, "author_profile": "https://Stackoverflow.com/users/6234", "pm_score": 5, "selected": false, "text": "<p>I think you are just looking for:</p>\n\n<pre><code>DateTime.Now.AddDays(-2);\n</code></pre>\n" }, { "answer_id": ...
2008/10/22
[ "https://Stackoverflow.com/questions/224665", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
i want to get datetime for 2days before. i.e) how to subtract 2 days from datetime.now
I think you are just looking for: ``` DateTime.Now.AddDays(-2); ```
224,687
<p>This is sort of a follow-up to <a href="https://stackoverflow.com/questions/223678">this question</a>.</p> <p>If there are multiple blobs with the same contents, they are only stored once in the git repository because their SHA-1's will be identical. How would one go about finding all duplicate files for a given t...
[ { "answer_id": 224948, "author": "CB Bailey", "author_id": 19563, "author_profile": "https://Stackoverflow.com/users/19563", "pm_score": 2, "selected": false, "text": "<p>The scripting answers from your linked question pretty much apply here too.</p>\n\n<p>Try the following git command f...
2008/10/22
[ "https://Stackoverflow.com/questions/224687", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4883/" ]
This is sort of a follow-up to [this question](https://stackoverflow.com/questions/223678). If there are multiple blobs with the same contents, they are only stored once in the git repository because their SHA-1's will be identical. How would one go about finding all duplicate files for a given tree? Would you have ...
Running this on the codebase I work on was an eye-opener I can tell you! ``` #!/usr/bin/perl # usage: git ls-tree -r HEAD | $PROGRAM_NAME use strict; use warnings; my $sha1_path = {}; while (my $line = <STDIN>) { chomp $line; if ($line =~ m{ \A \d+ \s+ \w+ \s+ (\w+) \s+ (\S+) \z }xms) { my $sha1 =...
224,689
<p>What are the best practices to do transactions in C# .Net 2.0. What are the classes that should be used? What are the pitfalls to look out for etc. All that commit and rollback stuff. I'm just starting a project where I might need to do some transactions while inserting data into the DB. Any responses or links for e...
[ { "answer_id": 224699, "author": "Joachim Kerschbaumer", "author_id": 20227, "author_profile": "https://Stackoverflow.com/users/20227", "pm_score": 1, "selected": false, "text": "<p>if you just need it for db-related stuff, some OR Mappers (e.g. NHibernate) support transactinos out of th...
2008/10/22
[ "https://Stackoverflow.com/questions/224689", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1688440/" ]
What are the best practices to do transactions in C# .Net 2.0. What are the classes that should be used? What are the pitfalls to look out for etc. All that commit and rollback stuff. I'm just starting a project where I might need to do some transactions while inserting data into the DB. Any responses or links for even...
There are 2 main kinds of transactions; connection transactions and ambient transactions. A connection transaction (such as SqlTransaction) is tied directly to the db connection (such as SqlConnection), which means that you have to keep passing the connection around - OK in some cases, but doesn't allow "create/use/rel...
224,704
<p>I ran into a problem while cleaning up some old code. This is the function:</p> <pre><code>uint32_t ADT::get_connectivity_data( std::vector&lt; std::vector&lt;uint8_t&gt; &gt; &amp;output ) { output.resize(chunks.size()); for(chunk_vec_t::iterator it = chunks.begin(); it &lt; chunks.end(); ++it) { ...
[ { "answer_id": 224739, "author": "1800 INFORMATION", "author_id": 3146, "author_profile": "https://Stackoverflow.com/users/3146", "pm_score": 1, "selected": false, "text": "<p>I don't really get what you are driving at with regards to the lambda, but I can make a couple of general sugges...
2008/10/22
[ "https://Stackoverflow.com/questions/224704", "https://Stackoverflow.com", "https://Stackoverflow.com/users/29049/" ]
I ran into a problem while cleaning up some old code. This is the function: ``` uint32_t ADT::get_connectivity_data( std::vector< std::vector<uint8_t> > &output ) { output.resize(chunks.size()); for(chunk_vec_t::iterator it = chunks.begin(); it < chunks.end(); ++it) { uint32_t success = (*it)->get_...
After a bit of work I came up with this solution: ``` std::transform(chunks.begin(), chunks.end(), back_inserter(tmp), boost::bind(&ADTChunk::get_connectivity_data, _1) ); ``` It required that I change get\_connectivity\_data to return std::vector instead of taking one by reference, and it also required that I chang...
224,712
<p>I had setup my clients &amp; server for passwordless login. Like passwordless login by copying RSA key of server to all client's /root/.ssh/id-rsa.pub. but this, I have done manually. I like to automate this process using shell script and providing password to the machines through script. If this problem is solved t...
[ { "answer_id": 224716, "author": "Vinko Vrsalovic", "author_id": 5190, "author_profile": "https://Stackoverflow.com/users/5190", "pm_score": 3, "selected": true, "text": "<p>This script comes in Debian (and derivatives) machines, to distribute the keys. It's called ssh-copy-id. You'd use...
2008/10/22
[ "https://Stackoverflow.com/questions/224712", "https://Stackoverflow.com", "https://Stackoverflow.com/users/24813/" ]
I had setup my clients & server for passwordless login. Like passwordless login by copying RSA key of server to all client's /root/.ssh/id-rsa.pub. but this, I have done manually. I like to automate this process using shell script and providing password to the machines through script. If this problem is solved then I a...
This script comes in Debian (and derivatives) machines, to distribute the keys. It's called ssh-copy-id. You'd use it like this: ``` ssh-copy-id [-i identity_file] [user@]machine ``` Then you'd enter the password and the copying would be done. You would do this one time only and then could use the rsync over ssh as ...
224,721
<p>I have the following class:</p> <pre><code>public abstract class AbstractParent { static String method() { return "OriginalOutput"; } } </code></pre> <p>I want to mock this method. I decide to use <a href="http://jmockit.dev.java.net" rel="noreferrer">JMockit</a>. So I create a mock class:</p> <pr...
[ { "answer_id": 224773, "author": "Epaga", "author_id": 6583, "author_profile": "https://Stackoverflow.com/users/6583", "pm_score": 4, "selected": true, "text": "<p>Found the solution: you simply need to make the mock's method public (the original method can stay in its original visibilit...
2008/10/22
[ "https://Stackoverflow.com/questions/224721", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6583/" ]
I have the following class: ``` public abstract class AbstractParent { static String method() { return "OriginalOutput"; } } ``` I want to mock this method. I decide to use [JMockit](http://jmockit.dev.java.net). So I create a mock class: ``` public class MockParent { static String method() { ...
Found the solution: you simply need to make the mock's method public (the original method can stay in its original visibility). I don't know why this works while the original way doesn't (someone who does is more than welcome to chime in), but all you need to do is simply change the mock class in the example above to:...
224,732
<p>I have a database with <code>account numbers</code> and <code>card numbers</code>. I match these to a file to <code>update</code> any card numbers to the account number so that I am only working with account numbers.</p> <p>I created a view linking the table to the account/card database to return the <code>Table ID<...
[ { "answer_id": 224740, "author": "Mark S. Rasmussen", "author_id": 12469, "author_profile": "https://Stackoverflow.com/users/12469", "pm_score": 11, "selected": false, "text": "<p>I believe an <code>UPDATE FROM</code> with a <code>JOIN</code> will help:</p>\n\n<h2>MS SQL</h2>\n\n<pre><co...
2008/10/22
[ "https://Stackoverflow.com/questions/224732", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I have a database with `account numbers` and `card numbers`. I match these to a file to `update` any card numbers to the account number so that I am only working with account numbers. I created a view linking the table to the account/card database to return the `Table ID` and the related account number, and now I need...
I believe an `UPDATE FROM` with a `JOIN` will help: MS SQL ------ ``` UPDATE Sales_Import SET Sales_Import.AccountNumber = RAN.AccountNumber FROM Sales_Import SI INNER JOIN RetrieveAccountNumber RAN ON SI.LeadID = RAN.LeadID; ``` MySQL and MariaDB ----------------- ``` UPDATE Sales_Import ...
224,748
<p>I'm having trouble with a custom tag:-</p> <p>org.apache.jasper.JasperException: /custom_tags.jsp(1,0) Unable to find setter method for attribute : firstname</p> <p>This is my TagHandler class:</p> <pre><code>package com.cg.tags; import javax.servlet.jsp.JspException; import javax.servlet.jsp.JspWriter; import j...
[ { "answer_id": 224833, "author": "John Topley", "author_id": 1450, "author_profile": "https://Stackoverflow.com/users/1450", "pm_score": 2, "selected": false, "text": "<p>The TLD file in your example looks like nonsense, I don't know if it's because you've not formatted it correctly.</p>...
2008/10/22
[ "https://Stackoverflow.com/questions/224748", "https://Stackoverflow.com", "https://Stackoverflow.com/users/28557/" ]
I'm having trouble with a custom tag:- org.apache.jasper.JasperException: /custom\_tags.jsp(1,0) Unable to find setter method for attribute : firstname This is my TagHandler class: ``` package com.cg.tags; import javax.servlet.jsp.JspException; import javax.servlet.jsp.JspWriter; import javax.servlet.jsp.tagext.Tag...
Check the case of the attributes in your tag element - they should match the case of the setter, not the case of the member variables (Which should probably be private, by the way). The rule is that the attribute name has its first letter capitalised and then the result is prefixed by 'set', to arrive at the setter na...
224,756
<p>Our customers application seems to hang with the following stack trace:</p> <pre><code> java.lang.Thread.State: RUNNABLE at java.io.UnixFileSystem.getBooleanAttributes0(Native Method) at java.io.UnixFileSystem.getBooleanAttributes(Unknown Source) at java.io.File.isFile(Unknown Source) at org.tmates...
[ { "answer_id": 224781, "author": "Chris Kimpton", "author_id": 48310, "author_profile": "https://Stackoverflow.com/users/48310", "pm_score": 0, "selected": false, "text": "<p>No idea, but the obvious question of which JDK/JRE comes to mind and what others have you tried...</p>\n" }, ...
2008/10/22
[ "https://Stackoverflow.com/questions/224756", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
Our customers application seems to hang with the following stack trace: ``` java.lang.Thread.State: RUNNABLE at java.io.UnixFileSystem.getBooleanAttributes0(Native Method) at java.io.UnixFileSystem.getBooleanAttributes(Unknown Source) at java.io.File.isFile(Unknown Source) at org.tmatesoft.svn.core.i...
`getBooleanAttributes0` calls `stat` (or `stat64`, if available). If you have the OpenJDK source code, this is listed in file `jdk/src/solaris/native/java/io/UnixFileSystem_md.c`. So the real question is, why is `stat` frozen? Is the file being accessed a network file on a server that's down, for example? If this is a...
224,765
<p>I am trying to create a user interface using XAML. However, the file is quickly becoming very large and difficult to work with. What is the best way for splitting it across several files.</p> <p>I would like to be able to set the content of an element such as a ComboBox to an element that is defined in a different ...
[ { "answer_id": 224803, "author": "EFrank", "author_id": 28572, "author_profile": "https://Stackoverflow.com/users/28572", "pm_score": 5, "selected": false, "text": "<p>You can split up XAML files by using a <a href=\"http://msdn.microsoft.com/en-us/library/system.windows.resourcedictiona...
2008/10/22
[ "https://Stackoverflow.com/questions/224765", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18966/" ]
I am trying to create a user interface using XAML. However, the file is quickly becoming very large and difficult to work with. What is the best way for splitting it across several files. I would like to be able to set the content of an element such as a ComboBox to an element that is defined in a different xaml file ...
You can split a large user interface by defining UserControls. Right-click on the solution tree, choose Add->New Item... then User Control. You can design this in the normal way. You can then reference your usercontrol in XAML using a namespace declaration. Let's say you want to include your UserControl in a Window. ...
224,771
<p>In python how do you read multiple files from a mysql database using the cursor or loop one by one and store the output in a separate table?</p>
[ { "answer_id": 224801, "author": "Vinko Vrsalovic", "author_id": 5190, "author_profile": "https://Stackoverflow.com/users/5190", "pm_score": 1, "selected": false, "text": "<p>I don't understand your question (what are files?, what's your table structure?), but here goes a simple sample:<...
2008/10/22
[ "https://Stackoverflow.com/questions/224771", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17451/" ]
In python how do you read multiple files from a mysql database using the cursor or loop one by one and store the output in a separate table?
I don't understand your question (what are files?, what's your table structure?), but here goes a simple sample: ``` >>> import MySQLdb >>> conn = MySQLdb.connect(host="localhost", user="root", password="merlin", db="files") >>> cursor = ...
224,777
<p>I'm working on a project where we mix .NET code and native C++ code via a C++/CLI layer. In this solution I want to use Thread Local Storage via the __declspec(thread) declaration:</p> <pre><code>__declspec(thread) int lastId = 0; </code></pre> <p>However, at the first access of the variable, I get a NullReference...
[ { "answer_id": 224802, "author": "Bogdan Maxim", "author_id": 23795, "author_profile": "https://Stackoverflow.com/users/23795", "pm_score": 4, "selected": true, "text": "<p>It seems that __declspec(thread) <a href=\"http://blogs.msdn.com/jeremykuhne/archive/2006/04/19/578670.aspx\" rel=\...
2008/10/22
[ "https://Stackoverflow.com/questions/224777", "https://Stackoverflow.com", "https://Stackoverflow.com/users/28572/" ]
I'm working on a project where we mix .NET code and native C++ code via a C++/CLI layer. In this solution I want to use Thread Local Storage via the \_\_declspec(thread) declaration: ``` __declspec(thread) int lastId = 0; ``` However, at the first access of the variable, I get a NullReferenceException. To be more pr...
It seems that \_\_declspec(thread) [isn't supported by CLR](http://blogs.msdn.com/jeremykuhne/archive/2006/04/19/578670.aspx). Take in mind that .net threads aren't necesarily native threads, [but can be also fibers](http://blogs.msdn.com/cbrumme/archive/2003/04/15/51351.aspx), so standard API's for threads don't work...
224,797
<p>I've got the following code to end a process, but I still receive an error code 2 (Access Denied).</p> <pre><code>strComputer = "." Set objWMIService = GetObject("winmgmts:\\" &amp; strComputer &amp; "\root\cimv2") Set colProcessList = objWMIService.ExecQuery("SELECT * FROM Win32_Process WHERE Name = 'MSSEARCH.exe...
[ { "answer_id": 224819, "author": "Zebra North", "author_id": 17440, "author_profile": "https://Stackoverflow.com/users/17440", "pm_score": 3, "selected": true, "text": "<p>It's quite legitimate to get \"access denied\" for ending a program. If it's a service (which I'm guessing mssearch...
2008/10/22
[ "https://Stackoverflow.com/questions/224797", "https://Stackoverflow.com", "https://Stackoverflow.com/users/28139/" ]
I've got the following code to end a process, but I still receive an error code 2 (Access Denied). ``` strComputer = "." Set objWMIService = GetObject("winmgmts:\\" & strComputer & "\root\cimv2") Set colProcessList = objWMIService.ExecQuery("SELECT * FROM Win32_Process WHERE Name = 'MSSEARCH.exe'") For each objProces...
It's quite legitimate to get "access denied" for ending a program. If it's a service (which I'm guessing mssearch.exe is), then it is probably running as the "SYSTEM" user, which has higher privileges than even the Administrator account. You can't log on as the SYSTEM account, but you could probably write a service to...
224,820
<p>I'm trying to figure out how to pass arguments to an anonymous function in JavaScript.</p> <p>Check out this sample code and I think you will see what I mean:</p> <pre><code>&lt;input type="button" value="Click me" id="myButton" /&gt; &lt;script type="text/javascript"&gt; var myButton = document.getElementByI...
[ { "answer_id": 224834, "author": "Sergey Ilinsky", "author_id": 23815, "author_profile": "https://Stackoverflow.com/users/23815", "pm_score": 7, "selected": true, "text": "<p>Your specific case can simply be corrected to be working:</p>\n\n<pre><code>&lt;script type=\"text/javascript\"&g...
2008/10/22
[ "https://Stackoverflow.com/questions/224820", "https://Stackoverflow.com", "https://Stackoverflow.com/users/29886/" ]
I'm trying to figure out how to pass arguments to an anonymous function in JavaScript. Check out this sample code and I think you will see what I mean: ``` <input type="button" value="Click me" id="myButton" /> <script type="text/javascript"> var myButton = document.getElementById("myButton"); var myMessage ...
Your specific case can simply be corrected to be working: ``` <script type="text/javascript"> var myButton = document.getElementById("myButton"); var myMessage = "it's working"; myButton.onclick = function() { alert(myMessage); }; </script> ``` This example will work because the anonymous function created and ...
224,830
<p>I have a large script file (nearly 300MB, and feasibly bigger in the future) that I am trying to run. It has been suggested in the comments of Gulzar's answer to my <a href="https://stackoverflow.com/questions/222442/sql-server-running-large-script-files">question about it</a> that I should change the script timeou...
[ { "answer_id": 224955, "author": "splattne", "author_id": 6461, "author_profile": "https://Stackoverflow.com/users/6461", "pm_score": 2, "selected": false, "text": "<p>I think there is <strong>no concept of timeout within a SQL script</strong> on SQL Server. You have to set the timeout i...
2008/10/22
[ "https://Stackoverflow.com/questions/224830", "https://Stackoverflow.com", "https://Stackoverflow.com/users/192/" ]
I have a large script file (nearly 300MB, and feasibly bigger in the future) that I am trying to run. It has been suggested in the comments of Gulzar's answer to my [question about it](https://stackoverflow.com/questions/222442/sql-server-running-large-script-files) that I should change the script timeout to 0 (no time...
``` sqlcmd -t {n} ``` Where {n} must be a number between 0 and 65535. Note that your question is a bit misleading since [the server has no concept of a timeout](http://blogs.msdn.com/khen1234/archive/2005/10/20/483015.aspx) and therefore you cannot set the timeout within your script. In your context the timeout is...
224,845
<p>I am using the ruby daemons gem to create a custom daemon for my rails project. The only problem is that when I try to start the daemons <code>ruby lib/daemons/test_ctl start</code> that it fails and will not start. The log file has this output.</p> <pre><code># Logfile created on Wed Oct 22 16:14:23 +0000 2008 by...
[ { "answer_id": 224990, "author": "Josh Moore", "author_id": 5004, "author_profile": "https://Stackoverflow.com/users/5004", "pm_score": 3, "selected": true, "text": "<p>OK, I actually found the answer to this problem. I require two custom files in the <code>config/environment.rb</code>....
2008/10/22
[ "https://Stackoverflow.com/questions/224845", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5004/" ]
I am using the ruby daemons gem to create a custom daemon for my rails project. The only problem is that when I try to start the daemons `ruby lib/daemons/test_ctl start` that it fails and will not start. The log file has this output. ``` # Logfile created on Wed Oct 22 16:14:23 +0000 2008 by / *** below you find th...
OK, I actually found the answer to this problem. I require two custom files in the `config/environment.rb`. I used relative path names and because the daemons are executed in the rails main directory it could not find these two files. after making them absolute path it fixed the problem.
224,865
<p>I'm wondering if there are any simple ways to get a list of all fixed-width (monospaced) fonts installed on a user's system in C#?</p> <p>I'm using .net 3.5 so have access to the WPF System.Windows.Media namespace and LINQ to get font information, but I'm not sure what I'm looking for.</p> <p>I want to be able to ...
[ { "answer_id": 224917, "author": "aku", "author_id": 1196, "author_profile": "https://Stackoverflow.com/users/1196", "pm_score": 3, "selected": false, "text": "<p>AFAIK you can't do it using BCL libraries only. You have to use WinAPI interop.</p>\n\n<p>You need to analyze 2 lowest bits o...
2008/10/22
[ "https://Stackoverflow.com/questions/224865", "https://Stackoverflow.com", "https://Stackoverflow.com/users/483/" ]
I'm wondering if there are any simple ways to get a list of all fixed-width (monospaced) fonts installed on a user's system in C#? I'm using .net 3.5 so have access to the WPF System.Windows.Media namespace and LINQ to get font information, but I'm not sure what I'm looking for. I want to be able to provide a filtere...
Have a look at: <http://www.pinvoke.net/default.aspx/Structures/LOGFONT.html> Use one of the structures in there, then loop over families, instantiating a Font, and getting the LogFont value and checking lfPitchAndFamily. The following code is written on the fly and untested, but something like the following should ...
224,868
<p>I know it's simple to implement, but I want to reuse something that already exist.</p> <p>Problem I want to solve is that I load configuration (from XML so I want to cache them) for different pages, roles, ... so the combination of inputs can grow quite much (but in 99% will not). To handle this 1%, I want to have ...
[ { "answer_id": 224886, "author": "Guido", "author_id": 12388, "author_profile": "https://Stackoverflow.com/users/12388", "pm_score": 8, "selected": true, "text": "<p>You can use a <a href=\"http://docs.oracle.com/javase/6/docs/api/index.html?java/util/LinkedHashMap.html\" rel=\"noreferre...
2008/10/22
[ "https://Stackoverflow.com/questions/224868", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1128722/" ]
I know it's simple to implement, but I want to reuse something that already exist. Problem I want to solve is that I load configuration (from XML so I want to cache them) for different pages, roles, ... so the combination of inputs can grow quite much (but in 99% will not). To handle this 1%, I want to have some max n...
You can use a [LinkedHashMap](http://docs.oracle.com/javase/6/docs/api/index.html?java/util/LinkedHashMap.html) (Java 1.4+) : ``` // Create cache final int MAX_ENTRIES = 100; Map cache = new LinkedHashMap(MAX_ENTRIES+1, .75F, true) { // This method is called just after a new entry has been added public boolean...
224,875
<p>Is it possible to do the equivalent of the following in xslt:</p> <pre><code>.//TagA[./TagB/[@AttrA='AttrAValue'] = 'TagBValue'] </code></pre> <p>This is failing within Visual Studio 2008 with the following error:</p> <pre><code>error: Unexpected token '[' in the expression. .//TagA[./TagB/ --&gt;[&lt;-- @AttrA='...
[ { "answer_id": 224886, "author": "Guido", "author_id": 12388, "author_profile": "https://Stackoverflow.com/users/12388", "pm_score": 8, "selected": true, "text": "<p>You can use a <a href=\"http://docs.oracle.com/javase/6/docs/api/index.html?java/util/LinkedHashMap.html\" rel=\"noreferre...
2008/10/22
[ "https://Stackoverflow.com/questions/224875", "https://Stackoverflow.com", "https://Stackoverflow.com/users/30273/" ]
Is it possible to do the equivalent of the following in xslt: ``` .//TagA[./TagB/[@AttrA='AttrAValue'] = 'TagBValue'] ``` This is failing within Visual Studio 2008 with the following error: ``` error: Unexpected token '[' in the expression. .//TagA[./TagB/ -->[<-- @AttrA='AttrAValue'] = 'TagBValue'] ``` Should th...
You can use a [LinkedHashMap](http://docs.oracle.com/javase/6/docs/api/index.html?java/util/LinkedHashMap.html) (Java 1.4+) : ``` // Create cache final int MAX_ENTRIES = 100; Map cache = new LinkedHashMap(MAX_ENTRIES+1, .75F, true) { // This method is called just after a new entry has been added public boolean...
224,878
<p>What is the best way to find out whether two number ranges intersect?</p> <p>My number range is <strong>3023-7430</strong>, now I want to test which of the following number ranges intersect with it: &lt;3000, 3000-6000, 6000-8000, 8000-10000, >10000. The answer should be <strong>3000-6000</strong> and <strong>6000-...
[ { "answer_id": 224897, "author": "Chris Kimpton", "author_id": 48310, "author_profile": "https://Stackoverflow.com/users/48310", "pm_score": 5, "selected": true, "text": "<p>Just a pseudo code guess:</p>\n\n<pre><code>Set&lt;Range&gt; determineIntersectedRanges(Range range, Set&lt;Range&...
2008/10/22
[ "https://Stackoverflow.com/questions/224878", "https://Stackoverflow.com", "https://Stackoverflow.com/users/476/" ]
What is the best way to find out whether two number ranges intersect? My number range is **3023-7430**, now I want to test which of the following number ranges intersect with it: <3000, 3000-6000, 6000-8000, 8000-10000, >10000. The answer should be **3000-6000** and **6000-8000**. What's the nice, efficient mathemati...
Just a pseudo code guess: ``` Set<Range> determineIntersectedRanges(Range range, Set<Range> setofRangesToTest) { Set<Range> results; foreach (rangeToTest in setofRangesToTest) do if (rangeToTest.end <range.start) continue; // skip this one, its below our range if (rangeToTest.start >range.end) continue; ...
224,926
<p>for example, I have the following xml document:</p> <pre><code>def CAR_RECORDS = ''' &lt;records&gt; &lt;car name='HSV Maloo' make='Holden' year='2006'/&gt; &lt;car name='P50' make='Peel' year='1962'/&gt; &lt;car name='Royale' make='Bugatti' year='1931'/&gt; &lt;/records&gt; ''' </code></p...
[ { "answer_id": 227467, "author": "danb", "author_id": 2031, "author_profile": "https://Stackoverflow.com/users/2031", "pm_score": 2, "selected": false, "text": "<p>&lt;hand-wave>\n<em>these are not the codz you seek</em>\n&lt;/hand-wave></p>\n\n<pre><code>Node root = new XmlParser().pars...
2008/10/22
[ "https://Stackoverflow.com/questions/224926", "https://Stackoverflow.com", "https://Stackoverflow.com/users/30275/" ]
for example, I have the following xml document: ``` def CAR_RECORDS = ''' <records> <car name='HSV Maloo' make='Holden' year='2006'/> <car name='P50' make='Peel' year='1962'/> <car name='Royale' make='Bugatti' year='1931'/> </records> ''' ``` and I want to move the car "Royale" up to first ...
I went down a similar route to danb, but ran into problems when actually printing out the resulting XML. Then I realized that the NodeList that was returned by asking the root for all of it's "car" children isn't the same list as you get by just asking for the root's children. Even though they happen to be the same lis...
224,952
<p>What ist most concise way to read the contents of a file or input stream in Java? Do I always have to create a buffer, read (at most) line by line and so on or is there a more concise way? I wish I could do just</p> <pre><code>String content = new File("test.txt").readFully(); </code></pre>
[ { "answer_id": 224970, "author": "Lars Westergren", "author_id": 15627, "author_profile": "https://Stackoverflow.com/users/15627", "pm_score": 1, "selected": false, "text": "<pre><code>String content = (new RandomAccessFile(new File(\"test.txt\"))).readUTF();\n</code></pre>\n\n<p>Unfortu...
2008/10/22
[ "https://Stackoverflow.com/questions/224952", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18722/" ]
What ist most concise way to read the contents of a file or input stream in Java? Do I always have to create a buffer, read (at most) line by line and so on or is there a more concise way? I wish I could do just ``` String content = new File("test.txt").readFully(); ```
Use the [Apache Commons IOUtils](http://commons.apache.org/io/description.html) package. In particular the `IOUtils` class provides a set of methods to read from streams, readers etc. and handle all the exceptions etc. e.g. ``` InputStream is = ... String contents = IOUtils.toString(is); // or List lines = IOUtils.r...
224,969
<p>I have a string (char) and I want to extract numbers out of it.</p> <p>So I have string: <code>1 2 3 4 /0</code><br> And now I want some variables, so I can use them as integer: <code>a=1, a=2, a=3, a=4</code></p> <p>How can I do that?</p>
[ { "answer_id": 224994, "author": "Ignacio Vazquez-Abrams", "author_id": 20862, "author_profile": "https://Stackoverflow.com/users/20862", "pm_score": 2, "selected": false, "text": "<p>sscanf() can do that.</p>\n\n<pre><code>#include &lt;stdio.h&gt;\n\nint main(void)\n{\n int a, b, c, d;...
2008/10/22
[ "https://Stackoverflow.com/questions/224969", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
I have a string (char) and I want to extract numbers out of it. So I have string: `1 2 3 4 /0` And now I want some variables, so I can use them as integer: `a=1, a=2, a=3, a=4` How can I do that?
If the string always contains 4 numbers delimited with spaces, then it could be done with sscanf: ``` sscanf(string, "%d %d %d %d", &a, &b, &c, &d); ``` If the count of numbers varies, then you would need to parse the string. Please clarify your question accordingly.
225,045
<p>I've been reading up on conditional-style expressions in ruby. However I came across one I couldn't quite understand to define the classic FizzBuzz problem. I understand the FizzBuzz problem and even wrote my own before finding the following quick solution utilising the ternary operator. If someone can explain to me...
[ { "answer_id": 225055, "author": "Greg Hewgill", "author_id": 893, "author_profile": "https://Stackoverflow.com/users/893", "pm_score": 5, "selected": true, "text": "<p>Some parentheses might help:</p>\n\n<pre><code>puts (i%3 == 0) ? ((i%5 == 0) ? \"FizzBuzz\" : \"Buzz\") : ((i%5 == 0) ?...
2008/10/22
[ "https://Stackoverflow.com/questions/225045", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2294/" ]
I've been reading up on conditional-style expressions in ruby. However I came across one I couldn't quite understand to define the classic FizzBuzz problem. I understand the FizzBuzz problem and even wrote my own before finding the following quick solution utilising the ternary operator. If someone can explain to me ho...
Some parentheses might help: ``` puts (i%3 == 0) ? ((i%5 == 0) ? "FizzBuzz" : "Buzz") : ((i%5 == 0) ? "Fizz" : i) ``` So, if i is divisible by 3, then it checks whether i is also divisible by 5. If so, it prints "FizzBuzz" otherwise just "Buzz". If i is not divisible by three, then it checks divisibility by 5 again ...
225,080
<p>I'm trying to configure an ejabberd installation, using LDAP authentication, but I just can't login, even with the admin user. This is part of my ejabberd.cfg file:</p> <pre><code>%... {auth_method, ldap}. {ldap_servers, ["server2000.tek2000.local"]}. {ldap_port,389}. {ldap_uidattr, "uid"}. {ldap_base, "dc=server20...
[ { "answer_id": 225077, "author": "Jon Skeet", "author_id": 22656, "author_profile": "https://Stackoverflow.com/users/22656", "pm_score": 6, "selected": true, "text": "<p>Use a <a href=\"http://java.sun.com/javase/6/docs/api/java/io/ByteArrayOutputStream.html\" rel=\"noreferrer\">ByteArra...
2008/10/22
[ "https://Stackoverflow.com/questions/225080", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2019426/" ]
I'm trying to configure an ejabberd installation, using LDAP authentication, but I just can't login, even with the admin user. This is part of my ejabberd.cfg file: ``` %... {auth_method, ldap}. {ldap_servers, ["server2000.tek2000.local"]}. {ldap_port,389}. {ldap_uidattr, "uid"}. {ldap_base, "dc=server2000,dc=tek2000,...
Use a [ByteArrayOutputStream](http://java.sun.com/javase/6/docs/api/java/io/ByteArrayOutputStream.html) and then get the data out of that using [toByteArray()](http://java.sun.com/javase/6/docs/api/java/io/ByteArrayOutputStream.html#toByteArray()). This won't test *how* it writes to the stream (one byte at a time or as...
225,086
<p>Is there a fairly easy way to convert a datetime object into an RFC 1123 (HTTP/1.1) date/time string, i.e. a string with the format</p> <pre><code>Sun, 06 Nov 1994 08:49:37 GMT </code></pre> <p>Using <code>strftime</code> does not work, since the strings are locale-dependant. Do I have to build the string by hand?...
[ { "answer_id": 225101, "author": "Ignacio Vazquez-Abrams", "author_id": 20862, "author_profile": "https://Stackoverflow.com/users/20862", "pm_score": 2, "selected": false, "text": "<p>You can set LC_TIME to force stftime() to use a specific locale:</p>\n\n<pre><code>&gt;&gt;&gt; locale.s...
2008/10/22
[ "https://Stackoverflow.com/questions/225086", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7779/" ]
Is there a fairly easy way to convert a datetime object into an RFC 1123 (HTTP/1.1) date/time string, i.e. a string with the format ``` Sun, 06 Nov 1994 08:49:37 GMT ``` Using `strftime` does not work, since the strings are locale-dependant. Do I have to build the string by hand?
You can use wsgiref.handlers.format\_date\_time from the stdlib which does not rely on locale settings ``` from wsgiref.handlers import format_date_time from datetime import datetime from time import mktime now = datetime.now() stamp = mktime(now.timetuple()) print format_date_time(stamp) #--> Wed, 22 Oct 2008 10:52:...
225,089
<p>Why can't we initialize members inside a structure ?</p> <p>example:</p> <pre><code>struct s { int i = 10; }; </code></pre>
[ { "answer_id": 225092, "author": "Alex B", "author_id": 23643, "author_profile": "https://Stackoverflow.com/users/23643", "pm_score": 5, "selected": false, "text": "<p>If you want to initialize <strong>non-static</strong> members in <code>struct</code> <strong>declaration</strong>:</p>\n...
2008/10/22
[ "https://Stackoverflow.com/questions/225089", "https://Stackoverflow.com", "https://Stackoverflow.com/users/21599/" ]
Why can't we initialize members inside a structure ? example: ``` struct s { int i = 10; }; ```
If you want to initialize **non-static** members in `struct` **declaration**: In C++ (not C), `structs` are almost synonymous to classes and can have members initialized in the constructor. ``` struct s { int i; s(): i(10) { } }; ``` If you want to initialize an **instance**: In C or C++: ``` str...
225,096
<p>I'm starting to look into the whole world of RJS and Prototype/jQuery in Rails and am a little bit confused. There seems to be no clear line of where to use one or the other.</p> <p>Say I wanted one of the "Active, Hot, Week" tabs like the ones here on SO. When pressing one of them, I want to remove a CSS class (li...
[ { "answer_id": 225306, "author": "Codebeef", "author_id": 12037, "author_profile": "https://Stackoverflow.com/users/12037", "pm_score": 2, "selected": true, "text": "<p>If you want to give users that ability to link to the generated page directly, then definitly go for a static page. Usi...
2008/10/22
[ "https://Stackoverflow.com/questions/225096", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9191/" ]
I'm starting to look into the whole world of RJS and Prototype/jQuery in Rails and am a little bit confused. There seems to be no clear line of where to use one or the other. Say I wanted one of the "Active, Hot, Week" tabs like the ones here on SO. When pressing one of them, I want to remove a CSS class (like "active...
If you want to give users that ability to link to the generated page directly, then definitly go for a static page. Using AJAX breaks the back button unless you use something like [Really Simple History](http://code.google.com/p/reallysimplehistory/) ([which is not 100% cross browser](http://code.google.com/p/reallysim...
225,103
<p>I'm writing a MUD engine and I've just started on the game object model, which needs to be extensible.</p> <p>I need help mainly because what I've done feels messy, but I can't think of a another solution that works better.</p> <p>I have a class called <code>MudObject</code>, and another class called <code>Contain...
[ { "answer_id": 225120, "author": "Jon Limjap", "author_id": 372, "author_profile": "https://Stackoverflow.com/users/372", "pm_score": 1, "selected": false, "text": "<p>What you want is quite reasonable: it's no different from Windows form controls, which can itself be a container of othe...
2008/10/22
[ "https://Stackoverflow.com/questions/225103", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1610/" ]
I'm writing a MUD engine and I've just started on the game object model, which needs to be extensible. I need help mainly because what I've done feels messy, but I can't think of a another solution that works better. I have a class called `MudObject`, and another class called `Container`, A container can contain mult...
What you're asking for is reasonable, and is the [Composite Design Pattern](http://home.earthlink.net/~huston2/dp/composite.html)
225,114
<pre><code>&lt;td title="this is a really long line that I'm going to truncate"&gt;this is a really long line that I'm going to trunc ...&lt;/td&gt; </code></pre> <p>Is this the correct way to do it?</p>
[ { "answer_id": 225131, "author": "Tamas Czinege", "author_id": 8954, "author_profile": "https://Stackoverflow.com/users/8954", "pm_score": 0, "selected": false, "text": "<p>Yes, that's how you supposed to assign tooltips to html elements. I wouldn't use it on &lt;td&gt; though. Although ...
2008/10/22
[ "https://Stackoverflow.com/questions/225114", "https://Stackoverflow.com", "https://Stackoverflow.com/users/21559/" ]
``` <td title="this is a really long line that I'm going to truncate">this is a really long line that I'm going to trunc ...</td> ``` Is this the correct way to do it?
The `title` attribute doesn't work inside the `td` tag. Enclose the text within a span tag instead: ``` <td> <span title="this is a really long line that I'm going to truncate">this is a really long line that I'm going to trunc ...</span> </td> ```
225,130
<p>I'm tryint to post to a ADO.NET Data Service but the parameters seems to get lost along the way.</p> <p>I got something like:</p> <pre><code>[WebInvoke(Method="POST")] public int MyMethod(int foo, string bar) {...} </code></pre> <p>and I make an ajax-call using prototype.js as:</p> <pre><code>var args = {foo: 4,...
[ { "answer_id": 225164, "author": "Ray Lu", "author_id": 11413, "author_profile": "https://Stackoverflow.com/users/11413", "pm_score": 0, "selected": false, "text": "<p>If you want to use POST, you need to specify the parameters to be wrapped in the request in WebInvoke attribute unless t...
2008/10/22
[ "https://Stackoverflow.com/questions/225130", "https://Stackoverflow.com", "https://Stackoverflow.com/users/24044/" ]
I'm tryint to post to a ADO.NET Data Service but the parameters seems to get lost along the way. I got something like: ``` [WebInvoke(Method="POST")] public int MyMethod(int foo, string bar) {...} ``` and I make an ajax-call using prototype.js as: ``` var args = {foo: 4, bar: "'test'"}; new Ajax.Requst(baseurl + '...
WCF and ASMX webservices tend to be a bit choosey about the request body, when you specify args the request is usually encoded as a form post i.e. foo=4&bar=test instead you need to specify the javascript literal:- ``` new Ajax.Request(baseurl + 'MyMethod', { method: 'POST', postBody: '{"foo":4, "ba...
225,149
<p>Guys, I’ve been writing code for 15+ years, but managed to avoid “Web Development” until 3 months ago.</p> <p>I have inherited a legacy Asp.net application (started in .net 1.1, we’re now on .Net 2.0), it’s the administration tool for our product.</p> <p>In several places the admin tool simply maintains long lists...
[ { "answer_id": 225187, "author": "Ray Lu", "author_id": 11413, "author_profile": "https://Stackoverflow.com/users/11413", "pm_score": 1, "selected": false, "text": "<p>The simplest way you can do is to pass back an id from PageB in the querystring in the URL while redirecting back to Pa...
2008/10/22
[ "https://Stackoverflow.com/questions/225149", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18797/" ]
Guys, I’ve been writing code for 15+ years, but managed to avoid “Web Development” until 3 months ago. I have inherited a legacy Asp.net application (started in .net 1.1, we’re now on .Net 2.0), it’s the administration tool for our product. In several places the admin tool simply maintains long lists of values. The ...
This could be achieved using Anchor Tags. When you output your elements on Page A, set an anchor tag next to each element like follows: ``` <a name="#175"></a> ``` Where this item would be item id 175. Then when you redirect back to PageA, add a "#175" onto the end of the url ``` Response.Redirect("PageA.aspx#175")...
225,233
<p>No I'm not being a wise guy ...</p> <p>For those fortunate enough to not know the My class: It's something that was <strong>added in VB 2005 (and doesn't exist in C#) and is best described as a 'speeddial for the .net framework'.</strong> Supposed to make life easier for newbies who won't read which framework clas...
[ { "answer_id": 225255, "author": "Jon Skeet", "author_id": 22656, "author_profile": "https://Stackoverflow.com/users/22656", "pm_score": 3, "selected": true, "text": "<p>It's the \"My namespace\" rather than the \"My class\" which may aid searching.</p>\n\n<p>So far I've found this: <a h...
2008/10/22
[ "https://Stackoverflow.com/questions/225233", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1695/" ]
No I'm not being a wise guy ... For those fortunate enough to not know the My class: It's something that was **added in VB 2005 (and doesn't exist in C#) and is best described as a 'speeddial for the .net framework'.** Supposed to make life easier for newbies who won't read which framework classes they should be usin...
It's the "My namespace" rather than the "My class" which may aid searching. So far I've found this: <http://msdn.microsoft.com/en-us/vbasic/ms789188.aspx> but it's not ideal. Looking for more... EDIT: I think ["Developing with My"](http://msdn.microsoft.com/en-us/library/5btzf5yk.aspx) is effectively the root of the ...
225,250
<p>I have a 3rd-party library which for various reasons I don't wish to link against yet. I don't want to butcher my code though to remove all reference to its API, so I'd like to generate a dummy implementation of it.</p> <p>Is there any tool I can use which spits out empty definitions of classes given their header ...
[ { "answer_id": 226368, "author": "Vinay", "author_id": 28641, "author_profile": "https://Stackoverflow.com/users/28641", "pm_score": 0, "selected": false, "text": "<p>Create one test application which reads the header file and creates the source file. Test application should parse the he...
2008/10/22
[ "https://Stackoverflow.com/questions/225250", "https://Stackoverflow.com", "https://Stackoverflow.com/users/23434/" ]
I have a 3rd-party library which for various reasons I don't wish to link against yet. I don't want to butcher my code though to remove all reference to its API, so I'd like to generate a dummy implementation of it. Is there any tool I can use which spits out empty definitions of classes given their header files? It's...
This is a harder problem than you might like, as parsing C++ can quickly become a difficult task. Your best bet would be to pick an existing parser with a nice interface. A quick search found [this thread](http://compilers.iecc.com/comparch/article/06-09-169) which has many recommendations for parsers to do something ...
225,263
<p>Lets say I have a single object of type Car which I want to render as HTML:</p> <pre><code>class Car { public int Wheels { get; set; } public string Model { get; set; } } </code></pre> <p>I don't want to use the ASP.NET Repeater or ListView controls to bind because it seems too verbose. I just have the one obj...
[ { "answer_id": 225278, "author": "Maxime Rouiller", "author_id": 24975, "author_profile": "https://Stackoverflow.com/users/24975", "pm_score": 6, "selected": true, "text": "<p>if the page is about a specific item (For exemple, Car.aspx?CarID=ABC123), I normally have a public property on ...
2008/10/22
[ "https://Stackoverflow.com/questions/225263", "https://Stackoverflow.com", "https://Stackoverflow.com/users/30056/" ]
Lets say I have a single object of type Car which I want to render as HTML: ``` class Car { public int Wheels { get; set; } public string Model { get; set; } } ``` I don't want to use the ASP.NET Repeater or ListView controls to bind because it seems too verbose. I just have the one object. But I still want to b...
if the page is about a specific item (For exemple, Car.aspx?CarID=ABC123), I normally have a public property on the page called "CurrentCar" ``` public Car CurrentCar { get; set; } ``` And I can then have the following: ``` <div> Wheels: <%= CurrentCar.Wheels %><br /> Model: <%= CurrentCar.Model %> </div> ``` ...
225,291
<p>I have been using git to keep two copies of my project in sync, one is my local box, the other the test server. This is an issue which occurs when I log onto our remote development server using ssh;</p> <pre><code>git clone me@me.mydevbox.com:/home/chris/myproject Initialized empty Git repository in /tmp/myproject/...
[ { "answer_id": 225315, "author": "Matt Curtis", "author_id": 17221, "author_profile": "https://Stackoverflow.com/users/17221", "pm_score": 8, "selected": true, "text": "<p>Make sure <code>git-upload-pack</code> is on the path from a non-login shell. (On my machine it's in <code>/usr/bin<...
2008/10/22
[ "https://Stackoverflow.com/questions/225291", "https://Stackoverflow.com", "https://Stackoverflow.com/users/24508/" ]
I have been using git to keep two copies of my project in sync, one is my local box, the other the test server. This is an issue which occurs when I log onto our remote development server using ssh; ``` git clone me@me.mydevbox.com:/home/chris/myproject Initialized empty Git repository in /tmp/myproject/.git/ Password...
Make sure `git-upload-pack` is on the path from a non-login shell. (On my machine it's in `/usr/bin`). To see what your path looks like on the remote machine from a non-login shell, try this: ``` ssh you@remotemachine echo \$PATH ``` (That works in Bash, Zsh, and tcsh, and probably other shells too.) If the path i...
225,309
<p>Today i stumbled upon an interesting performance problem with a stored procedure running on Sql Server 2005 SP2 in a db running on compatible level of 80 (SQL2000).</p> <p>The proc runs about 8 Minutes and the execution plan shows the usage of an index with an actual row count of 1.339.241.423 which is about facto...
[ { "answer_id": 225401, "author": "Tomalak", "author_id": 18771, "author_profile": "https://Stackoverflow.com/users/18771", "pm_score": 0, "selected": false, "text": "<p>To me it still sounds as if the statistics were incorrect. Rebuilding the indexes does not necessarily update them.</p>...
2008/10/22
[ "https://Stackoverflow.com/questions/225309", "https://Stackoverflow.com", "https://Stackoverflow.com/users/25727/" ]
Today i stumbled upon an interesting performance problem with a stored procedure running on Sql Server 2005 SP2 in a db running on compatible level of 80 (SQL2000). The proc runs about 8 Minutes and the execution plan shows the usage of an index with an actual row count of 1.339.241.423 which is about factor 1000 high...
Ok, finally i got to it myself. The two query plans are different in a small detail which i missed at first. the slow one uses a nested loops operator to join two subqueries together. And that results in the high number at current row count on the index scan operator which is simply the result of multiplicating the nu...
225,327
<p>Currently I am working with a <strong>custom</strong> regular expression validator <em>(unfortunately)</em>.</p> <p>I am trying to set the Regex pattern using a server side inline script like this:</p> <pre><code>ValidationExpression="&lt;%= RegExStrings.SomePattern %&gt;" </code></pre> <p>However, the script is ...
[ { "answer_id": 225343, "author": "WebDude", "author_id": 15360, "author_profile": "https://Stackoverflow.com/users/15360", "pm_score": 0, "selected": false, "text": "<p>Values in a web control do not render server side code.\nRather set that from the Code Behind</p>\n\n<pre><code>RegExVa...
2008/10/22
[ "https://Stackoverflow.com/questions/225327", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11702/" ]
Currently I am working with a **custom** regular expression validator *(unfortunately)*. I am trying to set the Regex pattern using a server side inline script like this: ``` ValidationExpression="<%= RegExStrings.SomePattern %>" ``` However, the script is not resolving to server side code. Instead it is being inte...
This has now been cleared up my MS. The issue I discovered was caused by the fact that the "action" attribute in server forms had no effect prior to .NET 2 SP2, but now can be set. Code render blocks have never worked in attribute values - this is explained towards the end of this post. This was a consequence of a del...
225,330
<p>I'm writing a tool to report information about .NET applications deployed across environments and regions within my client's systems.</p> <p>I'd like to read the values of assembly attributes in these assemblies.</p> <p>This can be achieved using <code>Assembly.ReflectionOnlyLoad</code>, however even this approach...
[ { "answer_id": 225355, "author": "Tamas Czinege", "author_id": 8954, "author_profile": "https://Stackoverflow.com/users/8954", "pm_score": 7, "selected": true, "text": "<p>From the <a href=\"http://msdn.microsoft.com/en-us/library/0et80c7k.aspx\" rel=\"noreferrer\">MSDN documentation of ...
2008/10/22
[ "https://Stackoverflow.com/questions/225330", "https://Stackoverflow.com", "https://Stackoverflow.com/users/24874/" ]
I'm writing a tool to report information about .NET applications deployed across environments and regions within my client's systems. I'd like to read the values of assembly attributes in these assemblies. This can be achieved using `Assembly.ReflectionOnlyLoad`, however even this approach keeps the assembly loaded. ...
From the [MSDN documentation of System.Reflection.Assembly.ReflectionOnlyLoad (String)](http://msdn.microsoft.com/en-us/library/0et80c7k.aspx) : > > The reflection-only context is no > different from other contexts. > Assemblies that are loaded into the > context can be unloaded only by > unloading the applicatio...
225,337
<p>What regex pattern would need I to pass to <code>java.lang.String.split()</code> to split a String into an Array of substrings using all whitespace characters (<code>' '</code>, <code>'\t'</code>, <code>'\n'</code>, etc.) as delimiters?</p>
[ { "answer_id": 225349, "author": "VonC", "author_id": 6309, "author_profile": "https://Stackoverflow.com/users/6309", "pm_score": 5, "selected": false, "text": "<p>\"\\\\s+\" should do the trick</p>\n" }, { "answer_id": 225354, "author": "glenatron", "author_id": 15394, ...
2008/10/22
[ "https://Stackoverflow.com/questions/225337", "https://Stackoverflow.com", "https://Stackoverflow.com/users/30323/" ]
What regex pattern would need I to pass to `java.lang.String.split()` to split a String into an Array of substrings using all whitespace characters (`' '`, `'\t'`, `'\n'`, etc.) as delimiters?
Something in the lines of ``` myString.split("\\s+"); ``` This groups all white spaces as a delimiter. So if I have the string: ``` "Hello[space character][tab character]World" ``` This should yield the strings `"Hello"` and `"World"` and omit the empty space between the `[space]` and the `[tab]`. As VonC point...
225,357
<p>I have to develop a system to <strong>monitor</strong> the <strong>generation/transmission</strong> of reports.</p> <ul> <li>System data will be stored in database tables (Sybase)</li> <li>Reports will be generated with different schedules ("mon-fri 10pm", "sat 5am", "1st day of the month", etc.)</li> <li>System wi...
[ { "answer_id": 225349, "author": "VonC", "author_id": 6309, "author_profile": "https://Stackoverflow.com/users/6309", "pm_score": 5, "selected": false, "text": "<p>\"\\\\s+\" should do the trick</p>\n" }, { "answer_id": 225354, "author": "glenatron", "author_id": 15394, ...
2008/10/22
[ "https://Stackoverflow.com/questions/225357", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15884/" ]
I have to develop a system to **monitor** the **generation/transmission** of reports. * System data will be stored in database tables (Sybase) * Reports will be generated with different schedules ("mon-fri 10pm", "sat 5am", "1st day of the month", etc.) * System will just monitor that the reports were created. It will...
Something in the lines of ``` myString.split("\\s+"); ``` This groups all white spaces as a delimiter. So if I have the string: ``` "Hello[space character][tab character]World" ``` This should yield the strings `"Hello"` and `"World"` and omit the empty space between the `[space]` and the `[tab]`. As VonC point...
225,362
<p>I have some numbers of different length (like 1, 999, 76492, so on) and I want to convert them all to strings with a common length (for example, if the length is 6, then those strings will be: '000001', '000999', '076492'). </p> <p>In other words, I need to add correct amount of leading zeros to the number.</p> <p...
[ { "answer_id": 225372, "author": "Pramod", "author_id": 1386292, "author_profile": "https://Stackoverflow.com/users/1386292", "pm_score": 2, "selected": false, "text": "<p>There are many ways of doing this. The simplest would be:</p>\n\n<pre><code>int n = 999;\nchar buffer[256]; sprintf(...
2008/10/22
[ "https://Stackoverflow.com/questions/225362", "https://Stackoverflow.com", "https://Stackoverflow.com/users/26276/" ]
I have some numbers of different length (like 1, 999, 76492, so on) and I want to convert them all to strings with a common length (for example, if the length is 6, then those strings will be: '000001', '000999', '076492'). In other words, I need to add correct amount of leading zeros to the number. ``` int n = 999;...
or using the stringstreams: ``` #include <sstream> #include <iomanip> std::stringstream ss; ss << std::setw(10) << std::setfill('0') << i; std::string s = ss.str(); ``` I compiled the information I found on [arachnoid.com](http://www.arachnoid.com/cpptutor/student3.html) because I like the type-safe way of iostream...
225,367
<p>Yes, I know you could use regular objects as associative arrays in JavaScript, but I'd like to use something closer to java's Map's implementation (HashMap, LinkedHashMap etc). Something that could have any kind of data used as key. Are there any good hash(code/table) in JavaScript implementation out there?</p>
[ { "answer_id": 225403, "author": "keparo", "author_id": 19468, "author_profile": "https://Stackoverflow.com/users/19468", "pm_score": 6, "selected": true, "text": "<p>In javascript, <strong>objects are literally a hash implementation</strong>. A Java HashMap will be a little bit of a fa...
2008/10/22
[ "https://Stackoverflow.com/questions/225367", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12540/" ]
Yes, I know you could use regular objects as associative arrays in JavaScript, but I'd like to use something closer to java's Map's implementation (HashMap, LinkedHashMap etc). Something that could have any kind of data used as key. Are there any good hash(code/table) in JavaScript implementation out there?
In javascript, **objects are literally a hash implementation**. A Java HashMap will be a little bit of a fake-out, so I'd **challenge you** to re-think your needs. The **straight answer is no**, I don't believe that there is a great implementation of Java's HashMap in javascript. If there is, it's bound to be part of ...
225,371
<p>How else might you compare two arrays ($A and $B )and reduce matching elements out of the first to prep for the next loop over the array $A?</p> <pre><code>$A = array(1,2,3,4,5,6,7,8); $B = array(1,2,3,4); $C = array_intersect($A,$B); //equals (1,2,3,4) $A = array_diff($A,$B); //equals (5,6,7,8) </code></pr...
[ { "answer_id": 225678, "author": "rg88", "author_id": 11252, "author_profile": "https://Stackoverflow.com/users/11252", "pm_score": 6, "selected": true, "text": "<p>You've got it. Just use <code>array_diff</code> or <code>array_intersect</code>. Doesn't get much easier than that.</p>\n\n...
2008/10/22
[ "https://Stackoverflow.com/questions/225371", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1149/" ]
How else might you compare two arrays ($A and $B )and reduce matching elements out of the first to prep for the next loop over the array $A? ``` $A = array(1,2,3,4,5,6,7,8); $B = array(1,2,3,4); $C = array_intersect($A,$B); //equals (1,2,3,4) $A = array_diff($A,$B); //equals (5,6,7,8) ``` Is this the simples...
You've got it. Just use `array_diff` or `array_intersect`. Doesn't get much easier than that. **Edit:** For example: ``` $arr_1 = array_diff($arr_1, $arr_2); $arr_2 = array_diff($arr_2, $arr_1); ``` [Source](https://stackoverflow.com/a/8691348/2210140)