body stringlengths 25 86.7k | comments list | answers list | meta_data dict | question_id stringlengths 1 6 |
|---|---|---|---|---|
<p>Note:</p>
<ol>
<li>I am very new to Javascript. </li>
<li>The code I provided is long but not complicated.</li>
</ol>
<p>The code below works and runs fine. But I would like to seperate it out into logical 'pure' functions to make it clearer whats going on.
I started to re-factor this myself and made some good p... | [] | [
{
"body": "<p>A lot of the logic in your code belongs to a template, not directly in code.\nYou can find tons of templating engines for javascript or make your own.</p>\n\n<p>An example of a template that could be used here is:</p>\n\n<pre><code><script type=\"text/html\" id=\"letter-index-view\">\n@if( m... | {
"AcceptedAnswerId": "10612",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-04T09:22:35.957",
"Id": "10610",
"Score": "-1",
"Tags": [
"javascript"
],
"Title": "Refactoring Javascript into pure functions to make code more readable and maintainable"
} | 10610 |
<p>I have a method which loads data from a remote app (send TCP request and parse response). Now, I have a simple class for sending a TCP request:</p>
<pre><code>public class PremieraTcpClient
{
public PremieraTcpClient()
{
QueryItems = new NameValueCollection();
int port;
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-04T10:26:57.940",
"Id": "16914",
"Score": "0",
"body": "I'm not sure I understand what the problem is. If you have a collection of items, using `foreach` to do something for each item is exactly what you should be doing. I certainly do... | [
{
"body": "<p>I have some suggestions about PremieraTcpClient. The way it is written may lead to unreleased resources. If you have an error then you will remain with a <strong><em>stream</em></strong> and <strong><em>client</em></strong> opened.\nThe correct way to do it is by using <strong><em>try...catch...f... | {
"AcceptedAnswerId": "10619",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-04T09:47:48.437",
"Id": "10611",
"Score": "4",
"Tags": [
"c#",
"asp.net-mvc-3",
"tcp"
],
"Title": "Loading data from a remote app"
} | 10611 |
<p>Some time ago I <a href="https://stackoverflow.com/a/9893623/917053">posted on Stack Overflow</a> an imperative C# implementation of Kadane's algorithm for finding a subarray with maximum sum. Then I considered implementing the same functionally in F# and came up with the following:</p>
<pre><code>let kadanes (xs: ... | [] | [
{
"body": "<p>A recursive function often works well in place of fold.</p>\n\n<pre><code>let kadanes xs =\n let rec loop (partSum, partIdx, maxSum, startIdx, endIdx) i =\n if i < Array.length xs then \n let x = xs.[i]\n let newPartSum, newPartIdx =\n if partSum + x > x then (partSum + ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-04T13:45:14.210",
"Id": "10616",
"Score": "2",
"Tags": [
"f#"
],
"Title": "How can this functional implementation of Kadane's algorithm be improved?"
} | 10616 |
<p>Taking the following cases in consideration.
Witch one would you prefer and why?
Suggestions appreciated.</p>
<ol>
<li><p>Using Delegates</p>
<pre><code>private void cmdDelete_enterClick(object sender, EventArgs e)
{
var accountManager = new BLAccountManager();
accountManager.OnAccountIn... | [] | [
{
"body": "<p>A third option is to use continuations:</p>\n\n<pre><code>public void DeleteAccount(string accountId, Action<string> OnAccountInUse, Func<string,bool> OnConfirmation)\n{\n var bookingsUsingAccount = GetBookingsUsingAccount(accountId);\n if (bookingsUsingAccount.Count > 0)\n ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-04T14:46:52.997",
"Id": "10617",
"Score": "2",
"Tags": [
"c#",
".net"
],
"Title": "Business Layer - UI communication"
} | 10617 |
<p>I'm not very experienced in C++, but I am trying to circumvent a kind of 'constructor order' situation, where I have class A wants class B in its constructor, and vice versa. They don't really want <em>eachother</em>, but both implement an interface and need each other. I decided to give object A a future. Is this e... | [] | [
{
"body": "<p>What's your inheritance relationship between A and B? If A is the parent of B, it's bad design if A needs to do ANYTHING with B in the constructor/destructor because B will not be valid until after A's construction.</p>\n\n<p>If you require RAII design, look at lazy resource acquisition to avoid r... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-04T14:54:02.333",
"Id": "10618",
"Score": "5",
"Tags": [
"c++",
"c++11"
],
"Title": "Is this a valid implementation of a 'future'?"
} | 10618 |
<p>I want to scale some sub images from an original image.<br>
I need to use <code>TCanvas.CopyRect</code> function for about 5,000 times and it is very slow (from a simple BMP image). </p>
<p>Do you know any other method that is faster that simple <code>TCanvas.CopyRect</code> method for the same job?</p>
<p>Again... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-26T20:41:07.527",
"Id": "16935",
"Score": "2",
"body": "`CopyRect` calls `StretchBlt`. That's pretty well optimised. What makes you thing it is reasonable to expect better performance? How slow is slow?"
},
{
"ContentLicense": ... | [] | {
"AcceptedAnswerId": null,
"CommentCount": "8",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-26T20:37:25.317",
"Id": "10620",
"Score": "5",
"Tags": [
"delphi"
],
"Title": "Fastest function for TCanvas.CopyRect"
} | 10620 |
<p>I am completely new to Objective-C. I have written a simple SingleView Tic Tac Toe Application application for learning purposes. While writing the app, I've tried to be as much sound as I could. Since this is my first shot, I think it can be improved a lot.</p>
<p>Please tell me what you think about it and what y... | [] | [
{
"body": "<pre><code>#import \"tttViewController.h\"\n\n@implementation tttViewController\n\n// @synthesize means \"create getter and setter\" methods.\n</code></pre>\n\n<p>I'd avoid commenting to explain language features. Assume your reader knows the language.</p>\n\n<pre><code>@synthesize slot1, slot2, slot... | {
"AcceptedAnswerId": "10633",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-04T18:50:41.580",
"Id": "10625",
"Score": "7",
"Tags": [
"beginner",
"objective-c",
"game"
],
"Title": "Review of Tic Tac Toe game in Objective-C"
} | 10625 |
<p>I wrote a small JavaScript libary that aims to simplify JavaScript cookies. You can find the code on Github:
<a href="https://github.com/js-coder/cookie.js" rel="nofollow">https://github.com/js-coder/cookie.js</a>
I tested it in various browsers and it seems to work everywhere.</p>
<p>It's not a lot of code so I'l... | [] | [
{
"body": "<p>I think you want to pass on the <code>options</code> argument and filter with <code>hasOwnProperty()</code> so inside of the <code>.set()</code> method this:</p>\n\n<pre><code> if (isPlainObj(key)) {\n for (var k in key) {\n this.set(k, key[k]);\n }\n }\n</code></pr... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-04T19:30:16.207",
"Id": "10626",
"Score": "2",
"Tags": [
"javascript",
"library"
],
"Title": "Review my JavaScript cookie library"
} | 10626 |
<p>I'm in QA Automation, and C# isn't my first language. I've written a small class of methods for GETting and POSTing to web URLs. I use these when I want to test certain things that really fall outside the jurisdiction of Selenium, but are still roughly "black box" type testing. Link scanning, and culling data from P... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-05T00:01:00.993",
"Id": "16963",
"Score": "1",
"body": "Hello Greg. Is this strictly used as a utility? Do you test repeated things, like test a=status code success and then b = check something in the body? Also, you are switching b... | [
{
"body": "<p>It's probably fine for test code. There are a few things I noticed. None of these are necessarily a problem. They may never affect your tests. But they're not ideal either. </p>\n\n<ol>\n<li>You're not calling <code>Dispose()</code> on everything that you strictly should (eg, Streams).</li>\n<li>Y... | {
"AcceptedAnswerId": "10647",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-04T21:18:21.750",
"Id": "10630",
"Score": "4",
"Tags": [
"c#",
"classes"
],
"Title": "C# Class of client methods for interacting with web servers"
} | 10630 |
<p>I coded a linear (without threads) app, which looks ok and has normal solving speed. Also, I coded a multithreaded app, and it is ok when I use 2 processors and 2 threads. It is also fine when I use 4 processors and 4 threads. But when I try to solve with 6 processors and 6 threads, I am not satisfied with the solvi... | [] | [
{
"body": "<p>You're probably encountering locking between threads, where the <code>synchronized</code> between threads is costing you more than you gain. Here's what I'd do:</p>\n\n<ul>\n<li>Instead of using <code>synchronized</code> to protect your counters I'd use <a href=\"http://docs.oracle.com/javase/6/d... | {
"AcceptedAnswerId": "10644",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-05T11:20:12.987",
"Id": "10643",
"Score": "5",
"Tags": [
"java",
"performance",
"multithreading",
"n-queens"
],
"Title": "N-queens multithreaded working time"
} | 10643 |
<p>The problem is find the number of factors of (N!)^2.</p>
<p>This is the code, I wrote:</p>
<pre><code>int prime[]={//list of primes <(10^6)};
int num_fac_of_factorial(int n, int x)
{
int p=x, z=0;
while(n/p>0)
{
z+=n/p;
p*=x;
}
return z;
}
int count=78498; //Count of pr... | [] | [
{
"body": "<p>There's no flaw in the logic, just a couple of implementation errors. And if e.g. <code>1/10 + 1/15 = 1/6</code> and <code>1/15 + 1/10 = 1/6</code> shall not be counted as different solutions but as one, then of course you need <code>(1 + number of divisors)/2</code>.</p>\n\n<p>Here</p>\n\n<pre><c... | {
"AcceptedAnswerId": "10648",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-05T16:18:32.330",
"Id": "10645",
"Score": "4",
"Tags": [
"c++",
"algorithm"
],
"Title": "Is there any flaw in the logic of this problem?"
} | 10645 |
<p>I want to create a ExtensionMethod to ordenate my linq query, called <code>Ordenar</code>. I'll sort it depending what columns is in <code>sortColumns</code> ListDictionary.</p>
<p>I tried some ways, but the best way I arquieve was this :</p>
<pre><code>static class ClienteBusinessExtensions
{
public s... | [] | [
{
"body": "<p>You definitely could use DynamicLinq to solve this problem. See Scott Guthries blog post about it at:\n<a href=\"http://weblogs.asp.net/scottgu/archive/2008/01/07/dynamic-linq-part-1-using-the-linq-dynamic-query-library.aspx\" rel=\"nofollow\">http://weblogs.asp.net/scottgu/archive/2008/01/07/dyn... | {
"AcceptedAnswerId": "10651",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-05T17:39:37.970",
"Id": "10646",
"Score": "2",
"Tags": [
"c#",
"optimization",
"linq",
"entity-framework",
"extension-methods"
],
"Title": "Clever way to build a extension... | 10646 |
<p>I have a function that takes a point, and given its velocity, and acceleration, calculates the time(s) for the point to collide with the line:</p>
<pre><code>def ParabolaLineCollision(pos, vel, acc, line):
"""A pure function that returns all intersections."""
pass
</code></pre>
<p>I have another function t... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-06T10:58:46.833",
"Id": "17021",
"Score": "0",
"body": "How does your entity behave? Instead of calling \"ParabolaLineCollision on each point of each object\" which is very expensive, couldn't you just track the two mass center traject... | [
{
"body": "<p>Not a lot of changes, but maybe a bit more legible. </p>\n\n<pre><code>a12 = entity.acceleration - other.acceleration\na21 = -a12\nv12 = entity.velocity - other.velocity\nv21 = -v12\n\nresult = [ (p, v12, a12, l) for l in other.lines for p in entity.points ] +\n [ (p, v21, a21, l) for l ... | {
"AcceptedAnswerId": "10652",
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-05T19:40:29.850",
"Id": "10650",
"Score": "2",
"Tags": [
"python"
],
"Title": "Logic/Code duplication, improve readability?"
} | 10650 |
<p>I've got this transform method with a triple-nested loop. The <code>Generate</code> methods do their own caching so they are fast. <code>K</code> will have a worst-case value of 150. <code>N</code> will have a worst-case value of about 20000. It's that 20000<sup>2</sup> that's killing me. It looks to me like the inn... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-05T19:41:06.977",
"Id": "16997",
"Score": "6",
"body": "What is the aim of this code?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-05T19:49:30.563",
"Id": "16998",
"Score": "1",
"body": "This... | [
{
"body": "<p>Note the comment on FFT <a href=\"http://en.wikipedia.org/wiki/Constant_Q_transform#Fast_calculation_using_FFT\" rel=\"nofollow\">here</a>. </p>\n\n<p>(I assume your hot path is <code>sum += (wcs[n] * x[index]) * piqs[(n + i) % N];</code>).</p>\n\n<p>If <code>N</code> is a power of 2, you could us... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-05T19:39:04.600",
"Id": "10653",
"Score": "4",
"Tags": [
"c#",
"performance"
],
"Title": "ConstantQ transformation method"
} | 10653 |
<p>Our application uses some singletons for localized strings. These calls used to be long and dirty. Therefore some co-worker created extensions for the <code>int</code> and <code>string</code> type to ease the usage of translations.</p>
<p>What does the code do: Find a translation string based on the key (the <code>... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-06T12:48:40.317",
"Id": "17027",
"Score": "5",
"body": "Why don't you use the built-in localization using resources? Something like `string.Format(Localization.WarrantyLength, warrantyDescription)` (where `Localization` is the resource... | [
{
"body": "<p>This is a <strong>horrible</strong> misuse of extension methods. The only thing worse (and I'm sure you'll see it) is <code>(n+5).Translate(...)</code>. You're absolutely correct - the starting point for the mistake is in thinking of the integer as the base object for the translation. There are... | {
"AcceptedAnswerId": "10695",
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-06T11:47:50.273",
"Id": "10659",
"Score": "4",
"Tags": [
"c#",
"localization"
],
"Title": "Extension methods for translation engine"
} | 10659 |
<p>I'm just getting my feet wet with F#, by implementing some simple algorithms. First up: Djikstras shortest path.</p>
<p>There is one piece I've written in this code which confuses me as to why it works: the <code>contains</code> function. As I understand it, <code>List.isEmpty</code> returns true when a list is emp... | [] | [
{
"body": "<p>Matthew Podwysocki wrote a nice <a href=\"http://codebetter.com/matthewpodwysocki/2009/04/21/functional-solution-for-the-shortest-path-problem/\">functional solution</a> for this on his blog a few years ago:</p>\n\n\n\n<pre><code>module Map =\n let transposeCombine m =\n (m, m) ||> Map.fold... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-06T18:37:39.233",
"Id": "10663",
"Score": "7",
"Tags": [
"algorithm",
"functional-programming",
"f#",
"beginner"
],
"Title": "F# Djikstras shortest path implementation"
} | 10663 |
<p>I am contemplating working with a development firm, and had asked for this piece of sample code. Could you please take a look and let me know if this is a quality piece of work, or if it needs improvement?</p>
<pre><code>// textures pvr
-(void)startWaitAnimation
{
if(![self numberOfRunningActions] && s... | [] | [
{
"body": "<p>I observe that:</p>\n\n<ol>\n<li>Only one function has any comments</li>\n<li>There is a fair amount of commented out code</li>\n<li>The variable names aren't very helpful</li>\n<li>Somethings are just misspelled: <code>getSyrvey</code>, <code>rectoreWorm</code></li>\n<li>The code seems to mix var... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-06T21:52:57.930",
"Id": "10665",
"Score": "15",
"Tags": [
"objective-c",
"interview-questions",
"ios",
"animation",
"sqlite"
],
"Title": "Sample game code for applying to a d... | 10665 |
<p>I'm new to coffeescripts. Can the <code>getSum</code> method be simplified more? Thanks</p>
<pre><code>MyObject =
checkCondition: (num) ->
return true if num is 5
getSum: (num) ->
total = 0
total += i for i in [1..num] when @checkCondition i
total
</code></pre>
<p>I tried removing the la... | [] | [
{
"body": "<p>It's not clear what you're trying to achieve here. </p>\n\n<p>The <code>getSum</code> method looks fine. The <code>checkCondition</code> is overcomplicated: it better be <code>checkCondition: (num) -> num is 5</code></p>\n",
"comments": [
{
"ContentLicense": "CC BY-SA 3.0",
... | {
"AcceptedAnswerId": "10679",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-06T19:11:27.627",
"Id": "10677",
"Score": "3",
"Tags": [
"coffeescript"
],
"Title": "Can this coffeescripts method be simplified?"
} | 10677 |
<p>I have a java function that reads a csv and returns its content as a <code>Vector<Vector<String>></code>.</p>
<p>The function seems to work as I need it, but my gut feeling says it could be better (never mind the fact that it is declared <code>throws Exception</code>).</p>
<p>So here it is:</p>
<pre><... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-12T01:58:40.320",
"Id": "58731",
"Score": "0",
"body": "Something like Óscar López said, don't use concrete class for method return.And Vector will cause performance hit."
}
] | [
{
"body": "<p>There's a constructor for <code>Vector</code> that takes any <code>Collection</code> as its argument. So you could write</p>\n\n<pre><code>String[] values = line.split(\",\"); \ncsvData.add( new Vector<String>( Arrays.asList( values ))); \n</code></pre>\n\n<p>instead of writing your own loo... | {
"AcceptedAnswerId": "10685",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-07T08:02:37.013",
"Id": "10681",
"Score": "19",
"Tags": [
"java",
"array",
"csv",
"vectors"
],
"Title": "Java function to read a CSV file"
} | 10681 |
<p>I'm mostly looking to get feedback on how well I've implemented the C++ language. But I would also like feedback on my algorithm. Did I make it more complex than it needs to be? Is there anything I could have done better?</p>
<p>Things my algorithm prevents:</p>
<ul>
<li>IIII <- "too many multiples," better rep... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-09T05:56:49.957",
"Id": "17104",
"Score": "0",
"body": "There is actually an accepted standard for using Roman numerals, however, you can parse them for complete fails that don't do it properly like IIIIV pretty easily still."
},
{... | [
{
"body": "<p>Well, first of all you should probably declare variables closer to usage. Not only this will compress your code a bit, it will also save you the trouble of assigning random things to them. For example <code>int current = 0</code> declaration can be omitted.</p>\n\n<p>You normally want to use <code... | {
"AcceptedAnswerId": "10693",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-07T16:38:40.260",
"Id": "10686",
"Score": "9",
"Tags": [
"c++",
"algorithm",
"converting",
"roman-numerals"
],
"Title": "Roman Numeral to Decimal Conversion"
} | 10686 |
<p>I was preparing myself for an interview at a well known .com firm. One of the question that they often ask is an algorithm to solve sudokus (that have one solution). Here is what came to my mind. Any hints criticisms or suggestions to tune it up? </p>
<pre><code>import itertools
sudoku_str="""003020600
900305001
00... | [] | [
{
"body": "<p>The biggest problem with the algorithm that I can see, is that it doesn't solve all possible solvable sudoku puzzles, instead (possibly) solving only those that can be filled without guesses, i.e. without backtracking. You can consult <a href=\"http://en.wikipedia.org/wiki/Sudoku_algorithms#Standa... | {
"AcceptedAnswerId": "10690",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-07T21:39:37.747",
"Id": "10688",
"Score": "4",
"Tags": [
"python",
"algorithm",
"sudoku"
],
"Title": "Sudoku solving algorithm - Revision needed"
} | 10688 |
<p>I've been cooking with gas since I got Daniel C Sobral's help on my last question. I am now re-reading Odersky's "Programming in Scala, 2nd Edition" (finished my first reading about this time last year).</p>
<p>I am eager to understand how to alter my mental modeling of problems to more fully embrace the functional... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-09T15:07:29.763",
"Id": "17114",
"Score": "0",
"body": "This article comes out right after I spent the weekend learning exactly this. I am feeling quite appreciative: http://nurkiewicz.blogspot.com/2012/04/secret-powers-of-foldleft-in-... | [
{
"body": "<p>One good technique at eliminating vars is recursion -- it can certainly be used in this example. Alternatively, you can identify a common pattern, such as fold, traversal, etc. For example:</p>\n\n<pre><code>var bitmaps = Set[List[List[Boolean]]]()\nvar result = List[Bitmap2d]()\nfor (\n bitmap2d... | {
"AcceptedAnswerId": "10699",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-08T02:28:37.390",
"Id": "10696",
"Score": "3",
"Tags": [
"functional-programming",
"scala",
"matrix"
],
"Title": "Attempting to eliminate var (and imperative style) from my Piece ... | 10696 |
<p>I'm looking for a code review on the following C++/STL graph implementation:</p>
<pre><code>#include <list>
#include <algorithm>
#include <vector>
#include <utility>
#include <iostream>
#include <stdexcept>
#include <assert.h>
namespace Graph
{
template <class T>
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-10T17:38:28.307",
"Id": "17159",
"Score": "0",
"body": "Why do your edges only have a single `vertex *`, and why is that pointer named `m_Edge` and `edge`?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-10... | [
{
"body": "<ul>\n<li><p>This is a <strong>directed</strong> <strong>weighted</strong> graph. You may want to indicate this by name. If you wish to be more general you can have two type parameters, one for vertex data and one for edge data. Also think about undirected graphs.</p></li>\n<li><p>I guess namespa... | {
"AcceptedAnswerId": "10723",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-08T03:19:30.690",
"Id": "10697",
"Score": "4",
"Tags": [
"c++",
"graph",
"stl"
],
"Title": "STL graph implementation"
} | 10697 |
<p>This is a simple filter that I have been using for a project reading data over a serial connection, and thought it would be good to use it as my first attempt to write docstrings. Does anyone have any suggestions? I have been reading PEP 257. As it is a class, should the keyword arguments come after the <code>__init... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-08T22:36:01.197",
"Id": "17090",
"Score": "0",
"body": "For better commentary, how about including a sample of usage?"
}
] | [
{
"body": "<p>I'd suggest noting that the filter will always return an <code>int</code>, regardless of what you pass in.</p>\n\n<p>I'd also avoid using a bare <code>except:</code> - masking ALL exceptions is generally a bad idea. Instead, catch the exceptions that you <em>want</em> to ignore (e.g. <code>ValueEr... | {
"AcceptedAnswerId": "10711",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-08T21:22:04.923",
"Id": "10709",
"Score": "4",
"Tags": [
"python"
],
"Title": "Filter for reading data over a serial connection"
} | 10709 |
<p>I was trying to solve the following <a href="http://programmingpraxis.com/2012/03/02/balanced-delimiters/" rel="nofollow">Programming Praxis</a> problem:</p>
<blockquote>
<p>Write a function that takes a string and determines if the delimiters
in the string are balanced. The pairs of delimiters are (), [], {},
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-08T22:34:25.183",
"Id": "17089",
"Score": "1",
"body": "One issue with your code is that `a)test(` returns as a balanced expression, although the bracket is closed before being opened."
},
{
"ContentLicense": "CC BY-SA 3.0",
... | [
{
"body": "<p>In order to solve this problem you should either use a stack or recursion to keep track of the current nesting levels. The proposed solutions (including the linked one from assylias) will not do when you have multiple different delimiters and also string delimiters.</p>\n\n<p>Here is a solution th... | {
"AcceptedAnswerId": "10852",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-08T21:41:33.227",
"Id": "10712",
"Score": "3",
"Tags": [
"java",
"algorithm",
"strings",
"balanced-delimiters"
],
"Title": "Balanced delimiter method"
} | 10712 |
<p>I originally posted this in stackoverflow.com but the question may be too broad. I'm trying to figure out the best way to download and use an SQL database from my server. I have included the code i whipped up but I'm not sure if it's a viable way to accomplish this so peer review would be extremely helpful :)</p>
... | [] | [
{
"body": "<p>Some generic Java notes, since I'm not too familiar with Android.</p>\n\n<ol>\n<li><p><code>databasePath</code>, <code>databaseFile</code>, <code>databaseBaseURL</code>, <code>databaseVersionURL</code> should be constants (all uppercase with words separated by underscores):</p>\n\n<pre><code>priva... | {
"AcceptedAnswerId": "11668",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-09T01:22:27.853",
"Id": "10715",
"Score": "3",
"Tags": [
"java",
"android"
],
"Title": "AsyncTask, Android, and SQL"
} | 10715 |
<p>I don't know if this is exactly refactoring but I recently completed a <a href="http://www.cstutoringcenter.com/problems/problems.php?id=20" rel="nofollow" title="Programming Challenge">programming challenge</a> to learn more about Ruby's iterators. However, I feel that the code is extremely "un-Ruby like". Would an... | [] | [
{
"body": "<p>I would not open a stream instead use IO.readlines and enum methods:</p>\n\n<pre><code>puts File.readlines(\"decimals.txt\").reduce(0) { |total, line| total += line.chomp.to_i.to_s(2).count(\"1\") }\n</code></pre>\n",
"comments": [
{
"ContentLicense": "CC BY-SA 3.0",
"Cre... | {
"AcceptedAnswerId": "10721",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-09T05:03:06.157",
"Id": "10717",
"Score": "4",
"Tags": [
"ruby",
"programming-challenge"
],
"Title": "Binary numbers challenge"
} | 10717 |
<p>Here are two methods of code that only vary in one place. Specifically, the first method calls GetReleaseYear(), and the second calls GetReleaseDate().</p>
<p>This is one example of a one-line difference in multiple methods, and each time the difference might be on a different line or couple of lines. One possible ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-08T01:16:02.243",
"Id": "17098",
"Score": "2",
"body": "get rid of those styles and move them to CSS at the least :)"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-08T01:21:50.540",
"Id": "17099",
... | [
{
"body": "<p>There's no one answer for all situations, and your code didn't indicate what the class structures involved might be. </p>\n\n<p>Here are some options:</p>\n\n<ul>\n<li>implement a GetReleaseValue(boolean fullDate) function, and have it\ncall either GetReleaseDate() or GetReleaseYear() depending o... | {
"AcceptedAnswerId": "10720",
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-08T01:14:02.917",
"Id": "10718",
"Score": "2",
"Tags": [
"c#",
"design-patterns"
],
"Title": "What is a good way to structure mark-up generating code and avoid the example mess?"
} | 10718 |
<p>I found myself struggling when it came to refactor the following (<em>working</em>) code. Since can't be found a lot of documentation about Rails '<strong>accepts_nested_attributes_for</strong>' applied to a <strong>many-to-many</strong> relationship (furthermore, with ancillary data), I figured out it would be inte... | [] | [
{
"body": "<p>You can try this, taken from <a href=\"http://apidock.com/rails/ActionView/Helpers/FormHelper/fields_for\" rel=\"nofollow\">Ruby on Rails API</a>:</p>\n\n<p><code>quantities_fields.html.erb</code>:</p>\n\n<pre><code><fieldset class=\"nested\">\n <legend>Ingredienti</legend>\n ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-09T12:34:55.240",
"Id": "10724",
"Score": "8",
"Tags": [
"jquery",
"ruby",
"ruby-on-rails"
],
"Title": "Refactoring contest: Rails accepts_nested_attributes_for a many-to-many associ... | 10724 |
<p>I saw <a href="http://odetocode.com/Blogs/scott/archive/2012/04/09/a-refactoring-experiment.aspx" rel="nofollow">this article that proposes a refactoring exercise</a> and thought I'd give it a try.</p>
<p><strong>Spoiler alert:</strong> I'm going to show my solution to the Kata below. You might want to attempt the ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-09T15:37:43.220",
"Id": "17116",
"Score": "1",
"body": "I would rename the fields in `Pair` to reflect their respective ages. Maybe something like `Senior` and `Junior` or `Elder` and `Younger`."
},
{
"ContentLicense": "CC BY-... | [
{
"body": "<p>My $0.02. Your solution is quite good as it stands. Just putting my thing down too.</p>\n\n<p>I'm a fan of interface-based development with factory methods, so I extracted out an interface for the <code>Person</code> class called <code>IPerson</code>:</p>\n\n<pre><code>public interface IPerson\n{\... | {
"AcceptedAnswerId": "10729",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-09T15:31:28.503",
"Id": "10726",
"Score": "3",
"Tags": [
"c#"
],
"Title": "OdeToCode Refactoring Kata"
} | 10726 |
<p>I had originally posted this question without posting the full algorithm. Here is the whole thing.</p>
<p>I have an HTML page like this:</p>
<pre><code><table id="inputTable">
<tr>
<td>Label1</td>
<td><input type="text" value="" id="inputA1"></td>
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-09T15:49:24.063",
"Id": "17117",
"Score": "0",
"body": "Often a good way to speed up jQuery code is to use less jQuery. This means being comfortable with the native API, and using it directly. For example, if you know *how* the element... | [
{
"body": "<p>As a general advice - use less document-wide selectors. I meant that you always selected something from entire document context: </p>\n\n<pre><code>$(input + indexArray[i] + \"5\")\n//.........\n$(\"#input\" + nextIndex + \"1\")\n</code></pre>\n\n<p>Try to narrow context - for example, assign a cl... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-09T15:29:14.413",
"Id": "10727",
"Score": "5",
"Tags": [
"javascript",
"jquery",
"performance"
],
"Title": "Conditional sum of table cells"
} | 10727 |
<p>I'm very new to backbone.js and JavaScript. I would like to hear some reasonable critiques / advice against my JavaScript code based on backbone.js framework with backbone-forms.</p>
<p>The aim of this simple app is to present a user with a simple registration form (twitter bootstrap modal dialog) and upon clickin... | [] | [
{
"body": "<p>It's pretty good code. Well done! There are no major mistakes or pain points that would annoy other developers. All I can do is to nitpick a little bit.</p>\n\n<ol>\n<li><p>First of all take a look at some JavaScript style guide. jQuery has <a href=\"http://docs.jquery.com/JQuery_Core_Style_Guide... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-09T14:43:17.087",
"Id": "10728",
"Score": "5",
"Tags": [
"javascript",
"form",
"backbone.js"
],
"Title": "Simple registration form"
} | 10728 |
<p>I need a simple singly-linked list to help implement some memory management functionality. I just finished writing it up and would really like a code review since I haven't written this particular data structure in a long time.</p>
<pre><code>struct pid_node {
int PID;
struct pid_node* next;
};
struct pid_... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-09T22:05:10.630",
"Id": "17126",
"Score": "1",
"body": "Since you're using kmalloc, why don't you use [klist](http://isis.poly.edu/kulesh/stuff/src/klist/)?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-0... | [
{
"body": "<p>General:</p>\n\n<ul>\n<li><p>Algorithm looks good. </p></li>\n<li><p>Functions normally start with the brace on column 0.</p></li>\n<li><p>Add a typedef so that you can refer to just <code>pid_node *</code>, not <code>struct\npid_node *</code>, throughout (except in the struct declaration).</p>\n\... | {
"AcceptedAnswerId": null,
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-09T21:49:01.367",
"Id": "10731",
"Score": "3",
"Tags": [
"algorithm",
"c",
"linked-list"
],
"Title": "Quick linked-list implementation"
} | 10731 |
<p>I'm trying to use inheritance and polymorphism to make it easy for the program to be enhance to many more rules. <code>ClassificationRule</code> is the base class and <code>RuleFirstOccrnc</code> and <code>RuleOccrncCount</code> and derived classes and by using the same non-static <code>apply()</code> method <code>C... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-30T16:28:58.430",
"Id": "18202",
"Score": "1",
"body": "Do yourself (and everybody else) a favor - don't use arbitrarily shortened class (or variable) names. Also, what's the point of using prefixed or suffixed variable names (`aUserI... | [
{
"body": "<p>In your code, two classes differently extend a base class <code>ClassificationRule</code>. \nObjects of these classes are added to a list, cast as the base class. \nThey are retrieved from the list and a method, <code>apply()</code>, which is present in the base class but overridden in the child c... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-10T00:35:00.310",
"Id": "10735",
"Score": "4",
"Tags": [
"java"
],
"Title": "Using inheritance and polymorphism in Java"
} | 10735 |
<p>What can I do with this program to improve its performance?</p>
<pre><code>#!/usr/bin/env ruby
require 'open-uri'
print "URL: "
add = gets
puts "Info from #{add}"
begin
open(add) do |f|
puts "Fetching images..."
puts "Fetching links..."
puts "Fetching div tags..."
puts "Fetching headers..."
pu... | [] | [
{
"body": "<p>Instead of opening, reading and closing the file all the time, you should read it once and then just use the string multiple times (this will also safe time and bandwidth).</p>\n\n<pre><code>img = f.read.scan(/<img/).length\n</code></pre>\n\n<p>This won't necessarily give you an accurate count ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-10T03:26:41.427",
"Id": "10737",
"Score": "6",
"Tags": [
"ruby",
"html"
],
"Title": "HTML tag counter"
} | 10737 |
<p>After a whole night of work I finally have my first useful class - for reading database.</p>
<p>It works like a charm, but if you got a moment, please take a glance and give me feedback. Harsh criticism welcome.</p>
<p>Please note that security is not addressed yet, as well as usual SQL clauses, but I'd like to kn... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-10T03:32:59.877",
"Id": "17142",
"Score": "6",
"body": "You can't return a value from a constructor."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-10T09:22:34.380",
"Id": "17145",
"Score": "0",
... | [
{
"body": "<p>Why don't you split the \"constructor\" part and the \"get the values\" part?</p>\n\n<p><strong>Code :</strong></p>\n\n<pre><code>class Database {\n\n protected $dbh; // Database handle connection\n\n public function __construct( $dbh) {\n $this->dbh = $dbh... | {
"AcceptedAnswerId": "10770",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-10T03:24:34.527",
"Id": "10738",
"Score": "3",
"Tags": [
"php",
"object-oriented"
],
"Title": "PHP OOP - Does this database reading class make sense?"
} | 10738 |
<p>I used this code in several projects. But I am not sure if it is stable. However on production it is working well, but I want to listen your advices:</p>
<pre><code>/// <summary>
/// Standard abstract parent for Timer-powered classes. Has Start|Stop|Pulse events
/// </summary>
public abstract class Time... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-11T13:00:42.787",
"Id": "17200",
"Score": "0",
"body": "Hi Orif, i loved your code and i wonder, for what the use of OnPulse ? should the derived class put the InvokePulse be in OnTick ?"
}
] | [
{
"body": "<p>One thing is that the way you're calling the events is not thread-safe:</p>\n\n<pre><code>if (OnStop != null) {\n OnStop(this, new EventArgs());\n}\n</code></pre>\n\n<p>If the only subscriber to the event unsubscribes between the <code>null</code> check and the invoke, you will get a <code>Null... | {
"AcceptedAnswerId": "10745",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-10T11:16:58.363",
"Id": "10744",
"Score": "1",
"Tags": [
"c#",
"multithreading",
"timer"
],
"Title": "Timer wrapper review"
} | 10744 |
<p><a href="https://github.com/asimihsan/crypto_example" rel="nofollow noreferrer">Python Cryptography Example</a></p>
<p>Last weekend I wrote some code to help people use <a href="https://www.dlitz.net/software/pycrypto/" rel="nofollow noreferrer">PyCrypto</a> in a canonical fashion to symmetrically encrypt and decry... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-15T22:14:03.573",
"Id": "32960",
"Score": "0",
"body": "I think lining up code (like the parameters of `_test_encrypt_then_decrypt_file`) is not good, because it get's out of sync quickly. I don't know about the encryption, but I know ... | [
{
"body": "<p>Well then, I guess no one is stepping up to review the code! I've been thinking it over and reading over the code and tests a few times and have come up with the following review comments. These comments apply to the git branch at <a href=\"https://github.com/asimihsan/crypto_example/commit/655694... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-10T12:07:40.330",
"Id": "10746",
"Score": "7",
"Tags": [
"python",
"programming-challenge",
"security",
"cryptography"
],
"Title": "Canonical Python symmetric cryptography exampl... | 10746 |
<p>I am having some performance problems with a little R script of mine that I use to visualize simulation results of a <a href="https://github.com/mapa17/Eruliaf" rel="nofollow">project of mine</a>. It now takes longer on my machine to run the R script than the simulation itself, and I guess I am doing something wrong... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-05T20:59:43.720",
"Id": "17147",
"Score": "0",
"body": "Oh, didnt know about something like this existing. Is there a way to move the question?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-05T21:15:02.20... | [
{
"body": "<p>That's a lot of code to wade through. But after a quick look at your <code>processData</code> function, some things stand out. </p>\n\n<pre><code># This part:\nonline[i*2 +1] <- nrow( data[ (data$Tick == i) & (data$Type==\"Peer\"), ] )\ncompleted[i*2 +1] <- nrow( data[ (data$Tick == i) ... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-05T20:49:54.877",
"Id": "10747",
"Score": "1",
"Tags": [
"performance",
"r"
],
"Title": "Visualizing simulation results of a project"
} | 10747 |
<p>I have this simple object setup in JavaScript - <a href="http://jsbin.com/uqacop/11/edit#javascript,live" rel="nofollow">Full code on jsbin</a></p>
<p>I'll break it up below, but the question(s) -</p>
<ol>
<li>Does it break? I mean, I'm sure we can find a interesting case where this would be broken, but how much w... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-10T18:57:06.337",
"Id": "17165",
"Score": "1",
"body": "Have you looked at how something like coffeescript achieves this? I'm of the opinion that OO-style programming is usually a bad idea in javascript but when I need it I just write ... | [
{
"body": "<p>My perspective on your questions:</p>\n\n<ol>\n<li><p>It breaks when you want to change the behavior of all cats, since you do not store functions in the <code>.prototype</code> of the classes. Also, not using <code>.prototype</code> makes your code consume more memory.</p></li>\n<li><p>There is i... | {
"AcceptedAnswerId": null,
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-09T12:55:42.847",
"Id": "10749",
"Score": "6",
"Tags": [
"javascript",
"object-oriented"
],
"Title": "Improving a JS object \"framework\""
} | 10749 |
<p>I've added a function that checks if the user is trying to use/access something which requires a session. I'd love to hear some criticisms of my choice of design.</p>
<pre><code>class MY_Controller extends CI_Controller {
function __construct() {
parent::__construct();
if(!$this->input->i... | [] | [
{
"body": "<p>You don't really need to check for <code>is_logged_in</code>. If you destroy/build the session data correctly all you should care about is \"<em>Does a user id exist in the session?</em>\", then you can let your main controller handle the rest.</p>\n\n<pre><code>class MY_Controller extends CI_Con... | {
"AcceptedAnswerId": "10772",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-10T13:09:38.323",
"Id": "10750",
"Score": "1",
"Tags": [
"php",
"codeigniter"
],
"Title": "Handling session resources in MY_Controller with Codeigniter"
} | 10750 |
<p>I'm a not-really-recent-anymore graduate of Michigan Tech. I've been a cook since graduation and I'm an eensie teensie bit rusty in pretty much all my learnin'. Couple weeks ago I got hired on to help create an online learning system. Essentially, it's going to be an online school. I need to be able to have departme... | [] | [
{
"body": "<p>This is pretty minor but I wonder why Contact, HometownInfo are seperate tables. \nIf you have that information, it is assosiated with a single user via usr_id, so it may as well be in the same table as the other data assosiated with that user.\nOtherwise you risk orphan data in those tables after... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-10T14:57:16.907",
"Id": "10751",
"Score": "3",
"Tags": [
"sql",
"mysql"
],
"Title": "Online learning system database"
} | 10751 |
<p><a href="http://en.wikipedia.org/wiki/Adobe_ColdFusion" rel="nofollow">ColdFusion</a> is a commercial rapid web application development platform invented by Jeremy and JJ Allaire in 1995. ColdFusion is an Adobe product today.</p>
<p><a href="/questions/tagged/cfml" class="post-tag" title="show questions tagged ... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-10T20:41:31.900",
"Id": "10757",
"Score": "0",
"Tags": null,
"Title": null
} | 10757 |
ColdFusion is a commercial rapid web application development platform invented by Jeremy and JJ Allaire in 1995 and is now an Adobe product. The main programming language for ColdFusion is CFML. Use this tag for code that targets the ColdFusion platform, and also add the "cfml" tag if applicable. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-10T20:41:31.900",
"Id": "10758",
"Score": "0",
"Tags": null,
"Title": null
} | 10758 |
<p>Pvik is a lighweight PHP framework that uses the model, view, controller principle.</p>
<p><strong>-- EXAMPLE --</strong></p>
<p>Here is a very simple example how you build a website with the framework. <strong>I'm asking you if this is easy to understand or just for me because I know the framework and of course i... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-11T00:17:17.603",
"Id": "17172",
"Score": "0",
"body": "You'll have to move the code you want reviewed here."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-11T00:30:50.020",
"Id": "17173",
"Score":... | [
{
"body": "<p>Do not force developers to hand-code ModelTable subclasses (it is error-prone, monotonous, and time-consuming). Use PDO to automatically create base classes for all selected tables (entities) in the system. You could develop a web UI for table selection, column selection, and so forth. You could a... | {
"AcceptedAnswerId": null,
"CommentCount": "10",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-10T22:54:31.183",
"Id": "10761",
"Score": "5",
"Tags": [
"php",
"mvc"
],
"Title": "Pvik - a small PHP framework"
} | 10761 |
<p>The problem description is: </p>
<blockquote>
<p>You are given n types of coin denominations of values v(1) < v(2) <
... < v(n) (all integers). Assume v(1) = 1, so you can always make
change for any amount of money C. Give an algorithm which makes change
for an amount of money C with as few coins a... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-10T23:51:44.843",
"Id": "17169",
"Score": "0",
"body": "float are not good a representing monetary units (because of their precision (or imprecision (and thus rounding errors))). So it is best to use integers. So rather than store the ... | [
{
"body": "<p>Firstly, yes there are better solutions: see <a href=\"http://www.algorithmist.com/index.php/Coin_Change\" rel=\"nofollow\">http://www.algorithmist.com/index.php/Coin_Change</a></p>\n\n<pre><code>/*!\n * Find the largest value just below the change\n * remaining. Binary search results in O(lg n) l... | {
"AcceptedAnswerId": "10769",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-10T23:32:30.640",
"Id": "10762",
"Score": "4",
"Tags": [
"c++",
"algorithm",
"programming-challenge",
"change-making-problem"
],
"Title": "More optimal \"Making Change\" Probl... | 10762 |
<p>Is this going to leak memory or is it ok? Please also let me know if there is something else that I need to pay attention to.</p>
<pre><code>typedef struct
{
int len;
UC * message;
}pack;
pack * prepare_packet_to_send(const int length,const unsigned char tag,const int numargs, ... )
{
pack *layer= malloc(sizeo... | [] | [
{
"body": "<p>Yes and no.</p>\n\n<p>As you've used it here, I don't see a memory leak, so that would be a \"no.\"</p>\n\n<p>The function itself, however allocates memory without ever freeing it, so it's pretty much a memory leak waiting to happen -- the client code has to free the memory it allocates. Worse, fr... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-10T23:54:53.643",
"Id": "10763",
"Score": "1",
"Tags": [
"c",
"memory-management"
],
"Title": "Free memory outside function"
} | 10763 |
<p>This is a script that emulates a recycle bin in the CLI.<br>
You can undo your last changes and delete files</p>
<p>This is my first bash script so don't hesitate to bash me. Thank you for taking a look.</p>
<pre><code>#! /bin/bash
usage(){
cat << EOF
Sends and restores files to and from the recycle bin
U... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-11T07:17:36.833",
"Id": "17193",
"Score": "0",
"body": "Looks nice. I'd reconsider naming it `rm`. Something like `srm - safe remove` or `urm - undo-able remove` sounds better and you can also leave the command in place. If you'd overr... | [
{
"body": "<ol>\n<li>You don't need a space in the current shebang line. Anyway, <a href=\"http://mywiki.wooledge.org/BashGuide/Practices\" rel=\"nofollow noreferrer\">Greg's wiki</a> and <a href=\"https://unix.stackexchange.com/questions/32132/how-to-find-bash-in-a-portable-way\">others</a> recommend <code>#!/... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-11T03:08:59.483",
"Id": "10768",
"Score": "4",
"Tags": [
"bash"
],
"Title": "Bash script to send to recycle bin or trash"
} | 10768 |
<p>I have a Java class which accepts some data and reads it in as a raster of characters x by y. The class is used then to look for occurrences of a certain word in any direction of the raster and store them in a multidimensional array.</p>
<p>My code works, but I would like to see the code optimized because to me it ... | [] | [
{
"body": "<p>You could theoretically make it nicer by introducing <code>Iterator<></code> concept into the code. It would make your code more optimal from readability point of view but I doubt it would make the code more optimal from execution speed point of view. Your <code>Iterator<></code> inter... | {
"AcceptedAnswerId": "10777",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-11T07:41:35.650",
"Id": "10774",
"Score": "3",
"Tags": [
"java",
"optimization",
"search",
"lookup"
],
"Title": "Word lookup code optimization"
} | 10774 |
<blockquote>
<p><strong>Task:</strong></p>
<p>On an alphabet set [a-z], a simplified regular expression is much
simpler than the normal regular expression. </p>
<p>It has only two meta characters: '.' and '*'.</p>
<blockquote>
<p>'.' -- exact one arbitrary character match.</p>
<p>'*' --... | [] | [
{
"body": "<p>In answer to 1) - No. Consider the regex <code>*********a</code> and the string <code>b</code>. Your code will have to consider all 9! (362880) cases before returning false.</p>\n\n<p>That being said, this solution seems to be going in the right direction, and for this restricted language we can s... | {
"AcceptedAnswerId": "10880",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-11T09:11:27.463",
"Id": "10776",
"Score": "5",
"Tags": [
"java",
"algorithm",
"performance",
"regex",
"interview-questions"
],
"Title": "Simplified regular expression engi... | 10776 |
<p>Please review this implementation of thread-safe chache. </p>
<pre><code>public class StaticCacheImpl<T extends Entity> implements StaticCache<T>
{
private boolean set = false;
private List<T> cachedObjects = Collections.synchronizedList(new ArrayList<T>());
@Override
... | [] | [
{
"body": "<ul>\n<li>Your cache can only be initialised once with the put method (hence your <code>set</code> flag): why not use a constructor instead and get rid of the flag?</li>\n<li>If 2 items with the same UUID are identical and you only need to store one of them, using a map would simplify your design a l... | {
"AcceptedAnswerId": "10780",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-11T09:58:19.840",
"Id": "10778",
"Score": "4",
"Tags": [
"java",
"thread-safety",
"cache"
],
"Title": "Thread safe cache implementation"
} | 10778 |
<p>In order for me to get better and create more desired code, I would like to find out if the following situation is bad or acceptable. </p>
<p>I am creating an animation that gets triggered by two buttons, one on the left of a <code>JPanel</code> and the other on the right. Depending on which button is pressed, the ... | [] | [
{
"body": "<p>Depends on application design. What is \"more important\" - image, or button?</p>\n\n<p>It could be something like <code>move(Image image)</code> method in the buttons (decalred in interface of the buttons), or it may be <code>reactOn(Button button)</code> in Image.</p>\n\n<p>It is hard to recomme... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-11T11:20:41.560",
"Id": "10781",
"Score": "1",
"Tags": [
"java",
"image"
],
"Title": "Animation that gets triggered by two buttons"
} | 10781 |
<p>This is a short class to take screenshots on mutltiple monitor systems, I made some modifications to the solution at <a href="https://stackoverflow.com/questions/10042086/screen-capture-in-java-not-capturing-whole-screen">https://stackoverflow.com/questions/10042086/screen-capture-in-java-not-capturing-whole-screen<... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2015-02-16T20:20:06.853",
"Id": "146024",
"Score": "0",
"body": "Use and Area to \"add\" all the Rectangles together, it's a lot simpler and will give you the same result"
}
] | [
{
"body": "<p>I understand the need for descriptive variable names, but perhaps <code>numberOfMinutesToSleepBetweenScreenshots</code> is taking it a bit too far. Using something like <code>minsBetweenShots</code> or something like that is nearly as descriptive, and in the context of the other code will be clear... | {
"AcceptedAnswerId": "10814",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-11T13:06:51.647",
"Id": "10783",
"Score": "6",
"Tags": [
"java"
],
"Title": "Java screengrab"
} | 10783 |
<p>You can see each list item has multiple attributes data-whatever. The user will choose from a dropdown box on how things should be sorted and the appropriate method is called. Is <code>eval()</code> the most appropriate choice for this or is there a better way? </p>
<pre><code>$('#sort-options').change(function()... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-11T14:16:56.623",
"Id": "17206",
"Score": "0",
"body": "as a note, avoid calling jquery in your sort method. this will greatly slow down the sort process.... `return $(a).attr('data-breed') - $(b).attr('data-breed');` can be replaced w... | [
{
"body": "<pre><code>function makeSorter(sortType) {\n sortType = \"data-\"+sortType;\n return function (a, b) {\n return $(a).attr(sortType) - $(b).attr(sortType);\n };\n}\n\n$('#sort-options').change(function () {\n var sortType = $(this).val();\n var $selectedList = $($(\".drop-zone.ui... | {
"AcceptedAnswerId": "10790",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-11T14:10:36.087",
"Id": "10786",
"Score": "3",
"Tags": [
"javascript",
"jquery"
],
"Title": "Too many JavaScript sort functions to accomplish the same type of sorting"
} | 10786 |
<p>I am trying to go through the problems on CodeChef and came across this <a href="http://www.codechef.com/problems/COINS" rel="nofollow">problem</a>:</p>
<blockquote>
<p>In Byteland they have a very strange monetary system. Each Bytelandian
gold coin has an integer number written on it. A coin n can be
exchang... | [] | [
{
"body": "<p>If you don't want to recompute the overlapping sub-problems, you could use a cache.</p>\n\n<p>Create the cache in your class:</p>\n\n<pre><code>private HashMap<int, int> resultCache = new HashMap<int, int>();\n</code></pre>\n\n<p>Then check it at the top of the function:</p>\n\n<pre><c... | {
"AcceptedAnswerId": "10799",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-11T14:40:05.690",
"Id": "10787",
"Score": "3",
"Tags": [
"java",
"optimization",
"algorithm",
"programming-challenge"
],
"Title": "ByteLandian challenge from CodeChef"
} | 10787 |
<p>I'm trying to develop an algorithm that generates a 16-digit validation number to interact with a given system.</p>
<p>This is how the algorithm should be implemented:</p>
<p><img src="https://i.stack.imgur.com/QKwmh.png" alt="Validation Algorithm"></p>
<p>I have implemented it, and have it working with 2 of 3 te... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-11T15:12:06.977",
"Id": "17210",
"Score": "0",
"body": "What does yours return for the last case?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2015-06-18T11:15:31.707",
"Id": "171054",
"Score": "0",
... | [
{
"body": "<p>The algorithm seems to be fine, and if it does not fail the tests it should be OK (try to get more test cases though).</p>\n\n<p>Regarding the implementation:</p>\n\n<ol>\n<li><p><strong>Indentation</strong> - not sure if it just the site or you deliberately placed your curly braces the way they a... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-11T13:50:52.233",
"Id": "10791",
"Score": "2",
"Tags": [
"c#",
"algorithm",
"bitwise"
],
"Title": "Algorithm with byte shifts and BCD calculation"
} | 10791 |
<p>I'm trying to implement a function that given a data frame returns the same data frame with four columns added. These new four columns are: for each row, I get the maximum element and its index and put them as two new columns. I do the same with the second maximum element. I don't care if they are repeated.</p>
<p... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-11T15:41:19.917",
"Id": "17211",
"Score": "0",
"body": "`ifelse` is notoriously slow, but since its working on a single row it shouldn't be an issue. As far as you last question... is it fast enough for you?"
},
{
"ContentLice... | [
{
"body": "<p>Here's a faster way:</p>\n\n<pre><code>add_2maxFaster <- function(x)\n{\n imax1 <- which.max(x)\n imax2 <- which.max(x[-imax1])\n if (imax2 >= imax1) imax2 <- imax2 + 1L\n c(x, x[imax1], x[imax2], imax1, imax2) \n}\n\nset.seed(42)\nm <- matrix(runif(1e6), 1e4)\n\n# Compare sp... | {
"AcceptedAnswerId": "10797",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-11T15:32:01.997",
"Id": "10792",
"Score": "4",
"Tags": [
"r"
],
"Title": "Returning an existing data frame with four new columns"
} | 10792 |
<p>Question:</p>
<blockquote>
<p>You are given an array that represents bills in certain currency
(for example <code>1, 2, 5, 10</code>) and an amount, for example <code>17</code>. You should output
the number of possible combinations of bills that sum to the given amount.</p>
</blockquote>
<p>Answer: </p>
<... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-23T18:03:30.817",
"Id": "22524",
"Score": "0",
"body": "I assume this is somewhat theoretical problem, because for anything real-world A) you could make some assumptions, B) You are not likely to have to support Zimbabwean dollars that... | [
{
"body": "<p>You could do some dynamic programming solution.</p>\n\n<p>The basic idea of it in this situation would be you keep track of what you can get with just the 1 dollar bill, then figure out where you can reach with the 2 dollar bill, then the 5 dollar bill. (For the sake of example, I'll use a 7 doll... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-11T16:01:28.870",
"Id": "10793",
"Score": "3",
"Tags": [
"java",
"algorithm",
"interview-questions"
],
"Title": "Possible combinations of bills that sum to the given amount"
} | 10793 |
<p>I'm new to production code. And also I'm learning how to test code, I'll use the unittest module that comes with python to do that.
One more question, how can I make this code more safe?</p>
<pre><code> """
Sync your iTunes files with your Android
"""
import os, string, re, shutil
from ctypes import windll... | [] | [
{
"body": "<pre><code>\"\"\"\n Sync your iTunes files with your Android\n \"\"\"\n import os, string, re, shutil\n from ctypes import windll\n\n def get_drives():\n drives = []\n bitmask = windll.kernel32.GetLogicalDrives()\n</code></pre>\n\n<p>I'd call this drives_bitmask just to be a bit cleare... | {
"AcceptedAnswerId": "10801",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-11T16:58:08.770",
"Id": "10796",
"Score": "2",
"Tags": [
"python",
"unit-testing"
],
"Title": "Do I need to create more functions? And also, is this code difficult to unit test?"
} | 10796 |
<p>After recently reading up on and watching videos on OO PHP programming I have decided to convert my existing site into OO to gain some experience.</p>
<p>I have successfully (well, I think) converted a page into OOP and would like to know whether this is considered the proper way to implement OOP and whether this s... | [] | [
{
"body": "<p><strong>Design and style</strong></p>\n\n<p>As a general remark - choose your naming convention and use it consistently.</p>\n\n<p><em>Validation</em></p>\n\n<p>Public properties are always a bad thing</p>\n\n<pre><code>public $date2;\npublic $typeofnumber;\npublic $phonenumber;\n</code></pre>\n\n... | {
"AcceptedAnswerId": "10819",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-11T19:09:00.753",
"Id": "10800",
"Score": "2",
"Tags": [
"php",
"object-oriented",
"validation"
],
"Title": "Validating booking information"
} | 10800 |
<p>Is this best practice way to send messages to the user?</p>
<p>Update: This has been changed to a simple function call.</p>
<pre><code>/**
*Message - Sends message to the .innerHTML of an element
*/
var Message = ( function ()
{
var messages =
{
name: 'Please enter a valid name',
... | [] | [
{
"body": "<p>I don't really understand what you are asking here, but I'll give some general pointers:</p>\n\n<ul>\n<li><p>I find that you have two different variables called <code>Message</code> very confusing. </p></li>\n<li><p>It's not really a good idea to add proprietary properties to DOM elements. You sho... | {
"AcceptedAnswerId": "10850",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-11T22:52:18.023",
"Id": "10803",
"Score": "2",
"Tags": [
"javascript"
],
"Title": "Message Object - Best Practice? | Consider data attribute for pulling text in"
} | 10803 |
<p>I'm just getting my feet on the ground with Python (maybe 3 days now). The only issue with teaching my self is that I have no one to critique my work.</p>
<p>Correct me if I'm wrong but I think my algorithm/method for solving this problem is quite promising; but, the code not so much.</p>
<p>The program basically ... | [] | [
{
"body": "<pre><code>import os, re, urllib\n\ndef Read(url):\n</code></pre>\n\n<p>Python convention is to name function lowercase_with_underscores</p>\n\n<pre><code> uopen = urllib.urlopen(url)\n</code></pre>\n\n<p>I recommend against abbreviations</p>\n\n<pre><code> uread = ''\n for line in uopen: ur... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-11T22:36:19.000",
"Id": "10804",
"Score": "4",
"Tags": [
"python",
"beginner",
"web-scraping"
],
"Title": "Saving images from a web page"
} | 10804 |
<p>How could I make this path-finding code dynamic? This is to allow an agent to search the path on its own (from one corner of the grid to another) while hiding it until moved to the grid.</p>
<p>I am new to C++ and tried to write this program, but it appears to be static. I need to make it dynamic, or I could just... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-12T08:28:10.530",
"Id": "17237",
"Score": "0",
"body": "This belongs to stackoverflow."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-12T14:34:27.337",
"Id": "17241",
"Score": "1",
"body": "The... | [
{
"body": "<p><em>I'm going to try to review this in spite of the lack of decent indentation and whitespace (in some places). As such, I won't mention them below. I'd recommended improving on this first, as that will help you improve everything else.</em></p>\n\n<ul>\n<li><p>The <code>#include <...></co... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-12T00:20:22.063",
"Id": "10805",
"Score": "5",
"Tags": [
"c++"
],
"Title": "How could I make this path-finding code dynamic?"
} | 10805 |
<p><strong>library.php</strong></p>
<p>My own HTML tag encoder that will print HTML codes according to the input.</p>
<pre><code><?php
function tag($tagname, $content = NULL, array $properties = NULL)
{
$html = "<$tagname";
if (!($properties === NULL))
foreach ($properties as $n... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-13T19:40:16.077",
"Id": "17288",
"Score": "0",
"body": "I would just use the more readable one and put in a comment the smaller one, then on production versions I will uncomment them and minify the whole thing. And when tracking bugs o... | [
{
"body": "<p>There are several advantages to sticking with HTML and embedded PHP:</p>\n\n<ul>\n<li>You get appropriate syntax highlighting.</li>\n<li>You can take advantage of code-completion.</li>\n<li>The all-PHP method lacks proper indentation of HTML elements in the code and when rendered.</li>\n<li>The fi... | {
"AcceptedAnswerId": "10813",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-12T03:10:50.323",
"Id": "10809",
"Score": "22",
"Tags": [
"php",
"html"
],
"Title": "HTML tag encoder"
} | 10809 |
<p>I've written a package manager for OS X in order to improve my Python skills. This is the second programming project I've ever worked on, so I do not expect it to be great, or anything, but I would like to get some input on the code and overall design.</p>
<p>I store the package info inside a SQLite database, which... | [] | [
{
"body": "<pre><code>def install(self, pkg_id):\n \"\"\"\n This method takes a package id and installs the associated package. It\n does so by getting all the information from the database and calling\n different methods to perform the installation steps.\n \"\"\"\n self.resolve_dependencies(... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-12T10:19:19.573",
"Id": "10816",
"Score": "1",
"Tags": [
"python"
],
"Title": "Package Manager in Python"
} | 10816 |
<p>I have written the following get/set for a username which is stored in local Storage. Do you think this "buys" me anything or even perhaps has major disadvantages? I have never liked relying on global variables so I figured the getter and setter would be tidier and more maintainable. </p>
<pre><code>var namespac... | [] | [
{
"body": "<p>I think this is a matter of taste, I don't see any major disadvantages but no major advantages either. In these cases I would err on the side of simplicity and go with querying localStorage directly.</p>\n\n<p>Now to fully whet my morning CR.SE appetite let's get really nitpicky:</p>\n\n<ul>\n<li>... | {
"AcceptedAnswerId": "10822",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-12T13:35:47.110",
"Id": "10820",
"Score": "4",
"Tags": [
"javascript",
"html5",
"browser-storage"
],
"Title": "Getters and Setters for localStorage"
} | 10820 |
<p>The question asked to find all the prime numbers within a particular range. The way I approached this was to loop through each of the numbers within the range and for each number check whether it's a prime. My method for checking prime is to start at 3 and loop till number/2 in hops of 2 (essentially excluding all t... | [] | [
{
"body": "<p>Well, for starters, it is a proven mathematical fact that if a number is prime, it is not divisible by any prime number that is less than its square root. In your inner loop you go up to <code>i/2</code> and you can change this to <code>Math.floor(Math.sqrt(i))</code>.</p>\n\n<p>Because you are ch... | {
"AcceptedAnswerId": "10824",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-12T15:01:03.957",
"Id": "10823",
"Score": "8",
"Tags": [
"java",
"optimization",
"algorithm",
"primes"
],
"Title": "Yet another prime number generator"
} | 10823 |
<p>For various reasons, I'm parsing a string, this code will explain what I'm after:</p>
<pre><code>string baseString = "This is a \"Very Long Test\"";
string[] strings = baseString.Split(' ');
List<String> stringList = new List<string>();
string temp = String.Empty;
foreach (var s in strings)
{
if (... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-12T19:06:26.127",
"Id": "17247",
"Score": "2",
"body": "It's usually a bad idea to concatenate strings in a loop. If performance matters to you, you should probably use `StringBuilder` instead."
},
{
"ContentLicense": "CC BY-SA... | [
{
"body": "<p>Seems like a job for a regular expression:</p>\n\n<pre><code>string baseString = \"This is a \\\"Very Long Test\\\"\";\nvar re = new Regex(\"(?<=\\\")[^\\\"]*(?=\\\")|[^\\\" ]+\");\nvar strings = re.Matches(baseString).Cast<Match>().Select(m => m.Value).ToArray();\n</code></pre>\n\n<p>... | {
"AcceptedAnswerId": "10828",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-12T18:08:23.033",
"Id": "10826",
"Score": "3",
"Tags": [
"c#",
"strings",
"parsing"
],
"Title": "Splitting a string into words or double-quoted substrings"
} | 10826 |
<p>Can anyone suggest any improvements to this <code>RangeFinder</code> class?</p>
<pre><code>import serial
from collections import deque
def str2int(x):
try:
return int(x)
except ValueError:
pass
class RangeFinder(object):
def __init__(self, mem=3) :
self.mem = deque(maxlen=me... | [] | [
{
"body": "<pre><code>import serial\nfrom collections import deque\n\ndef str2int(x):\n try: \n return int(x)\n except ValueError:\n pass\n</code></pre>\n\n<p>returning <code>None</code> is rarely more useful then throwing the exception. Learn to love exceptions, and don't write functions li... | {
"AcceptedAnswerId": "10833",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-12T20:01:40.853",
"Id": "10830",
"Score": "1",
"Tags": [
"python",
"interval"
],
"Title": "RangeFinder class"
} | 10830 |
<p>I need help refactoring the javascript. <a href="http://jsfiddle.net/BDLYP/" rel="nofollow">http://jsfiddle.net/BDLYP/</a></p>
<p>I was able to hide and show fields, but I know this can be improved upon.</p>
<p>If #state is empty, hide #high-schools and #other_high_schools</p>
<p>If #state is picked, show #high-s... | [] | [
{
"body": "<p>I will give you a sample which is very simplified. I hope you can understand what I am doing here. </p>\n\n<p>HTML</p>\n\n<pre><code><select class=\"toggle-data\">\n <option></option>\n <option value=\"1\" data-toggle=\"#foo-one\">foo one</option>\n <optio... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-12T20:22:34.803",
"Id": "10831",
"Score": "0",
"Tags": [
"javascript",
"jquery"
],
"Title": "refactor javascript - show and hide fields based on current selection"
} | 10831 |
<p>I've decided to write a Chess engine in Ruby. The first step (before any move generation, AI, search trees, etc.) is to get a solid board representation so the computer and I can effectively communicate the game state to one another. The board representation I am using here is of the 64-bitstring variety. (I imple... | [] | [
{
"body": "<p>I would separate logic from presentation and I would write unit tests from begin on.</p>\n\n<p>I would split <code>display</code> in two methods:</p>\n\n<ul>\n<li><code>build_board</code> is creating a String or an Array</li>\n<li><code>display</code> writes the result of <code>build_board</code><... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-12T20:36:20.057",
"Id": "10832",
"Score": "4",
"Tags": [
"beginner",
"ruby",
"chess"
],
"Title": "Chess engine in Ruby"
} | 10832 |
<p>I have this search script on my page which search through the displayed table. The table is displayed with PHP from a database. It is actually a list, and this list is sorted out alphabetically with the help of hyperlinks of A to Z. Now I need to search the whole database instead of displayed ones. Any helps or reso... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-13T04:12:35.173",
"Id": "17259",
"Score": "0",
"body": "It seems like you are looking for someone to write some code for you rather than receive a review of what you have written. Code Review is for working code (it is not the right p... | [
{
"body": "<p>I am doing a review of the code, not answering your question which should be on stackoverflow and not codereview.</p>\n\n<pre><code>//$( function(){} ) is a short cut for ready!\n$(function() {\n //No reason to keep looking this up on every keypress, store it once and reuse\n var tableRows = ... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-12T21:29:40.660",
"Id": "10837",
"Score": "-2",
"Tags": [
"javascript",
"php",
"jquery",
"mysql"
],
"Title": "How can I improve my search script?"
} | 10837 |
<p>I have a model that I've created in Codeigniter to represent a vote. The purpose of the site that it's a part of is to allow users to vote on their preferred pronunciation for a given word.</p>
<p>The routine first checks to see if a user has registered a vote for the given pronunciation and if so, whether it was u... | [] | [
{
"body": "<p>You have some cut and pasted code which can be re-factored by comparing already_voted with the direction rather than with 'up' and 'down' specifically.</p>\n\n<pre><code>if ($already_voted === false) {\n $this->db->insert('vote', $data);\n return true;\n}\nelseif ($already_voted == $di... | {
"AcceptedAnswerId": "10845",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-13T01:22:27.560",
"Id": "10840",
"Score": "1",
"Tags": [
"php",
"codeigniter"
],
"Title": "Codeigniter vote routine review"
} | 10840 |
<p>I am trying to learn <a href="http://en.wikipedia.org/wiki/Prolog" rel="nofollow">Prolog</a>, and wrote a bibtex reader using GNU Prolog. </p>
<p>I would like some feedback on my code in terms of: the way I write Prolog, and how it can be improved. </p>
<p><a href="https://gist.github.com/2357257" rel="nofollow">G... | [] | [
{
"body": "<p>Quite nice! A few comments: First of all, consider using SWI-Prolog because it has more extensive libraries that you can use. In particular, consider using SWI's <a href=\"http://www.swi-prolog.org/pldoc/doc_for?object=section%282,%27A.19%27,swi%28%27/doc/Manual/pio.html%27%29%29\" rel=\"nofollow\... | {
"AcceptedAnswerId": "10950",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-13T01:39:04.260",
"Id": "10842",
"Score": "1",
"Tags": [
"parsing",
"prolog"
],
"Title": "Bibtex reader using Prolog"
} | 10842 |
<p>Take 4 (alteration based on feedback from Rainer Joswig):</p>
<pre><code>(defmacro with-gensyms ((&rest names) &body body)
`(let ,(loop for n in names collect `(,n (gensym)))
,@body))
(defmacro let-alist ((&rest lookups) alist &body body)
(with-gensyms (alist-form)
`(let ((,alist-form ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-13T04:00:10.607",
"Id": "17258",
"Score": "0",
"body": "Wow, that is remarkably similar (in concept, not in implementation) to [my `let-with` macro](http://codereview.stackexchange.com/questions/1398/is-this-a-good-way-to-implement-let... | [
{
"body": "<p>The main problem with it is <code>alist</code>- the variable of the macro.</p>\n\n<pre><code>CL-USER > (pprint (macroexpand-1 '(let-alist (:bar |foo| baz)\n (this-function-takes-a-long-time-or-has-side-effects)\n (list |foo... | {
"AcceptedAnswerId": "10890",
"CommentCount": "7",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-13T03:19:32.010",
"Id": "10843",
"Score": "2",
"Tags": [
"lisp",
"common-lisp",
"macros"
],
"Title": "with-alist-bind"
} | 10843 |
<p>I'm VERY new to error/exception handling, previously just echoing everything to screen, and am trying to really clean up my code. My goal was to log everything but only show the user a friendly "oops" page if something was seriously broken. How does what I have below look?</p>
<p>Any best practice advice is appre... | [] | [
{
"body": "<p>A few things jump out at me:</p>\n\n<ul>\n<li><p>The redirect of $e['type'] == 0:\nFor exceptions the default code is 0. Another code could be used and if the exception is not catched, it will throw a fatal error. Your handler does watch for fatal errors, so this may be a non-issue. The exception ... | {
"AcceptedAnswerId": "10861",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-13T04:12:29.573",
"Id": "10846",
"Score": "3",
"Tags": [
"php",
"error-handling"
],
"Title": "PHP error handling: log everything, and redirect critical errors to an \"oops\" page"
} | 10846 |
<p>I'm looking for a better implementation of the algorithm.</p>
<pre><code>/*
* You have an ordered array X of n integers. Find the array M containing
* elements where Mi is the product of all integers in X except for Xi.
* You may not use division. You can use extra memory.
*/
#include <iostream>
#include... | [] | [
{
"body": "<p>First, some comments on the existing code:</p>\n\n<pre><code>/*\n * You have an ordered array X of n integers. Find the array M containing\n * elements where Mi is the product of all integers in X except for Xi.\n * You may not use division. You can use extra memory\n */\n</code></pre>\n\n<p>You d... | {
"AcceptedAnswerId": "10859",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-13T05:43:31.347",
"Id": "10848",
"Score": "3",
"Tags": [
"c++",
"algorithm",
"programming-challenge"
],
"Title": "Product of all ints in array besides that an index i"
} | 10848 |
<p>Two words are anagrams of each other if they contain the same letters, such as "pots == stop".</p>
<p>The easiest way to check is to sort both words, then compare. But that's an \$O(n*log(n))\$ solution and I'd like to find an \$O(n)\$ one.</p>
<ol>
<li><p>Is this code \$O(n)\$? I only make one pass per string, bu... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-13T06:54:48.433",
"Id": "17263",
"Score": "0",
"body": "`Dictionary.Remove()` is O(1), in the average case."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-13T07:14:39.960",
"Id": "17264",
"Score": ... | [
{
"body": "<p>Yes, it's probably as fast as it gets (apart from a possible mistake that I'll explain). The <strong>average-case complexity</strong> of Remove is O(1), and it seems unlikely to me that you could skip any characters in a string since string comparison is O(n) and anagram checking is likely more co... | {
"AcceptedAnswerId": "10857",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-13T06:36:52.300",
"Id": "10849",
"Score": "5",
"Tags": [
"c#",
"interview-questions"
],
"Title": "Anagram Checker"
} | 10849 |
<p>I've written a small markov chain monte carlo function that takes samples from a posterior distribution, based on a prior and a binomial (Bin(N, Z)) distribution.</p>
<p>I'd be happy to have it reviewed, especially perhaps, regarding how to properly pass functions as arguments to functions (as the function <code>pr... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2015-07-27T04:41:55.547",
"Id": "179822",
"Score": "0",
"body": "is it possible to replace `binom.pmf` with some more simple implementation"
}
] | [
{
"body": "<h2>Function Passing</h2>\n\n<p>To pass functions with possibly varying argument lists consider using <a href=\"http://docs.python.org/release/2.5.2/tut/node6.html#SECTION006740000000000000000\" rel=\"nofollow\">argument unpacking</a>.</p>\n\n<p>By using a dictionary at the call site, we can use the ... | {
"AcceptedAnswerId": "10855",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-13T09:02:04.380",
"Id": "10851",
"Score": "3",
"Tags": [
"python",
"performance",
"markov-chain"
],
"Title": "Small Markov chain Monte Carlo implementation"
} | 10851 |
<p>I recently graduated from college and applied for a position with a company. I was sent a coding exercise as part of the process. After completing the exercise and submitting it I was told that the code provided the correct solution but was too hard to follow, the logic should be in the Course class, and "..due to r... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-14T10:14:13.900",
"Id": "17313",
"Score": "2",
"body": "Please read again the section on generics in a recent Java book. You have it wrong. `List prerequisites` should be `List<String> prerequisites`."
},
{
"ContentLicense": "C... | [
{
"body": "<p>Yes, this code is hard to follow. Some thoughts:</p>\n\n<ul>\n<li>use generics, e.g. <code>private List<String> prerequisites</code></li>\n<li>Provide useful constructors. E.g. Does a course without name make any sense? If not, the course name should be a constructor parameter</li>\n<li>hono... | {
"AcceptedAnswerId": "10867",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2012-04-13T11:37:23.963",
"Id": "10858",
"Score": "8",
"Tags": [
"java",
"sorting",
"interview-questions",
"graph"
],
"Title": "Reorder a list of courses, given their prerequisites"
} | 10858 |
<p>I have the following code that our users will use to embed a widget on their page:</p>
<pre><code>var ttp_number = "1Z123489754897";
var ttp_key = "1234567890123457890123";
var ttp_width = 850;
var ttp_height = 650;
var ttp_m_width = 260;
var ttp_m_height = 200;
(function(){
document.write('<div id="ttp">... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-13T18:50:15.497",
"Id": "17281",
"Score": "0",
"body": "What is the purpose of the setTimeout?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-13T18:55:02.493",
"Id": "17283",
"Score": "0",
"bod... | [
{
"body": "<ul>\n<li><p><strong>Don't make your code more compact, it's a futile exercise. Use a minifier or even a compiler/optimizer. Your source code should be as readable as possible</strong></p></li>\n<li><p><code>document.write</code> is evil, don't use it.</p></li>\n</ul>\n\n<p>Here's how I would write i... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-13T18:46:34.003",
"Id": "10872",
"Score": "1",
"Tags": [
"javascript"
],
"Title": "Embedding a widget to a page"
} | 10872 |
<p>I have been doing some personal projects for fun and most of them have visual representation of boards (ej: sudoku solvers, chess PGN viewer, etc) and I always end up doing something like this:</p>
<pre><code>var wid=10;
var hei=6;
var len=(wid*hei);
var map="00500020000000000800060000000600070000004000000050003040... | [] | [
{
"body": "<p>IMO you're right, using <code>join</code> would solve part of the problem (a global <code>replace</code> using a <code>RegExp</code> can also help, for instance converting the zeroes into spaces). I'd also suggest using something else to separate rows, this way you won't need the variables <code>w... | {
"AcceptedAnswerId": "10881",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-13T19:14:21.663",
"Id": "10875",
"Score": "4",
"Tags": [
"javascript"
],
"Title": "Array to Grid using a table"
} | 10875 |
<p>Prolog is a general purpose dynamically typed logic programming language associated with artificial intelligence and computational linguistics.</p>
<p>Prolog has its roots in first-order logic, a formal logic, and unlike many other programming languages, Prolog is declarative: the program logic is expressed in term... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-13T21:42:48.823",
"Id": "10876",
"Score": "0",
"Tags": null,
"Title": null
} | 10876 |
Prolog is a general purpose logic programming language associated with artificial intelligence and computational linguistics.
| [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-13T21:42:48.823",
"Id": "10877",
"Score": "0",
"Tags": null,
"Title": null
} | 10877 |
<p>I have the following PHP function, which is admittedly not quite as robust as it could be (I'm missing some sanity checks including a proper one for <code>$sendTo</code> for example; odd choices in text formatting, too) but I don't see why it shouldn't work. A version of it certainly worked the other day, though I m... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-14T08:43:59.830",
"Id": "17309",
"Score": "0",
"body": "No idea, the code looks ok. Well, I can post some paranoid ideas, but it seems to me that the problem is outside. Anyway, try `diff` and figure what have you changed actually?"
... | [
{
"body": "<p>Don't know if you wanted a full review or not so I supplied one since I was going over it anyways. Not really much wrong, mostly aesthetics. I could find no errors in your code, but maybe one of these fixes will ninja your problem away. You never know, the all-powerful PHP god's might be feeling b... | {
"AcceptedAnswerId": "11050",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-14T04:46:28.163",
"Id": "10882",
"Score": "5",
"Tags": [
"php",
"email"
],
"Title": "Sanity check for mail code"
} | 10882 |
<p>I was writing a program that used a bit of recursion with objects, and it wasn't working at all. After debugging I realized that JS's evil scope was playing nasty tricks.</p>
<p>To spare you guys a wall of <s>text</s> code, I wrote a smaller program:</p>
<pre><code>//Class definition and framework:
TestClass=funct... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-14T07:27:50.223",
"Id": "17307",
"Score": "2",
"body": "`x = foo` is global, `var x = foo` is local"
}
] | [
{
"body": "<p>\"<em>From this, I see that JS joins the scope of a function with a function (recursively) called in itself.</em>\"</p>\n\n<p>No, it doesn't. You created a global variable called \"r\", not a method variable, and so there is only one \"r\", and it is accessible to all your JavaScript code.</p>\n\... | {
"AcceptedAnswerId": "10904",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-14T07:03:21.893",
"Id": "10883",
"Score": "0",
"Tags": [
"javascript"
],
"Title": "JS scope of member functions"
} | 10883 |
<p><a href="http://scrapy.org/" rel="nofollow">Scrapy</a> is a fast open-source high-level screen scraping and web crawling framework written in python, used to crawl websites and extract structured data from their pages. It can be used for a wide range of purposes, from data mining to monitoring and automated testing.... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-14T08:19:35.430",
"Id": "10884",
"Score": "0",
"Tags": null,
"Title": null
} | 10884 |
Scrapy is a fast open-source high-level screen scraping and web crawling framework written in python, used to crawl websites and extract structured data from their pages. It can be used for a wide range of purposes, from data mining to monitoring and automated testing. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-14T08:19:35.430",
"Id": "10885",
"Score": "0",
"Tags": null,
"Title": null
} | 10885 |
<pre><code><?
$debug = (isset($_GET['debug']) && !empty($_GET['debug']))? $_GET['debug'] : false;
define('TYPE_A', 'A');
define('TYPE_O', 'O');
define('DEBUG_STAT', $debug);
//get params from $_GET or setup default value
$payment_type = ((isset($_GET['payment']) && !empty($_GET['payment'... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-14T17:28:17.653",
"Id": "17322",
"Score": "1",
"body": "I'm not even attempting to review uncommented code."
}
] | [
{
"body": "<p>I'll be honest, I just skimmed most of this. As GordonM said, it really should be commented, especially for such a large procedural file. If you are still watching this thread, here are a few things to look into.</p>\n\n<p><strong>WARNING</strong> Large wall of text ahead! <strong>WARNING</strong>... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-14T10:38:21.433",
"Id": "10886",
"Score": "1",
"Tags": [
"php"
],
"Title": "PHP report from order table"
} | 10886 |
<p>I am very new to Objective-C as well as objected oriented programming, and in a book I am studying from there is an exercise in which I was supposed to create a class called <code>Rational</code>, that has hidden data members called numerator and denominator, and methods to add, multiply, subtract and divide the Rat... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-12T03:08:14.117",
"Id": "17314",
"Score": "2",
"body": "Memory management *could* be the issue here; but can you give us a clear definition of what you mean by 'it becomes extremely slow'. Is this during the first pass, just in specifi... | [
{
"body": "<p>I just had a flash of inspiration, although possibly not related.</p>\n\n<p>What happens if you change this method signature:</p>\n\n<pre><code>-(void) printObject:(Rational *)fraction{\n\n printf(\"%i/%i\",fraction.numerator, fraction.denominator);\n\n printf(\"\\n\");\n}\n</code></pre>\n\n... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-12T02:59:51.773",
"Id": "10887",
"Score": "5",
"Tags": [
"performance",
"beginner",
"object-oriented",
"objective-c",
"rational-numbers"
],
"Title": "Rational class to handle... | 10887 |
<p>Can someone please critique my C++ sample here?</p>
<pre><code>#include <iostream> //console io
#include <string> //string handling
#include <algorithm> //transform
using namespace std;
struct to_upper {
int operator() (int ch)
{
return toupper(ch);
}
};
void encrypt_vigenere(c... | [] | [
{
"body": "<p><em><strong>Return Values</em></strong></p>\n\n<p>I would modify the encrypt and decrypt functions to return a string value rather than take a string reference.</p>\n\n<p>From a design point of view this bring several advantages:</p>\n\n<ol>\n<li>It never makes more sense to use the reference to p... | {
"AcceptedAnswerId": "10899",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-14T18:51:59.013",
"Id": "10894",
"Score": "18",
"Tags": [
"c++",
"vigenere-cipher"
],
"Title": "Vigenere encryption"
} | 10894 |
<p>This shows the minimum of letters needed for a palindrome. It needs tweaking since it works fine for words 1-9 characters, but becomes slow for words with 10-12 characters, and for 13+ characters it really takes a lot of time. Any help is appreciated.</p>
<pre><code>#include <stdio.h>
#include <conio.h>... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-14T18:17:46.993",
"Id": "17325",
"Score": "0",
"body": "I don't completely understand your approach. But it seems like it is doing more than necessary. Why so much string manipulation?"
},
{
"ContentLicense": "CC BY-SA 3.0",
... | [
{
"body": "<p>(Previous Answer removed)</p>\n\n<p><strong>UPDATE:</strong></p>\n\n<p>Now that I understand the problem better, I see that my previous answer is no good. I think you need a new algorithm. What you have currently is getting into a combinatorial explosion. Try using a string difference algorithm... | {
"AcceptedAnswerId": "10897",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-14T18:05:50.537",
"Id": "10896",
"Score": "3",
"Tags": [
"performance",
"c",
"palindrome"
],
"Title": "Showing the minimum of letters needed for a palindrome"
} | 10896 |
<p>When releasing objects that might have been retained during the app's lifetime, how do you check if the object really exists and prevent releasing a nil object?</p>
<p>Here's how I'm doing it:</p>
<pre><code>- (void)dealloc{
if(account_)
[account_ release];
account_ = nil;
[super dealloc];
}
</... | [] | [
{
"body": "<pre><code>- (void)dealloc{\n if(account_)\n</code></pre>\n\n<p>You don't need to do this. Objective-C ignores attempts to call methods on nil objects. So you call <code>release</code> and nothing will happen if its already nil</p>\n\n<pre><code> [account_ release];\n account_ = nil;\n</... | {
"AcceptedAnswerId": "10903",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-14T23:34:18.553",
"Id": "10900",
"Score": "1",
"Tags": [
"objective-c"
],
"Title": "Releasing retained objects inside dealloc"
} | 10900 |
<p>I have lots of classes that inherit from abstract base class, which has abstract method</p>
<pre><code>public class BaseClass<T>
{
protected abstract void GetItems();
}
</code></pre>
<p>each subclass have almost the same implementation</p>
<pre><code>protected override void GetItems()
{
// some prep... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-16T13:06:52.447",
"Id": "17382",
"Score": "1",
"body": "`GetItems` suggests that the method would return the object retrieved. Perhaps you want to call it \"PopulateItems\" instead, or something similar?"
},
{
"ContentLicense":... | [
{
"body": "<p>You can create an <code>abstract</code> method that will wrap the <code>GetXXXAsync()</code> method:</p>\n\n<pre><code>public class BaseClass<T>\n{\n protected void Getitems()\n {\n // some preparation code here which is the same for all sublcasses\n\n GetItemsInternal(a ... | {
"AcceptedAnswerId": "10907",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-15T11:00:17.983",
"Id": "10906",
"Score": "2",
"Tags": [
"c#",
"design-patterns"
],
"Title": "How to make this code fit into the base class"
} | 10906 |
<p>This code implements a data structure for representing a Sudoku board, a very simple algorithm for setting up the board, and a GUI written in tkinter(requires tkinter and tkinter.tix).</p>
<pre><code>#!/usr/bin/python
# Sudoku board code, and Sudoku board generation code.
# TODO:
# - Sudoku Solver
# - GUI Load/Save... | [] | [
{
"body": "<p>In general I think the code is clear, self-explanatory and well implemented. For some points that could use improvement:</p>\n\n<ul>\n<li><p><code>SudokuBoard.get_nearest_region</code></p>\n\n<ul>\n<li><code>make_index</code> is unnecessary, use <code>v // 3 * 3</code> instead (in case you don't k... | {
"AcceptedAnswerId": "10919",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-15T12:31:27.680",
"Id": "10908",
"Score": "5",
"Tags": [
"python",
"gui",
"sudoku",
"tkinter"
],
"Title": "Python Sudoku GUI"
} | 10908 |
<p>This is my first useful bash script. It's meant to make it easy to switch between a "work" hosts file (that blocks sites like reddit.com, youtube.com, etc.) and my normal hosts file, and also to allow me to easily add/remove sites I want to block.</p>
<p>I'm not sure if I'm doing everything right or securely, so pl... | [] | [
{
"body": "<p>I think this is generally clean.</p>\n\n<h2>Style Points</h2>\n\n<p>use <code>$()</code> instead of <code>``</code>, it's clearer and they can be nested.</p>\n\n<p>E.g:</p>\n\n<pre><code>if [[ \"$(whoami)\" != \"root\" ]]; then\n echo \"You don't have sufficient priviledges to run this script (... | {
"AcceptedAnswerId": "11057",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-15T15:38:12.703",
"Id": "10910",
"Score": "3",
"Tags": [
"security",
"bash",
"linux"
],
"Title": "Bash script to swap out, edit host files"
} | 10910 |
<p>I'm trying to put lots of buttons inside a div with a bunch of little windows that make content change in a neighbor div, but I’m quite new to jQuery and I'm sure that this code can be much simpler.</p>
<p>It works, but it's just that I can see it's too long and repetitive I'm sure that it can be downsized.</p>
<p... | [] | [
{
"body": "<p>It is very difficult to tell what you are trying to do from you code, but here is a very general example of a cleanup I would do on your code based on some assumptions.</p>\n\n<p><a href=\"http://jsfiddle.net/tgcNd/1\" rel=\"nofollow\">http://jsfiddle.net/tgcNd/1</a></p>\n\n<ol>\n<li><p>Combine yo... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-15T02:34:44.307",
"Id": "10914",
"Score": "2",
"Tags": [
"javascript",
"beginner",
"jquery",
"html"
],
"Title": "Inserting buttons inside a div"
} | 10914 |
<p>I just know there's a simpler, better way to do this. Will eventually append <select> options with these values (e.g. 01:30, 02:45, 10:15, etc.)</p>
<pre><code>var arrHours=[]
var i=0, j=0, k=0;
for (i=0;i<=23;i++)
{
for(j=0;j<=45;j=j+15)
{
var m,n;
m=i.toString();
n=j.to... | [] | [
{
"body": "<p>I would do it like this. Note how the zero-padding is encapsulated in a function and how the double loops are turned into a single loop by using modulo and integer division. Also, the <code>var</code>s are pre-declared as is considered good style in JavaScript.</p>\n\n<pre><code>function zeroPad(n... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-16T06:14:33.227",
"Id": "10922",
"Score": "2",
"Tags": [
"javascript",
"jquery"
],
"Title": "Is there a \"code less\" way to construct this JS loop?"
} | 10922 |
<p>I've searched plenty on this topic and have gotten a lot of good (but different) results. Some of the results weren't quite related and it does seem to be a matter of preference in the end, but <strong>I'm interested in if I'm following good design principles or not</strong>.</p>
<p><strong>If this is too vague of ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-25T05:55:56.547",
"Id": "96648",
"Score": "0",
"body": "When a user is unable to create an account because it already exists, you shouldn't throw an exception. I assume you know what you need to do in such scenario which would most lik... | [
{
"body": "<p>Thought I see many questions to different pieces of the code, I'll answer to the question about exceptions only.</p>\n\n<p>I believe this is not good use of exceptions (one exception, actually). You use it just to indicate a problem in a function that can return a special value. This is not \"exce... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-16T06:42:44.680",
"Id": "10923",
"Score": "1",
"Tags": [
"php",
"exception-handling",
"exception"
],
"Title": "PHP - Is this proper use of exceptions for error handling within classe... | 10923 |
<p>I've written some code to group a list of items into arbitrarily sized buckets. If the items are all the same and the and the count is a multiple of the bucket size a single bucket is returned, if the items are different then they are grouped into buckets of a given size.</p>
<p>For example, with a bucket size of ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-16T16:10:04.970",
"Id": "17386",
"Score": "0",
"body": "What should happen if you have something like `1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1` and why?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-16T16:15:38.5... | [
{
"body": "<p>I'm not sure you could make this code less clunky, it seems to me the code is reasonably simple, considering what it has to do.</p>\n\n<p>But I can see other problems in your code:</p>\n\n<ol>\n<li>The <code>comparer</code> parameter is probably not necessary in most cases, you can use <a href=\"h... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-04-16T15:42:05.457",
"Id": "10926",
"Score": "3",
"Tags": [
"c#"
],
"Title": "Grouping Similar Items into buckets"
} | 10926 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.