body
stringlengths
25
86.7k
comments
list
answers
list
meta_data
dict
question_id
stringlengths
1
6
<p>Here's my first significant Haskell program - it presents a count of each word seen on stdin. Any comments are welcome.</p> <pre><code>import Data.Map emptyMap = empty :: Map String Integer countWord m s = alter (\x -&gt; case x of Nothing -&gt; Just 1 ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-12T04:26:42.500", "Id": "13944", "Score": "2", "body": "You might like `fromListWith`; you can replace `foldl countWord emptyMap` with something like `fromListWith (+) . flip zip (repeat 1)` and skip defining `countWord` at all." } ]
[ { "body": "<p>Your usage of <code>Data.Map</code> is sound. I see nothing that could be improved as long as you stay with <code>Data.Map</code>.</p>\n\n<p>If you give all of the functions explicit type declarations, so that the Monomorphism Restriction doesn't apply, you can use generic integral types:</p>\n\n<...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-12T03:34:39.100", "Id": "8904", "Score": "7", "Tags": [ "haskell" ], "Title": "My Haskell word count program" }
8904
<p>This little script makes list items selectable and draggable. I'm pretty new to programming in general, and even more so to Javascript. Most of my background is in PHP and some C++. On the large, I don't think this is the proper way to be writing code in JavaScript. I know global variables are bad, but I'm not used ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-13T13:47:02.937", "Id": "14004", "Score": "0", "body": "On the `var`: a variable declared with var is in the local scope, one without is in the global scope. So when you assign to it in one function, it is available in the other as the...
[ { "body": "<p>Edit: I missed that you were talking about the HTML5 drag and drop stuff, but I think this still kind of applies, so I'll leave it here for now. The idea is to \"namespace\" stuff into a singleton object.</p>\n\n<hr>\n\n<p>The usual approach is to use a singleton object and attach all those functi...
{ "AcceptedAnswerId": "8914", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-12T07:53:35.333", "Id": "8906", "Score": "4", "Tags": [ "javascript", "html5" ], "Title": "Drag and Drop file handler" }
8906
<p>blah - not even sure if that is the correct way to say it. Basically I have this</p> <pre><code>public class XmlAccess { public XmlAccess() { } public string ApplicationPath = ""; public string DBServer = ConfigurationManager.AppSettings["DB2_Server"]; public string DBName = ConfigurationManager.A...
[]
[ { "body": "<p>Does any code set those fields?</p>\n\n<p>Turn them into properties, then extract the interface that includes the properties. I recommend against letting any code set them, if at all possible.</p>\n", "comments": [ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012...
{ "AcceptedAnswerId": "8908", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-08T03:15:33.963", "Id": "8907", "Score": "4", "Tags": [ "c#" ], "Title": "spaghetti code for lunch: refactoring a bunch of fields that always get initialized" }
8907
<p>I have the following block of code which adds pins including descriptions and links onto a Google map. How can I refactor it so that I can add pins easier and without so much redundant code?</p> <pre><code>var map; function initializeMap() { var myOptions = { zoom: 9, center: new google.maps.LatLng(42.2340...
[]
[ { "body": "<p>The simplest solution is extract one function that will form the marker from the parameters and them call it as many times as markers count is:</p>\n\n<pre><code>var markers = []; // probably you don't need this array\nfunction CreateMarker(lat, lng, markerTitle, markerUrl)\n{\nvar marker = new...
{ "AcceptedAnswerId": "8913", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-10T00:18:24.230", "Id": "8912", "Score": "2", "Tags": [ "javascript", "jquery", "google-maps" ], "Title": "Adding pins onto a Google map" }
8912
<p>I'm new to Fortran, and this is pretty much my first escapade. Below is a function that I wrote which relies on calls to LAPACK. The function is sat in a module with some other functions and works perfectly, but seeing as this is really the workhorse of the program I'm building I want to squeeze it hard for performa...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-12T12:53:11.480", "Id": "13966", "Score": "0", "body": "Is there a directive to instruct the syntax highlighter on which language to highlight for?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-13T04:43:0...
[ { "body": "<p>Your code looks good. When <code>s</code> is small, there should be no need to use BLAS instead of <code>matmul()</code>. I like you exploit the shorthand array notation and the forall construct.</p>\n\n<p>Debatable is your use of explicit shaped arrays. They could be very slightly faster, because...
{ "AcceptedAnswerId": null, "CommentCount": "11", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-12T10:14:18.947", "Id": "8917", "Score": "5", "Tags": [ "beginner", "mathematics", "matrix", "fortran" ], "Title": "High performance exponential of a skew Hermitian matrix in Fo...
8917
<p>I have implemented <a href="http://en.wikipedia.org/wiki/Zeller%27s_congruence" rel="nofollow">Zeller's algorithm</a> in Python to calculate the day of the week for some given date. I would like to get some feedback on how I can make the code shorter and more elegant: </p> <pre><code>def input_value(input_name, pro...
[]
[ { "body": "<pre><code>def input_value(input_name, prompt, min_num, max_num):\n</code></pre>\n\n<p><code>input_name</code> is always a number - why are you calling it a 'name'? Also, there's no need to take it as an argument, since you never use its initial value in your function.</p>\n\n<pre><code> while Tru...
{ "AcceptedAnswerId": "8919", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-12T11:41:52.803", "Id": "8918", "Score": "2", "Tags": [ "python", "algorithm", "datetime" ], "Title": "Zeller's algorithm in Python" }
8918
<p><strong>My inspiration for creating this protocol came from iOS 5's "dismissViewControllerAnimated:completion:" addition to UIViewController. I wanted this functionality in iOS 4.3. I find using the modal view's -viewDidDissapear to invoke methods on the presenting view controller work's very well. One benefit is ...
[]
[ { "body": "<p>Two light suggestions:</p>\n\n<ul>\n<li>disappear has one s and two ps.</li>\n<li>the word \"block\" to describe a block is accurate but not very descriptive. OK, so I need to pass a block, but I can see that from the parameter list. What the block is <em>for</em> should be explained in the method...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-12T18:43:32.737", "Id": "8924", "Score": "2", "Tags": [ "objective-c", "ios" ], "Title": "iOS4 alternatives for dismissViewControllerAnimated:completion:" }
8924
<p>This is from an answer to my own <a href="https://stackoverflow.com/q/9242733/12048">StackOverflow question</a> on how to efficiently find a <a href="http://en.wikipedia.org/wiki/Regular_number" rel="nofollow noreferrer">regular number</a> that is greater than or equal to a given value.</p> <p>I originally implemen...
[]
[ { "body": "<pre><code>from itertools import ifilter, takewhile\nfrom Queue import PriorityQueue\n\ndef nextPowerOf2(n):\n</code></pre>\n\n<p>Python convention says that function should be named with_underscores</p>\n\n<pre><code> p = max(1, n)\n while p != (p &amp; -p):\n</code></pre>\n\n<p>Parens not nee...
{ "AcceptedAnswerId": "8931", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-12T23:29:25.053", "Id": "8928", "Score": "5", "Tags": [ "python" ], "Title": "Find the smallest regular number that is not less than N (Python)" }
8928
<p>It compiles, works well, solves my problem of zipping old or big log files and removes them from a hard drive. However, following <a href="https://stackoverflow.com/a/9190590/692020">this answer</a>, I would like to know what was wrong with the code.</p> <pre><code>Dir.foreach(FileUtils.pwd()) do |f| if f.end_w...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-11-03T01:39:05.067", "Id": "28985", "Score": "1", "body": "Ruby's indentation style is usually 2 spaces, just as a minor heads up." } ]
[ { "body": "<p>My proposal, please see also the comments in the code.</p>\n\n<pre><code>require 'zlib'\nMAX_FILE_SIZE = 1024 #One KB\n\n#Use a glob to get all log-files\nDir[\"#{Dir.pwd}/*.log\"].each do |f|\n #skip file, if file is small\n next unless File.size(f) &gt; MAX_FILE_SIZE\n #Make a one line info\n...
{ "AcceptedAnswerId": "8934", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-12T23:59:24.470", "Id": "8929", "Score": "3", "Tags": [ "ruby", "file-system", "file", "logging", "compression" ], "Title": "GZip archiver for log files" }
8929
<p>I've been playing with Clojure for the last few evenings, going through the well known 99 problems (I'm using <a href="http://aperiodic.net/phil/scala/s-99/" rel="nofollow">a set adapted for Scala</a>).</p> <blockquote> <p><strong>Problem 26</strong></p> <p>Given a set <em>S</em> and a no. of items <em>K</em...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-02T01:38:30.703", "Id": "34042", "Score": "2", "body": "Check how it is done in math.combinatorics https://github.com/clojure/math.combinatorics/blob/master/src/main/clojure/clojure/math/combinatorics.clj#L69" } ]
[ { "body": "<p>I'm currently reading \"Joy of Clojure\" so I'm (very) far from being \"fluent\" in Clojure but what I noticed is:</p>\n\n<ul>\n<li>your solution is clever but quite complicated, you use \"imperative\" habits like indexed iteration</li>\n<li>try to keep with simple abstractions like sequence <b>fi...
{ "AcceptedAnswerId": "9569", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-13T00:21:33.320", "Id": "8930", "Score": "5", "Tags": [ "clojure", "combinatorics" ], "Title": "Enumerate k-combinations in Clojure (P26 from 99 problems)" }
8930
<p>I saw this question <a href="https://codereview.stackexchange.com/q/7226/7153">"Is this implementation of an Asynchronous TCP/UDP Server correct"</a> and it is very similar to what I want to do but it goes about it in a different way so I am wondering if anyone would mind doing some constructive critism on my metho...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-18T08:17:48.860", "Id": "22229", "Score": "0", "body": "No comment on the listener at the mo, but a quick suggestion would be to make Logger private unless there's a specific reason you want to expose it to the world. I would then set...
[ { "body": "<p>I'd raise the events <code>DataReceived</code> and <code>FatalError</code> on a different thread, to avoid blocking the TCP work. To elaborate this point, I suggest you take a look at <a href=\"https://github.com/kayak/kayak/\" rel=\"nofollow\">Kayak</a>'s implementation (it's an implementation of...
{ "AcceptedAnswerId": "14842", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-13T12:22:54.503", "Id": "8935", "Score": "8", "Tags": [ "c#", ".net" ], "Title": ".Net TCP Server" }
8935
<p>i'm rewriting some Matlab code to c++ using <a href="http://arma.sourceforge.net/docs.html#syntax" rel="nofollow">armadillo</a>, a libs for linear algebra. really good libs, IMHO. but i had to translate some matlab construct because armadillo isn't matlab.</p> <p>i want to share my little snippet because i think th...
[]
[ { "body": "<p>Cannot say much about the speed, but here are two observations:</p>\n\n<ul>\n<li><p>Your implementation of any appears to give true and false in the opposite way that Matlab would give them.</p></li>\n<li><p>If you want to mimic the n dimensional matrix sum in Matlab, the output should not be a nu...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-13T14:35:00.433", "Id": "8938", "Score": "4", "Tags": [ "c++", "matlab" ], "Title": "MATLAB and Armadillo, hints on translating" }
8938
<p>I'm writing a checkout form for purchasing online tests. You can buy a certification or a recertification, as well as a pdf or book study manual.</p> <p>I'm using Jinja2 templates to provide test data into the Javascript. The test object is a dictionary with the following structure. All prices are in cents.</p> ...
[]
[ { "body": "<p>You're right, templating JavaScript code in the way you're doing is messy and usually a bad option. If possible it's almost always better to pass in a single JSON object with all of the values you need and then operate on that object in JavaScript. I don't know Python but something like this:</p>\...
{ "AcceptedAnswerId": "8941", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-13T15:14:32.993", "Id": "8939", "Score": "0", "Tags": [ "javascript", "python", "html" ], "Title": "How would you improve this point of interaction between Python and Javascript?" ...
8939
<p>I wrote some code which divides a line through the words of the text so that each substring is no longer than <code>MaxWidth</code>. It works well, but it's very slow.</p> <pre><code>Pattern pattern = Pattern.compile("(.{1," + symbols + "}(\\b|\\s))"); // symbols - MaxWidth Pattern pattern2 = Pattern.compile("\\s.*...
[]
[ { "body": "<p>Few thought,</p>\n\n<p>You do a while loop ( while( matcher.find() ) to find all matchs, then you do a for loop to deal with it. I think that can be done in only one loop.</p>\n\n<p>in you last for loop, you could remove the first if :</p>\n\n<pre><code> for(i = 0; i &lt; (temp.size() -1); i++...
{ "AcceptedAnswerId": "8943", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-13T15:52:36.657", "Id": "8940", "Score": "2", "Tags": [ "java", "performance", "strings" ], "Title": "Breaking a string into substrings" }
8940
<p>I have recently been trying to improve the quality of my code. Towards this goal I want to start writing unit tests and I also am trying to implement things i have read as best practices. I have read that its better to have a class raise exceptions over returning error codes. In the below class I have an <strong>ini...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-13T16:15:33.803", "Id": "14008", "Score": "0", "body": "I can't seem to get the code block to format correctly." } ]
[ { "body": "<p>You raise odd exceptions. <code>TypeError</code> should be raised when the type of an object is incorrect. But you are raising for not following business rules. <code>AttributeError</code> should be raised when an attribute is not available, not when you fail validation. You should really either r...
{ "AcceptedAnswerId": "8945", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-13T16:11:22.107", "Id": "8944", "Score": "1", "Tags": [ "python" ], "Title": "Best way to test for required attributes of a classes __init__ method" }
8944
<p>I'm working on a <a href="http://en.wikipedia.org/wiki/Conway%27s_Game_of_Life" rel="nofollow">Game Of Life</a> clone as my first project. I'm still relatively new to programming, so my code is probably not really optimised.</p> <p>The biggest bottleneck is in my <code>Start()</code> method, but that contains a lot...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-14T16:06:43.800", "Id": "14055", "Score": "0", "body": "This is too awesome... favourited!" } ]
[ { "body": "<ol>\n<li><p>I would advise you to count neighbours from alive points, not for cells to be checked. Null a 100x100 int array Neighbours. For every alive cell add +1 into every neighbouring cell in Neighbours. After the pass you have number of neighbours for the every cell, but time used is about 1/4 ...
{ "AcceptedAnswerId": "8947", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-13T19:23:26.657", "Id": "8946", "Score": "5", "Tags": [ "c#", "performance", "game-of-life" ], "Title": "Garbage collection loop in Game of Life" }
8946
<p>I need to count non-transparent pixels in a canvas. I am pretty sure there is a nice and elegant syntax for doing this. Note that the data returned by <code>getImageData</code> is not a regular array and cannot be sliced, for example, or it does not have a <code>reduce</code> method.</p> <pre><code>data = context.g...
[]
[ { "body": "<p>What about this?! </p>\n\n<pre><code>data = context.getImageData(0, 0, canvas.width, canvas.height).data\ncount = 0\ncount++ for x, i in data when (i+1) % 4 is 0 and x &gt; 0\n</code></pre>\n", "comments": [], "meta_data": { "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0"...
{ "AcceptedAnswerId": "8981", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-14T05:47:14.923", "Id": "8957", "Score": "0", "Tags": [ "beginner", "coffeescript" ], "Title": "Count non-transparent pixels in a canvas" }
8957
<p>This is a script I wrote to find the <em>n</em> biggest files in a given directory (recursively):</p> <pre><code>import heapq import os, os.path import sys import operator def file_sizes(directory): for path, _, filenames in os.walk(directory): for name in filenames: full_path = os.path.joi...
[]
[ { "body": "<p>You could replace your function with:</p>\n\n<pre><code>file_names = (os.path.join(path, name) for path, _, filenames in os.walk(directory)\n for name in filenames)\n\nfile_sizes = ((name, os.path.getsize(name)) for name in file_names)\n</code></pre>\n\n<p>However, I'm not sure that really ...
{ "AcceptedAnswerId": "8973", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-14T05:54:29.153", "Id": "8958", "Score": "6", "Tags": [ "python" ], "Title": "n largest files in a directory" }
8958
<p>This is my first 'large' JS project and I was hoping someone could have a quick look and suggest better coding practices, how it could be cleaner etc. It revolves around a one page web-site and contains some AJAX. </p> <pre><code> $(document).ready(function () { var curpoints; //int globals ...
[]
[ { "body": "<p>Giving your code a quick look does not make me understand a single line.\nWill you understand it if you go away for two weeks?</p>\n\n<p>Giving it a second look, I notice you've added some short comments describing each block.\nThat tells me each block is an excellent candidate for its own functio...
{ "AcceptedAnswerId": "8960", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-14T09:11:29.967", "Id": "8959", "Score": "2", "Tags": [ "javascript", "php", "jquery", "ajax" ], "Title": "Single-page personal portfolio site with AJAX navigation" }
8959
<p>I build a collection to ensure only valid entities in an array so I don't have to validate after every function / method call as I could rely on the collection to have only valid entities stored. </p> <pre><code>class WorldCollection implements Collection, ArrayAccess { private $container = array(); privat...
[]
[ { "body": "<h2>Design</h2>\n\n<p>Dependency injection is very useful when you have multiple implementations of a given dependency. If you don't plan implementing another <code>Validator</code>, then it's probably premature abstraction. I'll assume here that you have other <code>Validator</code> implementations....
{ "AcceptedAnswerId": "9717", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-14T13:21:48.403", "Id": "8962", "Score": "4", "Tags": [ "php", "design-patterns", "collections" ], "Title": "Entity collection best practice (separation of concerns, dependency inj...
8962
<p>I wrote code in python that works slow. Because I am new to python, I am not sure that I am doing everything right. My question is what I can do optimally? About the problem: I have 25 *.json files, each is about 80 MB. Each file just contain json strings. I need make some histogram based on data.</p> <p>In this p...
[]
[ { "body": "<p>Python uses a surprisingly large amount of memory when reading files, often 3-4 times the actual file size. You never close each file after you open it, so all of that memory is still in use later in the program.</p>\n\n<p>Try changing the flow of your program to</p>\n\n<ol>\n<li>Open a file</li>\...
{ "AcceptedAnswerId": "8966", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-10T03:51:37.250", "Id": "8963", "Score": "6", "Tags": [ "python", "json" ], "Title": "python: is my program optimal" }
8963
<p>I'm using manually implemented properties to handle sharing code between forms intended to edit a base object, and those intended to edit a derived version. My current setup works as long as everyone accesses the property and not the base object; but after spending an hour or so tracking down a bug that was due to ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-14T16:37:48.693", "Id": "14058", "Score": "0", "body": "Am I overlooking a tag that would be appropriate for inheritance problems?" } ]
[ { "body": "<p>Judging from the code you provided, the program is behaving as if you are using the new keyword. This causes your property to behave differently based upon whether your form is used in the context of type DataObjectEditForm versus type DataObjectExEditForm.</p>\n\n<p>To clarify:</p>\n\n<pre><code...
{ "AcceptedAnswerId": "8971", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-14T16:36:36.947", "Id": "8968", "Score": "1", "Tags": [ "c#" ], "Title": "Change type of property in derived class" }
8968
<p>I've stripped this down to its bare bones removing stopping/cancellation logic etc... to keep it simple.</p> <p>The <code>Producer</code> is a very simple class containing a timer. At regular intervals the <code>TimerOnElapsed</code> will let the host now that it has another batch of items available. The onus is o...
[]
[ { "body": "<p>As a matter of being thread-safe, you should replace this:</p>\n\n<pre><code> private void TimerOnElapsed(object sender, ElapsedEventArgs e)\n {\n if (BatchAvailable != null)\n BatchAvailable(sender , e);\n }\n</code></pre>\n\n<p>with this:</p>\n\n<pre><code> private ...
{ "AcceptedAnswerId": "8976", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-14T18:25:43.170", "Id": "8972", "Score": "6", "Tags": [ "c#", "task-parallel-library", "producer-consumer" ], "Title": "Producer / Consumer implementation for Parallel Processing i...
8972
<h2>The problem</h2> <hr /> <p>I'm trying to position a chosen element so that it's always horizontally aligned against the right-hand side of the page, and vertically aligned with the center of the web browser's vertical inner scrollbar, i.e. the part of the scrollbar that moves as you scroll up and down the page. The...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-15T05:44:35.857", "Id": "14095", "Score": "0", "body": "Is this a typo: `settings.scrollbar_button_height` vs. just `scrollbar_button_height`?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-16T19:55:52.773...
[ { "body": "<p>What is wrong with:</p>\n\n<pre class=\"lang-html prettyprint-override\"><code>&lt;body&gt;\n ...\n &lt;div id=\"myfloatingElement\"&gt;This is the element&lt;/div&gt;\n&lt;/body&gt;\n</code></pre>\n\n<p>css:</p>\n\n<pre class=\"lang-css prettyprint-override\"><code>#myfloatingElement\n{\n ...
{ "AcceptedAnswerId": "9161", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-14T21:22:28.010", "Id": "8977", "Score": "2", "Tags": [ "javascript", "jquery", "css" ], "Title": "Anchoring an element to the browser's vertical scrollbar" }
8977
<p>I've written a DOM element selector engine that I'm really quite happy with, and I'd love to hear some opinions on it from my fellow JavaScripters :D</p> <p>It's called Atomic, and I've got a repository for it over at GitHub - and I've also included the code below...</p> <p>Check it out (if you're in the mood) and...
[]
[ { "body": "<p>Some things I noticed:</p>\n\n<ol>\n<li>You don't need a semicolon after almost any case you use it after a <code>}</code> (see <a href=\"https://stackoverflow.com/questions/2717949/javascript-when-should-i-use-a-semicolon-after-curly-braces\">https://stackoverflow.com/questions/2717949/javascript...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-14T21:56:20.387", "Id": "8979", "Score": "6", "Tags": [ "javascript", "api" ], "Title": "Atomic elements selector engine" }
8979
<p>I need to allow incoming HTML in string parameters in my projects action methods, so we have disabled Input Validation. I have a good HTML sanitizer; the review I am interested in is the way I bound it into my project.</p> <p>I have the following Model Binder:</p> <pre><code> public class EIMBaseModelBinder : ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2015-11-16T23:22:24.907", "Id": "204468", "Score": "0", "body": "I've rolled back Rev 3 → 2, for editing away an issue that was helpfully pointed out in an answer." } ]
[ { "body": "<p>Can't comment on whether there is a better way or a better place in the framework to do this but some general remarks:</p>\n\n<ol>\n<li><p>This doesn't make much sense: <code>stringVal.IsNullOrEmpty()</code> - should be <code>string.IsNullOrEmpty(stringVal)</code>.</p></li>\n<li><p>You are inconsi...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-14T22:15:43.320", "Id": "8980", "Score": "7", "Tags": [ "c#", "asp.net-mvc-3" ], "Title": "ASP.NET MVC 3 ModelBinder with string sanitizing" }
8980
<p>While implementing auto refreshing div in jQuery that fetches updates on posts periodically as can be seen on Twitter, Facebook etc.</p> <p>I had to think about making the refresh as efficient as possible. I decided to send a request to the server every 30 seconds - 1 minute. And, the request will be sent only if t...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-14T22:47:54.317", "Id": "14079", "Score": "1", "body": "This seems like a sensible model, since you can't setup a proper Observer pattern. You could send out an AJAX request with no timeout, and have the server not respond until it nee...
[ { "body": "<p>If this is for a complex web application, I would recommend using some sort of MVC framework. Personally I prefer backbone.js. Here are some great resources that should help you develop a maintainable app, as well help with updating and refreshing views. </p>\n\n<p>MVC explanation: <a href=\"http:...
{ "AcceptedAnswerId": null, "CommentCount": "8", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-14T22:42:45.083", "Id": "8982", "Score": "1", "Tags": [ "javascript", "jquery" ], "Title": "Auto refreshing div in jQuery" }
8982
<p>What's a better and more elegant way of writing this:</p> <pre><code>$('#footer form').submit(function(event) { event.preventDefault(event); $('#footer form .preload').spin(opts); $.post('contact.php', $(this).serialize(), function(response) { $('#footer form .preload div').remove(); $('...
[]
[ { "body": "<p>First thing I would do is cache some selectors, like the form:</p>\n\n<pre><code>$form = $('#footer form');\n</code></pre>\n\n<p>And then you can use it like:</p>\n\n<pre><code>$form.find('h3');\n</code></pre>\n", "comments": [ { "ContentLicense": "CC BY-SA 3.0", "Creatio...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-15T01:49:46.240", "Id": "8984", "Score": "1", "Tags": [ "javascript", "jquery" ], "Title": "jQuery cleaner form submit function" }
8984
<p>I need to model an IP address and thought using a state machine (the state_machine gem) would be a good idea. </p> <p>An IP has the following characteristics:</p> <ol> <li>It is assigned to a server.</li> <li>It can be in state unbound (implies unprotected), bound (implies protected), reserved.</li> <li>It has sev...
[]
[ { "body": "<p><em>Better late than never.</em></p>\n\n<p>Yes, a state machine makes sense here. You've chosen good names and your coding style is good.</p>\n\n<p>A few comments:</p>\n\n<p>The \"puts\" lines appear to be for debugging. If that is so, <em>and</em> they are going to remain in the code, I would c...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-15T08:26:50.427", "Id": "8988", "Score": "6", "Tags": [ "ruby", "state" ], "Title": "Usage of state machine to model lifetime of an IP address" }
8988
<p>I have a <code>Dictionary&lt;string,string&gt;</code> and want to flatten it out with this pattern:</p> <pre><code>{key}={value}|{key}={value}|{key}={value}| </code></pre> <p>I tried with a LINQ approach at first but couldn't solve it, so I ended up writing an extension method like this:</p> <pre><code>public sta...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-02T17:47:38.933", "Id": "53980", "Score": "0", "body": "I would recommend declaring the concerned parameter in the Exception as follows: `throw new ArgumentException(\"Parameter can not be null.\", \"source\")`" }, { "ContentLi...
[ { "body": "<p>Something like this should work:</p>\n\n<pre><code>public static string ToString(this Dictionary&lt;string,string&gt; source, string keyValueSeparator, string sequenceSeparator)\n{\n if (source == null)\n throw new ArgumentException(\"Parameter source can not be null.\");\n\n var pairs = sour...
{ "AcceptedAnswerId": "8993", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-15T11:05:47.983", "Id": "8992", "Score": "28", "Tags": [ "c#", "strings", "linq", "hash-map" ], "Title": "LINQ approach to flatten Dictionary to string" }
8992
<pre><code>/** * Implements hook_field_validate(). * * @param string $entity_type * @param object $entity * @param array $field * @param array $instance * @param array $langcode * @param array $items * @param array $errors * * @return void */ function field_validate($entity_type, $entity, $field, $instance,...
[]
[ { "body": "<p>Ok, did not noticed that, then:</p>\n\n<p>@param int[int][string] $items</p>\n\n<p>foreach($items as $k => $e){...}</p>\n\n<p>here $k is int, $e is int[string].</p>\n\n<p>In the general case, if</p>\n\n<p>@param T[I1][I2][I3] $items</p>\n\n<p>then</p>\n\n<p>foreach($items as $k => $e){...}</p>\n\n...
{ "AcceptedAnswerId": "9034", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-15T12:13:31.080", "Id": "8995", "Score": "1", "Tags": [ "php" ], "Title": "What docblock definition on this function will satisfy PHPLint?" }
8995
<p>I'm a newbie to Python, and I was wondering whether anyone could give me any pointers on improving the following code:</p> <pre><code>import pygame, sys, time from pygame.locals import * # Define defaults bg = (0,0,0) # background colour spl = (255,255,255) # splash colour ver = "INDEV v1.0" # current version img ...
[]
[ { "body": "<pre><code>import pygame, sys, time\nfrom pygame.locals import *\n\n# Define defaults\nbg = (0,0,0) # background colour\nspl = (255,255,255) # splash colour\nver = \"INDEV v1.0\" # current version\nimg = \"icn.png\" # corner icon (UNUSED)\ncur = \"cur.png\" # cursor icon\nplayer = \"player.png\" # pl...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-15T13:32:47.997", "Id": "8996", "Score": "1", "Tags": [ "python", "performance", "beginner", "game", "console" ], "Title": "Moving a game character around the screen" }
8996
<p>I am trying to finish the K&amp;R book on C. Below is an exercise which took a long time to finish. I would like some feedback on optimization or any blatant issues with the code.</p> <blockquote> <p><strong>Exercise 1-21</strong></p> <p>Write a program <code>entab</code> that replaces strings of blanks by ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-15T17:00:46.550", "Id": "14118", "Score": "0", "body": "Small comment. It does not handle strings with spaces and tabs already intermixed correctly. \"A \\tB\" Should be encoded as \"A\\tB\" but it is not." }, { "ContentLicense...
[ { "body": "<p>Be consistent with you style:<br>\nIn yout first two function you use the style of putting the brace on the next line.</p>\n\n<pre><code>int main(int argc, char const *argv[])\n{\n\nvoid entab(char input[])\n{\n</code></pre>\n\n<p>While the second two functions you use the style of the trailing '{...
{ "AcceptedAnswerId": "9001", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-15T16:53:24.830", "Id": "9000", "Score": "3", "Tags": [ "optimization", "c", "strings" ], "Title": "Entabbing a string" }
9000
<p>I've tomcat running on my Macbook pro and a web application. Making a request to a servlet (below i'm showing post method code) and tipping top command in terminal show a java process with 200/300% cpu usage. The servlet make a request to a mongo database to retrieve 389 documents and then iterate over this document...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-15T21:38:30.483", "Id": "14135", "Score": "0", "body": "No, it's not normal to get more CPU usage than the machine can provide (200-300%?). And I don't know about anything else, but _please_ break this up into smaller methods - among o...
[ { "body": "<p>Some tips:</p>\n\n<ol>\n<li><p>Use <code>StringBuilder</code> instead of string concatenation. (<code>namedEntities</code>, <code>bagOfWords</code>)</p></li>\n<li><p>Maybe you should close the cursor at the end of the method.</p></li>\n</ol>\n\n<p>Some other notes:</p>\n\n<ol>\n<li><p>Handle excep...
{ "AcceptedAnswerId": "9018", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-15T18:02:27.637", "Id": "9004", "Score": "1", "Tags": [ "java" ], "Title": "CPU under full load java web app (tomcat)" }
9004
<p>It works pretty well, but I suspect there's too many variables, and I wonder what else.</p> <p>I'm using this library: <a href="http://apt.alioth.debian.org/python-apt-doc/library/index.html" rel="nofollow">Python APT</a>.</p> <pre><code>#!/usr/bin/env python3 import argparse import apt def getdeps(deptype, pkg,...
[]
[ { "body": "<pre><code>#!/usr/bin/env python3\n\nimport argparse\nimport apt\n\ndef getdeps(deptype, pkg, otherpkg):\n</code></pre>\n\n<p>I recommend not using abbrivates like dep or pkg.</p>\n\n<pre><code> deps = list()\n</code></pre>\n\n<p>We usually create lists with <code>[]</code> not <code>list()</code>...
{ "AcceptedAnswerId": "9009", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-15T18:53:10.583", "Id": "9006", "Score": "2", "Tags": [ "python", "linux" ], "Title": "Calculating reverse dependencies of a Debian package" }
9006
<p>I'm just trying to see if anyone disagrees with the way I'm handling my logic for this. Something doesn't feel right with it but I don't quite know what it is.</p> <p>Just wanted to add that the <code>new_password_key</code> is NOT a password for the user to log in with. As of right now I was going to have them dir...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-15T21:36:09.800", "Id": "14134", "Score": "2", "body": "They can only ask for a new password every two days? I'd remove the restriction. Otherwise, it becomes fairly trivial to DOS any customers who forget their passwords. I'd proba...
[ { "body": "<p>I see nothing that's wrong with your code. My first reaction though is that you repeat the echo quite a bit. I would turn all the</p>\n\n<pre><code>echo json_encode(array());\n</code></pre>\n\n<p>into something like this:</p>\n\n<pre><code>function output($message, $success = TRUE) {\n $status = ...
{ "AcceptedAnswerId": "9012", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-15T20:11:31.527", "Id": "9010", "Score": "3", "Tags": [ "php", "codeigniter" ], "Title": "Forgotten password logic" }
9010
<p>I created my first gem for Rails today. <a href="https://github.com/Fivell/activeresource-response" rel="nofollow">https://github.com/Fivell/activeresource-response</a>. This gem adds possibility to access http response object from result of activeresource call.</p> <ul> <li>I don't know how to create test for this...
[]
[ { "body": "<p>First thing, it unnecessary to use the <code>included</code> hook methods. Since your purpose is to redefine some methods in <code>ActiveresourceResponse::Connection</code> and <code>Activeresource::Base</code>, why not just do so directly?</p>\n\n<pre><code># if ActiveResource has not been loaded...
{ "AcceptedAnswerId": "9269", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-15T22:01:15.360", "Id": "9013", "Score": "3", "Tags": [ "ruby", "multithreading", "ruby-on-rails", "thread-safety", "library-design" ], "Title": "Activeresource-response ge...
9013
<p>Is my destructor correct? Does it properly deallocate the subtrees?</p> <pre><code>#ifndef HEADER_GUARD__TREE #define HEADER_GUARD__TREE #include &lt;deque&gt; namespace Sandbox { class Node { public: Node(); Node( Node* parent ); virtual ~Node(); Node* GetFirstChild(); ...
[]
[ { "body": "<p>This is not real C++ code.<br>\nThis is C written with a couple of classes.</p>\n\n<p>Pointers are dangerous and should rarely be used in code. C++ has moved away from C in this regard over the last decade and all pointers should be either wrapped in a smart pointer or be part of a container struc...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-15T22:14:00.380", "Id": "9015", "Score": "3", "Tags": [ "c++", "memory-management", "tree" ], "Title": "Tree Node class - deallocation in the destructor" }
9015
<p>I wrote a program to copy a <code>.doc</code> template, add some text to it, then save and close it. I have to do this many times, and saving and closing a word document is slow. I decided to use multi-threading, but I'm a noob at this stuff and just wrote what came to me. Any feedback would be greatly appreciated ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-15T23:32:34.527", "Id": "14161", "Score": "0", "body": "Are you sure you can't do this inside Word with MailMerge? It's not (even close to) limited to inserting addresses. If memory serves, you can use MailMerge to insert virtually any...
[ { "body": "<p>Until we know your answers to Alex and svick's questions, here's a recommendation I have. I would change your loop slightly to this so that you only get the next task to run once per loop instead of twice.</p>\n\n<p>I also normally name my variables used in LINQ expressions based on the variable ...
{ "AcceptedAnswerId": "9372", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-15T23:05:40.573", "Id": "9019", "Score": "2", "Tags": [ "c#", "multithreading" ], "Title": "Tips on my multi-threading intuition?" }
9019
<p>I'm interested in finding the most elegant and 'correct' solution to this problem. I'm new to JS/PHP and I'm really excited to be working with it. The goal is to compare the size of a given image to the size of a 'frame' for the image (going to be a <code>&lt;div&gt;</code> or <code>&lt;li&gt;</code> eventually) and...
[]
[ { "body": "<p><em>Note: I will be referring to each top level commit as a section.</em></p>\n\n<p>First off, in section 3: </p>\n\n<pre><code>if ($imageHeight / $height) &lt; 1) {\n $deferToHeight = true;\n} else {\n $deferToHeight = false;\n}\n</code></pre>\n\n<p>can become</p>\n\n<pre><code>$deferToHeight...
{ "AcceptedAnswerId": "9048", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-16T02:25:25.000", "Id": "9022", "Score": "3", "Tags": [ "javascript" ], "Title": "Most elegant image to image frame comparison algorithm" }
9022
<p>I need your opinion. Which way do you think is right?</p> <p>The definition of <code>message</code> in this code bothers me because it is a single method that has two separate behaviors. Depending on how many arguments are passed the method will do different things--that stinks. </p> <p>On the other hand, calling...
[]
[ { "body": "<p>It looks like you're building a small <a href=\"http://en.wikipedia.org/wiki/Domain-specific_language\" rel=\"nofollow\">DSL</a>, in which event <code>message \"Hello\"</code> is analogous to, say, Rails' <code>belongs_to :user</code>. The difference is that while <code>belongs_to</code> is only, ...
{ "AcceptedAnswerId": "9045", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-16T03:48:00.477", "Id": "9023", "Score": "0", "Tags": [ "ruby" ], "Title": "Method naming and violating single responsibility" }
9023
<p>I have two threads, called <code>Fun</code> and <code>Boring</code>. Each thread takes the same read-only data and runs some calculations over it and returns a <code>[0.0, 1.0]</code> result.</p> <p>In the current setup, <code>Fun</code> acts as the main thread. It gathers, prepares, and stores the data in a glob...
[]
[ { "body": "<p>This is correct code. It could go into production.</p>\n\n<p>You don't need the memory barrier because SetEvent will do that for you (if it didn't a <em>lot</em> of code would be broken).</p>\n\n<p>You could change this to use futures (provided that you have some C++ lib that supports them. I don'...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-14T19:56:10.740", "Id": "9026", "Score": "4", "Tags": [ "c++", "multithreading" ], "Title": "Two threads working on shared data" }
9026
<p>I'd just like to get some pointers on my newbie-ish C here. The intention is to have an environment variable provide the "prefix" for any paths this app needs.</p> <p>For example, <code>APP_PREFIX</code> could be <code>/opt/app</code>, a path the app wanted to get could be <code>/etc/app.conf</code>, and so <code>a...
[]
[ { "body": "<p>All seems good.</p>\n\n<p>As you mentioned it is sensitive to trailing slash being missing. I would just force that issue and always append one between the prefix and the path. An extra slash will not hurt but a missing one will.</p>\n\n<p>Apart from not using C in the first place :-) all my other...
{ "AcceptedAnswerId": "9049", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-16T10:58:56.113", "Id": "9037", "Score": "4", "Tags": [ "c", "beginner", "strings" ], "Title": "C-string manipulation" }
9037
<p>I recently answered a question on Stack Overflow where someone asked for advice about making a Hash thread-safe. They indicated that performance was important and that there would be a heavy read bias. I suggested a read-write lock, but couldn't find a Ruby implementation available anywhere. The only thing I found w...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-16T13:41:45.833", "Id": "14186", "Score": "0", "body": "Do you have this project at github, can you share the link? :)" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-16T14:21:17.783", "Id": "14188", ...
[ { "body": "<p>I am not an expert in multithreading, but I reviewed the code and here are my thoughts:</p>\n\n<p>The following code leads to deadlock:</p>\n\n<pre><code>l = ReadWriteLock.new\nl.with_write_lock { puts 'passed' }\n</code></pre>\n\n<p>This happens because writer wait for himself to release lock (it...
{ "AcceptedAnswerId": "9103", "CommentCount": "7", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-16T11:10:40.767", "Id": "9038", "Score": "5", "Tags": [ "performance", "ruby", "multithreading" ], "Title": "Read-write lock implementation for Ruby" }
9038
<p>I wrote this code using jQuery, but I think it can be improved. Can you provide some feedback?</p> <pre><code> var $i = 1, totalImg = $('.home-featured-bg .absolute div').length, $theWidth = $(window).width(), $theHeight = $(window).height(); $('.home-featured-bg .absolute').css('width',$theWidth...
[]
[ { "body": "<p>Here few suggestion:</p>\n\n<p>in the function you have :</p>\n\n<pre><code>if($i == 1)\n{\n\n var $el = $theWidth;\n}else{\n var $el = $theWidth * $i;\n}\n</code></pre>\n\n<p>could be replaced by a single line:</p>\n\n<pre><code>var $el = $theWidth * $i;\n</code></pre>\n\n<p>and you could ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-16T18:58:00.687", "Id": "9050", "Score": "2", "Tags": [ "javascript", "jquery", "css", "animation" ], "Title": "Periodically sliding images" }
9050
<p>I have created a page that displays markers for local attractions on a Google map. There are a few functions that do similar tasks and I have tried to reduce these by incorporating them into one function, but to no avail. Any suggestions on how to go about doing this?</p> <pre><code>&lt;script type="text/javascrip...
[]
[ { "body": "<p>First off, I find it helpful to use arrays instead of multiple variables. So, how about this:</p>\n\n<pre><code>var map = [], infoWindow = [];\n</code></pre>\n\n<p>Then, lets rename id <code>map</code> to <code>map0</code>. This will allow us to be clever with how we reference it :)</p>\n\n<p>Now ...
{ "AcceptedAnswerId": "9070", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-16T18:58:34.553", "Id": "9051", "Score": "2", "Tags": [ "javascript", "google-maps" ], "Title": "Displaying markers for local attractions on a Google map" }
9051
<p>I am using Trail Division Method with a pre-calculated list of primes to calculate the prime factorization of <strong>all</strong> numbers less than M (M &lt;= 10^7).</p> <p>I am using an array of vectors of pairs. The format for 10 is as follows:</p> <pre><code>PF[10][0].first = 2 // Base PF[10][0].second = 1 //...
[]
[ { "body": "<p>Off the top of my head, once you find a factor, you can look that up in your existing table. That will keep you from having to continue searching for more primes.</p>\n", "comments": [], "meta_data": { "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate"...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-16T18:13:53.240", "Id": "9052", "Score": "6", "Tags": [ "c++", "optimization", "primes" ], "Title": "Optimization - Prime Factorizations of Numbers <= 10^7" }
9052
<p>I'm creating Sudoku in JS but can't find the way to extract the numbers from the squares. The numbers from the rows and columns are easy to extract but I can't find the way around the squares. According to users input, I'll validate the column, then the row and finally the squares to see if the numbers are being rep...
[]
[ { "body": "<p>As we know, the numbers that could be placed in sudoku cells are limited (1..9). So we can easily make an index to existence of 1 through 9 in each row, column and square.\nConsider we use <code>rowIndex[9][10]</code>, <code>colIndex[9][10]</code> and <code>sqrIndex[9][10]</code> for this purpose....
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-16T23:21:43.783", "Id": "9066", "Score": "2", "Tags": [ "javascript", "gui", "sudoku" ], "Title": "Sudoku boxes count JavaScript" }
9066
<p>I have the following SQL statement that I think could be improved in areas (I believe there may be a way to use where over having, but I'm not sure how and I'm sure there's a way to reference the last updated column in the having clause but I'm unsure how to do it). Any suggestions would be greatly appreciated:</p> ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-17T08:09:57.213", "Id": "14244", "Score": "1", "body": "Don't you want `max` rather than `min`? Your comment at the top of the code suggest that you want tables whose latest statistics entry is more than two days ago, not whose earlie...
[ { "body": "<p>You can just use the condition in a <code>where</code>, that will filter the single records instead of filtering groups, then you can group the result to avoid duplicates in the result.</p>\n\n<p>You shouldn't convert the date to a string when you are comparing it. When you convert it to a string,...
{ "AcceptedAnswerId": "9081", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-16T23:24:50.130", "Id": "9067", "Score": "2", "Tags": [ "sql", "sql-server", "t-sql" ], "Title": "Statistics updating SQL Query" }
9067
<p>I need multiple read access to some data which can be updated from time to time. I created a class for managing lock-less access to the data. The class uses 2 counters, one for count of the acquired references and another one for the count of released references. The update function replaces the data pointer and the...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-15T15:10:45.450", "Id": "14223", "Score": "3", "body": "`(limit >= 0) <= (releaseCount >= 0)` ouch. What's wrong with `limit < 0 || releaseCount >= 0` ?" } ]
[ { "body": "<pre><code> bool CheckReleaseCount(int limit) //wrap-safe check to see if release count has reached the required limit \n {\n int releaseCount = m_releaseCount;\n return (limit &gt;= 0) &lt;= (releaseCount &gt;= 0) ? limit &lt;= releaseCount : limit &gt;= 0 &amp;&amp; releaseCount...
{ "AcceptedAnswerId": "9217", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-15T14:59:07.440", "Id": "9068", "Score": "4", "Tags": [ "c++", "multithreading" ], "Title": "Is my lockless data structure correct?" }
9068
<p>I am trying to make some code shorter and usable. Can someone look over the code I wrote and let me know if it's done correctly? I think it is but it seems a little too simple. The code allows a user to select a location form a drop down, then goes to that page.</p> <p>Old Code</p> <pre><code> if (type...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-16T22:58:42.533", "Id": "14230", "Score": "3", "body": "\"let me know if its done correctly\" --- does it work as expected? If yes - then yes, it's been done correctly. PS: there are `!=` and `!==` in js" } ]
[ { "body": "<p>Try this <a href=\"http://jsfiddle.net/deerua/yw52u/\" rel=\"nofollow\">sample</a></p>\n\n<p>html:</p>\n\n<pre><code>&lt;select&gt;\n &lt;option val=\"#\"&gt;---&lt;/option&gt;\n &lt;option val=\"#paris\"&gt;paris&lt;/option&gt;\n&lt;/select&gt;\n&lt;br/&gt;\n&lt;select&gt;\n &lt;option v...
{ "AcceptedAnswerId": "9073", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-16T22:55:17.823", "Id": "9071", "Score": "2", "Tags": [ "javascript", "jquery" ], "Title": "jQuery jump menu" }
9071
<p>The problem I want to solve is to replace a given string inside tags.</p> <p>For example, if I'm given:</p> <blockquote> <p>Some text abc [tag]some text abc, more text abc[/tag] still some more text</p> </blockquote> <p>I want to replace <code>abc</code> for <code>def</code> but only inside the tags, so the out...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-17T01:59:54.327", "Id": "14235", "Score": "0", "body": "This reminds me of bbcode ... could this help: http://www.codigomanso.com/en/2010/09/bbcodeutils-bbcode-parser-and-bbcode-to-html-for-python/" } ]
[ { "body": "<p>Your code is incorrect. See the following case:</p>\n\n<pre><code>print replace_inside(\"[tag]abc[/tag]abc[tag]abc[/tag]\")\n</code></pre>\n\n<p>You can indeed use regular expressions</p>\n\n<pre><code>pattern = re.compile(r\"\\[tag\\].*?\\[/tag\\]\")\nreturn pattern.sub(lambda match: match.group(...
{ "AcceptedAnswerId": "9074", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-17T00:17:09.643", "Id": "9072", "Score": "2", "Tags": [ "python", "regex" ], "Title": "Replace match inside tags" }
9072
<p>I did this code for somebody but need it to be double checked before I pass it onto them. Code seems fine but I need someone to confirm I have coded the crossover methods correctly.</p> <p>Would be great if somebody that is familiar with genetic algorithms and crossover methods, could confirm that I have the correc...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-17T01:35:43.227", "Id": "14238", "Score": "1", "body": "I suggest you write unit tests. See JUnit." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-17T01:46:30.627", "Id": "14239", "Score": "0", ...
[ { "body": "<p>It's difficult to just look at, but a few things jump out. More improvements than bugs:</p>\n\n<ul>\n<li><p>For single point crossover using <code>System.arraycopy()</code> would be much more reliable. For example:</p>\n\n<pre><code>System.arraycopy(parent1Genes, 0, childGenes, 0, xoverPoint);\nSy...
{ "AcceptedAnswerId": null, "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-17T01:34:08.313", "Id": "9077", "Score": "5", "Tags": [ "java", "algorithm" ], "Title": "Confirm code is correct - crossover methods in Java" }
9077
<p>This Socket Server should handle about 5000 lines of log file entries per second from at least 15 machines from same network. Any tips to further optimize this script or are there any big mistakes? </p> <pre><code>class Server { private $callback; private $clients; private $socket; public funct...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-23T11:19:20.830", "Id": "14637", "Score": "0", "body": "* removed @-operator from socket_select and socket_read" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-23T11:20:27.600", "Id": "14638", "Scor...
[ { "body": "<p>Why are you suppressing <code>socket_select</code> errors - I'd suggest at least catching any errors.</p>\n", "comments": [ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-23T11:13:37.000", "Id": "14636", "Score": "0", "body": "Had pro...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-17T09:49:47.153", "Id": "9086", "Score": "2", "Tags": [ "php", "php5" ], "Title": "PHP Socket Server" }
9086
<p>I built an extension method to cycle through all items of an <code>IEnumerable</code> starting at some index: </p> <pre><code>public static IEnumerable&lt;T&gt; Circle&lt;T&gt;(this IEnumerable&lt;T&gt; list, int startIndex) { if (list != null) { List&lt;T&gt; firstList = new List&lt;T&gt;(); ...
[]
[ { "body": "<p>A shorter form of Trevor's answer (but essentially doing the same thing):</p>\n\n<pre><code>public static IEnumerable&lt;T&gt; Circle&lt;T&gt;(this IEnumerable&lt;T&gt; list, int startIndex)\n{\n return list.Skip(startIndex).Concat(list.Take(startIndex));\n}\n</code></pre>\n\n<p>This will still...
{ "AcceptedAnswerId": "92070", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-17T11:37:52.040", "Id": "9088", "Score": "10", "Tags": [ "c#", "optimization", "extension-methods" ], "Title": "Cycle through an IEnumerable" }
9088
<p>I am building a web app with using UOW and Repository pattern. I have seen many different samples and found each one to be different, so not sure which is the correct way to go. I have a basic understanding of both these patterns and I wanted to know if I should keep one UOW implementation for all the tables in my p...
[]
[ { "body": "<p>The UoW pattern has a couple of properties. The UoW will:</p>\n\n<ul>\n<li>track changes to entities, wether that be adding, removing or updating.</li>\n<li>coordinate the persisting of these changes in one atomic action. Which also means rolling back if an error occurs.</li>\n</ul>\n\n<p>Since yo...
{ "AcceptedAnswerId": "9203", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-17T14:08:41.493", "Id": "9091", "Score": "3", "Tags": [ "c#", "design-patterns", "asp.net-mvc-3" ], "Title": "Is this a workable UnitOfWork with Repository pattern design?" }
9091
<p>I have this query built using the above, but it feels like it could be improved to make it more concise:</p> <pre><code> private IQueryable&lt;Lead&gt; _queryLeadsByHeat(int? ownerUserId, bool warmLeads) { var predicate = PredicateBuilder.False&lt;Lead&gt;(); predicate = predicate....
[]
[ { "body": "<p>First of all. Is _queryLeadsByHeat supposed to represent a method? If so I would steer away from using underscore in it's method name unless that's your naming convention in which case I guess your stuck with it. Underscore is traditionally mainly reserved for fields (if at all as there are lar...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-17T17:06:31.613", "Id": "9095", "Score": "2", "Tags": [ "c#", "linq" ], "Title": "How can this LINQ query using SqlFunctions.Datediff and LINQKit's PredicateBuilder be improved" }
9095
<p>Is there any simple way to detect user keystrokes that result in character input? In other words, ignore all soft keys and modifier keys? This works but seems sort of hacky:</p> <pre><code>var keycode = event.keyCode ? event.keyCode : event.charCode if((keycode&gt;=48 &amp;&amp; keycode&lt;=90) || (keycode&gt;=96 &...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-17T17:17:41.847", "Id": "14270", "Score": "1", "body": "Perhaps if you described what you were trying to achieve we could help more. Is this typing in a text input? Can you use the `keyup` event and see if the `.value` has changed as a...
[ { "body": "<p>You can use <code>String.fromCharCode</code> in combination with a Regular Expression test as alernative:</p>\n\n<pre><code>var cando = /[a-z0-9]/i\n .test(String.fromCharCode(event.keyCode || event.charCode));\nif( cando ){\n alert(\"realkey\")\n}\n</code></pre>\n\n<p>In the <cod...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-17T17:15:05.267", "Id": "9098", "Score": "2", "Tags": [ "javascript" ], "Title": "Detect real \"hard\" character keys only" }
9098
<p>I have been working on a parser generator, in which I want to employ a sort of fluent configuration interface - avoiding the pre-compile step that usually comes with parser generators. It's supposed to be a tool not just for language construction, but also for generalized parsing tasks that you usually end up coding...
[]
[ { "body": "<p>Refactor the Run()-method into seperate methods. It's barely readable now.</p>\n", "comments": [ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-18T20:49:19.527", "Id": "14307", "Score": "0", "body": "I agree. That would be the first ...
{ "AcceptedAnswerId": "9199", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-18T10:32:50.813", "Id": "9104", "Score": "1", "Tags": [ "c#", "parsing", "library" ], "Title": "Parsing library interface" }
9104
<p>I'm trying to implement <a href="http://www.cut-the-knot.org/Curriculum/Arithmetic/LCM.shtml" rel="nofollow">this algorithm for computing LCM</a> (from the cut-the-knot website). This is my Java code:</p> <pre><code>public class LcmAlgorithm { public static void main(String[] args) { long[] input = { 28, 50, 1...
[]
[ { "body": "<p>I've included my review comments in the revised code below as program comments, \nunmistakable because there weren't any comments in the OP.\nHmm. That's not a good sign. Though, I can't say that I've helped that much. Backward-looking reviewer comments make a poor substitute for useful forward-lo...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-18T11:07:59.970", "Id": "9106", "Score": "3", "Tags": [ "java", "algorithm" ], "Title": "Algorithm for computing LCM (least common multiple)" }
9106
<pre><code>def as_size( s ) prefix = %W(TiB GiB MiB KiB B) s = s.to_f i = prefix.length - 1 while s &gt; 512 &amp;&amp; i &gt; 0 s /= 1024 i -= 1 end ("%#{s &gt; 9 ? 'd' : '.1f'} #{prefix[i]}" % s).gsub /\.0/, '' end </code></pre> <p>I'd like a clean and fast code to convert raw file size to human-...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-09-10T13:47:36.467", "Id": "25098", "Score": "2", "body": "I wouldn't worry so much about the performance of this code. I ran the benchmark that you provided, and found that your code is 1 microsecond faster than Jordan's, which is 1 micr...
[ { "body": "<p>Possible solution: <code>reduce</code> your input to required precision. Returned result construction also reads cleaner with this approach:</p>\n\n<pre><code>def as_size(s)\n units = %W(B KiB MiB GiB TiB)\n\n size, unit = units.reduce(s.to_f) do |(fsize, _), utype|\n fsize &gt; 512 ? [fsize ...
{ "AcceptedAnswerId": "9661", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-18T13:16:35.503", "Id": "9107", "Score": "3", "Tags": [ "ruby" ], "Title": "Printing human-readable number of bytes" }
9107
<p>I figure there is a better way that I should be doing this:</p> <pre><code>if !db.collection_names.include?("reports".to_s) db.create_collection("reports") end if !db.collection_names.include?("days".to_s) db.create_collection("days") end if !db.collection_names.include?("users".to_s) db.create_collection("...
[]
[ { "body": "<p>Well, firstly: <code>\"string\".to_s</code> is entirely redundant. That's already a <code>String</code>, so converting it again is just wasting your (processor's) time. </p>\n\n<p>Secondly, writing <code>if</code> blocks with just one line and no <code>else</code> wastes a good deal of vertical re...
{ "AcceptedAnswerId": "95001", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-18T16:14:23.583", "Id": "9109", "Score": "3", "Tags": [ "ruby" ], "Title": "Validating Mongo collections" }
9109
<blockquote> <p><strong><em>K&amp;R</em> 1.8 exercise:</strong></p> <p>Write a program to count blanks,tabs, and newlines.</p> </blockquote> <p>Is this a viable solution to the problem and is it properly formatted? I have never programmed in C before, so I just wanted to see if this is proper c programming as i...
[]
[ { "body": "<p>That is a great start. It's almost perfect logically.</p>\n\n<p>First thing that caught my eye however is the lack of indentation. It could just be that something got lost in the transition between your code and your post here, I don't know. But you should indent whenever starting a new block. ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-18T16:52:20.337", "Id": "9111", "Score": "2", "Tags": [ "c", "beginner" ], "Title": "Counting blanks, tabs, and newlines" }
9111
<p>I wrote a simple class to deal with parsing and handling URIs for the project I'm currently working on, since it relies a lot on that functionality (eg the Router class and some HTML helpers). Here is the code already commented:</p> <pre><code>&lt;?php # URI class class uri { # URI scheme public $scheme; ...
[]
[ { "body": "<h1>Information Hiding</h1>\n\n<p><br/>\nYour class contains all public properties and methods.</p>\n\n<p>This means that users of the class are exposed to all of the internal properties, causing the following problems:</p>\n\n<ol>\n<li><strong>Confusion</strong> - With so many publicly accessible pr...
{ "AcceptedAnswerId": "9137", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-18T17:20:35.280", "Id": "9114", "Score": "4", "Tags": [ "php", "parsing" ], "Title": "URI parsing and handling class" }
9114
<p>I'm not a programmer, but am playing around with a binary tree Class in Python and would like help with a recursive method to count interior nodes of a given tree.</p> <p>The code below seems to work, but is this solution the clearest, in terms of logic, for counting interior nodes? I'm keen that the code is the cl...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-18T17:42:02.770", "Id": "14300", "Score": "0", "body": "Just to get your head thinking about this, suppose we were at the root node (so `parent` == `None`), what would happen if one of the children were `None`?" }, { "ContentLi...
[ { "body": "<p>So after our little discussion, I hope you see that you're missing some key cases here, when the <code>root</code> given is <code>None</code>.</p>\n\n<p>Some things that should be pointed out, when comparing to <code>None</code>, you should be checking if it <code>is</code> or <code>is not</code> ...
{ "AcceptedAnswerId": "9148", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-18T17:23:37.727", "Id": "9115", "Score": "1", "Tags": [ "python" ], "Title": "Method to count interior nodes of a binary tree" }
9115
<p>This is the code I came up with.It seems correct. </p> <p>I am interested in:<br> 1) Improvements on code<br> 2) How can it be better than this? i.e. this is <code>O(N^2)</code> Could I have done better in complexity? What should I have read to do it? </p> <p>Thanks</p> <pre><code> public int lengthOfLongestSub...
[]
[ { "body": "<p>I think, that after founding the first char that is present in the substring being checked, you should not stop checking it, but cut off the part up to the first appearance of the char, add to the second appearance and <strong>continue</strong> to check the string. So the algorithm remains be O(n^...
{ "AcceptedAnswerId": "9171", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-18T21:35:55.613", "Id": "9120", "Score": "4", "Tags": [ "java", "algorithm", "strings" ], "Title": "Longest substring with no repetitions" }
9120
<p>I have implemented the structure below at least 5 times, and it is getting cumbersome. Is there a better approach?</p> <h3>Current code-segment implemented</h3> <pre><code>public XmlNodeList Templates { get { return this.GetElementsByTagName( &quot;Templates&quot; ); } set { foreach( UITemplateAssoc n...
[]
[ { "body": "<p>There's a couple of nice alternatives for you.</p>\n\n<p><strong>Extensions</strong></p>\n\n<p>If you don't need to encapsulate the <code>XmlNodeList</code> instances, you could make your methods extensions for <code>XmlDocument</code> or whatever you've extended:</p>\n\n<pre><code>public static c...
{ "AcceptedAnswerId": "9178", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-18T22:57:03.490", "Id": "9127", "Score": "2", "Tags": [ "c#", "xml" ], "Title": "Collection of XmlNode control" }
9127
<p>How could this constructor code be improved? I feel like I'm not doing something optimally here...</p> <pre><code>@interface JGProduct : NSObject { NSString *identifier; } +(JGProduct *)productWithIdentifier:(NSString *)identifier_; -(JGProduct *)initWithIdentifier:(NSString *)identifier_; @end @implementati...
[]
[ { "body": "<p><strong>Why <code>-init...</code> should be declared to return <code>id</code></strong></p>\n\n<p>Imagine you have class A and its subclass B sharing the same designated initializer, <code>initWithString:</code>.</p>\n\n<pre><code>@interface A : NSObject\n-(A *) initWithString: (NSString *) string...
{ "AcceptedAnswerId": "9152", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-19T00:46:36.433", "Id": "9130", "Score": "3", "Tags": [ "objective-c", "constructor", "cocoa" ], "Title": "How could this constructor code be improved?" }
9130
<p>Some time ago I wrote myself a simple blog. The index page is generated with PHP5, using an SQLite3 database via the variable <code>id</code> handed to it via the URL.</p> <p>The SQLite database contains a table called <code>pages</code>. The <code>id</code> refers of course to the id intergers in this table. Other...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-20T00:29:45.730", "Id": "14345", "Score": "0", "body": "I don't know PHP, but I can tell you the first foreach is useless. A max query like that will return the same single value every call until an insert or an update changes the tabl...
[ { "body": "<p>You are right, the foreaches can be eliminated. The first foreach which grabs the highest id, can be eliminated by taking advantage of the fact that the query will only ever return a single cell and using the <a href=\"http://www.php.net/manual/en/pdostatement.fetchcolumn.php\" rel=\"nofollow\">P...
{ "AcceptedAnswerId": "9376", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-19T07:32:39.160", "Id": "9135", "Score": "4", "Tags": [ "sql", "php5", "sqlite" ], "Title": "Clumsy PHP5 code reading from an SQLite3 database" }
9135
<p>I'm creating a website that parses in currency rates of the three major cities listed below in the <code>$cities</code> array.</p> <pre><code>&lt;?php // Feed URL's // $theMoneyConverter = 'http://themoneyconverter.com/rss-feed/'; // Define arrays // $cities = array( 'London', 'New York', 'Paris' ); ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-10T04:05:40.537", "Id": "81873", "Score": "0", "body": "I just ran your url with ?x=15 and 16 - it does not grab the 15th element. it returns the entire XML." } ]
[ { "body": "<p>I see some inconsistencies in your getCurrency.php code. There are many variables that are never declared within the functions, so I don't think that's going to work as expected.</p>\n\n<p>I think the best approach would be to make a parser which looks for whatever currency code you need, regardle...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-19T10:13:19.597", "Id": "9138", "Score": "2", "Tags": [ "php", "parsing", "xml", "url", "finance" ], "Title": "Parse in currency rates of major cities" }
9138
<p>I'm working on a webpage with language detection and I have the following script so far (it's simple). I still haven't done the user detection, so it's not available to find the user language (yet), but this will be easily implemented. Though I'm not asking for that, I'm asking for other ways to improve this code. ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-09-10T14:18:48.847", "Id": "14320", "Score": "0", "body": "Beware of that `$_SERVER['HTTP_ACCEPT_LANGUAGE']` might not be set." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-09-10T14:25:39.637", "Id": "14321...
[ { "body": "<p>On principle the code is sound except for one issue: <strong>you do not check if the language is \"valid\"</strong>. This raises some questions:</p>\n\n<ul>\n<li>How will your localization code behave if I added a <code>lang</code> parameter with the value <code>\"foobar\"</code>?</li>\n<li>How wi...
{ "AcceptedAnswerId": "9143", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-09-10T14:10:29.107", "Id": "9141", "Score": "4", "Tags": [ "php", "http", "session", "i18n" ], "Title": "Language-detection PHP script" }
9141
<p>the question is simple, for a input [apple, banana, orange, apple, banana, apple], the program will count it as a map: {apple : 3, orange: 1, banana: 2}, then sort this map by it's values, get [(apple, 3), (banana, 2), (orange, 1)] below is my go version, I'm a go newbie, could you please review it and lecture me ho...
[]
[ { "body": "<p>In Go, I would write:</p>\n\n<pre><code>package main\n\nimport (\n \"bufio\"\n \"fmt\"\n \"io\"\n \"os\"\n \"sort\"\n)\n\ntype Key string\ntype Count int\n\ntype Elem struct {\n Key\n Count\n}\n\ntype Elems []*Elem\n\nfunc (s Elems) Len() int {\n return len(s)\n}\n\nfunc (s...
{ "AcceptedAnswerId": "12396", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-19T14:03:36.133", "Id": "9146", "Score": "3", "Tags": [ "python", "go" ], "Title": "code review for count then sort problems (go lang)" }
9146
<p>Here is my code to do it:</p> <pre><code>import Random (randomR, Random, StdGen) generateRandoms :: (Random a, Num a) =&gt; StdGen -&gt; a -&gt; a -&gt; [b] -&gt; [a] generateRandoms gen min max = map fst . tail . scanl f (0, gen) where f (x, g) _ = randomR (min, max) g </code></pre> <p>The problem I have wi...
[]
[ { "body": "<p>If you just need to generate a stream of random numbers, you can use standard \"randomRs\" function from System.Random:</p>\n\n<pre><code>randomRs :: (RandomGen g, Random a) =&gt; (a, a) -&gt; g -&gt; [a]\n</code></pre>\n\n<p>Usage:</p>\n\n<pre><code>Prelude System.Random&gt; newStdGen &gt;&gt;= p...
{ "AcceptedAnswerId": "9153", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-19T18:04:56.923", "Id": "9149", "Score": "3", "Tags": [ "haskell" ], "Title": "(Ab)using scanl to generate a random number stream, is there a better way?" }
9149
<p>This was a code test I was asked to complete by employer, and since they rejected me, I wonder what should I have done differently.</p> <pre><code>var w = 7, h = 6; var currentPlayer = 1; var animationInProgress = 0; var winner = 0; var map = new Array(h); var mapHtml = ""; for (var i = 0; i &lt; w; i++) { m...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-19T22:37:56.417", "Id": "14342", "Score": "2", "body": "What were the rules/requirements/limitations of the project?" } ]
[ { "body": "<p>I'll start with a list of observations:</p>\n\n<ol>\n<li><p>Hardly any comments. There are several places where it would be nice if you added some comments to explain how the main logic works for someone who has not seen the code before.</p></li>\n<li><p>A bunch of global variables and ones using...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-19T22:10:31.513", "Id": "9156", "Score": "11", "Tags": [ "javascript", "jquery", "game", "interview-questions" ], "Title": "Animated JavaScript/jQuery game" }
9156
<p>I basically want to convert all categorical column in an R dataframe to several binary columns:</p> <p>For example, a categorical column like</p> <blockquote> <pre class="lang-none prettyprint-override"><code>Company ------- IBM Microsoft Google </code></pre> </blockquote> <p>will be converted to 3 columns:</p>...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-20T01:05:47.023", "Id": "14356", "Score": "5", "body": "I suspect you under-estimate peoples' willingness to download anonymous executable code from person's they are unfamiliar with." }, { "ContentLicense": "CC BY-SA 3.0", ...
[ { "body": "<p><code>model.matrix</code> already does most of what you want:</p>\n\n<pre><code>company &lt;- c(\"IBM\", \"Microsoft\", \"Google\");\nmodel.matrix( ~ company - 1)\n</code></pre>\n", "comments": [], "meta_data": { "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "Cre...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-20T00:48:11.663", "Id": "9164", "Score": "8", "Tags": [ "performance", "r" ], "Title": "Converting dataframe columns to binary columns" }
9164
<p>Currently I'm displaying a news feed from an XML file and using a counter to limit the number of news articles that are displayed. But I'm unsure if this is the best way to do it.</p> <p>Here is my code.</p> <pre><code>&lt;?php function get_news($feed) { $xml = new SimpleXmlElement(uwe_get_file($feed)); $counter ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-19T19:58:30.207", "Id": "14359", "Score": "0", "body": "You could shorten your `++$counter;` and `if($counter == 5)` line to `if (++$counter == 5)`" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-19T19:59:1...
[ { "body": "<p>That's a perfectly good and valid way of doing it. Personally, I'd write <code>$counter++</code> rather than <code>++$counter</code>, but that's just my personal preference.</p>\n", "comments": [], "meta_data": { "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "Cre...
{ "AcceptedAnswerId": "9169", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-19T19:55:08.417", "Id": "9167", "Score": "0", "Tags": [ "php" ], "Title": "PHP Counter Improvement" }
9167
<p>I'm sure there's a better way to approach the following. I'm writing a plugin where users can enter settings in the following format:</p> <p>Setting: "object1setting -> object2setting"</p> <p>It's done this way to allow for multiple objects to be passed within the same JS call. I'm breaking the the strings apart a...
[]
[ { "body": "<p>I think you can use object literals. The user of your plugin can pass in an array of object literals: </p>\n\n<pre><code>var settings = [\n {bg_x_speed_in: ..., bg_x_speed_out_set : ...}\n , {bg_x_speed_in: ..., bg_y_speed_out_set : ....} \n , {bg_x_speed_in: ..., bg_x_speed_out_set : ......
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-17T17:47:28.907", "Id": "9172", "Score": "1", "Tags": [ "javascript", "jquery", "strings" ], "Title": "Splitting multiple strings" }
9172
<p>I have 3 tables: <code>students</code> and <code>classes</code> and <code>years</code>. In a fourth table called <code>StudentsInClass</code>, I'm saving students classes in each year. Now I want to show a list of students with their <code>className</code> in Current Year.</p> <p>This is the query I use but I'm not...
[]
[ { "body": "<p>Not entirely sure I got your schema right, but something like this should be possible.\n(omitted a bit of ordering, and I assume you only have one current year)</p>\n\n<pre><code>select top 10000\n s.*,\n c.Title classname,\n row_number() over (order by s.id) rownumber,\nfrom\n student...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-20T07:57:01.100", "Id": "9176", "Score": "2", "Tags": [ "sql", "sql-server" ], "Title": "List of students with their classname in current year" }
9176
<p>As an exercise in learning Haskell, I implemented a simple key value store, where you can put and get values (as <code>ByteString</code>s). (For reference this is inspired by this <a href="http://downloads.basho.com/papers/bitcask-intro.pdf" rel="nofollow">short note describing bitcask's design</a>). I'd appreciate ...
[]
[ { "body": "<p>Why not:</p>\n\n<pre><code>type KeySize = Integer\ntype ValueSize = Integer\ntype Header = (KeySize, ValueSize)\n</code></pre>\n\n<p>Instead of commenting, like you did here:</p>\n\n<pre><code>type Header = (Integer, Integer)\n -- keysize valuesize\n</code></pre>\n\n<p>Same ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-20T08:25:03.417", "Id": "9177", "Score": "4", "Tags": [ "haskell", "functional-programming" ], "Title": "Simple Haskell key value file store" }
9177
<p>I'm studying C on K&amp;R and now I'm facing a recursion exercise that states:</p> <blockquote> <p>Write a recursive version of the function reverse(s), which reverses the string <code>s</code> in place.</p> </blockquote> <p>I've written the code below and I'm pretty sure that it works. I'll be glad to receive ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-20T12:01:34.777", "Id": "14375", "Score": "1", "body": "What do you mean, you can't find a similar solution? The solution [on that page from David Kachlon](http://clc-wiki.net/wiki/K%26R2_solutions:Chapter_4:Exercise_13) is pretty much...
[ { "body": "<p>While this is recursive, it entirely misses the point. As the while loop will only ever execute once (because the function it calls only returns when <code>i &lt; j</code> it could just as well have been an if, and thus all you've got is tail-recursion.</p>\n\n<p>What you have is equivalent to th...
{ "AcceptedAnswerId": "9200", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-20T10:57:30.597", "Id": "9181", "Score": "8", "Tags": [ "c", "strings", "recursion" ], "Title": "Recursive string reverse function" }
9181
<p>I've written this "little" <code>typeof</code> extension for my JS. What do you think about it?</p> <p>Its aim is to provide a single reliable <code>typeof</code> in JavaScript, consistent between native vars and objects. I've tested it both in FF 4+, IE 7+, Chrome 12, Safari 5. Also, if you have a different browse...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-20T16:19:17.767", "Id": "14387", "Score": "0", "body": "`e.isArray` is a bit silly, try `Array.isArray(e)`" } ]
[ { "body": "<p>I don't think much of it, to be honest. It's not as reliable as you might think, because once you start passing objects between contexts (e.g. different windows) it will fail miserably. Add to that the fact that </p>\n\n<pre><code>Object.prototype.toString.call(&lt;any value&gt;);\n</code></pre>...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-20T16:01:04.093", "Id": "9184", "Score": "3", "Tags": [ "javascript" ], "Title": "Extension of JavaScript \"typeof\"" }
9184
<p>I recently discovered that there is no free read-write lock implementation for Ruby available on the Internet, so I built one myself. The intention is to keep it posted on GitHub indefinitely for the Ruby community at large to use.</p> <p>The code is at <a href="https://github.com/alexdowad/showcase/blob/master/rub...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-20T18:15:24.147", "Id": "14398", "Score": "0", "body": "And if someone were to test it on JRuby on an 864 core Azul Vega system, I'm sure Alex wouldn't complain, either :-)" }, { "ContentLicense": "CC BY-SA 3.0", "CreationD...
[ { "body": "<p>Have you considered to join reader and writer queues into a single writer-waiting queue? This may make the code easier to synchronize and also solve the issue with readers starvation when constant writes are performed, something like this: </p>\n\n<ol>\n<li>if write lock is taken or queue is not e...
{ "AcceptedAnswerId": "9545", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-20T17:03:27.877", "Id": "9186", "Score": "2", "Tags": [ "ruby", "multithreading", "locking" ], "Title": "Read-write lock implementation for Ruby, new version" }
9186
<p>I've just implemented a background animate on some social media icons where the image goes from grey to color on <code>:hover</code>.</p> <p>I wanted to know if there's a better way to write the following but also implement a fade, so as the background animates, it's also fading in on hover.</p> <pre><code> &lt...
[]
[ { "body": "<p>Instead of calling <code>mouseover</code> and <code>mouseout</code> separately, you can use <code>hover()</code> which takes care of this for you. Also, as both elements have the same code being executed you could employ DRY principles and group their selectors to use one block of code. Try this:<...
{ "AcceptedAnswerId": "9189", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-20T10:48:55.140", "Id": "9187", "Score": "1", "Tags": [ "javascript", "jquery", "css" ], "Title": "Adding fade to jquery background position animate" }
9187
<p>The Service:</p> <pre><code>&lt;?php namespace TestApp\Services\Ext; class ExtFilterParser { private $parsedFilters = array(); private $filters = ''; private $requestParam = 'filter'; public function __toString() { return $this-&gt;filters; } public function getParsedFilters() {...
[]
[ { "body": "<p>The concerns you have raised are valid. This test is currently relying on the Request object (and is testing that object where it shouldn't be).</p>\n\n<p>You have written the code well, injecting the dependency for the Request object into the constructor. This gives you the seam required for te...
{ "AcceptedAnswerId": "10335", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-20T17:03:34.633", "Id": "9191", "Score": "3", "Tags": [ "php", "parsing", "unit-testing", "php5", "symfony2" ], "Title": "Unit-testing ExtFilterParser Symfony2 service" }
9191
<p>In my time off I thought I'd implement some idiomatic data structures, starting with a linked list. </p> <p>Here's my current version: </p> <pre><code>#include &lt;iostream&gt; using namespace std; struct node{ int data; node *next; }; void traverseList(node *head){ for(node *iterator = head ; iterator ; ite...
[]
[ { "body": "<p>This is C++, not C. Therefore, your linked list class should contain the methods for operating on the list, and it shouldn't expose implementation details like nodes. For traversing the list, provide iterators. You should also make it a template so that it can be used with any type</p>\n\n<p>Th...
{ "AcceptedAnswerId": "9196", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-20T17:40:25.480", "Id": "9193", "Score": "3", "Tags": [ "c++" ], "Title": "Linked List review" }
9193
<p>I started playing with Python last week. This is a section of code from an application which reads a configuration file and launches <code>ssh</code> sessions and continuously displays data back to the local user.</p> <p>The whole project is <a href="https://github.com/maxmackie/vssh" rel="nofollow">on Github</a>.<...
[]
[ { "body": "<pre><code> usr = raw_input(\"Enter username for \" + server.address + \": \")\n pwd = getpass.unix_getpass(\"Enter passphrase for \" + server.address + \": \")\n con = paramiko.SSHClient()\n</code></pre>\n\n<p>I'd avoid using abbreviations. Call them <code>username</code> and <code>password...
{ "AcceptedAnswerId": "9671", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-20T18:14:44.380", "Id": "9195", "Score": "4", "Tags": [ "python", "optimization", "beginner", "session" ], "Title": "Display data based on read configuration file from ssh sess...
9195
<p>I have a function that compares sequential elements from a python list and returns 1 and -1:</p> <pre><code>&gt;&gt;&gt; up_down([0, 2, 1, 3]) [1, -1, 1] </code></pre> <p>I need a function to return all possible lists from a '-1, 1' list using the function up_down.</p> <pre><code>&gt;&gt;&gt; possible_lists([1, -...
[]
[ { "body": "<p>Your <code>comparison</code> function is the same as the builtin <code>cmp</code> function.</p>\n\n<p>Your filtering technique to find the matching lists may be not the most efficient. Permutations will generate a lot of lists which fail the test. On the other hand, itertools is written in C, whic...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-20T18:55:53.977", "Id": "9197", "Score": "2", "Tags": [ "python" ], "Title": "All possible lists from ups and downs between elements in python list" }
9197
<p>I could not find a Boost Python converter which converts <code>std::tuple</code>, so I wrote one.</p> <p>This was tested with a g++ 4.7 snapshot on Debian squeeze. It uses C++ 11 features, specifically variadic templates, so requires a recent compiler. This is based on <a href="https://stackoverflow.com/a/7858971/3...
[]
[ { "body": "<p>One thing that's not immediately clear to me is if the <code>tuple2tuple_wrapper</code>'s are supposed to be internal helpers, or actually part of the interface. They seem to be instantiated only once each in the code shown, both immediately followed by a call to their <code>delayed_dispatch</code...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-14T12:58:31.497", "Id": "9202", "Score": "14", "Tags": [ "c++", "c++11", "converting", "boost" ], "Title": "Boost Python converter for std::tuple" }
9202
<p>I have an old mp3 player with a broken screen. Consequently, it's a real pain to turn shuffle mode on and off; however, there are a few albums that I wanted to mix together and have shuffled for when I'm working out.</p> <p>That led me to whip up something in Python -- the first successful result was only about a d...
[]
[ { "body": "<pre><code># Figure out high range for random number generation, based on num-digits arg\nrand_max = 0\nfor n in xrange(args.num_digits):\n if rand_max == 0: rand_max = '9'\n else: rand_max += '9'\nrand_max = int(rand_max)\n</code></pre>\n\n<p>This whole loop can be written as <...
{ "AcceptedAnswerId": "9211", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-20T23:06:26.777", "Id": "9205", "Score": "1", "Tags": [ "python", "random" ], "Title": "randrename -- insert random nums in filenames" }
9205
<p>I have a directory of .xls workbooks with the following naming convention:</p> <blockquote> <pre class="lang-none prettyprint-override"><code>001.WIP Monthly Report 002.WIP Joes Custom Report ... 129.PUR Supplier Spend </code></pre> </blockquote> <p>The number of worksheets in each workbook varies but each works...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-04-18T20:02:39.020", "Id": "17478", "Score": "1", "body": "Perhaps this would be easier with a db? Even in MSAccess - just link all the tables (a lot of work with so many, but once it's done, it's done)." } ]
[ { "body": "<p>I find it easier to use the Interop vs. COM approach to Office automation. If nothing else it makes finding values to the enumerated types easier, everything else is basically the same.</p>\n\n<pre><code>Add-Type -ASSEMBLY \"Microsoft.Office.Interop.Excel\"\n</code></pre>\n\n<p>You should also lo...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-21T01:28:35.767", "Id": "9209", "Score": "9", "Tags": [ "performance", "beginner", "vba", "excel", "powershell" ], "Title": "Powershell script for manipulating Excel files" }
9209
<p>I wrote a simple client for handlersocket server, but I'm not a professional Java programmer and would like to know the opinion of Java developers on my code.</p> <p>Well I have not yet decided how to implement a class <code>HSResult</code>.</p> <p>My project is <a href="https://github.com/komelgman/Java-HandlerSo...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-21T19:44:26.037", "Id": "14474", "Score": "0", "body": "Please include code in the question. (Check the FAQ.)" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-22T07:03:23.457", "Id": "14514", "Score"...
[ { "body": "<ol>\n<li><p>The type of the <code>resultSet</code> reference could be simply <code>Map&lt;...&gt;</code>:</p>\n\n<pre><code>private final Map&lt;HSQuery, List&lt;ChannelBuffer&gt;&gt; resultSet\n</code></pre>\n\n<p>Reference: <em>Effective Java, 2nd edition</em>, <em>Item 52: Refer to objects by the...
{ "AcceptedAnswerId": "11911", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-21T09:59:26.440", "Id": "9215", "Score": "1", "Tags": [ "java", "mysql" ], "Title": "Client for handlersocket server" }
9215
<p>I just invented <strong>PSEUDO Query</strong>!</p> <pre><code>var objects = $.pquery([ '##pquery##', // Initialize as PSEUDO Query Object [document.body, 'css', [{'background-color':'#f00'}], 'append', ['##pquery##', // Helps distinguish array needing parsing from array of arguments '&lt;div...
[]
[ { "body": "<p>I'm not sure if there is a real use for this. Web apps normally don't need to execute arbitrary JavaScript, but instead just have a static library which gets data via AJAX on what they want to do. Can you give a more concrete use case? </p>\n\n<p>Also I don't really understand what you are saying ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-21T10:36:15.793", "Id": "9218", "Score": "-1", "Tags": [ "javascript", "jquery", "array", "ajax" ], "Title": "PSEUDO Query (jQuery extension)" }
9218
<p>I wrote the binary search algorithm with Ruby, the code is below. The question is if there's any way to make it look cleaner?</p> <pre><code>def binary_search(sample_array, x, l, r) mid = (l + r)/2 return -1 if r &lt; l return binary_search(sample_array, x, l, mid-1) if (sample_array[mid] &gt; x) return bin...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-21T10:44:10.677", "Id": "14438", "Score": "0", "body": "If nothing else, you can make it tail-recursive by conditionally assigning a new value to `l` or `r` (or returning) according to the comparisons between `sample_array[mid]` and `x...
[ { "body": "<ul>\n<li>Rather than defining it at the top level, why don't you make it a new method on <code>Array</code>?</li>\n<li>Taking <code>l</code> and <code>r</code> makes recursive calls possible, but would be annoying for the end user who always has to pass <code>0</code> and <code>array.length-1</code>...
{ "AcceptedAnswerId": "9270", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-21T07:13:47.243", "Id": "9220", "Score": "2", "Tags": [ "ruby", "algorithm", "search" ], "Title": "Refactoring binary search algorithm in Ruby" }
9220
<p>This program forms the reducer of a Hadoop MapReduce job. It reads data in from stdin that is tab delimited.</p> <pre><code>foo 1 foo 1 bar 1 </code></pre> <p>and outputs</p> <pre><code>foo 2 bar 1 </code></pre> <p>Any suggestions for improvements?</p> <pre><code>(use '[clojure.string :only [spli...
[]
[ { "body": "<p>Why don't you use <code>reduce</code> instead of the first <code>doseq</code>? Something along the lines (untested, entered directly here):</p>\n\n<pre><code>(def response\n (reduce (fn [map line]\n (let [k (fist (split line #\"\\t\"))]\n (update-map map k)))\n {...
{ "AcceptedAnswerId": "14821", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-21T10:55:42.150", "Id": "9221", "Score": "4", "Tags": [ "clojure" ], "Title": "Clojure MapReduce Reducer" }
9221
<p>This is a script I have written to calculate the population standard deviation. I feel that this can be simplified and also be made more pythonic. </p> <pre><code>from math import sqrt def mean(lst): """calculates mean""" sum = 0 for i in range(len(lst)): sum += lst[i] return (sum / len(lst...
[]
[ { "body": "<p>The easiest way to make <code>mean()</code> more pythonic is to use the <code>sum()</code> built-in function.</p>\n\n<pre><code>def mean(lst):\n return sum(lst) / len(lst)\n</code></pre>\n\n<p>Concerning your loops on lists, you don't need to use <code>range()</code>. This is enough:</p>\n\n<pr...
{ "AcceptedAnswerId": "9224", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-21T11:03:27.313", "Id": "9222", "Score": "10", "Tags": [ "python", "statistics" ], "Title": "Calculating population standard deviation" }
9222
<p>I previously wrote the question about version 1 of my code, since then I have released a version 1.6.3. I would just like everyone's opinion on it. Here is the old question: <a href="https://codereview.stackexchange.com/questions/8331/filemaker-php-api-interface">FileMaker PHP API Interface</a></p> <p>The code inte...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-02T12:46:27.300", "Id": "15220", "Score": "0", "body": "Feel free to read about [What makes a god question](http://meta.codereview.stackexchange.com/questions/75/what-makes-a-good-question) on meta. A link to the previous question and ...
[ { "body": "<p>Did you consider making this a REST API? Read more about <a href=\"http://broadcast.oreilly.com/2011/06/the-good-the-bad-the-ugly-of-rest-apis.html\" rel=\"nofollow\">The Good, the Bad, and the Ugly of REST APIs</a> and <a href=\"http://roy.gbiv.com/untangled/2008/rest-apis-must-be-hypertext-drive...
{ "AcceptedAnswerId": "9648", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-21T11:26:44.593", "Id": "9223", "Score": "1", "Tags": [ "php", "object-oriented", "api" ], "Title": "FileMaker PHP API Interface v1.6.3" }
9223
<p><img src="https://i.stack.imgur.com/4nE02.png" alt="VBA Image"></p> <p>Visual Basic for Applications (VBA) is an event-driven programming language first introduced by Microsoft in 1993 designed to give Excel 5.0 a more robust object-oriented language for writing macros and automating the use of Excel. The language ...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2012-02-21T13:28:41.437", "Id": "9225", "Score": "0", "Tags": null, "Title": null }
9225
Visual Basic for Applications (VBA) is an event-driven programming language first introduced by Microsoft in 1993 to give Excel 5.0 a more robust object-oriented language for writing macros and automating the use of Excel. It is now used for the entire Office suite and over 200 non-Office hosts.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2012-02-21T13:28:41.437", "Id": "9226", "Score": "0", "Tags": null, "Title": null }
9226
<p>I am having a <a href="http://pastie.org/3426970" rel="nofollow">challenge problem</a>. I have solved the problem but my solution is slow.</p> <p>The problem is basically the distribution of scores among players. <em>e.g</em> for a 2 player game the possible scorecards combination is 2 because either player can win...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-21T14:04:42.243", "Id": "14443", "Score": "1", "body": "a few notes on your code: 1. There's no reason to pass an integer as a const-ref. Just pass it by value. 2. Instead of `if(x==y) return true; return false;` you simply can do `ret...
[ { "body": "<p>Some more comments. </p>\n\n<ol>\n<li><p>The function <code>rangeSum()</code> can be optimized to:</p>\n\n<pre><code>int rangeSum(int start, int end)\n{\n return start*(start-1)/2 + end*(end-1)/2 - 2;\n}\n</code></pre>\n\n<p>which is much better since it's <code>O(1)</code> and not <code>O(n)</co...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-21T13:43:14.087", "Id": "9227", "Score": "5", "Tags": [ "c++", "optimization", "algorithm", "c++11", "programming-challenge" ], "Title": "Count Scorecards challenge problem r...
9227
<p>For a specific test-scenario I wanted:</p> <ol> <li>avoid accessing the file system through pythons builtin <code>open</code>-function</li> <li>don't want to use 3rd party libraries like <a href="http://www.voidspace.org.uk/python/mock/" rel="nofollow">Michael Foord's Mock</a> library</li> </ol> <p>I would like to...
[]
[ { "body": "<pre><code>from io import StringIO\n\nclass MockFile(StringIO):\n \"\"\"Wraps StringIO, because of python 2.6: clumsy name-property reset\"\"\"\n\n name = None #overwrite TextIOWrapper-property - part 1/2\n _vfs = {} #virtual File-System enables to \"re-read\" already written MockFiles\n</co...
{ "AcceptedAnswerId": "9231", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-21T13:50:39.647", "Id": "9228", "Score": "4", "Tags": [ "python", "unit-testing", "reinventing-the-wheel" ], "Title": "Monkeypatching builtin open and File Mock-Up for unit testing...
9228