body stringlengths 25 86.7k | comments list | answers list | meta_data dict | question_id stringlengths 1 6 |
|---|---|---|---|---|
<p>I'd like this to be reviewed:</p>
<pre><code>public class MaxHeap<E extends Comparable<E>> {
private E[] heap;
private int capacity; // maximum size of heap
private int numberOfNodes; // number of nodes in current heap
/**
* Create a new MaxHeap object.
*
* @param heap
... | [] | [
{
"body": "<p>I haven't checked the details of the algorithm, just some general feedback on the code, API, etc:</p>\n\n<ol>\n<li><p>It's usually a good practice to make a copy of mutable input parameters. (<code>E[] heap</code> in this case.) It prohibits malicious clients to modify the heap's internal structur... | {
"AcceptedAnswerId": "42020",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-05T01:41:51.157",
"Id": "32269",
"Score": "6",
"Tags": [
"java",
"heap"
],
"Title": "MaxHeap implementation"
} | 32269 |
<p>I use this interface for my BST node class:</p>
<pre><code>public interface BinNode<E> {
public E getValue();
public void setValue(E value);
public BinNode<E> getLeftChild();
public BinNode<E> getRightChild();
public boolean isLeaf();
}
</code></pre>
<p>My BSTNode is implem... | [] | [
{
"body": "<p>When you have a custom implementation of something, and it has internal structures, like, in your case, the <code>BinarySearchTreeNode</code>, there is no real reason to have the interface for it. There is no public use of the interface, and not even your actual tree uses it. It is redundant. You ... | {
"AcceptedAnswerId": "40667",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-05T01:45:46.860",
"Id": "32270",
"Score": "3",
"Tags": [
"java",
"tree",
"binary-search"
],
"Title": "Generic binary search tree implementation"
} | 32270 |
<p>I am writing code for breadth-first search of a tree with C++'s STL. Please help as I am new to the STL.</p>
<pre><code>#include<iostream>
#include<malloc.h> //on llvm we don't need this
#include<list>
using namespace std;
typedef struct Node{
int val;
struct Node* left;
struct Node* ... | [] | [
{
"body": "<p>Don't use <code>malloc()</code>. If you do then you will need to track memory that is allocated with new and that allocated with malloc and use the appropriate de-allocation functions. Also using new calls the constructor and makes sure the object is correctly initialized.</p>\n\n<pre><code>#inclu... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-05T08:09:45.407",
"Id": "32276",
"Score": "0",
"Tags": [
"c++",
"memory-management",
"tree",
"stl",
"breadth-first-search"
],
"Title": "Breadth-first tree traversal using STL... | 32276 |
<p>This implements binary search on an array of cstrings. One thing I'm wondering about is it faster or slower to pass a variable as <code>const</code> i.e. len. Also <code>strcmp()</code> gets called a lot and since I can't find any specific details on how it works, is it worthwhile to make my own function? For exampl... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-05T08:31:12.100",
"Id": "51564",
"Score": "0",
"body": "This question appears to be off-topic because it is about trying to understand the code snippet and not about seeking a review."
},
{
"ContentLicense": "CC BY-SA 3.0",
... | [
{
"body": "<p>You can assume that the implementation of <code>strcmp()</code> is not stupid. A <em>lot</em> of code out there relies on <code>strcmp()</code>, so rest assured that a lot of work has gone into optimizing it. Nevertheless, you don't want to call it twice per iteration through your loop.</p>\n\n<... | {
"AcceptedAnswerId": "32278",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-05T08:16:19.720",
"Id": "32277",
"Score": "1",
"Tags": [
"c",
"binary-search"
],
"Title": "Binary search on cstrings"
} | 32277 |
<p>Here, this vector was used at many APIs in the code with sync block on it. And all the places they want to search another collection based on each <code>itr.next()</code>.</p>
<pre><code>synchronised(vector)
{
Iterator itr = vector.iterator();
while (itr.hasNext)
{
//Perform some search on anoth... | [] | [
{
"body": "<p>It looks like you are trying to re-invent the <a href=\"http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/CopyOnWriteArrayList.html\" rel=\"nofollow\">CopyOnWriteArrayList</a>.</p>\n\n<p>By the way, <code>Vector</code> is very old fashioned, but I guess you are working with legacy code... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-05T12:55:48.223",
"Id": "32280",
"Score": "1",
"Tags": [
"java",
"thread-safety"
],
"Title": "Synchronized block over concurrent collections"
} | 32280 |
<p>This Review Request evolves into <a href="https://codereview.stackexchange.com/questions/32348/kings-drinking-game-review-request-2-0-jform-gui">this Review Request</a> now with a custom UI and other changes.</p>
<p>I wrote a program to simulate the drinking card game Kings. This is my third Java Project. I didn't... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-06T00:54:39.903",
"Id": "51602",
"Score": "0",
"body": "If the game loop runs until the 4th king is drawn (per comments), then why is the loop condition `while(true)`? If the loop condition was based on the 4th king being drawn you wou... | [
{
"body": "<p>Your code has exceptionally tight coupling between the business code (the actual implementation of the game) and the user interface code. This means I can't easily reuse your code e.g. to play it on the command line instead of the GUI you have implemented.</p>\n\n<p>You can achieve this seperation... | {
"AcceptedAnswerId": "32284",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-05T13:19:38.437",
"Id": "32281",
"Score": "3",
"Tags": [
"java",
"optimization",
"game",
"collections",
"playing-cards"
],
"Title": "Kings Drinking Game"
} | 32281 |
<p>I have written this program to compute the leading set of the following productions</p>
<pre><code>E->E+T
E->T
T->T*F
T->F
F->(E)
F->#
</code></pre>
<p>Here identifier is taken as '#'</p>
<pre><code>#include<stdio.h>
#include<conio.h>
#include<ctype.h>
struct leadT
{
int n;... | [] | [
{
"body": "<p>You should structure your code a bit better and improve your naming conventions.</p>\n\n<p>The first loop in <code>main()</code> apparently scans 6 strings into <code>ip</code>. From that I might deduce that <code>ip</code> is supposed to hold your input. So name it <code>input</code> or even <cod... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-05T13:29:04.300",
"Id": "32282",
"Score": "0",
"Tags": [
"c",
"parsing"
],
"Title": "Computing leading set (compiler design)"
} | 32282 |
<p>I'm using Bootstrap 3 as the front-end framework for this. It is quite simple but I feel I'm doing it wrong. I'm sure this code can be optimized not to duplicate the $('a[href=""]') functions but I just can't wrap my head around it.</p>
<p>For now, this code is only for mobile. I'll have to figure out how to contro... | [] | [
{
"body": "<p>you can add some data attribute to the HTML like this </p>\n\n<pre><code><ul id=\"menuMain\" class=\"nav navbar-nav\">\n <li><a href=\"#preface\">Préface</a></li>\n <li><a href=\"#maison\">Maison Ilan</a></li>\n <li><a href... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-05T15:28:23.190",
"Id": "32288",
"Score": "1",
"Tags": [
"javascript",
"performance",
"jquery"
],
"Title": "Optimizing jQuery functions for mobile menu"
} | 32288 |
<p>I am doing old versions of the Canadian Computing Competition, on a website where I can run my solution against some test cases they have. I am failing one of their test cases, and cannot figure out why. I have no access to the test case.</p>
<p>I have posted below the full problem description as well as my attempt... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-05T18:47:11.033",
"Id": "51591",
"Score": "3",
"body": "I've voted to keep this open despite @BlackSheep's admission that it gives incorrect results, because it does give the correct output for the sample input. According to the [Help ... | [
{
"body": "<p>As far as I can tell, the only thing blocking your code from producing valid output is one line in <code>getRoads</code>. When loading the input, your code saves the <em>lowest</em> weight between two points rather than the <em>highest</em>.</p>\n<pre><code> if (M [from - 1][to - 1] < 0 || ... | {
"AcceptedAnswerId": "32357",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-05T17:00:35.983",
"Id": "32294",
"Score": "0",
"Tags": [
"c++",
"optimization",
"graph"
],
"Title": "2003 Canadian Computing Competition, Stage 1 ; Why Is My Solution Invalid?"
} | 32294 |
<p>I am trying to find the uncommon elements from two sets in Java. Here is my way:</p>
<pre><code>private void findUnCommon{
Set<Integer> a = new HashSet<>(Arrays.asList(1, 2, 3, 4));
Set<Integer> b = new HashSet<>(Arrays.asList(3, 4, 5, 6));
// get all elements from set a and set... | [] | [
{
"body": "<p>If data is ordered, as is the case in your example, you can use a merge-sort algorithm to do it while traversing each collection only once:</p>\n\n<pre><code> List<Integer> a = Arrays.asList(1, 2, 3, 4);\n List<Integer> b = Arrays.asList(3, 4, 5, 6);\n List<Integer> resu... | {
"AcceptedAnswerId": "32316",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2013-10-05T17:36:37.917",
"Id": "32297",
"Score": "3",
"Tags": [
"java",
"performance",
"set"
],
"Title": "Find the uncommon elements from two sets"
} | 32297 |
<p>I wrote a <code>FastReader</code> utility class that is supposed to read input fast. It's mostly aimed at parsing input files in competitive programming.</p>
<p>How could I made this better? I am mainly looking for good code suggestions rather than the specific details of the logic. Though, any comments/recommenda... | [] | [
{
"body": "<ol>\n<li><p>I'm always wary of naming my classes according to performance criteria. What if you (or someone else) finds a faster method of reading tokens from an input stream. Would you then write an <code>EvenFasterReader</code>? How about something like <code>TokenReader</code>?</p></li>\n<li><p>C... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-05T19:54:26.713",
"Id": "32302",
"Score": "4",
"Tags": [
"java",
"io"
],
"Title": "Simple I/O class for reading input data fast"
} | 32302 |
<p>I implemented an algorithm to solve a <a href="http://labs.spotify.com/puzzles/" rel="nofollow">constraint satisfaction problem</a>. It is a non-trivial one, so I do not intend to take your time with its details. I am mainly looking for good code suggestions rather than the specific details on the logic.</p>
<p>How... | [] | [
{
"body": "<p>I have not read your code in detail, but a lot of extra complexity comes from handling <code>Map<Vote, Set<Vote>></code>. I'm a big fan of guava's <a href=\"http://guava-libraries.googlecode.com/svn/tags/release03/javadoc/com/google/common/collect/Multimap.html\"><code>Multimap<K,... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-05T20:11:31.133",
"Id": "32303",
"Score": "7",
"Tags": [
"java",
"programming-challenge"
],
"Title": "Spotify Cat vs. Dog Challenge"
} | 32303 |
<p>I implemented the <code>FixedSizePriorityQueue</code> class. The intended purpose is that, you can add as many elements as you want, but it will store only the greatest <code>maxSize</code> elements.</p>
<p>I would like any suggestions on how to improve this data structure implementation. Any comments on how to mak... | [] | [
{
"body": "<p>Three things which seem questionable to me (I don't do much Java so I'm not entirely familiar with all the language features):</p>\n\n<ol>\n<li><p>You access the <code>private final priorityQueue</code> which is the backing data structure directly within <code>Song</code> (<code>songsQueue.priorit... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-05T21:29:45.043",
"Id": "32305",
"Score": "1",
"Tags": [
"java",
"queue"
],
"Title": "FixedSizePriorityQueue for storing a max number of elements"
} | 32305 |
<p>I have a <code>FaultType</code> <code>enum</code> with more than 100 members:</p>
<pre><code>public enum FaultType
{
FaultType1,
FaultType2,
FaultType3,
FaultType4,
FaultType5,
}
</code></pre>
<p>And I have a <code>FaultTypeConstants</code> <code>class</code> corresponding to <code>FaultType</c... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-10T15:59:42.517",
"Id": "93787",
"Score": "0",
"body": "If you can't assign the `int`s directly in the `enum`, why not put it in a `Dictionary<FaultType,int>`? What possible reason could there be for splitting this into an `enum` and a... | [
{
"body": "<p>Get rid of the constants entirely and assign those values to the enum members themselves.<br>\nYou can then use the enum everywhere.</p>\n\n<p>You can cast an enum member to <code>int</code> to get its numeric value.</p>\n",
"comments": [
{
"ContentLicense": "CC BY-SA 3.0",
... | {
"AcceptedAnswerId": "32312",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-06T00:30:14.397",
"Id": "32309",
"Score": "3",
"Tags": [
"c#",
"enum",
"constants"
],
"Title": "Managing fault types"
} | 32309 |
<p>I needed a utility function/method that would get the next available filename to save as.</p>
<p>An example would be, if I need to save a file as <em>MyTestFile.html</em> but it already exists.</p>
<p>This method would then check to see what the next availble filename would be, and it would return
<code>MyTestFil... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-06T04:24:52.643",
"Id": "51607",
"Score": "0",
"body": "What is a baseFile example when you call GetNextAvailableName()? I'm trying to understand better what it is you want to do - then I can comment on a better solution. Thanks."
},... | [
{
"body": "<p>Your current code finds \"holes\" in the numbering. If that is not required (or desired) then you could parse the numbers of the end and find the max and return max + 1. Something along these lines:</p>\n\n<pre><code>public string GetNextAvailableName(List<string> files, string baseFile)\n{\... | {
"AcceptedAnswerId": "32327",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-06T01:05:58.597",
"Id": "32313",
"Score": "8",
"Tags": [
"c#"
],
"Title": "Method to get next available filename"
} | 32313 |
<p>I wanted to try out F# so I decided to I converted a library file from c# to f#. I have done that successfully(thanks a you people in stackoverflow). At first I ported the code from c# to f#. Than I tried to covert the code into FP after a lot of pain I have managed to get this far.</p>
<p>Here is the Source Code f... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-06T17:43:07.370",
"Id": "51622",
"Score": "1",
"body": "Any chance you could post the entire code? There are a number of simplifications you could make to your code to improve the performance, but it's difficult to know which optimizat... | [
{
"body": "<p>To start, I see a few issues with the functional version of your code which are contributing to the performance loss:</p>\n\n<ul>\n<li>Whenever you need maximum performance, use arrays instead of <code>list</code> or <code>seq</code> (if feasible for your specific application). Functions operating... | {
"AcceptedAnswerId": "32334",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-06T07:20:51.423",
"Id": "32319",
"Score": "3",
"Tags": [
"performance",
"functional-programming",
"f#"
],
"Title": "Coding Functional style taking longer time than its Imperative ... | 32319 |
<p>I've been thinking about how to create a robust function that parses the command line arguments for valid filenames. I came up with a while-switch construct because that allows me to reduce redundancy (no break-statement at the end of case 2).</p>
<p>As I am pretty new to programming, I can't really tell the qualit... | [] | [
{
"body": "<p>This solution does not sit well with me. It looks like you're doing too much: checking how to take the input, taking input, and then checking whether that input worked all at once.</p>\n\n<p>Before looking at the code, though, it's worth asking whether this is really the interface that you want t... | {
"AcceptedAnswerId": "32323",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-06T08:46:30.733",
"Id": "32321",
"Score": "4",
"Tags": [
"c++",
"parsing",
"beginner",
"file"
],
"Title": "Parsing argv with while-switch construct"
} | 32321 |
<p>I'm working on my students attendance system project. I have a list of students along with their ID (<code>jntuno</code>) and I need to create a database in MySQL for storing the daily attendance of each student for each subject.</p>
<p><strong>Table:</strong> <code>students</code></p>
<p><strong>Fields:</strong></p... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2021-05-13T17:23:44.847",
"Id": "514557",
"Score": "0",
"body": "Please do not update the code in your question to incorporate feedback from answers, doing so goes against the Question + Answer style of Code Review. This is not a forum where y... | [
{
"body": "<ol>\n<li>Remove all the <code>11341xxxx</code> fields.</li>\n<li>Add another table consisting of the student-ID and the course-number (I suppose, those <code>11341A0501</code>) are course numbers.</li>\n</ol>\n\n<p>To make it even better, introduce another table <code>Courses</code> with an ID (<cod... | {
"AcceptedAnswerId": "32338",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-06T09:44:54.487",
"Id": "32322",
"Score": "2",
"Tags": [
"mysql",
"sql"
],
"Title": "Choice of tables for a project to handle attendance"
} | 32322 |
<p>I have a method to provide an <code>NSManagedObjectContext</code> using <code>UIManagedDocument</code>. I need to ensure that the <code>context</code> did initialize before I return, so I added an infinite while loop at the end of the method. But I think that was very stupid and is not acceptable. </p>
<pre><code>-... | [] | [
{
"body": "<p>Create and run operation using </p>\n\n<pre><code>NSOperation *op = [NSBlockOperation ... your block...];\n[[NSOperationQueue new] addOperation: op];\n</code></pre>\n\n<p>and instead of using a runloop, wait for the result:</p>\n\n<pre><code>[op waitUntilFinished];\n</code></pre>\n",
"comments... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-06T10:55:27.333",
"Id": "32324",
"Score": "4",
"Tags": [
"objective-c",
"ios",
"cocoa"
],
"Title": "Is there a better way to make sure a variable is initialized when using blocks?"
} | 32324 |
<p>I have a website written in PHP but the whole script is old so today I started upgrading from Mysql to Mysqli.</p>
<p>So here's my register page. I still have to add account confirmation and send mail part but that part can wait for now.</p>
<pre><code>/* PUBLIC */
$IP = $_SERVER['REMOTE_ADDR'];
/* PRIVATE */
if... | [] | [
{
"body": "<p>While it's great to see someone actually take the trouble to refactor code, to move away from the depreacted <code>mysql_*</code> extension, it's not so great to see that, like most, you're actually trying to use the replacement (<code>mysqli_*</code>) as a 1-on-1 copy of the old extension.<br/>\n... | {
"AcceptedAnswerId": "32331",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-06T14:35:24.033",
"Id": "32330",
"Score": "3",
"Tags": [
"php",
"mysqli"
],
"Title": "PHP Register Page ( MYSQLI )"
} | 32330 |
<p>Here is the implementation with the interface below:</p>
<pre><code>public class DoublyLinkedList<E> implements ListInterface<E>, ListIteratorInterface<E> {
private DoublyLinkedListNode<E> head;
private DoublyLinkedListNode<E> tail;
private DoublyLinkedListNode<E> cur... | [] | [
{
"body": "<p>1) I would rename <code>getValue()</code> in your iterator to <code>currentValue()</code> to make it consistent with <code>currentPosition()</code> and also to express in name what the comment says (get current item).</p>\n\n<p>2) I don't like how the <code>ListInterface</code> and <code>ListItera... | {
"AcceptedAnswerId": "32343",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-06T18:33:44.567",
"Id": "32335",
"Score": "1",
"Tags": [
"java",
"linked-list",
"interface"
],
"Title": "Can someone review my doubly linked list?"
} | 32335 |
<p>The following is working but I just want to know if I can make it better in any way.
The header file can be <a href="https://github.com/quinnliu/DataStructuresAlgorithmsDesignPatterns/blob/master/src/dataStructures/polynomialInC/Polynomial.h" rel="nofollow">viewed here</a>. </p>
<pre><code>#include <stdbool.h&g... | [] | [
{
"body": "<p><code>Polynomial_EvaluateAt</code> returns 0 if <code>P</code> is <code>NULL</code>. But I guess the function could also return 0 as part of a \"normal\" result (X == 0 for example). Not sure if it's important to distinguish between those two. You could consider returning a <code>bool</code> and p... | {
"AcceptedAnswerId": "32341",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-06T18:36:57.650",
"Id": "32336",
"Score": "1",
"Tags": [
"c",
"mathematics"
],
"Title": "Polynomial data structure"
} | 32336 |
<p>Can someone review this?</p>
<p>The header file can be <a href="https://github.com/quinnliu/DataStructuresAlgorithmsDesignPatterns/blob/master/src/dataStructures/rationalInC/Rational.h" rel="nofollow">viewed here</a>.</p>
<pre><code>#include <stdio.h>
#include <stdbool.h>
#include <math.h> // sea... | [] | [
{
"body": "<ol>\n<li><p>I like that you are treating your rationals as immutable by returning new rationals from all your operations.</p></li>\n<li><p>Your naming conventions are a bit unusual. In most C like languages (C, C++, C#, Java) local variables and parameters are <code>camelCase</code>. Specifically in... | {
"AcceptedAnswerId": "36949",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-06T18:38:23.047",
"Id": "32337",
"Score": "4",
"Tags": [
"c",
"rational-numbers"
],
"Title": "Rational implementation"
} | 32337 |
<pre><code>/**
* credential
*
* Easy password hashing and verification in Node.
* Protects against brute force, rainbow tables, and
* timing attacks.
*
* Cryptographically secure per-password salts prevent
* rainbow table attacks.
*
* Variable work unit key stretching prevents brute force.
*
* Constant time... | [] | [
{
"body": "<p>At first, disclaimer - I'm not a crypto expert so maybe another answer will be better than mine, but I hope that the my comments still will be useful.</p>\n\n<ol>\n<li>The code is not protected against incorrect values. So the property <code>keyLength</code> and <code>workUnits</code> may be unint... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-06T20:49:30.767",
"Id": "32346",
"Score": "6",
"Tags": [
"javascript",
"security",
"node.js"
],
"Title": "Can we improve this password hashing library for Node.js?"
} | 32346 |
<p>This request is a new version of this request: <a href="https://codereview.stackexchange.com/questions/32281/kings-drinking-game-review-request">Kings Drinking Game</a></p>
<p><strong>This version has a custom JForm GUI and almost all new methods.</strong></p>
<p><strong>GUI:</strong>
<img src="https://i.stack.img... | [] | [
{
"body": "<p>Why do you do? It seems redundant to me.</p>\n\n<pre><code>Collections.shuffle(cards, new Random());\nCollections.shuffle(cards, new Random(System.nanoTime()));\n</code></pre>\n\n<p>I would not put labels of card ranks and other labels to the enums. I would use <a href=\"http://docs.oracle.com/jav... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-06T21:28:15.693",
"Id": "32348",
"Score": "3",
"Tags": [
"java",
"optimization",
"game",
"playing-cards"
],
"Title": "Kings Drinking Game Review Request 2.0 JForm GUI"
} | 32348 |
<p>I wrote the following interface and class to bijectively map a string to a long. I would like feedback on how to make the code more readable and maintainable. </p>
<p><strong>Interface:</strong></p>
<pre><code>/**
* Bijectively maps a string consisting of chars from a predefined 'charSet' to a long value
* Bijec... | [] | [
{
"body": "<p><strong>The interface</strong></p>\n\n<ul>\n<li>Always try to keep methods on an interface to a minimum.Try to focus on what a client really needs.</li>\n</ul>\n\n<p>In you case this should suffice :</p>\n\n<pre><code>public interface StringAndLongConverter {\n public boolean isValidLong(final lo... | {
"AcceptedAnswerId": "32399",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-06T21:33:03.193",
"Id": "32349",
"Score": "2",
"Tags": [
"java"
],
"Title": "Review of String to Long bijection class - focus on readability/maintainabiliy"
} | 32349 |
<p>I am currently working on a Python project. It is some sort of a hub, where you can do some cool but basic stuff, such as: setting timers, launching websites, doing basic math, ping and view source codes of URLs, and more.</p>
<p>I want to make this code just a little more compact. I especially want my math menu m... | [] | [
{
"body": "<p>I would suggest using a <code>dict</code> as switch-statement like structure. </p>\n\n<p>First some global helper functions/data structures:</p>\n\n<pre><code>math_dict_binary = {'+': lambda a, b: a+b,\n '-': lambda a, b: a-b,\n # fill out the rest of you bina... | {
"AcceptedAnswerId": "32353",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-06T22:52:14.227",
"Id": "32350",
"Score": "2",
"Tags": [
"python",
"calculator"
],
"Title": "Calculator that is part of a multipurpose program"
} | 32350 |
<p>I am trying to find unique hashtags from a tweet that a user inputs. I have the code to find the number of times a word is used in the input, but I just need to know the number of different hashtags used. For example, in the input</p>
<pre><code>#one #two blue red #one #green four
</code></pre>
<p>there would be ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-07T00:31:29.623",
"Id": "51646",
"Score": "0",
"body": "You might consider using a [`Set<String>`](http://docs.oracle.com/javase/6/docs/api/java/util/Set.html) to hold the hashtags."
}
] | [
{
"body": "<p>If it is not program for one purpose and then you will throw it away i will not put to much code in main method. I would just initialize the application, inputs and outputs in main and than call start, run or some other method.</p>\n\n<p>Also represent tweet as an object with methods <code>Tweet#p... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-07T00:27:15.307",
"Id": "32352",
"Score": "-1",
"Tags": [
"java",
"array"
],
"Title": "Unique hashtag extracting"
} | 32352 |
<p>Please pick my code apart and give me some feedback on how I could make it better or more simple.</p>
<pre><code>final class Edge {
private final Node node1, node2;
private final int distance;
public Edge (Node node1, Node node2, int distance) {
this.node1 = node1;
this.node2 = node2;
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-07T06:54:33.293",
"Id": "279875",
"Score": "0",
"body": "It looks ok to me (did not review functionality). The only thing I can suggest is to use [validation](http://commons.apache.org/proper/commons-lang/javadocs/api-3.1/org/apache/co... | [
{
"body": "<ol>\n<li><p>In your <code>Edge</code> class <code>getAdjacentNode()</code> returns <code>node1</code> or <code>node2</code> regardless whether the parameter is one of the two. You should consider throwing an exception (<code>IllegalStateEeption</code> maybe) if the parameter is neither of them.</p><... | {
"AcceptedAnswerId": "32364",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-07T00:53:25.813",
"Id": "32354",
"Score": "7",
"Tags": [
"java",
"algorithm",
"graph"
],
"Title": "Implementation of Dijkstra's algorithm"
} | 32354 |
<p>I was wondering if anyone could give a critique of my code. We are supposed to be using inheritance and OOP principles. All the functions but the <code>PlayerSet</code> class were given, so really I just need someone to critique that class.</p>
<p>The full code is <a href="http://ideone.com/42iFSt" rel="nofollow">h... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-07T04:29:08.333",
"Id": "51657",
"Score": "0",
"body": "Use new style classes if you use Python 2.2+. I use to put the closing upper commas of a docstring in a new line, under the doc itself. This gives readability and kinda split's th... | [
{
"body": "<p>Do not create players in <code>__init__()</code>. Pass a list of players into constructor instead of count. This will make your class more flexible. Also you class should not be bound to the UI implementation, so do not read data from a user in <code>__init__()</code>.</p>\n",
"comments": [],
... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-07T03:59:23.093",
"Id": "32358",
"Score": "3",
"Tags": [
"python",
"object-oriented",
"game"
],
"Title": "\"Pass the Pigs\" game"
} | 32358 |
<p>I posted a couple questions about a week ago, but have almost gotten it working. This program is supposed to simulate the following: </p>
<ol>
<li>Ask the user how many balls to drop</li>
<li>Drop one ball at a time</li>
<li>Allow it to bounce ten times moving either once to the right or once to the left each bounc... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-07T14:37:29.230",
"Id": "51713",
"Score": "1",
"body": "So, what's the question? Is your code working the way you want it to? If not, then your question is off topic here."
}
] | [
{
"body": "<p><strong>Comments</strong></p>\n\n<p>You should use <code>//</code> comments for single-line comments.</p>\n\n<p>I am not sure you are using comments properly. Comments shouldn't explain how, it should explain why.</p>\n\n<pre><code>/* Prototype for drop_Balls, int parameter is number of balls bein... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-07T05:28:13.187",
"Id": "32361",
"Score": "3",
"Tags": [
"c",
"simulation"
],
"Title": "Bouncing-ball simulation"
} | 32361 |
<p>I wonder whether or not I should improve my current practice on creating/calling dialogs with AngularJS.</p>
<p>Think of a simple information, displayed on demand as a modal window. To create such a thing, I would write a directive, include it to my page and use <code>ng-hide</code> to hide it.</p>
<p>If I want to... | [] | [
{
"body": "<p>The disadvantage is the modal directive hanging around for no good reason in the templates, and a tight coupling between the controller and the modal directive.</p>\n\n<p>Far better is using a service to inject this modal into the DOM as needed.\nThis is the approach that for example the <a href=\... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-07T08:03:11.570",
"Id": "32367",
"Score": "1",
"Tags": [
"javascript",
"angular.js"
],
"Title": "Creating dialogs and modals with AngularJS"
} | 32367 |
<p>I have some C# unit tests which each basically perform the same steps but supply different arguments to the unit under test.</p>
<p>I wanted to encapsulate the logic inside some "helper methods" but found that the method names, while descriptive, were cumbersome. For example, the code inside a test method would loo... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-07T18:01:43.920",
"Id": "51728",
"Score": "0",
"body": "Which unit testing framework are you using? Many frameworks allow you to use multiple test cases on a single test method (e.g., NUnit's TestCaseAttribute), but the mechanism to d... | [
{
"body": "<p>The most canonical way of accomplishing what you want is to use the testing framework's functionality for writing data-driven tests, rather than writing a common helper method and then a number of separate tests which pass arguments into it.</p>\n\n<p>Different frameworks do this differently, so I... | {
"AcceptedAnswerId": "32431",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-07T11:39:13.287",
"Id": "32374",
"Score": "2",
"Tags": [
"c#",
".net",
"unit-testing"
],
"Title": "Encapsulated unit testing logic"
} | 32374 |
<p>I am trying to make a <strong>very fast hash table</strong> based set of <strong>pointers</strong>. It is supposed to be as fast as possible, not conforming to standard C++ at times. This is always marked in the code. Collisions are resolved by linear probing. The maximum size is known at construction time and memor... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-07T11:54:50.487",
"Id": "51672",
"Score": "4",
"body": "Never design your own hashing algorithm (mathematically it is very complex to get correct to avoid collisions). But a hint. Use prime numbers in its generation will help with prev... | [
{
"body": "<p>Find it hard to believe that std::fill is slower than std::memeset</p>\n\n<pre><code>/// The following line is nonstandard and should be:\n/// std::fill(arrays_[operatingArray_].begin(),\n/// arrays_[operatingArray_].end(), nullptr);\nstd::memset(&(arrays_[operatingArray_][0]),0,\n ... | {
"AcceptedAnswerId": "32378",
"CommentCount": "9",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-07T11:44:59.257",
"Id": "32375",
"Score": "0",
"Tags": [
"c++",
"performance",
"hash-map"
],
"Title": "Fast hash table based set of pointers"
} | 32375 |
<p>I have written a simple copy file code, called 'Amature SVN', kindly review my code. </p>
<pre><code>using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;
namespace AmatureSVN
{
public partial class Form1 : Form
... | [] | [
{
"body": "<p>There isn't much too review. A few thing things that can be improved are:</p>\n\n<ol>\n<li>Use <code>Path.Combine()</code> instead of building file paths manually.</li>\n<li>Use <code>String.Empty</code> instead of <code>\"\"</code>.</li>\n<li><p>Reduce nesting by inverting <code>if</code> stateme... | {
"AcceptedAnswerId": "32391",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-07T11:47:43.013",
"Id": "32376",
"Score": "3",
"Tags": [
"c#",
"optimization",
".net"
],
"Title": "Amature SVN review"
} | 32376 |
<p>I am trying to make an universal implementation of <code>IDisposable</code> (as a base class):</p>
<pre><code>public abstract class DisposableObject : IDisposable
{
private bool hasUnmanagedResources;
private bool baseDisposeManagedResourcesCalled;
private bool baseDisposeUnmanagedResourcesCalled;
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-07T13:16:38.273",
"Id": "51696",
"Score": "11",
"body": "You only get to pick one base class - I'd have thought it unlikely that gaining a good Disposable implementation would be the most pressing requirement for most interesting class... | [
{
"body": "<p>This abstraction is a <em>leaky abstraction</em> and should be avoided.</p>\n\n<p>As <a href=\"https://stackoverflow.com/a/2635733/1188513\">Mark Seeman puts it</a>:</p>\n\n<blockquote>\n <p>Consider why you want to add IDisposable to your interface. It's probably because you have a particular im... | {
"AcceptedAnswerId": "32411",
"CommentCount": "7",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-07T13:11:08.440",
"Id": "32380",
"Score": "7",
"Tags": [
"c#",
"design-patterns",
"inheritance"
],
"Title": "Dispose pattern - DisposableObject"
} | 32380 |
<p>I have a lot of classes which are principal equal, but they consist small differences so that I can´t abstract then very well.</p>
<p>The classes represent different kinds of DataTables. Every Class has two important methods which every "table-class" has. Here a abstracted example:</p>
<pre><code>internal class Fo... | [] | [
{
"body": "<p>I can think of trying something like this.</p>\n\n<pre><code>interface ICount\n{\n int count();\n}\n\nclass CountOne : ICount { int count() { return 1; }}\nclass CountTwo : ICount { int count() { return 2; }}\n\nabstract class IFooTable<T> where T : ICount, new()\n{\n int count() { return ... | {
"AcceptedAnswerId": "32402",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-07T13:39:48.540",
"Id": "32382",
"Score": "1",
"Tags": [
"c#",
".net",
".net-datatable"
],
"Title": "Find abstraction for classes which represent tables with differnt amount of co... | 32382 |
<p>I am doing a bio-statistics calculation and the following code works. However, can someone help to improve the messy nested loop?</p>
<pre><code>for(int i=0; i<NN; i++) {
for (int j=0; j<NN; j++) {
if (i != j){
thirdlayer = 0;
for (int k=0; k<NN; k++) {
f... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-07T18:20:23.453",
"Id": "51730",
"Score": "3",
"body": "This doesn't look like matrix multiplication. What are `V`, `J`, `pi_cod`, and `Transitions`? Why is `sqrt()` involved in matrix multiplication?"
},
{
"ContentLicense": "C... | [
{
"body": "<p>Give this a shot. Though I suspect your compiler <em>might</em> have been doing this already.</p>\n\n<pre><code>for (int j=0; j<NN; j++) {\n thirdlayer = 0;\n for (int k=0; k<NN; k++) {\n fourthlayer = 0;\n for (int l=0; l<NN; l++) {\n fourthlayer = fourthlayer + V[j*NN+l]*V... | {
"AcceptedAnswerId": null,
"CommentCount": "10",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-07T17:32:50.887",
"Id": "32384",
"Score": "1",
"Tags": [
"c++",
"optimization",
"c",
"statistics"
],
"Title": "Improve nested loop for bio-statistics calculation"
} | 32384 |
<p>I have the following code that I know can be written in a better way. Basically I query tables and display the results for each student for the homework that has been marked.</p>
<pre><code><?php
include 'inc/db_con.php';
mysql_select_db("homework", $con);
$resultcourse = mysql_query("SELECT course_code FROM c... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-07T19:33:32.183",
"Id": "51737",
"Score": "0",
"body": "I am thinking that you might want to look at an array for the `$score##` variables, not sure what all you are doing with those, but it looks like a good spot for an array. it woul... | [
{
"body": "<p>Your queries are only different in the type of homework they look for. Also the processing of the data seems common. The basic way to refactor code like this is to extract it into a method:</p>\n\n<pre><code>function getHomeworkScore($homework, $student)\n{\n $score = 0;\n $result = mysql_qu... | {
"AcceptedAnswerId": "32390",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-07T17:54:43.550",
"Id": "32385",
"Score": "1",
"Tags": [
"php",
"mysql"
],
"Title": "Code tidy-up for multiple queries"
} | 32385 |
<p>I have this class containing two constructors with different signatures but they do the same thing:</p>
<pre><code>public Person(Dictionary dictionary, string someString)
: base(dictionary, someString)
{
base.GetProperty("FirstName");
base.GetProperty("LastName");
}
public Person(Dictionary dictionary,... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-13T02:11:26.190",
"Id": "52159",
"Score": "0",
"body": "Why must there be 2 constructors? Why can't there be only one: `public Person(Dictionary dct, string[] something)`. Simpler, better for the client."
},
{
"ContentLicense":... | [
{
"body": "<p>Two things your could do:</p>\n\n<ol>\n<li><p>Refactor the common code into a method (like <code>Initialize</code>) and call that:</p>\n\n<pre><code>private void Initialize()\n{\n base.GetProperty(\"FirstName\");\n base.GetProperty(\"LastName\");\n}\n\npublic Person(Dictionary dictionary, st... | {
"AcceptedAnswerId": "32387",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-07T18:43:06.303",
"Id": "32386",
"Score": "5",
"Tags": [
"c#",
"casting"
],
"Title": "Different Constructors, Same Implementation"
} | 32386 |
<p>I'm not familiar with threads but I am not against them either. A bit of background the original program would have taken about 2 years to run. I had modified it and knocked down that time to around 40 days.</p>
<p>Can I make it even faster by using threads or updating my code?</p>
<p>The reason it is 40 days is... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-07T20:35:04.123",
"Id": "51740",
"Score": "0",
"body": "What version of .Net are you using?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-10T13:06:17.323",
"Id": "51990",
"Score": "1",
"body":... | [
{
"body": "<p>Let's fire up some threads in the form of .NET 4.0 TPL <code>Task</code>s. I also create your commands once and <code>Prepare</code> the statements, only updating the parameters. That should relieve some GC and pooled database connection pressure. See how this works for you. Here's the updated cod... | {
"AcceptedAnswerId": "32393",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-07T19:16:02.837",
"Id": "32389",
"Score": "5",
"Tags": [
"c#",
"performance",
"sql",
"file-system"
],
"Title": "Lattitude document organizer"
} | 32389 |
<p>In this scenario I've got a textbox to which I have added autocomplete functionality. The kicker is that I want to dynamically change the source option of the AJAX call based on the value of a dropdown list. To do this I encapsulated the differences between the AJAX calls in an object of type <code>Resolver</code>... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-08T09:52:42.390",
"Id": "51769",
"Score": "0",
"body": "You needn't, and probably shouldn't, call `JSON.stringify` when passing an object as the `data` property to jQ's `$.ajax`, jQ will do that for you"
},
{
"ContentLicense": ... | [
{
"body": "<p>One way to make it extensible is to make it reusable rather than stick it to one dropdown. You can even make it into a jQuery plugin so that it looks like this:</p>\n\n<pre><code>$('.someAutocompleteBox').dependentAutoComplete({\n\n /* the selector of the element to monitor changes */\n elementT... | {
"AcceptedAnswerId": "32415",
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-07T20:26:16.617",
"Id": "32392",
"Score": "1",
"Tags": [
"javascript",
"jquery"
],
"Title": "Dynamically changing autocomplete source option jQuery"
} | 32392 |
<p>I have a pretty interesting problem that I'm trying to solve, and I am kind of stuck.</p>
<p>I want to count the triplets of distinct combinations <code>a</code>, <code>b</code>, <code>c</code>, that are smaller than <code>LIMIT</code>have the following properties:</p>
<ul>
<li><code>a >= b</code>, <code>a >... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-07T22:18:51.017",
"Id": "51746",
"Score": "0",
"body": "This is Project Euler [problem 86](http://projecteuler.net/problem=86)."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-08T05:55:04.173",
"Id": "5... | [
{
"body": "<h3>1. Missing GCD</h3>\n\n<p>You didn't give the code for your <code>gcd</code> function, so I'll assume it's something like this:</p>\n\n<pre><code>def gcd(m, n):\n \"\"\"Return the greatest common divisor of positive integers m and n.\"\"\"\n while n:\n m, n = n, m % n\n return m\n</co... | {
"AcceptedAnswerId": "32422",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-07T20:39:17.567",
"Id": "32395",
"Score": "1",
"Tags": [
"python",
"algorithm",
"project-euler"
],
"Title": "Pythagorean number decomposition"
} | 32395 |
<p>I'm new to Haskell. I'm developing a game-like simulation. I try to use lenses to update the state of the world.</p>
<p>Current iteration of code works, but looks clumsy. I am trying to improve it, e.g. I would like to:</p>
<ol>
<li>Get rid of direct enumeration of <code>q1</code> and so on, with usage of <code>qu... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-08T23:10:23.483",
"Id": "51817",
"Score": "4",
"body": "I have taken the liberty to edit the question to make it more suitable for a code review, which I believe is what you were after."
}
] | [
{
"body": "<blockquote>\n <p>Get rid of direct enumeration of q1 and so on, with usage of quantityPolymorph and others in them. Problem is that partial application won't help since the function which gets applied is \"in the middle\" of arguments</p>\n</blockquote>\n\n<p>That's not a problem, you can do partia... | {
"AcceptedAnswerId": "32703",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-07T21:33:03.513",
"Id": "32397",
"Score": "2",
"Tags": [
"haskell"
],
"Title": "Usage of lens for concise update of records"
} | 32397 |
<p>I've decided to improve / test my knowledge so far, as I haven't coded in Java for a while now. Is there anything I can improve in my code? The OOP structure? The code itself? Useless code?</p>
<p>Main.java:</p>
<pre><code>import java.util.Scanner;
class Main {
/**
* A Simple question-an... | [] | [
{
"body": "<p>Strcuture your classes in packages.</p>\n\n<p>use <code>final</code> in this cases</p>\n\n<pre><code> private static ArrayList<Question> questions = new ArrayList<Question>();\n</code></pre>\n\n<p>I think it is not necessary to have <a href=\"http://martinfowler.com/eaaCatalog/dataTran... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-07T21:43:45.640",
"Id": "32398",
"Score": "0",
"Tags": [
"java",
"object-oriented"
],
"Title": "Q&A minigame structure"
} | 32398 |
<p>I am working on converting a mailing list that has longitude and latitude coordinates within the CSV file. This script I came up with does what I need, but this is my first real-world use of python. I want to know where I am making any mistakes, not using best-practices, and what can be optimized to make it faster.<... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-08T02:52:49.393",
"Id": "51753",
"Score": "0",
"body": "I like how you did not try to implement CSV parsing yourself."
}
] | [
{
"body": "<p>Two things that pop out for me immediately:</p>\n\n<ul>\n<li>You named a parameter \"file\", which is a built-in function in python.</li>\n<li>In one of your except blocks, you incorrectly use a dictionary.</li>\n</ul>\n\n<p>See below:</p>\n\n<pre><code>converted['city': '']\nconverted['state': ''... | {
"AcceptedAnswerId": "35719",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-07T23:38:59.250",
"Id": "32400",
"Score": "4",
"Tags": [
"python",
"csv",
"sqlite",
"geospatial"
],
"Title": "Converting latitude and longitude coordinates from CSV using web ... | 32400 |
<p>Example:</p>
<pre><code>try
{
thisFunctionThrowsAnException();
}
catch (someException e)
{
// handle this exception
}
</code></pre>
| [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-08T00:41:06.770",
"Id": "32403",
"Score": "0",
"Tags": null,
"Title": null
} | 32403 |
The keywords `try` and `catch` are used for exception-handling during program execution. The `try` block contains the code in which an exception occurs. The `catch` block "catches" and handles exceptions from the `try` block. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-08T00:41:06.770",
"Id": "32404",
"Score": "0",
"Tags": null,
"Title": null
} | 32404 |
<p>I have the code above in my iOS SDK that I am building that makes it easy for users of the SDK to make API calls. Basically, users can specify an API endpoint and easily make API calls.</p>
<p>Is there any way to improve the code above to make it more maintainable and easy for users? Is that the proper way to han... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2017-04-29T08:13:16.303",
"Id": "307705",
"Score": "0",
"body": "`NSURLConnection` is deprecated. You should use `NSURLSession` and not `NSURLConnection`. See https://developer.apple.com/videos/play/wwdc2015/711/"
}
] | [
{
"body": "<p>This code is nice for asynchronous web service calls. Instead of writing this method every controller of your project, I would suggest writing down this method in another class such as <code>ServerHandler</code>. This class may declare one protocol which will have 2 delegates.</p>\n\n<pre><code>(v... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-08T00:57:41.813",
"Id": "32405",
"Score": "4",
"Tags": [
"objective-c",
"ios",
"networking"
],
"Title": "Asynchronous networking iOS API calls"
} | 32405 |
<p><a href="http://en.wikipedia.org/wiki/Hash_table" rel="nofollow">Hash tables (wikipedia)</a> are part of the standard libraries for many languages:</p>
<ul>
<li>C++: <code>std::unordered_map</code></li>
<li>C# and other .net languages: <code>Dictionary</code></li>
<li>Java: <code>HashMap</code>, <code>ConcurrentHas... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-08T01:20:28.373",
"Id": "32406",
"Score": "0",
"Tags": null,
"Title": null
} | 32406 |
A hash table is a data structure used to implement an associative array (a structure that can map keys to values). It uses a "hash function" to compute an index into an array from which the value can be found. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-08T01:20:28.373",
"Id": "32407",
"Score": "0",
"Tags": null,
"Title": null
} | 32407 |
<h3>What is Boost?</h3>
<p><a href="http://www.boost.org/" rel="nofollow">Boost</a> is a large collection of high-quality libraries intended for use in C++. They are free and cover a large variety of categories. Boost is often considered a "second standard library", and many C++ problems are resolved by using Boost.</... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-08T01:27:49.430",
"Id": "32408",
"Score": "0",
"Tags": null,
"Title": null
} | 32408 |
Boost is a large collection of high-quality libraries intended for use in C++. Boost is free, and is often considered a "second standard library". | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-08T01:27:49.430",
"Id": "32409",
"Score": "0",
"Tags": null,
"Title": null
} | 32409 |
<p>Consider the below:</p>
<pre><code>public int DoSomethingComplicated(ComplicatedObject input)
{
try {
return input.Analyse();
}
catch(CustomExceptionOne ex1)
{
throw;
}
catch(CustomExceptionTwo ex2)
{
Log(ex2.Message);
return -1;
}
}
</code></pre>
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-08T19:46:31.093",
"Id": "51807",
"Score": "1",
"body": "You should consider logging the entire exception not just the message. Otherwise you throw away the stacktrace and it might be hard to find where it came from."
}
] | [
{
"body": "<p>You can refactor your code the following way:</p>\n\n<pre><code>public int DoSomethingComplicated(ComplicatedObject input)\n{\n try \n {\n return input.Analyse();\n }\n catch(CustomExceptionTwo ex2)\n {\n Log(ex2.Message);\n return -1;\n }\n}\n</code></pre>... | {
"AcceptedAnswerId": "32419",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-08T08:06:05.437",
"Id": "32418",
"Score": "3",
"Tags": [
"c#",
"exception-handling",
"exception"
],
"Title": "Compiler warning on unused exception...need to improve structure?"
} | 32418 |
<p>This is part of a class for paginating a Backbone collection.</p>
<p>The <code>paginateTo</code> method is for paginating to a model <code>id</code>. It returns the model if it's already in the collection, otherwise it checks with the server that it exists. If so, it requests subsequent pages until it's loaded into... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-11T04:16:52.063",
"Id": "52057",
"Score": "0",
"body": "What you you find complicated about it or what do you dislike about this code? The only thing I really dislike is that the internals of the `paginateTo` function are indirectly ex... | [
{
"body": "<p>You could do something like this</p>\n\n<pre><code>paginateTo: (id) ->\n deferred = new $.Deferred\n modelCheck = null\n\n modelExists = =>\n modelCheck or= @checkModelExists id\n\n fetchUntilFound = =>\n return deferred.resolve model if model = @get id\n modelExists().fail... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-08T13:30:34.533",
"Id": "32423",
"Score": "3",
"Tags": [
"javascript",
"jquery",
"coffeescript",
"backbone.js",
"pagination"
],
"Title": "Paginating a Backbone collection"
} | 32423 |
<p>This time I'm not here to ask for help with my code, but to ask you to judge my code. Where can I improve? What should I do better? Where did I do things wrong? </p>
<p>This is a quiz that I had to do as an assignment today. I'm not a professional. I'm still studying, and at the moment, I'm doing an internship.... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-08T17:02:29.007",
"Id": "51793",
"Score": "7",
"body": "Uh, well english variable names would be a good start. You won't see me (german) writing code like `gericht.beilage(new Sauerkraut()); gericht.beilage(new Knödel()); if (!achtung)... | [
{
"body": "<p>You should get into the habit of using English variable names and identifiers. English is the de facto standard language of programming and in most environments there will be people from different nationalities working with the code, and everyone must understand what the names mean. (There's alway... | {
"AcceptedAnswerId": "32436",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-08T16:13:17.353",
"Id": "32425",
"Score": "7",
"Tags": [
"javascript",
"jquery",
"html"
],
"Title": "What do you think about my questionnaire?"
} | 32425 |
<p>I'm looking for some general feedback about the layout and structure of my code. Basically just any feedback, as I'm not super happy about this code, but I'm not sure how to improve it further.</p>
<pre><code>'use strict';
/* jshint node: true */
var fs = require('fs');
var os = require('os');
var... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-08T18:51:41.833",
"Id": "51803",
"Score": "0",
"body": "What are you not happy about? This code looks good enough."
}
] | [
{
"body": "<p>You code looks good and well formatted. There are only a few minor issues:</p>\n\n<ul>\n<li>It seems that you have tried to check it with JSHint but there are some issues that JSHint reports about your code. In particular, semicolons and unused variables.</li>\n<li>It is not clear when the charact... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-08T18:39:56.623",
"Id": "32430",
"Score": "2",
"Tags": [
"javascript",
"node.js"
],
"Title": "Node.js backup cron job"
} | 32430 |
<p>In my game, there is a terrain generator subsequently resulting in many instances.</p>
<p>I have implemented this code:</p>
<pre><code>for b in blocklist:
if b.rect.left>=0:
if b.rect.right<=640:
screen.blit(b.sprite, b.rect)
</code></pre>
<p>It only renders things within the screen (40... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-09T01:43:02.367",
"Id": "51818",
"Score": "0",
"body": "Just changed the code to make it load each sprite one time, but it still runs quite slow!"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-09T03:16:35.... | [
{
"body": "<p>First of all, a lot of people who would answer this question will not do so because you can't just copy/paste the code and run it. The code depends on a lot of external files, like images and textfiles, and to run your code, you basically have to trial'n'error your way while creating a bunch of pl... | {
"AcceptedAnswerId": "32518",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-08T21:24:18.617",
"Id": "32434",
"Score": "5",
"Tags": [
"python",
"pygame",
"performance"
],
"Title": "Terrain generator in a PyGame game"
} | 32434 |
<p>I'm working on a writing platform and am using a modified version of <a href="http://en.wikipedia.org/wiki/Levenshtein_distance" rel="nofollow">the Levenshtein distance algorithm</a> to track a writer's engagement with their writing. It tracks not only words added to their content, but also rewards editing by includ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-10T02:40:07.310",
"Id": "51960",
"Score": "0",
"body": "Kindly provide some explanation of what you are doing here. For example, I assume from the Wiki you reference that you are using a dynamic programming approach and `matrix[i,j]` e... | [
{
"body": "<p>Ruby is fundamentally more about simplicity (readability) than about time/memory efficiency. Otherwise you should choose another language. There are such high level languages, that can beat Ruby, like for example Javascript. And even Python handle strings faster than Ruby at the cost of eternal pr... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-08T22:48:36.157",
"Id": "32437",
"Score": "2",
"Tags": [
"algorithm",
"ruby",
"strings",
"parsing",
"edit-distance"
],
"Title": "Is this the most efficient way to track word ... | 32437 |
<p>I have this annoying problem in PHP with faking overloading constructors. I understand the concept, but the code I produce feels kind of ugly. It isn't a lot of code, just bad code. Any ideas on how to make this sane?</p>
<pre><code>/**
* Instantiate Fencer object from user meta database.
*
* If fencer data doe... | [] | [
{
"body": "<p>It is a bad idea for a constructor to contain non-trivial code. \nConstructors should assign values to fields or another simple actions.\nIf you need complex initialization, you should use factory object or <a href=\"http://sourcemaking.com/design_patterns/factory_method\" rel=\"nofollow\">factory... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-08T23:05:31.960",
"Id": "32438",
"Score": "1",
"Tags": [
"php",
"object-oriented",
"constructor"
],
"Title": "Cleaning up PHP object constructors"
} | 32438 |
<p>There's a bit of a weird piece in my API that I'm not too happy about, but I can't seem to see any other way of going about.</p>
<p>It involves a <code>IFunctionalityFactory</code> abstract factory:</p>
<pre><code>public interface IFunctionalityFactory
{
IFunctionality Create();
}
</code></pre>
<p>An <code>IF... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-09T02:04:27.070",
"Id": "51822",
"Score": "2",
"body": "Small note, I'd make `private bool _canExecute;` in `FunctionalityBase` `readonly`."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-09T02:07:30.377",
... | [
{
"body": "<p>First: Don't create a base class with a virtual method which simply throws. This moves problem detection from compile time (abstract member not implemented won't compile) to run time (forgotten to override or accidentally called base throws) - usually undesirable. Virtual method says \"You can ove... | {
"AcceptedAnswerId": "32452",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-09T00:10:14.053",
"Id": "32440",
"Score": "11",
"Tags": [
"c#",
".net",
"dependency-injection",
"ninject"
],
"Title": "Having trouble with KISSing"
} | 32440 |
<p>I have written a PHP class called "graph". It is a class that performs RESTful-like commands to a MySQL database. I have posted the <a href="https://github.com/vealdaniel/graph" rel="nofollow">GitHub repo</a>.</p>
<p>Here is the code as well:</p>
<p>config.php</p>
<pre><code><?php
//standard database connecti... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-09T01:45:24.040",
"Id": "51819",
"Score": "0",
"body": "Looks clean but not sure about `mysql_*`. Users on newer versions of PHP are going to get deprecated warnings everywhere, I'd switch to PDO."
},
{
"ContentLicense": "CC BY... | [
{
"body": "<p>A few points:</p>\n\n<ol>\n<li>You should avoid <code>mysql_query</code>. It's deprecated. Use PDO or mysqli.\n<ul>\n<li>Read up on SQL injection attacks and use parametrized queries.</li>\n</ul></li>\n<li>Your indentation seems to be all over the place (not sure if that's a result of copy-n-paste... | {
"AcceptedAnswerId": "32442",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-09T01:42:26.067",
"Id": "32441",
"Score": "3",
"Tags": [
"php",
"mysql",
"classes",
"graph"
],
"Title": "Review/rate my new graph class"
} | 32441 |
<p>I'm trying to learn PHP/MySQL and the likes, so I've been reading tutorials for PHP login systems. My current iteration is based heavily on one from <a href="http://forum.codecall.net/topic/69771-creating-a-simple-yet-secured-loginregistration-with-php5/" rel="nofollow noreferrer">this website</a> and contains the a... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-09T06:21:08.953",
"Id": "51834",
"Score": "0",
"body": "The indentation doesn't look too good, make sure to convert tabs to spaces when copy/pasting if it looks correct in your editor."
},
{
"ContentLicense": "CC BY-SA 3.0",
... | [
{
"body": "<p>For hashing passwords, I use the code below. Note, I need to support running on older versions of PHP, so that is why I have the different checks for available features.</p>\n\n<pre><code>static function hashPassword($pwd) {\n $salt = self::secure_rand(16);\n $salt = str_replace('+', '.', base64... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-09T05:30:25.523",
"Id": "32443",
"Score": "3",
"Tags": [
"php",
"mysql",
"security"
],
"Title": "PHP MySQL login"
} | 32443 |
<p>I wrote 2 filters in C for the Altera DE2 Nios II FPGA, one floating-point and one fixed-point. I've verified that they perform correctly and now I wonder if you can give examples for improvement or optimization? I'll reduce the C library to a small library and turn on optimization, and perhaps you can suggest how t... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-09T13:48:02.017",
"Id": "51859",
"Score": "0",
"body": "Try using doubles. They might be faster on your platform."
}
] | [
{
"body": "<p>With the float version, I would make the <code>coef</code> parameter <code>const</code> and add <code>restrict</code> to both parameters. But that is unlikely to make much difference to speed.</p>\n\n<p>For the integer version, I would make the coefficients bigger than 8 bit. You lose a lot of t... | {
"AcceptedAnswerId": "32544",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-09T05:38:39.017",
"Id": "32444",
"Score": "5",
"Tags": [
"c",
"comparative-review",
"signal-processing",
"fpga"
],
"Title": "FIR filters in C"
} | 32444 |
<p>I have a file with just 3500 lines like these:</p>
<pre><code>filecontent= "13P397;Fotostuff;t;IBM;IBM lalala 123|IBM lalala 1234;28.000 things;;IBMlalala123|IBMlalala1234"
</code></pre>
<p>Then I want to grab every line from the <code>filecontent</code> that matches a certain string (with python 2.7):</p>
<pre><... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-09T09:52:58.180",
"Id": "51842",
"Score": "6",
"body": "In Python it's not possible to avoid backtracking in regexps. If you can't fix the problem by modifying your regexp, then try to use the non-regexp `str.split` on the large string... | [
{
"body": "<p><code>.*?;.*?</code> will cause <a href=\"http://www.regular-expressions.info/catastrophic.html\" rel=\"nofollow noreferrer\">catastrophic backtracking</a>.</p>\n<p>To resolve the performance issues, remove <code>.*?;</code> and replace it with <code>[^;]*;</code>, that should be much faster.</p>\... | {
"AcceptedAnswerId": "32450",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-09T07:47:42.643",
"Id": "32449",
"Score": "22",
"Tags": [
"python",
"performance",
"regex",
"csv",
"python-2.x"
],
"Title": "Regex to parse semicolon-delimited fields is t... | 32449 |
<p>I'm using a very lightweight <a href="https://github.com/grantschulte/accordion-lite" rel="nofollow">jQuery accordion</a> with some tweaks and it's working nicely. Is there anything to improve?</p>
<p><strong>JS</strong></p>
<pre><code>;(function($, doc, win) {
"use strict";
$.fn.accordionLite = function(... | [] | [
{
"body": "<p>This is awesome code,</p>\n\n<p>I would have added an s to <code>var trigger</code> since you are counting on more than 1 trigger.</p>\n",
"comments": [],
"meta_data": {
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-10-30T20:36:49.853",
... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-09T10:47:41.710",
"Id": "32459",
"Score": "3",
"Tags": [
"javascript",
"jquery"
],
"Title": "Lightweight accordion script"
} | 32459 |
<p>How could the following code be made more concise?</p>
<p><strong>HTML structure</strong></p>
<pre><code><body>
<header>
<ul id="main-nav">
<li></li>
<li></li>
<li></li>
</ul>
</header>
... | [] | [
{
"body": "<p>The only part of the code that changes are the index values. What if you don't specific the index yourself, but use the <a href=\"http://api.jquery.com/index/\" rel=\"nofollow\">indexof()</a> to let it determ the index itself:</p>\n\n<pre><code>var index;\n$('#main-nav li').on({\n mouseenter: f... | {
"AcceptedAnswerId": "32467",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-09T12:10:33.467",
"Id": "32465",
"Score": "0",
"Tags": [
"javascript",
"jquery",
"html"
],
"Title": "Specifying that one set of HTML elements controls a corresponding set"
} | 32465 |
<p>I have created a function in C on OSX in Xcode which captures the screen, adds the mouse pointer to the image, rescales the image to fit a certain width X height requirement, and puts the rescaled image in a "bounding box", and finally converts the image from RGBA to RGB.</p>
<p>Is there a kind and experienced OSX ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-09T12:34:00.060",
"Id": "51852",
"Score": "0",
"body": "Please include the code that you would like us to review in your question ([see here](http://codereview.stackexchange.com/help/on-topic))."
},
{
"ContentLicense": "CC BY-S... | [
{
"body": "<p>Please make everyone (including yourself) a favor :</p>\n\n<ul>\n<li><p>Declare your variable in the smallest possible scope. Also define them as your declare them if you can (and you usually can).</p></li>\n<li><p>Split your code into smaller entities - smaller functions, smaller structures, etc.... | {
"AcceptedAnswerId": null,
"CommentCount": "7",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-09T12:28:43.223",
"Id": "32466",
"Score": "2",
"Tags": [
"objective-c",
"cocoa",
"osx"
],
"Title": "Reviewing C function which captures the screen"
} | 32466 |
<p>This script creates an adhoc network using hostapd.
I have tested it and seems to work reliably.
I am new to linux networking and not sure if this is a recommended way to create an adhoc network this way.</p>
<pre><code>#!/bin/bash
#set -x
DEVICE=wlan0
CONFIG_FILE=./hostapd.conf
ConfigureDevice()
{
if ! sudo iw... | [] | [
{
"body": "<p>Not answering your actual question, but offering a couple of code comments:</p>\n\n<p>use <code>cd -- \"$(dirname -- \"$0\")\"</code></p>\n\n<ul>\n<li>if the script is in the PATH and someone just enters the script name, you will try to cd to the (probably non-existant) \"script name\" directory i... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-09T13:09:00.133",
"Id": "32470",
"Score": "2",
"Tags": [
"bash",
"linux",
"networking"
],
"Title": "Bash script to set up an ad hoc wireless network"
} | 32470 |
<p>Is there is a better way of selecting the span tag that I'm dynamically adding?</p>
<p>Here's what I'm trying to do:</p>
<p>If you click the <code>.toggle</code> div, it shows a detailed div with the <code>id</code> that matches the <code>href</code> of the anchor tag in the particular <code>.toggle</code> div.</p... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-09T13:33:50.850",
"Id": "32471",
"Score": "1",
"Tags": [
"javascript",
"jquery"
],
"Title": "Checking if a child element exists"
} | 32471 |
<p>I've just solve one problem that notifies users if their password is going to expire in 14 days. The script is working fine. I just want to improve my code and desire some suggestions.</p>
<pre><code>#!/usr/bin/env python
# Author :- Rahul Patil<linuxian.com>
#
import sys
import os
#----------------------... | [] | [
{
"body": "<p>You should read through the <a href=\"http://www.python.org/dev/peps/pep-0008/\" rel=\"nofollow\">Python Style Guide</a>. You code does not follow the naming conventions most Python code uses.</p>\n\n<hr>\n\n<p>Single letter variables should be used sparingly because they might not be as intuitive... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-09T14:02:29.203",
"Id": "32473",
"Score": "2",
"Tags": [
"python",
"beginner",
"ldap"
],
"Title": "Password expiry notification script"
} | 32473 |
<p>In C++11 we have the option of using <code>std::unordered_set</code> if we require a list of elements that have no duplicates but order is not important.</p>
<p>In C++03 we don't have this options, although we can use the <code>std::set</code> to achieve something similar. Let's consider the following code:</p>
<p... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-09T20:43:36.317",
"Id": "51905",
"Score": "3",
"body": "Using `std::NotEqualTo` is not valid. The comparator must generate a **strict weak ordering** for the code to work."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDa... | [
{
"body": "<blockquote>\n<p>My questions are:</p>\n<p>There are any potentially problems that could arise from using this construct?</p>\n</blockquote>\n<p>Its not valid.<br />\nThe code will not work as expected as the <code>std::set</code> requires the comparator type to generate a strict weak ordering betwee... | {
"AcceptedAnswerId": "32494",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-09T14:15:22.493",
"Id": "32475",
"Score": "4",
"Tags": [
"c++",
"c++03"
],
"Title": "Using set for unordered, unique list of elements"
} | 32475 |
<p>I have the code below:</p>
<pre><code><?php
$i = array(1, 2, 3);
$w = array(1 => '11', 2 => '22', 3 => '33');
foreach ($i as $f) {
$ws = $w[$f];
$file_names[] = array(
'fn' => 'fname',
'sn' => 'sname',
'is' => 'is',
'rv' => 'rv'
);
foreach... | [] | [
{
"body": "<p>maybe I am missing something, but why do you even need to have two different arrays $i and $w? second thing, <code>$file_names</code> array should go outside of the foreach loop since this array doesn't depend on the iteration of the first foreach loop.</p>\n\n<p>I am not sure about the exact outp... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-09T16:23:06.793",
"Id": "32482",
"Score": "2",
"Tags": [
"php"
],
"Title": "Add elements to an array inside a foreach loop"
} | 32482 |
<p>My database (SQL Server 2008) looks like this:</p>
<blockquote>
<p>People 1 -- * TaskPersons * -- 1 Tasks * -- 1 Project</p>
</blockquote>
<p>The <code>GROUP BY</code> part of the query is quite long, all because of the <code>COUNT</code> aggregate. This seems to perform reasonably well. I would like to know i... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-10T03:48:55.700",
"Id": "51964",
"Score": "1",
"body": "If you group by project title, and there is a one-to-one correspondence between projects and tasks, then won't the count of tasks be 1 for every row?"
},
{
"ContentLicense... | [
{
"body": "<p>Try putting <code>GROUP BY</code> in a sub-select.</p>\n\n<pre><code>SELECT personTaskProject.TaskCount,\n ppl.Name,\n ppl.Birthdate,\n ppl.Title,\n ppl.Role,\n ppl.Status,\n ppl.Warehouse,\n ppl.StartDate,\n ppl.SalaryBand,\n ppl.Sal... | {
"AcceptedAnswerId": "32548",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-09T16:55:03.323",
"Id": "32484",
"Score": "3",
"Tags": [
"sql",
"sql-server"
],
"Title": "Listing employees and their project tasks"
} | 32484 |
<p>The main purpose of Ruby is to be readable. I hope I did a good job with this gem I made. If there's any kind of suggestion of how to make this better, then please tell me.</p>
<pre><code>class Trigger
def initialize event, *callbacks
@callbacks = callbacks
@event = event
if @callbacks[0].is_a? TrueC... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-20T12:51:44.933",
"Id": "52707",
"Score": "0",
"body": "added an answer, but now that i check your console example, I think you have a mistake on your logic : when you pass in a symbol as a callback, the method will be called on the `T... | [
{
"body": "<p>Here a some suggestions for the first three methods:</p>\n\n<pre><code> def initialize event, *callbacks\n @callbacks = callbacks\n @event = event\n\n case @callbacks[0]\n when TrueClass\n @progression = true\n @callbacks.delete_at(0)\n when FalseClass\n @progression... | {
"AcceptedAnswerId": "32962",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-09T17:24:10.530",
"Id": "32485",
"Score": "3",
"Tags": [
"ruby"
],
"Title": "Triggerful Ruby Gem: create dynamic callbacks to methods"
} | 32485 |
<p>What would be the fastest way of skipping certain values in a for loop? This is what I intend to do in its most basic form, with about 20 more keys to omit.</p>
<pre><code>for (var key in arr ) {
if ( key != 'ContentType' && key != 'FileRef' ) {
arrayPushUnknown( columns, formatTitle( key ), tru... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-09T17:51:57.127",
"Id": "51884",
"Score": "2",
"body": "I'm a big fan of 'continue'. `if( wanting_to_skip_condition ) continue;` then the rest of the code you want run during a good loop."
},
{
"ContentLicense": "CC BY-SA 3.0",... | [
{
"body": "<p>There are several possible approaches:</p>\n\n<p>1) The straightforward:</p>\n\n<pre><code>function contains(array,element){\n return array.indexOf(element)!=-1;\n}\n\nfunction filter(unfilteredArray){\n var filteredArray=[];\n for(var i=0; i<unfilteredArray.length; i+=1){\n if(... | {
"AcceptedAnswerId": "32506",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-09T17:42:54.603",
"Id": "32486",
"Score": "2",
"Tags": [
"javascript",
"performance"
],
"Title": "Optimal way of skipping certain values in a for loop"
} | 32486 |
<p>I'm trying to write a short function which takes a list (<code>a</code>) and returns another list which only contains the elements (<code>x</code>) such that <code>-x</code> is also in <code>a</code>. I've done that, and it works, but it runs really slowly. I know why it does, and I know the second <code>for</code> ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-09T23:29:33.923",
"Id": "51917",
"Score": "0",
"body": "How big are your lists? How fast is this code? Can you provide some more details?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-09T23:32:29.213",
... | [
{
"body": "<p>For the sake of clarity, here is a solution that keeps duplicates and retains the original order of elements in <code>a</code>.</p>\n\n<pre><code>def negated_stable(a):\n '''Take a list a and returns another list which only contains the elements x such that -x is also in a'''\n b = set(a)\n ... | {
"AcceptedAnswerId": null,
"CommentCount": "16",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-09T23:27:54.207",
"Id": "32496",
"Score": "2",
"Tags": [
"python",
"performance"
],
"Title": "Returning elements in a list also found in another list"
} | 32496 |
<p>I wrote a bash completion script for the <code>cpupower</code> command but I feel that it sucks. It's too long for such a simple task and have too much case/if-else nesting.</p>
<p>It supports all the subcommands of <code>cpupower</code> and their options but not the values. It also support the incompatibilities be... | [] | [
{
"body": "<ol>\n<li><p>Yes this starts to look a bit like godzilla, no dealbreaker though.</p>\n</li>\n<li><p>Divide this bulk in several parts. Here some tips to get started:</p>\n</li>\n</ol>\n<hr />\n<ol>\n<li><p>Start moving all your variable declarations to a separate file which you will source. This is g... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2013-10-10T00:08:10.097",
"Id": "32499",
"Score": "4",
"Tags": [
"bash"
],
"Title": "cpupower bash completion script"
} | 32499 |
<p>I have tried to mimic Golang channels in C# and its performance is pretty good compared to golang itself. On my machine, each channel operation of Golang takes ~75 nano-sec and each <code>Chan<T></code> (in C#) operation takes ~90 nano-sec.</p>
<p>Please let me know if this code can be improved in any way.</p... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-09T23:55:56.770",
"Id": "51950",
"Score": "0",
"body": "Have you tried TPL Dataflow? I think `BufferBlock` is quite similar to Go channel."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-10T00:27:19.247",
... | [
{
"body": "<p>I would not use <code>SpinWait</code>, since this basically runs a small loop that checks the condition over and over again. This means a lot of CPU cycles are wasted. I would suggest a signalling construct like the <a href=\"http://msdn.microsoft.com/en-us/library/system.threading.manualreseteven... | {
"AcceptedAnswerId": "32521",
"CommentCount": "7",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-09T22:44:16.940",
"Id": "32500",
"Score": "14",
"Tags": [
"c#",
"go"
],
"Title": "Golang channel in C#"
} | 32500 |
<p>I just started with Python a month ago, and with Flask this week. <a href="https://github.com/mrichman/nhs-listpull" rel="nofollow">This</a> is my first project.</p>
<p>I am curious about general style, proper use of Python idioms, and Flask best-practices.</p>
<p><strong>run.py:</strong></p>
<pre><code>#!/usr/bi... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-10T01:02:28.890",
"Id": "32502",
"Score": "3",
"Tags": [
"python",
"flask"
],
"Title": "Providing a daily feed of current segmented customer data for targeted email campaigns"
} | 32502 |
<p>How can I most effectively refactor the code in these 2 <code>ViewController</code>s?</p>
<p>I'm familiar with subclassing in Objective-C and have used it extensively else where with <code>NSObject</code>s and <code>UIView</code>s, but I'm not sure how to approach doing so with <code>ViewController</code>s. </p>
<... | [] | [
{
"body": "<p>From your description your approach with two different ViewControllers seems about right. It <em>might</em> make sense to base them of another baseClass, but I find that too busy base-classes often reduce readability at the altar of reusing code. I guess this part boils down to your personal prefe... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-10T03:57:56.440",
"Id": "32509",
"Score": "5",
"Tags": [
"objective-c",
"ios"
],
"Title": "iOS App ViewController"
} | 32509 |
<p>I wrote this Ruby code that takes data from a survey. Seeing as it is my first Ruby project, I know it can be written much better. How could some of this code be written in more idiomatic Ruby? This code is extracted from a Rails model (the rest of the model is tame).</p>
<pre><code>def prepare_anova_data
n = s... | [] | [
{
"body": "<p>Thanks for posting your code. You've done a good job with:</p>\n\n<ul>\n<li>formatting</li>\n<li>variable and method names</li>\n<li>relatively small, focused methods</li>\n</ul>\n\n<p>You may be new to Ruby, but I don't think you're new to programming.</p>\n\n<p>There's not much to be improved h... | {
"AcceptedAnswerId": "39259",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-10T08:15:54.953",
"Id": "32511",
"Score": "5",
"Tags": [
"ruby",
"ruby-on-rails"
],
"Title": "Taking data from a survey"
} | 32511 |
<p>I'm writing a simple JavaScript game, which uses a 2-dimensional array as the main data structure. I wrote this function-class-thing that allows me to give any two integers, positive or negative. This class <em>should</em> "wrap" those integers back onto the game grid.</p>
<p>For example:</p>
<pre><code>var g = n... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-10T08:29:54.440",
"Id": "51972",
"Score": "0",
"body": "What should happen if x = -11 and width = 10?"
}
] | [
{
"body": "<p>I can't say, that my variant of normalize function is easier to understand, but at least it is linear and it works correct (as i think) with <code>x</code>, that is less than <code>-width</code> </p>\n\n<pre><code>this._normalize = function(x, y) {\n x = x % this._width;\n y = y % this._heig... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-10T08:21:09.803",
"Id": "32512",
"Score": "4",
"Tags": [
"javascript",
"array",
"game"
],
"Title": "2-dimensional \"wrapping\" array"
} | 32512 |
<p>Is this a good/correct way to write a robust C program?</p>
<pre><code>//File1 => Module1.c
static int Fun(int);
struct{
int (*pFn)(int)
}Interface;
static int Fun(int){
//do something
}
Interface* Init(void)
{
Interface *pInterface = malloc(sizeof(Interface));
pInterface->pFn = Fun;
return pInterfa... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-21T19:04:11.557",
"Id": "73071",
"Score": "0",
"body": "This question appears to be off-topic because it is primarily a design review."
}
] | [
{
"body": "<p>As it stands it won't compile. The <code>Interface</code> structure is not in a header file and so <code>main</code> has no knowledge of it. Also your <code>malloc(sizeof(Interface))</code> will not compile as C (C++ will be happy) as it needs <code>struct</code> before the <code>Interface</code... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-10T09:33:17.543",
"Id": "32516",
"Score": "2",
"Tags": [
"c"
],
"Title": "Making each module expose an interface"
} | 32516 |
<pre><code>$(document).on('dblclick', '#li', function () {
oriVal = $(this).text();
$(this).text("");
input = $("<input type='text'>");
input.appendTo('#li').focus();
});
$(document).on('focusout', 'input', function () {
if (input.val() != "") {
newInput = input.val();
$(this... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-11T03:54:49.987",
"Id": "52056",
"Score": "0",
"body": "Do not listen to such a ridiculous statement and instead have a look at these articles, they should greatly help you. http://alistapart.com/article/writing-testable-javascript\nht... | [
{
"body": "<p>I wasn't sure how to answer this, so I went with what your code does...</p>\n\n<ol>\n<li>Scope your variables.</li>\n<li>Change your code to target all <code>li</code> instead of one element with the id <code>li</code>.</li>\n<li>Use <code>this</code> when events are triggered to make sure you hav... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-10T11:00:22.300",
"Id": "32520",
"Score": "3",
"Tags": [
"javascript",
"jquery",
"object-oriented"
],
"Title": "Double click to edit and add new value to li"
} | 32520 |
<p>I'm working on mobile app which doing requests to a server's API. I want to develop module that doing following:</p>
<ul>
<li>get authorization key already exists in previous session</li>
<li>connect to server api and read server StatusLine answer code</li>
<li>if answer code is 403 then try to re authorize</li>
<l... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-11T04:53:16.067",
"Id": "52061",
"Score": "1",
"body": "It is common to name enum elements in capital case such as CHECK_ANSWER."
}
] | [
{
"body": "<p>I would consider the <a href=\"http://en.wikipedia.org/wiki/State_pattern\" rel=\"nofollow\">state pattern</a>. The actual state-dependent code could be handled in the enum.</p>\n",
"comments": [],
"meta_data": {
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"Cre... | {
"AcceptedAnswerId": "32534",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-10T14:24:36.190",
"Id": "32525",
"Score": "1",
"Tags": [
"java",
"session",
"state-machine"
],
"Title": "Performing API calls from a mobile client, reauthorizing the session if ne... | 32525 |
<p>I just finished a little game of Tic-Tac-Toe for a class I'm in, and I think it looks alright, but I'm pretty fresh, so I would like to know how I might be able to improve it, given the situation I'm in. I'd like to host it on my website and I'd like it to be safe and expandable.</p>
<p>Please let me know where I'... | [] | [
{
"body": "<p>To start with, you can eliminate all your global variables by putting your code in an anonymous function, and then immediate invoke that function: </p>\n\n<pre><code><script type=\"text/javascript\">\n(function () {\n // all of your code\n}());\n</script>\n</code></pre>\n\n<p>Note t... | {
"AcceptedAnswerId": "32650",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-10T15:05:41.027",
"Id": "32528",
"Score": "4",
"Tags": [
"javascript",
"game",
"html5",
"canvas"
],
"Title": "JavaScript Tic-Tac-Toe review: best practices, correctness, and a... | 32528 |
<p>At the request of my father, I've adapted some C# code he wrote which uses a timer to display the true and approximate solutions of the ODE y' = -lambda*y in real time to do the same in java and then graph the solutions using JFreeChart. The approximate solution is Euler's (first order) method. I don't have much pro... | [] | [
{
"body": "<p>Your Graph class does not compile in the line</p>\n\n<pre><code>double item = (double)in[1].get(i);\n</code></pre>\n\n<p>you cannot convert Object to double. <strong>You should make sure that the code compiles before you show it to code review</strong>. Other notes:</p>\n\n<ul>\n<li>You should not... | {
"AcceptedAnswerId": "32535",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-10T15:38:12.833",
"Id": "32531",
"Score": "1",
"Tags": [
"java",
"beginner",
"layout"
],
"Title": "How's my and my father's java ODE Solving and Graphing Program?"
} | 32531 |
<p>I have a requirement where there are 3 selection criteria user selects countries from a map displayed as lets say in 3 categories , i am maintaining 3 arraylist for the same.Each time he selects a country i have to display list of country names displayed in Alphabetical order in a bottom bar with font color distingu... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-11T00:24:24.887",
"Id": "52048",
"Score": "0",
"body": "Should that be a `+=` in here: `initalContent!=\"<font>\"+country+\"</font>\";`?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-11T03:49:24.890",
... | [
{
"body": "<p>There are many improvements that can be done, but here are a few things I identified:</p>\n\n<ol>\n<li>I wouldn't have the <code>require</code> call within the function itself. I would rather create a top-level module with all listed dependencies. The <code>updateBottomBar</code> function would be... | {
"AcceptedAnswerId": "32542",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-10T15:56:06.497",
"Id": "32533",
"Score": "1",
"Tags": [
"javascript",
"optimization",
"sorting"
],
"Title": "Sorting Each Entry (code review + optimization)"
} | 32533 |
<p>I have this <a href="http://en.wikipedia.org/wiki/Crazy_Eights" rel="noreferrer">Crazy Eights</a> game (which at the moment does not include crazy cards):</p>
<pre><code>class Card(object):
RANKS = ("2", "3", "4", "5", "6", "7", "8", "9", "T", "J", "Q", "K", "A")
SUITS = ("c", "d", "h", "s")
def __init... | [] | [
{
"body": "<p>Generally speaking, the code seems quite good. However, there are some parts that could be a little bit enhanced. I did not try to understand the whole thing, but I can give you some pointers.</p>\n\n<pre><code>for _ in range(cards):\n</code></pre>\n\n<p>The name name <code>_</code> is often impor... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-10T16:54:47.400",
"Id": "32537",
"Score": "7",
"Tags": [
"python",
"object-oriented",
"game",
"playing-cards"
],
"Title": "How object oriented is my Crazy Eights game?"
} | 32537 |
<p>I have the following JavaScript code to work out the angle between two points (clockwise). The code I have seems a bit "hacky" to me, as I have a while loop ensuring the number is not negative (to make the range 0-360), as well as I have to subtract 270 degrees to get it to work correctly. Is there a better way to d... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-10T17:19:15.400",
"Id": "52015",
"Score": "2",
"body": "The angle relative to what?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-10T17:20:06.383",
"Id": "52016",
"Score": "0",
"body": "@Shmid... | [
{
"body": "<p>First of all, let's define the problem precisely. According to your comment, this is the behavior you want:</p>\n\n<blockquote>\n <p>You are correct in believing I am expecting it to be relative to 12 o'clock, and for it to move clockwise.</p>\n</blockquote>\n\n<p>However, your code doesn't actu... | {
"AcceptedAnswerId": "32558",
"CommentCount": "10",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-10T17:06:11.830",
"Id": "32539",
"Score": "10",
"Tags": [
"javascript",
"computational-geometry",
"mathematics"
],
"Title": "Best way to work out angle between points?"
} | 32539 |
<p>The game I am working with is a block game. It generates terrain and then allows you to freely mine and place blocks as you wish (sound familiar Cx) BUT! there is a problem. I have a code that snaps the mouse to a 32x32 grid:</p>
<pre><code>mse=pygame.mouse.get_pos()
mse=(((mse[0])/32)*32,((mse[1])/32)*32)
cursrect... | [] | [
{
"body": "<p>Here are some suggestions to get you going:</p>\n\n<ul>\n<li>Don't keep blocks in the list. Perhaps, create some ordered structure (e.g. Grid) where you can easily insert or query blocks (and you'll need that for faster collision detection later on)?</li>\n<li>Create camera and decouple it, don't ... | {
"AcceptedAnswerId": "32560",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-10T20:47:29.200",
"Id": "32545",
"Score": "1",
"Tags": [
"python",
"pygame",
"mathematics"
],
"Title": "Pygame snap mouse to grid?"
} | 32545 |
<p>In a web application I am writing, I have used the following:</p>
<pre><code>def dbgmsg(lvl, fmt, ...):
if dbglvl >= lvl:
# ... format and write the message
pass # just here for correctness
</code></pre>
<p>Which is then used inside the code as:</p>
<pre><code>dbgmsg(3, "Something happened"... | [] | [
{
"body": "<ol>\n<li><p>It's going to take some time for Python to run the test <code>dbglvl >= lvl</code>. You can estimate the amount of time using the <a href=\"http://docs.python.org/3/library/timeit.html\" rel=\"nofollow\"><code>timeit</code></a> module. For example, on my computer,</p>\n\n<pre><code>&g... | {
"AcceptedAnswerId": "32600",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-11T05:43:35.563",
"Id": "32554",
"Score": "1",
"Tags": [
"python"
],
"Title": "Debugging based on a debug level without performance impact?"
} | 32554 |
<p>Here is a self imposed exercise and solution to learn Scalaz state monad. How can I refactor it to take it to the next level? So far I've only studied the state monad so would welcome suggestions on introducing other Scalaz features of relevance, as well as general Scala style/approach.</p>
<p><strong>Exercise</s... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2013-10-11T06:18:35.387",
"Id": "32555",
"Score": "2",
"Tags": [
"scala",
"monads",
"scalaz"
],
"Title": "Scalaz state monad exercise to model sampling of coloured balls"
} | 32555 |
<p>I have a couple of fields which I am trying to put together into a single <code>ByteBuffer</code> before storing it in a Cassandra database.</p>
<p>That byte array which I will be writing into Cassandra is made up of three byte arrays as described below:</p>
<pre><code>short employeeId = 32767;
long lastModifiedDa... | [] | [
{
"body": "<p>I cannot see anything wrong with the way you are using it. The example is a little contrived (given that you are not actually using cassandra), and the only things I can see that look odd are a direct result of that.</p>\n\n<p>Bottom line is that it appears to be a fine piece of code (which is per... | {
"AcceptedAnswerId": "36265",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-11T06:26:50.480",
"Id": "32556",
"Score": "12",
"Tags": [
"java",
"database",
"integer",
"cassandra"
],
"Title": "Storing a ByteBuffer into a Cassandra database"
} | 32556 |
<p>The code uses SQLAlchemy Core. However, what I want to know is if writing code in this pattern is recommendable.</p>
<pre><code>def saveUser(self, user):
"""
Inserts or updates a user in database.
The method first checks if the provided user's id already exists. If no, then the user will be inserted. Ot... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-12T13:25:39.150",
"Id": "52132",
"Score": "1",
"body": "You don't need to roll your own insert-or-update logic: SQLAlchemy has a [`merge`](http://docs.sqlalchemy.org/en/rel_0_5/session.html#merging) method."
},
{
"ContentLicens... | [
{
"body": "<p>The only thing I can think of that might make it more Pythonic would be to wrap the body of deleteUser() in a try and catch and handle the OperationalError rather than checking user and email for None before making the attempt.</p>\n",
"comments": [],
"meta_data": {
"CommentCount": "... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-11T07:11:02.247",
"Id": "32559",
"Score": "2",
"Tags": [
"python",
"sqlalchemy"
],
"Title": "Insert or update a user in database"
} | 32559 |
<p>Here's my first VBA project. I have some very limited Python experience, and this is my first VBA project. I'm sure I could have done it a lot more simply, but I just stuck with what I knew, and googled what I didn't, so feedback is very welcome.</p>
<p>The basic purpose is to compare a table from one sheet (OP) wi... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-11T18:40:05.523",
"Id": "52102",
"Score": "2",
"body": "We don't see line numbers, it's useless to refer to them ;). I suggest you break down this monolith into smaller chunks that do very little, ideally just one thing."
}
] | [
{
"body": "<ol>\n<li>Always put Option Explicit at the top of your modules (Tools - Options - Editor - Require Variable Declaration).</li>\n<li>Never select or activate something unless it's necessary</li>\n<li>Limit reading and writing to worksheets as it's an expensive operations</li>\n<li>When you have code ... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-11T10:31:27.923",
"Id": "32564",
"Score": "7",
"Tags": [
"vba",
"excel"
],
"Title": "Comparing tables and printing discrepancies"
} | 32564 |
<p>I would like to know your opinion about my simple JS/jQquery switcher. Is it a good idea to use <code>toggle()</code>?</p>
<pre><code>var s = $('.slider'), i = 0;
setInterval(function(){
var o = $([]);
o = o.add(s[i]);
if(i === s.length - 1) {
i = -1;
}
i++;
o = o.add(s[i]);
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-11T11:05:04.880",
"Id": "52077",
"Score": "1",
"body": "Why are you saving the options in the DOM and not in a JavaScript array? http://jsfiddle.net/D37qR/"
}
] | [
{
"body": "<p>I would strongly advise you to modularize your code to make it testable an reusable.</p>\n\n<p>Since you are using jQuery, you could use the <a href=\"http://learn.jquery.com/jquery-ui/widget-factory/how-to-use-the-widget-factory/\" rel=\"nofollow\">widget factory</a>.</p>\n\n<p>I have created an ... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-11T10:51:33.527",
"Id": "32565",
"Score": "2",
"Tags": [
"javascript",
"jquery"
],
"Title": "JS/jQuery switcher"
} | 32565 |
<p>I'm working on a program that handles UTF-8 characters. I've made the following macros to detect UTF-8. I've tested them with a few thousand words and they seem to work.</p>
<p>I'll add another one to do error-checking later, but for now I would like to know what mistakes I've made and how these macros can be impr... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-13T08:45:43.200",
"Id": "52173",
"Score": "1",
"body": "I'd make the brackets consistent: add some extra brackets to the first two macros to make all comparisons match the first one. The first has the form `((b) >= 192)` whereas the re... | [
{
"body": "<p>If you are sure that you have only valid encoded UTF8, you can simplify</p>\n\n<pre><code>#define IS_UTF8_BYTE(b) (IS_UTF8_LEADING_BYTE(b) || IS_UTF8_SEQUENCE_BYTE(b))\n</code></pre>\n\n<p>to</p>\n\n<pre><code>#define IS_UTF8_BYTE(b) ((unsigned char)(b) >= 128)\n</code></pre>\n\n<p>because ever... | {
"AcceptedAnswerId": "32569",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-11T11:15:53.327",
"Id": "32567",
"Score": "4",
"Tags": [
"c",
"macros",
"utf-8"
],
"Title": "Macros to detect UTF-8"
} | 32567 |
<p>I'm trying to write Jasmine tests and I need a review and some advice on spying on events and their behavior.</p>
<pre><code>// my example source code
;(function () {
var app = {
exampleModuleName: {
navigateTo: function () { /* do something */ }
},
navigation: {
init: function () {
... | [] | [
{
"body": "<p>From a once over:</p>\n\n<ul>\n<li><p>I would drop this test, you are testing Jasmine and/or the test, but not the results of calling <code>app.navigation.init()</code></p>\n\n<pre><code>it ('spy on behavior', function () {\n var spy = spyOn(app.navigation, 'init');\n app.navigation.init();\... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-10-11T14:21:11.977",
"Id": "32573",
"Score": "5",
"Tags": [
"javascript",
"jquery",
"jasmine"
],
"Title": "spyOn click events and check call function"
} | 32573 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.