body stringlengths 25 86.7k | comments list | answers list | meta_data dict | question_id stringlengths 1 6 |
|---|---|---|---|---|
<p>I've written a simple program in Python which does the following:</p>
<p><strong>Input:</strong> an integer \$n\$</p>
<p><strong>Output:</strong> a \$2^n x 2^n\$ matrix containing small \$L\$s which fill the entire matrix except one single square. Each L has its unique number, and consists of three squares.</p>
<... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-23T19:19:32.157",
"Id": "25795",
"Score": "1",
"body": "Get out of the habit of using global variables like that. You're just asking for trouble when you do."
}
] | [
{
"body": "<pre><code>#!/usr/bin/env python\n\nimport sys, math\n\nur = [[1,0],\n [1,1]]\n\nul = [[0,1],\n [1,1]]\n\nlr = [[1,1],\n [1,0]]\n\nll = [[1,1],\n [0,1]]\n</code></pre>\n\n<p>Rather then creating four separate variables, I'd suggest making a list. I'd also suggest using the <code>n... | {
"AcceptedAnswerId": "15856",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-23T19:10:37.353",
"Id": "15852",
"Score": "2",
"Tags": [
"python",
"algorithm",
"matrix"
],
"Title": "Outputting a 2^n x 2^n matrix"
} | 15852 |
<p>I wrote this class which is a priority queue based on a numeric property of any object. As far as I can tell, the following code is working as intended. Are there any stylistic tendencies that I am getting wrong, or any gotchas I should look out for?</p>
<pre><code>//Constants
PriorityQueue.MAX_HEAP = 0;
PriorityQ... | [] | [
{
"body": "<p>You're off to a great start. +1 for providing comments.</p>\n\n<p>Here are some tips:</p>\n\n<h2>1) Define variables before modifying them.</h2>\n\n<p>So the constants <code>MAX_HEAP</code> and <code>MIN_HEAP</code> should be defined after <code>PriorityQueue</code>.</p>\n\n<p>Old Code:</p>\n\n<pr... | {
"AcceptedAnswerId": "15874",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-23T19:33:13.877",
"Id": "15853",
"Score": "5",
"Tags": [
"javascript",
"beginner",
"algorithm",
"object-oriented",
"priority-queue"
],
"Title": "Javascript PriorityQueue b... | 15853 |
<p>This script is meant to look for an id in the data attribute in each containment div, then send an Ajax call to get the amount of retweets, calculate the karma based on those retweets and then display that number in a div.</p>
<p>This code looks like spaghetti. How do I improve this to make each function more indep... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-24T06:59:55.430",
"Id": "25807",
"Score": "3",
"body": "I don't think this code is spaghetti."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-24T07:01:56.783",
"Id": "25809",
"Score": "0",
"body... | [
{
"body": "<p>I think your problem is best solved by using some MVC framework like <a href=\"http://angularjs.org/\" rel=\"nofollow\">AngularJS</a>. It helps you handle deferred promise and update your views automatically out of the box.</p>\n",
"comments": [
{
"ContentLicense": "CC BY-SA 3.0"... | {
"AcceptedAnswerId": "15884",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-23T23:57:20.823",
"Id": "15860",
"Score": "9",
"Tags": [
"javascript",
"jquery",
"ajax",
"twitter"
],
"Title": "Calculate karma based on retweets"
} | 15860 |
<p>First off, let me say that <a href="http://imar.spaanjaars.com/416/building-layered-web-applications-with-microsoft-aspnet-20-part-1" rel="nofollow">this article</a> pretty much changed how I program, for the better. Until I read this article, I was a spaghetti programming master --- if there were awards for crappi... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-24T14:15:48.293",
"Id": "25818",
"Score": "0",
"body": "\"Upon Object instantiation, I set everything to null.\" Well, if all your objects are nullable types as per your example, you don't have to set anything at all -- `null` is the d... | [
{
"body": "<p>Fist off, congratulations on your transformation. It's always nice to hear about people seeing the light!</p>\n\n<p>Second I tend to agree with you. If the layer is doing nothing but passing calls to another layer, it is not needed. I would take it out. If, in the future you decide, or figure ... | {
"AcceptedAnswerId": "15865",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-24T01:56:23.343",
"Id": "15864",
"Score": "4",
"Tags": [
"c#",
"asp.net"
],
"Title": "Fully utilizing the layers of an n-layered web application"
} | 15864 |
<p>I have written this jQuery code to traverse the HTML markup. Basically, I am selecting <code>data-icount</code> attribute of each anchor tag and appending it to anchor text as <code>(28)</code> e.g. the ALL becomes <code>ALL (38)</code> in the example. <code>38</code> here is the sum of all the <code>data-icount</co... | [] | [
{
"body": "<p>Here are some tips:</p>\n\n<h2>1) Don't create variables if they're only used once or are a don't perform complex operations.</h2>\n\n<p>Old Code:</p>\n\n<pre><code>var num_sub_uls = $sub_uls.length;\nvar count_icount = 0;\nif(num_sub_uls > 0) {\n</code></pre>\n\n<p>New Code:</p>\n\n<pre><code>... | {
"AcceptedAnswerId": "15875",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-24T11:04:56.260",
"Id": "15867",
"Score": "4",
"Tags": [
"javascript",
"jquery",
"html"
],
"Title": "Traversing un-ordered list and appending attibute values to the list item"
} | 15867 |
<p>I would really appreciate a review of my first game. It is a <a href="https://en.wikipedia.org/wiki/Bejeweled"><em>Bejeweled</em></a>-like game written in Python with <a href="http://pygame.org/">Pygame</a>:</p>
<pre><code>import pygame, random, time, sys
from pygame.locals import *
pygame.init()
NUM_SHAPES = 7 ... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2018-10-22T23:07:49.970",
"Id": "397516",
"Score": "0",
"body": "Link is broken now..."
}
] | [
{
"body": "<h3>1. Introduction</h3>\n\n<p>The code seems pretty good to me overall. I had no difficulty reading it or understanding what it did, and it seems to work well enough. So take all the points below (especially those in section 3) with a pinch of salt. I would have written it differently, but that does... | {
"AcceptedAnswerId": "15895",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-24T14:43:39.057",
"Id": "15873",
"Score": "12",
"Tags": [
"python",
"pygame"
],
"Title": "A small Bejeweled-like game in Pygame"
} | 15873 |
<p>I'm using Node.js and am creating some models for my different objects. This is a simplified version of what they look like at the moment.</p>
<pre><code>var Foo = module.exports = function () {
var values = { type: 'foo', prop1: '', prop2: '' };
function model() {}
model.init = function(val) {
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-24T17:27:26.273",
"Id": "25825",
"Score": "0",
"body": "What's the `db` variable? Is that mongodb?"
}
] | [
{
"body": "<p>Here are some tips:</p>\n\n<h2>1) Turn <code>Model</code> into a constructor that accepts an object as the default values.</h2>\n\n<p>Note: Constructors should start with a capital letter.\nCode:</p>\n\n<pre><code>// Model\nfunction Model(defaultValues) {\n this.values = defaultValues || {};\n}... | {
"AcceptedAnswerId": "15878",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-24T16:51:21.157",
"Id": "15876",
"Score": "4",
"Tags": [
"javascript",
"node.js"
],
"Title": "How to refactor common methods that depend on local variables into a base class"
} | 15876 |
<p>I'm trying to write a simple class to represent a text file - which one would think should be quite easy. I don't intend to add all bells and whistles to fully represent a text file just enough to be able create/open read and write etc.</p>
<p>The more I look at it the more I think that it's a bad idea or rather th... | [] | [
{
"body": "<ol>\n<li><p>I think you shouldn't use inheritance here. The <a href=\"http://docs.oracle.com/javase/6/docs/api/java/io/File.html\" rel=\"nofollow noreferrer\"><code>java.io.File</code></a> class is <em>an abstract representation of file and directory pathnames</em> (from the javadoc) and it has meth... | {
"AcceptedAnswerId": "15888",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-24T19:53:23.763",
"Id": "15885",
"Score": "7",
"Tags": [
"java",
"object-oriented",
"error-handling"
],
"Title": "Class representing a text file"
} | 15885 |
<p>I was working on a task to implement auto suggest from an array of couple of thousands of strings. </p>
<p>Of course, the first and the easiest implementable was to go through each element and do <code>a[i].startWith(query)</code>. Technically the time complexity of this algorithm then would be \$O(n+(q*m))\$. Here... | [] | [
{
"body": "<ol>\n<li><p>Eclipse says that the second <code>null</code> check in the <code>search</code> method is dead code:</p>\n\n<pre><code>if (current == null) {\n return matches;\n}\n</code></pre>\n\n<p>Furthermore, it could be refactored to the following:</p>\n\n<pre><code>public Set<Trie> search... | {
"AcceptedAnswerId": "15893",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-24T21:09:34.290",
"Id": "15887",
"Score": "11",
"Tags": [
"java",
"trie"
],
"Title": "Trie implementation for left to right wildcard search"
} | 15887 |
<p>I've quickly made a function to deny or allow access to files that are only used thru Ajax calls.</p>
<p><strong>Key Generator</strong></p>
<pre><code>/**
* Generate a key for file access permission
*
* Function that returns a key to grant access to a PHP file
* that will be consulted by an ajax call.
*
* ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-25T00:30:32.177",
"Id": "25845",
"Score": "0",
"body": "Whoever told you, that simple SHA1 hash with salt is secure, lied. Also .. where is the rest of the code? This seems more like topic for general StackOverflow site, because there ... | [
{
"body": "<p>Short version:</p>\n\n<ol>\n<li>You may trust your own PHP code, if you write it well.</li>\n<li>You should not trust data received by cookies, <code>$_GET</code> or <code>$_POST</code>.</li>\n<li>Attempting to distinguish data sent from your JavaScript application from malicious input relies on m... | {
"AcceptedAnswerId": "15892",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-24T21:47:04.203",
"Id": "15889",
"Score": "1",
"Tags": [
"security",
"php5"
],
"Title": "File access permission/deny function"
} | 15889 |
<p>This gets every form element and calculates its width, then changes the input fields depending on the parent-form width:</p>
<pre><code>$ ->
# Alter 'input' Width
inputResize = ->
$('form').each ->
tF = $(this)
formWidth = tF.width()
tF.find('input').each ->
tE = $(this)
inp... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-25T00:22:22.673",
"Id": "25844",
"Score": "1",
"body": "There is no point in optimizing coffeescript. If you want to write optimal code, write it in native javascript (and that means - no jquery)."
},
{
"ContentLicense": "CC BY... | [
{
"body": "<p>This is pretty good, you could do that, don't know if you find it much more readable:</p>\n\n<pre><code>$ ->\n # Alter 'input' Width\n inputResize = -> \n $('form').each ->\n tF = $ @\n formWidth = tF.width()\n tF.find('input').each ->\n tE = $ @\n inp... | {
"AcceptedAnswerId": "15941",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-24T15:30:22.957",
"Id": "15890",
"Score": "4",
"Tags": [
"coffeescript"
],
"Title": "Altering input field width"
} | 15890 |
<p>I've an <code>AbstractMessage</code> object (a hierarchy, actually). It represents a small text message and can be sent using <strong>different transport methods</strong>: HTTP, REST and a "mailer" transport. Each transport relies on an external library for executing the transport itself, injected using a DI contain... | [] | [
{
"body": "<p>I would use an abstract class instead of, or in addition to, an interface. You have quite a bit of repetition that could be removed by doing so. The only problem then would be that you would have to use protected instead of private properties and methods, at least for those that you need to share ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-25T07:18:54.610",
"Id": "15899",
"Score": "5",
"Tags": [
"php",
"object-oriented",
"design-patterns",
"php5"
],
"Title": "When an object has different representations... what's t... | 15899 |
<p>I have a class extending the Dictionary class. This class is used for storing some information (modeled in <code>CustomClass</code>) and accessing it through an integer ID.</p>
<p>To extend this class I have added a <code>TryAdd</code> method, specific to my workflow, which implement different behaviours for the ca... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-25T07:44:55.123",
"Id": "25857",
"Score": "3",
"body": "You should put the lock around all the code in the TryAdd method. If two threads both hit the 'ContainsKey' before an addition is performed, both threads will then add the object.... | [
{
"body": "<p>First of all, it's very good that you read about the evilness of <code>lock(this)</code>. Avoid it at all costs :)</p>\n\n<p>As for your solution, it's not thread safe, in terms of functionality:</p>\n\n<p>Thread A tries to add an object to id = 123.<br>\nSince this object doesn't exist, the <code... | {
"AcceptedAnswerId": "15909",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-25T07:23:53.687",
"Id": "15900",
"Score": "4",
"Tags": [
"c#",
"locking"
],
"Title": "Improving handling of data structure used in parallel"
} | 15900 |
<p>This is my socket.cpp </p>
<pre><code>#pragma hdrstop
#include "MySocketClient.h"
MySocketClient::MySocketClient() throw(SocketException){
WSAData data;
InitializeCriticalSection(&sect_);
if(WSAStartup(MAKEWORD(2,2),&data)!=0){
throw SocketException("Cant load WinSock library");
... | [] | [
{
"body": "<p>The code generally looks ok. Does it work as expected?</p>\n\n<p>What is the reason for using a critical section in <code>MySocketClient::receive()</code>? Are you sharing common data between multiple threads? It doesnt appear so, and even if you were, this wouldnt protect anything since each inst... | {
"AcceptedAnswerId": "15902",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-25T07:49:17.350",
"Id": "15901",
"Score": "4",
"Tags": [
"c++",
"c",
"multithreading",
"tcp"
],
"Title": "Multithreaded Socket code to connect to 100 different machines"
} | 15901 |
<p>I have a scenario wherein I have to filter a collection in a <code>PagedCollectionView</code>.
The filter criteria are <code>Name</code> and status which are checkboxes with Enabled and Disabled labels. If <code>Enabled</code> is checked it should filter out the list with all enabled rules and vice-versa. I have gi... | [] | [
{
"body": "<p>If performance is your concern, won't boxing and unboxing the variable unnecessarily add an overhead? Why would you want to do that?</p>\n\n<p>Wouldn't this be much easier?</p>\n\n<pre><code>this.AutoDepRuleList //if this is queryable/enumerable, or convert first\n.Where(r => (isDisabled &&... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-25T11:10:29.213",
"Id": "15904",
"Score": "2",
"Tags": [
"c#",
"performance",
"linq"
],
"Title": "Filter a collection in a PagedCollectionView"
} | 15904 |
<p>I'm writing a simple automatic backup/versioning bash script.</p>
<p>It should basically mirror a directory structure somewhere, and then copy files over there when they've been altered. The ghost files should then be named <code>filename.YYYYMMDD-HHMMSS.ext</code> (the included date/time being the time of last mod... | [] | [
{
"body": "<p>Implementing solutions to problems like this is good for exercise purposes. It is good for learning.</p>\n\n<p>But it is almost never good to re-invent the wheel in production systems. Please have a look at well-established data synchronization software such as <a href=\"http://en.wikipedia.org/wi... | {
"AcceptedAnswerId": "15908",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-23T20:20:07.617",
"Id": "15905",
"Score": "8",
"Tags": [
"linux",
"bash",
"shell"
],
"Title": "Can I speed up this simple versioning/backup script?"
} | 15905 |
<p>I'm currently studying Java by myself. The book I'm using (while very good)
lacks feedback (obviously). While trying to write this program, I found myself solving most of the problems I've encountered by trial and error and makeshift solutions, which I fear might have led to some haphazard code. A good example wo... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-26T11:58:05.977",
"Id": "25934",
"Score": "0",
"body": "Hi , been getting some great answers though one part remains unreviewed the recursive scoreBestMove , I know beggars can't be choosers but I would really love for that function to... | [
{
"body": "<p>Here are some simple fixes you should make to the beginning of the <code>Board</code> class. I'll let someone else tackle another part.</p>\n\n<pre><code>public class Board {\n int Square[][] = new int [3][3];\n\n\n Board(){\n int Square[][] = new int [3][3];\n }\n// constructor ... | {
"AcceptedAnswerId": "15939",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-25T14:07:05.083",
"Id": "15911",
"Score": "19",
"Tags": [
"java",
"beginner",
"game"
],
"Title": "TicTacToe logic in Java"
} | 15911 |
<p>I'm a total newbie teaching myself via Zed Shaw's <em>Learn Python The Hard Way</em> and I've gotten bored over a week long memorization lesson, so I thought I would make a character generator for a pen and paper RPG I'm writing. I havent really read about <code>if</code> statements or things like that, so I am expe... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2015-05-23T16:34:10.923",
"Id": "166160",
"Score": "0",
"body": "Small tip, that top comment should be a docstring."
}
] | [
{
"body": "<pre><code>def roll_stats():\n a = random.randint(1, 6)\n b = random.randint(1, 6) \n c = random.randint(1, 6)\n d = random.randint(1, 6)\n list = [a, b, c, d]\n</code></pre>\n\n<p>Call it <code>dice</code> or something more descriptive then <code>list</code>. You can also use <code>li... | {
"AcceptedAnswerId": "15914",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-25T14:23:22.620",
"Id": "15913",
"Score": "7",
"Tags": [
"python",
"beginner",
"game",
"dice",
"role-playing-game"
],
"Title": "Character generator"
} | 15913 |
<p>I'm new to Android and I wanted to create a class that would load an ad inside the current layout. All the layouts have a <code>RelativeLayout id=adLayout</code></p>
<p>From my main, I have:</p>
<pre><code>AdLoader al = new AdLoader();
al.GrabAd(this,"123");
</code></pre>
<p>Then on my AdLoader.java class I have... | [] | [
{
"body": "<p>You could also make a baseactivity for all the other activity that are going to use the adView</p>\n\n<pre><code> public class BaseActivity extends Activity {\n\n private DfpAdView adView;\n RelativeLayout rl;\n //some other stuff\n\n @Override\n public void onCreate(Bundle saved... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-25T15:36:57.343",
"Id": "15915",
"Score": "4",
"Tags": [
"java",
"beginner",
"android"
],
"Title": "findViewById - in separate class"
} | 15915 |
<p>Here's a class I created to parse XML to create an IList.
It seems to me that this is something that will be done a lot in general by a lot of different programs. Is there a more standard way of doing this using .Net and C#</p>
<pre><code>/// <summary>
/// public class CListFromXml {}
/// Created By: Michael ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-25T19:11:15.007",
"Id": "25896",
"Score": "1",
"body": "I really don't think deserializing from a variant of CSV inside XML is something that is “done a lot”. Can't you use XML serialization?"
},
{
"ContentLicense": "CC BY-SA 3... | [
{
"body": "<p>Your code is definitely not a standard way of parsing XML in .NET. Usually there are 2 main cases where XML parsing is needed:</p>\n\n<ol>\n<li><p>You expect a predefined XML structure. In this case all the types of XML nodes are known upfront, so there is no need to specify them inside XML (as yo... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-25T18:48:01.913",
"Id": "15922",
"Score": "4",
"Tags": [
"c#",
"strings",
"xml"
],
"Title": "Parsing XML to create IList"
} | 15922 |
<p>I am looking for some ideas on how this could be improved:</p>
<pre><code>switch ($periodValue) {
case "lastmonth":
$until = mktime(0, 0, 0, date('n'), 1, date('Y'));
$from = mktime(0, 0, 0, date('n', $until) - 1, 1, date('Y', $until));
break;
case "last3month":
$until = mkti... | [] | [
{
"body": "<p>The date/time functions in PHP are a tricky thing. Last I looked into this there were known bugs with many of the date/time functions, especially around leap years, but no solutions. I don't know if that has changed, haven't had the need to look, so this answer might not be the best one, but have ... | {
"AcceptedAnswerId": "15925",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-25T18:50:43.873",
"Id": "15923",
"Score": "8",
"Tags": [
"php",
"datetime"
],
"Title": "Calculate last month, last 3 months, and last 6 months from today"
} | 15923 |
<p>I have written a PDO wrapper and a class file like a model. It's looking good so far, but I'm just confuseed on where I should put the <code>try</code>/<code>catch</code> block. Would it be better to place it in the PDO wrapper (pdoDatabase.php), mobile.php (model) or test.php?</p>
<p><strong>pdoDatabase.php</str... | [] | [
{
"body": "<p>I'll probably revisit this later, but for now:</p>\n\n<hr>\n\n<p>The exception catching should be done at either the model or model-using layer. I would probably let the exceptions bubble up through the model unless you want the model to be fairly high level.</p>\n\n<p>For the sake of abstracting... | {
"AcceptedAnswerId": "15940",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-25T21:13:42.363",
"Id": "15927",
"Score": "5",
"Tags": [
"php",
"php5",
"exception-handling",
"pdo"
],
"Title": "Try/catch block in PDO wrapper"
} | 15927 |
<p>Please suggest ways of cleaning up this code.</p>
<pre><code>Hashtable newValues = e.Values;
string NewPosition = null;
string NewFirst = null;
string NewLast = null;
string NewEmail = null;
int NewAppt = 0;
if (newValues["Position"] == null)
{
NewPosition = "";
}
else
{
NewPosition = newValues["Position"... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-25T19:23:05.090",
"Id": "25903",
"Score": "0",
"body": "I would suggest rewording the question to only have a representative snippet of that pattern, rather than repeating it 5 times"
},
{
"ContentLicense": "CC BY-SA 3.0",
... | [
{
"body": "<p>You can use the <em>null-coalescing operator</em> <a href=\"http://msdn.microsoft.com/en-us/library/ms173224.aspx\" rel=\"nofollow\"><code>??</code></a> like this:</p>\n\n<pre><code>NewPosition = (newValues[\"Position\"] ?? \"\").ToString();\n</code></pre>\n\n<p>The core of this approach is this e... | {
"AcceptedAnswerId": "15929",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-25T19:16:47.677",
"Id": "15928",
"Score": "10",
"Tags": [
"c#",
".net"
],
"Title": "Cleaning up conditional statements regarding new values"
} | 15928 |
<p>How can I make this more readable?</p>
<pre><code>public class RssFeed
{
string url = "http://www.pwop.com/feed.aspx?show=dotnetrocks&filetype=master";
public string responseBody;
private string DATE_FORMAT = "ddd, dd MMM yyyy HH:mm:ss \\E\\D\\T";
public Story[] Getstories()
{
ge... | [] | [
{
"body": "<p>Not that ugly. I've seen ugly code, and trust me, this is not ugly.</p>\n\n<p>However, this is kind of a \"God Class\" that has more than a single responsibility, hence it violates <a href=\"http://en.wikipedia.org/wiki/Single_responsibility_principle\">SRP principle</a>.</p>\n\n<h1>How to improve... | {
"AcceptedAnswerId": "15943",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-26T03:16:07.440",
"Id": "15942",
"Score": "5",
"Tags": [
"c#",
"object-oriented",
"parsing",
"rss"
],
"Title": "RSS feed class in C#"
} | 15942 |
<p>I have a data stream of bytes and I'd like to get a little endian encoded int32 from four bytes. Is there a better way than to do this like the following code?</p>
<pre><code>package main
func read_int32(data []byte) int32 {
return int32(uint32(data[0]) + uint32(data[1])<<8 + uint32(data[2])<<16 + ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-26T07:10:39.247",
"Id": "25924",
"Score": "0",
"body": "This page should help. http://golang.org/pkg/encoding/binary/#ReadVarint"
}
] | [
{
"body": "<p><code>encoding/binary</code> package may have what you need. Check this: <a href=\"http://golang.org/pkg/encoding/binary/#example_Read\">http://golang.org/pkg/encoding/binary/#example_Read</a></p>\n\n<p>Your code with modified <code>read_int32</code> function could be:</p>\n\n<pre><code>package ma... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-26T06:13:21.330",
"Id": "15945",
"Score": "9",
"Tags": [
"go",
"integer",
"serialization"
],
"Title": "Effectively convert little endian byte slice to int32"
} | 15945 |
<p>I have some <code>ViewModel</code>s that have a lot of parameters like this one:</p>
<pre><code>public class ProductsMainViewModel : NotificationObject, IActiveAware, ...
{
public ProductsMainViewModel(IProductRepository productRepository, IWarehouseRepository warehouseRepository, IUnitOfMeasureRepository unitO... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-28T15:41:03.023",
"Id": "26028",
"Score": "2",
"body": "*\"Is it a good idea to create a 'IFooRepositoriesContext' and put related repositories in it?\"* This is the route I'd go."
}
] | [
{
"body": "<p>why don't you write an <a href=\"http://en.wikipedia.org/wiki/Abstract_factory_pattern\" rel=\"nofollow\">abstract factory</a> containing all the references you need?\nYou can then implement a factory method for your ViewModel creating an instance based on some configuration parameters.\nYour clie... | {
"AcceptedAnswerId": "16013",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-26T06:54:22.453",
"Id": "15947",
"Score": "8",
"Tags": [
"c#",
"mvvm"
],
"Title": "ViewModel constructor with many parameters"
} | 15947 |
<p>I have learned to make a carousel image slideshow script with JavaScript. I think it's better to learn it from the basic than just from the framework (instant script), but I'm a newbie. I wrote this script using my technique, but I think it's terrible.</p>
<p><div class="snippet" data-lang="js" data-hide="false" da... | [] | [
{
"body": "<p>Great start for far but you need to work on your overall design.</p>\n\n<p>Here are some tips.</p>\n\n<h2>1) Separate the css, html and javascript into their own files.</h2>\n\n<p>If you were place all your css into a file called \"style.css\" and javascript in a file called \"main.js\", then you ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2012-09-26T07:31:00.780",
"Id": "15948",
"Score": "6",
"Tags": [
"javascript",
"html",
"css",
"timer"
],
"Title": "Carousel image slideshow script"
} | 15948 |
<p>Task: per host concurrency limits for web crawler (<code>map[string]Semaphore</code>).</p>
<p>I considered <code>chan struct{} (chan bool)</code> approach, but essentially it would not make code a lot easier because the main hurdle is to delete unused keys from map. And then semaphore takes constant memory - good p... | [] | [
{
"body": "<p>For my initial implementation, I would personally apply the common semaphore pattern using buffered channels for controlling the number of running goroutines. The simplest application of which looks like the code below (also available in this <a href=\"https://gist.github.com/theckman/283e6fde3ba6... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-26T11:05:54.077",
"Id": "15954",
"Score": "15",
"Tags": [
"multithreading",
"locking",
"synchronization",
"go"
],
"Title": "Concurrency limit map in Go"
} | 15954 |
<p><a href="http://jsfiddle.net/hrishikeshp19/VyDsu/21/" rel="nofollow">http://jsfiddle.net/hrishikeshp19/VyDsu/21/</a></p>
<p>Following is my HTML body:</p>
<pre><code><div id="header">
<div id="logo">
</div>
<div id="headercontent1">
</div>
<div id="headercontent2">
</div&g... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-26T15:57:33.527",
"Id": "25941",
"Score": "1",
"body": "We ask that you post your code in your question. This makes it easier to look at, and links like you have posted sometimes expire, so if somebody is looking at this in the future... | [
{
"body": "<p>The code you posted doesn't have must meaning to me and it's hard to follow.</p>\n<p>Here are a few guidelines to follow to improve your code quality.</p>\n<h2>1) Format your code.</h2>\n<p>Formatting makes your code easier to read and maintain.</p>\n<h2>2) Add some comments</h2>\n<p>It looks like... | {
"AcceptedAnswerId": "15968",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-26T15:42:45.520",
"Id": "15957",
"Score": "2",
"Tags": [
"javascript",
"html",
"css"
],
"Title": "make the fiddle cleaner"
} | 15957 |
<p>I want to generate a random alphanumeric string in ruby, as succinctly and efficiently as possible. The following solution works, but is obviously not very efficient. </p>
<p>Please review the following code, bearing in mind that I am trying to keep it as succinct and readable as possible while improving efficiency... | [] | [
{
"body": "<p>I think this is both declarative and concise:</p>\n\n<pre><code>8.times.map { [*'0'..'9', *'a'..'z', *'A'..'Z'].sample }.join\n</code></pre>\n\n<p>It works because:</p>\n\n<ol>\n<li>You can call <code>map</code> on <code>times</code> since >= 1.8.7 made it return an enumerator when called without ... | {
"AcceptedAnswerId": "15997",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-26T16:52:28.520",
"Id": "15958",
"Score": "10",
"Tags": [
"optimization",
"ruby",
"random"
],
"Title": "Generating a random alphanumeric string succinctly and efficiently"
} | 15958 |
<p>In my never-ending quest to improve my coding skills I am requesting peer input on the following code logic. I am asking because I'm -NOT- an expert, but would like to be one day. Source material and recommended read is greatly welcome (no, do NOT point me to the PHP manual) especially for code formatting, unit test... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-27T16:13:11.993",
"Id": "25974",
"Score": "2",
"body": "Its not, but its also unnecessary. All this does is bring it back to the top of the general list. It is already at the top of the PHP list. Just be patient. This community is a bi... | [
{
"body": "<p>Well, first suggestion, don't use <code>set_time_limit()</code>. Try and refactor your code so that it is unnecessary, unless this is a CRON job or something and is running in the background. If you access it via a webpage then even if you are expecting it to take a while, it could be confusing. F... | {
"AcceptedAnswerId": "15985",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-26T19:08:38.373",
"Id": "15960",
"Score": "4",
"Tags": [
"php",
"performance",
"php5"
],
"Title": "Comparing multiple fields from two tables, looking for matches, updating 2nd tab... | 15960 |
<h2>Context</h2>
<p>As an exercise for myself (I'm learning clojure). I wanted to implement the <code>Depth-first search</code> algorithm.</p>
<h2>How I did it</h2>
<p>Using recursion</p>
<pre class="lang-lisp prettyprint-override"><code>(def graph
{:s {:a 3 :d 4}
:a {:s 3 :d 5 :b 4}
:b {:a 4 :e 5 :c 4}
... | [] | [
{
"body": "<p>I wrote the modified version of your <code>findpath</code> function using recursion:</p>\n\n<pre><code>(defn- dfs\n [graph goal]\n (fn search\n [path visited]\n (let [current (peek path)]\n (if (= goal current)\n [path]\n (->> current graph keys\n (remo... | {
"AcceptedAnswerId": "16010",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-26T19:20:00.183",
"Id": "15961",
"Score": "7",
"Tags": [
"optimization",
"algorithm",
"performance",
"clojure"
],
"Title": "Depth-first search algorithm in clojure"
} | 15961 |
<p>The <code>createReport</code> method takes around 30 seconds to execute and I was wondering how I could optimize it. I'm using the <code>Interop.Excel</code> class and the workbook I'm importing to is very formula intensive. </p>
<pre class="lang-vb prettyprint-override"><code>Dim UserDate As New Data_Entry_Form.... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-27T09:04:55.577",
"Id": "25965",
"Score": "0",
"body": "30 seconds for how many records? Anyway, seens like a lot of opportunities for an improvement. Can you detail your benchmarks? Like which lines of code are slowing down everything... | [
{
"body": "<p>The first step in attempting to optimize a function like this is to narrow down the problem. Determine how long each of the function calls, and then specific lines of code, take to execute. This will tell you where you need to focus your efforts.</p>\n",
"comments": [
{
"ContentL... | {
"AcceptedAnswerId": null,
"CommentCount": "7",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-26T23:01:21.207",
"Id": "15966",
"Score": "7",
"Tags": [
"optimization",
"vb.net",
"excel"
],
"Title": "Optimizing this Excel automation"
} | 15966 |
<p>I am writing a networked audio application that sends the audio in 320 byte chunks, later I need to provide the player a bigger amount of bytes to play so I try to merge 2 or more chunks into one buffer and return it, well the code works but I hear some small audio artifacts, any ideas if the code is correct?</p>
<... | [] | [
{
"body": "<p>This is the wrong way to sue realloc:</p>\n\n<pre><code>returnBuffer = (char*)realloc(returnBuffer, requestedBufferSize);\n</code></pre>\n\n<p>If it fails you have just leaked the old returnBuffer.<br>\nThe way realloc should be used is:</p>\n\n<pre><code>char* tmp = (char*)realloc(returnBuffer, r... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-27T08:04:34.100",
"Id": "15969",
"Score": "6",
"Tags": [
"objective-c",
"ios"
],
"Title": "Am I reconstructing the buffers correctly"
} | 15969 |
<p>For experimental and learning purposes. I was trying to create a sorting algorithm from a hash function that gives a value biased on alphabetical sequence of the string, it then would ideally place it in the right place from that hash.</p>
<p>The reasoning is that theoretically if done right this algorithm can achi... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-27T07:03:18.827",
"Id": "25962",
"Score": "0",
"body": "It will not be O(n), it will be O(n^2). For each of the `n` entries, the inner `while` loop will iterate some number of times that scales with `n`. So the algortihm has an O(n) lo... | [
{
"body": "<p>You have reinvented a form of <a href=\"http://en.wikipedia.org/wiki/Radix_sort\" rel=\"nofollow\">radix sort</a>.\nSee that page for how to get rid of the two nested O(n) loops.</p>\n\n<p>It is possible to get O(n) if the maximum length of the words to be sorted is assumed to be a constant.</p>\n... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-27T06:56:40.847",
"Id": "15971",
"Score": "3",
"Tags": [
"python",
"sorting",
"c",
"algorithm"
],
"Title": "creating a hash based sorting algorithm"
} | 15971 |
<p>This is my first complete program written in F# (I was from C# and occasionally do interop) and I believe there are quite a few places I didn't tackle well in terms of coding practice.</p>
<p>Unblock Me / Rush Hour:</p>
<pre><code> 5 b b k j
4 c c c k j
3 a a k i ... | [] | [
{
"body": "<p>There are some places you could tweak the code to squeeze out more performance and/or adhere to better F# style.</p>\n\n<hr>\n\n<p>If you're not going to use a function in curried form -- i.e., you're always going to pass all of the arguments at once -- it's better to define the function as such. ... | {
"AcceptedAnswerId": "16011",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-27T09:51:51.180",
"Id": "15973",
"Score": "4",
"Tags": [
"algorithm",
"f#"
],
"Title": "Unblock Me / Rush Hour solver"
} | 15973 |
<p>I'm trying to learn some Scala and decided to try to tackle some Project Euler problems. </p>
<p>For <a href="http://projecteuler.net/problem=48" rel="nofollow">problem #48</a>, coming from a Python background, my solution is the following one-liner:</p>
<pre><code>print ( (1 to 1000).map(i => BigInt(i).pow(i))... | [] | [
{
"body": "<p>Your solution is totally valid. Instead of <code>xs.map(f).sum</code> it is possible to use <code>xs.foldLeft(init)(f)</code>:</p>\n\n<pre><code>(1 to 1000).foldLeft(BigInt(0)) {\n (sum, n) => sum+BigInt(n).pow(n)\n}\n// or with /: synonym for foldLeft\n(BigInt(0) /: (1 to 1000)) {\n (sum, n)... | {
"AcceptedAnswerId": "20967",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-27T10:44:05.413",
"Id": "15974",
"Score": "6",
"Tags": [
"scala",
"project-euler"
],
"Title": "Solving Project Euler problem #48 in Scala"
} | 15974 |
<p>There are three servers. I want to assign a job to a server which has least <code>NotStarted</code> jobs. I have achieved this, but my code is very lengthy. I don't know how to minimize my code without changing my concept. Here is my code:</p>
<pre><code>public List<int> GetPaServer()
{
List<int> Pa... | [] | [
{
"body": "<p>Use arrays to hold your servers, then loop over the arrays instead of repeating the same code for each server. In the loop you have a server AND its index, so you can omit changing just one number and the server while copying around the code. Rinse and repeat for NotStarted and the other values yo... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-27T11:13:37.193",
"Id": "15975",
"Score": "8",
"Tags": [
"c#",
"entity-framework"
],
"Title": "How to reduce my code length without changing concept?"
} | 15975 |
<p>I understand that I should use prepared statements to prevent SQL injection. Unfortunately, having read the PHP docs on the matter I am none the wiser. Here is one of my simple active record SQL queries in a CI2 model, could someone show me an example of how I might turn this into a prepared statement - do I even ne... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-28T16:26:30.347",
"Id": "26031",
"Score": "1",
"body": "Your code is fine, everything that goes through ActiveRecord is properly escaped. Unless you do your own where statements, things like `$this->db->where('col = ' . $value)`, you a... | [
{
"body": "<p>I'm not really sure if this question is on topic, but I just started using SQL myself, so here's a chance for me to apply what I've learned. The following is using PDO.</p>\n\n<pre><code>//unspecified placeholder\n$sql = \"SELECT * FROM item_entries WHERE item_id=?\";\n$sth = $dbh->prepare( $sq... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-27T15:00:10.040",
"Id": "15982",
"Score": "3",
"Tags": [
"php",
"codeigniter",
"sql-injection"
],
"Title": "Codeigniter active record"
} | 15982 |
<p>I thought it was a good idea to use this in my C++ projects:</p>
<pre><code>class CRAIICall
{
public:
typedef void (WINAPI * FnType)(HANDLE);
CRAIICall(HANDLE h, FnType fun)
: m_h(h), m_fun(fun)
{}
~CRAIICall() {
if (m_h) { m_fun(m_h); }
}
private:
HANDLE m_h;
FnType m_f... | [] | [
{
"body": "<p>No it is not safe (It is undefined behavior):</p>\n\n<p>The called function may put stuff on the stack (or somewhere else) as the return value. Expecting the caller to deal with it at their end. If the caller does not deal with the return value appropriately then you have undefined behavior (the r... | {
"AcceptedAnswerId": "15989",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-27T15:55:51.400",
"Id": "15984",
"Score": "4",
"Tags": [
"c++",
"casting",
"raii"
],
"Title": "CRAIICall class"
} | 15984 |
<p>I have a parent object (a display window) and it has a few child objects (buttons and controls on the window). I would like one child object to hide itself when another is clicked. Currently, I have my parent object bind to a custom event expected to be fired from the child object. Then, the parent object passes the... | [] | [
{
"body": "<p>It's really hard to judge if exposing <code>selector</code> is the <i>"right"</i> thing to do without reviewing more of your source code.\nAlso, it depends on your architecture design. If you're using a <a href=\"http://www.phpzag.com/php-model-view-controller-mvc/\" rel=\"nofollow noref... | {
"AcceptedAnswerId": "15993",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-27T16:22:13.837",
"Id": "15986",
"Score": "5",
"Tags": [
"javascript",
"jquery"
],
"Title": "Having a parent respond to a child's event"
} | 15986 |
<p>I have been doing server-side development for a couple of years, but I am just now getting into doing some client-side programming. As a JavaScript exercise, I created a dead-simple jQuery image slider plugin, but I don't know if I did it the "right" way.</p>
<p>Specifically, I was wondering what improvements ought... | [] | [
{
"body": "<ol>\n<li><p>It's more idiomatic to use <code>[]</code> rather than <code>new Array()</code></p></li>\n<li><p>You should use <code>var</code> with your functions too. E.g. </p>\n\n<pre><code>var enqueue = function($image) {\n images.push($image);\n}\n</code></pre>\n\n<p>Otherwise you're defining t... | {
"AcceptedAnswerId": "16001",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-27T16:40:43.440",
"Id": "15988",
"Score": "11",
"Tags": [
"javascript",
"jquery"
],
"Title": "Trying to learn idiomatic JavaScript and jQuery"
} | 15988 |
<p>I've implemented the following two versions of the classic <a href="http://en.wikipedia.org/wiki/Maximum_subarray_problem" rel="nofollow">"Max Sub-Array" problem</a> in Clojure, using the Kadane algorithm.</p>
<p>First with <code>loop</code> / <code>recur</code></p>
<pre class="lang-lisp prettyprint-override"><cod... | [] | [
{
"body": "<p>I think your implementations are succinct and straightforward.\nHowever, I prefer using primitives for loop args to avoid auto-boxing:</p>\n\n<pre><code>(defn maximum-subarray\n [^longs ls]\n (loop [i 0, meh 0, msf 0] ; index, max-ending-here, max-so-far\n (if (< i (alength ls)... | {
"AcceptedAnswerId": "16066",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-27T18:38:06.190",
"Id": "15992",
"Score": "2",
"Tags": [
"clojure"
],
"Title": "More concise and/or idiomatic max subarray in Clojure?"
} | 15992 |
<p>I'm new to Java and have been reading <em>Java for Dummies</em> and other ones as well. I've started building this program like a week ago. I'm sure it's very messy. Just seeing if someone can clean it up and show easier ways of doing things. I have like 4 classes, but I'll just post the main class and a subclass f... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-27T20:10:27.100",
"Id": "25981",
"Score": "2",
"body": "Rule number 1: Don't repeat yourself. Rule number 2: Read more books. Try this http://www.amazon.com/Clean-Code-Handbook-Software-Craftsmanship/dp/0132350882"
},
{
"Conten... | [
{
"body": "<p>A few random notes:</p>\n\n<ol>\n<li><p>Floating point values are not precise. You should use <code>BigDecimal</code>s for the balance instead of <code>double</code>. Some useful reading:</p>\n\n<ul>\n<li><a href=\"https://stackoverflow.com/questions/3730019/why-not-use-double-or-float-to-represen... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-27T19:18:57.983",
"Id": "15994",
"Score": "10",
"Tags": [
"java",
"beginner",
"finance"
],
"Title": "Bank ATM program"
} | 15994 |
<p>I'm trying to write a matlab function that creates random, smooth trajectories in a square of finite side length. Here is my current attempt at such a procedure: </p>
<pre><code>function [] = drawroutes( SideLength, v, t)
%DRAWROUTES Summary of this function goes here
% Detailed explanation goes here
%Some param... | [] | [
{
"body": "<p>Random walks \"wander all around\" by definition. So you have to twist the odds of the walk staying in the area you want.</p>\n\n<p>It would be much simpler if you'd just make an attractor point at the center, that would move each point infinitesimally (some floating point value between 0 to 1 or ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-27T19:53:50.693",
"Id": "15996",
"Score": "6",
"Tags": [
"matlab"
],
"Title": "Drawing random smooth lines contained within a square"
} | 15996 |
<p>I implemented a queue capable of operating both in the FIFO mode and in the priority mode: when the priority mode is enabled, the elements are taken in order of decreasing priority; when the priority mode in disabled, the elements are taken in order of their arrival.</p>
<p>In order to manage the priority, I though... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-28T14:40:58.243",
"Id": "26022",
"Score": "2",
"body": "Can't you make the queue generic? Wouldn't a more general approach to priorities be better?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-28T15:50:0... | [
{
"body": "<p>Layout looks good, I like the use of white space, and tabs. You have too many redundant comments that are unneeded.</p>\n\n<p>I am not big on the use of <code>m_</code> to signify class members, I think the <code>_</code> is more commonly used, but that is a debate for another time. I have chang... | {
"AcceptedAnswerId": "16086",
"CommentCount": "9",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-28T11:05:55.240",
"Id": "16005",
"Score": "6",
"Tags": [
"c#",
"performance",
"queue"
],
"Title": "A queue that switches from FIFO mode to priority mode"
} | 16005 |
<p>I have been developing a <a href="https://github.com/santosh/capitalizr/blob/master/capitalizr" rel="nofollow noreferrer">capitalizer</a> in Python. This is actually a script that an end user will type at their terminal/command prompt. I have made this script to:</p>
<ol>
<li>Taking the first argument as a file name... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-29T07:00:35.923",
"Id": "26051",
"Score": "2",
"body": "\"because GitHub is for developers.\" Non-developers tend to not use command line scripts..."
}
] | [
{
"body": "<h3>As a Command Line Utility</h3>\n\n<p>The <a href=\"http://docs.python.org/library/argparse.html#module-argparse\">Argparse</a> module is designed to facilitate the creation of command line utilities. It makes processing command line arguments much easier, and will even automatically display usage... | {
"AcceptedAnswerId": "16016",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-28T12:09:18.237",
"Id": "16007",
"Score": "9",
"Tags": [
"python",
"performance",
"strings",
"file"
],
"Title": "Command-line utility to capitalize long words in a file"
} | 16007 |
<p>The subject is this small project - <a href="https://github.com/salebab/database" rel="nofollow">PHP/MySQL Database wrapper</a></p>
<p>The three main goals of this projects are:</p>
<ul>
<li>Easy way to map database columns to object properties</li>
<li>Simple solution to insert or update data</li>
<li>Query build... | [] | [
{
"body": "<p>Firstly, a bit of humorous wordplay: witch = itch = burn; \"She's a witch! BURN HER!\" I think you meant \"which\" in this context. Now that is out of my system, on to the review :)</p>\n\n<p>Why are you extending the stdClass? This is the class reserved for typecasting variables as classes. It is... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-28T23:55:40.030",
"Id": "16017",
"Score": "4",
"Tags": [
"php",
"sql",
"mysql",
"pdo"
],
"Title": "PDO Database wrapper"
} | 16017 |
<p>I have written <code>Validation</code> and <code>Form</code> classes in PHP.</p>
<ul>
<li><code>Validation</code> class allow you to define the rules of each field and a error message. </li>
<li><code>Form</code> class allow you to get a error message and also allow you to get a value of POST via <code>$_SESSION</c... | [] | [
{
"body": "<p>Short on time, but here's a few quick things:</p>\n\n<ul>\n<li>Consider making individual validators rather than putting all of the different validation rules in one class.\n<ul>\n<li>One option would be to make a <code>Field</code> class and have <code>Form</code> contain a collection of <code>Fi... | {
"AcceptedAnswerId": "16077",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-29T01:02:50.163",
"Id": "16018",
"Score": "5",
"Tags": [
"php",
"design-patterns",
"classes",
"php5",
"validation"
],
"Title": "Validation and Form classes"
} | 16018 |
<p>I have a catalogue of activities that are marked based on the age group that they are relevant to. There are 14 checkboxes for checking what grades. K, 1 - 12, and Adult. I have a switch statement to change the K and Adult to a numeric representation.</p>
<p>The following PHP code grabs the grades checked and displ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-28T20:45:14.280",
"Id": "26053",
"Score": "1",
"body": "You could replace the switch statement with an lookup array. And instead of the for-loop, you can use an foreach-loop"
},
{
"ContentLicense": "CC BY-SA 3.0",
"Creation... | [
{
"body": "<p>If we are speaking about conversion of some numeric value to its text representation when some very limited number of numeric values has non-numeric text representation and vice versa, then the most efficient way will be:</p>\n\n<pre><code>$display = $i == 0? \"K\" : ($i == 13 ? \"Adult\" : $i);\n... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-28T20:33:29.220",
"Id": "16023",
"Score": "2",
"Tags": [
"php"
],
"Title": "Generating an array of school grades"
} | 16023 |
<p>I want to build a set of <a href="http://en.wikipedia.org/wiki/Builder_pattern" rel="nofollow">builders</a> for generating test data. On one side I want my builders API to be natural to use for my teammates. On the other side I'm great fun of creating <a href="http://en.wikipedia.org/wiki/Domain-specific_language" r... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-29T08:48:40.510",
"Id": "26069",
"Score": "0",
"body": "Is my question too loooong or title unclear? Any feedback is welcome."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-29T10:38:18.517",
"Id": "260... | [
{
"body": "<p>A few, rather subjective thoughts:</p>\n\n<p><strong>Decision #1:</strong></p>\n\n<p>Here you have a flight builder. Which group of sentences looks more natural from the following?</p>\n\n<ul>\n<li><em>a flight builder with origin</em></li>\n<li><em>a flight builder with destination</em></li>\n</u... | {
"AcceptedAnswerId": "16027",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-29T07:58:55.627",
"Id": "16025",
"Score": "2",
"Tags": [
"java",
"design-patterns"
],
"Title": "Is my DSL good idea to replace builder pattern?"
} | 16025 |
<p>My Haskell set/map/list folds often become terse and difficult to read. I'm looking for tips on how to make my functional code easier to follow.</p>
<p>I'm working around a bug/feature in a plotting library. I have a map from tags to lists of (time,count) which I plot as a stacked graph:</p>
<pre><code>import ... | [] | [
{
"body": "<p>I think you should keep <code>CountMap</code> as <code>Map String (Map UTCTime Int)</code>. That is a better way of keeping counts. If you do that then you can use <code>mysc</code> function directly. I find <code>mysc</code> much more readable and clear. </p>\n\n<pre><code>import Data.T... | {
"AcceptedAnswerId": "16029",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-29T09:03:51.540",
"Id": "16026",
"Score": "3",
"Tags": [
"haskell",
"datetime",
"functional-programming"
],
"Title": "Filling gaps in time series data"
} | 16026 |
<p>the following is my code for the Java class connection to mysql server, i need to see if there is any suggestion to make it better.</p>
<p>this class not making the connection, it just control transactions, selecting, updating & deleting.</p>
<pre><code>package database;
import java.sql.*;
import java.util.*;... | [] | [
{
"body": "<p>scanned your code, good to go, just one thing-- by Convention Java methods start with lower case. \nSo, the method \"<strong>UpdateDB()</strong>\" better suit <strong>updateDb()</strong> or <strong>updateDatabase()</strong></p>\n",
"comments": [],
"meta_data": {
"CommentCount": "0",
... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-29T10:18:56.280",
"Id": "16030",
"Score": "4",
"Tags": [
"java",
"mysql"
],
"Title": "MySQL Java Connection with my application"
} | 16030 |
<p>My goal was to create class, that can run external method in non blocking manner.
Second requirement was to be able to abort method run if it is needed (i.e. running user script).
I decided to do that with Thread instead of Task, because only Thread can be truly aborted.
Because Thread have big creation overhead, it... | [] | [
{
"body": "<p><a href=\"https://stackoverflow.com/a/1560567/41071\"><strong>You should never use <code>Thread.Abort()</code>.</strong></a> If you don't have control over the code that's executing in the thread, then you don't know what will that abort do. It's quite possible it will leave some object in an inco... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-29T17:55:40.130",
"Id": "16036",
"Score": "3",
"Tags": [
"c#",
"multithreading",
"delegates"
],
"Title": "Cancelable thread worker"
} | 16036 |
<p>In the book <em>Real World Haskell</em>, the author writes in the first line of every file that uses, for example the following: <code>file: ch05/PrettyJSON</code>. The chapter slash and the name of a module.</p>
<p>I wanted to create a script which reads the first line and copies the files to the appropriate direc... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-29T14:04:02.660",
"Id": "26085",
"Score": "0",
"body": "A few links for scripting shell tasks in Haskell: [Haskell shell examples](http://www.haskell.org/haskellwiki/Applications_and_libraries/Operating_system#Haskell_shell_examples), ... | [
{
"body": "<p>The first thing you note is that although haskellers like one character variable names in a small scope, we do not like one character functions in a global scope.</p>\n\n<p>There is an implicit partial function in your code. The function that gets the chapter name from the file (called <code>getCh... | {
"AcceptedAnswerId": "16040",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-29T08:26:35.393",
"Id": "16038",
"Score": "15",
"Tags": [
"python",
"haskell"
],
"Title": "Script for copying files to the appropriate directory"
} | 16038 |
<p>I wanted something more flexible than System.Collections.ObjectModel.ReadOnlyCollection.
The goal was: consuming classes should only see what I want to show them, not whole underlying collection.</p>
<p>For example: I have an array of 10 elements. If I want to show consumer only first 5 elements, I don't want to cr... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-30T04:35:02.577",
"Id": "26098",
"Score": "0",
"body": "I think it's a nice abstraction, but could you please add some usage cases?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-30T12:41:21.683",
"Id"... | [
{
"body": "<p>I don't see how would this be useful.</p>\n\n<p>If you want to return the first 5 items from a collection, use LINQ: <code>Take(5)</code>. This will return <code>IEnumerable</code>, but that's most likely okay.</p>\n\n<p>If you want to return reordered collection and don't want to modify the origi... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-29T22:30:56.387",
"Id": "16044",
"Score": "3",
"Tags": [
"c#",
"collections",
"generics"
],
"Title": "ReadOnlyCollection - my alternative to .NET one"
} | 16044 |
<p>I'm trying to write a function that finds the largest two numbers from a list of positive integers in Clojure.</p>
<p>I've toyed around with Scheme in the past, but I'm very new to Clojure. This is what I came up with:</p>
<pre><code>; Accumulator function for reduce later
(defn top-two [acc x]
(let [big1 (first... | [] | [
{
"body": "<p>This looks like a clean way to find the max two elements. It can be shortened a little bit with destructuring:</p>\n\n<pre><code>; Accumulator function for reduce later\n(defn top-two [[big1 big2 :as acc] x]\n (cond\n (> x big1) [x big1]\n (> x big2) [big1 x]\n :else acc))\n\n(defn... | {
"AcceptedAnswerId": "16053",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-30T01:14:04.123",
"Id": "16047",
"Score": "3",
"Tags": [
"clojure"
],
"Title": "Find largest two numbers from list using clojure"
} | 16047 |
<p>I have 2 input fields to input the duration of a CD song. The first input is for minutes and the second is for seconds</p>
<p>When submitting the form, I must insert in the db the duration either in seconds (minutes + seconds) or <code>NULL</code>.</p>
<p>Here's my validation formula:</p>
<pre><code>$warning = ar... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-30T06:40:09.883",
"Id": "26102",
"Score": "3",
"body": "`$warning` doesn't seem to be accessible outside of the function?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-30T15:14:07.727",
"Id": "26121",... | [
{
"body": "<ol>\n<li><p>I'm not familiar with PHP too much but <a href=\"https://stackoverflow.com/a/5166527/843804\">globals are usually considered harmful</a>. I don't know what's the best practice in PHP but passing the <code>$warning</code> argument by reference seems a good idea here.</p></li>\n<li><p>When... | {
"AcceptedAnswerId": "16062",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-30T05:18:13.930",
"Id": "16049",
"Score": "2",
"Tags": [
"php",
"datetime",
"converting"
],
"Title": "Converting minutes and seconds in seconds"
} | 16049 |
<p>I have a problem from UVA online judge <a href="http://uva.onlinejudge.org/external/104/10474.html" rel="nofollow">here</a>. I have read it tons of times, and as they said, I have to get the answer really fast. </p>
<p>I have used a binary search and <code>std::sort</code>, but I am still having a time error. I don... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-30T13:32:41.797",
"Id": "26119",
"Score": "0",
"body": "I know that in UVa OJ, your program should read from standard input and write to standard output. You are reading from \"in.txt\" so no input is provided to your program and it ha... | [
{
"body": "<p>Your solution is slow because it performs the sorting before every binary search! Just move the sorting to the line above the</p>\n\n<pre><code>printf(\"CASE# %d:\\n\",cont+1);\n</code></pre>\n\n<p>and you'll see the difference.</p>\n\n<p>I also add my solution just to see what's possible to optim... | {
"AcceptedAnswerId": "27722",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-30T07:55:34.413",
"Id": "16050",
"Score": "3",
"Tags": [
"c++",
"performance",
"search",
"binary-search",
"time-limit-exceeded"
],
"Title": "UVA 10474 - \"Where is the mar... | 16050 |
<p>So I'm writing a program to format names to title case and display them in alphabetic order. Any advice please? And how can i add more methods?</p>
<pre><code>public static void main (String [] args)
{
//local variables
string name1;
string name2;
myLib = new Library();
/**************... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-01T06:03:21.480",
"Id": "26139",
"Score": "1",
"body": "Could you post the `string` class too?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-16T05:32:08.747",
"Id": "108902",
"Score": "0",
"bo... | [
{
"body": "<p>Create a List</p>\n\n<pre><code>List<String> al = new ArrayList<String();\n</code></pre>\n\n<p>and add (you can also use something like <code>while(! stringRead.isEmpty()) {..}</code> )</p>\n\n<pre><code>name = Keyboard.readChar()).toLowerCase();\nal.add(name.substring(0, 1).toUpperCase()... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-30T21:06:27.590",
"Id": "16063",
"Score": "3",
"Tags": [
"java",
"homework",
"functional-programming"
],
"Title": "Format names to title case"
} | 16063 |
<p>There can be a business or security requirement that certain fields on a model should never be exposed in an API. One approach to this is to tell the developers not to ever put the field in the API output, but I prefer to protect them at the model level because that's where the requirement actually is.</p>
<p>The g... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-01T06:03:18.797",
"Id": "26138",
"Score": "0",
"body": "Some advice I've received so far: 1) Make it an include for ActiveModel instead of ActiveRecord::Base. 2) Follow the attr_accessible conventions for Blacklist / Whitelist rules. 3... | [
{
"body": "<p>With regard to (1): I suppose you could consider wrapping an entire model instance in an object that presents some methods itself (like a filtered <code>to_json</code>, or filtered <code>columns</code>), and forwards only allowed methods to the model on <code>method_missing</code>. Basically proxy... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-09-30T22:01:08.527",
"Id": "16064",
"Score": "3",
"Tags": [
"ruby",
"security",
"ruby-on-rails",
"api",
"active-record"
],
"Title": "Protecting certain model attributes from bei... | 16064 |
<p>Sometimes I need <code>toString()</code> to be quite verbose, normally I don't. It can't be nicely solved by using other methods as <code>toString()</code> is what gets shown in debugger (and also in the logs unless I call some method explicitly). As nobody should ever rely on its behavior, I wonder if the following... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-03T05:30:55.613",
"Id": "26235",
"Score": "0",
"body": "Just had another thought, are you concatenating using `+` or `StringBuilder`? It might make a difference if the verbosity is expensive and is constantly being created. But may not... | [
{
"body": "<p>Personally, I use <code>toDebugString()</code> to prevent misuse for others that may be using this class (or even myself down the line). It has clear intent/purpose (self documenting) without requiring extra thinking to read the javadoc.</p>\n\n<p>On related note, you may find this <a href=\"http:... | {
"AcceptedAnswerId": "31999",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-01T09:23:38.150",
"Id": "16071",
"Score": "5",
"Tags": [
"java",
"static"
],
"Title": "Configuring toString via a public static variable"
} | 16071 |
<p><img src="https://i.stack.imgur.com/qFMEj.png" alt="enter image description here"></p>
<p>The requirement is to be able to cache method invocations made on a boundary layer (Services layer). I'm using Unity to inject the concrete implementation of the Service layer classes. The intercepting <code>CacheCallHandler</... | [] | [
{
"body": "<p>Personally i believe that there is no need for the reactive framework in this scenario.\nTo handle the multithreaded nature of your problem i would first make sure that your RequestCache (Icache) uses the ConcurrentDictionary> and exposrts the <a href=\"http://msdn.microsoft.com/en-us/library/ee37... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-01T12:28:55.847",
"Id": "16075",
"Score": "11",
"Tags": [
"c#",
"optimization",
"cache",
"system.reactive"
],
"Title": "Improve Parallel Cache with Reactive Extensions & Unity In... | 16075 |
<p>I started learning java a few days ago. I prefer C++ but since I'll need java this college semester I decided to learn a few things to ease myself in. Anyway in C++ I always used a foolproof input method for taking user input of primitive numeric types. I picked that method up from <a href="http://latedev.wordpress.... | [] | [
{
"body": "<p>Among other things, you're relying on 'global' (class-level) variables <em>way</em> too much. This will cause you problems later, especially if you want to do any sort of multi-threaded programming. You also haven't separated your concerns as much as you probably should - actually doing so may h... | {
"AcceptedAnswerId": "16087",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-01T15:13:50.583",
"Id": "16076",
"Score": "2",
"Tags": [
"java"
],
"Title": "Java foolproof input class"
} | 16076 |
<p>Ok so this works as is, and is not actually slow at all (from what I can see) - However I don't like the taste of nested while loops and was wondering if anyone could give some insight on a different approach? Or how to improve mine to take away the <code>while() { while() {}}</code></p>
<p>Here it is: </p>
<pre><... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-01T22:44:36.983",
"Id": "26163",
"Score": "0",
"body": "What's the difference between `str.length` and `ctx.measureText(str)`?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-01T22:54:50.543",
"Id": "26... | [
{
"body": "<p>The first thing I notice is an excessive use of measureText, which I am inclined to assume is a relatively expensive operation. At a minimum, every word is measured twice - once to verify it fits within the maxWidth constraint, and once again to verify it fits on the current line. Of course, as t... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-01T18:33:13.580",
"Id": "16081",
"Score": "7",
"Tags": [
"javascript",
"canvas"
],
"Title": "Splitting text into lines from a max width value for CANVAS"
} | 16081 |
<p>I'm interested in discussing string literals in Objective-C and would like to know 1. if there's a preferred paradigm / style and 2. what (if any) the performance implications might be.</p>
<p>There are parts of the Cocoa / CocoaTouch frameworks that use strings as identifiers. Some examples in Cocoa / CocoaTouch..... | [] | [
{
"body": "<p>Actually, they are completely equal (obviously sans the <code>extern</code> keyword on the constant define). When literal strings are declared <code>@\"\"</code>, the compiler expands them out to a compile-time constant expression, which looks familiar to us all: <code>(static) NSString *const;</... | {
"AcceptedAnswerId": "17651",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-01T19:09:18.337",
"Id": "16082",
"Score": "3",
"Tags": [
"objective-c"
],
"Title": "#define or NSString * const - Benefits and drawbacks of string literal constant syntax?"
} | 16082 |
<p>I am wondering if the self invoking function as displayed below, mainly the part of using the same function twice <code>('foo')('bar')</code>, would ever be seen as a good practice?</p>
<p>And more important, is there a good reason to use this? Personally in this particular example I would rather go for multiple at... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-04T00:24:38.227",
"Id": "26330",
"Score": "1",
"body": "Note that in IE (up to and including version 8 I think) named function expresssions became global variables regardless of the scope in which they were created."
},
{
"Cont... | [
{
"body": "<p>Wow. Basically you wrote <code>Code A</code> but in a cool functional programming style.</p>\n\n<p>Code A:</p>\n\n<pre><code>(function(){\n function foobar(id) {\n var element = document.getElementById(id);\n element.style.color = 'red';\n element.style.textIndent = '10px';... | {
"AcceptedAnswerId": "16096",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-01T20:12:18.333",
"Id": "16084",
"Score": "7",
"Tags": [
"javascript"
],
"Title": "Any use for this kind of self invoking function?"
} | 16084 |
<p>I have an object, <code>WorkflowGridBuilder</code>, which is responsible for building a <code>jqGrid</code> object and decorating it appropriately based on the type of grid being built.</p>
<p>Here is my builder:</p>
<pre><code>var WorkflowGridBuilder;
$(WorkflowGridBuilder = function () {
'use strict';
... | [] | [
{
"body": "<p>You could try using the prototype design pattern.</p>\n\n<pre><code>function GridFactory(name, queueUrl, obj) {\n this.name = name;\n this.gridObj = obj;\n this.url = {\n queue : queueUrl\n };\n};\nGridFactory.prototype.setWidth = function(width){\n this.gridObj.setGridWidth(... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-01T21:06:21.410",
"Id": "16088",
"Score": "0",
"Tags": [
"javascript",
"jquery"
],
"Title": "Creating a jqGrid builder object"
} | 16088 |
<p>I need to generate a Ruby hash that looks like this:</p>
<pre><code>{ "children" => [
{ "children" => [
{ "children" => [
{ "children" => [] }
]}
]}
]}
</code></pre>
<p>... for an arbitrary level of nesting. So far the best I've come up with is:</p>
<pre><code>def nested_hash(levels... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-02T07:48:16.100",
"Id": "26174",
"Score": "0",
"body": "why do you need arrays with a single element?"
}
] | [
{
"body": "<p>Recursion perhaps?</p>\n\n<pre><code>def nested_hash(levels)\n return if levels <= 0\n { \"children\" => [ nested_hash(levels - 1) ].compact }\nend\n</code></pre>\n\n<p>Or it could be</p>\n\n<pre><code>def nested_hash(levels)\n return nil if levels <= 0\n array = nested_hash(levels - ... | {
"AcceptedAnswerId": "16091",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-01T23:09:22.470",
"Id": "16090",
"Score": "5",
"Tags": [
"ruby"
],
"Title": "Terser way of generating deeply nested hash"
} | 16090 |
<p>In getting accustomed to Clojure syntax, I wrote the following <code>stutter</code> function:</p>
<pre><code>(defn doublelist [coll]
(flatten (map (fn [x] [x x]) coll)))
(defn stutter [s]
(clojure.string/join
" " (doublelist (clojure.string/split s #" "))))
</code></pre>
<p>This duplicates every word in a... | [] | [
{
"body": "<p>You may use <code>mapcat</code> to omit <code>flatten</code>:</p>\n\n<pre><code>user> (defn doublelist [coll]\n (mapcat #(repeat 2 %) coll))\n#'user/doublelist\nuser> (doublelist [:a :b :c :d])\n(:a :a :b :b :c :c :d :d)\n</code></pre>\n",
"comments": [],
"meta_data": {
... | {
"AcceptedAnswerId": "16098",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-02T01:44:10.717",
"Id": "16094",
"Score": "2",
"Tags": [
"clojure"
],
"Title": "Idiomatic text munging in Clojure"
} | 16094 |
<p>I'm working alone on my code, trying to learn Ruby as I go.</p>
<p>Class <code>Robot</code> is supposed to be instantiated with the position on a map, and whether it is facing toward a side of the map. It has a couple of moves: left or right, where the face of the robot changes direction, and a move action, one ste... | [] | [
{
"body": "<p>Looks like you over-thought it a little bit. Callbacks are indeed a powerful abstraction, but it looks overkill in this case. Some notes:</p>\n\n<ul>\n<li>Use symbols to codify <code>@facing</code>: :east, :north, ...</li>\n<li><p>a hint to write <code>move</code> without callbacks:</p>\n\n<pre><c... | {
"AcceptedAnswerId": "16140",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-02T12:38:45.600",
"Id": "16107",
"Score": "1",
"Tags": [
"ruby",
"object-oriented"
],
"Title": "General review of Robot class"
} | 16107 |
<p>could you please review the code for the implementation of the class (link: <a href="https://codereview.stackexchange.com/questions/16107/ruby-code-review-working-alone-on-the-code">General review of Robot class</a>)</p>
<pre><code>require_relative 'robot'
class Game
def initialize
# initialize values
@c... | [] | [
{
"body": "<p>A couple of issues I found or suggestions I have:</p>\n\n<ul>\n<li>avoid unnecessary or redundant comments (like <code># initialize values</code> within <code>initialize</code>)</li>\n<li>use symbols for your commands and facings</li>\n<li>don't use upper case letters in your variable names (<code... | {
"AcceptedAnswerId": "17887",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-02T13:08:06.057",
"Id": "16109",
"Score": "2",
"Tags": [
"ruby",
"object-oriented"
],
"Title": "Needs code review for class implementation"
} | 16109 |
<p>I wrote the following code for a Dynamic Programming problem but the online judge gives me a 'Time Limit Exceeded' error. How can I optimize this code to make it more efficient, especially the part of initializing the DP array to 0.0 (I am using <code>memset()</code> right now)?</p>
<p>Problem:</p>
<ol>
<li>There... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-03T12:15:15.433",
"Id": "26269",
"Score": "0",
"body": "Is there a public url that you could point us to for information on the problem?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-03T13:39:51.543",
... | [
{
"body": "<p>It looks like the nested loops of your algorithm are using only three rows of the <code>dp</code> matrix:</p>\n\n<pre><code>dp[j]\ndp[j-1]\ndp[j-2]\n</code></pre>\n\n<p>You can use this observation to transform your solution from one requiring <code>O(N^2)</code> space to one requiring <code>O(N)<... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-02T13:50:49.517",
"Id": "16111",
"Score": "6",
"Tags": [
"c++",
"programming-challenge",
"time-limit-exceeded"
],
"Title": "Efficient implementation of a Dynamic Programming challeng... | 16111 |
<p>I was trying to figure out how to make a breakable foreach macro for STL containers and I came up with this method that uses templates to recognize the container type automatically. Are there any performance / code-wise improvements you can think of?</p>
<pre><code>// polymorphic break-able foreach test that works ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-02T15:11:11.290",
"Id": "26203",
"Score": "1",
"body": "Have you seen [boost's FOREACH](http://www.boost.org/doc/libs/1_51_0/doc/html/foreach.html)?"
}
] | [
{
"body": "<p>This line gives my nightmares:</p>\n\n<pre><code>std::unordered_map<void *, bool> _advance_iterator__instances_done;\n</code></pre>\n\n<p>First up the name is <a href=\"https://stackoverflow.com/questions/228783/what-are-the-rules-about-using-an-underscore-in-a-c-identifier/228797#228797\">r... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-02T14:23:29.227",
"Id": "16113",
"Score": "2",
"Tags": [
"c++",
"template",
"iterator"
],
"Title": "Polymorphic STL foreach without passing the container type"
} | 16113 |
<p>How can I simplify this jQuery code? I feel like I should be able to do this with one click function.</p>
<p><strong>jQuery</strong></p>
<pre><code>$('.btn').eq(0).click(function () { $('.carousel').css({ 'left': '0%' }); });
$('.btn').eq(1).click(function () { $('.carousel').css({ 'left': '-100%' }); });
$('.btn'... | [] | [
{
"body": "<p>You are correct, you can <a href=\"https://stackoverflow.com/q/1188760/352449\">have one function</a> binding <code>click</code> events to all of your <code>.btn</code> elements.</p>\n<p>Working <a href=\"http://jsfiddle.net/zuul/zxSD3/\" rel=\"nofollow noreferrer\">Fiddle Example</a>:</p>\n<pre><... | {
"AcceptedAnswerId": "16116",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-02T18:52:01.003",
"Id": "16115",
"Score": "1",
"Tags": [
"javascript",
"jquery",
"html"
],
"Title": "Simplify multiple jQuery click functions"
} | 16115 |
<p>I have two lists with ca. 4000 elements where each each element have two columns. These are being fed into a function. Besides the function they are being fed into, is it possible to speed it up somehow? At this rate, it will take ca. 6-7 days to complete.</p>
<pre><code>results=rep(0, length(as.numeric(unlist(coor... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-01T08:07:03.060",
"Id": "26214",
"Score": "0",
"body": "I suggest you describe the task that you are trying to accomplish so that we can help you rethink the design."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "... | [
{
"body": "<p>What you have here is a nested loop. Since the inner loop is executed 4000 times for each iteration of the outer loop, the total number of calls to point.in.polygon is 4000^2 so 16 million times. </p>\n\n<p>The problem lies in how often the method is called and there is usually no direct way of sp... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-01T07:51:08.563",
"Id": "16118",
"Score": "3",
"Tags": [
"performance",
"r"
],
"Title": "Speeding up for-loop over a list"
} | 16118 |
<p>I want to implement numbering scheme like Microsoft Word uses for numbering.
first one gets = A,next is B, next is C, .... then AA, then AB,....and so on.
as shown below</p>
<pre><code> A
B
C
.
.
AA
AB
AC
.
.
AAA
AAB
....
</code></pre>
<p>'=>' here means converted to.</p>
<p>some examples: ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-02T21:30:52.340",
"Id": "26227",
"Score": "1",
"body": "If you're using HTML then just place `ul` or `ol`."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-02T21:34:24.703",
"Id": "26228",
"Score": "... | [
{
"body": "<p>The function in the question converts to base 26, then splits the resulting string, and converts each digit back to decimal - and then to a letter. That seems roundabout.</p>\n\n<p>Here's a simpler one:</p>\n\n<pre><code>function convertToNumberingScheme(number) {\n var baseChar = (\"A\").charCod... | {
"AcceptedAnswerId": "16129",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-02T21:16:56.910",
"Id": "16124",
"Score": "10",
"Tags": [
"javascript",
"strings",
"array",
"number-systems"
],
"Title": "Implement numbering scheme like A,B,C... AA,AB,... AA... | 16124 |
<p>I quite like this extra credit assignment I did for Zed Shaw's Learn Python The Hard Way. Its a neat little text adventure game that uses stats. I would like to eventually expand this, but let me know how the code looks so far! </p>
<pre><code># Legend Of Doobieus
import random
from sys import exit
#rolls 3d6
d... | [] | [
{
"body": "<p>It's difficult to know what advice to give, since some of it is beyond what you've learnt so far (exercise 31?), but...</p>\n\n<p><strong>roll_3d6</strong> - there's no need for the sort or list. For the number of items you have, it could just be:</p>\n\n<pre><code>def roll_3d6():\n return rand... | {
"AcceptedAnswerId": "16146",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-02T21:21:14.380",
"Id": "16126",
"Score": "8",
"Tags": [
"python"
],
"Title": "LPTHW extra credit game"
} | 16126 |
<p>I have the following Ruby code in an RSpec file:</p>
<pre><code> describe "order" do
before do
LIST_LENGTH ||= 10
@skills = FactoryGirl.create_list(:skill, LIST_LENGTH)
@developer = FactoryGirl.create(:user)
@requests = FactoryGirl.create_list(:request, LIST_LENGTH)
LIST_LENGTH.ti... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-13T08:49:47.340",
"Id": "26826",
"Score": "2",
"body": "I'm unsure of what you're accomplishing with the first repeated bit; you call `Request.all.shuffle`, so yes, the resulting list should not be in order. Ruby's code has been tested... | [
{
"body": "<p>Some suggestions:</p>\n\n<ul>\n<li>There's no need for the negative assertion. You're testing Ruby more than you're testing your own code and in the end, we don't actually care. It only matters that our attempt to order the results behaves as expected. Assuming they're un-ordered otherwise (or at ... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-02T21:26:06.293",
"Id": "16127",
"Score": "3",
"Tags": [
"ruby",
"rspec"
],
"Title": "How might I make this code more DRY?"
} | 16127 |
<p>This method receives an array of data and does some stuff in a database. I need to get some reviews on it if possible.</p>
<pre><code>public function doSomeStuff($arr = array())
{
$id = $arr['Employee']['id'];
$name = $arr['Employee']['name'];
$status = $arr['Employee']['status'] == 'Disabled' ? 0 : 1;... | [] | [
{
"body": "<ul>\n<li>Instead of accessing the employee key every time, just pass in the array rooted at the Employee key</li>\n<li>What happens if all of the array indexes are not set? You should either check for that or use an object on which you know they all exist\n<ul>\n<li>Important mostly for data integr... | {
"AcceptedAnswerId": "16133",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-03T04:54:50.437",
"Id": "16132",
"Score": "3",
"Tags": [
"php",
"php5"
],
"Title": "Receive array of data and access employee info fields"
} | 16132 |
<p>Below is my implementation of a stack in <code>C</code>. Is it correct? And/or is there anything that I should fix to make it better in any way?</p>
<p><strong>stack.h</strong></p>
<pre><code>#ifndef STACK_H
#define STACK_H
#define EMPTY_STACK -1
typedef struct stack
{
char ch;
struct stack* prev;
} Stack;
e... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-03T23:04:54.283",
"Id": "26325",
"Score": "0",
"body": "Too lazy to retype a tailored response, but some of this might be useful: http://codereview.stackexchange.com/questions/15819/dynamic-array-written-in-c/15823#15823"
}
] | [
{
"body": "<p>I would advise you not implementing stacks with a linked list because for each <code>char</code> of info you consume <code>2 * sizeof(void*)</code> because of memory alignment in your struct. </p>\n\n<p>Because of this you won't be able to handle a big amount of data.</p>\n\n<p>What happens if yo... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-03T05:47:56.730",
"Id": "16134",
"Score": "6",
"Tags": [
"c",
"stack"
],
"Title": "implementation of a stack in C"
} | 16134 |
<p>I have this code that basically reads the DOM and sends the values to the server. I am looking for any possible flaws that I may have in this JavaScript code and any advice to make it better and bug-free!</p>
<pre><code>$(document).ready(function () {
$('.editButton').click(function () {
var postData = ... | [] | [
{
"body": "<ul>\n<li><p>You're creating a <em>lot</em> of jQuery objects in there. It would be much more efficient to just create them once. For example:</p>\n\n<pre><code>var postData = {},\n cData = {},\n $this = $(this),\n $parent = $this.parent(),\n $balance = $parent.children(\".balance\");\n</... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-03T05:58:47.317",
"Id": "16135",
"Score": "3",
"Tags": [
"javascript",
"jquery"
],
"Title": "Read DOM and send values to server"
} | 16135 |
<p>I'm a bit novice/moderate at JS. To my surprise I managed to put this together and it <em>does</em> work for what I intended. </p>
<p>The objective is to convert an object into a format that is more conducive to being used with a treegrid. I'm using the underscore library to grab object keys at various points.</p>
... | [] | [
{
"body": "<p>I believe this does the same as yours, except it uses <code>buildLeaf</code> on each step (your function skips it in the \"middle\" loop, and just makes an empty object).</p>\n\n<pre><code>// Recursive convertion function\nfunction convert(obj) {\n var item, leaf, key, leaves = [];\n for( key in... | {
"AcceptedAnswerId": "16169",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2012-10-03T06:04:27.480",
"Id": "16136",
"Score": "5",
"Tags": [
"javascript",
"performance"
],
"Title": "Converting an object to be used with a treegrid"
} | 16136 |
<p>I wrote a wrapper library for a REST API in Perl using the Moose library. I would like to gather some feedback on it (mainly on the OOP part since I am new to moose), before pushing it out.</p>
<p>Base class:</p>
<pre><code>has 'debug' => (is => 'rw', isa => 'Bool', default => 0);
has 'api_key' ... | [] | [
{
"body": "<p>In Net::Semantics3 _make_request I wasn't too sure about the error handling. It looks like _req_error_msg doesn't die if any part of the request process fails. Also 200 may not be the only valid HTTP status code, it's safer to use the is_success method</p>\n\n<pre><code>if ($resp->is_success) {... | {
"AcceptedAnswerId": "16172",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2012-10-03T07:44:43.613",
"Id": "16139",
"Score": "3",
"Tags": [
"api",
"perl",
"meta-programming",
"rest"
],
"Title": "Perl wrapper library (written using Moose) for a REST API"
} | 16139 |
<p>I'm creating some age-verification functionality for an iOS app. The user is presented with a <code>UIDatePicker</code> object, and the latest selectable date should be today minus 18 years. How vulnerable to inaccuracy is my code? How could it be leaner?</p>
<pre><code>-(void)validateAge {
NSDateComponents *t... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-26T13:21:40.377",
"Id": "28579",
"Score": "0",
"body": "Well, first of all, what about leap years ? If someone uses it on the 29th of february on a leap year, february 18 years earlier will always be 28 days long. I don't know what wil... | [
{
"body": "<p>Check this method. Pass value as minus 18 (-18)</p>\n\n<pre><code>-(NSDate *)offsetYear:(int)numOfYears date:(NSDate*)date {\n NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];\n NSDateComponents *offsetComponents = [[NSDateComponents alloc] init];\n... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-03T10:12:49.687",
"Id": "16145",
"Score": "4",
"Tags": [
"objective-c",
"ios"
],
"Title": "Age verification in Objective-C"
} | 16145 |
<p>I know about the "little bobby tables" scenario and was just wondering if this code is vulnerable to such SQL injections.</p>
<p><sup>I am fairly new to PHP and am curious about this.</sup></p>
<p><strong>My code for a login script:</strong></p>
<pre><code><?php
# session
session_start();
# get the vari... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-02T09:55:22.513",
"Id": "26246",
"Score": "0",
"body": "the single quotes around the sql are not used, theyre only there for the purpose of this question"
}
] | [
{
"body": "<p>This is vulnerable:</p>\n\n<pre><code>mysql_real_escape_string($userid);\nmysql_real_escape_string($pword);\n</code></pre>\n\n<p>does not return the variable. Use:</p>\n\n<pre><code>$userid = mysql_real_escape_string($userid);\n$pword = mysql_real_escape_string($pword);\n</code></pre>\n\n<p>If you... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-02T09:54:10.483",
"Id": "16147",
"Score": "1",
"Tags": [
"php",
"mysql",
"security"
],
"Title": "How can I ascertain and test SQL injection vunerabilities on this login code?"
} | 16147 |
<p>My app saves data to a file - I obviously don't want the app to write to the file from multiple locations on disk. What I want is a generic "utility" class that will know how to run a piece of code (let's call it SingletonTask) with the following rules:</p>
<ol>
<li>Only one SingletonTask will run at any given mome... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-18T13:58:34.260",
"Id": "28120",
"Score": "0",
"body": "Found anything neater?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-18T14:13:02.977",
"Id": "28124",
"Score": "0",
"body": "Updated. I ... | [
{
"body": "<p>I made something like this before but I don't claim that it's better.<br>\nAlthough it's much simpler:</p>\n\n<pre><code>public sealed class SingleTask\n{\n private Task _Task;\n private readonly object _Lock = new object();\n\n // You can overload this with TaskCreationOptions, TaskSched... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-03T08:45:23.970",
"Id": "16150",
"Score": "5",
"Tags": [
"c#",
"asynchronous"
],
"Title": "\"Singleton\" task running - using Tasks/await - peer review/challenge"
} | 16150 |
<p>I have got such 2d jagged array (row is 1st dimension, column is 2nd dimension, bottom to up, left to right)</p>
<pre><code>0 0 b b b c
0 0 h g g c
0 0 h a a c
0 0 f f d d
0 0 i j e e
0 0 i j 0 0
</code></pre>
<p>I would like to get a 2d jagged array summ... | [] | [
{
"body": "<p>First of all get rid of these tuples. After one week you will forget what each int represents. Define simple struct/class for your brick.</p>\n\n<p>Second thing, small performance suggestion for big row count - explicit initial list size:</p>\n\n<pre><code>... = new List<Tuple<char, int, int... | {
"AcceptedAnswerId": "16171",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-03T12:49:21.283",
"Id": "16153",
"Score": "4",
"Tags": [
"c#",
"f#"
],
"Title": "How to refactor this groupby alike method but with index?"
} | 16153 |
<p>I posted <a href="https://stackoverflow.com/a/12679544/1075247">this</a> an answer this to a question about drawing a random line from a file too large to put into memory. I hacked the below code together. In essence, this is what Reservoir Sampling does, in pseudo-code:</p>
<pre><code>Scan over the 'tape'
Put t... | [] | [
{
"body": "<p>At the first glance </p>\n\n<p>You can use <code>Scanner.netxLine()</code> available on all OS.</p>\n\n<pre><code>(randomNumber = (int) ra.nextInt(count))<reservoirSize \n</code></pre>\n\n<p><em>EDIT suppressed unnecessary lines after comments</em></p>\n",
"comments": [
{
"Co... | {
"AcceptedAnswerId": "42838",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-03T13:00:57.810",
"Id": "16154",
"Score": "10",
"Tags": [
"java",
"random"
],
"Title": "Is this code an efficient implementation of Reservoir Sampling?"
} | 16154 |
<p>If you notice, there are variables of <code>street_address</code>, <code>route</code>, <code>intersection</code> re-used in the entire code base. They are actually from Google Maps geocoder address components.</p>
<p>How can I refactor this one so that I don't have to declare them one by one?</p>
<p>Note that in t... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-03T15:54:15.763",
"Id": "26275",
"Score": "1",
"body": "I was about to write up an answer, but then I noticed that inside the `$.map(results, ...` you're declaring these variables `var get_street_address, get_route, get_intersection;` ... | [
{
"body": "<p>You could refactor this using a few arrays to avoid as much typing, but I think readability is paramount, and I don't see many ways for it to be more readable than what you have submitted.</p>\n\n<p>You could try using filter instead, but it will be over 3 times slower (most of the time this won't... | {
"AcceptedAnswerId": "16182",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-03T15:37:42.097",
"Id": "16156",
"Score": "2",
"Tags": [
"javascript",
"jquery",
"geospatial",
"google-maps"
],
"Title": "Address geocoder"
} | 16156 |
<p>I was just trying to make an alternate Ajax watermark from "insert date" (first mode) to "mm/dd/yyyy" (second mode). After some trial and error, I successfully implemented a solution using JavaScript.</p>
<p>How can I improve this script functionality?</p>
<p><strong>JavaScript:</strong></p>
<pre><code>var origin... | [] | [
{
"body": "<p>I think you're trying to create a simple placeholder.</p>\n\n<p>A placeholder adds default text to an emtpy input field.</p>\n\n<p>The <a href=\"http://www.w3schools.com/html5/att_input_placeholder.asp\" rel=\"nofollow\">placeholder</a> attribute is introduced in HTML 5.</p>\n\n<h2>Example 1: (<a ... | {
"AcceptedAnswerId": "16292",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-03T16:07:09.687",
"Id": "16159",
"Score": "3",
"Tags": [
"javascript",
"performance",
"datetime",
"asp.net",
"ajax"
],
"Title": "Dual-mode JavaScript textbox watermark"
} | 16159 |
<p>I am calculating discounts based on a quantity after 6. </p>
<p>Is there a cleaner way to do this:</p>
<pre><code>$leg_directory_discount = array(
6 => .50,
7 => .50,
8 => .50,
9 => .50,
10 => .50,
11 => 1,
12 => 1,
13 => 1,
14 => ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-03T15:59:58.853",
"Id": "26281",
"Score": "3",
"body": "What have tried? Can you add more details?"
}
] | [
{
"body": "<p>Some simple logic will save you from all that (error-prone) writing. For instance:</p>\n\n<pre><code>if ($qty >= 6)\n{\n if ($qty >= 21)\n $leg_directory_discount = 1.5;\n elseif ($qty >=11)\n $leg_directory_discount = 1.0;\n else\n $leg_directory_discount = ... | {
"AcceptedAnswerId": "16162",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-03T15:58:45.380",
"Id": "16161",
"Score": "0",
"Tags": [
"php"
],
"Title": "Building array keys using a span of numbers for like values"
} | 16161 |
<p><strong>The Problem</strong></p>
<p>I have a cursor that I am trying to replace (perhaps unnecessarily) in an attempt to clean up a stored procedure. Essentially what it is doing is counting each note for each member in a temp table and then assigning each of those notes a sequential value into the field <code>NOTE... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-03T19:22:22.833",
"Id": "26304",
"Score": "0",
"body": "Is it possible for there to be multiple records keyed by MEMBER_UPI, CASE_SEQ, DIFF_ENCOUNTER_DATE? Just making sure I understand the requirements correctly. So, you would like to... | [
{
"body": "<p>So, you can simplify the CTE with some SQL magic:</p>\n\n<pre><code>WITH RecordsBeingUpdated AS \n( \n SELECT \n NOTE_COUNTER,\n MEMBER_UPI, \n CASE_SEQ, \n DIFF_ENCOUNTER_DATE, \n ROW_NUMBER() OVER (PARTITION BY MEMBER_UPI, CASE_SEQ ORDER BY DIFF_ENCOUNTER_DA... | {
"AcceptedAnswerId": "16170",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-03T17:06:42.820",
"Id": "16166",
"Score": "3",
"Tags": [
"sql",
"sql-server",
"t-sql"
],
"Title": "Is it necessary to replace this cursor in SQL Server 2005?"
} | 16166 |
<p>I need to calculate checksum using 16-bit ones' complement addition:</p>
<pre><code>while(byte>0) //len = Total num of bytes
{
Word = ((Buf[i]<<8) + Buf[i+1]) + Checksum; //get two bytes at a time and add previous calculated checsum value
Checksum = Word & 0x0FFFF; //Discard the carry if any... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2019-04-11T12:05:06.537",
"Id": "420238",
"Score": "1",
"body": "What are the types of `Word`, `Checksum` and `Buf`? It looks like `Word` must be a `uint32_t`, `Checksum` a `uint16_t` and `Buf` a `uint8_t*`, buf the information really ought... | [
{
"body": "<p>If the packet size is less than 32k words, then you do not need to add the carry until the end:</p>\n\n<pre><code>while(byte>0) //len = Total num of bytes\n{\n Checksum = ((Buf[i]<<8) + Buf[i+1]) + Checksum; //get two bytes at a time and add previous calculated checsum value\n\n l... | {
"AcceptedAnswerId": "16168",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-03T17:45:18.277",
"Id": "16167",
"Score": "5",
"Tags": [
"c",
"bitwise"
],
"Title": "16 bit checksum calculation"
} | 16167 |
<pre><code>/* Infinite Scroll Pagination with a Wookmark layout
*
* Requires: jQuery, Wookmark
*/
var myApp = myApp || {};
;(function(myApp,$){
var WookmarkPagination = function(elem, options){
this.elem = elem;
this.$elem = $(elem);
this.options = options;
};
WookmarkPagination.prototype = {
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-10T14:48:38.050",
"Id": "26688",
"Score": "0",
"body": "What is a Wookmark layout?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-08T12:04:38.417",
"Id": "29227",
"Score": "0",
"body": "Looks o... | [
{
"body": "<p>The code looks pretty good, but here are a couple suggestions:</p>\n\n<ul>\n<li>The semicolon at the top is unnecessary: <code>;(function(myApp,$){</code></li>\n<li>You use <code>_this</code> in many places where <code>this</code> would work:\n<ul>\n<li>Consider Function.bind (<a href=\"https://de... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-04T03:28:28.383",
"Id": "16183",
"Score": "8",
"Tags": [
"javascript",
"jquery",
"pagination"
],
"Title": "Infinite scroll pagination with a Wookmark layout"
} | 16183 |
<p>First off I would like to state that this is a homework assignment. However, I am not looking for you to complete anything for me. I code I am posting is the completed homework assignment. However, since this is my first time using C++ I was curious if there might have been a better method to accomplish the same tas... | [] | [
{
"body": "<p>You've done it well bro. Just a little comment:</p>\n\n<p>+) please remove the semi-colon </p>\n\n<pre><code>#include<cmath>;\n</code></pre>\n\n<p>+) put all <code>#include</code> stuff at the start of program before importing anything from namespace.</p>\n\n<p>+) <code>int main()</code> ... | {
"AcceptedAnswerId": "16187",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-04T05:43:29.843",
"Id": "16185",
"Score": "11",
"Tags": [
"c++",
"homework"
],
"Title": "Simple C++ function to determine the circumference and area of a circle"
} | 16185 |
<p>I wrote a C# tool that make a recursive search. I need the file size and the size on disc. I am using a function that give me the size on disc but it is very slow.</p>
<p>Is there any other way to do it except the following code?</p>
<pre><code>public void RecursiveSearch(string path)
{
try
{
forea... | [] | [
{
"body": "<p>One aside to mention: you should split your UI and business logic code. For the sake of tossing it into a working example quickly (I'm doing this over lunch), I removed all the UI code and replaced any print-outs with <code>Console.WriteLine</code> calls.</p>\n\n<p>I also did a little refactoring... | {
"AcceptedAnswerId": "16208",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-04T11:45:11.510",
"Id": "16195",
"Score": "6",
"Tags": [
"c#"
],
"Title": "Getting the size on disc"
} | 16195 |
<p>How to write following if condition clean/fast/readable.
Any one of the fields <code>'address', 'city', 'district', 'province'</code> can be null. I want to make full address by concat all these fields. Like </p>
<pre><code>address = "Street # 32"
city = "My City"
District = "New York"
Province = "NY"
fullAddress ... | [] | [
{
"body": "<p>I'd suggest to create a method like:</p>\n\n<pre><code>public static string CreateAddressFrom(Dictionary dr)\n{\n var addressDetails = new List<string>{\"Address\",\"City\",\"District\",\"Province\"};\n var fullAddress = string.Empty;\n\n foreach (var addressDetail in addressDetails)\n... | {
"AcceptedAnswerId": "16198",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-04T11:45:12.810",
"Id": "16196",
"Score": "1",
"Tags": [
"c#"
],
"Title": "Write it better/neat/fast (if condition)"
} | 16196 |
<p>The bellow functions are used to generate a string with random characters, and they have a parameter to specify the string length.</p>
<p>The string can be composed of letters, numbers or a conjunction of both.</p>
<p>I've been using this for a very long time now, and currently, I look at it and it seems to damn ext... | [] | [
{
"body": "<p>First: I'm sure there's even simpler way than this (i.e. a library that just does what you need, period), but heck, I figured I'd try. Been years since I spent my days with PHP (don't particularly miss it).</p>\n\n<p>Anyway, skip the whole <code>switch</code> lookup. <strike><code>chr()</code> wil... | {
"AcceptedAnswerId": "16204",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-04T12:55:01.410",
"Id": "16199",
"Score": "0",
"Tags": [
"php"
],
"Title": "Refactoring functions that generate string with random letters, numbers or mixed chars?"
} | 16199 |
<p>I have three input boxes that are all linked to each other by some pretty basic rules:</p>
<p><ul>
<li><strong>Editing the page title will copy the contents to menu title</strong>
<ul>
<li>Unless menu title has been manually edited</li>
<li>clearing menu title sets it back to automatic</li>
</ul>
</li>
<li>... | [] | [
{
"body": "<p>It's not so horrible. You managed to cache your jQuery selectors, which is more than a lot of people can say. Good job there.</p>\n\n<hr>\n\n<p><code>automatic</code> and <code>pager</code> are not super great names in this context. I suggest renaming them to <code>autoSlug</code>/<code>autoMenu</... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-04T15:00:01.213",
"Id": "16202",
"Score": "3",
"Tags": [
"javascript",
"jquery",
"optimization"
],
"Title": "Tidying up jquery code for linking inputs"
} | 16202 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.