body
stringlengths
25
86.7k
comments
list
answers
list
meta_data
dict
question_id
stringlengths
1
6
<pre><code>$(document).ready(function() { $('#state-list, #major-list').hide(); $('#state').bind('click', function() { $('#state-list').toggle(); }); $('#major').bind('click', function() { $('#major-list').toggle(); }); }); </code></pre> <p>All links and lists will follow the naming convention of...
[]
[ { "body": "<pre><code> &lt;a href=\"#\" id=\"link\" class=\"linksToWatch\"&gt;Link&lt;/a&gt;\n &lt;div id=\"link-list\" class=\"listsToToggle\"&gt;\n\n $('.listsToToggle').hide();\n\n $('.linksToWatch').bind('click', function() {\n var id = $(this).attr('id');\n $('#' + id + '-list').toggle();\n });\n</code...
{ "AcceptedAnswerId": "10933", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-16T20:50:52.063", "Id": "10931", "Score": "1", "Tags": [ "javascript", "jquery" ], "Title": "need to refactor multiple toggle lists" }
10931
<p>I've written a quick little helper for event &amp; call debounce/throttling. Since I'm at home and none of my regular code review friends are on-line I figured I'd turn to the great folks here! Would love any feedback you might have.</p> <pre><code>/** * debounce * @param {integer} milliseconds This param indicat...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-26T19:46:58.670", "Id": "18015", "Score": "0", "body": "Honestly, you'd probably be better off just using [underscore.js](http://documentcloud.github.com/underscore/), rather than reinventing the wheel (unless you're doing it for fun)....
[ { "body": "<p>The key differences between a throttled function and a debounced function are that the throttled function can return a value because it is called synchronously and the debounced version cannot because it is used asynchronously.</p>\n\n<p>You have lost that on your throttle implementation. I would ...
{ "AcceptedAnswerId": "11144", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-16T21:05:27.880", "Id": "10932", "Score": "1", "Tags": [ "javascript" ], "Title": "limit.js Code Review" }
10932
<p>I have an HTML form being populated by a table of customer requests. The user reviews each request, sets an operation, and submits. The operation gets set into a post arg as follow</p> <pre><code>$postArray = array_keys($_POST); </code></pre> <p>[1]=>Keep [2]=>Reject [3]=>Reject [4]=>Ignore ["item id"]=>"operati...
[]
[ { "body": "<p>It looks like you may want to unset the 'item id' entry in your post array before you do the processing:</p>\n\n<p><code>unset($_POST['item id']);</code></p>\n\n<p>Then you can use foreach to loop over the key (idx) and value (operation).</p>\n\n<pre><code>foreach ($_POST as $idx =&gt; $operation)...
{ "AcceptedAnswerId": "10936", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-16T22:53:16.790", "Id": "10934", "Score": "0", "Tags": [ "php", "html" ], "Title": "Parsing unknown POST Args in PHP" }
10934
<p>I'm just writing my first PHP-Mysqli sample (think about a Wiki 0.0.1) and I would like to ask you if this example is <strong>secure</strong> or not or if there are any other <strong>problems/suggestions</strong> you might recommend?</p> <p>I would like to use <strong>prepared statements</strong> and <strong>not ca...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-17T00:33:32.913", "Id": "17391", "Score": "0", "body": "Don't print errors out so they are visible. 1) It has no meaning to a user (my mum has no idea what a connect failure is nor how to resolve the problem) and makes your site look b...
[ { "body": "<p>Yes, that looks good.</p>\n\n<p>Minor comment: Normally an id is an integer. Should it have been \"i\" in your bind_param?</p>\n\n<p><strong>Connection Details</strong></p>\n\n<p>First, I am not a security expert. However, I would recommend storing the connection details in a location that is n...
{ "AcceptedAnswerId": "10943", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-17T00:10:49.727", "Id": "10935", "Score": "1", "Tags": [ "php", "mysql", "security", "mysqli" ], "Title": "PHP-Mysqli example secure?" }
10935
<p>I wrote this program for the Google Code Jam problem, "Recycled numbers."</p> <p>It took around 2 and half minutes to solve the small input set on my dual core, 1GB RAM system. But for the large input set it took around 25 minutes(processor usage was 100% for those 25 mins) to solve the problem.</p> <p><strong>Pro...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-17T03:21:31.440", "Id": "17392", "Score": "0", "body": "Sometimes the biggest gains come from changing the logic. Are you sure that you want to keep the logic? You need more laziness with the help of http://docs.python.org/library/iter...
[ { "body": "<pre><code> f=open('C-large.in')\n</code></pre>\n\n<p>Don't sue single letter variable names, its really hard to read</p>\n\n<pre><code> noi=int(f.readline().rstrip('\\r\\n'))\n</code></pre>\n\n<p>Since the default is already to remove whitespace, why both with the <code>\\r\\n</code> parameter?<...
{ "AcceptedAnswerId": "10939", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-17T03:12:04.447", "Id": "10938", "Score": "2", "Tags": [ "python", "performance", "programming-challenge" ], "Title": "\"Recycled numbers\" challenge" }
10938
<p>Here are two ways for writing this sample code (one using multi-threading, one without using multi-threading) - The original code (friend wrote it) uses multi-threading. I would like to know which method is better, and was there a motivation for using multi-threading in this situation?</p> <p><strong>1) First way (...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2017-07-09T22:12:58.780", "Id": "320639", "Score": "0", "body": "As an aside, why are you using `Object` in your for-each loop? For that matter, why are you calling `toArray()`?" } ]
[ { "body": "<p>I'm only commenting the threading part of the code you posted and regarding those parts I would say that the multithreaded code is not correctly written. None of the data structures written to by the threads are thread safe and no locking mechanism for maintaining thread safety is in place.</p>\n\...
{ "AcceptedAnswerId": "10944", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-17T04:22:07.823", "Id": "10940", "Score": "2", "Tags": [ "java", "multithreading" ], "Title": "What's the motivation for multi-threading in this code?" }
10940
<p>To learn and practice coding in C++, I wrote an implementation of <a href="http://en.wikipedia.org/wiki/Kosaraju%27s_algorithm" rel="nofollow">Kosaraju's two-pass algorithm</a> for computing the strongly connected components in a directed graph, using depth-first search.</p> <p>This was my first time touching any C...
[]
[ { "body": "<p>Fair enough. Lazy but OK I suppose. Personally when using <code>using</code> like this I bind it to the tightest scope possible.</p>\n\n<pre><code>using std::vector;\nusing std::map;\nusing std::list;\nusing std::ifstream;\nusing std::cout;\nusing std::endl;\n</code></pre>\n\n<p>The idea of making...
{ "AcceptedAnswerId": "10946", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-17T04:43:31.557", "Id": "10942", "Score": "8", "Tags": [ "c++", "algorithm", "graph", "search" ], "Title": "Implementation of Kosaraju's algorithm for strongly connected compo...
10942
<p>The following code detects if the system is idling. It approaches the problem by using the <code>Robot</code> class to take a screenshot, waits for a while, and then takes another screenshot. It then compares screenshot 1 with screenshot 2. If a certain amount of change is detected, it presumes the system is idling...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-17T12:04:13.287", "Id": "17403", "Score": "0", "body": "If, for instance, a Flash animation is being played in foreground, it wouldn't be detected as idling." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-...
[ { "body": "<p>In</p>\n\n<pre><code> if (compareScreens(screenShot, screenShot2) &lt; threshHold) {\n idle = true;\n } else {\n idle = false;\n }\n</code></pre>\n\n<p>Isn't this better as </p>\n\n<pre><code> idle = compareScreens(screenShot, screenShot2) &lt; thr...
{ "AcceptedAnswerId": "10995", "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-17T09:48:15.453", "Id": "10952", "Score": "4", "Tags": [ "java" ], "Title": "Detecting if the system is idling" }
10952
<p>I have an abstract class implementing some concrete functionality for its child classes:</p> <pre><code>abstract class Function { def eval: Double = some_concrete_functionality_which_calls_fEval def simplify: Funcion = more_concrete_calling_fSimplify protected def fEval: Double protected def fSimplify: Fun...
[]
[ { "body": "<p>I think that it's more a matter of taste. If I were to come along behind you, I wouldn't have any particular problem with <code>fEval</code> and <code>fSimplify</code>.</p>\n\n<p>I'm not sure that I would like <code>concreteEval</code>.</p>\n\n<p>In my own code I tend to use <code>doEval</code>, b...
{ "AcceptedAnswerId": "10955", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-17T11:46:30.237", "Id": "10954", "Score": "1", "Tags": [ "scala" ], "Title": "Which name should I choose for private abstract functionality with a public proxy?" }
10954
<p>I'm an experienced developer myself but for a current project I am working on I have decided to hire some developers to develop a mobile app which requires some supporting web services (developed in PHP).</p> <p>I know myself that the code I have pasted below is worse than what I would expect a 5 year old to produc...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-15T09:21:22.730", "Id": "71752", "Score": "0", "body": "If this is the server code, I don't want to see the mobile code. I bet 5/2 that they misuse ssl in at least one way" } ]
[ { "body": "<h2>In order of badness.</h2>\n\n<ol>\n<li><strong>SQL injection</strong> (as you pointed out).</li>\n<li>Plaintext <strong>passwords</strong>, hold the salt. Obviosuly no investigation was done on how to deal with passwords.</li>\n<li><strong>mysql_*</strong> is <strike>softly deprecated</strike> n...
{ "AcceptedAnswerId": "10987", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-17T14:56:00.987", "Id": "10956", "Score": "2", "Tags": [ "php5", "authentication" ], "Title": "User login and signup system" }
10956
<p>I'm a big fan of David Allen's <a href="http://rads.stackoverflow.com/amzn/click/0142000280" rel="nofollow noreferrer">Getting Things Done</a>, but the myriad software tools and sites I've tried haven't impressed me that much. That's why I've decided to write my own.</p> <h2>The concept</h2> <p>This app (I don't h...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-18T01:55:50.060", "Id": "17429", "Score": "0", "body": "don't store plaintext passwords" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-18T02:00:06.467", "Id": "17430", "Score": "0", "body": "wh...
[ { "body": "<ul>\n<li>consider utf8 charset and collation for your international users</li>\n<li><p>maximum length of an email address is 320 characters</p></li>\n<li><p>maximum length of a phone number is 15 characters, plus 11 for extension (plus 1 for a separator if you want to go that way)</p></li>\n<li><p>y...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-17T17:05:37.190", "Id": "10958", "Score": "3", "Tags": [ "mysql", "sql" ], "Title": "Database design for an online organization tool" }
10958
<p>I've been building a coloring book for kids: <a href="http://coloringbook.core.ba.lightburncloud.com/" rel="nofollow">http://coloringbook.core.ba.lightburncloud.com/</a></p> <p>It's got to work on an iPad, so I decided to try out Raphaël JS. I want to try and make this as efficient as possible, and was wondering i...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-17T21:07:45.333", "Id": "17421", "Score": "0", "body": "please put the code inline in the question (as per the faq)" } ]
[ { "body": "<p>First of all, the best way to optimize any code is to run it through a profiler to find the bottlenecks.</p>\n\n<p>Assuming you've already done that, here are a couple <em>very</em> minor things:</p>\n\n<ol>\n<li><p>This code:</p>\n\n<pre><code>for(var i = 0; i &lt; array.length; i++){\n</code></p...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-17T19:05:47.810", "Id": "10959", "Score": "2", "Tags": [ "javascript", "jquery", "optimization", "svg", "raphael.js" ], "Title": "Optimize coloring book built with Raphaël a...
10959
<p>I've been working on a lightweight XML schema parser, and have what I think is a moderately clean solution (some parts helped out by previous questions I posted here) so far for obtaining all schema details, but would like any criticism at all that could help further improve this code.</p> <p>Below I have supplied ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-28T02:10:02.910", "Id": "18109", "Score": "0", "body": "You're kind of reinventing the wheel, IMO. Have you seen http://www.aaronsw.com/2002/xmltramp/ ?" } ]
[ { "body": "<p>Well, your code is amazing in that it proves you can handle the most commonly used 10% subset of XML Schema in a few dozen lines of code. But where are you planning to go with this? As you try to increase your coverage of XSD features, your design won't scale. Perhaps that doesn't matter - there's...
{ "AcceptedAnswerId": "10989", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-17T21:11:22.230", "Id": "10960", "Score": "3", "Tags": [ "python", "parsing", "xml", "xsd" ], "Title": "XML schema parser" }
10960
RaphaëlJS is a cross-browser JavaScript library that draws vector graphics for web sites. It uses SVG for most browsers and VML for older versions of Internet Explorer.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-17T21:32:39.297", "Id": "10963", "Score": "0", "Tags": null, "Title": null }
10963
<p>SVG is a platform for two-dimensional graphics. It has two parts: an XML-based file format and a programming API for graphical applications. Key features include shapes, text and embedded raster graphics, with many different painting styles. It supports scripting through languages such as ECMAScript and has comprehe...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-17T21:35:55.440", "Id": "10964", "Score": "0", "Tags": null, "Title": null }
10964
XML Schema Document (XSD) is a document written in the XML Schema language, typically containing the "xsd" XML namespace prefix and stored with the ".xsd" filename extension. It can be used to express a set of rules to which an XML document must conform in order to be considered 'valid' according to that schema.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-17T21:38:19.117", "Id": "10967", "Score": "0", "Tags": null, "Title": null }
10967
<p>A best practice is a method or technique that is generally considered to be superior to other methods in achieving the same result. In the context of Code Review, questions with the <a href="/questions/tagged/best-practice" class="post-tag" title="show questions tagged &#39;best-practice&#39;" rel="tag">best-practi...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-18T00:43:23.083", "Id": "10971", "Score": "0", "Tags": null, "Title": null }
10971
Best-practice questions generally involve a short excerpt of code with a question of general interest, usually focused more on maintainability concerns than the algorithm to solve the task at hand. Note that questions must include a real code excerpt and sufficient context for reviewers to make specific recommendations...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-18T00:43:23.083", "Id": "10972", "Score": "0", "Tags": null, "Title": null }
10972
<p>I've built this two classes for a Poker game on Android and I would appreciate some feedback on my code.</p> <p>Have no mercy. The harsher you are, the better.</p> <p>Feel free to add your number of WTFs/minute.</p> <p><strong>PokerHand.java</strong></p> <pre><code>package com.poker.util; import java.util.Arra...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-18T09:27:48.183", "Id": "17437", "Score": "1", "body": "No Royal Flush? :)" } ]
[ { "body": "<p>You could try drying it a little bit,</p>\n\n<pre><code>public init(Card c1, Card c2, Card c3, Card c4, Card c5) {\n cards = new Card[NUM_CARDS];\n this.cards[0] = c1;\n this.cards[1] = c2;\n this.cards[2] = c3;\n this.cards[3] = c4;\n this.cards[4] = c5;\n Arrays.sort(cards,C...
{ "AcceptedAnswerId": "10980", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-18T00:49:45.290", "Id": "10973", "Score": "8", "Tags": [ "java", "classes", "android", "playing-cards" ], "Title": "Poker game classes" }
10973
<p>I supplied the following code as an answer to <a href="https://stackoverflow.com/q/10207890/698590">this question on SO</a>, but I was wondering if there was a better way to write out all those array loops (i.e. perhaps using a Collection/Dictionary?) It seems clunky/cumbersome as-is.</p> <pre><code>Function Contai...
[]
[ { "body": "<p>This is the final result of what was done with this code, though the code pertaining to the root question remained unchanged.</p>\n\n<pre><code>Function ContainsWhatMonths(OriginalStartDate As String, _\n OriginalEndDate As String) As Variant\n\n Dim MonthSet As Variant\n Dim AryCounter A...
{ "AcceptedAnswerId": "13362", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-18T15:30:19.157", "Id": "10990", "Score": "3", "Tags": [ "array", "vba" ], "Title": "Looping through arrays in VBA" }
10990
<p>I'm having trouble accessing variables throughout multiple functions. For example, I need to use <em>userinput</em> throughout many other functions, but do not have access to it with my current code. I am pretty sure that I need to change the parameters of my functions, so that I can pass the value of those function...
[]
[ { "body": "<p>Your problem is completely unrelated to smart pointers.</p>\n\n<p>The keyword here is <strong>separation of concerns</strong>. You have a function (well, several of them) who try to do everything: create a prompt, control user input, convert a value, and output the result.</p>\n\n<p>This is bad. Y...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-18T19:51:53.927", "Id": "10993", "Score": "1", "Tags": [ "c++" ], "Title": "Temperature Conversion Program" }
10993
<p>I want to know why Java is accepted over Python when it comes to runtime. On performing the following Euler problem, Python takes up less lines and runs faster (Python ~0.05s, Java ~0.3s on my machine).</p> <p>Could I optimize this Java code in any way? The problem is here (<a href="http://projecteuler.net/problem=...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-19T04:07:00.150", "Id": "17479", "Score": "2", "body": "How exactly are you compiling your java code? Try deleting the pyc file and timing the Python piece twice in a row. Also, time the io-bound piece and the cpu-bound piece for Pytho...
[ { "body": "<p>So, what exactly do you want to know, what is your question? I do not think you have to refactor anything here. Maybe you can push the limits, but first read this (and you should know why java is choosen):</p>\n\n<ol>\n<li>Are you counting just the time of program execution (your code does not sho...
{ "AcceptedAnswerId": null, "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-19T03:24:20.513", "Id": "10997", "Score": "4", "Tags": [ "java", "python", "programming-challenge" ], "Title": "Python vs. Java Runtime on Euler 22 - Name Scores" }
10997
<p>I made a stack monad that lets one manipulate and control values on a stack.</p> <p>I want to know if it's correct (it seems correct), how to make it faster, and how I could detect stack overflows without carrying around the stack size and checking against it (I've heard about guard pages but I have no idea how I'd...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-05T19:57:19.303", "Id": "18459", "Score": "5", "body": "Did you tried out an implementation where the stack is just a plain list? Letting the runtime do the work for you is usually faster." }, { "ContentLicense": "CC BY-SA 3.0"...
[ { "body": "<p>This code is simply incorrect. It is even not a stack (because it lacks\n<code>pop</code> operation and it is impossible to implement it in a type-safe way).\nHere is an example:</p>\n\n<pre><code>runStack $ do\n newStackRef (5:: Int)\n newStackRef False\n newStackRef 'x'\n</code></pre>\n\n<p>a...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-19T05:13:59.110", "Id": "11000", "Score": "27", "Tags": [ "optimization", "performance", "haskell", "stack", "monads" ], "Title": "How can I make my stack monad faster?" }
11000
<p>This is my rspec integration test for user, it always breaks when my teammate change something, how do i improve this?</p> <pre><code>describe "Users" do before(:each) do populate_role end describe "GET /users/sign_in" do #it "should redirect to redirect to user sign in page for user that is not si...
[]
[ { "body": "<p>Your specs look OK (I have a few comments, but none that would address your main question of why your specs break when your teammates push code). I suspect the problem lies not with your code, but with the team - sounds like you're trying to test drive, and they're not on-board?</p>\n\n<p>If every...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-19T09:21:42.503", "Id": "11001", "Score": "0", "Tags": [ "ruby", "unit-testing", "ruby-on-rails", "rspec" ], "Title": "Rspec Request break when teammate pushes some changes" }
11001
<p>Explained what I'm doing in the comments:</p> <pre><code>class User { public $id; public $email; public $username; public $password; public $rep; public function __constructor($id, $email, $username, $password, $rep) { // Assign all 'required' fields for our object upon instantiation ...
[]
[ { "body": "<p><strong>No, this is not OO code.</strong></p>\n\n<p>You are missing some of the key parts of OO.</p>\n\n<h2>Data Hiding</h2>\n\n<p>All of the class properties are public. Use protected for id, email, username etc. This stops outsiders from modifying the object without your control. The object s...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-19T09:39:55.383", "Id": "11004", "Score": "5", "Tags": [ "php", "object-oriented" ], "Title": "User class design" }
11004
<p>I have the following query which works as it should, but I'd like to know how I can make it run faster.</p> <p>For <code>info</code>, tables <code>cl</code>, <code>jo</code> and <code>mi</code> all have column <code>ref</code> as the <code>auto_inc</code> <code>primary key</code> and <code>ID</code> as the main ide...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-19T13:43:08.060", "Id": "17500", "Score": "0", "body": "Have you tried selecting the MAX from each of three tables first then using those values in the where clause?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "...
[ { "body": "<p>Moving your subqueries to the <em>from</em> clause may improve performance. </p>\n\n<p>Additional indexes may help too. Add a clustered index on <em>ID</em> or (<em>ID, ref</em>) for tables <em>mi</em>, <em>jo</em> and <em>cl</em> to speed up the <em>group by</em> and <em>max</em> operations. You ...
{ "AcceptedAnswerId": "11167", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-19T09:58:06.017", "Id": "11005", "Score": "0", "Tags": [ "sql", "mysql", "join" ], "Title": "Make a MySQL SELECT and INNER JOIN faster" }
11005
<p>I am implementing Dijkstra's Algorithm using Min Heap to speed up the code.</p> <p>For a small number of nodes, the code is really running very fast. But for a large number of nodes, my code is throwing <em>java.lang.OutOfMemoryError: Java heap space</em> exception. My Min heap implementation is based on the code, ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2015-07-21T13:45:09.173", "Id": "178596", "Score": "0", "body": "I was able to solve this question TSHPATH in spoj with your code... I think maybe you are not taking the Graph as a adjacency list... I am attaching the link to the code here: ht...
[ { "body": "<p>The only memory that you are allocating is the four arrays: <code>data</code>, <code>index</code>, <code>cost</code>, and <code>eval</code>. That means that if you are running out of memory then you probably need to allocate more memory. An array of primitives is just about as compact a structure ...
{ "AcceptedAnswerId": "82618", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-19T15:03:23.630", "Id": "11015", "Score": "5", "Tags": [ "java", "algorithm", "memory-management", "heap" ], "Title": "Min Heap implementation with Dijkstra's algorithm" }
11015
<p>I'm using VS 2008. I pass a <code>List&lt;T&gt; a</code> using <code>ref</code>, along with another <code>List&lt;T&gt; b</code>.</p> <p>I need to cycle thru <code>List&lt;T&gt; b</code>, which contains around 200,000 items, and for each item in <code>b</code>, it it matches criteria in <code>a</code>, which contai...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-19T16:01:46.193", "Id": "17504", "Score": "2", "body": "You are essentially doing a join and then an update. I suspect that this can be written shorter using LINQ over objects syntax. Let me try to look it up. It should not be hard to ...
[ { "body": "<p>Not knowing the full extent of the data types behind the <code>MatchA</code>, <code>MatchB</code> and <code>ToUpdate</code> properties, it'll be difficult to give an answer which completely solves your performance issues. However, one potential optimization could be realized in your <code>foreach<...
{ "AcceptedAnswerId": "11021", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-19T15:44:42.097", "Id": "11017", "Score": "2", "Tags": [ "c#", "performance" ], "Title": "Updating items of one List<t> that match another List<t>" }
11017
<p>Any improvements are welcome.</p> <p>a.bat</p> <pre><code>sed -r "s/private (.*) (.*);(.*)/&amp;\npublic \1 get\u\2(){return \2;}\npublic void set\u\2(\u\2){this.\2=\u\2;}\n/" "%~1"&gt;"%~2" </code></pre> <p>in:</p> <pre><code>private String firstName;// Stores firstName private String lastName; private String a...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-20T01:36:02.687", "Id": "17528", "Score": "2", "body": "Is this an exercise? Just because most IDEs do this out of the box. Otherwise I think it's an elegant solution :)" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate...
[ { "body": "<p><code>s/private (.*) (.*);(.*)</code>\nThis may be better done as <code>s/private ([^; ]+) +([^; ]+) *;(.*)$</code></p>\n\n<p>This avoids matching semicolon and space in the type and variable name.\n(Be as restrictive in your match as you can.)</p>\n", "comments": [], "meta_data": { ...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-20T01:11:29.050", "Id": "11024", "Score": "1", "Tags": [ "java", "regex", "sed" ], "Title": "Add getters and setters to a set of variables" }
11024
<p>I've a bunch of sequential activities. These are long running. Once an activity is complete, it can't be rolled back. Now something deep down the line fails. Now I've few options</p> <ol> <li>Report this to end user and ask him to fix something. And then Retry same thing.</li> <li>End user has no clue on what to do...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-19T19:56:12.090", "Id": "17563", "Score": "2", "body": "MS-DOS' most infamous error message. Infamous because no user could ever figure out what the proper response might be. There wasn't one :)" }, { "ContentLicense": "CC BY...
[ { "body": "<p>I would suggest that the outer routine should receive a <code>HandleError</code> delegate which is called when a problem is detected, before an exception is thrown by, or allowed to propagate beyond, anything but the lowest-level code. The code within that delegate can hopefully receive as parame...
{ "AcceptedAnswerId": "11034", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-19T19:46:51.100", "Id": "11032", "Score": "3", "Tags": [ "c#", ".net", "design-patterns", "exception-handling" ], "Title": "Is this right way to implement Abort, Retry and Ign...
11032
<p>I basically check for required input fields and if they fail to validate, I need to go to another level of output, check for other required fields, and so on...</p> <p>I can't get my head around this easy step-by-step validation. I already had it in a <code>while</code>-loop, but found it even more horrible than wi...
[]
[ { "body": "<p>Why do you only return a value if <code>$properties['step'] == 1</code>? If you could somehow change it so that both return, or both didn't need to, you could make it neater.</p>\n\n<pre><code>$req = array('cshort');\n$return = FALSE;\n\nif($properties['step'] == 1) {\n $req[] = 'cid';\n $re...
{ "AcceptedAnswerId": "11040", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-20T12:43:06.213", "Id": "11038", "Score": "1", "Tags": [ "php", "validation" ], "Title": "Validating required fields" }
11038
<p>In Framework Design guideline book there is a chapter about Exception and they talk about return-value-based error reporting and exception based error reporting and the fact that we in a O.O language like C# we should avoid return-value-based error reporting and use exceptions. With that in mind I was looking at our...
[]
[ { "body": "<p>Yes, the refactoring \"Replace error codes with exceptions\" work perfectly here.\nAs a first step you need to create an exception type that suits your need, something like</p>\n\n<pre><code>public class UpdateException : Exception\n{\n //your custom properties, fields etc.\n}\n</code></pre>\n\...
{ "AcceptedAnswerId": "11043", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-20T14:25:00.157", "Id": "11041", "Score": "0", "Tags": [ "c#", "exception", "error-handling" ], "Title": "uplifitng return value error reporting to Exception based error reporting...
11041
<p>I have an application that has multiple functions. Two in particular will query a remote computer using WMI, and return the installed printers in a datagridview. The other is a new method that will query the remote computer using WMI, and return information about the RAM.</p> <p>I don't want to repeat the code that...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-20T15:45:01.150", "Id": "17592", "Score": "2", "body": "Please run StyleCop on this first. You are not even following the right naming conventions ..." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-20T18:2...
[ { "body": "<p>First, please do what <a href=\"https://codereview.stackexchange.com/users/9778/leonid\">Leonid</a> mentions in his comment. The code is woefully out of standard convention for C# and .NET. Is this a Java port perhaps? Secondly, check your spelling in your comments. Nothing makes a developer wince...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-20T15:34:43.860", "Id": "11044", "Score": "3", "Tags": [ "c#", "winforms" ], "Title": "Query a remote computer using WMI, and return the installed printers in a datagridview" }
11044
<p>I have a class with some properties that I need to reflect over. One of the things I need, is a instance of a complex type returned for each of my properties, which means I can't just instantiate it directly in the attribute. </p> <p>Now, I have so far two ways to do this. Either I can write method-names, in string...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-20T16:42:14.963", "Id": "17599", "Score": "1", "body": "What is the underlying goal of this class? What purpose does the class serve? Do the properties need to be simple strings? You started with \"I have a class with properties I n...
[ { "body": "<p>I've done this several times with a typeof operator in the attribute. That's how MS does their Editor attribute. The only disadvantage is that you can't pass constructor attributes that way. In other words you have an attribute on your property like this:</p>\n\n<pre><code>[Widget(typeof(TextBoxWi...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-20T16:06:41.310", "Id": "11045", "Score": "2", "Tags": [ "c#", ".net" ], "Title": "Best way to relate methods with properties" }
11045
<p>I just completed <a href="https://projecteuler.net/problem=18" rel="nofollow">Project Euler</a> problem 18 which is a dynamic programming question through a graph of a triangle of numbers. The goal is to find the path from top to bottom of the triangle that has the largest sum.</p> <p>In the example below the path ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-20T20:45:21.663", "Id": "17612", "Score": "2", "body": "You can throw out a lot of code lad :) The array of arrays is already a tree (you do not need a graph). It is not uncommon to use an array as an underlying data structure for a tr...
[ { "body": "<p>I don't know about \"LINQ voodoo\", but you could do this in one pass if you reversed the order you're processing the rows. Something like this:</p>\n\n<pre><code> //build triangle graph \n var triangleGraph = new TriangleNode[triangleNumbers.Length][];\n\n for (int row = t...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-20T20:38:57.540", "Id": "11051", "Score": "1", "Tags": [ "c#", "programming-challenge" ], "Title": "Connect graph from 2D array" }
11051
<p>Working in C++ and I have some code which I'm refactoring. I have some code that needs to work with times of day but not dates. I do some juggling with <code>time_t</code> and <code>struct tm</code> but it's a pain and not intuitive to use. So I decided to make a basic time class with no date component. Let me k...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-20T21:05:07.143", "Id": "17615", "Score": "0", "body": "Why not call it TimeSpan which is the time span since last midnight. This has got to be a solved problem. For instance, see this document for inspiration http://msdn.microsoft.com...
[ { "body": "<p>Personally I would look at boost. They probably have something.</p>\n<h3>Comments:</h3>\n<pre><code>virtual ~TimeOnly();\n</code></pre>\n<p>Are you really going to derive from this class?</p>\n<h3>Implementation</h3>\n<pre><code>private:\n int hour_;\n int minute_;\n int second_;\n</code>...
{ "AcceptedAnswerId": "11053", "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-20T20:44:15.940", "Id": "11052", "Score": "6", "Tags": [ "c++", "datetime" ], "Title": "Time (only) class" }
11052
<p>So I have a little XML (Sub)language, it has 3 elements of interest: <code>para</code>, <code>point</code>, and <code>code</code></p> <p>If a <code>code</code> occurs inside a <code>para</code>, <code>point</code> element I want to handle it for inline use, if not, i want to set it up as it's own display section</p...
[]
[ { "body": "<p>It may not matter a lot for this case, but usually when dealing with XSLT our rule of thumb has been, always to handle different cases with different stylesheets rather than one huge complex XSLT.</p>\n", "comments": [], "meta_data": { "CommentCount": "0", "ContentLicense": "CC...
{ "AcceptedAnswerId": "14681", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-21T05:56:39.013", "Id": "11056", "Score": "1", "Tags": [ "xml", "template", "xslt" ], "Title": "Using Choose and Apply Templates with Mode, vs Complexless Template Matches" }
11056
<p>Just wanted a way of attaching a jQuery search plugin to an input element (or collection) and be able to pass specific options at invoke time:</p> <p>This is the plugin code</p> <pre><code>(function($){ $.fn.extend({ enableSearch:function(opts,callback){ return this .bind('focus',function(){ $(th...
[]
[ { "body": "<ol>\n<li>I find <code>$.ajax().promise().then(fn)</code> to be a little more confusing when looking at the code than it would have been if you instead used <code>$.ajax().complete(fn)</code> (or success if that is what you meant).</li>\n<li>I would throttle the ajax post so that it doesn't happen on...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-21T11:13:09.227", "Id": "11058", "Score": "1", "Tags": [ "javascript", "jquery", "plugin", "promise" ], "Title": "Simple jQuery search on input element" }
11058
<p>I'm aware standard delegate method declaration should include the object that triggers the method, usually of the class that declared the protocol.</p> <p>That's fine when the delegate method includes further arguments down the line, but what if it doesn't?</p> <p>Example:</p> <pre><code>@protocol MyObjectDelegat...
[]
[ { "body": "<p>This might indeed be confusing at first. The solution is to put the calling object as the only and last argument of the method. The second delegate method would then look like the one below.</p>\n\n<pre><code>- (void)myObjectDidPerformActionWithoutResult:(id)object;\n</code></pre>\n", "comment...
{ "AcceptedAnswerId": "11079", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-21T12:03:54.440", "Id": "11059", "Score": "2", "Tags": [ "objective-c", "ios" ], "Title": "Standard delegate methods" }
11059
<p>I have two types of session wrappers:</p> <p><strong>Type 1</strong></p> <pre><code>public class SessionHandler { public static SessionHandler CurrentSession { get { SessionHandler session = (SessionHandler)HttpContext.Current.Session[&quot;SessionId&quot;]; ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-21T14:38:35.550", "Id": "19169", "Score": "0", "body": "`Type 1` allows for inheritance, interface implementation and overall a better way to do unit testing. `static` classes should only be used when there is absolutely, positively, n...
[ { "body": "<p>Alternatively you might want to consider using enums that have string values attached to them. There is an article detailing how you can make <a href=\"http://www.codeproject.com/Articles/11130/String-Enumerations-in-C\" rel=\"nofollow\">that work with attributes</a>.</p>\n\n<p>That way you can de...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-13T09:32:07.020", "Id": "11060", "Score": "4", "Tags": [ "c#", "asp.net", "session" ], "Title": "Session Wrapper" }
11060
<p>This my first Python program and game. Can you please point how I can improve and what code should be changed?</p> <pre><code>import pygame from pygame import * import random import time import os import sys from pygame.locals import * black = (0,0,0) white = (255,255,255) pygame.init() def game(): os.environ...
[]
[ { "body": "<p>At the moment your game is one long \"noodle\" of code - I would split it into several... err... entities which represent separate activities - intro screen, the main game loop, high scores screen, settings screen, whatever. At their simplest they can be separate functions, but defining some class...
{ "AcceptedAnswerId": "11067", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-21T17:16:18.783", "Id": "11062", "Score": "3", "Tags": [ "python", "beginner", "game", "pygame" ], "Title": "A game called \"Twerk\"" }
11062
<p>I recently <a href="https://stackoverflow.com/a/10263759/908879">wrote a snippet</a> to make a custom <a href="https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/indexOf" rel="nofollow noreferrer">array.indexOf</a> but with nested array support in addition to allow using a nested array as nee...
[]
[ { "body": "<p>Here are some suggestions:</p>\n\n<p><code>fnd1 + \"\" == \"NaN\"</code> would be better as <code>isNaN(fnd1)</code>. It will also speed up your code by eliminating those concatenations.</p>\n\n<p>Using the <code>in</code> operator on a array is useless as it checks if the property exists. In the ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-22T04:33:25.837", "Id": "11070", "Score": "1", "Tags": [ "javascript", "optimization", "algorithm" ], "Title": "Snippet of custom array.indexOf that supports nested arrays" }
11070
<p>I create a simple feature tour sort of like what rdio and Facebook are doing. How can I make it better?</p> <pre><code>$(function () { $('a.close, a.closebtn').click(function () { $(".tour-block").hide(); }); $('a.tour-step-01').click(function () { $(".tour-block").hide(); $(".t...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-20T21:47:18.073", "Id": "17653", "Score": "0", "body": "Can you post html too?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-20T21:51:17.473", "Id": "17654", "Score": "0", "body": "We would ne...
[ { "body": "<p>If you could simplify your html, I would do something like this:</p>\n\n<pre><code>&lt;div class=\"tour-block\"&gt;\n &lt;h3&gt;Title Lorem Ipsum&lt;/h3&gt;\n &lt;p&gt;Content Lorem ipsum Content&lt;/p&gt;\n&lt;/div&gt;\n</code></pre>\n\n<p>(repeat this for each tour block on the site)</p>\n...
{ "AcceptedAnswerId": "11237", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-20T21:45:34.487", "Id": "11077", "Score": "4", "Tags": [ "javascript", "jquery", "html" ], "Title": "Script for simple feature tour" }
11077
<p><code>Shape</code> represents an abstract class and the other two classes inherits from it. This looks insufficiently abstract to me. How could I improve it?</p> <pre><code>import math class Point: def __init__(self,x,y): self.x = x self.y = y def move(self,x,y): self.x += x ...
[]
[ { "body": "<p>Your class Shape knows about what kind of shape it is (circle/square). This makes it tied to the two child classes. It should not know any thing about the composition. Rather just provide methods with empty implementations that can be overridden by child classes.</p>\n\n<p>The only thing I can see...
{ "AcceptedAnswerId": "11081", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-22T16:50:14.460", "Id": "11080", "Score": "3", "Tags": [ "python", "object-oriented", "python-2.x", "homework" ], "Title": "Abstractness of Shape class" }
11080
<p>I occasionally find myself bumping into code like this (either in other projects or banging out initial prototypes myself):</p> <pre><code> if @product.save if current_member.role == "admin" redirect_to krowd_path(@product) else redirect_to new_product_offer_path(@product) end else ren...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-22T18:50:52.250", "Id": "17657", "Score": "0", "body": "Use small functions that call each other and do not be afraid of multiple return points within one function." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2...
[ { "body": "<p>One suggestion is to make the roles two classes, initialize them based on the role and call the save function.</p>\n\n<pre><code> class UserRole\n def save(product)\n redirect_to new_product_offer_path(product) \n end\n end\n class AdminRole &lt; UserRole\n def save(product)\n red...
{ "AcceptedAnswerId": "11091", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-22T18:47:17.553", "Id": "11083", "Score": "2", "Tags": [ "ruby", "ruby-on-rails" ], "Title": "Avoiding nested if statements" }
11083
<p>This is the "Codebreaker" game in Ruby. Tell me what I can make better!</p> <pre><code>#!/usr/bin/env ruby class Sequence attr_accessor :guess, :code def initialize puts "Type the difficulty level you would like: 1, 2, 3, 4, or 5" begin @level = gets; @level = @level.to_i if @level &gt; 6 ...
[]
[ { "body": "<p>Interesting game :), and reasonable code. I only have a few suggestions.</p>\n\n<p>for</p>\n\n<pre><code> if @level &gt; 6\n raise \"Error\"\n end\n</code></pre>\n\n<p>and</p>\n\n<pre><code> if @code.length &gt; 5\n puts \"Invalid Difficulty!\"\n exit\n end\n</code...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-22T18:59:30.680", "Id": "11084", "Score": "3", "Tags": [ "ruby", "game" ], "Title": "Codebreaker game" }
11084
<p>So I spent a while this morning creating an xml parser in java which is part of a job interview. I would love to have some people tear it apart so I can learn from any mistakes that I made so I can grow for future job interviews.</p> <p>XML file:</p> <pre><code>&lt;Employees&gt; &lt;Employee&gt; &lt;N...
[]
[ { "body": "<p>Why do you have two different try blocks here? Why not join them?</p>\n\n<pre><code>do{\n try{\n String s = \"\";\n System.out.println(\"Enter the employee number that you're searching for: \");\n s = input.next(); \n try{\n i= Integer.parseInt(s); ...
{ "AcceptedAnswerId": "11115", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-22T19:44:43.150", "Id": "11085", "Score": "2", "Tags": [ "java", "xml", "parsing" ], "Title": "Parse an XML file using objects / methods" }
11085
<p>I have this Facebook class and I'm wondering if the OOP nature of it could be improved at all?</p> <p>(GitHub project <a href="https://github.com/benhowdle89/facebookInfo" rel="nofollow">here</a>):</p> <pre><code>&lt;?php class Facebook { private $baseUrl = 'https://graph.facebook.com/'; public function...
[]
[ { "body": "<p>This answer is in two sections. Firstly I am going to cover the <strong>Object Oriented</strong> nature of your solution and suggest possible architectural changes. Then I am going to look at your existing <strong>Code</strong> line by line for improvements.</p>\n\n<h2>Object Oriented</h2>\n\n<p...
{ "AcceptedAnswerId": "11100", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-23T00:30:24.690", "Id": "11092", "Score": "2", "Tags": [ "php", "object-oriented" ], "Title": "Could this PHP Facebook class be any more OOP-ified?" }
11092
<p>What is the best way to optimize this jQuery code?</p> <pre><code>$('#hde_test').hide(); $('#shw_test').click(function() { $('#shw_test').hide(); $('#hde_test').show(); $('.class1').show(); }); $('#hde_test').click(function() { $('#shw_test').show(); $('#hde_test').hide(); $('.class1').hid...
[]
[ { "body": "<p>You can use the <a href=\"http://api.jquery.com/toggle/\" rel=\"noreferrer\">.toggle() method</a> or <a href=\"http://api.jquery.com/toggleClass/\" rel=\"noreferrer\">.toggleClass() method</a> to toggle the objects visibility. That would let you do something like:</p>\n\n<pre><code>$('#show_toggle...
{ "AcceptedAnswerId": "11096", "CommentCount": "0", "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2010-03-07T17:59:52.400", "Id": "11094", "Score": "11", "Tags": [ "javascript", "jquery" ], "Title": "More elegant way to show | hide in jQuery" }
11094
<p>I have created a queue in javascript. This queue also has blocking <code>take()</code>. As you all probably know this is not really true, because javascript does not have threads. It just wait until element has been added to queue. You can view to source-code at <a href="https://gist.github.com/2467432" rel="nofollo...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2020-01-05T23:07:19.267", "Id": "460039", "Score": "0", "body": "PS: Your code does not actually work (`Array.prototype.shift` does not return a function). Also, starting a property name with `_` does not make it private." } ]
[ { "body": "<p>Personally the only issue I see with the code in terms of your constructor doing real work or testability is the instantiation of an <code>EventEmitter</code> object. Doing this in the constructor prevents you from mocking out or injecting a different class/instance for testing. You could use <a h...
{ "AcceptedAnswerId": "11139", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-22T23:46:45.497", "Id": "11098", "Score": "3", "Tags": [ "javascript", "unit-testing", "node.js" ], "Title": "my constructor is doing work. Is this a code smell in this example?" ...
11098
<p>Starting from a specific number of 1-element sets, I want to pair these sets together (forming 2-elements sets), then pair the paired sets with the original one-element sets (forming 3-elements sets), etc...</p> <p>For example, if I start with these 1-element sets:</p> <pre><code>{1}, {2}, {3}, {4} </code></pre> ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-23T04:40:49.303", "Id": "17667", "Score": "0", "body": "You want a power set, which can't be that hard. http://www.roseindia.net/tutorial/java/core/powerset.html You can then throw out the empty set. Essentially you can loop through {t...
[ { "body": "<p>Firstly, there is a bunch of general stuff that can be cleaned up here:</p>\n\n<pre><code> boolean addInteger(LinkedList&lt;Integer&gt; IntegerToBeAdded)\n</code></pre>\n\n<p>You aren't add Integers here. You are adding sets. You should pick better names</p>\n\n<pre><code> { \n Node st...
{ "AcceptedAnswerId": null, "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-23T04:06:53.837", "Id": "11099", "Score": "4", "Tags": [ "java" ], "Title": "Efficient form/pair sets from existing (1-element) sets" }
11099
<p>This is my code that implements Dijkstra's single source shortest path algorithm, which is called multiple times to recalculate after graph changes. the graph is a road system of a city and shortest path needs to be calculated when certain roads close one at a time.</p> <p>I am looking for advice on the following:<...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-23T05:40:06.777", "Id": "17670", "Score": "0", "body": "Why do you use typedef struct? That looks very odd in a c++ program. c++ does not have need for that construct because user defined data types can be used exactly the same way as ...
[ { "body": "<h3>Lets start with the explicit questions:</h3>\n\n<blockquote>\n <p>i am looking for advice on the following</p>\n \n <p>will this read better if it is object oriented?</p>\n</blockquote>\n\n<p>Most definitely. I have implemented this before; probably using less than a quarter of the lines of co...
{ "AcceptedAnswerId": "11102", "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-23T05:34:18.400", "Id": "11101", "Score": "5", "Tags": [ "c++", "beginner", "object-oriented", "homework" ], "Title": "Implementation of Dijkstra's shortest path algorithm" }
11101
<p>I have been working on a personal CMS for a site I've been running, and right now I'm working on a page that lists all entries, or posts from a database. I have given the user, with checkboxes and a drop down menu, the option to either delete or edit a post.</p> <pre><code> //query database $query = mysql_qu...
[]
[ { "body": "<p>I suppose it could be condensed a little, but overall, it's solid code. Consider using a ternary operator for your conditional echos:</p>\n\n<pre><code>echo count($_REQUEST['chkBox']) &gt; 1 ? \"&lt;p&gt;For now, please just select 1 post you would like to edit.&lt;/p&gt;\" : \"You will edit your ...
{ "AcceptedAnswerId": "11112", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-23T01:56:54.227", "Id": "11103", "Score": "2", "Tags": [ "php" ], "Title": "CMS for allowing users to delete or edit a post" }
11103
<p>I need to remove last text after <code>:</code> in my String and <code>:</code> too. I have tried this. Please review. If there is a better way to do, please tell me.</p> <pre><code>String test = "temp:content:region:deposit:up"; System.out.println(test.replace(test.substring(test.lastIndexOf(":"), test.length()), ...
[]
[ { "body": "<p>Using regexp (replace) isn't the best solution. I think you should use only substring:</p>\n\n<pre><code>System.out.println(test.substring(0, test.lastIndexOf(\":\")))\n</code></pre>\n", "comments": [], "meta_data": { "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", ...
{ "AcceptedAnswerId": "11111", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-23T09:19:44.913", "Id": "11107", "Score": "2", "Tags": [ "java", "strings" ], "Title": "Removing text after `:`, `:` included" }
11107
<p>I try to learn amd64 assembler. This is the first thing I tried. This piece of assembly should replicate the functionality of the following piece of C code, which turns a binary sha-256 hash into a human readable form.</p> <h3>assembly code</h3> <pre><code>1: .ascii "0123456789abcdef" .global show_hash show_h...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-10-22T23:42:16.977", "Id": "28370", "Score": "0", "body": "I don't think you can access data unless it's in the data segment." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-10-23T05:02:39.727", "Id": "28381"...
[ { "body": "<p>I'm not sure whether it's correct:</p>\n\n<ul>\n<li><strike>If <code>show_hash</code> uses <a href=\"http://en.wikipedia.org/wiki/X86_calling_conventions#cdecl\" rel=\"nofollow\">cdecl calling conventions</a> you should preserve registers like <code>%bl</code>, and read the input parameter values ...
{ "AcceptedAnswerId": "43622", "CommentCount": "7", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-23T10:46:55.513", "Id": "11110", "Score": "5", "Tags": [ "linux", "assembly", "lookup" ], "Title": "First steps with amd64 assembly" }
11110
<p>Is there a way to reduce this lengthy <code>if</code> condition:</p> <pre><code>if( statusCode.equals( NO_ERRORS_NO_WARNINGS ) || statusCode.equals( HAS_ERRORS_NO_WARNINGS ) || statusCode.equals( HAS_ERRORS_HAS_WARNINGS ) || statusCode.equals( NO_ERRORS_HAS_WARNINGS ) ){ //do something } </code...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-23T13:53:46.247", "Id": "17690", "Score": "0", "body": "I'm not sure you could. You might convert to an enum to use a switch statement, but that doesn't buy you much." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": ...
[ { "body": "<p>First of all, if <code>statusCode</code> can be null, the code above could possibly throw a null pointer exception.</p>\n\n<p>To directly answer your question though, you could use a Set, such as a HashSet.</p>\n\n<pre><code>HashSet&lt;String&gt; errorOrWarning = new HashSet&lt;String&gt;();\nerro...
{ "AcceptedAnswerId": "11114", "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-23T13:48:22.553", "Id": "11113", "Score": "9", "Tags": [ "java" ], "Title": "Reduce length of condition" }
11113
<p>I'm facing an interesting issue at the moment: </p> <p><strong>My Situation:</strong> </p> <p>I'm having (in Java) String-Arrays like the following (more complicated, of course). Each String-Array represents one sentence (I cant change the representation): </p> <pre><code>String[] tokens = {"This", "is", "just", ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-23T13:43:00.607", "Id": "17694", "Score": "0", "body": "You could do it more declaratively, that would make it less complex. Create a Set of tokens that have no WS in front and another Set of those with no WS after. Then you just check...
[ { "body": "<p>I'm not sure if you are allowed to leverage open source projects, but perhaps you could use something like <a href=\"http://java2s.com/Open-Source/Java/Natural-Language-Processing/OpenNLP/CatalogOpenNLP.htm\" rel=\"nofollow\" title=\"OpenNLP\">OpenNLP</a>. They have an interface <code>opennlp.too...
{ "AcceptedAnswerId": "11137", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-23T13:11:44.210", "Id": "11116", "Score": "5", "Tags": [ "java", "strings" ], "Title": "Build a sentence from tokens / words in a String-Array" }
11116
<p>I am implementing RSA algorithm in C++ and here's my design(code structure).</p> <p><code>keygen.h</code></p> <pre><code>namespace rsa{ class keygen{ public: //Constructor keygen(size); //Generate keys void generate(); //Getters char* gete(){ return xyz; ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-23T16:31:54.333", "Id": "17706", "Score": "0", "body": "I think you did not provide enough information - just a few lines of code. It's hard to say something interesting about this besides trivial things like \"it is better to use `Key...
[ { "body": "<p>Just a couple of short comments as a starting point.</p>\n\n<p>First of all, you don't need separate encrypt and decrypt functions -- the algorithm is identical for both. You just pass different parameters for them.</p>\n\n<p>Second, I wouldn't use <code>char const *</code> for the input or output...
{ "AcceptedAnswerId": "11123", "CommentCount": "7", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-23T15:50:08.530", "Id": "11120", "Score": "0", "Tags": [ "c++" ], "Title": "Implementing RSA in C++" }
11120
<p>I have a method that exacts data from an XML and returns an <code>IEnumerable&lt;Foo&gt;</code>. I am trying to create a method that will merge the results from 2 different XML's files into a single <code>IEnumerable</code> and remove any duplicate data that may be found </p> <p>A duplicate in this case is defined...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-23T17:34:37.843", "Id": "17712", "Score": "0", "body": "Can you implement `Equals()` (and preferably also `IEquatable<Foo>`) on `Foo`, to compare by `Name`?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-2...
[ { "body": "<p>With things like this, it's usually best to look at the documentation.</p>\n\n<p>Is your approach with <code>GroupBy()</code> going to work? <a href=\"http://msdn.microsoft.com/en-us/library/bb534501.aspx\" rel=\"noreferrer\">Yes</a>:</p>\n\n<blockquote>\n <p>Elements in a grouping are yielded in...
{ "AcceptedAnswerId": "11122", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-23T17:15:43.093", "Id": "11121", "Score": "7", "Tags": [ "c#", "linq" ], "Title": "Merging IEnumerable and removing duplicates" }
11121
<p>Ive written a script to loop through a couple of unparalleled arrays a loop within a loop, Now im trying to find out if using <code>break</code> is all that's needed to exit and then continue over again.</p> <p>What eles can you see or know to improve this?</p> <pre><code>var arr_vals = ["74","f4e3","22","r31","17...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-23T21:01:08.190", "Id": "17722", "Score": "0", "body": "`break` will break out of the inner loop but not the outer one, so it will continue with the next iteration of the outer loop. Is that what you're asking? Also, I think you mean `...
[ { "body": "<p>Instead of iterating through the inner array multiple times, it might be faster to create a map for the inner array beforehand and then test for a match within the map. (I think this will only work if they're arrays of strings, though.)</p>\n\n<pre><code>var arr_vals = [\"74\",\"f4e3\",\"22\",\"r3...
{ "AcceptedAnswerId": "11127", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-23T20:55:53.073", "Id": "11125", "Score": "1", "Tags": [ "javascript", "optimization" ], "Title": "Improving script performance for looping unparalleled arrays" }
11125
<p>I'm working on a show/hide div with checkbox on change and on load. I've come up with this so far:</p> <p><a href="http://jsfiddle.net/bK8EC/115/" rel="nofollow">jsFiddle</a></p> <pre><code>$(document).ready(function() { var $cbtextbook = $('#in-product_category-14'), $cbimod = $('#in-product_category-15'), ...
[]
[ { "body": "<p>It could be done with:</p>\n\n<pre><code>$(document).ready(function() {\n $(\"input\").change(function() {\n var index = $(this).closest(\"li\").index();\n $(\".metabox\").eq(index)[this.checked ? \"show\" : \"hide\"]();\n }).change();\n});​\n</code></pre>\n\n<p><a href=\"http:...
{ "AcceptedAnswerId": "11129", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-23T23:57:53.773", "Id": "11128", "Score": "1", "Tags": [ "javascript", "jquery" ], "Title": "Show/hide checkbox div on change and load" }
11128
<p>Carrying on from:</p> <ul> <li><a href="https://codereview.stackexchange.com/q/7536/507">Yet another C++ Json Parser</a></li> <li><a href="https://codereview.stackexchange.com/q/7567/507">Yet another C++ Json Parser (Recursive)</a></li> </ul> <p>All the code is available from git hub: <a href="https://github.com/L...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-24T12:41:21.767", "Id": "17735", "Score": "8", "body": "I strongly doubt that Loki would name something after Thor. Unless it was to ingratiate himself for some nefarious scheme." }, { "ContentLicense": "CC BY-SA 3.0", "Cre...
[ { "body": "<p>Before even trying to review this by nature incredible complex code I would comment on your {}-religion, code wrap, and vertical spacing.</p>\n\n<p>It is incredible personal what works best for you, me and others. Some of these comments might seem contradictory to each other, but some sacrifices m...
{ "AcceptedAnswerId": null, "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-24T11:31:18.157", "Id": "11138", "Score": "32", "Tags": [ "c++", "json", "template-meta-programming", "serialization" ], "Title": "JSON Serializer" }
11138
<p>I have a basic class that I'd like to get some feedback on. I'm refactoring some old code but the new code looks more complex. Basically I'm passing a list of included and excluded cultures into a function that should return if the current culture should be allowed. Exclusions win. Any advice how to better it woul...
[]
[ { "body": "<p>I would do it like this (WARNING - not tested):</p>\n\n<pre><code>public static void SampleUsage()\n{\n IsCurrentCultureIncluded(\"*\", \"*\", Thread.CurrentThread.CurrentCulture.Name);\n}\n\npublic static bool IsCurrentCultureIncluded(string includedCultures, string excludedCultures, string cu...
{ "AcceptedAnswerId": "11164", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-24T22:04:27.940", "Id": "11146", "Score": "1", "Tags": [ "c#" ], "Title": "Checking for culture in comma separated list, any suggestions?" }
11146
<p>Is this correct coding for prepared statements in php. I've done some reading but the best way to learn is criticism from peers. Any suggestions to improve this code? Anything I've done wrong? Thanks you!</p> <pre><code>$dbh = new PDO('mysql:host=localhost;dbname=tests;charset=UTF-8', $user, $pass); $stmt = $d...
[]
[ { "body": "<p>First off, if I were about to do something this repetitive, I would set it up so that I would only have to type it all once. Best way to do this is set up an array and run it through loops. Lets start with that array.</p>\n\n<pre><code>$bindValues = array(\n 'item_id' =&gt; '44',\n 'itemuni'...
{ "AcceptedAnswerId": "11157", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-24T22:41:24.067", "Id": "11147", "Score": "5", "Tags": [ "php", "mysql" ], "Title": "PHP prepared statements" }
11147
<p>I am using an external library named <code>enchant</code> here. My problem is that I guess my program is not returning all possible English words and is slow as well for large string input.</p> <p>I am using both <code>en_US</code> and <code>en_UK</code> here:</p> <pre><code>import enchant import itertools uk = en...
[]
[ { "body": "<p>As a general advice, you may want to organize your code into functions - say</p>\n\n<ul>\n<li>One function to receive user input and process it</li>\n<li>One function to generate all possible permutations for a string passed in less than a value (here 3).</li>\n<li>Another function to filter this ...
{ "AcceptedAnswerId": "11308", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-24T23:28:46.127", "Id": "11151", "Score": "1", "Tags": [ "python", "optimization", "algorithm", "performance" ], "Title": "Returning all possible English dictionary words that...
11151
<p>We implement a C++ class <code>Proposition</code> that represents a (possibly compound) propositional logic statement made up of named atomic variables combined with the operators AND, OR, NOT, IMPLIES and IFF.</p> <p>We then use it to find all the truth assignments of the following proposition:</p> <blockquote> ...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2019-11-11T13:43:31.743", "Id": "453245", "Score": "0", "body": "There are no reasons for this question to have close votes without a comment, it seems to be working and the context is perfectly clear." } ]
[]
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2012-04-25T01:13:01.590", "Id": "11154", "Score": "4", "Tags": [ "c++", "c++11" ], "Title": "Propositional Logic: Proposition Evaluator" }
11154
<p>I have written a helper method which computes the sum of values in some custom grid, given the column indexes. The method appears to work (for a decimal - as Anthony pointed out, I need to test this further), but I am not at ease with the following conversions:</p> <pre><code>decimal valIfNull = (decimal)(object)va...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-25T01:27:43.053", "Id": "17777", "Score": "2", "body": "Your method is not going to work if `T` is not `decimal`. When you box a value type, you can only unbox to the same type (or its nullable counterpart). For example, given `long L ...
[ { "body": "<p>You've already placed a constraint on the first parameter that it should be <code>IConvertible</code>, so the methods of that interface is available to you.</p>\n\n<pre><code>decimal decimalValueIfNull = valueIfNull.ToDecimal(CultureInfo.InvariantCulture);\n</code></pre>\n\n<p>Converting back to t...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-25T01:20:35.810", "Id": "11156", "Score": "3", "Tags": [ "c#", "casting" ], "Title": "Computing value sums in a custom grid" }
11156
<p>I come from a Java background so my desire for proper unambiguous logging is strong. I prefer using the console to using some other gui widget however, in the browser I know that I can't always count on the console to exist or for it to have all the levels I might like. To remedy this I worked up the following conso...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-25T04:32:04.743", "Id": "17791", "Score": "0", "body": "I think I saw a really good discussion of this exact problem. Perhaps on StackExchange - did you check there?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "...
[ { "body": "<p>I don't see any problems with that. It's similar to <a href=\"https://stackoverflow.com/a/3265752/1100355\">this answer on SO</a>.</p>\n\n<p>Just a couple minor things:</p>\n\n<ul>\n<li><p>You don't need <code>args</code> in the empty <code>log</code> function</p></li>\n<li><p>You should make the ...
{ "AcceptedAnswerId": "11168", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-25T04:28:52.563", "Id": "11159", "Score": "1", "Tags": [ "javascript" ], "Title": "Safely using console.* in browser" }
11159
<p>I've been working some forth looking on design patterns, and I would like some help to improve the code (fixes, tips, just generally improvements, or things you consider bad practise, etcetera in my code).</p> <p>And finally: Am I on the right track, or should just back the wheel and start over?</p> <p>UserMapper...
[]
[ { "body": "<p>There's no verification that the sql was executed correctly in your <code>UserMapper::save</code> method. It just assumes that everything went ok after <code>execute</code> (actually all your <code>execute</code> calls go un-checked). Always verify your results. You should at the very least be wra...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-25T11:55:14.380", "Id": "11163", "Score": "0", "Tags": [ "php", "sql", "pdo" ], "Title": "User lib php v2" }
11163
<p>The following code is part a class called <code>class db_tables</code>. All the other <code>getTbl*</code> methods other than <code>getTblHerd</code> pull information based on the ID of the animal that is passed to them.<BR></p> <p>My question is while the following code works would it be better to move all the oth...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-26T10:00:58.470", "Id": "17870", "Score": "0", "body": "Small note: [Classes in Java are normally in UpperCamelCase](http://www.oracle.com/technetwork/java/javase/documentation/codeconventions-141270.html#381), of course there are exce...
[ { "body": "<p>Well, Your code looks good, and your suspicion seems right. I would agree with you. My reasoning is that your objects should be modeled after the problem rather than the data base schema. Here I would say that the other <code>getTbl*</code> methods are actually getters on particular animals. So it...
{ "AcceptedAnswerId": "11166", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-25T14:09:01.010", "Id": "11165", "Score": "2", "Tags": [ "java" ], "Title": "Should I Move Methods To A Different Class" }
11165
<p>i do have two dimentional array of data in php. </p> <p>I do want to add another column with constant to that array for passing tabular data to next program.</p> <p>i am iterating and adding manually. What can be alternate code?</p> <p>my code:</p> <pre><code> if( is_array( $arrSource )){ ...
[]
[ { "body": "<p>I see nothing wrong with what you already have. Assuming of course that you meant to append identical data to each <code>$arrSource</code> element. You are already doing the shorthand by using the reference operator. The only other way would be to write it all out manually, which would be pointles...
{ "AcceptedAnswerId": "11173", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-25T18:01:35.730", "Id": "11171", "Score": "1", "Tags": [ "php", "array" ], "Title": "PHP Add Column to two dimentional array" }
11171
<p>I wanted a pattern to manage web.config appsettings. I want to be able to have a default setting if the config setting was missing. I also wanted the check for the value in the config file to happen only once, not each time the the value is retrieved.</p> <pre><code>Public NotInheritable Class ExternalReportRequest...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2016-05-15T13:58:51.980", "Id": "240117", "Score": "0", "body": "May I ask what lend you to wanting this? Typically, those settings are specifically for specifying defaults and configuration settings. I'm smelling an XY problem, but I don't ye...
[ { "body": "<p><code>Integer.TryParse</code> will overwrite the value of that shared property with 0 if the value is not there. Use something like this instead:</p>\n\n<pre><code>Shared Sub New()\n Dim parsed As Integer\n If Integer.TryParse(ConfigurationManager.AppSettings(\"ReportRequestMaxExecuteAttempt...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-26T00:11:43.817", "Id": "11180", "Score": "1", "Tags": [ "asp.net", "vb.net" ], "Title": "Managing web.config appSettings" }
11180
<p>How can I improve this code for counting the number of bits of a positive integer n in Python?</p> <pre><code>def bitcount(n): a = 1 while 1&lt;&lt;a &lt;= n: a &lt;&lt;= 1 s = 0 while a&gt;1: a &gt;&gt;= 1 if n &gt;= 1&lt;&lt;a: n &gt;&gt;= a s += a ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-26T00:53:23.950", "Id": "17849", "Score": "3", "body": "My silly question :): Cant you use `math.floor(math.log(number,2)) + 1`? Or do you mean the number of bits set?" } ]
[ { "body": "<p>The very first thing you should do to improve it is comment it. I'm reading it for almost half an hour and still can't understand what it does. I tested it, and it indeed work as intended, but I have no idea why. What algorithm are you using?</p>\n\n<p>I pointed below parts of the code that aren't...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-26T00:29:57.943", "Id": "11181", "Score": "5", "Tags": [ "python", "algorithm", "bitwise" ], "Title": "Counting the number of bits of a positive integer" }
11181
<p>This is an alphabetical navigation which shows only the letter that have posts in both that letter and the currently filtered "genero" taxonomy term.</p> <p>I use multiple taxonomy queries to find "artistas" posts that, for example, are tagged as both "rock" and "funk".</p> <p>The function works perfectly and outp...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-25T11:31:00.553", "Id": "17798", "Score": "2", "body": "Have to agree with Cygal. There's not enough information here to provide a decent answer, and adding more would really only confuse the issue as what you already have is so large ...
[ { "body": "<p>First of all, notice that declaring <code>has_artists()</code> in <code>bam_artists_alfa</code> is confusing. It doesn't make the function \"local\", since you can call it outside of <code>has_artists()</code> too.</p>\n\n<p>It's hard to tell where the bottleneck is! You only have one <strong>visi...
{ "AcceptedAnswerId": "11172", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-25T04:11:25.617", "Id": "11182", "Score": "5", "Tags": [ "performance", "beginner", "php" ], "Title": "Alphabetical navigation" }
11182
<p>I'm wondering how I could refactor this code. It may look a little reiterative and probably there's a shorter method to accomplish the same.</p> <pre><code>def self.location(distance=100,location) if distance.is_a? Integer if distance.between?(1,5000) distance = distance elsif distance &lt; 1 ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-25T22:11:11.313", "Id": "17857", "Score": "2", "body": "begin by splitting in two methods: one with distance condition, other with conditionnal scope" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-29T18:57...
[ { "body": "<p>I've replaced the part where you take care that distance is between 1 and 5000 with <code>distance = [1, [distance, 5000].min].max</code> . </p>\n\n<pre><code>def self.location(distance=100,location)\n if distance.is_a? Integer \n distance = [1, [distance, 5000].min].max\n else \n distance...
{ "AcceptedAnswerId": "11189", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-25T22:07:46.283", "Id": "11187", "Score": "4", "Tags": [ "ruby-on-rails", "ruby" ], "Title": "Finding locations with a distance between 1 and 5000" }
11187
<p>Basically trying to create a dict of all declared variables and functions along with their types of a .c source file. Does anyone think I missed anything?</p> <pre><code>#!usr/python import string import re from types import * from pprint import pprint varDict = {} def find_substring(needle, haystack): index ...
[]
[ { "body": "<p>I think this code is fundamentally broken. What about comments and the preprocessor? And just by eyeballing the code I doubt very much that it parses declarations remotely correctly.</p>\n\n<p>This is the wrong approach. <code>string.find</code> will only take you so far. You need to <em>parse</em...
{ "AcceptedAnswerId": "11213", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-26T03:38:50.370", "Id": "11191", "Score": "2", "Tags": [ "python", "c" ], "Title": "Python & C: Trying to create a dict of all declared variables and functions and their types of a .c...
11191
<p>I have a a couple of different radio buttons which return an ethnicity and a gender. The script runs inside an internal application so rather than returning "boy", "girl" or "both" I get back 7707330, 7707333, and 7707336. Similar from the ethnicity radio button. </p> <p>I then need to validate data based on the co...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-01-19T08:27:23.980", "Id": "502852", "Score": "0", "body": "The current question title, which states your concerns about the code, applies to too many questions on this site to be useful. The site standard is for the title to **simply sta...
[ { "body": "<p>One option is to have a map from key -> value</p>\n\n<p>for example:</p>\n\n<pre><code>var var2 = radioResults[1].toString();\nvar gender = {'7707330': 'boy',\n '7707333': 'girl',\n '7707336': 'both'}[var2];\n</code></pre>\n\n<p>You could even put functions as the value...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-26T03:48:07.260", "Id": "11194", "Score": "5", "Tags": [ "javascript" ], "Title": "Javascript - Replace lots of if statements" }
11194
<p>I have method which checks period and return schedules:</p> <pre><code>public IEnumerable&lt;EventSchedule&gt; GetSchedulesForPeriod(PeriodEvent period, string tab = "") { switch (period) { case PeriodEvent.Today: return GetTodaySchedules(tab); ...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-01-31T16:58:21.290", "Id": "504002", "Score": "0", "body": "The current question title, which states your concerns about the code, applies to too many questions on this site to be useful. The site standard is for the title to **simply sta...
[ { "body": "<p>Just add another argument to the method:</p>\n\n<pre><code>private IEnumerable&lt;EventSchedule&gt; GetSchedules(string tab, DateTime day)\n{\n var result = Database.EventSchedules.Where(s =&gt; s.RecurrenceStart.Value.Date &lt;= day &amp;&amp;\n s.RecurrenceEnd.Value.Date &gt;= day &am...
{ "AcceptedAnswerId": "11229", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-26T11:43:27.143", "Id": "11201", "Score": "4", "Tags": [ "c#" ], "Title": "similar code in several methods" }
11201
<p>If I want to strip a string completely of its <strong>whitespaces, punctuation and numbers</strong> (i.e. anything that is not A-Z, a-z), what is the most efficient way of doing it in C++?</p> <p>I tried this:</p> <pre><code>string strip(string in) { string final; for(int i = 0; i &lt; in.length(); i++) { ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-26T10:49:37.250", "Id": "17876", "Score": "0", "body": "How fast/slow is your computer? Using a normal machine with about 100 mil ops per second, I think 2000 chars should be short enough." }, { "ContentLicense": "CC BY-SA 3.0"...
[ { "body": "<p>Try calling reserve(2000) on your final string before using it. Also take a const ref as argument.</p>\n\n<p>Edit:</p>\n\n<p>I would suspect that on Unix, the <code>isalpha</code> function is performing a lot more work to support Unicode, and you are only interested in the ASCII range. It's still ...
{ "AcceptedAnswerId": null, "CommentCount": "39", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-26T10:47:37.983", "Id": "11203", "Score": "25", "Tags": [ "c++", "strings", "algorithm", "homework" ], "Title": "Most efficient way in C++ to strip strings" }
11203
<p>I took a little heat on a method I had to resize an image and I'm hoping I can get a little help on the best way to do it. This is intended for a simple <a href="https://github.com/kentcdodds/Java-Helper" rel="nofollow">Java Helper Library</a> I'm developing. I have a few ways to do it.</p> <p>New Method:</p> <pre...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-29T21:55:44.650", "Id": "18164", "Score": "0", "body": "Doing this correctly (working around some bugs in the Java2D pipeline, incompatible image types or poorly chosen image types, etc.) is actually not as straight forward as it seems...
[ { "body": "<p>Edit: about the new method, I'd say Graphics2D is a bit overkill (look at Konrad Rudolph's comment for another opinion). And you don't use the max parameter anymore. Does it stretch the image?</p>\n\n<p>The original method is better, but you should have a real <code>if else</code>: resizing the im...
{ "AcceptedAnswerId": "11221", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-26T12:34:32.167", "Id": "11214", "Score": "2", "Tags": [ "java", "optimization", "image", "comparative-review" ], "Title": "Image-resizing methods" }
11214
<p>I have a class with approximately 140 menu buttons in a nested ribbon-style menu over a canvas type area within a WinForms application.</p> <p>As a result of this, a large swathe of my codebehind file consists of 140 event handlers for click events.</p> <p>Many of them however, are remarkable similar, for example:...
[]
[ { "body": "<p>You can create a Dictionary, where key is a MenuItem, a value us function/delegate that has to be called on click. All 140+ menu items subscribe to the <em>same</em> event hadler and in that event \nhandler write something like </p>\n\n<pre><code>myMenuItemsDictionary[((MenuItem)sender)]()\n</cod...
{ "AcceptedAnswerId": "11216", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-26T12:19:13.803", "Id": "11215", "Score": "3", "Tags": [ "c#", "winforms" ], "Title": "Refactoring Event Handlers - How to go about this for growing WinForms application" }
11215
<p>Looking at a code review at work for a Win32 C# code I am seeing some lines like this:</p> <pre><code>int MinutesPerDay = 1440; int MinutesPerWeek = 10080; int MinutesPerMonth = 43200; </code></pre> <p>and so on ...</p> <p>I am not sure what is wrong with it but still I feel this is not a good code and design? Wh...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-26T17:08:10.053", "Id": "17995", "Score": "1", "body": "It should be noted that these values are only valid in timezones which do not participate in Daylight Savings Time. `MinutesPerMonth` is of course approxiamate, which may not be ...
[ { "body": "<p>There is a class called \"TimeSpan\", you can use that</p>\n\n<pre><code>TimeSpan interval = TimeSpan.FromDays(1);\ndouble seconds = interval.TotalSeconds;\n</code></pre>\n\n<p>I don't consider that better from a coding stand point. You should probably look at your code and figure out why you are ...
{ "AcceptedAnswerId": "11223", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-26T15:04:19.240", "Id": "11222", "Score": "2", "Tags": [ "c#" ], "Title": "MinutesPerDay - Does .NET have anything for it?" }
11222
<p>Here is a utility that supports ETL/merging in Entity Framework. </p> <p>If it's not appealing as a general purpose tool, why?</p> <p>If it is appealing as a general purpose tool, how might the design be made better?</p> <p>Also, I'm not the world's most experienced programmer when it comes to writing re-usable c...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-26T21:06:06.530", "Id": "18020", "Score": "0", "body": "Is there a suitable *Contrib project?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2015-03-27T21:52:12.957", "Id": "153451", "Score": "1", "bod...
[ { "body": "<p>In this object method I would change a couple of things</p>\n\n<blockquote>\n<pre><code> private object Convert(Type convertToType)\n {\n object converted = null;\n\n if (this.Value == null)\n {\n return converted;\n }\n else if (convertToType.Is...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-26T17:25:39.493", "Id": "11231", "Score": "5", "Tags": [ "c#", "entity-framework", "etl" ], "Title": "MergeUtility for Entity Framework" }
11231
<p>This is a fairly popular interview question that I conceptually understand but have never really attempted to implement. In other similar implementations of this in Java I have seen they typically operate on an array of boolean values which kind of irks me. It turns out that the way the JVM works however is that it...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-26T20:43:17.020", "Id": "18019", "Score": "1", "body": "http://docs.oracle.com/javase/6/docs/api/java/util/BitSet.html" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-27T09:37:00.660", "Id": "18051", ...
[ { "body": "<p>So just a few things that I am seeing here. You are using Math.floor, ceil on integers which is totally unnecessary, integers by definition don't have a decimal portion. You also don't need to cast an int as an int. </p>\n\n<p>To make this run faster and take up less stack space, in the for loo...
{ "AcceptedAnswerId": null, "CommentCount": "7", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-26T17:44:57.980", "Id": "11232", "Score": "3", "Tags": [ "java", "optimization", "memory-management", "interview-questions" ], "Title": "Java: Find the smallest integer not in th...
11232
<p>I have all these functions that work together to create functionality on a page. Is the structure of these functions OK? Can I do anything to speed this up or make my code better? I'm not exactly sure what namespaces are, but might they help me here?</p> <p>This code is for a responsive/adaptive calendar website....
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-26T18:07:28.210", "Id": "18004", "Score": "0", "body": "Look into object oriented programming, DRY, modules, separation of concerns. As it is now, anyone trying to understand this code needs to be intimately familiar with the whole thi...
[ { "body": "<p>Here are the first steps I would take (not necessarily in order):</p>\n\n<ol>\n<li><p><strong>Surround everything with an anonymous self calling function</strong></p>\n\n<pre><code>(function () {\n ...\n}());\n</code></pre>\n\n<p>This both helps ensure you don't accidentally add/overwrite globa...
{ "AcceptedAnswerId": "11235", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-26T17:57:44.017", "Id": "11233", "Score": "12", "Tags": [ "javascript", "jquery", "beginner", "functional-programming", "datetime" ], "Title": "Responsive/adaptive website...
11233
<p>I'm attempting to create a comparison table to compare products depending on the add-ons they have. To grab the data and filter it I'm using LINQ To SQL.</p> <p>Table's Layout (cut short):</p> <blockquote> <pre class="lang-none prettyprint-override"><code>Products Table ID Name CategoryID ProductAddons Catego...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-27T04:32:10.483", "Id": "18033", "Score": "2", "body": "Do you have some sample data that would produce those results that you could share with us? Your query is _very_ complicated, much more complicated than it probably has to be and...
[ { "body": "<p>So it looks like what you want is some sort of outer join. I think this should work for you:</p>\n\n<pre><code>var categoryFilter = \"Category1\";\nvar query =\n from addon in dc.Addons\n select new\n {\n Addon = addon.Name,\n Amounts =\n from product in dc.Produ...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-26T19:56:14.097", "Id": "11236", "Score": "7", "Tags": [ "c#", "linq", "entity-framework", "linq-to-sql" ], "Title": "Comparison table for comparing products" }
11236
<p>Firstly, apologies if this is not the correct type of question for here, I had it on the stackoverflow but it was closed with a suggestion I post here. </p> <p>I’m in the process of converting from Latin 15 to Unicode/UTF-8 and researched several tutorials, and am looking here for a critique of what I have implemen...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-27T13:05:24.147", "Id": "18057", "Score": "1", "body": "I don't see why they closed it and told you to move it here. This is a legitimate question and not so much a code review. At least if I am understanding your issue correctly, you ...
[ { "body": "<p>Your code seems legit to me, so I'll try to answer some of your questions.\n<code>preg_match()</code> uses UTF-8 input based on code points, so you don't have to worry about that.\nThe difference between <code>\\xYY</code> and <code>\\x{YYYY}</code> is that the first one accepts either one or two ...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-27T12:24:32.123", "Id": "11242", "Score": "3", "Tags": [ "php", "parsing", "regex", "unicode" ], "Title": "Unicode parsing in PHP" }
11242
<p>I have some code that loops over a number and populates a list using other lists. I think I can refactor it somehow to make it look nicer but not sure the best way to do it.</p> <p>Here is the code:</p> <pre><code>for (int i = 0; i &lt; loopCount; i++) { switch (NoOfRows) { case 1: if (...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-26T13:20:41.257", "Id": "18060", "Score": "0", "body": "And how/where are `InputList1..10` defined?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-26T13:21:11.883", "Id": "18061", "Score": "0", ...
[ { "body": "<p>Yes, a very simple way to do this is to have a number of methods and store delegates to them in a dictionary, keyed on NumberOfRows. </p>\n\n<p>It'll look prettier but doesn't add any functional benefit. For instance: </p>\n\n<pre><code> switch (NoOfRows)\n {\n ...
{ "AcceptedAnswerId": null, "CommentCount": "8", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-26T13:17:38.667", "Id": "11245", "Score": "5", "Tags": [ "c#", ".net" ], "Title": "Refactoring code into a simpler method" }
11245
<p>Assume that we have a <code>.txt</code> file that has one word per line. Find out the word that occurs the most.</p> <p>Here's what I was able to write (I used array of strings instead of a file in this example):</p> <pre><code>string[] source = { "test1", "test2", "test3", "test4", "test1", "test1", "test3" }; Di...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-28T15:49:54.397", "Id": "18120", "Score": "0", "body": "In addition to other answers listed here, if you have a 10GB file, then you should consider parallel computations. The trick is to keep reading the file sequentially, but hand off...
[ { "body": "<p>You are trying to count each key separately. This means you need to iterate through the entire list to count each key. Instead you can keep a running total of your key's and only have to iterate through your list once:</p>\n\n<pre><code>string[] source = { \"test1\", \"test2\", \"test3\", \"test...
{ "AcceptedAnswerId": "11261", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-27T18:36:29.733", "Id": "11254", "Score": "6", "Tags": [ "c#", "algorithm", ".net" ], "Title": "Find most occurring word in a txt file" }
11254
<p>Ok, I am in a JavaScript class, and I have no desire for anyone to do my schoolwork, I have already done what I think is correct, I am just hoping someone can take a look and tell me if I am close, or right, or whatever. Any feedback appreciated. Also, the instructor was very specific in saying that if it asks for ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-27T18:37:39.650", "Id": "18088", "Score": "0", "body": "@CorbinHolbert This may be better for our Code Review site. I'll migrate it for you, and then you can watch there as people help evaluate your code." } ]
[ { "body": "<p>It looks like you're not following the instructions strictly. For example, here:</p>\n\n<blockquote>\n <p>1.Write a line of code using the Location object to return the uniform resource locator (URL) of a Web page to a variable called myWebPage.</p>\n</blockquote>\n\n<p>You didn't write a line of...
{ "AcceptedAnswerId": "11257", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-27T18:35:15.960", "Id": "11255", "Score": "3", "Tags": [ "javascript", "homework" ], "Title": "JavaScript Objects- Can you confirm?" }
11255
<p>I have Django unit tests that are pretty much the following format:</p> <pre><code>class Tests(unittest.TestCase): def check(self, i, j): self.assertNotEquals(0, i-j) for i in xrange(1, 4): for j in xrange(2, 6): def ch(i, j): return lambda self: self.check(i, j) setattr...
[]
[ { "body": "<p>Don't bother with generating tests:</p>\n\n<pre><code>class Tests(unittest.TestCase):\n def check(self, i, j):\n self.assertNotEquals(0, i-j)\n\n def test_thingies(self):\n for i in xrange(1, 4):\n for j in xrange(2, 6):\n self.check(i,j)\n</code></pre...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-27T18:54:37.923", "Id": "11259", "Score": "4", "Tags": [ "python", "unit-testing", "functional-programming" ], "Title": "How do I dynamically create Python unit tests in a readable w...
11259
<p>I have made the following classes and objects. It was made to create forms programattically easily. It should produce highly readable, valid, and clean HTML.</p> <p>Care to give me some feedback? :)</p> <p><a href="https://gist.github.com/2510553">https://gist.github.com/2510553</a></p> <p>Full code:</p> <pre><c...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-27T21:49:11.397", "Id": "18102", "Score": "0", "body": "I only got about halfway through this, so here are a few questions for you while I finish, get home, and write a better reply. What do you do for self terminating tags (`<input />...
[ { "body": "<p>If you cannot write form mockup, you leave it to the designer. Or if you are the only one working on the project you use online tools or similar libraries. I'm not saying what you have here is bad, far from it, I'm just saying solutions for this already exist and more well known solutions will be ...
{ "AcceptedAnswerId": "12135", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-27T19:23:55.720", "Id": "11262", "Score": "5", "Tags": [ "php", "object-oriented", "form" ], "Title": "PHP Form generator class" }
11262
<p>I am trying to improve my C skills, and I hope someone might be able to provide me with some feedback on the following code.</p> <p>It is just basic string splitting, it should behave the similar to <a href="http://www.ruby-doc.org/core-1.9.3/String.html#method-i-split" rel="nofollow">Ruby's String#split</a> or Clo...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-27T21:26:04.110", "Id": "18098", "Score": "0", "body": "Hmm...at least for me, `strdup` doesn't lead to warm fuzzy feelings, and `strtok` makes me feel...less than happy." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDat...
[ { "body": "<p>I'd suggest not rolling your own implementation; just use <code>strtok_r</code> properly and save yourself some time. For memory allocation, you can either use the offsets into the string in-place, or use <code>strndup</code> to get copies of each token as you find it.</p>\n", "comments": [ ...
{ "AcceptedAnswerId": "11321", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-27T21:17:20.237", "Id": "11265", "Score": "5", "Tags": [ "c" ], "Title": "String splitting in C" }
11265
<p>I sometimes find myself wanting custom events on a global object with JQuery.</p> <p>For example:</p> <pre><code>$(window).trigger('blah', {x: 'y'}); </code></pre> <p>This plugin is designed to provide exactly that, except faster:</p> <pre><code>$.multicast('blah')({x: 'y'}); </code></pre> <p>Full plugin code (...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-28T15:25:36.457", "Id": "35875", "Score": "0", "body": "How come you don't use $.fn if it's a jQuery plugin?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-01T20:12:15.100", "Id": "35958", "Score":...
[ { "body": "<h3>Namespacing</h3>\n<p>There's no reason why this needs to be a jQuery plugin other than that you're using the jQuery $ as the namespace, and that you're using $.extend. You could easily make this an independent library, and use a UMD-style header to load it into whatever namespace is available.</p...
{ "AcceptedAnswerId": "32351", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-27T22:21:42.527", "Id": "11267", "Score": "2", "Tags": [ "javascript", "jquery" ], "Title": "JQuery plugin for lightweight global events" }
11267
<p>I'm using C# for a project and thought I would get a feel for the language by making some simple programs. My current program is a simple file recurser that prints the names of files and directories. Any suggestions would be greatly appreciated.</p> <pre><code>using System; using System.IO; namespace FileRecurse...
[]
[ { "body": "<p>I don't like how you use static field to indicate level of indentation, I think it would be better if you passed it down the recursion in parameters of the methods.</p>\n\n<p>And while you're at it, you should probably separate your concerns: don't have everything in your <code>Program</code> clas...
{ "AcceptedAnswerId": "11271", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-28T00:47:10.410", "Id": "11270", "Score": "3", "Tags": [ "c#", "recursion", "file" ], "Title": "Simple file recurser" }
11270
<p>I've implementing the <a href="http://www.csie.ntu.edu.tw/~cjlin/papers/online_ranking/" rel="nofollow">this algorithm</a> in Java, Scala, and Clojure to show my teammates. I know the code works as expected. What I'm looking for is tips on good Clojure style.</p> <pre><code>(ns gaming.online.ranking "Synopsis: ...
[]
[ { "body": "<p>This is a huge file to comment on, so maybe just some general tips:</p>\n\n<ul>\n<li><p><code>map</code> and <code>mapv</code> (a variant of map returning a vector) can take any number of sequences as argument, each element of the nth sequence being used as the nth argument of the function given t...
{ "AcceptedAnswerId": "18018", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-28T06:30:37.550", "Id": "11275", "Score": "8", "Tags": [ "clojure" ], "Title": "Bayesian approximation method for online ranking" }
11275
<p>In the code below, I want to remove the "white space character" from 2 places only, from the end of 1st line and from the end of last line. How can I optimize it ?</p> <p>Platform : Linux , gcc compiler </p> <pre><code>int remove_special_chars(char *file_path, char *dest_file, int flag) { PRINT_FUN_NAME ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-28T18:52:49.043", "Id": "18124", "Score": "0", "body": "Minor nitpick: could you please correct the spelling of \"intermediate\" ?" } ]
[ { "body": "<p>A couple lines that bother me:</p>\n\n<pre><code>strncpy(str_buffer, tmp_strstrlen(tmp_str));\n</code></pre>\n\n<p>First, bear in mind that <code>strncpy</code> does not place a <code>\\0</code> terminator at the end of the string if the buffer size limit is reached (but it does in every other cas...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-28T08:24:39.603", "Id": "11276", "Score": "3", "Tags": [ "optimization", "c", "linux" ], "Title": "Trimming whitespace from the beginning and ending of a file" }
11276
<p>This is my first attempt with MVC and I almost get it, but a small thing bothers me.</p> <p>I have this controller in CodeIgniter:</p> <pre><code>&lt;?php class Page extends CI_Controller { public function index($page = "home") { $data['page'] = $page; list($data['title']) = array_...
[]
[ { "body": "<p>This a nice example: it shows how the MVC is just a pattern which should be ajusted to your needs.</p>\n\n<ul>\n<li>The menu items you're showing seem <em>very unlikely</em> to change over time. This means you can simply put them in your \"templates/menu\" <strong>view</strong>.</li>\n<li>If they'...
{ "AcceptedAnswerId": "11278", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-28T13:16:23.910", "Id": "11277", "Score": "3", "Tags": [ "php", "mvc", "codeigniter" ], "Title": "Where should I put menu items in MVC with PHP - Model or Controller?" }
11277
<p>So I have convert the <code>getDisplayPosition</code> from the beta version of the Kinect SDK to the full version. Here's what I have right now<br/><h3>The Original</h3></p> <pre><code> private Point getDisplayPosition(Joint joint) { float depthX, depthY; nui.SkeletonEngine.SkeletonToDepthImage(...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-28T19:21:59.787", "Id": "18126", "Score": "7", "body": "Hmm, I think to would be better received at [SO]. This isn't really a \"please review my working code\" question but more of a \"help me get this updated to the current version\" ...
[ { "body": "<p>Since I have this same question on Stack Overflow now, the answer can be found <a href=\"https://stackoverflow.com/questions/10367582/converting-kinect-methods-from-beta-2-to-version-1/10448663#10448663\">here</a>. The updated version is:</p>\n\n<pre><code>private Point getDisplayPosition(DepthIma...
{ "AcceptedAnswerId": "14880", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-28T18:06:32.350", "Id": "11280", "Score": "4", "Tags": [ "c#" ], "Title": "Converting Kinect Methods from Beta 2, to Version 1" }
11280
<p>Any suggestions to make this better? </p> <pre><code> import math # BSD License: """Copyright (c) 2012, Solomon Wise All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: 1. Re...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-28T19:19:04.033", "Id": "18125", "Score": "0", "body": "Better in what way? Be specific." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-28T19:33:13.783", "Id": "18127", "Score": "2", "body": "@...
[ { "body": "<pre><code>import math\n# BSD License:\n\"\"\"Copyright (c) 2012, Solomon Wise\nAll rights reserved.\n\nRedistribution and use in source and binary forms, with or without\nmodification, are permitted provided that the following conditions are met:\n1. Redistributions of source code must retain the ab...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-28T19:05:45.600", "Id": "11282", "Score": "1", "Tags": [ "python" ], "Title": "Suggestions for changeable range object?" }
11282