body
stringlengths
25
86.7k
comments
list
answers
list
meta_data
dict
question_id
stringlengths
1
6
<p>I have strong feeling that the code below is ugly at least as there are 2 same "cons".<br> I would appreciate if you advise me ways to improve it. </p> <p>The code produces all allocation by n items from list lst. </p> <pre><code>(defun allocations (lst n) (if (= n 1) (loop for i in lst collect (c...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-14T13:08:34.600", "Id": "31402", "Score": "1", "body": "To make sure I understood you: you are trying to do permutations based on an assumption that the elements of the list are unique non-negative integers? In that case, I'd rather us...
[ { "body": "<pre><code>(defun allocations (source length)\n (if (= 1 length)\n (list (list (car source)))\n (loop for processed = nil then (cons (car i) processed)\n for i on source\n for todo = (cdr i)\n appending\n (loop for intermediate\n in (allocatio...
{ "AcceptedAnswerId": "19615", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-14T12:51:58.993", "Id": "19614", "Score": "3", "Tags": [ "combinatorics", "common-lisp" ], "Title": "Producing all allocations by n items from a list" }
19614
<pre><code>def get_all_friends(uid, client) friends = client.friendships.friends(uid: uid) total = friends.total_number get_friends(total, 0, uid, client) end def get_friends(total, cursor, uid, client) left = total count = [200, left].min friends = client.friendships.friends(uid: uid, count: count, curso...
[]
[ { "body": "<p>It looks pretty good to me. Some notes: </p>\n\n<ul>\n<li>I'd avoid return on the last expression</li>\n<li>I'd avoid the \"-=\" (not very functional)</li>\n<li>I'd avoid inline returns (write a full-fledged conditional instead) </li>\n<li>I have my doubts about this <code>more_friends.users &lt;&...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-14T18:10:52.230", "Id": "19620", "Score": "1", "Tags": [ "ruby", "functional-programming", "recursion" ], "Title": "How to rewrite recursion in a more ruby way" }
19620
<p>The code above is a implementation of a lock-free queue that makes the assumption that there is exactly one Consumer thread and one Producer thread. This works as intended? The memory barriers is used in the right place? The code has race points?</p> <p>PS: I know about the existence of lock-free queue implementati...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-22T12:17:32.300", "Id": "31751", "Score": "0", "body": "Could you link to the original that your ported this from?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-25T18:21:27.593", "Id": "104088", "...
[ { "body": "<ol>\n<li><p>I've never see a naming convention that would use <code>_</code> <em>suffix</em> for private fields in C#. The most often used conventions use <code>m_</code>, <code>_</code> as a prefix, or nothing at all.</p>\n\n<p>Similarly, the <code>k</code> prefix is not usual for constants in C#.<...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-14T21:08:50.663", "Id": "19625", "Score": "2", "Tags": [ "c#", "multithreading", "thread-safety", "lock-free" ], "Title": "Publisher/Consumer thread-safe lock-free queue with a s...
19625
<p>I have a GiftCard class where I have method can_deliver? and deliver! that I think can be refactored to better looking code :</p> <pre><code> def can_deliver? (self.sent_at.nil? &amp;&amp; self.scheduled_at.nil?) || (self.sent_at.nil? &amp;&amp; self.scheduled_at &amp;&amp; self.scheduled_at &lt; Time.now) e...
[]
[ { "body": "<p>Some notes:</p>\n\n<ul>\n<li><p><code>self</code>: You write <code>self.attribute</code> to access attributes. I won't say that's bad practice, not at all, mainly because it's easier to see if you're accessing local variables or instance methods. However, in Ruby it's idiomatic not to use <code>se...
{ "AcceptedAnswerId": "19630", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-14T22:48:40.517", "Id": "19626", "Score": "1", "Tags": [ "ruby", "ruby-on-rails" ], "Title": "Refactor or simple code RoR" }
19626
<p>Pythonic way of expressing the simple problem:</p> <blockquote> <p>Tell if the list <code>needle</code> is sublist of <code>haystack</code></p> </blockquote> <hr> <pre><code>#!/usr/bin/env python3 def sublist (haystack, needle): def start (): i = iter(needle) return next(i), i try: ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-15T03:27:04.163", "Id": "31422", "Score": "0", "body": "So, what's the question?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-15T12:30:16.977", "Id": "31427", "Score": "0", "body": "@JeffVanz...
[ { "body": "<h3>1. Bug</h3>\n\n<p>Here's a case where your function fails:</p>\n\n<pre><code>&gt;&gt;&gt; sublist([1, 1, 2], [1, 2])\nFalse\n</code></pre>\n\n<p>this is because in the <code>else:</code> case you go back to the beginning of the needle, but you keep going forward in the haystack, possibly skipping...
{ "AcceptedAnswerId": "19629", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-14T22:54:25.417", "Id": "19627", "Score": "4", "Tags": [ "python", "python-3.x" ], "Title": "Finding sub-list" }
19627
<p>I've written the following program as a submission to the German Federal Computer Science Competition for highschool students. The program makes the following simulation with a given number of days and a given <em>α</em>. In order to simplify my code, I use a shellscript to run multiple simulations in parallel. You ...
[]
[ { "body": "<p>Overall, this is very clean and I have only a few small improvements.</p>\n\n<p>1) In <code>happy</code>:</p>\n\n<pre><code>/* get amount of cups drunk, cans brewed */\nfor (i = 0; i &lt; STAT_DAYS; i++) cup_count += (*worker)[i].cups;\nfor (i = 0; i &lt; STAT_DAYS; i++) can_count += (*worker)[i]....
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-15T13:18:53.580", "Id": "19633", "Score": "6", "Tags": [ "c", "bash", "simulation", "statistics" ], "Title": "Statistical simulation" }
19633
<pre><code>function C = convolve_slow(A,B) (file name is accordingly convolve_slow.m ) This routine performs convolution between an image A and a mask B. Input: A - a grayscale image (values in [0,255]) B - a grayscale image (values in [0,255]) serves as a mask in the convolution. Output...
[]
[ { "body": "<p>Rather than making four variables just to index the matrix, I would go for two in such a way:</p>\n\n<pre><code>paddedA(i :i_end,j:j_end)\n</code></pre>\n", "comments": [], "meta_data": { "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-24T1...
{ "AcceptedAnswerId": "19898", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-15T13:43:28.147", "Id": "19634", "Score": "3", "Tags": [ "matlab" ], "Title": "2D convolution in matlab" }
19634
<ul> <li>Purpose: Educational</li> <li>Requirement: Given 64KB of memory, implement your own <code>malloc</code> and <code>free</code></li> <li>Method: <a href="http://www.memorymanagement.org/articles/alloc.html#first.fit" rel="nofollow">First-Fit</a></li> </ul> <p></p> <pre><code>struct Header { unsigned short...
[]
[ { "body": "<p>I think this is a bug:</p>\n\n<pre><code>if (current-&gt;size == nblocks) \n{\n //we've found an exact match, remove the chunk from the free list\n if (prev == NULL) //remove the first chunk\n _dTail = NULL;\n ^^^^^^^^^^^^^^^\n You are just removing the head of the list\...
{ "AcceptedAnswerId": "19636", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-15T16:03:43.813", "Id": "19635", "Score": "7", "Tags": [ "c", "memory-management" ], "Title": "malloc / free implementation" }
19635
<p>This is a piece of C89 code testing a function titled <code>logging_function()</code>, which takes two arguments and uses them to log a bit of information. </p> <p>In this case, the first argument to the function is the string to be logged, and the second argument is a string holding a path in a filesystem to a log...
[]
[ { "body": "<p>For one... I don't see any check of <code>argc == 3</code> to make sure the two arguments were actually passed on the command line.</p>\n\n<p>As to others, well, I'd have to study it some more (and frankly I'm not so sure I want to look that hard right now).</p>\n", "comments": [ { ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-16T00:08:12.663", "Id": "19643", "Score": "2", "Tags": [ "performance", "c", "strings", "logging" ], "Title": "Logging input and log file strings" }
19643
<p>I am a CS student about to enter my junior year. I am attempting to get better and better at programming and thought that this would be a good place to toss my code out there to see if some of you could give me some tips on how to make it better.</p> <p>If you've got tips as to different websites I could go to for...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-17T14:05:28.710", "Id": "31504", "Score": "0", "body": "MinPQ cannot be resolved to a type" } ]
[ { "body": "<p>In the Constructor, you manually copy an array:</p>\n\n<pre><code>for(int j = 0; j &lt; N; j++)\n{\n this.tiles[i][j] = tiles[i][j];\n}\n</code></pre>\n\n<p>Which can be replaced with:</p>\n\n<pre><code>System.arraycopy(tiles[i], 0, this.tiles[i], 0, N);\n</code></pre>\n\n<p>And the entire swit...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-16T00:16:08.653", "Id": "19644", "Score": "5", "Tags": [ "java", "ai" ], "Title": "Optimizations to 8-puzzle" }
19644
<p>I'm writing a Telnet parser in Haskell that can run within any monad that implements some event-handling functions. When it finishes processing a block of input - whether because it read it all or because it was interrupted by an event handler - it returns the remainder of the text and a continuation for more input....
[]
[ { "body": "<p>I think one of the reason why functional programming is usually easier is its natural modularity. Consider to design your solution in a more layered way. I.e. separate parser and invocations. Avoid callbacks in favor of lazy stream of events (see <a href=\"http://www.haskell.org/ghc/docs/7.6.1/htm...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-16T04:04:00.867", "Id": "19652", "Score": "4", "Tags": [ "haskell" ], "Title": "Refactoring a Telnet parser" }
19652
<p>I've written a script to generate DNA sequences and then count the appearance of each step to see if there is any long range correlation.</p> <p>My program runs really slow for a length 100000 sequence 100 times replicate. I already run it for more than 100 hours without completion.</p> <pre><code>#!/usr/bin/env ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-13T21:26:31.680", "Id": "31452", "Score": "0", "body": "Could you explain what this is supposed to do in plain English? 1) At the moment, this is a bit long to read without explanation, 2) It may help you identify the problem yourself,...
[ { "body": "<p>One word: numpy.</p>\n\n<p>A few more words: </p>\n\n<p><code>numpy</code> is a library that includes highly-tuned algorithms (often in Fortran, C, and C++) specifically for the purposes of accelerating numerical computations over matrices and other arrays. If it's at all applicable to what you're...
{ "AcceptedAnswerId": null, "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-13T21:20:57.837", "Id": "19654", "Score": "6", "Tags": [ "python", "beginner", "algorithm", "bioinformatics" ], "Title": "Generating DNA sequences and looking for correlations" }
19654
<p>Are there ways to avoid this triply nested for-loop?</p> <pre><code>def add_random_fields(): from numpy.random import rand server = couchdb.Server() databases = [database for database in server if not database.startswith('_')] for database in databases: for document in couchdb_pager(server[database]): i...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-16T05:37:54.397", "Id": "31467", "Score": "4", "body": "Fundamentally, you're descending through three separate levels of data. Unless you can flatten them or skip one, you have to use a for-loop for each level in the hierarchy. I'd su...
[ { "body": "<p>I agree with the question comments - there's no real way to avoid them (unless you can restructure the databases!), but the code can be made more readable by removing the loops into a separate generator function, especially since you're not doing any processing between each loop.</p>\n\n<p>Conside...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-16T05:07:32.170", "Id": "19657", "Score": "3", "Tags": [ "python" ], "Title": "Removing the massive amount of for-loops in this code" }
19657
<p>Is this an acceptable way to make sure a java.sql.ResultSet is always closed, and also make sure that an Exception caught is propagated to the caller? </p> <p>Please don't hesitate to review other aspects of this sample as well.</p> <pre><code>public void updateReplicationStatus(BeanReplicationTask taskBean, Stri...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-17T14:15:33.313", "Id": "31505", "Score": "0", "body": "To answer the questions: 2 times yes." } ]
[ { "body": "<h1>Close a ResultSet/Resource</h1>\n\n<p>If you are using java 7 then I would recommend to use <a href=\"http://docs.oracle.com/javase/tutorial/essential/exceptions/tryResourceClose.html\">try with resources</a></p>\n\n<p>it will take care of closing ResultSet for you and make your code a little cle...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-16T12:04:20.740", "Id": "19659", "Score": "2", "Tags": [ "java", "exception" ], "Title": "Closing a ResultSet and rethrowing an Exception" }
19659
<p>What do you think about this?</p> <pre><code>#utils.py def is_http_url(s): """ Returns true if s is valid http url, else false Arguments: - `s`: """ if re.match('https?://(?:www)?(?:[\w-]{2,255}(?:\.\w{2,6}){1,2})(?:/[\w&amp;%?#-]{1,300})?',s): return True else: return F...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-22T05:23:48.827", "Id": "64943", "Score": "0", "body": "I'd use [urlparse](http://docs.python.org/2/library/urlparse.html) in the standard library to check it." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-0...
[ { "body": "<p>I would check out <a href=\"https://github.com/django/django/blob/master/django/core/validators.py\" rel=\"nofollow\">Django's validator</a> - I'm willing to bet it's going to be decent, and it's going to be very well tested.</p>\n\n<pre><code>regex = re.compile(\n r'^(?:http|ftp)s?://' # http:...
{ "AcceptedAnswerId": "19670", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-16T15:53:42.797", "Id": "19663", "Score": "3", "Tags": [ "python", "regex", "validation", "url", "http" ], "Title": "HTTP URL validating" }
19663
<p>So basically jqueryphp is a jQuery plugin that allows you to call any PHP function within client-side JavaScript: <a href="https://github.com/Xaxis/jqueryphp" rel="nofollow">jqueryphp@github</a></p> <p>I wrote it as a response to projects such as PHP.JS and other JavaScript emulated PHP function libraries. I realiz...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-16T17:52:13.940", "Id": "31479", "Score": "0", "body": "Use a whitelist instead of a blacklist. You **will** miss something important in the blacklist." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-16T17:...
[ { "body": "<p>It's an interesting idea but I'm struggling to see any real-world use for it at such a simple level. Most of the relevant inbuilt PHP functions have javascript counterparts which would be preferred. For instance, there's no reason you'd ever want to use an ajax request just to do a string replace....
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-16T17:33:45.823", "Id": "19664", "Score": "2", "Tags": [ "javascript", "php", "jquery" ], "Title": "Would a plugin for calling PHP functions within JavaScript prove useful?" }
19664
<p>For example, given a 2D array (a matrix):</p> <pre><code>{{1, 2, 3, 4}, {5, 6, 7, 8}, {9, 10, 11, 12}} </code></pre> <p>What are the solutions to find a number, such as 6?</p> <p>Here's the code I tried using binary search method:</p> <pre><code>int main(){ int sample[3][4] = {{1, 2, 3, 4}, {5, 6, 7, 8}, {...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-10-16T17:25:09.097", "Id": "121896", "Score": "0", "body": "[Similarly finding an element in a matrix](http://www.writeulearn.com/element-sorted-2d-matrix/)" } ]
[ { "body": "<p>Binary search is typically the best you can do for this sort of thing, but only if you can assure that the data is ordered. You never mentioned that the data will appear presorted, but did give it as an example. If the data isn't sorted, this would be a linear search.</p>\n\n<p>How well a search p...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-16T18:15:25.357", "Id": "19665", "Score": "1", "Tags": [ "optimization", "c", "search", "binary-search", "matrix" ], "Title": "Searching for an element in a 2D array" }
19665
<p>I have a CakePHP function here that gets info for a twitter screen_name from the twitter api and writes it to a mysql db. I'm just looking for feedback about other ways to accomplish this that might be more efficient with fewer loops maybe. The challenge is, there are many screen_names that need to be processed for ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-17T11:43:33.830", "Id": "31498", "Score": "0", "body": "admin_wtfTwitter() function is doing too many things. you should split this and distribute the responsibilities." } ]
[ { "body": "<p>There are two fundamental principles I would like to point out: \"Don't Repeat Yourself\" (DRY) and Single Responsibility. The principles should be self explanatory from their names. The very first thing I notice is that you have a \"god\" function. In other words, a function that is trying to do ...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-16T18:48:40.567", "Id": "19667", "Score": "2", "Tags": [ "php", "mysql", "api", "cakephp" ], "Title": "Is there a better way to loop through records and call an api?" }
19667
<p>To start with Common Lisp I am doing Project Euler using this language. Usually I manage to solve problems but I am quite sure that my code is not as efficient as it could be in Common Lisp. That is why I need a review from experienced lispers.</p> <p>This is my code for <a href="http://projecteuler.net/problem=35"...
[]
[ { "body": "<p>In <code>list-&gt;num</code> you can count down with something like <code>for i downfrom n</code>.</p>\n\n<pre><code>(defun num-&gt;list (n)\n (loop for c across (write-to-string n)\n collect (parse-integer (string c))))\n</code></pre>\n\n<p>In above function you can just collect <code>(di...
{ "AcceptedAnswerId": "19701", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-16T19:45:20.107", "Id": "19669", "Score": "4", "Tags": [ "programming-challenge", "lisp", "common-lisp" ], "Title": "Project Euler #35 in Common Lisp" }
19669
<p>I'm trying to figure out a pattern to best accommodate this pretty ugly code:</p> <pre><code>var userDiscounts = _discountRepository.GetUserDiscountsForUsersWithDiscounts(new List&lt;int&gt; { buyerUserId, sellerUserId }).ToList(); // Buyer. var buyerHasFreeCommission = false; var buyerDiscounts = userDiscounts.Wh...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-16T23:54:39.033", "Id": "31488", "Score": "1", "body": "Did you forgot to finish your sentence?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-17T01:07:17.563", "Id": "31489", "Score": "0", "bo...
[ { "body": "<p>You can filter all the data needed right from repository, and then iterate over collection containing required elements only:</p>\n\n<pre><code>var usersWithoutSingleFreeCommision = _discountRepository\n .GetUserDiscountsForUsersWithDiscounts(new List&lt;int&gt; { buyerUserId, sellerUserId })\n...
{ "AcceptedAnswerId": "19691", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-16T20:21:39.863", "Id": "19672", "Score": "5", "Tags": [ "c#", "design-patterns" ], "Title": "Does this ugly code fit into a design pattern?" }
19672
<p>I'm a code banger from way back trying to learn good Python style. Here is my attempt at the classic game. I'm trying to learn Tk, because I have a couple codes that need GUIs. Any suggestions or comments?</p> <pre><code>from tkinter import * import random # use a class definition to hold all my functions class...
[]
[ { "body": "<p><strong>Lambda Usage</strong></p>\n\n<p>I'm not a great fan of the lambda usage to create what are effectively partially applied functions in the <code>self.player_button</code> and <code>self.computer_button</code>. Instead I'd rather do something like:</p>\n\n<pre><code>import functools\nself.pl...
{ "AcceptedAnswerId": "19684", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-17T03:48:00.813", "Id": "19683", "Score": "11", "Tags": [ "python", "game", "gui" ], "Title": "Tic Tac Toe game GUI" }
19683
<p>I am reading lot of articles regarding memory leaks. But i am not sure about below code. I usually do coding in this way. Can anyone tell me, will they leak memory?</p> <p>I have doubts in following 3 scenarios (marked them in code).</p> <p>I got these suspects after reading this <a href="http://coding.smashingmag...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-17T11:58:10.780", "Id": "31499", "Score": "0", "body": "There is no such thing a memory leaks in JavaScript. However there can be memory leaks in JavaScript **implementations** of browsers due to bugs. But these are very different from...
[ { "body": "<p>No, there is nothing you're doing in that code that would result in memory leaks.</p>\n\n<p>I found an article written by Jack Slocum (creator of the ExtJS framework) that details some basic steps to follow to avoid memory leaks. The original article is a bit dated and browsers have gotten a lot b...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-17T07:44:42.810", "Id": "19686", "Score": "3", "Tags": [ "javascript", "jquery", "memory-management" ], "Title": "Will this kind of codes leak memory?" }
19686
<p>I have written a basic image upload function that handles up to five file inputs, intended to be hosted live on the internet very soon.</p> <p>As far as I know it's secure and works well (minus checking the range of the first 100 bytes and looking for magic numbers), but please tell me if you can see any flaws or a...
[]
[ { "body": "<p>Immediately I see globals. Avoid globals at all cost. Strike them from your memory. You will never need them. Ever. Globals are one of the worst things PHP has ever done. It is not always obvious when a variable is a global thus it is very easy to miss and sometimes impossible to trace. It is also...
{ "AcceptedAnswerId": "19826", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-17T08:58:45.933", "Id": "19687", "Score": "2", "Tags": [ "php", "php5" ], "Title": "Image upload script in PHP" }
19687
<p>I am very new to programming and this is my first functional code. It works fine but I'm sure that I could use a lot of optimization. If you see any blunders or would be able to help condense the script that would be fantastic.</p> <pre><code>#!/usr/bin/python import sys, getopt, subprocess, os, tempfile, shutil, ...
[]
[ { "body": "<p>Can you explain what your program is supposed to do? You should put your function calls in a main function and just call main():</p>\n\n<pre><code> if __name__ == 'main':\n main()\n</code></pre>\n\n<p>Also use one line per import and put function definitions under the imports. You might ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-17T14:34:22.033", "Id": "19695", "Score": "5", "Tags": [ "python", "file", "bioinformatics", "child-process" ], "Title": "FASTA file processing using Python to invoke external fi...
19695
<p>I humbly submit the following for critique. This was my final project for an Intro To Java Programming class ("handed-in" already, I can't make changes).</p> <p>The abundant commenting is required by the professor.</p> <blockquote> <p>Design and implement a stringed musical instrument class using the following ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-17T17:36:28.797", "Id": "31510", "Score": "0", "body": "I haven't looked at it in depth but something I can see straight away is that you didn't really document the methods: public methods are exposed for other classes to use. These cl...
[ { "body": "<p>C++ guy here so maybe I am wrong about this but it looks like you've got a bug. Does java automatically call no-argument constructors from constructors that take arguments? If not then Guitar(int numberOfStrings) doesn't increment \"numberOfGuitars\".</p>\n\n<p>Also it would make more design sense...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-17T16:35:19.520", "Id": "19699", "Score": "4", "Tags": [ "java", "classes" ], "Title": "Stringed musical instrument class" }
19699
<p>I am using ElasticSearch and Tire for search in my app across all models.</p> <ol> <li>I would like to refactor autocomplete method because it looks to complex for me.</li> <li>Am I using a good pattern for searching across model?</li> </ol> <p><strong>Model</strong></p> <pre><code>class Link &lt; ActiveRecord::B...
[]
[ { "body": "<p>I'll take <code>autocomplete</code> and leave the rest for others. Some notes:</p>\n\n<ul>\n<li>Never write the pattern \"empty array\" + each + push + return array. That's a <code>map</code> (more on functional programming <a href=\"https://code.google.com/p/tokland/wiki/RubyFunctionalProgramming...
{ "AcceptedAnswerId": "19706", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-17T18:10:07.743", "Id": "19702", "Score": "4", "Tags": [ "ruby", "ruby-on-rails", "search" ], "Title": "ElasticSearch, Tire - refactor autocomplete method for multiple resources" ...
19702
<p>I have a Python file with several function definitions in it. One of the functions, named 'main' will be called as soon as the Python file is run.</p> <p>Example:</p> <pre><code>myFile.py import sys def main(arg1....): ---code--- --more functions-- main() </code></pre> <p>When a person wants to run my file th...
[]
[ { "body": "<p>You can use the <a href=\"http://docs.python.org/2/tutorial/controlflow.html#tut-unpacking-arguments\" rel=\"nofollow\">apply</a> operator (<code>*</code>):</p>\n\n<pre><code>import sys\n\ndef main(name = \"Bill\", age = 22, num_pets=5, hobby = \"soccer\"):\n pass\n\nif __name__ = \"__main__\":...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-17T19:15:33.640", "Id": "19707", "Score": "3", "Tags": [ "python" ], "Title": "Python file with several function definitions" }
19707
<p>Let's say I have three files: a page that is used for searching data called search, a file that handles requests called controller, and a file that has functions which the controller calls based on what POST parameter is passed. From the search page, I post some data and specify my action (search) via AJAX to the co...
[]
[ { "body": "<p>Your approach, which is to load a partial view (html) via ajax, is just fine. Yes, you could load something else such as json, xml, etc. The problem you'd face is that you would require additional client side (js) code to deal with the data. Some feel that the lighter payload of json offers faster...
{ "AcceptedAnswerId": "19723", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-17T20:40:12.617", "Id": "19710", "Score": "3", "Tags": [ "javascript", "php", "mysql", "ajax", "json" ], "Title": "Better way to return data via AJAX?" }
19710
<p>This is a project I am working on, which generates an HTML table out of a query result.</p> <p>(The result <code>DataTable</code> of an SQL command via SP)</p> <p>This section of the project is the one that will generate the headers of the table according to the list of columns of each table selected (from the dat...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-17T22:51:08.833", "Id": "31534", "Score": "0", "body": "Have you looked using the HTML Agility Pack. It may be overkill but it might also make some of the steps easier." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate...
[]
{ "AcceptedAnswerId": null, "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-17T21:47:28.927", "Id": "19712", "Score": "1", "Tags": [ "c#", "performance", "html", "asp.net" ], "Title": "DataTable 'adapter' to HTML table generator" }
19712
<p>I'm making a family tree. The following script allows the user to expand branches of the tree. It works fine, but there must be a better way.</p> <p>You can see it working <a href="http://www.nicholsonfamilytree.co.uk/test1.asp" rel="nofollow">here</a>.</p> <pre><code>$(function(){ $('.oc').prepend('&lt;img sr...
[]
[ { "body": "<p>A couple notes:</p>\n\n<ol>\n<li><p>I would use classes instead of ids for the nested links. I don't know if it's faster to search the DOM for all elements with a specific class, but it looks cleaner and doesn't require you to create unique ids for each element:</p>\n\n<pre><code>$('a.nested-trigg...
{ "AcceptedAnswerId": "19716", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-17T22:38:11.213", "Id": "19713", "Score": "3", "Tags": [ "javascript", "jquery", "tree" ], "Title": "Expanding branches of a family tree" }
19713
<p>The first block of code is my main app.js that is included on every request. It is essentially a library of functions and objects that include related functions (ie: app.utils) that I can use on other pages like page1.js:</p> <p>./app.js</p> <pre><code>var app = window.app || {}; (function($){ app.req = app.r...
[]
[ { "body": "<p>In JavaScript, there is no sure-fire way to organize framework code. As proof, just take a look at the different frameworks that reside on GitHub. You will see that every developer has his/her own way of organizing code.</p>\n\n<p>Here's what I can recommend in your case:</p>\n\n<p>I see that in y...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-18T05:37:16.443", "Id": "19721", "Score": "1", "Tags": [ "javascript", "jquery" ], "Title": "looking for review of code organization for jQuery/javascript code" }
19721
<p>I had a question regarding my code which downloads a file from S3 with the highest (most recent) timedated filename format:</p> <p>YYYYMMDDHHMMSS.zip</p> <pre><code>from boto.s3.connection import S3Connection from boto.s3.key import Key import sys conn = S3Connection('____________________', '______________________...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-18T12:16:27.860", "Id": "31553", "Score": "0", "body": "What are you looking for specifically?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-18T12:34:22.500", "Id": "31555", "Score": "1", "bod...
[ { "body": "<p>The names will properly compare lexically even without converting them to datetimes, and you can just use the <a href=\"http://docs.python.org/2/library/functions.html#max\" rel=\"nofollow\"><code>max</code></a> function:</p>\n\n<pre><code>from boto.s3.connection import S3Connection\nfrom boto.s3....
{ "AcceptedAnswerId": "19768", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-18T09:37:04.007", "Id": "19727", "Score": "2", "Tags": [ "python", "amazon-s3" ], "Title": "Python Boto Script - Sorting based on date" }
19727
<p>I have a helper class that I am using to return the selected items in a number of IEnumerable POCO collection but I'm not happy with the implementation. One of the reasons for using this method is that the collections area returned by RIA services as ReadOnlyObservableCollections and I don't believe they support LIN...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-18T10:59:40.827", "Id": "31550", "Score": "2", "body": "Anything IEnuerable or IQueryable supports LINQ. If it isn't generic, you can call .Cast<Type>() first, then it's generic." }, { "ContentLicense": "CC BY-SA 3.0", "Cre...
[ { "body": "<p>Implement this interface in all of your Dto where it needed:</p>\n\n<pre><code>interface ICommonDtoStuff&lt;T&gt;\n{\n bool IsSelected { get; }\n T ID { get; }\n}\n</code></pre>\n\n<p>Then you can create a method like this:</p>\n\n<pre><code>public IList&lt;T&gt; GetSelectedResults&lt;T, U&g...
{ "AcceptedAnswerId": "19733", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-18T09:57:12.593", "Id": "19728", "Score": "1", "Tags": [ "c#", ".net" ], "Title": "POCO helper class refactoring" }
19728
<p>I'm fairly new to mvc and almost finished my auth class I wanted to check that I'm using it all correctly any feedback would be welcome. I used the PIP framework to get started <a href="http://gilbitron.github.com/PIP/" rel="nofollow">http://gilbitron.github.com/PIP/</a></p> <p>here's the controller</p> <pre><code...
[]
[ { "body": "<p>From an MVC perspective, your controllers are doing far too much. Anything that's related processing on domain concepts (users, logins, products, etc) belongs in the model. </p>\n\n<p>The entire point of MVC is Separation of Concerns so that each component is reusable/replaceable.</p>\n\n<p>To tes...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-18T14:05:11.990", "Id": "19738", "Score": "2", "Tags": [ "php", "mvc" ], "Title": "PHP Mvc code review" }
19738
<p>I was fixing a bug in the code and it was something like this:</p> <pre><code>int const ROW_LOC = 1; //.... Foo ( x , y , ROW_LOC ) ; </code></pre> <p>so it was passing that constant to a method ... and this ROW_LOC constant is being used in multiple other places in the code too.</p> <p>For ONLY ONE place in the ...
[]
[ { "body": "<p>It depends on the meaning of this constant. If the value <code>ROW_LOC - 1</code> has logical relation to <code>ROW_LOC</code> (e.g. it means that it should go right before <code>ROW_LOC</code> in some list) then just use <code>ROW_LOC - 1</code> there, but if it's just <code>0</code> - then eithe...
{ "AcceptedAnswerId": "19742", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-18T14:52:53.037", "Id": "19741", "Score": "2", "Tags": [ "c#" ], "Title": "Should we create a new constant or modify an existing one" }
19741
<p>I have following method which highlight matched word in text: </p> <pre><code># Hightlight matched term # # Ex(for term: some): # "&lt;span class="bold"&gt;Some&lt;/span&gt; CEO Event" # def highlight_matched(matched_word, text) regex = matched_word.gsub(/\*|\"|\'/, "") .split(" ") ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-18T20:06:23.063", "Id": "31585", "Score": "0", "body": "Is `text` pure text or HTML? can you add to the question some asserts?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-18T20:18:21.813", "Id": "31...
[ { "body": "<p>You should use a better class name, such as <code>highlighted</code> or <code>search-term</code> or <code>search-match</code>.</p>\n\n<h1>Bug</h1>\n\n<p>Your solution will break anchors, or titles, or other hmtl properties:</p>\n\n<pre><code># Yields: \"Broken &lt;a href='http://www.example.org/&l...
{ "AcceptedAnswerId": "19783", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-18T15:58:51.893", "Id": "19744", "Score": "6", "Tags": [ "ruby", "ruby-on-rails", "regex" ], "Title": "Refactor highlight matched word in string" }
19744
<p>I have a mixin function which is as follows - </p> <pre><code>function mixin(receiver, supplier) { for (var property in supplier) { if (supplier.hasOwnProperty(property)) { receiver[property] = supplier[property]; } } } </code></pre> <p>To test this function, I am using the <cod...
[]
[ { "body": "<p>Your code is correct, but can be simplified. <code>ok</code> method usually gets an expression rather than a in-place function that is immediately evaluated.</p>\n\n<p>Here is how I would write this test:</p>\n\n<pre><code>test('Mixin Test Runner', function () {\n var receiver = {\n name...
{ "AcceptedAnswerId": "19750", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-18T16:05:30.073", "Id": "19745", "Score": "2", "Tags": [ "javascript", "unit-testing" ], "Title": "Testing a mixin function" }
19745
<p>I have this <a href="http://plus.maths.org/content/os/issue50/features/havil/index" rel="nofollow noreferrer">Sundaram's sieve</a> to generate prime numbers up to <code>limit</code> in Common Lisp.</p> <pre><code>(defun sundaram-sieve (limit) (let ((numbers (range 3 (+ limit 1) 2)) (half (/ limit 2)) ...
[]
[ { "body": "<pre><code> (let ((numbers (range 3 (+ limit 1) 2))\n</code></pre>\n\n<p>Above defines a list of numbers. Later you set various numbers to zero. That's not good for a list structure. Use a vector, an one-dimensional array.</p>\n\n<pre><code>(dolist (step (range 3 (+ limit 1) 2))\n</code></pre>\n\n<p...
{ "AcceptedAnswerId": "19791", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-18T17:02:54.470", "Id": "19747", "Score": "7", "Tags": [ "functional-programming", "common-lisp", "primes" ], "Title": "Sundaram's sieve in Common Lisp" }
19747
<p>I've been on stackoverflow looking for an alternative to the ugly if-elif-else structure shown below. The if-else structure takes three values as input and returns a pre-formatted string used for an SQL query. The code works right now, but it is difficult to explain, ugly, and I don't know a better way to do re-form...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-18T21:03:41.157", "Id": "31588", "Score": "1", "body": "I'm not sure it's possible to answer this without knowing more about the range of possible parameters and return values. It might be worth creating more variables with meaningful ...
[ { "body": "<p>My thought would be to create a collection of objects that can be iterated over. Each object would have an interface like the following.</p>\n\n<pre><code>def _getQuery(activity,pollutant,feedstock):\n for matcher in MATCHERS:\n if matcher.matches(activity,pollutant,feedstock):\n return m...
{ "AcceptedAnswerId": "19756", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-18T19:54:14.617", "Id": "19753", "Score": "2", "Tags": [ "python", "sql" ], "Title": "Constructing an SQL expression from three parameters" }
19753
<p>So I started wondering why it takes 3.5 seconds to <code>AcceptChanges</code> for one changed record in a large <code>DataTable</code>. I wrote another implementation of <code>AcceptChanges</code> (VB.NET) - <code>Me</code> is a <code>DataTable</code> here:</p> <pre class="lang-vb prettyprint-override"><code>Public...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-28T15:01:17.397", "Id": "31953", "Score": "0", "body": "I am not fluent in VB, but there must be a reason why they put _two_ try clauses in the function. My guess is that your function is more efficient but less robust." }, { "...
[ { "body": "<p>It's quite easy to answer your question by looking at the <a href=\"http://typedescriptor.net/browse/members/388932-System.Data.DataTable.AcceptChanges%28%29\" rel=\"nofollow\"><code>DataTable.AcceptChanges</code> source code</a>.</p>\n\n<p>As you can see they copy all <code>DataRow</code> objects...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-18T20:13:32.343", "Id": "19754", "Score": "2", "Tags": [ "vb.net", ".net-datatable" ], "Title": "A faster implementation of AcceptChanges?" }
19754
<p>I want your suggestions on this algorithm:</p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; namespace FCFS_Console { class Program { static void Main(string[] args) { //----------------------------------------R...
[]
[ { "body": "<p>Here is a sample solution you can use to improve you code,. I have created a simple processor class to do processing logic in which input string will be passed from you console application and processor will generate the according to configured writer. (This code can be re factored too).let me kn...
{ "AcceptedAnswerId": "19788", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-18T20:53:15.497", "Id": "19755", "Score": "4", "Tags": [ "c#", "algorithm" ], "Title": "First-come first-serve (FCFS) algorithm" }
19755
<p>This is a command line BlackJack game created in Java as my final project for an advanced programming class.</p> <ul> <li>What do you think about it? </li> <li>Have I used OOP correctly?</li> <li>What grade should I get for this? :D</li> <li>Any concept in game that could be improved? </li> </ul> <p>I used JRE 1.7...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-19T18:58:28.443", "Id": "31638", "Score": "3", "body": "If you ever have a class with only static methods, it is should only be a Utility class (such as for static operations, extracting variables etc). This class is not OO!" }, { ...
[ { "body": "<p>A few notes:</p>\n\n<ol>\n<li><p>I don't think you're utilizing OOP to its full potential in your <code>BlackJack</code> class; all its methods are static and you're passing around too many variables. A cleaner alternative would be to make <code>deck</code>, <code>playersHand</code>, <code>splitHa...
{ "AcceptedAnswerId": "19766", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-19T00:55:22.077", "Id": "19760", "Score": "8", "Tags": [ "java", "object-oriented", "game", "playing-cards" ], "Title": "How is my BlackJack game design?" }
19760
<p>I would like a review regarding the following code in which I index and search the City model. Currently both solr (with sunspot gem) and elaticsearch (with the tire gem) are show. I am migrating from solr to ES and want to make sure I am not making any major mistakes.</p> <p>I am new to ES. </p> <pre><code>class ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-19T03:29:27.147", "Id": "31598", "Score": "0", "body": "Is this Ruby? Please add a language tag, it will give your question better visibility to those who can answer it." } ]
[]
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-19T02:09:52.133", "Id": "19762", "Score": "3", "Tags": [ "ruby", "ruby-on-rails", "search" ], "Title": "Moving from Solr (Sunspot) to ElasticSearch (Tire), Review needed" }
19762
<p>I have a dropdown that contains around 100,000 rows which make up a list.</p> <pre><code>&lt;input id="search" type="text" /&gt; &lt;ul&gt; &lt;li&gt;item 1&lt;/li&gt; &lt;li&gt;item 2&lt;/li&gt; ... &lt;li&gt;item 100,000&lt;/li&gt; &lt;/ul&gt; </code></pre> <p>I have a text box which acts as ...
[]
[ { "body": "<p>A couple notes:</p>\n\n<ol>\n<li><p><code>display: none</code> does everything you're trying to do with your existing CSS class; it hides and completely removes the element from the layout. So instead of adding the <code>zero</code> class you would set <code>display</code> to <code>none</code>, an...
{ "AcceptedAnswerId": "19784", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-19T02:16:17.203", "Id": "19763", "Score": "5", "Tags": [ "javascript", "jquery", "optimization" ], "Title": "Fastest way to remove/hide a lot of elements from a list" }
19763
<p>I am writing an object in C# to mimic jQuery's various functions. That is, calling the constructor is akin to calling the <code>$()</code> function of jQuery. For example,</p> <pre><code>var a = new JQuery("div").eq(0); Assert.AreEqual("$(\"div\").eq(0)", a.ToString()); </code></pre> <p>I also have an Append funct...
[]
[ { "body": "<p>Here are few comment: </p>\n\n<ol>\n<li><p>it seems like ChangeLastPredecessor is an implementation of linked list. </p></li>\n<li><p>instead of returning a new object in every function , return by modifying the same object.</p></li>\n<li><p>you may use Builder pattern (this is under investigation...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-19T04:05:25.120", "Id": "19765", "Score": "3", "Tags": [ "c#", "recursion" ], "Title": "JQuery typed wrapper in C#; possible recursion" }
19765
<p>I want to convert a <code>java.lang.String</code> to a <code>java.lang.Integer</code>, assigning a default value of <code>0</code> if the <code>String</code> is not convertible. Here is what I came up with. I would appreciate an assesment of this approach.</p> <p>To be honest, it feels a little squirrely to me:</p...
[]
[ { "body": "<p>here is a solution :</p>\n\n<pre><code>int tryParseInt(String value) { \n try { \n return Integer.parseInt(value); \n } catch(NumberFormatException nfe) { \n // Log exception.\n return 0;\n } \n}\n</code></pre>\n\n<p>you should catch NumberFormatException instead of exception.<...
{ "AcceptedAnswerId": "19776", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-19T10:32:52.940", "Id": "19773", "Score": "24", "Tags": [ "java" ], "Title": "Convert String to Integer with default value" }
19773
<p>I have a child <code>iframe</code> in my page that will load content from a different web application in a different virtual directory than the parent page.</p> <p>The DOM will look roughly like this:</p> <pre><code>&lt;html&gt; &lt;!-- Content from www.contoso.com/WebApp1/Home --&gt; &lt;div id="parentDiv" ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-20T01:36:45.100", "Id": "31645", "Score": "3", "body": "I thought that cookies were shareable across an entire domain, unless you explicitly set the path when creating the cookie. Any cookies set when the user logs in should be availab...
[ { "body": "<p><strong>My Answer (best guess)</strong></p>\n\n<ul>\n<li>Tag is correct, out of security concer i would still not pass the session id as parameter(only if there is no other way)</li>\n<li>It makes it harder to tamper with, if it is httplony see <a href=\"http://en.wikipedia.org/wiki/HTTP_cookie#Ht...
{ "AcceptedAnswerId": "23487", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-19T13:54:40.623", "Id": "19781", "Score": "5", "Tags": [ "javascript", "html", "security" ], "Title": "Need to pass cookie information to a child iFrame - Are there any security c...
19781
<p>I've written a couple of functions to check if a consumer of the API should be authenticated to use it or not.</p> <p>Have I done anything blatantly wrong here?</p> <p><strong>Config</strong></p> <pre><code>API_CONSUMERS = [{'name': 'localhost', 'host': '12.0.0.1:5000', 'api_ke...
[]
[ { "body": "<p>Exception itself actually inherits from a class called BaseException so: </p>\n\n<pre><code>class BaseException(Exception):\n</code></pre>\n\n<p>Seems backwards.</p>\n", "comments": [], "meta_data": { "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": ...
{ "AcceptedAnswerId": "136029", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-19T19:10:36.143", "Id": "19786", "Score": "4", "Tags": [ "python", "authentication", "web-services", "flask" ], "Title": "Authentication for a Flask API" }
19786
<p>I have a string that must be splitted into an <strong>array</strong> of strings so using strtok makes perfect sense but before that I want to allocate the array of strings and thus I count how many words in it.</p> <pre><code>static inline int countWords(char *str) { int count = 0; char *buf = str; ...
[]
[ { "body": "<p>Here are some impressions:</p>\n\n<pre><code> if(isgraph(*buf) &gt; 0)\n</code></pre>\n\n<p>Why <code>&gt; 0</code>? Why not just <code>if (isgraph(*buf))</code>?</p>\n\n<pre><code> while(*buf != '\\0')\n</code></pre>\n\n<p>You don't have to write <code>'\\0'</code>. You can just write <co...
{ "AcceptedAnswerId": "19810", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-19T21:28:03.843", "Id": "19787", "Score": "11", "Tags": [ "optimization", "c", "strings" ], "Title": "Count words in a C string" }
19787
<p>I've planning to create crosswords game for Android platform. Basically, crossword is a matrix of <code>TextFields</code> (<code>EditTexts</code>) and <code>TextViews</code>. Each crossword might be in american style (first <code>TextView</code> in every question stores question number, and there's no TextView with...
[]
[ { "body": "<pre><code> // loop through CrosswordEntryModels, look for mutual position for TextFields\n</code></pre>\n\n<p>You need to have a model of a actual crossword letter grid. (which can initially some object wrapping a char[][])</p>\n\n<p>You need to <em>look for mutual position</em> because you do no...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-19T22:00:51.697", "Id": "19789", "Score": "1", "Tags": [ "java", "android" ], "Title": "Crossword game - designing class structure" }
19789
<p>I just learned about <code>Maybe</code> in Haskell, so I decided to try to use it with a binary search.</p> <p>Here's the function:</p> <pre><code>binarySearch :: (Ord a, Int b) =&gt; [a] -&gt; a -&gt; b -&gt; b -&gt; Maybe b binarySearch l e beg last | lookat &lt; e = (binarySearch l e i last) | lookat &gt; e ...
[]
[ { "body": "<p>You don't want <code>Int b</code>, you just want <code>Int</code>:</p>\n\n<pre><code>Ord a =&gt; [a] -&gt; a -&gt; Int -&gt; Int -&gt; Maybe Int\n</code></pre>\n", "comments": [ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-19T23:22:22.323", "Id": "...
{ "AcceptedAnswerId": "19792", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-19T22:28:57.203", "Id": "19790", "Score": "1", "Tags": [ "haskell", "beginner", "binary-search" ], "Title": "Errors with binary search in Haskell" }
19790
<p>I have been coding for some time (3 years I think), and have recently been wondering if my coding pattern is any good. Any kind of feedback is welcome:</p> <p>EDIT: The thing that concerns me most is that I have read a lot around that getters/setters are bad for OOP. Is this true?</p> <pre><code>//Point3D.as publi...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-20T00:19:18.363", "Id": "31644", "Score": "0", "body": "You should mention what kind of things concern you about what you wrote." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-30T16:06:59.707", "Id": "...
[ { "body": "<p>Looks good to me. Only thing I would say is:</p>\n\n<ul>\n<li>The accessor methods (<code>get</code> / <code>set</code>) in <code>Point3D</code> are unnecessary as they don't do any processing or restrict any access. The class would be better suited to have simple, public <code>x</code>, <code>y</...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-20T00:18:25.940", "Id": "19793", "Score": "0", "Tags": [ "object-oriented", "design-patterns", "actionscript-3" ], "Title": "Actionscript 3.0, good OOP?" }
19793
<p>I have three methods that are really similar but do slightly different things. This doesn't feel very DRY to me, but I can't think of a way to reduce the duplication. Here are the methods, I think they're fairly self explanatory:</p> <pre><code># Present a date as a string, optionally without a year # Example outpu...
[]
[ { "body": "<p>Well, I don't see much you can do with the first method (being as it has a different responsibility than the other two). You can just combine the latter two methods into one and make the time object a parameter, like such:</p>\n\n<pre><code>def time_string(time_obj, meridian=true)\n if time_obj\n...
{ "AcceptedAnswerId": "19818", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-20T00:52:31.760", "Id": "19796", "Score": "3", "Tags": [ "strings", "ruby", "datetime" ], "Title": "Presenting a time as a string" }
19796
<p>I need to write a jQuery plugin that doesn't take an element to work.</p> <p>Example call:</p> <pre><code>$.funkyTown(); </code></pre> <p>... <strong>not</strong> called like this:</p> <pre><code>$('#foo').funkyTown(); </code></pre> <p>...in other words, I need this plugin to act more like a "utility" plugin (v...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-28T15:42:07.520", "Id": "35878", "Score": "1", "body": "To answer your last update's question, you should probably still return `this` to continue chaining. Yeah it might not seem useful, but it's what someone would expect if they just...
[ { "body": "<p>What I suggest is read the jQuery source. Check out how they do it. In their init method they return this for certain cases, but not for others.</p>\n\n<p>Like when there is no selector:</p>\n\n<pre><code>if ( !selector ) {\n return this;\n}\n</code></pre>\n\n<p>But if you check out other \"uti...
{ "AcceptedAnswerId": "24203", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-20T05:26:47.550", "Id": "19799", "Score": "3", "Tags": [ "javascript", "jquery" ], "Title": "A jQuery \"utility\" plugin template" }
19799
<p>I wrote a small script as an <a href="https://stackoverflow.com/questions/13927204/how-to-get-php-comment-lines-code-lines-count-in-ruby-on-rails-using-regular-ex/13964135#13964135">answer for a Stack Overflow question</a>, which referred to counting lines of code and comments (in C and C++ style).</p> <pre><code>f...
[]
[ { "body": "<p>Your code looks pretty good to me, only that it's very imperative. I know it's not for everybody's taste, but a functional approach on text processing is also feasible. </p>\n\n<p>My take: you start by defining an object (which may be a hash) to store the state (needed for in intermediate iteratio...
{ "AcceptedAnswerId": "19813", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-20T07:17:25.473", "Id": "19800", "Score": "3", "Tags": [ "ruby", "regex" ], "Title": "Count comments and lines of code" }
19800
<p>I am trying to solve <a href="https://www.interviewstreet.com/challenges/dashboard/#problem/4e14b2cc47f78" rel="nofollow">the "Meeting Point" problem from interviewstreet.com</a>:</p> <blockquote> <p>There is an infinite integer grid at which <strong>N</strong> people have their houses on. They decide to unite at...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-20T09:55:18.843", "Id": "31654", "Score": "0", "body": "Dont have an idea for a fancy algorithm, but on the code: Instead of your pos function, you can use math.fabs() and try to use list comprehensions.\n`for i in range(n):\n min +...
[ { "body": "<h3>1. Comments on your code</h3>\n\n<ol>\n<li><p>Your function <code>pos</code> computes the <a href=\"http://en.wikipedia.org/wiki/Absolute_value\" rel=\"nofollow noreferrer\">absolute value</a> of <code>a</code>, and is already built into Python under the name <a href=\"http://docs.python.org/2/li...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-20T09:14:04.683", "Id": "19801", "Score": "5", "Tags": [ "python", "performance" ], "Title": "Meeting Point problem from interviewstreet.com" }
19801
<p>i am trying to learn Trie Data Structure and just implemented it without giving much attention to the code standards , its a raw implementation , can you guys help me to understand whether this implementation make some good progress?</p> <p>Thanks</p> <pre><code>public class TrieNode { public string Word { get...
[]
[ { "body": "<p>It looks like valid implementation, but it could be simplified. Also there are some naming issues: <code>tempWord</code> in <code>AddWord</code> method is actually a <code>char</code> and not a string. <code>TrieNode.Word</code> carries a single char but is declared as <code>string</code>.</p>\n\n...
{ "AcceptedAnswerId": "19815", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-20T09:47:23.780", "Id": "19802", "Score": "1", "Tags": [ "c#", "algorithm", "trie" ], "Title": "Is this a valid implementation of trie Data structure?" }
19802
<p>I have written a little bit of code which illustrates DI(dependency injection) and IoC(Inversion of control) container. The point of this exercise is to illustrate the two methods by which you can actieve inversion of control.</p> <p>Please let me know if this code achieves the objective. (That is, if I have illust...
[]
[ { "body": "<p>Possible Improvements of above code:</p>\n\n<p>WritePredictions class should not be responsible for calling the WhatWillBeGoodNextYear method of Prediction, this is the job of TheOracle Class.I have created IWriter interface for switching out the Output console. so WritePredictions class is not ...
{ "AcceptedAnswerId": "19806", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-20T10:06:45.050", "Id": "19803", "Score": "2", "Tags": [ "c#", "dependency-injection" ], "Title": "Illustrating DI and IoC concepts : Simple code requesting review" }
19803
<p>I'm working on the Rails project where I have many-to-many :through relationship. Each setting has many notifications through email_notification model where the notification can be primary or a secondary.</p> <p><code>schema.rb</code></p> <pre><code>create_table "email_notifications", :force =&gt; true do |t| t...
[]
[ { "body": "<pre><code># TODO: refactor this bullshit\n</code></pre>\n\n<p>While amusing to devs, swear words probably don't belong in production code.</p>\n\n<p>In your copypasta of <code>schema.rb</code>, I do believe you forgot to paste the <code>end</code> keywords. </p>\n\n<p>As a side note, you can also wr...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-20T11:44:26.817", "Id": "19807", "Score": "7", "Tags": [ "ruby", "ruby-on-rails", "email", "active-record" ], "Title": "Email notifications system in Rails project" }
19807
<p>Having an issue optimising has_many through relationship</p> <p>To quickly introduce I have Setting model and Notification model (that is mainly used as a storage of all notification types).</p> <p>They have through relationship :email_notification, where notification can be specified as primary or secondary.</p> ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-20T17:35:53.900", "Id": "31672", "Score": "2", "body": "just two comments: 1) never, ever, hardcode ids in the code, 2) Move code to the model, these methods have too much code." } ]
[ { "body": "<p>This is just a starting point for you. Move the logic found in the new controller into the settings model. Refactor the constant id into a model constant. Move Notification.all into a before_filter since it is called in every controller action. In the edit, I do not like having the if statement...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-20T12:08:50.720", "Id": "19808", "Score": "-1", "Tags": [ "ruby", "ruby-on-rails" ], "Title": "Has many through relationship needs code review" }
19808
<p>Yesterday I got a sudden urge to go from writing Python to something, well, more UNIX core-ish. I read some examples on <a href="http://c.learncodethehardway.org/book/" rel="noreferrer">here</a> and decided I might as well put some of that stuff to use to test something else I'm working on: computability theory. Erg...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-21T07:57:56.230", "Id": "31704", "Score": "0", "body": "You might find this page interesting: http://codegolf.stackexchange.com/questions/8787/turing-machine-simulator/8795#2381" }, { "ContentLicense": "CC BY-SA 3.0", "Crea...
[ { "body": "<p>Identifiers with two underscores are reserved for the implementation (so don't use them).\nAlso MACROS (things defined by #define) are traditionally all uppercase (because they do not obey scope rules (because they are not part of the C language but part of the pre-processor system) we make them a...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-20T15:39:58.350", "Id": "19814", "Score": "24", "Tags": [ "c", "beginner", "error-handling", "simulation", "state-machine" ], "Title": "Simple Turing machine simulator" }
19814
<p>Is there better way to read from a file and connect all data in one big data than to use generators?</p> <p>At the moment, I do the following:</p> <ol> <li>use generators to read data from files.</li> <li>use NumPy to pack all files in 3D array.</li> <li>use pandas to stack it to 2D array so readable for next oper...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-20T15:06:38.810", "Id": "31670", "Score": "1", "body": "This all looks pretty good to me. Do you have a specific concern, or are you merely looking for review?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-1...
[ { "body": "<blockquote>\n <p>Is there better way to read from a file and connect all data in one big data than to use generators?</p>\n</blockquote>\n\n<p>Whenever possible, using generators is better than collecting data in one big object.\nOne big object needs a lot of memory at once,\nusing a generator you ...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-20T14:59:23.490", "Id": "19817", "Score": "2", "Tags": [ "python", "numpy", "generator", "matplotlib" ], "Title": "Reading from a file and connect all data in one big data than t...
19817
<p>Looking for general feedback on this module. <code>remember</code> is property that a user sets via clicking "remember me" when logging in.</p> <p>A token identifies the user - h_token. If <code>localStorage.h_token</code> is set, it is assumed the user has clicked remember me, this is checked at load time.</p> ...
[]
[ { "body": "<p>Looks really good. It's clear and easy to understand. Regarding this specific implementation, a couple of things that came to mind:</p>\n\n<ul>\n<li><p>In <code>setRemember()</code>, unless you specifically only want to support the values <code>1</code> or <code>0</code>, the code can be changed t...
{ "AcceptedAnswerId": "19935", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-20T20:47:18.150", "Id": "19825", "Score": "1", "Tags": [ "javascript" ], "Title": "SStorage (remember) - v0" }
19825
<p>Is this the right way to do a singleton in Objective-C (coming from an Android background, with a little understanding of threading)?</p> <pre><code>#import "ItemsManager.h" #define kNumMaxSelectableItems 15 @implementation ItemsManager{ NSMutableArray *currentItems; } static ItemsManager *myself; -(id)init...
[]
[ { "body": "<p>This is the the way singletons are usually implemented in apple's code samples.</p>\n\n<pre><code>+ (ItemsManager *)sharedInstance\n{\n static ItemsManager *sharedInstance = nil;\n static dispatch_once_t once;\n\n /* Doing the allocation inside dispatch_once queue ensures the code\n ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-21T00:18:31.553", "Id": "19829", "Score": "2", "Tags": [ "objective-c", "singleton" ], "Title": "Objective-C singleton implementation" }
19829
<p>I am utilizing CodeIgniter's Pagination class to implement pagination in the project.</p> <p>In this project, there are 3 modules: Event, Business and Parts. Each Module has the same "view" for pagination. I have written pagination code for the event module, which has 3 types of pagination depending on the conditio...
[]
[ { "body": "<p>When you have long argument lists, you might consider compacting the arguments into an array. However, sometimes its not an issue of the size of the argument list, its an issue of the size of the method. In this case it is the latter. Your <code>event_list()</code> method is doing entirely too muc...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-21T04:53:12.960", "Id": "19835", "Score": "3", "Tags": [ "php", "object-oriented", "codeigniter", "pagination" ], "Title": "Implementing pagination with three modules" }
19835
<p>This question is a follow-up to the questions here: <a href="https://codereview.stackexchange.com/questions/19803/illustrating-di-and-ioc-concepts-simple-code-requesting-review">Illustrating DI and IoC concepts : Simple code requesting review</a></p> <p>I have taken the very good review comments got and tweaked the...
[]
[ { "body": "<p>There are two issues I would like to emphasize in your question/code:</p>\n\n<ol>\n<li>it looks like you're trying to separate DI and IoC principles. In fact they are just different points of view on a same thing, because Dependency Injection is the software pattern usually used to implement Inver...
{ "AcceptedAnswerId": "19841", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-21T12:02:07.453", "Id": "19838", "Score": "0", "Tags": [ "c#" ], "Title": "Illustrating DI and IoC concepts" }
19838
<p>I posted this same question on StackOverflow but guys over there told me to post it here.</p> <p>I have programming in PHP since past 2 years and yet haven't found a perfect script for logging the user in. It's very messy when it comes to deciding whether to use Session or Cookies or both. What value to assign to t...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-21T13:57:25.947", "Id": "31717", "Score": "0", "body": "Try to avoid using globals everywhere." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-21T15:46:02.963", "Id": "31725", "Score": "0", "bod...
[ { "body": "<p>I'm no security expert, not even close, but I can tell you what I use and have observed. I only use cookies to remember the username. Cookies aren't secure so you want to limit what you save in them. I also use sessions to create persistence by passing the user object on. Is this the right way? I ...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-21T12:16:28.100", "Id": "19839", "Score": "2", "Tags": [ "php", "mysql" ], "Title": "The perfect PHP login script" }
19839
<p>I'm looking to remove all magic quotes at the start of my PHP script (if they are turned on). The code I'm using to do this is rather simple, so I was wondering if I was overlooking anything:</p> <pre><code>if (get_magic_quotes_gpc()) { foreach ($_GET as $key =&gt; $value) $_GET[$key] = stripslashes($va...
[]
[ { "body": "<p><a href=\"http://php.net/manual/en/security.magicquotes.php\" rel=\"nofollow noreferrer\">Magic Quotes are removed as of PHP 5.4</a>. I would consider something like this only if you don't have control over the php.ini and only if you are on &lt; 5.4.</p>\n\n<p>Your code does not handle multi dime...
{ "AcceptedAnswerId": "19896", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-21T14:20:29.300", "Id": "19843", "Score": "1", "Tags": [ "php" ], "Title": "Foreach removal of Magic Quotes PHP" }
19843
<p>Here is the class:</p> <pre><code>class Field(object): """Class which contains logic of field-processing """ def __init__(self, routes, callback=None, is_iterable=False,default=None): """ Arguments: - `routes`: sequence of xPath routes to the field, in order of descending prior...
[]
[ { "body": "<p>You are only evaluating the first matching route, but the expected behavior for <code>is_iterable=True</code> and multiple matching routes would be to match all routes. If this was not the intention, distinguish between all 4 use cases:</p>\n\n<ol>\n<li>Only use first matching route, only match 1<...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-21T15:53:19.120", "Id": "19846", "Score": "4", "Tags": [ "python", "parsing", "xml" ], "Title": "DOMDocument field class" }
19846
<p>I have written the following code, I am quite new to C# and Sockets, so perhaps I have made some big mistakes that only more experienced eyes can detect. This is to be used in a Windows Mobile 6.1 device, so I am trying to avoid using many threads.</p> <pre><code>using System; using System.Collections.Generic; usi...
[]
[ { "body": "<p>There are a number of naming issues here so it's quite hard to understand the code, I'll start from those:</p>\n\n<ul>\n<li>public properties/events/methods should be named <code>PascalCase</code> (<code>receiveMessageHandler</code> => <code>ReceiveMessageHandler</code>)</li>\n<li>events are named...
{ "AcceptedAnswerId": "19852", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-21T18:15:05.110", "Id": "19850", "Score": "6", "Tags": [ "c#", ".net", "networking" ], "Title": "C# Async Socket Server with Events" }
19850
<p>This code is for a spreadsheet that tracks weekly picks for NFL games. Four friends and I pick winners for every NFL game each week. Suppose there are 18 games being played this week; for each game, we all pick a winner, and also a level of confidence in that winner. We rank each game 1 to 18 based on our confidence...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-22T03:32:55.460", "Id": "31750", "Score": "0", "body": "Are you sure this code works correctly? Looking at your player/opponent comparison loops, the `if(player==opponent){break}` line means that (e.g.) \"player\" 3 will be compared to...
[ { "body": "<p>You can get rid of repetition in several places.</p>\n\n<p>The long if statement could be replaced with this:</p>\n\n<pre><code>if (lastCellModified.indexOf(['A10', 'A11', 'A12', 'A13', 'A14', 'A15', 'A16', \n 'A17', 'A18', 'A19', 'A20', 'A21', 'A22', 'A23', 'A25']) &gt; -1) {\n</code></pre>\n\...
{ "AcceptedAnswerId": "19870", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-21T22:08:19.510", "Id": "19856", "Score": "4", "Tags": [ "javascript" ], "Title": "Tracking weekly picks for NFL games" }
19856
<p>I'm currently using a scientific information management system that employs a RESTful API. I've never used this API with PHP, and I had a hard time finding best practice examples online. After some reading and experimenting, I came up with the following proof-of-concept procedure to retrieve data from the API and th...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-24T15:17:14.420", "Id": "31805", "Score": "0", "body": "There's not really much that I've noticed. Though I should warn I'm unfamiliar with REST and cURL. You might consider creating a config file for your suffixes and prefixes, and yo...
[ { "body": "<p>The most obvious omission is error handling. You don't handle curl errors or xml parsing errors.</p>\n\n<p>A REST api is like any other external service you might use in your application (such as a database). You might consider creating a client library for it (first check to see if one does not a...
{ "AcceptedAnswerId": "19899", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-21T23:02:54.477", "Id": "19859", "Score": "1", "Tags": [ "php", "api" ], "Title": "Accessing a REST API with PHP" }
19859
<p>I am looking to submit the following code (adapted to fit into <code>java.util</code> obviously) which <a href="https://gist.github.com/4356621">significantly improves performance</a> and reduces useless allocations of <code>java.util.UUID</code>. Help me find the bugs and stupidity before I submit myself to the ju...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-01T16:52:43.837", "Id": "35950", "Score": "2", "body": "In Java 7 [`String.split()`](http://grepcode.com/file/repository.grepcode.com/java/root/jdk/openjdk/7-b147/java/lang/String.java#String.split%28java.lang.String%2Cint%29) has a \"...
[ { "body": "<p>I could not get Caliper running, but hacked my own test:</p>\n\n<p>My initial results were:</p>\n\n<pre><code>warmup\nJdkFrom: 1787.38 JdkTo: 635.12 NessFrom: 460.15 NessTo: 183.67 [-4552303853801426784, 69220000, -4552303853801426784, 69220000]\nReal Run\nJdkFrom: 1415.68 JdkTo: 553.28 NessFrom: ...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-21T23:51:11.950", "Id": "19860", "Score": "31", "Tags": [ "java", "performance" ], "Title": "Improving the Java UUID class performance" }
19860
<p>I've put together this simple fetcher for text data (which I just copy and pasted from a flight info website) - it takes in text data, and spits out an array of objects containing values for each property of each flight it finds. I thought it would be a good accompaniment exercise to "Eloquent Javascript: Chapter 3...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-22T02:19:14.917", "Id": "31747", "Score": "0", "body": "maybe you're doing it like this for a particular reason? You could simplify a lot using `slice` and `join` methods on `words`." } ]
[ { "body": "<p>The individual flights here are good candidates for being individual objects, along the following lines. I take a slightly different approach of first identifying the index of the flight code and the index of the date, and then using that to parse all the other information using <code>words.slice<...
{ "AcceptedAnswerId": "19863", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-22T01:20:50.707", "Id": "19862", "Score": "2", "Tags": [ "javascript" ], "Title": "Simplifying and improving (namely DRY) for flight info fetcher" }
19862
<p>This is my first attempt at trying to write a "monitor" class to determine if a UNC path is available. I need the monitor to not block the main thread and to also event when the UNC is toggled UP/DOWN so that I can respond to that event. </p> <p>I'm looking for:</p> <ol> <li>Best practice suggestions</li> <li>Am I...
[]
[ { "body": "<p>The implementation you have will forever consume one thread from the ThreadPool. That's not the end of the world, but not ideal either. An easy solution would be to use an overload of <code>Task.Factory.StartNew</code> that accepts a <code>TaskCreationOptions</code> argument, and specify <code>Tas...
{ "AcceptedAnswerId": "19871", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-22T10:06:08.453", "Id": "19868", "Score": "4", "Tags": [ "c#", ".net", "multithreading", "task-parallel-library" ], "Title": "UNC path exists monitor" }
19868
<p>Listening to <a href="https://codereview.stackexchange.com/a/19826/11197">mseancole's advice in my previous post</a>, I have rewritten the code. </p> <pre><code>function fihHomeIndex() { global $conf, $DBH; if (strtoupper($_SERVER['REQUEST_METHOD']) == 'POST') { $prelim_check_errors = array(); ...
[]
[ { "body": "<p>You ignored mseancole's first bit of advice about not using globals. Note that the globals are not only $conf and $DBH but also $_POST, $_SESSION, and $_FILES. All of these globals should be passed to your functions. And your code is still very difficult to read mostly due to heavy indentation. Yo...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-22T16:58:26.830", "Id": "19872", "Score": "1", "Tags": [ "php", "php5" ], "Title": "Image upload script" }
19872
<p>I'm currently attempting to learn OCaml, and I'm working thought the Project Euler problems to do so. Here's some code I knocked together for problem 10.</p> <p>I am looking for idiomatic feedback rather than algorithmic</p> <pre><code>(* The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17. Find the sum of all...
[]
[ { "body": "<p>Here are some comments and an example rewrite of your code.</p>\n\n<p>Indentation and line breaks are not idiomatic to OCaml, it's good practice in any language.</p>\n\n<p>A more intuitive type for <code>is_prime</code> would be to have only one argument, so let's encapsulate <code>is_prime_rec</c...
{ "AcceptedAnswerId": "19876", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-22T21:42:28.160", "Id": "19874", "Score": "3", "Tags": [ "programming-challenge", "primes", "ocaml" ], "Title": "Project Euler 10 - Summation of primes" }
19874
<p>I have a textView which is displaying a string. I also have an array which keeps track of where every line begins, it stores the "start index" or NSRange.location for every line.</p> <p>However, when text is inserted on one line, the start indexes of every line afterwards change. So I'm doing this:</p> <pre><code>...
[]
[ { "body": "<p>You could consider creating a class that holds the indices for a larger amount of text (for example a paragraph or a section or a subsection in the text). That class would have the absolute index for where in the file it begins and relative indices within the paragraph/section each line begins. </...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-23T18:45:01.387", "Id": "19880", "Score": "2", "Tags": [ "array", "objective-c", "ios", "integer", "casting" ], "Title": "NSArray and NSNumber-int conversions" }
19880
<p>I wrote this code about finding the end of file (EOF). Please review this.</p> <pre><code>#include&lt;stdio.h&gt; #include&lt;conio.h&gt; void main (void) { int x,y,m; for(x=0;x&gt;=0;x++){ m=scanf("%d %d",&amp;x,&amp;y); if (m!=2 || m==EOF){ break; } else printf("/%d/%d/\n",x,y); } if (feof ( ...
[]
[ { "body": "<p>Let me look at this...first you include the headers, good.</p>\n\n<pre><code>void main (void)\n{\n /* snip */\n}\n</code></pre>\n\n<p>Well, for C it's standard to call <code>int main(int argc, char** argv)</code> to facilitate <a href=\"http://publications.gbdirect.co.uk/c_book/chapter10/argume...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-23T19:21:41.667", "Id": "19882", "Score": "4", "Tags": [ "beginner", "c", "file", "error-handling" ], "Title": "Finding the end of file (EOF)" }
19882
<p>I have view and it works correct, but very slow</p> <pre><code>class Reading(models.Model): meter = models.ForeignKey(Meter, verbose_name=_('meter')) reading = models.FloatField(verbose_name=_('reading')) code = models.ForeignKey(ReadingCode, verbose_name=_('code')) date = models.DateTimeField(verbo...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-24T08:18:32.167", "Id": "31790", "Score": "0", "body": "How slow it is? How many records the view returns?\nLooks like you have a loots of SQL Queries there, try to reduce amount of queries." } ]
[ { "body": "<p>There's nothing intrinsically time-consuming here code-wise - I think the best approach is to make sure that your database tables are set up correctly with the required indices. Perhaps create a view on the db to push some work onto that rather than select in code?</p>\n\n<p>I am a little puzzled ...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-24T06:24:10.340", "Id": "19886", "Score": "2", "Tags": [ "python", "django" ], "Title": "Django how to make this view faster?" }
19886
<p>I'm wondering if perhaps I am doing this all wrong:</p> <p>Questions:</p> <ol> <li>How is my OOP?</li> <li>Is it running multiple methods on a value {i.e.: is <code>strip_tags($copy-&gt;truncateString($articles[$i]['body'], 250, " "))</code>} a terrible way to manage resources?</li> <li><p>Should I create separate...
[]
[ { "body": "<p>I have a few good suggestions for you.</p>\n<h2>Max Line Length</h2>\n<p>Try to cut down on the length of your lines, at my current resolution(running from a cheap laptop on the train) stackexchange displays 90 characters per code line, your longest lines are far above 300, for sharing code try to...
{ "AcceptedAnswerId": "19895", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-24T11:12:42.720", "Id": "19888", "Score": "4", "Tags": [ "php", "object-oriented" ], "Title": "Rendering articles with breadcrumb navigation" }
19888
<p>There is no doubt that Knockout.js is a very useful tool, which will save you from a lot of JavaScript (jQuery) binding hassle, which will reduce your team's bug ratio concerning this part.</p> <p>But unfortunately, its JavaScript part gets ugly sooner than you can imagine. The resulting unreadable code is killing...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-24T16:54:12.847", "Id": "31809", "Score": "2", "body": "This site is for reviewing code. While your statement may be true, a working illustration with actual code would help and follows the [FAQ](http://codereview.stackexchange.com/faq...
[ { "body": "<p>The sample code from knockout probably just wants to show what can be done, not how it ought to be done. ( You messed up indenting btw ).</p>\n\n<p>If this were my code, I would have 3 or 4 models/objects: </p>\n\n<ul>\n<li>Groups<br>\n<ul>\n<li>get ( aka findSavedList ) </li>\n<li>save ( aka s...
{ "AcceptedAnswerId": null, "CommentCount": "7", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-24T16:30:46.160", "Id": "19900", "Score": "5", "Tags": [ "javascript", "knockout.js" ], "Title": "How to enhance the readability of JavaScript part?" }
19900
<p>My solution to this feels 'icky' and I've got calendar math falling out of my ears after working on similar problems for a week so I can't think straight about this.</p> <p>Is there a better way to code this?</p> <pre><code>import datetime from dateutil.relativedelta import relativedelta def date_count(start, en...
[]
[ { "body": "<p>How about...</p>\n\n<pre><code>def date_count(start, end, day_of_month=1):\n dates = [start]\n next_date = start.replace(day=day_of_month)\n if day_of_month &gt; start.day:\n dates.append(next_date)\n while next_date &lt; end.replace(day=day_of_month):\n next_date += rela...
{ "AcceptedAnswerId": "19907", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-24T19:49:00.440", "Id": "19903", "Score": "6", "Tags": [ "python", "datetime" ], "Title": "Building a list of dates between two dates" }
19903
<p>I always seem to struggle refactoring my code. I can look at any other code and know exactly what is going on, but when it comes to cleaning up my code, I get writers block. </p> <p>The following code works, but I know if can be done much nicer, and with few lines of code. I just wanted to wrap a memcache client to...
[]
[ { "body": "<p>This DRY's the code in <code>self.memcache</code> and simply uses a ternary operator for <code>self.fetch</code>.</p>\n\n<pre><code>require 'dalli'\nclass Cache\n def self.fetch(key, ttl, &amp;block)\n memcache ? memcache.fetch(key, ttl, &amp;block) : block.call\n end\n\n def self.memcache\n...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-24T20:35:35.003", "Id": "19904", "Score": "5", "Tags": [ "ruby", "cache" ], "Title": "Using Dalli to connect to memcached" }
19904
<p>Is this code (also available at <a href="https://github.com/andrewcooke/simple-crypt/blob/master/src/simplecrypt/__init__.py" rel="nofollow">github</a> with <a href="https://github.com/andrewcooke/simple-crypt/blob/master/src/simplecrypt/tests.py" rel="nofollow">tests</a>, <a href="https://github.com/andrewcooke/sim...
[]
[ { "body": "<p>I'm not a crypto expert, but I see that at least your decryption code is vulnerable to verification timing attacks (see e.g. here: <a href=\"http://rdist.root.org/2009/05/28/timing-attack-in-google-keyczar-library/\">http://rdist.root.org/2009/05/28/timing-attack-in-google-keyczar-library/</a>)</p...
{ "AcceptedAnswerId": "19997", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-24T23:57:37.130", "Id": "19910", "Score": "3", "Tags": [ "python", "security", "cryptography" ], "Title": "Simple crypto library in Python" }
19910
<p>I'm working on a game in JavaScript and I'm trying to generate rooms in a map. For this example, the map is 32 by 24 (each tile is 32 by 32 pixels).</p> <p>A room is made up of a collection of tiles. A room is always in a square or rectangle shape. For example, 16,16,8,8 would make a room that draws from the top...
[]
[ { "body": "<p>In your locationIsFine it seems you check for each room in your roomStore if any of its tiles intersect with a tile inside your new/fake room.</p>\n\n<p>It would probably be worth wile to add some basic checks which (the larger your roomStore will grow, the more it) will reduce the number of check...
{ "AcceptedAnswerId": "19912", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-25T01:13:50.480", "Id": "19911", "Score": "0", "Tags": [ "javascript", "optimization" ], "Title": "Generating rooms in a map" }
19911
<p>I created a function that rewrites file names according to the available space on screen:</p> <pre><code>@{ var index = 0; foreach (var item in Model) { &lt;div class="gallery-item"&gt; &lt;a href="@item.Uri" title="Click to open file" target="_blank" style="display:block; width: 100%;"&gt; ...
[]
[ { "body": "<p>In general case I would to get text_width and container_width, then <code>calculate new_string_length=container_width/text_width*length</code>, than setup increase or decrease text, depending on result_text_width > container_width and do the loop like yours.</p>\n\n<p>This is really needed only i...
{ "AcceptedAnswerId": "19963", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-25T01:58:30.990", "Id": "19913", "Score": "3", "Tags": [ "javascript", "jquery", "file" ], "Title": "Rewriting file names according to the available screen space" }
19913
<p>I have following HTML class collector. Is there a better way than <code>[]tap</code> for this?</p> <pre><code>def tr_classes(user) classes = [].tap do |c| c &lt;&lt; "error" if user.company.nil? c &lt;&lt; "disabled" if user.disabled? end if classes.any? " class=\"#{classes.join(" ")}\"" end end...
[]
[ { "body": "<p>Notes:</p>\n\n<ul>\n<li>This <code>tap</code> usage is not uncommon to see but IMHO it's very, very dubious. You can use a functional approach (see code below).</li>\n<li>I wouldn't return the string along with the attribute, just the array of classes (which Rails3 helpers understand).</li>\n</ul>...
{ "AcceptedAnswerId": "19950", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-25T02:28:14.333", "Id": "19914", "Score": "0", "Tags": [ "ruby", "html", "ruby-on-rails" ], "Title": "Refactoring a HTML class collector?" }
19914
<p>I am wondering if someone can take a look at my lock-free, circular ring implementation which I use to implement a background logger.</p> <p>The <code>CircularRing</code> pre-allocates <code>LoggableEntity</code> elements and stores them in an AtomicReferenceArray. Then, I have multiple producer threads which will ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-27T18:43:34.660", "Id": "31931", "Score": "0", "body": "Why are you exposing the index? The very fact that it's a ring buffer is immaterial; you should implement [java.util.Queue](http://docs.oracle.com/javase/6/docs/api/java/util/Que...
[ { "body": "<p>I think there is a synchronization problem in <code>incrementModAndGet</code>. It is not <code>synchronized</code>, thus it can happen that two threads reaches the first if when the current index is at the end of the buffer, both passes the condition and the second that calls to <code>aInt.increme...
{ "AcceptedAnswerId": null, "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-25T03:16:32.837", "Id": "19916", "Score": "2", "Tags": [ "java", "thread-safety", "lock-free", "atomic", "circular-list" ], "Title": "Lock-Free Ring Implementation" }
19916
<p>I have a data structure, containing time span nodes, with the following properties:</p> <ul> <li>Nodes are sorted ascending</li> <li>Time spans will not overlap, but may have gaps between them</li> <li>Each node will have a start datetime and a finish datetime</li> <li>The last node's finish may also be null (not f...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-26T14:52:36.203", "Id": "31879", "Score": "0", "body": "You will probably get better luck with algorithms on either SO or Programmers.SO. This site is more geared towards code review, not algorithm review. I wish I could help more, but...
[ { "body": "<h3>Flatter code is less arrow-shaped</h3>\n\n<p>In cases like this:</p>\n\n<blockquote>\n<pre><code>if( $max &lt; $min )\n{\n return false;\n}\nelse\n{\n // more deeply nested conditions ...\n}\n</code></pre>\n</blockquote>\n\n<p>When the <code>if</code> branch ends with a <code>return</code> ...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-25T10:28:29.877", "Id": "19919", "Score": "3", "Tags": [ "php", "optimization", "algorithm", "binary-search" ], "Title": "Binary search algorithm for non-overlapping time spans a...
19919
<p>I have a file containing lines having this structure :</p> <blockquote> <pre><code>var marker25 = createMarker(point, '&lt;div id="infowindow" style="white-space: nowrap;"&gt;&lt;h3&gt;Katz\'s Deli&lt;/h3&gt;205 E. Houston Street, Manhattan, New York City,&lt;br /&gt;New York, USA&lt;br /&gt;&lt;br /&gt; &lt;a href...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-25T20:37:24.703", "Id": "31859", "Score": "2", "body": "Bash, sed and regexps are notoriously not suited for parsing html. Use a specialized library in another language instead." }, { "ContentLicense": "CC BY-SA 3.0", "Crea...
[ { "body": "<p>Consider removing tags with </p>\n\n<pre><code>sed 's/&lt;[^&gt;]*&gt;/ /g'\n</code></pre>\n", "comments": [], "meta_data": { "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-25T20:40:52.510", "Id": "19933", "ParentId": "19921", ...
{ "AcceptedAnswerId": "19933", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-25T10:46:06.157", "Id": "19921", "Score": "1", "Tags": [ "parsing", "bash", "sed" ], "Title": "Parsing of a file using sed" }
19921
<p>I am working on a P2P streaming sim (which I think is correct), however I've discovered a huge bottleneck in my code. During the run of my sim, the function I've included below gets called about 25000 times and takes about 560 seconds from a total of about 580 seconds (I used pycallgraph).</p> <p>Can anyone identi...
[]
[ { "body": "<p><code>valid_sorted</code> is created using <code>sorted</code> function, and then it is sorted again. I don't see how the first sort is helping in any way. Maybe I'm wrong..</p>\n\n<hr>\n\n<p>You create the iterator <code>grouped</code> with the function <code>groupby</code>, but then you turn it ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-25T11:07:55.517", "Id": "19922", "Score": "3", "Tags": [ "python", "optimization" ], "Title": "P2P streaming sim" }
19922
<p>I'm using this simple plugin to show a simple countdown in my pages, what I would like is to keep it more accurate, cause somentimes it seems it isn't accurate.</p> <p>This is the plugin:</p> <pre><code>/* countdown is a simple jquery plugin for countdowns Dual licensed under the MIT (http://www.opensource.org/li...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-01T00:04:33.803", "Id": "32070", "Score": "0", "body": "Can you post values of the `data-expiration` attribute along with string representations of the corresponding dates that are created in JS for both inaccurate and accurate countdo...
[ { "body": "<p>I do not quite understand, why in your code had so many passages from date to date?<br /> if your \"tag attribute\" was already with a correct date format.</p>\n\n<p>I've done some adjustments in the source code, I've tested and I do not see any kind of delay in the source code or in the plugin.</...
{ "AcceptedAnswerId": "20115", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-25T12:08:40.630", "Id": "19923", "Score": "1", "Tags": [ "javascript", "jquery", "plugin", "datetime" ], "Title": "jQuery countdown - accuracy" }
19923
<p>Here I have 2 email validation regexps, which one is better and why?</p> <pre><code>new RegExp("^[a-zA-Z0-9_-]+@[a-zA-Z0-9-]{2,}[.][a-zA-Z]{2,}$", "i"); new RegExp("^([a-zA-Z0-9._%-]+@[a-zA-Z0-9.-]+.[a-zA-Z]{2,4})*$", ""); </code></pre>
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2020-07-13T23:30:25.560", "Id": "482017", "Score": "1", "body": "Related [Email validation using JavaScript](https://codereview.stackexchange.com/q/65190/91556)" }, { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2020-07-14T00...
[ { "body": "<p>Both are totally broken as they both fail to accept the <code>+</code> character in the local part and one of them requires more than one digit for the domain name. Single-digit domain names are perfectly fine in some TLDs (such as <code>.de</code>).</p>\n\n<p>If you really need more validation th...
{ "AcceptedAnswerId": "19944", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-25T14:38:13.380", "Id": "19925", "Score": "-3", "Tags": [ "javascript", "regex", "validation" ], "Title": "Which email detection regex is better?" }
19925
<p>Basically, the code looks for certain emoticon characters (like <code>:)</code> or <code>:|</code>) and replace them with an emoji icon. It also does this for emoji keywords like (<code>:blush:</code> or <code>:smirk:</code>).</p> <p>A better explanation is probably on the <a href="https://github.com/hassankhan/emo...
[]
[ { "body": "<p>here are few improvement area which i would suggest , </p>\n\n<ol>\n<li><p>Current code select all emot element of a document and apply the icon on that , it should be section based or say it should be dependent upon library user (just like jquery does).</p></li>\n<li><p>child.nodeType == 1 is not...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-25T16:29:58.307", "Id": "19927", "Score": "4", "Tags": [ "javascript", "regex" ], "Title": "Replacing emoticon characters with emoji icons" }
19927
<p>I am trying to solve the following via recursion: In a phone we have each digit mapped to a number.</p> <p>Example:</p> <pre class="lang-none prettyprint-override"><code>1 2(ABC) 3(DEF) 4(GHI) 5(JKL) 6(MNO) 7(PRS) 8(TUV) 9(XYZ) * 0 # </code></pre> <p>I need to print out all the...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-26T10:52:11.140", "Id": "31874", "Score": "0", "body": "You forgot `Q` on `7` and `W` on `9`!" } ]
[ { "body": "<p>Here are some comments from my side:</p>\n\n<ol>\n<li><p>The <code>end</code> parameter is unnecessary. You can just test for <code>start &gt;= letters.length</code> instead. Also, you might want to rename start.</p></li>\n<li><p>It might make sense to wrap your algorithm in a callable method such...
{ "AcceptedAnswerId": "19931", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-25T18:19:35.290", "Id": "19929", "Score": "1", "Tags": [ "java", "algorithm", "strings", "recursion" ], "Title": "Recursion to map phone number to strings" }
19929
<p>So I've been working on <a href="http://blog.tmorris.net/understanding-practical-api-design-static-typing-and-functional-programming/">Tony Morris' Tic-Tac-Toe challenge</a>. The rules are as follows:</p> <blockquote> <p>Write an API for playing tic-tac-toe. There should be no side-effects (or variables), at al...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-31T14:08:07.063", "Id": "32059", "Score": "0", "body": "here's the answers.\nhttps://github.com/tonymorris/course/tree/answers/" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-31T14:14:30.323", "Id": "3...
[ { "body": "<p>why do you extend Move also of Winner?</p>\n\n<p>what is the relation between every move object and winning state?</p>\n\n<pre><code> sealed trait Move extends Winner\n</code></pre>\n", "comments": [ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-01T07:41:59...
{ "AcceptedAnswerId": null, "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-26T12:34:48.517", "Id": "19940", "Score": "5", "Tags": [ "object-oriented", "functional-programming", "scala" ], "Title": "Typesafe Tic-Tac-Toe API" }
19940
<p>Here is a link to my project, more details regarding the Diffie Hellman Key Exchange using MODP cyclic grous are available here, no ECP currently implemented</p> <p><a href="https://en.wikipedia.org/wiki/Diffie_hellman" rel="nofollow">https://en.wikipedia.org/wiki/Diffie_hellman</a></p> <p>I would like to know if ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-26T17:11:35.280", "Id": "31881", "Score": "1", "body": "You should add your code directly in your post, per [FAQ](http://codereview.stackexchange.com/faq#questions). Otherwise you risk having your question being closed as off topic." ...
[ { "body": "<p>Just a heads up: You don't have to include the \".php\" extension on \".inc\" files. They are typically considered separate extensions. The \".inc\" extension usually indicates a file to be included, such as a template file, not a class file. However, this is probably more of a point of preference...
{ "AcceptedAnswerId": "19949", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-26T16:55:02.870", "Id": "19945", "Score": "2", "Tags": [ "php", "cryptography" ], "Title": "Review my Diffie Hellman class" }
19945
<p><em>Service Class</em></p> <pre><code># services/search.rb class Search include Rails.application.routes.url_helpers include ActionView::Helpers::TagHelper def initialize(term, app_ids) @term = term @app_ids = app_ids end def results term = @term app_ids = @app_ids multi_search = T...
[]
[ { "body": "<p>Use <code>let</code> (or <code>let!</code>) to set up your fixtures instead of the instance variables. </p>\n\n<pre><code>let!(:app) { create :app, name: \"Marketing\", id: 76 }\nlet!(:question1) { create :question, content: \"Some super question?\" }\nlet!(:question2) { create :question,...
{ "AcceptedAnswerId": "20015", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-26T17:30:19.020", "Id": "19947", "Score": "1", "Tags": [ "ruby", "ruby-on-rails", "rspec" ], "Title": "Refactor specs for service class methods" }
19947
<p>Trying to see if anyone sees any potential flaws with this submit function. One concern is this line:</p> <pre><code>/* Not sure if this is needed if ($this-&gt;session-&gt;userdata('failed_logins')) { // User has previous failed logins in session $failed_logins = $this-&gt;session-&gt;userdata('failed_logi...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-26T20:59:30.467", "Id": "31895", "Score": "0", "body": "for starts Replace `if ($this->form_validation->run() == TRUE)` for `if ($this->form_validation->run())` you don't need to compare `if(true == true)`" } ]
[ { "body": "<p><strong>Replace</strong> </p>\n\n<p><code>if ($this-&gt;form_validation-&gt;run() == TRUE)</code> <strong>for</strong> <code>if ($this-&gt;form_validation-&gt;run())</code> </p>\n\n<p>You don't need to compare <code>if(true == true)</code></p>\n\n<hr>\n\n<p><strong>In this part:</strong></p>\n\n<p...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-26T20:04:55.050", "Id": "19951", "Score": "0", "Tags": [ "php", "codeigniter" ], "Title": "Submit function For Login" }
19951