qid
int64
4
22.2M
question
stringlengths
18
48.3k
answers
list
date
stringlengths
10
10
metadata
list
319,262
<p>Let's say I have two existing tables, "dogs" and "cats":</p> <pre><code> dog_name | owner ---------+------ Sparky | Bob Rover | Bob Snoopy | Chuck Odie | Jon cat_name | owner ---------+------ Garfield | Jon Muffy | Sam Stupid | Bob </code></pre> <p>How do I write a query with this output?</p> <pre><code> owner | num_dogs | num_cats ------+----------+--------- Bob | 2 | 1 Chuck | 1 | 0 Sam | 0 | 1 Jon | 1 | 1 </code></pre>
[ { "answer_id": 319268, "author": "Andru Luvisi", "author_id": 5922, "author_profile": "https://Stackoverflow.com/users/5922", "pm_score": 5, "selected": true, "text": "select owner, sum(num_dogs), sum(num_cats) from\n (select owner, 1 as num_dogs, 0 as num_cats from dogs\n union\n s...
2008/11/25
[ "https://Stackoverflow.com/questions/319262", "https://Stackoverflow.com", "https://Stackoverflow.com/users/91385/" ]
319,267
<p>I can not figure out what all the parameters to the arc() function are (by experimentation) and I have not found any tutorial that seems to explain them. Where would a good explanation of the arc() function be?</p>
[ { "answer_id": 319286, "author": "strager", "author_id": 39992, "author_profile": "https://Stackoverflow.com/users/39992", "pm_score": 2, "selected": false, "text": "arc(x, y, radius, startAngle, endAngle, anticlockwise)\n" }, { "answer_id": 319432, "author": "Sparr", "au...
2008/11/25
[ "https://Stackoverflow.com/questions/319267", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10608/" ]
319,279
<p>What's the best way to validate that an IP entered by the user is valid? It comes in as a string.</p>
[ { "answer_id": 319291, "author": "chills42", "author_id": 23855, "author_profile": "https://Stackoverflow.com/users/23855", "pm_score": 3, "selected": false, "text": "def validIP(address):\n parts = address.split(\".\")\n if len(parts) != 4:\n return False\n for item in p...
2008/11/25
[ "https://Stackoverflow.com/questions/319279", "https://Stackoverflow.com", "https://Stackoverflow.com/users/27729/" ]
319,292
<p>I have a vector with 1000 "nodes"</p> <pre><code> if(count + 1 &gt; m_listItems.capacity()) m_listItems.reserve(count + 100); </code></pre> <p>The problem is I also clear it out when I'm about to refill it. </p> <pre><code>m_listItems.clear(); </code></pre> <p>The capacity doesn't change. I've used the resize(1); but that doesn't seem to alter the capacity. So how does one change the reserve?</p>
[ { "answer_id": 319301, "author": "Tim Stewart", "author_id": 26002, "author_profile": "https://Stackoverflow.com/users/26002", "pm_score": 1, "selected": false, "text": "std::vector< int > v;\n// ... fill v with stuff...\nstd::vector< int >().swap( v );\n" }, { "answer_id": 31930...
2008/11/25
[ "https://Stackoverflow.com/questions/319292", "https://Stackoverflow.com", "https://Stackoverflow.com/users/31325/" ]
319,294
<p>when releasing an instance that could exist or not, I usually write this:</p> <p>if (object != nil) [object release];</p> <p>but since sending a message to nil is not a problem, is that conditional necessary?</p> <p>I suppose the question comes down to this: which uses more overhead, comparing an object to nil, or sending nil a message?</p>
[ { "answer_id": 322582, "author": "Matt Gallagher", "author_id": 36103, "author_profile": "https://Stackoverflow.com/users/36103", "pm_score": 3, "selected": false, "text": "nil" }, { "answer_id": 322596, "author": "Kornel", "author_id": 27009, "author_profile": "https...
2008/11/25
[ "https://Stackoverflow.com/questions/319294", "https://Stackoverflow.com", "https://Stackoverflow.com/users/36182/" ]
319,304
<p>So I added an EXE to my project's solution. The EXE does some stuff and outputs data via stdout. I want to capture the output, but more importantly how do I execute that EXE within my program?</p>
[ { "answer_id": 319311, "author": "Marc Gravell", "author_id": 23354, "author_profile": "https://Stackoverflow.com/users/23354", "pm_score": 2, "selected": false, "text": "Process.Start" }, { "answer_id": 319312, "author": "Alan", "author_id": 37843, "author_profile": ...
2008/11/25
[ "https://Stackoverflow.com/questions/319304", "https://Stackoverflow.com", "https://Stackoverflow.com/users/40856/" ]
319,305
<p>I love stretching my terminal on unix. What is the history or reason behind windows lame command line?</p>
[ { "answer_id": 375505, "author": "jmucchiello", "author_id": 44065, "author_profile": "https://Stackoverflow.com/users/44065", "pm_score": 7, "selected": false, "text": "mode <cols>,<lines>\nmode 80,25\nmode 120,50\netc.\n" }, { "answer_id": 1065833, "author": "Sasha Chedygov...
2008/11/25
[ "https://Stackoverflow.com/questions/319305", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4491/" ]
319,320
<p>I'm a little lost (still working with Ron Jeffries's book). Here's a simple class:</p> <pre><code>public class Model{ private String[] lines; public void myMethod(){ String[] newLines = new String[lines.length + 2]; for (i = 0, i &lt;= lines.length, i++) { newLines[i] = lines[i]; } } } </code></pre> <p>I have another class that initializes <code>Model</code>, and an empty array, by setting <code>myModel = new String[0]</code>. When I invoke <code>myModel.myMethod()</code>, I get a subscript out of range error. Looking at the debugger, what I see is that <code>myModel.lines</code> has zero dimensions and zero length. Shouldn't it have a dimension and length of 1? Granted the value of <code>lines[0]</code> is <code>null</code>, but the array itself shouldn't be, should it? </p> <p>Any thoughts truly appreciated. </p> <p>Randy</p>
[ { "answer_id": 319327, "author": "FerranB", "author_id": 40441, "author_profile": "https://Stackoverflow.com/users/40441", "pm_score": 1, "selected": false, "text": "null" }, { "answer_id": 319345, "author": "Paul Sonier", "author_id": 28053, "author_profile": "https:...
2008/11/26
[ "https://Stackoverflow.com/questions/319320", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16851/" ]
319,328
<p>I am asking this question from an educational/hacking point of view, (I wouldn't really want to code like this).</p> <p>Is it possible to implement a while loop only using <strong>C</strong> preprocessor directives. I understand that macros cannot be expanded recursively, so how would this be accomplished?</p>
[ { "answer_id": 8665535, "author": "Vlad", "author_id": 1120747, "author_profile": "https://Stackoverflow.com/users/1120747", "pm_score": 3, "selected": false, "text": "#ifdef pad_always\n\n#define pad(p,f) p##0\n\n#else\n\n#define pad0(p,not_used) p\n#define pad1(p,not_used) p##0\n\n#def...
2008/11/26
[ "https://Stackoverflow.com/questions/319328", "https://Stackoverflow.com", "https://Stackoverflow.com/users/27653/" ]
319,334
<p>On Windows XP when a process crashes, we get a dialog box with a link:</p> <p>"To view technical information about the error report, click here."</p> <p>The "click here" link brings up a whole lot of information in a window, but no obvious way to save it to a file. Is there a way? It would be very nice to be able to send that data to several different external vendors we're working with.</p> <p>The only other option I see in the dialog box is to send it to Microsoft, but this crash is likely not Microsoft's fault and there is no reason to send it to them.</p>
[ { "answer_id": 8665535, "author": "Vlad", "author_id": 1120747, "author_profile": "https://Stackoverflow.com/users/1120747", "pm_score": 3, "selected": false, "text": "#ifdef pad_always\n\n#define pad(p,f) p##0\n\n#else\n\n#define pad0(p,not_used) p\n#define pad1(p,not_used) p##0\n\n#def...
2008/11/26
[ "https://Stackoverflow.com/questions/319334", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4761/" ]
319,339
<p>I can start with my own .NET dll. I have a dll I use in all my web projects (around 10) and I have util classes for FTP, zip, imageresizing, extensionmethods and a generic singleton class.</p> <p>I think it is a common practice and I just thought it would be interesting to hear what people put in their 'Utils' dlls</p> <p>EDIT: What small code gems do you have that have made you much more productive with lesser code?</p> <p>These extension methods are pretty useful for me when parsing nullable form input before putting into the database</p> <pre><code> public static int? ToInt(this string input) { int val; if (int.TryParse(input, out val)) return val; return null; } public static DateTime? ToDate(this string input) { DateTime val; if (DateTime.TryParse(input, out val)) return val; return null; } public static decimal? ToDecimal(this string input) { decimal val; if (decimal.TryParse(input, out val)) return val; return null; } </code></pre>
[ { "answer_id": 319360, "author": "bugmagnet", "author_id": 426, "author_profile": "https://Stackoverflow.com/users/426", "pm_score": 1, "selected": false, "text": "(Autogenerated by TLViewer, © Mark Pryor 2000-2003) \n\nLibrary: Std\n P:\\other\\StdLib\\StdLib.dll \n Description: S...
2008/11/26
[ "https://Stackoverflow.com/questions/319339", "https://Stackoverflow.com", "https://Stackoverflow.com/users/29519/" ]
319,343
<p>Here's a question for those of you with experience in larger projects and API/framework design.</p> <p>I am working on a framework that will be used by many other projects in the future, so I want to make it nice and extensible, but at the same time it needs to be simple and easy to understand.</p> <p>I know that a lot of people complain that the .NET framework contains too many sealed classes and private members. Should I avoid this criticism and open up all my classes with plenty of protected virtual members?</p> <p>Is it a good idea to make as many of my methods and properties <strong>protected virtual</strong> as possible? Under what situations would you avoid <strong>protected virtual</strong> and make members private.</p>
[ { "answer_id": 319361, "author": "FerranB", "author_id": 40441, "author_profile": "https://Stackoverflow.com/users/40441", "pm_score": 2, "selected": false, "text": "events" }, { "answer_id": 320181, "author": "Brian Rasmussen", "author_id": 38206, "author_profile": "...
2008/11/26
[ "https://Stackoverflow.com/questions/319343", "https://Stackoverflow.com", "https://Stackoverflow.com/users/21966/" ]
319,354
<p>I have a SQL Server database and I want to know what columns and types it has. I'd prefer to do this through a query rather than using a GUI like Enterprise Manager. Is there a way to do this?</p>
[ { "answer_id": 319366, "author": "Brannon", "author_id": 5745, "author_profile": "https://Stackoverflow.com/users/5745", "pm_score": 7, "selected": false, "text": "EXEC sp_help tablename\n" }, { "answer_id": 319368, "author": "Vincent Ramdhanie", "author_id": 27439, "...
2008/11/26
[ "https://Stackoverflow.com/questions/319354", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
319,367
<p>I have a problem with time<br> My server is in the USA and I'm in Denmark (Europa) and I would like to have my site show the time in my local time. How can I do that?</p> <p>I try this </p> <pre><code>Datetime localtime = DateTimeOffset.Now.ToOffset(new TimeSpan(1,0,0)).DateTime; </code></pre> <p>and it works, but it will only work when I'm in GMT+1 / UTC+1 and not when I'm in GMT+2 / UTC+2. Is there another way of doing this - a simpler way of doing it?</p>
[ { "answer_id": 319380, "author": "HitLikeAHammer", "author_id": 35165, "author_profile": "https://Stackoverflow.com/users/35165", "pm_score": 0, "selected": false, "text": "DateTime myTimeGMT = ServerTime.ToUniversalTime();\n" }, { "answer_id": 319398, "author": "Robert Pauls...
2008/11/26
[ "https://Stackoverflow.com/questions/319367", "https://Stackoverflow.com", "https://Stackoverflow.com/users/31296/" ]
319,384
<p>I have a column in my database (a flag) with type varchar(1) that is populated either Y or NULL (this is how it is, not in my control).</p> <p>In SQL Server, doing an ascending order by query, NULL is ordered at the top. Should this behaviour be consistent for Oracle and DB2? </p> <p>If, instead I have a COALESCE on the column to ensure it is not null in the query, am I likely to hit any performance issues (due to table scans and the like)?</p> <p><strong>EDIT</strong></p> <p>The query needs to be consistent over all 3 databases, otherwise I will have to handle it in code, hence my thinking of using the COALESCE function</p> <p><strong>EDIT</strong></p> <p>I chose Pax as the answer, as it dealt with both parts of the question and gave a helpful workaround, however, thanks to me.yahoo.com/a/P4tXrx for the link to <a href="http://en.wikipedia.org/wiki/Order_by_(SQL)" rel="nofollow noreferrer">here</a></p>
[ { "answer_id": 319390, "author": "FerranB", "author_id": 40441, "author_profile": "https://Stackoverflow.com/users/40441", "pm_score": 0, "selected": false, "text": "ORDER BY value NULLS FIRST \n" }, { "answer_id": 319418, "author": "paxdiablo", "author_id": 14860, "a...
2008/11/26
[ "https://Stackoverflow.com/questions/319384", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5302/" ]
319,393
<p>I am trying to create a control that implements the per-pixel alpha blend while painting a 32-bit bitmap.</p> <p>I extended a CWnd and use static control in the resource editor. I managed to paint the alpha channel correctly but still the static control keep painting the gray background.</p> <p>I overwrote the OnEraseBkgnd to prevent the control from painting the background but it didn't worked. I finally managed to do it by using WS_EX_TRANSPARENT.</p> <p>My problem now is that my control is placed over other control. The first time the dialog is painted all works fine...but if I click over the "parent" control (ie the one beneath my control) my control doesn't received the WM_PAINT message. So it is not painted anymore.</p> <p>If I minimize the aplication and maximized it again the controls are painted again.</p> <p>Please, can anybody give a hint? I am getting crazy with this control!!!</p> <p>Thanks. </p>
[ { "answer_id": 4454240, "author": "Alexander Stoyan", "author_id": 543837, "author_profile": "https://Stackoverflow.com/users/543837", "pm_score": 2, "selected": false, "text": "BEGIN_MESSAGE_MAP(CTransparentStatic, CStatic)\n ON_WM_ERASEBKGND()\n ON_WM_CTLCOLOR_REFLECT()\nEND_MESS...
2008/11/26
[ "https://Stackoverflow.com/questions/319393", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14053/" ]
319,395
<p>I have two questions:</p> <p>1) How can I make an array which points to objects of integers?</p> <pre><code>int* myName[5]; // is this correct? </code></pre> <p>2) If I want to return a pointer to an array, which points to objects (like (1)) how can I do this in a method? ie) I want to impliment the method:</p> <pre><code>int **getStuff() { // what goes here? return *(myName); // im pretty sure this is not correct } </code></pre> <p>Thanks for the help!</p>
[ { "answer_id": 319404, "author": "Johannes Schaub - litb", "author_id": 34509, "author_profile": "https://Stackoverflow.com/users/34509", "pm_score": 4, "selected": true, "text": "int * myName[5]; /* correct */\n" }, { "answer_id": 319405, "author": "Adam Rosenfield", "au...
2008/11/26
[ "https://Stackoverflow.com/questions/319395", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
319,401
<p>It would be really handy to be able to somehow say that certain properties in the generated entity classes should, for example, be decorated by (say) validation attributes (as well as Linq To SQL column attributes).</p> <p>Is it a T4 template someplace? Or are there other ways to skin the cat?</p>
[ { "answer_id": 319772, "author": "Marc Gravell", "author_id": 23354, "author_profile": "https://Stackoverflow.com/users/23354", "pm_score": 0, "selected": false, "text": "Foo" }, { "answer_id": 368255, "author": "Erwin", "author_id": 7236, "author_profile": "https://S...
2008/11/26
[ "https://Stackoverflow.com/questions/319401", "https://Stackoverflow.com", "https://Stackoverflow.com/users/20971/" ]
319,413
<p>I have a search form in an app I'm currently developing, and I would like for it to be the equivalent of <code>method="GET"</code>.</p> <p>Thus, when clicking the search button, the user goes to <code>search.aspx?q=the+query+he+entered</code></p> <p>The reason I want this is simply bookmarkable URLs, plus it feels cleaner to do it this way.</p> <p>I also don't want the viewstate hidden field value appended to the URL either.</p> <p>The best I could come up with for this is: </p> <ol> <li>Capture the server-side click event of the button and <code>Response.Redirect</code>.</li> <li>Attach a Javascript <code>onclick</code> handler to the button that fires a <code>window.location.replace</code>.</li> </ol> <p>Both feel quirky and sub-optimal... Can you think of a better approach?</p>
[ { "answer_id": 319645, "author": "tvanfosson", "author_id": 12950, "author_profile": "https://Stackoverflow.com/users/12950", "pm_score": 0, "selected": false, "text": " $(document).ready( function() {\n $('input[type=hidden]').remove();\n $('form').attr('method','get');\n });\n"...
2008/11/26
[ "https://Stackoverflow.com/questions/319413", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3314/" ]
319,422
<p>i'm generating controls dynamically on my asp.net page by xslt transformation from an xml file. i will need to reference these controls from code behind later. i would like to add these references to the list/hashtable/whatever during creation (in xslt file i suppose) so that i could reach them later and i have no idea how to do this. i will be absolutely grateful for any suggestions, agnieszka</p>
[ { "answer_id": 320164, "author": "Generic Error", "author_id": 40944, "author_profile": "https://Stackoverflow.com/users/40944", "pm_score": 3, "selected": true, "text": "protected void Page_Load(object sender, EventArgs e)\n{\n // Fetch your XML here and transform it. This string re...
2008/11/26
[ "https://Stackoverflow.com/questions/319422", "https://Stackoverflow.com", "https://Stackoverflow.com/users/40872/" ]
319,423
<p>I am new to mysqli, and trying to confirm that if I so something like the below, the errno will be set to the last error, if any, and not the error of the last query. </p> <p>Is this a decent practice or should I be checking for the error in between every query?</p> <p>Thanks! </p> <pre><code>$mysqli-&gt;autocommit(FALSE); $mysqli-&gt;query("INSERT INTO ....."); $mysqli-&gt;query("INSERT INTO ....."); $mysqli-&gt;query("INSERT INTO ....."); $mysqli-&gt;query("INSERT INTO ....."); $mysqli-&gt;query("INSERT INTO ....."); if ( 0==$mysqli-&gt;errno ) { $mysqli-&gt;commit(); } else { $mysqli-&gt;rollback(); // Handle error } </code></pre>
[ { "answer_id": 319436, "author": "Bill Karwin", "author_id": 20860, "author_profile": "https://Stackoverflow.com/users/20860", "pm_score": 2, "selected": false, "text": "$mysqli->query()" }, { "answer_id": 15491620, "author": "Community", "author_id": -1, "author_prof...
2008/11/26
[ "https://Stackoverflow.com/questions/319423", "https://Stackoverflow.com", "https://Stackoverflow.com/users/27580/" ]
319,426
<p>How can I compare strings in a case insensitive way in Python?</p> <p>I would like to encapsulate comparison of a regular strings to a repository string, using simple and Pythonic code. I also would like to have ability to look up values in a dict hashed by strings using regular python strings.</p>
[ { "answer_id": 319435, "author": "Harley Holcombe", "author_id": 1057, "author_profile": "https://Stackoverflow.com/users/1057", "pm_score": 11, "selected": true, "text": "string1 = 'Hello'\nstring2 = 'hello'\n\nif string1.lower() == string2.lower():\n print(\"The strings are the same...
2008/11/26
[ "https://Stackoverflow.com/questions/319426", "https://Stackoverflow.com", "https://Stackoverflow.com/users/52490/" ]
319,429
<p>I have a C# .NET application with which I've created a custom image display control. Each image display represents its own display context and draws the image using glDrawPixels (Yes I know it would be better to use textures, I plan to in the futures but this app is already too far along and my time is limited).</p> <p>I am now trying to have both images pan simultaneously. That is, when one image is moved down ten pixels, the second image moves down ten pixels. Like so:</p> <pre><code>imageOne.YPan -= 10; imageTwo.YPan -= 10; imageOne.Invalidate(); //This forces a redraw. imageTwo.Invalidate(); //This forces a redraw. </code></pre> <p>Alright so here is the problem I am having. Only one of the images displays is redrawing. If I place a pause in between the two Invalidate calls and make the pause duration at least 110 milliseconds both will redraw, but not simultaneously. So it looks as if the second image is always trying to catch up to the first. Plus, a 110 millisecond pause slows down the motion too much. </p> <p>I have tried placing the updating and invalidating of each image in its own thread but this did not help.</p> <p>At the beginning of drawing I make the appropriate context is current, and at the end I am calling swapbuffers(). I tried adding a glFinish to the end of the draw function, but there was no change. </p> <p>Could it be that its the graphics card that is the problem? I am stuck using an integrated gpu that only has openGL 1.4. </p> <p>Hopefully, I have provided enough detail that the answer to my problem can be found. </p>
[ { "answer_id": 319561, "author": "shoosh", "author_id": 9611, "author_profile": "https://Stackoverflow.com/users/9611", "pm_score": 1, "selected": false, "text": "glFinish()" }, { "answer_id": 5628707, "author": "Ben Voigt", "author_id": 103167, "author_profile": "htt...
2008/11/26
[ "https://Stackoverflow.com/questions/319429", "https://Stackoverflow.com", "https://Stackoverflow.com/users/55638/" ]
319,438
<p>I'm able to get cells to format as Dates, but I've been unable to get cells to format as currency... Anyone have an example of how to create a style to get this to work? My code below show the styles I'm creating... the styleDateFormat works like a champ while styleCurrencyFormat has no affect on the cell.</p> <pre><code>private HSSFWorkbook wb; private HSSFCellStyle styleDateFormat = null; private HSSFCellStyle styleCurrencyFormat = null; </code></pre> <p>......</p> <pre><code>public CouponicsReportBean(){ wb = new HSSFWorkbook(); InitializeFonts(); } public void InitializeFonts() { styleDateFormat = wb.createCellStyle(); styleDateFormat.setDataFormat(HSSFDataFormat.getBuiltinFormat("m/d/yy")); styleCurrencyFormat = wb.createCellStyle(); styleCurrencyFormat.setDataFormat(HSSFDataFormat.getBuiltinFormat("$#,##0.00")); } </code></pre>
[ { "answer_id": 319917, "author": "Dave K", "author_id": 19864, "author_profile": "https://Stackoverflow.com/users/19864", "pm_score": 7, "selected": true, "text": " styleCurrencyFormat.setDataFormat((short)8); //8 = \"($#,##0.00_);[Red]($#,##0.00)\"\n" }, { "answer_id": 990756...
2008/11/26
[ "https://Stackoverflow.com/questions/319438", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19864/" ]
319,443
<p>I'm not at all familiar with VB.NET or ASP. I need to create a simple page which makes a call to a remote web service. I used the wsdl utility which comes with the DotNet SDK to generate a service proxy and write it to a VB file. Unfortunately I have no idea how to reference this code in either my ASPX file or the code behind VB file so I can create an instance of the proxy.</p> <p>Edit: I should have qualified this by noting that I'm not using visual studio. I just coded up a .aspx with a .vb behind it and dropped it into an IIS location. Is there a way to do what you're suggesting outside of VS?</p>
[ { "answer_id": 319469, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 0, "selected": false, "text": "dim x as new xyz\nvar = x.methodname()\n" } ]
2008/11/26
[ "https://Stackoverflow.com/questions/319443", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14128/" ]
319,463
<p>Is there a way using the iPhone SDK to get the same results as an HTTP POST or GET methods? </p>
[ { "answer_id": 322573, "author": "Matt Gallagher", "author_id": 36103, "author_profile": "https://Stackoverflow.com/users/36103", "pm_score": 5, "selected": false, "text": "responseData" } ]
2008/11/26
[ "https://Stackoverflow.com/questions/319463", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
319,479
<p>Are there any libraries out there for Java that will accept two strings, and return a string with formatted output as per the *nix diff command?</p> <p>e.g. feed in </p> <pre><code>test 1,2,3,4 test 5,6,7,8 test 9,10,11,12 test 13,14,15,16 </code></pre> <p>and </p> <pre><code>test 1,2,3,4 test 5,6,7,8 test 9,10,11,12,13 test 13,14,15,16 </code></pre> <p>as input, and it would give you </p> <pre><code>test 1,2,3,4 test 1,2,3,4 test 5,6,7,8 test 5,6,7,8 test 9,10,11,12 | test 9,10,11,12,13 test 13,14,15,16 test 13,14,15,16 </code></pre> <p>Exactly the same as if I had passed the files to <code>diff -y expected actual</code></p> <p>I found <a href="https://stackoverflow.com/questions/132478/how-to-perform-string-diffs-in-java">this question</a>, and it gives some good advice on general libraries for giving you programmatic output, but I'm wanting the straight string results.</p> <p>I could call <code>diff</code> directly as a system call, but this particular app will be running on unix and windows and I can't be sure that the environment will actually have <code>diff</code> available.</p>
[ { "answer_id": 319857, "author": "madlep", "author_id": 14160, "author_profile": "https://Stackoverflow.com/users/14160", "pm_score": 4, "selected": true, "text": "public static String diffSideBySide(String fromStr, String toStr){\n // this is equivalent of running unix diff -y comman...
2008/11/26
[ "https://Stackoverflow.com/questions/319479", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14160/" ]
319,482
<p>I have a simple app that uses an SQL Express 2005 database. When the user closes the app, I want to give the option to back up the database by making a copy in another directory. However, when I try to do it, I get "The process cannot access the file '...\Pricing.MDF' because it is being used by another process." I closed the connection, disposed the connection, set it to nothing, and GC.Collect(), but it makes no difference. My connection string is "Data Source=.\SQLEXPRESS2005;AttachDbFilename=|DataDirectory|\Pricing.mdf;Integrated Security=True; User Instance=True" and I just keep using the same connection throughout. I didn't see where I could detach the database to counter the attach in the connection string.</p> <p>1 - How do I RELEASE the thing? 2 - Is there a better way than just copying the database? The app is for my husband only, so I will be able to handle it if he actually does need to restore from backup.</p> <p>Thanks!</p>
[ { "answer_id": 319686, "author": "Adam", "author_id": 13320, "author_profile": "https://Stackoverflow.com/users/13320", "pm_score": 3, "selected": true, "text": "BACKUP DATABASE [mydatabasename]\nTO DISK = N'C:\\Program Files\\Microsoft SQL Server\\MSSQL.1\\MSSQL\\Backup\\Scheduled Task...
2008/11/26
[ "https://Stackoverflow.com/questions/319482", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12897/" ]
319,506
<p>I've be working with a Java application run through the command-line. It deals with XML files, specially the dblp.xml database which has more than 400MB. </p> <p>I was using JVM 5 and my app needed sort of 600-700MB of memory to processe the dblp.xml. After updating to JVM 6, it starting needing more than 1gb of memory (something I don't have), although it runs a bit faster.</p> <p>I'm pretty sure of the memory consumption difference, because I've already tested both again and again in this same computer. Resulting in the same difference of memory consumption.</p> <p>I didn't set any special parameters, just -Xmx800M or -Xmx1000M. Running with Ubuntu Hardy Heron on a dual core 1.7ghz, with 1,5gb of memory Using only the top/ps commands to measure</p> <p>Any one have an idea why this occurs? I really wanted to use JVM 6, because in my production server it is the JVM in use, and I'm not quite able to change easily.</p> <p>Thanks</p>
[ { "answer_id": 320217, "author": "the.duckman", "author_id": 21368, "author_profile": "https://Stackoverflow.com/users/21368", "pm_score": 2, "selected": false, "text": "java -version\n" }, { "answer_id": 321957, "author": "the.duckman", "author_id": 21368, "author_pr...
2008/11/26
[ "https://Stackoverflow.com/questions/319506", "https://Stackoverflow.com", "https://Stackoverflow.com/users/40876/" ]
319,508
<p>I want to get the VB.NET or VB code to access the hard disk serial no when starting the program. It's to help me to protect my own software from people who try to pirate copies. </p>
[ { "answer_id": 319655, "author": "Jon B", "author_id": 27414, "author_profile": "https://Stackoverflow.com/users/27414", "pm_score": 3, "selected": false, "text": "string driveLetter = Environment.SystemDirectory.Substring(0, 2);\nstring sn = new System.Management.ManagementObject(\"Win3...
2008/11/26
[ "https://Stackoverflow.com/questions/319508", "https://Stackoverflow.com", "https://Stackoverflow.com/users/40875/" ]
319,516
<p>I'm developing an FTP-like program to download a large number of small files onto an Xbox 360 devkit (which uses Winsock), and porting it to Playstation3 (also a devkit, and uses linux AFAIK). The program uses BSD-style sockets (TCP). Both of the programs communicate with the same server, downloading the same data. The program iterates through all the files in a loop like this:</p> <pre>for each file send(retrieve command) send(filename) receive(response) test response receive(size) receive(data) </pre> <p>On the Xbox 360 implementation, the whole download takes 1:27, and the time between the last send and first receive takes about 14 seconds. This seems quite reasonable to me.</p> <p>The Playstation3 implementation takes 4:01 for the same data. The bottleneck seems to be between the last send and first receive, which takes up 3:43 of that time. The network and disk times are both significantly less than the Xbox 360.</p> <p>Both these devkits are on the same switch as my PC, which does the file serving, and there is no other traffic on said switch.</p> <p>I've tried setting the <code>TCP_NODELAY</code> flag, which didn't change things significantly. I've also tried setting the <code>SO_SNDBUF</code>/<code>SO_RCVBUF</code> to 625KB, which also didn't significantly affect the time.</p> <p>I'm assuming that the difference lies between the TCP/IP stack implementations between Winsock and linux; is there some socket option that I could set to make the linux implementation behave more like Winsock? Is there something else I'm not accounting for?</p> <p>The only solution looks to be to rewrite it so that it sends all the file requests together, then receives them all.</p> <p>Unfortunately, Sony's implementation does not have the TCP_CORK option, so I cannot say if that is the difference.</p>
[ { "answer_id": 319550, "author": "geocar", "author_id": 37507, "author_profile": "https://Stackoverflow.com/users/37507", "pm_score": 2, "selected": false, "text": "TCP_CORK" } ]
2008/11/26
[ "https://Stackoverflow.com/questions/319516", "https://Stackoverflow.com", "https://Stackoverflow.com/users/40877/" ]
319,518
<p>I've got the a SQL Server stored procedure with the following T-SQL code contained within:</p> <pre><code>insert into #results ([ID], [Action], [Success], [StartTime], [EndTime], [Process]) select 'ID' = aa.[ActionID], 'Action' = cast(aa.[Action] as int), 'Success' = aa.[Success], 'StartTime' = aa.[StartTime], 'EndTime' = aa.[EndTime], 'Process' = cast(aa.[Process] as int) from [ApplicationActions] aa with(nolock) where 0 = case when (@loggingLevel = 0) then 0 when (@loggingLevel = 1 and aa.[LoggingLevel] = 1) then 0 end and 1 = case when (@applicationID is null) then 1 when (@applicationID is not null and aa.[ApplicationID] = @applicationID) then 1 end and 2 = case when (@startDate is null) then 2 when (@startDate is not null and aa.[StartTime] &gt;= @startDate) then 2 end and 3 = case when (@endDate is null) then 3 when (@endDate is not null and aa.[StartTime] &lt;= @endDate) then 3 end and 4 = case when (@success is null) then 4 when (@success is not null and aa.[Success] = @success) then 4 end and 5 = case when (@process is null) then 5 when (@process is not null and aa.[Process] = @process) then 5 end </code></pre> <p>It's that "dynamic" WHERE clause that is bothering me. The user doesn't have to pass in every parameter to this stored procedure. Just the ones that they are interested in using as a filter for the output.</p> <p>How would I go about using SQL Server Studio or Profiler to test whether or not this store procedure is recompiling every time?</p>
[ { "answer_id": 319558, "author": "Cade Roux", "author_id": 18255, "author_profile": "https://Stackoverflow.com/users/18255", "pm_score": 2, "selected": false, "text": " 2 = case\n when (@startDate is null) then 2\n when (@startDate is not null and...
2008/11/26
[ "https://Stackoverflow.com/questions/319518", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2049/" ]
319,524
<p>I'm looking to generate a random number and issue it to a table in a database for a particular user_id. The catch is, the same number can't be used twice. There's a million ways to do this, but I'm hoping someone very keen on algorithms has a clever way of solving the problem in an elegant solution in that the following criteria is met:</p> <p>1) The least amount of queries to the database are made. 2) The least amount of crawling through a data structure in memory is made.</p> <p>Essentially the idea is to do the following</p> <p>1) Create a random number from 0 to 9999999<br> 2) Check the database to see if the number exists<br> OR<br> 2) Query the database for all numbers<br> 3) See if the returned result matches whatever came from the db<br> 4) If it matches, repeat step 1, if not, problem is solved. </p> <p>Thanks.</p>
[ { "answer_id": 319547, "author": "UnkwnTech", "author_id": 115, "author_profile": "https://Stackoverflow.com/users/115", "pm_score": 1, "selected": false, "text": "<?php\n//Lets assume we already have a connection to the db\n$sql = \"SELECT randField FROM tableName\";\n$result = mysql_qu...
2008/11/26
[ "https://Stackoverflow.com/questions/319524", "https://Stackoverflow.com", "https://Stackoverflow.com/users/40882/" ]
319,527
<p>I have config.time_zone in environment.rb set to "UTC", and my mySQL server returns the current time in my local time zone when I issue "select now();" and in utc when I ask for "select utc_timestamp;"</p> <p>I'm running rails 2.1.2, the mysql gem 2.7.3, activerecord gem 2.1.2, and mysql --version returns "Ver 14.12 Distrib 5.0.27 for Win32 (ia32)". </p> <p>EDIT: My environment.rb is set to UTC and had been since I started the project. A server restart would have picked up no changes.</p> <pre><code>record = Record.find(:first) puts Time.now # Tue Nov 25 17:40:48 -0800 2008 record.time_column = Time.now record.save mysql&gt; select * from records; --------------------- 2008-11-26 01:40:48 #note that this is the same time, in UTC. record = Record.find(:first) puts record.time_column Wed Nov 26 01:40:48 -0800 2008 #NOTE that this is eight hours in advance! #All I've done is store a date in the database and retrieve it again! </code></pre> <p>Any ideas what causes this?</p>
[ { "answer_id": 320263, "author": "Laurent Farcy", "author_id": 40666, "author_profile": "https://Stackoverflow.com/users/40666", "pm_score": 4, "selected": true, "text": "(\"time = %t\", Tue Nov 25 17:40:48 -0800 2008) => \"time = '2008-11-26 01:40:48'\n" } ]
2008/11/26
[ "https://Stackoverflow.com/questions/319527", "https://Stackoverflow.com", "https://Stackoverflow.com/users/30997/" ]
319,530
<p>What does RESTful Authentication mean and how does it work? I can't find a good overview on Google. My only understanding is that you pass the session key (remeberal) in the URL, but this could be horribly wrong.</p>
[ { "answer_id": 7158864, "author": "Arnaud Bouchez", "author_id": 458259, "author_profile": "https://Stackoverflow.com/users/458259", "pm_score": 10, "selected": true, "text": "GET /spec.html HTTP/1.1\nHost: www.example.org\nAuthorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==\n" } ]
2008/11/26
[ "https://Stackoverflow.com/questions/319530", "https://Stackoverflow.com", "https://Stackoverflow.com/users/35338/" ]
319,531
<p>For example, I hate typing things like:</p> <pre><code>$x = mysql_escape_string(stripslashes($_GET['x'])); </code></pre> <p>Is there a way to alias those two functions in init.php or something without writing a separate function that takes one argument and returns that argument with those functions applied to it?</p> <p>My C/C++ is not very good, but I think this is sort of like #typedef but for functions?</p>
[ { "answer_id": 319536, "author": "Bill Karwin", "author_id": 20860, "author_profile": "https://Stackoverflow.com/users/20860", "pm_score": 2, "selected": false, "text": "function myget($string)\n{\n return mysql_real_escape_string(stripslashes($_GET[$string]));\n}\n" }, { "answe...
2008/11/26
[ "https://Stackoverflow.com/questions/319531", "https://Stackoverflow.com", "https://Stackoverflow.com/users/29595/" ]
319,552
<p>I am working on setting up a Drupal based website and wanted to replace the site title in the header with an image file. I came across this article: <a href="http://www.mezzoblue.com/tests/revised-image-replacement/" rel="nofollow noreferrer">"Revised Image Replacement"</a> summarizing several techniques for doing just that.</p> <p>I was wondering what the current best practice is, in terms of SEO and browser compatibility?</p>
[ { "answer_id": 319536, "author": "Bill Karwin", "author_id": 20860, "author_profile": "https://Stackoverflow.com/users/20860", "pm_score": 2, "selected": false, "text": "function myget($string)\n{\n return mysql_real_escape_string(stripslashes($_GET[$string]));\n}\n" }, { "answe...
2008/11/26
[ "https://Stackoverflow.com/questions/319552", "https://Stackoverflow.com", "https://Stackoverflow.com/users/40332/" ]
319,576
<p>I'm trying to make a TCP Client program in C where the client will start up, connect to a server. Then it will send a little information and then just listen to what it receives and react accordingly.</p> <p>The part that I'm having trouble with is the continuous listening. Here is what I have</p> <pre><code>... while (1) { numbytes = recv(sockfd, buf, MAXDATASIZE-1, 0); buf[numbytes] = '\0'; printf("Received: %s\n", buf); // more code to react goes here } ... </code></pre> <p>Upon connecting to the server, after sending two lines of data, the server should receive a good bit of information, but when I run this, it prints:</p> <blockquote> <p>Received:</p> </blockquote> <p>And then continues to just sit there until i force it to close.</p> <p>** EDIT ** when i do what Jonathan told me to do, I get the following:</p> <blockquote> <p>Count: -1, Error: 111, Received:</p> </blockquote> <p>So that means its erroring, but what do i do about it?</p>
[ { "answer_id": 319584, "author": "Jonathan Leffler", "author_id": 15168, "author_profile": "https://Stackoverflow.com/users/15168", "pm_score": 3, "selected": true, "text": "while (1) {\n numbytes = recv(sockfd, buf, MAXDATASIZE-1, 0);\n buf[numbytes] = '\\0';\n printf(\"Count: ...
2008/11/26
[ "https://Stackoverflow.com/questions/319576", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2128/" ]
319,578
<p>I have an app that I'm writing a little wizard for. It automated a small part of the app by moving the mouse to appropriate buttons, menus and clicking them so the user can watch.</p> <p>So far it moves the mouse to a tree item and sends a right-click. That pops up a menu via TrackPopupMenu. Next I move the mouse to the appropriate item on the popup menu. What I can't figure out is how to select the menu item.</p> <p>I've tried sending left-clicks to the menu's owner window, tried sending WM_COMMAND to the menu's owner, etc. Nothing works.</p> <p>I suppose the menu is a window in and of itself, but I don't know how to get the HWND for it from the HMENU that I have.</p> <p>Any thoughts on how to PostMessage a click to the popup menu?</p> <p>PS I'm using a separate thread to drive the mouse and post messages, so no problems with TrackPopupMenu being synchronous.</p>
[ { "answer_id": 319640, "author": "Rob Kennedy", "author_id": 33732, "author_profile": "https://Stackoverflow.com/users/33732", "pm_score": 1, "selected": false, "text": "SendInput" }, { "answer_id": 326608, "author": "DougN", "author_id": 7442, "author_profile": "http...
2008/11/26
[ "https://Stackoverflow.com/questions/319578", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7442/" ]
319,587
<p>When using Html.ActionLink passing a string containing the # char renders it like it is but if you UrlEncode it renders as %2523.</p> <p>I believe it's a bug. MVC Beta Release.</p> <p>Is it really a bug?</p> <p><a href="http://example.com/test#" rel="nofollow noreferrer">http://example.com/test#</a> is rendered as </p> <p><a href="http://example.com/test%2523" rel="nofollow noreferrer">http://example.com/test%2523</a> instead of </p> <p><a href="http://example.com/test%2523" rel="nofollow noreferrer">http://example.com/test%2523</a></p>
[ { "answer_id": 319614, "author": "Turnkey", "author_id": 13144, "author_profile": "https://Stackoverflow.com/users/13144", "pm_score": 1, "selected": false, "text": "using System;\nusing System.Collections.Generic;\nusing System.Text;\nusing System.Web;\n\nnamespace ConsoleApplication1\n...
2008/11/26
[ "https://Stackoverflow.com/questions/319587", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
319,591
<p>With .net 3.5, there is a SyndicationFeed that will load in a RSS feed and allow you to run LINQ on it. </p> <p>Here is an example of the RSS that I am loading:</p> <pre><code>&lt;rss version="2.0" xmlns:media="http://search.yahoo.com/mrss/"&gt; &lt;channel&gt; &lt;title&gt;Title of RSS feed&lt;/title&gt; &lt;link&gt;http://www.google.com&lt;/link&gt; &lt;description&gt;Details about the feed&lt;/description&gt; &lt;pubDate&gt;Mon, 24 Nov 08 21:44:21 -0500&lt;/pubDate&gt; &lt;language&gt;en&lt;/language&gt; &lt;item&gt; &lt;title&gt;Article 1&lt;/title&gt; &lt;description&gt;&lt;![CDATA[How to use StackOverflow.com]]&gt;&lt;/description&gt; &lt;link&gt;http://youtube.com/?v=y6_-cLWwEU0&lt;/link&gt; &lt;media:player url="http://youtube.com/?v=y6_-cLWwEU0" /&gt; &lt;media:thumbnail url="http://img.youtube.com/vi/y6_-cLWwEU0/default.jpg" width="120" height="90" /&gt; &lt;media:title&gt;Jared on StackOverflow&lt;/media:title&gt; &lt;media:category label="Tags"&gt;tag1, tag2&lt;/media:category&gt; &lt;media:credit&gt;Jared&lt;/media:credit&gt; &lt;enclosure url="http://youtube.com/v/y6_-cLWwEU0.swf" length="233" type="application/x-shockwave-flash"/&gt; &lt;/item&gt; &lt;/channel&gt; </code></pre> <p>When I loop through the items, I can get back the title and the link through the public properties of SyndicationItem.</p> <p>I can't seem to figure out how to get the attributes of the enclosure tag, or the values of the media tags. I tried using </p> <pre><code>SyndicationItem.ElementExtensions.ReadElementExtensions&lt;string&gt;("player", "http://search.yahoo.com/mrss/") </code></pre> <p>Any help with either of these?</p>
[ { "answer_id": 321548, "author": "jr.", "author_id": 2415, "author_profile": "https://Stackoverflow.com/users/2415", "pm_score": 4, "selected": true, "text": "string xml = @\"\n <rss version='2.0' xmlns:media='http://search.yahoo.com/mrss/'> \n <channel> \n <title>Title of R...
2008/11/26
[ "https://Stackoverflow.com/questions/319591", "https://Stackoverflow.com", "https://Stackoverflow.com/users/24841/" ]
319,594
<p>Given two colors and <em>n</em> steps, how can one calculate n colors including the two given colors that create a fade effect? </p> <p>If possible pseudo-code is preferred but this will probably be implemented in Java.</p> <p>Thanks!</p>
[ { "answer_id": 319604, "author": "nickf", "author_id": 9021, "author_profile": "https://Stackoverflow.com/users/9021", "pm_score": 5, "selected": true, "text": "oldRed = 120;\nnewRed = 200;\nsteps = 10;\nredStepAmount = (newRed - oldRed) / steps;\n\ncurrentRed = oldRed;\nfor (i = 0; i < ...
2008/11/26
[ "https://Stackoverflow.com/questions/319594", "https://Stackoverflow.com", "https://Stackoverflow.com/users/868/" ]
319,595
<p>Hi if I am creating something on the stack using new I declare it like:</p> <pre><code>object *myObject = new object(contr, params); </code></pre> <p>Is there a way to declare this such as:</p> <pre><code>object *myObject; myObject = new object(constr, params); </code></pre> <p>Is this correct?</p>
[ { "answer_id": 319602, "author": "SoapBox", "author_id": 36384, "author_profile": "https://Stackoverflow.com/users/36384", "pm_score": 3, "selected": false, "text": "object myObject(constr, params);\n" }, { "answer_id": 319603, "author": "JaredPar", "author_id": 23283, ...
2008/11/26
[ "https://Stackoverflow.com/questions/319595", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
319,623
<p>void (int a[]) { a[5] = 3; // this is wrong? }</p> <p>Can I do this so that the array that is passed in is modified?</p> <p>Sorry for deleting, a bit new here...</p> <p>I have another question which might answer my question:</p> <p>If I have</p> <pre><code>void Test(int a) { } void Best(int &amp;a) { } </code></pre> <p>are these two statements equivalent?</p> <pre><code>Test(a); Best(&amp;a); </code></pre>
[ { "answer_id": 319663, "author": "James Curran", "author_id": 12725, "author_profile": "https://Stackoverflow.com/users/12725", "pm_score": 5, "selected": true, "text": "void Test(int a[]) \n{\n a[5] = 3;\n}\n" }, { "answer_id": 319723, "author": "Jason Baker", "author...
2008/11/26
[ "https://Stackoverflow.com/questions/319623", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
319,626
<p>I have a DataTable that queries out something like below</p> <pre><code>usergroupid...userid......username 1.............1...........John 1.............2...........Lisa 2.............3...........Nathan 3.............4...........Tim </code></pre> <p>What I'm trying to do is write a LINQ statement that will return an array of UserGroup instances. The UserGroup class has properties of UserGroupId and Users. Users is an array of User instances. The User class then has properties of UserId and UserName.</p> <p>Can filling such a hierarchy be done with a single LINQ statement and what would it look like?</p> <p>Thanks a million</p>
[ { "answer_id": 319691, "author": "Rohan West", "author_id": 38686, "author_profile": "https://Stackoverflow.com/users/38686", "pm_score": 4, "selected": true, "text": "var users = new[] \n{\n new {UserGroupId = 1, UserId = 1, UserName = \"John\"},\n new {UserGroupId = 1, UserId = 2...
2008/11/26
[ "https://Stackoverflow.com/questions/319626", "https://Stackoverflow.com", "https://Stackoverflow.com/users/8280/" ]
319,634
<p>all files in ~/Cipher/nsdl/crypto can be found <a href="http://nsdeleon.wikispaces.com/file/detail/crypto.zip" rel="nofollow noreferrer">here</a> java files compiled with gcj, see compile.sh</p> <pre><code>nmint@nqmk-mint ~/Cipher/nsdl/crypto $ echo test | ./cryptTest encrypt deadbeefdeadbeefdeadbeefdeadbeef deadbeef Blowfish CBC &gt; test null Exception in thread "main" java.lang.IllegalStateException: cipher is not for encrypting or decrypting at javax.crypto.Cipher.update(libgcj.so.81) at javax.crypto.CipherOutputStream.write(libgcj.so.81) at nsdl.crypto.BlockCrypt.encrypt(cryptTest) at nsdl.crypto.cryptTest.main(cryptTest) </code></pre> <p>BlockCrypt.java: </p> <pre><code>package nsdl.crypto; import java.io.*; import java.security.spec.*; import javax.crypto.*; import javax.crypto.spec.*; public class BlockCrypt { Cipher ecipher; Cipher dcipher; byte[] keyBytes; byte[] ivBytes; SecretKey key; AlgorithmParameterSpec iv; byte[] buf = new byte[1024]; BlockCrypt(String keyStr, String ivStr, String algorithm, String mode) { try { ecipher = Cipher.getInstance(algorithm + "/" + mode + "/PKCS5Padding"); dcipher = Cipher.getInstance(algorithm + "/" + mode + "/PKCS5Padding"); keyBytes = hexStringToByteArray(keyStr); ivBytes = hexStringToByteArray(ivStr); key = new SecretKeySpec(keyBytes, algorithm); iv = new IvParameterSpec(ivBytes); ecipher.init(Cipher.ENCRYPT_MODE, key, iv); dcipher.init(Cipher.DECRYPT_MODE, key, iv); } catch (Exception e) { System.err.println(e.getMessage()); } } public void encrypt(InputStream in, OutputStream out) { try { // out: where the plaintext goes to become encrypted out = new CipherOutputStream(out, ecipher); // in: where the plaintext comes from int numRead = 0; while ((numRead = in.read(buf)) &gt;= 0) { out.write(buf, 0, numRead); } out.close(); } catch (IOException e) { System.err.println(e.getMessage()); } } public void decrypt(InputStream in, OutputStream out) { try { // in: where the plaintext come from, decrypted on-the-fly in = new CipherInputStream(in, dcipher); // out: where the plaintext goes int numRead = 0; while ((numRead = in.read(buf)) &gt;= 0) { out.write(buf, 0, numRead); } out.flush(); out.close(); } catch (IOException e) { System.err.println(e.getMessage()); } } public static byte[] hexStringToByteArray(String s) { int len = s.length(); byte[] data = new byte[len / 2]; for (int i = 0; i &lt; len; i += 2) { data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) &lt;&lt; 4) + Character.digit(s.charAt(i+1), 16)); } return data; } } </code></pre> <p>cryptTest.java: </p> <pre><code>package nsdl.crypto; import nsdl.crypto.BlockCrypt; public class cryptTest { public static void main (String args[]) { if (args.length != 5) { System.err.println("Usage: cryptTest (encrypt|decrypt) key iv algorithm mode"); System.err.println("Takes input from STDIN. Output goes to STDOUT."); } else { String operation = args[0]; String key = args[1]; String iv = args[2]; String algorithm = args[3]; String mode = args[4]; BlockCrypt blockCrypt = new BlockCrypt(key, iv, algorithm, mode); if (operation.equalsIgnoreCase("encrypt")) { blockCrypt.encrypt(System.in, System.out); } else if (operation.equalsIgnoreCase("decrypt")) { blockCrypt.decrypt(System.in, System.out); } else { System.err.println("Invalid operation. Use (encrypt|decrypt)."); } } } } </code></pre>
[ { "answer_id": 320032, "author": "erickson", "author_id": 3474, "author_profile": "https://Stackoverflow.com/users/3474", "pm_score": 3, "selected": true, "text": "ecipher" } ]
2008/11/26
[ "https://Stackoverflow.com/questions/319634", "https://Stackoverflow.com", "https://Stackoverflow.com/users/40807/" ]
319,649
<p>I have a database with one table, like so:</p> <pre><code>UserID (int), MovieID (int), Rating (real) </code></pre> <p>The userIDs and movieIDs are large numbers, but my database only has a sample of the many possible values (4000 unique users, and 3000 unique movies)</p> <p>I am going to do a matrix SVD (singular value decomposition) on it, so I want to return this database as an ordered array. Basically, I want to return each user in order, and for each user, return each movie in order, and then return the rating for that user, movie pair, or null if that user did not rate that particular movie. example:</p> <pre><code>USERID | MOVIEID | RATING ------------------------- 99835 8847874 4 99835 8994385 3 99835 9001934 null 99835 3235524 2 . . . 109834 8847874 null 109834 8994385 1 109834 9001934 null etc </code></pre> <p>This way, I can simply read these results into a two dimensional array, suitable for my SVD algorithm. (Any other suggestions for getting a database of info into a simple two dimensional array of floats would be appreciated)</p> <p>It is important that this be returned in order so that when I get my two dimensional array back, I will be able to re-map the values to the respective users and movies to do my analysis.</p>
[ { "answer_id": 319669, "author": "Jonathan Leffler", "author_id": 15168, "author_profile": "https://Stackoverflow.com/users/15168", "pm_score": 4, "selected": true, "text": "SELECT m.UserID, m.MovieID, r.Rating\n FROM (SELECT a.userid, b.movieid\n FROM (SELECT DISTINCT Us...
2008/11/26
[ "https://Stackoverflow.com/questions/319649", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2504/" ]
319,651
<p>I used standard exception handling methods in C++. Which is try{} and catch{} block. In my code, func1() would throw an exception, And func2 is like this:</p> <pre><code>bool func2() { try{ func1(); } catch(myException&amp; e) { cerr &lt;&lt; "error!" &lt;&lt; endl; return false; } return true; } </code></pre> <p>But when I run my code, a strange thing happens. I never reached the code of throwing the exception, but I always reached the line of return false in catch block (but the line of <code>cerr &lt;&lt;</code> is never reached either). Then the function continue to return true. I don't know what the reason is. Can anyone help me to figure the problem out? Thank you very much!</p>
[ { "answer_id": 320279, "author": "CesarB", "author_id": 28258, "author_profile": "https://Stackoverflow.com/users/28258", "pm_score": 2, "selected": false, "text": "bool func2()\n{\n bool ret;\n\n try{\n func1();\n ret = true;\n }\n\n catch(myException& e)\n {\...
2008/11/26
[ "https://Stackoverflow.com/questions/319651", "https://Stackoverflow.com", "https://Stackoverflow.com/users/26404/" ]
319,672
<p>I was using GetWindowLong like this:</p> <pre><code>[DllImport("user32.dll")] private static extern IntPtr GetWindowLong(IntPtr hWnd, int nIndex); </code></pre> <p>But according to the MSDN docs I am supposed to be using GetWindowLongPtr to be 64bit compatible. <a href="http://msdn.microsoft.com/en-us/library/ms633584(VS.85).aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/ms633584(VS.85).aspx</a></p> <p>The MSDN docs for GetWindowLongPtr say that I should define it like this (in C++):</p> <pre><code>LONG_PTR GetWindowLongPtr(HWND hWnd, int nIndex); </code></pre> <p>I used to be using IntPtr as the return type, but what the heck would I use for an equivalent for LONG_PTR? I have also seen GetWindowLong defined as this in C#:</p> <pre><code>[DllImport("user32.dll")] private static extern long GetWindowLong(IntPtr hWnd, int nIndex); </code></pre> <p>What is right, and how can I ensure proper 64bit compatibility?</p>
[ { "answer_id": 319693, "author": "SoapBox", "author_id": 36384, "author_profile": "https://Stackoverflow.com/users/36384", "pm_score": 3, "selected": false, "text": "[DllImport(\"user32.dll\")]\nprivate static extern IntPtr GetWindowLongPtr(IntPtr hWnd, int nIndex);\n" } ]
2008/11/26
[ "https://Stackoverflow.com/questions/319672", "https://Stackoverflow.com", "https://Stackoverflow.com/users/343/" ]
319,696
<p>This is probably pretty basic... but I don't seem to get it:</p> <p>How does </p> <pre><code>(2 &amp; 1) = 0 (3 &amp; 1) = 1 (4 &amp; 1) = 0 </code></pre> <p>etc..</p> <p>This pattern above seems to help find even numbers</p> <p>or </p> <pre><code>(0 | 1) = 1 (1 | 1) = 1 (2 | 1) = 3 (3 | 1) = 4 (4 | 1) = 5 (5 | 1) = 5 </code></pre> <p>I know how boolean algebra works between bits. But I don't understand how Boolean algebra works with integers (in C# at the least).</p> <p>thanks in advance.</p>
[ { "answer_id": 319698, "author": "SoapBox", "author_id": 36384, "author_profile": "https://Stackoverflow.com/users/36384", "pm_score": 3, "selected": false, "text": "2 | 1 = 3" }, { "answer_id": 319708, "author": "chromakode", "author_id": 40508, "author_profile": "ht...
2008/11/26
[ "https://Stackoverflow.com/questions/319696", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
319,702
<pre><code>public enum myEnum { VAL1(10), VAL2(20), VAL3("hai") { public Object getValue() { return this.strVal; } public String showMsg() { return "This is your msg!"; } }; String strVal; Integer intVal; public Object getValue() { return this.intVal; } private myEnum(int i) { this.intVal = new Integer(i); } private myEnum(String str) { this.strVal = str; } } </code></pre> <p>In the above enum what exactly happens when I add a constant specific class body for VAL3?<br><br> The type of VAL3 is definetly a subtype of myEnum as it has overloaded and additional methods. (the class type comes as 'myEnum$1' ) <br><br> But how can the compiler creates a subtype enum extending myEnum as all the enums are already extending java.lang.enum ? <br></p>
[ { "answer_id": 320152, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 0, "selected": false, "text": "\npackage com.sun.tools.xjc.outline;\n\n\npublic final class Aspect extends Enum\n{\n public static final Aspect EXPOSED;\n...
2008/11/26
[ "https://Stackoverflow.com/questions/319702", "https://Stackoverflow.com", "https://Stackoverflow.com/users/27784/" ]
319,711
<p>I posted a question earlier today when I'd not zeroed in quite so far on the problem. I'll be able to be more concise here.</p> <p>I'm running RoR 2.1.2, on Windows, with MySQL. The SQL server's native time zone is UTC. My local timezone is Pacific (-0800)</p> <p>I have a model with a :timestamp type column which I can do things like this with:</p> <pre><code>record = Record.find(:first) record.the_time = Time.now() </code></pre> <p>When I do a "select * from records" in the database, the time shown is eight hours in advance of my local time, which is correct, given that the DB is on UTC. (I have verified that it is 'thinking in utc' with a simple 'select now()' and 'select utc_timestamp()')</p> <p>This is where the trouble begins. If I display the time in a view:</p> <pre><code>&lt;%= h record.the_time %&gt; </code></pre> <p>...then I get back the correct time, displayed in UTC format. If I wrote to the database at 16:40:00 local time, the database showed 00:40:00.</p> <p>HOWEVER, if I am running a standalone script:</p> <pre><code>record = Record.find(:first) puts record.the_time </code></pre> <p>...then I get back the UTC time that I stored in the database (00:40:00,) but with the local timezone:</p> <pre><code>Wed Nov 26 00:40:00 (-0800) 2008 </code></pre> <p>...an eight-hour time warp. Why is it that storing the time translates it correctly, but retrieving it does not? If I compare a stored time from the recent past in the DB and compare it to the current time, the current time is less - telling me this isn't just a string conversion issue. </p> <p>Any ideas?</p>
[ { "answer_id": 328157, "author": "mrflip", "author_id": 41857, "author_profile": "https://Stackoverflow.com/users/41857", "pm_score": 1, "selected": false, "text": "# Make Time.zone default to the specified zone, and make Active Record store time values\n# in the database in UTC, and ret...
2008/11/26
[ "https://Stackoverflow.com/questions/319711", "https://Stackoverflow.com", "https://Stackoverflow.com/users/30997/" ]
319,716
<p>I'm working on a .Net application which uses Asp.net 3.5 and Lucene.Net I am showing search results given by Lucene.Net in an asp.net datagrid. I need to implement Paging (10 records on each page) for this aspx page.</p> <p>How do I get this done using Lucene.Net?</p>
[ { "answer_id": 319770, "author": "David Thibault", "author_id": 5903, "author_profile": "https://Stackoverflow.com/users/5903", "pm_score": 6, "selected": true, "text": "int first = 0, last = 9; // TODO: Set first and last to correct values according to page number and size\nSearcher sea...
2008/11/26
[ "https://Stackoverflow.com/questions/319716", "https://Stackoverflow.com", "https://Stackoverflow.com/users/40907/" ]
319,728
<p>Has anyone ever used the <a href="https://www.dofactory.com/net/bridge-design-pattern" rel="nofollow noreferrer">Bridge pattern</a> in a real world application? If so, how did you use it? Is it me, or is it just the <a href="https://www.dofactory.com/net/adapter-design-pattern" rel="nofollow noreferrer">Adapter pattern</a> with a little dependency injection thrown into the mix? Does it really deserve its own pattern?</p>
[ { "answer_id": 319792, "author": "Dima", "author_id": 13313, "author_profile": "https://Stackoverflow.com/users/13313", "pm_score": 3, "selected": false, "text": "class A\n{\npublic: \n void foo()\n {\n pImpl->foo();\n }\nprivate:\n Aimpl *pImpl;\n};\n\nclass Aimpl\n{\npublic:\n ...
2008/11/26
[ "https://Stackoverflow.com/questions/319728", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7705/" ]
319,730
<p>How can I escape a bracket in a full-text SQL Server <code>contains()</code> query? I've tried all the following, <em>none</em> of which work:</p> <pre><code>CONTAINS(crev.RawText, 'arg[0]') CONTAINS(crev.RawText, 'arg[[0]]') CONTAINS(crev.RawText, 'arg\[0\]') </code></pre> <p>Using double quotes does work, but it <strong>forces the entire search to be a phrase</strong>, which is a showstopper for multiple word queries. </p> <pre><code>CONTAINS(crev.RawText, '"arg[0]"') </code></pre> <p>All I really want to do is escape the bracket, but I can't seem to do that..</p>
[ { "answer_id": 319737, "author": "Cade Roux", "author_id": 18255, "author_profile": "https://Stackoverflow.com/users/18255", "pm_score": 2, "selected": false, "text": "LIKE" }, { "answer_id": 319795, "author": "arcanecode", "author_id": 40912, "author_profile": "https...
2008/11/26
[ "https://Stackoverflow.com/questions/319730", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1/" ]
319,732
<p>I have a .NET 2.0 server that seems to be running into scaling problems, probably due to poor design of the socket-handling code, and I am looking for guidance on how I might redesign it to improve performance.</p> <p><strong>Usage scenario:</strong> 50 - 150 clients, high rate (up to 100s / second) of small messages (10s of bytes each) to / from each client. Client connections are long-lived - typically hours. (The server is part of a trading system. The client messages are aggregated into groups to send to an exchange over a smaller number of 'outbound' socket connections, and acknowledgment messages are sent back to the clients as each group is processed by the exchange.) OS is Windows Server 2003, hardware is 2 x 4-core X5355. </p> <p><strong>Current client socket design:</strong> A <code>TcpListener</code> spawns a thread to read each client socket as clients connect. The threads block on <code>Socket.Receive</code>, parsing incoming messages and inserting them into a set of queues for processing by the core server logic. Acknowledgment messages are sent back out over the client sockets using async <code>Socket.BeginSend</code> calls from the threads that talk to the exchange side.</p> <p><strong>Observed problems:</strong> As the client count has grown (now 60-70), we have started to see intermittent delays of up to 100s of milliseconds while sending and receiving data to/from the clients. (We log timestamps for each acknowledgment message, and we can see occasional long gaps in the timestamp sequence for bunches of acks from the same group that normally go out in a few ms total.) </p> <p>Overall system CPU usage is low (&lt; 10%), there is plenty of free RAM, and the core logic and the outbound (exchange-facing) side are performing fine, so the problem seems to be isolated to the client-facing socket code. There is ample network bandwidth between the server and clients (gigabit LAN), and we have ruled out network or hardware-layer problems.</p> <p>Any suggestions or pointers to useful resources would be greatly appreciated. If anyone has any diagnostic or debugging tips for figuring out exactly what is going wrong, those would be great as well.</p> <p><em>Note: I have the MSDN Magazine article <a href="http://msdn2.microsoft.com/en-us/magazine/cc300760.aspx" rel="noreferrer">Winsock: Get Closer to the Wire with High-Performance Sockets in .NET</a>, and I have glanced at the Kodart "XF.Server" component - it looks sketchy at best.</em></p>
[ { "answer_id": 319806, "author": "Luke Quinane", "author_id": 18437, "author_profile": "https://Stackoverflow.com/users/18437", "pm_score": 2, "selected": false, "text": "Socket.BeginConnect" } ]
2008/11/26
[ "https://Stackoverflow.com/questions/319732", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3776/" ]
319,736
<p>I using GWT and have created a login form. I've tried all sorts of ways to get IE7 to prompt to remember the login info but with no success. I thought that maybe this would have worked (but it didn't):</p> <pre><code> TextBox submit = new TextBox(); submit.getElement().setAttribute("type", "submit"); </code></pre> <p>Any ideas?</p>
[ { "answer_id": 325772, "author": "Drejc", "author_id": 6482, "author_profile": "https://Stackoverflow.com/users/6482", "pm_score": 2, "selected": false, "text": "private TextBox mName = new TextBox();\nprivate PasswordTextBox mPassword = new PasswordTextBox();\n\nmName.setText(\"username...
2008/11/26
[ "https://Stackoverflow.com/questions/319736", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
319,741
<p>Here is pseudo-code of how I setup an array representing the MandelBrot set, yet it becomes horribly stretched when leaving an aspect ratio of 1:1.</p> <pre><code>xStep = (maxX - minX) / width; yStep = (maxY - minY) / height; for(i = 0; i &lt; width; i++) for(j = 0; j &lt; height; j++) { constantReal = minReal + xStep * i; constantImag = minImag + yStep * j; image[i][j] = inSet(constantReal, constantImag); } </code></pre> <p>Thanks!</p>
[ { "answer_id": 319750, "author": "Ned Batchelder", "author_id": 14343, "author_profile": "https://Stackoverflow.com/users/14343", "pm_score": 0, "selected": false, "text": "image" }, { "answer_id": 319818, "author": "Federico A. Ramponi", "author_id": 18770, "author_p...
2008/11/26
[ "https://Stackoverflow.com/questions/319741", "https://Stackoverflow.com", "https://Stackoverflow.com/users/868/" ]
319,748
<p>I have tried to use ASP.NET MVC for a while, then I face a problem that I don't want to include all of my js and css in master page. But how can I register it in head of master page from my specific view?</p>
[ { "answer_id": 322517, "author": "sliderhouserules", "author_id": 31385, "author_profile": "https://Stackoverflow.com/users/31385", "pm_score": 4, "selected": true, "text": "<head runat=\"server\">\n <title></title>\n <asp:ContentPlaceHolder ID=\"head\" runat=\"server\" />\n</head>...
2008/11/26
[ "https://Stackoverflow.com/questions/319748", "https://Stackoverflow.com", "https://Stackoverflow.com/users/35700/" ]
319,752
<p>We have a C# windows application that needs to be able to connect to a server on a network, download and save a file to a specified location. We can not use a web service as we can not assume that our clients will have IIS on their server. </p> <p>The way that I am considering doing it is to FTP onto the server and download the file. I can write the code to connect to the server and located the file but I have 2 questions. </p> <ol> <li><p>Is there a way of using the windows credentials to FTP on to the remote server? (I understand that I cannot directly get the user's password).</p></li> <li><p>Is there a better way of getting the file from a server other than ftp-ing on to it?</p></li> </ol> <p>Thanks for the advice. </p>
[ { "answer_id": 322517, "author": "sliderhouserules", "author_id": 31385, "author_profile": "https://Stackoverflow.com/users/31385", "pm_score": 4, "selected": true, "text": "<head runat=\"server\">\n <title></title>\n <asp:ContentPlaceHolder ID=\"head\" runat=\"server\" />\n</head>...
2008/11/26
[ "https://Stackoverflow.com/questions/319752", "https://Stackoverflow.com", "https://Stackoverflow.com/users/26300/" ]
319,762
<p>I am trying to use this in my page class. I only just started using objects in PHP so I'm still a little clueless (but learning as much as I can). This is in my <code>page()</code> function (so called when there is a new instance of page)</p> <pre><code>set_error_handler('$this-&gt;appendError'); </code></pre> <p>This is causing an error</p> <blockquote> <p>Warning: set_error_handler() expects the argument (appendError) to be a valid callback</p> </blockquote> <p>Now how do I set a class internal function whilst passing the function as a string. Is this not possible? Should I use a normal function which then calls the class function and sends through all arguments? This sounds a little cumbersome to me.</p> <p>Or have I missed the problem? I've tried making my appendError return a string, and echo.. but it still isn't playing nice.</p> <p>Any help would be greatly appreciated.</p> <p>Thank you!!</p>
[ { "answer_id": 319786, "author": "Paige Ruten", "author_id": 813, "author_profile": "https://Stackoverflow.com/users/813", "pm_score": 1, "selected": false, "text": "// Type 3: Object method call\n$obj = new MyClass();\ncall_user_func(array($obj, 'myCallbackMethod'));\n" } ]
2008/11/26
[ "https://Stackoverflow.com/questions/319762", "https://Stackoverflow.com", "https://Stackoverflow.com/users/31671/" ]
319,764
<p>I'm using (GNU) Make in my project. I'm currently putting one makefile per directory and specify the subdirectories using SUBDIRS. It's been suggested to me that this is not the ideal way of using make, that using a one toplevel make file (or several, split up using include). I've tried migrating/using this layout in the past, but it appears to me that it's unnecessary complicated.</p> <p>Which are the benefits/drawbacks of using recursive makefiles?</p>
[ { "answer_id": 320527, "author": "JesperE", "author_id": 13051, "author_profile": "https://Stackoverflow.com/users/13051", "pm_score": 6, "selected": true, "text": " main: CFLAGS=-O2\n lib: CFLAGS=-O2 -g\n" }, { "answer_id": 5893381, "author": "Kramer", "author_id": 12536...
2008/11/26
[ "https://Stackoverflow.com/questions/319764", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14337/" ]
319,765
<p>Is there any way other than using reflection to access the members of a anonymous inner class?</p>
[ { "answer_id": 319953, "author": "Ivan Dubrov", "author_id": 31118, "author_profile": "https://Stackoverflow.com/users/31118", "pm_score": 3, "selected": false, "text": "public class Test {\n public static void main(String... args) {\n class MyInner {\n private int v...
2008/11/26
[ "https://Stackoverflow.com/questions/319765", "https://Stackoverflow.com", "https://Stackoverflow.com/users/27784/" ]
319,788
<p>I am using Zend_Db to insert some data inside a transaction. My function starts a transaction and then calls another method that also attempts to start a transaction and of course fails(I am using MySQL5). So, the question is - how do I detect that transaction has already been started? Here is a sample bit of code:</p> <pre><code> try { Zend_Registry::get('database')-&gt;beginTransaction(); $totals = self::calculateTotals($Cart); $PaymentInstrument = new PaymentInstrument; $PaymentInstrument-&gt;create(); $PaymentInstrument-&gt;validate(); $PaymentInstrument-&gt;save(); Zend_Registry::get('database')-&gt;commit(); return true; } catch(Zend_Exception $e) { Bootstrap::$Log-&gt;err($e-&gt;getMessage()); Zend_Registry::get('database')-&gt;rollBack(); return false; } </code></pre> <p>Inside PaymentInstrument::create there is another beginTransaction statement that produces the exception that says that transaction has already been started. </p>
[ { "answer_id": 319844, "author": "Sean McSomething", "author_id": 39413, "author_profile": "https://Stackoverflow.com/users/39413", "pm_score": 2, "selected": false, "text": "SELECT @@autocommit" }, { "answer_id": 319939, "author": "Bill Karwin", "author_id": 20860, "...
2008/11/26
[ "https://Stackoverflow.com/questions/319788", "https://Stackoverflow.com", "https://Stackoverflow.com/users/35520/" ]
319,789
<p>Sorry if this is basic but I was trying to pick up on .Net 3.5.</p> <p>Question: Is there anything great about Func&lt;> and it's 5 overloads? From the looks of it, I can still create a similar delgate on my own say, MyFunc&lt;> with the exact 5 overloads and even more.</p> <p>eg: <code>public delegate TResult MyFunc&lt;TResult&gt;()</code> and a combo of various overloads...</p> <p>The thought came up as I was trying to understand Func&lt;> delegates and hit upon the following scenario:</p> <pre><code>Func&lt;int,int&gt; myDelegate = (y) =&gt; IsComposite(10); </code></pre> <p>This implies a delegate with one parameter of type int and a return type of type int. There are five variations (if you look at the overloads through intellisense). So I am guessing that we can have a delegate with no return type?</p> <p>So am I justified in saying that Func&lt;> is nothing great and just an example in the .Net framework that we can use and if needed, create custom "func&lt;>" delegates to suit our own needs?</p> <p>Thanks,</p>
[ { "answer_id": 319803, "author": "Mark Cidade", "author_id": 1659, "author_profile": "https://Stackoverflow.com/users/1659", "pm_score": 4, "selected": false, "text": "Func" }, { "answer_id": 319920, "author": "Jon Skeet", "author_id": 22656, "author_profile": "https:...
2008/11/26
[ "https://Stackoverflow.com/questions/319789", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
319,809
<p>escaping html is fine - it will remove <code>&lt;</code>'s and <code>&gt;</code>'s etc. </p> <p>ive run into a problem where i am outputting a filename inside a comment tag eg. <code>&lt;!-- ${filename} --&gt;</code></p> <p>of course things can be bad if you dont escape, so it becomes: <code>&lt;!-- &lt;c:out value="${filename}"/&gt; --&gt;</code></p> <p>the problem is that if the file has "--" in the name, all the html gets screwed, since youre not allowed to have <code>&lt;!-- -- --&gt;</code>. </p> <p>the standard html escape doesnt escape these dashes, and i was wondering if anyone is familiar with a simple / standard way to escape them. </p>
[ { "answer_id": 319830, "author": "Paige Ruten", "author_id": 813, "author_profile": "https://Stackoverflow.com/users/813", "pm_score": 0, "selected": false, "text": "[HYPHEN]" }, { "answer_id": 320753, "author": "bobince", "author_id": 18936, "author_profile": "https:...
2008/11/26
[ "https://Stackoverflow.com/questions/319809", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18582/" ]
319,811
<p>Does anyone have an example AUTORUN.INF which can launch an MSI installer automatically when the user inserts the CD.</p> <p>I'm sure this can be done but I've been Googling around for ages and have not found any working solution.</p> <p><strong>UPDATE:</strong> I have an AUTORUN.INF similar to this but it won't launch the installer:</p> <pre><code>[autorun] open=MyInstaller-1.0.0.msi label=My CD Label icon=MyIcon.ico </code></pre>
[ { "answer_id": 319837, "author": "Adam Pierce", "author_id": 5324, "author_profile": "https://Stackoverflow.com/users/5324", "pm_score": 1, "selected": false, "text": "[autorun]\nshellexecute=MyInstaller-1.0.0.msi\nlabel=My CD Label\nicon=MyIcon.ico\n" } ]
2008/11/26
[ "https://Stackoverflow.com/questions/319811", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5324/" ]
319,814
<p>Could someone please point me toward a cleaner method to generate a random enum member. This works but seems ugly.</p> <p>Thanks!</p> <pre><code>public T RandomEnum&lt;T&gt;() { string[] items = Enum.GetNames(typeof( T )); Random r = new Random(); string e = items[r.Next(0, items.Length - 1)]; return (T)Enum.Parse(typeof (T), e, true); } </code></pre>
[ { "answer_id": 319826, "author": "Mark Cidade", "author_id": 1659, "author_profile": "https://Stackoverflow.com/users/1659", "pm_score": 6, "selected": true, "text": "public T RandomEnum<T>()\n{ \n T[] values = (T[]) Enum.GetValues(typeof(T));\n return values[new Random().Next(0,values...
2008/11/26
[ "https://Stackoverflow.com/questions/319814", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10178/" ]
319,835
<p>Scott Gu just posted about a new set of charting controls being distributed by the .NET team. They look incredible: <a href="http://weblogs.asp.net/scottgu/archive/2008/11/24/new-asp-net-charting-control-lt-asp-chart-runat-quot-server-quot-gt.aspx" rel="noreferrer">http://weblogs.asp.net/scottgu/archive/2008/11/24/new-asp-net-charting-control-lt-asp-chart-runat-quot-server-quot-gt.aspx</a></p> <p>The million dollar question is ... will they work with MVC, and if so, when?</p>
[ { "answer_id": 320891, "author": "Simon Steele", "author_id": 4591, "author_profile": "https://Stackoverflow.com/users/4591", "pm_score": 8, "selected": true, "text": "Chart chart = new Chart();\nchart.BackColor = Color.Transparent;\nchart.Width = Unit.Pixel(250);\nchart.Height = Unit.Pi...
2008/11/26
[ "https://Stackoverflow.com/questions/319835", "https://Stackoverflow.com", "https://Stackoverflow.com/users/34133/" ]
319,847
<p>In a program to find whether the given number is an <a href="http://en.wikipedia.org/wiki/Narcissistic_number" rel="nofollow noreferrer">Armstrong</a> number, I stored the input no (3 digit) as string as follows.</p> <pre><code>char input[10]; scanf("%s",&amp;input); </code></pre> <p>Now I have to calculate cube of each digit by using pow method of math.h as follows.</p> <pre><code>int a; a = pow(input[0],3); </code></pre> <p>By coding like this, I could not get correct result. If I print the value of "a", it shows some irrelevant answer. My doubt is, how to convert from string value to integer value? </p>
[ { "answer_id": 319854, "author": "Paige Ruten", "author_id": 813, "author_profile": "https://Stackoverflow.com/users/813", "pm_score": 1, "selected": false, "text": "input" }, { "answer_id": 319856, "author": "Adam Pierce", "author_id": 5324, "author_profile": "https:...
2008/11/26
[ "https://Stackoverflow.com/questions/319847", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
319,873
<p>I have a table with some duplicate rows. I want to modify only the duplicate rows as follows.</p> <p>Before:</p> <pre><code>id col1 ------------ 1 vvvv 2 vvvv 3 vvvv </code></pre> <p>After:</p> <pre><code>id col1 ------------ 1 vvvv 2 vvvv-2 3 vvvv-3 </code></pre> <p>Col1 is appended with a hyphen and the value of <code>id</code> column.</p>
[ { "answer_id": 319928, "author": "Dheer", "author_id": 17266, "author_profile": "https://Stackoverflow.com/users/17266", "pm_score": 2, "selected": false, "text": "IN" }, { "answer_id": 320275, "author": "Berzerk", "author_id": 37599, "author_profile": "https://Stacko...
2008/11/26
[ "https://Stackoverflow.com/questions/319873", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
319,879
<p>I have two strings</p> <pre><code>&lt;EM&gt;is &lt;i&gt;love&lt;/i&gt;&lt;/EM&gt;,&lt;PARTITION /&gt; </code></pre> <p>and</p> <pre><code>&lt;EM&gt;is &lt;i&gt;love&lt;/i&gt;,&lt;PARTITION /&gt; </code></pre> <p>I want a regex to match the second string completely but should not match the first one. Please help.</p> <p>Note: Everything can change except the EM and PARTITION tags.</p>
[ { "answer_id": 319978, "author": "PhiLho", "author_id": 15459, "author_profile": "https://Stackoverflow.com/users/15459", "pm_score": 0, "selected": false, "text": "^<EM>(?:(?<!</EM>).)*<PARTITION />$\n" }, { "answer_id": 320235, "author": "Jan Goyvaerts", "author_id": 33...
2008/11/26
[ "https://Stackoverflow.com/questions/319879", "https://Stackoverflow.com", "https://Stackoverflow.com/users/40570/" ]
319,880
<p>Suppose <code>a</code> and <code>b</code> are both of type <code>int</code>, and <code>b</code> is nonzero. Consider the result of performing <code>a/b</code> in the following cases:</p> <ol> <li><code>a</code> and <code>b</code> are both nonnegative.</li> <li><code>a</code> and <code>b</code> are both negative.</li> <li>Exactly one of them is negative.</li> </ol> <p>In Case 1 the result is rounded down to the nearest integer. But what does the standard say about Cases 2 and 3? An old draft I found floating on the Internet indicates that it is implementation dependent (yes, even case 2) but the committee is leaning toward making it always 'round toward zero.' Does anyone know what the (latest) standard says? Please answer only based on the standard, not what makes sense, or what particular compilers do.</p>
[ { "answer_id": 8137586, "author": "Sjoerd", "author_id": 396551, "author_profile": "https://Stackoverflow.com/users/396551", "pm_score": 5, "selected": false, "text": "a%b" } ]
2008/11/26
[ "https://Stackoverflow.com/questions/319880", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
319,893
<p>I am using gravatar to load avatars for each user that posts a story on a page. I also am using jquery to round the corners of some span elements on the page. Unfortunately, it looks like grabbing the avatars from gravatar occurs before the jquery effects are applied (Without the gravatar code the elements are immediately rounded) so the elements change in appearance an instant after being visible on the site. Is there any way to work around this? (I am using asp.net mvc)</p>
[ { "answer_id": 15237259, "author": "Maksym Kozlenko", "author_id": 171847, "author_profile": "https://Stackoverflow.com/users/171847", "pm_score": 0, "selected": false, "text": " $(\"form\").on(\"submit\", function(e) {\n e.preventDefault();\n\n $.ajax(\"http://en.gravata...
2008/11/26
[ "https://Stackoverflow.com/questions/319893", "https://Stackoverflow.com", "https://Stackoverflow.com/users/15059/" ]
319,894
<p>Many of our customers have access to InstallShield, WISE or AdminStudio. These aren't a problem. I'm hoping there is some way I can provide our smaller customers <strong>without access to commercial repackaging tools</strong> a freely available set of tools and steps to do the file replacement themselves.</p> <p>Only need to replace a single configuration file inside a compressed MSI, the target user can be assumed to already have Orca installed, know how to use this to customize the Property table (to embed license details for GPO deployment) and have generated an MST file.</p> <p><br><br> <strong>Disclaimer</strong>: <em>this is very similar to <a href="https://stackoverflow.com/questions/126562/how-to-replace-a-file-in-a-msi-installer">another question</a> but both questions and answers in that thread are not clear.</em></p>
[ { "answer_id": 519092, "author": "saschabeaumont", "author_id": 592, "author_profile": "https://Stackoverflow.com/users/592", "pm_score": 4, "selected": true, "text": "Option Explicit\n\nConst MY_CONFIG = \"MyConfigApp.xml\"\nConst CAB_FILE = \"config.cab\"\nConst MSI = \"MyApp.msi\"\n\n...
2008/11/26
[ "https://Stackoverflow.com/questions/319894", "https://Stackoverflow.com", "https://Stackoverflow.com/users/592/" ]
319,896
<p>using jython</p> <p>I have a situation where emails come in with different attachments. Certain file types I process others I ignore and dont write to file. I am caught in a rather nasty situation, because sometimes people send an email as an attachment, and that attached email has legal attachments. </p> <p>What I want to do is skip that attached email and all its attachments.</p> <p>using python/jythons std email lib how can i do this?</p> <hr> <p>to make it clearer</p> <p>I need to parse an email (named ROOT email), I want to get the attachments from this email using jython. Next certain attachments are supported ie .pdf .doc etc now it just so happens that, the clients send an email (ROOT email) with another email message (CHILD email) as an attachment, and in CHILD email it has .pdf attachments and such like.</p> <p>What I need is: to get rid of any CHILD emails attached to the ROOT email AND the CHILD emails attachments. What happens is I walk over the whole email and it just parses every attachment, BOTH ROOT attachments and CHILD attachments as if they were ROOT attachments.</p> <p>I cannot have this. I am only interested in ROOT attachements that are legal ie .pdf .doc. xls .rtf .tif .tiff</p> <p>That should do for now, I have to run to catch a bus! thanks!</p>
[ { "answer_id": 320093, "author": "bortzmeyer", "author_id": 15625, "author_profile": "https://Stackoverflow.com/users/15625", "pm_score": 0, "selected": false, "text": "import email\n...\nmsg = email.message_from_file(fp)\n...\nfor part in msg.walk():\n # multipart/* are just containe...
2008/11/26
[ "https://Stackoverflow.com/questions/319896", "https://Stackoverflow.com", "https://Stackoverflow.com/users/21537/" ]
319,899
<p>Suppose I have a text file with data separated by whitespace into columns. I want to write a shell script which takes as input a filename and a number N and prints out only that column. With awk I can do the following:</p> <pre><code>awk &lt; /tmp/in '{print $2}' &gt; /tmp/out </code></pre> <p>This code prints out the second column. </p> <p>But how would one wrap that in a shell script so that a arbitrary column could be passed in argv?</p>
[ { "answer_id": 319914, "author": "strager", "author_id": 39992, "author_profile": "https://Stackoverflow.com/users/39992", "pm_score": 3, "selected": false, "text": "awk '{print $'$myvar'}' < /tmp/in > /tmp/out\n" } ]
2008/11/26
[ "https://Stackoverflow.com/questions/319899", "https://Stackoverflow.com", "https://Stackoverflow.com/users/39584/" ]
319,900
<p>I am going to spend 30 minutes teaching Perl to an experienced programmer. The best way to learn Perl is by writing code. In addition to CPAN, what would you show a programmer so they would understand the expressiveness of Perl, the amount of functionality provided by CPAN, while keeping everything clean and tidy so they walk away comfortable with the language? I'll save the tricky stuff for another day. </p> <pre> use warnings; use strict; # use A_CPAN_LIB; sub example_func1 { # use the CPAN lib or demonstrate some basic feature of Perl } example_func1(); # ... __END__ </pre> <p><hr> Here's what I came up with...<br></p> <h2>Where to Start</h2> <p>Believe it or not, the man pages. Ok, we'll just use perldoc instead to be Windows friendly.</p> <p>The perldoc pages (or man pages on Unix/Mac) are excellent for Perl. You can type man perl or perldoc perl</p> <p><strong>perldoc perl</strong>; # Show an overview and dozens of tutorials; man perl is the same.<br></p> <p><strong>perldoc perlintro</strong>; # A Perl intro for beginners; man perlintro<br> <strong>perldoc perlrequick</strong>; # An example Perl regex tutoral<br></p> <p><strong>perldoc perlfunc</strong>; # Shows builtin Perl functions<br> <strong>perldoc perlre</strong>; # More Perl regex.<br></p> <h2>CPAN</h2> <p>There are thousands of libraries on the Perl library site CPAN.<br> <strong>perl -MCPAN -e 'install DateTime'</strong><br></p> <p>perldoc works for installed modules too: perldoc module<br></p> <p><strong>perldoc DateTime</strong><br> <strong>perldoc DBI</strong>; # Database API. If this doesn't work then install it:<br> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<strong>perl -MCPAN -e 'install DBI'</strong></p> <h2>Recommended Modules</h2> <p><strong>perl -MCPAN -e 'install Moose'</strong>; # Perl does OOP<br> <strong>perldoc Moose</strong>; # Tell me more about the Moose<br> <strong>perl -MCPAN -e 'install CGI'</strong>; # Quick and dirty web pages<br> <strong>perl -MCPAN -e 'install Catalyst'</strong>; # Big web framework. Sometimes have problems installing. Google is your friend<br> <strong>perl -MCPAN -e 'install CGI::Application'</strong>; # Another web framework<br> <strong>perldoc CGI::Application</strong>; # Take a quick look at the docs<br> <br> A little Q&amp;A.<br> <br> Q: Why should I use Perl instead Ruby or Python?<br> A: More people use Perl. There are more libraries for Perl(way more). Perl is a really great GTD language.<br> <br> Q: Why do people hate Perl?<br> A: You can do some ugly stuff with it. Remember use warnings; use strict; in all of your code. You can check your code before running it. <strong>perl -c</strong> hello.pl<br></p> <p><br></p> <h2>Perl Topics</h2> <h3>Using Perl with Databases</h3> <p><a href="http://www.perl.com/pub/a/1999/10/DBI.html" rel="nofollow noreferrer"><a href="http://www.perl.com/pub/a/1999/10/DBI.html" rel="nofollow noreferrer">http://www.perl.com/pub/a/1999/10/DBI.html</a></a> <br></p> <h3>Using Perl for Web Development</h3> <p><a href="http://www.catalystframework.org" rel="nofollow noreferrer"><a href="http://www.catalystframework.org" rel="nofollow noreferrer">http://www.catalystframework.org</a></a> <br></p> <h3>OO Perl</h3> <p><a href="http://www.iinteractive.com/moose" rel="nofollow noreferrer"><a href="http://www.iinteractive.com/moose" rel="nofollow noreferrer">http://www.iinteractive.com/moose</a></a> <br></p> <h3>Perl 1-Liners</h3> <p><a href="http://www.perlmonks.org/?node_id=470397" rel="nofollow noreferrer"><a href="http://www.perlmonks.org/?node_id=470397" rel="nofollow noreferrer">http://www.perlmonks.org/?node_id=470397</a></a><br> <a href="http://sial.org/howto/perl/one-liner" rel="nofollow noreferrer"><a href="http://sial.org/howto/perl/one-liner" rel="nofollow noreferrer">http://sial.org/howto/perl/one-liner</a></a> <br></p> <h3>Other Tutorials</h3> <p><a href="http://perlmonks.org/index.pl?node=Tutorials" rel="nofollow noreferrer"><a href="http://perlmonks.org/index.pl?node=Tutorials" rel="nofollow noreferrer">http://perlmonks.org/index.pl?node=Tutorials</a></a></p> <h2>Books</h2> <p>There are dozens.<br> <a href="http://www.amazon.com/s/ref=nb_ss_gw?url=search-alias%3Dstripbooks&amp;field-keywords=perl&amp;x=0&amp;y=0" rel="nofollow noreferrer">http://www.amazon.com/s/ref=nb_ss_gw?url=search-alias%3Dstripbooks&amp;field-keywords=perl&amp;x=0&amp;y=0</a><br> <br></p> <h2>Websites</h2> <p><a href="http://perlmonks.com" rel="nofollow noreferrer">Perlmonks</a><br> <a href="http://www.perl.org" rel="nofollow noreferrer">Perl.org</a><br> <a href="http://pleac.sourceforge.net" rel="nofollow noreferrer">Pleac</a><br> <a href="https://stackoverflow.com/questions/161872/hidden-features-of-perl">StackOverFlow's Hidden Features of Perl</a><br> <a href="http://www.cpan.org/misc/cpan-faq.html" rel="nofollow noreferrer">CPAN FAQ</a><br> <a href="http://www.stonehenge.com/merlyn/LinuxMag" rel="nofollow noreferrer">Randall Schwartz's articles</a><br> <br> <br></p> <h2>Getting Help</h2> <p><a href="http://www.nabble.com/Perl-f13578.html" rel="nofollow noreferrer">Perl Nabble Forum</a><br> IRC Channels: freenode, irc.perl.org. There are several:<br> <br> irc://irc.perl.org/perl<br> irc://irc.perl.org/catalyst<br> irc://irc.freenode.net/modperl<br> irc://irc.perl.org/perl6<br></p>
[ { "answer_id": 319956, "author": "zoul", "author_id": 17279, "author_profile": "https://Stackoverflow.com/users/17279", "pm_score": 2, "selected": false, "text": "-d:DProf" }, { "answer_id": 321642, "author": "Brad Gilbert", "author_id": 1337, "author_profile": "https...
2008/11/26
[ "https://Stackoverflow.com/questions/319900", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
319,923
<p>I'm looking for a way to upload a file to s3. I am using django. I am currently using amazon's python library for uploading along with the following code: </p> <p>View:</p> <pre><code>def submitpicture(request): fuser = request.session["login"] copied_data = request.POST.copy() copied_data.update(request.FILES) content_type = copied_data['file'].get('content-type') ffile = copied_data['file']['content'] key = '%s-%s' % (fuser, ''.join(copied_data['file']['filename'].split(' '))) site_s3.save_s3_data(key, ffile, content_type) </code></pre> <p>Template:</p> <pre><code>&lt;form action="/submitpicture/" method="POST"&gt; &lt;input type="file" id="file" name="file" /&gt; &lt;input type="submit" value="submit" /&gt; &lt;/form&gt; </code></pre> <p>However, when I actually try to run it i get the following error:</p> <pre><code>"Key 'file' not found in &lt;QueryDict: {}&gt;" #MultiValueDictKeyError </code></pre> <p>I really don't see what I'm doing wrong. Can someone point me in the right direction?</p> <p>Edit: Just in case someone wonders, I am planning on adding some validation after I get the actual upload working. </p>
[ { "answer_id": 319943, "author": "ayaz", "author_id": 23191, "author_profile": "https://Stackoverflow.com/users/23191", "pm_score": 5, "selected": true, "text": "<form action=\"/submitpicture/\" method=\"POST\" enctype=\"multipart/form-data\" >\n" } ]
2008/11/26
[ "https://Stackoverflow.com/questions/319923", "https://Stackoverflow.com", "https://Stackoverflow.com/users/23695/" ]
319,925
<p>I am in the process of writing a text editor. After looking at other text editors I have noticed that a number of them refer to a "soft" versus "hard" wrap. What is the difference? I can't seem to find the answer by searching.</p>
[ { "answer_id": 319996, "author": "Will Robertson", "author_id": 4161, "author_profile": "https://Stackoverflow.com/users/4161", "pm_score": 4, "selected": false, "text": "diff" } ]
2008/11/26
[ "https://Stackoverflow.com/questions/319925", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18091/" ]
319,936
<p>How do I connect to the database(MYSQL) in connection bean using JSF to retrieve its contents. Also please let me know how do I configure the web.xml file?</p>
[ { "answer_id": 355514, "author": "Warrior", "author_id": 40933, "author_profile": "https://Stackoverflow.com/users/40933", "pm_score": 3, "selected": true, "text": "public void open() {\n try {\n String databaseName = \"custom\";\n String userName = \"root\";...
2008/11/26
[ "https://Stackoverflow.com/questions/319936", "https://Stackoverflow.com", "https://Stackoverflow.com/users/40933/" ]
319,950
<p>i want to create a number of databases in ms-access using a code or any option of ms-access, but i want delete databases also. Please help me</p>
[ { "answer_id": 320351, "author": "Berzerk", "author_id": 37599, "author_profile": "https://Stackoverflow.com/users/37599", "pm_score": 2, "selected": false, "text": " Set fso = CreateObject(\"scripting.filesystemobject\")\n fso.CopyFile \"c:\\db.mdb\", \"c:\\db_copy1.mdb\", True\n fso...
2008/11/26
[ "https://Stackoverflow.com/questions/319950", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
319,973
<p>I would like to use Linq to query a bus schedule in my project, so that at any time I can get the next 5 bus arrival times. How can I limit my query to the first 5 results?</p> <p>More generally, how can I take a slice of a list in C#? (In Python I would use <code>mylist[:5]</code> to get the first 5 elements.)</p>
[ { "answer_id": 319976, "author": "Matt Hamilton", "author_id": 615, "author_profile": "https://Stackoverflow.com/users/615", "pm_score": 11, "selected": true, "text": "var firstFiveItems = myList.Take(5);\n" }, { "answer_id": 320055, "author": "netadictos", "author_id": 3...
2008/11/26
[ "https://Stackoverflow.com/questions/319973", "https://Stackoverflow.com", "https://Stackoverflow.com/users/38146/" ]
319,993
<p>This is a <a href="https://stackoverflow.com/questions/319199/why-is-java-able-to-store-0xff000000-as-an-int">follow up question</a>. So, Java store's integers in <a href="http://en.wikipedia.org/wiki/Two%27s_complement" rel="nofollow noreferrer">two's-complements</a> and you can do the following:</p> <pre><code>int ALPHA_MASK = 0xff000000; </code></pre> <p>In C# this requires the use of an unsigned integer, <code>uint</code>, because it interprets this to be <code>4278190080</code> instead of <code>-16777216</code>.</p> <p>My question, how do declare negative values in hexadecimal notation in c#, and how exactly are integers represented internally? What are the differences to Java here?</p>
[ { "answer_id": 320000, "author": "Martin v. Löwis", "author_id": 33006, "author_profile": "https://Stackoverflow.com/users/33006", "pm_score": 6, "selected": true, "text": "int ALPHA_MASK = unchecked((int)0xFF000000);\n" }, { "answer_id": 320006, "author": "Marc Gravell", ...
2008/11/26
[ "https://Stackoverflow.com/questions/319993", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13466/" ]
320,001
<p>So I wrote buggy code that occasionally crash ... and creates a stackdump file.</p> <p>Using <a href="https://man7.org/linux/man-pages/man1/addr2line.1.html" rel="nofollow noreferrer">addr2line</a> I can figure out how the program got to the crash point by decoding the addresses from the stackdump one by one. Is there an alternative tool that can ease the debug using stack dumps? Is there a way to to load this information in Insight/Gdb?</p>
[ { "answer_id": 320029, "author": "BenB", "author_id": 11703, "author_profile": "https://Stackoverflow.com/users/11703", "pm_score": 0, "selected": false, "text": "gcc -g -o myfile myfile.c\n" }, { "answer_id": 415923, "author": "Gerhard", "author_id": 34989, "author_p...
2008/11/26
[ "https://Stackoverflow.com/questions/320001", "https://Stackoverflow.com", "https://Stackoverflow.com/users/34989/" ]
320,004
<p>Given a couple of simple tables like so:</p> <pre><code>create table R(foo text); create table S(bar text); </code></pre> <p>If I were to union them together in a query, what do I call the column?</p> <pre><code>select T.???? from ( select foo from R union select bar from S) as T; </code></pre> <p>Now, in mysql, I can apparently refer to the column of T as 'foo' -- the name of the matching column for the first relation in the union. In sqlite3, however, that doesn't seem to work. Is there a way to do it that's standard across all SQL implementations?</p> <p>If not, how about just for sqlite3?</p> <p>Correction: sqlite3 does allow you to refer to T's column as 'foo' after all! Oops!</p>
[ { "answer_id": 320018, "author": "Ali Ersöz", "author_id": 4215, "author_profile": "https://Stackoverflow.com/users/4215", "pm_score": 4, "selected": false, "text": "select T.Col1\nfrom (\n select foo as Col1\n from R\n union\n select bar as Col1\n from S) as T;\n" }, ...
2008/11/26
[ "https://Stackoverflow.com/questions/320004", "https://Stackoverflow.com", "https://Stackoverflow.com/users/22897/" ]
320,009
<p>In C++, I code this way:</p> <pre><code>//foo.h class cBar { void foobar(); } </code></pre> <hr> <pre><code>//foo.cpp void cBar::foobar() { //Code } </code></pre> <p>I tried to do this on PHP but the parser would complain. PHP's documentation also doesn't help. Can this be done in PHP?</p>
[ { "answer_id": 320024, "author": "Aron Rotteveel", "author_id": 11568, "author_profile": "https://Stackoverflow.com/users/11568", "pm_score": 1, "selected": false, "text": "abstract class cBar\n{\n // MUST be extended\n abstract protected function foobar();\n\n // MAY be extende...
2008/11/26
[ "https://Stackoverflow.com/questions/320009", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1599/" ]
320,028
<p>I cannot get a two-way bind in WPF to work. </p> <p>I have a string property in my app's main window that is bound to a TextBox (I set the mode to "TwoWay"). </p> <p>The only time that the value of the TextBox will update is when the window initializes. </p> <p>When I type into the TextBox, the underlying string properties value does not change. </p> <p>When the string property's value is changed by an external source (an event on Click, for example, that just resets the TextBox's value), the change doesn't propagate up to the TextBox.</p> <p>What are the steps that I must implement to get two-way binding to work properly in even this almost trivial example?</p>
[ { "answer_id": 320035, "author": "Gishu", "author_id": 1695, "author_profile": "https://Stackoverflow.com/users/1695", "pm_score": 7, "selected": true, "text": "<Window x:Class=\"DataBinding.MyWindow\" ...\n Title=\"MyWindow\" Height=\"300\" Width=\"300\">\n <StackPanel x:Name=\"To...
2008/11/26
[ "https://Stackoverflow.com/questions/320028", "https://Stackoverflow.com", "https://Stackoverflow.com/users/29119/" ]
320,045
<p>When programming a large transaction (lots of inserts, deletes, updates) and thereby violating a constraint in Informix (v10, but should apply to other versions too) I get a not very helpful message saying, for example, I violated constraint r190_710. How can I find out which table(s) and key(s) are covered by a certain constraint I know only the name of?</p>
[ { "answer_id": 337605, "author": "user39039", "author_id": 39039, "author_profile": "https://Stackoverflow.com/users/39039", "pm_score": 0, "selected": false, "text": "SELECT si.part1, si.part2, si.part3, si.part4, si.part5, \n si.part6, si.part7, si.part8, si.part9, si.part10, \n ...
2008/11/26
[ "https://Stackoverflow.com/questions/320045", "https://Stackoverflow.com", "https://Stackoverflow.com/users/39039/" ]
320,046
<p>This is intended to be a more concrete, easily expressable form of my earlier question.</p> <p>Take a list of words from a dictionary with common letter length.<br> How to reorder this list tto keep as many letters as possible common between adjacent words? </p> <p>Example 1:</p> <pre><code>AGNI, CIVA, DEVA, DEWA, KAMA, RAMA, SIVA, VAYU reorders to: AGNI, CIVA, SIVA, DEVA, DEWA, KAMA, RAMA, VAYU </code></pre> <p>Example 2:</p> <pre><code>DEVI, KALI, SHRI, VACH reorders to: DEVI, SHRI, KALI, VACH </code></pre> <p>The simplest algorithm seems to be: Pick anything, then search for the shortest distance?<br> However, DEVI->KALI (1 common) is equivalent to DEVI->SHRI (1 common)<br> Choosing the first match would result in fewer common pairs in the entire list (4 versus 5). </p> <p>This seems that it should be simpler than full TSP? </p>
[ { "answer_id": 320063, "author": "schnaader", "author_id": 34065, "author_profile": "https://Stackoverflow.com/users/34065", "pm_score": 0, "selected": false, "text": "Start with one of the words, call it w\nFindNext(w, l) // l = list of words without w\n Get a list l of the words near ...
2008/11/26
[ "https://Stackoverflow.com/questions/320046", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
320,052
<p>What is your preferred method of traversing a tree data structure, since recursive method calls can be pretty inefficient in some circumstances. I am simply using a generator like the one above. Do you have any hints to make it faster?</p> <pre><code>def children(self): stack = [self.entities] while stack: for e in stack.pop(): yield e if e.entities: stack.append(e.entities) </code></pre> <p>Here is some test data. The first one is recursive, the second uses the generator:</p> <pre><code>s = time.time() for i in range(100000): e.inc_counter() print time.time() - s s = time.time() for i in range(100000): for e in e.children(): e.inc_counter_s() print time.time() - s </code></pre> <p>Results:</p> <pre><code>0.416000127792 0.298999786377 </code></pre> <p>Test code:</p> <pre><code>import random class Entity(): def __init__(self, name): self.entities = [] self.name = name self.counter = 1 self.depth = 0 def add_entity(self, e): e.depth = self.depth + 1 self.entities.append(e) def inc_counter_r(self): for e in self.entities: e.counter += 1 e.inc_counter_r() def children(self): stack = [self.entities] while stack: for e in stack.pop(): yield e if e.entities: stack.append(e.entities) root = Entity("main") def fill_node(root, max_depth): if root.depth &lt;= max_depth: for i in range(random.randint(10, 15)): e = Entity("node_%s_%s" % (root.depth, i)) root.add_entity(e) fill_node(e, max_depth) fill_node(root, 3) import time s = time.time() for i in range(100): root.inc_counter_r() print "recursive:", time.time() - s s = time.time() for i in range(100): for e in root.children(): e.counter += 1 print "generator:", time.time() - s </code></pre>
[ { "answer_id": 320061, "author": "Aaron Digulla", "author_id": 34088, "author_profile": "https://Stackoverflow.com/users/34088", "pm_score": 2, "selected": false, "text": "def children(self):\n if self._children_cache is not None:\n return self._children_cache\n # Put your c...
2008/11/26
[ "https://Stackoverflow.com/questions/320052", "https://Stackoverflow.com", "https://Stackoverflow.com/users/40948/" ]
320,058
<p>Greetings,</p> <p>I've got a bat script which copies certain information from a computer onto a USB hard drive using Robocopy. The hard drive is FAT formatted and therefore doesn't support directories with extended attributes, leading me to robocopy error 282 <a href="http://forums.hexus.net/thecus-care-hexus/121981-n5200pro-error-mounted-file-system-does-not-support-extended-attributes.html" rel="nofollow noreferrer">as described here</a>.</p> <p>How do I tell robocopy to copy all the attribute information EXCEPT for the extendable attributes?</p> <p><strong>I still need help, but, some helpful info from the googling ive done thus far</strong></p> <ul> <li>Robocopy Command-Line Options: <a href="http://www.ss64.com/nt/robocopy.html" rel="nofollow noreferrer">http://www.ss64.com/nt/robocopy.html</a></li> <li>What is an Extended File Attribute: <a href="http://en.wikipedia.org/wiki/Extended_file_attributes" rel="nofollow noreferrer">http://en.wikipedia.org/wiki/Extended_file_attributes</a></li> <li>Windows Hotfix (which would be great if I wasn't copying to a USB hard drive): <a href="http://support.microsoft.com/kb/329145/en-us" rel="nofollow noreferrer">http://support.microsoft.com/kb/329145/en-us</a></li> </ul> <p><strong>EDIT:</strong> <em>Wow, the file system isn't FAT, I was wrong. Its RAW.</em></p>
[ { "answer_id": 6185871, "author": "jack", "author_id": 181699, "author_profile": "https://Stackoverflow.com/users/181699", "pm_score": 0, "selected": false, "text": "convert e: /fs:ntfs \n" } ]
2008/11/26
[ "https://Stackoverflow.com/questions/320058", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5021/" ]
320,078
<p>How do you add that little "X" button on the right side of a UITextField that clears the text? I can't find an attribute for adding this sub-control in Interface Builder in the iPhone OS 2.2 SDK.</p> <p><strong>Note:</strong> In Xcode 4.x and later (iPhone 3.0 SDK and later), you can do this in Interface Builder.</p>
[ { "answer_id": 320079, "author": "Kristopher Johnson", "author_id": 1175, "author_profile": "https://Stackoverflow.com/users/1175", "pm_score": 10, "selected": true, "text": "UITextField" }, { "answer_id": 18078048, "author": "Hossam Ghareeb", "author_id": 1752899, "a...
2008/11/26
[ "https://Stackoverflow.com/questions/320078", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1175/" ]
320,089
<p>My WPF application generates sets of data which may have a different number of columns each time. Included in the output is a description of each column that will be used to apply formatting. A simplified version of the output might be something like:</p> <pre><code>class Data { IList&lt;ColumnDescription&gt; ColumnDescriptions { get; set; } string[][] Rows { get; set; } } </code></pre> <p>This class is set as the DataContext on a WPF DataGrid but I actually create the columns programmatically:</p> <pre><code>for (int i = 0; i &lt; data.ColumnDescriptions.Count; i++) { dataGrid.Columns.Add(new DataGridTextColumn { Header = data.ColumnDescriptions[i].Name, Binding = new Binding(string.Format("[{0}]", i)) }); } </code></pre> <p>Is there any way to replace this code with data bindings in the XAML file instead?</p>
[ { "answer_id": 343447, "author": "Generic Error", "author_id": 40944, "author_profile": "https://Stackoverflow.com/users/40944", "pm_score": 4, "selected": false, "text": "public static void GenerateColumns(this DataGrid dataGrid, IEnumerable<ColumnSchema> columns)\n{\n dataGrid.Colum...
2008/11/26
[ "https://Stackoverflow.com/questions/320089", "https://Stackoverflow.com", "https://Stackoverflow.com/users/40944/" ]
320,096
<p>If there a way to protect against concurrent modifications of the same data base entry by two or more users?</p> <p>It would be acceptable to show an error message to the user performing the second commit/save operation, but data should not be silently overwritten.</p> <p>I think locking the entry is not an option, as a user might use the "Back" button or simply close his browser, leaving the lock for ever.</p>
[ { "answer_id": 320221, "author": "Guillaume", "author_id": 23704, "author_profile": "https://Stackoverflow.com/users/23704", "pm_score": 5, "selected": false, "text": "UPDATE ... WHERE version = 'version_from_user';\n" }, { "answer_id": 1874807, "author": "seanyboy", "aut...
2008/11/26
[ "https://Stackoverflow.com/questions/320096", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11527/" ]
320,103
<p>Using the Facebook API, is there a way of getting a friend's phone/cell number? I'm sure I saw an app a while ago that could sync Facebook with your Mac Address Book, but I haven't found anything in the API documentation that allows you to get a friend's number. Is this possible?</p> <p>Thanks in advance.</p>
[ { "answer_id": 320221, "author": "Guillaume", "author_id": 23704, "author_profile": "https://Stackoverflow.com/users/23704", "pm_score": 5, "selected": false, "text": "UPDATE ... WHERE version = 'version_from_user';\n" }, { "answer_id": 1874807, "author": "seanyboy", "aut...
2008/11/26
[ "https://Stackoverflow.com/questions/320103", "https://Stackoverflow.com", "https://Stackoverflow.com/users/21709/" ]
320,119
<p>I use the <kbd>Shift</kbd> + <kbd>F7</kbd> often to switch between source and design view.</p> <p>Does anyone know of a hotkey to switch between the <strong>source file</strong> and its <strong>code behind file</strong>, e.g. between (Default.aspx and Default.aspx.cs)?</p>
[ { "answer_id": 19097004, "author": "Eduardo Cuomo", "author_id": 717267, "author_profile": "https://Stackoverflow.com/users/717267", "pm_score": 7, "selected": false, "text": ">" }, { "answer_id": 20342984, "author": "James G", "author_id": 1196415, "author_profile": ...
2008/11/26
[ "https://Stackoverflow.com/questions/320119", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4639/" ]
320,124
<p>I want to debug an application in Linux. The application is created in C++. The GUI is created using QT. The GUI is linked with a static library that can be treated as the back end of the application.</p> <p>I want to debug the static library but am not sure how to do that.</p> <p>I tried using gdb</p> <pre><code>gdb GUI </code></pre> <p>But how can I attach the library?</p> <p>Has anyone had experience in debugging libraries in linux?</p>
[ { "answer_id": 320136, "author": "Johannes Schaub - litb", "author_id": 34509, "author_profile": "https://Stackoverflow.com/users/34509", "pm_score": 4, "selected": true, "text": "gdb ./foo\nrun\n" }, { "answer_id": 320257, "author": "Sam Stokes", "author_id": 20131, ...
2008/11/26
[ "https://Stackoverflow.com/questions/320124", "https://Stackoverflow.com", "https://Stackoverflow.com/users/33411/" ]
320,128
<p>This problem crops up every now and then at work. Our build machine can have it's files accessed via a normal windows file share. If someone browses a folder remotely on the machine, and leaves the window open overnight, then the build fails (as it has done now). The explorer window left opened points at one of the sub folders in the source tree. The build deletes the source, and does a clean checkout before building. The delete is failing.</p> <p>Right now, I'd like to get the build to work. I'm logged in from home, and I'd rather not reboot the build machine. I'm unable to get hold of the person whose machine is looking and the files, and I can't remotely reboot their machine.</p> <p>When a windows share has a lock, the locking process is System, so I don't think I can kill it, as with normal locks.</p> <p>Does anyone know a way to release the lock on a shared folder without having to reboot the machine?</p>
[ { "answer_id": 34425394, "author": "Charles Burns", "author_id": 161816, "author_profile": "https://Stackoverflow.com/users/161816", "pm_score": 3, "selected": false, "text": "Miscellaneous" }, { "answer_id": 44355260, "author": "Panuels", "author_id": 8110637, "autho...
2008/11/26
[ "https://Stackoverflow.com/questions/320128", "https://Stackoverflow.com", "https://Stackoverflow.com/users/28840/" ]
320,135
<p>I need to ensure that an application I am developing is accessable and also works with JavaScript turned off. I just need a pointer to assist with the following.</p> <p>I had 3 'chained' select boxes and I wanted JavaScript enabled clients to have a nice Ajax experience. I can easily write the required functionality to populate the chained boxes on the change event of the preceeding select using jQuery and JSON with a WCF service. However what about the non JavaScript client?</p> <p>Would I wrap a submit next to the select and place these inside their own form to post back with a certain action or different querstring parameter? Can the same controller give me a partial JSON response as well as feeding the full HTML response. Can anyone point me to a good demo that utilises both JSON and normal HTTP posts to produce the same result in ASP.NET MVC. All ASP.NET MVC demo/examples I see forget about the non JavaScript enabled client.</p> <p><strong>Update</strong></p> <p>But isn't that true for Ajax calls using the Microsoft Ajax client library if I read it corectly - which I am wanting to avoid and use only jQuery - apologies should have mentioned that.</p> <p>Also I would prefer not to put that noise everywhere in the controllers (reminds me of ispostback from webforms...shudder).</p> <p>It's a shame there is no attribute that I can use on a controller like with [AcceptVerbs(HttpVerbs.Post)] but for content types e.g [AcceptType(httpTypes.Json)].</p> <p>There must be a better way than using that if statement everywhere.....</p>
[ { "answer_id": 321473, "author": "rodbv", "author_id": 79101, "author_profile": "https://Stackoverflow.com/users/79101", "pm_score": 2, "selected": false, "text": "public ActionResult List()\n{\n if (!Request.IsMvcAjaxRequest())\n {\n // Non AJAX requests see the entire ViewPag...
2008/11/26
[ "https://Stackoverflow.com/questions/320135", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6440/" ]