body
stringlengths
25
86.7k
comments
list
answers
list
meta_data
dict
question_id
stringlengths
1
6
<p>I recently came up with the idea to attempt generating ungodly large prime numbers and their generators modulo N in php. I don't know much about number theory and just wanted to get some comments to see if this code should be sucessful. The output is just directed to a file at the moment because I didn't want to was...
[]
[ { "body": "<p>Instead of a global conditional operator is much more advantageous to use the boundary conditions</p>\n\n<p>For example:</p>\n\n<pre><code>if ($prime_fail){\n message_error(PRIME_FAIL);\n exit;\n}\n\n$generator_found = false;\n$g_upper_limit = 10; \n$onemod = gmp_intval(gmp_mod(1, $safe_prime));...
{ "AcceptedAnswerId": "6536", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-03T19:24:43.333", "Id": "2215", "Score": "8", "Tags": [ "php", "optimization", "primes" ], "Title": "Generating very large prime numbers and their generator modulo N in php" }
2215
<p>This is the first time I've written a start-stop-daemon script, so I would love some feedback. :) The goal is to have it start late, when the network and everything is ready. I also have 2 other start-stop-daemons that depend on this once being started before they launch and are nearly identical.</p> <pre><code>#! ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-07T05:05:49.137", "Id": "4377", "Score": "0", "body": "Awesome script. I see you activated the --background flag. In fact, this ties into my interest on this question (http://codereview.stackexchange.com/q/2841/4307). I plan on making ...
[ { "body": "<p>Probably, you also may implement <code>condrestart</code>:</p>\n\n<blockquote>\n <p>The condrestart (conditional restart) option only starts the daemon if it is currently running.\n This option is useful for scripts, because it does not start the daemon if it is not running.</p>\n</blockquote>\n...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-03T19:43:52.430", "Id": "2217", "Score": "5", "Tags": [ "bash" ], "Title": "Is this a decent way of writing a start-stop-daemon script?" }
2217
<p>I was trying to write a program that will read a collection of strings from the user, and then end the moment it encounters a <code>"."</code>. So then I write a <code>do</code>-<code>while</code> loop.</p> <p>I came across a something like this:</p> <pre><code>string temp; vector&lt;string&gt; params; do { ci...
[]
[ { "body": "<p>I prefer:</p>\n\n<pre><code>cin &gt;&gt; temp;\nwhile (temp != \".\")\n{\n params.push_back(temp);\n cin &gt;&gt; temp;\n}\n</code></pre>\n", "comments": [], "meta_data": { "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-04T00:36:49.633...
{ "AcceptedAnswerId": "2227", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-04T00:30:56.843", "Id": "2220", "Score": "24", "Tags": [ "c++" ], "Title": "Reading a collection of strings from the user" }
2220
<p>I have the task to create a function that adds some messages to the page and another to show them in last to first order with a jQuery <code>slideDown()</code> effect.</p> <p><a href="http://jsfiddle.net/WjaDE/5/" rel="nofollow noreferrer">jsFiddle</a></p> <pre><code>jQuery("#input1").click(function() { //Repr...
[]
[ { "body": "<p>I skipped the second button for simplicity's sake.</p>\n\n<p><a href=\"http://jsfiddle.net/WjaDE/7/\" rel=\"nofollow\">http://jsfiddle.net/WjaDE/7/</a></p>\n\n<pre><code>var jParent = $(\"#parent\"); \n// used an id for the unique element\n// cached the element up front\nvar DURATION = 500;\n\n$(\...
{ "AcceptedAnswerId": "9636", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-04T03:17:43.620", "Id": "2223", "Score": "3", "Tags": [ "javascript", "jquery", "jquery-ui" ], "Title": "jQuery Delay slideDown using Queue" }
2223
<p>The question of the cleanest way to write a loop that executes some action between each iteration has always interested me.</p> <p>In a sense, what is the best way in c/c++ to implement this fictional construct:</p> <pre><code>for (...) { } between { } </code></pre> <p>Using such a construct you could trivially i...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-04T05:27:45.983", "Id": "3574", "Score": "4", "body": "This seems more appropriate for Stack Overflow." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-04T21:46:11.127", "Id": "3604", "Score": "0", ...
[ { "body": "<p>The closest I've come to this in C or C++ is a slight modification to Knuth's <a href=\"http://www.google.com/search?q=%22loop+and+a+half%22\" rel=\"nofollow\">loop-and-a-half</a>:</p>\n\n<pre><code>template&lt;class T&gt;\nvoid print(std::vector&lt;T&gt; const &amp;x) {\n std::cout &lt;&lt; '[';...
{ "AcceptedAnswerId": "2226", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-04T04:41:34.090", "Id": "2225", "Score": "3", "Tags": [ "c++", "c" ], "Title": "Best syntax for executing an action between each loop iteration." }
2225
<p>I'm pretty new to Haskell and was playing around with some number manipulation in different bases when I had to write an integer logarithm function for my task.</p> <p>I don't mean discrete/modular logs, but simply <code>greatest x s/t b^x &lt;= n</code></p> <p>I developed a few versions and can't decide which I l...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2018-09-22T09:55:46.760", "Id": "393659", "Score": "0", "body": "I don't really know haskell, and so can't say which one is best, but `intlog''` is clearly the worst, as it will produce the wrong output! `log` returns floating point values, wh...
[ { "body": "<p>The problem with your <code>intLog'</code> function is definitely that it goes through all <code>n</code> numbers in the list. As a result of this it takes ages for large <code>n</code> (for <code>n = 2^130</code> it ran until I killed it, while your other solutions all returned the result instant...
{ "AcceptedAnswerId": "2235", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-04T15:06:19.783", "Id": "2233", "Score": "5", "Tags": [ "algorithm", "haskell" ], "Title": "Haskell - Different log methods" }
2233
<p>I have a WCF client which passes Self-Tracking Entities to a WPF application built with MVVM. The application itself has a dynamic interface. Users can select which objects they want visible in their Work area depending on what role they are in or what task they are doing.</p> <p>My self-tracking entities have qui...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-04T16:46:59.053", "Id": "3595", "Score": "2", "body": "Just passing right now but initially what I'll say immediately is _don't use properties that have side effects_, and if a **method** is asynchronous then explicitly mark it so by n...
[ { "body": "<p>I had <a href=\"https://stackoverflow.com/a/5955268/302677\">cross-posted this question on SO</a>, and got some good answers there. The answer I ended up going with was my own, although it was based on some of the other answers given to the SO question.</p>\n\n<p>Here's a copy of the answer I ende...
{ "AcceptedAnswerId": "10495", "CommentCount": "7", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-04T15:42:33.317", "Id": "2234", "Score": "15", "Tags": [ "c#", "asynchronous", "entity-framework" ], "Title": "What is better for Lazy-Loading Navigation Properties of detached Se...
2234
<p>This is a follow-up to the <a href="https://codereview.stackexchange.com/questions/2211/what-would-be-a-good-way-refactor-this-interpreter-written-in-c">question that I posted earlier regarding my interpreter</a>.</p> <p>After a lot of help, I refactored my code and added more functionality to it. Now, it allows us...
[]
[ { "body": "<ol>\n<li><p>Some of the previous recommendation haven't yet been resolved.</p></li>\n<li><p><code>double get_func_variable(const string&amp; op, istream&amp; in, vector&lt;Variable&gt; v)</code></p>\n\n<ul>\n<li>you generate exception in end of functions, which is ok, but where are you catching it?<...
{ "AcceptedAnswerId": "2243", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-04T18:36:55.607", "Id": "2236", "Score": "5", "Tags": [ "c++", "interpreter" ], "Title": "Preparing interpreter for error-handling" }
2236
<p>Here's the issue. When I build an asp.net application I create a singleton to read the values from the web.config file so that the values are only read once and gives a slight speed increase to the app. I basically do the following :</p> <pre><code>/// &lt;summary&gt; /// Static class that handles the web.config ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-04T19:01:33.330", "Id": "3598", "Score": "2", "body": "The web.config is loaded into memory once per-request anyway - it isn't loaded and parsed every time you access a section via the `WebConfigurationManager`. What speed increases ha...
[ { "body": "<p>The web.config is loaded into memory once per-request anyway - it isn't loaded and parsed every time you access a section via the WebConfigurationManager. What speed increases have you actually noticed? </p>\n\n<p>In fact, it might not even occur for each request, <a href=\"http://msdn.microsoft.c...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-04T18:37:09.080", "Id": "2237", "Score": "5", "Tags": [ "c#", "asp.net" ], "Title": "Optimizing the reading of web.config" }
2237
<p>I wrote a wrapper around boost-mpl and transformed it to an sql engine. It is a compile time sql thing, not related to normal databases. I have not finished it completely. I have some problem with the interface.</p> <p>A template meta program run in compile time. So input data always present in compile time that is...
[]
[ { "body": "<p>You my also want to have a look at how the Poco library achieves a similar thing using a Tuple class. From the <a href=\"http://www.appinf.com/docs/poco/00200-DataUserManual.html#11\" rel=\"nofollow\">docs</a>:</p>\n\n<pre><code>typedef Poco::Tuple&lt;std::string, std::string, int&gt; Person;\ntyp...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-04T19:27:33.390", "Id": "2238", "Score": "5", "Tags": [ "c++", "sql" ], "Title": "C++ template meta sql" }
2238
<p>The subroutine below, GetDetailsQuarterly, accepts two dates. Then it writes out each quarter that falls within the date range. It also gives the first and last day of the quarter. I really don't like how the beginning and ending dates of each quarter are hardcoded. I don't believe this solution accounts for leap ye...
[]
[ { "body": "<p>I am a bit lost in terms of what you are actually trying to accomplish, but I can give some pointers.</p>\n\n<p>First, leap years do not particularly impact quarters unless you truly have some unique rules. Under normal behaviors, February 29 will be in the same quarter as February 28, and would s...
{ "AcceptedAnswerId": "2242", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-04T20:27:08.403", "Id": "2240", "Score": "3", "Tags": [ ".net", "classes", "object-oriented", "vb.net" ], "Title": "Refactor a subroutine that divides date range into quarters....
2240
<p>Can you please help me split this method to reuse the repeating code?</p> <p>Any advice/comments on the code are welcome.</p> <pre><code>//This method will return Dictionary object having key/value pair of keywords and URLs. //Keywords are single word or bunch of words from db. //Value in dictionary is URLs aga...
[]
[ { "body": "<p>I would probably start by cleaning up the method before trying to extract anything as it will make it easier to see where to draw the line.</p>\n\n<ul>\n<li><p>There are a couple of places where you define a variable with an initial value and then override that value on the next line (singularKeyw...
{ "AcceptedAnswerId": "2252", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-05T06:09:27.603", "Id": "2246", "Score": "5", "Tags": [ "c#", "hash-map" ], "Title": "Return Dictionary object having key/value pair of keywords and URLs" }
2246
<h2>Description</h2> <p>Structured Query Language (SQL) is the most common language to use for interacting with relational databases. However, over the years, database vendors have implemented extensions of SQL to provide more functionality as well as simplify queries. Because most database systems are not fully com...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2011-05-05T08:16:59.207", "Id": "2247", "Score": "0", "Tags": null, "Title": null }
2247
Structured Query Language is a language for interacting with relational databases. Read the tag wiki's guidelines for requesting SQL reviews: 1) Provide context, 2) Include the schema, 3) If asking about performance, include indexes and the output of EXPLAIN SELECT.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-05T08:16:59.207", "Id": "2248", "Score": "0", "Tags": null, "Title": null }
2248
<p>I'm learning Haskell at the moment, and have just written my first useful module - a parser fo INI files. I used Parsec. I'd like to know what can be improved here - or maybe I did some things completely wrong and there is a better way. Thanks.</p> <pre><code>module IniFile (iniFileToMap) where import Text.ParserC...
[]
[ { "body": "<p>The first thing I noticed is that you have grouped all the type signatures together, away from the function bodies. This seems very strange to me. It's way more common (and as far as I'm concerned also way more readable) to have a value's type directly before its definition.</p>\n\n<p>The second t...
{ "AcceptedAnswerId": "2286", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-05T12:29:02.973", "Id": "2253", "Score": "6", "Tags": [ "haskell", "parsec" ], "Title": "INI File Parser in Haskell" }
2253
<p>I would like to write the following piece of code cleaner and more efficient, any comments will be greatly appreciated:</p> <pre><code>Dim dt As DataTable = SomeDataTable For Each dr As DataRow In dt.Rows Dim myColumn As String = dr("column").Trim().ToUpper() For Each group As String In collecti...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-05T11:53:31.270", "Id": "3619", "Score": "1", "body": "Unrelated, but don't use ToUpper() for case-insensitive string compares unless you're positive there will never be localized versions of your application (see: http://www.mattryall...
[ { "body": "<p>There are two concerns with the code presented. If you can guarantee that you won't ever need localization and that the strings in <code>collection</code> will ALWAYS be upper case then you could use something like this:</p>\n\n<pre><code>Dim dt As DataTable = SomeDataTable\n\nFor Each dr As DataR...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-05T11:37:16.133", "Id": "2254", "Score": "2", "Tags": [ "vb.net", "strings" ], "Title": "Iterate comparison - How can I write this better?" }
2254
<p>How to make this code better?</p> <pre><code>if (Program.Data.DataBase.TryOpenDataBase()) { bool result; DataBase= new Program.Data.DataBase(out result); if (!result) { if (Program.DataBase!= null) Program.DataBase.Dispose(); Program.DataBase= null; Log.WriteERROR("Can not open database")...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-05T14:22:45.773", "Id": "3636", "Score": "1", "body": "There's a lot of stuff here that appears to be proprietary and has no real meaning in a usable context. Are you using MSSQL, MySQL, Oracle? What does `TryOpenDataBase()` look like?...
[ { "body": "<p>I would remove the out parameter from the constructor. It is really confusing to read. Maybe create a function that throws an exception instead. If the database implements IDisposable you can use a using block instead.</p>\n\n<p><strong>Edit -</strong> You have some duplicate code as well:</p>\n\n...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-05T14:00:11.253", "Id": "2257", "Score": "4", "Tags": [ "c#", "exception-handling" ], "Title": "Open database and hande errors" }
2257
<p>I work as a C# developer at a company that doesn't use best practices at all. We're on .NET 3.5 but most code is written in a .NET 1.1 style (e.g. almost all the logic is in the code behind of the ASPX page, everything uses untyped DataSets instead of returning objects, makes gratuitous use of Session and QueryStri...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-27T08:39:18.513", "Id": "48131", "Score": "0", "body": "Did you show your peers any unit tests that you were able to write as a result of segregating the interfaces? That might have gone some way towards convincing them" }, { "...
[ { "body": "<p>The interfaces might be a little overkill, but they're not necessarily a bad idea. This is how the code is meant to be written. If it's too complicated for the lead and potentially the rest of the team, then perhaps the company needs a new team. I have to architect things with our junior developer...
{ "AcceptedAnswerId": "2263", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-05T14:26:42.713", "Id": "2259", "Score": "5", "Tags": [ "c#", "design-patterns", "xml" ], "Title": "Is this architecture overly complex or following best practices?" }
2259
<p>Note: This was originally posted at <a href="https://stackoverflow.com/questions/5883475/javascript-closure-code-trivia-to-keep-the-event-handler-separate">SO</a>, and as per the recommendation moving to this form. </p> <p>In my effort to learn JS on the backdrop of SVG development, I got lot of help from <a href="...
[]
[ { "body": "<ol>\n<li>Add more spaces.</li>\n<li>Use more named functions. (wrap the whole thing in an anonimous wrapper if you're worried about name space conflicts).</li>\n<li>When you do use lamdas give them names (it makes the code easier to read and you don't get showing up in the error log. </li>\n<li>Dec...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-05T14:37:19.507", "Id": "2260", "Score": "4", "Tags": [ "javascript", "jquery", "closure" ], "Title": "JavaScript closure: code trivia to keep the event handler separate" }
2260
<p>I have a representation for each <a href="http://en.wikipedia.org/wiki/Tetris#Colors_of_tetrominoes" rel="nofollow">initial shape</a> as an <code>Enum</code> with points and another for each rotated shape in the same <code>Enum</code>.</p> <p>Here is an example of the latter <code>Enum</code>:</p> <pre><code>// /...
[]
[ { "body": "<p>How are you rotating them now? Would it make more sense to change from an enum to a class with a Rotate method instead?</p>\n", "comments": [ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-06T06:55:46.180", "Id": "3656", "Score": "0", ...
{ "AcceptedAnswerId": "2273", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-05T21:59:03.937", "Id": "2265", "Score": "6", "Tags": [ "java", "design-patterns" ], "Title": "Tetris clone in Java" }
2265
<p>Over on <a href="https://stackoverflow.com/questions/5904425/what-is-difference-between-protected-and-private-derivation-in-c">StackOverflow</a>, I was asked if I could come up with an example where private inheritance would be preferred to composition (in C++). The following is the situation I described, and I was...
[]
[ { "body": "<p>Herb Sutter in his book 'Exceptional C++', Item 24 (Uses and Abuses of Inheritance), discusses the issue, and cites the following reasons for using private inheritance (instead of containment):</p>\n\n<ul>\n<li>Override a virtual function</li>\n<li>Access to a protected member</li>\n<li>Construct ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-05T23:08:54.410", "Id": "2268", "Score": "8", "Tags": [ "c++" ], "Title": "Composition or Private Inheritance for Implementing Builder?" }
2268
<p>I've got a method that parses a file. I take all the words and add them to a <code>SortedSet</code>. Every word contains a list of <code>Lines</code> that contain said word. Words are not strings but a class I created:</p> <pre><code>class Word : IComparable&lt;Word&gt; { public Word() { Lines = ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-06T02:10:40.870", "Id": "3646", "Score": "0", "body": "I would change the `foreach` to a `for` if you can. I was trying to do a lot of small things really fast (few thousand in less than a second) and `foreach` added a great deal of ov...
[ { "body": "<p>Your best bet is to not speculate or make assumptions when it comes to performance. Grab a profiler and get some real data so you can make the correct decisions based on that.</p>\n", "comments": [ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-06T01:09:12.1...
{ "AcceptedAnswerId": "2274", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-05T23:20:49.543", "Id": "2269", "Score": "7", "Tags": [ "c#", "performance", "parsing" ], "Title": "Slow-running File parser" }
2269
<p>Readability is a subjective parameter used to measure an aspect of code quality. It is based on the assumption that code should be easily comprehensible by humans, both in its form and in its meaning. </p> <p>To improve code readability, the following is usually considered:</p> <ul> <li><p>The code is written such...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-05T23:58:16.970", "Id": "2270", "Score": "0", "Tags": null, "Title": null }
2270
<p>I have written a simple web-scraper in Common Lisp, &amp; would greatly appreciate any feedback:</p> <pre><code>(defpackage :myfitnessdata (:use :common-lisp) (:export #:main)) (in-package :myfitnessdata) (require :sb-posix) (load (merge-pathnames "quicklisp/setup.lisp" (user-homedir-pathname))) (ql:quickload...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-06T16:19:09.227", "Id": "3660", "Score": "0", "body": "I always feel interested in every CL projects . Hey thank to your codebase, now I know how to use defpackage :D" } ]
[ { "body": "<p>You might want to take a look at defining <code>asdf</code> systems instead of using <code>quicklisp</code> to load dependencies internally.</p>\n\n<p>The standard way of doing this is to set up an <code>asd</code> file. <a href=\"http://tychoish.com/rhizome/using-asdf-install-with-sbcl/\" rel=\"n...
{ "AcceptedAnswerId": "2293", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-06T09:33:26.050", "Id": "2277", "Score": "6", "Tags": [ "common-lisp" ], "Title": "Simple web-scraper in Common Lisp (SBCL)" }
2277
<p>As a Python newbie, I have coded this binary tree as best as I could to follow Python idioms. However, I know it is still very verbose and not up to standard. I would like Python experts to tear this apart and identify its weaknesses. </p> <pre><code>class TreeNode(object): """ applicable to all tree nodes includ...
[]
[ { "body": "<p>Firstly, the official python style guide recommends 4-space indentation, and you are using 2. (No big deal but following the style guide is helpful)</p>\n\n<pre><code>class TreeNode(object):\n \"\"\" applicable to all tree nodes including root node \"\"\"\n def __init__(self, value, left=None, r...
{ "AcceptedAnswerId": "2282", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-06T10:06:26.743", "Id": "2280", "Score": "9", "Tags": [ "python", "beginner", "tree" ], "Title": "Binary tree in Python" }
2280
<p>I've got a list with about 120 items in IE and I have some items I want to activate. I compare, build and randomize some Arrays on the fly. The for loop in the <code>run()</code> function is really slow, and i tried to add a <code>setTimeout()</code>, like i've read somewhere on stackoverflow.</p> <p>It does not se...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-06T13:57:19.827", "Id": "3659", "Score": "0", "body": "I haven't looked at it too deeply, but just on the surface it looks like you're ultimately nesting 3 loops, each with a minimum of 120 members. This becomes 1,728,000 operations. i...
[ { "body": "<ol>\n<li><p>Interacting with the DOM is one of the slowest operations in JavaScript. I'd suggest selecting all your elements before the loop, then referring to the cached elements inside.</p></li>\n<li><p>On the same token, do not perform any DOM manipulation in a loop if you can help it. Since it...
{ "AcceptedAnswerId": "2295", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-06T13:37:15.867", "Id": "2283", "Score": "4", "Tags": [ "javascript", "performance", "jquery", "shuffle" ], "Title": "Activating items in some randomized arrays" }
2283
<p>I noticed a pattern in some elisp modes I was putting together:</p> <pre><code>(let ((map (make-sparse-keymap))) (define-key map KEY 'FN) ... (setq FOO map)) </code></pre> <p>so I wrote up the following macro</p> <pre><code>(defmacro def-sparse-map (name &amp;rest key/fn-list) `(let ((map (make-sparse-key...
[]
[ { "body": "<h3>General notes</h3>\n\n<ul>\n<li>Standard modes are not supposed to use <code>cl</code>. This, in practice, leads to more code duplication than it saves memory (a lot of third-party modes or user init files use <code>cl</code> anyway). So don't worry about using it unless you're really intent on h...
{ "AcceptedAnswerId": "3635", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-06T16:07:36.827", "Id": "2284", "Score": "4", "Tags": [ "elisp", "macros" ], "Title": "Keys in mode maps" }
2284
<p>I'm a hacker, not a trained engineer. I ask/answer specific questions on StackOverflow and am pretty confident in my ability to get the browser to do what I want, I thought I could benefit a great deal from a code review- hopefully I'm in the right place.</p> <p>Please tear down my bright-eyed naivetie with cuttin...
[]
[ { "body": "<p>The usefulness of creating a class is that you can have private variables.</p>\n\n<p>Simply placing every thing in an object defeats that point. Instead you should define everything in the protected part of the function and simply expose an external API with the return.</p>\n\n<p><a href=\"http:/...
{ "AcceptedAnswerId": "2302", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-06T16:48:20.973", "Id": "2287", "Score": "2", "Tags": [ "javascript", "jquery", "classes" ], "Title": "Javascript filter class to hide and show content on data-attributes" }
2287
<p>Could someone review the following code?</p> <pre><code>class PigLatin attr_accessor :phrase ending = "ay" def initialize the_phrase @phrase = the_phrase end def translate translated_phrase = String.new words = @phrase.split words.each do |word| puts word if vowel_is_first w...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-06T19:41:09.987", "Id": "3666", "Score": "0", "body": "Oh and btw: `0` is \"truthy\" in ruby, so `=~` returning `0` will not lead to problems in an `if`." } ]
[ { "body": "<p>First of all there are two mistakes in the code:</p>\n\n<ol>\n<li><code>ending = \"ay\"</code> is a local variable only visible directly in the class body, not inside of the <code>def</code>s. For this reason <code>translate_with_vowel</code> will throw a NameError when it is called. You should ma...
{ "AcceptedAnswerId": "2294", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-06T17:26:29.083", "Id": "2290", "Score": "7", "Tags": [ "ruby", "pig-latin" ], "Title": "Pig Latin Translator" }
2290
<p>I am trying to update my server to let it know that the user had some activity in the past 15 minutes. In order to do that, I made this implementation:</p> <pre><code>var page = { updated: false, change_state: function(e) { var self = this; if(!this.updated){ debugConsole.log...
[]
[ { "body": "<p>I wouldn't recommend using $(\"*\").live, you only need the events on the document body, so long as they are allowed to properly bubble.</p>\n", "comments": [ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-06T18:40:41.140", "Id": "3663", "Sco...
{ "AcceptedAnswerId": "2292", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-06T17:53:27.853", "Id": "2291", "Score": "3", "Tags": [ "javascript", "jquery" ], "Title": "Checking user mouse movement" }
2291
<pre><code>import random import rlereader class Board: """Handles the status of all cells.""" def __init__(self, size): self.size = size self.grid = self.make_blank_grid() self.furthest_col = 0 self.furthest_row = 0 def run_turns(self, num_turns): """Run a the sim...
[]
[ { "body": "<pre><code>import random\n\nimport rlereader\n\nclass Board:\n \"\"\"Handles the status of all cells.\"\"\"\n\n def __init__(self, size):\n self.size = size\n self.grid = self.make_blank_grid()\n self.furthest_col = 0\n self.furthest_row = 0\n\n def run_turns(self...
{ "AcceptedAnswerId": "2304", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-07T18:35:57.523", "Id": "2303", "Score": "10", "Tags": [ "python", "game-of-life" ], "Title": "Python implementation of a wrapped Conway's Game Of Life board" }
2303
<p>I need to extend the default <code>TextWriterTraceListener</code> class to include timestamps with each message on same line and file rotation. I can't seem to find any way of doing it with <code>TraceListener</code> configuration.</p> <p>Can you please review it and let me know any flaws to be used in a multi-thre...
[]
[ { "body": "<p>In my opinion the code is ok.</p>\n\n<p>there may be some minor issues</p>\n\n<ul>\n<li>Rotate-logfile is only called in the constructor of MyTextWriterTraceListener. So if you are tracing long running applications (i.e. a service) the logfile is not rotated at all.</li>\n<li>The LinePrefix with d...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-08T02:10:52.180", "Id": "2305", "Score": "4", "Tags": [ "c#" ], "Title": "TextWriterTraceListener class" }
2305
<p>From <a href="http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-18.html" rel="nofollow">SICP</a>:</p> <blockquote> <p><strong>Exercise 2.84</strong></p> <p>Using the raise operation of exercise 2.83, modify the apply-generic procedure so that it coerces its arguments to have the same type by the m...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-08T07:00:26.083", "Id": "2307", "Score": "1", "Tags": [ "lisp", "scheme", "sicp" ], "Title": "Coercion of arguments using successive raising" }
2307
<p>I'm posting my PHP code for sessions using MySQL. Please tell me if there are any errors, if it can be optimized, or if security can be enhanced.</p> <ul> <li>Host: localhost</li> <li>User: root</li> <li>Password: ""</li> <li>Database: pro</li> </ul> <p>Table structure:</p> <blockquote> <p>SessionID [pk] - Data...
[]
[ { "body": "<p>Your <code>open</code> and <code>close</code> functions don't do anything. You <em>could</em> use them to connect &amp; disconnect from the database. That way, an error in the connection won't be a read or write error, but will be an error in <code>open</code>. That may later help diagnosing such ...
{ "AcceptedAnswerId": "2311", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-08T14:32:01.737", "Id": "2310", "Score": "3", "Tags": [ "php", "mysql", "session" ], "Title": "Session in database" }
2310
<p>I'm a beginner-intermediate C++ programmer, and I never used or understood C input &amp; validation. I just always used C++ streams.</p> <p>Anyway, I just want code critique, as I have never used the C input functions (I admit, I have used and like <code>printf()</code>! I even made my own <code>sprintf()</code>, ...
[]
[ { "body": "<ul>\n<li>after <code>malloc</code> check result to NULL</li>\n<li>getCipherText check <code>src</code> to NULL, if <code>strlen</code> get NULL string it crushed.</li>\n<li>function <code>get_int</code> free <code>s</code> string before return result</li>\n</ul>\n", "comments": [], "meta_dat...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-08T20:42:37.177", "Id": "2314", "Score": "10", "Tags": [ "c", "beginner", "caesar-cipher" ], "Title": "Caesar Cipher program in C" }
2314
<p>I've just written this Twisted resource base class for serving files. It's part of a larger application, this is just for serving its images, JavaScript files, etc.</p> <p>Is it okay? I wonder if checking for <code>..</code> in the path is enough -- all the files that exist in <code>self.directory</code> are intend...
[]
[ { "body": "<p>Firstly, don't try to think of everything that could go wrong. Instead, check for what you know to be valid.</p>\n\n<pre><code>import re\ndirectory, filename = re.match('/([A-Za-z0-9]+)/([A-Za-z0-9]+)/?', alpha).groups()\n</code></pre>\n\n<p>By using this method to extract the directory and filena...
{ "AcceptedAnswerId": "2317", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-08T20:58:38.770", "Id": "2315", "Score": "4", "Tags": [ "python", "twisted" ], "Title": "File-serving Twisted resource" }
2315
<p>I am new to the world of coding, PHP as well as XHTML. As my first stab at object oriented coding, I put together a basic registration form that is meant to serve as a means to collect user details.</p> <p><strong>What this form does not do is the following;</strong></p> <ul> <li>Capture information is a file or d...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-09T04:42:21.637", "Id": "3692", "Score": "0", "body": "One quick critique: you shouldn't have echos in your class. Instead you should return strings and echo those strings in the xhtml. It makes things clearer." }, { "Content...
[ { "body": "<ul>\n<li><p>Why you create class <code>eventform</code> 3 times in XHTML? I think one is enough.</p></li>\n<li><p><code>&lt;?php echo isset($_POST['email']) ? $_POST['email'] : ''; ?&gt;</code> This is a classical example of <a href=\"http://en.wikipedia.org/wiki/Cross-site_scripting\" rel=\"nofollo...
{ "AcceptedAnswerId": "2356", "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-09T03:09:24.400", "Id": "2320", "Score": "2", "Tags": [ "php", "html", "css", "object-oriented" ], "Title": "Event Registration" }
2320
<p>At my work, I need to create a script that third-party webmasters could include in their pages without need to include something else. But this script had dependencies on jQuery and some amount of their plug-ins.</p> <p>On the Internet, I have found libraries that have same functionality except for an important one...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-10T01:52:42.237", "Id": "3716", "Score": "0", "body": "Parts of it are very clear, but the callback handling could use some comments or reworking. You have `obj` which can be a function or an object with a `callback` property, and `lib...
[ { "body": "<p>My 2 cents:</p>\n\n<ul>\n<li>please use lowercase camelcase ( lib_is_list -> libIsList )</li>\n<li>The first 5 lines seem clumsy\n<ul>\n<li>Checking for an array with typeof 'object' is odd</li>\n<li>Changing the type of a variable/parameter is odd and not recommended, you do this twice</li>\n<li>...
{ "AcceptedAnswerId": null, "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-09T07:59:32.850", "Id": "2324", "Score": "4", "Tags": [ "javascript" ], "Title": "On demand JS loader review" }
2324
<p>I am trying to learn OOP using PHP5 and I wrote a simple MySQL connection class. Please take a look and give me some feedback on better practices, critical errors, and any other feedback you can provide.</p> <p>Note: in the <code>verifyDatabaseConnection</code> method, I used an <code>@</code> symbol to curb the er...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-08T17:01:35.267", "Id": "3693", "Score": "0", "body": "i don't think this is a site for people to critique your code. this is a place to ask questions" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-08T17:0...
[ { "body": "<p>Nothing seems <em>too</em> amiss (the fact that you're suppressing errors via <code>$link = @mysql_connect</code> is OK, as you're explicitly checking the <code>$link</code> variable afterwards.)</p>\n\n<p>That said I'm really not sure why you wouldn't use <a href=\"http://www.php.net/mysqli\" rel...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-08T16:58:50.667", "Id": "2325", "Score": "3", "Tags": [ "php", "mysql", "php5" ], "Title": "MySQL connection class" }
2325
<p>I have designed the code but the problem is it timeouts as the range is 1000000000 but works fine with 1000. Any idea to optimize this or a mathematic logic for it? I just need to find the no of <code>pairs(a,b)</code> such that <code>a &lt; b</code> and <code>a*b % a+b == 0</code> if a range is given, eg: 15 - o/p...
[]
[ { "body": "<p>I have no algorithm that gives you the number for a given number (and I doubt there is one), but I can see a little improvement: indeed, if both <code>a</code> and <code>b</code> are odd, <code>a + b</code> which is even cannot divide <code>a * b</code> which is odd, so <code>a * b % a + b == 0</c...
{ "AcceptedAnswerId": "2352", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-09T07:36:35.273", "Id": "2327", "Score": "9", "Tags": [ "php", "algorithm" ], "Title": "Find the no of pairs whose sum divides the product from 0 - 1000000000" }
2327
<p>I tried putting a script i saw together, plus used an existing script to make something run as a service. Now I have the following pl script and the init.d / start/stop scripts.</p> <p>They work, but I am wondering if I did it right, because when I start the service and i would start it again, it would just start a...
[]
[ { "body": "<p>Oh crap, no. You have <code>use strict</code> commented out. Always, always, always <code>use strict</code> and <code>use warnings</code> until you understand when you might want to selectively turn off parts of what they do. Failure to do so will add huge amounts of extra debugging to your fut...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-09T12:22:44.507", "Id": "2330", "Score": "3", "Tags": [ "perl", "bash" ], "Title": "service build with perl - is it correct" }
2330
<p>Anyone want to comment on this plugin I'm making? (improvements, etc)</p> <pre><code>(function($) { var methods = { init: function(data) { var options = { function: null, timeout: 1000, option: undefined } return this...
[]
[ { "body": "<p>jQuery already has this functionality. Multiple animations on an element already automatically queue and wait until the previous animation has run. If you want to have a pause between two animations you can use <code>.delay()</code>. </p>\n\n<p>For example: </p>\n\n<pre><code>$('div.B').show('blin...
{ "AcceptedAnswerId": "2351", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-09T19:18:47.207", "Id": "2332", "Score": "-7", "Tags": [ "javascript", "jquery" ], "Title": "waitForIt Plugin" }
2332
<p>As a personal challenge, I am trying to make a very basic calculator without using any CLR's integer and arithmetic operations, but to only use memory. The idea was to do what CLR/OS does. i came up with a basic counter, Addition and multiplication, which works fine but multiplication takes long time to compute (if...
[]
[ { "body": "<p>It's a cool project you've got; but the performance is going to stink. The truth is, what you are doing is very different from what would happen when you perform basic math with + - / * in .NET. </p>\n\n<p>The obvious answer is to use the + - / * but that would defeat the purpose of what your do...
{ "AcceptedAnswerId": "2337", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-09T21:12:50.290", "Id": "2334", "Score": "13", "Tags": [ "c#", "algorithm" ], "Title": "To make a calculator from scratch" }
2334
<p>Please help me improve this function that compares the jQuery version currently available <sup>(or not)</sup> with the one required.</p> <pre><code>function(need) { if (typeof(jQuery) != 'undefined') { if (!need) return true; var re = /(\d+)\.(\d+)\.(\d+)/, cur = re.exec(jQuery.fn.jq...
[]
[ { "body": "<p>I'm sorry, but that code is completely broken. </p>\n\n<ul>\n<li>It doesn't work if either version contains only two numbers such as the current \"1.6\".</li>\n<li>It uses string comparison instead of integer comparison, so that it will return <code>true</code> if you \"need\" (theoretical) versio...
{ "AcceptedAnswerId": "2347", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-10T05:20:29.983", "Id": "2340", "Score": "4", "Tags": [ "javascript", "jquery" ], "Title": "Improve this function that compares jQuery versions" }
2340
<p>I want the fastest way in Mathematica 7 to generate a list of the factors (not prime factors) of an integer into a specified number of terms, with each factor greater than one.</p> <p>For example, 240 into three terms:</p> <pre><code>{{2,2,60}, {2,3,40}, {2,4,30}, {2,5,24}, {2,6,20}, {2,8,15}, {2,10,12}, {3,4,20}...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-10T12:51:38.990", "Id": "3725", "Score": "0", "body": "Welcome to CodeReview, Mr. :)" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-10T16:39:11.437", "Id": "3740", "Score": "0", "body": "@belis...
[ { "body": "<p>Because <code>Divisor</code> is quite efficient at its job, the only optimization I see, is to avoid unnecessary calls to it, by using memoization technique:</p>\n\n<pre><code>FactorIntoFixedTerms[in_Integer, terms_Integer] := Block[{f, div},\n div[n_] := (div[n] = Divisors[n]);\n f[n_, 1] := {{...
{ "AcceptedAnswerId": null, "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-06T15:36:41.180", "Id": "2342", "Score": "2", "Tags": [ "algorithm", "wolfram-mathematica" ], "Title": "List of integer factorization into n terms" }
2342
<p><strong>Requirement</strong>: Parse a String into chunks of numeric characters and alpha characters. Alpha characters should be separated from the numeric, other characters should be ignored. </p> <p><strong>Example Data:</strong></p> <pre> Input Desired Output 1A [1, A] 12 [1...
[]
[ { "body": "<p>I'm sure this possible with some crazy RegExp and <code>.split()</code>, but I would avoid RegExps for \"simple\" tasks like these.</p>\n\n<p>One thing I would change, is the check if a \"chunk\" matches the pattern. For example, when working on the string <code>\"AB12\"</code>, then currently you...
{ "AcceptedAnswerId": "2349", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-10T13:35:46.913", "Id": "2345", "Score": "13", "Tags": [ "java", "strings", "parsing", "regex" ], "Title": "Simplify splitting a String into alpha and numeric parts" }
2345
<p>Beeing on .NET 3.5 i don't have access to the TPL. Yet i have become fed up of having to manage manually the logic behind delegate.BeginInvoke type of scenarios each time and i set up to implement my own Task class.</p> <p>Functionality it should support:</p> <ul> <li>starting a parallel execution (using a thread...
[]
[ { "body": "<ul>\n<li><p>You may want to consider replacing the flags (<code>IsRunning</code>/<code>IsCompleted</code>) with a single state enum.</p></li>\n<li><p>Some state checks use <code>_abortLock</code> while others use <code>_completedLock</code>.</p>\n\n<ol>\n<li>If <code>Abort()</code> is called on a Ta...
{ "AcceptedAnswerId": "2365", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-10T13:35:48.240", "Id": "2346", "Score": "10", "Tags": [ "c#", ".net" ], "Title": "Async Task implementation" }
2346
<p>About a week ago, I put up this code and got some really good help. I've modified it a bit and was seeking if someone would review my second iteration. Original can be found <a href="https://codereview.stackexchange.com/questions/2290/pig-latin-translator">here</a>.</p> <p>Here's the new stuff. Basically, I stuck...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-10T19:16:46.807", "Id": "3745", "Score": "0", "body": "Any reason you didn't go with `String#split` to split the word into segments?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-10T20:08:40.150", "Id...
[ { "body": "<p>I think this is a great way to work on your skills, and I applaud your perseverance here. In particular, it is important to recognize that building software is incremental, and ideally there is a tight loop of development, review, re-factoring, re-review, etc.</p>\n\n<p>Here are some comments from...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-10T19:01:39.193", "Id": "2353", "Score": "7", "Tags": [ "ruby", "pig-latin" ], "Title": "Pig Latin Translator - follow-up" }
2353
<p>I am wondering if this code will work in 10.1.</p> <p>This <a href="http://resources.arcgis.com/gallery/video/arcgis-server/details?entryID=C0806E5E-1422-2418-A02E-CF00BF8ABEC7" rel="nofollow noreferrer">video</a> at 1:02 says not to create mxd based services. I think that just means not using <a href="http://help....
[]
[ { "body": "<p>The reason why the video states that you should not create SOEs on top of MXD based map services is because in 10.1 you will not be able to start a service from an mxd. You will need to convert your map document into a service definition. </p>\n\n<p>One of the issues you will find with MXD-based S...
{ "AcceptedAnswerId": "2357", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-10T22:58:30.130", "Id": "2355", "Score": "4", "Tags": [ "c#" ], "Title": "IMapDocument in a 10.1 SOE" }
2355
<p>I found a SERP checker written in PHP and I decided, in order to better learn to program, I would re-write it in Ruby.</p> <p>All I have written so far takes a list of keywords that a user inputs and cleans the list and turns each keyword into a url for Google search.</p> <p>Here is the code:</p> <pre><code>requi...
[]
[ { "body": "<p>I see you haven't got any response on this for a long while, so I'll give it a try.</p>\n\n<p>I don't really see anything to pick on when it comes to style or technique. To me this looks very good. A few questions though:</p>\n\n<ol>\n<li>why do you <code>require \"rspec\"</code> in the controller...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-11T05:45:05.150", "Id": "2358", "Score": "5", "Tags": [ "ruby" ], "Title": "Critique some Ruby + RSpec Code for a SERP checker" }
2358
<p>With some advice from SO, I developed this system, which I think is quite strong for bots to automatically post comments.</p> <p><strong>index.php</strong> </p> <pre><code>&lt;html&gt; &lt;head&gt; &lt;script type="text/javascript" src="jquery.js"&gt;&lt;/script&gt; &lt;script&gt; function main() { var str=$("#ke...
[]
[ { "body": "<ul>\n<li><p><code>365*60*60*24</code> should be a constant.</p></li>\n<li><p>You should really improve your variable naming.</p>\n\n<pre><code>$date2 = date(\"Y-m-d H:i:s\");\n</code></pre></li>\n<li><p><code>date2</code>? Does that say anything? <code>currentTime</code> is more like it. <em>Always<...
{ "AcceptedAnswerId": "2363", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-11T09:51:57.917", "Id": "2362", "Score": "7", "Tags": [ "php", "security", "php5", "ai" ], "Title": "Anti-Bot comment system" }
2362
<p>I want to perform a search in several columns of a table. I use the following query:</p> <pre><code>select * from Tabela t inner join "TabelaPai" tp on tp."ID" = t."RefTabelaPai" and tp."RefProject" = 'projectid' where not t."Deleted" and (t.Col1 ~ '.*__param1__.*' or t.Col2 ~ '.*__param1__.*' or t.Col3 ~ '.*__pa...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-25T20:09:53.310", "Id": "4104", "Score": "2", "body": "I think this is more of a database design issue rather than a query issue. How is your database used such that you need to search for the same value *across several columns* to fin...
[ { "body": "<p>I must admit, I don't really see what's wrong with the repetition — assuming it <em>is</em> what you're wanting to do (and your columns aren't <em>actually</em> named <code>t.Colx</code>!). If I came across this query in a project, I'd know pretty quickly what it's doing I think: searching a bunc...
{ "AcceptedAnswerId": "2649", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-11T11:11:45.173", "Id": "2364", "Score": "9", "Tags": [ "sql", "postgresql" ], "Title": "SQL: Search for a keyword in several columns of a table" }
2364
<p>I am 100% self-taught, and so I try to read as much as I can about best practices, conventions, etc. However I freelance, and have been in a long-term contract position for the past little while with almost no peers to review my code. So I get nervous about developing bad habits.</p> <p>Looking closely at this func...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-12T21:06:51.873", "Id": "3786", "Score": "0", "body": "Your style is very readable. Almost makes me feel like I would be able to pick up PHP with ease." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-13T15:...
[ { "body": "<p>Your code looks like its good quality code. And yes, you’re right to be concerned. Most likely, after you’re gone, somebody else will (eventually) maintain, or change the code that you’ve written to date. I suggest that you comment and write the code so that a maintainer understands its purpose at...
{ "AcceptedAnswerId": "2391", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-11T23:32:56.007", "Id": "2370", "Score": "6", "Tags": [ "php", "mysql" ], "Title": "Working with databases in PHP" }
2370
<ol> <li><p>This function computes and returns the number of divisors an integer has. But it is very slow and I believe it can be optimized for speed.</p> <pre><code>unsigned long long int find_no_of_divisors(unsigned long long int myno,FILE *ifp) { unsigned long long int divsrs = 2; unsigned long long in...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-12T09:35:42.240", "Id": "3770", "Score": "0", "body": "I believe the formatting was messed up a bit due to the numberings in your question, adding some extra spacing seemed to have solved it." }, { "ContentLicense": "CC BY-SA 3...
[ { "body": "<p>The first function can be sped up by just iterating up to <code>sqrt(myno)</code> and adding 2 instead of 1 to <code>divsrs</code> when <code>k</code> divides <code>myno</code> unless <code>k</code> is the square root of <code>myno</code> (in which case you would only add 1).</p>\n\n<p>The second ...
{ "AcceptedAnswerId": "2380", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-12T09:10:14.613", "Id": "2378", "Score": "7", "Tags": [ "optimization", "c", "mathematics" ], "Title": "Find number of divisors for integer and sum of integers" }
2378
<p>I think that the <code>slice()</code> is a bit hacky, and prone to breaking if I change my mind about the <code>id</code> names, but I wanted this to be generic so I could add types easily.</p> <p>Is there maybe another / better way to do this just using CSS nesting the 'panels' inside the li elements?</p> <p>Mark...
[]
[ { "body": "<p>This kind of navigation is usually referred to as tabs or tabbed navigation. There are loads of ready scripts on the net for this - for exampe - since you are using jQuery - <a href=\"http://jqueryui.com/demos/tabs/\">jQuery UI</a>. But since this is really a quite trivial functionality, it's quit...
{ "AcceptedAnswerId": "2384", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-12T09:32:26.997", "Id": "2379", "Score": "6", "Tags": [ "javascript", "jquery", "html" ], "Title": "JavaScript navigation UI" }
2379
<p>I am looking to optimize the following computation. First, some explanations:</p> <p><strong>Explanation</strong></p> <p>I have a directed graph whose adjacency matrix may only contain 1s and 0s. The <em>similarity</em> of nodes <em>i</em> and <em>j</em> is defined as follows:</p> <ol> <li>count how many nodes ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-12T15:35:05.230", "Id": "3782", "Score": "0", "body": "Please see my latest edit." } ]
[ { "body": "<p>Minor improvements, but consider using:</p>\n\n<pre><code>pList = ArrayFlatten[{{am\\[Transpose], am}}];\n</code></pre>\n\n<p>and</p>\n\n<pre><code>dropDiagonal = MapThread[Delete, {#, Range@Length@#}] &amp;;\n</code></pre>\n\n<p>I also tried <code>dropDiagonal = MapIndexed[Drop, #] &amp;</code> b...
{ "AcceptedAnswerId": "2386", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-12T13:52:13.963", "Id": "2385", "Score": "7", "Tags": [ "optimization", "wolfram-mathematica" ], "Title": "Directed graph similarity calculation -- optimizing Mathematica code" }
2385
<p>I use the following code to put all of my error messages for the application in one javascript variable. Is this efficient way to store my error messages?</p> <pre><code>var cosmoBase = { messages: { empty: "Please enter ", numeric: "Please enter a valid number for ", date: "Please enter...
[]
[ { "body": "<p>I would recommend you use a factory instead.</p>\n\n<pre><code>cosmo.error = function(id) {\n ...\n};\n</code></pre>\n\n<p>then just use <code>cosmo.error(\"ssn-empty\")</code></p>\n\n<p>Having your logic in a factory rather then an object gives you more control and makes your code significantl...
{ "AcceptedAnswerId": "2389", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-12T14:44:06.180", "Id": "2387", "Score": "6", "Tags": [ "javascript" ], "Title": "Is this a good way to store error messages to display back to the user?" }
2387
<p>How do I handle multi-tenancy with routes in ASP.NET MVC?</p> <p>The application is a multitenant ASP.NET MVC 3 application. Tenants are identified based on hostname so this does not interfere with routing.</p> <p>Other important information:</p> <ul> <li><p>The application has a number of features (or plugins). ...
[]
[ { "body": "<p>One way to handle it is to write an ActionFilter that does checking against the list of features the customer owns, and if they don't own that feature, it redirects them to buy it. </p>\n", "comments": [ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-12T21:3...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-12T14:41:48.413", "Id": "2393", "Score": "14", "Tags": [ "c#", "asp.net", "asp.net-mvc-3", "url-routing" ], "Title": "\"Pluggable\" routes in ASP.NET MVC" }
2393
<p>I have posted an <a href="https://codereview.stackexchange.com/questions/2325/critique-my-first-oop-attempt">earlier version of this</a> and here is the improved version from the feedback I recieved. Some of the feedback I received was;</p> <ul> <li>Don't chain method (tried my best to limit this)</li> <li>Do not u...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-26T08:09:16.250", "Id": "4116", "Score": "0", "body": "Not too bad, way too much conditional nesting though. Move your verification code to another method and try and reduce all that nesting. `$this->data != NULL` is the same as `!$thi...
[ { "body": "<p>Let me show my version of this code:</p>\n\n<p><code>DatabaseException.php</code>:</p>\n\n<pre><code>class DatabaseException extends Exception {\n}\n</code></pre>\n\n<p><code>Database.php</code>:</p>\n\n<pre><code>abstract class Database {\n protected $login;\n protected $password;\n prot...
{ "AcceptedAnswerId": "2397", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-13T02:18:07.537", "Id": "2395", "Score": "5", "Tags": [ "php", "php5", "object-oriented" ], "Title": "Learning OOP PHP, simple MySQL connection class." }
2395
<p>Here's some explanation for <code>accuracy</code> and <code>neg_accuracy</code>:</p> <p>It's meant to keep all the values in terms of what the user specified he wanted (how many decimal digits deep they want to go). <code>accuracy</code> is meant to cut the huge number returned by <code>GetTickCount()</code> to siz...
[]
[ { "body": "<p>Why are you using strings to command the class? They may be fast enough for your needs (since you're only using tick) but they are generally slow, and if you were to extend the class to support faster timing it could throw off your results. Consider using an enum or define to command the class:<...
{ "AcceptedAnswerId": "2401", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-13T04:47:48.983", "Id": "2398", "Score": "7", "Tags": [ "c++", "optimization", "timer" ], "Title": "Homemade Stopwatch class" }
2398
<p>I'm building a navigation that has a breadcrumb with drop down menus. I want the menus to open up when I click the open link, then there are many instances when the menu should close:</p> <ul> <li>The link is clicked a second time, with the intention of closing the menu</li> <li>When another menu is open, the first...
[]
[ { "body": "<p>The switch statement isn't needed.</p>\n\n<p>Just set a click function for each class.</p>\n\n<pre><code>$(document).ready(function ready () { \n $('.expandDropDown').click( handleBreadCrumbDropDownClick );\n $('.headlineTitle').click( handleAccordionItemClick );\n});\n\nfunction handleBr...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-13T13:39:00.583", "Id": "2400", "Score": "4", "Tags": [ "javascript", "jquery" ], "Title": "Handling click events to open and close menus depending on the click target" }
2400
<p>I have been working through the exercises in <a href="http://en.wikibooks.org/wiki/Write_Yourself_a_Scheme_in_48_Hours/Parsing">a Write Yourself a Scheme in 48 Hours/Parsing</a> and hacked together something to get parseString to comprehend escaped characters. Also had some inspiration from Real World Haskell chapte...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-14T14:31:37.643", "Id": "3804", "Score": "0", "body": "Is `\\/` really a valid escape sequence in scheme?" } ]
[ { "body": "<p>Some suggestions:</p>\n\n<ul>\n<li>Replace <code>fst</code> and <code>snd</code> with a pattern match or explicit function arguments.</li>\n<li>Extract the common <code>char '\\\\'</code> parser. You can then avoid the <code>try</code>.</li>\n<li>Strings with lots of escaped characters are hard to...
{ "AcceptedAnswerId": "2572", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-14T13:49:33.557", "Id": "2406", "Score": "15", "Tags": [ "haskell", "parsec" ], "Title": "Parsing strings with escaped characters using Parsec" }
2406
<p>Suppose you have a list of the diameters of some circular holes, and a list of the diameters of some cylindrical pegs. Now the problem is finding all the ways you can fit the pegs in the holes, where the order in which you put them in doesn't matter, and it's OK to put a peg in a hole that's too large.</p> <p>I've ...
[]
[ { "body": "<ol>\n<li>I recommend against using single letter variable names, in particular your use of p and h. \nI think the code is clearer if you use peg and hole. </li>\n<li>Your code is going to break if you have multiple holes or pegs of the same size.</li>\n<li>You'd be better off using tuples instead of...
{ "AcceptedAnswerId": "2408", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-14T15:47:54.207", "Id": "2407", "Score": "5", "Tags": [ "python", "optimization", "algorithm" ], "Title": "all the ways to fit some pegs into given holes" }
2407
<p>I have \$ N^2 \$ matrices. Each one is a \$ 3 \times 3 \$ matrix. I want to concatenation them to a \$ 3N \times 3N \$ matrix. I know that the big matrix is symmetric. Evaluation of whole \$ 3 \times 3 \$ matrices are time consuming so I want to speed up my program. </p> <p>Do you have any suggestion to speed it up...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-15T04:58:48.113", "Id": "3814", "Score": "0", "body": "A bigger [rv](http://dl.dropbox.com/u/21031944/Stack/rv_bigger.mat)" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-15T04:59:51.340", "Id": "3815",...
[ { "body": "<p>In my experience with finite element problems, I found that creating the large matrix <code>A</code> easily took as long, if not longer, than calculating the solution <code>x = A/b</code>. Matlab does a good job with that matrix inverse. </p>\n\n<p>In (old) FORTRAN creation of <code>A</code> is ...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-15T04:57:32.200", "Id": "2413", "Score": "4", "Tags": [ "matrix", "matlab" ], "Title": "Set of linear equations" }
2413
<p>Here's my function but it sometimes has unpredicted results with entering different numbers but with the same number of digits getting different results. I figure it has something to do with a computers inaccurate decimal saving tecnique but i would like to know how to make it more accurate.</p> <pre><code>////////...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-15T12:51:08.377", "Id": "3824", "Score": "2", "body": "For one, the formatting of that code looks awful. No room to breath. ;p" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-15T14:23:02.827", "Id": "38...
[ { "body": "<p>To get the number of whole numbers, <a href=\"https://stackoverflow.com/questions/554521/how-can-i-count-the-digits-in-an-integer-without-a-string-cast\">you can just use log10</a>.</p>\n\n<pre><code>int wholeNumbers = ( number == 0 ) ? 1 : (int)log10( abs( number ) ) + 1;\n</code></pre>\n\n<p>I i...
{ "AcceptedAnswerId": "2418", "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-15T06:59:56.147", "Id": "2414", "Score": "2", "Tags": [ "c++" ], "Title": "How can i make my Get_Numb_of_Digits_in_a_number() function more accurate?" }
2414
<p>This is a quick script I whipped up to collapse some folder trees down to individual folders. The specific situation that arose was my formerly-itunes collection (it's currently organized <code>Music\artist\album\songs.(mp3|m4a)</code> and I'd really prefer it to be <code>Music\artist\song.(mp3|m4a)</code>).</p> <p...
[]
[ { "body": "<pre><code>options={}\n# ...\nif not options[:types]\n options[:types] = [\"mp3\", \"m4a\"]\nend\n</code></pre>\n\n<p>I would initialize <code>options</code> with the default values first, instead of checking whether the option is set afterwards. I.e.</p>\n\n<pre><code>options = {:types =&gt; [\"mp3...
{ "AcceptedAnswerId": "2423", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-15T16:41:42.747", "Id": "2419", "Score": "5", "Tags": [ "ruby", "shell" ], "Title": "Collapsing Folder Trees with Ruby" }
2419
<blockquote> <p>Traverse a binary search tree in iterative inorder.</p> </blockquote> <p>Note that the iterative methods below contain the meat of the code; the remaining code is included for completeness.</p> <pre><code>// tree node struct node { int elem; node *left, *right; // Statically create a ...
[]
[ { "body": "<p>Your program looks okay for the most part and will probably work without any observable bugs. However there are a couple of problematic areas and sticky points you should address. I'll start with the most important first:</p>\n\n<ul>\n<li><p>Accessing data member of a struct after deletion:</p>\n\...
{ "AcceptedAnswerId": "2433", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-15T19:47:40.443", "Id": "2422", "Score": "4", "Tags": [ "c++", "tree" ], "Title": "Traversing a BST in iterative inorder" }
2422
<p>I am writing a simple raytracer just for fun. I want to iterate over rows, and each row must be an iterator over columns. A strategy I produced is the following:</p> <pre><code>class ViewPlane(object): def __init__(self, resolution, pixel_size, gamma): self.resolution = resolution self.pixel_siz...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-16T05:31:17.523", "Id": "3831", "Score": "0", "body": "This is from one who isn't seasoned... why `self.resolution = resolution` if `resolution` is already available to the whole class (among others)?" }, { "ContentLicense": "C...
[ { "body": "<pre><code>class Foo:\n def __iter__(self):\n def innergen():\n yield something\n return innergen()\n</code></pre>\n\n<p>Is the same as:</p>\n\n<pre><code>class Foo:\n def __iter__(self):\n yield something\n</code></pre>\n\n<p>In other words, there is no need to define the genera...
{ "AcceptedAnswerId": "2443", "CommentCount": "7", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-15T21:14:13.107", "Id": "2424", "Score": "6", "Tags": [ "python", "iterator", "raytracing" ], "Title": "Iterator over row and columns" }
2424
<p><strong>How can I improve this PHP MySql Rank generation function?</strong><br> <em>(Mostly looking to improve <strong>speed</strong>, but any feedback is very welcome)</em> </p> <p>Right now I keep <strong>stats</strong> and <strong>ranks</strong> in 2 separate tables. The only problem with this is I don't know...
[]
[ { "body": "<p>It seems like you're just ordering <code>player_stats</code> by some passed-in column and then going through numbering the result starting at 1. It might be simpler to forget storing explicit <code>rank</code> in your DB, and instead implement the numbering on the view layer.</p>\n", "comments...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-16T02:18:02.660", "Id": "2425", "Score": "4", "Tags": [ "php", "mysql", "pdo" ], "Title": "How can I improve this PHP MySql Rank generation function?" }
2425
<pre><code>private string FormatComments(string comments) { //If comments has no space and inserted as a single line then following code will break //the comments into multiple lines. StringBuilder sb = new StringBuilder(); int c = 65; int l = comments.Length; if (l &lt; ...
[]
[ { "body": "<p>Using a lower-case \"el\" as an identifier is a bad practice. It is easy to confuse it with the literal 1 in many fonts.</p>\n", "comments": [ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-18T17:16:37.307", "Id": "3915", "Score": "4", ...
{ "AcceptedAnswerId": "2445", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-16T05:25:00.733", "Id": "2426", "Score": "4", "Tags": [ "c#", ".net", "asp.net" ], "Title": "Comment formatter" }
2426
<p>I had to find the corresponding process for a windows service the other day, and I kept on getting this one exception. I've spent some time researching the exception only to find that this exception will occur if the process is terminating, Hence my question, is it really that bad to catch expected exceptions ?</p> ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-16T20:38:12.497", "Id": "3866", "Score": "1", "body": "and who told you it was bad to catch expected exceptions? If you didn't expect the exception, how are you supposed to catch it?" } ]
[ { "body": "<p>Sometimes they are hard to avoid, as in your example. I would consider it bad practice only in cases where the exception is easy to avoid (e.g. by testing the sign before calculating the square root).</p>\n", "comments": [], "meta_data": { "CommentCount": "0", "ContentLicense":...
{ "AcceptedAnswerId": "2440", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-16T07:59:55.437", "Id": "2429", "Score": "9", "Tags": [ "c#" ], "Title": "Is catching 'expected' exceptions that bad?" }
2429
<p>This is an emulator I am currently re-writing for my Operating Systems course. It is a simple emulator that is supposed to represent hardware, OS, etc. It is strictly for learning purposes and I want to propose my solution to the teacher as a method of modern C++ (since his solution is more "C with classes"). </p> ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-16T16:51:59.923", "Id": "97025", "Score": "0", "body": "[Boost.Signal](http://www.boost.org/doc/libs/1_46_0/doc/html/signals.html)\nalso provides good tools for implementing callbacks." } ]
[ { "body": "<p>That's not what friends are for. Friends are for tightly integrated classes which need to be able to play with each other's private data. OS and Hardware are not tightly related; they interact through a specifically designed interface.</p>\n\n<p>If you don't want other classes besides OS to call t...
{ "AcceptedAnswerId": "2438", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-16T13:50:43.757", "Id": "2437", "Score": "10", "Tags": [ "c++", "boost" ], "Title": "Emulator for representing hardware and operating systems" }
2437
<p>Before I tried to <a href="http://www.mssqlcity.com/Tips/tipCursor.htm" rel="nofollow">avoid using cursor</a> because of performance issues. But now I have to do some calculations to reach some goals. I have a stored procedure that has a code like this:</p> <pre><code>DECLARE Outer_Cursor CURSOR FOR... OPEN Ou...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-01T18:05:24.053", "Id": "4302", "Score": "2", "body": "it might be easier for someone to give you an answer if you actually post what is going into the cursors" } ]
[ { "body": "<p>If the inner cursor can be run through one time, create a table variable and store the results there to be re-used before working within the outer cursor.</p>\n\n<p>And as far as calculations go, is it possible to do away with the cursors by using common table expressions?</p>\n", "comments": ...
{ "AcceptedAnswerId": "6877", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-16T14:54:34.400", "Id": "2439", "Score": "4", "Tags": [ "performance", "sql", "sql-server" ], "Title": "Inner cursor performance issues" }
2439
<p>I need to implement a TCP client application. The client and the server send messages to each other. I want to make this program scalable enough to handle connections to multiple servers at the same time. It seems like asynchronous sockets is the way to go for this. I'm new to C# so I'm pretty sure I don't know what...
[]
[ { "body": "<p><H2>Thread safety stuff.</H2></p>\n\n<p><H3>Raising events</H3></p>\n\n<p>This is not thread safe:</p>\n\n<pre><code>if (SetLiveStatusEvent != null)\n{\n SetLiveStatusEvent(this, new SetLiveStatusEventArgs(hostname, message));\n}\n</code></pre>\n\n<p>The value of SetLiveStatusEvent could change...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-16T18:36:16.597", "Id": "2444", "Score": "6", "Tags": [ "c#", "multithreading", "asynchronous", "socket" ], "Title": "Asynchronous Sockets" }
2444
<p>I need some thoughts about an approach a colleague and I am are taking with Entity Framework. Basically, the entities are represented by contracts. These contracts hold a collection of business rules so when they are finally persisted we know they are valid. We can also check the validity from Entity Framework, but ...
[]
[ { "body": "<p>your <code>IUserContract</code> inherits <code>IEntityContract</code> but doesn't implement the <code>bool IsValid();</code> method, I always assumed that if you inherit an interface that you have to implement everything inside that interface.</p>\n<p>that is the only thing that I can see that lo...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-17T00:46:25.067", "Id": "2448", "Score": "15", "Tags": [ "c#", "entity-framework" ], "Title": "Constructing a Data Contract interface that can be used with Entity Framework 4.1 to ensure...
2448
<p>After solving the error in SO (like suggested) I return now for codereview. :-)</p> <p>The task is to parse a huge file <code>dblp.xml</code> (~800 MB) presented by <a href="http://dblp.uni-trier.de/xml/">DBLP</a>. The records in this huge file do look for example like <a href="http://dblp.uni-trier.de/rec/bibtex/j...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-17T12:35:14.083", "Id": "3873", "Score": "0", "body": "Since you are getting an error (million author record), isn't this material for SO?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-17T13:58:06.477", ...
[ { "body": "<p>The name fast_iter2 seems to lack much of a connection with the function is actually doing.</p>\n\n<p>Rather then having your two sets be local variables, I suggest putting them as global constants.</p>\n\n<p>Calling them elements and childElements is kinda generic. I suggest something more specif...
{ "AcceptedAnswerId": "2454", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-17T07:18:26.023", "Id": "2449", "Score": "7", "Tags": [ "python", "xml" ], "Title": "Parsing huge xml file with lxml.etree.iterparse in python" }
2449
<p>Can i refactor these code ? </p> <p>The diffrent between these block of code are.</p> <ol> <li>They are using different casting type.</li> <li><p>They call different property </p> <pre><code> var objBillOfMaterialRow = (MISheetDataSet.BillOfMaterialRow)pObjDataset.Tables["BillOfMaterial"].Rows[0]; if (objB...
[]
[ { "body": "<p>This should work if you don't want to change anything in your classes: </p>\n\n<pre><code>var rows = new Dictionary&lt;string, Func&lt;DataRow, ShowReport&gt;&gt;\n {\n {\"BillOfMaterial\", dr =&gt; ((MISheetDataSet.BillOfMaterialRow)dr).mi1_BillOfMaterial},\n {\"LayerBuil...
{ "AcceptedAnswerId": "2451", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-17T09:51:07.887", "Id": "2450", "Score": "2", "Tags": [ "c#" ], "Title": "Is Refactoring with different class casting and property calling possible ?" }
2450
<p>I often use C API's in C++ that force me to use C-style arrays. I got sick of constantly using a dynamic vector with <code>&amp;vec[0]</code>, so I wrote this C-style array container. Please review and give suggestions.</p> <p>I also have one question: is my implementation of <code>swap</code> correct? My biggest w...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-18T09:39:50.493", "Id": "3893", "Score": "1", "body": "I will take my stab at this design in a second, but wasn't boost::Array an option for you?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-18T10:20:53....
[ { "body": "<p>Alright, I made a couple of minor changes:</p>\n\n<ol>\n<li><p>Changed ctor to use initialization list:</p>\n\n<pre><code>Carray(size_type size) \n: elements(size), data(allocator.allocate(size))\n{ }\n\nCarray(size_type size, const_reference newobj) \n: elements(size), data(allocator.allocate...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-17T20:55:23.263", "Id": "2455", "Score": "8", "Tags": [ "c++", "c", "classes", "array" ], "Title": "C-style array class" }
2455
<p><a href="https://en.wikipedia.org/wiki/C_%28programming_language%29" rel="nofollow noreferrer">C</a> (pronounced "See", like the letter C) is a general-purpose computer programming language developed between 1969 and 1973 by <a href="http://cm.bell-labs.com/who/dmr/" rel="nofollow noreferrer">Dennis Ritchie</a> at t...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-17T21:42:00.087", "Id": "2456", "Score": "0", "Tags": null, "Title": null }
2456
C is a general-purpose computer programming language used for operating systems, games, and other high performance work and is clearly distinct from C++. It was developed in 1972 by Dennis Ritchie for use with the Unix operating system.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-17T21:42:00.087", "Id": "2457", "Score": "0", "Tags": null, "Title": null }
2457
<p>This program converts Brainfuck source code to C and compiles it with gcc. It runs very well (that was my first time I played <a href="http://jonripley.com/i-fiction/games/LostKingdomBF.html">Lost Kingdom</a>), however, the code is quite long because some parts are repeated.</p> <p>Is there a way to reduce the code...
[]
[ { "body": "<ol>\n<li>Don't put everything in a giant main function, that just makes it hard to follow</li>\n<li>Print error message, such as usage information to stderr</li>\n<li>You have argc (argument <strong>count</strong>) and argv (argument <strong>vector</strong>) backwards</li>\n<li>You don't free anythi...
{ "AcceptedAnswerId": "2459", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-17T22:52:26.377", "Id": "2458", "Score": "14", "Tags": [ "c", "converting", "brainfuck" ], "Title": "Brainfuck to C converter" }
2458
<p>I have written the following code that tests if the current time is within a time window. It seems to work ok with my test cases, but I would be interested if anyone can see any possible problems or has any ideas for improvements?</p> <pre><code>Public Function IsCurrentTimeBetween(ByRef dteStartTime As DateTime, B...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-23T14:32:11.017", "Id": "4036", "Score": "0", "body": "Are you implying a date component to your times? e.g IF it is 00:01 on Jan 2 you are asking if that time is between 23:55 on Jan 1 and 00:15 on Jan 2." }, { "ContentLicens...
[ { "body": "<p>A couple of quick things:</p>\n\n<p>You are passing in the parameters by reference unnecessarily. This method of passing is useful if you need to make modifications to variables that are observed at the callsite, but it should otherwise be avoided, as it could introduce a bug that may be more diff...
{ "AcceptedAnswerId": "2480", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-18T08:49:14.603", "Id": "2460", "Score": "6", "Tags": [ ".net", "vb.net" ], "Title": "Function to test if the current time is within a time window" }
2460
<p>This works:</p> <pre><code>$('#ShowAll').click(function() { if ($(this).prop('checked')) { $('tr.hidden').show(); // todo: There's probably some clever toggle that could be used here. } else { $('tr.hidden').hide(); } }); </code></pre> <p>Is there a one-liner I can be doing instead? Whe...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-18T13:59:03.683", "Id": "3906", "Score": "1", "body": "$('tr.hidden').setHidden(!!$(this).prop('checked')); // or just look for generic method that toggles visibility. Like set css property or something" } ]
[ { "body": "<p><a href=\"http://api.jquery.com/toggle/\"><code>.toggle()</code></a> exists and seems to do exactly what you want here.</p>\n", "comments": [], "meta_data": { "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-18T16:50:47.270", "Id": "24...
{ "AcceptedAnswerId": "2471", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-18T13:51:08.627", "Id": "2465", "Score": "1", "Tags": [ "javascript", "jquery" ], "Title": "Hidden rows toggle" }
2465
<p>I'm still pretty new to Ruby, and am really enjoying the language. I came across this method in my code base and realized that it could be cleaned up:</p> <pre><code>def friend_all_followers(friends) client.followers.each do |follower| if not friends.include?(follower.screen_name) friend = Friend.new(:s...
[]
[ { "body": "<p>You can replace</p>\n\n<pre><code>friend = Friend.new(:screen_name =&gt; follower.screen_name)\nclient.friendship_create(friend.screen_name, true)\nfriend.save\n</code></pre>\n\n<p>With</p>\n\n<pre><code>friend = Friend.create(:screen_name =&gt; follower.screen_name)\nclient.friendship_create(frie...
{ "AcceptedAnswerId": "2468", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-18T14:24:34.490", "Id": "2467", "Score": "4", "Tags": [ "ruby" ], "Title": "Simplification of loop in Ruby" }
2467
<p>From <a href="http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-20.html" rel="nofollow">SICP</a>:</p> <blockquote> <p><strong>Exercise 3.8</strong></p> <p>When we defined the evaluation model in section 1.1.3, we said that the first step in evaluating an expression is to evaluate its subexpression...
[]
[ { "body": "<p>Your code returns 1/2 if the <code>(f 0)</code> is evaluated first, not 0. A better way would be to return the last argument to <code>f</code>, with a default of 0.</p>\n\n<pre><code>(define last 0)\n(define (f x)\n (define temporary last)\n (set! last x)\n temporary\n)\n</code></pre>\n\n<p>Whe...
{ "AcceptedAnswerId": "2488", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-19T03:28:53.623", "Id": "2476", "Score": "2", "Tags": [ "lisp", "scheme", "sicp" ], "Title": "Order of evaluation of function arguments" }
2476
<p>I have a function that is suppose to store variables based on their datatype, and this is table I have come up with to store those variables into.</p> <p>Is it smarter to have everything broken down like this or would be wiser to only have columns for the largest for the largest datatype of a group (such as string ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-19T16:56:16.330", "Id": "3922", "Score": "0", "body": "Can you explain more about the example that motivated this? Normally, when you store data in a database, you know what type you are working with and write the schema accordingly. I...
[ { "body": "<p>I would probably tackle it like this:</p>\n\n<ol>\n<li><p>The database would have a few columns:</p>\n\n<ul>\n<li><code>id</code></li>\n<li><code>label</code></li>\n<li><code>data</code> (of some type, say, <code>varchar</code> for now)</li>\n</ul></li>\n<li><p>The <code>Wrapper</code> class would...
{ "AcceptedAnswerId": "2495", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-19T13:38:34.820", "Id": "2477", "Score": "3", "Tags": [ "sql", "mysql" ], "Title": "Maintaining a column for each datatype" }
2477
<p>I've got a couple of utility functions to support memoization for functions with anywhere between 0 to 8 arguments:</p> <pre><code>Public Shared Function Mize(Of TResult)(ByVal input_f As System.Func(Of TResult)) As System.Func(Of TResult) Dim is_new = True Dim result As TResult Return Function() ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-19T15:12:53.660", "Id": "3958", "Score": "0", "body": "@Pacerier: Next time please say it only one time and use a list of names. ;) Also, would you now be so kindly and press the Delete-Button?" }, { "ContentLicense": "CC BY-SA...
[ { "body": "<p>Unless you want to go with another approach, like code injection (see Anton's comment), you're pretty much stuck with this. I agree it is ugly and repetitive. Basically you've run up against the edges of the type system. Type parameters are a little like method parameters, and type arguments are a...
{ "AcceptedAnswerId": "2509", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-19T14:59:10.227", "Id": "2478", "Score": "12", "Tags": [ "design-patterns", ".net", "vb.net", "memoization" ], "Title": "Utility functions for supporting memoization for functi...
2478
<p>I have this set of legacy C++ projects with a large number of public functions. At the start, none of those publicly exposed functions had <code>try..catch</code> insulation inside them. When a C++ exception fired across that boundary, if the caller wasn't compiled with the same C++ compiler and the same project s...
[]
[ { "body": "<p>Well, there's a way of doing it with template functions, but I don't think I like it any more than your solution:</p>\n\n<pre><code>#include &lt;iostream&gt;\n\nusing namespace std;\n\ntemplate&lt;typename P, typename Q, typename Ret&gt;\nRet handle_all( Ret(*fn)(P, Q), P p, Q q) {\n try {\n ...
{ "AcceptedAnswerId": "2517", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-19T16:57:22.787", "Id": "2484", "Score": "18", "Tags": [ "c++", "error-handling", "exception", "macros", "poco-libraries" ], "Title": "Generic C++ exception catch handler m...
2484
<p>This is exercise 5-4 from <em>K&amp;R</em>. I spent hours tweaking it but now it seems to work. I'm new to pointers and I'd welcome any comments about how to do it better.</p> <pre><code>/* Function strend(s, t), which returns 1 if the string t * occurs at the end of string s and zero otherwise */ int strend(co...
[]
[ { "body": "<p>Const correct the pointers. The function is not changing anything in memory, no reason they shouldn't be <code>const</code>. Same with variables you declare in the function; Make them <code>const</code></p>\n\n<pre><code>int strend(const char* s, const char* t)\n</code></pre>\n\n<p>Check for NULL ...
{ "AcceptedAnswerId": "2491", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-19T20:30:56.087", "Id": "2489", "Score": "7", "Tags": [ "c", "strings", "pointers" ], "Title": "Determining if one string occurs at the end of another" }
2489
<p>I would like to efficiently import real numbers stored in CSV format into an array. Is there a way to modify my code to make it faster? Also, is there a way to scan the file and compute the number of rows and columns rather than having to provide these directly?</p> <pre><code>double * getcsv(string fname, int m,...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-19T20:57:49.177", "Id": "3932", "Score": "0", "body": "I am not sure how to do the formatting to indicate my code. If someone knows how, I will fix this quickly." } ]
[ { "body": "<ul>\n<li>In C++, we usually avoid <code>malloc</code> - in this case, you could use a <code>std::vector&lt; double &gt;</code> in stead. Doing this, you will allow the user of your code to use RAII in stead of manually managing the allocated memory. You cal tell the vector how much to allocate by in...
{ "AcceptedAnswerId": "2493", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-19T20:57:08.133", "Id": "2490", "Score": "2", "Tags": [ "c++", "csv" ], "Title": "Fast import of numbers stored in a CSV file" }
2490
<p>Today, I came across a code example like the following:</p> <pre><code>Option Explicit Sub MySub() Dim iCount As Integer For iCount = 0 To 100 Debug.Print "Arbitrary Code Here" If iCount Mod 2 = 0 Then Dim myString As String 'This is the line I'm curious about myS...
[]
[ { "body": "<p>It is bad programming practice to declare a variable in a loop, when it's only going to be re-used in the loop, even if in VB it won't be re-initialized every time.</p>\n\n<p>A good link on declarations in VB is <a href=\"http://www.vb6.us/tutorials/vb6-variable-scope\" rel=\"nofollow\">here</a>.<...
{ "AcceptedAnswerId": "2518", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-20T01:14:31.587", "Id": "2496", "Score": "6", "Tags": [ "vb6", "vba" ], "Title": "Is it a bad programming practice to declare variable in a loop?" }
2496
<p>From <a href="http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-22.html" rel="nofollow">SICP</a>:</p> <p>For background, here is exercise 3.16:</p> <blockquote> <p><strong>Exercise 3.16</strong></p> <p>Ben Bitdiddle decides to write a procedure to count the number of pairs in any list structure. <c...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-20T03:01:13.143", "Id": "2497", "Score": "1", "Tags": [ "lisp", "scheme", "sicp" ], "Title": "Correctly count the number of pairs in an irregular list structure" }
2497
<p>From <a href="http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-22.html" rel="nofollow">SICP</a>:</p> <blockquote> <p>Exercise 3.18. Write a procedure that examines a list and determines whether it contains a cycle, that is, whether a program that tried to find the end of the list by taking successive...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-07T02:56:59.943", "Id": "13656", "Score": "0", "body": "Have you tried this on a cyclic list? I did, and it goes into an infinite loop." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-07T12:10:04.417", ...
[ { "body": "<p>I can not express it in Lisp, but the idea is as follows:</p>\n\n<p>use two pointers, at start point both to the list head. Then, increment one pointer by 1, and another by 2. If you detect two equal objects eventually, it means that list has a loop. In pseudo-code:</p>\n\n<pre><code>P0 = head;\nP...
{ "AcceptedAnswerId": "10065", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-20T04:02:02.663", "Id": "2499", "Score": "5", "Tags": [ "lisp", "scheme", "sicp" ], "Title": "Examine a list for cycles" }
2499
<p>From <a href="http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-22.html" rel="nofollow">SICP</a>:</p> <blockquote> <p>Exercise 3.22. Instead of representing a queue as a pair of pointers, we can build a queue as a procedure with local state. The local state will consist of pointers to the beginning ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-17T04:48:19.517", "Id": "66045", "Score": "1", "body": "Looking through your questions, you have a lot of titles that unnecessarily contain tags. You should only use titles to briefly describe what your program/method does." } ]
[ { "body": "<p>You did not provide implementations of the queue operations using this representation. In SICP this usually refers to syntactic sugar to make working with a data structure less awkward, e.g.</p>\n<pre><code>(define (queue-insert! q item)\n ((q 'insert!) item) )\n</code></pre>\n<p>Also I would p...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-20T07:06:19.157", "Id": "2501", "Score": "5", "Tags": [ "lisp", "scheme", "sicp" ], "Title": "Representing a queue as a procedure with local state" }
2501
<p>I'm trying to solve an <a href="http://code.google.com/codejam/contest/dashboard?c=32003#s=p0" rel="nofollow">old GCJ</a>. It's a very simple puzzle, but I'm trying to sharpen my Scala-fu.</p> <p>Basically, you're getting a list of triple <code>number srcLanguage dstLanguage</code>, where <code>number</code> is an ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-04T02:44:45.100", "Id": "4347", "Score": "0", "body": "Here is a similar quizzle (http://codegolf.stackexchange.com/questions/1620/arbitrary-base-conversion/2256#2256). It doesn't fit exactly your interface." } ]
[ { "body": "<ul>\n<li>You should definitely use <code>scala.io.Source</code> for File-IO</li>\n<li>I wouldn't consider String splitting a responsibility of a general-purpose class. This should be done in the main loop</li>\n<li>For tuples you can write map{ case (one,two) => ... }, which is often clearer than us...
{ "AcceptedAnswerId": "2505", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-20T07:41:11.970", "Id": "2502", "Score": "3", "Tags": [ "scala", "programming-challenge" ], "Title": "Alien Numbers - how Scala-ish is my solution?" }
2502
<h3>Introduction</h3> <p>The name LISP derives from "LISt Processing". It was originally created as a practical mathematical notation for computer programs. See <a href="http://en.wikipedia.org/wiki/Lisp_%28programming_language%29" rel="nofollow">wikipedia</a> for more information.</p> <h3>Hello World Program in Lisp...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-20T14:08:43.037", "Id": "2510", "Score": "0", "Tags": null, "Title": null }
2510
Lisp is a (family of) general purpose programming language(s), based on the lambda calculus, and with the ability to manipulate source code as a data structure.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-20T14:08:43.037", "Id": "2511", "Score": "0", "Tags": null, "Title": null }
2511
<p><a href="http://www.java.com/en/" rel="nofollow noreferrer" title="Java official Site">Java</a> is a high-level, platform-independent, object-oriented programming language and run-time environment. The Java language derives much of its syntax from <a href="/questions/tagged/c" class="post-tag" title="show questions ...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2011-05-20T14:12:10.057", "Id": "2512", "Score": "0", "Tags": null, "Title": null }
2512
Java (not to be confused with JavaScript) is a class-based, object-oriented, strongly typed, reflective language and run-time environment (JRE). Java programs are compiled to bytecode and run in a virtual machine (JVM) enabling a "write once, run anywhere" (WORA) methodology.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-20T14:12:10.057", "Id": "2513", "Score": "0", "Tags": null, "Title": null }
2513
<p>JavaScript is one of the most ubiquitous programming languages on the earth. It runs on virtually every OS, and a JS engine is included in virtually every mainstream web browser. Standalone JavaScript engines or interpreters are available as well, and there are also embedding frameworks used to allow JS in additiona...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-20T14:35:58.953", "Id": "2514", "Score": "0", "Tags": null, "Title": null }
2514