body stringlengths 25 86.7k | comments list | answers list | meta_data dict | question_id stringlengths 1 6 |
|---|---|---|---|---|
<p>A particular application may refer to a specific property in one of three languages in different contexts: in lowercase English, in uppercase English, and in Hebrew. To facilitate ease of converting one language to another, this monstrosity exists:</p>
<pre><code>public string translatePersonType(string personType,... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-13T20:44:27.950",
"Id": "15925",
"Score": "0",
"body": "Per @Carl Manaster s answer: using a table is simpler in this case than using a switch or a dictionary. Table is more natural. The details are up to you - you can store this mappi... | [
{
"body": "<p>OK, this is Java and might take a little tickling to work in C#, but:</p>\n\n<pre><code>final String[] employee = {\"employee\", \"EMPLOYEE\", \"ืขืืื\"};\nfinal String[] contractor = {\"contractor\", \"CONTRACTOR\", \"ืงืืื\"};\nfinal String[] supplier = {\"supplier\", \"SUPPLIER\", \"ืกืคืง\"};\nfina... | {
"AcceptedAnswerId": "9936",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-12T17:43:18.390",
"Id": "9934",
"Score": "7",
"Tags": [
"c#"
],
"Title": "Refactor embedded switch"
} | 9934 |
<p>I've made a solution for <a href="http://acm.timus.ru/problem.aspx?space=1&num=1292&locale=en" rel="nofollow noreferrer">this problem</a>:</p>
<blockquote>
<p><strong>Task:</strong></p>
<p>Write a program for calculation of the distance to the next space station.</p>
<p><strong>Algorithm:</stron... | [] | [
{
"body": "<p>Here are a few tips:</p>\n\n<ul>\n<li><p>Instead of getting each character, creating a new string from it, and then parse the string into a number, just get the character and convert the character code into the number.</p></li>\n<li><p>Alternatively, parse the whole number once, then get the digit... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-12T20:40:44.390",
"Id": "9942",
"Score": "4",
"Tags": [
"c#",
"algorithm",
"performance",
"programming-challenge"
],
"Title": "Calculation of the distance to the next space stati... | 9942 |
<p>This takes in a user specified number of points then finds the two points with the shortest distance.</p>
<pre><code>import java.util.Scanner;
import java.lang.Math;
public class FindNearestPoints
{
public static void main(String[] args)
{
Scanner scan = new Scanner(System.in);
System.out.... | [] | [
{
"body": "<p>For starters, this code should use a Point class, consisting of an x and y location. Your variable points would then be Point[] rather than a two dimensional array. The Point class should have a method for reading values, printing values and calculating the distance between two points.</p>\n\n<p>T... | {
"AcceptedAnswerId": "9945",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-12T20:44:14.767",
"Id": "9943",
"Score": "9",
"Tags": [
"java",
"homework",
"computational-geometry",
"clustering"
],
"Title": "Finding points with the shortest distance"
} | 9943 |
<p><strong><em>Problem:</em></strong> <em>Find the intersection of two Object arrays without creating any new classes (no anonymous classes either) and without using any native Java classes in the solution (so no ArrayList implementations etc., but Object can be used)</em></p>
<p>My solution:</p>
<pre><code>public O... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-12T23:33:24.710",
"Id": "15835",
"Score": "2",
"body": "Except for renaming the parameters of contains(), this looks OK to me. I would also simply \"return true\" from inside the loop and \"return false\" after the loop completes, ins... | [
{
"body": "<p>If you want to optimize you can : Use arrayCopy() from the System Class to create the final array and reduce variable. Here is my \"solution\" : </p>\n\n<pre><code>public static Object[] handleArrayIntersection(Object[] array1, Object[] array2) {\n Object[] dest;\n\n int itemCount = 0;\n ... | {
"AcceptedAnswerId": "9953",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-12T23:04:23.313",
"Id": "9948",
"Score": "3",
"Tags": [
"java",
"optimization"
],
"Title": "Intersection of Array Question, limited only to methods"
} | 9948 |
<p>I have written a game engine for the game <a href="http://en.wikipedia.org/wiki/Reversi" rel="nofollow">Reversi, also called Othello</a>. The game engine works not exactly like the official rules. For example it is possible to place "holes" on the board, places which can never hold a stone.</p>
<p>The game engine w... | [] | [
{
"body": "<ul>\n<li><strong>Handling of errors</strong> is done via <em>monads</em>, but you don't need to understand monads in their full glory to know how to <a href=\"http://book.realworldhaskell.org/read/error-handling.html\" rel=\"nofollow\">handle errors gracefully in Haskell</a>. Oh, and <a href=\"http:... | {
"AcceptedAnswerId": "9958",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-12T23:57:25.460",
"Id": "9950",
"Score": "4",
"Tags": [
"haskell"
],
"Title": "Reversi (Othello) game engine + command line interface"
} | 9950 |
<p>I'm currently working with TornadoWeb but appear to have picked up a lot of bad habbits. I'd appreciate some feedback on the code below: </p>
<pre><code>import tornado.ioloop
import tornado.web
import tornado.template
#modules
import auth
import base
import tag
#pymongo
import pymongo
connection = pymongo.Connect... | [] | [
{
"body": "<pre><code>import tornado.ioloop\nimport tornado.web\nimport tornado.template\n\n#modules\n</code></pre>\n\n<p>This comment doesn't say much, its fairly clear that anything starting with <code>import</code> is a module. It would be better to say something about why these three modules are grouped - e... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-13T07:31:09.237",
"Id": "9952",
"Score": "2",
"Tags": [
"python"
],
"Title": "TornadoWeb Python"
} | 9952 |
<p>I was just looking at a standard scaffolded Rails controller spec, and tried to get it to use subject or let blocks, and failed miserably ... can subject or let tidy controller specs the same as it would a model spec?</p>
<pre><code>require 'spec_helper'
describe ProjectsController do
def valid_attributes
{... | [] | [
{
"body": "<p>Check <a href=\"https://codereview.stackexchange.com/a/695/12102\">the answer from Pavel Druzyak for a different question</a>. It answers your question as well. </p>\n\n<p>Your code can be refactored to this;</p>\n\n<pre><code>describe ProjectsController do\n let(:project) { Project.create! }\n... | {
"AcceptedAnswerId": "10300",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-13T09:25:04.150",
"Id": "9954",
"Score": "2",
"Tags": [
"ruby",
"ruby-on-rails",
"rspec"
],
"Title": "Tidying scaffolded Rails controller spec with subject/let"
} | 9954 |
<p>I'm creating my first login process in CodeIgniter. I'm using the simpleloginsecure library for actual session management but I wrote the controller and model myself and I was hoping if you could see any flaws in it.</p>
<p>My User_model Class</p>
<pre><code><?php if ( ! defined('BASEPATH')) exit('No direct scr... | [] | [
{
"body": "<ol>\n<li>Simply use <code>return $this->simpleloginsecure->login($email, $password)</code> in the login method.</li>\n<li><code>redirect('/user/xxx')</code> is enough, since <code>location</code> is the default redirect type.</li>\n<li>Since you're doing a <code>redirect()</code>, <code>$data[... | {
"AcceptedAnswerId": "9967",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-13T12:59:03.427",
"Id": "9966",
"Score": "3",
"Tags": [
"php",
"security",
"codeigniter"
],
"Title": "Is this good login process in CodeIgniter?"
} | 9966 |
Microsoft Windows Azure Platform is a Microsoft cloud computing platform used to build, host and scale web applications through Microsoft data centers. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-13T13:39:57.620",
"Id": "9969",
"Score": "0",
"Tags": null,
"Title": null
} | 9969 |
The Actor model is a mathematical model of concurrent computation that treats "actors" as the universal primitives of concurrent digital computation: in response to a message that it receives, an actor can make local decisions, create more actors, send more messages, and determine how to respond to the next message rec... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-13T13:40:40.943",
"Id": "9971",
"Score": "0",
"Tags": null,
"Title": null
} | 9971 |
<p>I was working on a syllable counting function for a text editor(this function is accurate enough). However, I would like to know if it is possible to optimize it, it already separated into another thread, but I would like to know if there is any kind of optimization that I can do with it to make it more efficient.</... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-12T17:13:52.560",
"Id": "15882",
"Score": "1",
"body": "Is it currently too slow? It sounds like youve just heard that it might be slow. There's no need to optimize it until you've figured out if it's actually too slow."
},
{
"... | [
{
"body": "<p>If you're worried about regexp being slow, you could try a simple Split(): </p>\n\n<pre><code>int count = word.Split(new char[] { 'a','e','i','o','u','y' }, \n StringSplitOptions.RemoveEmptyEntries).Length ; \n</code></pre>\n\n<p>It would be easy to benchmark the difference. ... | {
"AcceptedAnswerId": "9974",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-12T17:10:02.880",
"Id": "9972",
"Score": "2",
"Tags": [
"c#",
"performance",
".net"
],
"Title": "Syllable-counting function"
} | 9972 |
<p>i am testing an application that i wrote and want to test the solution my algorithm produces to a Monte carlo solution. I use the harddisk a lot and i was wondering if there was a solution that uses writing data to a file a lot less, since it is really slowing the process down.</p>
<p>The solutions are computed on ... | [] | [
{
"body": "<p>You don't need to store in files between each command. Instead, just redirect the output:</p>\n\n<pre><code>$script/std_dev.sh < <(grep \"Overlapscore:\" $file.monte | awk '/./{print $2}') > $file.out\n</code></pre>\n\n<p>The Bash Guide has an <a href=\"http://mywiki.wooledge.org/BashGuid... | {
"AcceptedAnswerId": "9983",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-13T14:42:24.380",
"Id": "9977",
"Score": "1",
"Tags": [
"optimization",
"bash"
],
"Title": "optimizing a bash script chain - speed suggestions?"
} | 9977 |
<p>I use Ruby 1.8.7. I have a method which selects records according to the item that I pass to the method.</p>
<p>In my opinion, the code is not DRY. Could somebody offer suggestions on refactoring it to make it shorter?</p>
<pre><code>def get_record (id,item)
case item
when "category"
@temp = Category.... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-13T13:58:37.980",
"Id": "15898",
"Score": "0",
"body": "I'd say the code is a sample of bad programming, but I fail to see the relation with DRY principles."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-1... | [
{
"body": "<p>You want to use <code>classify</code> and <code>constantize</code>:</p>\n\n<pre><code>require 'set'\nAUTHORIZED = Set[Product, Status, Industry]\ndef get_record(id, item)\n model = item.classify.constantize\n raise \"Go away, hacker\" unless AUTHORIZED.include? model\n model.find(id).name\nend\... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-13T13:53:15.487",
"Id": "9978",
"Score": "3",
"Tags": [
"ruby"
],
"Title": "Selecting records according to an item"
} | 9978 |
<p>All I want do to is simply get the result of how long (in seconds) the PHP takes to process the SQL query. Am I on a right track? Is my code correct to get the result I want?</p>
<pre><code><?php
$con = mysql_connect("localhost","root","");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_... | [] | [
{
"body": "<ol>\n<li>Yes, microtime is designed to be used for this. The PHP documentation mentions this <a href=\"http://www.php.net/manual/en/function.microtime.php\" rel=\"nofollow\">use case for <code>microtime()</code></a>.</li>\n<li>Consider putting this into a loop and print out the average result: if th... | {
"AcceptedAnswerId": "9986",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-13T15:15:00.403",
"Id": "9985",
"Score": "2",
"Tags": [
"php",
"mysql"
],
"Title": "Calculating SQL query processing"
} | 9985 |
<p>i have 3 method which do almost the same thing,they different models to achieve the same goal.I did small refactoring but its still not looks like
ruby,can we improve it?
Thanks in advance. </p>
<p>after: </p>
<pre><code>def get_list(id,list_name,attribute_id,attribute,locale_string)
map={ "resent... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-19T06:06:54.623",
"Id": "16151",
"Score": "1",
"body": "1. please re-format your code. 2. please provide test code."
}
] | [
{
"body": "<pre><code>def get_payact_list(id) \n ## Dont use class instance variables ( prefixed with @ ) for method scoped variables\n @temp=\"\" # temp = \"\"\n ## In this case, you dont need the temporary variable, but lets keep it, but turn it into an array.\n # temp = [] \n\n ## No need for the temp ... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-13T16:44:42.807",
"Id": "9987",
"Score": "1",
"Tags": [
"ruby"
],
"Title": "refactor ruby method"
} | 9987 |
<p>My problem is the following: I wrote a method, which counts words and returns a hash. There is a Ruby idiom which was found by me in some of the forums discussions, which I don't understand.</p>
<p>Here is the whole code:</p>
<pre><code>text = "bla bla blahh blahh"
def count_words(string)
inp = string.downcase.s... | [] | [
{
"body": "<ol>\n<li><p>It is about <code>inject</code> initial value when you give <code>Hash.new(0)</code>\nand call <code>c[w] += 1</code> in block it is expanded to <code>c[w] = c[w] + 1</code> as we said\nto <code>Hash</code> initializer if it has no key then key will set to <code>0</code> when\nfirst appe... | {
"AcceptedAnswerId": "9992",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-13T19:29:15.850",
"Id": "9991",
"Score": "1",
"Tags": [
"ruby",
"strings"
],
"Title": "Words counter with a hash"
} | 9991 |
<p>From the Factor wiki:</p>
<blockquote>
<p>Factor is an experiment to build a modern, useful concatenative language with strong abstraction capabilities and good support for interactive development </p>
</blockquote>
<p>To get started, the Factor compiler can be found at <a href="http://factorcode.org/" rel="nofo... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-13T21:33:57.760",
"Id": "9996",
"Score": "0",
"Tags": null,
"Title": null
} | 9996 |
Factor is a concatenative programming language that is influenced by Forth, Joy and Lisp. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-13T21:33:57.760",
"Id": "9997",
"Score": "0",
"Tags": null,
"Title": null
} | 9997 |
<p>I wrote a string escaping function in C, and I'm trying to rewrite it to Haskell. The C version, along with comments explaining why it does what it does, <a href="https://github.com/joeyadams/haskell-libpq/blob/copy-from/cbits/escape-copy.c#L39" rel="nofollow">can be found on GitHub</a>.</p>
<p>Here's a naรฏve impl... | [] | [
{
"body": "<p>Whew, this is quite a tricky one. The main problem here is that you really, really need to keep Haskell from allocating anything in the relatively spacious inner loop. Otherwise, you are looking at a dozen bytes going through the garbage collector for every byte you escape.</p>\n\n<p>As you note, ... | {
"AcceptedAnswerId": "10079",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-13T21:50:29.333",
"Id": "9998",
"Score": "5",
"Tags": [
"optimization",
"strings",
"haskell"
],
"Title": "Optimizing ByteString escaping"
} | 9998 |
<p>I'm writing a simple text-based RPG in Java. I think it's a good exercise to practice OO and think about how objects should best interact. I'd be interested in hearing any thoughts!</p>
<p>The <code>Game</code> class contains a single game:</p>
<pre><code>public final class Game {
private final Player player... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-13T22:20:52.027",
"Id": "15931",
"Score": "4",
"body": "You shouldn't be using `System.out.println()` directly - in fact, your back-end classes should have _absolutely no clue_ that it's a text based system. Interestingly, doing so ma... | [
{
"body": "<p><strong>IO:</strong> You use everywhere <code>System.out.println</code> and <code>System.in</code> (BTW, <code>Scanner</code> is much more convenient than a <code>Reader</code>). Even if you want to switch from console output to a simple Swing application with little more than a text area, you hav... | {
"AcceptedAnswerId": "10002",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-13T21:56:48.090",
"Id": "9999",
"Score": "15",
"Tags": [
"java",
"object-oriented",
"role-playing-game"
],
"Title": "Text-based RPG in Java"
} | 9999 |
<p>I am working on a web mapping library, that makes it possible to create a map with SVG and JavaScript. As every map shall consist of SVG and Image elements, which can be grouped in layers, which in turn can be set invisible, I need an API to reflect this functionality. I started with two classes/prototypes:</p>
<pr... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-21T18:39:19.430",
"Id": "73055",
"Score": "0",
"body": "This question appears to be off-topic because it is a design review and not a code review."
}
] | [
{
"body": "<p>Since namespaces are always optional, you can follow the common JavaScript convention and put them at the end of the arguments list:</p>\n\n<pre><code>Map()\n.add(object, namespace1)\n.remove(namespace1)\n.on(events, handler, namespace2)\n.off(events)\n.on(otherEvents, handler)\n</code></pre>\n\n<... | {
"AcceptedAnswerId": "10010",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-13T22:47:46.290",
"Id": "10001",
"Score": "6",
"Tags": [
"javascript",
"api"
],
"Title": "Registering layers in a web mapping library. API design"
} | 10001 |
<p>Trying to implement something like <a href="http://msdn.microsoft.com/en-us/library/windows/desktop/bb776391%28v=vs.85%29.aspx" rel="nofollow">CommandLineToArgV</a>:</p>
<pre><code>template<typename InIter, typename OutIter>
inline InIter CmdLineToArgvWUnescape(InIter begin, InIter end, OutIter target)
{
... | [] | [
{
"body": "<p>My one comment is add a comment on exactly what it is doing.</p>\n\n<p>Even after studying I am not 100% sure what it does (I would need some unit tests to feel I understood it).</p>\n\n<p>What I think you are trying to achieve:</p>\n\n<ul>\n<li>Convert \\\" into \"</li>\n<li>Convert \\\\\\\" into... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-14T02:01:17.373",
"Id": "10005",
"Score": "2",
"Tags": [
"c++"
],
"Title": "CommandLineToArgV Unescaping"
} | 10005 |
<p><em><strong>Question:</em></strong><em>Write an algorithm in C to do integer multiplication without using multiplication nor division operators</em>.</p>
<p>Could I get a critique of the doMultiplication function? I know the rest of the code has some dumb stuff in it (like using scanf), but I'm looking for feedback... | [] | [
{
"body": "<p><a href=\"http://en.wikipedia.org/wiki/Multiplication_algorithm#Shift_and_add\" rel=\"nofollow\">Your algorithm</a> is optimal for numbers that fit into a int, but a <a href=\"http://en.wikipedia.org/wiki/Multiplication_algorithm#Fast_multiplication_algorithms_for_large_inputs\" rel=\"nofollow\">l... | {
"AcceptedAnswerId": "10009",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-14T07:21:04.017",
"Id": "10006",
"Score": "4",
"Tags": [
"optimization",
"c"
],
"Title": "Binary Multiplication in C"
} | 10006 |
<p>Basically, I'm comparably new to Haskell, which means lacking both knowledge of advanced principles, available libraries and, maybe, some syntax.</p>
<p>For educational purposes I hacked together a code implementing Stam-style fluid dynamics solver. For now the code is running in constant space and linear time, whi... | [] | [
{
"body": "<p>Get rid of all the cascading <code>where</code> clauses, e.g.</p>\n\n<pre><code>project x y = (setBoundary YHard x', setBoundary XHard y')\n where (x', y') = (createMatrix (indicies !! 1) (projectCellX x p), createMatrix (indicies !! 1) (projectCellY y p))\n where p = linearSolver... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-14T07:03:38.140",
"Id": "10012",
"Score": "2",
"Tags": [
"haskell"
],
"Title": "How to make following CFD program more idiomatic?"
} | 10012 |
<p>Nothing too special here, just a bunch of stuff. Please tell me if you would've done something different.</p>
<pre><code><?php
/**
* SQL_Helper are functions which help with... SQL... :)
*
* @package SQL_Helper
* @author Itai Sagi
* @version 1.0
* SQL Helper function... | [] | [
{
"body": "<p>To be honest, if I were an employer I wouldn't read past the first class, which contains <code>static</code>, <code>global</code> and use of the deprecated <code>mysql_*</code>. They should be avoided, especially <code>mysql_*</code> which should be replaced by <code>mysqli</code> or PDO.</p>\n\n... | {
"AcceptedAnswerId": "10033",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-14T15:36:44.027",
"Id": "10015",
"Score": "5",
"Tags": [
"php",
"object-oriented",
"interview-questions"
],
"Title": "I have a home test for job interview"
} | 10015 |
<p>I have a need to represent a finite set of discrete string values: </p>
<ul>
<li>When these strings are used in code, they must belong to the valid set, or serious errors (or worse) can occur. </li>
<li>As "magic strings" are a terrible code smell, I want to encapsulate the strings within a non-string type, so that... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-15T18:53:22.827",
"Id": "16021",
"Score": "0",
"body": "Doesn't this break your requirement for โno constantsโ?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-17T16:20:35.773",
"Id": "16087",
"Scor... | [
{
"body": "<p>A few things don't add up for me regarding your usage. You want compile time absolution, but dynamic values while stating the critical nature of its use. </p>\n\n<p>One option:\n You can just take care of this by having objects with inheritance structures and loading your \"dynamic\" values ... | {
"AcceptedAnswerId": "10022",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-14T16:00:48.430",
"Id": "10016",
"Score": "4",
"Tags": [
"c#",
"strings"
],
"Title": "\"String Enum\" implementation - comments?"
} | 10016 |
<p>Here is a simple plugin I have written for a jQuery dropdown effect. Simple show / hide (although open classes may be better).</p>
<p>When you click the HTML the event searches the whole DOM for a specific class and then hides it (or removes the open class), even if the dropdown is already close.</p>
<p>Is there a... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-15T21:04:34.667",
"Id": "16025",
"Score": "0",
"body": "Why `e.stopPropagation()`? Do you really want this not to prograte up the dom tree?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-16T10:55:07.813",
... | [
{
"body": "<p>Comments:</p>\n\n<ul>\n<li>Don't use the name 'dropdown' that has a very high probability for naming collisions with other libraries.</li>\n<li>I get that you might want to do stuff as a learning experience but you are recreating something that already exists (as a matter of fact a lot of versions... | {
"AcceptedAnswerId": "10053",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-14T17:15:24.867",
"Id": "10019",
"Score": "2",
"Tags": [
"javascript",
"jquery",
"plugin"
],
"Title": "jQuery dropdown plugin to prevent scanning the whole DOM on every click"
} | 10019 |
<p>Is this the way PHP developers write PHP or is echoing the html the preferred method?</p>
<pre><code><html>
<head>
</head>
<body>
<?php
require_once 'db_connect.php';
session_start();
$result = mysql_query("SELECT * FROM products");
?>
<table border=1>
<th>
Produ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-14T18:16:43.203",
"Id": "15958",
"Score": "1",
"body": "If this was JSP I'd say absolutely not. You'd use the Java Standard Tag Library. I'm not sure if there is an equivalent for PHP."
},
{
"ContentLicense": "CC BY-SA 3.0",
... | [
{
"body": "<p>In <strong>small scripts</strong>, it's OK. PHP has features to make this easier:</p>\n\n<ul>\n<li><code><?= $var ?></code> is equivalent to <code><?php echo $var ?></code> (such short tags should not be used at the beginning of the document).</li>\n<li><code>if (condition):</code> and... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-14T18:03:23.260",
"Id": "10020",
"Score": "2",
"Tags": [
"php",
"html"
],
"Title": "Is this an acceptable way of writing PHP code(in scriptlets)"
} | 10020 |
<pre><code>public class BuscaDiretaBusiness
{
PortalIOEntities portalIO = new PortalIOEntities();
public IQueryable CarregaAlias(out int ItemsCount)
{
var query = from a in portalIO.DO_CadernoBuscaDiretaAlias
select new
{
a.CDP_ID,
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-14T19:37:48.520",
"Id": "15968",
"Score": "6",
"body": "Why not just return the IQueryable. Do you need to pass in an out parameter? And yes, that is the way to get count of items"
}
] | [
{
"body": "<p>You're fine. It will only make 1 query.</p>\n\n<p>Plus dreza is right, don't pass back \"count\" through the out parameter. It isn't needed. </p>\n",
"comments": [],
"meta_data": {
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-14T19:57... | {
"AcceptedAnswerId": "10048",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-14T19:24:40.500",
"Id": "10026",
"Score": "5",
"Tags": [
"c#",
".net",
"linq"
],
"Title": "Is it a good way to get Count on Linq?"
} | 10026 |
<p>I'm trying to reflect a ray of a triangle using <a href="http://processing.org/" rel="nofollow noreferrer">Processing</a> and not sure I got the code right. I'm using two bits of pseudo code from two locations:</p>
<ol>
<li>Intersection of a Line with a Plane from <a href="http://paulbourke.net/geometry/planeline/"... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-15T09:53:22.837",
"Id": "16000",
"Score": "0",
"body": "It definitely looks wrong, but it could be due to 3D perspective. The reflected vector only meets a normal (I guess you mean the one raising from the centre of the shape) by coinc... | [
{
"body": "<p>Turns out I needed to normalize the normal first:</p>\n\n<pre><code>n.normalize();\n</code></pre>\n\n<p>full code for reference:</p>\n\n<pre><code>PVector[] face = new PVector[3];\nfloat ai = TWO_PI/3;//angle increment\nfloat r = 300;//overall radius\nfloat ro = 150;//random offset\n\nPVector n;/... | {
"AcceptedAnswerId": "10381",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-14T19:36:06.430",
"Id": "10028",
"Score": "3",
"Tags": [
"computational-geometry",
"processing",
"raytracing"
],
"Title": "Ray reflection with a triangle"
} | 10028 |
<p>I am a moderately new Scala developer working mostly by myself, so I don't have anyone to tell me what I'm doing wrong (except that the system mostly does work, so it can't be too awful). I would appreciate some feedback on how to make better use of Scala as well as any comments about obvious performance issues.</p>... | [] | [
{
"body": "<p><strong>Some words at beginning:</strong> I have never used OSGI, so I can't say if the tips below may all work in your context. If they do not, than keep them in the back of your head and use them when you can.</p>\n\n<hr>\n\n<p>One of the most important rules is to avoid mutable state if possibl... | {
"AcceptedAnswerId": "10066",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-14T20:24:35.743",
"Id": "10030",
"Score": "10",
"Tags": [
"scala",
"library"
],
"Title": "OSGi-like infrastructure"
} | 10030 |
<p>This is supposed to be strict ANSI C89 pedantic code. It should extract <code>word1</code>, <code>word2</code> and <code>word3</code> from a string formatted [ word1 ] word2 [ word3 ] and return failure in any other format.</p>
<p>It seems to work, but it seems so ugly. No need to comment about the fact <code>GetTo... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-14T22:10:13.440",
"Id": "15971",
"Score": "0",
"body": "First off fix your indentation. Markdown engine doesn't like tabs - replace them with spaces."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-14T22:27... | [
{
"body": "<pre><code>#include <stdio.h>\n#include <string.h>\n#include <ctype.h>\n\nchar * TrimWhiteSpaces(char *str) {\n char *out = str;\n int i;\n int len = strlen(str);\n for (i=0; i<len && isspace(str[i]); i++, out++); /*scan forward*/\n</code></pre>\n\n<p>I'd at l... | {
"AcceptedAnswerId": "10036",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-14T20:30:47.173",
"Id": "10031",
"Score": "4",
"Tags": [
"c",
"strings",
"parsing"
],
"Title": "String parsing in C"
} | 10031 |
<p>I have a type that receives serial data over a pipe:</p>
<pre><code>struct Packet : Base { // Base is POD, too
int foo;
char data[];
};
</code></pre>
<p>In the context, where I instantiate <code>Packet</code>, I already know how large this particular packet will be, so I write:</p>
<pre><code>size_t const siz... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-15T04:48:09.483",
"Id": "15987",
"Score": "0",
"body": "In my opinion this approach makes a lot more sense in C than it does in C++. I've seen it more often in projects which choose to do C rather than C++. (In fact AFAIK this is sta... | [
{
"body": "<p>The main thing I see wrong is that you are not accounting for <code>sizeof(foo)</code>.</p>\n\n<p>The other problem is that auto_ptr<> will not de-allocate the memory correctly. It calls <code>delete X</code>, but this is not legal as you did not allocate the memory with <code>new</code>. Y... | {
"AcceptedAnswerId": "10035",
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-15T01:38:14.230",
"Id": "10034",
"Score": "1",
"Tags": [
"c++",
"memory-management"
],
"Title": "Variable sized type allocation"
} | 10034 |
<p>This is a personal project of mine. I am currently in the research phase of developing my own bootloader that will be used to load a single task operating system. I am far away from the final goal, but have been trying to document my process as a reference. The content of my code documentation and code can be found... | [] | [
{
"body": "<ul>\n<li>Your code is well-commented. Other <a href=\"/questions/tagged/assembly\" class=\"post-tag\" title=\"show questions tagged 'assembly'\" rel=\"tag\">assembly</a> answers on this site mention the importance of good comments: and yours are good.</li>\n<li>An infinite loop at the end of... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-15T04:50:08.653",
"Id": "10037",
"Score": "5",
"Tags": [
"assembly"
],
"Title": "The beginnings of a bootloader using GNU-based tools"
} | 10037 |
<p>This is a ( single file ) library I wrote as an helper to check arguments validity.Here below a sample usage:</p>
<pre><code>public class Demo
{
/// <summary>
/// Classical not null verification
/// </summary>
/// <param name="arg1"></param>
public... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-15T14:11:51.833",
"Id": "16009",
"Score": "1",
"body": "I'm curious, why don't you use [.NET 4 Code Contracts](http://msdn.microsoft.com/en-us/library/dd287492.aspx)?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": ... | [
{
"body": "<p>Felice, can you expand on what you are looking for? Are you trying to infer constraints to be applied dynamically? I looked at your link to the whole code base at bitbucket.</p>\n\n<p>First of all, nice work. Looks like you spent a good deal of time whipping that up.</p>\n\n<p>On the surface, g... | {
"AcceptedAnswerId": null,
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-15T09:54:12.947",
"Id": "10039",
"Score": "3",
"Tags": [
"c#"
],
"Title": "An argument checking library"
} | 10039 |
<p>Is it possible to make this code more efficient & elegant? </p>
<pre><code>int HexToDecimal(char ch)
{
ch = tolower(ch);
if ('a' <= ch && ch <= 'f')
{
return ch - 'a' + 10;
}
else if ('0' <= ch && ch <= '9')
{
return ch - '0';
}
printf(... | [] | [
{
"body": "<p>The first idea comming to mind is to check <code>0 <= ch <=9</code> before <code>tolower(ch)</code>, because if it's a digit, then you don't need to make <code>tolower</code>.</p>\n\n<p>Say, what does it means if the function returns <code>0</code>? How to determine the case \"it returns <co... | {
"AcceptedAnswerId": "10047",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-15T10:22:39.117",
"Id": "10040",
"Score": "1",
"Tags": [
"c++",
"converting"
],
"Title": "Converting hex character to decimal"
} | 10040 |
<p>I use this class for scheduling bits of work on a single thread. Work can be scheduled to be executed immediately or at a future time with the use of timers. It has many producers (the work adders) and a single consumer (the thread which executes the work).</p>
<p>This class works well but I'm under no illusion tha... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-14T07:36:17.267",
"Id": "16005",
"Score": "0",
"body": "What version of the framework are you using, and what version of C#? (For example, you have several properties which could be automatically implemented to start with, and .NET 4 c... | [
{
"body": "<ol>\n<li><p>A slightly better way to wait for the queue to be not empty in your <code>Loop</code> method would be to use a <a href=\"http://msdn.microsoft.com/en-us/library/System.Threading.Monitor_methods%28v=vs.110%29.aspx\" rel=\"nofollow\"><code>Monitor</code></a> instead of an <code>AutoResetEv... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-14T07:33:58.273",
"Id": "10042",
"Score": "4",
"Tags": [
"c#",
".net",
"multithreading"
],
"Title": "Producer/Consumer queue"
} | 10042 |
<p>Is there a better way to format this code, to make it more readable?</p>
<pre><code>footnotes_paragraph.xpath('./small').children.slice_before do |element|
element.name == 'br'
end.map do |element|
Footnote.new element
end.reject(:empty?)
</code></pre>
| [] | [
{
"body": "<p>You could extract out the initial xquery part into a separate method</p>\n\n<pre><code>def small_children\n footnotes_paragraph.xpath('./small').children\nend\n</code></pre>\n\n<p>Instead of using <code>do</code> <code>end</code> you could use <code>{}</code>. Then just a little reformatting, p... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-15T13:42:29.047",
"Id": "10045",
"Score": "1",
"Tags": [
"ruby"
],
"Title": "Ruby blocks format"
} | 10045 |
<p>I wrote a non-blocking MySQL interface for java (wrapped around the standard mysql java connector).</p>
<p>I think the code to use it looks a bit ugly however...</p>
<pre><code>db.rawQuery(queries.someAlreadyPreparedStatement, (new Callback(){
public void result(ResultSet result){
while (result.next())... | [] | [
{
"body": "<p>This is as good as it gets in Java. The idea of callbacks are very popular, and are the foundation of functional languages. Even Javascript offers a cleaner approach, as <a href=\"http://api.jquery.com/jQuery.get/\" rel=\"nofollow\">JQuery shows</a>. Unfortunately for Java, anonymous inner classes... | {
"AcceptedAnswerId": "10084",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-15T20:03:02.690",
"Id": "10051",
"Score": "2",
"Tags": [
"java",
"mysql"
],
"Title": "Non-Blocking MySQL queries in Java"
} | 10051 |
<p>I have created an NBT format reader (<a href="http://web.archive.org/web/20110723210920/http://www.minecraft.net/docs/NBT.txt" rel="nofollow">NBT</a> is a binary serialization format that Minecraft uses to store its data). I made a node-like class that can be a data entry or the root of a subtree (that's how NBT is ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-15T22:34:03.547",
"Id": "16030",
"Score": "0",
"body": "I think its hard to judge without some idea (sample code?) of how you are going to actually use it."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-15... | [
{
"body": "<p>Couple of things I noticed:</p>\n\n<p>The serialize members:</p>\n\n<pre><code>void read(std::istream& stream);\nvoid write(std::ostream& stream);\n</code></pre>\n\n<p>I don't particular mind them but I also would prefer to have <code>operator<<</code> and <code>operator>></cod... | {
"AcceptedAnswerId": "10055",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-15T22:29:48.843",
"Id": "10054",
"Score": "1",
"Tags": [
"c++",
"api"
],
"Title": "Interface of a variant-like class"
} | 10054 |
<p>This is just a big HTML file that can be setup to test any RESTful API. The only change that needs to be made is updating the config array for any specific API you are developing.</p>
<pre><code><html>
<head>
<title>RESTful API Debugger</title>
<style>
label{ display:inline... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-15T23:17:03.273",
"Id": "16032",
"Score": "0",
"body": "There is a lot of repeated code in there, you can easily clean up those ifs. Why are you using eval? There is no need for that,build the object instead of a string."
},
{
... | [
{
"body": "<p>As @epascarello mentioned, there is a ton of repeated code here.</p>\n\n<p>Some pointers if you wish:</p>\n\n<p>You could consider to have the number of variables configurable. This means you can add that to your config object and then do the following in your <code>$(document).ready()</code>:<br>... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-15T23:12:12.657",
"Id": "10056",
"Score": "1",
"Tags": [
"javascript",
"html"
],
"Title": "Code review of my quick and dirty RESTful API Debugger"
} | 10056 |
<p>My goal with vervPHP was to create a framework I could create applications in very quickly, without any excessive configuration or over the top framework.</p>
<p>Here's a link to the github, to see more: <a href="https://github.com/verv/vervPHP" rel="nofollow">https://github.com/verv/vervPHP</a></p>
<p>And now, fo... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-22T07:59:28.373",
"Id": "16299",
"Score": "0",
"body": "vervPHP - The constructor that does it all (and you're done)"
}
] | [
{
"body": "<p>You are <a href=\"http://www.youtube.com/watch?v=H33vSYapNNs\" rel=\"nofollow\">on a long way to success</a>. </p>\n\n<p>Consider autoload function (better from SPL) to avoid includes, it will also force you to establish good directory structure and clear class naming convention plus more security... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-16T01:29:17.477",
"Id": "10060",
"Score": "1",
"Tags": [
"php",
"php5"
],
"Title": "Review of my PHP framework, vervPHP"
} | 10060 |
<p>I have a blob whose format is something like:</p>
<p>(id1,key1,value1)(id2,key2,value2).... </p>
<p>where id is a <code>uint32_t</code>, and key and value are null-terminated strings. I am looking for an iterator-like interface that will extract records from the blob.</p>
<p>This is what I have come up with:</p>... | [] | [
{
"body": "<p>You're just setting pointers in your function.\nIf the original data changes, you will be accessing wrong data ...</p>\n\n<pre><code>char data[] = \"\\x01\\x00\\x00\\x01key\\0value\";\np = get_next_obj(data, data + sizeof data);\nif (p.id != 16777217) /* error */;\nif (strcmp(p.key, \"key\")) /* e... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-16T09:33:52.313",
"Id": "10062",
"Score": "2",
"Tags": [
"c",
"iterator"
],
"Title": "Iterator-like interface for extracting records from a blob"
} | 10062 |
<p>I am using jQuery datepicker on 2 forms on the same page.<br>
I currently am using the following code (below), but as you can see, I am using the same parameters over again (showOn, buttonImage, buttonImageOnly, dateFormat, & constrainInput)</p>
<p>Is there a more efficient way to do this rather then repeating ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-16T15:28:29.933",
"Id": "16056",
"Score": "0",
"body": "You could have a `defaultOptions` object that contains all the common elements (showOn, buttonImage, buttonImageOnly, etc), then just modify it as necessary?"
},
{
"Conten... | [
{
"body": "<p>You'll want to use <code>setDefaults</code> to clean up your code a bit. Also with a few variables you can clean it up even more.</p>\n\n<pre><code>$.datepicker.setDefaults({\n showOn: 'both',\n buttonImage: '/assets/images/calendar_symbol.png',\n buttonImageOnly: true,\n dateFormat: '... | {
"AcceptedAnswerId": "10074",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-16T13:59:23.130",
"Id": "10068",
"Score": "4",
"Tags": [
"javascript",
"jquery-ui"
],
"Title": "Refactor this jQuery datepicker code to be as small as possible"
} | 10068 |
<p>I've created a set of classes thatwork together to create the html needed to display social plugins like Facebook like, google plus and twitter.
At firsti defined an abstract class SocialButtonAbstract that is the base class that will be extended by the various plugins</p>
<pre><code>abstract class SocialButtonAbs... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-19T20:27:19.123",
"Id": "16168",
"Score": "0",
"body": "Is the question too long?Should i take out the code?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-30T22:19:11.650",
"Id": "16737",
"Score":... | [
{
"body": "<p>I know this is rather old, but I came across it while look through the unanswered pile and thought there were a few things I could add. Because it is so old and I'm unsure if you are still watching this, I won't go into a lot of detail. However, if you want me to, I will of course return and do a ... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-16T15:00:43.943",
"Id": "10071",
"Score": "2",
"Tags": [
"php",
"design-patterns",
"classes"
],
"Title": "Set of classes for generating social plugins, is my design correct?"
} | 10071 |
<p>I'm trying to teach myself a new pattern, the command pattern, and came up with the following example. Looking for feedback.</p>
<pre><code>public class BaseTool
{
private List<ICommand> CommandHistory = new List<ICommand>();
public string State = string.Empty;
public BaseTool()
{
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-16T19:00:44.403",
"Id": "16060",
"Score": "0",
"body": "Just curious, why do you have parentheses around (t != null)? And I'm not sure how much you gain in readability by having the CanExecute() method."
},
{
"ContentLicense": ... | [
{
"body": "<p>The Command Pattern's goal is to decouple the requestor object from the object performing the request. Your example does that. </p>\n\n<p>However there is a small separation of responsibilities issue. Tool should not have to know to ask if ICommand can execute. That responsibility should be in the... | {
"AcceptedAnswerId": "10108",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-16T16:48:45.137",
"Id": "10075",
"Score": "5",
"Tags": [
"c#",
"design-patterns"
],
"Title": "Command Pattern"
} | 10075 |
<p>I have a class that produces a key based on the two objects passed. The key for the items passed is simply the string of the ID (a GUID) for each object. There is also a subclass that makes sure any to items are only represented once (sets).</p>
<p>The classes looked like the first code block below. But then I ran ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-15T16:59:58.280",
"Id": "22136",
"Score": "0",
"body": "If you asked me, the inheritance is not a good idea here. You're not inheriting anything but a different implementation of the `Key` function. You should make a common interface... | [
{
"body": "<p>Based upon your use case, the code below is what I would recommend. I'm sorry that it is in C#, on this computer I don't have my vb.net loaded so it was easier to express in c#.</p>\n\n<p>There are 3 parts to this. The class on the bottom should address your needs (KeySet). the second class hel... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-16T16:58:47.460",
"Id": "10076",
"Score": "1",
"Tags": [
".net",
"vb.net"
],
"Title": "Inheriting needed when only difference is performed in the constructor?"
} | 10076 |
<p>I'd like this reviewed.</p>
<pre><code>public sealed class FibonacciHeap<TKey, TValue>
{
readonly List<Node> _root = new List<Node>();
int _count;
Node _min;
public void Push(TKey key, TValue value)
{
Insert(new Node {
Key = key,
Value = value
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-16T19:04:17.427",
"Id": "16061",
"Score": "1",
"body": "`a, x, d, y, t`: I think I would really enjoy reading your code if not for these random variable names. `i, n` are proper one-letter variable names because they are obvious, but t... | [
{
"body": "<p>Disclaimer: I will not address the actual FibonacciHeap itself, just the c# code.</p>\n\n<hr>\n\n<p>I explicitly write the <code>private</code> keyword on those methods and properties, so they are indented roughly the same as the <code>public</code> ones. A matter of preference, I guess.</p>\n\n<p... | {
"AcceptedAnswerId": "10145",
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-16T17:00:56.890",
"Id": "10077",
"Score": "2",
"Tags": [
"c#",
"fibonacci-sequence",
"heap"
],
"Title": "Fibonacci heap implementation"
} | 10077 |
<p>I am trying to implement a shared cache for arrays. It must support two operations: set(owner, idx, value) and fetch(owner, idx) where <code>idx</code> is the index into the array and <code>owner</code> is an opaque handle to an owning object -- <code>fetch(owner_1, idx)</code> should return the value stored by <co... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-17T14:42:10.347",
"Id": "16083",
"Score": "0",
"body": "Shouldn't `slot` be declared as a pointer? As in, `struct *slot = &cache[idx];` . That's how you're accessing it."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDa... | [
{
"body": "<p>It's not clear from you're post whether <code>owner</code> is unique for each thread or if two threads can call the functions with the same value of <code>owner</code>. If two threads can call the functions with the same value for <code>owner</code>, your code is incorrect.</p>\n\n<p>If one thread... | {
"AcceptedAnswerId": "10227",
"CommentCount": "7",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-16T19:27:44.737",
"Id": "10080",
"Score": "3",
"Tags": [
"c",
"multithreading"
],
"Title": "Implementing a shared array cache without locking"
} | 10080 |
<pre><code>public sealed class SinglyLinkedList<T> : IEnumerable<T>
{
readonly static SinglyLinkedList<T> _empty = new SinglyLinkedList<T>();
readonly bool _isEmpty;
readonly T _head;
readonly SinglyLinkedList<T> _tail;
private SinglyLinkedList()
{
_isEmpty... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-27T01:36:10.860",
"Id": "67442",
"Score": "1",
"body": "Just want to point out that Microsoft has put out an [immutable collections library](https://www.nuget.org/packages/Microsoft.Bcl.Immutable/)"
}
] | [
{
"body": "<ol>\n<li>The constructor with one argument is never used and doesn't make much sense (list with a head but no tail?).</li>\n<li>You shouldn't use <code>Count</code> in your own methods unless absolutely necessary, because it's O(n). Or you should cache the result in a field.</li>\n<li>Because you us... | {
"AcceptedAnswerId": "10085",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-16T21:29:15.023",
"Id": "10083",
"Score": "1",
"Tags": [
"c#",
"linked-list",
"immutability"
],
"Title": "Care to review my immutable singly linked list?"
} | 10083 |
<p>I'm writing an if with nested conditions and end up with this ugly if:</p>
<pre><code>if( !arg ||
(typeof arg.search != 'undefined' && typeof arg.done == 'undefined' &&
item.attributes.text.toLowerCase().indexOf(arg.search.toLowerCase()) != -1) ||
type... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-17T13:21:11.433",
"Id": "16080",
"Score": "0",
"body": "You can get rid of the typeof checks and just check for undefined. `arg.search !== undefined`"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-17T15:51... | [
{
"body": "<p>Obviously there's no way I can try this out but you could organize your code in functions. Also I don't understand why this:</p>\n\n<pre><code>(arg.done && item.attributes.done) || (!arg.done && !item.attributes.done)\n</code></pre>\n\n<p>If both exist or don't exist seems trivial.... | {
"AcceptedAnswerId": null,
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-17T04:03:18.800",
"Id": "10087",
"Score": "-1",
"Tags": [
"javascript"
],
"Title": "Rendering a view if item is done or contains a search term"
} | 10087 |
<p>I've created a functional A* implementation in C#/XNA for a game I'm working on. However, I am using rather large paths, and of course, the larger the paths are, the longer it takes to trace them. There is no way to shorten the paths (Thin Maze - Style) and I assume this is a horrid way to implement it. I followed <... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-17T08:41:05.133",
"Id": "16077",
"Score": "0",
"body": "Have you considered caching results for frequently used values? This is probably the easiest way to gain some performance with the least effort."
}
] | [
{
"body": "<p>The #1 mistake I see in new A* implementations, which is the mistake you've made, is not using a <a href=\"http://en.wikipedia.org/wiki/Priority_queue\" rel=\"nofollow\">priority queue</a> for the open set, and not using a better data structure than a list (e.g. a tree or hash map) for the closed ... | {
"AcceptedAnswerId": "10119",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2012-03-17T04:47:11.820",
"Id": "10088",
"Score": "1",
"Tags": [
"c#",
"performance",
"algorithm",
"pathfinding"
],
"Title": "A* Implementation results in exponential speed loss"
} | 10088 |
<p>The <a href="https://github.com/swapsmagic/CausesPuzzle/tree/0fd7fe69e0f55ee03ac16adec6a7809c4b55dfd5" rel="nofollow">"Causes" puzzle</a> is to recursively find, starting with the word "causes", the number of words that can be formed by substituting one letter.</p>
<pre><code>sub addMember {
my ( $self, $newMembe... | [] | [
{
"body": "<p>Here is one idea: You could first put the words into a hashmap, the length of them being the key. O(n)</p>\n\n<p>Then, since you are only interested in \"causes\", grab that word and make a node and remove it from the hashmap. </p>\n\n<p>Then, a recursive function</p>\n\n<ul>\n<li>adds all friends... | {
"AcceptedAnswerId": "10105",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-17T05:52:31.033",
"Id": "10089",
"Score": "1",
"Tags": [
"graph",
"perl",
"edit-distance"
],
"Title": "\"Causes\" Puzzle solution (network of words with Levenshtein distance 1)"
} | 10089 |
<p>After <a href="https://stackoverflow.com/questions/9743859/how-to-represent-class-that-contains-no-methods-only-fields">my question on StackOverflow</a>, I've written code that should create a <code>Config</code> class from an XML file. XML loading is mixed with structures declaration and break in a lot of small pie... | [] | [
{
"body": "<p>Make sure you code defensively, I see many potential null reference exceptions. Verify all inputs (what happens if you put a null value or a string like \"adsf\") in your Config constructor. What happens if you don't have a xml file in the proper configuration, what if a node is missing?</p>\n",
... | {
"AcceptedAnswerId": "10391",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-17T20:12:56.263",
"Id": "10100",
"Score": "2",
"Tags": [
"c#",
"xml"
],
"Title": "Loading config file from XML"
} | 10100 |
<pre><code>int *getUserInput(FILE *fpin, int *elementCount) {
int *userInput;
// Load file into buffer
int length = fileLength(fpin);
char *buffer = (char *) malloc(length * sizeof(char));
int written = fread(buffer, sizeof(char), length, fpin);
// Number of int's allocated in userInput
int allocated = 10... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-21T16:25:23.347",
"Id": "16264",
"Score": "0",
"body": "note that sizeof(char) is 1 by definition and so is redundant (noise)"
}
] | [
{
"body": "<p>Check that malloc didn't return NULL; in general, use defensive programming; That means always assume things went wrong, and check all return values. It helps with debugging too.</p>\n\n<p>You should be aware that strtok and atoi are not safe functions for arbitrary user input. That means you are ... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-17T22:56:16.580",
"Id": "10103",
"Score": "1",
"Tags": [
"c"
],
"Title": "Reading tokenized numbers from a file"
} | 10103 |
<p>At the moments the requirements do not need me to change this code, however I think there is something wrong with it in the fact that it seems to know too much. The code takes a memory stream which is essentially a file and uploads this to a post URL supplying the necessary credentials. It may also need to pass ot... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-18T17:08:38.597",
"Id": "16140",
"Score": "1",
"body": "Quick small notes: See the answer to: http://stackoverflow.com/questions/2845055/getting-rid-of-nested-using-statements\nAlso in the `WriteToHttpStream`, your `using` body is too ... | [
{
"body": "<p>The code looks ok, but indeed there are too many responsibilities in a single class, hence SRP is violated.</p>\n\n<p>For instance, you could use a decorator to add the credentials, instead of having them injected in the constructor. But this leads to <strong>your own model</strong> of HTTP reques... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-18T03:15:27.293",
"Id": "10112",
"Score": "1",
"Tags": [
"c#"
],
"Title": "Separate responsibilities out of this class that uploads data to a post URL"
} | 10112 |
<p>How can I optimize checking a value in recursion before operating on it? I'm using <code>Array.indexOf</code> (this is Javascript)</p>
<pre><code>var nums = [], lengths = [];
function findNumLength(n) {
//preliminary check to see if
//we've done this number before
var indexOf = nums.indexOf(n);
if(... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-18T03:55:25.563",
"Id": "16115",
"Score": "0",
"body": "Can you include more complete code? What you have so far isn't making sense to me. You check to see if the number is in the array and if it's not, you `return 1`. If it is in t... | [
{
"body": "<p><code>Array.indexOf</code> loops through the entire array, which hurts speed, especially when the array gets big and the recursion enters several levels. One way to optimize would be to do:</p>\n\n<pre><code>//set up the array as normal\nvar numbers = []; \nfunction recurse(number) {\n //if num... | {
"AcceptedAnswerId": "10116",
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-18T03:21:40.280",
"Id": "10113",
"Score": "1",
"Tags": [
"javascript",
"optimization",
"array"
],
"Title": "Optimize Array.indexOf"
} | 10113 |
<p>For anyone familiar with the UVa Programming Challenges website, I have started experimenting with some of the basic challenges. I was hoping to get critique for the code I wrote for <a href="http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=3&page=show_problem&problem=36... | [] | [
{
"body": "<p>This is overly confusing, and things are obscurely named. This is a one-off for a programming contest thingy, so it doesn't seem like it's that important. But I find that organizing my code well helps me think. You might find that's true of you.</p>\n\n<p>Also, you have several fixed sized tables ... | {
"AcceptedAnswerId": "10127",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-18T10:35:45.923",
"Id": "10120",
"Score": "3",
"Tags": [
"c++",
"algorithm"
],
"Title": "UVa Challenge Problem: 3n+1"
} | 10120 |
<p>Inspired by <a href="https://stackoverflow.com/questions/9742725/solving-google-code-jams-minimum-scalar-product-in-haskell">a Stack Overflow question</a>, I decided to practice my Haskell by taking a crack at the <a href="http://code.google.com/codejam/contest/32016/dashboard" rel="nofollow noreferrer">Google Code ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2015-02-21T14:26:42.323",
"Id": "147825",
"Score": "5",
"body": "You do know that this problem can be solved by just sorting the vectors? Why do it in such a complicated way when it's just a reference implementation, what's wrong with Data.Lis... | [
{
"body": "<p>Somewhat old question, but still it's a pity it hasn't been answered :). Putting aside the asymptotically better solution suggested in the comments, and focusing just on the code:</p>\n\n<p>Pluses: Top-level types for all funtcions, that's very good, as well as comments. The code shows good unders... | {
"AcceptedAnswerId": "135024",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-18T12:06:23.123",
"Id": "10123",
"Score": "41",
"Tags": [
"programming-challenge",
"haskell",
"combinatorics",
"computational-geometry",
"monads"
],
"Title": "Finding min... | 10123 |
<p>Source XML (since I haven't bothered with a schema):</p>
<pre><code><?xml version="1.0"?>
<ContactDetails>
<Names>
<FullName>
Nicholas Example
</FullName>
<AltName context="Nickname">
Nick
</AltName>
<AltName context="Online">
oxinabox
</A... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-18T15:45:09.077",
"Id": "16138",
"Score": "2",
"body": "I tend to like email addresses in `First Last <name@place.domain>` format. It lets me easily select just the name. And if I select the whole thing their name shows up in the outgo... | [
{
"body": "<pre><code><xsl:output\n method=\"text\"\n omit-xml-declaration=\"yes\"\n indent=\"no\"\n media-type=\"text/plain\"/> \n</code></pre>\n\n<p>Consider using XSLT 2.0, which can't hurt but could help if you need a XSLT 2.0 function in the future. Also note that you don't need <code>omi... | {
"AcceptedAnswerId": "10132",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-18T14:44:17.970",
"Id": "10125",
"Score": "4",
"Tags": [
"xml",
"xslt"
],
"Title": "Making a flat file"
} | 10125 |
<p>This is my first Clojure script (simple word translator based on Wikipedia), and I guess there are things which could be simplified / done more idiomatic way. Specifically, I wonder if <code>get-translations</code> couldn't be done better (it produces map lang code => term form regexp sequence).</p>
<pre><code>(ns ... | [] | [
{
"body": "<p>Don't use the multiple-arity syntax for <code>defn</code> unless you actually need to:</p>\n\n<pre><code>(defn url-decode\n [text]\n (URLDecoder/decode text \"UTF-8\"))\n</code></pre>\n\n<p>Your code could use some line breaks here and there. This is how clojure is usually indented:</p>\n\n<pre>... | {
"AcceptedAnswerId": "10179",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-18T16:07:16.120",
"Id": "10126",
"Score": "3",
"Tags": [
"clojure",
"web-scraping",
"wikipedia"
],
"Title": "Simple word translator taking advantage of Wikipedia"
} | 10126 |
<p>After programming a lot in high level languages such as Python and R, I started working with C++ recently. To get my C++ skills up, I of course read a lot of books. In addition, I try and replicate some functionality from high level languages in C++. My first attempt at this (after Hello World :)) was to create a C+... | [] | [
{
"body": "<h3>Header Files</h3>\n<p>Should always be protected by include guards.<br />\nOtherwise you are sustainable to infinite recursion and multiple definitions.</p>\n<pre><code>// Header.h\n#ifndef XXX\n#define XXX\n\n/// The header file goes here\n\n#endif\n</code></pre>\n<p>XXX Should be a unique ide... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-18T19:20:03.140",
"Id": "10128",
"Score": "6",
"Tags": [
"c++"
],
"Title": "Class to read comma separated data from disk"
} | 10128 |
<pre><code>#include <cassert>
#include <string>
#include <vector>
using namespace std;
inline size_t min(size_t x, size_t y, size_t z)
{
if (x < y)
return x < z ? x : z;
else
return y < z ? y : z;
}
size_t edit_distance(const string& A, const string& B)
{
... | [] | [
{
"body": "<p>I hope you're enjoying the NLP class. I do. :)</p>\n\n<p><strong>Min</strong></p>\n\n<pre><code>inline size_t min(size_t x, size_t y, size_t z)\n{\n if (x < y)\n return x < z ? x : z;\n else\n return y < z ? y : z;\n}\n</code></pre>\n\n<p>This could be rewritten as:</p... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-18T21:24:49.807",
"Id": "10130",
"Score": "7",
"Tags": [
"c++",
"strings",
"c++11",
"edit-distance"
],
"Title": "Edit Distance Between Two Strings"
} | 10130 |
<p>Here is my code:</p>
<pre><code>hasAttr = new function(tag, attrName) {
return (tag.attrName)
}
</code></pre>
<p>Will this code work? I can't test it now because I cannot acces <a href="http://jsfiddle.net/" rel="nofollow">jsfiddle</a> and <a href="http://jsbin.com/" rel="nofollow">jsbin</a> but <a href="http:... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-19T00:10:34.330",
"Id": "16147",
"Score": "1",
"body": "`hasAttr(\"div\", \"id\")` You are sending a string \"div\" and you are treating it like an object in your function. Something is wrong!"
}
] | [
{
"body": "<p>Testing JavaScript code in jsFiddle to make sure it works is suicide. The difficult part about JavaScript is really cross-browser compatibility, which means you just <strong>can't</strong> just test in one browser to say it works.</p>\n\n<p>That being said, the name <code>hasAttr</code> makes me t... | {
"AcceptedAnswerId": "10135",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-18T21:27:27.420",
"Id": "10131",
"Score": "1",
"Tags": [
"javascript",
"html"
],
"Title": "Will this test to check if an element has an attribute work?"
} | 10131 |
<p>Here is some code that I put together for an app I am working on that loads 2 XML files and a large CVS file to a dataset at startup. It runs fairly fast, but I would like a second opinion on what I could do to either make it more consise or faster. I'm newer to .NET as well, so if you see anything that isn't very... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-21T19:16:39.177",
"Id": "16275",
"Score": "1",
"body": "I'm not a vb.net expert but do you need to do a line.ToList() on the string when you are doing a ToArray() later on. Seems like possible duplication to me?"
},
{
"Content... | [
{
"body": "<p>Move code that displays Message Boxes up the call hierarchy.\nMake better use of exceptions.\nUse String Builders only when you append a lot, not just a couple of lines, try using String.Format.\nFollow official VB.NET naming conventions \"Begin each separate word in a name with a capital letter\"... | {
"AcceptedAnswerId": "10209",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-18T23:17:08.343",
"Id": "10137",
"Score": "2",
"Tags": [
".net",
"xml",
"csv",
"vb.net"
],
"Title": "Loading XML and csv files to datatables at startup"
} | 10137 |
<p>The game of life is often implemented by representing the board as a 2D boolean array. This doesn't scale very well to larger boards -- it starts to consume lots of memory, and without some separate mechanism to keep track of a list of live cells, you have to visit each board cell on each iteration. This implement... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-19T18:10:20.540",
"Id": "50326",
"Score": "0",
"body": "If you want to compute long and large sequences of Life, you might be interested in [hashlife](https://en.wikipedia.org/wiki/Hashlife)."
}
] | [
{
"body": "<p><strong>Edit</strong>: This answer was given when the reviewed code looked quite differently.</p>\n\n<p>Any specific questions? Here's what stands out for me:</p>\n\n<ol>\n<li><p>Why do <code>toList</code> in <code>emptyNeighbors</code>, then go back to <code>Set</code> again? You could simply use... | {
"AcceptedAnswerId": "10150",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-19T01:26:43.753",
"Id": "10139",
"Score": "3",
"Tags": [
"haskell",
"game-of-life"
],
"Title": "The game of life with a truly infinite board"
} | 10139 |
<pre><code>public interface ICacheable<TK,TV>
{
TV Get(TK key);
void Add(TK key, TV val);
}
public abstract class BaseCache<TK, TV>
{
protected static Dictionary<Guid, Dictionary<TK, TV>> data = new Dictionary<Guid, Dictionary<TK, TV>>();
private Guid StorageNameSpage;... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-19T15:30:02.470",
"Id": "16164",
"Score": "1",
"body": "How is this better than having a private static dictionary elsewhere? The dictionary gives you a lot of functionality, such as it can tell you whether a key exists, it can partici... | [
{
"body": "<p>One comment on the code: you will find your constructors easier to maintain if you use constructor chaining</p>\n\n<p>protected BaseCache() : this(Guid.NewGuid() ) \n{\n} </p>\n\n<p>Now my possibly ignorant comments on other things. </p>\n\n<ul>\n<li>The usage is almost identical to <code>Dictiona... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-19T11:29:42.850",
"Id": "10146",
"Score": "3",
"Tags": [
"c#",
"cache"
],
"Title": "C# small caching API"
} | 10146 |
<p>I use ruby 1.8.7. I have method wich select records and fill hash. In my opinion the code is not dry. Could somebody help me to refactor it and make it shorter and more elegant?</p>
<pre><code>def fill_attributes()
if (!$array[:status_id])
$array[:status_id] = @customer.status_id
@status_... | [] | [
{
"body": "<p>I think you can optimize it like :</p>\n\n<pre><code>def fill_attributes()\n if (!$array[:status_id])\n $array[:status_id] = @customer.status_id\n $array[:status]= get_attribute_name('status',$array[:status_id] )\n end\n\n if (!$array[:color_id])\n $array[:color_id] = @customer.color_i... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-18T20:31:32.673",
"Id": "10147",
"Score": "2",
"Tags": [
"ruby",
"ruby-on-rails"
],
"Title": "Select records and fill hash"
} | 10147 |
<p>I've defined a Client class to connect to an external API. The Client class will return XML responses for various resources. Here's what it looks like now:</p>
<pre><code>require 'nokogiri'
class Client
include Exceptions
CONFIG = YAML.load_file(File.join(Rails.root, 'config', 'mark.yml'))
def self.get_l... | [] | [
{
"body": "<p>Using the <code>@url</code> and <code>@url_params</code> variables this way is not idiomatic Ruby. There are similar uses of instance fields in Ruby on Rails, but this is for passing state out of Controllers and into Views. It is not standard object-oriented practice, but in Rails it is done to re... | {
"AcceptedAnswerId": "11008",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-19T15:36:40.650",
"Id": "10152",
"Score": "2",
"Tags": [
"ruby",
"classes",
"api"
],
"Title": "Ruby - class definition for connecting to external API"
} | 10152 |
<p>I'm pretty new to OCaml, so any feedback is appreciated. The goal is to implement a trie that efficiently stores and sorts strings.</p>
<pre><code>module CharMap = Map.Make(Char)
(* count of members of the set that end at this node * mapping from
next char => children *)
type trie = Node of int * trie CharMa... | [] | [
{
"body": "<p>You're pretty new to OCaml? You're using OCaml 3.12 features and probably did a lot of functional programming before. Let's see if I can show what idioms I've seen before. I'm not an OCaml expert though, far from it.</p>\n\n<p><strong>Empty trie</strong> Consider using something like <code>Empty</... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-19T17:46:58.623",
"Id": "10154",
"Score": "5",
"Tags": [
"ocaml"
],
"Title": "String Trie in OCaml"
} | 10154 |
<p>I would like some eyes on this:</p>
<pre><code>/* Little XHR
* by: rlemon http://github.com/rlemon/
* see README for useage.
* */
var xhr = {
xmlhttp: (function() {
var xmlhttp;
try {
xmlhttp = new XMLHttpRequest();
} catch (e) {
try {
xm... | [] | [
{
"body": "<p>Its interface might not be obvious enough for junior programmers in a hurry. I suppose there's some assistance in your README. Anyway the code is quite clear given a little experience or effort. It doesn't use exactly the subset of JavaScript that Douglas Crockford recommended in <em>JavaScript: T... | {
"AcceptedAnswerId": "10237",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-19T19:53:19.623",
"Id": "10156",
"Score": "3",
"Tags": [
"javascript",
"ajax"
],
"Title": "Simple XmlHttpRequest object"
} | 10156 |
<p>Is this the easiest way to delete everything between and including the two first quotes (if present) in an <code>std::wstring</code>?</p>
<pre><code>unsigned int firstQuotePos = logFileName.find_first_of(L"\"");
unsigned int secondQuotePos = logFileName.find_first_of(L"\"", firstQuotePos + 1);
if (firstQuotePos !=... | [] | [
{
"body": "<p>C++ is very picky about types.<br>\nYou should always try and use the correct ones:</p>\n\n<pre><code>unsigned int firstQuotePos = logFileName.find_first_of(L\"\\\"\");\nunsigned int secondQuotePos = logFileName.find_first_of(L\"\\\"\", firstQuotePos + 1);\n</code></pre>\n\n<p>should be:</p>\n\n<p... | {
"AcceptedAnswerId": "10164",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-19T20:10:28.053",
"Id": "10157",
"Score": "2",
"Tags": [
"c++",
"strings"
],
"Title": "Deleting everything between two quotes in a string"
} | 10157 |
<p>I successfully created an expression evaluator in C#, and I would like to know if it works well, and what I can do to improve it.</p>
<pre><code> class ExpressionEvaluator2
{
public enum Token
{
None,
Literal,
Variable,
Operator,
Function,
FunctionArgumentS... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-19T21:17:02.010",
"Id": "16172",
"Score": "0",
"body": "A very quick minor thing is I would put braces around your else if statements in the Tokenize method."
}
] | [
{
"body": "<p>It is very inconvenient to force the client to call your methods in a very specific order. I would have a top level API that is easy to use. Have the API take care of all the grunt work for you. In the following example, take notice that I am using <code>decimal</code> instead of <code>double</cod... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-19T20:10:37.943",
"Id": "10158",
"Score": "3",
"Tags": [
"c#",
".net",
"parsing"
],
"Title": "C# expression evaluator review request"
} | 10158 |
<pre><code>string Format(string format_string, T1 p1, T2 p2, ..., TN pn)
</code></pre>
<p>The <code>Format()</code> function takes a copy of <code>format_string</code> and replace occurrences of <code>"___"</code> with the remaining parameters to the function (<code>p1</code>, <code>p2</code>,...). The first occurren... | [] | [
{
"body": "<p>I can't fault the code (assuming it works). Looks good.</p>\n\n<p>But what I would point is that to improve flexibility you should probably use numbered replacement sites.</p>\n\n<p>The problem with format strings is that for I18N and L10N the format strings will be pulled out of the source code a... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-19T21:37:56.377",
"Id": "10163",
"Score": "1",
"Tags": [
"c++",
"strings",
"c++11",
"formatting"
],
"Title": "String format function"
} | 10163 |
<p>I am stuck with some old API that involves COM and ODBC, and I cannot switch to cool things like MEF or entity framework. So, I am working on some wrappers that will help me write less code and also bring some of the type safety back (as you know, COM and SQL do not have type safety, at least not in the same way as ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-20T04:44:01.340",
"Id": "16180",
"Score": "0",
"body": "For sql at least look at MicroORMs like Dapper and Massive. I have used Dapper on a multi-month project and was very happy. Not the end-all be-all but really very nice for most of... | [
{
"body": "<p>I believe you can shorten this by using <a href=\"http://msdn.microsoft.com/en-us/library/dtb69x08.aspx\" rel=\"nofollow\">Convert.ChangeType</a>. Also I altered your catch to handle only <code>InvalidCastException</code> since the name of your <code>bool</code> argument is quite specific. You may... | {
"AcceptedAnswerId": "10166",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-20T00:16:41.120",
"Id": "10165",
"Score": "1",
"Tags": [
"c#",
"linq",
"converting"
],
"Title": "Using strong types on top of COM and ODBC"
} | 10165 |
<p>Just wondering if there was someone out there that could offer help in optimizing my script which "derpifies" images.</p>
<pre><code><?php
/**
* If you don't understand what this does
* you have no hope as a programmer.
*
*/
function usage ( )
{
// Ahhh the marvels of echo, such a wonderful tool
// yet s... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-20T07:28:13.740",
"Id": "16183",
"Score": "38",
"body": "You're not funny. :) Oh, and `echo pathinfo($file)['extension']; // PHP 5.4`"
}
] | [
{
"body": "<pre><code>sed 's/\\(\\/\\/\\|#\\).*$//g' YOUR_FILENAME | sed '/^$/N;/^\\s*$/D'\n</code></pre>\n\n<p>To clarify, that strips comments and multiple blank lines. Generally comments are a good idea. I would not remove them or create shorter names for functions and variables for performance. Any benef... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-20T03:24:47.490",
"Id": "10167",
"Score": "-50",
"Tags": [
"php",
"performance"
],
"Title": "Derpifying Images"
} | 10167 |
<p>For more information, see <a href="http://cakephp.org" rel="nofollow">http://cakephp.org</a>.</p>
| [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-20T07:58:23.423",
"Id": "10171",
"Score": "0",
"Tags": null,
"Title": null
} | 10171 |
CakePHP is a rapid development framework for PHP that provides an extensible architecture for developing, maintaining, and deploying applications. It uses commonly known design patterns like MVC and ORM within the convention over configuration paradigm. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-20T07:58:23.423",
"Id": "10172",
"Score": "0",
"Tags": null,
"Title": null
} | 10172 |
<p>This is a very simple nested property extractor. I wonder if it can be optimised further?</p>
<pre><code>/**
* Extract nested property from object. If nested property cannot be reached, return value of rescue
* @param obj Object
* @param path Can be dot-separated string or array
* @param rescue (optional) defa... | [] | [
{
"body": "<p>Here are some of my thoughts:</p>\n\n<ul>\n<li>I don't see the point in providing the path as a dot separated string, but it may be useful in your application. </li>\n<li>If you keep the dot separated string, then you should consider extracting the recursive function into a separate internal funct... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2012-03-20T09:14:05.807",
"Id": "10176",
"Score": "5",
"Tags": [
"javascript",
"recursion",
"properties"
],
"Title": "javascript property extractor optimisation"
} | 10176 |
<p>This is intended to be part of a generalised solution to the problem of converting any (with some minor restrictions) CSV content into XML. The restrictions on the CSV, and the purpose of the schema should be apparent from the annotations.</p>
<p>The main review criteria I request are:</p>
<ol>
<li>Is it suitable ... | [] | [
{
"body": "<p>(This is more of a comment, than an answer, but there are several longer points I'd like to address which is easier in an answer).</p>\n\n<p>Could you show some use cases for this? Considering that both CSV and XML are both formats for general data storage, I don't see point in converting as CSV f... | {
"AcceptedAnswerId": "10208",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-20T11:21:54.047",
"Id": "10180",
"Score": "6",
"Tags": [
"xml",
"xsd",
"xslt"
],
"Title": "XML Schema for an XML representation of CSV"
} | 10180 |
<p>I have an application which is used for displaying and modifying huge volumes of point cloud data from lidar files (up to few gigabytes each, sometimes loaded in simultaneously). In the app the user is able to view a 2D image of loaded points (from the top) and select a profile to view in another window (from the si... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-22T12:35:01.163",
"Id": "16306",
"Score": "0",
"body": "Are you using a library for your Lidar data? What does LidarPoint look like under the hood?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-22T19:20:3... | [
{
"body": "<p>Profiling is always good to locate bottlenecks.</p>\n\n<p>If quadtree construction is a bottleneck, it might help to use multiple passes. A first pass might only store the x/y values which are all that is needed to determine the structure of the quadtree. For a second pass, the buckets can be pre-... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-20T12:51:08.067",
"Id": "10181",
"Score": "15",
"Tags": [
"c++",
"performance",
"tree",
"opengl"
],
"Title": "Quadtree design"
} | 10181 |
<p>Ok I have a method:</p>
<pre><code>//_seen is defined as a HashSet earlier
public boolean isTerminal(Node node)
{
if (_seen.contains(node.getState()))
{
return true;
}
else
{
_seen.add(node.getState());
return false;
}
}
</code></pre>
<p>What is the nicest way of doi... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-20T13:35:39.780",
"Id": "16189",
"Score": "1",
"body": "What does this function actually do? The name `isTerminal` seems heavily misleading."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-20T14:36:08.613",... | [
{
"body": "<p>Both forms will produce the same result. Choosing between them is a stylistic/aesthetic question.</p>\n\n<p>Many people will claim that the more compact form is easier to read, despite the fact that someone new to Java might not be aware of the fact that the add method of HashMap returns true if t... | {
"AcceptedAnswerId": "10261",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-20T12:55:24.447",
"Id": "10182",
"Score": "6",
"Tags": [
"java"
],
"Title": "Sets, Check and add"
} | 10182 |
<p>This is for a college assignment, it has been submitted but I'd like some general feedback on how to improve it or whether I should be using more functions or less functions.</p>
<p>Also, is my commenting too extreme?</p>
<pre><code>/**
* This program takes two binary integers and performs one of three operations... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-21T12:31:57.067",
"Id": "16238",
"Score": "1",
"body": "Typos in file comment:\n - \"multiple\" should be \"multiply\"\n - \"modulo of\" should be \"result of applying modulo to\"\n - \"it's\" (the contraction for \"it is\") should be ... | [
{
"body": "<p>Good work delineating the functions. You have met several relevant guidelines for each one of your functions. It is reasonably short. It performs one clearly defined operation. It uses a limited amount of conditional logic. Each of its conditional statements has a purpose that is clearly related t... | {
"AcceptedAnswerId": "10219",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-20T15:48:17.043",
"Id": "10186",
"Score": "4",
"Tags": [
"c",
"calculator"
],
"Title": "Calculator supporting multiplication, division, or modulo of two numbers"
} | 10186 |
<p>This script fetches a list of "end-positions" from a MySQL database. The positions are array positions that are the same in both MySQL and R.</p>
<p>Next, the script takes the previous 34 elements for each metric and calculates their correlation with a query series.</p>
<p>The top X highest correlated (in total fo... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-07T04:02:19.500",
"Id": "16201",
"Score": "5",
"body": "Just off the top of my head: 1) Don't name things `c`. It's a very important base R function. 2) Now that you've renamed it, don't sort it twice. Sort it once, and then use `head`... | [
{
"body": "<p>The comments are good; I copy them here so this question has a \"proper\" answer, and add some my own:</p>\n\n<blockquote>\n <p>Just off the top of my head: 1) Don't name things <code>c</code>. It's a very important base R function. 2) Now that you've renamed it, don't sort it twice. Sort it once... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-02-07T03:43:53.527",
"Id": "10191",
"Score": "2",
"Tags": [
"optimization",
"beginner",
"mysql",
"r"
],
"Title": "Script for fetching a list of \"end-positions\" from a MySQL databa... | 10191 |
<p>I have black and white <code>SDL_Surface</code> and I'm trying to change colors, such as from black to white and from white to red. I did it, but it is taking too long to work.</p>
<pre><code>SDL_Surface* tempSurface = SDL_DisplayFormat(textSurface);
for(int i=0;i<256;i++){
SDL_SetColorKey(textSurface,SDL_S... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-20T19:03:18.203",
"Id": "16205",
"Score": "1",
"body": "`C`? `C++`? So this is working but not fast enough?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-20T19:43:01.237",
"Id": "16206",
"Score": ... | [
{
"body": "<p>It would be helpful to know how textSurface is created. There may be a performance win to be had by using, say, a hardware surface instead of a software surface.</p>\n\n<p>If you are using a surface that supports double buffering I would reccomend using SDL_FLip rather than flipping the buffers yo... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-20T18:52:59.543",
"Id": "10193",
"Score": "3",
"Tags": [
"c++",
"optimization",
"c",
"sdl"
],
"Title": "Colors changing in SDL program"
} | 10193 |
<p>I have about 5 of these but I can't figure out how to consolidate them.</p>
<pre><code>$('#togglemass').toggle(function () {
$("#plusmass").attr("src", "minus.png");
},
function () {
$(".plusmass").attr("src", "plus.png");
});
$('#togglestar').toggle(function () {
$(".plusstar").attr("src", "m... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-21T09:03:14.777",
"Id": "16232",
"Score": "1",
"body": "You should explain your use case and show the HTML to this, because I think the optimization could start on the HTML level. For example, I think you should't need to hard code the... | [
{
"body": "<pre><code>$(function() {\n\n var togglePlusMin = function(clicker, img) {\n $(clicker).toggle(function() {\n $(img).attr(\"src\", \"minus.png\");\n }, function() {\n $(img).attr(\"src\", \"plus.png\");\n });\n };\n\n // can be used by\n togglePl... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-20T20:34:27.760",
"Id": "10196",
"Score": "2",
"Tags": [
"javascript",
"jquery"
],
"Title": "Toggling icon images using jQuery"
} | 10196 |
<p>I have three tables</p>
<pre><code>class User < AR::Base
has_many :lexemes, :dependent => :destroy
end
class Lexeme < AR::Base
belongs_to :user
belongs_to :word
end
class Word < AR::Base
has_many :lexemes
end
</code></pre>
<p>This code is storing the word to Words table and assign it to the u... | [] | [
{
"body": "<pre><code>class User < AR::Base\n has_many :lexemes, :dependent => :destroy\n has_many :words, :through => :lexemes\nend\n\nclass Lexeme < AR::Base\n belongs_to :user\n belongs_to :word\nend\n\nclass Word < AR::Base\n has_many :lexemes\n has_many :users, :through => :lexemes... | {
"AcceptedAnswerId": "10543",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-20T20:39:03.990",
"Id": "10197",
"Score": "1",
"Tags": [
"ruby",
"ruby-on-rails"
],
"Title": "activerecord, refactoring the source code"
} | 10197 |
<p>This class is used to draw an old school flame on a canvas element. I'm wondering if there is any way to speed up the <code>fire</code> method. The class is based on old C code.</p>
<pre><code>LayerFire = {
init : function(options, elem) {
this.options = $.extend({
width : '320',
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-21T03:29:57.707",
"Id": "16225",
"Score": "2",
"body": "Do you have a runnable example (perhaps in a jsFiddle)? It's hard to run performance tests on a piece of code that you can't run because you're missing pieces that are need to ma... | [
{
"body": "<p>I'm not really an expert on speed optimization, but here are some thoughts:</p>\n\n<ul>\n<li>You should keep references/copies to often used objects/values instead of accessing them repeatedly through properties, e.g:</li>\n</ul>\n\n<p><b></b></p>\n\n<pre><code>var bufferp = this.bufferp;\nvar wid... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-21T02:36:33.080",
"Id": "10201",
"Score": "3",
"Tags": [
"javascript",
"optimization"
],
"Title": "Optimization of a javascript class flame effect"
} | 10201 |
<p>I've come up with a simple Datasource design which allows me to quickly create Datasources and even abstract it behind Interfaces. Of course I ask myself if I can do something better.</p>
<p>The goal of these classes is to have a simple and easily exchangeable layer which just returns Objects. By easily exchangeabl... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-21T10:25:05.940",
"Id": "16234",
"Score": "0",
"body": "Have you considered using one of the simple one-file ORMs such as Dapper instead?\n\nhttp://code.google.com/p/dapper-dot-net/"
},
{
"ContentLicense": "CC BY-SA 3.0",
"... | [
{
"body": "<p>You can move parameter checks out of locks:</p>\n\n<pre><code>public Item[] GetItems(string search)\n{\n if (string.IsNullOrEmpty(search))\n return new Item() {};\n\n lock(sync)\n {\n CheckConnection();\n\n itemSearcher.Parameters[\"SEARCH\"].Value = search;\n\n ... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-21T10:04:37.607",
"Id": "10207",
"Score": "0",
"Tags": [
"c#"
],
"Title": "Simple Datasource design using connections derived from System.Data.IDbConnection"
} | 10207 |
<p>I've written a small function which displays a div related to an anchor element using data attributes.</p>
<p>The data attribute is used to match the class of the relevant div which is then displayed whilst the others are hidden.</p>
<p>All very basic, however I'm wondering if there is anyway to improve it? Is there... | [] | [
{
"body": "<p><code>$(\".tabs-content\").find(cssClass).show().siblings().hide();</code> is confusing and not easy to read.</p>\n\n<p>Otherwise it seems to be working. As for best practices:</p>\n\n<ul>\n<li>Make sure your content is accessible to non JS users, such as search engines or browsers without JS.</li... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-21T11:07:34.177",
"Id": "10211",
"Score": "2",
"Tags": [
"javascript",
"jquery",
"html"
],
"Title": "jQuery tabs improvement"
} | 10211 |
<p>I just wrote some code that is very representative of a recurring theme (in my coding world lately): repeated logic leads to an instinct to eliminate duplication which results in something that is more complex the tradeoff seems wrong to me (the examples of the negative side aren't worth posting - but this is probab... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-20T21:38:02.960",
"Id": "16239",
"Score": "1",
"body": "As phrased this question would appear to be better asked on Stack Overflow, however, with a change of wording (\"How can I/should I improve this code\") then it would be suitable ... | [
{
"body": "<p>Why not something like...</p>\n\n<pre><code>static void Main(string[] sargs)\n{\n try\n {\n var urls = new DirectTrackRestUrls();\n var restCall = new DirectTrackRestCall();\n var logger = new ConsoleLogger();\n Args args = (Args)Enum.Parse(typeof(Args), string.Jo... | {
"AcceptedAnswerId": "10215",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-20T20:54:19.757",
"Id": "10214",
"Score": "3",
"Tags": [
"c#"
],
"Title": "How to deal with elimination of duplicate logic vs. cost of complexity increase?"
} | 10214 |
<p>I just began to study Scala (coming from Python I had quite a few problems with types) and I want to know if my first code to solve a real problem is nicely done or if there is some points that need to be redone.</p>
<p>The problem I had to solve is for an homework but my code is already working, I just want to kno... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-22T12:23:59.547",
"Id": "16305",
"Score": "0",
"body": "`new Container(capacity, filled + toAdd)` -> no `new` needed for case classes."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-16T03:23:25.827",
"... | [
{
"body": "<p>It seems pretty reasonable, actually. I'm confused by the <code>ArraySeq</code>. Also, I'd rewrite this:</p>\n\n<pre><code> if (Option(parent) != None) parent :: parent.ancesters\n else List[State]()\n</code></pre>\n\n<p>As</p>\n\n<pre><code> Option(parent).map(parent... | {
"AcceptedAnswerId": "55265",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-21T17:31:22.283",
"Id": "10224",
"Score": "5",
"Tags": [
"scala",
"homework",
"breadth-first-search"
],
"Title": "Pouring water problem"
} | 10224 |
<p>I have an API that takes a class as a configuration parameter, but I don't want to load the class (I'm using Rails) at the time that I'm setting up the API. I figured I could get around this by passing it an object that acts like the class in every way (by delegating to it) but doesn't actually reference the class, ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-25T08:13:05.030",
"Id": "16426",
"Score": "1",
"body": "I don't get it? What is your question?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-26T23:23:59.423",
"Id": "16525",
"Score": "0",
"bod... | [
{
"body": "<p>You could pass in a string instead of a proc and use <code>Object.const_get()</code>.</p>\n\n<pre><code>class_const = Object.const_get 'String'\n=> String\nclass_const.new \"hello\"\n=> \"hello\"\n</code></pre>\n\n<p>With a <code>call</code>-able constructor.</p>\n\n<pre><code>constructor = ... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-21T18:24:19.503",
"Id": "10226",
"Score": "3",
"Tags": [
"ruby",
"object-oriented"
],
"Title": "Delegating to a lazily loaded object in Ruby"
} | 10226 |
<p>Prompted by <a href="https://stackoverflow.com/questions/9783943/increasing-decreasing-sequence">this question</a> on Stack Overflow, I wrote an implementation in Python of the <a href="http://en.wikipedia.org/wiki/Longest_increasing_subsequence" rel="nofollow noreferrer">longest increasing subsequence problem</a>. ... | [] | [
{
"body": "<pre><code>from random import randrange\nfrom itertools import islice\n\ndef randomSeq(max):\n</code></pre>\n\n<p>The python style guide recommend that you use space_with_underscores for function names</p>\n\n<pre><code> while True: yield randrange(max)\n\n\n\ndef randomList(N,max):\n return list(i... | {
"AcceptedAnswerId": "10231",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-21T21:34:29.410",
"Id": "10230",
"Score": "7",
"Tags": [
"python",
"dynamic-programming"
],
"Title": "Python implementation of the longest increasing subsequence"
} | 10230 |
<p>I think this code cannot be shortened much, especially because I only consider two cases. But maybe there's a language construct that I don't know that would help.</p>
<pre><code>if (subControl.inverted) {
newValue = subControl.value+(float)(1.0f/(float)subControl.decorator.ticks);
if (newValue > 1)
... | [] | [
{
"body": "<p>Not a lot shorter, but a bit...</p>\n\n<pre><code>float ticks = (float)(1.0f/(float)subControl.decorator.ticks);\nnewValue = subControl.value + subControl.inverted ? ticks : - ticks;\n\nif (subControl.inverted && newValue > 1) {\n newValue = 0;\n} else if (!subControl.inverted &... | {
"AcceptedAnswerId": "10238",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-21T23:34:31.223",
"Id": "10232",
"Score": "0",
"Tags": [
"objective-c"
],
"Title": "Shorten This Code with... blocks?"
} | 10232 |
<p>I have a ASP.NET Web Forms project, and I want to build calls to .aspx pages in a strongly-typed fashion. I ended up rolling my own serializer that takes simple structs and saves them to/loads them from the query string. What do you think? Is my approach sane? Is there an accepted alternative I don't know about? Any... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2016-02-08T17:52:21.987",
"Id": "222197",
"Score": "0",
"body": "The line that parses an empty string seems a bit of a hack to get a NamveValueCollection. `var queryStringBuilder = HttpUtility.ParseQueryString(\"\");` Is there a reason for thi... | [
{
"body": "<p>One of my favorite patterns for handling URL parameters in WebForms is the WebNavigator - <a href=\"http://polymorphicpodcast.com/shows/webnavigator/\" rel=\"nofollow\">http://polymorphicpodcast.com/shows/webnavigator/</a></p>\n\n<p>If you're going through these kinds of Strongly-typed interaction... | {
"AcceptedAnswerId": "10424",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-22T01:53:58.017",
"Id": "10234",
"Score": "4",
"Tags": [
"c#",
".net",
"asp.net",
"parsing",
"reflection"
],
"Title": "Query String Serializer"
} | 10234 |
<p>I've written this brief function for calculating which calendar year a student would be in Year 1 based on their DOB (date of birth). In 1998 there was a change in the DOB cut points for starting Year 1, hence the need for a function. </p>
<pre><code>year1 <- function(x){
if(x <= as.Date("1996-12-31")) {o... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-22T04:32:54.570",
"Id": "16293",
"Score": "0",
"body": "I see, primary school in Australia for children six to seven years old is called year 1."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-22T04:36:05.8... | [
{
"body": "<p>I think this is equivalent to your function.</p>\n\n<pre><code>year1 <- function(dob) as.numeric(format(dob, \"%Y\")) + 6 +\n (as.Date(\"1997-07-01\") <= dob & 7 <= as.numeric(format(dob, \"%m\")))\n</code></pre>\n\n<p>You would run it like this.</p>\n\n<pre><code>> test <- c... | {
"AcceptedAnswerId": "10240",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-22T03:03:40.660",
"Id": "10235",
"Score": "3",
"Tags": [
"datetime",
"r"
],
"Title": "Calculating calendar year for a student based on DOB"
} | 10235 |
<p>This is a pagination program that works perfectly fine. I want to be able to save this code and reuse it whenever I need it as a method in jQuery (read: <code>$(myData).pagination()</code>).</p>
<p>jQuery:</p>
<pre><code>$(document).ready(function(){
var post = $(".note > li")
var page= 1;
var posts... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-22T12:50:11.707",
"Id": "16307",
"Score": "0",
"body": "There is a really good tutorial at http://docs.jquery.com/Plugins/Authoring"
}
] | [
{
"body": "<p>Without going the whole plugin route (to which I would suggest using the jQueryUI widget design), I have made a few modifications to clean up your code:</p>\n\n<p><a href=\"http://jsfiddle.net/KALpP/2/\" rel=\"nofollow\">Commented version over at jsfiddle</a></p>\n\n<pre><code>(function ($, Math) ... | {
"AcceptedAnswerId": "11179",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-22T12:15:16.173",
"Id": "10246",
"Score": "2",
"Tags": [
"javascript",
"jquery",
"performance",
"html",
"pagination"
],
"Title": "Reusable pagination"
} | 10246 |
<p>I'm trying to implement a custom made 2D geometry library. Originally I was looking at the problem of intersections of many circles but wanted to widen the scope of the code to deal with many future geometry based problems.</p>
<p>I already have a vector (2D) class defined. I wish to derive all my other geometrical... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-22T19:10:49.130",
"Id": "16324",
"Score": "0",
"body": "Consider using auto-properties with `get; private set;` in the `Segment` class. I would also chain constructors like so: `public Segment() : this(s: null, e: null)`. Finally, can ... | [
{
"body": "<p>First of all I really would like to have a good computational library in C#, will be your OS?\nAnyway my two cents:</p>\n\n<ul>\n<li>I really appreciate the fact you are considering circular segmants to\n( arcs ), if you manage to use it properly everywere (\ndistance/intersection, offseting ) thi... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-22T13:54:51.470",
"Id": "10247",
"Score": "7",
"Tags": [
"c#",
"computational-geometry"
],
"Title": "Implementing a collection class to represent a Path of Segments"
} | 10247 |
<p>I'm working with some strange APIs that requires the dates to be sent in the YYYYMMDD format.</p>
<p>I was thinking of doing something like this:</p>
<pre><code>string date = string.Concat(DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day);
</code></pre>
<p>Is there a better practice?</p>
| [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-22T18:50:08.157",
"Id": "16322",
"Score": "5",
"body": "Be careful when calling `DateTime.Now` several times like this. For example, if `DateTime.Now.Month` is called just before the midnight of 31 January and `DateTime.Now.Day` after ... | [
{
"body": "<p>Yes there is: <a href=\"http://msdn.microsoft.com/en-us/library/8kb3ddd4.aspx\">Date Formatting</a></p>\n\n<pre><code>var dateString = DateTime.Now.ToString(\"yyyyMMdd\");\n</code></pre>\n",
"comments": [],
"meta_data": {
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
... | {
"AcceptedAnswerId": "10252",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-03-22T16:10:26.387",
"Id": "10250",
"Score": "4",
"Tags": [
"c#",
"strings",
"datetime",
"formatting"
],
"Title": "Formatting a datetime string in the YYYYMMDD format"
} | 10250 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.