qid
int64
4
22.2M
question
stringlengths
18
48.3k
answers
list
date
stringlengths
10
10
metadata
list
230,792
<p>I have noticed that regardless of a given script's execution time, every date() call will return the same timestamp regardless of where the function is called within the script. It looks like it just returns the time at which the script first started executing.</p> <p>For logging purposes, it would be extremely useful to be able to get incremental timestamps from within a script. Is this possible? Is there a way to do this that is relatively lightweight?</p> <p><strong>Edit:</strong> Would the example for the <a href="http://us.php.net/microtime" rel="nofollow noreferrer">microtime()</a> function suggests it might do this. Can anyone confirm?</p> <p><strong>Update:</strong> microtime() does work, but I cannot format it with the date() function because date() only accepts timestamps as integers (so no microseconds). How can I get a properly formatted date from the value returned by microtime() ?</p>
[ { "answer_id": 231010, "author": "Paolo Bergantino", "author_id": 16417, "author_profile": "https://Stackoverflow.com/users/16417", "pm_score": 2, "selected": false, "text": "<?php\n$time_start = time();\n\nsleep(2);\n\n$time_end = time();\n\nprint 'Start: ' . date(\"m/d/Y @ g:i:sA\", $t...
2008/10/23
[ "https://Stackoverflow.com/questions/230792", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5291/" ]
230,796
<p>I'm creating a table that looks something like this.</p> <pre><code>CREATE TABLE packages ( productCode char(2) , name nvarchar(100) , ... ) </code></pre> <p>How do I make sure the productCode is always one of two values <code>XJ</code> or <code>XD</code>?</p>
[ { "answer_id": 230819, "author": "Amy B", "author_id": 8155, "author_profile": "https://Stackoverflow.com/users/8155", "pm_score": 4, "selected": true, "text": "ALTER TABLE packages\nADD CONSTRAINT constraintname CHECK (productCode in ('XJ', 'XD'))\n" }, { "answer_id": 230833, ...
2008/10/23
[ "https://Stackoverflow.com/questions/230796", "https://Stackoverflow.com", "https://Stackoverflow.com/users/437/" ]
230,831
<p><img src="https://upload.wikimedia.org/wikipedia/commons/thumb/a/a9/Unbalanced_binary_tree.svg/251px-Unbalanced_binary_tree.svg.png" alt="alt text"></p> <p>The image above is from <a href="http://en.wikipedia.org/wiki/AVL_tree" rel="nofollow noreferrer">"Wikipedia's entry on AVL trees"</a> which Wikipedia indicates is unbalanced. How is this tree not balanced already? Here's a quote from the article:</p> <blockquote> <p>The balance factor of a node is the height of its right subtree minus the height of its left subtree and a node with balance factor 1, 0, or -1 is considered balanced. A node with any other balance factor is considered unbalanced and requires rebalancing the tree. The balance factor is either stored directly at each node or computed from the heights of the subtrees.</p> </blockquote> <p>Both the left and right subtrees have a height of 4. The right subtree of the left tree has a height of 3 which is still only 1 less than 4. Can someone explain what I'm missing?</p>
[ { "answer_id": 230966, "author": "James Curran", "author_id": 12725, "author_profile": "https://Stackoverflow.com/users/12725", "pm_score": 5, "selected": true, "text": "Root: 23\n(23) -> 14 & 67\n(14) -> 12 & 17\n(12) -> 9\n(17) -> 19\n(67) -> 50 & 72\n(50) -> 54\n(72) -> 76\n" }, {...
2008/10/23
[ "https://Stackoverflow.com/questions/230831", "https://Stackoverflow.com", "https://Stackoverflow.com/users/412/" ]
230,834
<p>This is a winforms application.</p> <p>In windows, I want the user to click and button, and then a popup should make the user select the path of where they want to save the file.</p>
[ { "answer_id": 230867, "author": "gimel", "author_id": 6491, "author_profile": "https://Stackoverflow.com/users/6491", "pm_score": 1, "selected": false, "text": "StringBuilder.ToString()" }, { "answer_id": 230874, "author": "Jon Grant", "author_id": 18774, "author_pro...
2008/10/23
[ "https://Stackoverflow.com/questions/230834", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
230,842
<p>The first one is definitely something that works, but which one below is the efficient way?</p> <pre><code>switch($type) { case 1: print 'success'; break; case 2: print 'success'; break; case 3: print 'success'; break; case 4: print 'success for type 4'; break; } </code></pre> <p>Since 1, 2 and 3 print do the same, can I do this?</p> <pre><code>switch($type) { case 1, 2, 3: print 'success'; break; case 4: print 'success for type 4'; break; } </code></pre> <p>or</p> <pre><code>switch($type) { case 1: case 2: case 3: print 'success'; break; case 4: print 'success for type 4'; break; } </code></pre>
[ { "answer_id": 230857, "author": "Nescio", "author_id": 14484, "author_profile": "https://Stackoverflow.com/users/14484", "pm_score": 5, "selected": true, "text": " switch($type) \n {\n case 1:\n case 2:\n case 3:\n print 'success';\n break;\n case 4:\n ...
2008/10/23
[ "https://Stackoverflow.com/questions/230842", "https://Stackoverflow.com", "https://Stackoverflow.com/users/26130/" ]
230,845
<p>I'm writing a python script that executes a csh script in Solaris 10. The csh script prompts the user for the root password (which I know) but I'm not sure how to make the python script answer the prompt with the password. Is this possible? Here is what I'm using to execute the csh script:</p> <pre><code>import commands commands.getoutput('server stop') </code></pre>
[ { "answer_id": 230855, "author": "Owen", "author_id": 2109, "author_profile": "https://Stackoverflow.com/users/2109", "pm_score": 0, "selected": false, "text": "commands.getoutput('server stop -p password')\n" }, { "answer_id": 230862, "author": "Douglas Mayle", "author_i...
2008/10/23
[ "https://Stackoverflow.com/questions/230845", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7949/" ]
230,869
<p>I have this situation. I have a real stored in a varbinary field in a sql 2005 database. As I can't convert a varbinary to a real in sql 2005, I'm trying to do that in vb.net.</p> <p>That field gets stored as a byte() array in a DataTable.</p> <p>Now I would like to read that byte() into a double, or decimal variable. But I don't have much of a clue on how to do that...</p>
[ { "answer_id": 231295, "author": "biozinc", "author_id": 30698, "author_profile": "https://Stackoverflow.com/users/30698", "pm_score": 1, "selected": false, "text": "'declare a test array\nDim testArray As Byte() = {0, 0, 0, 0}\n'wrap it into a memory stream\nDim memStream As MemoryStrea...
2008/10/23
[ "https://Stackoverflow.com/questions/230869", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
230,886
<p>I've seen this format used for comma-delimited lists in some C++ code (although this could apply to any language):</p> <pre><code>void function( int a , int b , int c ) </code></pre> <p>I was wondering why would someone use that over a more common format such as:</p> <pre><code>void function (int a, int b, int c ) </code></pre>
[ { "answer_id": 230915, "author": "Max Lybbert", "author_id": 10593, "author_profile": "https://Stackoverflow.com/users/10593", "pm_score": 1, "selected": false, "text": "std::cout << \"some info \"\n << \"some more info \" << 4\n + 5 << std::endl;\n" }, { "answer_id": 23092...
2008/10/23
[ "https://Stackoverflow.com/questions/230886", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4086/" ]
230,892
<p>I have quickly read (and will read with more care soon) the article of Scott Allen concerning the possibility to use an other provider of the default SQL Express or SQL Server database to use the "<a href="http://weblogs.asp.net/scottgu/archive/2006/02/24/ASP.NET-2.0-Membership_2C00_-Roles_2C00_-Forms-Authentication_2C00_-and-Security-Resources-.aspx" rel="nofollow noreferrer">Membership and Role Providers</a>" for ASP.NET.</p> <p>We will soon need to open a part of our project to some client via the web and I thought about using the "<a href="http://weblogs.asp.net/scottgu/archive/2006/02/24/ASP.NET-2.0-Membership_2C00_-Roles_2C00_-Forms-Authentication_2C00_-and-Security-Resources-.aspx" rel="nofollow noreferrer">Membership and Role Providers</a>" but our database is PostGreSql. </p> <p>Does any one have some experience with "<a href="http://weblogs.asp.net/scottgu/archive/2006/02/24/ASP.NET-2.0-Membership_2C00_-Roles_2C00_-Forms-Authentication_2C00_-and-Security-Resources-.aspx" rel="nofollow noreferrer">Membership and Role Providers</a> and an other database type (not SQL Server)? Is it worth it or it's a pain?</p>
[ { "answer_id": 230915, "author": "Max Lybbert", "author_id": 10593, "author_profile": "https://Stackoverflow.com/users/10593", "pm_score": 1, "selected": false, "text": "std::cout << \"some info \"\n << \"some more info \" << 4\n + 5 << std::endl;\n" }, { "answer_id": 23092...
2008/10/23
[ "https://Stackoverflow.com/questions/230892", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13913/" ]
230,893
<p>What is the fastest way to load data from flatfiles into a MySQL database, and then create the relations between the tables via foreign keys? </p> <p>For example... I have a flat file in the format: </p> <pre><code>[INDIVIDUAL] [POP] [MARKER] [GENOTYPE] "INDIVIDUAL1", "CEU", "rs55555","AA" "INDIVIDUAL1", "CEU", "rs535454","GA" "INDIVIDUAL1", "CEU", "rs555566","AT" "INDIVIDUAL1", "CEU", "rs12345","TT" ... "INDIVIDUAL2", "JPT", "rs55555","AT" </code></pre> <p>Which I need to load into four tables:</p> <pre><code>IND (id,fk_pop,name) POP (id,population) MARKER (id,rsid) GENOTYPE (id,fk_ind,fk_rsid,call) </code></pre> <p>Specifically, how does one populate the foreign keys in a way that scales? The figures are in the range of 1000+ individuals, each with 1 million+ genotypes.</p>
[ { "answer_id": 449373, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": 3, "selected": true, "text": " LOAD DATA INFILE 'data.txt' IGNORE INTO TABLE POP FIELDS TERMINATED BY ','\n ENCLOSED BY '\"' LINES TERMINATED BY '\\n' IGN...
2008/10/23
[ "https://Stackoverflow.com/questions/230893", "https://Stackoverflow.com", "https://Stackoverflow.com/users/30911/" ]
230,896
<p>I have a list of variable names, like this:</p> <pre><code>['foo', 'bar', 'baz'] </code></pre> <p>(I originally asked how I convert a list of variables. See Greg Hewgill's answer below.)</p> <p>How do I convert this to a dictionary where the keys are the variable names (as strings) and the values are the values of the variables?</p> <pre><code>{'foo': foo, 'bar': bar, 'baz': baz} </code></pre> <p>Now that I'm re-asking the question, I came up with:</p> <pre><code>d = {} for name in list_of_variable_names: d[name] = eval(name) </code></pre> <p>Can that be improved upon?</p> <p><strong>Update</strong>, responding to the question (in a comment) of why I'd want to do this:</p> <p>I often find myself using the % operator to strings with a dictionary of names and values to interpolate. Often the names in the string is just the names of local variables. So (with the answer below) I can do something like this:</p> <pre><code>message = '''Name: %(name)s ZIP: %(zip)s Dear %(name)s, ...''' % dict((x, locals()[x]) for x in ['name', 'zip']) </code></pre>
[ { "answer_id": 230907, "author": "Greg Hewgill", "author_id": 893, "author_profile": "https://Stackoverflow.com/users/893", "pm_score": 2, "selected": false, "text": "[foo, bar, baz]" }, { "answer_id": 230955, "author": "Douglas Mayle", "author_id": 8458, "author_prof...
2008/10/23
[ "https://Stackoverflow.com/questions/230896", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4766/" ]
230,925
<p>Visual Studio does it; Reflector does it; and now I want to as well :)</p> <p>I want to retrieve the XML documentation for some members in some framework assemblies (i.e. <code>mscorlib.dll</code>, <code>System.dll</code>, etc). I assume this would involve:</p> <ul> <li>finding the XML file for the assembly, </li> <li>navigating to the appropriately named child element, and </li> <li>retrieving the desired items (<code>&lt;summary&gt;</code>, <code>&lt;remarks&gt;</code>, etc)</li> </ul> <p><br/> Where are the XML files kept for framework assemblies? Any points on deciphering the XMLDOC naming scheme? Are there any libraries out there that will make this process easier?</p>
[ { "answer_id": 238058, "author": "Emperor XLII", "author_id": 2495, "author_profile": "https://Stackoverflow.com/users/2495", "pm_score": 2, "selected": false, "text": "static FileInfo GetXmlDocFile( Assembly assembly ) {\n string assemblyDirPath = Path.GetDirectoryName( assembly.Locati...
2008/10/23
[ "https://Stackoverflow.com/questions/230925", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2495/" ]
230,927
<p>I'm looking for best practices for establishing connections between Oracle 8 and Visual Studio 2005 applications. The target would be a Windows Forms application written in C# that hits the database once a second to monitor tables looking for their last inserted record. I'm considering using "Application settings" to store the connection string there, but I'd love to hear from you guys. Thanks in advance!</p> <p>This is a very rudimentary draft:</p> <pre><code>using System.Data; using System.Data.OracleClient; try { StringBuilder str = new StringBuilder(); string ora = Properties.Settings.Default.OracleConnectionString; OracleConnection con = new OracleConnection(ora); OracleCommand cmd = new OracleCommand(); cmd.Connection = con; cmd.CommandText = "SELECT timestamp FROM jde_out WHERE rownum = 1"; cmd.CommandType = CommandType.Text; con.Open(); OracleDataReader rdr = cmd.ExecuteReader(); rdr.Read(); str.AppendLine(cmd.ExecuteScalar().ToString()); this.lblJDEtime.Text = str.ToString(); rdr.Close(); con.Close(); } catch (OracleException err) { MessageBox.Show("Exception caught:\n\n" + err.ToString()); } </code></pre> <p>I've just updated the code needed to perform the connection. Changed the Exception type to the more specific OracleException. Added the connection string via Properties.Settings.</p>
[ { "answer_id": 231073, "author": "Loscas", "author_id": 22706, "author_profile": "https://Stackoverflow.com/users/22706", "pm_score": 2, "selected": true, "text": "<?xml version='1.0' encoding='utf-8'?>\n <configuration>\n <connectionStrings>\n <clear />\n <add name=\"Name\...
2008/10/23
[ "https://Stackoverflow.com/questions/230927", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6992/" ]
230,931
<p>As I've read somewhere it is advised to use !== and === instead.</p>
[ { "answer_id": 230944, "author": "Joel Coehoorn", "author_id": 3043, "author_profile": "https://Stackoverflow.com/users/3043", "pm_score": 4, "selected": false, "text": "5 == \"5\"\n" }, { "answer_id": 230957, "author": "olliej", "author_id": 784, "author_profile": "h...
2008/10/23
[ "https://Stackoverflow.com/questions/230931", "https://Stackoverflow.com", "https://Stackoverflow.com/users/28098/" ]
230,973
<p>I saw a code snippet yesterday in one of the responses here on StackOverflow that intrigued me. It was something like this:</p> <pre><code> List&lt;string&gt; myList = new List&lt;string&gt; {"aBc", "HELLO", "GoodBye"}; myList.ForEach(d=&gt;d.ToLower()); </code></pre> <p>I was hoping I could use it to convert all items in myList to lowercase. However, it doesn't happen... after running this, the casing in myList is unchanged.</p> <p>So my question is whether there IS a way, using LINQ and Lambda expressions to easily iterate through and modify the contents of a list in a manner similar to this.</p> <p>Thanks, Max</p>
[ { "answer_id": 230991, "author": "marcumka", "author_id": 30761, "author_profile": "https://Stackoverflow.com/users/30761", "pm_score": 2, "selected": false, "text": "[TestMethod]\npublic void LinqStringTest()\n{\n List<string> myList = new List<string> { \"aBc\", \"HELLO\", \"GoodBye...
2008/10/23
[ "https://Stackoverflow.com/questions/230973", "https://Stackoverflow.com", "https://Stackoverflow.com/users/29662/" ]
230,974
<p>I am attempting to disable SSL v2.0 protocol on IIS 7.</p> <p>The following article refers to IIS v6: <a href="http://support.microsoft.com/kb/187498" rel="noreferrer">http://support.microsoft.com/kb/187498</a></p> <p>It doesn't seem to apply because the only protocol listed in the registry is SSL 2.0 (not all the others) and the setting "DisabledByDefault=1" is already in there, which would seem to imply that it is disabled.</p> <p>However, the following article seems to suggest that it still applies and to turn off "DisabledByDefault" which seems strange. <a href="http://forums.iis.net/t/1151822.aspx" rel="noreferrer">http://forums.iis.net/t/1151822.aspx</a></p> <p>I only need to disable SSL v2.0, but I want to be relatively confident I am doing the right thing.</p>
[ { "answer_id": 5057027, "author": "Martin Buberl", "author_id": 135441, "author_profile": "https://Stackoverflow.com/users/135441", "pm_score": 5, "selected": false, "text": "HKey_Local_Machine\\System\\CurrentControlSet\\Control\\SecurityProviders" } ]
2008/10/23
[ "https://Stackoverflow.com/questions/230974", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
230,981
<p>I am working with some input that is in the possible forms</p> <pre><code>$1,200 20 cents/ inch $10 </code></pre> <p>Is there a way to parse these to numbers in VB? Also printing these numbers?</p> <p><strong>EDIT:</strong> Regular expressions would be great.</p> <p><strong>EDIT:</strong> VB 6 in particular</p>
[ { "answer_id": 231025, "author": "EBGreen", "author_id": 1358, "author_profile": "https://Stackoverflow.com/users/1358", "pm_score": 2, "selected": true, "text": "Dim oRE As Object\nSet oRE = New VBScript_RegExp.RegExp\noRe.Pattern = \"\\D\"\nstrTest = oRE.Replace(strTest, \"\")\n" }, ...
2008/10/23
[ "https://Stackoverflow.com/questions/230981", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17712/" ]
230,984
<p>Is there a compression API available for use on the iPhone? We're building some RESTful web services for our iPhone app to talk to, but we want to compress at least some of the conversations for efficiency.</p> <p>I don't care what the format (ZIP, LHA, whatever) is, and it does not need to be secure.</p> <p>Some respondents have pointed out that the server can compress its output, and the iPhone can consume that. The scenario we have is exactly the reverse. We'll be POSTing compressed content <strong>to</strong> the web service. We're not concerned with compression going the other way.</p>
[ { "answer_id": 234099, "author": "Brad Larson", "author_id": 19679, "author_profile": "https://Stackoverflow.com/users/19679", "pm_score": 6, "selected": false, "text": "@interface NSData (NSDataExtension)\n\n// Returns range [start, null byte), or (NSNotFound, 0).\n- (NSRange) rangeOfNu...
2008/10/23
[ "https://Stackoverflow.com/questions/230984", "https://Stackoverflow.com", "https://Stackoverflow.com/users/27779/" ]
231,023
<p>I'd like to align label/value pairs in the center using CSS without using absolute positioning or tables (see screen shot). In that screen shot I positioned the value (ie. $4,500/wk) absolute and then floated the label right up against it. But absolute doesn't work so well in IE and I've heard it's not a good technique.</p> <p>But how can I acheive this effect where the labels are all justified right without absolute?</p> <p><a href="http://www.amherstparents.org/files/shot.jpg" rel="nofollow noreferrer">alt text http://www.amherstparents.org/files/shot.jpg</a></p>
[ { "answer_id": 231056, "author": "Rahul", "author_id": 16308, "author_profile": "https://Stackoverflow.com/users/16308", "pm_score": 2, "selected": false, "text": "<dl>\n<dt>Cost:</dt>\n<dd>$4,500/wk</dd>\n<dt>Sleeps:</dt>\n<dd>1</dd>\n</dl>\n" }, { "answer_id": 231078, "auth...
2008/10/23
[ "https://Stackoverflow.com/questions/231023", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6957/" ]
231,027
<p>I make a request to an xml web service, and get back a response. This response, being a stream, is then saved to a string. The problem is, the response is full of tags, CDATA, etc (as you would expect). There is no line breaking either, as to be expected.</p> <p>I want to take this string, which represents an xml document, and strip it of all its tags but keep the actual values, and also, make sure that each record is in one line, so:</p> <pre><code>&lt;Record&gt; &lt;name&gt;adam&lt;/name&gt; &lt;telephoneno&gt;000&lt;/telephonenumber&gt; &lt;/Record&gt; &lt;Record&gt; &lt;name&gt;mike&lt;/name&gt; &lt;telephoneno&gt;001&lt;/telephonenumber&gt; &lt;/Record&gt; </code></pre> <p>Will be transformed to:</p> <pre><code>adam 000 mike 001 </code></pre> <p>Headings is an easy issue, but how could I achieve this? I've tried datatables and datasets but I don't think they have great support for achieving what I am trying to do.</p>
[ { "answer_id": 231041, "author": "Michael Haren", "author_id": 29, "author_profile": "https://Stackoverflow.com/users/29", "pm_score": 3, "selected": false, "text": "<?xml version=\"1.0\"?>\n<?xml-stylesheet type=\"text/xsl\" href=\"style.xsl\"?>\n<Records>\n <Record>\n <name>adam</n...
2008/10/23
[ "https://Stackoverflow.com/questions/231027", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
231,029
<p>I am trying to include a value from a database table within the value element of an input field.<br> This is what I have, but it is not working:</p> <pre><code>?&gt;&lt;input type="text" size="10" value="&lt;?= date("Y-m-d", strtotime($rowupd['upcoming_event_featured_date'])) ?&gt;" name="upcoming_event_featured_date" id="keys"/&gt;&lt;?php </code></pre> <p>I have done this before, but I usually print it out like this:</p> <pre><code>print '&lt;input type="text" size="10" value="'.date("Y-m-d", strtotime($rowupd['upcoming_event_featured_date'])).'" name="upcoming_event_featured_date" id="keys"/&gt;'; </code></pre> <p>What is the appropriate way of doing this without using <code>print ''</code>?</p>
[ { "answer_id": 231037, "author": "Devon", "author_id": 13850, "author_profile": "https://Stackoverflow.com/users/13850", "pm_score": 1, "selected": false, "text": "ini_set('short_open_tag', true);\n" }, { "answer_id": 231058, "author": "Stefan Gehrig", "author_id": 11354,...
2008/10/23
[ "https://Stackoverflow.com/questions/231029", "https://Stackoverflow.com", "https://Stackoverflow.com/users/26130/" ]
231,034
<p>I'm using Visual Studio 2008 Team Development Edition and my Project properties page will not display. I right-clicked the project name and selected "Properties" and no page displayed as it normally would. Also, when I double-click the Settings.settings the normal Settings GUI does not display. I only see the XML in the Settings.settings file. Please Help. Thanks.</p>
[ { "answer_id": 27580436, "author": "slavash", "author_id": 4380689, "author_profile": "https://Stackoverflow.com/users/4380689", "pm_score": 2, "selected": false, "text": "devenv.exe /resetskippkgs\n" } ]
2008/10/23
[ "https://Stackoverflow.com/questions/231034", "https://Stackoverflow.com", "https://Stackoverflow.com/users/27852/" ]
231,051
<p>After reading <a href="http://www.javaworld.com/javaworld/javatips/jw-javatip130.html?page=2" rel="noreferrer">this old article</a> measuring the memory consumption of several object types, I was amazed to see how much memory <code>String</code>s use in Java:</p> <pre><code>length: 0, {class java.lang.String} size = 40 bytes length: 7, {class java.lang.String} size = 56 bytes </code></pre> <p>While the article has some tips to minimize this, I did not find them entirely satisfying. It seems to be wasteful to use <code>char[]</code> for storing the data. The obvious improvement for most western languages would be to use <code>byte[]</code> and an encoding like UTF-8 instead, as you only need a single byte to store the most frequent characters then instead of two bytes.</p> <p>Of course one could use <code>String.getBytes(&quot;UTF-8&quot;)</code> and <code>new String(bytes, &quot;UTF-8&quot;)</code>. Even the overhead of the String instance itself would be gone. But then there you lose very handy methods like <code>equals()</code>, <code>hashCode()</code>, <code>length()</code>, ...</p> <p>Sun has a <a href="http://www.freepatentsonline.com/6751790.html" rel="noreferrer">patent</a> on <code>byte[]</code> representation of Strings, as far as I can tell.</p> <blockquote> <p><strong>Frameworks for efficient representation of string objects in Java programming environments</strong><br /> ... The techniques can be implemented to create Java string objects as arrays of one-byte characters when it is appropriate ...</p> </blockquote> <p>But I failed to find an API for that patent.</p> <p>Why do I care?<br /> In most cases I don't. But I worked on applications with huge caches, containing lots of Strings, which would have benefitted from using the memory more efficiently.</p> <p>Does anybody know of such an API? Or is there another way to keep your memory footprint for Strings small, even at the cost of CPU performance or uglier API?</p> <p>Please don't repeat the suggestions from the above article:</p> <ul> <li>own variant of <code>String.intern()</code> (possibly with <code>SoftReferences</code>)</li> <li>storing a single <code>char[]</code> and exploiting the current <code>String.subString(.)</code> implementation to avoid data copying (nasty)</li> </ul> <p><strong>Update</strong></p> <p>I ran the code from the article on Sun's current JVM (1.6.0_10). It yielded the same results as in 2002.</p>
[ { "answer_id": 231352, "author": "Sam Stokes", "author_id": 20131, "author_profile": "https://Stackoverflow.com/users/20131", "pm_score": 0, "selected": false, "text": "String.intern" }, { "answer_id": 3323724, "author": "J. Dimeo", "author_id": 198371, "author_profil...
2008/10/23
[ "https://Stackoverflow.com/questions/231051", "https://Stackoverflow.com", "https://Stackoverflow.com/users/21368/" ]
231,052
<p>I have a page where a few textboxes cannot be empty before clicking a Save button. </p> <pre><code>&lt;TextBox... &lt;TextBox.Text&gt; &lt;Binding Path ="LastName" UpdateSourceTrigger="PropertyChanged"&gt; &lt;Binding.ValidationRules&gt; &lt;local:StringRequiredValidationRule /&gt; &lt;/Binding.ValidationRules&gt; &lt;/Binding&gt; &lt;/TextBox.Text&gt; </code></pre> <p>My rule works, I have a red border around my textbox until I enter a value. I now want to add this validation rule to my other text boxes.</p> <p>How do I disable the Save button until the page has no validation errors? I'm not sure what to check.</p>
[ { "answer_id": 808190, "author": "Christoph", "author_id": 98795, "author_profile": "https://Stackoverflow.com/users/98795", "pm_score": 4, "selected": false, "text": "this.AddHandler(Validation.ErrorEvent,new RoutedEventHandler(OnErrorEvent)); \n" }, { "answer_id": 7512442, ...
2008/10/23
[ "https://Stackoverflow.com/questions/231052", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3047/" ]
231,057
<p>Is there any library function for this purpose, so I don't do it by hand and risk ending in TDWTF?</p> <pre><code>echo ceil(31497230840470473074370324734723042.6); // Expected result 31497230840470473074370324734723043 // Prints &lt;garbage&gt; </code></pre>
[ { "answer_id": 231171, "author": "Greg", "author_id": 24181, "author_profile": "https://Stackoverflow.com/users/24181", "pm_score": 4, "selected": true, "text": "$x = '31497230840470473074370324734723042.9';\n\nbcscale(100);\nvar_dump(bcFloor($x));\nvar_dump(bcCeil($x));\nvar_dump(bcRoun...
2008/10/23
[ "https://Stackoverflow.com/questions/231057", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13211/" ]
231,062
<p>I'm building up a library of filters for a validation class in PHP, some of them using regular expressions. I have a lot of filters in mind, but I also don't want to potentially miss any. What do you most often use regular expressions to check? What are some of the not-so-common things that you've had to check that would still be useful in a library? Note: I'm not looking for the actual regex code, just what you use it for.</p>
[ { "answer_id": 231101, "author": "tom.dietrich", "author_id": 15769, "author_profile": "https://Stackoverflow.com/users/15769", "pm_score": 1, "selected": false, "text": " '[\\s]*--\n" } ]
2008/10/23
[ "https://Stackoverflow.com/questions/231062", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13281/" ]
231,069
<p>I want to write a default structure, N times, to a file, using fwrite.</p> <pre><code>typedef struct foo_s { uint32 A; uint32 B; char desc[100]; }foo_t; void init_file(FILE *fp, int N) { foo_t foo_struct = {0}; foo_struct.A = -1; foo_struct.B = 1; fwrite(&amp;foo_struct, sizeof(foo_struct), N, fp); } </code></pre> <p>The above code does not write foo_struct N times to the file stream fp.</p> <p>Instead it writes N*sizeof(foo_struct) bytes starting from &amp;foo_struct to fp. </p> <p>Can anyone tell how to achieve the same with a single fwrite?</p>
[ { "answer_id": 231084, "author": "Ferruccio", "author_id": 4086, "author_profile": "https://Stackoverflow.com/users/4086", "pm_score": 5, "selected": true, "text": "int i;\nfor (i = 0; i < N; ++i)\n fwrite(&foo_struct, sizeof(foo_struct), 1, fp);\n" } ]
2008/10/23
[ "https://Stackoverflow.com/questions/231069", "https://Stackoverflow.com", "https://Stackoverflow.com/users/29405/" ]
231,089
<p>Is there any point to freeing memory in an atexit() function?</p> <p>I have a global variable that gets malloc'ed after startup. I could write an atexit() function to free it, but isn't the system going to reclaim all that memory when the program exits anyway?</p> <p>Is there any benefit to being tidy and actively cleaning it up myself?</p>
[ { "answer_id": 242317, "author": "Artelius", "author_id": 31945, "author_profile": "https://Stackoverflow.com/users/31945", "pm_score": 4, "selected": false, "text": "malloc()" } ]
2008/10/23
[ "https://Stackoverflow.com/questions/231089", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17693/" ]
231,098
<p>I'd like a loop that uses a UInt16 (ushort) to loop through all of its values. However, this doesn't do it:</p> <pre><code>for( ushort i = 0; i &lt; UInt16.MaxValue; i++ ) { // do something } </code></pre> <p>The problem is that the loop will quit when i == 0xFFFF and not "do something". If I change the 'for' statement to "for(ushort i = 0; i &lt;= UInt16.MaxValue; i++ )", then it becomes an infinite loop because i never gets to 0x10000 because ushorts only go to 0xFFFF.</p> <p>I could make 'i' an int and cast it or assign it to a ushort variable in the loop.</p> <p>Any suggestions?</p>
[ { "answer_id": 231112, "author": "Chris Marasti-Georg", "author_id": 96, "author_profile": "https://Stackoverflow.com/users/96", "pm_score": 5, "selected": true, "text": "do...while" }, { "answer_id": 231114, "author": "Burkhard", "author_id": 12860, "author_profile":...
2008/10/23
[ "https://Stackoverflow.com/questions/231098", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9516/" ]
231,121
<p>As a counterpart to <a href="https://stackoverflow.com/questions/215470/c-coding-guideline-102">C++ Coding Guideline 102</a>, which of the <a href="http://www.gotw.ca/publications/c++cs.htm" rel="nofollow noreferrer">101 guidelines of Sutter &amp; Alexandrescu</a> do you violate or ignore most often, and why?</p>
[ { "answer_id": 231713, "author": "Steve Jessop", "author_id": 13005, "author_profile": "https://Stackoverflow.com/users/13005", "pm_score": 3, "selected": false, "text": "uint64_t i = getIEEEbitpatternByMeansRelevantToTheQuestion();\ndouble d;\nmemcpy(&d, &i, 8);\n" } ]
2008/10/23
[ "https://Stackoverflow.com/questions/231121", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19863/" ]
231,125
<p>I remember reading at one point that indexing a field with low cardinality (a low number of distinct values) is not really worth doing. I admit I don't know enough about how indexes work to understand why that is.</p> <p>So what if I have a table with 100 million rows in it, and I am selecting records where a bit field is 1? And let's say that at any point in time, there are only a handful of records where the bit field is 1 (as opposed to 0). Is it worth indexing that bit field or not? Why?</p> <p>Of course I can just test it and check the execution plan, and I will do that, but I'm also curious about the theory behind it. When does cardinality matter and when does it not?</p>
[ { "answer_id": 231366, "author": "Ian Boyd", "author_id": 12597, "author_profile": "https://Stackoverflow.com/users/12597", "pm_score": 1, "selected": false, "text": "tinyint" }, { "answer_id": 18969193, "author": "Ben Thul", "author_id": 568209, "author_profile": "ht...
2008/10/23
[ "https://Stackoverflow.com/questions/231125", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1436/" ]
231,126
<p>I'm terribly new to SQL, and cannot seem to get the desired information out, after trying a few different google searches, and reading through some SQL tutorials.</p> <p>I think it involves some sort of joins, but cannot get them straight.</p> <p>Given the following sample tables:</p> <p>Table 1(Activity This is updated every time a change is made to a task, could be manytimes per day):</p> <pre><code>ID Who What When 001 John Created 2008-10-01&lt;br&gt; 001 Bill Closed 2008-10-02&lt;br&gt; 001 John Updated 2008-10-03&lt;br&gt; 002 Bill Created 2008-10-04&lt;br&gt; 002 John Updated 2008-10-05&lt;br&gt; 002 Bill Closed 2008-10-06&lt;br&gt; </code></pre> <p>Table 2(Tasks - This is the main task tracking table):</p> <pre><code>ID Created Status 001 2008-10-01 Closed 002 2008-10-04 Closed </code></pre> <p>Table 3(Comments):</p> <pre><code>ID When Comment&lt;br 001 2008-10-01 "I'm creating a new task" 001 2008-10-02 "I have completed the task" 001 2008-10-03 "Nice job" 002 2008-10-04 "I'm creating a second task" 002 2008-10-05 "This task looks too easy" 002 2008-10-06 "I have completed this easy task" </code></pre> <p>What SQL (mySQL if it makes any difference) query would I use to find out who had done something on a task that had been closed?</p> <p>The results would be something like:</p> <pre><code>Who What ID When Comment Bill Updated 002 2008-10-03 "Nice job" </code></pre> <p>Meaning that Bill changed task 002 after it was closed, and added the comment "Nice Job"</p> <p>Any help would be much appreciated.</p> <p>Thanks in advance.</p>
[ { "answer_id": 231139, "author": "Totty", "author_id": 30838, "author_profile": "https://Stackoverflow.com/users/30838", "pm_score": 2, "selected": false, "text": "SELECT Activity.Who, Activity.What, Comments.When, Comments.Comment FROM Activity JOIN Comments ON Activity.ID = Comments.ID...
2008/10/23
[ "https://Stackoverflow.com/questions/231126", "https://Stackoverflow.com", "https://Stackoverflow.com/users/30939/" ]
231,128
<p>Just about every piece of example code everywhere omits error handling (because it "confuses the issue" that the example code is addressing). My programming knowledge comes primarily from books and web sites, and you seldom see any error handling in use at all there, let alone good stuff.</p> <p>Where are some places to see good examples of C++ error handling code? Specific books, specific open-source projects (preferably with the files and functions to look at), and specific web pages or sites will all be gratefully accepted.</p>
[ { "answer_id": 231302, "author": "Roddy", "author_id": 1737, "author_profile": "https://Stackoverflow.com/users/1737", "pm_score": 2, "selected": false, "text": "int DoA() \n{\n if (location == hellInAHandcart)\n return ERROR;\n else\n RETURN OK;\n}\n\nint DoB()\n{\n int err = DoA();\...
2008/10/23
[ "https://Stackoverflow.com/questions/231128", "https://Stackoverflow.com", "https://Stackoverflow.com/users/12193/" ]
231,132
<p>I'm trying to get Wininet to ignore Internet Explorer's "Work Offline" mode, for both HTTP and FTP.</p> <p>So I'm trying to use <code>InternetSetOption()</code> with <code>INTERNET_OPTION_IGNORE_OFFLINE</code>. The documentation says "This is used by <code>InternetQueryOption</code> and <code>InternetSetOption</code> with a request handle." However, you can't get a request handle because if IE is in Work Offline mode then <code>InternetConnect()</code> will always return a null handle. Without a connection handle you can't get a request handle. So I tried using it with an <code>InternetOpen()</code> handle and a <code>NULL</code> handle. Both failed with <code>ERROR_INTERNET_INCORRECT_HANDLE_TYPE</code>.</p> <p>Is there a way to get this option to work? I found a reference on an MS newsgroup from 2003 that <code>INTERNET_OPEN_TYPE_PRECONFIG</code> is "broken". 5 years later with IE8 beta 2 and they still haven't fixed it? Or am I doing it wrong.</p> <p><strong>Edit</strong><br/> I wasn't quite correct. <code>InternetConnect()</code> always returns null if you are on "Work Offline" mode and using FTP, but it returns a valid handle if you are using Http. However, it still doesn't work even with a request handle.</p> <p>If I am set to "Work Offline" and I call</p> <pre><code>BOOL a = TRUE; ::InternetSetOption(hData, INTERNET_OPTION_IGNORE_OFFLINE, &amp;a, sizeof(BOOL)); </code></pre> <p>on the handle from </p> <pre><code>HINTERNET hData = HttpOpenRequest(hInternet, L"POST", path, NULL, NULL, NULL, flags, 0 ); </code></pre> <p>the <code>InternetSetOption()</code> call succeeds.<br> However, the call to <code>HttpSendRequest()</code> still fails with error code 2 (file not found), same as it does if I don't set the option.<br> Same thing if I call</p> <pre><code>::InternetSetOption(hData, INTERNET_OPTION_IGNORE_OFFLINE, 0, 0); </code></pre>
[ { "answer_id": 471159, "author": "michael", "author_id": 31207, "author_profile": "https://Stackoverflow.com/users/31207", "pm_score": 0, "selected": false, "text": "GET" }, { "answer_id": 5739763, "author": "Rick Strahl", "author_id": 11197, "author_profile": "https:...
2008/10/23
[ "https://Stackoverflow.com/questions/231132", "https://Stackoverflow.com", "https://Stackoverflow.com/users/24267/" ]
231,146
<p>I'm trying to change user input in wildcard form <code>("*word*")</code> to a regular expression format. To that end, I'm using the code below to strip off the <code>'*'</code> at the beginning and end of the input so that I can add the regular expression characters on either end:</p> <pre><code>string::iterator iter_begin = expressionBuilder.begin(); string::iterator iter_end = expressionBuilder.end(); iter_end--; if ((char)*iter_begin == '*' &amp;&amp; (char)*iter_end == '*') { expressionBuilder.erase(iter_begin); expressionBuilder.erase(iter_end); expressionBuilder = "\\b\\w*" + expressionBuilder + "\\w*\\b"; } </code></pre> <p>However, the call to <code>"expressionBuilder.erase(iter_end)"</code> does <em>not</em> erase the trailing <code>'*'</code> from the input string so I wind up with an incorrect regular expression. What am I doing wrong here? <code>"(char)*iter_end == '*'"</code> must be true for the code inside the if statment to run (which it does), so why doesn't the same iterator work when passed to erase()?</p>
[ { "answer_id": 231173, "author": "Greg Hewgill", "author_id": 893, "author_profile": "https://Stackoverflow.com/users/893", "pm_score": 3, "selected": true, "text": "expressionBuilder.erase(iter_end);\nexpressionBuilder.erase(iter_begin);\n" }, { "answer_id": 231183, "author"...
2008/10/23
[ "https://Stackoverflow.com/questions/231146", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1544/" ]
231,159
<p>I remember from C days that we were encouraged to use</p> <pre><code>i &gt; -1 </code></pre> <p>instead of</p> <pre><code>i &gt;= 0 </code></pre> <p>because of performance.</p> <p>Does this still apply in the C# .NET world? What are the performance implications of using one over the other with today's compilers? i.e. Is the compiler clever enough to optimize these for you?</p> <p>(As an aside try and type the question "use >= or >" into the question field on Stack Overflow and see what happens.)</p>
[ { "answer_id": 231179, "author": "Dan Lenski", "author_id": 20789, "author_profile": "https://Stackoverflow.com/users/20789", "pm_score": 7, "selected": true, "text": " ;; if (i > -1) {\n cmp eax, -1\n jle else\nthen:\n ...\nelse:\n\n ;; if (i >= 0) {\n cmp eax, 0\n jl else\nthen:\n ...\...
2008/10/23
[ "https://Stackoverflow.com/questions/231159", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1463/" ]
231,175
<p>Where can I find comprehensive documentation for MOQ? I'm just starting with mocking and am having difficulty getting my head around it. I've read through all the links at <a href="http://code.google.com/p/moq/wiki/QuickStart" rel="noreferrer">http://code.google.com/p/moq/wiki/QuickStart</a> but can't seem to find a tutorial or gentle introduction.</p> <p>I have also looked briefly at Rhino Mocks but found it very confusing.</p> <hr> <p>Yes - I read Stephen Walthers article - very helpful. I also went through the links. I can't seem to watch the video at <strike><a href="http://www.bestechvideos.com/2008/06/08/dimecasts-net-introduction-to-mocking-with-moq" rel="noreferrer">http://www.bestechvideos.com/2008/06/08/dimecasts-net-introduction-to-mocking-with-moq</a></strike> <sup>[broken link]</sup></p> <p>Specifically I am trying to determine whether an event was raised from the mocked class. I can't get the example for events on the QuickStarts page to compile. On the google groups, Daniel explained that CreateEventHandler can only handle an event of type <code>EventHandler&lt;TEventArgs&gt;</code>, but even then I can't get the code to compile.</p> <p>More specifically I have a class that implements <code>INotifyChanged</code>. </p> <pre><code>public class Entity : INotifyChanged { public event PropertyChangingEventHandler PropertyChanging; public int Id { get {return _id;} set { _id = value; OnPropertyChanged("Id"); } } protected void OnPropertyChanged(string property) { if (PropertyChanged != null) PropertyChanged(this, new PropertyChangedEventArgs(propertyName)); } etc ..... } </code></pre> <p>How do I mock the class to test whether the <code>PropertyChanged</code> event was fired? I can't rewrite the event to <code>public event EventHandler&lt;PropertyChangedEventArgs&gt;</code> becuase I get this error:</p> <blockquote> <p>Error 1 'CoreServices.Notifier' does not implement interface member System.ComponentModel.INotifyPropertyChanged.PropertyChanged'. 'CoreServices.Notifier.PropertyChanged' cannot implement 'System.ComponentModel.INotifyPropertyChanged.PropertyChanged' because it does not have the matching return type of 'System.ComponentModel.PropertyChangedEventHandler'.</p> </blockquote>
[ { "answer_id": 8546583, "author": "TrueWill", "author_id": 161457, "author_profile": "https://Stackoverflow.com/users/161457", "pm_score": 1, "selected": false, "text": "Id" } ]
2008/10/23
[ "https://Stackoverflow.com/questions/231175", "https://Stackoverflow.com", "https://Stackoverflow.com/users/30046/" ]
231,189
<p>What tool or method do you recommend to find and replace values in your code? If code is on Linux/Unix, are find and grep the best method?</p>
[ { "answer_id": 231241, "author": "Andy Lester", "author_id": 8454, "author_profile": "https://Stackoverflow.com/users/8454", "pm_score": 4, "selected": true, "text": "$ perl -i -p -e's/\\bthisword\\b/thatword/g' $(find . -name *.html)\n" }, { "answer_id": 231290, "author": "K...
2008/10/23
[ "https://Stackoverflow.com/questions/231189", "https://Stackoverflow.com", "https://Stackoverflow.com/users/26180/" ]
231,191
<p>Ok simple question. I have a JSF application, containing a login page. The problem is if the user loads the login page, leaves it for a while, then tries to login the session expires and a ViewExpiredException is thrown. I could redirect back to the login when this happens, but that isn't very smooth. How can I allow this flow to properly login without an additional attempt?</p>
[ { "answer_id": 232829, "author": "Community", "author_id": -1, "author_profile": "https://Stackoverflow.com/users/-1", "pm_score": -1, "selected": false, "text": "<meta http-equiv=\"refresh\" content=\"5\"/>" }, { "answer_id": 265908, "author": "Serxipc", "author_id": 340...
2008/10/23
[ "https://Stackoverflow.com/questions/231191", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17614/" ]
231,198
<p>The following code compiles correctly under VC++ 8 on XPSP3, but running it causes a runtime error. </p> <p>My header looks like:</p> <pre><code>#include &lt;stdexcept&gt; #include &lt;iterator&gt; #include &lt;list&gt; template&lt;typename T&gt; class test_generator { public: typedef T result_type; //constructor test_generator() { std::generate_n( std::back_inserter( tests ), 100, rand ); value = tests.begin(); } result_type operator()( void ) { if( value == tests.end() ) { throw std::logic_error( "" ); } return *value++; } private: std::list&lt;T&gt; tests; typename std::list&lt;T&gt;::iterator value; }; </code></pre> <p>My implementation looks like:</p> <pre><code>#include &lt;functional&gt; #include &lt;algorithm&gt; #include &lt;iostream&gt; #include &lt;deque&gt; #include "test.h" int main() { test_generator&lt;double&gt; test; std::deque&lt;double&gt; tests; std::generate_n( std::back_inserter( tests ), 10, test ); return 0; } </code></pre> <p>This compiles fine, it generates an exception (not the logic_error exception defined in the header).</p> <p>If I change the implementation to use a function instead of a functor, it works:</p> <pre><code>int main() { std::deque&lt;int&gt; tests; std::generate_n( std::back_inserter( tests ), 10, rand ); return 0; } </code></pre> <p>What's wrong with using a functor here?</p>
[ { "answer_id": 231270, "author": "C. K. Young", "author_id": 13, "author_profile": "https://Stackoverflow.com/users/13", "pm_score": 0, "selected": false, "text": "return *value++" }, { "answer_id": 231319, "author": "ChrisN", "author_id": 3853, "author_profile": "htt...
2008/10/23
[ "https://Stackoverflow.com/questions/231198", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14069/" ]
231,206
<p>What's everyone take on tieing code enum's to row ID's in a database table? I'm really looking for a cleaner alternative. What if for example your static rows in a given table are ID's 1,2,3, and then that table gets filled with user transactional data using ID's 4-100, and then you later want to add a new row ID which in your local production database is row ID 4, but when that row goes to a customers database it will have to be 101...well that kinda breaks everything.</p> <p>So how do you handle static locked rows in a table that also gets filled with transactional data?</p> <p>Thanks, MeshMan</p>
[ { "answer_id": 231240, "author": "Stephen Wrighton", "author_id": 7516, "author_profile": "https://Stackoverflow.com/users/7516", "pm_score": 0, "selected": false, "text": "[Enum].Parse(System.Type, Value)\n" }, { "answer_id": 11615617, "author": "GenericJoe", "author_id"...
2008/10/23
[ "https://Stackoverflow.com/questions/231206", "https://Stackoverflow.com", "https://Stackoverflow.com/users/30943/" ]
231,211
<p>Here are two different questions but I think they are related.</p> <ol> <li><p>When using Git, how do I find which changes I have committed locally, but haven't yet pushed to a remote branch? I'm looking for something similar to the Mercurial command <code>hg outgoing</code>.</p></li> <li><p>When using Git, how do I find what changes a remote branch has prior to doing a pull? I'm looking for something similar to the Mercurial command <code>hg incoming</code>.</p></li> </ol> <p>For the second: is there a way to see what is available and then cherry-pick the changes I want to pull?</p>
[ { "answer_id": 231379, "author": "Jordi Bunster", "author_id": 4272, "author_profile": "https://Stackoverflow.com/users/4272", "pm_score": 8, "selected": true, "text": "git fetch" }, { "answer_id": 6122592, "author": "robinst", "author_id": 305973, "author_profile": "...
2008/10/23
[ "https://Stackoverflow.com/questions/231211", "https://Stackoverflow.com", "https://Stackoverflow.com/users/796/" ]
231,214
<p>I am on the way to build an ASP.NET MVC application with the latest beta release and I wonder if it is possible to change the default project Layout of</p> <p>/Views/Home/Index.aspx /Views/Home/About.aspx</p> <p>to</p> <p>/Blog/Views/Home/Index.aspx /Blog/Views/Home/About.aspx</p> <p>/Forum/Views/Home/Index.aspx /Forum/Views/Home/About.aspx</p> <p>The goal is to get some separation between "applications" within one single Web project, something like Thomas Owens asked already here: <a href="https://stackoverflow.com/questions/178398/under-an-mvc-framework-which-directory-structure-would-be-expected-by-other-dev">Under an MVC framework, which directory structure would be expected by other developers?</a> </p> <p>Of course this should include the Controllers as well, not only the Views.</p>
[ { "answer_id": 231565, "author": "Craig Stuntz", "author_id": 7714, "author_profile": "https://Stackoverflow.com/users/7714", "pm_score": 1, "selected": false, "text": "routes.MapRoute(\"Default\",\n \"{applicationName}/{controller}/{action}/{id})\",\n null,...
2008/10/23
[ "https://Stackoverflow.com/questions/231214", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
231,226
<pre><code> include('adodb5/adodb.inc.php'); $myServer = "localhost"; $myUser = "root"; $myPass = "root"; $myDB = "database"; //create an instance of the ADO connection object $conn = new COM("ADODB.Connection") or die("Cannot start ADO"); //define connection string, specify database driver $connStr = "PROVIDER=SQLOLEDB;SERVER=".$myServer.";UID=".$myUser.";PWD=".$myPass.";DATABASE=".$myDB; $conn-&gt;open($connStr); //Open the connection to the database </code></pre> <p>This is the first time I have come across the ADODB library and it supposedly is going to help me switch over from MySQL to Microsoft SQL Server. Does anyone know why i am getting this error or if there is a simpler way that does not involve playing around with the php.ini file?</p>
[ { "answer_id": 234072, "author": "Tom Haigh", "author_id": 22224, "author_profile": "https://Stackoverflow.com/users/22224", "pm_score": 1, "selected": false, "text": "include('adodb5/adodb.inc.php');\n\n$myServer = \"localhost\";\n$myUser = \"root\";\n$myPass = \"root\";\n$myDB = \"data...
2008/10/23
[ "https://Stackoverflow.com/questions/231226", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
231,229
<p>I have source in a bunch of subdirectories like:</p> <pre><code>src/widgets/apple.cpp src/widgets/knob.cpp src/tests/blend.cpp src/ui/flash.cpp </code></pre> <p>In the root of the project I want to generate a single Makefile using a rule like:</p> <pre><code>%.o: %.cpp $(CC) -c $&lt; build/test.exe: build/widgets/apple.o build/widgets/knob.o build/tests/blend.o src/ui/flash.o $(LD) build/widgets/apple.o .... build/ui/flash.o -o build/test.exe </code></pre> <p>When I try this it does not find a rule for build/widgets/apple.o. Can I change something so that the %.o: %.cpp is used when it needs to make build/widgets/apple.o ?</p>
[ { "answer_id": 231418, "author": "JesperE", "author_id": 13051, "author_profile": "https://Stackoverflow.com/users/13051", "pm_score": 7, "selected": true, "text": "%.o: %.cpp\n ...\n" }, { "answer_id": 1427198, "author": "Community", "author_id": -1, "author_pr...
2008/10/23
[ "https://Stackoverflow.com/questions/231229", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7743/" ]
231,250
<p>How would you write a non-recursive algorithm to compute <code>n!</code>?</p>
[ { "answer_id": 231255, "author": "Chris Marasti-Georg", "author_id": 96, "author_profile": "https://Stackoverflow.com/users/96", "pm_score": 3, "selected": false, "text": "public double factorial(int n) {\n double result = 1;\n for(double i = 2; i<=n; ++i) {\n result *= i;\n...
2008/10/23
[ "https://Stackoverflow.com/questions/231250", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
231,257
<p>Let's say you have a dynamic language (similar to common scripting languages) and want to write a compiler for it. Is it good idea to reserve some bits of a machine word for something like type tags? Especially for microcontrollers and similar devices, is it a good idea?</p> <p>I can think of some advantages like reduced storage for type information, somewhat easier memory management (maybe even gc) and easier debugging. But would these justify the overhead on common arithmetic operations or other operations which needs the full word? Note that a bytecode VM will be much worse in this regard since there is much more performance overhead. So don't suggest it ;)</p> <p>It is not like some would write a numerical intense code for a microcontroller-class hardware anyway but still...</p>
[ { "answer_id": 231360, "author": "Dan Lenski", "author_id": 20789, "author_profile": "https://Stackoverflow.com/users/20789", "pm_score": 0, "selected": false, "text": "list" } ]
2008/10/23
[ "https://Stackoverflow.com/questions/231257", "https://Stackoverflow.com", "https://Stackoverflow.com/users/7988/" ]
231,288
<p>I have started using Jython as it seems to be a excellent language, and has proved to be so far.</p> <p>I am using dom4j to manipulate and retrieve data from the DOM of a bunch of HTML files I have on disk. I have wrote the below script to check threw the DOM using Xpath for <strong>H1</strong> tags and grab text, if a <strong>H1</strong> tag is not present in the DOM it then searches for the <strong>title</strong> tag and grabs the text from that.</p> <p>I am very new to Jython but I am sure there is way to perform the required task a lot more graceful than the below method, If I am right in thinking this, is there someone that can show me a better way to do it?</p> <pre><code>elemHolder = dom.createXPath('//xhtml:h1') elemHolder.setNamespaceURIs(map) elem = elemHolder.selectSingleNode(dom) if elem != None: h1 = elem.getText() else: elemHolder = dom.createXPath('//xhtml:title') elemHolder.setNamespaceURIs(map) elem = elemHolder.selectSingleNode(dom) if elem != None: title = elem.getText() else: title = "Page does not contain a H1 or title tag" </code></pre> <p>If anyone could help it would be great. Cheers</p>
[ { "answer_id": 231335, "author": "C. K. Young", "author_id": 13, "author_profile": "https://Stackoverflow.com/users/13", "pm_score": 3, "selected": true, "text": "for path in ('//xhtml:h1', '//xhtml:title'):\n elemHolder = dom.createXPath(path)\n elemHolder.namespaceURIs = map\n ...
2008/10/23
[ "https://Stackoverflow.com/questions/231288", "https://Stackoverflow.com", "https://Stackoverflow.com/users/30786/" ]
231,321
<p>I cant' figure out how to reference the current instance object defined by the XAML file in the XAML file.</p> <p>I have a converter that I want to send in the current instance as the parameter object.</p> <pre><code>{Binding Path=&lt;bindingObject&gt;, Converter={x:Static namespace:Converter.Instance}, ConverterParameter=this} </code></pre> <p>In this code this is converted to a string instead of a reference to the current instance object.</p> <p>Thanks</p> <p>John</p>
[ { "answer_id": 231446, "author": "Omer van Kloeten", "author_id": 4979, "author_profile": "https://Stackoverflow.com/users/4979", "pm_score": 0, "selected": false, "text": "RelativeSource" }, { "answer_id": 231500, "author": "Dillie-O", "author_id": 71, "author_profil...
2008/10/23
[ "https://Stackoverflow.com/questions/231321", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9331/" ]
231,323
<p>Anyone know off the top of their heads how to convert a System.Xml.XmlNode to System.Xml.Linq.XNode?</p>
[ { "answer_id": 231412, "author": "Chris Shaffer", "author_id": 6744, "author_profile": "https://Stackoverflow.com/users/6744", "pm_score": 5, "selected": true, "text": "XmlNode myNode;\nXNode translatedNode = XDocument.Parse(myNode.OuterXml);\n" } ]
2008/10/23
[ "https://Stackoverflow.com/questions/231323", "https://Stackoverflow.com", "https://Stackoverflow.com/users/21909/" ]
231,327
<p>I want to use the <a href="http://simplehtmldom.sourceforge.net/manual_api.htm" rel="noreferrer">php simple HTML DOM parser</a> to grab the image, title, date, and description from each article on a page full of articles. When looking at the API I notice it has a set_callback which Sets a callback function. However im not sure what this does or how I would use it? In one of the examples its used to call a function which strips out some stuff, im wondering if you have to use this to call all functions?</p> <p>I guess im wondering why I use this, and what does it do as I have never come across a callback function before!</p>
[ { "answer_id": 231339, "author": "Mark Biek", "author_id": 305, "author_profile": "https://Stackoverflow.com/users/305", "pm_score": 6, "selected": true, "text": "<?php\n\nfunction thisFuncTakesACallback($callbackFunc)\n{\n echo \"I'm going to call $callbackFunc!<br />\";\n $callba...
2008/10/23
[ "https://Stackoverflow.com/questions/231327", "https://Stackoverflow.com", "https://Stackoverflow.com/users/28241/" ]
231,340
<p>In a project I am working on, Apache is set up to only forward requests that come in as /prefix/* to mongrel. How can I tell ruby on rails to generate all URLs with that prefix? </p> <p>I have the routes set up for forward to the correct controller action by doing this:</p> <pre><code>map.connect 'sfc/:controller/:action' </code></pre> <p>but that doesn't seem to affect the way that the url writer generates the URLs.</p> <p>Any ideas?</p>
[ { "answer_id": 231417, "author": "Can Berk Güder", "author_id": 2119, "author_profile": "https://Stackoverflow.com/users/2119", "pm_score": 2, "selected": false, "text": "RAILS_RELATIVE_URL_ROOT" }, { "answer_id": 231752, "author": "Mike Breen", "author_id": 22346, "a...
2008/10/23
[ "https://Stackoverflow.com/questions/231340", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1486/" ]
231,344
<p>I am using the ASP.Net plugin and control provided by <a href="http://recaptcha.net" rel="noreferrer">reCAPTCHA</a>. I can successfully get the control to work if the submit button on the web form is not in a validationgroup. There is no validationgroup attribute for the reCAPTCHA control. </p> <p>Has anybody had any success with this or any solutions to get the reCAPTCHA control to work when there is a validationgroup on the web form?</p>
[ { "answer_id": 352439, "author": "bzlm", "author_id": 7724, "author_profile": "https://Stackoverflow.com/users/7724", "pm_score": 3, "selected": true, "text": "ValidationGroup" }, { "answer_id": 4380268, "author": "Remotec", "author_id": 169640, "author_profile": "htt...
2008/10/23
[ "https://Stackoverflow.com/questions/231344", "https://Stackoverflow.com", "https://Stackoverflow.com/users/24522/" ]
231,355
<p>Hi guys I wrote this code and i have two errors.</p> <ol> <li>Invalid rank specifier: expected ',' or ']' </li> <li>Cannot apply indexing with [] to an expression of type 'int'</li> </ol> <p>Can you help please?</p> <pre><code> static void Main(string[] args) { ArrayList numbers = new ArrayList(); foreach (int number in new int[12] {10,9,8,7,6,5,4,3,2,1}) //error No.1 { numbers.Add(number); } numbers.Insert(numbers.Count - 1, 75); numbers.Remove(7); numbers.RemoveAt(6); for(int i=0; i&lt;numbers.Count; i++) { int number = (int) number[i]; // error No.2 Console.WriteLine(number); } } </code></pre>
[ { "answer_id": 231380, "author": "Drew Noakes", "author_id": 24874, "author_profile": "https://Stackoverflow.com/users/24874", "pm_score": 2, "selected": false, "text": "foreach (int number in new int[] {10,9,8,7,6,5,4,3,2,1})\n" }, { "answer_id": 231385, "author": "Adam Lass...
2008/10/23
[ "https://Stackoverflow.com/questions/231355", "https://Stackoverflow.com", "https://Stackoverflow.com/users/30858/" ]
231,358
<p>I'm using NuSOAP on PHP 5.2.6 and I'm seeing that the max message size is only 1000 bytes (which makes it tough to do anything meaningful). Is this set in the endpoint's WSDL or is this something I can configure in NuSOAP?</p>
[ { "answer_id": 232885, "author": "Dan Soap", "author_id": 25253, "author_profile": "https://Stackoverflow.com/users/25253", "pm_score": 2, "selected": false, "text": "max_input_time (defaults to 60)\n" }, { "answer_id": 3926436, "author": "Daniel Alvarez Arribas", ...
2008/10/23
[ "https://Stackoverflow.com/questions/231358", "https://Stackoverflow.com", "https://Stackoverflow.com/users/11577/" ]
231,362
<p>For some weeks now I simply can't run gem install in windows. It sticks on this line:</p> <pre><code>C:\Windows\System32&gt;gem install rails --version 2.1.2 Bulk updating Gem source index for: http://gems.rubyforge.org/ </code></pre> <p>Any ideas what it could be?</p>
[ { "answer_id": 231670, "author": "dbr", "author_id": 745, "author_profile": "https://Stackoverflow.com/users/745", "pm_score": 1, "selected": true, "text": "gem install rails.gem" } ]
2008/10/23
[ "https://Stackoverflow.com/questions/231362", "https://Stackoverflow.com", "https://Stackoverflow.com/users/19224/" ]
231,364
<p>I am currently building a small website where the content of the main div is being filled through an Ajax call. I basically have a php script that returns the content like this:</p> <p>(simplified php script...)</p> <pre><code> if(isset($_POST["id_tuto"])){ PrintHtml($_POST["id_tuto"]); } function PrintHtml($id) { switch($id) { case [...]: echo "THIS IS MY HTML CONTENT"; break; [...] } } </code></pre> <p>The web page then gets the text from that echo command and replaces the inner html of the content div.</p> <p>My question is this : What is the best way to echo that html content? there is a lot of content each time since it's a step by step tutorial. Each string will be about 50-80 lines of HTML code. Is there a way to put that html content in a separate html file and echo that file or...?</p> <p>Thanks a lot!!</p>
[ { "answer_id": 231430, "author": "defrex", "author_id": 6007, "author_profile": "https://Stackoverflow.com/users/6007", "pm_score": 3, "selected": true, "text": "<?php\n function PrintHtml($id) {\n switch($id) {\n case [...]:\n?>\n <h1>Tut page 1</h1>\n <p>this...
2008/10/23
[ "https://Stackoverflow.com/questions/231364", "https://Stackoverflow.com", "https://Stackoverflow.com/users/25152/" ]
231,371
<p>Which are the most advanced frameworks and tools there are available for python for practicing Behavior Driven Development? Especially finding similar tools as rspec and mocha for ruby would be great.</p>
[ { "answer_id": 2999652, "author": "Douglas Camata", "author_id": 361638, "author_profile": "https://Stackoverflow.com/users/361638", "pm_score": 5, "selected": false, "text": "pip install specloud\n" }, { "answer_id": 11279439, "author": "mdwhatcott", "author_id": 605022,...
2008/10/23
[ "https://Stackoverflow.com/questions/231371", "https://Stackoverflow.com", "https://Stackoverflow.com/users/30958/" ]
231,377
<p>I would like to use JavaScript to manipulate hidden input fields in a JSF/Facelets page. When the page loads, I need to set a hidden field to the color depth of the client.</p> <p>From my Facelet:</p> <pre><code>&lt;body onload="setColorDepth(document.getElementById(?????);"&gt; &lt;h:form&gt; &lt;h:inputHidden value="#{login.colorDepth}" id="colorDepth" /&gt; &lt;/h:form&gt; </code></pre> <p>When JSF processes the page, it is of course changing the IDs of the elements. What's the best way to reference these elements from my JavaScript code?</p>
[ { "answer_id": 231393, "author": "sblundy", "author_id": 4893, "author_profile": "https://Stackoverflow.com/users/4893", "pm_score": 3, "selected": true, "text": "<body onload=\"setColorDepth(document.getElementById('myForm:colorDepth');\">\n\n<h:form id=\"myForm\">\n <h:inputHidden val...
2008/10/23
[ "https://Stackoverflow.com/questions/231377", "https://Stackoverflow.com", "https://Stackoverflow.com/users/27515/" ]
231,381
<p>Is this seen as an in efficient prime number generator. It seems to me that this is pretty efficient. Is it the use of the stream that makes the program run slower?</p> <p>I am trying to submit this to <a href="http://www.spoj.pl/" rel="nofollow noreferrer">SPOJ</a> and it tells me that my time limit exceeded... </p> <pre><code>#include &lt;iostream&gt; #include &lt;sstream&gt; using namespace std; int main() { int testCases, first, second, counter = 0; bool isPrime = true; stringstream out; cin &gt;&gt; testCases; for (int i = 0; i &lt; testCases; i++) { // get the next two numbers cin &gt;&gt; first &gt;&gt; second; if (first%2 == 0) first++; // find the prime numbers between the two given numbers for (int j = first; j &lt;= second; j+=2) { // go through and check if j is prime for (int k = 2; k &lt; j; k++) { if (j%k == 0) { isPrime = false; break; } } if (isPrime) { out &lt;&lt; j &lt;&lt; "\n"; } isPrime = true; } out &lt;&lt; "\n"; } cout &lt;&lt; out.str(); return 0; } </code></pre> <p>EDIT: The program is supposed to generate prime numbers between the numbers specified in the input. (See here for more details: <a href="http://www.spoj.pl/problems/PRIME1/" rel="nofollow noreferrer">Prime Generator Problem</a> )</p> <p>-Tomek</p>
[ { "answer_id": 231400, "author": "warren", "author_id": 4418, "author_profile": "https://Stackoverflow.com/users/4418", "pm_score": 3, "selected": false, "text": "<= (sqrt(num))" }, { "answer_id": 231421, "author": "Austin Salonen", "author_id": 4068, "author_profile"...
2008/10/23
[ "https://Stackoverflow.com/questions/231381", "https://Stackoverflow.com", "https://Stackoverflow.com/users/29326/" ]
231,390
<p>I've been trying to install <a href="http://thoughtbot.com/projects/shoulda" rel="nofollow noreferrer">Shoulda</a></p> <pre><code>script/plugin install git://github.com/thoughtbot/shoulda.git </code></pre> <p>but all I get is:</p> <pre><code>removing: C:/Documents and Settings/Danny/My Documents/Projects/Ruby On Rails/_ProjectName_/vendor/plugins/shoulda/.git &gt; </code></pre> <p>And the <code>vender/plugins</code> directory is empty. I have Rails 2.1.1 installed as a gem and have verified that 2.1.1 is loaded (using a puts inserted into config/boot.rb). Any ideas about what's going on?</p> <p>(this is on a windows box)</p>
[ { "answer_id": 3067200, "author": "Chris Charabaruk", "author_id": 5697, "author_profile": "https://Stackoverflow.com/users/5697", "pm_score": 0, "selected": false, "text": "--- reporting.rb.orig 2010-06-11 01:00:24.739991600 -0400\n+++ reporting.rb 2010-06-18 00:16:39.517649400...
2008/10/23
[ "https://Stackoverflow.com/questions/231390", "https://Stackoverflow.com", "https://Stackoverflow.com/users/13216/" ]
231,407
<p>I'm looking for a GWT common purpose paging widget. So far I have found <a href="http://gwt-widget.sourceforge.net/" rel="nofollow noreferrer">GWT widget library</a> and the <a href="http://code.google.com/p/google-web-toolkit-incubator/w/list" rel="nofollow noreferrer">Google Incubator widgets</a>. Is there any other free (possibly open source) widget library implementing a paging behavior.</p>
[ { "answer_id": 4300686, "author": "Robin", "author_id": 416740, "author_profile": "https://Stackoverflow.com/users/416740", "pm_score": 0, "selected": false, "text": "CellTable" } ]
2008/10/23
[ "https://Stackoverflow.com/questions/231407", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6482/" ]
231,438
<p>Does anybody have an implementation of <a href="http://en.wikipedia.org/wiki/Cuckoo_hashing" rel="noreferrer">Cuckoo hashing</a> in C? If there was an Open Source, non GPL version it would be perfect!</p> <p>Since Adam mentioned it in his comment, anyone knows why it is not much used? Is it just a matter of implementation or the good theoretical properties do not materialize in practice?</p>
[ { "answer_id": 232624, "author": "Remo.D", "author_id": 16827, "author_profile": "https://Stackoverflow.com/users/16827", "pm_score": 1, "selected": false, "text": "void *" }, { "answer_id": 239964, "author": "Remo.D", "author_id": 16827, "author_profile": "https://St...
2008/10/23
[ "https://Stackoverflow.com/questions/231438", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16827/" ]
231,439
<p>Is there any easy way to create an acronym from a string?</p> <pre><code>First_name Middle_name Last_name =&gt; FML first_name middle_name last_name =&gt; FML First_name-Middle_name Last_name =&gt; F-ML first_name-middle_name last_name =&gt; F-ML </code></pre>
[ { "answer_id": 231473, "author": "Franci Penov", "author_id": 17028, "author_profile": "https://Stackoverflow.com/users/17028", "pm_score": 2, "selected": false, "text": "Tokenize the string on whitespace.\nFor each token1,\n Tokenize on dash.\n For each token2\n Take token2[0] and ...
2008/10/23
[ "https://Stackoverflow.com/questions/231439", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3718/" ]
231,478
<p>I have a site, foo.com, that makes ajax requests to bar.foo.com. Will this work.</p> <p>Also, if foo is a secure connection, https, does bar.foo.com need to be https too? Can these two sites use different certificates?</p>
[ { "answer_id": 231706, "author": "joelhardi", "author_id": 11438, "author_profile": "https://Stackoverflow.com/users/11438", "pm_score": 4, "selected": false, "text": "document.domain" }, { "answer_id": 14816153, "author": "Yogi", "author_id": 1995680, "author_profile...
2008/10/23
[ "https://Stackoverflow.com/questions/231478", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
231,491
<p>Is there an elegant way to create and initialize a <code>const std::vector&lt;const T&gt;</code> like <code>const T a[] = { ... }</code> to a fixed (and small) number of values?<br> I need to call a function frequently which expects a <code>vector&lt;T&gt;</code>, but these values will never change in my case.</p> <p>In principle I thought of something like</p> <pre><code>namespace { const std::vector&lt;const T&gt; v(??); } </code></pre> <p>since v won't be used outside of this compilation unit.</p>
[ { "answer_id": 231495, "author": "Ferruccio", "author_id": 4086, "author_profile": "https://Stackoverflow.com/users/4086", "pm_score": 7, "selected": true, "text": "vector<int> luggage_combo = { 1, 2, 3, 4, 5 };\n" }, { "answer_id": 231524, "author": "Steve Jessop", "auth...
2008/10/23
[ "https://Stackoverflow.com/questions/231491", "https://Stackoverflow.com", "https://Stackoverflow.com/users/26613/" ]
231,512
<p>I am using RedCloth with Rails 2.1.1. The Textile <code>&lt;del&gt;</code> tag markup format (i.e. -delete-) was not translating at all. Tried a few choice options.</p> <pre><code>&gt; x=RedCloth.new('foobar -blah-') =&gt; "foobar -blah-" &gt; x.to_html =&gt; "&lt;p&gt;foobar &lt;del&gt;blah&lt;/del&gt;&lt;/p&gt;" # WORKED! &gt; x=RedCloth.new('foobar * -blah-') =&gt; "foobar * -blah-" &gt; x.to_html =&gt; "&lt;p&gt;foobar * &lt;del&gt;blah&lt;/del&gt;&lt;/p&gt;" # WORKED! &gt; x=RedCloth.new("foobar\n* -blah-") =&gt; "foobar\n* -blah-" &gt; x.to_html =&gt; "&lt;p&gt;foobar&lt;/p&gt;\n&lt;ul&gt;\n\t&lt;li&gt;-blah-&lt;/li&gt;\n&lt;/ul&gt;" # DID NOT WORK! </code></pre> <p>It appears to me that newlines are the culprit in throwing RedCloth up-in-arms. Any solutions to getting RedCloth to properly recognize '-delete-'? I have tried RedCloth 4.0.1, 4.0.3, and 4.0.4.</p>
[ { "answer_id": 231660, "author": "Michael Sepcot", "author_id": 6033, "author_profile": "https://Stackoverflow.com/users/6033", "pm_score": 2, "selected": false, "text": ">> RedCloth.new(\"foobar\\n* [-blah-]\").to_html\n=> \"<p>foobar</p>\\n<ul>\\n\\t<li><del>blah</del></li>\\n</ul>\"\n...
2008/10/23
[ "https://Stackoverflow.com/questions/231512", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14895/" ]
231,525
<p>We're all familiar with the horror that is C# event declaration. To ensure thread-safety, <a href="http://blogs.msdn.com/brada/archive/2005/01/14/353132.aspx" rel="noreferrer">the standard is to write something like this</a>:</p> <pre><code>public event EventHandler SomethingHappened; protected virtual void OnSomethingHappened(EventArgs e) { var handler = SomethingHappened; if (handler != null) handler(this, e); } </code></pre> <p>Recently in some other question on this board (which I can't find now), someone pointed out that extension methods could be used nicely in this scenario. Here's one way to do it:</p> <pre><code>static public class EventExtensions { static public void RaiseEvent(this EventHandler @event, object sender, EventArgs e) { var handler = @event; if (handler != null) handler(sender, e); } static public void RaiseEvent&lt;T&gt;(this EventHandler&lt;T&gt; @event, object sender, T e) where T : EventArgs { var handler = @event; if (handler != null) handler(sender, e); } } </code></pre> <p>With these extension methods in place, all you need to declare and raise an event is something like this:</p> <pre><code>public event EventHandler SomethingHappened; void SomeMethod() { this.SomethingHappened.RaiseEvent(this, EventArgs.Empty); } </code></pre> <p>My question: Is this a good idea? Are we missing anything by not having the standard On method? (One thing I notice is that it doesn't work with events that have explicit add/remove code.)</p>
[ { "answer_id": 231536, "author": "Jon Skeet", "author_id": 22656, "author_profile": "https://Stackoverflow.com/users/22656", "pm_score": 7, "selected": true, "text": "public event EventHandler SomethingHappened = delegate {};\n" }, { "answer_id": 231548, "author": "Cristian L...
2008/10/23
[ "https://Stackoverflow.com/questions/231525", "https://Stackoverflow.com", "https://Stackoverflow.com/users/5486/" ]
231,538
<p>So I have a snazzy custom route for login</p> <pre><code># routes.rb map.login '/login', :controller =&gt; 'sessions', :action =&gt; 'new' </code></pre> <p>Visit www.asite.com/login and you're there. As is custom with failed login, however, we'll do the following in our action. Note what happens on failed login.</p> <pre><code> # sessions_controller.rb def create self.current_user = User.authenticate(params[:email], params[:password]) if logged_in? # some work and redirect the user else flash.now[:warning] = "The email and/or password you entered is invalid." render :action =&gt; 'new' end end </code></pre> <p>This is very typical. Simply render the new action and prompt for login again. Unfortunately you also get with it an ugly URL: www.asite.com/session. Ick! Is it possible to get rendering to respect the original URL?</p>
[ { "answer_id": 231625, "author": "Michael Sepcot", "author_id": 6033, "author_profile": "https://Stackoverflow.com/users/6033", "pm_score": 0, "selected": false, "text": "render :action => 'new'" }, { "answer_id": 232888, "author": "tomafro", "author_id": 7126, "autho...
2008/10/23
[ "https://Stackoverflow.com/questions/231538", "https://Stackoverflow.com", "https://Stackoverflow.com/users/14895/" ]
231,550
<p>I'd like to use the <a href="https://developer.mozilla.org/en/Rhino_JavaScript_Compiler" rel="nofollow noreferrer">Rhino JavaScript</a> compiler to compile some JavaScript to .class bytecode files for use in a project. It seems like this should already exist, since there are groovyc, netrexxc, and jythonc tasks for Groovy, NetREXX(!) and Jython, respectively. Has anyone used or written such an Ant task, or can anyone provide some tips on how to write one?</p> <p>Ideally it would have some way to resolve dependencies among JavaScript or Java classes.</p>
[ { "answer_id": 231750, "author": "Vladimir Dyuzhev", "author_id": 1163802, "author_profile": "https://Stackoverflow.com/users/1163802", "pm_score": 4, "selected": true, "text": "<java fork=\"yes\" \n classpathref=\"build.path\" \n classname=\"org.mozilla.javascript.tools.jsc.Main\" \n ...
2008/10/23
[ "https://Stackoverflow.com/questions/231550", "https://Stackoverflow.com", "https://Stackoverflow.com/users/28604/" ]
231,553
<p>As an amateur software developer (I'm still in academia) I've written a few schemas for XML documents. I routinely run into design flubs that cause ugly-looking XML documents because I'm not entirely certain what the semantics of XML exactly are.</p> <p>My assumptions:</p> <pre><code>&lt;property&gt; value &lt;/property&gt; </code></pre> <p>property = value</p> <pre><code>&lt;property attribute=&quot;attval&quot;&gt; value &lt;/property&gt; </code></pre> <p>A property with a special descriptor, the attribute.</p> <pre><code>&lt;parent&gt; &lt;child&gt; value &lt;/child&gt; &lt;/parent&gt; </code></pre> <p>The parent has a characteristic &quot;child&quot; which has the value &quot;value.&quot;</p> <pre><code>&lt;tag /&gt; </code></pre> <p>&quot;Tag&quot; is a flag or it directly translates to text. I'm not sure on this one.</p> <pre><code>&lt;parent&gt; &lt;child /&gt; &lt;/parent&gt; </code></pre> <p>&quot;child&quot; describes &quot;parent.&quot; &quot;child&quot; is a flag or boolean. I'm not sure on this one, either.</p> <p>Ambiguity arises if you want to do something like representing cartesian coordinates:</p> <pre><code>&lt;coordinate x=&quot;0&quot; y=&quot;1&quot; /&gt; &lt;coordinate&gt; 0,1 &lt;/coordinate&gt; &lt;coordinate&gt; &lt;x&gt; 0 &lt;/x&gt; &lt;y&gt; 1 &lt;/y&gt; &lt;/coordinate&gt; </code></pre> <p>Which one of these options is most correct? I would lean towards the third based upon my current conception of XML schema design, but I really don't know.</p> <p>What are some resources that succinctly describe how to effectively design xml schemas?</p>
[ { "answer_id": 231586, "author": "Greg Beech", "author_id": 13552, "author_profile": "https://Stackoverflow.com/users/13552", "pm_score": 2, "selected": false, "text": "<coordinate x=\"\" y=\"\"/>" }, { "answer_id": 231595, "author": "Kris", "author_id": 18565, "autho...
2008/10/23
[ "https://Stackoverflow.com/questions/231553", "https://Stackoverflow.com", "https://Stackoverflow.com/users/29119/" ]
231,592
<p>I have some char() fields in a DBF table that were left encrypted by a past developer in the project. </p> <p>However, I know the plaintext result of the decryption of several records. How can I determine the function/algorithm/scheme to decrypt the original data? These are some sample fields:</p> <p>For cryptext:</p> <pre><code>b5 01 02 c1 e3 0d 0a </code></pre> <p>plaintext should be:</p> <pre><code>3543921 or 3.543.921 </code></pre> <p>And for cryptext:</p> <pre><code>41 c3 c5 07 17 0d 0a </code></pre> <p>plaintext should be</p> <pre><code>1851154 or 1.851.154 </code></pre> <p>I believe <code>0d 0a</code> is just padding. Was from data gathered in win-1252 encoding (dunno if matters)</p> <p><strong>EDIT:</strong> It's for the sake of curiosity and learning. I want to be able to undestand the encryption used(seems a simple one, although is binary data) to recover the value of the fields for the tuples whose plaintext I don't know.</p> <p><strong>EDIT 2:</strong> Added a couple samples.</p>
[ { "answer_id": 231611, "author": "Sergey", "author_id": 29363, "author_profile": "https://Stackoverflow.com/users/29363", "pm_score": 3, "selected": true, "text": "for (i in originalString) {\nnewString[i] = originalString[i] ^ CRYPT_BYTE;\n}\n" } ]
2008/10/23
[ "https://Stackoverflow.com/questions/231592", "https://Stackoverflow.com", "https://Stackoverflow.com/users/861/" ]
231,607
<p>Suppose you have the canonical Customer domain object. You have three different screens on which Customer is displayed: External Admin, Internal Admin, and Update Account.</p> <p>Suppose further that each screen displays only a subset of all of the data contained in the Customer object. </p> <p>The problem is: when the UI passes data back from each screen (e.g. through a DTO), it contains only that subset of a full Customer domain object. So when you send that DTO to the Customer Factory to re-create the Customer object, you have only part of the Customer.</p> <p>Then you send this Customer to your Customer Repository to save it, and a bunch of data will get wiped out because it isn't there. Tragedy ensues.</p> <p>So the question is: how would you deal with this problem?</p> <p>Some of my ideas:</p> <ul> <li><p>include an argument to the Repository indicating which part of the Customer to update, and ignore others</p></li> <li><p>when you load the Customer, keep it in static memory, or in the session, or wherever, and then when you receive one of the DTOs from the UI, update only the parts relevant to the DTO</p></li> </ul> <p>IMO, both of these are kludges. Are there any other better ideas?</p> <p>@chadmyers: Here is the problem.</p> <p>Entity has properties A, B, C, and D.</p> <p>DTO #1 contains properties for B and C.</p> <p>DTO #2 contains properties for C and D.</p> <p>UI asks for DTO #1, you load entity from the repository, convert it into DTO #1, filling in only B and C, and give it to the UI.</p> <p>Now UI updates B and sends the DTO back. You recreate the entity and it has only B and C filled in because that is all that is contained in the DTO.</p> <p>Now you want to save the entity, which has only B and C filled in, with A and D null/blank. The repository has no way of knowing if it should update A and D in persistence as blanks, or whether it should ignore them.</p>
[ { "answer_id": 904930, "author": "5x1llz", "author_id": 96074, "author_profile": "https://Stackoverflow.com/users/96074", "pm_score": 1, "selected": false, "text": "dtoUser.MapFrom<In,Out>(Entity)\nor\ndtoAdmin.MapFrom<In,Out>(Entity)\n" } ]
2008/10/23
[ "https://Stackoverflow.com/questions/231607", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10759/" ]
231,630
<p>I want to override the default CreateObject() function in VBScript with my own.</p> <p>Basically this example in VB6:</p> <p><a href="http://www.darinhiggins.com/the-vb6-createobject-function/" rel="nofollow noreferrer">http://www.darinhiggins.com/the-vb6-createobject-function/</a></p> <p>I cannot figure out is this line:</p> <pre><code> Set CreateObject = VBA.CreateObject(Class$, ServerName$) </code></pre> <p>How do I refer to "VBA" in VBSript?</p>
[ { "answer_id": 231701, "author": "PhiLho", "author_id": 15459, "author_profile": "https://Stackoverflow.com/users/15459", "pm_score": 2, "selected": false, "text": "Function CreateObject(className, serverName)\n '---- override the CreateObject\n ' function in order to register wh...
2008/10/23
[ "https://Stackoverflow.com/questions/231630", "https://Stackoverflow.com", "https://Stackoverflow.com/users/-1/" ]
231,637
<p>I need to match (case insensitive) "abcd" and an optional trademark symbol</p> <p>Regex: <code>/abcd(™)?/gi</code></p> <p>See example:</p> <pre><code>preg_match("/abcd(™)?/gi","AbCd™ U9+",$matches); print_r($matches); </code></pre> <p>When I run this, <code>$matches</code> isn't populated with anything... Not even created as an empty array. Any ideas?</p>
[ { "answer_id": 231656, "author": "Douglas Mayle", "author_id": 8458, "author_profile": "https://Stackoverflow.com/users/8458", "pm_score": 4, "selected": true, "text": "\\x99" }, { "answer_id": 231659, "author": "tzot", "author_id": 6899, "author_profile": "https://St...
2008/10/23
[ "https://Stackoverflow.com/questions/231637", "https://Stackoverflow.com", "https://Stackoverflow.com/users/53001/" ]
231,647
<p>How do you set the timeout for blocking operations on a Ruby socket?</p>
[ { "answer_id": 231662, "author": "readonly", "author_id": 4883, "author_profile": "https://Stackoverflow.com/users/4883", "pm_score": 5, "selected": true, "text": "require 'timeout'\n ...\nbegin \n timeout(5) do\n message, client_address = some_socket.recvfrom(1024)\n end...
2008/10/23
[ "https://Stackoverflow.com/questions/231647", "https://Stackoverflow.com", "https://Stackoverflow.com/users/4883/" ]
231,649
<p>With common lisp and I am assuming the introspection properties. How can I add code to common lisp code that will tell me when a function is called and when has finished executing. I want to take any lisp code and this particular modification to the code. I figure with lisp's AST analysis, this should be possible.</p>
[ { "answer_id": 232638, "author": "dsm", "author_id": 7780, "author_profile": "https://Stackoverflow.com/users/7780", "pm_score": 4, "selected": true, "text": "(trace function)" } ]
2008/10/23
[ "https://Stackoverflow.com/questions/231649", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10522/" ]
231,666
<p>I wonder if anyone could suggest the best way of looping through all the <code>&lt;option&gt;</code> s in a <code>&lt;select&gt;</code> element with jQuery, and building an array.</p> <p>Eg.</p> <p>Instead of the following, whereby a string ins passed to the autoCompleteArray(),</p> <pre><code>$("#CityLocal").autocompleteArray( [ "Aberdeen", "Ada", "Adamsville", "Zoar" //and a million other cities... ], { delay:10, minChars:1, matchSubset:1, onItemSelect:selectItem, onFindValue:findValue, autoFill:true, maxItemsToShow:10 } ); </code></pre> <p>...I need to loop through all the <code>&lt;options&gt;</code> in a <code>&lt;select&gt;</code> and push them into an array, and just pass that array variable to the function instead of a long string.</p> <p>Eg,</p> <pre><code>$("#CityLocal").autocompleteArray( [ MyBigArrayOfOptions ], { delay:10, minChars:1, matchSubset:1, onItemSelect:selectItem, onFindValue:findValue, autoFill:true, maxItemsToShow:10 } ); </code></pre> <p>I'd be grateful if you could suggest how to push stuff into an array in the correct format. I've pretty much sussed the looping part from another post on this site.</p> <p>Thanks.</p>
[ { "answer_id": 231699, "author": "Damir Zekić", "author_id": 401510, "author_profile": "https://Stackoverflow.com/users/401510", "pm_score": 4, "selected": true, "text": "$(document).ready(function(){\n // array of option elements' values\n var optionValues = [];\n // array of option ...
2008/10/23
[ "https://Stackoverflow.com/questions/231666", "https://Stackoverflow.com", "https://Stackoverflow.com/users/26107/" ]
231,677
<p>Given this in a grails action:</p> <pre><code>def xml = { rss(version: '2.0') { ... } } render(contentType: 'application/rss+xml', xml) </code></pre> <p>I see this:</p> <pre><code>&lt;rss&gt;&lt;channel&gt;&lt;title&gt;&lt;/title&gt;&lt;description&gt;&lt;/description&gt;&lt;link&gt;&lt;/link&gt;&lt;item&gt;&lt;/item&gt;&lt;/channel&gt;&lt;/rss&gt; </code></pre> <p>Is there an easy way to pretty print the XML? Something built into the render method, perhaps?</p>
[ { "answer_id": 232101, "author": "seansand", "author_id": 9452, "author_profile": "https://Stackoverflow.com/users/9452", "pm_score": 4, "selected": false, "text": "def xml = \"<rss><channel><title></title><description>\" +\n \"</description><link></link><item></item></channel></rss>\"...
2008/10/23
[ "https://Stackoverflow.com/questions/231677", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2031/" ]
231,679
<p>To add a svg graphics in html page, it is common to use object tag to wrap it like this:</p> <pre><code>&lt;object id="svgid" data="mysvg.svg" type="image/svg+xml" wmode="transparent" width="100" height="100"&gt; this browser is not able to show SVG: &lt;a linkindex="3" href="http://getfirefox.com"&gt;http://getfirefox.com&lt;/a&gt; is free and does it! If you use Internet Explorer, you can also get a plugin: &lt;a linkindex="4" href="http://www.adobe.com/svg/viewer/install/main.html"&gt; http://www.adobe.com/svg/viewer/install/main.html&lt;/a&gt; &lt;/object&gt; </code></pre> <p>If you do not use width and height attributes in the object tag, the svg will be displayed in full size. Normally I get svg files from Open Graphics Library for testing. Is there any way to get svg's size by using JavaScript? Or maybe I should just look at the svg xml file to find out the size from the top svg tag?</p>
[ { "answer_id": 233819, "author": "Jon Cram", "author_id": 5343, "author_profile": "https://Stackoverflow.com/users/5343", "pm_score": 3, "selected": false, "text": "object" }, { "answer_id": 1577890, "author": "codedread", "author_id": 67838, "author_profile": "https:...
2008/10/23
[ "https://Stackoverflow.com/questions/231679", "https://Stackoverflow.com", "https://Stackoverflow.com/users/62776/" ]
231,690
<p>When creating web parts for Sharepoint, is it better to create an actual web part, or is using and ASP.NET User Control (.ascx) just as good?</p> <p>I already know how to create the user controls that I need, so it seems like the extra effort of creating a web part is just unnecessary leg work.</p> <p>What are the advantages of using a web part over just creating and ASP.NET user control?</p>
[ { "answer_id": 232185, "author": "Nat", "author_id": 13813, "author_profile": "https://Stackoverflow.com/users/13813", "pm_score": 3, "selected": false, "text": "CreateChildControls()" } ]
2008/10/23
[ "https://Stackoverflow.com/questions/231690", "https://Stackoverflow.com", "https://Stackoverflow.com/users/10420/" ]
231,693
<p>I have created a pretty basic Flash website for a client and am having an issue programming a Client Login feature that he would like. Currently, if I navigate to the site and click Client Login, it takes me to a login page. The way I need this to work is -- within the Flash, using ActionScript 2.0 -- have the user enter their UserID and Password and click to login, which submits POST vars to the form action of the Client Login website.</p> <p>Is this possible/legal to do from a different domain? How would I go about doing this, assuming it's possible?</p>
[ { "answer_id": 231779, "author": "Diodeus - James MacFarlane", "author_id": 12579, "author_profile": "https://Stackoverflow.com/users/12579", "pm_score": 3, "selected": true, "text": "myVars = new LoadVars();\nmyVars.username = username.text;\nmyVars.password = pwd.text;\nmyVars.onLoad =...
2008/10/23
[ "https://Stackoverflow.com/questions/231693", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2715/" ]
231,695
<p>I need to store several date values in a database field. These values will be tied to a "User" such that each user will have their own unique set of these several date values.</p> <p>I could use a one-to-many relationship here but each user will have exactly 4 date values tied to them so I feel that a one-to-many table would be overkill (in many ways e.g. speed) but if I needed to query against them I would need those 4 values to be in different fields e.g. MyDate1 MyDate2 ... etc. but then the SQL command to fetch it out would have to check for 4 values each time.</p> <p>So the one-to-many relationship would probably be the best solution, but is there a better/cleaner/faster/whatever another way around? Am I designing it correctly?</p> <p>The platform is MS SQL 2005 but solution on any platform will do, I'm mostly looking for proper db designing techniques.</p> <p><strong>EDIT:</strong> The 4 fields represent 4 instances of the same thing.</p>
[ { "answer_id": 231711, "author": "Douglas Mayle", "author_id": 8458, "author_profile": "https://Stackoverflow.com/users/8458", "pm_score": 3, "selected": true, "text": "SELECT * FROM MyTable WHERE 'DateLiteral' IN (MyDate1, MyDate2, MyDate3, MyDate4);\n" }, { "answer_id": 231828,...
2008/10/23
[ "https://Stackoverflow.com/questions/231695", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3055/" ]
231,716
<p>I have a table in an MS SQL Server db. I want to create a script that will put the table and all records into another db. So I right-click the table in Management Studio and select Create-To new query editor... but all I get is the table structure. </p> <p>How exactly do I get the values too?</p>
[ { "answer_id": 231754, "author": "Vinko Vrsalovic", "author_id": 5190, "author_profile": "https://Stackoverflow.com/users/5190", "pm_score": 2, "selected": false, "text": "INSERT INTO [destinationdb].[dbo].[destinationtable] SELECT * \nFROM [originaldb].[dbo].[originaltable]\n" } ]
2008/10/23
[ "https://Stackoverflow.com/questions/231716", "https://Stackoverflow.com", "https://Stackoverflow.com/users/22471/" ]
231,739
<p>Im adding textboxes (not a fixed number of textboxes) dynamically to a form on ASP.NET page, how do i read back data from these textboxes?</p>
[ { "answer_id": 231759, "author": "Dillie-O", "author_id": 71, "author_profile": "https://Stackoverflow.com/users/71", "pm_score": 1, "selected": false, "text": "ctl00$cphBody$[ControlID]\n" } ]
2008/10/23
[ "https://Stackoverflow.com/questions/231739", "https://Stackoverflow.com", "https://Stackoverflow.com/users/24958/" ]
231,741
<p>Looking for free/opensource code or description of algorithms to code (simple) and decode (hard) the 2D barcode <a href="http://en.wikipedia.org/wiki/QR_Code" rel="noreferrer">QR code</a>.</p> <p>It doesn't seem like a trivial problem, but it's so popular in Japan that there must be something already available...</p>
[ { "answer_id": 6575376, "author": "Adriano Petrich", "author_id": 326220, "author_profile": "https://Stackoverflow.com/users/326220", "pm_score": 2, "selected": false, "text": "#!/usr/bin/python\n\nfrom sys import argv\nimport zbar\nimport Image\n\n\n# create a reader\nscanner = zbar.Ima...
2008/10/23
[ "https://Stackoverflow.com/questions/231741", "https://Stackoverflow.com", "https://Stackoverflow.com/users/2915/" ]
231,746
<p>Use case: 3rd party application wants to programatically monitor a text file being generated by another program. Text file contains data you want to analyze as it's being updated.</p> <p>I'm finding a lot of answers to this question wrapped around FileSystemWatcher but let's say you are writing an application for a Windows machine and can't guarantee .NET is installed. </p> <p>Are there any libraries out there available for this, or am I just going to have to roll my own solution then?</p> <p>Thanks.</p>
[ { "answer_id": 231858, "author": "Adam Pierce", "author_id": 5324, "author_profile": "https://Stackoverflow.com/users/5324", "pm_score": 3, "selected": false, "text": "struct __stat64 fileinfo;\n\nif(-1 != _stat64(filename, &fileinfo)\n return fileinfo.st_mtime;\n" } ]
2008/10/23
[ "https://Stackoverflow.com/questions/231746", "https://Stackoverflow.com", "https://Stackoverflow.com/users/9450/" ]
231,760
<p>This seems like a simple question, but I can't find it with the Stack Overflow search or Google. What does a type followed by a <code>_t</code> mean? Such as</p> <pre><code>int_t anInt; </code></pre> <p>I see it a lot in C code meant to deal closely with hardware—I can't help but think that they're related.</p>
[ { "answer_id": 231765, "author": "Douglas Mayle", "author_id": 8458, "author_profile": "https://Stackoverflow.com/users/8458", "pm_score": 4, "selected": false, "text": "size_t" }, { "answer_id": 231789, "author": "mmacaulay", "author_id": 22152, "author_profile": "ht...
2008/10/23
[ "https://Stackoverflow.com/questions/231760", "https://Stackoverflow.com", "https://Stackoverflow.com/users/26237/" ]
231,764
<p>This is one of those meta-programming questions that may or may not belong on SO, but here goes...</p> <p>Have any other programmers out there noticed that their ability to communicate with people (technical or otherwise) almost disappears during and after a period of intense programming?</p> <p>I normally think of myself as a relatively good communicator. However, last night after staying late to work on some relatively challenging programming tasks, I found even ordering a takeaway meal was very difficult: my words got tied up before they left my mouth. This is not the first time this has happened ... </p> <p>Has anyone else experienced this phenomenon? Is there a name for it?</p>
[ { "answer_id": 231842, "author": "Rob Wells", "author_id": 2974, "author_profile": "https://Stackoverflow.com/users/2974", "pm_score": 0, "selected": false, "text": "SYN\n" } ]
2008/10/23
[ "https://Stackoverflow.com/questions/231764", "https://Stackoverflow.com", "https://Stackoverflow.com/users/26331/" ]
231,767
<p>What is the use of the <code>yield</code> keyword in Python? What does it do?</p> <p>For example, I'm trying to understand this code<sup><strong>1</strong></sup>:</p> <pre><code>def _get_child_candidates(self, distance, min_dist, max_dist): if self._leftchild and distance - max_dist &lt; self._median: yield self._leftchild if self._rightchild and distance + max_dist &gt;= self._median: yield self._rightchild </code></pre> <p>And this is the caller:</p> <pre><code>result, candidates = [], [self] while candidates: node = candidates.pop() distance = node._get_dist(obj) if distance &lt;= max_dist and distance &gt;= min_dist: result.extend(node._values) candidates.extend(node._get_child_candidates(distance, min_dist, max_dist)) return result </code></pre> <p>What happens when the method <code>_get_child_candidates</code> is called? Is a list returned? A single element? Is it called again? When will subsequent calls stop?</p> <hr /> <sub> 1. This piece of code was written by Jochen Schulz (jrschulz), who made a great Python library for metric spaces. This is the link to the complete source: <a href="https://well-adjusted.de/~jrspieker/mspace/" rel="noreferrer">Module mspace</a>.</sub>
[ { "answer_id": 231778, "author": "Douglas Mayle", "author_id": 8458, "author_profile": "https://Stackoverflow.com/users/8458", "pm_score": 9, "selected": false, "text": "yield" }, { "answer_id": 231801, "author": "Jason Baker", "author_id": 2147, "author_profile": "ht...
2008/10/23
[ "https://Stackoverflow.com/questions/231767", "https://Stackoverflow.com", "https://Stackoverflow.com/users/18300/" ]
231,821
<p>I am working on a VB.NET WinForms app that was "upgraded" by Visual Studio (originally 1.0 or 1.1) from VB6 code (which was itself upgraded from VB5). Except for the few new forms I've created since taking over maintenance of this app, all of the forms in the application have a method called DefInstance which allows you to grab an in-memory copy of the form if there is one. What I can't figure out is why: when would I ever need to reference a form object in memory when it's not immediately in scope where I'm working. To my mind this violates all kinds of sound programming principles and seems like an invitation for memory leaks or worse.</p> <p>The questions: (1) is this DefInstance thing an merely unfortunate remnant of the VB6 heritage of this app, and (2) should I make a point of removing DefInstance methods throughout the application?</p>
[ { "answer_id": 231852, "author": "BQ.", "author_id": 4632, "author_profile": "https://Stackoverflow.com/users/4632", "pm_score": 1, "selected": false, "text": "Private Sub Command_Click()\n Call DoStuff\nEnd Sub\n\nPrivate Sub DoStuff()\n Form1.myTextbox.Text = \"Bad Idea\"\nEnd Sub\...
2008/10/23
[ "https://Stackoverflow.com/questions/231821", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3799/" ]
231,827
<p>I'm designing a multi-tiered database driven web application – SQL relational database, Java for the middle service tier, web for the UI. The language doesn't really matter.</p> <p>The middle service tier performs the actual querying of the database. The UI simply asks for certain data and has no concept that it's backed by a database.</p> <p>The question is how to handle large data sets? The UI asks for data but the results might be huge, possibly too big to fit in memory. For example, a street sign application might have a service layer of:</p> <pre><code>StreetSign getStreetSign(int identifier) Collection&lt;StreetSign&gt; getStreetSigns(Street street) Collection&lt;StreetSign&gt; getStreetSigns(LatLonBox box) </code></pre> <p>The UI layer asks to get all street signs meeting some criteria. Depending on the criteria, the result set might be huge. The UI layer might divide the results into separate pages (for a browser) or just present them all (serving up to Goolge Earth). The potentially huge result set could be a performance and resource problem (out of memory).</p> <p>One solution is not to return fully loaded objects (StreetSign objects). Rather return some sort of result set or iterator that lazily loads each individual object.</p> <p>Another solution is to change the service API to return a subset of the requested data:</p> <pre><code>Collection&lt;StreetSign&gt; getStreetSigns(LatLonBox box, int pageNumber, int resultsPerPage) </code></pre> <p>Of course the UI can still request a huge result set:</p> <pre><code>getStreetSigns(box, 1, 1000000000) </code></pre> <p>I'm curious what is the standard industry design pattern for this scenario?</p>
[ { "answer_id": 231864, "author": "Niniki", "author_id": 4155, "author_profile": "https://Stackoverflow.com/users/4155", "pm_score": 0, "selected": false, "text": "public interface Pageable\n{\n public void setStartIndex( int index );\n public int getStartIndex();\n public int ge...
2008/10/23
[ "https://Stackoverflow.com/questions/231827", "https://Stackoverflow.com", "https://Stackoverflow.com/users/24396/" ]
231,838
<p>Alright, so I have a query that looks like this:</p> <pre><code>SELECT `orders`.*, GROUP_CONCAT( CONCAT( `menu_items`.`name`, ' ($', FORMAT(`menu_items`.`price`,2), ')' ) SEPARATOR '&lt;br&gt;' ) as `items`, SUM(`menu_items`.`price`) as `additional`, `children`.`first_name`, `children`.`last_name`, `organizations`.`base_price` FROM `orders`, `order_items`, `menu_items`, `children`, `organizations` WHERE `order_items`.`menu_item_id` = `menu_items`.`id` AND `order_items`.`order_id` = `orders`.`id` AND `orders`.`added_by` = {$user_id} AND `orders`.`date` &gt; '{$cutoff}' AND `children`.`id` = `orders`.`child_id` AND `organizations`.`id` = `children`.`organization_id` GROUP BY `orders`.`id` </code></pre> <p>I know it's a monstrosity and that some people will die before not using explicit joins. Ignoring that, however, what I wish to do is to only use the <code>CONCAT</code> inside the <code>GROUP_CONCAT</code> if the <code>menu_items.price</code> is greater than 0, otherwise only return <code>menu_items.name</code>. I have had, however, no success trying to throw an <code>IF</code> in there. I've read the manual but all the ways that I've tried aren't working and I'm pretty sure I'm missing something on the whole conditional statements thing.</p>
[ { "answer_id": 231846, "author": "Lance Roberts", "author_id": 13295, "author_profile": "https://Stackoverflow.com/users/13295", "pm_score": 4, "selected": true, "text": "CASE WHEN 'menu_items'.'price' = 0 THEN 'menu.items'.'name' ELSE CONCAT (etc) END \n" }, { "answer_id": 23195...
2008/10/23
[ "https://Stackoverflow.com/questions/231838", "https://Stackoverflow.com", "https://Stackoverflow.com/users/16417/" ]
231,839
<p>In C++ you can disable a function in parent's class by declaring it as private in the child class. How can this be done in Python? I.E. How can I hide parent's function from child's public interface?</p>
[ { "answer_id": 231857, "author": "Jason Baker", "author_id": 2147, "author_profile": "https://Stackoverflow.com/users/2147", "pm_score": 3, "selected": false, "text": "class X(object):\n def some_function(self):\n do_some_stuff()\n\nclass Y(object):\n some_function = None\n"...
2008/10/23
[ "https://Stackoverflow.com/questions/231839", "https://Stackoverflow.com", "https://Stackoverflow.com/users/17523/" ]
231,848
<p>The follow code (running in ASP.Net 2.0) displays the contents of the requested URL <strong>twice</strong>. I only want it to display the contents of the requested URL once. I can't figure out what I'm doing wrong. The URL requested is returning XML and if I visit the URL directly, it works fine.</p> <pre><code>HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); byte[] postDataBytes = Encoding.UTF8.GetBytes(postData); request.Method = "POST"; request.ContentType = "application/xml"; request.ContentLength = postDataBytes.Length; Stream requestStream = request.GetRequestStream(); requestStream.Write(postDataBytes, 0, postDataBytes.Length); requestStream.Close(); // get response and write to console response = (HttpWebResponse) request.GetResponse(); StreamReader responseReader = new StreamReader(response.GetResponseStream(), Encoding.UTF8); try { Response.Write(responseReader.ReadToEnd()); } finally { responseReader.Close(); } response.Close(); </code></pre>
[ { "answer_id": 231857, "author": "Jason Baker", "author_id": 2147, "author_profile": "https://Stackoverflow.com/users/2147", "pm_score": 3, "selected": false, "text": "class X(object):\n def some_function(self):\n do_some_stuff()\n\nclass Y(object):\n some_function = None\n"...
2008/10/23
[ "https://Stackoverflow.com/questions/231848", "https://Stackoverflow.com", "https://Stackoverflow.com/users/30996/" ]
231,862
<p>I'm working with a MySQL query that writes into an outfile. I run this query once every day or two and so I want to be able to remove the outfile without having to resort to su or sudo. The only way I can think of making that happen is to have the outfile written as owned by someone other than the mysql user. Is this possible?</p> <p>Edit: I am not redirecting output to a file, I am using the INTO OUTFILE part of a select query to output to a file.</p> <p>If it helps:<pre> mysql --version mysql Ver 14.12 Distrib 5.0.32, for pc-linux-gnu (x86_64) using readline 5.2 </pre></p>
[ { "answer_id": 232254, "author": "Draemon", "author_id": 26334, "author_profile": "https://Stackoverflow.com/users/26334", "pm_score": 3, "selected": false, "text": "mysql db_schema -e 'SELECT col,... FROM table' > /tmp/outfile.txt\n" }, { "answer_id": 3028580, "author": "cod...
2008/10/23
[ "https://Stackoverflow.com/questions/231862", "https://Stackoverflow.com", "https://Stackoverflow.com/users/1447/" ]
231,868
<p>I'm getting a strange error from <code>g++</code> 3.3 in the following code:</p> <pre><code>#include &lt;bitset&gt; #include &lt;string&gt; using namespace std; template &lt;int N, int M&gt; bitset&lt;N&gt; slice_bitset(const bitset&lt;M&gt; &amp;original, size_t start) { string str = original.to_string&lt;char, char_traits&lt;char&gt;, allocator&lt;char&gt; &gt;(); string newstr = str.substr(start, N); return bitset&lt;N&gt;(newstr); } int main() { bitset&lt;128&gt; test; bitset&lt;12&gt; result = slice_bitset&lt;12, 128&gt;(test, 0); return 0; } </code></pre> <p>The error is as follows:</p> <pre> In function `std::bitset slice_bitset(const std::bitset&, unsigned int)': syntax error before `,' token `char_traits' specified as declarator-id two or more data types in declaration of `char_traits' `allocator' specified as declarator-id two or more data types in declaration of `allocator' syntax error before `>' token </pre> <p>It has to be something really silly, but I've already told it to my rubber duck and a friend to no avail.</p> <p>Thanks, Lazyweb.</p>
[ { "answer_id": 231904, "author": "CAdaker", "author_id": 30579, "author_profile": "https://Stackoverflow.com/users/30579", "pm_score": 3, "selected": false, "text": "original.to_string();\n" }, { "answer_id": 231922, "author": "Tim Stewart", "author_id": 26002, "autho...
2008/10/23
[ "https://Stackoverflow.com/questions/231868", "https://Stackoverflow.com", "https://Stackoverflow.com/users/3594/" ]
231,870
<p>I have a separate partition on my disk formatted with FAT32. When I hibernate windows, I want to be able to load another OS, create/modify files that are on that partition, then bring Windows out of hibernation and be able to see the changes that I've made.</p> <p>I know what you're going to type, "Well, you're not supposed to do that!" and then link me to some specs about how what I'm trying to do is wrong/impossible/going to break EVERYTHING. However, I'm sure there's some way I can get around that. :)</p> <p>I don't need the FAT32 partition in Windows, except to read the files that were written there, then I'm done - so whatever the solution is, it's acceptable for the disk to be completely inaccessible for a period of time. Unfortunately, I can't take the entire physical disk offline because it is just a partition of the same physical device that windows is installed on -- just the partition.</p> <p>These are the things I've tried so far...</p> <ol> <li>Google it. I got at least one "this is NEVER going to happen" answer. Unacceptable! :)</li> <li>Unmount the disk before hibernating. Mount after coming out of hibernation. This seems to have no effect. Windows still thinks the FAT is the same as it was before, so whatever data I wrote to disk is lost, and any files I resized are corrupted. If any of the file was cached, it's even worse.</li> <li>Use DeviceIoControl to call IOCTL_DISK_UPDATE_PROPERTIES to try and refresh the disk (but the partition table hasn't changed, so this doesn't really do anything).</li> </ol> <p>Is there any way to invalidate the disk/volume read cache to force windows to go back to the disk? </p> <p>I thought about opening the partition and reading/writing directly by using libfat and bypassing the cache or something is overkill.</p>
[ { "answer_id": 254756, "author": "Nick", "author_id": 30425, "author_profile": "https://Stackoverflow.com/users/30425", "pm_score": 3, "selected": false, "text": "volumeHandle = CreateFile(volumePath,\n GENERIC_READ|GENERIC_WRITE, \n FILE...
2008/10/23
[ "https://Stackoverflow.com/questions/231870", "https://Stackoverflow.com", "https://Stackoverflow.com/users/30425/" ]
231,885
<p>I encountered a problem when running some old code that was handed down to me. It works 99% of the time, but once in a while, I notice it throwing a "Violation reading location" exception. I have a variable number of threads potentially executing this code throughout the lifetime of the process. The low occurrence frequency may be indicative of a race condition, but I don't know why one would cause an exception in this case. Here is the code in question:</p> <pre><code>MyClass::Dostuff() { static map&#60;char, int&#62; mappedChars; if (mappedChars.empty()) { for (char c = '0'; c &#60;= '9'; ++c) { mappedChars[c] = c - '0'; } } // More code here, but mappedChars in not changed. } </code></pre> <p>The exception is thrown in the map's operator[] implementation, on the very first call to the operator[] (Using the VS2005 implementation of STL.)</p> <pre><code> mapped_type& operator[](const key_type& _Keyval) { iterator _Where = this->lower_bound(_Keyval); //exception thrown on the first line // More code here } </code></pre> <p>I already tried freezing threads in operator[] and trying to get them to all run through it at the same time, but I was unable to reproduce the exception using that methodology.</p> <p>Can you think of any reason why that would throw, and only some of the time? </p> <p>(Yes, I know STL is not thread-safe and I'll need to make changes here. I am mostly curious as to WHY I'm seeing the behavior I described above.)</p> <p>As requested, here some further details about the exception:<br> Unhandled exception at 0x00639a1c (app.exe) in app15-51-02-0944_2008-10-23.mdmp: 0xC0000005: Access violation reading location 0x00000004.</p> <p>Thanks to everyone suggesting solutions to multithreading issues, but this isn't what this question is meant to address. Yes, I understand the presented code is not protected correctly and is overkill in what it's trying to accomplish. I already have the fix for it implemented. I'm just trying to get a better understanding of why this exception was thrown to begin with.</p>
[ { "answer_id": 231895, "author": "Henk", "author_id": 4613, "author_profile": "https://Stackoverflow.com/users/4613", "pm_score": 2, "selected": false, "text": "DoStuff" }, { "answer_id": 231921, "author": "Tony Lee", "author_id": 5819, "author_profile": "https://Stac...
2008/10/23
[ "https://Stackoverflow.com/questions/231885", "https://Stackoverflow.com", "https://Stackoverflow.com/users/22724/" ]
231,886
<p>This may seem like a somewhat contrived example, but I'm left scratching my head.</p> <p>Ok, I have a console app that instantiates a WindowsForm and calls a method called DoSomeWork() on the form.</p> <pre><code>class Program { static void Main(string[] args) { Form1 form = new Form1(); form.DoSomeWork(); } } </code></pre> <p>Form1 looks like this...</p> <pre><code>public partial class Form1 : Form { public Form1() { InitializeComponent(); } public void DoSomeWork() { OuterClass outerClass = new OuterClass(); outerClass.DoSomeWork(); } } </code></pre> <p>Outer class, in turn, looks like this...</p> <pre><code>public class OuterClass { public void DoSomeWork() { InnerClass innerClass = new InnerClass(); innerClass.DoSomeWork(); } } </code></pre> <p>And finally InnerClass looks like this...</p> <pre><code>public class InnerClass { private BackgroundWorker _backgroundWorker = new BackgroundWorker(); public InnerClass() { _backgroundWorker.WorkerReportsProgress = true; _backgroundWorker.DoWork += new DoWorkEventHandler(BackgroundWorker_DoWork); _backgroundWorker.ProgressChanged += new ProgressChangedEventHandler(BackgroundWorker_ProgressChanged); } void BackgroundWorker_ProgressChanged(object sender, ProgressChangedEventArgs e) { int i = 0; //I've placed a break point here. But it's never hit } void BackgroundWorker_DoWork(object sender, DoWorkEventArgs e) { BackgroundWorker worker = sender as BackgroundWorker; worker.ReportProgress(42); } public void DoSomeWork() { _backgroundWorker.RunWorkerAsync(); } } </code></pre> <p>For a reason unknown (to me), the BacgroundWorker in InnerClass never seems to fire the <strong>ProgressChanged</strong> event. If I replace </p> <pre><code>Form1 form = new Form1(); </code></pre> <p>with </p> <pre><code>OuterClass outerClass = new OuterClass() </code></pre> <p>in class Program, it works fine. So why is that my events don't fire when I'm calling the same methods through a Form?</p> <p>Thanks!</p> <p>EDIT: I seemed to be throwing people off by leaving the ProgressChanged event handler as throwing a NotImplementedException, so I've removed it for clarity.</p>
[ { "answer_id": 231894, "author": "chakrit", "author_id": 3055, "author_profile": "https://Stackoverflow.com/users/3055", "pm_score": 2, "selected": false, "text": "throw NotImplementedException();" }, { "answer_id": 232073, "author": "Hans Passant", "author_id": 17034, ...
2008/10/23
[ "https://Stackoverflow.com/questions/231886", "https://Stackoverflow.com", "https://Stackoverflow.com/users/6419/" ]