qid
int64
4
22.2M
question
stringlengths
18
48.3k
answers
list
date
stringlengths
10
10
metadata
list
60,680
<p>I'm writing a small web server in Python, using BaseHTTPServer and a custom subclass of BaseHTTPServer.BaseHTTPRequestHandler. Is it possible to make this listen on more than one port?</p> <p>What I'm doing now:</p> <pre><code>class MyRequestHandler(BaseHTTPServer.BaseHTTPRequestHandler): def doGET [...] class ThreadingHTTPServer(ThreadingMixIn, HTTPServer): pass server = ThreadingHTTPServer(('localhost', 80), MyRequestHandler) server.serve_forever() </code></pre>
[ { "answer_id": 60753, "author": "Eli Courtwright", "author_id": 1694, "author_profile": "https://Stackoverflow.com/users/1694", "pm_score": 6, "selected": true, "text": "from threading import Thread\nfrom SocketServer import ThreadingMixIn\nfrom BaseHTTPServer import HTTPServer, BaseHTTP...
2008/09/13
[ "https://Stackoverflow.com/questions/60680", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4321/" ]
60,683
<p>Can you have a multicolumn listview control where one of the columns is a checkbox? Example code or links would be greatly appreciated.</p> <p>I am using visual studio 2005</p>
[ { "answer_id": 60695, "author": "Winter", "author_id": 6227, "author_profile": "https://Stackoverflow.com/users/6227", "pm_score": 4, "selected": true, "text": "\n GlacialList mylist = new GlacialList();\n\nmylist.Columns.Add( \"Column1\", 100 ); // this can also be added \n\n ...
2008/09/13
[ "https://Stackoverflow.com/questions/60683", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4653/" ]
60,684
<p><strong><em>Edit:</em></strong> This question had been tagged "Tolstoy" in appreciation of the quality and length of my writing:) Just reading the first and the last paragraph should be enough:) If you tend to select and move code with the mouse, the stuff in middle could be interesting to you.</p> <p>This question is about how you use text editors in general. I’m looking for the best way to <em>delete</em> a plurality of lines of code (no intent to patent it:) This extends to <em>transposing</em> lines, i.e. deleting and adding them somewhere else. Most importantly, I don’t want to be creating any blank lines that I have to delete separately. Sort of like Visual Studio's SHIFT+DELETE feature, but working for multiple lines at once.</p> <p>Say you want to delete line 3 from following code (tabs and newlines visualized as well). The naïve way would be to select the text between angle brackets:</p> <pre> if (true) {\n \t int i = 1;\n \t &lt;i *= 2;&gt;\n \t i += 3;\n }\n </pre> <p>Then hit backspace. This creates a blank line. Hit backspace twice more to delete \t and \n. </p> <p>You end up with:</p> <pre> if (true) {\n \t int i = 1;\n \t i += 3;\n }\n </pre> <p>When you try to select a whole line, Visual Studio doesn't let you select the trailing newline character. For example, placing the cursor on a line and hitting SHIFT+END will not select the newline at the end. Neither will you select the newline if you use your mouse, i.e. clicking in the middle of a line and dragging the cursor all the way to the right. You only select the trailing newline characters if you make a selection that spans at least two lines. Most editors I use do it this way; Microsoft WordPad and Word are counter-examples (and I frequently get newlines wrong when deleting text there; at least Word has a way to display end-of-line and end-of-paragraph characters explicitly).</p> <p>When using Visual Studio and other editors in general, here’s the solution that currently works best for me:</p> <p>Using the mouse, I select the characters that I put between angle brackets:</p> <pre> if (true) {\n \t int i = 1;&lt;\n \t i *= 2;&gt;\n \t i += 3;\n }\n </pre> <p>Hitting backspace now, you delete the line in one go without having to delete any other characters. This works for several contiguous lines at once. Additionally, it can be used for transposing lines. You could drag the selection between the angle brackets to the point marked with a caret:</p> <pre> if (true) {\n \t int i = 1;&lt;\n \t i *= 2;&gt;\n \t i += 3;^\n }\n </pre> <p>This leaves you with:</p> <pre> if (true) {\n \t int i = 1;\n \t i += 3;&lt;\n \t i *= 2;&gt;\n }\n </pre> <p>where lines 3 and 4 have switched place.</p> <p>There are variations on this theme. When you want to delete line 3, you could also select the following characters:</p> <pre> if (true) {\n \t int i = 1;\n &lt;\t i *= 2;\n &gt;\t i += 3;\n }\n </pre> <p>In fact, this is what Visual Studio does if you tell it to select a complete line. You do this by clicking in the margin between your code and the column where the red circles go which indicate breakpoints. The mouse pointer is mirrored in that area to distinguish it a little better, but I think it's too narrow and physically too far removed from the code I want to select.</p> <p>Maybe this method is useful to other people as well, even if it only serves to make them aware of how newlines are handled when selecting/deleting text:) It works nicely for most non-specialized text editors. However, given the vast amount of features and plugins for Visual Studio (which I use most), I'm sure there is better way to use it to delete and move lines of code. Getting the indentation right automatically when moving code between different blocks would be nice (i.e. without hitting "Format Document/Selection"). I'm looking forward to suggestions; no rants on micro-optimization, please:)</p> <hr> <p><strong><em>Summary of Answers</em></strong></p> <p>With respect to Visual Studio: Navigating well with the cursor keys.</p> <p>The solution that would best suit my style of going over and editing code is the <em>Eclipse</em> way:</p> <p>You can select several consecutive lines of code, where the first and the last selected line may be selected only partially. Pressing ALT+{up,down} moves the complete lines (not just the selection) up and down, fixing indentation as you go. Hitting CTRL+D deletes the lines completely (not just the selection) without leaving any unwanted blank lines. I would love to see this in Visual Studio!</p>
[ { "answer_id": 60697, "author": "jfs", "author_id": 4279, "author_profile": "https://Stackoverflow.com/users/4279", "pm_score": 2, "selected": false, "text": "kill-whole-line" }, { "answer_id": 60709, "author": "Nathan Fellman", "author_id": 1084, "author_profile": "h...
2008/09/13
[ "https://Stackoverflow.com/questions/60684", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6103/" ]
60,685
<p>What follows is a regular expression I have written to match multi-line pre-processor macros in C / C++ code. I'm by no means a regular expressions guru, so I'd welcome any advice on how I can make this better.</p> <p>Here's the regex:</p> <pre><code>\s*#define(.*\\\n)+[\S]+(?!\\) </code></pre> <p>It should match all of this:</p> <pre><code>#define foo(x) if(x) \ doSomething(x) </code></pre> <p>But only some of this (shouldn't match the next line of code:</p> <pre><code>#define foo(x) if(x) \ doSomething(x) normalCode(); </code></pre> <p>And also shouldn't match single-line preprocessor macros.</p> <p>I'm pretty sure that the regex above works - but as I said, there probably a better way of doing it, and I imagine that there are ways of breaking it. Can anyone suggest any?</p>
[ { "answer_id": 60723, "author": "Douglas Leeder", "author_id": 3978, "author_profile": "https://Stackoverflow.com/users/3978", "pm_score": 4, "selected": true, "text": "#!/usr/bin/env python\n\nTEST1=\"\"\"\n#include \"Foo.h\"\n#define bar foo\\\\\n x\n#include \"Bar.h\"\n\"\"\"\n\nTE...
2008/09/13
[ "https://Stackoverflow.com/questions/60685", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1304/" ]
60,720
<p>What is the best way for me to determine a controller variable's value during execution?</p> <p>For example, is there a way I can insert a break in the code, and cause the value of the variable to be output to the screen (or the log)?</p>
[ { "answer_id": 60731, "author": "Jordi Bunster", "author_id": 4272, "author_profile": "https://Stackoverflow.com/users/4272", "pm_score": 5, "selected": true, "text": "raise @foo.to_s" }, { "answer_id": 60732, "author": "John Topley", "author_id": 1450, "author_profil...
2008/09/13
[ "https://Stackoverflow.com/questions/60720", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3764/" ]
60,736
<p>I have a laptop running Ubuntu that I would like to act as a Subversion server. Both for myself to commit to locally, and for others remotely. What are the steps required to get this working? Please include steps to:</p> <ul> <li>Get and configure Apache, and necessary modules (I know there are other ways to create a SVN server, but I would like it Apache-specific)</li> <li>Configure a secure way of accessing the server (SSH/HTTPS)</li> <li>Configure a set of authorised users (as in, they must authorised to commit, but are free to browse)</li> <li>Validate the setup with an initial commit (a "Hello world" of sorts)</li> </ul> <p>These steps can involve any mixture of command line or GUI application instructions. If you can, please note where instructions are specific to a particular distribution or version, and where a users' choice of a particular tool can be used instead (say, <a href="https://en.wikipedia.org/wiki/GNU_nano" rel="noreferrer">nano</a> instead of <a href="http://en.wikipedia.org/wiki/Vi" rel="noreferrer">vi</a>).</p>
[ { "answer_id": 60741, "author": "UnkwnTech", "author_id": 115, "author_profile": "https://Stackoverflow.com/users/115", "pm_score": -1, "selected": false, "text": "sudo apt-get -yq install apache2\n" }, { "answer_id": 60792, "author": "Grundlefleck", "author_id": 4120, ...
2008/09/13
[ "https://Stackoverflow.com/questions/60736", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4120/" ]
60,740
<p>Is there an IE6/PNG fix that is officially developed by the jQuery team?</p> <p>If not which of the available plugins should I use?</p>
[ { "answer_id": 2163740, "author": "Guilherme Santos", "author_id": 262002, "author_profile": "https://Stackoverflow.com/users/262002", "pm_score": 1, "selected": false, "text": "// this line\njQuery(this).find(\"img[src$=.png]:visible\").each(function() { \n// this line\njQuery(this).fin...
2008/09/13
[ "https://Stackoverflow.com/questions/60740", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3747/" ]
60,751
<p>Currently my app uses just Direct3D9 for graphics, however in the future I' m planning to extend this to D3D10 and possibly OpenGL. The question is how can I do this in a tidy way?</p> <p>At present there are various Render methods in my code</p> <pre><code>void Render(boost::function&lt;void()&gt; &amp;Call) { D3dDevice-&gt;BeginScene(); Call(); D3dDevice-&gt;EndScene(); D3dDevice-&gt;Present(0,0,0,0); } </code></pre> <p>The function passed then depends on the exact state, eg MainMenu->Render, Loading->Render, etc. These will then oftern call the methods of other objects.</p> <pre><code>void RenderGame() { for(entity::iterator it = entity::instances.begin();it != entity::instance.end(); ++it) (*it)-&gt;Render(); UI-&gt;Render(); } </code></pre> <p>And a sample class derived from entity::Base</p> <pre><code>class Sprite: public Base { IDirect3DTexture9 *Tex; Point2 Pos; Size2 Size; public: Sprite(IDirect3DTexture9 *Tex, const Point2 &amp;Pos, const Size2 &amp;Size); virtual void Render(); }; </code></pre> <p>Each method then takes care of how best to render given the more detailed settings (eg are pixel shaders supported or not).</p> <p>The problem is I'm really not sure how to extend this to be able to use one of, what may be somewhat different (D3D v OpenGL) render modes...</p>
[ { "answer_id": 60790, "author": "Tobi", "author_id": 5422, "author_profile": "https://Stackoverflow.com/users/5422", "pm_score": 4, "selected": true, "text": "class IRenderer {\n public:\n virtual ~IRenderer() {}\n virtual void RenderModel(CModel* model) = 0;\n virtual void Dra...
2008/09/13
[ "https://Stackoverflow.com/questions/60751", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6266/" ]
60,757
<p>What is the best way to handle user account management in a system, without having your employees who have access to a database, to have access to the accounts.</p> <p>Examples:</p> <ol> <li><p>Storing username/password in the database. This is a bad idea because anyone that has access to a database can see the username and password. And hence use it.</p></li> <li><p>Storing username/password hash. This is a better method, but the account can be accessed by replacing the password hash in the database with the hash of another account that you know the auth info for. Then after access is granted reverting it back in the database. </p></li> </ol> <p>How does windows/*nix handle this?</p>
[ { "answer_id": 60864, "author": "Mr Shark", "author_id": 6093, "author_profile": "https://Stackoverflow.com/users/6093", "pm_score": 2, "selected": false, "text": "SetPassword(user, password)\n salt = RandomString()\n hash = Hashfunction(salt+password)\n StoreInDatabase(user, sa...
2008/09/13
[ "https://Stackoverflow.com/questions/60757", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3153/" ]
60,764
<p>Why is it so hard to do this in Java? If you want to have any kind of module system you need to be able to load JAR files dynamically. I'm told there's a way of doing it by writing your own <code>ClassLoader</code>, but that's a lot of work for something that should (in my mind at least) be as easy as calling a method with a JAR file as its argument.</p> <p>Any suggestions for simple code that does this?</p>
[ { "answer_id": 60766, "author": "Allain Lalonde", "author_id": 2443, "author_profile": "https://Stackoverflow.com/users/2443", "pm_score": 7, "selected": false, "text": "File file = ...\nURL url = file.toURI().toURL();\n\nURLClassLoader classLoader = (URLClassLoader)ClassLoader.getSystem...
2008/09/13
[ "https://Stackoverflow.com/questions/60764", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2443/" ]
60,768
<p>I am trying to dynamicaly compile code using CodeDom. I can load other assemblies, but I cannot load System.Data.Linq.dll. I get an error:</p> <p>Metadata file 'System.Data.Linq.dll' could not be found</p> <p>My code looks like:</p> <pre><code>CompilerParameters compilerParams = new CompilerParameters(); compilerParams.CompilerOptions = "/target:library /optimize"; compilerParams.GenerateExecutable = false; compilerParams.GenerateInMemory = true; compilerParams.IncludeDebugInformation = false; compilerParams.ReferencedAssemblies.Add("mscorlib.dll"); compilerParams.ReferencedAssemblies.Add("System.dll"); compilerParams.ReferencedAssemblies.Add("System.Data.Linq.dll"); </code></pre> <p>Any ideas? </p>
[ { "answer_id": 60781, "author": "Curt Hagenlocher", "author_id": 533, "author_profile": "https://Stackoverflow.com/users/533", "pm_score": 3, "selected": true, "text": "compilerParams.ReferencedAssemblies.Add(typeof(DataContext).Assembly.Location);\n" } ]
2008/09/13
[ "https://Stackoverflow.com/questions/60768", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5189/" ]
60,779
<p>Trying to do this sort of thing...</p> <pre><code>WHERE username LIKE '%$str%' </code></pre> <p>...but using bound parameters to prepared statements in PDO. e.g.:</p> <pre><code>$query = $db-&gt;prepare("select * from comments where comment like :search"); $query-&gt;bindParam(':search', $str); $query-&gt;execute(); </code></pre> <p>I've tried numerous permutations of single quotes and % signs and it's just getting cross with me.</p> <p>I seem to remember wrestling with this at some point before but I can't find any references. Does anyone know how (if?) you can do this nicely in PDO with named parameters?</p>
[ { "answer_id": 60782, "author": "Polsonby", "author_id": 137, "author_profile": "https://Stackoverflow.com/users/137", "pm_score": 5, "selected": true, "text": "$str = \"%$str%\";\n$query = $db->prepare(\"select * from comments where comment like :search\");\n$query->bindParam(':search',...
2008/09/13
[ "https://Stackoverflow.com/questions/60779", "https://Stackoverflow.com", "https://Stackoverflow.com/users/137/" ]
60,785
<p>How can I show a grey transparent overlay in C#?<br> It should overlay other process which are not owned by the application doing the overlay.</p>
[ { "answer_id": 60782, "author": "Polsonby", "author_id": 137, "author_profile": "https://Stackoverflow.com/users/137", "pm_score": 5, "selected": true, "text": "$str = \"%$str%\";\n$query = $db->prepare(\"select * from comments where comment like :search\");\n$query->bindParam(':search',...
2008/09/13
[ "https://Stackoverflow.com/questions/60785", "https://Stackoverflow.com", "https://Stackoverflow.com/users/44972/" ]
60,802
<p>I'm having trouble ordering by more than one field in my Linq to NHibernate query. Does anyone either know what might be wrong or if there is a work around?</p> <p>Code:</p> <pre><code>IQueryable&lt;AgendaItem&gt; items = _agendaRepository.GetAgendaItems(location) .Where(item =&gt; item.Minutes.Contains(query) || item.Description.Contains(query)); int total = items.Count(); var results = items .OrderBy(item =&gt; item.Agenda.Date) .ThenBy(item =&gt; item.OutcomeType) .ThenBy(item =&gt; item.OutcomeNumber) .Skip((page - 1)*pageSize) .Take(pageSize) .ToArray(); return new SearchResult(query, total, results); </code></pre> <p>I've tried replacing ThenBy with multiple OrderBy calls. Same result. The method works great if I comment out the two ThenBy calls.</p> <p>Error I'm receiving:</p> <pre> [SqlException (0x80131904): Invalid column name '__hibernate_sort_expr_0____hibernate_sort_expr_1__'. Invalid column name '__hibernate_sort_expr_0____hibernate_sort_expr_1__'.] System.Data.SqlClient.SqlConnection.OnError(SqlException exception, Boolean breakConnection) +1948826 System.Data.SqlClient.SqlInternalConnection.OnError(SqlException exception, Boolean breakConnection) +4844747 System.Data.SqlClient.TdsParser.ThrowExceptionAndWarning(TdsParserStateObject stateObj) +194 System.Data.SqlClient.TdsParser.Run(RunBehavior runBehavior, SqlCommand cmdHandler, SqlDataReader dataStream, BulkCopySimpleResultSet bulkCopyHandler, TdsParserStateObject stateObj) +2392 [ADOException: could not execute query [ SELECT this_.Id as Id5_2_, this_.AgendaId as AgendaId5_2_, this_.Description as Descript3_5_2_, this_.OutcomeType as OutcomeT4_5_2_, this_.OutcomeNumber as OutcomeN5_5_2_, this_.Minutes as Minutes5_2_, agenda1_.Id as Id2_0_, agenda1_.LocationId as LocationId2_0_, agenda1_.Date as Date2_0_, location2_.Id as Id7_1_, location2_.Name as Name7_1_ FROM AgendaItem this_ left outer join Agenda agenda1_ on this_.AgendaId=agenda1_.Id left outer join Location location2_ on agenda1_.LocationId=location2_.Id WHERE location2_.Id = ? and (this_.Minutes like ? or this_.Description like ?) ORDER BY agenda1_.Date asc, this_.OutcomeType asc, this_.OutcomeNumber asc ] Positional parameters: #0>1 #0>%Core% #0>%Core% [SQL: SELECT this_.Id as Id5_2_, this_.AgendaId as AgendaId5_2_, this_.Description as Descript3_5_2_, this_.OutcomeType as OutcomeT4_5_2_, this_.OutcomeNumber as OutcomeN5_5_2_, this_.Minutes as Minutes5_2_, agenda1_.Id as Id2_0_, agenda1_.LocationId as LocationId2_0_, agenda1_.Date as Date2_0_, location2_.Id as Id7_1_, location2_.Name as Name7_1_ FROM AgendaItem this_ left outer join Agenda agenda1_ on this_.AgendaId=agenda1_.Id left outer join Location location2_ on agenda1_.LocationId=location2_.Id WHERE location2_.Id = ? and (this_.Minutes like ? or this_.Description like ?) ORDER BY agenda1_.Date asc, this_.OutcomeType asc, this_.OutcomeNumber asc]] NHibernate.Loader.Loader.DoList(ISessionImplementor session, QueryParameters queryParameters) +258 NHibernate.Loader.Loader.ListIgnoreQueryCache(ISessionImplementor session, QueryParameters queryParameters) +18 NHibernate.Loader.Loader.List(ISessionImplementor session, QueryParameters queryParameters, ISet`1 querySpaces, IType[] resultTypes) +87 NHibernate.Impl.SessionImpl.List(CriteriaImpl criteria, IList results) +342 NHibernate.Impl.CriteriaImpl.List(IList results) +41 NHibernate.Impl.CriteriaImpl.List() +35 NHibernate.Linq.CriteriaResultReader`1.List() in C:\home\dev\tools\NHibernate\NHibernateContribSrc\src\NHibernate.Linq\src\NHibernate.Linq\CriteriaResultReader.cs:22 NHibernate.Linq.d__0.MoveNext() in C:\home\dev\tools\NHibernate\NHibernateContribSrc\src\NHibernate.Linq\src\NHibernate.Linq\CriteriaResultReader.cs:27 </pre>
[ { "answer_id": 86686, "author": "dcstraw", "author_id": 10391, "author_profile": "https://Stackoverflow.com/users/10391", "pm_score": 4, "selected": true, "text": "var results = items\n .ToArray()\n .OrderBy(item => item.Agenda.Date)\n .ThenBy(item => item.OutcomeType)\n .ThenBy(...
2008/09/13
[ "https://Stackoverflow.com/questions/60802", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2595/" ]
60,805
<p>How do I select one or more random rows from a table using SQLAlchemy? </p>
[ { "answer_id": 60811, "author": "Fire Lancer", "author_id": 6266, "author_profile": "https://Stackoverflow.com/users/6266", "pm_score": -1, "selected": false, "text": "SELECT colum FROM table\nORDER BY RAND()\nLIMIT 1\n" }, { "answer_id": 60815, "author": "Łukasz", "autho...
2008/09/13
[ "https://Stackoverflow.com/questions/60805", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1448/" ]
60,825
<p>I am working on a web application, where I transfer data from the server to the browser in XML.</p> <p>Since I'm danish, I quickly run into problems with the characters <code>æøå</code>.</p> <p>I know that in html, I use the <code>"&amp;amp;aelig;&amp;amp;oslash;&amp;amp;aring;"</code> for <code>æøå</code>.</p> <p>however, as soon as the chars pass through JavaScript, I get black boxes with <code>"?"</code> in them when using <code>æøå</code>, and <code>"&amp;aelig;&amp;oslash;&amp;aring;"</code> is printed as is.</p> <p>I've made sure to set it to utf-8, but that isn't helping much.</p> <p>Ideally, I want it to work with any special characters (naturally).</p> <p>The example that isn't working is included below:</p> <pre><code>&lt;!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"&gt; &lt;html&gt; &lt;head&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt; &lt;title&gt;Untitled Document&lt;/title&gt; &lt;script type="text/javascript" charset="utf-8"&gt; alert("&amp;aelig;&amp;oslash;&amp;aring;"); alert("æøå"); &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>What am I doing wrong?</p> <hr> <p>Ok, thanks to Grapefrukts answer, I got it working.</p> <p>I actually needed it for data coming from an MySQL server. Since the saving of the files in UTF-8 encoding only solves the problem for static content, I figure I'd include the solution for strings from a MySQL server, pulled out using PHP:</p> <p><code>utf8_encode($MyStringHere)</code></p>
[ { "answer_id": 60832, "author": "chryss", "author_id": 5169, "author_profile": "https://Stackoverflow.com/users/5169", "pm_score": 0, "selected": false, "text": "alert(\"&aelig;&oslash;&aring;\");\n" }, { "answer_id": 67289, "author": "enricopulatzo", "author_id": 9883, ...
2008/09/13
[ "https://Stackoverflow.com/questions/60825", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1090/" ]
60,830
<p>While it would be very convenient to use inline functions at some situations,</p> <p>Are there any drawbacks with inline functions?</p> <p><strong>Conclusion</strong>:</p> <p>Apparently, There is nothing wrong with using inline functions.</p> <p>But it is worth noting the following points!</p> <ul> <li><p>Overuse of inlining can actually make programs slower. Depending on a function's size, inlining it can cause the code size to increase or decrease. Inlining a very small accessor function will usually decrease code size while inlining a very large function can dramatically increase code size. On modern processors smaller code usually runs faster due to better use of the instruction cache. <a href="http://google-styleguide.googlecode.com/svn/trunk/cppguide.xml#Inline_Functions" rel="noreferrer">- Google Guidelines</a></p></li> <li><p>The speed benefits of inline functions tend to diminish as the function grows in size. At some point the overhead of the function call becomes small compared to the execution of the function body, and the benefit is lost <a href="http://www-rocq.inria.fr/who/Marc.Thiriet/Langages/tic0324.html" rel="noreferrer">- Source</a></p></li> <li><p>There are few situations where an inline function may not work:</p> <ul> <li>For a function returning values; if a return statement exists.</li> <li>For a function not returning any values; if a loop, switch or goto statement exists. </li> <li>If a function is recursive. <a href="http://www-rocq.inria.fr/who/Marc.Thiriet/Langages/tic0324.html" rel="noreferrer">-Source</a></li> </ul></li> <li><p>The <code>__inline</code> keyword causes a function to be inlined only if you specify the optimize option. If optimize is specified, whether or not <code>__inline</code> is honored depends on the setting of the inline optimizer option. By default, the inline option is in effect whenever the optimizer is run. If you specify optimize , you must also specify the noinline option if you want the <code>__inline</code> keyword to be ignored. <a href="http://support.sas.com/documentation/onlinedoc/sasc/doc750/html/clug/zcoptinl.htm" rel="noreferrer">-Source</a></p></li> </ul>
[ { "answer_id": 60854, "author": "Fire Lancer", "author_id": 6266, "author_profile": "https://Stackoverflow.com/users/6266", "pm_score": 1, "selected": false, "text": "__forceinline" }, { "answer_id": 60941, "author": "maccullt", "author_id": 4945, "author_profile": "h...
2008/09/13
[ "https://Stackoverflow.com/questions/60830", "https://Stackoverflow.com", "https://Stackoverflow.com/users/123/" ]
60,848
<p>Is it possible to retrieve items from a Python dictionary in the order that they were inserted?</p>
[ { "answer_id": 60862, "author": "dF.", "author_id": 3002, "author_profile": "https://Stackoverflow.com/users/3002", "pm_score": 7, "selected": true, "text": "dict" }, { "answer_id": 61031, "author": "Eli Courtwright", "author_id": 1694, "author_profile": "https://Stac...
2008/09/13
[ "https://Stackoverflow.com/questions/60848", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4883/" ]
60,874
<p>I know a few advanced ways, to change directories. <code>pushd</code> and <code>popd</code> (directory stack) or <code>cd -</code> (change to last directory).</p> <p>But I am looking for quick way to achieve the following:</p> <p>Say, I am in a rather deep dir:</p> <pre><code>/this/is/a/very/deep/directory/structure/with\ lot\ of\ nasty/names </code></pre> <p>and I want to switch to </p> <pre><code>/this/is/another/very/deep/directory/structure/with\ lot\ of\ nasty/names </code></pre> <p>Is there a cool/quick/geeky way to do it (without the mouse)?</p>
[ { "answer_id": 60887, "author": "dF.", "author_id": 3002, "author_profile": "https://Stackoverflow.com/users/3002", "pm_score": 4, "selected": true, "text": "cd ${PWD/a/another}\n" }, { "answer_id": 60936, "author": "Rob Wells", "author_id": 2974, "author_profile": "h...
2008/09/13
[ "https://Stackoverflow.com/questions/60874", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1870/" ]
60,877
<p>I have a query where I wish to retrieve the oldest X records. At present my query is something like the following:</p> <pre><code>SELECT Id, Title, Comments, CreatedDate FROM MyTable WHERE CreatedDate &gt; @OlderThanDate ORDER BY CreatedDate DESC </code></pre> <p>I know that normally I would remove the 'DESC' keyword to switch the order of the records, however in this instance I still want to get records ordered with the newest item first.</p> <p>So I want to know if there is any means of performing this query such that I get the oldest X items sorted such that the newest item is first. I should also add that my database exists on SQL Server 2005.</p>
[ { "answer_id": 60882, "author": "Jason Punyon", "author_id": 6212, "author_profile": "https://Stackoverflow.com/users/6212", "pm_score": 6, "selected": true, "text": "SELECT T1.* \nFROM\n(SELECT TOP X Id, Title, Comments, CreatedDate\nFROM MyTable\nWHERE CreatedDate > @OlderThanDate\nORD...
2008/09/13
[ "https://Stackoverflow.com/questions/60877", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5086/" ]
60,904
<p>How can I open a cmd window in a specific location without having to navigate all the way to the directory I want?</p>
[ { "answer_id": 60907, "author": "Allain Lalonde", "author_id": 2443, "author_profile": "https://Stackoverflow.com/users/2443", "pm_score": 9, "selected": false, "text": "cmd /K \"cd C:\\Windows\\\"\n" }, { "answer_id": 215534, "author": "Community", "author_id": -1, "...
2008/09/13
[ "https://Stackoverflow.com/questions/60904", "https://Stackoverflow.com", "https://Stackoverflow.com/users/44972/" ]
60,910
<p>I've recently had a need to do a bit of lisp editing and I found the nifty Ready Lisp package for OS X, which is great, except Aquamacs automatically uses a proportional font (which is idiotic, IMHO) and I want to change it to a monospace font. However, I'm not really much of an EMACS user, and the preferences menu in Aquamacs is less than clear on where and how one might make such a change. </p>
[ { "answer_id": 60948, "author": "Natalie Weizenbaum", "author_id": 2518, "author_profile": "https://Stackoverflow.com/users/2518", "pm_score": 4, "selected": true, "text": "(set-default-font \"-apple-bitstream vera sans mono-medium-r-normal--0-0-0-0-m-0-mac-roman\")\n" }, { "answ...
2008/09/13
[ "https://Stackoverflow.com/questions/60910", "https://Stackoverflow.com", "https://Stackoverflow.com/users/85/" ]
60,918
<p>I'm trying to do 'Attach to Process' for debugging in Visual Studio 2008 and I can't figure out what process to attach to. Help.</p>
[ { "answer_id": 6362634, "author": "Robin Minto", "author_id": 1456, "author_profile": "https://Stackoverflow.com/users/1456", "pm_score": 4, "selected": false, "text": "cscript iisapp.vbs" } ]
2008/09/13
[ "https://Stackoverflow.com/questions/60918", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4541/" ]
60,919
<p>Can I use this approach efficiently?</p> <pre><code>using(SqlCommand cmd = new SqlCommand("GetSomething", new SqlConnection(Config.ConnectionString)) { cmd.Connection.Open(); // set up parameters and CommandType to StoredProcedure etc. etc. cmd.ExecuteNonQuery(); } </code></pre> <p>My concern is : Will the Dispose method of the SqlCommand (which is called when exiting the using block) close the underlying SqlConnection object or not?</p>
[ { "answer_id": 60934, "author": "Ryan Farley", "author_id": 1627, "author_profile": "https://Stackoverflow.com/users/1627", "pm_score": 8, "selected": true, "text": "SqlCommand" }, { "answer_id": 5654064, "author": "Chuck Bevitt", "author_id": 704658, "author_profile"...
2008/09/13
[ "https://Stackoverflow.com/questions/60919", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1796/" ]
60,942
<p>I'd like to redirect the stdout of process proc1 to two processes proc2 and proc3:</p> <pre><code> proc2 -&gt; stdout / proc1 \ proc3 -&gt; stdout </code></pre> <p>I tried</p> <pre><code> proc1 | (proc2 &amp; proc3) </code></pre> <p>but it doesn't seem to work, i.e.</p> <pre><code> echo 123 | (tr 1 a &amp; tr 1 b) </code></pre> <p>writes</p> <pre><code> b23 </code></pre> <p>to stdout instead of </p> <pre><code> a23 b23 </code></pre>
[ { "answer_id": 60955, "author": "dF.", "author_id": 3002, "author_profile": "https://Stackoverflow.com/users/3002", "pm_score": 8, "selected": true, "text": ">(…)" }, { "answer_id": 61716, "author": "Jay Bazuzi", "author_id": 5314, "author_profile": "https://Stackover...
2008/09/13
[ "https://Stackoverflow.com/questions/60942", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4085/" ]
60,950
<p>I find working on the command line in Windows frustrating, primarily because the console window is wretched to use compared to terminal applications on linux and OS X such as "rxvt", "xterm", or "Terminal". Major complaints:</p> <ol> <li><p>No standard copy/paste. You have to turn on "mark" mode and it's only available from a multi-level popup triggered by the (small) left hand corner button. Then copy and paste need to be invoked from the same menu</p></li> <li><p>You can't arbitrarily resize the window by dragging, you need to set a preference (back to the multi-level popup) each time you want to resize a window</p></li> <li><p>You can only make the window so big before horizontal scroll bars enter the picture. Horizontal scroll bars suck.</p></li> <li><p>With the cmd.exe shell, you can't navigate to folders with \\netpath notation (UNC?), you need to map a network drive. This sucks when working on multiple machines that are going to have different drives mapped</p></li> </ol> <p>Are there any tricks or applications, (paid or otherwise), that address these issue?</p>
[ { "answer_id": 60956, "author": "Apocalisp", "author_id": 3434, "author_profile": "https://Stackoverflow.com/users/3434", "pm_score": 5, "selected": false, "text": "xterm" } ]
2008/09/13
[ "https://Stackoverflow.com/questions/60950", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4668/" ]
60,977
<p>Sometimes I have to work on code that moves the computer clock forward. In this case some .cpp or .h files get their latest modification date set to the future time.</p> <p>Later on, when my clock is fixed, and I compile my sources, system rebuilds most of the project because some of the latest modification dates are in the future. Each subsequent recompile has the same problem.</p> <p>Solution that I know are:</p> <p>a) Find the file that has the future time and re-save it. This method is not ideal because the project is very big and it takes time even for windows advanced search to find the files that are changed.</p> <p>b) Delete the whole project and re-check it out from svn.</p> <p>Does anyone know how I can get around this problem?</p> <p>Is there perhaps a setting in visual studio that will allow me to tell the compiler to use the archive bit instead of the last modification date to detect source file changes?</p> <p>Or perhaps there is a recursive modification date reset tool that can be used in this situation?</p>
[ { "answer_id": 61015, "author": "Nathan Jones", "author_id": 5848, "author_profile": "https://Stackoverflow.com/users/5848", "pm_score": 1, "selected": false, "text": "touch temp\nfind . -newer temp -exec touch {} ;\nrm temp\n" }, { "answer_id": 61105, "author": "Jay Bazuzi",...
2008/09/13
[ "https://Stackoverflow.com/questions/60977", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3153/" ]
61,000
<p>I am wondering what directory structure are commonly used in development projects. I mean with the idea of facilitating builds, deploys release, and etc.</p> <p>I recently used a <a href="http://maven.apache.org/guides/introduction/introduction-to-the-standard-directory-layout.html" rel="nofollow noreferrer">Maven structure</a> for a java project, but I am not sure it's the best structure for a non-maven driven project.</p> <p>So, I have two questions: When you guys start new projects, what structure you use? And: What if you need to integrate two different languages, like for example java classes into a PHP application; PHP files are source files, web files, you you use a /src, /classes, webapps/php ? What are your choices in such scenarios. </p> <p>As a note: I am wondering also what are you choices for directories names. I like the 3-letters names (src, lib, bin, web, img, css, xml, cfg) but what are your opinions about descriptive names like libraris, sources or htdocs/public_html ?</p>
[ { "answer_id": 4540307, "author": "Fernando Barrocal", "author_id": 2274, "author_profile": "https://Stackoverflow.com/users/2274", "pm_score": 4, "selected": true, "text": "/project_name (everything goes here)\n /web (htdocs)\n /img\n /css\n /app (usual...
2008/09/14
[ "https://Stackoverflow.com/questions/61000", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2274/" ]
61,002
<p>I'd like to script, preferably in rake, the following actions into a single command:</p> <ol> <li>Get the version of my local git repository.</li> <li>Git pull the latest code.</li> <li>Git diff from the version I extracted in step #1 to what is now in my local repository.</li> </ol> <p>In other words, I want to get the latest code form the central repository and immediately generate a diff of what's changed since the last time I pulled.</p>
[ { "answer_id": 61004, "author": "Greg Hewgill", "author_id": 893, "author_profile": "https://Stackoverflow.com/users/893", "pm_score": 4, "selected": false, "text": "git fetch\ngit diff ...origin\n" }, { "answer_id": 61477, "author": "Greg", "author_id": 108, "author_...
2008/09/14
[ "https://Stackoverflow.com/questions/61002", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4061/" ]
61,005
<p>What are the best file permission settings for PHP scripts? Any suggestions on ways to figure out the minimum required permissions?</p>
[ { "answer_id": 61004, "author": "Greg Hewgill", "author_id": 893, "author_profile": "https://Stackoverflow.com/users/893", "pm_score": 4, "selected": false, "text": "git fetch\ngit diff ...origin\n" }, { "answer_id": 61477, "author": "Greg", "author_id": 108, "author_...
2008/09/14
[ "https://Stackoverflow.com/questions/61005", "https://Stackoverflow.com", "https://Stackoverflow.com/users/814/" ]
61,033
<p>I've got a table of URLs and I don't want any duplicate URLs. How do I check to see if a given URL is already in the table using PHP/MySQL?</p>
[ { "answer_id": 61035, "author": "Paige Ruten", "author_id": 813, "author_profile": "https://Stackoverflow.com/users/813", "pm_score": -1, "selected": false, "text": "SELECT url FROM urls WHERE url = 'http://asdf.com' LIMIT 1\n" }, { "answer_id": 61036, "author": "roman m", ...
2008/09/14
[ "https://Stackoverflow.com/questions/61033", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6305/" ]
61,051
<p>You can use more than one css class in an HTML tag in current web browsers, e.g.:</p> <pre><code>&lt;div class="style1 style2 style3"&gt;foo bar&lt;/div&gt; </code></pre> <p>This hasn't always worked; with which versions did the major browsers begin correctly supporting this feature?</p>
[ { "answer_id": 61414, "author": "Bryan M.", "author_id": 4636, "author_profile": "https://Stackoverflow.com/users/4636", "pm_score": 4, "selected": true, "text": "<div class=\"bold italic\">content</div>\n\n.bold {\n font-weight: 800;\n}\n\n.italic {\n font-style: italic;\n{\n" } ]
2008/09/14
[ "https://Stackoverflow.com/questions/61051", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3283/" ]
61,052
<p>I need to know the application's ProductCode in the Installer.OnCommitted callback. There doesn't seem to be an obvious way of determining this.</p>
[ { "answer_id": 61298, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 1, "selected": false, "text": "string productCode = (string)Context.Parameters[\"productcode\"];\n" }, { "answer_id": 67385558, "author": "aolszow...
2008/09/14
[ "https://Stackoverflow.com/questions/61052", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
61,084
<p>I'm trying to create a sitemap using Linq to Xml, but am getting an empty namespace attribute, which I would like to get rid of. e.g.</p> <pre><code>XNamespace ns = "http://www.sitemaps.org/schemas/sitemap/0.9"; XDocument xdoc = new XDocument(new XDeclaration("1.0", "utf-8", "true"), new XElement(ns + "urlset", new XElement("url", new XElement("loc", "http://www.example.com/page"), new XElement("lastmod", "2008-09-14")))); </code></pre> <p>The result is ...</p> <pre><code>&lt;urlset xmlns="http://www.sitemaps.org/schemas/sitemap/0.9"&gt; &lt;url xmlns=""&gt; &lt;loc&gt;http://www.example.com/page&lt;/loc&gt; &lt;lastmod&gt;2008-09-14&lt;/lastmod&gt; &lt;/url&gt; &lt;/urlset&gt; </code></pre> <p>I would rather not have the xmlns="" on the url element. I can strip it out using Replace on the final xdoc.ToString(), but is there a more correct way?</p>
[ { "answer_id": 61141, "author": "Micah", "author_id": 6209, "author_profile": "https://Stackoverflow.com/users/6209", "pm_score": 6, "selected": true, "text": "XDocument xdoc = new XDocument(new XDeclaration(\"1.0\", \"utf-8\", \"true\"),\nnew XElement(ns + \"urlset\",\nnew XElement(ns +...
2008/09/14
[ "https://Stackoverflow.com/questions/61084", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4449/" ]
61,085
<p>I've been trying to use SQLite with the PDO wrapper in PHP with mixed success. I can read from the database fine, but none of my updates are being committed to the database when I view the page in the browser. Curiously, running the script from my shell does update the database. I suspected file permissions as the culprit, but even with the database providing full access (chmod 777) the problem persists. Should I try changing the file owner? If so, what to?</p> <p>By the way, my machine is the standard Mac OS X Leopard install with PHP activated.</p> <p>@Tom Martin</p> <p>Thank you for your reply. I just ran your code and it looks like PHP runs as user _www. I then tried chowning the database to be owned by _www, but that didn't work either.</p> <p>I should also note that PDO's errorInfo function doesn't indicate an error took place. Could this be a setting with PDO somehow opening the database for read-only? I've heard that SQLite performs write locks on the entire file. Is it possible that the database is locked by something else preventing the write?</p> <p>I've decided to include the code in question. This is going to be more or less a port of <a href="https://stackoverflow.com/questions/6936/using-what-ive-learned-from-stackoverflow-html-scraper">Grant's script</a> to PHP. So far it's just the Questions section:</p> <pre><code>&lt;?php $db = new PDO('sqlite:test.db'); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, "https://stackoverflow.com/users/658/kyle"); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_COOKIE, "shhsecret=1293706652"); $page = curl_exec($ch); preg_match('/summarycount"&gt;.*?([,\d]+)&lt;\/div&gt;.*?Reputation/s', $page, $rep); $rep = preg_replace("/,/", "", $rep[1]); preg_match('/iv class="summarycount".{10,60} (\d+)&lt;\/d.{10,140}Badges/s', $page, $badge); $badge = $badge[1]; $qreg = '/question-summary narrow.*?vote-count-post"&gt;&lt;strong.*?&gt;(-?\d*).*?\/questions\/(\d*).*?&gt;(.*?)&lt;\/a&gt;/s'; preg_match_all($qreg, $page, $questions, PREG_SET_ORDER); $areg = '/(answer-summary"&gt;&lt;a href="\/questions\/(\d*).*?votes.*?&gt;(-?\d+).*?href.*?&gt;(.*?)&lt;.a)/s'; preg_match_all($areg, $page, $answers, PREG_SET_ORDER); echo "&lt;h3&gt;Questions:&lt;/h3&gt;\n"; echo "&lt;table cellpadding=\"3\"&gt;\n"; foreach ($questions as $q) { $query = 'SELECT count(id), votes FROM Questions WHERE id = '.$q[2].' AND type=0;'; $dbitem = $db-&gt;query($query)-&gt;fetch(PDO::FETCH_ASSOC); if ($dbitem['count(id)'] &gt; 0) { $lastQ = $q[1] - $dbitem['votes']; if ($lastQ == 0) { $lastQ = ""; } $query = "UPDATE Questions SET votes = '$q[1]' WHERE id = '$q[2]'"; $db-&gt;exec($query); } else { $query = "INSERT INTO Questions VALUES('$q[3]', '$q[1]', 0, '$q[2]')"; echo "$query\n"; $db-&gt;exec($query); $lastQ = "(NEW)"; } echo "&lt;tr&gt;&lt;td&gt;$lastQ&lt;/td&gt;&lt;td align=\"right\"&gt;$q[1]&lt;/td&gt;&lt;td&gt;$q[3]&lt;/td&gt;&lt;/tr&gt;\n"; } echo "&lt;/table&gt;"; ?&gt; </code></pre>
[ { "answer_id": 61102, "author": "Tom Martin", "author_id": 5303, "author_profile": "https://Stackoverflow.com/users/5303", "pm_score": 1, "selected": false, "text": "echo exec('whoami');" }, { "answer_id": 3470364, "author": "paolo_O", "author_id": 418707, "author_pro...
2008/09/14
[ "https://Stackoverflow.com/questions/61085", "https://Stackoverflow.com", "https://Stackoverflow.com/users/658/" ]
61,088
<p><strong>What "Hidden Features" of JavaScript do you think every programmer should know?</strong></p> <p>After having seen the excellent quality of the answers to the following questions I thought it was time to ask it for JavaScript.</p> <ul> <li><a href="https://stackoverflow.com/questions/954327/">Hidden Features of HTML</a></li> <li><a href="https://stackoverflow.com/questions/628407">Hidden Features of CSS</a></li> <li><a href="https://stackoverflow.com/questions/61401/">Hidden Features of PHP</a></li> <li><a href="https://stackoverflow.com/questions/54929/">Hidden Features of ASP.NET</a></li> <li><a href="https://stackoverflow.com/questions/9033/">Hidden Features of C#</a></li> <li><a href="https://stackoverflow.com/questions/15496/">Hidden Features of Java</a></li> <li><a href="https://stackoverflow.com/questions/101268/">Hidden Features of Python</a></li> </ul> <p>Even though JavaScript is arguably the most important Client Side language right now (just ask Google) it's surprising how little most web developers appreciate how powerful it really is.</p>
[ { "answer_id": 61094, "author": "Gulzar Nazim", "author_id": 4337, "author_profile": "https://Stackoverflow.com/users/4337", "pm_score": 8, "selected": false, "text": "var passFunAndApply = function (fn,x,y,z) { return fn(x,y,z); };\n\nvar sum = function(x,y,z) {\n return x+y+z;\n};\n\n...
2008/09/14
[ "https://Stackoverflow.com/questions/61088", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2443/" ]
61,092
<p>Having read the threads <a href="https://stackoverflow.com/questions/60919/is-sqlcommanddispose-enough">Is SqlCommand.Dispose enough?</a> and <a href="https://stackoverflow.com/questions/23867/closing-and-disposing-a-wcf-service">Closing and Disposing a WCF Service</a> I am wondering for classes such as SqlConnection or one of the several classes inheriting from the Stream class does it matter if I close Dispose rather than Close?</p>
[ { "answer_id": 61096, "author": "Curt Hagenlocher", "author_id": 533, "author_profile": "https://Stackoverflow.com/users/533", "pm_score": 4, "selected": false, "text": "SqlConnection" }, { "answer_id": 61131, "author": "Brannon", "author_id": 5745, "author_profile": ...
2008/09/14
[ "https://Stackoverflow.com/questions/61092", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5086/" ]
61,109
<p>I have been learning C++ for a while now, I find it very powerful. But, the problem is the the level of abstraction is not much and I have to do memory management myself. What are the languages that I can use which uses a higher level of abstraction.</p>
[ { "answer_id": 12147944, "author": "mikera", "author_id": 214010, "author_profile": "https://Stackoverflow.com/users/214010", "pm_score": 1, "selected": false, "text": ";; treat a vector as a sequence and reverse it\n(reverse [1 2 3 4 5])\n=> (5 4 3 2 1)\n\n;; Take 10 items from a infini...
2008/09/14
[ "https://Stackoverflow.com/questions/61109", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6323/" ]
61,110
<p>I need advice on how to have my C# console application display text to the user through the standard output while still being able access it later on. The actual feature I would like to implement is to dump the entire output buffer to a text file at the end of program execution.</p> <p>The workaround I use while I don't find a cleaner approach is to subclass <code>TextWriter</code> overriding the writing methods so they would both write to a file and call the original stdout writer. Something like this:</p> <pre><code>public class DirtyWorkaround { private class DirtyWriter : TextWriter { private TextWriter stdoutWriter; private StreamWriter fileWriter; public DirtyWriter(string path, TextWriter stdoutWriter) { this.stdoutWriter = stdoutWriter; this.fileWriter = new StreamWriter(path); } override public void Write(string s) { stdoutWriter.Write(s); fileWriter.Write(s); fileWriter.Flush(); } // Same as above for WriteLine() and WriteLine(string), // plus whatever methods I need to override to inherit // from TextWriter (Encoding.Get I guess). } public static void Main(string[] args) { using (DirtyWriter dw = new DirtyWriter("path", Console.Out)) { Console.SetOut(dw); // Teh codez } } } </code></pre> <p>See that it writes to and flushes the file all the time. I'd love to do it only at the end of the execution, but I couldn't find any way to access to the output buffer.</p> <p>Also, excuse inaccuracies with the above code (had to write it <em>ad hoc</em>, sorry ;).</p>
[ { "answer_id": 61119, "author": "Jason Cohen", "author_id": 4926, "author_profile": "https://Stackoverflow.com/users/4926", "pm_score": 3, "selected": false, "text": "MultiWriter" }, { "answer_id": 61123, "author": "Shog9", "author_id": 811, "author_profile": "https:/...
2008/09/14
[ "https://Stackoverflow.com/questions/61110", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4850/" ]
61,143
<p>Can someone show me how to implement a recursive lambda expression to traverse a tree structure in C#. </p>
[ { "answer_id": 61149, "author": "DevelopingChris", "author_id": 1220, "author_profile": "https://Stackoverflow.com/users/1220", "pm_score": 1, "selected": false, "text": " public void HandleTreeItems(Action<TreeItem> item, TreeItem parent)\n {\n if (parent.Children.Count > 0...
2008/09/14
[ "https://Stackoverflow.com/questions/61143", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5360/" ]
61,150
<p>My motto for Java is "just because Java has static blocks, it doesn't mean that you should be using them." Jokes aside, there are a lot of tricks in Java that make testing a nightmare. Two of the most I hate are Anonymous Classes and Static Blocks. We have a lot of legacy code that make use of Static Blocks and these are one of the annoying points in our push in writing unit tests. Our goal is to be able to write unit tests for classes that depend on this static initialization with minimal code changes. </p> <p>So far my suggestion to my colleagues is to move the body of the static block into a private static method and call it <code>staticInit</code>. This method can then be called from within the static block. For unit testing another class that depends on this class could easily mock <code>staticInit</code> with <a href="https://jmockit.github.io/" rel="noreferrer">JMockit</a> to not do anything. Let's see this in example.</p> <pre><code>public class ClassWithStaticInit { static { System.out.println("static initializer."); } } </code></pre> <p>Will be changed to</p> <pre><code>public class ClassWithStaticInit { static { staticInit(); } private static void staticInit() { System.out.println("static initialized."); } } </code></pre> <p>So that we can do the following in a <a href="https://junit.org/junit5/" rel="noreferrer">JUnit</a>.</p> <pre><code>public class DependentClassTest { public static class MockClassWithStaticInit { public static void staticInit() { } } @BeforeClass public static void setUpBeforeClass() { Mockit.redefineMethods(ClassWithStaticInit.class, MockClassWithStaticInit.class); } } </code></pre> <p>However this solution also comes with its own problems. You can't run <code>DependentClassTest</code> and <code>ClassWithStaticInitTest</code> on the same JVM since you actually want the static block to run for <code>ClassWithStaticInitTest</code>.</p> <p>What would be your way of accomplishing this task? Or any better, non-JMockit based solutions that you think would work cleaner?</p>
[ { "answer_id": 61153, "author": "Justin Standard", "author_id": 92, "author_profile": "https://Stackoverflow.com/users/92", "pm_score": 3, "selected": false, "text": "staticInit()" }, { "answer_id": 61190, "author": "marcospereira", "author_id": 4600, "author_profile"...
2008/09/14
[ "https://Stackoverflow.com/questions/61150", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3087/" ]
61,151
<p>If you're writing a library, or an app, where do the unit test files go? </p> <p>It's nice to separate the test files from the main app code, but it's awkward to put them into a "tests" subdirectory inside of the app root directory, because it makes it harder to import the modules that you'll be testing. </p> <p>Is there a best practice here?</p>
[ { "answer_id": 61169, "author": "Cristian", "author_id": 680, "author_profile": "https://Stackoverflow.com/users/680", "pm_score": 6, "selected": false, "text": "parent_dir/\n foo.py\n tests/\n" }, { "answer_id": 61531, "author": "John Millikin", "author_id": 3560, ...
2008/09/14
[ "https://Stackoverflow.com/questions/61151", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4883/" ]
61,155
<p>I'm trying to place this menu on the left hand side of the page:</p> <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false"> <div class="snippet-code"> <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div class="left-menu" style="left: 123px; top: 355px"&gt; &lt;ul&gt; &lt;li&gt; Categories &lt;/li&gt; &lt;li&gt; Weapons &lt;/li&gt; &lt;li&gt; Armor &lt;/li&gt; &lt;li&gt; Manuals &lt;/li&gt; &lt;li&gt; Sustenance &lt;/li&gt; &lt;li&gt; Test &lt;/li&gt; &lt;/ul&gt; &lt;/div&gt;</code></pre> </div> </div> </p> <p>The problem is that if I use absolute or fixed values, different screen sizes will render the navigation bar differently. I also have a second <code>div</code> that contains all the main content which also needs to be moved to the right, so far I'm using relative values which seems to work no matter the screen size.</p>
[ { "answer_id": 61200, "author": "Konrad Rudolph", "author_id": 1968, "author_profile": "https://Stackoverflow.com/users/1968", "pm_score": 4, "selected": true, "text": "float" }, { "answer_id": 61438, "author": "Bryan M.", "author_id": 4636, "author_profile": "https:/...
2008/09/14
[ "https://Stackoverflow.com/questions/61155", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4298/" ]
61,176
<p>I want to access messages in Gmail from a Java application using <a href="http://www.ing.iac.es/~docs/external/java/javamail/javadocs/index.html" rel="nofollow noreferrer">JavaMail</a> and <a href="https://en.wikipedia.org/wiki/Internet_Message_Access_Protocol" rel="nofollow noreferrer">IMAP</a>. Why am I getting a <em><a href="https://docs.oracle.com/javase/7/docs/api/java/net/SocketTimeoutException.html" rel="nofollow noreferrer">SocketTimeoutException</a></em> ?</p> <p>Here is my code:</p> <pre><code>Properties props = System.getProperties(); props.setProperty("mail.imap.host", "imap.gmail.com"); props.setProperty("mail.imap.port", "993"); props.setProperty("mail.imap.connectiontimeout", "5000"); props.setProperty("mail.imap.timeout", "5000"); try { Session session = Session.getDefaultInstance(props, new MyAuthenticator()); URLName urlName = new URLName("imap://MYUSERNAME@gmail.com:MYPASSWORD@imap.gmail.com"); Store store = session.getStore(urlName); if (!store.isConnected()) { store.connect(); } } catch (NoSuchProviderException e) { e.printStackTrace(); System.exit(1); } catch (MessagingException e) { e.printStackTrace(); System.exit(2); } </code></pre> <p>I have set the timeout values so that it wouldn't take "forever" to timeout. Also, <em>MyAuthenticator</em> also has the username and password, which seems redundant with the URL. Is there another way to specify the protocol? (I didn't see it in the JavaDoc for <a href="https://en.wikipedia.org/wiki/Internet_Message_Access_Protocol" rel="nofollow noreferrer">IMAP</a>.)</p>
[ { "answer_id": 61185, "author": "C. K. Young", "author_id": 13, "author_profile": "https://Stackoverflow.com/users/13", "pm_score": 3, "selected": false, "text": "imaps" }, { "answer_id": 61469, "author": "Dave", "author_id": 2512222, "author_profile": "https://Stacko...
2008/09/14
[ "https://Stackoverflow.com/questions/61176", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2512222/" ]
61,212
<p>How do I delete untracked local files from the current working tree?</p>
[ { "answer_id": 61214, "author": "Fire Lancer", "author_id": 6266, "author_profile": "https://Stackoverflow.com/users/6266", "pm_score": 9, "selected": false, "text": "git-clean" }, { "answer_id": 64966, "author": "Community", "author_id": -1, "author_profile": "https:...
2008/09/14
[ "https://Stackoverflow.com/questions/61212", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4883/" ]
61,217
<p>This question is a follow up to my <a href="https://stackoverflow.com/questions/56279/export-aspx-to-html">previous question</a> about getting the HTML from an ASPX page. I decided to try using the webclient object, but the problem is that I get the login page's HTML because login is required. I tried "logging in" using the webclient object:</p> <pre><code>WebClient ww = new WebClient(); ww.DownloadString("Login.aspx?UserName=&amp;Password="); string html = ww.DownloadString("Internal.aspx"); </code></pre> <p>But I still get the login page all the time. I know that the username info is not stored in a cookie. I must be doing something wrong or leaving out an important part. Does anyone know what it could be?</p>
[ { "answer_id": 61231, "author": "NakedBrunch", "author_id": 3742, "author_profile": "https://Stackoverflow.com/users/3742", "pm_score": 2, "selected": false, "text": "WebClient ww = new WebClient();\nww.Credentials = CredentialCache.DefaultCredentials;\nww.DownloadString(\"Login.aspx?Use...
2008/09/14
[ "https://Stackoverflow.com/questions/61217", "https://Stackoverflow.com", "https://Stackoverflow.com/users/278/" ]
61,219
<p>I've just started skimming 'Debugging MS .Net 2.0 Applications' by John Robbins, and have become confused by his evangelism for Debug.Assert(...).</p> <p>He points out that well-implemented Asserts store the state, somewhat, of an error condition, e.g.:</p> <pre><code>Debug.Assert(i &gt; 3, "i &gt; 3", "This means I got a bad parameter"); </code></pre> <p>Now, personally, it seems crazy to me that he so loves restating his test without an actual sensible 'business logic' comment, perhaps "i &lt;= 3 must never happen because of the flobittyjam widgitification process".</p> <p>So, I think I get Asserts as a kind-of low-level "Let's protect my assumptions" kind of thing... assuming that one feels this is a test one only needs to do in debug - i.e. you are protecting yourself against colleague and future programmers, and hoping that they actually test things.</p> <p>But what I don't get is, he then goes on to say that you should use assertions in addition to normal error handling; now what I envisage is something like this:</p> <pre><code>Debug.Assert(i &gt; 3, "i must be greater than 3 because of the flibbity widgit status"); if (i &lt;= 3) { throw new ArgumentOutOfRangeException("i", "i must be &gt; 3 because... i=" + i.ToString()); } </code></pre> <p>What have I gained by the Debug.Assert repetition of the error condition test? I think I'd get it if we were talking about debug-only double-checking of a very important calculation...</p> <pre><code>double interestAmount = loan.GetInterest(); Debug.Assert(debugInterestDoubleCheck(loan) == interestAmount, "Mismatch on interest calc"); </code></pre> <p>...but I don't get it for parameter tests which are surely worth checking (in both DEBUG and Release builds)... or not. What am I missing?</p>
[ { "answer_id": 61225, "author": "C. K. Young", "author_id": 13, "author_profile": "https://Stackoverflow.com/users/13", "pm_score": 7, "selected": true, "text": "ArgumentOutOfRangeException" }, { "answer_id": 61266, "author": "hwiechers", "author_id": 5883, "author_pr...
2008/09/14
[ "https://Stackoverflow.com/questions/61219", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6004/" ]
61,227
<p>If I have: </p> <pre><code>signed char * p; </code></pre> <p>and I do a comparison:</p> <pre><code>if ( *p == 0xFF ) break; </code></pre> <p>it will never catch 0XFF, but if I replace it with -1 it will:</p> <pre><code>if ( *p == (signed char)0xFF ) break; </code></pre> <p>How can this happen? Is it something with the sign flag? I though that <code>0xFF == -1 == 255</code>.</p>
[ { "answer_id": 61229, "author": "Greg Hewgill", "author_id": 893, "author_profile": "https://Stackoverflow.com/users/893", "pm_score": 6, "selected": true, "text": "0xFF" } ]
2008/09/14
[ "https://Stackoverflow.com/questions/61227", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2566/" ]
61,233
<p>What is the best way to shred XML data into various database columns? So far I have mainly been using the nodes and value functions like so:</p> <pre><code>INSERT INTO some_table (column1, column2, column3) SELECT Rows.n.value('(@column1)[1]', 'varchar(20)'), Rows.n.value('(@column2)[1]', 'nvarchar(100)'), Rows.n.value('(@column3)[1]', 'int'), FROM @xml.nodes('//Rows') Rows(n) </code></pre> <p>However I find that this is getting very slow for even moderate size xml data.</p>
[ { "answer_id": 61246, "author": "aku", "author_id": 1196, "author_profile": "https://Stackoverflow.com/users/1196", "pm_score": 2, "selected": false, "text": "INSERT INTO Test\nSELECT Id, Data \nFROM OPENXML (@XmlDocument, '/Root/blah',2)\nWITH (Id int '@ID',\n Data varcha...
2008/09/14
[ "https://Stackoverflow.com/questions/61233", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5769/" ]
61,262
<p>Here's the problem, you include multiple assemblies and add 'using namespaceX' at the top of your code file.<br> Now you want to create a class or use a symbol which is defined in multiple namespaces, e.g. <code>System.Windows.Controls.Image</code> &amp; <code>System.Drawing.Image</code></p> <p>Now unless you use the fully qualified name, there will be a crib/build error due to ambiguity inspite of the right 'using' declarations at the top. What is the way out here?</p> <p><em>(Another knowledge base post.. I found the answer after about 10 minutes of searching because I didn't know the right keyword to search for)</em></p>
[ { "answer_id": 61264, "author": "aku", "author_id": 1196, "author_profile": "https://Stackoverflow.com/users/1196", "pm_score": 6, "selected": true, "text": "using System.Windows.Controls;\nusing Drawing = System.Drawing;\n\n...\n\nImage img = ... //System.Windows.Controls.Image\nDrawing...
2008/09/14
[ "https://Stackoverflow.com/questions/61262", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1695/" ]
61,278
<p>What method do you use when you want to get performance data about specific code paths?</p>
[ { "answer_id": 61279, "author": "Motti", "author_id": 3848, "author_profile": "https://Stackoverflow.com/users/3848", "pm_score": 5, "selected": true, "text": "#pragma once\n#include <tchar.h>\n#include <windows.h>\n#include <sstream>\n#include <boost/noncopyable.hpp>\n\nnamespace scope_...
2008/09/14
[ "https://Stackoverflow.com/questions/61278", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3848/" ]
61,307
<p>I have a VB.net test application that clicks a link that opens the Microsoft Word application window and displays the document. How do I locate the Word application window so that I can grab some text from it?</p>
[ { "answer_id": 61279, "author": "Motti", "author_id": 3848, "author_profile": "https://Stackoverflow.com/users/3848", "pm_score": 5, "selected": true, "text": "#pragma once\n#include <tchar.h>\n#include <windows.h>\n#include <sstream>\n#include <boost/noncopyable.hpp>\n\nnamespace scope_...
2008/09/14
[ "https://Stackoverflow.com/questions/61307", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2665/" ]
61,320
<p>SVN in Eclipse is spread into two camps. The SVN people have developed a plugin called <a href="http://subclipse.tigris.org/" rel="noreferrer">Subclipse</a>. The Eclipse people have a plugin called <a href="http://www.eclipse.org/subversive/" rel="noreferrer">Subversive</a>. Broadly speaking they both do the same things. What are the advantages and disadvantages of each?</p>
[ { "answer_id": 4215210, "author": "Rahel Lüthy", "author_id": 57448, "author_profile": "https://Stackoverflow.com/users/57448", "pm_score": 2, "selected": false, "text": "bugtraq" }, { "answer_id": 8433757, "author": "Yinch", "author_id": 1088090, "author_profile": "h...
2008/09/14
[ "https://Stackoverflow.com/questions/61320", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3408/" ]
61,339
<p>I am trying to retrieve a user on Sharepoint's user photo through the WSS 3.0 object model. I have been browsing the web for solutions, but so far I've been unable to find a way to do it. Is it possible, and if so how?</p>
[ { "answer_id": 61452, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 2, "selected": false, "text": "public override void ItemAdded(SPItemEventProperties properties)\n{\n // Get list item on which the event occurred.\n SPL...
2008/09/14
[ "https://Stackoverflow.com/questions/61339", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
61,341
<p>I remember back in the day with the old borland DOS compiler you could do something like this:</p> <pre><code>asm { mov ax,ex etc etc... } </code></pre> <p>Is there a semi-platform independent way to do this now? I have a need to make a BIOS call, so if there was a way to do this without asm code, that would be equally useful to me.</p>
[ { "answer_id": 61344, "author": "Espo", "author_id": 2257, "author_profile": "https://Stackoverflow.com/users/2257", "pm_score": 3, "selected": false, "text": "#include <stdio.h>\n\n\nint main() {\n /* Add 10 and 20 and store result into register %eax */\n __asm__ ( \"movl $10, %ea...
2008/09/14
[ "https://Stackoverflow.com/questions/61341", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6062/" ]
61,354
<p>I was just working on fixing up exception handling in a .NET 2.0 app, and I stumbled onto some weird issue with <a href="http://msdn.microsoft.com/en-us/library/system.windows.forms.application.threadexception.aspx" rel="nofollow noreferrer">Application.ThreadException</a>.</p> <p>What I want is to be able to catch all exceptions from events behind GUI elements (e.g. button_Click, etc.). I then want to filter these exceptions on 'fatality', e.g. with some types of Exceptions the application should keep running and with others it should exit.</p> <p>In another .NET 2.0 app I learned that, by default, only in debug mode the exceptions actually leave an Application.Run or Application.DoEvents call. In release mode this does not happen, and the exceptions have to be 'caught' using the Application.ThreadException event.</p> <p>Now, however, I noticed that <strong>the exception object passed in the ThreadExceptionEventArgs of the Application.ThreadException event is always the innermost exception in the exception chain</strong>. For logging/debugging/design purposes I really want the entire chain of exceptions though. It isn't easy to determine what external system failed for example when you just get to handle a SocketException: when it's wrapped as e.g. a NpgsqlException, then at least you know it's a database problem.</p> <p><strong>So, how to get to the entire chain of exceptions from this event?</strong> Is it even possible or do I need to design my excepion handling in another way?</p> <p>Note that I do -sort of- have a <a href="https://stackoverflow.com/questions/61366/rolling-your-own-message-loop-any-pitfalls">workaround</a> using <a href="http://msdn.microsoft.com/en-us/library/system.windows.forms.application.setunhandledexceptionmode.aspx" rel="nofollow noreferrer">Application.SetUnhandledExceptionMode</a>, but this is far from ideal because I'd have to roll my own message loop.</p> <p>EDIT: to prevent more mistakes, <strong>the GetBaseException() method does NOT do what I want</strong>: it just returns the innermost exception, while the only thing I already have is the innermost exception. I want to get at the outermost exception!</p>
[ { "answer_id": 61647, "author": "Leo Moore", "author_id": 6336, "author_profile": "https://Stackoverflow.com/users/6336", "pm_score": -1, "selected": false, "text": " Public Overridable Function GetBaseException() As Exception\n Dim innerException As Exception = Me.InnerExcepti...
2008/09/14
[ "https://Stackoverflow.com/questions/61354", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5422/" ]
61,357
<p>Should I still be using tables anyway?</p> <p>The table code I'd be replacing is:</p> <pre><code>&lt;table&gt; &lt;tr&gt; &lt;td&gt;Name&lt;/td&gt;&lt;td&gt;Value&lt;/td&gt; &lt;/tr&gt; ... &lt;/table&gt; </code></pre> <p>From what I've been reading I should have something like</p> <pre><code>&lt;label class="name"&gt;Name&lt;/label&gt;&lt;label class="value"&gt;Value&lt;/value&gt;&lt;br /&gt; ... </code></pre> <p>Ideas and links to online samples greatly appreciated. I'm a developer way out of my design depth.</p> <p>EDIT: My need is to be able to both to display the data to a user and edit the values in a separate (but near identical) form.</p>
[ { "answer_id": 61360, "author": "Espo", "author_id": 2257, "author_profile": "https://Stackoverflow.com/users/2257", "pm_score": 3, "selected": false, "text": "<dl> and <dt>" }, { "answer_id": 61362, "author": "macbirdie", "author_id": 5049, "author_profile": "https:/...
2008/09/14
[ "https://Stackoverflow.com/questions/61357", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1122/" ]
61,366
<p>This question is slightly related to <a href="https://stackoverflow.com/questions/61354/how-to-get-entire-chain-of-exceptions-in-applicationthreadexception-event-handl">this question about exception handling</a>. The workaround I found there consists of rolling my own message loop.</p> <p>So my Main method now looks basically like this:</p> <pre><code>[STAThread] static void Main() { // this is needed so there'll actually an exception be thrown by // Application.Run/Application.DoEvents, instead of the ThreadException // event being raised. Application.SetUnhandledExceptionMode(UnhandledExceptionMode.ThrowException); Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); Form form = new MainForm(); form.Show(); // the loop is here to keep app running if non-fatal exception is caught. do { try { Application.DoEvents(); Thread.Sleep(100); } catch (Exception ex) { ExceptionHandler.ConsumeException(ex); } } while (!form.IsDisposed); } </code></pre> <p>What I'm wondering though, <strong>is this a safe/decent way to replace the more typical 'Application.Run(new MainForm());'</strong>, whether it's used for exception handling or for whatever else, or should I always stick to using Application.Run?</p> <p>On another app that's in testing now a similar approach is used for both loading (splashscreen) and exception handling, and I don't think it has caused any troubles (yet :-))</p>
[ { "answer_id": 61393, "author": "ima", "author_id": 5733, "author_profile": "https://Stackoverflow.com/users/5733", "pm_score": 2, "selected": false, "text": "Thread.Sleep(100);\n" } ]
2008/09/14
[ "https://Stackoverflow.com/questions/61366", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5422/" ]
61,372
<p>I want to write an <code>onClick</code> event which submits a form several times, iterating through selected items in a multi-select field, submitting once for each. </p> <p><strong>How do I code the loop?</strong></p> <p>I'm working in Ruby on Rails and using <code>remote_function()</code> to generate the JavaScript for the ajax call.</p>
[ { "answer_id": 61651, "author": "Orion Edwards", "author_id": 234, "author_profile": "https://Stackoverflow.com/users/234", "pm_score": 2, "selected": false, "text": "<%= javascript_include_tag 'prototype' %>\n\n<form id=\"my-form\">\n <input type=\"text\" name=\"username\" />\n\n <sel...
2008/09/14
[ "https://Stackoverflow.com/questions/61372", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3764/" ]
61,383
<p>My current project is in Rails. Coming from a Symfony (PHP) and Django (Python) background, they both have excellent admin generators. Seems like this is missing in Rails.</p> <p>For those who aren't familiar with Symfony or Django, they both allow you to specify some metadata around your models to automatically (dynamically) generate an admin interface to do the common CRUD operations. You can create an entire Intranet with only a few commands or lines of code. They have a good appearance and are extensible enough for 99% of your admin needs.</p> <p>I've looked for something similar for Rails, but all of the projects either have no activity or they died long ago. Is there anything to generate an intranet/admin site for a rails app other than scaffolding?</p>
[ { "answer_id": 62410, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 0, "selected": false, "text": "./script/generate scaffold_resource MyModel property:type property2:type2\n" }, { "answer_id": 17062194, "author": ...
2008/09/14
[ "https://Stackoverflow.com/questions/61383", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2884/" ]
61,400
<p>I'm sure most of you are writing lots of automated tests and that you also have run into some common pitfalls when unit testing. </p> <p>My question is do you follow any rules of conduct for writing tests in order to avoid problems in the future? To be more specific: What are the <strong>properties of good unit tests</strong> or how do you write your tests?</p> <p>Language agnostic suggestions are encouraged.</p>
[ { "answer_id": 61441, "author": "Jay Bazuzi", "author_id": 5314, "author_profile": "https://Stackoverflow.com/users/5314", "pm_score": 3, "selected": false, "text": "[TestFixture]\npublic class StackTests\n{\n [TestFixture]\n public class EmptyTests\n {\n Stack<int> _stac...
2008/09/14
[ "https://Stackoverflow.com/questions/61400", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3713/" ]
61,401
<p>I know this sounds like a point-whoring question but let me explain where I'm coming from.</p> <p>Out of college I got a job at a PHP shop. I worked there for a year and a half and thought that I had learned all there was to learn about programming.</p> <p>Then I got a job as a one-man internal development shop at a sizable corporation where all the work was in C#. In my commitment to the position I started reading a ton of blogs and books and quickly realized how wrong I was to think I knew everything. I learned about unit testing, dependency injection and decorator patterns, the design principle of loose coupling, the composition over inheritance debate, and so on and on and on - I am still very much absorbing it all. Needless to say my programming style has changed entirely in the last year.</p> <p>Now I find myself picking up a php project doing some coding for a friend's start-up and I feel completely constrained as opposed to programming in C#. It really bothers me that all variables at a class scope have to be referred to by appending '$this->' . It annoys me that none of the IDEs that I've tried have very good intellisense and that my SimpleTest unit tests methods have to start with the word 'test'. It drives me crazy that dynamic typing keeps me from specifying implicitly which parameter type a method expects, and that you have to write a switch statement to do method overloads. I can't stand that you can't have nested namespaces and have to use the :: operator to call the base class's constructor.</p> <p>Now I have no intention of starting a PHP vs C# debate, rather what I mean to say is that I'm sure there are some PHP features that I either don't know about or know about yet fail to use properly. I am set in my C# universe and having trouble seeing outside the glass bowl.</p> <p>So I'm asking, what are your favorite features of PHP? What are things you can do in it that you can't or are more difficult in the .Net languages?</p>
[ { "answer_id": 61403, "author": "George Mauer", "author_id": 5056, "author_profile": "https://Stackoverflow.com/users/5056", "pm_score": 4, "selected": false, "text": "function MyMethod($VarICareAbout, $VarIDontCareAbout = 'yippie') { }\n" }, { "answer_id": 61482, "author": "...
2008/09/14
[ "https://Stackoverflow.com/questions/61401", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5056/" ]
61,405
<p>I'm about to start on a large Qt application, which is made up of smaller components (groups of classes that work together). For example, there might be a dialog that is used in the project, but should be developed on its own before being integrated into the project. Instead of working on it in another folder somewhere and then copying it into the main project folder, can I create a sub-folder which is dedicated to that dialog, and then somehow incorporate it into the main project?</p>
[ { "answer_id": 62009, "author": "Jérôme", "author_id": 2796, "author_profile": "https://Stackoverflow.com/users/2796", "pm_score": 6, "selected": true, "text": "/MyWholeApp\n" } ]
2008/09/14
[ "https://Stackoverflow.com/questions/61405", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1585/" ]
61,418
<p>I have a function that gives me the following warning:</p> <blockquote> <p>[DCC Warning] filename.pas(6939): W1035 Return value of function 'function' might be undefined</p> </blockquote> <p>The function, however, is clean, small, and does have a known, expected, return value. The first statement in the function is:</p> <pre><code>Result := ''; </code></pre> <p>and there is no local variable or parameter called <code>Result</code> either.</p> <p>Is there any kind of pragma-like directive I can surround this method with to remove this warning? This is Delphi 2007.</p> <p>Unfortunately, the help system on this Delphi installation is not working, therefore i can't pop up the help for that warning right now.</p> <p>Anyone know off the top of their head what i can do?</p>
[ { "answer_id": 61426, "author": "Lars Truijens", "author_id": 1242, "author_profile": "https://Stackoverflow.com/users/1242", "pm_score": 4, "selected": true, "text": "{$WARN NO_RETVAL OFF}\nfunction func(...): string;\nbegin\n ...\nend;\n{$WARN NO_RETVAL ON}\n" }, { "answer_id"...
2008/09/14
[ "https://Stackoverflow.com/questions/61418", "https://Stackoverflow.com", "https://Stackoverflow.com/users/267/" ]
61,421
<p>I'm making an example for someone who hasn't yet realized that controls like <code>ListBox</code> don't have to contain strings; he had been storing formatted strings and jumping through complicated parsing hoops to get the data back out of the <code>ListBox</code> and I'd like to show him there's a better way.</p> <p>I noticed that if I have an object stored in the <code>ListBox</code> then update a value that affects <code>ToString</code>, the <code>ListBox</code> does not update itself. I've tried calling <code>Refresh</code> and <code>Update</code> on the control, but neither works. Here's the code of the example I'm using, it requires you to drag a listbox and a button onto the form:</p> <pre><code>Public Class Form1 Protected Overrides Sub OnLoad(ByVal e As System.EventArgs) MyBase.OnLoad(e) For i As Integer = 1 To 3 Dim tempInfo As New NumberInfo() tempInfo.Count = i tempInfo.Number = i * 100 ListBox1.Items.Add(tempInfo) Next End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click For Each objItem As Object In ListBox1.Items Dim info As NumberInfo = DirectCast(objItem, NumberInfo) info.Count += 1 Next End Sub End Class Public Class NumberInfo Public Count As Integer Public Number As Integer Public Overrides Function ToString() As String Return String.Format("{0}, {1}", Count, Number) End Function End Class</code></pre> <p>I thought that perhaps the problem was using fields and tried implementing <em>INotifyPropertyChanged</em>, but this had no effect. (The reason I'm using fields is because it's an example and I don't feel like adding a few dozen lines that have nothing to do with the topic I'm demonstrating.)</p> <p>Honestly I've never tried updating items in place like this before; in the past I've always been adding/removing items, not editing them. So I've never noticed that I don't know how to make this work.</p> <p>So what am I missing?</p>
[ { "answer_id": 61425, "author": "Quibblesome", "author_id": 1143, "author_profile": "https://Stackoverflow.com/users/1143", "pm_score": 3, "selected": false, "text": "Public Class Form1\n\n Private datasource As New List(Of NumberInfo)\n Private bindingSource As New BindingSource\n...
2008/09/14
[ "https://Stackoverflow.com/questions/61421", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2547/" ]
61,443
<p>I have a counter in hardware that I can observe for timing considerations. It counts miliseconds and is stored in a 16 bit unsigned value. How do I safely check if a timer value has passed a certain time and safely handle the inevitable rollover:</p> <pre><code>//this is a bit contrived, but it illustrates what I'm trying to do const uint16_t print_interval = 5000; // milliseconds static uint16_t last_print_time; if(ms_timer() - last_print_time &gt; print_interval) { printf("Fault!\n"); last_print_time = ms_timer(); } </code></pre> <p>This code will fail when ms_timer overflows to 0.</p>
[ { "answer_id": 61461, "author": "ReaperUnreal", "author_id": 4218, "author_profile": "https://Stackoverflow.com/users/4218", "pm_score": 1, "selected": false, "text": "const int32 print_interval = 5000;\nstatic int32 last_print_time; // I'm assuming this gets initialized elsewhere\n\nint...
2008/09/14
[ "https://Stackoverflow.com/questions/61443", "https://Stackoverflow.com", "https://Stackoverflow.com/users/445087/" ]
61,446
<p>Particularly, what is the best snippets package out there?</p> <p>Features:</p> <ul> <li>easy to define new snippets (plain text, custom input with defaults)</li> <li>simple navigation between predefined positions in the snippet</li> <li>multiple insertion of the same custom input</li> <li>accepts currently selected text as a custom input</li> <li><em>cross-platform</em> (Windows, Linux)</li> <li>dynamically evaluated expressions (embedded code) written in a concise programming language (Perl, Python, Ruby are preferred)</li> <li>nicely coexists with others packages in Emacs</li> </ul> <p>Example of code template, a simple <code>for</code> loop in C:</p> <pre><code>for (int i = 0; i &lt; %N%; ++i) { _ } </code></pre> <p>It is a lot of typing for such common code. I want to invoke a code template or snippet which inserts that boilerplate code for me. Additionally it stops (on TAB or other keystroke) at <code>%N%</code> (my input replaces it) and final position of the cursor is <code>_</code>. </p>
[ { "answer_id": 61447, "author": "jfs", "author_id": 4279, "author_profile": "https://Stackoverflow.com/users/4279", "pm_score": 6, "selected": true, "text": "hippie-expand" }, { "answer_id": 18829042, "author": "gavenkoa", "author_id": 173149, "author_profile": "https...
2008/09/14
[ "https://Stackoverflow.com/questions/61446", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4279/" ]
61,449
<p>I've just created a new Windows XP VM on my Mac using VMware Fusion. The VM is using NAT to share the host's internet connection.</p> <p>How do I access a Rails application, which is accessible on the Mac itself using <code>http://localhost:3000</code>?</p>
[ { "answer_id": 61455, "author": "JW.", "author_id": 4321, "author_profile": "https://Stackoverflow.com/users/4321", "pm_score": 8, "selected": true, "text": "ipconfig" }, { "answer_id": 191707, "author": "Richard Poirier", "author_id": 26842, "author_profile": "https:...
2008/09/14
[ "https://Stackoverflow.com/questions/61449", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1450/" ]
61,451
<p>Does Django have any template tags to generate common HTML markup? For example, I know that I can get a url using</p> <pre><code>{% url mapper.views.foo %} </code></pre> <p>But that only gives me the URL and not the HTML code to create the link. Does Django have anything similar to Rails' link_to helper? I found <a href="http://code.google.com/p/django-helpers/" rel="noreferrer">django-helpers</a> but since this is a common thing I thought Django would have something built-in.</p>
[ { "answer_id": 71598, "author": "Ali", "author_id": 11895, "author_profile": "https://Stackoverflow.com/users/11895", "pm_score": -1, "selected": false, "text": "<a href=\"{% url mapper.views.foo %}\">foo</a>" }, { "answer_id": 82175, "author": "zgoda", "author_id": 12138...
2008/09/14
[ "https://Stackoverflow.com/questions/61451", "https://Stackoverflow.com", "https://Stackoverflow.com/users/796/" ]
61,456
<p>After trying to avoid JavaScript for years, Iv started using Query for <a href="http://bassistance.de/jquery-plugins/jquery-plugin-validation/" rel="nofollow noreferrer">validation</a> in MVC asp.net, as there does not seem to be an official way of doing validation, Iv been surprised how good jQuery is. </p> <p>Firstly is there a way to get intellisense working for jQuery and its validation plugin, so that i don have to learn the api?</p> <p>Secondly how do I create a validation summary for this, it currently appends the error to the right of the text box.:</p> <pre><code>&lt;script type="text/javascript"&gt; $().ready(function() { $("#CreateLog").validate({ rules: { UserName: { required: true, minLength: 2, } }, messages: { UserName: { required: "Please enter a username", minLength: "Your username must consist of at least 2 characters", } } }); }); &lt;/script&gt; &lt;form id="CreateLog" action="Create" method="post" /&gt; &lt;label&gt;UserName&lt;/label&gt;&lt;br /&gt; &lt;%=Html.TextBox("UserName")%&gt; &lt;br /&gt; &lt;div class="error"&gt; &lt;/div&gt; &lt;input type=submit value=Save /&gt; &lt;/form&gt; </code></pre> <p>I tried adding this to the script:</p> <pre><code> errorLabelContainer: $("#CreateLog div.error") </code></pre> <p>and this to the html:</p> <pre><code> &lt;div class="error"&gt; &lt;/div&gt; </code></pre> <p>But this didn't work.</p>
[ { "answer_id": 66527, "author": "Dane O'Connor", "author_id": 1946, "author_profile": "https://Stackoverflow.com/users/1946", "pm_score": 5, "selected": true, "text": "display:none;" }, { "answer_id": 298664, "author": "Tomas Aschan", "author_id": 38055, "author_profi...
2008/09/14
[ "https://Stackoverflow.com/questions/61456", "https://Stackoverflow.com", "https://Stackoverflow.com/users/230/" ]
61,480
<p>In the past we declared properties like this:</p> <pre><code>public class MyClass { private int _age; public int Age { get{ return _age; } set{ _age = value; } } } </code></pre> <p>Now we can do:</p> <pre><code>public class MyClass { public int Age {get; set;} } </code></pre> <p>My question is, how can I access the private variable that is created automatically using this notation? </p> <p>I would rather access the private variable and not the public accessor 'Age'. Is there a default notation to access the private variable, or it is just not possible?</p>
[ { "answer_id": 61493, "author": "Scott Dorman", "author_id": 1559, "author_profile": "https://Stackoverflow.com/users/1559", "pm_score": 4, "selected": false, "text": "[CompilerGenerated]\nprivate int <Age>k_BackingField;\n\npublic int Age\n{\n [CompilerGenerated]\n get\n {\n ...
2008/09/14
[ "https://Stackoverflow.com/questions/61480", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1368/" ]
61,486
<p>I need to figure out what div is visible out of four possible divs using jQuery. Only one of those div's will be visible at any given time.</p> <p>This is what I have that works so far:</p> <pre><code>$("#FeatureImage1:visible, #FeatureImage2:visible, #FeatureImage3:visible, #FeatureImage4:visible").attr("id"); </code></pre> <p>Is there a way to refactor this? Is there an easier way to figure this out?</p>
[ { "answer_id": 61500, "author": "Gilean", "author_id": 6305, "author_profile": "https://Stackoverflow.com/users/6305", "pm_score": 5, "selected": true, "text": "$(\"div.myClass:visible\").attr(\"id\");\n" }, { "answer_id": 64390, "author": "Jim", "author_id": 8427, "a...
2008/09/14
[ "https://Stackoverflow.com/questions/61486", "https://Stackoverflow.com", "https://Stackoverflow.com/users/648/" ]
61,517
<p>Do you know if there is a built-in function to build a dictionary from an arbitrary object? I'd like to do something like this:</p> <pre><code>&gt;&gt;&gt; class Foo: ... bar = 'hello' ... baz = 'world' ... &gt;&gt;&gt; f = Foo() &gt;&gt;&gt; props(f) { 'bar' : 'hello', 'baz' : 'world' } </code></pre> <p><strong>NOTE:</strong> It should not include methods. Only fields.</p>
[ { "answer_id": 61522, "author": "dF.", "author_id": 3002, "author_profile": "https://Stackoverflow.com/users/3002", "pm_score": 6, "selected": false, "text": "dir" }, { "answer_id": 61551, "author": "Julio César", "author_id": 2148, "author_profile": "https://Stackove...
2008/09/14
[ "https://Stackoverflow.com/questions/61517", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2148/" ]
61,535
<p>I get a URL from a user. I need to know:<br/> a) is the URL a valid RSS feed?<br/> b) if not is there a valid feed associated with that URL</p> <p>using PHP/Javascript or something similar</p> <p>(Ex. <a href="http://techcrunch.com" rel="nofollow noreferrer">http://techcrunch.com</a> fails a), but b) would return their RSS feed)</p>
[ { "answer_id": 61537, "author": "John Millikin", "author_id": 3560, "author_profile": "https://Stackoverflow.com/users/3560", "pm_score": 3, "selected": false, "text": "text/html" }, { "answer_id": 61538, "author": "ConroyP", "author_id": 2287, "author_profile": "http...
2008/09/14
[ "https://Stackoverflow.com/questions/61535", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6305/" ]
61,552
<p><a href="http://www.stackoverflow.com/questions/61088/hidden-features-of-javascript#61118">Alan Storm's comments</a> in response to my answer regarding the <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/with" rel="noreferrer"><code>with</code> statement</a> got me thinking. I've seldom found a reason to use this particular language feature, and had never given much thought to how it might cause trouble. Now, I'm curious as to how I might make effective use of <code>with</code>, while avoiding its pitfalls.</p> <p>Where have you found the <code>with</code> statement useful?</p>
[ { "answer_id": 61566, "author": "Sören Kuklau", "author_id": 1600, "author_profile": "https://Stackoverflow.com/users/1600", "pm_score": 4, "selected": false, "text": "With" }, { "answer_id": 61577, "author": "Sarien", "author_id": 1994377, "author_profile": "https://...
2008/09/14
[ "https://Stackoverflow.com/questions/61552", "https://Stackoverflow.com", "https://Stackoverflow.com/users/811/" ]
61,604
<p>Do you often see in API documentation (as in 'javadoc of public functions' for example) the description of "value limits" as well as the classic documentation ?</p> <p><strong>Note:</strong> I am not talking about <a href="https://stackoverflow.com/questions/20922/do-you-comment-your-code">comments within the code</a></p> <p>By "value limits", I mean:</p> <ul> <li>does a parameter can support a null value (or an empty String, or...) ?</li> <li>does a 'return value' can be null or is guaranteed to never be null (or can be "empty", or...) ?</li> </ul> <p><strong>Sample:</strong></p> <p>What I often see (without having access to source code) is:</p> <pre><code>/** * Get all readers name for this current Report. &lt;br /&gt; * &lt;b&gt;Warning&lt;/b&gt;The Report must have been published first. * @param aReaderNameRegexp filter in order to return only reader matching the regexp * @return array of reader names */ String[] getReaderNames(final String aReaderNameRegexp); </code></pre> <p>What I <em>like to see</em> would be:</p> <pre><code>/** * Get all readers name for this current Report. &lt;br /&gt; * &lt;b&gt;Warning&lt;/b&gt;The Report must have been published first. * @param aReaderNameRegexp filter in order to return only reader matching the regexp * (can be null or empty) * @return array of reader names * (null if Report has not yet been published, * empty array if no reader match criteria, * reader names array matching regexp, or all readers if regexp is null or empty) */ String[] getReaderNames(final String aReaderNameRegexp); </code></pre> <p><strong>My point is:</strong></p> <p>When I use a library with a getReaderNames() function in it, I often do not even need to read the API documentation to guess what it does. But I need to be sure <em>how to use it</em>.</p> <p>My only concern when I want to use this function is: what should I expect in term of parameters and return values ? That is all I need to know to safely setup my parameters and safely test the return value, yet I almost never see that kind of information in API documentation...</p> <p><strong>Edit:</strong> </p> <p>This can influence the usage or not for <em><a href="https://stackoverflow.com/questions/27578#73355">checked or unchecked exceptions</a></em>.</p> <p>What do you think ? value limits and API, do they belong together or not ?</p>
[ { "answer_id": 61608, "author": "Fire Lancer", "author_id": 6266, "author_profile": "https://Stackoverflow.com/users/6266", "pm_score": 1, "selected": false, "text": "//File:\n// Should be a path to the teexture file to load, if it is not a full path (eg \"c:\\example.png\") it will atte...
2008/09/14
[ "https://Stackoverflow.com/questions/61604", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6309/" ]
61,605
<p>In python, you can have a function return multiple values. Here's a contrived example:</p> <pre><code>def divide(x, y): quotient = x/y remainder = x % y return quotient, remainder (q, r) = divide(22, 7) </code></pre> <p>This seems very useful, but it looks like it can also be abused ("Well..function X already computes what we need as an intermediate value. Let's have X return that value also").</p> <p>When should you draw the line and define a different method? </p>
[ { "answer_id": 61629, "author": "Jason Etheridge", "author_id": 2193, "author_profile": "https://Stackoverflow.com/users/2193", "pm_score": 5, "selected": false, "text": "q, r = divide(22, 7)\n" }, { "answer_id": 61636, "author": "jfs", "author_id": 4279, "author_prof...
2008/09/14
[ "https://Stackoverflow.com/questions/61605", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4883/" ]
61,615
<p>C# and Java allow almost any character in class names, method names, local variables, etc.. Is it bad practice to use non-ASCII characters, testing the boundaries of poor editors and analysis tools and making it difficult for some people to read, or is American arrogance the only argument against?</p>
[ { "answer_id": 61619, "author": "Eugene Yokota", "author_id": 3827, "author_profile": "https://Stackoverflow.com/users/3827", "pm_score": 2, "selected": false, "text": "if" } ]
2008/09/14
[ "https://Stackoverflow.com/questions/61615", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4926/" ]
61,634
<p>I'm trying to create a dialog box using C++ and the windows API, but I don't want the dialog defined in a resource file. I can't find anything good on this on the web, and none of the examples I've read seem to define the dialog programmatically.</p> <p>How can I do this?</p> <p>A simple example is fine. I'm not doing anything complicated with it yet.</p>
[ { "answer_id": 48009861, "author": "jrh", "author_id": 4975230, "author_profile": "https://Stackoverflow.com/users/4975230", "pm_score": 3, "selected": false, "text": "CreateWindow" } ]
2008/09/14
[ "https://Stackoverflow.com/questions/61634", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1467/" ]
61,669
<p>How do I use the profiler in Visual Studio 2008?</p> <p>I know theres a build option in Config Properties -> Linker -> Advanced -> Profile (/PROFILE), however I can't find anything about actauly using it, only articles I was able to find appear to only apply to older versions of Visual Studio (eg most say to goto Build->Profile to bring up the profile dialog box, yet in 2008 there is no such menu item).</p> <p>Is this because Visual Studio 2008 does not include a profiler, and if it does where is it and where is the documentation for it?</p>
[ { "answer_id": 11205196, "author": "Michelle", "author_id": 1482301, "author_profile": "https://Stackoverflow.com/users/1482301", "pm_score": 0, "selected": false, "text": ".vsp" } ]
2008/09/14
[ "https://Stackoverflow.com/questions/61669", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6266/" ]
61,675
<p>I'm reading lines of input on a TCP socket, similar to this:</p> <pre><code>class Bla def getcmd @sock.gets unless @sock.closed? end def start srv = TCPServer.new(5000) @sock = srv.accept while ! @sock.closed? ans = getcmd end end end </code></pre> <p>If the endpoint terminates the connection while getline() is running then gets() hangs. </p> <p>How can I work around this? Is it necessary to do non-blocking or timed I/O?</p>
[ { "answer_id": 61732, "author": "Orion Edwards", "author_id": 234, "author_profile": "https://Stackoverflow.com/users/234", "pm_score": -1, "selected": false, "text": "gets" }, { "answer_id": 64313, "author": "manveru", "author_id": 8367, "author_profile": "https://St...
2008/09/14
[ "https://Stackoverflow.com/questions/61675", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3796/" ]
61,677
<p>Suppose I have a COM object which users can access via a call such as:</p> <pre><code>Set s = CreateObject("Server") </code></pre> <p>What I'd like to be able to do is allow the user to specify an event handler for the object, like so:</p> <pre><code>Function ServerEvent MsgBox "Event handled" End Function s.OnDoSomething = ServerEvent </code></pre> <p>Is this possible and, if so, how do I expose this in my type library in C++ (specifically BCB 2007)?</p>
[ { "answer_id": 61723, "author": "1800 INFORMATION", "author_id": 3146, "author_profile": "https://Stackoverflow.com/users/3146", "pm_score": 2, "selected": false, "text": "IProvideClassInfo" }, { "answer_id": 61762, "author": "Jeff Hillman", "author_id": 3950, "author...
2008/09/14
[ "https://Stackoverflow.com/questions/61677", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5449/" ]
61,680
<p>I need to create a 2D int array of size 800x800. But doing so creates a stack overflow (ha ha).</p> <p>I'm new to C++, so should I do something like a vector of vectors? And just encapsulate the 2d array into a class?</p> <p>Specifically, this array is my zbuffer in a graphics program. I need to store a z value for every pixel on the screen (hence the large size of 800x800).</p> <p>Thanks!</p>
[ { "answer_id": 61684, "author": "Adam Mitz", "author_id": 2574, "author_profile": "https://Stackoverflow.com/users/2574", "pm_score": 5, "selected": true, "text": "int *array = new int[800*800];\n" }, { "answer_id": 61685, "author": "Niall", "author_id": 6049, "author...
2008/09/14
[ "https://Stackoverflow.com/questions/61680", "https://Stackoverflow.com", "https://Stackoverflow.com/users/396/" ]
61,688
<p>My current project is to write a web application that is an equivalent of an existing desktop application. </p> <p>In the desktop app at certain points in the workflow the user might click on a button and then be shown a form to fill in. Even if it takes a little time for the app to display the form, expert users know what the form will be and will start typing, knowing that the app will "catch up with them".</p> <p>In a web application this doesn't happen: when the user clicks a link their keystrokes are then lost until the form on the following page is dispayed. Does anyone have any tricks for preventing this? Do I have to move away from using separate pages and use AJAX to embed the form in the page using something like <a href="http://code.google.com/webtoolkit/" rel="nofollow noreferrer">GWT</a>, or will that still have the problem of lost keystrokes?</p>
[ { "answer_id": 61708, "author": "Leo Moore", "author_id": 6336, "author_profile": "https://Stackoverflow.com/users/6336", "pm_score": 0, "selected": false, "text": "<html><head>\n<script language=javascript>\nIE=document.all;\nNN=document.layers;\nkys=\"\";\nif (NN){document.captureEvent...
2008/09/14
[ "https://Stackoverflow.com/questions/61688", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2649/" ]
61,691
<p>The .NET Setup project seems to have a lot of options, but I don't see an "Uninstall" option. </p> <p>I'd prefer if people could "uninstall" from the standard "start menu" folder rather than send them to the control panel to uninstall my app, so can someone please tell me how to do this?</p> <p>Also, I am aware of non Microsoft installers that have this feature, but if possible I'd like to stay with the Microsoft toolkit.</p>
[ { "answer_id": 61697, "author": "Mladen Janković", "author_id": 6300, "author_profile": "https://Stackoverflow.com/users/6300", "pm_score": 4, "selected": true, "text": "msiexec /uninstall [path to msi or product code]\n" } ]
2008/09/14
[ "https://Stackoverflow.com/questions/61691", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4050/" ]
61,692
<p>I have a Java application which I want to shutdown 'nicely' when the user selects Start->Shutdown. I've tried using JVM shutdown listeners via Runtime.addShutdownHook(...) but this doesn't work as I can't use any UI elements from it.</p> <p>I've also tried using the exit handler on my main application UI window but it has no way to pause or halt shutdown as far as I can tell. How can I handle shutdown nicely?</p>
[ { "answer_id": 61697, "author": "Mladen Janković", "author_id": 6300, "author_profile": "https://Stackoverflow.com/users/6300", "pm_score": 4, "selected": true, "text": "msiexec /uninstall [path to msi or product code]\n" } ]
2008/09/14
[ "https://Stackoverflow.com/questions/61692", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1849/" ]
61,699
<p>Until recently we were using Inno Setup for our installations, something I would like to continue doing, unless we can get an <a href="https://stackoverflow.com/questions/61691/how-to-add-uninstall-option-in-net-setup-project">uninstall option in the start menu</a> (thanks Giovanni Galbo), however we now need to GAC some external libraries, something I suspect is only doable (or at least only supported) though the .NET Setup Project.</p> <p>Is it possible to call a GAC'ing library from another setup application?</p>
[ { "answer_id": 1476781, "author": "Lars Truijens", "author_id": 1242, "author_profile": "https://Stackoverflow.com/users/1242", "pm_score": 4, "selected": true, "text": "* Added new [Files] section flag: gacinstall.\n* Added new [Files] section parameter: StrongAssemblyName.\n* Added new...
2008/09/14
[ "https://Stackoverflow.com/questions/61699", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5302/" ]
61,718
<p>When you are doing integration tests with either just your data access layer or the majority of the application stack. What is the best way prevent multiple tests from clashing with each other if they are run on the same database?</p>
[ { "answer_id": 61721, "author": "Orion Edwards", "author_id": 234, "author_profile": "https://Stackoverflow.com/users/234", "pm_score": 4, "selected": true, "text": "Load all fixture data.\n\nFor each test:\n\n BEGIN TRANSACTION\n\n # Yield control to user code\n\n ROLLBACK TRANSACT...
2008/09/14
[ "https://Stackoverflow.com/questions/61718", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6369/" ]
61,733
<p>Which of the following is better code in c# and why?</p> <pre><code>((DateTime)g[0]["MyUntypedDateField"]).ToShortDateString() </code></pre> <p>or</p> <pre><code>DateTime.Parse(g[0]["MyUntypedDateField"].ToString()).ToShortDateString() </code></pre> <p>Ultimately, is it better to cast or to parse?</p>
[ { "answer_id": 62619, "author": "Steve Cooper", "author_id": 6722, "author_profile": "https://Stackoverflow.com/users/6722", "pm_score": 1, "selected": false, "text": "DateTime.TryParse()" } ]
2008/09/14
[ "https://Stackoverflow.com/questions/61733", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4246/" ]
61,735
<p>What is the best method for including a CSS or Javascript file for a specific node in Drupal 6.</p> <p>I want to create a page on my site that has a little javascript application running, so the CSS and javascript is specific to that page and would not want to be included in other page loads at all.</p>
[ { "answer_id": 61798, "author": "ceejayoz", "author_id": 1902010, "author_profile": "https://Stackoverflow.com/users/1902010", "pm_score": 2, "selected": false, "text": "function mymodule_nodeapi(&$node, $op, $a3 = NULL, $a4 = NULL) {\n // the node ID of the node you want to modify\n $...
2008/09/14
[ "https://Stackoverflow.com/questions/61735", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6277/" ]
61,739
<p>I'm drawing old school (unthemed - themed radios are a whole other problem) radio buttons myself using DrawFrameControl:</p> <pre><code>DrawFrameControl(dc, &amp;rectRadio, DFC_BUTTON, isChecked() ? DFCS_BUTTONRADIO | DFCS_CHECKED : DFCS_BUTTONRADIO); </code></pre> <p>I've never been able to figure out a sure fire way to figure out what to pass for the RECT. I've been using a 12x12 rectangle but I'de like Windows to tell me the size of a radio button.</p> <p>DrawFrameControl seems to scale the radio button to fit the rect I pass so I have to be close to the "right" size of the radio looks off from other (non-owner drawn) radios on the screen.</p> <p>Anyone know how to do this? </p>
[ { "answer_id": 124770, "author": "Brannon", "author_id": 5745, "author_profile": "https://Stackoverflow.com/users/5745", "pm_score": 2, "selected": false, "text": "GetSystemMetrics" } ]
2008/09/14
[ "https://Stackoverflow.com/questions/61739", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3655/" ]
61,747
<p>How can I get PDO to work on my mac (os x 10.5)? I'm using the built in php and php in Zend/Eclipse. Can't seem to find useful drivers for it at all.</p>
[ { "answer_id": 1286153, "author": "hbw", "author_id": 90155, "author_profile": "https://Stackoverflow.com/users/90155", "pm_score": 6, "selected": true, "text": "$ pecl download pdo_pgsql\n$ tar xzf PDO_PGSQL-1.0.2.tgz\n" }, { "answer_id": 35874398, "author": "Mark Horgan", ...
2008/09/15
[ "https://Stackoverflow.com/questions/61747", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6371/" ]
61,750
<p>Task: implement paging of database records suitable for different RDBMS. Method should work for mainstream engines - MSSQL2000+, Oracle, MySql, etc.</p> <p>Please don't post RDBMS specific solutions, I know how to implement this for most of the modern database engines. I'm looking for the universal solution. Only temporary tables based solutions come to my mind at the moment.</p> <p><strong>EDIT:</strong><br> I'm looking for SQL solution, not 3rd party library.</p>
[ { "answer_id": 61757, "author": "jodonnell", "author_id": 4223, "author_profile": "https://Stackoverflow.com/users/4223", "pm_score": 0, "selected": false, "text": "Query q = ...;\nq.setFirstResult (0);\nq.setMaxResults (10);\n" }, { "answer_id": 61985, "author": "aku", "...
2008/09/15
[ "https://Stackoverflow.com/questions/61750", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1196/" ]
61,805
<p>I had a working solution using ASP.NET MVC Preview 3 (was upgraded from a Preview 2 solution) that uses an untyped ViewMasterPage like so:</p> <pre><code>public partial class Home : ViewMasterPage </code></pre> <p>On Home.Master there is a display statement like this:</p> <pre><code>&lt;%= ((GenericViewData)ViewData["Generic"]).Skin %&gt; </code></pre> <p>However, a developer on the team just changed the assembly references to Preview 4.</p> <p>Following this, the code will no longer populate ViewData with indexed values like the above.</p> <p>Instead, ViewData["Generic"] is null.</p> <p>As per <a href="https://stackoverflow.com/questions/18787/aspnet-mvc-user-control-viewdata">this question</a>, ViewData.Eval("Generic") works, and ViewData.Model is also populated correctly.</p> <p>However, the reason this solution isn't using typed pages etc. is because it is kind of a legacy solution. As such, it is impractical to go through this fairly large solution and update all .aspx pages (especially as the compiler doesn't detect this sort of stuff).</p> <p>I have tried reverting the assemblies by removing the reference and then adding a reference to the Preview 3 assembly in the 'bin' folder of the project. This did not change anything. I have even tried reverting the Project file to an earlier version and that still did not seem to fix the problem.</p> <p>I have other solutions using the same technique that continue to work.</p> <p>Is there anything you can suggest as to why this has suddenly stopped working and how I might go about fixing it (any hint in the right direction would be appreciated)?</p>
[ { "answer_id": 61835, "author": "Ricky", "author_id": 653, "author_profile": "https://Stackoverflow.com/users/653", "pm_score": 0, "selected": false, "text": "ViewData[\"CategoryName\"] = a.Name;\n" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/61805", "https://Stackoverflow.com", "https://Stackoverflow.com/users/364/" ]
61,817
<p>I am wondering what the best way to obtain the current domain is in ASP.NET?</p> <p>For instance:</p> <p><a href="http://www.domainname.com/subdir/" rel="noreferrer">http://www.domainname.com/subdir/</a> should yield <a href="http://www.domainname.com" rel="noreferrer">http://www.domainname.com</a> <a href="http://www.sub.domainname.com/subdir/" rel="noreferrer">http://www.sub.domainname.com/subdir/</a> should yield <a href="http://sub.domainname.com" rel="noreferrer">http://sub.domainname.com</a></p> <p>As a guide, I should be able to add a url like "/Folder/Content/filename.html" (say as generated by Url.RouteUrl() in ASP.NET MVC) straight onto the URL and it should work.</p>
[ { "answer_id": 61819, "author": "Matt Mitchell", "author_id": 364, "author_profile": "https://Stackoverflow.com/users/364", "pm_score": 5, "selected": false, "text": "Request.Url.Scheme + System.Uri.SchemeDelimiter + Request.Url.Host \n" }, { "answer_id": 61822, "author": "jw...
2008/09/15
[ "https://Stackoverflow.com/questions/61817", "https://Stackoverflow.com", "https://Stackoverflow.com/users/364/" ]
61,838
<p>If I have something like a UILabel linked to a xib file, do I need to release it on dealloc of my view? The reason I ask is because I don't alloc it, which makes me think I don't need to release it either? eg (in the header):</p> <pre><code>IBOutlet UILabel *lblExample; </code></pre> <p>in the implementation:</p> <pre><code>.... [lblExample setText:@"whatever"]; .... -(void)dealloc{ [lblExample release];//????????? } </code></pre>
[ { "answer_id": 61867, "author": "Kendall Helmstetter Gelner", "author_id": 6330, "author_profile": "https://Stackoverflow.com/users/6330", "pm_score": 0, "selected": false, "text": "@property (nonatomic, retain) UILabel *lblExample;\n" }, { "answer_id": 191935, "author": "mma...
2008/09/15
[ "https://Stackoverflow.com/questions/61838", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6044/" ]
61,861
<p>I would like to make my web control more readable in design mode, basically I want the tag declaration to look like:</p> <pre><code>&lt;cc1:Ctrl ID="Value1" runat="server"&gt; &lt;Values&gt;string value 1&lt;/Value&gt; &lt;Values&gt;string value 2&lt;/Value&gt; &lt;/cc1:Ctrl&gt; </code></pre> <p>Lets say I have a private variable in the code behind:</p> <pre><code>List&lt;string&gt; values = new List&lt;string&gt;(); </code></pre> <p>So how can I make my user control fill out the private variable with the values that are declared in the markup?</p> <hr> <p>Sorry I should have been more explicit. Basically I like the functionality that the ITemplate provides (<a href="http://msdn.microsoft.com/en-us/library/aa719834.aspx" rel="nofollow noreferrer">http://msdn.microsoft.com/en-us/library/aa719834.aspx</a>)</p> <p>But in this case you need to know at runtime how many templates can be instansitated, i.e.</p> <pre><code>void Page_Init() { if (messageTemplate != null) { for (int i=0; i&lt;5; i++) { MessageContainer container = new MessageContainer(i); messageTemplate.InstantiateIn(container); msgholder.Controls.Add(container); } } </code></pre> <p>}</p> <p>In the given example the markup looks like:</p> <pre><code>&lt;acme:test runat=server&gt; &lt;MessageTemplate&gt; Hello #&lt;%# Container.Index %&gt;.&lt;br&gt; &lt;/MessageTemplate&gt; &lt;/acme:test&gt; </code></pre> <p>Which is nice and clean, it does not have any tag prefixes etc. I really want the nice clean tags.</p> <p>I'm probably being silly in wanting the markup to be clean, I'm just wondering if there is something simple that I'm missing.</p>
[ { "answer_id": 61925, "author": "Matt", "author_id": 4154, "author_profile": "https://Stackoverflow.com/users/4154", "pm_score": 0, "selected": false, "text": " <asp:ListBox ID=\"ListBox1\" runat=\"server\">\n <asp:ListItem>String 1</asp:ListItem>\n <asp:ListItem>String ...
2008/09/15
[ "https://Stackoverflow.com/questions/61861", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2758/" ]
61,872
<p>We are rewriting our legacy <a href="https://en.wikipedia.org/wiki/Accounting_information_system" rel="nofollow noreferrer">accounting system</a> in VB.NET and SQL Server. We brought in a new team of .NET/ SQL Programmers to do the rewrite. Most of the system is already completed with the dollar amounts using floats. The legacy system language, I programmed in, did not have a float, so I probably would have used a decimal.</p> <p>What is your recommendation?</p> <p>Should the float or decimal data type be used for dollar amounts?</p> <p>What are some of the pros and cons for either?</p> <p>One <em>con</em> mentioned in our <a href="https://en.wikipedia.org/wiki/Scrum_%28software_development%29#Daily_scrum" rel="nofollow noreferrer">daily scrum</a> was you have to be careful when you calculate an amount that returns a result that is over two decimal positions. It sounds like you will have to round the amount to two decimal positions.</p> <p>Another <em>con</em> is all displays and printed amounts have to have a <em>format statement</em> that shows two decimal positions. I noticed a few times where this was not done and the amounts did not look correct. (i.e. 10.2 or 10.2546)</p> <p>A <em>pro</em> is the float-only approach takes up eight bytes on disk where the decimal would take up nine bytes (decimal 12,2).</p>
[ { "answer_id": 62071, "author": "Keith", "author_id": 905, "author_profile": "https://Stackoverflow.com/users/905", "pm_score": 3, "selected": false, "text": "money" }, { "answer_id": 62493, "author": "David T. Macknet", "author_id": 6850, "author_profile": "https://S...
2008/09/15
[ "https://Stackoverflow.com/questions/61872", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4964/" ]
61,882
<p>In a typical handheld/portable embedded system device Battery life is a major concern in design of H/W, S/W and the features the device can support. From the Software programming perspective, one is aware of MIPS, Memory(Data and Program) optimized code. I am aware of the H/W Deep sleep mode, Standby mode that are used to clock the hardware at lower Cycles or turn of the clock entirel to some unused circutis to save power, but i am looking for some ideas from that point of view:</p> <p>Wherein my code is running and it needs to keep executing, given this how can I write the code "power" efficiently so as to consume minimum watts?</p> <p>Are there any special programming constructs, data structures, control structures which i should look at to achieve minimum power consumption for a given functionality.</p> <p>Are there any s/w high level design considerations which one should keep in mind at time of code structure design, or during low level design to make the code as power efficient(Least power consuming) as possible? </p>
[ { "answer_id": 61912, "author": "macbirdie", "author_id": 5049, "author_profile": "https://Stackoverflow.com/users/5049", "pm_score": 5, "selected": false, "text": "1800 INFORMATION" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/61882", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2759376/" ]
61,888
<p>Is it possible to use <a href="http://subversion.apache.org/" rel="noreferrer">Apache Subversion</a> (SVN) as general purpose backup tool? (As a kind of <a href="http://en.wikipedia.org/wiki/Rsync" rel="noreferrer">rsync</a> alternative.)</p>
[ { "answer_id": 15548768, "author": "user2195264", "author_id": 2195264, "author_profile": "https://Stackoverflow.com/users/2195264", "pm_score": 1, "selected": false, "text": "cd" } ]
2008/09/15
[ "https://Stackoverflow.com/questions/61888", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1897/" ]