body
stringlengths
25
86.7k
comments
list
answers
list
meta_data
dict
question_id
stringlengths
1
6
<p>Can someone please review this simple code for printing all paths in a matrix from bottom left to top right? If an element is 1, it is a "wall" and you cannot take it. </p> <p>Possible steps: up and right</p> <pre><code> // Prints possible paths from bottom left to top right public static void findPath(int n,...
[]
[ { "body": "<p>You can refactor the <code>findPath</code> logic somewhat and reduce the indent level while preserving the method's behavior:</p>\n\n<pre><code>// Prints possible paths from bottom left to top right\npublic static void findPath(int n, int i , int j, int[][] mat, ArrayList&lt;Integer&gt; path)\n{\n...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-28T03:54:51.573", "Id": "3156", "Score": "1", "Tags": [ "java", "algorithm", "matrix" ], "Title": "Matrix bottom left to top right" }
3156
<p>Can someone please review this code for me? I have not implemented all the methods for simplicity.</p> <pre><code>/** * Implements a blocking bounded queue from a given non-blocking unbounded queue implementation */ abstract class DerivedQueue&lt;E&gt; implements Queue&lt;E&gt; { DerivedQueue(Queue&lt;E&gt; q...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-07-03T06:41:52.780", "Id": "4886", "Score": "0", "body": "Logical OR is done using a double-pipe `||`. A single pipe `|` is for bitwise OR." } ]
[ { "body": "<p>In my oppinion class variables should always be defined first - even before the constructor. Another issue: why are your variables prefixed with <code>f</code>? Rename to something less-confusing instead. Especially <code>fSize</code> and <code>fCnt</code> are quite close to each other. (Suggestin...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-28T06:25:56.973", "Id": "3157", "Score": "2", "Tags": [ "java", "multithreading", "interview-questions", "queue" ], "Title": "Bounded blocking queue" }
3157
<p>I've written the following SQL to count the number of times the name 'Cthulhu' turns up for each tag on Stack Overflow (original <a href="http://data.stackexchange.com/stackoverflow/s/1527/cthulhu-fhtagn" rel="nofollow">here</a>):</p> <pre><code>select t.TagName, count (*) 'Tainted' from Posts p, Tags t, PostTags p...
[]
[ { "body": "<pre><code>select t.TagName, count (*) 'Tainted'\n from Posts p\n inner join PostTags pt on (pt.PostId == p.Id)\n inner join Tags t on (t.Id == pt.TagId)\n where lower(p.Body) like '%cthulhu%'\n group by t.TagName\n order by Tainted desc, t.TagName asc\n</code></pre>\n\n<ul>\n<li>Notice the <code>lo...
{ "AcceptedAnswerId": "3163", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-28T06:32:25.100", "Id": "3158", "Score": "5", "Tags": [ "sql", "stackexchange" ], "Title": "Finding the use of the word 'Cthulhu' in tags on Stack Overflow" }
3158
<p>I have a list of <code>checkboxes</code> styled using JQuery UI as buttons. Each have a <code>data-price</code> attributem containing a price in this format: <code>data-price="40.00"</code>, <code>data-price="25.00"</code> etc.</p> <p>When the user "checks" a box, I am adding it's <code>data-price</code> to the <co...
[]
[ { "body": "<p>When working with prices, then in my opinion it's usually a good idea to avoid floating point numbers. Binary rounding errors can easily strike unexpectedly any time. </p>\n\n<p>Instead I'd suggest to work with integers (thus pennies) internally, and just add the decimal point for output.</p>\n\n<...
{ "AcceptedAnswerId": "3165", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-28T11:24:58.170", "Id": "3164", "Score": "2", "Tags": [ "javascript", "jquery", "jquery-ui" ], "Title": "jQuery UI button and some calculations" }
3164
<p>I wrote the following code to insert records into a database. The user selects the rows from the <code>RadGrid</code> and the insert command is executed when that user clicks the button. I've been spending a lot of time trying to make this work (nothing currently happens when I click the button). However, I just ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-28T13:47:42.707", "Id": "4758", "Score": "2", "body": "ADO.NET will actually not dispose or open/close the connection behind the scenes but decides whether to reuse an existing connection with enabled [Connection Pooling](http://msdn.m...
[ { "body": "<p>The insert block itself is alright: it safe and clean. And it avoids <a href=\"http://en.wikipedia.org/wiki/SQL_injection\" rel=\"nofollow\">SQL Injection</a>.</p>\n\n<p>However, you should consider moving your persistent code away from the UI code. Try working in layers. There are some design pat...
{ "AcceptedAnswerId": "3172", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-28T13:40:48.650", "Id": "3170", "Score": "6", "Tags": [ "c#", "asp.net", "sql" ], "Title": "Inserting records into a database" }
3170
<p>I've created this (very) contrived example that demonstrates how we currently organize page specific JS in our app. Basically each page has a matching JS file that uses the <a href="http://ajaxian.com/archives/a-javascript-module-pattern" rel="nofollow">module pattern</a> to enclose page specific behaviors. Each mod...
[]
[ { "body": "<pre><code>MyPage = (function() {\n var Page = {\n addFile: function(e) {\n this._files.push($(e.target).val());\n },\n\n doUpload: function() {\n alert('uploading ' + this._files.length + ' files...');\n },\n\n clear: function() {\n ...
{ "AcceptedAnswerId": "3183", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-28T15:03:31.853", "Id": "3179", "Score": "1", "Tags": [ "javascript", "unit-testing" ], "Title": "What is a better (more testable) way to structure this page-specific JS?" }
3179
<p>I've written the following C# code to insert rows (that a user enters from a web application) into a SQL database. How does this code look? Is there a better, more efficient way to accomplish the task?</p> <pre><code>public void UpdateDeviceStatus(string[] deviceId, byte[] status, string userId, string[] remarks,...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-29T13:45:46.297", "Id": "4801", "Score": "0", "body": "I just fixed my question. I'm sorry for the headaches caused by the ****ed part where I mixed up the question and the code sample." } ]
[ { "body": "<p>You are building a dynamic insert statement with parametrized values. This works and there's nothing wrong with this method. It may even be the best method for your circumstance. It works well when your table is \"small\". I have a rather large database which grows monotonically. We keep addi...
{ "AcceptedAnswerId": "3190", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-28T16:49:49.450", "Id": "3184", "Score": "11", "Tags": [ "c#", ".net", "sql" ], "Title": "Insert multiple rows into a SQL table" }
3184
<p>I'm trying to implement the Strategy Pattern into my current code base. I would like to know if i'm going in the right direction on this?</p> <p><b>IOracleDB.cs:</b></p> <pre><code>/// &lt;summary&gt; /// Strategy /// &lt;/summary&gt; interface IOracleDB { DataSet DatabaseQuery(string query, OracleConnection o...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-09-12T20:28:50.483", "Id": "7140", "Score": "0", "body": "Thanks to everyone who responded to my question. I actually answered my own question a long time ago. I ended up rewriting everything and it all worked out in the end. Lol I don't ...
[ { "body": "<p>There are several issues that could be improved:</p>\n\n<ol>\n<li><p>First of all, having concrete classes which are all tied to a specific database (in this case Oracle), is usually completely opposite of what a Data Layer's responsibility should be. Consider changing the classes' names as follow...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-28T19:12:23.093", "Id": "3187", "Score": "5", "Tags": [ "c#", ".net", "oracle" ], "Title": "Strategy Pattern for Oracle Database?" }
3187
<p>I have started learning HTML. Here is one of the very basic HTML pages I have written. I would appreciate advice about how to write code especially regarding indentation.</p> <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; &...
[]
[ { "body": "<p>I start my intention in head and body.</p>\n\n<pre><code>&lt;!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Transitional//EN\" \"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd\"&gt; \n&lt;html xmlns=\"http://www.w3.org/1999/xhtml\" xml:lang=\"en\" lang=\"en\"&gt; \n&lt;head&gt;\n &lt;tit...
{ "AcceptedAnswerId": "3194", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-29T05:31:03.627", "Id": "3193", "Score": "4", "Tags": [ "beginner", "html" ], "Title": "Introductory HTML exercise" }
3193
<p>How would I make this code look less ugly?</p> <pre><code>// we are looping over an array of images // width is a parameter passed to the current function // // the resulting string looks like this: "30px 0" // (it's a tool that returns coordinates for a CSS sprite) // when iterating over the first item, we don't ...
[]
[ { "body": "<pre><code>// old\n\nvar result = [], width, is2PixelRatio;\nfor (var i = 0; i &lt; 10; i++) {\n width = i;\n result.push(\n ( i === 0 ? \"0\" : \"-\" + i * ( ( is2PixelRatio ? width / 2 : width ) + 10 ) + \"px\" ) + \" 0\"\n );\n}\nconsole.log(result);\n\n// new\n\nvar result2 = [\"0...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-29T09:27:53.670", "Id": "3195", "Score": "2", "Tags": [ "javascript" ], "Title": "JavaScript string manipulation with certain logic in it" }
3195
<blockquote> <p><strong><em>Follow-up to:</strong> <a href="https://codereview.stackexchange.com/questions/2650/waiting-for-a-lock-to-release-with-thread-sleep">Waiting for a lock to release with Thread.Sleep()?</a></em></p> </blockquote> <p>I've found the time I tried to rewrite my <code>WaitForLock</code>-Method t...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-16T19:53:23.717", "Id": "10818", "Score": "0", "body": "I don't see any benefits in using Quartz.Net vs polling it like you did in the first question. This is a far more complicated way of polling in 1s intervals. I am not sure how you...
[ { "body": "<p>I read your original question and this one and don't see how using ManualResetEvent/Quartz adds anything valuable. As far as I understand the whole point of sleeping is just to avoid polling the DB too frequently.</p>\n\n<p>Here some pseudocode...</p>\n\n<pre><code>create table lock (name varchar(...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-29T10:33:13.163", "Id": "3197", "Score": "7", "Tags": [ "c#", "locking" ], "Title": "Waiting for a lock to release with ManualResetEvent and Quartz" }
3197
<p>I wrote this program to do a simple Caesar shift by a user inputted key, and then deshift. I'm really enjoying it, but I've run out of ideas on improvements! Can you think of anything?</p> <pre><code>def decrypt(): a=raw_input("Give me the word to decrypt:") number=input("What was it shifted by?") b=l...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-29T18:23:02.880", "Id": "4810", "Score": "0", "body": "Agree with previous comment. One \"easy way\" to often improve code is to use more (smaller) functions that do less but do whatever they do really well -- it makes the program more...
[ { "body": "<p>This might not be quite what you've got in mind, but one big improvement you could make would be to use meaningful variable names and insert whitespace.</p>\n\n<pre><code>def decrypt():\n cyphertext = raw_input('Give me the word to decrypt:')\n shift = input('What was it shifted by?')\n\n ...
{ "AcceptedAnswerId": "3203", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-29T18:14:34.163", "Id": "3201", "Score": "14", "Tags": [ "python", "caesar-cipher" ], "Title": "Simple Caesar shift and deshift" }
3201
<p>I am trying to <a href="http://www.htmliseasy.com/exercises/part06.html">learn by doing</a>. Here is the first problem that I have solved. I have actually not done it perfectly. The table header should cover both the text and the image but it is only above text. If you can help me out with the design I will be thank...
[]
[ { "body": "<p>The HTML you submitted was invalid. I changed the following things so your html would be valid:</p>\n\n<ol>\n<li><p>Don't put <code>&lt;h3&gt;</code> tags inside a table. Header tags are used for headings only. Don't use headings to make text BIG or bold. Use CSS for positioning and font sizing.</...
{ "AcceptedAnswerId": "3205", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-29T20:37:04.163", "Id": "3204", "Score": "12", "Tags": [ "beginner", "html" ], "Title": "Practicing HTML Tables" }
3204
<p>It's <a href="https://stackoverflow.com/q/6512914/497934">been pointed out</a> (see the first comment) that my makefile rebuilds <em>all</em> source files regardless of changes made.</p> <pre><code># Variables # TARGETS := libAurora.a libAurora.so # The names of targets that can be built. # This is used in...
[]
[ { "body": "<p>I think the suggestion in the link you mention is to not bother with making your object files \"intermediate\". I tend to agree.</p>\n\n<p>If <code>make</code> deletes the object files after the link step then it has to re-build them all at the next invocation of <code>make</code>. Without this,...
{ "AcceptedAnswerId": "3221", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-29T20:58:44.370", "Id": "3206", "Score": "3", "Tags": [ "makefile" ], "Title": "Optimizing a Makefile" }
3206
<p>Earlier this year, before I learnt about Code Review Stack Exchange, I gave <a href="https://stackoverflow.com/questions/5756147/basic-simple-asp-net-jquery-json-example/5756591#5756591">this answer</a> in response to a question about how to combine ASP.NET, jQuery, and JSON: </p> <p>I keep thinking that there must...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-30T13:45:25.017", "Id": "4845", "Score": "0", "body": "Thanks for the answer. I was wondering, specifically, if there is a way to improve the client side scripting; a good way to format JSON client side. Supposing that the `dateStamp...
[ { "body": "<p>You are correct. There is a better way. Starting in .NET 3.5, there is a <a href=\"http://msdn.microsoft.com/en-us/library/system.web.script.serialization.javascriptserializer.aspx\">JavaScriptSerializer</a> class that can be used for simplifying JSON responses. It can be found in the <code>System...
{ "AcceptedAnswerId": "3214", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-29T22:29:25.740", "Id": "3208", "Score": "12", "Tags": [ "c#", "jquery", "asp.net", "ajax", "json" ], "Title": "Making a simple call to a server" }
3208
<p>Here is <a href="http://www.htmliseasy.com/exercises/part03.html" rel="nofollow">a problem</a> I solved. Please review this.</p> <pre><code>&lt;!DOCTYPE HTML&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;BLA| Welcome &lt;/title&gt; &lt;/head&gt; &lt;body&gt; &lt;h1 align="center"&gt...
[]
[ { "body": "<p>Okay, I am not sure exactly in what limits your exercise is, but I'll answer to what I think is good web standard. (I've been a web developer for ~4 years)</p>\n\n<ol>\n<li>Don't use the align attribute. HTML is supposed to be a markup language. Use CSS to control the appearance of your html eleme...
{ "AcceptedAnswerId": "3211", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-29T22:36:45.937", "Id": "3209", "Score": "6", "Tags": [ "html", "html5" ], "Title": "HTML website practice exercise" }
3209
<p>How can I improve upon this integer class that I wrote? I am/will be using this for some calculation intensive crypto algorithms, mainly POLY1305AES. I might even write RSA using this. I know that there are more efficient algorithms for at least the algebraic operators, but I will rewrite those when I learn them.</p...
[]
[ { "body": "<p>For here:</p>\n\n<pre><code>while ((value.begin() != value.end()) &amp; !value.front())\n</code></pre>\n\n<p>You should use logical <code>&amp;&amp;</code> instead of <code>&amp;</code>.</p>\n", "comments": [], "meta_data": { "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0...
{ "AcceptedAnswerId": "3237", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-30T02:20:44.760", "Id": "3212", "Score": "7", "Tags": [ "c++", "bitwise", "integer" ], "Title": "Custom integer class for calculating crypto algorithms" }
3212
<p>I have an OpenClose class which just represents the hours of operation of a business by the opening and closing time. It takes the opening and closing times as arguments to its constructor, and each is a datetime object.</p> <p>The data is coming from an external source in a string, formatted like "HH:MM (AM|PM)-HH...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-07-11T16:06:39.140", "Id": "5095", "Score": "0", "body": "Please define \"best\" so that we know what's important to you." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-07-12T05:41:46.930", "Id": "5110", ...
[ { "body": "<p>Yes, too much for one line, yes, too confusing. Making a map an lambda for two values like that is silly, unless you are trying to win an obfuscation contest.</p>\n\n<p>So, the middle version is best.</p>\n", "comments": [ { "ContentLicense": "CC BY-SA 3.0", "CreationDate...
{ "AcceptedAnswerId": "3217", "CommentCount": "10", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-30T04:25:13.827", "Id": "3213", "Score": "5", "Tags": [ "python", "datetime", "comparative-review", "interval" ], "Title": "Representing the opening and closing time for a bus...
3213
<p>I'm building a web application and is trying to make my code reusable. I've decided to create components that can be used outside this project.</p> <p>Now I'm trying to create a simple DI container, one class, and I would like some help checking it out. I'm thinking to do something like this:</p> <pre><code>class ...
[]
[ { "body": "<p>You should read the following series of articles: <a href=\"http://fabien.potencier.org/article/11/what-is-dependency-injection\" rel=\"nofollow\">http://fabien.potencier.org/article/11/what-is-dependency-injection</a></p>\n\n<p>Additionally, the resulting component (PHP 5.2+) is there: <a href=\"...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-30T07:01:14.280", "Id": "3218", "Score": "5", "Tags": [ "php", "design-patterns" ], "Title": "Simple DI container" }
3218
<p>For every word there are 2^n different ways of writing the word if you take into account upper/lower case letters. Eg for "word" we can write;</p> <ul> <li>word</li> <li>Word</li> <li>wOrd</li> <li>WOrd</li> <li>woRd</li> <li>WoRd</li> <li>etc</li> </ul> <p>I've written this code to calculate all the combinations....
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-30T11:04:52.783", "Id": "4837", "Score": "1", "body": "Why would you want to *know* all possible combinations if all you want to know is the strength of the password?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": ...
[ { "body": "<pre><code>public static void comb(String word) {\n int combinations = 1 &lt;&lt; word.length();\n char[][] chars = { word.toLowerCase().toCharArray(),\n word.toUpperCase().toCharArray() };\n char[] result = new char[word.length()]; \n\n for (int i = 0; i &lt; combin...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-30T10:37:28.190", "Id": "3222", "Score": "2", "Tags": [ "java", "optimization" ], "Title": "Finding all upper/lower case combinations of a word" }
3222
<p>I have searched for method to find and replace strings sequence in binary files without any luck. The main requirement was that method should not load all file in memory but rather use chunks. I am new in c# and code may look not "polished" but it works fine. Maybe someone will have ideas how this code could be impr...
[]
[ { "body": "<p>One thing I noted is that your <code>SearchBytePattern</code> function returns an int that is always equal to the number of elements in the <code>position</code> list. You can either make the return void, or make the function return a new list, since the two are superfluous.</p>\n\n<p>Also, comme...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-30T14:42:08.453", "Id": "3226", "Score": "3", "Tags": [ "c#", "strings", "file" ], "Title": "Replace sequence of strings in binary file" }
3226
<p>I wonder if there is any way to write the followig in a few lines instead of using all cases. Both <code>CategoryType</code> and <code>AnimalSpecies</code> are <code>Enum</code>s.</p> <pre><code>private AnimalSpecies GetAnimalSpeciesBasedOnCategoryType(CategoryType categoryType) { switch (categoryType) { ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-30T17:34:47.750", "Id": "4856", "Score": "0", "body": "Dictionary data structure?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-30T17:51:52.010", "Id": "4857", "Score": "1", "body": "This is p...
[ { "body": "<p>How about (untested not near a computer at the moment)</p>\n\n<pre><code> return (AnimalSpecies )Enum.Parse(typeof(AnimalSpecies ), categoryType.ToString());\n</code></pre>\n", "comments": [ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-30T17:57:09.443", ...
{ "AcceptedAnswerId": "3230", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-30T17:32:27.037", "Id": "3229", "Score": "3", "Tags": [ "c#" ], "Title": "Return specific variable of Enum, determined by variable with the same name of another Enum?" }
3229
<p>I'm using an ObservableCollection in a WPF app. The source of the data doesn't provide changes. It provides snapshots instead. The method I wrote to update the ObservableCollection works but it seems inelegant. Is there a better way to do this?</p> <pre><code> public static void UpdateMarketOrderList( ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-30T19:33:53.413", "Id": "4862", "Score": "0", "body": "Is it assumed that lists are sorted by `Price` and there are no duplicates per Price?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-30T19:50:41.333",...
[ { "body": "<p>After studying your code snippet for a bit here's what I came up with. </p>\n\n<p>I wouldn't call them iterators. They're really acting more as indexing operators that doubles as a loop counter. Furthermore, they're always incremented in sync and they have the exact same initial value.</p>\n\n<pre...
{ "AcceptedAnswerId": "3256", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-30T18:28:48.907", "Id": "3231", "Score": "4", "Tags": [ "c#" ], "Title": "Keeping an observable collection up to date" }
3231
<p>This code kinda hurts my feelings -- everything else in my code is done in neat one-liners, exploiting algorithms and, sometimes <code>boost::bind</code>, except for this piece. To say nothing about awkward <code>if(b!=a)</code>.</p> <p>Is there a better way to do the task?</p> <pre><code>#include &lt;iostream&gt;...
[]
[ { "body": "<p>Also not really pretty, but perhaps a start</p>\n\n<pre><code>#include &lt;algorithm&gt;\n#include &lt;iostream&gt;\n#include &lt;list&gt;\nusing namespace std;\n\nint main()\n{\n list&lt;int&gt; lst = {1,2,3,4,5,6};\n\n auto a = lst.cbegin();\n int first = *a;\n auto output_pairs = [&...
{ "AcceptedAnswerId": "3260", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-07-01T12:57:53.863", "Id": "3243", "Score": "3", "Tags": [ "c++", "iterator", "iteration" ], "Title": "Iterating over unequal unordered pairs in one collection" }
3243
<p>I have the following code, but it's too slow. How can I make it faster?</p> <pre><code>&lt;?php class Ngram { const SAMPLE_DIRECTORY = "samples/"; const GENERATED_DIRECTORY = "languages/"; const SOURCE_EXTENSION = ".txt"; const GENERATED_EXTENSION = ".lng"; const N_GRAM_MIN_LENGTH = "1"; const N_GRAM_MAX_LENGTH = ...
[]
[ { "body": "<p>This code seems to be very good as far as performance is concerned. I cannot see any way to improve it.</p>\n\n<p>I used xdebug and cachegrind to see that my test samples were bound by the performance of the loop that creates the tokens. I investigated switching the $i and $j loops around, but t...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-07-01T14:21:08.343", "Id": "3244", "Score": "6", "Tags": [ "performance", "regex", "php5", "natural-language-processing", "unicode" ], "Title": "N-gram generation" }
3244
<p>I am always tired of the very verbose syntax in Java for creating small maps. <a href="http://download.oracle.com/javase/6/docs/api/java/util/Arrays.html#asList%28T...%29" rel="nofollow"><code>Arrays.asList(T... a)</code></a> is very convenient, and therefore I want something similar for a map.</p> <pre><code>publi...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-07-01T21:33:38.000", "Id": "4878", "Score": "0", "body": "Looks nice to me. But Landeis solution seems reasonable. :)" } ]
[ { "body": "<p>google-collections has all about it, e.g. <a href=\"http://google-collections.googlecode.com/svn/trunk/javadoc/com/google/common/collect/ImmutableMap.html#of%28K,%20V,%20K,%20V%29\" rel=\"nofollow\">ImmutableMap.of()</a>.\nMoreover they teach using right data structure, like <strong>true</strong> ...
{ "AcceptedAnswerId": "3250", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-07-01T14:27:49.660", "Id": "3245", "Score": "11", "Tags": [ "java" ], "Title": "asMap-implementation for Java (based on Arrays.asList)" }
3245
<p>We have some required services down temporarily when our server start. So we need some reconnection logic for them until they are finally up. There is a requirement to have also syncronious way for that. Here is my generic implementation for that via a single background thread:</p> <pre><code>public class RunUntilS...
[]
[ { "body": "<p>When you submit a task to an Executor you get back a Future, which feels like the appropriate API here since you want to block in one thread on a delayed computation.</p>\n", "comments": [], "meta_data": { "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDa...
{ "AcceptedAnswerId": "7212", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-07-01T14:57:54.470", "Id": "3246", "Score": "3", "Tags": [ "java", "multithreading" ], "Title": "connect in a background until success" }
3246
<p>I've been using this variation of the Repository pattern for over a year now:</p> <pre><code> public interface IReadOnlyRepository&lt;T, in TId&gt; where T : AbstractEntity&lt;TId&gt; { T Get( TId id ); IEnumerable&lt;T&gt; GetAll(); } /// &lt;summary&gt; /// Defines a generic reposito...
[]
[ { "body": "<p>I think it be useful to introduce explicit units of work that can be used in areas where needed such as Save(). I'd also suggest a generic Query() interface that will take a lambda to improve flexibility in retrieval. You might also consider asynchronous scenarios.</p>\n", "comments": [ ...
{ "AcceptedAnswerId": "3263", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-07-01T15:29:08.620", "Id": "3247", "Score": "2", "Tags": [ "c#", "design-patterns" ], "Title": "Variations of the Repository Pattern" }
3247
<p>For my project, I needed a way to instantiate different object types during runtime using "string names", for this I designed a generic factory that is created for each object hierarchy type (currently there are two different hierarchies that need the factory).</p> <p>We want the factory to be simple to use and sim...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-07-03T22:26:11.663", "Id": "4908", "Score": "0", "body": "Are all your objects default-constructible?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-07-03T22:33:45.170", "Id": "4909", "Score": "0", "...
[ { "body": "<p>Here are two things that you could do to generalise the Factory pattern and decouple the parameter problem. Either or both would make your life easier.</p>\n\n<ol>\n<li>You could consider using the concept of <code>boost::any</code> to allow an arbitrary number arguments of any type in your constr...
{ "AcceptedAnswerId": null, "CommentCount": "9", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-07-01T16:12:06.417", "Id": "3248", "Score": "9", "Tags": [ "c++", "design-patterns", "template" ], "Title": "Generic C++ Factory" }
3248
<p>I've only been writing php for a couple of months, and I've never really had anyone to look at any code I have written. I've written this class, that returns an email address from a database, based on a set schedule. I feel like a lot of the time, I'm doing things the long way, or just the wrong way. So I would rea...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-07-07T17:11:33.387", "Id": "4985", "Score": "0", "body": "Ok, I went through and commented out the whole mess. Will someone give me some suggestions please?" } ]
[ { "body": "<p>I'd consider:</p>\n\n<ul>\n<li>breaking it into smaller object (e.g. extract counters)</li>\n<li>do not hardcode the <code>dblink</code> connection + settings (e.g. pass the object in the constructor)</li>\n<li>use phpdoc comments</li>\n<li>correct formatting</li>\n</ul>\n\n<p>Try to write unit te...
{ "AcceptedAnswerId": "3743", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-07-01T21:16:38.260", "Id": "3252", "Score": "2", "Tags": [ "php", "mysql" ], "Title": "PHP email selector class" }
3252
<p>I'm working on a project for an image recognition software. The software takes an image and returns a set of labels (a label is just a string of text) which describe the contents of that image. Each returned label is also associated with a confidence value which quantifies how certain the algorithm of its label assi...
[]
[ { "body": "<p>for starters, if you are going to be linqy, you can be totally linqy</p>\n\n<pre><code>public List&lt;LookupResult&gt; PerformLookUp(HeuristicReturnValues unlabeledReturnValues)\n{\nif (unlabeledReturnValues.Label != null) \n throw new Exception(\"This guy is supposed to be unlabeled!\");\n\nret...
{ "AcceptedAnswerId": "3279", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-07-01T21:30:36.017", "Id": "3254", "Score": "1", "Tags": [ "c#", "library" ], "Title": "Critique the design and quality of this TrainingData class used in my image recognition software" }
3254
<p>Assuming I have 5 arrays, all just indexed arrays, and I would like to combine them, this is the best way I can figure, has anyone found a more efficient solution?</p> <pre><code>function mymap_arrays() { $args = func_get_args(); $key = array_shift($args); return array_combine($key, $args); } $keys ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-07-01T23:16:12.070", "Id": "4881", "Score": "4", "body": "Do you have to use arrays? I think using classes to group related data (and behavior) would be a lot nicer." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "201...
[ { "body": "<p>I would suggest the following:</p>\n\n<pre><code>function combine_keys_with_arrays($keys, $arrays) {\n $results = array();\n\n foreach ($arrays as $subKey =&gt; $arr)\n {\n foreach ($keys as $index =&gt; $key)\n {\n $results[$key][$subKey] = $arr[$index]; \n ...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-07-01T22:03:50.947", "Id": "3255", "Score": "6", "Tags": [ "php", "array" ], "Title": "Combining 3 or more arrays in php" }
3255
<p>The source code, or rather the concept I'd like to get reviewed is what now allows me to do the following during reflection:</p> <pre><code>object validator; // An object known to implement IValidation&lt;T&gt; object toValidate; // The object which can be validated by using the validator. // Assume validator is ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-07-03T19:23:31.103", "Id": "4903", "Score": "1", "body": "Having check the articles on your blog, I still haven't found the actual (concrete) use cases (which you said exist). Could you elaborate a bit more on that? I don't see the point ...
[ { "body": "<p>I recently faced a similar problem, but took a duck-typing approach instead, which works providing the type assumptions hold. For your case, this is what I would have written:</p>\n\n<pre><code>var validatorType = validator.GetType();\nvalidatorType.GetMethod(\"IsValid\").Invoke(validator, toVali...
{ "AcceptedAnswerId": null, "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-07-02T00:58:29.050", "Id": "3258", "Score": "5", "Tags": [ "c#", "proxy", "reflection" ], "Title": "Casting to less generic types" }
3258
<p>I have a live chat database and I am trying to get an idea of how many concurrent chats staff are taking. I'm not sure of the best way to report it so I have decided to get a list of chats for a given period then for each one display a count of chats that overlapped that one in some way.</p> <p>I am querying 2 tabl...
[]
[ { "body": "<p>A faster version of your final where clause is:</p>\n\n<pre><code>cr.Answered.Value &lt;= g.chat.Closed.Value &amp;&amp; cr.Closed.Value &gt;= g.chat.Answered.Value\n</code></pre>\n\n<p>If you do not want to count end points as overlapping (e.g. a call ending exactly at 9:59 and a call beginning e...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-07-02T02:26:24.103", "Id": "3259", "Score": "5", "Tags": [ "c#", "linq", "chat" ], "Title": "Getting items with overlapping DateTime using Linq" }
3259
<p>I have built a website using HTML and CSS. Actually I wanted to learn by implementing real world examples. I have built a site like Google. The search box does not work(I actually did not wanted to go further in the form action part and also did not wanted to use any search engine) and I have <strong>not</strong> co...
[]
[ { "body": "<p>One reason the <code>&lt;hr/&gt;</code> tag does not display is because the hr element is known to render differently depending on your browser. Try using Firefox, it usually is the best at rendering all sorts of tags. </p>\n", "comments": [ { "ContentLicense": "CC BY-SA 3.0", ...
{ "AcceptedAnswerId": "3270", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-07-02T16:03:18.547", "Id": "3261", "Score": "1", "Tags": [ "html", "css" ], "Title": "Please have a look at my HTML" }
3261
<p>I just watched a Khan Academy <a href="http://www.khanacademy.org/video/insertion-sort-algorithm?playlist=Computer%20Science" rel="nofollow">video</a> on Insertion Sort and I've tried to write an implementation in Python. Please suggest corrections or improvements on this program:</p> <pre><code>unsorted_list=[45,9...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-07-03T12:15:18.220", "Id": "4893", "Score": "1", "body": "This acts more like [bubble sort](http://en.wikipedia.org/wiki/Bubble_sort) in that it swaps more elements than necessary. The inner loop should not put the sorted sublist out of o...
[ { "body": "<p>And swapping in Python can be performed less verbose way:</p>\n\n<pre><code>unsorted[i], unsorted[j] = unsorted[j], unsorted[i]\n</code></pre>\n", "comments": [], "meta_data": { "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-07-03T14:31:08.91...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-07-03T07:57:02.547", "Id": "3264", "Score": "6", "Tags": [ "python", "sorting", "insertion-sort" ], "Title": "Khan inspired Insertion Sort" }
3264
<p>I have a little project going on and so far I'm not really having any problems. But since I haven't internalized all of Python's core features yet, I'm pretty sure my code offers pretty many subjects to optimize.</p> <p>Please point out anything that could be done better. For example, I'm feeling uncomfortable with...
[]
[ { "body": "<p>A few things I can see that will clean up the code a tad are:</p>\n\n<pre><code>def updateMousePosition(self, event):\n \"\"\" Slot that is called by the mouseMovedSignal of the ExtendedLabel\n which shows the image.\n Computes the u and v coordinates of the current mouse position and\n ...
{ "AcceptedAnswerId": "3299", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-07-03T12:04:34.450", "Id": "3267", "Score": "3", "Tags": [ "python", "performance", "image" ], "Title": "Texture viewer widget" }
3267
<p>I have created a data structure to handle some audio data I am generating (simple sine wave right now). It had some errors in it due to some misunderstanding of my ancient C knowledge that has been fixed by my cousin. I am wondering if there may yet still be more issues.</p> <p>I have considered turning this into a...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-07-08T12:39:29.503", "Id": "62831", "Score": "1", "body": "Just a comment about malloc/calloc: in C you shouldn't cast the result. (While in C++, you would have to cast it.) http://stackoverflow.com/questions/605845/do-i-cast-the-result-o...
[ { "body": "<p>Looks pretty good....</p>\n\n<p>there's a few style things I'd change</p>\n\n<pre><code>if (fifo-&gt;max_length - (int)(fifo-&gt;end - fifo-&gt;buffer) &lt; count) {\n</code></pre>\n\n<p>I'd bracket things here for clarity.</p>\n\n<p>potentially I'd also extract fifo->end - fifo->buffer into a sep...
{ "AcceptedAnswerId": "3283", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-07-03T19:50:20.503", "Id": "3273", "Score": "4", "Tags": [ "c", "objective-c", "queue", "audio" ], "Title": "FIFO queue for audio data" }
3273
<p>I've been focusing on my PHP skills lately but have been shifting to JavaScript. I'm familiar with the bare-bone basics of jQuery. I'm not as familiar with JavaScript as I'd like to be. I'm a solo-developer so I'd just like somebody to take a look at this and point out any mistakes or things I could be doing bett...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-07-03T23:26:19.467", "Id": "4911", "Score": "1", "body": "I believe no harm would be done were you to call [`setAttribute`](https://developer.mozilla.org/En/SetAttribute) directly on `element` rather than creating explicit attribute nodes...
[ { "body": "<p>You've erred many times in the above code. However, that means you get to learn a lot about how to properly interact with the DOM. In many instances, there are built-ins that quickly and efficiently get the job done.</p>\n\n<p>First off, you're incorrectly accessing the body. <a href=\"http://www....
{ "AcceptedAnswerId": "3275", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-07-03T23:00:59.230", "Id": "3274", "Score": "6", "Tags": [ "javascript" ], "Title": "JavaScript dynamic <script> creation" }
3274
<p>So this isn't EXACTLY my code but it is close enough to show what I have. Also the naming is only for this site so if its not really clear forgive me. Its much clearer in the actual code.</p> <pre><code>class Member(models.Model): team = models.IntegerField(default=0) match = models.ForeignKey(Match, null=T...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-07-06T16:05:41.200", "Id": "4969", "Score": "0", "body": "Can you clarify what are you trying to achieve? Such an unusual `Match` initialization *might* be \"odd and clumsy\", but without knowing the intent of the code it's hard to tell i...
[ { "body": "<p>Sorry, it just seems to me that issues lie outside of the piece of code that you're suggesting to review. The code itself is more or less fine, but some assumptions behind it seem not right.</p>\n\n<blockquote>\n <p>I had thought about Team objects but I was hoping not to get too complex. i can't...
{ "AcceptedAnswerId": "3358", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-07-04T01:59:17.650", "Id": "3278", "Score": "2", "Tags": [ "python", "django" ], "Title": "Django Team Sport class" }
3278
<p>In a web game there is a ranking of the top points games played of the month:</p> <pre><code>// QUERY SELECT * FROM game WHERE date &gt;= date_sub(CURDATE(),INTERVAL 1 MONTH) ORDER BY points DESC limit 0, 20 </code></pre> <p>But, in that case one player can be the top 1,2,3... so I have changed the query to add a ...
[]
[ { "body": "<p>You will have to test performance, but a <code>GROUP BY</code> should help:</p>\n\n<pre><code>SELECT playerName, MAX(points) AS points /*[, other columns]*/\nFROM game\nWHERE date &gt;= date_sub(CURDATE(),INTERVAL 1 MONTH)\nGROUP BY playerName /*[, other columns]*/\nORDER BY points DESC\nLIMIT 0, ...
{ "AcceptedAnswerId": "3282", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-07-04T07:30:54.657", "Id": "3281", "Score": "2", "Tags": [ "mysql", "sql" ], "Title": "Query of top players of the month" }
3281
<p>As you can see, the following is pretty ugly and seems to be unnecessarily long. Is there a shorter/neater way to do this?</p> <pre><code>function addNewRow(body, id){ var myRow = document.createElement("tr"); myRow.id = id+''; var c1 = document.createElement("td"); var c2 = document.createElement(...
[]
[ { "body": "<p>You need to use loops. Really, that's about it - all of the element creation and appending can be done in a loop, while the prefix for each of the element's <code>name</code> and <code>id</code> be stored in an array.</p>\n\n<pre><code>function addNewRow(body, id) {\n var myRow = document.creat...
{ "AcceptedAnswerId": "3285", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-07-04T10:44:52.423", "Id": "3284", "Score": "3", "Tags": [ "javascript", "html" ], "Title": "Generating table rows for a form using js" }
3284
<p>I'm creating a JavaScript/WebGL based game and would like you all to take a look at the current entity component system which I created for it. I've used it once before on another project, and while I was very happy with the results, there were parts of it I did not feel 100% good about. </p> <p>In particular, some...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-07-04T20:35:29.327", "Id": "4936", "Score": "2", "body": "\"i did not feel 100% about. <code dump>\" Would you like to give a high level overview of which parts might need addressing" }, { "ContentLicense": "CC BY-SA 3.0", "Cr...
[ { "body": "<p>Your code requires a ton of domain knowledge to properly review. I went to your Github repository to try and be more familiar with what you have.</p>\n\n<p><strong>Entity support for components</strong></p>\n\n<p>You asked specifically for this one, and I did find some things to ponder upon.</p>\n...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-07-04T20:08:27.150", "Id": "3287", "Score": "11", "Tags": [ "javascript", "design-patterns", "game", "entity-component-system" ], "Title": "Component-based system for JavaScript gam...
3287
<p>Is there any way to refactor this?</p> <pre><code>public IEnumerable&lt;Option&gt; Options { get { { List&lt;Option&gt; ListOption = new List&lt;Option&gt;(); if (!String.IsNullOrEmpty(Option1)) { ListOption.Add(new Option() {Name=Option1 }); ...
[]
[ { "body": "<p>This is a bit neater:</p>\n\n<pre><code>List&lt;Option&gt; ListOption = new List&lt;Option&gt; { };\nAction&lt;string&gt; add = x =&gt; { if (!String.IsNullOrEmpty(x)) ListOption.Add(new Option { Name = x }); }\nadd(Option1);\nadd(Option2);\nadd(Option3);\nadd(Option4);\nreturn ListOption;\n</code...
{ "AcceptedAnswerId": "3291", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-07-05T04:35:04.967", "Id": "3290", "Score": "15", "Tags": [ "c#", "null" ], "Title": "Checking for Null before adding into List" }
3290
<p>I started to play around with Hibernate since yesterday and came up with the following example of one-to-many relationship example, but I am not sure if I am doing right and I have no one around me knowing Hibernate. Please take a quick look at it, then maybe point out anything wrong.</p> <p>My goal is to use a on...
[]
[ { "body": "<p>Just 3 little remarks because it really looks good already.</p>\n\n<ul>\n<li><p>You want the setters of the id's to be private. They are generated\nvalues by Hibernate and other classes shouldn't mess with them.</p></li>\n<li><p>Also for the default constructors of <code>Student</code> and <code>P...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-07-05T13:43:03.407", "Id": "3293", "Score": "5", "Tags": [ "java", "hibernate" ], "Title": "Hibernate @OneToMany relationship" }
3293
<p>I'm currently trying to prove a data structure which I've created to speed up lookups for integral keys. The specific case I have in mind has the following usage case:</p> <ol> <li>At start is populated with n number of items (where n can be from 1 to thousands), and the specific key is actually an <code>unsigned i...
[]
[ { "body": "<p>Just a few points (caveat: I'm not a C++ expert).</p>\n\n<ol>\n<li><p>Comparing structured (i.e., non-scalar) keys is often the most expensive part of doing a search; it is usually worth searching first on an integer hash of the key. This way you only need to do integer comparisons for the most p...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-07-05T13:45:04.533", "Id": "3294", "Score": "6", "Tags": [ "c++", "algorithm", "tree", "lookup" ], "Title": "Tree/array mashup" }
3294
<p>I've written a python module that randomly generates a list of ideas that can be used as the premises for furthur research. For instance, it would be useful in situations where a new thesis topic is required, either for a masters or a doctorate program. Or if someone is just simply bored with their lives and wants ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-07-06T16:21:17.783", "Id": "4971", "Score": "1", "body": "Even for such simple program there's a thing you could do: replace each <tab> with four spaces (it isn't obvious here, but it is on the GitHub); this is a PEP recommendation. On a ...
[ { "body": "<p>I can't tell from your question whether you are wanting ideas to improve this python code or the project itself. Your code above works and is readable, so take the following re-spelling of it as minor nitpicks.</p>\n\n<pre><code>def topics(f):\n for i in open(f): # inline the call to open(),...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-07-05T13:57:34.133", "Id": "3295", "Score": "5", "Tags": [ "python", "python-2.x", "random", "generator" ], "Title": "Random Topic Generator" }
3295
<p>I'm a pretty visual person and I like to see all the cool information about objects, arrays and different variables in PHP. In the beginning I would just <code>echo '&lt;pre&gt;', var_dump($var), '&lt;/pre&gt;';</code> liberally throughout my code. Then I was introduced to MVC and started grasping the concept of O...
[]
[ { "body": "<blockquote>\n <p>Does this look horribly bad? </p>\n</blockquote>\n\n<p>It actually looks great: </p>\n\n<ul>\n<li>Perfectly consistent</li>\n<li>Code is self documented, simple and broken into appropriate blocks (your functions <em>make sense</em>)</li>\n<li>phpDoc everywhere! </li>\n</ul>\n\n<p>I...
{ "AcceptedAnswerId": "5980", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-07-06T01:09:17.280", "Id": "3301", "Score": "6", "Tags": [ "php", "object-oriented" ], "Title": "PHP Debugger Object needs review" }
3301
<p>I am currently developing a login script for my application. The login will use SSL and all required resources will be served through this. It is not protecting anything like a bank however I would like to know what is right and wrong especially for learning purposes</p> <p>I would love some feedback on my class th...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-07-06T10:02:39.997", "Id": "4964", "Score": "0", "body": "take care of sql injection: mysql_real_escape_string(form[data])" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-07-06T10:51:21.623", "Id": "4966", ...
[ { "body": "<p>Like Fanis said in his comment, you might want to put error checking on both your <code>getUserId()</code> and <code>getUsername()</code>.</p>\n\n<p>Good code overall (except maybe the singleton for your database object), few minor things like replacing <code>rand()</code> with <a href=\"http://ph...
{ "AcceptedAnswerId": null, "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-07-06T09:53:35.167", "Id": "3308", "Score": "3", "Tags": [ "php", "security" ], "Title": "Login script for an application" }
3308
<p>Is this good or not? Input arguments for <code>OsFile_Open</code> must be in UTF8 format. </p> <pre><code>#include &lt;stdio.h&gt; #ifdef WIN32 #include &lt;Windows.h&gt; #endif // Types declaration, originally they are located in header file // typedef int Bool_T; typedef signed long long ...
[]
[ { "body": "<p>I'd re-structure (the Win32 part of) the open function to something like this:</p>\n\n<pre><code>#ifdef WIN32\n\n wchar_t unicodeMode[MAX_PATH];\n wchar_t unicodeName[MAX_PATH];\n\n if (MultiByteToWideChar( CP_UTF8, 0, name, -1, unicodeName, MAX_PATH) &amp;&amp; \n MultiByteToWideC...
{ "AcceptedAnswerId": "3311", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-07-06T12:23:12.933", "Id": "3309", "Score": "4", "Tags": [ "c", "stream" ], "Title": "File stream functions" }
3309
<p><em>Moved originally from <a href="https://stackoverflow.com/questions/6592763/how-might-i-improve-the-structure-of-this-haskell-source">StackOverflow</a>, not knowing the existence of this sister site ...</em></p> <p>Must say I find programming in Haskell to require much more cognitive intensity than any other lan...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-07-08T13:45:11.743", "Id": "5002", "Score": "2", "body": "This may be a nitpick for a small program but it's a _really_ good habit to give functions explicit type signatures. It's good documentation and it helps sanity check your mental ...
[ { "body": "<p>I'm definitely <em>not</em> a Haskell expert, but here are my 2 cents:</p>\n\n<ul>\n<li>You should break your main functions in several methods. The amount of code running inside the IO monad should be minimized.</li>\n<li>You often use <code>case ... of</code> where a separate function with patte...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2011-07-06T14:36:42.100", "Id": "3310", "Score": "6", "Tags": [ "haskell", "file", "image" ], "Title": "Haskell program to rename images based on EXIF data" }
3310
<p>My current setup is a 3 layered application: UI > BLL > DAL. Each layer is set up as a separate project. The UI is an ASP.Net website and the BLL &amp; DAL are Class Library projects.</p> <p>I've shown some sample code from each of my layers. Hopefully you guys can critique my application design and give me some ti...
[]
[ { "body": "<p>Things I would change in your code/approach:</p>\n\n<ul>\n<li>log errors</li>\n<li>get rid of static service methods</li>\n<li>hide dll exceptions in ui. Catch it in BLL and log it/do something with it.</li>\n<li>change DLL so the method in BLL instead of:</li>\n</ul>\n\n<p><code>int userId = Int3...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-07-06T17:58:42.833", "Id": "3312", "Score": "7", "Tags": [ "c#", ".net", "asp.net" ], "Title": "3-layer ASP.NET app - Need critique/advice" }
3312
<pre><code>#region GetBookListByPriority private static List&lt;BCBook&gt; GetBookListByPriority(List&lt;BCBook&gt; listBcBook) { List&lt;BCBook&gt; newList = new List&lt;BCBook&gt;(); try { List&lt;BCBook&gt; listNonPriorityBcBooks = new List&lt;BCBook&gt;(); List&lt;BCBook&gt; listPriority...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-07-06T21:26:08.287", "Id": "4972", "Score": "0", "body": "You have several loops there. Which one is \"*this loop*?\"" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-07-07T13:26:55.307", "Id": "4981", "Sc...
[ { "body": "<p>I would get rid of <code>foreach</code> and use <code>for</code>. I have found (and read about) a huge performance difference between the 2 (<strong><em>EDIT</strong>, but not always, see below</em>). </p>\n\n<p><strong>Example (untested code):</strong></p>\n\n<pre><code>int c = listBcBook.Count;...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-07-06T21:08:28.037", "Id": "3315", "Score": "4", "Tags": [ "c#", "performance", "sorting" ], "Title": "Listing books by priority" }
3315
<p>I created a function which has, I believe, truly private variables. It's not quite production ready for several reasons:</p> <ul> <li>It's using <code>Object.defineProperty</code> -- I can deal with this</li> <li>It is re-defining every function in the prototype by doing <code>eval( fn.toString() )</code> -- I do ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-07-07T01:19:36.677", "Id": "4973", "Score": "1", "body": "You will likely get more informed comments if you ask on the Usenet forum comp.lang.javascript, which can be accessed using a newsreader (referable), or using [Google Groups](http:...
[ { "body": "<p>It looks like you can get rid of the eval</p>\n\n<pre><code>this[ fn ] = eval( '(' + proto[fn] + ')' );\n</code></pre>\n\n<p>by replacing it with</p>\n\n<pre><code>this[fn] = (proto[fn]);\n</code></pre>\n\n<p><a href=\"http://jsfiddle.net/somethingkindawierd/BRVcP/\" rel=\"nofollow\">Here's a jsfi...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-07-07T01:16:26.007", "Id": "3319", "Score": "6", "Tags": [ "javascript" ], "Title": "Truly private JavaScript variables" }
3319
<p>Could you please review the following code, and point out how I can make it cleaner, more idiomatic and easier to understand? </p> <pre><code>module Cabbage ( solve ) where data Place = Here | There deriving (Eq, Show) data Pos = Pos { cabb :: Place , goat :: Place , wolf :: Place ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-07-30T17:19:38.633", "Id": "5662", "Score": "0", "body": "Oh, I can write `data Pos = Pos {cabb, goat, wolf, farmer :: Place} deriving (Eq, Show)`." } ]
[ { "body": "<p>Haskell's record system is not really good at providing you uniform access to record entries. That is the reason your <code>findMoves</code> implementation has to be so verbose: You cannot generalize over the fields.</p>\n\n<p>There are a number of ways to get around that. One could be using a lib...
{ "AcceptedAnswerId": "3327", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-07-07T07:33:05.660", "Id": "3322", "Score": "2", "Tags": [ "haskell" ], "Title": "Cabbage-Goat-Wolf puzzle in Haskell" }
3322
<p>I was wondering if someone could have a look at this <a href="http://jsfiddle.net/sta444/Zz8yM/3/" rel="nofollow">BBC iPlayer style content accordion/slider</a> I've just made, and help me to get it working properly? I'm no expert in jQuery and I'm sure I haven't done this correctly, or if there are more efficient w...
[]
[ { "body": "<p>I'd normally suggest you post this on <a href=\"http://stackoverflow.com\">StackOverflow</a> as it doesn 't work properly.</p>\n\n<p>Firstly:</p>\n\n<ol>\n<li><p>You have the same two functions repeated over and over .... don't. Put them in one big selector.</p>\n\n<pre><code>$('#accordion &gt; ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-07-07T11:53:46.697", "Id": "3325", "Score": "4", "Tags": [ "javascript", "jquery" ], "Title": "'iplayer' style content accordion/slider" }
3325
<p>In response to <a href="https://stackoverflow.com/questions/6539461/any-value-in-javascript-html-decoupling-if-so-how/6539734">my own question</a> on Stack Overflow, I'm attempting a solution to decouple JavaScript and html. I'd appreciate any comments, proposed refactoring, or criticism.</p> <p>I have a fiddle of...
[]
[ { "body": "<p>Update here: <a href=\"http://jsfiddle.net/5ej8G/3/\" rel=\"nofollow\">http://jsfiddle.net/5ej8G/3/</a> (code is also pasted below)</p>\n\n<p>Main suggestions:</p>\n\n<ul>\n<li>your exportSymbol function can be refactored to handle an array of publicPaths and Objects.</li> \n<li>The subscribe cond...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-07-07T14:02:27.883", "Id": "3328", "Score": "3", "Tags": [ "javascript" ], "Title": "Decoupling JavaScript and Html" }
3328
<p>I've recently come across some areas of code in our solution that have a few thread-safety problems. Thread-safety is a minefield at best so I thought I'd have an attempt at writing a few little utility classes that would make it easier to write safe multi-threaded code.<br> The general idea is to link a resource w...
[]
[ { "body": "<p>This looks promising, though without the ability to enforce ordering i would remove the ability to associate multiple locks with a protected object, because you are just asking for a deadlock.</p>\n\n<p>Also, how do you protect against something like this:</p>\n\n<pre><code>Protected&lt;Reference&...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-07-07T14:46:15.070", "Id": "3329", "Score": "7", "Tags": [ "c#", "multithreading", "locking" ], "Title": "Associating a lock/mutex with the data it protects" }
3329
<p>I am parsing a huge XML file. It contains some million article entries like this one:</p> <pre><code>&lt;article key="journals/cgf/HaeglerWAGM10" mdate="2010-11-12"&gt; &lt;author&gt;Simon Haegler&lt;/author&gt; &lt;author&gt;Peter Wonka&lt;/author&gt; &lt;author&gt;Stefan Müller Arisona&lt;/author&gt; &lt;...
[]
[ { "body": "<p>You might want to try doing everything inside a transaction. It may be faster that way. I think with InnoDB you might be creating a committing a transaction for every statement which will be slow.</p>\n\n<pre><code>keys = str(tuple(keys)).replace(\"'\", \"\")\n</code></pre>\n\n<p>That's an odd way...
{ "AcceptedAnswerId": "3341", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-07-07T16:52:46.007", "Id": "3331", "Score": "2", "Tags": [ "python", "performance", "mysql" ], "Title": "Function to store data in MySQL database (using OurSQL)" }
3331
<p>I've created and launched our first HTML5 site. I've done a lot of research in to the "best practices" for writing a page in HTML5 and put a majority of them to use. I was hoping someone wouldn't mind looking over the site and shouting back any comments, issues, or recommendations on it. I'm looking for anything, fr...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-10-26T20:37:53.337", "Id": "28645", "Score": "0", "body": "Why are you using javascript for the menu? I don't see anything with the menu that can't be done without JS. This would also eliminate the `noscript` problem that RoToRa addressed...
[ { "body": "<p>I only have a few small points:</p>\n\n<ul>\n<li><p>The CSS Validator warns about the missing <code>type</code> attribute in the style sheet <code>link</code>. I'm aware it's not really needed, but I would add it nevertheless.</p></li>\n<li><p>Some people say, that <code>&lt;noscript&gt;</code> sh...
{ "AcceptedAnswerId": "3345", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-07-07T18:53:21.053", "Id": "3335", "Score": "6", "Tags": [ "html5" ], "Title": "First HTML5 site for a university computer lab" }
3335
<p>Due to the fact that Entity does not support Enums, I am converting them to strings, string lists, and back again.</p> <p>The reason is two fold: type-safety, and consistency in the database.</p> <p>Now, I have a bunch of these, but I will use Credit Cards as an example:</p> <pre><code> public enum CreditCardN...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-08-08T17:52:10.053", "Id": "107329", "Score": "0", "body": "Are you talking about Entity Framework when talking about Entity?" } ]
[ { "body": "<p>I solved a similar issue by inventing a DisplayName attribute, so I can define my enums like this:</p>\n\n<pre><code>public enum CreditCardName\n{\n [DisplayName(\"VISA\")]\n Visa,\n\n [DisplayName(\"MasterCard\")]\n MasterCard,\n\n [DisplayName(\"Discover\")]\n Discover,\n\n ...
{ "AcceptedAnswerId": "3350", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-07-08T05:00:35.037", "Id": "3337", "Score": "6", "Tags": [ "c#", "enum" ], "Title": "Is this a good/safe way to convert enums?" }
3337
<p>The program finds the largest palindrome made from the product of two <em>n</em>-digit numbers, where <em>n</em> is specified by the user.</p> <p>The code included works, however, when the user enters 5 or greater, the program runs very slowly. I believe it is \$O(n^2)\$ (feel free to correct that estimate if neede...
[]
[ { "body": "<p>First, as a general observation, you've made created essentially all your variables as belonging to the <code>FindPalindrome</code> object. IMO, this is a mistake. Each variable should have the minimum scope necessary to do its job. Any variable that's only used inside a particular function, for e...
{ "AcceptedAnswerId": "3357", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-07-08T06:25:53.873", "Id": "3338", "Score": "6", "Tags": [ "c++", "performance", "palindrome" ], "Title": "Finding the largest palindrome from the product of two n-digit numbers" }
3338
<p>My BLL's function is like:</p> <pre><code> public Categorymaster GetByPrimaryKey(CategorymasterKeys keys) { return _dataObject.SelectByPrimaryKey(keys); } </code></pre> <p>// above funciton is calling function written below</p> <pre><code> public Categorymaster SelectByPrimaryKey(Cate...
[]
[ { "body": "<p>What is the exception you are getting? What do you mean returns null and throws Exception?</p>\n\n<p>From putting this code into a class and executing a test on it, I get back an object or null when the record exists or does not respectively.</p>\n\n<p>If you're getting an exception from the abov...
{ "AcceptedAnswerId": "4057", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-07-08T06:56:58.453", "Id": "3339", "Score": "3", "Tags": [ "c#", "asp.net" ], "Title": "Handling Null Result with class object" }
3339
<p>The task is to write a function <code>findFraction maxDen number</code> to find a short but good rational approximation to a decimal representation of a number — <a href="http://www.topcoder.com/stat?c=problem_statement&amp;pm=11073&amp;rd=14236" rel="nofollow">problem statement on TopCoder</a>:</p> <blockquote> ...
[]
[ { "body": "<p>Hmmm, not much ideas, only syntax:</p>\n\n<pre><code>showResult :: (Int, Int, Int) -&gt; String\nshowResult (a, b, x) = concat [show a, \"/\", show b, \" has \", show x, \" exact digits\"]\n\n\npreciseDivision :: Int -&gt; Int -&gt; [Int]\npreciseDivision a b = let (d,r) = divMod (10*a) b in d : p...
{ "AcceptedAnswerId": "5295", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-07-08T07:46:34.993", "Id": "3340", "Score": "5", "Tags": [ "algorithm", "haskell", "programming-challenge", "rational-numbers" ], "Title": "BestApproximationDiv2 problem in Haskel...
3340
<p>I feel like repeating myself but i don't know how to refactor this. Linq condition is the same but property to compare is different (BookingDate ,CheckInDate ,CheckOutDate) </p> <pre><code> protected void FilterByDateRange(ref IEnumerable&lt;ViewBooking&gt; pObjListBooking) { DateTime startDate; ...
[]
[ { "body": "<p>You could do something like this, but I don't know, whether it's a good idea:</p>\n\n<pre><code>Func&lt;ViewBooking,DateTime&gt; getDate = null;\nswitch(...)\n{\n case ...:\n getDate = (ViewBooking item) =&gt; item.BookingDate;\n break;\n}\n\npObjListBooking = pObjListBooking.Where(item =...
{ "AcceptedAnswerId": "3343", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-07-08T08:49:17.093", "Id": "3342", "Score": "2", "Tags": [ "c#", "linq" ], "Title": "Property to compare in Linq is different by criteria." }
3342
<p>Normally I could just declare the 'email' variable as the base class for both of EmailInbound &amp; EmailOutbound, then cast-up to the inherited class. However, I don't think when defining EF codefirst classes you can use inherited classes, only POCOs. I could be wrong. Hence I've used the dynamic keyword. Could I u...
[]
[ { "body": "<p>I think it is quite defendable to use <code>dynamic</code> here. I'm not too familiar with EF, but it could very well be that you can't make the objects type-compatible. </p>\n\n<p>Even if you could, I would not do it if it was only to make this piece of code work. </p>\n\n<p>Declaring <code>email...
{ "AcceptedAnswerId": "3413", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-07-08T14:27:04.920", "Id": "3348", "Score": "4", "Tags": [ "c#", "entity-framework" ], "Title": "Dynamic variable - is that best way to dynamically assign?" }
3348
<p>I am developing some software that uses a pretty ancient low-level TCP/IP protocol from (I think) the eighties. I can send messages to the server very reliably, but I am a little unsure about receiving them. I cannot predict when the server will send me a message, so I have this method in an infinite loop. GetNextMe...
[]
[ { "body": "<p>A: 1. Here's a better way to check if a socket has disconnected.</p>\n\n<pre><code> bool SocketConnected(Socket s)\n {\n bool part1 = s.Poll(1000, SelectMode.SelectRead);\n bool part2 = (s.Available == 0);\n if (part1 &amp; part2)\n return false;\n else...
{ "AcceptedAnswerId": "3403", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-07-08T14:46:55.137", "Id": "3349", "Score": "3", "Tags": [ "c#" ], "Title": "Is this a good way to receive a message from a server?" }
3349
<pre><code>public partial class CreateAdmin : System.Web.UI.Page { #region Events. protected void Page_Load(object sender, EventArgs e) { if (!IsPostBack) { LoadOrganizations(); } } // Save Admin and Organization Admin in ...
[]
[ { "body": "<p>I don't like that you are using exceptions to determine if the email address is already in use. Exceptions are for <strong>exceptional behaviour</strong>, not something that is to be (reasonably) expected. It's not that unlikely that someone will try to use the same email address to register on ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-07-08T15:51:46.577", "Id": "3351", "Score": "2", "Tags": [ "c#", "asp.net", "exception" ], "Title": "Critical review of a Simple Class" }
3351
<p>I've recently got into an habit where I've used extension methods for giving things fluent-like properties - such as the below example or as another example <code>entity.AssertNotNull()</code></p> <pre><code>public static class GenericHelper { public static void AssignOrThrowIfNull&lt;T&gt;(this T obj, ref T as...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-17T10:50:09.047", "Id": "8164", "Score": "0", "body": "You can omit usage of `Expression<Func<bool>>` and replace it usage with `Func<T,bool>` with captured variables within the scope of the expression, as i did in my extended example....
[ { "body": "<p>I think that your instincts are right, I don't like it and it seems to be over-architected. The general pattern of checking if an parameter is null and throwing an exception is well established and programmers are used to it - so much so that they can understand it with a quick glance. Your refa...
{ "AcceptedAnswerId": "3362", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-07-08T19:22:52.273", "Id": "3352", "Score": "3", "Tags": [ "c#", "extension-methods" ], "Title": "Using an extension method for a small helper task that (ab)uses the fact that the object ...
3352
<p>I'm currently trying to brush up on ADT implementations, specifically an implementation for a Linked List (I'm using Java 5 to do this).</p> <p>Is this implementation I've written for <code>add(i, x)</code> correct and efficient?</p> <pre><code>public void add(int i, Object x) { // Possible Cases: // ...
[]
[ { "body": "<p>First: Java-1.5 and a List of Object, not a generic List? But a CS-degree and intermediate level? </p>\n\n<p>Second: Your comment complicates 2 cases: List is empty or not - if not ... - well, if you don't distinguish the cases, from: </p>\n\n<pre><code>// 1. The list is non-empty, but the request...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-07-08T20:14:19.497", "Id": "3353", "Score": "5", "Tags": [ "java", "linked-list" ], "Title": "Java Implementation of linked list add(i, x) method" }
3353
<p>What I'm trying to do here is get an RSS feed and append an Enclosure XML node to each item, which has a link to a video file (wmv).</p> <p>Try the below code with</p> <pre><code>url = "http://www.microsoft.com/events/series/digitalblackbelt.aspx?tab=rss" </code></pre> <p>for eg to get the point</p> <p>The perfo...
[]
[ { "body": "<p>I would bet that the regex.Match is the performance problem, as Jeff Atwood describes <a href=\"https://blog.codinghorror.com/regex-performance/\" rel=\"nofollow noreferrer\">here</a>.</p>\n<p>One thing that I would do is move regex definition to a static variable outside of the function defined a...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-07-08T20:19:10.613", "Id": "3354", "Score": "1", "Tags": [ "c#", "performance", "regex" ], "Title": "A faster way to look up for a url in a WebRequest/WebResponse html" }
3354
<p>I'm a beginner and have written my first Python module that parses a XML file containing some events and prints them out to <code>stdout</code> as JSON. I would appreciate some feedback about design, code layout, best practices, what can be optimized and so on.</p> <pre><code>from __future__ import with_statement ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-07-10T07:17:30.600", "Id": "5033", "Score": "0", "body": "I would stay away from using module names for anything else. In your case, it's `string`. It threw me off a little." } ]
[ { "body": "<pre><code>from __future__ import with_statement\n\nimport json\nimport xml.etree.ElementTree as etree\n\n\ndef _sanitize_string(string):\n \"\"\"docstring for _clean_string\"\"\"\n</code></pre>\n\n<p>Docstrings should contain a description of the function, not some old name for the function.</p>\...
{ "AcceptedAnswerId": "3370", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-07-09T18:38:38.053", "Id": "3365", "Score": "1", "Tags": [ "python", "beginner", "parsing", "json", "xml" ], "Title": "Parsing XML file containing some events" }
3365
<p>Please review this:</p> <pre class="lang-html prettyprint-override"><code>&lt;!DOCTYPE html &gt; &lt;html dir="ltr" lang="en-UK"&gt; &lt;head&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt; &lt;title&gt;Fahad | Just another web designer&lt;/title&gt; ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-07-10T19:07:36.870", "Id": "5052", "Score": "0", "body": "You should not put `script` or `noscript` or any other tags outside of the `html` tag itself. Use the [online version of the W3C validator](http://validator.w3.org/) or try the [Fi...
[ { "body": "<p>When writing HTML code (forgive me if I am wrong since I do not do a lot in HTML), the code doesn't really matter (sort of). As long as it's clean (which yours is) and with clear organizational pattern, the actual content of code shouldn't matter because HTML is based on laying out information in ...
{ "AcceptedAnswerId": "3410", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-07-09T20:17:48.500", "Id": "3367", "Score": "1", "Tags": [ "html", "css", "html5" ], "Title": "Website built with HTML and CSS" }
3367
<p>I'm writing a function to take an anagram pair (words or phrases spelled with the same letters) and determine how you could move the letters to change one into the other.</p> <p>For example: Admirer -> Married</p> <p>The results would be something like this:</p> <pre><code>[[0, 1], [1, 6], [2, 0], [3, 4], [4, 2],...
[]
[ { "body": "<p>You can simplify the logic by setting each character you find in target to NULL. I also like to use a \"while\" loop as shown below.</p>\n\n<pre><code>function _get_new_positions(source, target) {\n var transform = [], i, j, found, want;\n// convert both strings to arrays - uppercase so we can ...
{ "AcceptedAnswerId": "3400", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-07-10T03:09:30.280", "Id": "3371", "Score": "1", "Tags": [ "javascript" ], "Title": "Rearrange string to an anagram of the string - get new position, old position values" }
3371
<p>I have some code that I've included in a project I want to release. Here is one such block:</p> <pre><code>NSString *path = nil; if (delegate &amp;&amp; [delegate respondsToSelector:@selector(toolbarAssociatedXibName:)]) { path = [delegate toolbarAssociatedXibName:_toolbar]; if (![[NSBundle mainBundle] pat...
[]
[ { "body": "<p>Maybe you want something like this, (you will also need to log the error though)</p>\n\n<pre><code>(delegate &amp;&amp; [delegate respondsToSelector:@selector(toolbarAssociatedXibName)]) ? path = [delegate toolbarAssociatedXibName:_toolbar] : path = _identifier;\n</code></pre>\n", "comments": ...
{ "AcceptedAnswerId": "3453", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-07-10T06:34:22.797", "Id": "3373", "Score": "1", "Tags": [ "objective-c", "comparative-review", "delegates", "cocoa" ], "Title": "Setting the path to toolbarAssociatedXibName, wit...
3373
<p>Is there any other way to do this without all the extra outside parens here?</p> <pre><code>((ScheduledTask)(scheduledTasks[intCount])).TaskIntervalType </code></pre>
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-25T03:53:17.857", "Id": "5035", "Score": "4", "body": "You can drop the parentheses surrounding `scheduledTasks[intCount]` but that's as far as you can go without changing to `as` casting or using local variables..." } ]
[ { "body": "<p>Somewhat better:</p>\n\n<pre><code>(scheduledTasks[intCount] as ScheduledTask).TaskIntervalType\n</code></pre>\n\n<p>Note that the behavior would be somewhat different: The as cast will not throw an exception when not successful, but return <code>null</code> - so you would get a <code>NullReferenc...
{ "AcceptedAnswerId": "3375", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-25T03:50:44.273", "Id": "3374", "Score": "1", "Tags": [ "c#" ], "Title": "Cleaner Cast Syntax" }
3374
<p>On most my $_post data inputted on my site I use the following php:</p> <pre><code>$example = $_POST['textfield']; $example = strip_tags($example); $example = mysql_real_escape_string($example); </code></pre> <p>And then I would interact with the MySQL database...</p> <p>Is this 'secure' / 'safe'?</p> <p>Any maj...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-07-10T19:01:34.377", "Id": "5051", "Score": "2", "body": "I believe it's considered more secure to do prepared statements using [PDO](http://php.net/manual/en/book.pdo.php)." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDat...
[ { "body": "<p>It doesn't seem like there are any security issues with your code. But like grossvogel said, you shouldn't try to implement security by constantly writing that function every time you have a query, because maybe you'll forget. What I would recommend is that you write a helper function that automat...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-07-10T17:59:48.407", "Id": "3381", "Score": "1", "Tags": [ "php", "mysql", "security" ], "Title": "How could I make this PHP $_POST more secure? -Or is it secure already?" }
3381
<p>I have written the code below and I am trying to work out if there is a more efficient way of doing it: i.e. less lines of code and quicker etc.</p> <p>I am also wondering whether it is OK to declare variables inside of an <code>if</code> ... <code>else if</code> statement.</p> <pre><code>function test() { var...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-03T15:16:08.510", "Id": "98500", "Score": "1", "body": "Just had a 'collaboration' with Jamal. There is a lot of history on this question, and you're right, the code has not significantly changed, and your edits added more context. To ...
[ { "body": "<p>I don't know what the purpose of declaring your variable within your <code>if</code> statement is supposed to be here. For readability, I would declare those variables at the beginning of your function, like so:</p>\n\n<pre><code>function test() {\n var x = 3, \n msg, \n state;\n ...
{ "AcceptedAnswerId": "3385", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-07-10T19:10:17.863", "Id": "3382", "Score": "2", "Tags": [ "javascript", "jquery", "optimization" ], "Title": "Setting variables inside if / else-if statment blocks" }
3382
<p>I'm on a project involving converting HTML code to HTML5, and I'd like some feedback as to whether my code is correct or not.</p> <p>Here's my stripped-down code:</p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html lang="en"&gt; &lt;head&gt; &lt;meta charset="UTF-8"&gt; &lt;title&gt;Page Title Goes Here&lt;/title&gt; &l...
[]
[ { "body": "<ul>\n<li>give the site heading in a <code>h1</code> (probably in <code>header</code>); if the \"headerImg.png\" is your site name/logo, enclose it in <code>h1</code> instead (and give the site name in <code>alt</code>)</li>\n<li>if your \"headerImg.png\" is a typical site header image, you shouldn't...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-07-10T22:39:57.843", "Id": "3384", "Score": "5", "Tags": [ "html5" ], "Title": "Is the HTML5 code correct?" }
3384
<p>I am working on a Web chat application. In the app, users can run commands (such as /nick, /msg, etc) by starting with a / and then typing the command followed by parameters. For example, if someone wanted to change their username to "foobar", they would enter this in: </p> <pre><code>/whois foobar </code></pre> <...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-07-20T16:27:06.707", "Id": "5354", "Score": "0", "body": "Just a note that you really want to whitelist the possible commands that can match, to be secure." } ]
[ { "body": "<p>Just an idea, but maybe this will help you from a manageability point of view:</p>\n\n<pre><code> public function process($command, $parameters) {\n $method = 'MinteCommand_' . $command; \n $methodFile = dirname(__FILE__) . 'commands/' . $method . \".php\";\n if (file_exists($method...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-07-11T00:58:41.053", "Id": "3389", "Score": "4", "Tags": [ "php" ], "Title": "Suggestions for improving collection of related PHP functions?" }
3389
<p>I have zones</p> <pre><code>public class Zone { public string Caption { get; set; } public IList&lt;Module&gt; Contents { get; set; } } public class Zone1 : Zone { } public class Zone2 : Zone { } public class Zone3 : Zone { public enum Direction { Up = 1, Down = 2, ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-07-11T13:12:31.437", "Id": "5083", "Score": "0", "body": "Have you tried [gson](http://code.google.com/p/google-gson/)? It will probably work for Zone as well, and if not, you can create custom serializers." }, { "ContentLicense"...
[ { "body": "<blockquote>\n <p>I can add this property to class Zone, but I don't want that anybody\n could access it from outside.</p>\n</blockquote>\n\n<p>Which 'access' do you have in mind? through JSON (send you a 'fake' direction for zone1,2) or through code?</p>\n\n<p>Either way, I don't think that by not...
{ "AcceptedAnswerId": null, "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-07-11T13:05:14.800", "Id": "3392", "Score": "6", "Tags": [ "c#" ], "Title": "Is my way for parser written properly?" }
3392
<p>I just completed my first real application (command line app). It's simple, but I had no prior knowledge of Python. Everything was hit and miss, with many Python books and help from those in this community to guide me. Now, I am trying to see where I can refine my code and make things more efficient, as well as beco...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-07-11T12:45:34.327", "Id": "5085", "Score": "0", "body": "There's something wrong with your indentation. This is not valid python code." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-07-11T12:51:17.050", "Id...
[ { "body": "<ol>\n<li><p>Your indentation is wrong in the posted code. Please <strong>edit</strong> your question to (a) paste the code then (b) select all the code and (c) click the <code>{}</code> button to get it <em>all</em> indented correctly.</p></li>\n<li><p>A single large class which does everything is ...
{ "AcceptedAnswerId": "3394", "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-07-11T12:35:24.557", "Id": "3393", "Score": "0", "Tags": [ "python", "beginner", "strings", "converting", "console" ], "Title": "Command line tool for extracting, searching, a...
3393
<p>I have a situation where I have to connect to multiple schema to populate a single page.</p> <p>I altered our singleton db class in to help me do this.</p> <p>It will now destroy and re-declare itself whenever we pass a new set of db credential.</p> <p>Will the PHP pros mind code-reviewing this? we do not have co...
[]
[ { "body": "<p>I'm not sure if I necessarily agree with the idea of destroying the singleton and recreating the connection with different credentials. Perhaps there's a specific use-case for this that you have in mind, but I would personally not want to do this.</p>\n\n<p>I once solved an issue that I think is s...
{ "AcceptedAnswerId": "3412", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-07-11T22:05:20.547", "Id": "3402", "Score": "4", "Tags": [ "php", "php5" ], "Title": "Accessing multiple schemas using singleton pattern" }
3402
<p>I have a MySQL database with several columns and two rows of data, so far. I'm using mysql_fetch_assoc to return the data in database, but I don't know how to put it all together in a table so that I can display it in another file.</p> <p>Here is the code of the file that does the process (<code>query.php</code>):<...
[]
[ { "body": "<p>Aren't you forgetting something, called <code>&lt;td&gt;</code>?</p>\n\n<p>Try</p>\n\n<pre><code>&lt;?php\n\n// Configure connection settings\n\n$db = 'scorecard';\n$db_admin = 'root';\n$db_password = '********';\n$tablename = 'scoreboard';\n\n// Title\n\n//echo \"&lt;b&gt;DIV!&lt;/b&gt;\";\n\n// ...
{ "AcceptedAnswerId": "3406", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-07-12T04:19:20.703", "Id": "3405", "Score": "0", "Tags": [ "mysql", "php5", "ajax" ], "Title": "How can I display the results of mysql_fetch_assoc in a dynamic table?" }
3405
<p>I am developing a high level OpenCL binding in Haskell, and I need peer-review and testing. It currently only gets platform and device info from OpenCL.</p> <p>I have lots of functions that only change the returned type and the size of the type passed to the C library, but I don't know how to fix it.</p> <p><a hre...
[]
[ { "body": "<p>Looking through the code, I see often the \"high level wrapper\" returns CLuints and such. I would say that is improper - Why not return the haskell type?</p>\n\n<p>Instead of returning, say, CLint, do</p>\n\n<pre><code>f :: Integral i =&gt; ... -&gt; i\n</code></pre>\n\n<p>so that the user doesn'...
{ "AcceptedAnswerId": "3443", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-07-12T09:12:20.820", "Id": "3407", "Score": "6", "Tags": [ "haskell", "opencl" ], "Title": "New Haskell package: OpenCL" }
3407
<p>I have this coding and I think it works. However, I would like to understand if there is a better way to do this. This would automatically create new textboxes or delete them based on the given selected number.</p> <pre><code>&lt;script&gt; var OLD_CASE_NUMBER = 1; $("#cornercases").ready(function () { ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-07-11T19:06:22.767", "Id": "5134", "Score": "1", "body": "this might be more appropriate for the code review exchange." } ]
[ { "body": "<pre><code>$(document.createElement('div')). ...\n</code></pre>\n\n<p>is the same as:</p>\n\n<pre><code>$('&lt;DIV&gt;&lt;/DIV&gt;'). ....\n</code></pre>\n\n<hr>\n\n<p>you can just build uppon your previus jQuery statements:</p>\n\n<pre><code>$('&lt;DIV&gt;&lt;/DIV&gt;')\n .attr('id','lol')\n ....
{ "AcceptedAnswerId": "3416", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-07-11T19:04:04.787", "Id": "3415", "Score": "1", "Tags": [ "javascript", "jquery" ], "Title": "Adding/remving dynamically text boxes" }
3415
<p>I've just written two new headers: one that integrates Box2D and SFML by a class called <code>BodyRep</code> which creates/ is a graphic representation of any body, and one that produces huge amounts of uniform shapes, as to reduce copy/pasting. </p> <p>Things I'm worried about:</p> <ul> <li><strong>Performance:</...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2019-10-19T17:52:13.373", "Id": "450241", "Score": "1", "body": "Can you please provide code that would use these headers as an example, or provide test cases for it." } ]
[]
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-07-13T05:45:56.660", "Id": "3418", "Score": "3", "Tags": [ "c++", "performance", "memory-management", "sfml" ], "Title": "Integrating SFML and Box2D lib, and a Mass Production Shape...
3418
<p>How can I improve this code ? It takes an infinite time if i want to create un big maze (arguments 5000 5000 100 50 100)</p> <p>main.c</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; #include &lt;time.h&gt; #include "maze.h" /*test: valgrind --show-reachable=yes --leak-check=full -v ./dungeon 5...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-07-13T16:25:22.483", "Id": "5153", "Score": "1", "body": "That is a lot of uncommented code for someone to look at and figure out to answer your question. Can you provide an explanation (ideally in comments) or a link to the algorithm yo...
[ { "body": "<p>I didn't look in great detail because there's no explanation of the algorithm you are using, but I did notice that you have several code blocks similar to the following:</p>\n\n<pre><code>do {\n x = rand()%(maxx-1);\n y = rand()%(maxy-1);\n} while (map[x][y].visited != 0);\n</code></pre>\n\n...
{ "AcceptedAnswerId": "3425", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-07-13T15:10:23.250", "Id": "3423", "Score": "4", "Tags": [ "optimization", "c" ], "Title": "Maze generation, long random time" }
3423
<p>I'm looking for a single-pass algorithm for finding the topX percent of floats in a stream where I do not know the total number ahead of time ... but its on the order of 5-30 million floats. It needs to be single-pass since the data is generated on the fly and recreate the exact stream a second time.</p> <p>The alg...
[]
[ { "body": "<pre><code>top_nums = sorted(list(islice(iterable, int(percent*min_guess)))) #get an initial guess\n</code></pre>\n\n<p>There is no reason to make a list out of it before you sort it.</p>\n\n<pre><code>for ind, val in enumerate(iterable, len(top_nums))\n</code></pre>\n\n<p>I dislike abbreviations. I ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-07-14T00:26:44.347", "Id": "3429", "Score": "4", "Tags": [ "python", "algorithm" ], "Title": "Single pass algorithm for finding the topX percent of items" }
3429
<p>Can this part of a view controller subclass be checked for memory leaks. I am not that good at finding leaks. I need this class to be able to be loaded many time over without it crashing due to memory leaks. The endgame gets called every time it needs to go back to the main menu. I want it to be able to go back to t...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-07-14T02:01:06.917", "Id": "5166", "Score": "2", "body": "You have to indent your code with the {} - button in the edit box. And look at it in the preview, which is below your edit section. Didn't you read the FAQ and HOWTOS? The posts in...
[ { "body": "<p>There are several views that you're allocating and installing as subviews in <code>-viewDidLoad</code>. Among these are <code>NumberLabel</code>, <code>Background</code>, and <code>QuestionNumber</code>. (BTW, it'd be a little easier to follow your code if you stuck to Objective-C naming conventio...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-07-14T00:51:04.343", "Id": "3430", "Score": "2", "Tags": [ "objective-c", "memory-management" ], "Title": "Memory Question" }
3430
<p>I've created the following class to persist data by serializing/deserializing objects that are sent to it. I would like to know if there is a better way of writing this class, or if my class is fine the way it is.</p> <pre><code>using System.IO; using System.Runtime.Serialization.Formatters.Binary; using System.Run...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-07-16T00:02:23.313", "Id": "5246", "Score": "0", "body": "You say \"better way of writing\" the class. Better for what purpose?" } ]
[ { "body": "<p>There is no point in catching the IOException and then throwing a new exception. You only loose information here. Either handle it or remove the try-catch altogether.</p>\n\n<p>Also, use <code>using</code> to always dispose <code>IDisposable</code> objects.</p>\n", "comments": [ { ...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-07-14T07:33:54.357", "Id": "3432", "Score": "5", "Tags": [ "c#", ".net", "formatting", "serialization" ], "Title": "Persist data by serializing/deserializing objects that are sent t...
3432
<p>I have the following type of many functions so many if condtions are there is there is any way to reduce no. of lines.</p> <pre><code>enter: function(request, callback, callback1){ request.on={}; if(callback==undefined &amp;&amp; NodeClientUI.initdata.join!=undefined){ callback=NodeClientUI.initdata.j...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-07-14T10:03:14.313", "Id": "5168", "Score": "0", "body": "Is there no way to receive an array of callbacks? Or perhaps make some sort of resizing array for callbacks prior to the calling of this method? It would allow you to reduce this...
[ { "body": "<p>Try this:</p>\n\n<pre><code>enter: function(request, callbacks){\n request.on={};\n for(var key in callbacks) {\n var callback = callbacks[key];\n if(callback === undefined) {\n callback = NodeClientUI.initData[key];\n }\n request.on[key]=function(data)...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-07-14T08:00:25.060", "Id": "3434", "Score": "3", "Tags": [ "javascript", "node.js" ], "Title": "reduce no. of lines" }
3434
<p>It feels like pagination is one of the most discussed questions on the web, which always ends up with some quick and dirty hacks on how to paginate. I want to paginate a large result set from an SQL query on a website where I use Spring-JDBC for querying and <a href="http://www.displaytag.org/" rel="nofollow">Displa...
[]
[ { "body": "<p>Pagination should be done by the database server where applicable. There is really no point pushing data down the wire if it is not being used, so what you should think about doing, is passing in your page number and count variables to the query or preferable a stored procedure, and use SQL to se...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-07-14T09:17:48.127", "Id": "3436", "Score": "8", "Tags": [ "java", "pagination", "jdbc" ], "Title": "Paginating large SQL-Results" }
3436
<p>Here's a working version of my code - <a href="http://jsfiddle.net/sambenson/g3qsa/#base" rel="nofollow">http://jsfiddle.net/sambenson/g3qsa/#base</a><br> How can this be improved upon?</p> <pre><code>$(function(){ var box = {}, island = {}, canvas = {}; box.el = $('#box'); canvas.el = ...
[]
[ { "body": "<p>My comments are more just on style as opposed to performance:</p>\n\n<p>Instead of using :</p>\n\n<pre><code>if(box.el.css('visibility') == 'hidden'){\n</code></pre>\n\n<p>it's more readable to use :</p>\n\n<pre><code>if(box.el.is(\":hidden\")){\n</code></pre>\n\n<p>And similarly, instead of using...
{ "AcceptedAnswerId": "3447", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-07-14T13:33:07.860", "Id": "3439", "Score": "1", "Tags": [ "javascript", "performance", "jquery", "canvas" ], "Title": "Map markers on a canvas that pop up boxes when clicked" }
3439
<p>I am curious as to what the performance/functional differences are between:</p> <pre><code>private bool OftenCalledMethod(string s) { Regex reg = new Regex(@"^matchme$", RegexOptions.IgnoreCase); return (reg.IsMatch(s)); } </code></pre> <p>Versus:</p> <pre><code>readonly Regex reg = new Regex(@"^matchme$"...
[]
[ { "body": "<p>I would go with the former unless you profile your code and it tells you that the constructor for Regex is using a significant amount of time.</p>\n\n<p>Creating the Regex inside your method makes the clear statement that this given Regex is being used by only this method. The compiler doesn't ca...
{ "AcceptedAnswerId": "3442", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-07-14T15:31:45.917", "Id": "3441", "Score": "1", "Tags": [ "c#" ], "Title": "Performance difference between declaring Regex inside or outside of often-called method." }
3441
<p>I've created a JQuery script to help illustrate a few points for my teaching class, but I have having trouble slimming it down.</p> <pre><code>$(document).ready(function() { var red = $(".small-box"); var blue = $(".small-box2"); var green = $(".large-box"); red.hover( function () { ...
[]
[ { "body": "<p>A little shorter:</p>\n\n<pre><code>$(document).ready(function() {\n var red = $(\".small-box\");\n var blue = $(\".small-box2\");\n var green = $(\".large-box\");\n var boxes = red.add(blue).add(green);\n\n boxes.mouseleave(function() {\n boxes.removeClass(\"selected-highlig...
{ "AcceptedAnswerId": "3445", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-07-14T16:39:53.953", "Id": "3444", "Score": "2", "Tags": [ "javascript", "jquery" ], "Title": "Hover effects for red, blue, and green boxes" }
3444
<p>Yes I'm very slowly making my way through Purely Functional Data Structures. So I went through the section on Red Black Trees. What he presents is amazingly concise, except for the fact that he didn't include the delete function. Searching around didn't turn up many functional delete methods, well only two so far. O...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-07-12T11:31:58.393", "Id": "5176", "Score": "2", "body": "The built-in Set type is implemented using Red-Black trees and includes a remove function, so you could look at the source for that." }, { "ContentLicense": "CC BY-SA 3.0",...
[ { "body": "<p>Google for \"left leaning red black trees\"; they're Sedgewick's (substantial) simplification of RB trees and the paper includes all the code, including delete. By adding the constraint that all \"three-nodes\" lean left, the number of cases you need to consider is reduced dramatically.</p>\n\n<p...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-07-10T17:39:08.983", "Id": "3448", "Score": "9", "Tags": [ "f#", "functional-programming" ], "Title": "Deleting from Red Black Tree in F#" }
3448
<p><strong>Requirement:</strong> </p> <p>If the bookshop manager field changes from A to B, I need to email the person B saying that the new Bookshop has been allotted to him and he has to do certain activities. </p> <pre><code>private void SendEmailToAllottedManager() { EmailExpress mEmailExpress = new EmailExpre...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-07-15T12:28:21.220", "Id": "5179", "Score": "1", "body": "`SendEmailToManagerIfRequired`" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-07-15T13:25:25.677", "Id": "5181", "Score": "0", "body": "Mr Di...
[ { "body": "<p>I agree with you. The performed action of a method should correspond to it's name. In your colleague's suggestion, an email sent to the allotted manager is, as you already pointed out, not always being sent and thus not 100% semantically accurate.</p>\n\n<p>However, for the sake of readability, it...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-07-15T10:30:13.830", "Id": "3451", "Score": "2", "Tags": [ "c#" ], "Title": "Sending email for allotment" }
3451
<p>Can you please help me with the following script?</p> <p>At the moment the script is taking up to 20 mins to execute, depending on the amount of data being processed (each time the script is executed, it processes several thousand lines of data). I would like to make the script more responsive. Can you tell me ho...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-07-13T18:17:58.000", "Id": "5184", "Score": "0", "body": "I just noticed the part you said is problematic. Can you specify what you're trying to do and what are the datastructures. For example, what is `opco`?" }, { "ContentLicens...
[ { "body": "<p>Suggestions:</p>\n\n<ul>\n<li>compile your regex-es once and use the compiled version</li>\n<li>go over the log files <strong>once</strong> instead of three times.</li>\n<li>find the lines in the log using a regex - I don't know the exact syntax but it should say: \"starts with a newline, ends wit...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-07-13T18:00:45.737", "Id": "3454", "Score": "7", "Tags": [ "python", "optimization", "hash-map" ], "Title": "Holding records using dictionary" }
3454
<p>In your opinion what is the best way to construct an object given the two examples below:</p> <p><strong>Option 1:</strong> Lots of parameters</p> <pre><code>private string firstname; private string surname; private Address homeAddress; private PhoneNumber homeNumber; public Person(string firstname, string surnam...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-07-16T09:32:55.910", "Id": "5211", "Score": "0", "body": "Good question! An answer to the downside of option 1 is to require programmers to properly comment their long constructor calls (one comment per parameter). Something that can be e...
[ { "body": "<p>Starting out with immutable classes is typically a good idea. (according to Effective Java). I like to do things that way when I can.</p>\n\n<p>You should also check out the <a href=\"http://en.wikipedia.org/wiki/Builder_pattern\" rel=\"nofollow\">builder pattern</a>.</p>\n\n<p>As it encapsulates...
{ "AcceptedAnswerId": "3470", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-07-15T17:54:58.383", "Id": "3462", "Score": "7", "Tags": [ "c#", "constructor" ], "Title": "Constructors - lots of paramters or none and use of set methods" }
3462