body stringlengths 25 86.7k | comments list | answers list | meta_data dict | question_id stringlengths 1 6 |
|---|---|---|---|---|
<p>I need to improve this section of code:</p>
<pre><code>
uint32_t to_handle = 0;
uint32_t test_const1 = Constraint3::VAL1 + Constraint3::VAL2;
uint32_t test_const2 = Constraint1::VAL2 + Constraint1::VAL4 + Constraint1::VAL8;
uint32_t test_const3 = Constraint2::VAL1 + Constraint2::VAL2 + Constraint2... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-01T15:06:36.880",
"Id": "39770",
"Score": "0",
"body": "So to be chosen (the first time), the item has to be zero (`item & to_handle == item` with `to_handle=0`). Or is that meant to be `test_const1`?"
},
{
"ContentLicense": "C... | [
{
"body": "<p><code>to_handle</code> actually varies, but the <code>test_const</code>s are all constant, so we can give the compiler a hint here</p>\n\n<pre><code>const uint32_t test_const1 = Constraint3::VAL1 + Constraint3::VAL2;\nconst uint32_t test_const2 = Constraint1::VAL2 + Constraint1::VAL4 + Constraint1... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-01T14:23:56.970",
"Id": "25687",
"Score": "3",
"Tags": [
"c++",
"performance",
"boost"
],
"Title": "Selecting element from a collection based on bitwise-and result"
} | 25687 |
<ol>
<li>I find the tail in the first while loop and store it in the <code>tailEnd</code> node. </li>
<li>I update the tail to the previous node and change the <code>tail.next</code> to point to the previous node.</li>
<li>Once <code>head.next.next == head</code>, the reversing is finished.</li>
</ol>
<p></p>
<pre>... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-03T11:02:11.467",
"Id": "39904",
"Score": "0",
"body": "Assigning a local variable more than once decreases understandability. Especially *never* assign to a parameter."
}
] | [
{
"body": "<p>This could be done simpler and more efficiently. This only requires one iteration through the list:</p>\n\n<pre><code>public static LinkedList reverse(LinkedList Node) {\n LinkedList previous = null;\n while (Node != null) {\n LinkedList next = Node.next;\n Node.next = previous... | {
"AcceptedAnswerId": "25717",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-01T17:18:14.270",
"Id": "25696",
"Score": "4",
"Tags": [
"java",
"linked-list"
],
"Title": "Critique Request: Reversing a singly linked list"
} | 25696 |
<p>I'm looking for OOP tips or advice.</p>
<pre><code> ;(function ( $, window, document, undefined ) {
if ( typeof Object.create !== 'function' ) {
Object.create = function (o) {
function F() {}
F.prototype = o;
return new F();
};
}
if (!Function.prototype.bind) { // check if... | [] | [
{
"body": "<p>From a once over:</p>\n\n<ul>\n<li>Your code is not consistently indented, especially the first dozen lines need some TLC</li>\n<li><code>$.component = function( name, object ) {</code> needs commenting, it is not clear what this is trying to achieve.</li>\n<li><code>evt</code> is an unfortunate p... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-01T17:42:13.953",
"Id": "25697",
"Score": "3",
"Tags": [
"javascript",
"jquery",
"plugin"
],
"Title": "jQuery dropdown plugin"
} | 25697 |
<p>I am working on an application which first loads a 'settings' panel and then loads the application. It all works fine, loading the settings panel takes a few seconds longer than I would like it to. The problem is in loading the settings panel, not the application itself.</p>
<p>I have a simple main method:</p>
<pr... | [] | [
{
"body": "<p>Looks like most of the time is spent in the <code>frame.pack()</code> call. Replacing it with <code>frame.setSize(222, 181);</code> is a lot faster. I simply ran the code once with <code>frame.pack()</code> and added a line to output the resulting frame size. Then replaced the <code>pack()</code> ... | {
"AcceptedAnswerId": "25726",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-01T18:34:36.607",
"Id": "25699",
"Score": "3",
"Tags": [
"java",
"performance",
"swing"
],
"Title": "JPanel rendering too slowly"
} | 25699 |
<p>I created a reusable function for changing block name in Djago templates. I want to know if the code is good or is there any probable issues in it. I developed the function as a hack for the following <a href="https://stackoverflow.com/questions/16320010/is-there-a-way-to-set-name-of-a-block-using-variables-in-djang... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-16T17:17:09.053",
"Id": "44851",
"Score": "0",
"body": "have you tried running django's unit tests? is there a unit test for templates for dealing with similar issues and can you write your own? That's the only thing I can think of jud... | [
{
"body": "<p>This seems valid, and I don't think it should mess up Django's functionality.\nSome improvements are possible.</p>\n\n<hr>\n\n<p>This is not <em>Pythonic</em>:</p>\n\n<blockquote>\n<pre><code>if len(extend_nodes) == 0:\n return\n</code></pre>\n</blockquote>\n\n<p>Write like this:</p>\n\n<pre><c... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-01T19:21:36.310",
"Id": "25700",
"Score": "4",
"Tags": [
"python",
"django"
],
"Title": "Django template block name changing function"
} | 25700 |
<p>I have some code for a calculator, and I was wondering what I could look at to make the code smaller, easier to read or better in any way. I'm particularly looking at my global variable <code>x</code>. Is there any way to change the code to completely remove that? Someone mentioned a <code>getTwoInputs()</code> func... | [] | [
{
"body": "<p>Personally, I find long blocks of <code>if</code> statements to be difficult to read and maintain. Instead, I populated a dictionary with function handles, pointing to each of your arithmetic operations. I then added a second set of keys, but taking each of your function names, grabbing the first ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-01T19:42:42.393",
"Id": "25701",
"Score": "5",
"Tags": [
"python",
"python-3.x",
"calculator"
],
"Title": "Four-function calculator with roots and powers"
} | 25701 |
<p>I'm extracting 4 columns from an imported CSV file (~500MB) to be used for fitting a <code>scikit-learn</code> regression model.</p>
<p>It seems that this function used to do the extraction is extremely slow. I just learnt python today, any suggestions on how the function can be sped up?</p>
<p>Can multithreading/... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-01T22:55:18.333",
"Id": "39821",
"Score": "0",
"body": "Can you provide a sample of the `train_data_path`?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-02T02:06:29.573",
"Id": "39840",
"Score": "... | [
{
"body": "<p><code>titles = [jobs[i]['title'] for i, v in enumerate(jobs)]</code> can (should?) be rewritten :</p>\n\n<p><code>titles = [j['title'] for j in jobs.items()]</code> \nbecause we just want to access the value at position i (<a href=\"https://stackoverflow.com/questions/10498132/how-to-iterate-over-... | {
"AcceptedAnswerId": "25715",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-01T19:55:07.530",
"Id": "25702",
"Score": "1",
"Tags": [
"python"
],
"Title": "Speed up simple Python function that uses list comprehension"
} | 25702 |
<p>for the following function </p>
<pre><code>#!/usr/bin/ruby -w
e=0
g=0
h=1
while h < 10000000
a = h
f=0
while f !=1 && f!= 89
d=0
f=0
while a.to_s[d] != nil
e = a.to_s[d]
b = e.to_i
f += b**2
d+=1
end
a = f... | [] | [
{
"body": "<p>In benchmarking various techniques for this question, I found the biggest speed boost was in abandoning string conversion in favor of <code>%10</code> to get the individual digits - try using a method like this to get your sums:</p>\n\n<pre><code>def sum_square_digits(n)\n sum = 0\n until n == 0... | {
"AcceptedAnswerId": "25711",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-01T20:22:22.307",
"Id": "25703",
"Score": "1",
"Tags": [
"ruby"
],
"Title": "speed up square digit function"
} | 25703 |
<p>I just started to make a static website after years of not playing in that field (I stopped in the early 2000s) just to try to remember what I lost over time. Before going any further, I wanted to know if the way I'm building my page is working alright. It can be seen at <a href="http://kaivoslab.site44.com/" rel="n... | [] | [
{
"body": "<p>The best way to make your code minimal and keep all browsers aligned is to use some front-end framework.</p>\n\n<p>The most popular and widely used framework is <a href=\"http://twitter.github.io/bootstrap/\" rel=\"nofollow\">bootstrap</a> from Twitter. This will handle all nitty gritty things for... | {
"AcceptedAnswerId": "25736",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-02T01:06:18.640",
"Id": "25716",
"Score": "1",
"Tags": [
"html",
"css"
],
"Title": "HTML Containers and Positioning"
} | 25716 |
<p>I have this CoffeeScript code running <a href="http://chapter.zmgc.net" rel="nofollow">here</a> (with <a href="https://github.com/TZM/tzm-blade" rel="nofollow">TZM-Blade</a>) and would like to have your opinion on how to better optimize it.</p>
<pre><code>express = require "express"
gzippo = require "gzippo"
assets... | [] | [
{
"body": "<p>Get rid of all those commas:</p>\n\n<pre><code>i18n.init\n detectLngQS: \"lang\"\n ,ns: { namespaces: ['ns.common', 'ns.layout'], defaultNs: 'ns.common'}\n ,resSetPath: \"./locales/__lng__/new.__ns__.json\"\n ,...\n</code></pre>\n\n<p>CoffeScript doesn't need them:</p>\n\n<pre><code>i18n.init\... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-02T01:54:54.807",
"Id": "25719",
"Score": "1",
"Tags": [
"node.js",
"coffeescript",
"express.js"
],
"Title": "Express, blade with connect-assets"
} | 25719 |
<p>Referring to <a href="https://stackoverflow.com/questions/16328828/one-thread-controlling-many-others">this post</a>, my problem (summarized):</p>
<p>One main thread waits for connections, on <code>accept()</code> spawns a new thread for each connection. After we received <code>n</code> connections, the main thread... | [] | [
{
"body": "<p>The threading mechanics mostly look correct. Your main thread and your subthreads only share the <code>mCommandToExecute</code> and <code>commands</code> variables. The subthreads only read them between <code>mWaitForCommand</code> and <code>mWaitForAllDone</code>, and the main thread reads and ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-02T02:48:31.577",
"Id": "25720",
"Score": "4",
"Tags": [
"c",
"multithreading",
"pthreads"
],
"Title": "Uses of barriers for one main thread controlling n threads"
} | 25720 |
<p>I have to write a program in C that reads an array with <em>n</em> elements and then displays how many elements are bigger than the average of the elements of the vector.</p>
<p>Is there any other way to do this in a shorter or simpler way?</p>
<pre><code>#include <stdio.h>
#include <stdlib.h>
#define... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-02T11:36:09.633",
"Id": "39867",
"Score": "0",
"body": "You seem to have forgotten the value: `printf(\"The number of elements above the average is %d:\");`"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-0... | [
{
"body": "<p>How about this change to countAboveAverage. For each iteration, there is an assignment whether or not \"count\" has changed.</p>\n\n<pre><code>int countAboveAverage(int arr[], int n, double average) {\n int count=0, i;\n\n for(i=0; i<n; i++) {\n if(arr[i]>average)\n count++;\n }\n return ... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-02T07:22:40.553",
"Id": "25725",
"Score": "3",
"Tags": [
"c",
"array"
],
"Title": "Displaying the number of elements larger than the average of an array"
} | 25725 |
<p>I have an object that's generated from an incoming json string. The string is deserialized in a custom converter that returns an object. This object has a method called <code>IsValidForDB</code> that checks if the properties are valid. This method looks like this:</p>
<pre><code>public class MyObject
{
public bo... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-01T23:40:04.617",
"Id": "39859",
"Score": "0",
"body": "Are the conditions you check all 100% different from each other? If there is any way you can code it more generically you should. Long if/else if chains are ugly ugly."
},
{
... | [
{
"body": "<p>If you need to check all of these conditions and they are all different then it would seems there's no getting around having to validate them in this sort of manner. Is validation during deserialization an option (and return an error or mark the deserialized object as faulty). Or checks on the db ... | {
"AcceptedAnswerId": "25729",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-01T23:38:33.080",
"Id": "25727",
"Score": "7",
"Tags": [
"c#"
],
"Title": "pattern for validating an object against some condition"
} | 25727 |
<p>I have a long-running task that processes an input file and then uploads it to a web server. The processing part can be interrupted (with cleanup) but the upload shouldn't be interruptable so that we know whether the server received the file correctly.</p>
<p>My thread looks like this (I'm using PyQt but I imagine ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-02T12:34:40.493",
"Id": "39868",
"Score": "0",
"body": "How does do_processing_task find out it was stopped?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-02T12:40:48.667",
"Id": "62380",
"Score":... | [
{
"body": "<p>The code itself is readable: it makes sense to check if the thread is still running before doing extra work. It's not the usual <code>if</code> spaghetti, and is, I think, a common threading idiom. But it's hard to understand the logic behind the code and I'm not sure it works as intended.</p>\n\n... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-02T12:18:54.653",
"Id": "25733",
"Score": "2",
"Tags": [
"python",
"multithreading",
"pyqt"
],
"Title": "Uploading an input file to a web server"
} | 25733 |
<p>I have some jquery that pretty much just runs a small drop-line navigation. Each tab size differs, so i used the same jquery line 5 times to make it look and function the way i wanted it to. I'm sure there is a way to condense it but im not quite a pro. Can anybody help me out a bit? The jquery is below, and here is... | [] | [
{
"body": "<p>You're jQuery can be written in one simple function as a catch all for the entire navigation. As you stated you think it could be condensed, you'd be right. As a rule of thumb if you see yourself writing the same thing over and over you should be able to cut it all down into one function.</p>\n\n<... | {
"AcceptedAnswerId": "25744",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-02T14:56:36.667",
"Id": "25741",
"Score": "2",
"Tags": [
"javascript",
"jquery",
"html"
],
"Title": "Condensing Navigation jQuery"
} | 25741 |
<p>I'm trying to compete on HackerRank and my answer got accepted, but the times are not so good. I have a friend who sent the answer in C# too but somehow made it a lot faster. I'm wondering what can I do to improve it.</p>
<pre><code>using System;
using System.Collections.Generic;
using System.IO;
using System.Text;... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-02T18:51:48.097",
"Id": "39891",
"Score": "2",
"body": "What's this supposed to do? I can't make any sense of it. You should use descriptive variable names."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-0... | [
{
"body": "<p>There are a lot of stylistic changes I'd normally suggest, but I'm going to forgo that to mention three very simple optimizations:</p>\n\n<ul>\n<li>remove <code>new Char[] { ' ', '\\t', '\\n' }</code> from within the loop. No need to recreate this object every time as it's an invariant.</li>\n<li>... | {
"AcceptedAnswerId": "25752",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-02T15:07:58.653",
"Id": "25742",
"Score": "2",
"Tags": [
"c#",
"programming-challenge"
],
"Title": "Improving performance hacker rank Median"
} | 25742 |
<p>I'd like to design a settings class thread save. The settings have 2 attributes: <code>String x</code> and <code>int y</code> and should provide listener functionality to notify listener about changes. The problem is, how to make it thread safe.</p>
<p>Here is a complete code:</p>
<pre><code>package org.example;
... | [] | [
{
"body": "<p>Java isn't my first language, so bear with me if I confuse the syntax a bit. I agree that your <code>copyFrom</code> is not atomic in that the changes are externally visible before the copy is complete. I would <em>also</em> say that it isn't atomic because the <em>origin</em> is not locked and so... | {
"AcceptedAnswerId": "25753",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-02T15:12:27.230",
"Id": "25743",
"Score": "1",
"Tags": [
"java",
"thread-safety"
],
"Title": "Thread safe settings"
} | 25743 |
<p>I'm trying to improve my javascript and have been using the revealing module pattern to good effect but I noticed that code in the module not in a function or the return is executed on creation have utilised this, such as:</p>
<pre><code>var MyModule = function ($) {
setUp();
function setUp() {
//... | [] | [
{
"body": "<p>In this case, <a href=\"https://stackoverflow.com/q/9304473/575527\">you don't actually use the <code>new</code> keyword</a>. It's valid to return something from a constructor, since constructors are functions as well. But when you use <code>new</code> to construct objects, it should return an ins... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-02T17:38:25.480",
"Id": "25747",
"Score": "4",
"Tags": [
"javascript",
"revealing-module-pattern"
],
"Title": "Revealing module implicity calling an internal function - is this a “smell”... | 25747 |
<p>Object interfaces allow you to create code which specifies which methods a class must implement, without having to define how these methods are handled.</p>
<p>Interfaces are defined using the <strong>interface</strong> keyword, in the same way as a standard class, but without any of the methods having their conten... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-02T19:34:19.197",
"Id": "25749",
"Score": "0",
"Tags": null,
"Title": null
} | 25749 |
Object interfaces allow you to create code which specifies which methods a class must implement, without having to define how these methods are handled. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-02T19:34:19.197",
"Id": "25750",
"Score": "0",
"Tags": null,
"Title": null
} | 25750 |
<p>I wish to ensure I am using the "best" pattern when using an Execute As/Revert from within a Try/Catch block on SQL Server 2012. The below code "seems" to behave correctly... Am I missing anything or are there any security concerns, "better" approaches, etc.? </p>
<p>Below is my code:</p>
<pre><code>CREATE PROCEDU... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-06T21:38:06.200",
"Id": "40056",
"Score": "0",
"body": "I realize that your code is an artificial example, but I don't immediately see what problem you're trying to solve. It looks like you want procedure 1 to call procedure 2, which s... | [
{
"body": "<p>One thing to be wary of is if you grant execute permissions on a schema in sql server, then no matter what's in the Stored Procedure, the user is granted rights to execute that stored procedure and whatever it entails.</p>\n\n<p>So I <strong>think</strong> that, even if you change user contexts, t... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-02T19:45:48.327",
"Id": "25751",
"Score": "4",
"Tags": [
"sql",
"security",
"sql-server",
"t-sql"
],
"Title": "SQL Server 'Execute As'/Revert pattern in a 'Try/Catch' Block"
} | 25751 |
<p>The following code ended up to be ugly and I can't find a way to make it better. Any comments will be very appreciated.</p>
<p>The expected HTML output is this (it is working, the output is just for guidance):</p>
<pre><code><div class="attachments-face">
<div class="files">
<div class="custom... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-02T21:09:56.930",
"Id": "25754",
"Score": "1",
"Tags": [
"ruby",
"ruby-on-rails"
],
"Title": "Review of helper method that adds some divs"
} | 25754 |
<p>I had my original threading code which worked well, but since my tasks were shortlived, I decided to use thread pools through <code>ExecutorService</code>.</p>
<p>This was my original code</p>
<pre><code>public class MyRun implements Runnable
{
private Socket socket = null;
public MyRun(Socket s)
{
... | [] | [
{
"body": "<p>A few simple remarks :</p>\n\n<ul>\n<li><code>thread = new Thread(this, \"SocketThread\");</code> is no longer needed in MyRun, since the ExecutorService is the one creating and managing the <code>Thread</code>s.</li>\n<li>you will want to call <code>execService.shutDown()</code> to properly clean... | {
"AcceptedAnswerId": "25764",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-03T11:31:51.983",
"Id": "25763",
"Score": "5",
"Tags": [
"java",
"multithreading"
],
"Title": "Moving from normal threads to ExecutorService thread pools in java"
} | 25763 |
<p>I want to get just the first and last values in a date range. I have the following code:</p>
<pre><code> using (var myEntities = new dataEntities())
{
var myValues = (from values in myEntities.PointValues
where values.PointID == dataValue && values.DataTime >= fromDate &... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-05T07:55:13.237",
"Id": "39987",
"Score": "0",
"body": "Looks like Last() might be implemented already potentially? http://msdn.microsoft.com/en-us/library/bb354927%28v=vs.100%29.aspx. Guess it might depend on your Target framework t... | [
{
"body": "<p>What you could do is to remove the <code>ToList()</code> from your query. This would change your code from making a single query that returns many values to two queries, each returning a single value.</p>\n",
"comments": [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate... | {
"AcceptedAnswerId": "25771",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-03T14:22:50.223",
"Id": "25769",
"Score": "7",
"Tags": [
"c#",
"asp.net",
"linq",
"entity-framework"
],
"Title": "Using Linq to select the first and last values"
} | 25769 |
<p>I have this interpretation of <a href="http://en.wikipedia.org/wiki/Conway%27s_Game_of_Life" rel="nofollow">John Conway's Game of Life</a> in Python 3.3.1:</p>
<pre><code>#JOHN CONWAY'S GAME OF LIFE
def countSurrounding(universe, a, b):
count = 0
surrounding = [[a - 1, b - 1],
[a - 1, b ... | [] | [
{
"body": "<p>Overall, it seems really really good to me and I like the way you use IndexError to count surrounding cells in a concise way without bothering about edge cases.</p>\n\n<p>Here are a few comments anyway :</p>\n\n<p><strong>Removing a useless check</strong></p>\n\n<p>This is not much but you can rem... | {
"AcceptedAnswerId": "25776",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-03T16:41:02.730",
"Id": "25772",
"Score": "4",
"Tags": [
"python",
"game-of-life"
],
"Title": "Game of Life in Python"
} | 25772 |
<p>I realize this won't stop people who know what they're doing, just a project I decided to undertake while I'm trying to learn Python and Tkinter. Would love some input!</p>
<pre><code>import Tkinter
import base64
class crypt_mod(Tkinter.Tk):
def __init__(self, parent):
Tkinter.Tk.__init__(self, parent)... | [] | [
{
"body": "<pre><code>import Tkinter\nimport base64\n\nclass crypt_mod(Tkinter.Tk):\n</code></pre>\n\n<p>Do you know about <a href=\"http://www.python.org/dev/peps/pep-0008/\" rel=\"nofollow\">PEP8</a>? It's a style guide for Python that lots of Python developers follow. One of the things it says is that class ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-03T16:59:49.900",
"Id": "25773",
"Score": "3",
"Tags": [
"python"
],
"Title": "Made a simple gui string encrypter, just to obfuscate plaintext"
} | 25773 |
<p>I wrote two functions to return point coordinates spanning the n-dimensional hypercubic lattice of half size K (meaning that the coordinates along each axis go from -K,.. 0.. K). The n-dimensional cube volume should have (2*K+1)**N grid points.</p>
<p>The functionality is split across two functions: one for returni... | [] | [
{
"body": "<ul>\n<li>I find your code hard to understand. You should write docstrings and more comments.</li>\n<li>The function <code>get_k_cube_shell_of_dim</code> is long and complicated. We can't even view it all at once on this page. I did not go through all of it. Break it into smaller functions.</li>\n<li... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-03T18:48:57.343",
"Id": "25777",
"Score": "2",
"Tags": [
"python",
"computational-geometry"
],
"Title": "Recursive algorithm to obtain grid points inside a n-cube volume or surface"
} | 25777 |
<p>I have the following method which I use in multiple places, but it only differs by a few different things, so I was wondering how I can refactor it so I can have it in a common class and call it from there everywhere.</p>
<pre><code>public override DataTable GetRecords(QueryContext queryContext, out int totalRecord... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-03T22:54:09.030",
"Id": "39929",
"Score": "5",
"body": "Is an ORM available to you such as EntityFramework?"
}
] | [
{
"body": "<p>For this, I'll be addressing the second code snippet you've given, as it seems to be heading in the right track.</p>\n\n<p>I'm assuming QueryContext is custom code, because I couldn't find any reference to it in the MSDN and you haven't provided any other tags. In a case like this it would probabl... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-03T18:51:00.593",
"Id": "25778",
"Score": "3",
"Tags": [
"c#"
],
"Title": "How can I refactor this method so I don't use it in multiple places?"
} | 25778 |
<p>I am working on <a href="http://projecteuler.net/problem=37" rel="nofollow">Project Euler problem 37</a> and I have the following program:</p>
<pre><code>#!/usr/bin/ruby -w
require 'prime'
h=11
y=0
x=0
while x < 11
if h.prime? == true
boo = true
f=0
n=h
c=0
while ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-03T20:35:05.790",
"Id": "39925",
"Score": "0",
"body": "i dont know any ruby, but i was reading about Truncatable primes and found this post that have 2 different approaches to solver it, maybe it can help you. http://www.mathblog.dk/p... | [
{
"body": "<p>Some small notes on style:</p>\n\n<ul>\n<li><p><code>if h.prime? == true</code> should be <code>if h.prime?</code>; never use <code>method? == true</code> or <code>method? == false</code>, use <code>if</code> and <code>unless</code>.</p></li>\n<li><p>I would replace your <code>if h.prime?</code> w... | {
"AcceptedAnswerId": "25782",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-03T18:58:17.310",
"Id": "25780",
"Score": "1",
"Tags": [
"ruby",
"primes",
"project-euler"
],
"Title": "Project Euler problem 37: truncatable primes"
} | 25780 |
<p>The application is a student administration system using a .csv file for persistence as part of our school project.</p>
<p>This is my first created a basic DAO. I'd like to have some feedback about what could be improved until now and how I could write good unit tests for the UserDAO.class.</p>
<p><strong>UserDAO... | [] | [
{
"body": "<p>It looks like there is a potential bug in <code>writeCSV()</code>. You open a temp file and write to it, but then you move that file before closing it.</p>\n\n<pre><code>try {\n File temp = File.createTempFile(\"tempfile\", \".tmp\");\n beanWriter = new CsvBeanWriter(new FileWriter(temp), Cs... | {
"AcceptedAnswerId": "25811",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-03T22:42:54.420",
"Id": "25788",
"Score": "1",
"Tags": [
"java",
"csv"
],
"Title": "Student administration application using a .csv file for persistence"
} | 25788 |
<p>I have a Clock class who inherites from pyglet.clock.Clock and behaves like a Singleton.</p>
<p>Into the constructor method I have the following line:</p>
<pre><code>pyglet.clock.set_default(self)
</code></pre>
<p>Who changes the state of the default clock of pyglet, setting my Clock object as the default clock.<... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-04T02:52:56.590",
"Id": "39934",
"Score": "0",
"body": "Why are you subclassing pyglet's Clock?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-04T03:01:17.847",
"Id": "39935",
"Score": "0",
"bo... | [
{
"body": "<p>In Python, a singleton should be a module, not a class. There's no good reason to define a class for that. That's what's going on in pyglet's case with <code>pyglet.clock</code>. If you want to define your own version you should do something like:</p>\n\n<pre><code># myclock.py\n\nfrom pyglet.cloc... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-04T02:09:32.457",
"Id": "25790",
"Score": "3",
"Tags": [
"python",
"design-patterns",
"constructor",
"pyglet"
],
"Title": "Changing the state of another entity into the construct... | 25790 |
<p>I am trying to teach myself a new language in three weeks. Can you please give me some advice on how to clean my code and make it faster or more reliable? This works fine. I don't "need" any 'free' code, I need the knowledge of what I am doing wrong, and what I am doing right so I can learn.</p>
<pre><code> Using... | [] | [
{
"body": "<p>As you're beginner, your code can be considered ok.</p>\n\n<p>However you may want to consider following points which help you to write reliable (maintainable) code and improve performance.</p>\n\n<ul>\n<li>You want to store connectionstring to some common place like web.config. You don't have to ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-04T03:02:49.180",
"Id": "25792",
"Score": "2",
"Tags": [
"sql",
"vb.net"
],
"Title": "VB.NET | SQL Code Cleanup"
} | 25792 |
<p>I'm in the process of cross-training myself from CFML to PHP as part of a learning exercise. I'm learning from the docs and online tutorials and googling.</p>
<p>As an initial exercise, I've knocked together the following PHP facsimile of some CFML code I have. I have a <a href="http://adamcameroncoldfusion.blogspo... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-10-23T19:37:38.133",
"Id": "123521",
"Score": "0",
"body": "It boggles my mind that you thought that edit was necessary, Jamal. Do you not have anything better to do with your time? My wording was deliberate, and you have removed the tone... | [
{
"body": "<p>Took this from your blog post:</p>\n\n<blockquote>\n <p>What I need to do is this:</p>\n \n <ul>\n <li>take a directory on the URL, which by default will be the current directory;</li>\n <li>list the files / directories;</li>\n <li>for each entry, convert the filesystem path to a URL, using ... | {
"AcceptedAnswerId": "25872",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-04T07:05:16.867",
"Id": "25800",
"Score": "4",
"Tags": [
"php"
],
"Title": "Workaround for directory-browsing"
} | 25800 |
<p>I made simple JavaScript xor function. It accepts string, numeric array and mixed array (char, string, num) as params. It returns string or an array. </p>
<p>Returning an array is a must!. All numbers are printable on screen and there is no potential loss of information. String works excellent if you pass it in a ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-04T11:52:09.197",
"Id": "39940",
"Score": "0",
"body": "Don't overload functions so horribly. An `xor` for only Strings would have been enough"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-04T13:09:34.657... | [
{
"body": "<p>From a once over:</p>\n\n<ul>\n<li><code>p</code> is a terrible variable name, I can live with <code>i</code> and <code>s</code> but I draw the line at <code>p</code>, at the very least you should put a comment next <code>var p</code> to indicate what <code>p</code> stands for</li>\n<li>lowerCamel... | {
"AcceptedAnswerId": "44192",
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-04T09:02:49.570",
"Id": "25805",
"Score": "2",
"Tags": [
"javascript",
"bitwise",
"cryptography"
],
"Title": "JavaScript xor function"
} | 25805 |
<p>This code generally works exactly as it is supposed to. I'm learning bash I'm looking for some constructive help that could help me improve my work.</p>
<pre><code>#!/bin/bash
usage()
{
echo "Program for uncompressing tar, gzip, rar archives"
echo "Allowed parametres: --help, --file, --input, --director... | [] | [
{
"body": "<ol>\n<li>Don't use <code>cut</code> and <code>grep</code>, use <a href=\"http://tldp.org/LDP/abs/html/parameter-substitution.html\" rel=\"nofollow\">parameter substitution</a> and a case statement over the file extension to decide the file type (or use the <code>file</code> command if you want to be... | {
"AcceptedAnswerId": "26050",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-04T09:36:11.300",
"Id": "25806",
"Score": "4",
"Tags": [
"bash",
"linux"
],
"Title": "Bash script that can uncompress: tar, gzip, rar"
} | 25806 |
<p>I'm making a function that takes the date a page was last edited, accessed through MediaWiki's API, compares it to the current date, and returns how long ago the page was edited, e.g. 1 year/2 days/etc.</p>
<p>It's essentially a massive <code>if</code>/<code>else</code> statement, and I was wondering if there was a... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-04T13:04:42.970",
"Id": "39946",
"Score": "0",
"body": "Take a look at [this similar question](http://codereview.stackexchange.com/q/1548/9390)."
}
] | [
{
"body": "<p>I looked at the source code of moment.js for inspiration:</p>\n\n<p><a href=\"http://momentjs.com/\" rel=\"nofollow\">http://momentjs.com/</a></p>\n\n<p>And I'm trying to be as declarative as possible, using data to define the time-units I want to use:</p>\n\n<pre><code>unitMillisecondFactors = {\... | {
"AcceptedAnswerId": "25815",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-03T09:09:23.347",
"Id": "25807",
"Score": "3",
"Tags": [
"javascript",
"datetime"
],
"Title": "Determining how long ago a page was last edited"
} | 25807 |
<p>I'm working on my Scala chops and implemented a small graph API to track vertices and edges added to graph. I have basic GraphLike Trait, and have an Undirected Graph class ( <code>UnDiGraph</code>) and a Directed graph class (<code>DiGraph</code> ) that extend the <code>GraphLike</code> trait.</p>
<p>Here is some ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-04T17:14:03.010",
"Id": "39954",
"Score": "2",
"body": "Your bottleneck can lay everywhere, just use a profiler and check it out. I don't think you will get much information here other than \"try out to use a mutable collection\"."
}... | [
{
"body": "<p>Oh wow... I figured out what was going on. In the GraphInstantiater method, the very first call which passes synMap.keys, keys returns an iterable[Int]. Looks like taking tail on this is a long process, most likely going through the whole set of keys each time. </p>\n\n<p>changing the call to </p>... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-04T16:50:58.217",
"Id": "25813",
"Score": "1",
"Tags": [
"performance",
"scala",
"graph"
],
"Title": "Small graph API to track vertices and edges added to graph"
} | 25813 |
<p>I'm trying to validate email addresses as being from certain universities. I have a table, <code>University</code>, which is full of university domains. University email addresses often have different subdomains, and I want to be able to tolerate any subdomain under the domains in my table.</p>
<p>I think the follo... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-04T18:41:23.700",
"Id": "39956",
"Score": "0",
"body": "how many universities are there? a dozend? hundreds? thousands?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-04T18:48:47.887",
"Id": "39957",
... | [
{
"body": "<p>Build a regular expression from all your university domain, build it just once.\nIf you domains are <strong>brunel.ac.uk bton.ac.uk cam.ac.uk</strong> you\nneed to build the expression </p>\n\n<pre><code>/brunel\\.ac\\.uk$|bton\\.ac\\.uk$|cam\\.ac\\.uk$/\n</code></pre>\n\n<p>like so:</p>\n\n<pre><... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-04T18:28:29.733",
"Id": "25814",
"Score": "4",
"Tags": [
"ruby",
"email"
],
"Title": "Check if email address contains one of many domains from a table, ignoring the subdomain"
} | 25814 |
<p>I am learning to program in R and to do that and create something useful in the process, I have decided to rewrite <a href="http://opl.apa.org/contributions/Rice/rvls_sim/stat_sim/repeated_measures/index.html" rel="nofollow">this Java applet</a> for repeated measures simulation and to implement some new functionalit... | [] | [
{
"body": "<p>I am not sure if this will be under 2 seconds on your machine, but should be quite close.</p>\n\n<p>The main points of optimisation:</p>\n\n<ol>\n<li>Converting <code>matrix</code> (from <code>mvrnorm</code>) to <code>data.frame</code> is slow. I dropped <code>data.frame</code> and used resulting ... | {
"AcceptedAnswerId": "25828",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-04T20:26:51.903",
"Id": "25817",
"Score": "1",
"Tags": [
"optimization",
"simulation",
"r"
],
"Title": "Repeated measures simulator optimisation"
} | 25817 |
<p>The purpose of this code is important, so here's a quick rundown.</p>
<p>This code runs controls a physical machine which utilizes a camera and a moving stage holding an object to be imaged. Imaging can be broken down into two parts; exposing (collecting photons) and readout (reading the formatted image from the c... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-05T01:04:06.800",
"Id": "39977",
"Score": "0",
"body": "I also tried a few variations, but without success. This project looks to me very interesting. Could you say more, perhaps with some diagrams to understand the process."
},
{
... | [
{
"body": "<p>Since what matters here is the ordering of the operations, not what the operations mean, I'm going to use these abbreviations:</p>\n\n<pre><code>A - MoveStageAsync\nB - WaitForMotionEnd\nC - ExposeTile\nD - WaitForReadout\n</code></pre>\n\n<p>(I'm trying to explain how I got my version using these... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-04T20:31:15.463",
"Id": "25818",
"Score": "3",
"Tags": [
"c#",
"asynchronous",
"iteration",
"mechatronics"
],
"Title": "Coordinating camera stage movement and data readout"
} | 25818 |
<p>I have written a binary search algorithm, but it seems to be a bit different than other peoples that I've seen. I was hoping that the community could give me some feedback as to whether or not I'm missing something, or doing something the wrong way. </p>
<p>Binary Search: </p>
<pre><code>import java.util.Arrays;
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-05T03:31:52.950",
"Id": "39979",
"Score": "2",
"body": "one problem I see with the code is that you are returning \"num[mid]\" where you should be returning \"mid\" in case the number is found!"
}
] | [
{
"body": "<p>I see 1 bug, 1 problem and 1 minor thing:</p>\n\n<ul>\n<li>as listed in the comment above: You are returning the number instead of the index. That's not very helpful for a binary search algorithm ;)</li>\n<li>when the array does not contain the item you are returning 0. 0 is a valid array index, b... | {
"AcceptedAnswerId": "25832",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-05T01:13:35.990",
"Id": "25822",
"Score": "1",
"Tags": [
"java",
"binary-search"
],
"Title": "Binary Search Feedback"
} | 25822 |
<p>I've finally decided to design a class for this program, but some of the code still looks messy. I'm also a bit concerned about DRY, particularly in <code>binaryToOctalHex()</code>. The program is looking better, but I'm still not liking what I'm doing in the aforementioned function. I don't mind refactoring that... | [] | [
{
"body": "<p>Behind all the <code>if</code>s in <code>main()</code>, I see lurking a parameter:</p>\n\n<pre><code>unsigned inputBases[] = { 2, 10, 8, 16 };\nunsigned inputBase = inputBases[choice - 1];\n\nstd::string input;\nstd::getline(std::cin, input);\nNumberSystemsConverter conversion(inputBase, input);\n... | {
"AcceptedAnswerId": "28154",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-05T01:52:39.533",
"Id": "25824",
"Score": "5",
"Tags": [
"c++",
"c++11",
"converting",
"floating-point"
],
"Title": "Floating-point binary/decimal/octal/hex converter"
} | 25824 |
<p>I'm writing a function to append 5-10 bytes (count is random) at the beginning of a byte array, and 5-10 random bytes at the end:</p>
<pre><code>func padWithRandomBytes(b []byte) []byte {
startBytes := make([]byte, 10-rand.Intn(5))
endBytes := make([]byte, 10-rand.Intn(5))
newSlice := make([]byte, len(s... | [] | [
{
"body": "<p>For example,</p>\n\n<pre><code>package main\n\nimport (\n \"fmt\"\n \"math/rand\"\n \"time\"\n)\n\nfunc padWithRandomBytes(b []byte) []byte {\n s := 5 + rand.Intn(5+1)\n e := 5 + rand.Intn(5+1)\n r := make([]byte, s+len(b)+e)\n copy(r[s:], b)\n return r\n}\n\nfunc main() {\... | {
"AcceptedAnswerId": "25831",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-05T02:52:56.620",
"Id": "25825",
"Score": "2",
"Tags": [
"random",
"go"
],
"Title": "Pad a function with random bytes"
} | 25825 |
<p>I've just started learning assembly yesterday, and the first useful thing I've written is a <code>clearmem</code> function.</p>
<p>I'm looking for general feedback regarding my coding of this function, whether there any flaws with it other than the obvious one of a user passing a value <= 0 to the <code>size</co... | [] | [
{
"body": "<ul>\n<li><p>The comments in the <code>clearmem</code> procedure for the Linux block look a bit confusing. You could just have a summary of the procedure commented above, and have the individual comments for each line specify the meaning of the assembly instructions.</p>\n\n<p>Specifically, the line... | {
"AcceptedAnswerId": "44183",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-05T09:37:38.437",
"Id": "25830",
"Score": "16",
"Tags": [
"c++",
"linux",
"assembly",
"windows"
],
"Title": "x64 assembly clearmem / zeromem"
} | 25830 |
<p>I have just started learning Java, and don't want to start any bad habits, so please review my latest game code:</p>
<pre><code>import java.util.Random;
import java.util.Scanner;
class GuessMyNumber {
public static void main(String args[]) {
Random random = new Random();
Scanner input = new Scan... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-05T19:21:48.107",
"Id": "40002",
"Score": "0",
"body": "Good job by the way with your indention levels.. do you have a background in a scripting language?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-05T... | [
{
"body": "<p>So although this code is a small example it still can benefit from having a few methods sprinkled in to help clear up what you are trying to do. For instance what if you decided that you wanted to change the max and min to be entered in as a parameter to starting the program? You would have to cha... | {
"AcceptedAnswerId": "25840",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-05T18:10:08.720",
"Id": "25837",
"Score": "3",
"Tags": [
"java",
"beginner",
"game",
"number-guessing-game"
],
"Title": "\"Guess my Number\" in Java"
} | 25837 |
<p>I'm working on a CMS system. The basis is pretty much done but before going any further I would like to know if there are things I really should change in the way I code things.</p>
<p>I am pretty sure there will be a few things that could be done different, since I pretty much started with this project without any... | [] | [
{
"body": "<p>Well for starters you can start learning object oriented programming and why the procedural approach you've taken will be 100% impossible to maintain and further develop. You can also stop using global variables (which the use of objects will help you avoid).</p>\n\n<p>Unfortunately I can't get mo... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-05T18:57:52.240",
"Id": "25838",
"Score": "2",
"Tags": [
"php",
"optimization",
"mysql"
],
"Title": "Practical advise for CMS"
} | 25838 |
<p>The following code is a self-implementation of the static class <code>ThreadPool</code> in C#, only the <code>QueueUserWorkItem</code> (the simpler method), written to practice multithreading in the .NET environment and generally C# coding.</p>
<p>Implementation details: </p>
<p>The background threads are simulate... | [] | [
{
"body": "<pre><code>public static int FinishedThreads = 0;\npublic static int TotalQueued = 0;\npublic static int MaxThreadsUsed = 0;\n</code></pre>\n\n<p>Public fields are usually not a good idea, you should make them <code>private</code>.</p>\n\n<pre><code>while (true)\n{\n DequeueRun();\n Thread.Slee... | {
"AcceptedAnswerId": "25843",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-05T19:58:48.607",
"Id": "25841",
"Score": "2",
"Tags": [
"c#",
"multithreading",
"queue",
"locking"
],
"Title": "Static class ThreadPool implementation"
} | 25841 |
<p>I'm beginning with PHP programming and would appreciate a critique on my code and how I could make it more efficient, rather than repeating the <code>if</code> statements.</p>
<p>What I'm basically doing is getting the fields typed in by the user and displaying these fields in a sidebar of a custom page template.</... | [] | [
{
"body": "<p>Your code can be simplified a bit.\nThe parantheses on the right side is not needed. Instead of</p>\n\n<pre><code> $name = (get_field('name'));\n</code></pre>\n\n<p>you can just say</p>\n\n<pre><code> $name = get_field('name');\n</code></pre>\n\n<p>However, since you are outputting t... | {
"AcceptedAnswerId": "25878",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-05T20:50:05.977",
"Id": "25842",
"Score": "2",
"Tags": [
"php",
"beginner",
"wordpress"
],
"Title": "Displaying fields in a sidebar of a custom page template"
} | 25842 |
<p>I need to use this code to fetch data from web service and show them in a site properly but after I request for the webservice I am unable to load them fast. Site is loading very slow.</p>
<pre><code><?php
$jRequestURLPrefix = 'http://demo.4ds.com/rema/1.1/';
$menu_json_url = $jRequestURLPrefix."rules/origins... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-03T13:18:34.913",
"Id": "40008",
"Score": "0",
"body": "the webservice is responding slowly or its responding fast enough but your code is slow?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-03T13:24:14.0... | [
{
"body": "<p>Your code itself does not present any problems that would make it run significantly slower. However, it is worth to bear in mind the following:</p>\n\n<ul>\n<li>The other server's latency (i.e. how bad/good his response time is) will affect your script's run time, as curl does not \"magically\" re... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-03T13:16:37.227",
"Id": "25844",
"Score": "1",
"Tags": [
"php",
"performance",
"json",
"web-services",
"curl"
],
"Title": "Calling restful web services efficiently"
} | 25844 |
<p>A little while ago I wrote this implementation of Conway's Game of Life in Ruby. It's based on this <a href="https://www.youtube.com/watch?v=a9xAKttWgP4" rel="nofollow">Game of Life in APL</a> video, which I think is rather elegant, though a bit dense. Feel free to give feedback on any aspect of the program, but the... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-06T17:29:10.370",
"Id": "40040",
"Score": "0",
"body": "For nice printing you should use [curses](http://ruby-doc.org/stdlib-1.9.2/libdoc/curses/rdoc/Curses/Window.html). Ruby's implementation has some problems, but they are googlable ... | [
{
"body": "<p>Instead of magic numbers, extract them to either explaining variables or constants.\nFor example, in <code>neighbor_counts</code>, what are -1, 0, and 1?\nPeople who are familiar with the GoL might know what you're trying to do, but assume you're passing this off to someone who is new to the GoL a... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-05T23:33:01.900",
"Id": "25850",
"Score": "2",
"Tags": [
"ruby",
"game-of-life"
],
"Title": "Ruby Game of Life with matrices"
} | 25850 |
<p>This class is responsible for storing an API Key and Secret pair. The secret is encrypted with AES in CFB mode, using a key derived from a passphrase, a random salt and a number of rounds of SHA1.</p>
<p>An additional hash of the plaintext and the salt is stored to allow for detecting incorrect passphrase entry.</p... | [] | [
{
"body": "<ol>\n<li><blockquote>\n<pre><code>key.write(passphrase, new FileOutputStream(filename));\n</code></pre>\n</blockquote>\n\n<p>I see that the stream is flushed in the <code>write</code> method but it will be cleaner to <code>close</code> it too.</p>\n\n<p>(<em>Guideline 1-2: Release resources in all c... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-05T23:37:48.003",
"Id": "25851",
"Score": "5",
"Tags": [
"java",
"security",
"cryptography"
],
"Title": "API Key storage using AES encryption in Java"
} | 25851 |
<p>I'm writing a script to archive email messages from one IMAP folder to another. It looks, more or less, like the following. I've obfuscated about 30 lines unrelated to this question:</p>
<pre><code>import imaplib
import getpass
def main():
user = getpass.getuser() + '@mymailbox.com'
mailbox = imaplib.IMAP4_... | [] | [
{
"body": "<p>Move the working logic into its own function</p>\n\n<pre><code>def process_mailbox(mailbox):\n user = getpass.getuser() + '@mymailbox.com'\n try:\n mailbox.login(user, getpass.getpass())\n except imaplib.IMAP4.error:\n raise RuntimeError('Credential error.')\n mailbox.sel... | {
"AcceptedAnswerId": "25854",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-06T01:14:56.270",
"Id": "25853",
"Score": "1",
"Tags": [
"python",
"exception-handling"
],
"Title": "Is 'try / finally' the best way for me to handle (and close) this long-running IMA... | 25853 |
<p>I have a list of cities, and a set of "travel time" between any given two cities. The "travel time" is fixed and not necessarily dependent on absolute distance between the two cities, and it currently exists in an Excel doc that's manually maintained.</p>
<p>I wanted users to be able to specify two cities from two ... | [] | [
{
"body": "<p>Sometimes, it's good to code from scratch. However, in your case, it seems like you'd be maintaining this code for a while. Scratch coding isn't that fun in the long run because you <em>will</em> run into bugs, cross-browser issues, and security. </p>\n\n<p>I would suggest you use a framework, eve... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-06T03:31:01.457",
"Id": "25856",
"Score": "1",
"Tags": [
"javascript",
"php",
"mysql",
"ajax"
],
"Title": "Using AJAX to look up MySQL value using two dropdown inputs"
} | 25856 |
<p>I always did my lookup in JSON collection like that:</p>
<pre><code>var data = [
{
"Key": "1111-1111-1111",
"Email": "test@test.com"
}
];
function getByKey(key) {
var found = null;
for (var i = 0; i < data.length; i++) {
var element = data[i];
if (element.Key ==... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-06T19:33:39.087",
"Id": "40048",
"Score": "1",
"body": "Why aren't you using the Array.prototype.filter-method?\n\n [{key:\"1\", name=\"name\"}, ..... ].filter(function(o){ return o.key===\"1\"})"
},
{
"ContentLicense": "CC ... | [
{
"body": "<p>I tend to generate a lookup dictionary as soon as I have the data. So in any case I only need to iterate the data <strong>once</strong>.</p>\n\n<p>Comparing with your approach, let's say we need to call <code>getByKey()</code> multiple times, the total cost of iterating the data might actually be ... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-06T04:47:02.437",
"Id": "25858",
"Score": "11",
"Tags": [
"javascript",
"lookup"
],
"Title": "JSON lookup by key"
} | 25858 |
<p>I wrote simple lock-free collection class for saving items from multithreading code. I did it just for fun and experience. Can you check my code for potentially problems please? </p>
<pre><code> public class InputBox<T>
{
private BoxItem<T> _current;
public InputBox()
... | [] | [
{
"body": "<pre><code>public bool TryAdd(T value)\n</code></pre>\n\n<p>A method that intentionally doesn't work when there is contention? I don't see how would that be ever useful.</p>\n\n<pre><code>internal BoxItem<T> Next\n{\n get { return _next; }\n set { _next = value; }\n}\n</code></pre>\n\n<p>... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-06T05:56:56.877",
"Id": "25860",
"Score": "2",
"Tags": [
"c#",
"multithreading",
"lock-free"
],
"Title": "Simple Freelock collection"
} | 25860 |
<p>so this is my code for a equipping an item in my game dev't: </p>
<pre><code>try {
$db = getConnection();
$db->beginTransaction();
$sql_chara_gold = $db->query("SELECT chara_gold FROM chara WHERE chara_id = $shop->chara_id");
$get_chara_gold = $sql_chara_gold->fetchC... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-10T03:23:45.560",
"Id": "40237",
"Score": "0",
"body": "Have you considered using an ORM?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-10T05:33:16.343",
"Id": "40248",
"Score": "0",
"body": "... | [
{
"body": "<p>I don't know if I'd use ORM for something so simple, but it may be something to look into. At the very least, you should get in the practice of escaping query parameters to avoid <a href=\"http://en.wikipedia.org/wiki/SQL_injection\" rel=\"nofollow\">SQL injection</a>. I often use Aura SQL for thi... | {
"AcceptedAnswerId": "26164",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-06T06:13:02.037",
"Id": "25861",
"Score": "3",
"Tags": [
"php",
"mysql",
"sql",
"pdo"
],
"Title": "Code Reiview for an PHP PDO Queries? is there a better way to do it?"
} | 25861 |
<p>I have this code to generate some tables in my PDF document for my Android app.
It works fine, but I just think I need to refactor it as the same structure is repeated 3 times.</p>
<pre><code>//tables!
public static PdfPTable createTableA() {
//empty space
Paragraph paragraph = new Paragraph();
... | [] | [
{
"body": "<p>It is not clear what you are realy trying to do. But if I understand you right, you want to save a lot of duplicate code while creating different tables. I added two variables to the table creation method, which could now create the different tables without the code duplication.</p>\n\n<p>Iterator... | {
"AcceptedAnswerId": "25877",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-06T10:54:43.337",
"Id": "25865",
"Score": "2",
"Tags": [
"java",
"android",
"pdf"
],
"Title": "Generating tables in a PDF document"
} | 25865 |
<p>I have to check a string to various regular expressions in C++. Up to now, I've done this using something similar to this:</p>
<pre><code>regex regex_a (".."); string rewrite_a = "($1/$2)";
regex regex_b (".."); string rewrite_b = "($1)";
regex regex_c (".."); string rewrite_c = "($2)";
if (regex_match(string, reg... | [] | [
{
"body": "<p>Probably like this:</p>\n\n<p>C++11:</p>\n\n<pre><code>vector< pair<regex, string> > regex_pairs = { {regex(\"..\"), \"($1/$2)\"}, {regex(\"..\"), \"($1)\"}, {regex(\"..\"), \"($2)\"} };\nfor(auto pa:regex_pairs){\n cout << regex_replace(string, pa.first, pa.second);\n}\n</cod... | {
"AcceptedAnswerId": "25870",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-06T11:22:54.800",
"Id": "25866",
"Score": "2",
"Tags": [
"c++",
"array",
"regex"
],
"Title": "Can I make a regex array to iterate through in C++?"
} | 25866 |
<p>I'm trying to implement a HashTable. In fact, I want a HashSet with Persons that have a name and a phoneNumber, both string. I understood the theory with collisions and everything but I don't know how to really implement something. This is what I've done so far:</p>
<pre><code>#ifndef HASHSET_H_
#define HASHSET_H_
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-06T12:13:28.430",
"Id": "40029",
"Score": "0",
"body": "It's quite good, everything makes sense, but you can't insert or delete values from your HashSet, that kinds of defeats the point."
},
{
"ContentLicense": "CC BY-SA 3.0",
... | [
{
"body": "<ul>\n<li><p>You're attempting to read values from uninitialized variables which has undefined behavior:</p>\n\n<pre><code>int sum; // uninitialized` \nfor(int i=0; i < length; i++){` \n sum+=e[i]; // reading from uninitialized variable \"sum\"\n</code></pre>\n\n<p><a href=\"https://stackover... | {
"AcceptedAnswerId": null,
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-06T11:42:19.873",
"Id": "25867",
"Score": "5",
"Tags": [
"c++",
"hash-map"
],
"Title": "HashTable - separate chaining collision in C++"
} | 25867 |
<p>I want to make a map object that key is object.</p>
<p>But, JavaScript only allows string as a hash key. (at least before ECMAScript6 comes?)</p>
<p>So, I tried to write auxiliary functions to emulate, hash-ish (but actually linear search).
Are there any suggestions on improvement?</p>
<pre><code>var tabInfo = {}... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-06T12:02:52.457",
"Id": "40027",
"Score": "3",
"body": "Why don't you simply use a [shim](https://github.com/WebReflection/es6-collections)?"
}
] | [
{
"body": "<p>I can't see a good use for this, but nonetheless:</p>\n\n<ul>\n<li>Since you treat tabInfo as a list, why not have it be an array, this way you don't need <code>tabInfoKey</code> and you can use <code>push</code> instead. Arrays are objects too.</li>\n<li>Don't use console.log for production code<... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-06T11:50:56.293",
"Id": "25868",
"Score": "4",
"Tags": [
"javascript",
"hash-map"
],
"Title": "Object map in JavaScript"
} | 25868 |
<p>I developed a <code>QuickIndex</code> class which serves to index arrays of stringafiable objects using a tree structure. The purpose is to then primarily to allow for fast index or include? method calls directed to the <code>quick_index</code> object as a proxy for the original array, as the index tree can be trave... | [] | [
{
"body": "<p>You can build it faster <em>and</em> use it faster if you use a flat hash instead of cascading hashes.</p>\n\n<p>Here's a simple implementation using a \"flat\" hash:</p>\n\n<pre><code>class QuickerIndex\n\n def initialize(array)\n @index = {}\n array.each_with_index do |item, i|\n (@i... | {
"AcceptedAnswerId": "38863",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-06T14:35:42.060",
"Id": "25874",
"Score": "2",
"Tags": [
"optimization",
"ruby"
],
"Title": "Improvements on tree index class"
} | 25874 |
<p>I am doing a redesign and have some previously existing content in HTML that is similar to </p>
<pre><code><p class="testimonial-text">Bacon ipsum dolor sit amet aliquip est tail occaecat bacon ad qui short loin exercitation.Strip steak sint dolore et ut, elit kielbasa quis.</p>
&ndash;<span clas... | [] | [
{
"body": "<p>Something did feel wrong about your code</p>\n\n<h1>IDs are unique</h1>\n\n<p>A bit of redundancy is this: <code>div#testimonials</code></p>\n\n<p>IDs are unique in the page and should only be one element. You can just to <code>#testimonials</code> and still get that div.</p>\n\n<h1>Span? Which on... | {
"AcceptedAnswerId": "25881",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-06T18:34:24.897",
"Id": "25880",
"Score": "5",
"Tags": [
"html",
"css",
"inheritance"
],
"Title": "Least amount of HTML and CSS to create a bottom border for every section?"
} | 25880 |
<p>I was looking over questions related to setting up markers on a Google map, and though the following works perfectly fine for me, it was different from the other (and accepted) answers. I just wanted to see if I'm doing something incorrect, or just a different way.</p>
<p>Mine:</p>
<p><code>this</code> references ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-07T07:48:05.933",
"Id": "40075",
"Score": "0",
"body": "Your version does seem fine and simple. Can you give the link to the answers you saw?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-08T16:44:18.617"... | [
{
"body": "<p>Your code is definitely simpler, though I would not use it myself. There is no good reason to have an anonymous function, and if you have multiple markers, then you will have multiple clones of the same function. I would create a named function and use that function with <code>addListener</code>.<... | {
"AcceptedAnswerId": "45899",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-06T20:19:32.647",
"Id": "25882",
"Score": "2",
"Tags": [
"javascript",
"google-maps"
],
"Title": "Adding events to multiple markers in a Google map"
} | 25882 |
<p>I'm writing my first Java MVC application which should be a desktop student administration application with a Swing GUI.</p>
<p>DAO is already implemented: <a href="https://codereview.stackexchange.com/questions/25788/need-some-feedback-student-administration-application">Student administration application using a ... | [] | [
{
"body": "<p><strong>Main.java</strong></p>\n\n<pre><code>class Main {\n public static void main(String[] args) {\n User user = new User();\n UserView userView = new UserView();\n UserController userController = new UserController(user, userView);\n userController.login();\n }... | {
"AcceptedAnswerId": "25894",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-06T21:18:58.117",
"Id": "25883",
"Score": "1",
"Tags": [
"java",
"mvc",
"swing"
],
"Title": "Desktop student administration application"
} | 25883 |
<p>In your opinion, do I need to do all these validations? I thought to do well and stay safe but it seriously raises the question if it isn't slower.</p>
<p><strong>jQuery</strong></p>
<pre><code>$(document).ready(function () {
// jQuery validate plugin
$('#login > form').validate({
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-07T08:10:29.920",
"Id": "40078",
"Score": "0",
"body": "Good question! :) I have a few comments. No, a couple of `if` won't slow your code down. Yes, it helps to catch errors early, especially to give feedback to your users. And no, `... | [
{
"body": "<p>Since <code>throw</code> interrupts the program flow, you don't need to provide an <code>else</code> branch. That way, you also visibly follow the good practice of using 'watchdogs':</p>\n\n<pre><code><?php\n\ninclude_once('config.php');\ninclude_once(ROOT . 'libs/database.php');\ninclude_once(... | {
"AcceptedAnswerId": "25904",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-06T23:59:04.490",
"Id": "25886",
"Score": "2",
"Tags": [
"javascript",
"php",
"jquery",
"ajax",
"validation"
],
"Title": "My login with AJAX and PHP"
} | 25886 |
<p>This takes a name, 2 images and a birthday for an artist, uploads images and insert info into MySQL. I seem to be missing something and I'm looking to see if I'm following best practices.</p>
<pre><code><?php
require_once '../config.php';
require 'includes/functions.php';
?>
<!DOCTYPE html>
<html la... | [] | [
{
"body": "<p>I'm not a fan of mixing PHP and HTML, but I'll leave that alone for now.</p>\n\n<pre><code><?php\n if (isset($_FILES['artist_thumb'], $_FILES['artist_profile_image']) === true) {\n</code></pre>\n\n<p>There is no need for any function returning boolean values to test them against true or fals... | {
"AcceptedAnswerId": "25903",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-07T02:43:27.213",
"Id": "25891",
"Score": "2",
"Tags": [
"php",
"html"
],
"Title": "Adding artist info into MySQL"
} | 25891 |
<p>This query is serving me a home page for users where a user can see all posts by him/her and his/her friends. This is an excellent query without any errors but I only wish to make it shorter if possible!</p>
<pre><code>select U.fname, U.lname, P.postid, P.status, P.date, U.usernick, P.visible
from posts as P natura... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-07T15:43:55.267",
"Id": "40093",
"Score": "0",
"body": "Do you want the code to be shorter or the query to execute faster?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-07T15:52:17.603",
"Id": "40096"... | [
{
"body": "<p>It looks like you are performing the same query against the Friends table twice. If you need that query, I would split it off and run that query first, passing the result to your main query as a parameter. But as you'll see at the end, I don't think that is necessary.</p>\n\n<p>Also, you are usi... | {
"AcceptedAnswerId": "25940",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-07T06:06:51.350",
"Id": "25893",
"Score": "3",
"Tags": [
"mysql",
"sql"
],
"Title": "Query: user can see all posts by him and his friends"
} | 25893 |
<p>Say I have 5 <code>JTextField</code>: <code>jTextField1</code>, <code>jTextField2</code>...</p>
<p>Now I want them to behave the same on <code>DocumentListener</code>, so I decided to make only one <code>DocumentListener</code> and set it to the 5 components.</p>
<p>Meanwhile I'm doing this:</p>
<pre><code>jTextF... | [] | [
{
"body": "<p>Almost fine. You are doing the same stuff in all 3 update methods of the DocumentListener, so I suggest creating a new private method in it and just calling it from all 3 update methods. That way you avoid code duplication and only have one location to change in the future instead of having to mai... | {
"AcceptedAnswerId": "25930",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-07T08:43:55.533",
"Id": "25895",
"Score": "2",
"Tags": [
"java",
"swing"
],
"Title": "Applying DocumentListener on multiple JTextField"
} | 25895 |
JDBC (Java DataBase Connectivity) is the base API which enables interacting with SQL database servers by executing SQL statements using the Java programming language. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-07T09:58:02.757",
"Id": "25897",
"Score": "0",
"Tags": null,
"Title": null
} | 25897 |
<p>I am looking for ways to improve my API wrapper for Pocket. So far, my code is quite compact and nice (I think), but I feel like there must be a better way to do this.</p>
<p>This is the part where I think a lot of code redundancy due to different parameters that need to be serialized to Json and later send to serv... | [] | [
{
"body": "<p>Well, you should refactor your code so that you don't repeat yourself:</p>\n\n<pre><code>private async Task<List<ItemRetrieved>> GetValuesAsync(object parametersAsAnonymousObject)\n{\n var requestUrl = MakeRequestUri(\"v3/get\");\n\n var request = new HttpRequest(HttpMethod.Post,... | {
"AcceptedAnswerId": "25900",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-07T12:27:02.800",
"Id": "25899",
"Score": "2",
"Tags": [
"c#",
"api"
],
"Title": "Refactor code for API wrapper"
} | 25899 |
<p>I recently asked to use <a href="https://stackoverflow.com/q/16395570/1048572"><code>eval()</code> for a module function</a>. Now I ended up doing a very weird function which does what I want. I like the idea I made it but I'm not so sure if this is state of the art, or more, good to build an application on.</p>
<p... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-07T15:26:01.117",
"Id": "40090",
"Score": "0",
"body": "Hello, and welcome to Code Review! What's the point of this? There are lots of libraries that handle this issue, eg. RequireJS. Aren't they a better fit for this?"
},
{
"C... | [
{
"body": "<p>The functionality you are looking for is found in <a href=\"http://requirejs.org/\" rel=\"nofollow\">RequireJS</a> and follows a spec called <a href=\"https://github.com/amdjs/amdjs-api/wiki/AMD\" rel=\"nofollow\">Asynchronous Module Definition (AMD)</a>. It is a mechanism that allows dependency m... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-07T14:24:38.527",
"Id": "25901",
"Score": "3",
"Tags": [
"javascript",
"modules",
"dynamic-loading"
],
"Title": "JavaScript modules loading with eval()"
} | 25901 |
<p>I followed a tutorial to create a PHP contact form that sends to multiple emails depending on drop down field selection. Is it protected from spam/other dangers? Or is it basically wide open for bots and the like to gain access? I'm a beginner to PHP, and don't really understand what determines the safeness of this ... | [] | [
{
"body": "<p>Since only addresses from <code>$emailAddresses</code> are allowed, it is not possible to inject other addresses. So the form is protected against being used as a spam relay.</p>\n\n<p>On the other hand, you're instantiating a mailer and captcha class, but not using it. So you don't benefit from i... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-07T14:57:51.167",
"Id": "25902",
"Score": "3",
"Tags": [
"php",
"beginner",
"validation",
"form",
"email"
],
"Title": "Contact form that goes to multiple addresses based on d... | 25902 |
<p>I'm willing to simplify the use of the ASP.NET cache.</p>
<p>I wrote this helper class:</p>
<pre><code>public static class CacheHelper
{
public static T GetCached<T>(string key, Func<T> initializer, DateTime absoluteExpiration)
{
return GetCached(key, initializer, Cache.NoSlidingExpirat... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-07T16:55:16.567",
"Id": "40104",
"Score": "0",
"body": "You could simplify your lambda to `() => ComputeExpensiveResult()`, or even just `ComputeExpensiveResult`. Also, `GetSomeCachedData()` should probably be a property."
},
{
... | [
{
"body": "<p>Several suggestions:</p>\n\n<ol>\n<li>You could use <a href=\"http://msdn.microsoft.com/en-us/library/vstudio/system.runtime.caching.memorycache%28v=vs.100%29.aspx\" rel=\"nofollow\">MemoryCache</a> class as of .NET 4, which would free you from <code>System.Web</code> assembly.</li>\n<li>You shoul... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-07T16:10:52.367",
"Id": "25907",
"Score": "1",
"Tags": [
"c#",
"asp.net"
],
"Title": "ASP.NET caching helper"
} | 25907 |
<p>I created this game in Java:</p>
<pre><code>import java.util.Scanner;
public class TicTacToe {
public static Scanner input = new Scanner(System.in);
public static String getName(int noPlayer) {
System.out.print("Enter name of Player " + noPlayer + ": ");
return input.next();
}
public... | [] | [
{
"body": "<p>Please note that the following points are in no particular order and I do not claim the list to be exhaustive, because frankly I'm far from perfect and also I won't touch really advanced stuff here. And it's always possible to do something more sophisticated, but I don't think that is required her... | {
"AcceptedAnswerId": "25915",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-07T16:11:30.617",
"Id": "25908",
"Score": "2",
"Tags": [
"java",
"optimization",
"game",
"tic-tac-toe"
],
"Title": "TicTacToe in Java"
} | 25908 |
<p>The last month I've been reading up on how to take my JavaScript code to the next level. I am a Java programmer at heart, so it feels nice when everything is encapsulated in classes/objects, and these are ready to be instantiated or inhertid or whatever.</p>
<p>I wrote a simple test project with the purpose to refi... | [] | [
{
"body": "<pre><code><!DOCTYPE html>\n<html charset=\"utf-8\">\n\n <head>\n </head>\n\n <body>\n\n <ul id=people></ul>\n\n <script>\n\n (function () { // create a new scope\n\n 'use strict';\n /*jsli... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-07T21:00:47.420",
"Id": "25916",
"Score": "1",
"Tags": [
"javascript",
"design-patterns",
"inheritance"
],
"Title": "My take at OOP module/prototyping JavaScript"
} | 25916 |
<pre><code><?php
session_start();
include_once("model/Model.php");
class Controller {
public $model;
public function __construct()
{
$this->model = new Model();
}
public function invoke()
{
if (isset($_GET['page']) && $_GET['page'] == "registration")
... | [] | [
{
"body": "<p>If you want an honest opinion, I'd say no, this is not a good controller. I won't bother with code styles, but as far as logic goes:</p>\n\n<ol>\n<li>Conditional includes? Not a good idea. You should be writing code that <em>could</em> be included anywhere if necessary (but possibly not used). Usi... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-07T21:05:03.163",
"Id": "25917",
"Score": "4",
"Tags": [
"php",
"mvc",
"web-services"
],
"Title": "Is this a good controller?"
} | 25917 |
<p><a href="http://projecteuler.net/problem=407">Project Euler problem 407</a>:</p>
<blockquote>
<p>If we calculate <em>a</em><sup>2</sup> mod 6 for 0 ≤ <em>a</em> ≤ 5 we get: 0, 1, 4, 3, 4, 1.</p>
<p>The largest value of <em>a</em> such that <em>a</em><sup>2</sup> mod 6 = <em>a</em> is 4.
Let's call M(<em>n<... | [] | [
{
"body": "<h3>1. Introduction</h3>\n\n<p>The feature of <a href=\"http://projecteuler.net/\" rel=\"nofollow noreferrer\">Project Euler</a> that makes it interesting is that solving the problems is rarely a matter of writing down a straightforward algorithm and then optimizing it piecewise until it runs in the ... | {
"AcceptedAnswerId": "25943",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-07T22:23:41.727",
"Id": "25919",
"Score": "8",
"Tags": [
"python",
"optimization",
"algorithm",
"primes",
"project-euler"
],
"Title": "Project Euler 407: Is there any more... | 25919 |
<p>This code works exactly as the prompt and the code predict.
Is my style good, my implementations, or what should I change, or what? I'm trying to improve my code, and writing more of it helps... Any and all relevant feedback is good.</p>
<pre><code>#include <stdio.h>
#include <time.h>
#include <math.... | [] | [
{
"body": "<h2>Compiler Warnings</h2>\n\n<p>Firstly, always enable maximum warning settings for your compiler, it will catch things that you miss. For example, with <code>gcc -Wall -Wextra</code>, the following is produced:</p>\n\n<blockquote>\n <p>timer.c:20:5: warning: first argument of 'main' should be 'int... | {
"AcceptedAnswerId": "25924",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-08T00:20:54.377",
"Id": "25921",
"Score": "6",
"Tags": [
"c"
],
"Title": "Is my C style good? 100 line timer program"
} | 25921 |
<p>Could you please review the following? My concern is XML parsing is hardcoded:</p>
<pre><code> Ext.Ajax.request({
url: storageDataItem.contentlink,
success: function (response) {
var store;
try {
var parser = new DOMParser();
// TODO: remov... | [] | [
{
"body": "<p>From looking a little into this</p>\n\n<ul>\n<li>You derive <code>mediaContentURL</code> through <code>response.responseXML</code> and <code>title</code> through <code>xml</code>, I would stick in both cases to <code>xml</code></li>\n<li>As you guessed, your approach to getting the mediaContentURL... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-08T01:39:59.770",
"Id": "25923",
"Score": "3",
"Tags": [
"javascript",
"xml",
"ext.js"
],
"Title": "Sencha touch with XML"
} | 25923 |
<p>I have a comment system on 2 levels (like Blizzard <a href="http://eu.battle.net/sc2/en/blog/7935264/#c-7257875753" rel="nofollow">http://eu.battle.net/sc2/en/blog/7935264/#c-7257875753</a>), it's working fine but my code is a bit dirty :</p>
<pre><code>// $datacoms array from mysql_query
foreach($datacoms as $com... | [] | [
{
"body": "<p>Depends on how your data is modeled. I dont know that, but I can assume that you use three relational tables. Something along these lines:</p>\n\n<pre><code>Post [parent]\n+-------------+---------+\n| Field | Type |\n+-------------+---------+\n| id | int |\n| value | va... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-08T04:30:18.777",
"Id": "25927",
"Score": "2",
"Tags": [
"php"
],
"Title": "Array inside array (comment system with 2 levels)"
} | 25927 |
<p>I have some hack-ey programming experience and recently made a Tic-Tac-Toe game in JavaScript. The game seems to work fine. I am looking for some constructive criticism to help understand what can be better.</p>
<p>(full code in <a href="https://github.com/erdogan/Tic-Tac-Toe" rel="nofollow">Github repo</a>)</p>
<... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-08T05:36:18.620",
"Id": "62817",
"Score": "0",
"body": "I think you should try a search tree with Alpha Beta pruning Here's the wikipedia link to the algorithm\nhttp://en.wikipedia.org/wiki/Alpha%E2%80%93beta_pruning"
},
{
"Con... | [
{
"body": "<p>The code is nice, most comments are minor issues. General issues are:</p>\n\n<ol>\n<li>the way you're involving winning conditions with the chance system</li>\n<li>user interaction: you're over-using alerts when you could slide down messages with jQuery. Avoid modal interfaces.</li>\n<li>AI is sim... | {
"AcceptedAnswerId": "25935",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-08T04:46:56.583",
"Id": "25929",
"Score": "2",
"Tags": [
"javascript",
"game"
],
"Title": "Suggestions for improving my Tic-Tac-Toe code in JavaScript"
} | 25929 |
<p>This is my <em>bare-bones</em> Brainfuck interpreter in C using lots of unixisms. What improvements can I make (with respect to the clarity of code, or obvious features to add)?</p>
<pre><code>#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <sys/mma... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-29T06:05:01.213",
"Id": "45888",
"Score": "0",
"body": "Ehrm.. `init` has some issues. It's kinda stupid to arrange to pass a NULL pointer if there's no filename, and then pass that NULL pointer to `open` and try to `assert` afterwords... | [
{
"body": "<p>My biggest complaint on readability would be your <code>findmatch()</code> function. There are too many non-descriptive variables (i.e. <code>i</code>, <code>j</code>, <code>p</code>, etc). Changing the names to be more descriptive, or adding some comments to elaborate on what you're trying to do ... | {
"AcceptedAnswerId": "87342",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-08T06:37:13.393",
"Id": "25934",
"Score": "12",
"Tags": [
"c",
"interpreter",
"brainfuck"
],
"Title": "Brainfuck interpreter in C"
} | 25934 |
<p>This is code for finding largest prime number smaller than \$N\$, where \$N\$ can be as large as \$10^{18}\$. But, it takes 1 minute for \$10^{18}\$. I need to pass it in 2-3 sec.</p>
<p>What changes should I make to pass it? My compiler used is g++ 4.3.2</p>
<p>The program here runs for multiple test cases.</p>... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-10-14T16:35:26.993",
"Id": "121413",
"Score": "0",
"body": "Basically you go in the right direction: Miller-Rabin test, fast modular exponentiation. The calculation should be very fast (a lot less than 2-3 sec). So check where you loose t... | [
{
"body": "<ul>\n<li><p>These macros are not needed in C++:</p>\n\n<blockquote>\n<pre><code>#define c2 341550071728321\n#define c1 4759123141\n</code></pre>\n</blockquote>\n\n<p>They should be constants, using the <code>const</code> keyword (or <code>constexpr</code> in C++11):</p>\n\n<pre><code>const int c2 = ... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-08T13:31:26.473",
"Id": "25941",
"Score": "9",
"Tags": [
"c++",
"performance",
"primes"
],
"Title": "Greatest prime number smaller than N where N can be as large as 10^18"
} | 25941 |
<p>I'd like to check my understanding and usage of the AutoMapper in my ASP.Net MVC app.</p>
<p>I setup the maps in Application_Start:</p>
<pre><code> Mapper.CreateMap<Customer, CustomerViewModel>();
Mapper.CreateMap<CustomerViewModel, Customer>();
Mapper.AssertConfigurationIsValid();
</code></pre>
<p>... | [] | [
{
"body": "<p>If you were not using AutoMapper, your POST method would either have a block of manual mapping, or it would call out to a custom mapper class. In the latter case, you would have a line (or two) calling that helper class instead of a line calling AutoMapper.</p>\n\n<p>Whether returning a PartialVie... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-08T14:32:14.360",
"Id": "25945",
"Score": "1",
"Tags": [
"c#",
"asp.net-mvc-3"
],
"Title": "Using AutoMapper in ASP.Net MVC"
} | 25945 |
<p>I am using <code>preg_replace_callback()</code>, and I am concerned that I might have some sort of security risk. I am hoping to get a review of the below <code>substitute()</code> function. The purpose of the function is to parse a user provided template with user provided data. A quick description on how it is ... | [] | [
{
"body": "<h2>Escaping the RegExp</h2>\n\n<p>You should never do manual escaping, if an appropriate function exists. For RegExp, this is preg_quote. Another risk is that you'r escaping <em>before</em> splitting, so you might destroy an escaping sequence. Better do</p>\n\n<pre><code>function substitute($templat... | {
"AcceptedAnswerId": "26019",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-08T15:06:14.033",
"Id": "25947",
"Score": "3",
"Tags": [
"php",
"security",
"dependency-injection"
],
"Title": "Template parsing function"
} | 25947 |
<p>I'm new to programming and have created a simple Rock, Paper, Scissors game. The entire program is under a single class and the main method. I hear that's probably not the best way to code. </p>
<p>How should I have written this to utilize multiple classes or to adhere to best practice? </p>
<pre><code>import jav... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-08T22:36:04.557",
"Id": "40167",
"Score": "6",
"body": "For trivial programs such as your average CS class assignment, it's not as evil as we generally make it out to be. However, two things are central to good code design at any level... | [
{
"body": "<p>I would make some changes, although your code is quite simple.</p>\n\n<p>First, get rid of the magic Strings for rock/paper/scissors, and create an enum.</p>\n\n<p>I would possibly also move the logic of checking if it's a win/draw/loose inside that enum, so it would be much easier to add new entr... | {
"AcceptedAnswerId": "25950",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-08T16:01:53.103",
"Id": "25949",
"Score": "12",
"Tags": [
"java",
"beginner",
"game",
"rock-paper-scissors"
],
"Title": "Rock Paper Scissors in one single method in Java - Goo... | 25949 |
<p>I am a backbone.js newbie. I have created a color picker application using backbone.js. I am trying to figure out if I have nailed the MVC concept. Please review my code and let me know if I can do better.</p>
<pre><code><!DOCTYPE html>
<head>
<meta http-equiv="Content-Type" content="text/html; chars... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-02T15:17:05.957",
"Id": "105782",
"Score": "0",
"body": "I'd recommend you checkout some Backbone data binding library such as Thorax, Epoxy or stick-it"
}
] | [
{
"body": "<p>Interesting question,</p>\n\n<p><strong>MVC</strong></p>\n\n<p>It seems, you did not nail the MVC concept perfectly.</p>\n\n<p>In essence, you should have 1 single render routine for both RGB, HSV and CMYK since all these are just outputs of the same value from the model. It does not make sense to... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-08T17:57:45.797",
"Id": "25953",
"Score": "4",
"Tags": [
"javascript",
"mvc",
"html5",
"backbone.js"
],
"Title": "MVC Design using backbone.js"
} | 25953 |
<p>I have managed to write some pretty terrible code in VBA and I know there has to be a better way. I have made all of these variables to store some data which I eventually reference in the application. I'm fairly certain I need to loop over the recordset or fields and store the variables that way but I can't figure ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-28T19:11:03.083",
"Id": "89867",
"Score": "0",
"body": "You might be interested in [this code](http://codereview.stackexchange.com/q/46506/23788), which pretty much mootinates my answer. Came up with it recently ;)"
}
] | [
{
"body": "<p>From the <a href=\"http://msdn.microsoft.com/en-us/library/office/bb177501%28v=office.12%29.aspx\" rel=\"nofollow noreferrer\">help</a> : \"The default collection of a Recordset object is the Fields collection, and the default property of a Field object is the Value property. Use these defaults to... | {
"AcceptedAnswerId": "31117",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-08T20:02:19.463",
"Id": "25956",
"Score": "5",
"Tags": [
"vba"
],
"Title": "Storing recordset data"
} | 25956 |
<p>I wrote a little ruby script to download issues of PragPub magazine and send them to my Kindle via email. I would love to get some feedback on it.</p>
<p>One part, specifically, where I feel like there might be a better way is where it downloads the file and writes to disk. It used to do this:</p>
<pre><code>open(... | [] | [
{
"body": "<p>For the first snippet there is no much room for improvement, but you can use <code>File.write</code>:</p>\n\n<pre><code>begin\n content = open(url).read\n File.write(filepath, content)\nrescue OpenURI::HTTPError => e\n abort \"Unable to download #{url}: #{e.to_s}\"\nend\n</code></pre>\n\n<p>... | {
"AcceptedAnswerId": "25977",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-08T21:46:24.560",
"Id": "25958",
"Score": "1",
"Tags": [
"ruby"
],
"Title": "Ruby script to send PragPub magazine to Kindle"
} | 25958 |
<p>I have a simple Rails app, which is used to run some clinical surveys. Participants answer sets of questions (multiple-choice, valued 1-5), and, within each set, the answers are summed up and the resulting score placed into to certain score brackets, which are different for each set of questions, and for each partic... | [] | [
{
"body": "<p>You repeat this pattern a couple of times:</p>\n\n<pre><code>score_ranges = []\nbracket[:min_scores].each_cons(2) do |bounds|\n score_ranges << Range.new(bounds.first, bounds.last, true)\nend\n</code></pre>\n\n<p>Note that this can be written in functional style. Also, you can unpack the ar... | {
"AcceptedAnswerId": "25979",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-08T22:57:16.497",
"Id": "25959",
"Score": "6",
"Tags": [
"ruby",
"ruby-on-rails",
"lookup"
],
"Title": "Mapping arrays to ranges in Ruby"
} | 25959 |
<p>I have an <code>Order</code> object that <code>belongs_to</code> a BillingAddress and a ShippingAddress. I want to present my user with only ShippingAddress fields and a checked checkbox indicating that the billing address matches the shipping address. If the user unchecks the box, the BillingAddress fields appear.<... | [] | [
{
"body": "<h2>Solution still relying on callbacks</h2>\n\n<p>validations in rails accept a \"condition\" option:</p>\n\n<pre><code>validates :shipping_address, presence: true, unless: :ship_to_billing_address?\n</code></pre>\n\n<p>for simplicity and consistency, i would advise to use a \"real\" attribute inste... | {
"AcceptedAnswerId": "25982",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-09T00:55:24.680",
"Id": "25963",
"Score": "2",
"Tags": [
"ruby",
"ruby-on-rails"
],
"Title": "ActiveRecord object for billing and shipping addresses"
} | 25963 |
<p>From a programming assignment:</p>
<blockquote>
<p>Write a method <code>writeSequence</code> that accepts an integer <code>n</code> as a
parameter and prints a symmetric sequence of <code>n</code> numbers with
descending integers ending in 1 followed by ascending integers
beginning with 1, as in the table... | [] | [
{
"body": "<p>Assuming you can use a helper function, you could do this:</p>\n\n<pre><code> public static void writeSequence(int n) {\n if (n < 1) throw new IllegalArgumentException();\n writeSequenceHelper(n);\n }\n\n public static void writeSequenceHelper(int n) {\n if (n <= 0) return;\n ... | {
"AcceptedAnswerId": "25966",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-09T01:28:07.253",
"Id": "25964",
"Score": "4",
"Tags": [
"java",
"recursion"
],
"Title": "Recursive method to print a descending then ascending integer sequence"
} | 25964 |
<p>Philosophical question: How far should I break down my objects?</p>
<p>Inuit.css and Bootstrap have islands, islets, wells, grayboxes, and other objects that have repeating properties. I don't think it was DRY enough, so I created a generic .box object & a few skins. I am just not sure if this is overkill?</p>
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-27T15:27:51.837",
"Id": "50930",
"Score": "0",
"body": "it really depends on how many you have and how you are combining them"
}
] | [
{
"body": "<p><strong>Don't Repeat Yourself</strong> as a principle doesn't really mean that you <strong>NEVER</strong> should repeat yourself. It's a general advice to avoid repetition.</p>\n\n<p>First of all, I'd suggest not using single letters for things like <code>small</code> or <code>large</code>. Writin... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-09T04:28:41.190",
"Id": "25968",
"Score": "11",
"Tags": [
"design-patterns",
"html",
"css"
],
"Title": "OOCSS: Is this broken down too much?"
} | 25968 |
<p>Why does this Erlang code take about one minute on my machine?</p>
<p>On Pascal something like this took less then second on my machine.</p>
<p>What I can do to speed it up?</p>
<pre><code>-module(slow).
-export([slow/0]).
pyth(N) ->
[{A, B, C} ||
A <- lists:seq(1, N - 2),
B <- lists... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2015-06-05T21:07:12.317",
"Id": "168554",
"Score": "0",
"body": "i think it is possible to generate triplets in linear time, just think how to limit lists"
}
] | [
{
"body": "<p>Erlang runs on a VM, so you will get better performance on such a pure arithmetic computation by compiling it into native code using HIPE.</p>\n\n<p>From the command line:</p>\n\n<pre><code>erlc +native slow.erl\n</code></pre>\n\n<p>Or from the Erlang shell:</p>\n\n<pre><code>1> hipe:c(slow).\n... | {
"AcceptedAnswerId": "25996",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-09T07:02:12.077",
"Id": "25971",
"Score": "2",
"Tags": [
"performance",
"erlang"
],
"Title": "Slow Erlang code to find Pythagorean triplets"
} | 25971 |
<p>I am developing a C# Windows service that will always watch different folders/files and DB query results on different time intervals. There can be dozens of watchers each watching a specific file or folder or DB query results and sends emails at specific email address if some predefined threshold is met, and begins ... | [] | [
{
"body": "<p>Took a quick glance, seems relatively logical. Can't think of anything I would do wildly differently.</p>\n\n<p>I do have one suggestion, though:</p>\n\n<p>Subscribe to the <code>System.Threading.Tasks.TaskScheduler.UnobservedTaskException</code> event handler. In case you do a mistake or somethin... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-09T08:08:43.050",
"Id": "25972",
"Score": "3",
"Tags": [
"c#",
"multithreading",
"timer",
"windows",
"task-parallel-library"
],
"Title": "File/folder watcher Windows service"... | 25972 |
<p>GOAL:</p>
<ul>
<li>Accept DSV strings where the delimiter may consist of more than one character</li>
<li>Accept DSV strings where there are no embedded delimiters</li>
<li>Output text with no modification to the source string other than aligning custom delimiter with optional padding</li>
</ul>
<p>QUESTION:</p>
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-09T15:14:30.833",
"Id": "40192",
"Score": "1",
"body": "As usual I'd recommend re-writing it in functional style, code with side-effects is harder to understand. Are you insterested in how it'd look?"
},
{
"ContentLicense": "CC... | [
{
"body": "<p>Some notes:</p>\n\n<ul>\n<li><code>include DreftymacAddon::String</code>. Monkeypatching common classes is always controversial, but in this case I wouldn't do it, it's not a general enough abstraction.</li>\n<li>As always, I'd recommend using <a href=\"https://code.google.com/p/tokland/wiki/RubyF... | {
"AcceptedAnswerId": "25995",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-09T08:28:45.427",
"Id": "25974",
"Score": "4",
"Tags": [
"ruby",
"strings"
],
"Title": "Ruby: refactor simple string method for aligning DSV text"
} | 25974 |
<p>Would it be possible to get some feedback on some code I've just written? I've been working my way through Deitels' <em>Java How to Program</em> for the past few months and thought I'd better ask for some help before my bad coding habits get too ingrained.</p>
<p>The current problem I've just been working on is thi... | [] | [
{
"body": "<p>I have several suggestions: </p>\n\n<ol>\n<li><p>For readability I would suggest to introduce <code>enum</code>s like</p>\n\n<pre><code>public enum SeatType {\n FIRSTCLASS, ECONOMY }\n</code></pre>\n\n<p>If you have to make several decisions depending on the seats type <code>SeatType.FIRSTCLASS... | {
"AcceptedAnswerId": "25992",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-09T12:15:49.347",
"Id": "25978",
"Score": "4",
"Tags": [
"java",
"object-oriented",
"console"
],
"Title": "Airline Reservations System"
} | 25978 |
<p>I have a piece of code that divides a group of numbers into two groups of numbers of which the sums are equal. </p>
<p>I created this because of a <a href="https://stackoverflow.com/questions/16458067/how-to-make-equal-subsets-of-integers">Stack Overflow question</a>:</p>
<p>For example:</p>
<ul>
<li>{10,15,20,5}... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-09T14:16:03.010",
"Id": "40187",
"Score": "0",
"body": "What's slow about it? Have you measured it and determined the hot spot(s)?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-09T14:21:39.933",
"Id":... | [
{
"body": "<p>Here's some stuff I did to increase the performance. If there's any parts that you'd like explained fuller, let me know and I will.</p>\n\n<pre><code> private static readonly IList<int> emptyList = Enumerable.Empty<int>().ToList();\n\n public static bool Partition(IList<int>... | {
"AcceptedAnswerId": "26219",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-09T13:14:38.253",
"Id": "25980",
"Score": "3",
"Tags": [
"c#",
"performance",
"collections",
"bitwise"
],
"Title": "Divide group of numbers into two groups of which the sums a... | 25980 |
<p>I'm just getting started with AJAX and am unsure of the best way to structure a PHP AJAX handler. I created a PHP file, <code>ajax_handler.php</code>, and the way I have it structured now is just a bunch of <code>if-else</code> statements (one for each AJAX event), like the following.</p>
<p>First, I make sure ther... | [] | [
{
"body": "<p>Lots of <code>if</code>'s tend to signal the need for some classes. What are you using for the main routing that's being done by your app? In other words, when you point to <code>domain.com/blog</code>, how does your app know where to go?</p>\n\n<p>One way to do routing is to use a front controlle... | {
"AcceptedAnswerId": "25988",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-09T15:45:04.097",
"Id": "25987",
"Score": "5",
"Tags": [
"php",
"ajax"
],
"Title": "Best way to structure PHP AJAX handlers?"
} | 25987 |
<p>I have implemented the Dining Philosopher problem using <code>ReentrantLock</code> in Java.</p>
<p>The goal of this program is:</p>
<ul>
<li>Every philosopher should follow the workflow of think, getchopsticks, eat, putchopsticks (no race conditions).</li>
<li>No Philosopher should be starving for food (no deadloc... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-07T09:49:11.040",
"Id": "64735",
"Score": "1",
"body": "I am sorry but could you explain to me why this code doesn't generate a deadlock if all the philosophers pick up the left chopstick?"
}
] | [
{
"body": "<p>I post full code in the hope that you will learn. If this is homework please try to understand all the changes I have made instead of just copying it.</p>\n\n<pre><code>public class DiningPhilosopherProblem {\n // Makes the code more readable.\n public static class ChopStick {\n // Make sure ... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-09T16:08:42.160",
"Id": "25989",
"Score": "6",
"Tags": [
"java",
"multithreading",
"thread-safety",
"dining-philosophers"
],
"Title": "Dining Philosophers problem solution with J... | 25989 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.