body stringlengths 25 86.7k | comments list | answers list | meta_data dict | question_id stringlengths 1 6 |
|---|---|---|---|---|
<p>I need to call an <code>upsert</code> to my Category table in PostgreSQL. My current solution uses the <code>exec_query</code> API in ActiveRecord, using binding.</p>
<p>What I got so far looks like this:
<strike>
</p>
<pre><code>VERIFY_CATEGORY_SQL = <<SQL
WITH sel AS (SELECT id FROM categories WHERE name... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-09T10:41:50.150",
"Id": "70826",
"Score": "1",
"body": "In regular `PostgreSQL` you could just re-use `$1` and `$2`; try it with `PREPARE` then `EXECUTE` in `psql`. So if you can't here, it's a Rails or Pg gem limitation. My main conce... | [
{
"body": "<p>Statement, formatted readably:</p>\n\n<pre><code>WITH \nsel AS (\n SELECT id FROM categories WHERE name=$1 AND source=$2\n),\nins AS (\n INSERT INTO categories (name, source, created_at, updated_at )\n SELECT $1, $2, 'now', 'now'\n WHERE NOT EXISTS (SELECT * FROM sel) \n RETURNING id\n)\nSEL... | {
"AcceptedAnswerId": "41306",
"CommentCount": "7",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-09T07:16:20.767",
"Id": "41277",
"Score": "5",
"Tags": [
"ruby",
"sql",
"postgresql",
"active-record"
],
"Title": "How to properly call an \"upsert\" using parameterized raw S... | 41277 |
<blockquote>
<p>Rewrite <code>readlines</code> to store lines in an array supplied by main, rather than calling <code>alloc()</code> to maintain storage. How much faster is the program?</p>
</blockquote>
<p>Here is my solution:</p>
<pre><code>int readlines(char **lineptr, char *storage, int maxlines, int storage_si... | [] | [
{
"body": "<p>I don't know what <code>_getline</code> is; perhaps it's something like <a href=\"http://www.gnu.org/software/libc/manual/html_node/Line-Input.html\" rel=\"nofollow\">the file-input function described here</a>.</p>\n\n<hr>\n\n<p>This looks strange ...</p>\n\n<pre><code>int nlines;\n\nnlines = 0;\n... | {
"AcceptedAnswerId": "41297",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-09T10:03:13.523",
"Id": "41280",
"Score": "7",
"Tags": [
"c",
"beginner",
"pointers"
],
"Title": "Storing lines in an array"
} | 41280 |
<p>I've written a custom binding for KnockoutJS which renders <code><select></code> elements with <code><optgroup></code> children.</p>
<p>When run, this binding adds <code><optgroup></code> and <code><option></code> DOM elements.</p>
<p>In order to make the binding two-way I obviously need to... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-09T14:22:26.123",
"Id": "70839",
"Score": "0",
"body": "Furthermore, it sounds like your code is not working the way you want it to. Please only submit working code."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "... | [
{
"body": "<p>From a once over:</p>\n\n<ul>\n<li><p>You use the following type of coding a ton:<br></p>\n\n<pre><code>var groupsLabel = \"Label\";\n...\nif (typeof (groups[\"label\"]) === \"string\" && groups[\"label\"].length) {\n groupsLabel = groups[\"label\"];\n}\n</code></pre>\n\n<p>You could cons... | {
"AcceptedAnswerId": null,
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-09T10:55:40.410",
"Id": "41281",
"Score": "4",
"Tags": [
"javascript",
"knockout.js"
],
"Title": "Knockout custom binding"
} | 41281 |
<p>I wanted to fiddle around with the <code>BackgroundWorker</code> and <code>Task</code> classes, to see how I would implement a given task with these two techniques.</p>
<p>So I created a new WinForms project, and implemented a simple UI; two sections, each with a <code>ProgressBar</code>, and <kbd>Start</kbd> + <kbd... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-09T22:13:01.367",
"Id": "70877",
"Score": "1",
"body": "BTW, you might be interested in [Stephen Cleary's *Task.Run vs BackgroundWorker* series](http://blog.stephencleary.com/2013/09/taskrun-vs-backgroundworker-conclusion.html) (unless... | [
{
"body": "<p>It does show very good example for the progressbar in WinForms. \nHere are my code-review outputs for you.</p>\n\n<ul>\n<li>Closebutton_Click calls the other click \"handlers\". This is not the common way. Implement another method and call it from those handlers.</li>\n<li>I couldnt understand the... | {
"AcceptedAnswerId": "41302",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-09T21:09:29.680",
"Id": "41295",
"Score": "13",
"Tags": [
"c#",
"asynchronous",
"winforms",
"task-parallel-library"
],
"Title": "BackgroundWorker vs TPL ProgressBar Exercise"
... | 41295 |
<p>Is it possible to write this in fewer lines of code?</p>
<p>If you input an integer it will output it as an ordinal number if it is less than 100. The below code works perfectly, but I'm wondering if it could be written more succinctly.</p>
<pre><code>def ordinal(self, num):
"""
Returns ordinal number st... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-10T03:41:44.447",
"Id": "70887",
"Score": "0",
"body": "Off topic (As this is a python question, not .net), But https://github.com/MehdiK/Humanizer has extension methods to do this kind of thing nicely e.g., `1.Ordinalize() == \"1st\"`... | [
{
"body": "<p>You can simplify the repeated <code>n == 1 or (n % 10) == 1</code>, as well as special-case test for <code>11th</code>, <code>12th</code>, and <code>13th</code>, by using a <a href=\"https://stackoverflow.com/a/394814/49942\">ternary expression</a>;</p>\n\n<p>So:</p>\n\n<pre><code>i = n if (n <... | {
"AcceptedAnswerId": "41301",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-09T22:41:01.643",
"Id": "41298",
"Score": "21",
"Tags": [
"python"
],
"Title": "Producing ordinal numbers"
} | 41298 |
<p>While trying to teach myself C, I decided to take a stab at writing this Tic-Tac-Toe program on a 4x4 board. It will be great if somebody could review it and let me know of some ways of refining this.</p>
<pre><code>#include <stdio.h>
#include <stddef.h>
typedef struct {
int xpos;
int ypos;
} B... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-10T04:49:24.847",
"Id": "70889",
"Score": "1",
"body": "The `struct` name should only *start* with an uppercase letter. Having the entire name in caps makes it appear as a macro."
},
{
"ContentLicense": "CC BY-SA 3.0",
"Cr... | [
{
"body": "<h2>General:</h2>\n\n<p>I myself am writing a <a href=\"https://codereview.meta.stackexchange.com/q/1471\">Tic-Tac-Toe game of sorts</a>, so I am go to try to not give my code away too much. For a self-taught beginning C programmer, this code looks good. However, it looks like you were over thinking... | {
"AcceptedAnswerId": "41309",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-10T01:25:48.907",
"Id": "41304",
"Score": "12",
"Tags": [
"c",
"game",
"tic-tac-toe"
],
"Title": "4×4 Tic-Tac-Toe in C"
} | 41304 |
<p>I am building a Chrome extension that injects a small overlay in to all websites using a content script. At this point all the injected elements do is sit in the bottom left corner. It has two buttons the top one produces another element and the button one doesn't do anything. The extra element has a button that clo... | [] | [
{
"body": "<p>Some notes on your CSS:</p>\n\n<ol>\n<li><p>You can apply the <code>box-sizing</code> declaration to all the elements in your container:</p>\n\n<pre><code>.t_inject_container,\n.t_inject_container * {\n -webkit-box-sizing: border-box;\n -moz-box-sizing: border-box;\n box-sizing... | {
"AcceptedAnswerId": "41319",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-10T01:45:36.517",
"Id": "41305",
"Score": "6",
"Tags": [
"javascript",
"jquery",
"html",
"css",
"google-chrome"
],
"Title": "Injection with Chrome extension"
} | 41305 |
<p>With the help of some people here and there, I wrote the module below which works very well <strong><em>if the file <code>targets.csv</code> is not too big.</em></strong></p>
<p>As soon as this file exceeds 100 MB, a <code>MemoryError</code> is returned.</p>
<p>The problem is that I used <code>numpy</code> to make... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-10T12:59:59.847",
"Id": "70934",
"Score": "1",
"body": "What does \"100 Mo\" mean?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-10T21:12:59.137",
"Id": "71010",
"Score": "0",
"body": "100 Mb,... | [
{
"body": "<p>Here you read your data into a Python list that you pass to <code>array</code>:</p>\n\n<pre><code>targets = np.array([(float(X), float(Y), float(Z))\n for X, Y, Z in csv.reader(open('targets.csv'))])\n</code></pre>\n\n<p>A Python list of floats uses much more memory than a NumPy array, b... | {
"AcceptedAnswerId": "41326",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-10T07:25:05.673",
"Id": "41316",
"Score": "7",
"Tags": [
"python",
"numpy"
],
"Title": "Python, numpy, optimize module to handle big file"
} | 41316 |
<p>Even though I am working with one socket, I have wrapped it with an object which allows <code>.recv()</code> method which accepts timeout, using Python's <code>select.poll()</code>.</p>
<p>The initialization of the wrapping object defines a socket using the address/protocol family, of type stream; then it connects,... | [] | [
{
"body": "<p>Looks okay in general. One set of lines that gave me pause was:</p>\n\n<pre><code>## We set the socket to non-blocking mode\nif not self.blocking:\n self.socket.setblocking(0)\n</code></pre>\n\n<p>it looked redundant until I realized this was initial socket configuration. So it might be a littl... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-10T10:10:35.843",
"Id": "41317",
"Score": "4",
"Tags": [
"python",
"socket"
],
"Title": "A polling wrapper for Python's socket library"
} | 41317 |
<p>I've got this largish (for me) script, and I want to see if anybody could tell me if there are any ways to improve it, both in terms of speed, amount of code and the quality of the code. I still consider myself a beginner, and I think that there are parts of my code that aren't maybe all that good - for example, all... | [] | [
{
"body": "<p>I have a limited understanding of the different parts of your code so I'll just comment on some details that can be greatly improved.</p>\n\n<hr>\n\n<p>General:</p>\n\n<p>A few things are not quite pythonic. You can make your code go through some automatic checks with <a href=\"http://pep8online.c... | {
"AcceptedAnswerId": "41322",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-10T10:46:16.340",
"Id": "41320",
"Score": "4",
"Tags": [
"python",
"strings",
"python-3.x",
"csv",
"bioinformatics"
],
"Title": "Cutting strings into smaller ones based on... | 41320 |
<p>I am trying to create a simple validation for forms. I am almost there, but there are few bugs and optimization errors that I am really struggling with. I'm looking for advice on how to make this function simpler and more understandable.</p>
<pre><code>var errorMessage = {
required: "This field can not be empt... | [] | [
{
"body": "<p>From a once over:</p>\n\n<ul>\n<li>Function names in JavaScript should only start with a capital if they are constructors, so <code>Number</code> is no good, since it returns a boolean, I would call it <code>isNumber()</code></li>\n<li>I would put a <code>\"use strict\";</code> after <code>$(docu... | {
"AcceptedAnswerId": "41336",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-10T10:57:00.267",
"Id": "41321",
"Score": "5",
"Tags": [
"javascript",
"optimization",
"html",
"form",
"validation"
],
"Title": "Validating HTML Form"
} | 41321 |
<p>I am working on Android applications for last 2 years and about 80% applications I have developed involve web-services consumption followed by some sort of XML or JSON parsing. Initially, when I had to call a web service, I had to create a separate <code>AsyncTask</code> class and then parsing was also the part of t... | [] | [
{
"body": "<p>Your idea seems quite feasible, I just had a brief look through and these would be my suggestions:</p>\n\n<ol>\n<li><p>TaskResult class </p>\n\n<ul>\n<li>\"code\" and \"message\" members should probably be encapsulated via getter/setter with proper namings.</li>\n</ul></li>\n<li><p>ConnectionManag... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-10T12:41:54.737",
"Id": "41325",
"Score": "3",
"Tags": [
"java",
"parsing",
"android",
"asynchronous",
"web-services"
],
"Title": "Android AsyncTask, HTTP Request and Parsing... | 41325 |
<p>I need to create an efficient algorithm that returns unique values from an unsorted input. I don't know the length of the input.</p>
<p>As the function that will call this algorithm can abort the reading at any time, I think that using a well defined <code>Iterable</code> implementation is the right way, so I will ... | [] | [
{
"body": "<p>you have a O(n) time algorithm using O(n) space I don't see how much better this can be without using an external data store or a <code>RandomAccessFile</code></p>\n\n<p>calling hasNext will advance the input several times which is not what you want. to fix test if next is already set:</p>\n\n<pre... | {
"AcceptedAnswerId": "41334",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-10T12:46:01.427",
"Id": "41327",
"Score": "6",
"Tags": [
"java",
"algorithm"
],
"Title": "Algorithm to return unique values from unsorted input"
} | 41327 |
<p>I'm using simple script to handle tab menu like this:</p>
<p>HTML:</p>
<pre><code><nav id="personal">
<ul class="clearfix">
<li id="personal-info">Info</li>
<li id="personal-orders">Orders</li>
<li id="personal-models">Models</li>
... | [] | [
{
"body": "<p>You're building a navigation, however there are no links. It's highly recommended to use <code>anchor</code> tags for linking purposes.</p>\n\n<p>Your naming is a bit loose. What is <em>personal</em> in your context? Please specify that. Even something like <code>personal-navigation</code> is quit... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-10T13:04:13.083",
"Id": "41329",
"Score": "8",
"Tags": [
"jquery",
"html",
"coffeescript"
],
"Title": "Simple CoffeeScript navigation menu"
} | 41329 |
<p>I am trying to populate a vector of integers with one billion random number. The only constraint is that there can be no duplicates in the array.</p>
<pre><code>#include <iostream>
#include <algorithm>
#include <vector>
#include <ctime>
using namespace std;
int main()
{
srand(time(NU... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-10T14:26:23.547",
"Id": "70945",
"Score": "1",
"body": "1) `rand` *sucks*. On some machines there might not even be enough distinct values for `rand` to return. `RAND_MAX` may be as small as 2^15. 2) A hash set based approach would be ... | [
{
"body": "<p>Your solution as it stands currently is going to be incredibly slow - it's complexity is <code>O(n^2)</code>, so you're looking at roughly 10^18 \"operations\" for a billion numbers. This is because you need to search through the vector as it grows to see if you have a duplicate, which will go thr... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-10T13:25:12.287",
"Id": "41332",
"Score": "11",
"Tags": [
"c++",
"optimization",
"performance"
],
"Title": "Most efficient way to populate a vector of integers with no duplicates"
} | 41332 |
<p>I am trying to find whether a given number is a perfect square or not by using just addition and subtraction.</p>
<p>Please review my code.</p>
<pre><code>#include<stdio.h>
int check(int);
main()
{
int N;
printf("\n Enter the N:");
scanf("%d",&N);
if(check(N))
{
printf("\n[%... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-10T14:17:23.430",
"Id": "70942",
"Score": "1",
"body": "Applying proper formatting to your code would be a good first step."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-10T14:21:18.743",
"Id": "70944... | [
{
"body": "<p><strong>Presentation</strong></p>\n\n<p>I have re-indented your code, I do not know how your code is on your side but you should definitly indent it properly.\nAlso, you should remove useless lines.</p>\n\n<p><strong>Naming</strong></p>\n\n<p><code>check</code> is not a good function name. <code>i... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-10T13:54:51.817",
"Id": "41333",
"Score": "7",
"Tags": [
"c",
"algorithm",
"reinventing-the-wheel"
],
"Title": "Find whether a given number is a perfect square or not"
} | 41333 |
<p>I was asked to create a function that checks if an array of <code>double</code>s has all negative numbers or none. If these 2 (all negative, all positive) are false, check the first negative number, using recursion and <strong>only using built-in C++ features</strong>.</p>
<pre><code>int first_negative(const doubl... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-10T15:56:49.993",
"Id": "70960",
"Score": "0",
"body": "Can you please rephrase on what this is supposed to do?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-10T15:58:11.167",
"Id": "70961",
"Scor... | [
{
"body": "<ul>\n<li><p>I believe the parameter names <code>val</code> and <code>array</code> are switched around. An array shouldn't be a single variable, and a value shouldn't be an array. Otherwise, the names themselves are okay.</p></li>\n<li><p>It's preferred to index through a C-style array with an <cod... | {
"AcceptedAnswerId": "41340",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-10T15:50:21.947",
"Id": "41339",
"Score": "14",
"Tags": [
"c++",
"algorithm",
"recursion"
],
"Title": "Identifying first negative number in array of doubles"
} | 41339 |
<blockquote>
<p>There is no error checking in <code>day_of_year</code> or <code>month_day</code>. remedy this defect.</p>
</blockquote>
<p>Here is the solution:</p>
<pre><code>int day_of_year(unsigned int year, unsigned int month, int day) {
int leap, i;
leap = ((year % 4 == 0 && year % 100 != 0) |... | [] | [
{
"body": "<ol>\n<li><p>Incorrect <code>yearday</code> limit</p>\n\n<pre><code>// if((leap == 1 ... || (leap == 0 && (yearday >= 1 && yearday <= 366))) {\nif((leap == 1 ... || (leap == 0 && (yearday >= 1 && yearday <= 365))) {\n// ... | {
"AcceptedAnswerId": "41356",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-10T16:11:08.653",
"Id": "41343",
"Score": "6",
"Tags": [
"c",
"beginner",
"datetime",
"error-handling"
],
"Title": "Functions that converts day of year to month and day and re... | 41343 |
<p>I don't understand what is taking the program so long:</p>
<pre><code>#!/bin/python
primes=[]
i=0
j=0
k=0
for i in range(2,2000000): #fill in the list
primes.append(i)
i=0
while i<len(primes):
j=primes[i]
print(j)
k=0
while j*(j+k)<primes[len(primes)-1]: ##referred as 'line A'
t... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-10T16:16:55.577",
"Id": "70963",
"Score": "0",
"body": "There is a lot you can do to improve performances in this script. The first for loop can be replaced with `primes = list(range(2,2000000))`, `primes[len(primes)-1]` is `primes[-1]... | [
{
"body": "<p>I don't believe it is actually the specific <code>Lne A</code> that is the problem, but everything that is happening inside that loop, and most importantly, the line: <code>primes.remove(...)</code>. From <a href=\"https://stackoverflow.com/questions/1521784/cost-of-list-functions-in-python\">this... | {
"AcceptedAnswerId": "41345",
"CommentCount": "8",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-10T16:11:23.807",
"Id": "41344",
"Score": "4",
"Tags": [
"python",
"performance",
"primes"
],
"Title": "Sum of primes program is taking too long"
} | 41344 |
<p>I'm just starting to learn PHP. I have three random questions about PHP and one question about Code Review. None of them are technical questions ("will this work?"); they're best practices questions ("is this the best way to do this?"). Can you offer advice?</p>
<ol>
<li><p>I put commonly used data in separate file... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-10T17:53:41.470",
"Id": "70989",
"Score": "3",
"body": "Your third question is not really on-topic for this site. Such questions tends to attract opinion answers and spam. The only SE place I know of where that question would be on-top... | [
{
"body": "<p><strong>1.)</strong> What you do here is to extract code used in several locations into a shared file. Instead of describing what do to you refer to a building block to use here (the <code>footer</code> building block). This is a technique commonly used in other engineering areas as well (e.g. con... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-10T17:44:38.767",
"Id": "41349",
"Score": "7",
"Tags": [
"php",
"beginner",
"mysql"
],
"Title": "Best Practices concerning Includes and SQL Connect Strings"
} | 41349 |
<p>I'm working on a small GTK+ program and I'm now implementing undo and redo capabilities. This is the code that I'm using to handle the different states.</p>
<p>It's just a linked list storing the allocated <code>char *</code> returned by the text buffer. It monitors the size of the structure and the <code>char *</c... | [] | [
{
"body": "<p>Just a few notes:</p>\n\n<ul>\n<li><p>You have some <code>#define</code> statements at the beginning of your header.</p>\n\n<blockquote>\n<pre><code> #define TS_SUCCESS 0\n #define TS_ERROR 1\n #define TS_GREATER_THAN_BUFFER 2\n #define TS_FAILED_TO_ALLOCATE_NODE 4\n</code></pre>\n</blockq... | {
"AcceptedAnswerId": "41366",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-10T17:58:23.197",
"Id": "41350",
"Score": "11",
"Tags": [
"c",
"linked-list",
"stack",
"gtk"
],
"Title": "Undo and redo functionality for a GTK+ program"
} | 41350 |
<p>I am solving one problem with shortest path algorithm, but it is too slow.</p>
<p>The problem is that I have N points and these can be connected only if the distance between them is smaller or equal than the D. I have a <code>start</code> index and finish(<code>ciel</code> in code) index and have to return the sho... | [] | [
{
"body": "<p><strong>C++-specific:</strong></p>\n\n<ul>\n<li><p>You're mixing C and C++ libraries:</p>\n\n<ul>\n<li><p>You already have <code><iostream></code>, so you don't need <code><stdio.h></code>.</p>\n\n<p>However, if you can <em>only</em> use <code>printf</code> and <code>scanf</code> for w... | {
"AcceptedAnswerId": "41371",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-10T18:07:37.420",
"Id": "41351",
"Score": "7",
"Tags": [
"c++",
"algorithm",
"performance",
"pathfinding"
],
"Title": "Shortest path algorithm is too slow"
} | 41351 |
<p>This is a (relatively) cleaned-up version of a Python script I've been working on for the past day or two based on <a href="http://timgolden.me.uk/python/win32_how_do_i/watch_directory_for_changes.html" rel="nofollow">Tim Golden's first solution</a> to the above problem. I know about watchdog but I'm trying to keep ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2016-10-10T18:14:15.563",
"Id": "269829",
"Score": "0",
"body": "Readers may be interested in an alternative solutions to this problem, such as this one, and the others on the same page: http://superuser.com/a/970780/57697"
}
] | [
{
"body": "<p>I think it's generally good! There are a few little things that stand out to me as being repetitive and not quite Pythonic. </p>\n\n<p>For instance the block at the end could be rewritten to avoid all the extra assignments. Unless you think they add readability. In which case I would suggest that ... | {
"AcceptedAnswerId": "41402",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-10T20:29:29.553",
"Id": "41357",
"Score": "4",
"Tags": [
"python",
"file-system"
],
"Title": "Python script that polls for changes in filesystems"
} | 41357 |
<p>The purpose of this code is to return an address for one of the seven judicial circuits for the cases that is passed into the function. </p>
<p>I am taking a Node ID, which is a 3-digit number the circuit number is the first digit and the county number is the last two digits.</p>
<pre><code>Set oNode = XmlDoc.Sel... | [] | [
{
"body": "<p>Your faith in your input data is absolute... you do not do any validation. This is not a 'best practice'.</p>\n\n<p>You should at least be doing an input range check on the <code>oNode</code>.</p>\n\n<p>Once you have the range-check done, you can avoid the whole switch statement, and skip to some ... | {
"AcceptedAnswerId": "41377",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-10T22:51:42.510",
"Id": "41364",
"Score": "6",
"Tags": [
"vbscript"
],
"Title": "Extracting information and returning specific data"
} | 41364 |
<p>I'm writing a program to process log files. Currently, I have a script that will extract the desired information from each log and put it into a list - I have about nine different lists all containing different information.</p>
<p>Currently, I'm loading the file, extracting the desired information, and storing it ... | [] | [
{
"body": "<p>Are you more worried about memory, speed or maintainability? if the lists are long enough that you worry about them filling up your available memory, write them out one at a time. If not, process them in bulk.</p>\n\n<p>in either case, a list-of-lists is better than maintaining 6 copies of ident... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2014-02-10T22:56:19.153",
"Id": "41365",
"Score": "6",
"Tags": [
"python",
"performance",
"csv"
],
"Title": "Fastest way to write multiple CSV's"
} | 41365 |
<p>I am very new to Java so please ignore if there are obvious mistakes. If my question seems redundant then please guide me towards the correct link. However, I have surfed enough in order to find the answer. Any changes in code will be greatly appreciated.</p>
<p>I am reading an input file and storing the elements o... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-11T00:17:14.197",
"Id": "71031",
"Score": "0",
"body": "Your code does not actually process the `double` values...."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-11T00:52:04.650",
"Id": "71032",
"... | [
{
"body": "<p>Assuming that the characters on the left of the \">\" are unique (or the doubles to the right are unique), the easiest way I can think of to do this is to use a <a href=\"http://docs.oracle.com/javase/7/docs/api/java/util/HashMap.html\">HashMap</a> object. Just split the string on the \">\", and ... | {
"AcceptedAnswerId": "41375",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-10T23:55:48.173",
"Id": "41367",
"Score": "6",
"Tags": [
"java",
"beginner",
"array",
"parsing"
],
"Title": "Read an input text file and store the tokens in 2 different arrays... | 41367 |
<p>I have this code in a model for an invoicing app. This virtual attribute <code>current_invoice</code> gets the only non-rescinded invoice associated with a contract. The code works but it seems really verbose. Can this be done in a prettier way?</p>
<pre><code> def current_invoice
result = []
invoices.each... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-11T11:45:56.857",
"Id": "71089",
"Score": "2",
"body": "I know you said current_status is virtual, but is it initialised based on a value in the database, perhaps in another model and may be you could use that to create a query?"
},
... | [
{
"body": "<p>Some notes:</p>\n\n<ul>\n<li><p><code>result = []</code>: Try not to use generic names like <code>result</code>. Also, use plural names for collections.</p></li>\n<li><p>init empty array + each + conditional push = select/reject. More on <a href=\"https://code.google.com/p/tokland/wiki/RubyFunctio... | {
"AcceptedAnswerId": "42098",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-11T02:30:36.903",
"Id": "41374",
"Score": "7",
"Tags": [
"ruby",
"ruby-on-rails"
],
"Title": "Shorter, better way to write a \"query\" involving virtual attributes"
} | 41374 |
<p>I just want to know if my schema file is correct:</p>
<p>XML File:</p>
<pre><code> <?xml version="1.0" encoding="UTF-8"?>
<xs:books xmlns="http://www.w3.com/1999/XML/prjXMLValidation"
xmlns:xs="http://www.w3.org/2001/XMLSchema/prjXMLValidation"
xs:noNamespaceSchemaLocation="collection.xsd">... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-11T05:01:14.207",
"Id": "71051",
"Score": "0",
"body": "Well, you may want to include the XSD file `collection.xsd` ... ;-)"
}
] | [
{
"body": "<p>Overall your structures look OK. Your actual XML document could be indented more neatly, but it's OK.</p>\n\n<p>I would recommend that you change your <code>stars</code> element to have an attribute. Using the PCDATA space is not a great place to put a numeric value.... Actually, I would recommend... | {
"AcceptedAnswerId": "41381",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-11T04:56:02.280",
"Id": "41379",
"Score": "3",
"Tags": [
"xml",
"xsd"
],
"Title": "XML Schema File that validates my XML File"
} | 41379 |
<p>My work is pretty simple. I have to migrate a bulk of data into the specified tables, so that the data does show up at the front-end. The data is provided through the Excel sheet and I have to convert it into a CSV file with <code>$</code> as a field delimiter.</p>
<p>And later I have to write a method in an Acti... | [] | [
{
"body": "<p>Using an array to hold your variables is hard to maintain and to read. You can assign the fields to real variable names:</p>\n\n<pre><code>while (line = file.gets)\n discipline_name, _, location_name, speciality_name, code = \n line.split(\"$\").map(&:to_s).map(&:chomp).(&:strip)\n... | {
"AcceptedAnswerId": "41431",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-11T05:37:38.300",
"Id": "41382",
"Score": "2",
"Tags": [
"ruby",
"ruby-on-rails",
"excel",
"csv"
],
"Title": "Updating tables with bulk of data through CSV"
} | 41382 |
<p>Help me refactor this class that helps to represent an object state as String:</p>
<pre><code>public class ConvertorToString {
private static final String SEPARATOR_BETWEEN_FIELD_NAME_AND_VALUE = "=";
private static final String SEPARATOR_BETWEEN_FIELDS = ", ";
private static final String OPEN_FIELDS = ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-11T08:29:51.237",
"Id": "71073",
"Score": "1",
"body": "Is there a particular reason why your're using your own `toString()` instead of, for example, Guava's String Helper: http://code.google.com/p/guava-libraries/wiki/CommonObjectUtil... | [
{
"body": "<p>I like the idea of this utility class, but there are a few points I would like to mention.</p>\n\n<p>Let's start with naming. I would rename the <code>ConvertorToString</code> class, probably, to one of the following <code>ToStringUtil</code>, <code>ToStringHelper</code>, <code>ObjectToString</cod... | {
"AcceptedAnswerId": "41397",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-11T06:10:25.557",
"Id": "41387",
"Score": "1",
"Tags": [
"java",
"strings",
"converting"
],
"Title": "Refactor ConvertorToString class"
} | 41387 |
<p>I have implemented a linked list. I feel I overdid it with pointers, used old standards and C++11, and I ended with too many lines of code. I will make my quotations into two parts: one for the <code>Node</code> and iterator struct and the other for rest of the class.</p>
<p>For node and iterator, how can I optimi... | [] | [
{
"body": "<p>There are several small things I can see in class <code>Node</code>:</p>\n\n<ul>\n<li>You have a move constructor, but no copy constructor.</li>\n<li>You have a move assignment operator, but no copy assignment operator.</li>\n<li>Since you use C++11, you should replace the exception specification ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-11T06:12:15.427",
"Id": "41388",
"Score": "5",
"Tags": [
"c++",
"optimization",
"c++11",
"linked-list",
"pointers"
],
"Title": "Optimising a LinkedList data structure - Part ... | 41388 |
<p>This is part 2. My problems are with too any pointers and with long body code in the following functions: </p>
<blockquote>
<pre><code>void push_back(T_ data);
void push_front(T_ data);
T_ pop_back();
T_ pop_front();
void insert(iterator_t& i, T_ data);
void erase(iterator_t& i);
T_ front();
T_ back();
vo... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-11T23:12:31.403",
"Id": "71193",
"Score": "0",
"body": "You should probably include your `Node` implementation, or at least mention that it exists. At first glance, I thought you were implementing the list *and* the node in one class.... | [
{
"body": "<p><strong>Size</strong></p>\n\n<p>Normally I'd say right away that <code>size</code> should return an <code>std::size_t</code> instead of an <code>int</code>, but some recent collaborations amongst top C++ experts (including Bjarne Stroustrup himself) have revealed that this can be problematic due t... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-11T06:28:01.287",
"Id": "41389",
"Score": "5",
"Tags": [
"c++",
"c++11",
"linked-list",
"pointers"
],
"Title": "Optimising LinkedList class - Part 2"
} | 41389 |
<p>I have implemented the following PHP magic method behavior to save my time of creating accessor and mutators for properties of any class that extends this base class.</p>
<p>I am looking for suggesiongs on improving it for my application that assumes the following:</p>
<p><strong>Properties of the form:</strong></... | [] | [
{
"body": "<p>Exceptions are fine, but consider using less general <code>Exception</code> classes, like <code>BaseException</code> or whatever. This will allow for more flexible error reporting.</p>\n\n<p>First thing that strikes me as odd about your code is that you're using underscore to name your properties,... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-11T07:14:00.683",
"Id": "41392",
"Score": "4",
"Tags": [
"php",
"design-patterns"
],
"Title": "PHP magic function for accessors and mutators"
} | 41392 |
<p>I'am trying to build a PHP/MySQL/jQuery comment system. Off late I started to realize that manual spamming is a serious issue that need to be addressed carefully. So I thought of building a PHP function (initially, later can be implemented in OOPS concept) that will sniff the content and give points (spam points) b... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-13T22:28:38.340",
"Id": "71509",
"Score": "1",
"body": "You could pull the spam words from a database or text file. That way you don't have to keep change the code."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2... | [
{
"body": "<p>Minor (and subjective) remarks:</p>\n\n<ul>\n<li>Function name: The function does not sniff spam but calculate a score for the given content. Therefore I'd rename the function to something like <code>getSpamScore</code></li>\n<li>The variable <code>$matches</code> is not declared. Declaring it bef... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-11T12:59:51.270",
"Id": "41399",
"Score": "3",
"Tags": [
"php"
],
"Title": "Spam detection in PHP for comment system"
} | 41399 |
<p>This will be a function that returns a random number from Dice Notation (<a href="http://en.wikipedia.org/wiki/Dice_notation" rel="nofollow">more on Wikipedia</a>). I will later use this function to determine whether some skill check is passed or not.</p>
<ol>
<li>Is there any need for optimization?</li>
<li>If so... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-11T14:49:58.487",
"Id": "71105",
"Score": "2",
"body": "Hi, and welome to CodeReview's 'First Question' review. It would be helpful if you added a bit more of a description about what your code is supposed to do. Adding a description g... | [
{
"body": "<h1>Bug</h1>\n\n<p>Your code has an integer-division/multiplication problem/bug.</p>\n\n<p>Consider the dice-roll specification <code>10d10+0</code>.</p>\n\n<p>Your code will parse this down to:</p>\n\n<pre><code>string dicePart1 = \"10\";\nstring dicePart2 = \"10\";\nstring dicePart3 = \"0\";\n</cod... | {
"AcceptedAnswerId": "41408",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-11T13:57:52.997",
"Id": "41403",
"Score": "11",
"Tags": [
"c++",
"strings",
"game",
"random",
"dice"
],
"Title": "Simple dice roll using std::string as dice notation"
} | 41403 |
<p>I have a Python script I have written to copy files to a mounted Windows SMB share on a Mac.</p>
<pre><code>import os
import distutils.core
# Create a local site for the mount to reside
directory = "/Users/username/share"
if not os.path.exists(directory): os.makedirs(directory)
# Mount the Windows smb share
os.syst... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-11T14:40:00.133",
"Id": "71102",
"Score": "1",
"body": "You do not use `toDirectory1`. Is it normal ?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-11T15:14:38.517",
"Id": "71109",
"Score": "0",
... | [
{
"body": "<p>The code looks OK. A few specific improvements can be made.</p>\n\n<h2>Readability</h2>\n\n<pre><code>import os\nimport distutils.core\n</code></pre>\n\n<p>Learn about PEP8, you should have two empty lines between imports and the rest of the code. More generally, you should give more structure to ... | {
"AcceptedAnswerId": "41463",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-11T14:31:03.027",
"Id": "41405",
"Score": "5",
"Tags": [
"python",
"beginner",
"file-system",
"osx"
],
"Title": "Python script using distutils to copy files on a Mac"
} | 41405 |
<p>I have inherited a function which calculates a first payment due after a certain age.<br>
Using the function I typically pass in database values to custom calculate certain dates:</p>
<pre><code> Dim result = FPDA("#1/12/1952#", "9/29/1948", 1, 55)
MsgBox(result) 'in this example, I am returning first paymen... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-11T15:47:18.970",
"Id": "71113",
"Score": "0",
"body": "Well, if you need to explain the meaning of the variable, I guess you could consider renaming the variables."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2... | [
{
"body": "<p>You're doing a lot more looping than necessary. It would probably be more efficient to jump the return date to the same year than adjust the month accordingly. As was mentioned an enum, properly named makes the code much more readable and manitainable. Something like this:</p>\n\n<pre><code>Pub... | {
"AcceptedAnswerId": "41505",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-11T15:45:32.620",
"Id": "41410",
"Score": "8",
"Tags": [
"vb.net"
],
"Title": "Calculate a payment due after X age"
} | 41410 |
<p>I am trying to speed up the process of inserting all of the rows in my text file into an Access DB. I originally switched to this route because of the size of those text files (that I am generating on another step of my process). I have more ROM than RAM. The overall process is working now, but I am falling into the... | [] | [
{
"body": "<p>OK, thought I might get a quick win if you were using a version of Access old enough to be using the Jet engine (in that case DAO is inherently much faster).</p>\n\n<p>First thing: Don't go down the road of your \"Logic 2\". The fact that you realized you have to escape any quotes in the input fi... | {
"AcceptedAnswerId": "41507",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-11T15:58:07.263",
"Id": "41411",
"Score": "5",
"Tags": [
"strings",
".net",
"vb.net"
],
"Title": "Inserting text file rows into an Access DB"
} | 41411 |
<p>I've got a view which has a corresponding template. The template looks something like like:</p>
<pre><code><div id="streamItems" class="left-list droppable-list"></div>
<div class="context-buttons">
<div class="left-group">
<div id="shuffleButtonView" class="view-placeholder... | [] | [
{
"body": "<p>From looking at it, the name of your function <code>toggleSaveStream</code> is lying, calling it twice will not make it toggle, it will look at the the status of the user and set the status accordingly. So I would simply call it <code>updateSaveStreamButton</code>.</p>\n\n<p>Since it does that, yo... | {
"AcceptedAnswerId": "41420",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-11T17:27:49.703",
"Id": "41417",
"Score": "4",
"Tags": [
"javascript",
"template"
],
"Title": "toggleSaveStream button template"
} | 41417 |
<p>My intention is to separate components on a file basis. For example, I want a specific controller to have it's own file (Same goes with services, filters and directives). Of course, files will be group together based on the module they will fall into.</p>
<p>Here's an overview of what I currently have:</p>
<p>Dire... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2015-01-11T12:50:55.577",
"Id": "139838",
"Score": "0",
"body": "I would organise the files exactly as you have done: functional. Otherwise the components that works together are split around and are likely not so easy available for reuse. Mor... | [
{
"body": "<p>It would be much easier to give feedback if we saw your actual code, for those 5 js files.</p>\n\n<p>Regardless, I tend to organize differently:</p>\n\n<pre><code>controllers/\n user.js\nviews/\n user.js\nmodels/\n user.js\n</code></pre>\n\n<p>So anything that does not fit <code>controller/user... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-11T17:31:07.827",
"Id": "41418",
"Score": "4",
"Tags": [
"javascript",
"angular.js",
"meteor"
],
"Title": "Angular Modular File Structure"
} | 41418 |
<p>Not a follow-up, but related to <a href="https://codereview.stackexchange.com/q/41207/35408">Member list reveals member information on click (#1)</a>. I now want my CSS reviewed.</p>
<p><strong>What I'm doing?</strong></p>
<p>The content in a list of members is revealed by jQuery (see review #1). Instead of having... | [] | [
{
"body": "<p>this popped out at me, I haven't looked at the entire code completely yet, so take this with a grain of salt please</p>\n\n<p>not sure why you do this</p>\n\n<pre><code><a href=\"#member-name-2\" class=\"block-list__link\">\n <div class=\"block-list__thumbnail\">\n <img src=... | {
"AcceptedAnswerId": "41567",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-11T18:38:14.483",
"Id": "41423",
"Score": "6",
"Tags": [
"html",
"css",
"sass"
],
"Title": "Member list reveals member information on click (#2)"
} | 41423 |
<p>Partial ordering may be useful in some scientific contexts. This is quick prototype in Python, which I believe works correctly.</p>
<p>Do you notice any flaws? Can you provide a counter-example of wrong results? Additional test cases will be also rewarded with +1.</p>
<pre><code>#!/usr/bin/env python3
import unit... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-12T04:44:58.760",
"Id": "71216",
"Score": "2",
"body": "Decav, since `l >= 0` is always `true`, the `return` statement appears to be the same as `return g == 0`, suggesting that `false` is returned if and only if `v1 > v2` for at least... | [
{
"body": "<p>Not much to say about it, good job!</p>\n\n<ul>\n<li>Documentation: explain the mathematical explanation of your partial ordering unless it's really that obvious for your intended readers</li>\n<li>Names:\n<ul>\n<li>In Python, names starting with uppercase letters are for class names: of course yo... | {
"AcceptedAnswerId": "41464",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-11T21:54:58.647",
"Id": "41433",
"Score": "7",
"Tags": [
"python"
],
"Title": "Review implementation for Partial Ordering of Vectors"
} | 41433 |
<p>I am interested in the performance tradeoffs of linked lists, standard lists and unrolled linked lists. This will depend on various factors including what operation is being performed (e.g. delete, insert, and from where), and the size of the nodes. I've written some performance tests (not listed here).</p>
<p>I ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-12T04:24:17.763",
"Id": "71215",
"Score": "1",
"body": "Welcome to CR! Please add a bit more context / details about your implementation. Is there any part you think deserves particular attention?"
},
{
"ContentLicense": "CC BY... | [
{
"body": "<p>A few things off the bat:</p>\n\n<ol>\n<li>You should consider prefixing private field names with underscores, so it is possible to distinguish them from local variables.\n<strong>Edit:</strong> There is no \"official\" naming conventions regarding private members. Not that i know of anyway. Under... | {
"AcceptedAnswerId": "41452",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-11T22:35:27.523",
"Id": "41436",
"Score": "11",
"Tags": [
"c#",
"performance",
"linked-list",
"collections"
],
"Title": "Unrolled linked list"
} | 41436 |
<p>My class takes functions as a parameter. There are 6 of them, along with numerous other parameters. Almost all of the fields have default values.</p>
<p>It also has a class method that creates an instance of the class with 2 of the fields initialized randomly. It has a subclass that cheats a bit by making 2 of t... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-12T01:33:18.667",
"Id": "71207",
"Score": "1",
"body": "[I know nothing of python](http://codereview.stackexchange.com/users/23788/lol-upvote?tab=tags&sort=votes), but in other languages having a class with lots of constructor paramete... | [
{
"body": "<p>A few suggestions:</p>\n\n<ol>\n<li>You can simplify <code>random_init</code> as: <code>def random_init(self, **kwargs):</code>; this allows you to pass any provided arguments straight through to <code>return cls(weights, biases, **kwargs)</code> without explicitly specifying them. This prevents t... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-12T01:23:27.560",
"Id": "41440",
"Score": "10",
"Tags": [
"python",
"constructor",
"python-2.x"
],
"Title": "Long constructors, inheritance, class method constructors"
} | 41440 |
<p>I have solved fibonacci series and then used the topdown and bottom up approaches to solve it. Also I have included the stairway climbing question as follows "You are climbing a stair case. Each time you can either make 1 step or 2 steps. The staircase has numStairs steps. Returns In how many distinct ways can you ... | [] | [
{
"body": "<p>From a once over:</p>\n\n<ul>\n<li><p>The parameter name in <code>stairCount</code> represents the number of steps, maybe it ought to be called <code>numSteps</code> instead of <code>numStairs</code>. Also, personally, I would prefer <code>stepCount</code>.</p></li>\n<li><p>There really should be ... | {
"AcceptedAnswerId": "41446",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-12T02:04:10.020",
"Id": "41441",
"Score": "3",
"Tags": [
"java",
"fibonacci-sequence"
],
"Title": "Fibonacci series, topdown and bottom up approaches, stairway climbing"
} | 41441 |
<p>I recently had a Java interview where I was asked to write a client-server application. I don't code primarily in Java, but with my preliminary Java knowledge, I thought I built a reasonable working solution. After evaluating my solution, I was told that I wasn't going to be interviewed further. I'm fine with their ... | [] | [
{
"body": "<h3>Protocol</h3>\n\n<p>I find your client-server protocol odd. <strong>Usually, XML is mostly indifferent to whitespace.</strong> That is, a document spread over multiple lines, such as</p>\n\n<pre><code><hello>\n <message language=\"en\">How are you</message>\n</hello>\n<... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-12T05:27:46.343",
"Id": "41445",
"Score": "6",
"Tags": [
"java",
"multithreading",
"xml",
"interview-questions",
"networking"
],
"Title": "Client Sends XML, Server Parses XML... | 41445 |
<p>It took me a while to figure out how to write this code, but I'm glad to say that I did eventually figure it out.</p>
<p>Can someone tell me what they think about it? Is it well written? What could have been done better?</p>
<p>Note that I am going through exercises in a book; I know there's a <code>math.h</code>... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-12T09:51:51.883",
"Id": "71238",
"Score": "3",
"body": "I'd move the factorial computation into its own function."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-12T12:30:39.753",
"Id": "71266",
"Sc... | [
{
"body": "<p>Looks pretty good! Just a few minor things:</p>\n\n<ul>\n<li><p>Your variables should be on separate lines, which is useful for maintainability and possible commenting. They can also be initialized instead of declared and then assigned.</p>\n\n<pre><code>int n = 1;\nint factorial = 1;\nint count... | {
"AcceptedAnswerId": "41450",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-12T05:40:12.707",
"Id": "41447",
"Score": "13",
"Tags": [
"c"
],
"Title": "Factorial code in C"
} | 41447 |
<blockquote>
<p>Given a staircase with N steps, you can go up with 1 or 2 steps each
time. Output all possible ways you go from bottom to top.</p>
</blockquote>
<p>I'm looking for code review, best practices, optimizations etc. Complexity: O(2<sup>n</sup>)</p>
<pre><code> public final class StairRoutes {
... | [] | [
{
"body": "<p>Very nice code, well done. The first thing that came to mind was that it contains the <code>main()</code> function inside the same class as work is done. This is not bad in itself, but consider to keep it in it's own class. That way the program is better structured.</p>\n\n<hr>\n\n<p>It's not nece... | {
"AcceptedAnswerId": "41475",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-12T05:46:38.807",
"Id": "41448",
"Score": "5",
"Tags": [
"java",
"combinatorics",
"fibonacci-sequence"
],
"Title": "Print routes on the stairway when only 1 or 2 steps are possibl... | 41448 |
<p>I have this WCF service providing search functionality - to be used by our client in his web application. There can be any number of search parameters and possible nesting of <code>AND</code>/<code>OR</code> operations.</p>
<p>Could you please have a look and share some ideas on if I can make it more client-friendl... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-12T09:14:45.767",
"Id": "71234",
"Score": "0",
"body": "Can you add information like is this a search page, and the user customises the AND/OR scenarios for all permutations? Is this application used for the internet or intranet? Do yo... | [
{
"body": "<p>Without knowing its intended audience (Intranet / Internet), I'm assuming Intranet.</p>\n\n<p>In my opinion, you are giving a lot of flexibility to this service in one method call, which isn't immediately clear how a user would structure a call to this. The caller has to have knowledge of a \"prop... | {
"AcceptedAnswerId": "41459",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-12T08:11:58.827",
"Id": "41453",
"Score": "1",
"Tags": [
"c#",
".net",
"sql",
"wcf"
],
"Title": "Exposing WCF Service with dynamic search operation"
} | 41453 |
<p>I am programming a rotator using Delphi, with two different angles: azimuth and elevation. Up to now I am testing, so I tried to move the rotator 1 by 1 degree in azimuth and elevation. The rotator starts in (0,0) and finishes in (30,30).</p>
<p>Another important thing is that I need to pause or have the program sl... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-12T11:18:11.020",
"Id": "71255",
"Score": "2",
"body": "Depending on the implementation and operating system, `sleep` functions only provide a rough estimation. It can be that they sleep too long or too short, are you aware of that?"
... | [
{
"body": "<p>A minor comment re. the code style: I don't like <code>angle = -1; while (angle < 30) begin angle = angle + 1; use angle</code>. If angle were an unsigned integer then <code>angle = -1</code> wouldn't work properly. I'd prefer to see a <a href=\"http://www.tutorialspoint.com/pascal/pascal_for_d... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-12T09:21:09.317",
"Id": "41457",
"Score": "7",
"Tags": [
"delphi"
],
"Title": "Sleeping in Delphi"
} | 41457 |
<p>I've written this minishell but I'm not sure I'm making a correct control of the errors. Could you give me some advice?</p>
<pre><code>#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdbool.h>
#define LINE_LEN 50
#define MAX_PARTS 50
int main ()
{
char* token;
ch... | [] | [
{
"body": "<p>I think I haven't really understood the point of your program but I'll try to give you a few hints :</p>\n\n<ul>\n<li>The indentation is not really good. I am not sure if this is because of SE but I'd rather point it out just in case.</li>\n<li>You'll hear everything and its opposite about <code>g... | {
"AcceptedAnswerId": "41468",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-12T09:36:22.487",
"Id": "41460",
"Score": "4",
"Tags": [
"c",
"error-handling"
],
"Title": "Making a minishell in C. How to improve error control with feoh and ferror?"
} | 41460 |
<p>The input pointer <code>*data</code> contains the data that needs to be split into different arrays and put in <code>yuvInput</code>. Each pixel is 32 bytes 4 * 8. Note the (j*4) to break it up per pixel segment. The 4th byte is the alpha channel which gets skipped (the reason there is no idx+3).</p>
<p>This met... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-12T10:10:59.433",
"Id": "71242",
"Score": "0",
"body": "Your issue is locality of reference. you are very limited. one thing you can do is read as much data at once, and then write that. for instance, you can read 8 bytes in a 64 bit i... | [
{
"body": "<p>Your multiplication expressions aren't ideal; instead (which might be faster) you could add 4 and subtract srcStride from the previous value at the top of each loop.</p>\n\n<p>Apart from that (and this is just a guess) I guess some other things might in theory make this faster.</p>\n\n<ol>\n<li>Ha... | {
"AcceptedAnswerId": "41481",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-12T09:39:23.007",
"Id": "41461",
"Score": "6",
"Tags": [
"c++",
"optimization",
"array",
"image"
],
"Title": "Optimize YUV channel splitting function"
} | 41461 |
<p>I'd like to get input on my approach of continuously receiving messages from an Azure Service Bus queue using the async part of the library.
My main concern being whether its "safe" to use Task.Factory.StartNew to process the incoming messages and then continue to call the Action's to continue receiving new messages... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-17T09:37:03.510",
"Id": "72035",
"Score": "1",
"body": "Indent your code properly, please. ._."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-17T09:37:09.397",
"Id": "72036",
"Score": "0",
"bod... | [
{
"body": "<p>First, some notes:</p>\n<ol>\n<li><p>You shouldn't be using <code>Task.Factory.StartNew()</code> unless you have to, <a href=\"http://blog.stephencleary.com/2013/08/startnew-is-dangerous.html\" rel=\"nofollow noreferrer\"><code>Task.Run()</code> is better</a>.</p>\n</li>\n<li><p>I think you're usi... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-12T09:51:33.350",
"Id": "41462",
"Score": "12",
"Tags": [
"c#",
"asynchronous",
"queue"
],
"Title": "Continuously receive messages async from Azure Service Bus Queues"
} | 41462 |
<p>A friend of mine has a popular open source JavaScript library which is quite well used in the community. He is now going through a process of refactoring and applying best practices and conventions and is wanting to upper case all constructor functions. So in the past where he may have defined a <code>chart</code>... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-12T17:56:28.707",
"Id": "71316",
"Score": "1",
"body": "You probably want to have wrapper return the result of `replacementFunction` to ensure its compatible with closure classes and prototypical ones. If this is only for prototypical ... | [
{
"body": "<p>From looking at your fiddle, the first thing I would do is make sure that your function is not anonymous:</p>\n\n<pre><code>// new function implementation\nvar Chart = function Chart(name, data) { //See what I did there?\n this.name = name;\n this.data = data;\n\n console.log(\"Chart >... | {
"AcceptedAnswerId": "41483",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-12T10:53:09.447",
"Id": "41467",
"Score": "5",
"Tags": [
"javascript"
],
"Title": "Creating a Deprecated/Obsolete behavior for methods in a JavaScript library"
} | 41467 |
<p>I have implemented code for parsing annotation:</p>
<pre><code>/**
* @Route(path="sample \n test",code,value,boolean,test)
* @access(code=false)
* @sample as asdad asd
* asd
*/
function sample()
{
}
$refelection = new ReflectionFunction("sample");
$pattern = "/@(\w+?)(.*?)/U";
preg_match_all($pattern, $ref... | [] | [
{
"body": "<p>Focusing on the regex side only....</p>\n\n<p>The use of the <a href=\"http://php.net/manual/en/reference.pcre.pattern.modifiers.php\" rel=\"nofollow\">UNGREEDY modifier</a> on your pattern, and then internally reversing that, is odd.</p>\n\n<blockquote>\n<pre><code>$pattern = \"/@(\\w+?)(.*?)/U\"... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-12T11:28:10.243",
"Id": "41470",
"Score": "3",
"Tags": [
"php",
"parsing",
"regex"
],
"Title": "Parsing annotation"
} | 41470 |
<p>I've written this as part of my contact form on my website. It checks to see if required inputs are empty, if so adds a red warning color and text. It also checks the email field for a properly formatted email.</p>
<p>This code works 100%, but somehow I feel like I'm repeating myself and I am not sure how to elimin... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-12T14:04:03.507",
"Id": "71275",
"Score": "0",
"body": "You should probably have a look at http://stackoverflow.com/questions/201323/using-a-regular-expression-to-validate-an-email-address"
},
{
"ContentLicense": "CC BY-SA 3.0"... | [
{
"body": "<p>From a once over:</p>\n\n<p>I would do the languages like this:</p>\n\n<pre><code>var translations = {\n 'en-CA' : {\n emptyFieldMessage: 'This field is required.',\n invalidEmail : 'This email address seems invalid.'\n },\n 'fr-CA' : {\n emptyFieldMessage: 'Ce champ est requis.',\... | {
"AcceptedAnswerId": "41477",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-12T13:40:56.290",
"Id": "41476",
"Score": "6",
"Tags": [
"javascript",
"jquery",
"validation",
"email"
],
"Title": "Checking input and email field"
} | 41476 |
<p>I'd like this reviewed.</p>
<p><a href="http://jsbin.com/nehut/1/edit?html,css,output" rel="nofollow">Demo</a></p>
<p><strong>HTML</strong></p>
<pre class="lang-html prettyprint-override"><code><body>
<!-- Introduction to the text shadow property -->
<div class="container one">
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-12T14:52:24.443",
"Id": "71289",
"Score": "3",
"body": "It would really help to have a description of what you have there, what its purpose is, etc."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-12T15:59:... | [
{
"body": "<ol>\n<li><p>You're using prefixed versions for the <code>background-clip</code> property. There is only a need for the <code>-webkit-</code> prefix here, so you have support for Android 2.x. You can omitt <code>-moz-</code>, unless you need to support Firefox 3.6.</p>\n\n<p><a href=\"http://caniuse.... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-12T14:48:46.193",
"Id": "41478",
"Score": "5",
"Tags": [
"html",
"css"
],
"Title": "Inset Text Shadow"
} | 41478 |
<p>I solved <a href="http://www.sebnozzi.com/244/beginner-words-and-lines/">this problem</a> in Ruby:</p>
<blockquote>
<p>Write an utility that takes 3 command-line parameters P1, P2 and P3.
P3 is OPTIONAL (see below) P1 is always a file path/name. P2 can take
the values:</p>
<ul>
<li>“lines”</li>
<li>“... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-27T20:26:50.757",
"Id": "74111",
"Score": "0",
"body": "If you are satisfied with any of the answers, you should select the one that was most helpful to you."
}
] | [
{
"body": "<h1>Formatting</h1>\n\n<p>Most Rubiest favor some white space between methods, such as:</p>\n\n<pre><code>class LineCounter\n\n # Initialize instance variables\n def initialize\n @line_count = 0\n end\n\n def process(line)\n @line_count += 1\n end\n\n def print_result\n puts \"#{@line_... | {
"AcceptedAnswerId": "41495",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-12T15:16:58.847",
"Id": "41480",
"Score": "13",
"Tags": [
"object-oriented",
"ruby",
"file"
],
"Title": "Counting words / lines in Ruby"
} | 41480 |
<p>To test incoming data for string values that are too large for the "database" (MS Access), I could do this:</p>
<pre><code>private void SaveToMSAccess(InventoryItem invItem, string dbContext)
{
invItem = TruncateVerboseStringMembers(invItem);
. . .
}
private InventoryItem TruncateVerboseStringMembers(Inven... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-13T01:55:47.863",
"Id": "71378",
"Score": "2",
"body": "You are still doing the double check. There is no good reason to check the length of all the strings, only to re-check all of them if any of them should be truncated. You only get... | [
{
"body": "<p>Making duplicate testing just to avoid a method call doesn't make much sense. Method calls are not that expensive. On the contrary, they can help make the code cleaner.</p>\n\n<p>You can make a method that helps you clean up the strings, just pass in how long each string may be. I think that maked... | {
"AcceptedAnswerId": "41502",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-12T17:26:46.687",
"Id": "41489",
"Score": "5",
"Tags": [
"c#",
"performance",
"database",
"comparative-review",
"ms-access"
],
"Title": "Truncating long strings when savin... | 41489 |
<p>Example: <code>00010111</code> -> <code>11101000</code></p>
<pre><code>public long reverse(long x) {
long r = 0;
int i = 0;
while (x > 0) {
int bit = 0x0001 & x;
r += bit << (63 - i);
x >>= 1;
i++;
}
return r;
}
</code></pre>
<p>Can someone rev... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-12T19:52:59.043",
"Id": "71328",
"Score": "0",
"body": "Greetings, your question can be put out of hold if you update it with code that does not contain an infinite loop."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDat... | [
{
"body": "<p>This code does not work, right?</p>\n\n<p>What you have is an infinite loop, because <code>x >> 1;</code> does not do what you think it does.</p>\n\n<p>There are a number of things wrong in here....</p>\n\n<ol>\n<li>if the input long value is negative, you will never reverse it (it's < 0)... | {
"AcceptedAnswerId": "41491",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-12T17:47:59.447",
"Id": "41490",
"Score": "0",
"Tags": [
"java"
],
"Title": "Reversing a 64 bit Integer"
} | 41490 |
<p>I am writing a script which <code>checkout</code> a git repo to certain commit hash, do something and switch back to <code>master</code>. The purpose of this script is to take homework solutions of students from bitbucket. Note that all the repos are under same bitbucket account. There is a master bitbucket account ... | [] | [
{
"body": "<p>Your idea of inspecting the timestamps of the commits is conceptually flawed. Git is a distributed version control system, with no central server or any other means of notarizing timestamps. The timestamps are determined solely by the system clock on the machine on which the commit was created, ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-12T18:36:48.070",
"Id": "41492",
"Score": "6",
"Tags": [
"python",
"git"
],
"Title": "Script to checkout multiple repositories to a certain commit hash"
} | 41492 |
<p>I am trying to print the elements of an array into a table, but I'm having trouble formatting the array elements itself. Perhaps there is a better solution than what I'm currently using?</p>
<pre><code>import java.util.Scanner;
public class RainFall{
public static void main(String args[]) {
//create rainfal... | [] | [
{
"body": "<p>You cannot use %d for double values.Try something like %3.2f for printing the rainfall values if you want to avoid the unnecessary precision.I am not sure why you are trying to print only one value while you have listed three months of rainfall.Try something like:</p>\n\n<pre><code> System.out.pri... | {
"AcceptedAnswerId": "41500",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-12T19:10:30.567",
"Id": "41496",
"Score": "1",
"Tags": [
"java",
"array"
],
"Title": "Print the elements of an array into a table"
} | 41496 |
<p>Suggestions for improving coding style are greatly appreciated.</p>
<pre><code>import qualified Data.List as L
import qualified Data.Map.Strict as M
import qualified Data.Vector as V
type Queue a = ([a], [a])
emptyQueue = ([], [])
pushListToAnother fromLst toLst = L.foldl' (\ys x -> (x:ys)) toLst fromLst
en... | [] | [
{
"body": "<p>Some general ideas:</p>\n\n<ul>\n<li>Always give types to top level functions. It improves readability of your code very much.</li>\n<li>Unless you really need to, it's better to use existing data structures than inventing your own. Instead of using <code>Queue</code>, you could as well use <code>... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-12T20:22:59.490",
"Id": "41503",
"Score": "3",
"Tags": [
"haskell",
"breadth-first-search"
],
"Title": "Solve a maze in the form of a 2D array using BFS - Haskell"
} | 41503 |
<p>I would prefer if more experienced users could give pointers on how I can optimize and think better when writing code.</p>
<p>Using <a href="https://codereview.meta.stackexchange.com/questions/62/homework-questions">Homework Questions</a> as reference, as this is a homework related question. This should fall into t... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-12T21:17:44.550",
"Id": "71331",
"Score": "0",
"body": "`typedef const char Datatyp;` *Datatyp*... is that a typo, or something you can't change?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-12T21:20:33.... | [
{
"body": "<ol>\n<li><p>Your variable's names confused me; I'd suggest renaming 'previous' to 'current', and 'tmp' to 'previous'.</p></li>\n<li><p>You don't do anything sensible if malloc fails.</p></li>\n<li><p>The following ...</p>\n\n<pre><code>else if (tmp != NULL)\n{\n tmp = previous;\n previous = pr... | {
"AcceptedAnswerId": "41518",
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-12T21:11:04.417",
"Id": "41504",
"Score": "5",
"Tags": [
"optimization",
"c",
"homework",
"queue"
],
"Title": "Optimization for add function in queue"
} | 41504 |
<p>This is my first more-than-1-line script. It takes an input folder and a file prefix and gets all the matching files. For the first of the files, the script grabs the first line and appends an extra label string and puts that into <code>$data</code>. For all files (including the first), it takes the second line, add... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-13T19:24:32.903",
"Id": "71484",
"Score": "0",
"body": "Are you running this on GNU/[tag:linux]? [tag:osx]? Or are you aiming for the code to be portable?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-13T... | [
{
"body": "<p>The problem is almost certainly this line here:</p>\n\n<pre><code>t=$(echo $fn | perl -pe 's|.*?(\\d+\\.\\d+)|\\1|');\n</code></pre>\n\n<p>If you are invoking the Perl interpreter for each line, you will struggle.</p>\n\n<p>A close second is that, for each file, you invoke 2 subshells, and two oth... | {
"AcceptedAnswerId": "41520",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-12T22:15:28.880",
"Id": "41508",
"Score": "10",
"Tags": [
"optimization",
"performance",
"beginner",
"regex",
"bash"
],
"Title": "Locating matching files with input folder... | 41508 |
<p>Could this script be shortened?</p>
<pre><code>import random
def var():
strength = 10
skill = 10
dice4 = 0
dice12 = 0
dice_score = 0
character_name = ""
attr_list = [character_name, strength, skill]
character_name = str(input("Please enter your characters name: "))
skill_func(s... | [] | [
{
"body": "<p>You can start with multi-assignment: </p>\n\n<pre><code>strength = skill = 10\nstrength, skill = 10, 10\nstrength, skill = (10,10)\nstrength, skill = [10]*2\n</code></pre>\n\n<p>I prefer the first way as long as the thing you are assining is immutable / constant literal. If you are assigning two e... | {
"AcceptedAnswerId": "41513",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-12T22:36:23.003",
"Id": "41509",
"Score": "4",
"Tags": [
"python",
"random",
"dice",
"battle-simulation"
],
"Title": "Dice game in Python"
} | 41509 |
<p>I was asked in my textbook <em>Lectures on Discrete Mathematics for Computer Science</em> to construct a program that would take an alphabet (<code>{a,b,c}</code> or any combination of characters <code>{1,4,s,a}</code>) as well as a length value and calculate all possible combinations of this alphabet.</p>
<p>For e... | [] | [
{
"body": "<p>your code looks fine.</p>\n\n<ul>\n<li>a slight performance improvement i'd do is pass a StringBuilder instead of a String - a String in java is immutable so every time you call <code>curr += alphabet[i]</code> youre actually allocating a new String object. instead you could append the character t... | {
"AcceptedAnswerId": "41511",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-12T06:32:12.227",
"Id": "41510",
"Score": "6",
"Tags": [
"java",
"strings",
"combinatorics"
],
"Title": "Calculate all possible combinations of given characters"
} | 41510 |
<p>I have a long set of IF statements that basically set a null object Value to <code>0</code>, I feel that because i am doing the same action each time their has to be a simple way to make this allot shorter. It just looks like something I wouldn't normally see in code.</p>
<p>My code looks like this:</p>
<pre><code... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-12T23:03:39.923",
"Id": "71346",
"Score": "0",
"body": "So there are some conditions? A subset of lists matching certain conditions? It's hard to make one up with no background."
},
{
"ContentLicense": "CC BY-SA 3.0",
"Crea... | [
{
"body": "<p>In short, the CSV parser is using the wrong data types. Whenever you have contiguous variable names, it screams \"use an array!\" If you at all, possibly can, use an array. That allows you to operate on it much, much more naturally, it's more flexible, and it's way less prone to human error.</p>\n... | {
"AcceptedAnswerId": "41516",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-12T22:51:23.070",
"Id": "41514",
"Score": "4",
"Tags": [
"php",
"iteration"
],
"Title": "Is there a way to shorten a set of conditionals like this?"
} | 41514 |
<p>I have a bit of trouble simplifying the binary search code. This is different from the traditional binary search because we effectively want to find the location for which <code>A[j]</code> is the least element larger than the current unsorted value.</p>
<p>Thoughts?</p>
<pre><code>def binary_search(A, value, star... | [] | [
{
"body": "<p>Your <code>binary_search</code> is the same as the built-in function <a href=\"http://docs.python.org/3/library/bisect.html#bisect.bisect\" rel=\"nofollow\"><code>bisect.bisect</code></a>, and you might find <a href=\"http://hg.python.org/cpython/file/1166b3321012/Lib/bisect.py#l24\" rel=\"nofollo... | {
"AcceptedAnswerId": "41592",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-12T23:14:57.817",
"Id": "41517",
"Score": "3",
"Tags": [
"python",
"algorithm",
"sorting",
"insertion-sort"
],
"Title": "Insertion sort with binary search in Python"
} | 41517 |
<p>A little background first - I'm working on a server application that requires the ability to use multiple data access class libraries based on the resources available on the server it is installed on (MySQL, SQL Server, XML, etc.). The are currently implemented as modular plugins, where the executable is paired wit... | [] | [
{
"body": "<p>You're loading every DLL in the directory even if you find what you want in the first one.</p>\n\n<p>I'd guess that loading an assembly is what takes more time and resources than looking for what you want in the assembly-after-it's-loaded.</p>\n\n<p>You code will fail if there's a type which imple... | {
"AcceptedAnswerId": "41526",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-13T00:59:37.867",
"Id": "41524",
"Score": "6",
"Tags": [
"c#",
"reflection"
],
"Title": "Using reflection to connect to an arbitrary backend"
} | 41524 |
<p>I am writing small roguelike game where I spawn some items and put them into the <code>std::list</code>. Is this the right way to do it?</p>
<p>The <code>Item</code> class is as followed (I know it has public <code>id</code> property):</p>
<pre><code>class Item {
public:
Item();
~Item();
unsigned int id... | [] | [
{
"body": "<p>If <code>Item</code> has subclasses, then make the <code>~Item()</code> destructor virtual.</p>\n\n<p>If <code>Item</code> has a copy constructor, and is not a superclass of a subclass, then you can store a copy of the item (not pointer to the item) in the list:</p>\n\n<pre><code>list<Item> ... | {
"AcceptedAnswerId": "41527",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-13T01:00:47.813",
"Id": "41525",
"Score": "7",
"Tags": [
"c++"
],
"Title": "Creating objects and putting them into std::list"
} | 41525 |
<p>A little disclaimer: you're going to have a field day with this. It's horrible. Looking at it makes me want to vomit, and don't ask me to explain it, because I've long forgotten what I was thinking when I wrote it. That being said, I can't really find a way to shorten it of make it make sense. Perhaps someone could ... | [] | [
{
"body": "<p>Firstly, your <code>installfromdownload</code> function should be <code>install_from_download</code> (and have a docstring to go with it explaining what it does).</p>\n\n<p>This line:</p>\n\n<pre><code>targetfolder = r\"C:\\Program Files (x86)\\Mod Manager\\Mods\\f_\" + filename[:-4]\n</code></pre... | {
"AcceptedAnswerId": "41558",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-13T04:11:49.337",
"Id": "41531",
"Score": "11",
"Tags": [
"python",
"python-3.x",
"installer"
],
"Title": "Installing \"mods\" with Python"
} | 41531 |
<p>I've written the following code, but I need some review on design style. I want to develop a library/module and expose an API to client programs. How do I do that?</p>
<p>The code just runs a TCP server listening for incoming messages and another thread accepting user input to send messages. </p>
<pre><code>from ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-13T09:30:34.693",
"Id": "71405",
"Score": "1",
"body": "I have the feeling that the AgTime and the Ntp classes are not actually useful. Also, the indentation of the last line looks wrong to me."
},
{
"ContentLicense": "CC BY-SA... | [
{
"body": "<p>I'm just going to review the <code>Ntp</code> class. As you'll see, there's plenty here for one answer.</p>\n<ol>\n<li><p>There's no documentation. What is this class supposed to do? What value does the <code>time</code> method return?</p>\n</li>\n<li><p>There are some "tells" that you h... | {
"AcceptedAnswerId": "41555",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-13T07:02:34.197",
"Id": "41537",
"Score": "3",
"Tags": [
"python",
"design-patterns",
"multithreading",
"socket"
],
"Title": "Run a TCP server listening for incoming messages"... | 41537 |
<p>I'm using two category filters from this <a href="http://demo.webcodo.net/switch-products-view-grid-list-jquery-with-filter-and-cookie/" rel="nofollow">demo</a>. I give the filters two different sets of classes so they won't affect each other. Since I'm very new to jQuery, all I can come up with is repeating the sam... | [] | [
{
"body": "<p>When you see that you're basically copy-pasting the code and changing a few values, you can usually encapsulate all the common stuff inside a function. Here:</p>\n\n<pre><code>var registerStuff = function(category, active, prod, select) {\n $(category).click(function(){\n var CategoryID ... | {
"AcceptedAnswerId": "41547",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-13T10:22:16.270",
"Id": "41544",
"Score": "5",
"Tags": [
"javascript",
"beginner",
"jquery",
"html",
"css"
],
"Title": "Two filters for products on a page"
} | 41544 |
<p>I have a Java dynamic proxy with an invoke method that looks like this:</p>
<pre><code> @Override
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
Object result;
try {
//Not sure if this line is ok?
Token token = (Token) args[0];
System.out.println... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-13T12:34:54.707",
"Id": "71419",
"Score": "2",
"body": "Why the hassle to have a single return, while you have those throws in between?"
}
] | [
{
"body": "<p>Casting is never 'pretty'.... But, in a proxy situation like this (assuming you really need the proxy), it is possibly unavoidable.</p>\n\n<p>I can recommend though that you do it defensively... you should really do:</p>\n\n<pre><code>if (args.length > 0) {\n if (args[0] instanceof Token) {\... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-13T11:54:47.237",
"Id": "41546",
"Score": "3",
"Tags": [
"java"
],
"Title": "Is it ok to pull out specific arguments from a Java dynamic proxy invocation?"
} | 41546 |
<p>The following two functions are used to compress arbitrary Python objects and send them safely via socket or email, using only printable chars. In my specific message protocol, '=' signs are also not allowed; I could have replaced them or truncate them - I chose to truncate them.</p>
<p>I think they work quite well... | [] | [
{
"body": "<p>Avoid single letter variable names. Spell out the words they stand for to make your code easier to read.</p>\n\n<p>Your comments are useless. You are just restating the code in less detail. The only comment you should have is explaining about the '=' like you did in your post.</p>\n\n<p>Don't doub... | {
"AcceptedAnswerId": "41566",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-13T12:49:47.840",
"Id": "41549",
"Score": "7",
"Tags": [
"python",
"strings",
"serialization"
],
"Title": "Python compress and send"
} | 41549 |
<p>I am retrieving information from an <a href="http://en.wikipedia.org/wiki/SQLite" rel="nofollow">SQLite</a> database that gives me back around 20 million rows that I need to process. This information is then transformed into a dict of lists which I need to use. I am trying to use generators wherever possible.</p>
<... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-13T14:02:54.533",
"Id": "71433",
"Score": "3",
"body": "Despite your comment to my answer, I can still spot errors in your code. Can you please provide a working version of your code and some tests ?"
},
{
"ContentLicense": "CC... | [
{
"body": "<p>I have missed the whole point of your program but these comments might be useful to you anyway :</p>\n\n<p><strong>dict_generator</strong></p>\n\n<p>I might be wrong but <code>dict_generator(large_dict)</code> looks like <code>large_dict.iteritems()</code> (Python 2) / <code>large_dict.items()</co... | {
"AcceptedAnswerId": "41560",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-13T13:19:52.903",
"Id": "41551",
"Score": "6",
"Tags": [
"python",
"python-3.x",
"sqlite",
"generator",
"bioinformatics"
],
"Title": "Optimization for SQLite result set pa... | 41551 |
<p>I am making a program to find primes between the given range of numbers. Unfortunately, the algorithm I created is too slow. Do you have any ideas of how to optimize the code? </p>
<pre><code>import java.io.*;
import java.util.*;
public class Main {
public static void main(String[] args)throws IOException {
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-14T11:47:28.267",
"Id": "71612",
"Score": "0",
"body": "see http://stackoverflow.com/search?tab=newest&q=user%3a849891%20%22offset%20sieve%22"
}
] | [
{
"body": "<p>Firstly, let's take a look at minor issues:</p>\n\n<ol>\n<li><p>Whenever you do a <code>scanner.nextInt()</code>, there is a possibility of exception been thrown when an invalid input is given. You should always check if a valid <code>int</code> value is available to read before actually reading i... | {
"AcceptedAnswerId": "41564",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-13T15:27:21.503",
"Id": "41559",
"Score": "10",
"Tags": [
"java",
"performance",
"algorithm",
"primes",
"sieve-of-eratosthenes"
],
"Title": "Sieve of Eratosthenes optimiza... | 41559 |
<p>I'm starting to learn Clojure, and would like feedback on some code I wrote to manage database migrations. Any recommendations to make it more robust, efficient, idiomatic, elegant, etc... are welcome!</p>
<pre><code>(ns myapp.models.migrations
(:require [clojure.java.jdbc :as sql]
[myapp.models.d... | [] | [
{
"body": "<p>Honestly, I think this code looks great! Kudos -- this looks especially good for a beginner to Clojure. I have just a few minor improvements:</p>\n\n<pre><code>(defn create-migrations-table! []\n (when-not (table-exists? \"migrations\")\n (sql/db-do-commands db-spec\n (s... | {
"AcceptedAnswerId": "44754",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-13T16:49:12.287",
"Id": "41568",
"Score": "6",
"Tags": [
"sql",
"clojure"
],
"Title": "Database Migrations"
} | 41568 |
<p>I am using RequireJS JavaScript library. I have the following JavaScript module define for dataservice:</p>
<pre><code>define(['jquery'], function ($) {
var callApi = function (url, type, dataType, data, callback) {
$.ajax({
url: url,
type: type,
data: data,
... | [] | [
{
"body": "<p>I really like this code.</p>\n\n<p>Still, 2 observations:</p>\n\n<ul>\n<li>The code is awfully optimistic, no default error handling ?</li>\n<li><code>success</code> gets <code>data</code>, <code>textStatus</code>, and <code>jqXHR</code>. I would pass all 3 to the callback function.</li>\n</ul>\n"... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-13T17:07:31.377",
"Id": "41570",
"Score": "4",
"Tags": [
"javascript",
"require.js"
],
"Title": "Is there anything can be improved in this JavaScript module?"
} | 41570 |
<p>I am having some issue to use PHP5 <code>password_hash()</code> function. My server is not supporting it, so I am using a function to hash. Is this one secure?</p>
<pre><code>public function Pass_Hash ($password) {
$blowfish_salt = bin2hex(openssl_random_pseudo_bytes(22));
$hash = md5(crypt($password,... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-13T17:51:59.890",
"Id": "71467",
"Score": "2",
"body": "Why do you hash the `crypt` hash with `md5`?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-13T17:53:38.423",
"Id": "71469",
"Score": "0",
... | [
{
"body": "<p>No.</p>\n\n<h2>Concern 1:</h2>\n\n<p>Most password hashing libraries will perform a hash recursively 2<sup>n</sup> times. On modern systems, they choose 2<sup>8</sup> or higher (resulting in 512 hashes).</p>\n\n<p>While you are using a salt, you're only hashing the password once. This would allo... | {
"AcceptedAnswerId": "41582",
"CommentCount": "7",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-13T17:21:46.380",
"Id": "41571",
"Score": "12",
"Tags": [
"php",
"security",
"cryptography"
],
"Title": "Password hashing method"
} | 41571 |
<p><strong>Scenario:</strong> I am using a helper class called 'OutputHelper' to add a new record to the table 'Output'. My 'Output' object contains the following:</p>
<ul>
<li>ShiftID </li>
<li>Model</li>
<li>WorksOrder</li>
<li>LotNo</li>
<li>Quantity</li>
<li>ShiftHour</li>
</ul>
<p>I do not want a record to be ad... | [] | [
{
"body": "<h3>String literals vs. constants vs. enums</h3>\n<p>I think that the biggest terrible thing that you are doing here is 1) using magic string literals that are not defined as constants. 2) using a string when you can use an <code>enum</code> instead.</p>\n<pre><code>public enum SaveResult\n{\n Exi... | {
"AcceptedAnswerId": "41576",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-13T17:41:44.247",
"Id": "41572",
"Score": "10",
"Tags": [
"c#",
"entity-framework"
],
"Title": "'Better' way to handle adding a record"
} | 41572 |
<p>In researching the new .NET Async and Await keywords in .NET 4.5, I created a simple example showing how to update a progress bar and a label while an async function is running. I also included how to cancel the process while it is taking place.</p>
<p>To use the code below, create a Windows form and include two bu... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-13T18:06:45.963",
"Id": "71472",
"Score": "2",
"body": "Why not name `Button1` as `StartButton` and `Button2` as `StopButton`?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-13T18:12:25.960",
"Id": "71... | [
{
"body": "<blockquote>\n <p>The final asynchronous VB function we use is <code>WebClient.DownloadStringTaskAsync()</code>. This is arbitrary, and is used for example purposes only.</p>\n</blockquote>\n\n<p>This indicates to me that you should think about making this reusable, so that when you need to use the ... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-13T18:03:32.347",
"Id": "41573",
"Score": "1",
"Tags": [
".net",
"vb.net",
"async-await"
],
"Title": "Simple async/await progress bar"
} | 41573 |
<p>For example, with this differential equation, how can I do it in a pythonic way?</p>
<pre><code>dx/dt=f(x,t)
</code></pre>
<p>I have a way to do it, but I think this is not the most pythonic way:</p>
<pre><code>import numpy as np
dt=0.01
N_iter=10./dt
def f(x,t):
return x**2*t#insert your favorite function he... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-13T20:50:15.710",
"Id": "71499",
"Score": "2",
"body": "What was wrong with [`scipy.integrate`](http://docs.scipy.org/doc/scipy/reference/tutorial/integrate.html)?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "20... | [
{
"body": "<p>Using a <code>for</code> loop is not an <em>unpythonic</em> way at all. Instead, an Euler method could be implemented with a recursive function, but it not necessary and less optimized in Python.</p>\n\n<p>However, methods for <a href=\"http://numpy-discussion.10968.n7.nabble.com/vectorizing-recur... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-13T19:14:41.450",
"Id": "41580",
"Score": "6",
"Tags": [
"python",
"mathematics",
"numpy"
],
"Title": "What is the most pythonic way to solve a differential equation using the Euler ... | 41580 |
<p>I was using brute force to remove duplicate words since the lists were really small. But I want a solution that won't become too slow if the input grows.</p>
<p>This function creates a binary tree and inserts all words appearing on the list, then collects the unique words without sorting. Duplicate words are handle... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2015-09-14T17:54:26.457",
"Id": "191482",
"Score": "0",
"body": "If I'm not mistaken, isn't adding them to the Binary Search Tree somehow a sort?"
}
] | [
{
"body": "<p>This question boils down to the number and sequence of operations. If you are building one large list but removing lots of duplicates, use a hash table or sort and uniquify the list.</p>\n\n<p>Sorting and making the list unique is <em>O(n log n)</em> at best. Removing a duplicate is <em>O(n)</em> ... | {
"AcceptedAnswerId": "41616",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-13T19:34:29.620",
"Id": "41581",
"Score": "6",
"Tags": [
"performance",
"algorithm",
"c"
],
"Title": "Removing duplicate words from an unsorted list"
} | 41581 |
<p>For exercise, I wrote this code:</p>
<pre><code>def BigPrime(numP, plist = [], x = 1, counter =0):
while len(plist) <= numP:
if x == 1 or x == 2 or x == 5:
plist.append(x)
elif x % 2 is not 0 and int(str(x)[-1]) is not 5:
for div in plist[1:]:
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-13T21:43:38.543",
"Id": "71506",
"Score": "0",
"body": "1 is not a prime."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-13T22:28:27.320",
"Id": "71508",
"Score": "0",
"body": "Yeah you're righ... | [
{
"body": "<p>Well for starters:</p>\n\n<p><code>int(str(x)[-1])</code> is a really expensive operation:</p>\n\n<ol>\n<li>Go from integer (x) to a string that represents X</li>\n<li>Get the last element as a char [-1]</li>\n<li>Transform that char back to an integer</li>\n</ol>\n\n<p>Given what you're trying to... | {
"AcceptedAnswerId": "41593",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-13T19:45:13.327",
"Id": "41583",
"Score": "7",
"Tags": [
"python",
"optimization",
"primes"
],
"Title": "Strange performance difference"
} | 41583 |
<p>I have a Factory class for a queuing system I'm playing around with.</p>
<p>Consuming classes only care that they get a particular interface (Job) as a result of calling the factory's load method. </p>
<p>Some Jobs may require a database connection, so I want to inject a PDO instance. Others may require something ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-13T21:14:16.847",
"Id": "71502",
"Score": "0",
"body": "Are you... attempting to implement you own IoC container?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-13T21:17:03.577",
"Id": "71504",
"Sc... | [
{
"body": "<p>No. What you are doing is called <strong>The Service Locator Antipattern</strong>. And it's a bad thing.</p>\n\n<p>The basic rule of thumb: <strong>Don't inject the container!</strong>.</p>\n\n<p>The IoC container is supposed to be some sort of overseer, wiring your objects together at the bootstr... | {
"AcceptedAnswerId": "51818",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-13T21:02:35.243",
"Id": "41587",
"Score": "7",
"Tags": [
"php",
"design-patterns",
"dependency-injection"
],
"Title": "Is this a sensible way of using an IoC container?"
} | 41587 |
<p>This is an implementation of Bloom filter with <code>add</code> and <code>contain</code> functionality. I'm looking for code review, best practices, optimizations etc.</p>
<p>I'm also verifying complexity: \$O(1)\$</p>
<pre><code>public class BloomFilter<E> {
private final BitSet bitSet;
private fi... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-14T01:16:15.097",
"Id": "71528",
"Score": "1",
"body": "Instead of a comment telling us what `e` is, why not indicate why it is important? Why are setting it to `(int) Math.round((bitSetSize / (double)expectedNumberOfElements) * Math.l... | [
{
"body": "<ol>\n<li><p>Where's the class-level documentation?</p></li>\n<li><p> </p>\n\n<pre><code>private final MessageDigest md5Digest;\n</code></pre>\n\n<p>will need renaming if you change your hash function. Better to call it <code>hasher</code>?</p></li>\n<li><p> </p>\n\n<pre><code> * Constructs... | {
"AcceptedAnswerId": "41646",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-13T21:09:25.290",
"Id": "41589",
"Score": "4",
"Tags": [
"java",
"algorithm",
"bloom-filter"
],
"Title": "Bloom filter implementation"
} | 41589 |
<blockquote>
<p>Rewrite the routines <code>day_of_year</code> and <code>month_day</code> with pointers instead of indexing.</p>
</blockquote>
<p>The exercise is quite simple, this is the solution:</p>
<pre><code>int day_of_year(unsigned int year, int month, int day) {
int leap, i;
leap = ((year % 4 == 0 &a... | [] | [
{
"body": "<p>It would have been nice to see your <code>daytab</code> definition as well. I'll just assume that you're satisfied with the way it's defined, and that the functions work as intended.</p>\n\n<p>I find this condition in <code>month_day()</code> a bit monstrous:</p>\n\n<pre><code>if((leap == 1 &... | {
"AcceptedAnswerId": "41609",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-13T21:15:01.043",
"Id": "41590",
"Score": "4",
"Tags": [
"c",
"beginner",
"array",
"datetime",
"pointers"
],
"Title": "Writting day_of_month and month_day with pointers in... | 41590 |
<p>The following code is helpful to anyone who uses websockets in general... and is probably good template for anyone getting started in this area. I'd like to flesh this out into something that is more general purpose, and reusable, since the assumptions and questions I have will apply to many different situations. <... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2016-09-13T09:41:07.113",
"Id": "264583",
"Score": "0",
"body": "in Receive()\n\nwe could add support for handling fragmentation - happens when the sent message is large ..."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "... | [
{
"body": "<ol>\n<li>You may want to be using <code>CancellationToken</code>s via the overload for the async methods of the <code>ClientWebSocket</code> class to properly cleanup tasks on exit.</li>\n<li>1024 is usually the value I like to use for web connectivity, the MTU (Maximum Transmission Unit)1 for Ether... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-13T21:21:16.630",
"Id": "41591",
"Score": "28",
"Tags": [
"c#",
"task-parallel-library",
"websocket"
],
"Title": "Websockets client code and making it production-ready"
} | 41591 |
<p>I am currently in a data-structures class. The professor will be providing a singly linked list. I wanted to make a doubly linked list to "learn" how to do it. I tested it and I think it works. After making it, I did compare it to other doubly linked lists but I still want to see if there is anything I am missing. ... | [] | [
{
"body": "<p><strong>LinkNode</strong></p>\n\n<p>Assuming this is not an internal class:</p>\n\n<p>A huge problem (probably the biggest) with this is that <em>everything</em> is <code>public</code>. The three data members should be <code>private</code>. Data members should <em>always</em> be <code>private</c... | {
"AcceptedAnswerId": "41723",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-13T22:55:16.040",
"Id": "41596",
"Score": "30",
"Tags": [
"c++",
"linked-list"
],
"Title": "Validity of doubly linked list"
} | 41596 |
<p>I have been playing around with some improvements to some sort algorithms like Selection Sort and Merge Sort and I ended up needing some sort of measurement to check if my versions were any faster than the original algorithm form. I also had a need to implement some sort of time measurement before but never did it, ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-14T12:56:50.833",
"Id": "71621",
"Score": "0",
"body": "Can you explain what you are checking with `watch.Elapsed.Milliseconds < precision*(100-error)` condition?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "201... | [
{
"body": "<p>The thing you're timing is:</p>\n\n<pre><code>while (watch.Elapsed.Milliseconds < precision*(100-error))\n{\n action();\n ++iterations;\n}\n</code></pre>\n\n<p>The problem is that if action takes a very short time, then most of what you're timing is the time it takes to call the <code>wat... | {
"AcceptedAnswerId": "41605",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-13T23:16:56.367",
"Id": "41597",
"Score": "7",
"Tags": [
"c#",
"performance",
"unit-testing"
],
"Title": "Measuring a given method's execution time"
} | 41597 |
<p>Because I was spoiled with C# and the .NET framework, whenever I have to work with VB6 I feel like something's missing in the language. A little while ago I implemented a <code>List<T></code> for VB6 (<a href="https://codereview.stackexchange.com/questions/32618/listt-implementation-for-vb6-vba">here</a>), and... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-14T01:31:37.830",
"Id": "71529",
"Score": "1",
"body": "VB6 has the nasty habit of instantiating a new object if a method is called on something that is Nothing. I'm curious to see your test function for the Set n = Nothing bit. I su... | [
{
"body": "<p>I think the itself class might be mis-named, because it is really 'Empty-able' not Nullable or 'Nothing-able'.</p>\n\n<p>You have to keep in mind that Empty, Null, and Nothing are very different concepts in VB6. Setting and object to Nothing is basically just syntactic sugar for releasing the poin... | {
"AcceptedAnswerId": "41607",
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-14T00:49:00.190",
"Id": "41601",
"Score": "11",
"Tags": [
"vba",
"type-safety",
"vb6",
"null"
],
"Title": "Nullable<T> Implementation for VB6/VBA"
} | 41601 |
<p>Is this the correct way to implement a thread-safe concurrent FIFO queue in C++? It requires passing <code>unsigned char*</code> arrays of binary data.</p>
<p><strong>Thread Safe Concurrent Queue</strong></p>
<pre><code>#include <queue>
#include <pthread.h>
class concurrent_queue
{
private:
std... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-14T13:10:46.147",
"Id": "71622",
"Score": "1",
"body": "Please read [Can I edit my own question to include suggested changes from answers?](http://meta.codereview.stackexchange.com/q/1482/34757)"
},
{
"ContentLicense": "CC BY-S... | [
{
"body": "<p>You are guarding the state of one variable</p>\n\n<pre><code>std::queue<unsigned char*> _queue_;\n</code></pre>\n\n<p>So you only have one mutex.</p>\n\n<pre><code>pthread_mutex_t push_mutex;\npthread_mutex_t pop_mutex;\n</code></pre>\n\n<p>If you have two then push and pop can modify queue ... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-14T01:46:35.913",
"Id": "41604",
"Score": "22",
"Tags": [
"c++",
"thread-safety",
"queue",
"pthreads"
],
"Title": "Thread-safe concurrent FIFO queue in C++"
} | 41604 |
<p>I always add an exception handler when a new method is created, and I don't know if it is a good or bad practice. I thought it may be a bit of an annoyance when viewing the source code.</p>
<p>Is it a good practice to put logging functions in the exception block?</p>
<pre><code>def insert_new_camera(self, camera,... | [] | [
{
"body": "<p>Don't do that.</p>\n\n<p>If you log your exceptions at every function, you'll print the same exception over and over and over again. Its only useful the first time, after that its a pain.</p>\n\n<p>It will also make your code much harder to read and write.</p>\n\n<p>You should log the exception wh... | {
"AcceptedAnswerId": "41611",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-14T03:09:04.857",
"Id": "41610",
"Score": "23",
"Tags": [
"python",
"exception"
],
"Title": "Is it a good practice to put an exception handler in every method?"
} | 41610 |
<p>A user must query a large database for information repeatedly. This query may take up to ~7 seconds. This must be done asynchronously. Only one query will be running at a time.</p>
<p>I did not create a new thread for each query as the code would be less clean, less maintable, etc.</p>
<p>I did not use ThreadPool... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-14T03:44:40.953",
"Id": "71549",
"Score": "1",
"body": "What advice are you seeking? You are either wasting a thread if these requests are infrequent or slowing users making these if frequent. Neither of these will be terrible, but you... | [
{
"body": "<p>As it stands, I do not really see any problem. You are using the thread as I would think it should be used.</p>\n\n<p>One note, you could add a priority to the queue so someone could be added at the top of the queue instead of the bottom. That way that someone is next in line and won't have to wai... | {
"AcceptedAnswerId": "42516",
"CommentCount": "9",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-14T03:24:41.587",
"Id": "41612",
"Score": "11",
"Tags": [
"c#",
"multithreading"
],
"Title": "Long running, frequent async advice?"
} | 41612 |
<p>I need a little help in finding a better solution. In the screen shot below any change to the forecast line I need to find the value in column B. The screen shot is only a sample in my production sheet the row count is currently 4200.</p>
<pre><code> Column A Col B Col C Col D Col E
Row 5 ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-14T04:46:50.280",
"Id": "71562",
"Score": "3",
"body": "It isn't exactly clear what you are trying to accomplish here. Is the code you posted in a Worksheet event, a custom defined function, a macro, or something else? Can you post s... | [
{
"body": "<p>Not relevant to your algo, but you shouldn't be using <code>\"\"</code> like this; use the <code>vbNullString</code> language constant instead, which consumes 0 memory (as opposed to <code>\"\"</code> which has the overhead of a <code>string</code>).</p>\n\n<p>As for suggestions, in order to find ... | {
"AcceptedAnswerId": "41617",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-14T04:34:48.153",
"Id": "41615",
"Score": "12",
"Tags": [
"vba",
"excel"
],
"Title": "Suspiciously redundant Excel macro code"
} | 41615 |
<p>This code lists the permutations of the string, and eliminates duplicates if any. I'm looking for code review, best practices, optimizations etc.</p>
<p>I'm also verifying complexity: \$O(n! * n)\$ as time complexity and \$O(n * n)\$ as space complexity, where \$n\$ is length of the input string.</p>
<pre><code>pu... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-14T08:43:51.483",
"Id": "71599",
"Score": "2",
"body": "Your space complexity is definitely not O(n*n). And cannot be less than O(n*n!) (for n distinct chars) because you have n! different arrays with n chars each. This program fills ... | [
{
"body": "<ol>\n<li>Best beginner's code I've seen. Possibly ever. Admittedly, I haven't reviewed too many beginner's programmes, but this one was definitely an easy review.</li>\n<li>Only style change I'd suggest is to avoid the single-line <code>if (s.charAt(currIndex) == s.charAt(i)) continue;</code>. It... | {
"AcceptedAnswerId": "41627",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-14T04:59:02.570",
"Id": "41618",
"Score": "3",
"Tags": [
"java",
"algorithm",
"strings",
"combinatorics"
],
"Title": "Permutation of a string eliminating duplicates"
} | 41618 |
<p>I've written an Erlang implementation of the genetic algorithm for a "Hello World" program as described <a href="http://www.puremango.co.uk/2010/12/genetic-algorithm-for-hello-world/">here</a>.</p>
<p>This is my first time writing any code in Erlang and also my first time writing code in a functional language, so I... | [] | [
{
"body": "<h1>General Remarks</h1>\n\n<ul>\n<li>Give your constants all uppercase names <a href=\"http://erlang.org/doc/reference_manual/macros.html\">see Style in reference manual</a>.</li>\n<li>If you make the pool size a parameter in the <code>run_genetic</code> function, you should match it with an unbound... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-14T05:27:04.077",
"Id": "41622",
"Score": "11",
"Tags": [
"beginner",
"algorithm",
"functional-programming",
"erlang",
"genetic-algorithm"
],
"Title": "Genetic algorithm for ... | 41622 |
<p>I created a Java Trie as part of a project someone challenged me to do. I'm not sure that this is the most efficient way to go about producing a Trie, I know that this works but I was hoping someone with some professional experience could enlighten me on anything I might be doing fundamentally wrong.</p>
<p>I'm stu... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-14T09:35:41.807",
"Id": "71604",
"Score": "2",
"body": "also small note, while you are lowercasing the words you are saving the contains function is not lowered, so it will always return false. especially surprising seeing as the word ... | [
{
"body": "<p>Your <code>Trie</code> class looks fine.</p>\n\n<p>In <code>TrieNode</code> I can see a few problems with you algorithm:</p>\n\n<p><strong><code>addWord</code></strong></p>\n\n<ol>\n<li>You do not properly check for the edge conditions, i.e. when <code>word</code> is <code>null</code> or empty.</l... | {
"AcceptedAnswerId": "41649",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-14T08:44:49.150",
"Id": "41630",
"Score": "6",
"Tags": [
"java",
"trie"
],
"Title": "Trie (tree form) in Java"
} | 41630 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.