qid int64 4 22.2M | question stringlengths 18 48.3k | answers list | date stringlengths 10 10 | metadata list |
|---|---|---|---|---|
275,544 | <p>I know in a lot of asynchronous communication, the packet begins starts with a start bit.</p>
<p>But a start bit is just a 1 or 0. How do you differentiate a start bit from the end bit from the last packet?</p>
<p>Ex.
If I choose my start bit to be 0 and my end bit to be 1.
and I receive 0 (data stream A) 1 0 (data stream B) 1,
what's there to stop me from assuming there is a data stream C which contains the same contents of "(data stream A) 1 0 (data stream B)" ?</p>
<p>Isn't it more convenient to have a start BYTE and then check the data stream for that combination of bits? That will reduce the possibility of a confusing between the start/end bit.</p>
| [
{
"answer_id": 275554,
"author": "Adam Liss",
"author_id": 29157,
"author_profile": "https://Stackoverflow.com/users/29157",
"pm_score": 3,
"selected": false,
"text": "ABC"
}
] | 2008/11/09 | [
"https://Stackoverflow.com/questions/275544",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/28462/"
] |
275,550 | <p>I know how to include files that are in folders further down the heirachy but I have trouble finding my way back up.
I decided to go with the set_include_path to default all further includes relative to a path 2 levels up but don't have the slightest clue how to write it out.</p>
<p>Is there a guide somewhere that details path referencing for PHP?</p>
| [
{
"answer_id": 275556,
"author": "Owen",
"author_id": 4853,
"author_profile": "https://Stackoverflow.com/users/4853",
"pm_score": 1,
"selected": false,
"text": "set_include_path('/path/to/files');\n"
},
{
"answer_id": 275647,
"author": "Rob",
"author_id": 3542,
"autho... | 2008/11/09 | [
"https://Stackoverflow.com/questions/275550",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/24416/"
] |
275,562 | <p>I'm writing a simple time tracking program to manage my own projects. I'm a big fan of keeping reporting code in the database, so I've been attempting to create a few sprocs that generate the invoices and timesheets etc.</p>
<p>I have a table that contains Clock Actions, IE "Punch In", and "Punch Out". It also contains the user that did this action, the project associated with the action, and the current date/time.</p>
<p>I can select from this table to get clock in's for a specific time/project/and user, but I want to aggregate it down so that each clock in and out is converted from 2 rows to a single row containing total time.</p>
<p>For example, here is a sample output:</p>
<pre><code>ClockActionID ActionType DateTime
-------------------- ---------- -----------------------
17 1 2008-11-08 18:33:56.000
18 2 2008-11-08 18:33:59.587
19 1 2008-11-08 18:34:01.023
20 2 2008-11-08 18:34:02.037
21 1 2008-11-08 18:45:06.317
22 2 2008-11-08 18:46:14.597
23 1 2008-11-08 18:46:16.283
24 2 2008-11-08 18:46:17.173
25 1 2008-11-08 18:50:37.830
26 2 2008-11-08 18:50:39.737
27 1 2008-11-08 18:50:40.547
(11 row(s) affected)
</code></pre>
<p>Where ActionType 1 is "ClockIn" and ActionType 2 is "ClockOut". I also pruned out the User, Project, and Description columns for brevity.</p>
<p>I need to generate, in pure SQL, a result set like:</p>
<pre><code>Description | Total Time
</code></pre>
<p>For each ClockIn / ClockOut Pair.</p>
<p>I figure this will actually be fairly simple, I'm just not quite sure which way to approach it.</p>
<p>EDIT: The user will be able to clock into multiple projects simultaneously, though by first narrowing down the result set to a single project, this shouldn't make any difference to the logic here.</p>
| [
{
"answer_id": 275615,
"author": "Michael Haren",
"author_id": 29,
"author_profile": "https://Stackoverflow.com/users/29",
"pm_score": 2,
"selected": true,
"text": "DECLARE @clock TABLE (ClockActionID INT PRIMARY KEY IDENTITY, ActionType INT, ActionDateTime DATETIME)\n\nINSERT INTO @cloc... | 2008/11/09 | [
"https://Stackoverflow.com/questions/275562",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1965/"
] |
275,569 | <p>This is kind of a brainteaser question, since the code works perfectly fine as-is, it just irritates my aesthetic sense ever so slightly. I'm turning to Stack Overflow because my own brain is failing me right now.</p>
<p>Here's a snippet of code that looks up an address using the Google Maps JS API and places a marker on a map. However, sometimes the initial lookup fails, so I want to repeat the process with a different address.</p>
<pre><code>geocoder.getLatLng(item.mapstring, function(point) {
if (!point) {
geocoder.getLatLng(item.backup_mapstring, function(point) {
if (!point) return;
map.setCenter(point, 13);
map.setZoom(7);
map.addOverlay(new GMarker(point));
})
return;
}
map.setCenter(point, 13);
map.setZoom(7);
map.addOverlay(new GMarker(point));
})
</code></pre>
<p>(The second parameter to <code>getLatLng</code> is a callback function.)</p>
<p>Of course you can see that the three lines that center and zoom the map and add the marker are duplicated, once in the primary callback and once in the "fallback callback" (ha ha). Can you find a way to express the whole thing without any redundancy? You earn bonus points, and my adulation, if your solution works for an arbitrary number of backup map strings.</p>
| [
{
"answer_id": 275582,
"author": "Jay Kominek",
"author_id": 32878,
"author_profile": "https://Stackoverflow.com/users/32878",
"pm_score": 1,
"selected": false,
"text": "function place_point(mapstrings,idx)\n{\n if(idx>=mapstrings.length) return;\n geocoder.getLatLng(mapstrings[idx... | 2008/11/09 | [
"https://Stackoverflow.com/questions/275569",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/56817/"
] |
275,571 | <p>I want to write a simple utility to upload images to various free image hosting websites like TinyPic or Imageshack via a right-click context menu for the file.</p>
<p>How can I do this using .NET? I've seen some linux scripts that use cURL to post images to these website but I'm not sure how I could create the post request, complete with an image in C#?</p>
<p>Can someone point me in the right direction?</p>
<hr>
<p>EDIT:</p>
<p>I've found a pretty good resource. Cropper, a free screenshot tool written in .net, has a lot of open-source plugins. One of them is a SendToTinyPic.. complete with source. Link here:<br>
<a href="http://www.codeplex.com/cropperplugins" rel="nofollow noreferrer">http://www.codeplex.com/cropperplugins</a></p>
| [
{
"answer_id": 275586,
"author": "Jeff Hillman",
"author_id": 3950,
"author_profile": "https://Stackoverflow.com/users/3950",
"pm_score": 2,
"selected": false,
"text": "// http://www.flickr.com/services/api/misc.api_keys.html\nstring flickrApiKey = \"<api key>\";\nstring flickrApiSharedS... | 2008/11/09 | [
"https://Stackoverflow.com/questions/275571",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
275,577 | <p>If I have a char which holds a hex value such has 0x53, (S), how can I display this as "S"?</p>
<p>Code:</p>
<pre><code>char test = 0x53;
cout << test << endl;
</code></pre>
<p>Thanks!</p>
| [
{
"answer_id": 275646,
"author": "Paige Ruten",
"author_id": 813,
"author_profile": "https://Stackoverflow.com/users/813",
"pm_score": 3,
"selected": false,
"text": "test = 0x53; // hex\ntest = 'S'; // literal constant\ntest = 83; // decimal\ntest = 0123; // octal\n"
},
{
"ans... | 2008/11/09 | [
"https://Stackoverflow.com/questions/275577",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/33481/"
] |
275,593 | <p>I'm having trouble converting my Cocoa project from a manually-synched interface model to a bindings model so that I don't have to worry about interface glue code.</p>
<p>I followed the CocoaDevCentral <a href="http://cocoadevcentral.com/articles/000080.php" rel="nofollow noreferrer">Cocoa Bindings tutorial</a> to make sure that I had covered all the bases, but things aren't working correctly. I have a master-detail interface, but I'm having trouble even getting the master portion of the interface to work correctly. No data is showing up in the master column, even though I've set up the bindings model similar to how it is shown in the tutorial. I've made sure all my controllers and objects have <code>-(id)key</code> and <code>-(void)setKey:(id)key</code> methods so that they're bindings-compliant, I've created a ControllerAlias object in my nib, connected it to my controller, created an NSArrayController that binds to one of the NSMutableArrays from the class that ControllerAlias connects to, made sure to set the type of objects that are contained within the array, and then I've bound a table column to the NSArrayController.</p>
<p>I'm getting no errors whatsoever in the Console, and setting <code>NSBindingDebugLogLevel</code> to 1 doesn't produce any errors either, that would help me figure out what the problem is.</p>
<p>The only other thing I could think of to make sure that things are working correctly is to check that the NSMutableArray that connects to the NSArrayController actually has something in it, and it does.</p>
<p>Any suggestions? What other typical pitfalls are there with Cocoa bindings that I should check?</p>
| [
{
"answer_id": 275616,
"author": "Peter Hosey",
"author_id": 30461,
"author_profile": "https://Stackoverflow.com/users/30461",
"pm_score": 0,
"selected": false,
"text": "NSMutableArray"
},
{
"answer_id": 275666,
"author": "Community",
"author_id": -1,
"author_profile"... | 2008/11/09 | [
"https://Stackoverflow.com/questions/275593",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
275,625 | <pre><code>var pattern = /^0+$/;
</code></pre>
<p>My guess is this:</p>
<p>"Take a look at both the beginning and the end of the string, and if there's a pattern of one or more zeros at the beginning and the end, then return that pattern."</p>
<p>I'm sure that's wrong, though, because when I run the expression with this string:</p>
<pre><code>var string = "0000009000000";
</code></pre>
<p>It comes up <code>null</code>.</p>
<p>So what's it really saying? And while I'm asking, what/how does JavaScript consider the beginning, middle and end of a string? </p>
<p><strong>UPDATE #1:</strong> Thanks for the responses! I think I understand this now. My confusion stemmed from the fact that I'm visualizing the string as having a beginning, a middle and an end. Like this:</p>
<p>[beginning][middle][end]</p>
<p>In other words, for the given string above, the following expressions work as I expect them to:</p>
<p><code>/^0+/;</code> returns "000000" (a pattern of one or more zeros at the beginning of the string)</p>
<p>and</p>
<p><code>/0+$/</code>; returns "000000" (a pattern of one or more zeros at the end of the string)</p>
<p><strong>UPDATE #2:</strong> I up-voted all the responses to this point, because they're all helpful, and I compiled the answers into one great big one:</p>
<p>Given the following JavaScript code:</p>
<pre><code>var string = "0000009000000";
var regExp = /^0+$/;
alert(regExp.exec(string));
</code></pre>
<p>It reads, in part, like this: </p>
<p>"If the exact character(s) followed by the ^ modifier and preceded by the $ modifier in the regular expression are not SIMULTANEOUSLY sitting in the first position(s) of the string AND the last position(s) of the string (i.e., they are not the only character(s) in the string), then return <code>null</code>. Else, return the character(s)."</p>
<p>In other words, let's say the given string is six zeros "000000". This results in a match because the exact same group of "0" characters are sitting in BOTH the first positions (<strong>1st 2nd 3rd</strong> 4th 5th 6th) AND the last positions (1st 2nd 3rd <strong>4th 5th 6th</strong>) of the string.</p>
<p>However, in the original given string, there are six zeros, followed by a nine, followed by six zeros ("0000009000000"). Now, the six zeros in the first positions of the string (1st, 2nd, 3rd, 4th, 5th, 6th) are NOT the exact same six zeros sitting in the last positions of the string (8th, 9th, 10th, 11th, 12th, 13th). Hence, a <code>null</code> is returned.</p>
| [
{
"answer_id": 275636,
"author": "Nate Parsons",
"author_id": 34910,
"author_profile": "https://Stackoverflow.com/users/34910",
"pm_score": 2,
"selected": false,
"text": "var pattern = /^0+.*0+$/\n"
},
{
"answer_id": 275638,
"author": "Rob",
"author_id": 3542,
"author... | 2008/11/09 | [
"https://Stackoverflow.com/questions/275625",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
275,630 | <p>I'm trying to automate some stuff in MS Excel. When I try to set the Calculation property I get the following error message: 'Unable to set the Calculation property of the Application class'</p>
<p>I believe this property should be settable.</p>
<p>Any advice appreciated!</p>
| [
{
"answer_id": 275635,
"author": "BradC",
"author_id": 21398,
"author_profile": "https://Stackoverflow.com/users/21398",
"pm_score": 1,
"selected": false,
"text": " Application.Calculation = xlCalculationManual\n"
},
{
"answer_id": 275743,
"author": "dbb",
"author_id": 25... | 2008/11/09 | [
"https://Stackoverflow.com/questions/275630",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
275,631 | <p>There are <code><meta></code> tags and other things you can place in the <code><head></code> of your HTML document. What <code><meta></code> tags etc. and best practices do you make use of in your HTML document to make it more accessible, searchable, optimized etc.</p>
| [
{
"answer_id": 275665,
"author": "andyk",
"author_id": 26721,
"author_profile": "https://Stackoverflow.com/users/26721",
"pm_score": 5,
"selected": true,
"text": "Content-type"
},
{
"answer_id": 275673,
"author": "eyelidlessness",
"author_id": 17964,
"author_profile":... | 2008/11/09 | [
"https://Stackoverflow.com/questions/275631",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/21406/"
] |
275,683 | <p>Using <a href="http://imdbpy.sourceforge.net" rel="noreferrer">IMDbPy</a> it is painfully easy to access movies from the IMDB site:</p>
<pre><code>import imdb
access = imdb.IMDb()
movie = access.get_movie(3242) # random ID
print "title: %s year: %s" % (movie['title'], movie['year'])
</code></pre>
<p>However I see no way to get the picture or thumbnail of the movie cover. Suggestions?</p>
| [
{
"answer_id": 275774,
"author": "Tim Kersten",
"author_id": 33514,
"author_profile": "https://Stackoverflow.com/users/33514",
"pm_score": 4,
"selected": true,
"text": "import imdb\n\naccess = imdb.IMDb()\nmovie = access.get_movie(1132626)\n\nprint \"title: %s year: %s\" % (movie['title'... | 2008/11/09 | [
"https://Stackoverflow.com/questions/275683",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/432/"
] |
275,689 | <p>There's a part in my apps that displays the file path loaded by the user through OpenFileDialog. It's taking up too much space to display the whole path, but I don't want to display only the filename as it might be ambiguous. So I would prefer to show the file path relative to the assembly/exe directory.</p>
<p>For example, the assembly resides at <code>C:\Program Files\Dummy Folder\MyProgram</code> and the file at <code>C:\Program Files\Dummy Folder\MyProgram\Data\datafile1.dat</code> then I would like it to show <code>.\Data\datafile1.dat</code>. If the file is in <code>C:\Program Files\Dummy Folder\datafile1.dat</code>, then I would want <code>..\datafile1.dat</code>. But if the file is at the root directory or 1 directory below root, then display the full path. </p>
<p>What solution would you recommend? Regex?</p>
<p>Basically I want to display useful file path info without taking too much screen space.</p>
<p>EDIT: Just to clarify a little bit more. The purpose of this solution is to help user or myself knowing which file did I loaded last and roughly from which directory was it from. I'm using a readonly textbox to display the path. Most of the time, the file path is much longer than the display space of the textbox. The path is supposed to be informative but not important enough as to take up more screen space.</p>
<p>Alex Brault comment was good, so is Jonathan Leffler. The Win32 function provided by DavidK only help with part of the problem, not the whole of it, but thanks anyway. As for James Newton-King solution, I'll give it a try later when I'm free.</p>
| [
{
"answer_id": 275691,
"author": "Kevin",
"author_id": 40,
"author_profile": "https://Stackoverflow.com/users/40",
"pm_score": 2,
"selected": false,
"text": "RelPath = AbsPath.Replace(ApplicationPath, \".\")\n"
},
{
"answer_id": 275740,
"author": "DavidK",
"author_id": 31... | 2008/11/09 | [
"https://Stackoverflow.com/questions/275689",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20007/"
] |
275,701 | <p>I'm playing around with CodeIgniter; hoping to convert some of my old, ugly PHP into a more maintainable framework. However, I've come across a rather frustrating roadblock - I can't seem to define methods in my views. Any time I try I get a completely blank page, and when I look in the debug log the processing seemed to stop after the view was loaded. Can I define methods within views? If not, why, and what workarounds would you suggest?</p>
<p><strong>Note</strong>: The method has to do with formatting output strings.</p>
| [
{
"answer_id": 275729,
"author": "Josh",
"author_id": 10902,
"author_profile": "https://Stackoverflow.com/users/10902",
"pm_score": 0,
"selected": false,
"text": "if (!function_exists('myfunc'))\n{\n function myfunc() {}\n}\n"
}
] | 2008/11/09 | [
"https://Stackoverflow.com/questions/275701",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/658/"
] |
275,707 | <p>Create a file called Valid[File].txt and stick some text in it. Start powershell and go to the directory.<br>
<PRE>
gc Valid[File].txt
</PRE>
should display the value in the file. It returns blank. If you use tab auto-completion it escapes the name:
<PRE>
gc 'Valid<code>[File</code>].txt'
</PRE>
but still returns nothing.</p>
<p>How do I reference files with brackets in their names?</p>
| [
{
"answer_id": 275719,
"author": "Brian Adams",
"author_id": 32992,
"author_profile": "https://Stackoverflow.com/users/32992",
"pm_score": 4,
"selected": true,
"text": "-literalpath"
}
] | 2008/11/09 | [
"https://Stackoverflow.com/questions/275707",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/32992/"
] |
275,711 | <p>Is there a better way of getting this result? This function fails if num has more digits than digits, and I feel like it should be in the library somewhere (like Integer.toString(x,"%3d") or something)</p>
<pre><code>static String intToString(int num, int digits) {
StringBuffer s = new StringBuffer(digits);
int zeroes = digits - (int) (Math.log(num) / Math.log(10)) - 1;
for (int i = 0; i < zeroes; i++) {
s.append(0);
}
return s.append(num).toString();
}
</code></pre>
| [
{
"answer_id": 275715,
"author": "begray",
"author_id": 12123,
"author_profile": "https://Stackoverflow.com/users/12123",
"pm_score": 12,
"selected": true,
"text": "String formatted = String.format(\"%03d\", num);\n"
},
{
"answer_id": 275716,
"author": "Jason Coco",
"auth... | 2008/11/09 | [
"https://Stackoverflow.com/questions/275711",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/34910/"
] |
275,717 | <p>I have a very weird problem which I cannot seem to figure out. Unfortunately, I'm not even sure how to describe it without describing my entire application. What I am trying to do is:</p>
<pre>
1) read a byte from the serial port
2) store each char into tagBuffer as they are read
3) run a query using tagBuffer to see what type of tag it is (book or shelf tag)
4) depending on the type of tag, output a series of bytes corresponding to the type of tag
</pre>
<p>Most of my code is implemented and I can get the right tag code sent back out the serial port. But there are two lines that I've added as debug statements which when I tried to remove them, they cause my program to stop working.</p>
<p>The lines are the two lines at the very bottom:
<code></p>
<pre><code> sprintf(buf,"%s!\n", tagBuffer);
WriteFile(hSerial,buf,strlen(buf), &dwBytesWritten,&ovWrite);
</code></pre>
<p></code></p>
<p>If I try to remove them, "tagBuffer" will only store the last character as oppose being a buffer. Same thing with the next line, WriteFile().</p>
<p>I thought sprintf and WriteFile are I/O functions and would have no effect on variables.
I'm stuck and I need help to fix this.</p>
<p><code></p>
<pre><code>//keep polling as long as stop character '-' is not read
while(szRxChar != '-')
{
// Check if a read is outstanding
if (HasOverlappedIoCompleted(&ovRead))
{
// Issue a serial port read
if (!ReadFile(hSerial,&szRxChar,1,
&dwBytesRead,&ovRead))
{
DWORD dwErr = GetLastError();
if (dwErr!=ERROR_IO_PENDING)
return dwErr;
}
}
// resets tagBuffer in case tagBuffer is out of sync
time_t t_time = time(0);
char buf[50];
if (HasOverlappedIoCompleted(&ovWrite))
{
i=0;
}
// Wait 5 seconds for serial input
if (!(HasOverlappedIoCompleted(&ovRead)))
{
WaitForSingleObject(hReadEvent,RESET_TIME);
}
// Check if serial input has arrived
if (GetOverlappedResult(hSerial,&ovRead,
&dwBytesRead,FALSE))
{
// Wait for the write
GetOverlappedResult(hSerial,&ovWrite,
&dwBytesWritten,TRUE);
if( strlen(tagBuffer) >= PACKET_LENGTH )
{
i = 0;
}
//load tagBuffer with byte stream
tagBuffer[i] = szRxChar;
i++;
tagBuffer[i] = 0; //char arrays are \0 terminated
//run query with tagBuffer
sprintf(query,"select type from rfid where rfidnum=\"");
strcat(query, tagBuffer);
strcat(query, "\"");
mysql_real_query(&mysql,query,(unsigned int)strlen(query));
//process result and send back to handheld
res = mysql_use_result(&mysql);
while(row = mysql_fetch_row(res))
{
printf("result of query is %s\n",row[0]);
string str = "";
str = string(row[0]);
if( str == "book" )
{
WriteFile(hSerial,BOOK_INDICATOR,strlen(BOOK_INDICATOR),
&dwBytesWritten,&ovWrite);
}
else if ( str == "shelf" )
{
WriteFile(hSerial,SHELF_INDICATOR,strlen(SHELF_INDICATOR),
&dwBytesWritten,&ovWrite);
}
else //this else doesn't work
{
WriteFile(hSerial,NOK,strlen(NOK),
&dwBytesWritten,&ovWrite);
}
}
mysql_free_result(res);
// Display a response to input
//printf("query is %s!\n", query);
//printf("strlen(tagBuffer) is %d!\n", strlen(tagBuffer));
//without these, tagBuffer only holds the last character
sprintf(buf,"%s!\n", tagBuffer);
WriteFile(hSerial,buf,strlen(buf), &dwBytesWritten,&ovWrite);
}
}
</code></pre>
<p></code></p>
<p>With those two lines, my output looks like this:
s sh she shel shelf shelf0 shelf00 BOOKCODE shelf0001</p>
<p>Without them, I figured out that tagBuffer and buf only stores the most recent character at any one time.</p>
<p>Any help at all will be greatly appreciated. Thanks.</p>
| [
{
"answer_id": 275725,
"author": "1800 INFORMATION",
"author_id": 3146,
"author_profile": "https://Stackoverflow.com/users/3146",
"pm_score": 1,
"selected": false,
"text": "buf"
}
] | 2008/11/09 | [
"https://Stackoverflow.com/questions/275717",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/28462/"
] |
275,736 | <p>I use the dark-blue2 color theme but it seems ugly under console.
So I want to use no color theme under terminal, what can I do then?</p>
| [
{
"answer_id": 275755,
"author": "Samuel Tardieu",
"author_id": 22890,
"author_profile": "https://Stackoverflow.com/users/22890",
"pm_score": 2,
"selected": true,
"text": "TERM=xterm-mono emacs -nw\n"
},
{
"answer_id": 276586,
"author": "quodlibetor",
"author_id": 25616,
... | 2008/11/09 | [
"https://Stackoverflow.com/questions/275736",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/34924/"
] |
275,737 | <pre><code>DECLARE @p_date DATETIME
SET @p_date = CONVERT( DATETIME, '14 AUG 2008 10:45:30',?)
SELECT *
FROM table1
WHERE column_datetime = @p_date
</code></pre>
<p>I need to compare date time like:</p>
<pre><code>@p_date=14 AUG 2008 10:45:30
column_datetime=14 AUG 2008 10:45:30
</code></pre>
<p>How can I do this?</p>
| [
{
"answer_id": 275776,
"author": "Marc Gravell",
"author_id": 23354,
"author_profile": "https://Stackoverflow.com/users/23354",
"pm_score": 1,
"selected": false,
"text": "DECLARE @end datetime\nSET @end = DATEADD(ss,1,@p_date)\n"
}
] | 2008/11/09 | [
"https://Stackoverflow.com/questions/275737",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
275,756 | <p>I was looking at the <a href="http://www.python.org/doc/2.5.2/lib/module-popen2.html" rel="noreferrer">Python documentation</a> and saw that there are 4-5 different versions of popen(), e.g. os.popen(), os.popen2(), etc. </p>
<p>Apart from the fact that some include <em>stderr</em> while others don't, what are the differences between them and when would you use each one? The documentation didn't really explain it very well.</p>
| [
{
"answer_id": 275817,
"author": "J S",
"author_id": 25676,
"author_profile": "https://Stackoverflow.com/users/25676",
"pm_score": 4,
"selected": false,
"text": "subprocess"
}
] | 2008/11/09 | [
"https://Stackoverflow.com/questions/275756",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18676/"
] |
275,761 | <p>I have a textbox and a link button.
When I write some text, select some of it and then click the link button, the selected text from textbox must be show with a message box.</p>
<p>How can I do it?</p>
<hr />
<p>When I click the submit button for the textbox below, the message box must show <em>Lorem ipsum</em>. Because "Lorem ipsum" is selected in the area.</p>
<hr />
<p>If I select any text from the page and click the submit button it is working, but if I write a text to textbox and make it, it's not. Because when I click to another space, the selection of textbox is canceled.</p>
<p>Now problem is that, when I select text from textbox and click any other control or space, the text, which is selected, must still be selected.</p>
<p>How is it to be done?</p>
| [
{
"answer_id": 275797,
"author": "Shadow2531",
"author_id": 1697,
"author_profile": "https://Stackoverflow.com/users/1697",
"pm_score": 2,
"selected": false,
"text": "function getTextFieldSelection(textField) {\n return textField.value.substring(textField.selectionStart, textField.sel... | 2008/11/09 | [
"https://Stackoverflow.com/questions/275761",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/439507/"
] |
275,771 | <p>I need to get the values in the registers with GCC.</p>
<p>Something similar to this:</p>
<pre>
EAX=00000002 EBX=00000001 ECX=00000005 EDX=BFFC94C0
ESI=8184C544 EDI=00000000 EBP=0063FF78 ESP=0063FE3C
CF=0 SF=0 ZF=0 OF=0
</pre>
<p>Getting the 32-bit registers is easy enough, but I'm not sure what the simplest way to get the flags is.</p>
<p>In the examples for this book: <a href="http://kipirvine.com/asm/" rel="nofollow noreferrer">http://kipirvine.com/asm/</a></p>
<p>They do it by getting the whole EFLAGS register and shifting for the bit in question. I also thought of doing it using Jcc's and CMOVcc's. </p>
<p>Any other suggestions on how to do it? Some test cases to verify would also be useful.</p>
| [
{
"answer_id": 275837,
"author": "Nils Pipenbrinck",
"author_id": 15955,
"author_profile": "https://Stackoverflow.com/users/15955",
"pm_score": 3,
"selected": true,
"text": " PUSHFD\n POP EAX \n , eax now contains the EFLAG data\n"
},
{
"answer_id": 6405090,
"author": "jw... | 2008/11/09 | [
"https://Stackoverflow.com/questions/275771",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/30626/"
] |
275,778 | <p>How can I draw something in JPanel that will stay the same and not be repainted, I am doing a traffic simulation program and I want the road to be drawn once because It will not change.
Thanks </p>
| [
{
"answer_id": 275785,
"author": "Dan Vinton",
"author_id": 21849,
"author_profile": "https://Stackoverflow.com/users/21849",
"pm_score": 3,
"selected": true,
"text": "public class RoadPanel extends JPanel {\n\n @Override\n public void paintComponent(Graphics g) {\n super.pa... | 2008/11/09 | [
"https://Stackoverflow.com/questions/275778",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4885/"
] |
275,781 | <p>Can anyone explain the difference between <code>Server.MapPath(".")</code>, <code>Server.MapPath("~")</code>, <code>Server.MapPath(@"\")</code> and <code>Server.MapPath("/")</code>?</p>
| [
{
"answer_id": 275791,
"author": "splattne",
"author_id": 6461,
"author_profile": "https://Stackoverflow.com/users/6461",
"pm_score": 11,
"selected": true,
"text": "Server.MapPath(\".\")"
},
{
"answer_id": 17616488,
"author": "dav_i",
"author_id": 1185053,
"author_pro... | 2008/11/09 | [
"https://Stackoverflow.com/questions/275781",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2133/"
] |
275,795 | <p>E.g.</p>
<p>What's best out of these:</p>
<pre><code>std::string f() {}
</code></pre>
<p>or </p>
<pre><code>const std::string& f() {}
</code></pre>
| [
{
"answer_id": 275811,
"author": "Nicola Bonelli",
"author_id": 19630,
"author_profile": "https://Stackoverflow.com/users/19630",
"pm_score": 5,
"selected": false,
"text": "operator<<"
},
{
"answer_id": 275819,
"author": "C. K. Young",
"author_id": 13,
"author_profile... | 2008/11/09 | [
"https://Stackoverflow.com/questions/275795",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
275,810 | <p>Is anyone using Castle MonoRail and ELMAH with success?</p>
<p>We are using a number of Resuces to present users with friendly error messages, but if we do this the exceptions never get as far as ELMAH as the MonoRail rescue intercepts them.</p>
<p>Ideally we want the user to see the rescue, but for the exception to be logged in ELMAH.</p>
<p>Any ideas/pointers?</p>
<p>Cheers,</p>
<p>Jay.</p>
| [
{
"answer_id": 620066,
"author": "Mauricio Scheffer",
"author_id": 21239,
"author_profile": "https://Stackoverflow.com/users/21239",
"pm_score": 3,
"selected": true,
"text": "public class ElmahExceptionHandler : AbstractExceptionHandler {\n public override void Process(IRailsEngineCon... | 2008/11/09 | [
"https://Stackoverflow.com/questions/275810",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8542/"
] |
275,824 | <p>I am getting an 'Access to the path is denied" error message when running in debug mode. I have tried granting permissions to {MACHINENAME}\ASPNET and to NETWORK SERVICE but this hasn't made any difference. I have also tried < impersonate = true /> using an admin account, this also made no difference. So how do I establish exactly which account is being used?</p>
| [
{
"answer_id": 275830,
"author": "mdb",
"author_id": 8562,
"author_profile": "https://Stackoverflow.com/users/8562",
"pm_score": 5,
"selected": true,
"text": " Dim User = System.Security.Principal.WindowsIdentity.GetCurrent.User\n Dim UserName = User.Translate(GetType(System.Securi... | 2008/11/09 | [
"https://Stackoverflow.com/questions/275824",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/27805/"
] |
275,836 | <p>I'm looking for a way to display multiple colors in a single C#/.NET label. E.g the label is displaying a series of csv separated values that each take on a color depending on a bucket they fall into. I would prefer not to use multiple labels, as the values are variable length and I don't want to play with dynamic layouts. Is there a native support for this?</p>
| [
{
"answer_id": 275876,
"author": "MusiGenesis",
"author_id": 14606,
"author_profile": "https://Stackoverflow.com/users/14606",
"pm_score": 7,
"selected": true,
"text": "public void RenderRainbowText(string Text, PictureBox pb)\n{\n // PictureBox needs an image to draw on\n pb.Image... | 2008/11/09 | [
"https://Stackoverflow.com/questions/275836",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8207/"
] |
275,842 | <p>Frequently, I've dug into apropos and docs looking for something like the following only to give up to get back to the task at hand:</p>
<p>(repeat-last-command)</p>
<p>do the last C- or M- command I just executed (to be rebound to a fn key)</p>
<p>or sometimes the related: </p>
<p>(describe-last-function)</p>
<p>what keystroke did I just mistakenly issue, the effect of which I'd like to add to my bag of tricks. describe-key is close, but requires knowing what I typed. </p>
<p>Am I simply asking too much from my trusty sidekick?</p>
| [
{
"answer_id": 275861,
"author": "Emerick Rogul",
"author_id": 33837,
"author_profile": "https://Stackoverflow.com/users/33837",
"pm_score": 7,
"selected": false,
"text": "repeat.el"
},
{
"answer_id": 275862,
"author": "echox",
"author_id": 35915,
"author_profile": "h... | 2008/11/09 | [
"https://Stackoverflow.com/questions/275842",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/35911/"
] |
275,853 | <p>I myself am convinced that in a project I'm working on signed integers are the best choice in the majority of cases, even though the value contained within can never be negative. (Simpler reverse for loops, less chance for bugs, etc., in particular for integers which can only hold values between 0 and, say, 20, anyway.)</p>
<p>The majority of the places where this goes wrong is a simple iteration of a std::vector, often this used to be an array in the past and has been changed to a std::vector later. So these loops generally look like this:</p>
<pre><code>for (int i = 0; i < someVector.size(); ++i) { /* do stuff */ }
</code></pre>
<p>Because this pattern is used so often, the amount of compiler warning spam about this comparison between signed and unsigned type tends to hide more useful warnings. Note that we definitely do not have vectors with more then INT_MAX elements, and note that until now we used two ways to fix compiler warning:</p>
<pre><code>for (unsigned i = 0; i < someVector.size(); ++i) { /*do stuff*/ }
</code></pre>
<p>This usually works but might silently break if the loop contains any code like 'if (i-1 >= 0) ...', etc.</p>
<pre><code>for (int i = 0; i < static_cast<int>(someVector.size()); ++i) { /*do stuff*/ }
</code></pre>
<p>This change does not have any side effects, but it does make the loop a lot less readable. (And it's more typing.)</p>
<p>So I came up with the following idea:</p>
<pre><code>template <typename T> struct vector : public std::vector<T>
{
typedef std::vector<T> base;
int size() const { return base::size(); }
int max_size() const { return base::max_size(); }
int capacity() const { return base::capacity(); }
vector() : base() {}
vector(int n) : base(n) {}
vector(int n, const T& t) : base(n, t) {}
vector(const base& other) : base(other) {}
};
template <typename Key, typename Data> struct map : public std::map<Key, Data>
{
typedef std::map<Key, Data> base;
typedef typename base::key_compare key_compare;
int size() const { return base::size(); }
int max_size() const { return base::max_size(); }
int erase(const Key& k) { return base::erase(k); }
int count(const Key& k) { return base::count(k); }
map() : base() {}
map(const key_compare& comp) : base(comp) {}
template <class InputIterator> map(InputIterator f, InputIterator l) : base(f, l) {}
template <class InputIterator> map(InputIterator f, InputIterator l, const key_compare& comp) : base(f, l, comp) {}
map(const base& other) : base(other) {}
};
// TODO: similar code for other container types
</code></pre>
<p>What you see is basically the STL classes with the methods which return size_type overridden to return just 'int'. The constructors are needed because these aren't inherited.</p>
<p><strong>What would you think of this as a developer, if you'd see a solution like this in an existing codebase?</strong></p>
<p>Would you think 'whaa, they're redefining the STL, what a huge WTF!', or would you think this is a nice simple solution to prevent bugs and increase readability. Or maybe you'd rather see we had spent (half) a day or so on changing all these loops to use std::vector<>::iterator?</p>
<p>(In particular if this solution was combined with banning the use of unsigned types for anything but raw data (e.g. unsigned char) and bit masks.)</p>
| [
{
"answer_id": 275873,
"author": "Johannes Schaub - litb",
"author_id": 34509,
"author_profile": "https://Stackoverflow.com/users/34509",
"pm_score": 3,
"selected": true,
"text": "'int'"
},
{
"answer_id": 275889,
"author": "fizzer",
"author_id": 18167,
"author_profile... | 2008/11/09 | [
"https://Stackoverflow.com/questions/275853",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5422/"
] |
275,855 | <p>I have a custom attribute which can be assigned to a class, <code>[FooAttribute]</code>. What I would like to do, from within the attribute, is determine which type has actually used me. e.g. If I have:</p>
<pre><code>[FooAttribute]
public class Bar
{
}
</code></pre>
<p>In the code for FooAttribute, how can I determine it was Bar class that added me? I'm not specifically looking for the Bar type, I just want to set a friendly name using reflection. e.g.</p>
<pre><code>[FooAttribute(Name="MyFriendlyNameForThisClass")]
public class Bar
{
}
public class FooAttribute()
{
public FooAttribute()
{
// How do I get the target types name? (as a default)
}
}
</code></pre>
| [
{
"answer_id": 275921,
"author": "Marc Gravell",
"author_id": 23354,
"author_profile": "https://Stackoverflow.com/users/23354",
"pm_score": 4,
"selected": true,
"text": "[DisplayName]"
}
] | 2008/11/09 | [
"https://Stackoverflow.com/questions/275855",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/986/"
] |
275,868 | <p>How would I go about having a CMake buildsystem, which scans for source files now using <a href="http://www.cmake.org/cmake/help/cmake2.6docs.html#command:aux_source_directory" rel="noreferrer">AUX_SOURCE_DIRECTORY</a>, scan for header files too in the same directory, preferably using a similar command?</p>
<p>I didn't find an easy way to do this in the documentation yet, so I now have a crappy bash script to post-process my (CodeBlocks) project file...</p>
| [
{
"answer_id": 309455,
"author": "David",
"author_id": 28275,
"author_profile": "https://Stackoverflow.com/users/28275",
"pm_score": 5,
"selected": true,
"text": "set(dir my_search_dir)\nfile (GLOB headers \"${dir}/*.h\")\nmessage(\"My headers: \" ${headers})\n"
}
] | 2008/11/09 | [
"https://Stackoverflow.com/questions/275868",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5422/"
] |
275,871 | <p>Suppose I have code like this:</p>
<pre><code>template<class T, T initial_t> class Bar {
// something
}
</code></pre>
<p>And then try to use it like this:</p>
<pre><code>Bar<Foo*, NULL> foo_and_bar_whatever_it_means_;
</code></pre>
<p>GCC bails out with error (on the above line):</p>
<blockquote>
<p>could not convert template argument
'0' to 'Foo*'</p>
</blockquote>
<p>I found this thread: <a href="http://gcc.gnu.org/ml/gcc-help/2007-11/msg00066.html" rel="nofollow noreferrer">http://gcc.gnu.org/ml/gcc-help/2007-11/msg00066.html</a>, but I have to use NULL in this case (ok, I could probably refactor - but it would not be trivial; any suggestions?). I tried to overcome the problem by creating a variable with value of NULL, but GCC still complains that I pass variable and not address of variable as a template argument. And reference to a variable initialized with default ctor would not be the same as NULL.</p>
| [
{
"answer_id": 275884,
"author": "Assaf Lavie",
"author_id": 11208,
"author_profile": "https://Stackoverflow.com/users/11208",
"pm_score": 0,
"selected": false,
"text": "Bar<Foo*, (Foo*)NULL> foo_and_bar_whatever_it_means_;\n"
},
{
"answer_id": 277934,
"author": "MSalters",
... | 2008/11/09 | [
"https://Stackoverflow.com/questions/275871",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/9403/"
] |
275,878 | <p>My client gets a <code>sec_error_unknown_issuer</code> error message when visiting <a href="https://mediant.ipmail.nl" rel="noreferrer">https://mediant.ipmail.nl</a> with Firefox.
I can't reproduce the error myself. I installed FF on a Vista and a XP machine and had no problems. FF on Ubuntu also works fine.</p>
<p>Does anyone get the same error and does anyone have some clues for me so I can tell my ISP to change some settings?
The certificate is a so called wild-card SSL certificate that works for all subdomains (*.ipmail.nl). Was I wrong to pick the cheapest one?</p>
| [
{
"answer_id": 1026287,
"author": "user126810",
"author_id": 126810,
"author_profile": "https://Stackoverflow.com/users/126810",
"pm_score": 5,
"selected": false,
"text": "SSLCertificateChainFile /etc/ssl/crt/yourSERVERNAME.ca-bundle\n"
},
{
"answer_id": 14721055,
"author": "... | 2008/11/09 | [
"https://Stackoverflow.com/questions/275878",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/21238/"
] |
275,885 | <p>Although a DataTable is a memory hog, wouldn't a DataTable be the best choice to implement and IdentityMap if the set of objects is very large since retrieval time is O(1)?</p>
<p><strong>Update</strong></p>
<p>If I decide to use IDictionary, do I sacrifice speed when retrieving my objects?</p>
| [
{
"answer_id": 275915,
"author": "Marc Gravell",
"author_id": 23354,
"author_profile": "https://Stackoverflow.com/users/23354",
"pm_score": 4,
"selected": true,
"text": "Dictionary<,>"
}
] | 2008/11/09 | [
"https://Stackoverflow.com/questions/275885",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19799/"
] |
275,888 | <p>Use HttpWebRequest to download web pages without key sensitive issues</p>
| [
{
"answer_id": 275905,
"author": "Marc Gravell",
"author_id": 23354,
"author_profile": "https://Stackoverflow.com/users/23354",
"pm_score": 2,
"selected": false,
"text": "WebClient"
},
{
"answer_id": 275938,
"author": "gimel",
"author_id": 6491,
"author_profile": "htt... | 2008/11/09 | [
"https://Stackoverflow.com/questions/275888",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/35917/"
] |
275,891 | <p>I wan't to change the background color of a div dynamicly using the following HTML, CSS and javascript.
HTML:</p>
<pre><code><div id="menu">
<div class="menuItem"><a href=#>Bla</a></div>
<div class="menuItem"><a href=#>Bla</a></div>
<div class="menuItem"><a href=#>Bla</a></div>
</div>
</code></pre>
<p>CSS:</p>
<pre><code>.menuItem{
display:inline;
height:30px;
width:100px;
background-color:#000;
}
</code></pre>
<p>Javascript:</p>
<pre><code>$('.menuItem').hover( function(){
$(this).css('background-color', '#F00');
},
function(){
$(this).css('background-color', '#000');
});
</code></pre>
<p><strong>EDIT:</strong> I forgot to say that I had reasons not to want to use the css way.</p>
<p>And I indeed forgot to check if the DOM was loaded.</p>
| [
{
"answer_id": 275912,
"author": "foxy",
"author_id": 30119,
"author_profile": "https://Stackoverflow.com/users/30119",
"pm_score": 7,
"selected": true,
"text": "$(function() {\n $('.menuItem').hover( function(){\n $(this).css('background-color', '#F00');\n },\n function(){\n ... | 2008/11/09 | [
"https://Stackoverflow.com/questions/275891",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/35197/"
] |
275,920 | <p>I have been trying to set up my Beta 1 MVC app on IIS 6 and cannot get it to run correctly. I have added a Wildcard mapping to the .net isapi DLL as suggested in other blog posts but get the following error when I access the root of the website:</p>
<pre><code>The incoming request does not match any route.
..
[HttpException (0x80004005): The incoming request does not match any route.]
System.Web.Routing.UrlRoutingHandler.ProcessRequest(HttpContextBase httpContext) +147
System.Web.Routing.UrlRoutingHandler.ProcessRequest(HttpContext httpContext) +36
System.Web.Routing.UrlRoutingHandler.System.Web.IHttpHandler.ProcessRequest(HttpContext context) +4
HCD.Intranet.Web.Default.Page_Load(Object sender, EventArgs e) +81
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +15
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +33
System.Web.UI.Control.OnLoad(EventArgs e) +99
System.Web.UI.Control.LoadRecursive() +47
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1436
</code></pre>
<p>I am using the Default.aspx page supplied in the MVC template application that rewrites access to the root of the website properly.</p>
<pre><code>public partial class Default : Page
{
public void Page_Load(object sender, System.EventArgs e)
{
HttpContext.Current.RewritePath(Request.ApplicationPath);
IHttpHandler httpHandler = new MvcHttpHandler();
httpHandler.ProcessRequest(HttpContext.Current);
}
}
</code></pre>
<p>If I try and access a route within the application, such as /Project, I get the standard IIS 404 error page, not the .net error page.</p>
<p>I tried adding the following line to my Web.config httpHandlers section:</p>
<pre><code><add verb="*" path="*" validate="false" type="System.Web.Mvc.MvcHttpHandler, System.Web.Mvc, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31BF3856AD364E35"/>
</code></pre>
<p>This gave me a different error - the .net 404 error page.</p>
<p>I added the following to my Global.asax, which did nothing:</p>
<pre><code>protected void Application_BeginRequest(object sender, EventArgs e)
{
if (Context.Request.FilePath.Equals("/"))
Context.RewritePath("Default.aspx");
}
</code></pre>
<p>I am using the following route configuration (uses the restful routing supplied by the MvcContrib project):</p>
<pre><code>routes.IgnoreRoute("{resource}.axd/{*pathInfo}");
SimplyRestfulRouteHandler.BuildRoutes(routes);
routes.MapRoute(
"Default",
"{controller}/{action}/{id}",
new { controller = "Home", action = "Index", id = "" }
);
</code></pre>
<p>Any suggestions would be grealy received as I've exhausted all options for the time I have right now.</p>
<p>Many thanks.</p>
| [
{
"answer_id": 275928,
"author": "TheCodeJunkie",
"author_id": 25319,
"author_profile": "https://Stackoverflow.com/users/25319",
"pm_score": 1,
"selected": false,
"text": "routes.IgnoreRoute(\"{resource}.axd/{*pathInfo}\");\n\nSimplyRestfulRouteHandler.BuildRoutes(routes);\n\nroutes.MapR... | 2008/11/09 | [
"https://Stackoverflow.com/questions/275920",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/31412/"
] |
275,926 | <p>We are developing a WCF based system. In the process we are trying to lock some data from being modified by more than one users. So we decided to have a data structure that will contain the necessary information for the locking logic to execute (by for example storing the ID of the locked objects)</p>
<p>The problem we are having is persisting that data between sessions. Is there anyway we can avoid executing expensive database calls?
I am not sure how can we do that in WCF since it can only persist data (in memory) during an open session.</p>
| [
{
"answer_id": 430569,
"author": "Matt Davis",
"author_id": 51170,
"author_profile": "https://Stackoverflow.com/users/51170",
"pm_score": 2,
"selected": false,
"text": "[ServiceContract]\npublic interface IMyService\n{\n [OperationContract]\n void Start(IPAddress address);\n}\n\n[S... | 2008/11/09 | [
"https://Stackoverflow.com/questions/275926",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/28212/"
] |
275,931 | <p>I'm brand new to jQuery and have some experience using Prototype. In Prototype, there is a method to "flash" an element — ie. briefly highlight it in another color and have it fade back to normal so that the user's eye is drawn to it. Is there such a method in jQuery? I see fadeIn, fadeOut, and animate, but I don't see anything like "flash". Perhaps one of these three can be used with appropriate inputs?</p>
| [
{
"answer_id": 275953,
"author": "okoman",
"author_id": 35903,
"author_profile": "https://Stackoverflow.com/users/35903",
"pm_score": 4,
"selected": false,
"text": "jQuery.fn.flash = function( color, duration )\n{\n\n var current = this.css( 'color' );\n\n this.animate( { color: 'r... | 2008/11/09 | [
"https://Stackoverflow.com/questions/275931",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7961/"
] |
275,944 | <p>I have the string </p>
<pre><code>a.b.c.d
</code></pre>
<p>I want to count the occurrences of '.' in an idiomatic way, preferably a one-liner.</p>
<p>(Previously I had expressed this constraint as "without a loop", in case you're wondering why everyone's trying to answer without using a loop).</p>
| [
{
"answer_id": 275969,
"author": "Jon Skeet",
"author_id": 22656,
"author_profile": "https://Stackoverflow.com/users/22656",
"pm_score": 8,
"selected": false,
"text": "split"
},
{
"answer_id": 275975,
"author": "Yonatan Maman",
"author_id": 20065,
"author_profile": "h... | 2008/11/09 | [
"https://Stackoverflow.com/questions/275944",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/4343/"
] |
275,957 | <p>I am working on a background program that will be running for a long time, and I have a external logging program (<a href="http://www.gurock.com/products/smartinspect/" rel="noreferrer">SmartInspect</a>) that I want to feed with some values periodically, to monitor it in realtime when debugging.</p>
<p>I know I can simply fire up multiple programs, like the Task Manager, or IARSN TaskInfo, but I'd like to keep everything in my own program for this, as I also wants to add some simple rules like if the program uses more than X% CPU, flag this in the log.</p>
<p>I have a background thread that periodically feeds some statistics to SmartInspect, like memory consumption, working set, etc.</p>
<p>Is it possible for this thread to get a reasonably accurate measure of how much of the computer's CPU resources it consumes? The main program is a single-threaded application (apart from the watchdog thread that logs statistics) so if a technique is limited to <em>how much does a single thread use</em> then that would be good too.</p>
<p>I found some entries related to something called <em>rusage</em> for Linux and C. Is there something similar I can use for this?</p>
<hr>
<p><strong>Edit:</strong> Ok, I tried the performance counter way, but it added quite a lot of GC-data each time called, so the graph for memory usage and garbage collection skyrocketed. I guess I'll just leave this part out for now.</p>
| [
{
"answer_id": 275963,
"author": "Sunlight",
"author_id": 33650,
"author_profile": "https://Stackoverflow.com/users/33650",
"pm_score": 3,
"selected": false,
"text": "System.Diagnostics.PerformanceCounter"
},
{
"answer_id": 276181,
"author": "sundar venugopal",
"author_id... | 2008/11/09 | [
"https://Stackoverflow.com/questions/275957",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/267/"
] |
275,958 | <p>I have a list of say 100 unsorted items. Each item belongs to a group. The group the item belongs to is simply a member of the item class.</p>
<p>Using C/C++ I'm looking for the most efficient way of scanning through the list of items, checking which group they are in and printing the item to the screen. Here's the catch though. Once an item from a group has been printed to the screen, I don't want to print any more items belonging to that group.</p>
<p>I'm using a pre STL compiler and the size of the executable is critical so I don't want to start defining my own Hash classes.</p>
| [
{
"answer_id": 275961,
"author": "Kasprzol",
"author_id": 5957,
"author_profile": "https://Stackoverflow.com/users/5957",
"pm_score": 1,
"selected": false,
"text": "#include <unordered_map>\n#include <string>\n#include <iostream>\n\nstd::string getGroupForNumber( int num )\n{\n//\n}\n\ni... | 2008/11/09 | [
"https://Stackoverflow.com/questions/275958",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/7129/"
] |
275,994 | <p>I need to move backwards through an array, so I have code like this:</p>
<pre><code>for (int i = myArray.Length - 1; i >= 0; i--)
{
// Do something
myArray[i] = 42;
}
</code></pre>
<p>Is there a better way of doing this?</p>
<p>Update: I was hoping that maybe C# had some built-in mechanism for this like:</p>
<pre><code>foreachbackwards (int i in myArray)
{
// so easy
}
</code></pre>
| [
{
"answer_id": 275996,
"author": "Adam Rosenfield",
"author_id": 9530,
"author_profile": "https://Stackoverflow.com/users/9530",
"pm_score": 4,
"selected": false,
"text": "std::vector"
},
{
"answer_id": 276001,
"author": "Marc Gravell",
"author_id": 23354,
"author_pro... | 2008/11/09 | [
"https://Stackoverflow.com/questions/275994",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14606/"
] |
276,022 | <p>Do you follow a standard for wrapping long lines in source code? What line length do you find most comfortable to read?</p>
<p>Sometimes I find people who program on wide-screen monitors and like to use its full width for displaying source code. I prefer shorter lines, around 80-100 characters, but I have a hard time trying to convince colleagues with the ever-increasing popularity of wide-screen devices.</p>
<p><em>Edit:</em></p>
<p>Similiar questions:</p>
<ul>
<li><a href="https://stackoverflow.com/questions/110928/">Is there a valid reason for enforcing a maximum width of 80 characters in a code file, this day and age?</a></li>
</ul>
| [
{
"answer_id": 276048,
"author": "Ilya",
"author_id": 6807,
"author_profile": "https://Stackoverflow.com/users/6807",
"pm_score": 2,
"selected": false,
"text": "status = do_something(); \nif (status == error)\n{\n do_error_handling();\n return;\n} \n/* do you regular flow */\nstatu... | 2008/11/09 | [
"https://Stackoverflow.com/questions/276022",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/23193/"
] |
276,029 | <p>I want to write a regular expression that will replace the word Paris by a link, for only the word is not ready a part of a link.</p>
<p>Example:</p>
<pre><code> i'm living <a href="Paris" atl="Paris link">in Paris</a>, near Paris <a href="gare">Gare du Nord</a>, i love Paris.
</code></pre>
<p>would become </p>
<pre><code> i'm living.........near <a href="">Paris</a>..........i love <a href="">Paris</a>.
</code></pre>
| [
{
"answer_id": 276073,
"author": "okoman",
"author_id": 35903,
"author_profile": "https://Stackoverflow.com/users/35903",
"pm_score": 0,
"selected": false,
"text": "!(<a.*</a>.*)*Paris!isU\n"
},
{
"answer_id": 276109,
"author": "Tomalak",
"author_id": 18771,
"author_p... | 2008/11/09 | [
"https://Stackoverflow.com/questions/276029",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/35937/"
] |
276,030 | <p>As we all know, global data, like the locale settings affecting the numeric decimal point printf() and strtod() are using, is evil. Fortunately, MSVC++ 9 allows to use per-thread locales by a <code>_configthreadlocale(_ENABLE_PER_THREAD_LOCALE)</code> call. Unfortunately, it seems that the localeconv() function does not notice this and still returns the global locale settings, e.g. localeconv()->decimal_point seems to always return the global locale setting before the _configthreadlocale() call. Is this a bug in the MSVC library or is this expected?</p>
<p>TIA
Paavo</p>
| [
{
"answer_id": 7516333,
"author": "rubenvb",
"author_id": 256138,
"author_profile": "https://Stackoverflow.com/users/256138",
"pm_score": 0,
"selected": false,
"text": "_configthreadlocale"
}
] | 2008/11/09 | [
"https://Stackoverflow.com/questions/276030",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/34911/"
] |
276,033 | <p>How would one go about deleting all of the directories in a directory tree that have a certain name if the only access to the server available is via FTP?</p>
<p>To clarify, I would like to iterate over a directory tree and delete every directory whose name matches a certain string via FTP. A way to implement this in PHP would be nice - where should I start? Also, if anyone knows of any utilities that would already do this, that would be great as well.</p>
| [
{
"answer_id": 276407,
"author": "Tom Haigh",
"author_id": 22224,
"author_profile": "https://Stackoverflow.com/users/22224",
"pm_score": 3,
"selected": true,
"text": "function scan_ftp_dir($conn, $dir, $pattern) {\n $files = ftp_nlist($conn, $dir);\n if (!$files) {\n return;... | 2008/11/09 | [
"https://Stackoverflow.com/questions/276033",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3831/"
] |
276,040 | <p>Generally I connect and retrieve data using the standard way (error checking removed for simplicity):</p>
<pre><code>$db = mysql_select_db("dbname", mysql_connect("host","username","passord"));
$items = mysql_query("SELECT * FROM $db");
while($item = mysql_fetch_array($items)) {
my_function($item[rowname]);
}
</code></pre>
<p>Where my_function does some useful things witht that particular row.</p>
<p>What is the equivalent code using objects?</p>
| [
{
"answer_id": 276065,
"author": "I GIVE TERRIBLE ADVICE",
"author_id": 35344,
"author_profile": "https://Stackoverflow.com/users/35344",
"pm_score": 3,
"selected": true,
"text": "$dbh = new PDO(\"mysql:host=$hostname;dbname=$db\", $username, $password); //connect to the database\n//each... | 2008/11/09 | [
"https://Stackoverflow.com/questions/276040",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/16511/"
] |
276,052 | <p>How can I get the current system status (current CPU, RAM, free disk space, etc.) in Python? Ideally, it would work for both Unix and Windows platforms.</p>
<p>There seems to be a few possible ways of extracting that from my search:</p>
<ol>
<li><p>Using a library such as <a href="http://www.psychofx.com/psi/trac/wiki/" rel="noreferrer">PSI</a> (that currently seems not actively developed and not supported on multiple platforms) or something like <a href="http://www.i-scream.org/pystatgrab/" rel="noreferrer">pystatgrab</a> (again no activity since 2007 it seems and no support for Windows).</p>
</li>
<li><p>Using platform specific code such as using a <code>os.popen("ps")</code> or similar for the *nix systems and <code>MEMORYSTATUS</code> in <code>ctypes.windll.kernel32</code> (see <a href="http://code.activestate.com/recipes/511491/" rel="noreferrer">this recipe on ActiveState</a>) for the Windows platform. One could put a Python class together with all those code snippets.</p>
</li>
</ol>
<p>It's not that those methods are bad but is there already a well-supported, multi-platform way of doing the same thing?</p>
| [
{
"answer_id": 276934,
"author": "monkut",
"author_id": 24718,
"author_profile": "https://Stackoverflow.com/users/24718",
"pm_score": 4,
"selected": false,
"text": "'''\nMonitor window processes\n\nderived from:\n>for sys available mem\nhttp://msdn2.microsoft.com/en-us/library/aa455130.a... | 2008/11/09 | [
"https://Stackoverflow.com/questions/276052",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/35935/"
] |
276,066 | <p>I need a function count_permutations() that returns the number of permutations of a given range. <em>Assuming that the range is allowed to be modified, and starts at the first permutation,</em> I could naively implement this as repeated calls to next_permutation() as below:</p>
<pre><code>template<class Ret, class Iter>
Ret count_permutations(Iter first, Iter last)
{
Ret ret = 0;
do {
++ret;
} while (next_permutation(first, last));
return ret;
}
</code></pre>
<p><em>Is there a faster way that doesn't require iterating through all the permutations to find the answer? It could still assume that the input can be modified, and starts in the first permutation, but obviously if it is possible to implement without those assumtions it'd be great too.</em></p>
| [
{
"answer_id": 276077,
"author": "Nicola Bonelli",
"author_id": 19630,
"author_profile": "https://Stackoverflow.com/users/19630",
"pm_score": 0,
"selected": false,
"text": "// generic factorial implementation...\n\nint factorial(int number) {\n int temp;\n if(number <= 1) return 1;... | 2008/11/09 | [
"https://Stackoverflow.com/questions/276066",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/5963/"
] |
276,072 | <p>I just picked up Agile Web Development with Rails 3rd Ed., and I'm going thru the Depot Application chapters, and I have a question about Product/Item options.</p>
<p>If I wanted to modify the product catalog and store so that products could have options (size, color, whatever), where/how would I do that?</p>
<p>Let's say I'm selling t-shirts, and they come in different sizes. I don't feel like that's something that really needs a model created to handle sizes, so I thought I could just add it as a select box in the html in the store's view.</p>
<p>But, each Add to Cart button is wrapped by a form tag that is automatically generated by button_to, and doesn't seem to give me the ability to pass additional parameters to my cart. How can I get the size of the item added into the POST to add_to_cart?</p>
<p>The helper in my view:</p>
<pre><code><%= button_to "Add to Cart" , :action => :add_to_cart, :id => product %>
</code></pre>
<p>The form that it generates:</p>
<pre><code><form method="post" action="/store/add_to_cart/3" class="button-to">
</code></pre>
| [
{
"answer_id": 276083,
"author": "Can Berk Güder",
"author_id": 2119,
"author_profile": "https://Stackoverflow.com/users/2119",
"pm_score": 0,
"selected": false,
"text": "button_to"
},
{
"answer_id": 278388,
"author": "Cameron Price",
"author_id": 35526,
"author_profi... | 2008/11/09 | [
"https://Stackoverflow.com/questions/276072",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
276,087 | <p>I am working on a web application that is designed to display a bunch of data that is updated periodically with AJAX. The general usage scenario would be that a user would leave it open all day and take a glance at it now and then.</p>
<p>I am encountering a problem where the browsers memory footprint is growing slowly over time. This is happening in both Firefox and IE 7 (Although not in Chrome). After a few hours, it can cause IE7 to have a footprint of ~200MB and FF3 to have a footprint of ~400MB.</p>
<p>After a lot of testing, I have found that the memory leak only occurs if the AJAX calls are being responded to. If the server doesn't respond to anything, I can leave the page open for hours and the footprint won't grow.</p>
<p>I am using prototype for my AJAX calls. So, I'm guessing there is an issue with the onSuccess callback creating these memory leaks. </p>
<p>Does anyone have any tips on preventing memory leaks with prototype / AJAX? Or any methods on how to troubleshoot this problem?</p>
<p>EDIT: found out the issue lies in a js graphing library I am using. Can be seen <a href="http://code.google.com/p/flotr/issues/detail?id=5" rel="noreferrer">here</a>. </p>
| [
{
"answer_id": 276124,
"author": "eyelidlessness",
"author_id": 17964,
"author_profile": "https://Stackoverflow.com/users/17964",
"pm_score": 5,
"selected": true,
"text": "<div id=\"ajaxResponseTarget\">\n ...\n</div>\n<script type=\"text/javascript\">\n $(someButton).observe('clic... | 2008/11/09 | [
"https://Stackoverflow.com/questions/276087",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12983/"
] |
276,088 | <p>My ASP.NET application allows users to upload and download large files. Both procedures involve reading and writing filestreams. What should I do to ensure the application doesn't hang or crash when it handles a large file? Should the file operations be handled on a worker thread for example?</p>
| [
{
"answer_id": 276098,
"author": "Turnkey",
"author_id": 13144,
"author_profile": "https://Stackoverflow.com/users/13144",
"pm_score": 2,
"selected": true,
"text": "// Read the data in buffer.\nlength = iStream.Read(buffer, 0, bufferSize);\n\n// Write the data to the current output strea... | 2008/11/09 | [
"https://Stackoverflow.com/questions/276088",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/27805/"
] |
276,099 | <p>I want to read a mac id from command line and convert it to an array of <code>uint8_t</code> values to use it in a struct. I can not get it to work. I have a vector of string for the mac id split about <code>:</code> and I want to use <code>stringstream</code> to convert them with no luck. What I am missing?</p>
<pre><code>int parseHex(const string &num){
stringstream ss(num);
ss << std::hex;
int n;
ss >> n;
return n;
}
uint8_t tgt_mac[6] = {0, 0, 0, 0, 0, 0};
v = StringSplit( mac , ":" );
for( int j = 0 ; j < v.size() ; j++ ){
tgt_mac[j] = parseHex(v.at(j));
}
</code></pre>
| [
{
"answer_id": 276149,
"author": "Martin York",
"author_id": 14065,
"author_profile": "https://Stackoverflow.com/users/14065",
"pm_score": 0,
"selected": false,
"text": "#include <sstream>\n#include <iostream>\n\nint main()\n{\n std::string h(\"a5\");\n std::stringstream s(h)... | 2008/11/09 | [
"https://Stackoverflow.com/questions/276099",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/29742/"
] |
276,102 | <p>Is there some way to catch exceptions which are otherwise unhandled (including those thrown outside the catch block)?</p>
<p>I'm not really concerned about all the normal cleanup stuff done with exceptions, just that I can catch it, write it to log/notify the user and exit the program, since the exceptions in these casese are generaly fatal, unrecoverable errors.</p>
<p>something like:</p>
<pre><code>global_catch()
{
MessageBox(NULL,L"Fatal Error", L"A fatal error has occured. Sorry for any inconvience", MB_ICONERROR);
exit(-1);
}
global_catch(Exception *except)
{
MessageBox(NULL,L"Fatal Error", except->ToString(), MB_ICONERROR);
exit(-1);
}
</code></pre>
| [
{
"answer_id": 276110,
"author": "EvilTeach",
"author_id": 7734,
"author_profile": "https://Stackoverflow.com/users/7734",
"pm_score": 6,
"selected": true,
"text": "catch (...)\n{\n std::cout << \"OMG! an unexpected exception has been caught\" << std::endl;\n}\n"
},
{
"answer_... | 2008/11/09 | [
"https://Stackoverflow.com/questions/276102",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/6266/"
] |
276,113 | <p>Do bubble sorts have any real world use? Every time I see one mentioned, it's always either:</p>
<ol>
<li>A sorting algorithm to learn with.</li>
<li>An example of a sorting algorithm <em>not</em> to use.</li>
</ol>
| [
{
"answer_id": 276156,
"author": "buti-oxa",
"author_id": 2515,
"author_profile": "https://Stackoverflow.com/users/2515",
"pm_score": 1,
"selected": false,
"text": "// Use sort of stooge to sort the three elements by cpFirst\n\nSwapElementsIfNeeded(&elementTop, &elementBottom);\nSwapElem... | 2008/11/09 | [
"https://Stackoverflow.com/questions/276113",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2147/"
] |
276,121 | <p>I have been using netbeans as a tool for my java, and i have a problem. I read <a href="http://www.netbeans.org/kb/61/java/gui-db-custom.html" rel="nofollow noreferrer">this tutorial</a> and then i tried to create a table using this SQL:</p>
<pre><code>CREATE TABLE CUSTOMERS (
ID INTEGER NOT NULL AUTO_INCREMENT PRIMARY KEY,
FIRST_NAME VARCHAR(20),
LAST_NAME VARCHAR(30),
ADDRESS VARCHAR(30),
CITY VARCHAR(30),
STATE_ VARCHAR(30),
ZIP VARCHAR(15),
COUNTRY_ID INTEGER,
PHONE VARCHAR(15),
EMAIL_ADDRESS VARCHAR(50)
)ENGINE=INNODB;
</code></pre>
<p>When i tried to run it, I got this error message:</p>
<blockquote>
<p>sql state 42X01 : Syntax error :
encountered "AUTO_INCREMENT" at line 2
column 29</p>
</blockquote>
<p>and when i delete the AUTO_INCREMENT, another error:</p>
<blockquote>
<p>detected ENGINE=INNODB;</p>
</blockquote>
<p>can someone help me? Thanks.</p>
| [
{
"answer_id": 276129,
"author": "fmsf",
"author_id": 26004,
"author_profile": "https://Stackoverflow.com/users/26004",
"pm_score": 1,
"selected": false,
"text": "CREATE TABLE CUSTOMERS \n( ID INTEGER NOT NULL auto_increment,\nFIRST_NAME VARCHAR(20), \nLAST_NAME VARCHAR(30), \nADDRESS VA... | 2008/11/09 | [
"https://Stackoverflow.com/questions/276121",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
276,126 | <p>Using ASP.net 2.0, how do I present the information to the user similar to the Questions list on SO where each question has some child items (like the tags).</p>
<p>I would probably be making two separate queries, one to first find the list of questions, then another query to find all tags which belonged to the list of questions.</p>
<p><em>Approach 1:</em></p>
<p>Then I would probably be using nested repeaters and doing a select statement in the code-behind on each nested repeater "OnItemDataBind"...</p>
<p><em>Approach 2:</em></p>
<p>Or with the two datasets, I would use C# code to create a business entity of each of the "Questions" and have a property called "Tags". I would then loop through my tags dataset and assign the property.</p>
<p>What's more efficient? Are there any other alternatives?</p>
| [
{
"answer_id": 276240,
"author": "flesh",
"author_id": 27805,
"author_profile": "https://Stackoverflow.com/users/27805",
"pm_score": 3,
"selected": true,
"text": "<asp:DataList ID=\"dlMenuOne\" runat=\"server\" onitemdatabound=\"dlMenu_ItemDataBound\" >\n <ItemTemplate>\n ... | 2008/11/09 | [
"https://Stackoverflow.com/questions/276126",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/32372/"
] |
276,132 | <p>I'm setting up an Internet-facing ASP.NET MVC application, on Windows 2008. It uses SQL Server 2008 for its database. I'm looking for best-practices for securing it.</p>
<p>I found <a href="http://www.enterprisenetworkingplanet.com/netsecur/article.php/3552711" rel="nofollow noreferrer">this article</a>, but it's a bit dated now. How much of that advice is still valuable?</p>
<p>Some background -- it's a personal site, behind my home NAT/firewall box; and I'll only forward ports 80 and 443 to it. The IIS server itself is a Windows 2008 host running on HyperV (I only have one physical box to spare).</p>
<p>One useful thing that's mentioned in that article (which had occurred to me already) is that the IIS box shouldn't be a member of the domain, so that an intruder can't easily get off the box. I'll be removing it from the domain in a moment :)</p>
<p>What other tips should I (and anyone deploying to a bigger environment) bear in mind?</p>
<p>I know that this isn't strictly a programming-related question (there's no source code in it!), but I guess that most programmers have to dabble in operations stuff when it comes to deployment recommendations.</p>
| [
{
"answer_id": 276240,
"author": "flesh",
"author_id": 27805,
"author_profile": "https://Stackoverflow.com/users/27805",
"pm_score": 3,
"selected": true,
"text": "<asp:DataList ID=\"dlMenuOne\" runat=\"server\" onitemdatabound=\"dlMenu_ItemDataBound\" >\n <ItemTemplate>\n ... | 2008/11/09 | [
"https://Stackoverflow.com/questions/276132",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/8446/"
] |
276,166 | <p>table data of 2 columns "category" and "subcategory"</p>
<p>i want to get a collection of "category", [subcategories]
using code below i get duplicates. Puting .Distinct() after outer "from" does not help much. What do i miss?</p>
<pre><code> var rootcategories = (from p in sr.products
orderby p.category
select new
{
category = p.category,
subcategories = (
from p2 in sr.products
where p2.category == p.category
select p2.subcategory).Distinct()
}).Distinct();
</code></pre>
<p>sr.products looks like this</p>
<pre><code>category subcategory
----------------------
cat1 subcat1
cat1 subcat2
cat2 subcat3
cat2 subcat3
</code></pre>
<p>what i get in results is </p>
<pre><code>cat1, [subcat1,subcat2]
cat1, [subcat1,subcat2]
</code></pre>
<p>but i only want one entry</p>
<p>solved my problem with this code:</p>
<pre><code> var rootcategories2 = (from p in sr.products
group p.subcategory by p.category into subcats
select subcats);
</code></pre>
<p>now maybe it is time to think of what was the right question.. (-:</p>
| [
{
"answer_id": 276171,
"author": "chakrit",
"author_id": 3055,
"author_profile": "https://Stackoverflow.com/users/3055",
"pm_score": 2,
"selected": false,
"text": "var mainCategories = (from p in products select p.category).Distinct();\n\nvar rootCategories =\n from c in mainCategorie... | 2008/11/09 | [
"https://Stackoverflow.com/questions/276166",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/35954/"
] |
276,173 | <p>What are your favorite C++ coding style idioms? I'm asking about style or coding typography such as where you put curly braces, are there spaces after keywords, the size of indents, etc. This is opposed to best-practices or requirements such as always deleting arrays with <code>delete[]</code>. </p>
<p>Here is an example of one of my favorites: In C++ Class initializers, we put the separators at the front of the line, rather than the back. This makes it easier to keep this up to date. It also means that source code control diffs between versions are cleaner.</p>
<pre><code>TextFileProcessor::
TextFileProcessor( class ConstStringFinder& theConstStringFinder )
: TextFileProcessor_Base( theConstStringFinder )
, m_ThreadHandle ( NULL )
, m_startNLSearch ( 0 )
, m_endNLSearch ( 0 )
, m_LineEndGetIdx ( 0 )
, m_LineEndPutIdx ( 0 )
, m_LineEnds ( new const void*[ sc_LineEndSize ] )
{
;
}
</code></pre>
| [
{
"answer_id": 276201,
"author": "Ather",
"author_id": 1065163,
"author_profile": "https://Stackoverflow.com/users/1065163",
"pm_score": 1,
"selected": false,
"text": "int ReturnMaxValue(\n int* inputList, /* the list of integer values from which to get the maximum */\n long size... | 2008/11/09 | [
"https://Stackoverflow.com/questions/276173",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18256/"
] |
276,177 | <p>In my ASP.NET 1.1 application, I am compressing and replacing the hidden Viewstate variable with an alternate compressed value, stored in a hidden field called __VSTATE. This works well but on a few occasions, submitting a page causes the common "potentially dangerous Request.Form value ..." error.</p>
<p>I examined the __VSTATE value and nothing seems to be potentially dangerous. I was able to reproduce the error with a completely stripped down version of the page and __VSTATE value as shown below. Pressing the submit button causes the error. The page works fine if I change the value to "".</p>
<pre><code><%@ Page Language="vb" AutoEventWireup="false" Codebehind="Dangerous.aspx.vb" Inherits="Dynalabs.Dangerous" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<body MS_POSITIONING="FlowLayout">
<form id="Form1" method="post" runat="server">
<input type="hidden" id="__VSTATE" runat="server" value="Onw=" />
<asp:Button ID="btnSubmit" Runat="server" Text="Submit" />
</form>
</body>
</html>
</code></pre>
<p>Changing the field name to "MyHiddenWT" made no difference. Removing the runat="server" did stop the error but that just means that .NET only examines server side controls. I also tried some additional values and found that of the following:</p>
<pre><code>"Anw=", "Bnw=", "Cnw=", ... "Nnw=", "Onw=", "Pnw=", ... "Znw=",
</code></pre>
<p>"Onw=" is the only one that causes the problem. Is the captial O being seen as an octal value somehow?</p>
<p>Can someone explain why this value is triggering the error message? I'm also looking for a solution but, please, do not tell me to remove page validation. That's the same as saying a car with bad brakes can be fixed by not driving the car.</p>
<p>Thank you in advance.</p>
| [
{
"answer_id": 276270,
"author": "chakrit",
"author_id": 3055,
"author_profile": "https://Stackoverflow.com/users/3055",
"pm_score": 1,
"selected": false,
"text": "<input type=\"hidden\" id=\"__VSTATE\" runat=\"server\" value=\"vOnw=\" />\n"
}
] | 2008/11/09 | [
"https://Stackoverflow.com/questions/276177",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/35955/"
] |
276,179 | <p>Does anyone know which property sets the text color for disabled control?
I have to display some text in a disabled <code>TextBox</code> and I want to set its color to black.</p>
| [
{
"answer_id": 276193,
"author": "Eric Schoonover",
"author_id": 3957,
"author_profile": "https://Stackoverflow.com/users/3957",
"pm_score": 7,
"selected": true,
"text": "BackColor"
},
{
"answer_id": 631983,
"author": "Cheetah",
"author_id": 7649,
"author_profile": "h... | 2008/11/09 | [
"https://Stackoverflow.com/questions/276179",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/22996/"
] |
276,180 | <p>What software does everyone use to monitor hardware? I know about nagios and cacti, but does anyone use any other software?</p>
| [
{
"answer_id": 3765800,
"author": "VxJasonxV",
"author_id": 106813,
"author_profile": "https://Stackoverflow.com/users/106813",
"pm_score": 0,
"selected": false,
"text": "god"
}
] | 2008/11/09 | [
"https://Stackoverflow.com/questions/276180",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
276,184 | <p>Is there any example code of a <a href="http://www.python.org/" rel="noreferrer">cpython</a> (not IronPython) client which can call Windows Communication Foundation (WCF) service?</p>
| [
{
"answer_id": 3865315,
"author": "r3nrut",
"author_id": 373428,
"author_profile": "https://Stackoverflow.com/users/373428",
"pm_score": 4,
"selected": false,
"text": "from suds.client import Client\n\nprint \"Connecting to Service...\"\nwsdl = \"http://serviceurl.com/service.svc?WSDL\"\... | 2008/11/09 | [
"https://Stackoverflow.com/questions/276184",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/30289/"
] |
276,188 | <p>C++0x will allow template to take an arbitrary number of arguments. What is the best use of this feature other than implementing tuples ?</p>
| [
{
"answer_id": 276197,
"author": "Konrad Rudolph",
"author_id": 1968,
"author_profile": "https://Stackoverflow.com/users/1968",
"pm_score": 2,
"selected": false,
"text": "printf"
},
{
"answer_id": 277487,
"author": "Johannes Schaub - litb",
"author_id": 34509,
"author... | 2008/11/09 | [
"https://Stackoverflow.com/questions/276188",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/19630/"
] |
276,198 | <p>What would be the best way to manage large number of instances of the same class in MATLAB?</p>
<p>Using the naive way produces absymal results:</p>
<pre><code>classdef Request
properties
num=7;
end
methods
function f=foo(this)
f = this.num + 4;
end
end
end
>> a=[];
>> tic,for i=1:1000 a=[a Request];end;toc
Elapsed time is 5.426852 seconds.
>> tic,for i=1:1000 a=[a Request];end;toc
Elapsed time is 31.261500 seconds.
</code></pre>
<p>Inheriting handle drastically improve the results:</p>
<pre><code>classdef RequestH < handle
properties
num=7;
end
methods
function f=foo(this)
f = this.num + 4;
end
end
end
>> tic,for i=1:1000 a=[a RequestH];end;toc
Elapsed time is 0.097472 seconds.
>> tic,for i=1:1000 a=[a RequestH];end;toc
Elapsed time is 0.134007 seconds.
>> tic,for i=1:1000 a=[a RequestH];end;toc
Elapsed time is 0.174573 seconds.
</code></pre>
<p>but still not an acceptable performance, especially considering the increasing reallocation overhead </p>
<p>Is there a way to preallocate class array? Any ideas on how to manage lange quantities of object effectively?</p>
<p>Thanks,<br>
Dani</p>
| [
{
"answer_id": 276530,
"author": "Marc",
"author_id": 8478,
"author_profile": "https://Stackoverflow.com/users/8478",
"pm_score": 2,
"selected": false,
"text": "repmat"
},
{
"answer_id": 285407,
"author": "b3.",
"author_id": 14946,
"author_profile": "https://Stackover... | 2008/11/09 | [
"https://Stackoverflow.com/questions/276198",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/28772/"
] |
276,206 | <p>I have a form made up of multiple, optional subparts - each of which is enclosed in a</p>
<pre><code><div class="details"></div>
</code></pre>
<p>When editing the form I would like to hide those subparts which aren't as yet completed, and obviously I would like to do it unobtrusively. To simplify things I'm just checking to see if those fields whose name ends in 'surname' are empty, and then show/hide appropriately. So far, I have this.</p>
<pre><code>//hide the all of the element class details
$(".details").each(function (i) {
if ($('input[name$=surname]:empty',this).length == 1) {
$(this).hide();
} else {
$(this).show();
}
});
</code></pre>
<p>Of course, the :empty selector may be wrong, or indeed inappropriate. (Of course what I really want to do is show any parts where any fields are completed, but I thought I'd start with just checking the most important one.)</p>
<p>I would be greatful if anyone could anyone point me in the right direction...</p>
| [
{
"answer_id": 276221,
"author": "Cristian Libardo",
"author_id": 16526,
"author_profile": "https://Stackoverflow.com/users/16526",
"pm_score": 4,
"selected": true,
"text": "<div class=\"details\">\n <input type=\"text\" name=\"surname\" />\n</div>\n\n<script type=\"text/javascript\">... | 2008/11/09 | [
"https://Stackoverflow.com/questions/276206",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/35961/"
] |
276,212 | <p>I have a table in a database that represents dates textually (i.e. "2008-11-09") and I would like to replace them with the UNIX timestamp. However, I don't think that MySQL is capable of doing the conversion on its own, so I'd like to write a little script to do the conversion. The way I can think to do it involves getting all the records in the table, iterating through them, and updating the database records. However, with no primary key, I can't easily get the exact record I need to update.</p>
<p>Is there a way to get MySQL to assign temporary IDs to records during a SELECT so that I refer back to them when doing UPDATEs?</p>
| [
{
"answer_id": 276226,
"author": "Dana the Sane",
"author_id": 2567,
"author_profile": "https://Stackoverflow.com/users/2567",
"pm_score": 1,
"selected": false,
"text": "ALTER TABLE t ADD COLUMN dates DATETIME;\nUPDATE t set t.dates=t.olddate;\n"
},
{
"answer_id": 276228,
"au... | 2008/11/09 | [
"https://Stackoverflow.com/questions/276212",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/658/"
] |
276,249 | <p>I have this form:</p>
<pre><code><form name="customize">
Only show results within
<select name="distance" id="slct_distance">
<option>25</option>
<option>50</option>
<option>100</option>
<option value="10000" selected="selected">Any</option>
</select> miles of zip code
<input type="text" class="text" name="zip_code" id="txt_zip_code" />
<span id="customize_validation_msg"></span>
</form>
</code></pre>
<p>How can I select the <code>input</code> and <code>select</code> with one jQuery selector?</p>
<p>I tried this but it selected all of the selects and inputs on the page:</p>
<pre><code>$("form[name='customize'] select,input")
</code></pre>
| [
{
"answer_id": 276267,
"author": "okoman",
"author_id": 35903,
"author_profile": "https://Stackoverflow.com/users/35903",
"pm_score": 2,
"selected": false,
"text": "form[name='customize'] select, form[name='customize'] input\n"
},
{
"answer_id": 276284,
"author": "Kevin Gorsk... | 2008/11/09 | [
"https://Stackoverflow.com/questions/276249",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/13009/"
] |
276,253 | <p>C#: How do you pass an object in a function parameter?</p>
<pre><code>public void MyFunction(TextBox txtField)
{
txtField.Text = "Hi.";
}
</code></pre>
<p>Would the above be valid? Or?</p>
| [
{
"answer_id": 276279,
"author": "Marc Gravell",
"author_id": 23354,
"author_profile": "https://Stackoverflow.com/users/23354",
"pm_score": 2,
"selected": false,
"text": "public void MyFunction(ref MyMutableStruct whatever)\n{\n whatever.Value = \"Hi.\"; // but avoid mutable structs in ... | 2008/11/09 | [
"https://Stackoverflow.com/questions/276253",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
276,254 | <p>I have a window (derived from JFrame) and I want to disable the close button during certain operations which are not interruptible. I know I can make the button not do anything (or call a handler in a WindowListener) by calling</p>
<pre><code>setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
</code></pre>
<p>but I would like to make it clear visually that it is pointless to click it.</p>
| [
{
"answer_id": 279826,
"author": "Malfist",
"author_id": 12243,
"author_profile": "https://Stackoverflow.com/users/12243",
"pm_score": 5,
"selected": false,
"text": "setUndecorated(true);\ngetRootPane().setWindowDecorationStyle(JRootPane.NONE);\n"
},
{
"answer_id": 27587807,
... | 2008/11/09 | [
"https://Stackoverflow.com/questions/276254",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/18308/"
] |
276,266 | <p>I tried playing a .wav file using pyaudio. It works great on windows, but doesn't work in Ubuntu when another device is using sound.</p>
<blockquote>
<p>The error is "IOError: [Errorno
Invalid output device (no default
output device)] -9996</p>
</blockquote>
<p>Is there another library I could try to use? Another method?</p>
| [
{
"answer_id": 276322,
"author": "lpfavreau",
"author_id": 35935,
"author_profile": "https://Stackoverflow.com/users/35935",
"pm_score": 2,
"selected": false,
"text": "import time, wave, pymedia.audio.sound as sound\nf= wave.open('YOUR FILE NAME', 'rb')\nsampleRate= f.getframerate()\ncha... | 2008/11/09 | [
"https://Stackoverflow.com/questions/276266",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/14520/"
] |
276,278 | <p>Comparing LinkedLists and Arrays while also comparing their differences with sorted and unsorted data</p>
<ul>
<li>Adding </li>
<li>Removing</li>
<li>Retrieving </li>
<li>Sorting</li>
<li>Overall speed</li>
<li>Overall memory usage</li>
</ul>
<p>Actual questions</p>
<blockquote>
<p>Discuss the feasibility of implementing an unsorted data set as a linked list rather than an array. What would the tradeoffs be in terms of insertion, removal, retrieval, computer memory, and speed of the application?</p>
<p>Discuss the feasibility of implementing a sorted data set as a linked list rather than an array. What would the tradeoffs be in terms of insertion, removal, retrieval, computer memory, and speed of the application? </p>
<p>Based on your answers to the previous questions, summarize the costs and benefits of using linked lists in an application.</p>
</blockquote>
<p>My answers/input:</p>
<blockquote>
<p>LinkedLists have to allocate memory everytime a new Node is added, useful when adding many Nodes and size keeps changing but generally slower when adding few elements</p>
<p>Arrays allocated memory at the beggining of the program run, resizing list slow (adding many elements slow if have to resize)</p>
<p>Retrieval is faster in array due to indexing</p>
<p>Adding/removing faster in LinkedList due to pointers</p>
</blockquote>
| [
{
"answer_id": 276361,
"author": "The Archetypal Paul",
"author_id": 21755,
"author_profile": "https://Stackoverflow.com/users/21755",
"pm_score": 3,
"selected": true,
"text": "* Adding\n"
},
{
"answer_id": 50168373,
"author": "Sandeep Singh",
"author_id": 4067548,
"a... | 2008/11/09 | [
"https://Stackoverflow.com/questions/276278",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/27570/"
] |
276,281 | <p>Is it possible for me to see the amount of processor usage (% of maximum) that the current, python, app is using?</p>
<p>Scenario:
My host will allow me to run my app as long as it does not consume more then X% of the CPU power, so I would like it to 'keep an eye on itself' and slowdown. So how can I know how much CPU the app is using?</p>
<p>Target platform is *nix, however I would like to do it on a Win host also.</p>
| [
{
"answer_id": 276289,
"author": "Greg Hewgill",
"author_id": 893,
"author_profile": "https://Stackoverflow.com/users/893",
"pm_score": 3,
"selected": false,
"text": "resource"
},
{
"answer_id": 276295,
"author": "gimel",
"author_id": 6491,
"author_profile": "https://... | 2008/11/09 | [
"https://Stackoverflow.com/questions/276281",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/115/"
] |
276,286 | <p>When a webpage has moved to a new location, how do I show the moved web page AND return a 301 permanent redirect HTTP response status code in <a href="http://djangoproject.com/" rel="nofollow noreferrer">Django</a>?</p>
| [
{
"answer_id": 276326,
"author": "Owen",
"author_id": 4853,
"author_profile": "https://Stackoverflow.com/users/4853",
"pm_score": 4,
"selected": true,
"text": " from django import http\n\n return http.HttpResponsePermanentRedirect('/yournewpage.html')\n"
}
] | 2008/11/09 | [
"https://Stackoverflow.com/questions/276286",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11452/"
] |
276,292 | <p>How can I continuously capture images from a webcam?</p>
<p>I want to experiment with object recognition (by maybe using java media framework). </p>
<p>I was thinking of creating two threads</p>
<p>one thread:</p>
<ul>
<li>Node 1: capture live image</li>
<li>Node 2: save image as "1.jpg"</li>
<li>Node 3: wait 5 seconds</li>
<li>Node 4: repeat...</li>
</ul>
<p>other thread:</p>
<ul>
<li>Node 1: wait until image is captured</li>
<li>Node 2: using the "1.jpg" get colors
from every pixle</li>
<li>Node 3: save data in arrays</li>
<li>Node 4: repeat...</li>
</ul>
| [
{
"answer_id": 971686,
"author": "Community",
"author_id": -1,
"author_profile": "https://Stackoverflow.com/users/-1",
"pm_score": 2,
"selected": false,
"text": "import javax.media.*;\nimport javax.swing.*;\nimport java.awt.*;\nimport java.net.*;\nimport java.awt.event.*;\nimport javax.s... | 2008/11/09 | [
"https://Stackoverflow.com/questions/276292",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/35962/"
] |
276,310 | <p>I am using sfOpenID plugin for Symfony, which doesn't support OpenID 2.0. That means, for example, that people using Yahoo! OpenID can't login to my site.</p>
<p>There is an OpenID 2.0 plugin that works with sfGuard, but I am not using nor planning to use sfGuard. Plus, it requires to install Zend framework, too, which is an overkill in my scenario.</p>
<p>So I've got two questions, really:</p>
<ul>
<li>is there another OpenID plugin for Symfony supporting OpenID 2.0?</li>
<li>what would be the hack required to make sfOpenID support OpenID 2.0?</li>
</ul>
<p>I suppose I could study OpenID specs and hack it myself, but then, I am a lazy programmer :)</p>
| [
{
"answer_id": 276339,
"author": "lpfavreau",
"author_id": 35935,
"author_profile": "https://Stackoverflow.com/users/35935",
"pm_score": 4,
"selected": true,
"text": "sfUser"
}
] | 2008/11/09 | [
"https://Stackoverflow.com/questions/276310",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/2706/"
] |
276,319 | <p>Is there a way to create a Zip archive that contains multiple files, when the files are currently in memory? The files I want to save are really just text only and are stored in a string class in my application. But I would like to save multiple files in a single self-contained archive. They can all be in the root of the archive.</p>
<p>It would be nice to be able to do this using SharpZipLib.</p>
| [
{
"answer_id": 276330,
"author": "Jon Skeet",
"author_id": 22656,
"author_profile": "https://Stackoverflow.com/users/22656",
"pm_score": 3,
"selected": false,
"text": "MemoryStream"
},
{
"answer_id": 276347,
"author": "Cory",
"author_id": 8207,
"author_profile": "http... | 2008/11/09 | [
"https://Stackoverflow.com/questions/276319",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/194/"
] |
276,324 | <p>I'm trying to create a horizontal navigation bar in css with 5 evenly spaced links. The html hopefully will remain like this:</p>
<pre><code><div id="footer">
<ul>
<li><a href="one.html">One</a></li>
<li><a href="two.html">Two</a></li>
<li><a href="three.html">Three</a></li>
<li><a href="four.html">Four</a></li>
<li><a href="five.html">Five</a></li>
</ul>
</div>
</code></pre>
<p>So with CSS, I want to space them evenly within the footer div. So far I'm using this:</p>
<pre><code>div#footer{
height:1.5em;
background-color:green;
clear:both;
padding-top:.5em;
font-size:1.5em;
width:800px;
}
div#footer ul{
margin:0;
padding:0;
list-style:none;
}
div#footer li{
width:155px;
display:inline-block;
text-align:center;
}
</code></pre>
<p>This works pretty well, but there is spacing between the li's that I do not want. That is why I've used the 155px instead of 160px for their width, there is about 5px of space being put in between each li. Where is that spacing coming from? How can I get rid of it? If I increase the fontsize, the spacing increases as well. </p>
| [
{
"answer_id": 276333,
"author": "mercutio",
"author_id": 1951,
"author_profile": "https://Stackoverflow.com/users/1951",
"pm_score": 4,
"selected": false,
"text": "div#footer li{\n width:160px;\n display:block;\n float: left;\n text-align:center;\n}\n"
},
{
"answer_id": 2763... | 2008/11/09 | [
"https://Stackoverflow.com/questions/276324",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
276,336 | <p>This is what I am working with to get back to the web dev world</p>
<p>ASP.Net with VS2008</p>
<p>Subsonic as Data Access Layer</p>
<p>SqlServer DB</p>
<p>Home Project description:
I have a student registration system. I have a web page which should display the student records. </p>
<p>At present I have a gridview control which shows the records</p>
<p>The user logs on and gets to the view students page. The gridview shows the students in the system, where one of the columns is the registration status of open, pending, complete.</p>
<p>I want the user to be able to apply dynamic sorting or filters on the result returned so as to obtain a more refined result they wish to see. I envisioned allowing user to filter the results by applying where clause or like clause on the result returned, via a dataset interface by a subsonic method. I do not want to query the databse again to apply the filter</p>
<p>example: initial query </p>
<pre><code>Select * from studentrecords where date = convert(varchar(32,getdate(),101)
</code></pre>
<p>The user then should be able to applly filter on the resultset returned so that they can do a last name like '%Souza%'</p>
<p>Is this even possible and is binding a datasource to a gridview control the best approach or should i create a custom collection inheriting from collectionbase and then binding that to the gridview control?</p>
<p>PS: Sorry about the typo's. My machine is under the influence of tea spill on my laptop </p>
| [
{
"answer_id": 276405,
"author": "Marc Gravell",
"author_id": 23354,
"author_profile": "https://Stackoverflow.com/users/23354",
"pm_score": 1,
"selected": false,
"text": "SET @today = GETDATE()\nSET @today = CAST(FLOOR(CAST(@today as float)) as datetime)\n"
},
{
"answer_id": 2785... | 2008/11/09 | [
"https://Stackoverflow.com/questions/276336",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/-1/"
] |
276,345 | <p>I'm trying to do the following in my Django template:</p>
<pre><code> {% for embed in embeds %}
{% embed2 = embed.replace("&lt;", "<") %}
{{embed2}}<br />
{% endfor %}
</code></pre>
<p>However, I always get an invalid block or some syntax error when I do anything like that (by that I mean {% %} code inside a loop). Python doesn't have {} to signify "scope" so I think this might be my problem? Am I formatting my code wrong?</p>
<p>Edit: the exact error is: <code>Invalid block tag: 'embed2'</code></p>
<p>Edit2: Since someone said what I'm doing is not supported by Django templates, I rewrote the code, putting the logic in the view. I now have:</p>
<pre><code>embed_list = []
for embed in embeds:
embed_list[len(embed_list):] = [embed.replace("&lt;", "<")] #this is line 35
return render_to_response("scanvideos.html", {
"embed_list" :embed_list
})
</code></pre>
<p>However, I now get an error: <code>'NoneType' object is not callable" on line 35</code>.</p>
| [
{
"answer_id": 276387,
"author": "vincent",
"author_id": 34871,
"author_profile": "https://Stackoverflow.com/users/34871",
"pm_score": 2,
"selected": false,
"text": "embed_list.append(embed.replace(\"<\", \"<\"))\n"
},
{
"answer_id": 276394,
"author": "lacker",
"author... | 2008/11/09 | [
"https://Stackoverflow.com/questions/276345",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/23695/"
] |
276,355 | <p>I could really do with updating a user's session variables from within my HTTPModule, but from what I can see, it isn't possible.</p>
<p><em>UPDATE:</em> My code is currently running inside the <code>OnBeginRequest ()</code> event handler.</p>
<p><em>UPDATE:</em> Following advice received so far, I tried adding this to the <code>Init ()</code> routine in my HTTPModule:</p>
<p><code>AddHandler context.PreRequestHandlerExecute, AddressOf OnPreRequestHandlerExecute</code></p>
<p>But in my <code>OnPreRequestHandlerExecute</code> routine, the session state is still unavailable!</p>
<p>Thanks, and apologies if I'm missing something!</p>
| [
{
"answer_id": 276373,
"author": "Jim Harte",
"author_id": 4544,
"author_profile": "https://Stackoverflow.com/users/4544",
"pm_score": 7,
"selected": true,
"text": "using System;\nusing System.Web;\nusing System.Web.Security;\nusing System.Web.SessionState;\nusing System.Diagnostics;\n\n... | 2008/11/09 | [
"https://Stackoverflow.com/questions/276355",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/475/"
] |
276,360 | <p>Optimization of PHP code via runtime benchmarking is straight forward. Keep track of $start and $end times via microtime() around a code block - I am not looking for an answer that involves microtime() usage.</p>
<p>What I would like to do is measure the time it takes PHP to get prepared to run it's code - code-parse/op-code-tree-building time. My reasoning is that while it's easy to just include() every class that you <strong>might</strong> need for every page that you have on a site, the CPU overhead can't be "free". I'd like to know how "expensive" parse time really is.</p>
<p>I am assuming that an opcode cache such as APC is <strong>not</strong> part of the scenario.</p>
<p>Would I be correct that measurement of parse time in PHP is something that would have to take place in mod_php?</p>
<p><strong>EDIT</strong>: If possible, taking into account <code>$_SERVER['DOCUMENT_ROOT']</code> usage in code would be helpful. Command solutions might take a bit of tinkering to do this (but still be valuable answers).</p>
| [
{
"answer_id": 276366,
"author": "mercutio",
"author_id": 1951,
"author_profile": "https://Stackoverflow.com/users/1951",
"pm_score": 2,
"selected": false,
"text": "$ time php5 -r 'echo \"Hello world\";'\nHello world\nreal 0m1.565s\nuser 0m0.036s\nsys 0m0.024s\n"
},
{
"... | 2008/11/09 | [
"https://Stackoverflow.com/questions/276360",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/12694/"
] |
276,362 | <p>I'm working on a project for OSX where the user can pick a collection of documents (from any application) which I need to generate PDF's from. The standard Macintosh Print dialog has a PDF button which has a number of PDF-related commands including "Save as PDF...". However, I need to generate the PDF file without requiring user interactions. I ideally want this to work with any type of document.</p>
<p>Here's the options I've explored so far:</p>
<ul>
<li>Automator actions. There's a PDF library for Automator but it provides actions for working with PDF files, not generating them. There's a Finder action for printing any file but only to a real printer.</li>
<li>AppleScript. Some applications have the ability to generate PDF files (for instance, if you send 'save doc in "test.pdf"' to Pages it will generate a PDF (but this only works for Pages - I need support for any type of document).</li>
<li>Custom Printer. I could create a virtual printer driver and then use the automator action but I don't like the idea of confusing the user with an extra printer in the print list.</li>
</ul>
<p>My hope is that there's some way to interact with the active application as if the user was carrying out the following steps:</p>
<ol>
<li>Do Cmd-P (opens the print dialog)</li>
<li>Click the "PDF" button</li>
<li>Select "Save as PDF..." (second item in menu)</li>
<li>Type in filename in save dialog</li>
<li>Click "Save"</li>
</ol>
<p>If that's the best approach (is it?) then the real problem is: how do I send UI Events to an external application (keystrokes, mouse events, menu selections) ?</p>
<p><strong>Update:</strong> Just to clarify one point: the documents I need to convert to PDF are documents that are created by <em>other applications</em>. For example, the user might pick a Word document or a Numbers spreadsheet or an OmniGraffle drawing or a Web Page. The common denominator is that each of these documents has an associated application and that application knows how to print it (and OSX knows how to render print output to a PDF file).</p>
<p>So, the samples at Cocoa Dev Central don't help because they're about generating a PDF from <em>my application</em>.</p>
| [
{
"answer_id": 277015,
"author": "Timour",
"author_id": 21105,
"author_profile": "https://Stackoverflow.com/users/21105",
"pm_score": 4,
"selected": true,
"text": "tell application \"System Events\"\n tell window of process \"Safari\"\n set foremost to true\n ... | 2008/11/09 | [
"https://Stackoverflow.com/questions/276362",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/35958/"
] |
276,382 | <p>In my app users need to be able to enter numeric values with decimal places. The iPhone doesn't provides a keyboard that's specific for this purpose - only a number pad and a keyboard with numbers and symbols.</p>
<p>Is there an easy way to use the latter and prevent any non-numeric input from being entered without having to regex the final result?</p>
<p>Thanks!</p>
| [
{
"answer_id": 321605,
"author": "shek",
"author_id": 40618,
"author_profile": "https://Stackoverflow.com/users/40618",
"pm_score": 7,
"selected": true,
"text": "NSNumberFormatter *currencyFormatter = [[NSNumberFormatter alloc] init];\n[currencyFormatter setNumberStyle:NSNumberFormatterC... | 2008/11/09 | [
"https://Stackoverflow.com/questions/276382",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/1043/"
] |
276,383 | <p>I have a Dictionary that when I add multiple values to it, the items that were entered before take the values of the item added. I am using the .Net 3.5 Here is the code:</p>
<pre><code>public static Dictionary<string, Neighborhoods> Families()
{
if (File.Exists(calculatePath() + "Family.txt")){}
else {File.Create(calculatePath() + "Family.txt").Close();}
string[] inp = File.ReadAllLines(calculatePath() + "Family.txt");
Neighborhoods temp = new Neighborhoods();
Dictionary<string, Neighborhoods> All_Families = new Dictionary<string, Neighborhoods>();
string currentphase = null;
foreach (string s in inp)
{
switch (s)
{
case "!<Start Family>!": temp = new Neighborhoods();
break;
case "<Family Name>": currentphase = "<Family Name>";
break;
case "<End Family Name>": currentphase = null;
break;
case "<Neighbour Enabled>True": temp.Neighbourhood_Enabled1 = true;
currentphase = "<Neighbour Enabled>True";
break;
case "<Neighbour Enabled>False": temp.Neighbourhood_Enabled1 = false;
temp.Neighbourhood_Input1 = null;
break;
case "<University Enabled>True": temp.University_Enabled1 = true;
currentphase = "<University Enabled>True";
break;
case "<University Enabled>False": temp.University_Enabled1 = false;
temp.University_Input1 = null;
currentphase = null;
break;
case "<Downtown Enabled>True": temp.Downtown_Enabled1 = true;
currentphase = "<Downtown Enabled>True";
break;
case "<Downtown Enabled>False": temp.Downtown_Enabled1 = false;
temp.Downtown_Input1 = null;
currentphase = null;
break;
case "!<End Family>!": All_Families.Add(temp.Name, temp);
break;
default: if (currentphase == "<Family Name>") temp.Name = s;
if (currentphase == "<Neighbour Enabled>True") temp.Neighbourhood_Input1 = s;
if (currentphase == "<University Enabled>True") temp.University_Input1 = s;
if (currentphase == "<Downtown Enabled>True") temp.Downtown_Input1 = s;
break;
}
}
return All_Families;
}
</code></pre>
<p>How can I make it so that when I add new keys and values, the old keys keep their original value</p>
<hr>
<p>Sample data:</p>
<pre><code>!<Start Family>!
Family Name>
qwe
<End Family Name>
<Neighbour Enabled>True
qwe
<University Enabled>True
we
<Downtown Enabled>True
qwe
!<End Family>!
!<Start Family>!
<Family Name>
123
<End Family Name>
<Neighbour Enabled>True
123
<University Enabled>True
123
<Downtown Enabled>True
123
!<End Family>!
</code></pre>
<hr>
<p>Here is the nieghbourhoods class for reference. I will try the xml methods but it wont be finished quickly, I'm still learning this stuff.</p>
<pre><code>class Neighborhoods
{
public Neighborhoods()
{
name = "";
Neighbourhood_Enabled = false;
Neighbourhood_Input = "";
University_Enabled = false;
University_Input = "";
Downtown_Enabled = false;
Downtown_Input = "";
}
static string name;
public string Name
{
get { return Neighborhoods.name; }
set { Neighborhoods.name = value; }
}
static bool Neighbourhood_Enabled;
public bool Neighbourhood_Enabled1
{
get { return Neighborhoods.Neighbourhood_Enabled; }
set { Neighborhoods.Neighbourhood_Enabled = value; }
}
static string Neighbourhood_Input;
public string Neighbourhood_Input1
{
get { return Neighborhoods.Neighbourhood_Input; }
set { Neighborhoods.Neighbourhood_Input = value; }
}
static bool University_Enabled;
public bool University_Enabled1
{
get { return Neighborhoods.University_Enabled; }
set { Neighborhoods.University_Enabled = value; }
}
static string University_Input;
public string University_Input1
{
get { return Neighborhoods.University_Input; }
set { Neighborhoods.University_Input = value; }
}
static bool Downtown_Enabled;
public bool Downtown_Enabled1
{
get { return Neighborhoods.Downtown_Enabled; }
set { Neighborhoods.Downtown_Enabled = value; }
}
static string Downtown_Input;
public string Downtown_Input1
{
get { return Neighborhoods.Downtown_Input; }
set { Neighborhoods.Downtown_Input = value; }
}
}
</code></pre>
| [
{
"answer_id": 276411,
"author": "FlySwat",
"author_id": 1965,
"author_profile": "https://Stackoverflow.com/users/1965",
"pm_score": 2,
"selected": false,
"text": "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n<families>\n <family>\n <name>Smith</name>\n <neighborhood>true</neighbor... | 2008/11/09 | [
"https://Stackoverflow.com/questions/276383",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/35984/"
] |
276,386 | <p>Say I have a C program which is broken to a set of *.c and *.h files. If code from one file uses functions from another file, where should I include the header file? Inside the *.c file that used the function, or inside the header of that file?</p>
<p>E.g. file <code>foo.c</code> includes <code>foo.h</code>, which contains all declarations for <code>foo.c</code>; same for <code>bar.c</code> and <code>bar.h</code>. Function <code>foo1()</code> inside <code>foo.c</code> calls <code>bar1()</code>, which is declared in <code>bar.h</code> and defined in <code>bar.c</code>. Now the question is, should I include <code>bar.h</code> inside <code>foo.h</code>, or inside <code>foo.c</code>?</p>
<p>What would be a good set of rules-of-thumb for such issues?</p>
| [
{
"answer_id": 276391,
"author": "mipadi",
"author_id": 28804,
"author_profile": "https://Stackoverflow.com/users/28804",
"pm_score": 2,
"selected": false,
"text": ".h"
},
{
"answer_id": 276573,
"author": "Adam Liss",
"author_id": 29157,
"author_profile": "https://Sta... | 2008/11/09 | [
"https://Stackoverflow.com/questions/276386",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/35324/"
] |
276,400 | <p>I'm trying to make a webpage that allows the uploading of multiple files at the same times. I will limit the file extensions to the most common images like JPG, JPEG, PNG and GIF.</p>
<p>I've done some research on this and everywhere I look it's flash this and flash that.</p>
<p>I don't want to use flash really. Especially with Flash 10, which disables the most common used method to enable multifile upload.</p>
<p>What I'm looking for is a way to keep creating more and more input fields, each with a browse button and then with one final upload button at the bottom of the form. Creating the new input fields with a Javascript is nog big deal really.</p>
<p>So I'm wondering how this works. Do I need to give all file-input fields the same name atribute so I can use 1 piece of PHP code to solve this? Or Is there some way for PHP to detect howmany files have been sumbitted and simply put the code for parsing a file inside a for-loop?</p>
| [
{
"answer_id": 276414,
"author": "Tom Haigh",
"author_id": 22224,
"author_profile": "https://Stackoverflow.com/users/22224",
"pm_score": 4,
"selected": false,
"text": "<input type=\"file\" name=\"upload[]\">\n"
}
] | 2008/11/09 | [
"https://Stackoverflow.com/questions/276400",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/11795/"
] |
276,433 | <p>With LINQ to SQL most likely going to not get as much active development as Entity Framework do you think it's best to switch to Entity Framework?</p>
<p>I've personally found EF to be very clunky and hard to use compared to LINQ to SQL which feels very natural.</p>
<p>EDIT: I recently posted an article on my blog about my feelings towards this potential decision...</p>
<p><a href="http://weblogs.asp.net/chadmoran/archive/2008/11/09/ado-net-v-linq-to-sql.aspx" rel="noreferrer">ADO.NET v LINQ to SQL</a></p>
| [
{
"answer_id": 506433,
"author": "LaserJesus",
"author_id": 45207,
"author_profile": "https://Stackoverflow.com/users/45207",
"pm_score": 3,
"selected": false,
"text": "foo.Foreign_TypeReference.EntityKey = \n new EntityKey(\"DataContextName.Foreign_Type\", \"Foreign_Type_Id\", Forei... | 2008/11/09 | [
"https://Stackoverflow.com/questions/276433",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/25416/"
] |
276,443 | <p>I'm developing a PHP website that uses url routing. I'd like the site to be directory independent, so that it could be moved from <a href="http://site.example.com/" rel="noreferrer">http://site.example.com/</a> to <a href="http://example.com/site/" rel="noreferrer">http://example.com/site/</a> without having to change every path in the HTML. The problem comes up when I'm linking to files which are not subject to routing, like css files, images and so on. </p>
<p>For example, let's assume that the view for the action <code>index</code> of the controller <code>welcome</code> contains the image <code>img/banner.jpg</code>. If the page is requested with the url <a href="http://site.example.com/welcome" rel="noreferrer">http://site.example.com/welcome</a>, the browser will request the image as <a href="http://site.example.com/img/banner.jpg" rel="noreferrer">http://site.example.com/img/banner.jpg</a>, which is perfectly fine. But if the page is requested with the url <a href="http://site.example.com/welcome/index" rel="noreferrer">http://site.example.com/welcome/index</a>, the browser will think that <code>welcome</code> is a directory and will try to fetch the image as <a href="http://site.example.com/welcome/img/banner.jpg" rel="noreferrer">http://site.example.com/welcome/img/banner.jpg</a>, which is obviously wrong.</p>
<p>I've already considered some options, but they all seem imperfect to me:</p>
<ul>
<li><p>Use url rewriting to redirect requests from (<strong>*.css</strong>|<strong>*.js</strong>|...) or (<strong>css/*</strong>|<strong>js/*</strong>|...) to the right path. </p>
<p><em>Problems</em>: Every extension would have to be named in the rewrite rules. If someone would add a new filetype (e.g. an mp3 file), it wouldn't be rewritten.</p></li>
<li><p>Prepend the base path to each relative path with a php function. For example:<br>
<code><img src="<?php echo url::base(); ?>img/banner.jpg" /></code> </p>
<p><em>Problems</em>: Looks messy; <strong>css</strong>- and <strong>js</strong>-files containing paths would have to be processed by PHP.</p></li>
</ul>
<p>So, how do you keep a website directory independent? Is there a better/cleaner way than the ones I came up with?</p>
| [
{
"answer_id": 276444,
"author": "Tom Haigh",
"author_id": 22224,
"author_profile": "https://Stackoverflow.com/users/22224",
"pm_score": 4,
"selected": true,
"text": "<base href=\"<?php echo url::base(); ?>\" /> \n"
},
{
"answer_id": 276583,
"author": "da5id",
"author_id"... | 2008/11/09 | [
"https://Stackoverflow.com/questions/276443",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/35951/"
] |
276,479 | <p>I saw a potential answer here but that was for YYYY-MM-DD: <a href="http://paulschreiber.com/blog/2007/03/02/javascript-date-validation/" rel="noreferrer">JavaScript date validation</a></p>
<p>I modified the code code above for MM-DD-YYYY like so but I still can't get it to work:</p>
<pre><code>String.prototype.isValidDate = function()
{
var IsoDateRe = new RegExp("^([0-9]{2})-([0-9]{2})-([0-9]{4})$");
var matches = IsoDateRe.exec(this);
if (!matches) return false;
var composedDate = new Date(matches[3], (matches[1] - 1), matches[2]);
return ((composedDate.getMonth() == (matches[1] - 1)) &&
(composedDate.getDate() == matches[2]) &&
(composedDate.getFullYear() == matches[3]));
}
</code></pre>
<p>How can I get the above code to work for MM-DD-YYYY and better yet MM/DD/YYYY?</p>
<p>Thanks.</p>
| [
{
"answer_id": 276488,
"author": "Kevin Gorski",
"author_id": 35806,
"author_profile": "https://Stackoverflow.com/users/35806",
"pm_score": 1,
"selected": false,
"text": "var matches = this.match(/^([0-9]{2})\\/([0-9]{2})\\/([0-9]{4})$/);\n"
},
{
"answer_id": 276497,
"author"... | 2008/11/09 | [
"https://Stackoverflow.com/questions/276479",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/3401/"
] |
276,489 | <p>We'll soon be embarking on the development of a new mobile application. This particular app will be used for heavy searching of text based fields. Any suggestions from the group at large for what sort of database engine is best suited to allowing these types of searches on a mobile platform?</p>
<p>Specifics include Windows Mobile 6 and we'll be using the .Net CF. Also some of the text based fields will be anywhere between 35 and 500 characters. The device will operate in two different methods, batch and WiFi. Of course for WiFi we can just submit requests to a full blown DB engine and just fetch results back. This question centres around the "batch" version which will house a database loaded with information on the devices flash/removable storage card.</p>
<p>At any rate, I know SQLCE has some basic indexing but you don't get into the real fancy "full text" style indexes until you've got the full blown version which of course isn't available on a mobile platform.</p>
<p>An example of what the data would look like:</p>
<p><em>"apron carpenter adjustable leather container pocket waist hardware belt"</em> etc. etc.</p>
<p>I haven't gotten into the evaluation of any other specific options yet as I figure I'd leverage the experience of this group in order to first point me down some specific avenues.</p>
<p>Any suggestions/tips?</p>
| [
{
"answer_id": 451671,
"author": "Jason Down",
"author_id": 9732,
"author_profile": "https://Stackoverflow.com/users/9732",
"pm_score": 4,
"selected": true,
"text": "public class SmallItem\n{\n private int _sku;\n public int Sku\n {\n get { return _sku; }\n set { _... | 2008/11/09 | [
"https://Stackoverflow.com/questions/276489",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/26853/"
] |
276,499 | <p>I have a custom UILabel subclass for displaying currency values. I only want the user to be able to enter digits and let the view format those digits into a currency value -- like a cash register. This makes UITextField an inappropriate choice for this kind of input.</p>
<p>I've already overridden hitTest: so that the UILabel will return itself -- this is apparently a bug. Also, I've overridden both canBecomeFirstResponder and becomeFirstResponder to return YES. Neither of these methods are being called, though.</p>
<p>I only want to let the user type numbers and use the backspace key. I've implemented UITextInputTraits, but the keyboard does not appear. So, can this be done? And does if so, what am I missing?</p>
| [
{
"answer_id": 451671,
"author": "Jason Down",
"author_id": 9732,
"author_profile": "https://Stackoverflow.com/users/9732",
"pm_score": 4,
"selected": true,
"text": "public class SmallItem\n{\n private int _sku;\n public int Sku\n {\n get { return _sku; }\n set { _... | 2008/11/09 | [
"https://Stackoverflow.com/questions/276499",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/35999/"
] |
276,512 | <p>I have seen some very weird <code>for</code> loops when reading other people's code. I have been trying to search for a full syntax explanation for the <code>for</code> loop in C but it is very hard because the word "for" appears in unrelated sentences making the search almost impossible to Google effectively.</p>
<p>This question came to my mind after reading <a href="https://stackoverflow.com/questions/260511/russian-peasant-multiplication">this thread</a> which made me curious again.</p>
<p>The <code>for</code> here: </p>
<pre><code>for(p=0;p+=(a&1)*b,a!=1;a>>=1,b<<=1);
</code></pre>
<p>In the middle condition there is a comma separating the two pieces of code, what does this comma do? The comma on the right side I understand as it makes both <code>a>>=1</code> and <code>b<<=1</code>. </p>
<p>But within a loop exit condition, what happens? Does it exit when <code>p==0</code>, when <code>a==1</code> or when both happen?</p>
<p>It would be great if anyone could help me understand this and maybe point me in the direction of a full <code>for</code> loop syntax description.</p>
| [
{
"answer_id": 276518,
"author": "Konrad Rudolph",
"author_id": 1968,
"author_profile": "https://Stackoverflow.com/users/1968",
"pm_score": 3,
"selected": false,
"text": "for"
},
{
"answer_id": 276519,
"author": "CesarB",
"author_id": 28258,
"author_profile": "https:/... | 2008/11/09 | [
"https://Stackoverflow.com/questions/276512",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/26004/"
] |
276,514 | <p>I am trying to install SQL server express 2008 on my machine. I get an error message that says that older version of VS 2008 in installed on the computer. Upgrade to VS2008 SP1 before installing Sql server 2008. </p>
<p>I tried to install sp1 but I get an error message that a compatible version of vs2008 is not detected on the system. the upgrade is not compatible with express editions. </p>
<p>I am having trouble installing sql server 2008 express installed on my machine and I am having problems. Please help me. </p>
| [
{
"answer_id": 2397422,
"author": "sergiopereira",
"author_id": 21420,
"author_profile": "https://Stackoverflow.com/users/21420",
"pm_score": 2,
"selected": false,
"text": "HKLM\\SOFTWARE\\Wow6432Node\\Microsoft\\DevDiv\\VS\\Servicing\\9.0\\IDE\\1033"
}
] | 2008/11/09 | [
"https://Stackoverflow.com/questions/276514",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/35948/"
] |
276,516 | <p>I need to build a function which parses the domain from a URL.</p>
<p>So, with</p>
<pre><code>http://google.com/dhasjkdas/sadsdds/sdda/sdads.html
</code></pre>
<p>or</p>
<pre><code>http://www.google.com/dhasjkdas/sadsdds/sdda/sdads.html
</code></pre>
<p>it should return <code>google.com</code></p>
<p>with</p>
<pre><code>http://google.co.uk/dhasjkdas/sadsdds/sdda/sdads.html
</code></pre>
<p>it should return <code>google.co.uk</code>.</p>
| [
{
"answer_id": 276525,
"author": "Owen",
"author_id": 4853,
"author_profile": "https://Stackoverflow.com/users/4853",
"pm_score": 10,
"selected": true,
"text": "parse_url()"
},
{
"answer_id": 1974047,
"author": "philfreo",
"author_id": 137067,
"author_profile": "https... | 2008/11/09 | [
"https://Stackoverflow.com/questions/276516",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/26823/"
] |
276,531 | <p>If I have the LINQ objects:</p>
<pre><code>public class SampleDataContext : DataContext {
public Table<Customer> Customers { get { return this.GetTable<Customer>(); } }
public SampleDataContext( string connectionString ) : base( connectionString ) { }
}
[Table( Name="dbo.tblCustomers" )]
public class Customer {
private Guid? customerID;
[Column( Storage="customerID", DbType="uniqueidentifier NOT NULL", IsPrimaryKey=true )]
public Guid? CustomerID {
get { return this.customerID; }
set { this.customerID = value; }
}
private string customerName;
[Column( Storage = "customerName", DbType = "nvarchar(255) NOT NULL" )]
public string CustomerName {
get { return this.customerName; }
set { this.customerName = value; }
}
}
</code></pre>
<p>and somewhere else in application:</p>
<pre><code>public static void DoSomethingWithCustomer( Customer customer ) {
// some operations
// now, I want save changes to the database
}
</code></pre>
<p>how can I get instance of DataContext which tracks changes of the "customer" object?</p>
<p><strong>Edit: Why I don't want pass the DataContext into method.</strong></p>
<p>1) Passing always 2 objects instead of 1 is "ugly" pattern for whole application.</p>
<ul>
<li>Methods will need next parameter for every business object.</li>
<li>Collection will needs changed from "List" to "List>".</li>
</ul>
<p>Both points will more hard to maintain - developer must every-time sets the correct instance of DataContext (easy to create a bug), despite the DataContext know that the concrete object is(or not) attached to another DataContext.</p>
<p>2) I want (current version of application use it) process "any" business logic on collection of objects which came from different "places" ( floating windows by drag & drop for example ).</p>
<p>Currentyl we use custom typed DataSets, so informations about changes are in the data rows (DataRow = business object) and wasn't problem to get it, or create a clone and then save it into database.</p>
| [
{
"answer_id": 986109,
"author": "Mark",
"author_id": 64084,
"author_profile": "https://Stackoverflow.com/users/64084",
"pm_score": 4,
"selected": true,
"text": "Private Const StandardChangeTrackerName As String = \"System.Data.Linq.ChangeTracker+StandardChangeTracker\"\n\nPrivate _conte... | 2008/11/09 | [
"https://Stackoverflow.com/questions/276531",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/20382/"
] |
276,546 | <p>Let's say you have a text file like this one:
<a href="http://www.gutenberg.org/files/17921/17921-8.txt" rel="noreferrer">http://www.gutenberg.org/files/17921/17921-8.txt</a></p>
<p>Does anyone has a good algorithm, or open-source code, to extract words from a text file?
How to get all the words, while avoiding special characters, and keeping things like "it's", etc...</p>
<p>I'm working in Java.
Thanks</p>
| [
{
"answer_id": 276559,
"author": "Claudiu",
"author_id": 15055,
"author_profile": "https://Stackoverflow.com/users/15055",
"pm_score": 2,
"selected": false,
"text": "create words, a list of words, by splitting the input by whitespace\nfor every word, strip out whitespace and punctuation ... | 2008/11/09 | [
"https://Stackoverflow.com/questions/276546",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/25645/"
] |
276,555 | <p>I'm looking to implement something in Java along the lines of:</p>
<pre><code>class Foo{
private int lorem; //
private int ipsum;
public setAttribute(String attr, int val){
//sets attribute based on name
}
public static void main(String [] args){
Foo f = new Foo();
f.setAttribute("lorem",1);
f.setAttribute("ipsum",2);
}
public Foo(){}
}
</code></pre>
<p>...where a variable is set based on the variable name without the variable names hard-coded and without using any other data structures. Is this possible?</p>
| [
{
"answer_id": 276576,
"author": "C. K. Young",
"author_id": 13,
"author_profile": "https://Stackoverflow.com/users/13",
"pm_score": 6,
"selected": true,
"text": "setAttribute"
},
{
"answer_id": 276653,
"author": "Frank Krueger",
"author_id": 338,
"author_profile": "h... | 2008/11/09 | [
"https://Stackoverflow.com/questions/276555",
"https://Stackoverflow.com",
"https://Stackoverflow.com/users/25985/"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.