body
stringlengths
25
86.7k
comments
list
answers
list
meta_data
dict
question_id
stringlengths
1
6
<p>I'd like to know how to optimize this by shadowing symbols 'lo and 'hi inside nested function f. I guess CPS conversion would solve this but how?</p> <pre><code>;; chess engine - early development ;; Alist: (cons 'piece xy-coordinates) (define whites) (define blacks) (begin (define setup     (let ([lo `(p0 p1 p...
[]
[ { "body": "<p>Your question and code are both confusing to me, but I'll give it a shot.</p>\n\n<p><code>(define whites)</code> doesn't compile with my standard definition of <code>define</code>. <code>define</code> usually needs to bind the identifier to something, even if it is just <code>'()</code> or <code>...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-01T19:59:41.617", "Id": "13236", "Score": "1", "Tags": [ "optimization", "scheme", "functional-programming" ], "Title": "Optimize this Scheme-written chess engine module" }
13236
<p>Please review the two code snippets below and let me know if the second snippet is better than the first one.</p> <p>In code snippet 2 I have added an inline function. According to my peers, using inline functions can help improve performance, since context switch will occur less often. </p> <p>But I am not able t...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-02T08:11:51.557", "Id": "21410", "Score": "2", "body": "Have you tried profiling these code snippets to find any performance differences?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-02T09:09:29.783", ...
[ { "body": "<p>You seem to be confusing several concepts, some completely unrelated.</p>\n\n<p>First, the second snippet is less readable, because it adds quite a lot of complexity that's not necessary. Unless you have a good reason to do something like this (for example, significant <em>measurable</em> performa...
{ "AcceptedAnswerId": "13241", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-02T07:16:33.887", "Id": "13239", "Score": "2", "Tags": [ "c#", "performance" ], "Title": "Inline Functions C#" }
13239
<p>I am quite new to ASP.net and am currently trying to implement my data access layers of my application. I have so far implemented a generic repository pattern as follows:</p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Data; using System.Data.Entity; using PayPlate.Mod...
[]
[ { "body": "<p>Your UnitOfWork class is unnessesary complicated and untestable, unreadable. If you are working with Entity Framework then you don't need to create your own UnitOfWork implementation because EF has its own.</p>\n\n<p>What you really need it is a container (<code>IRepositorContainer</code> with a g...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-02T11:29:48.090", "Id": "13240", "Score": "2", "Tags": [ "c#", "asp.net", "entity-framework" ], "Title": "IAuditable and IArchivable Repository with Repository Pattern and UnitOfWork...
13240
<p>I'm curious what people think about this little bit of logging code. It seems to work ok. Is there anything I'm missing?</p> <pre><code>public static class Logger { private static readonly object Locker = new object(); private static readonly StreamWriter Writer = new StreamWriter...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2016-11-16T11:56:09.563", "Id": "276620", "Score": "0", "body": "When do you actually call writer.Dispose so the writer writes?" } ]
[ { "body": "<p>Here's a slightly different version. It implements <code>IDisposable</code> so that the <code>StreamWriter</code> can eventually be closed and disposed properly and also uses a typed <code>delegate</code> for asynchronous invocation and properly calls <code>EndInvoke</code> upon completion.</p>\n\...
{ "AcceptedAnswerId": "13250", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-02T16:03:11.080", "Id": "13248", "Score": "4", "Tags": [ "c#", ".net", "asynchronous" ], "Title": "Async file writer in .Net 3.5" }
13248
<p>I thought about the best way to implement localisation with runtime in Swing.</p> <p>I currently solve the problem like that:</p> <pre><code>JMenu menuData = new JMenu("Data"); menuData.setName("mainframe.menu.data"); // property key localeChangedListener.add(menuData); </code></pre> <p>The <code>LocaleC...
[]
[ { "body": "<p>Consider <a href=\"http://docs.oracle.com/javase/7/docs/api/java/awt/Component.html#applyComponentOrientation%28java.awt.ComponentOrientation%29\" rel=\"nofollow noreferrer\"><code>applyComponentOrientation()</code></a>, which recursively \"Sets the <code>ComponentOrientation</code> property of th...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-02T18:00:25.847", "Id": "13251", "Score": "4", "Tags": [ "java", "swing", "localization" ], "Title": "Working with Locales in Swing (with change at runtime)?" }
13251
<p>I am new to PHP so this is largely compiled from examples around the web. It seems to work fine. Are there any ways in which it can be improved upon? Is it secure?</p> <pre><code>&lt;?php mysql_connect("localhost", "myusername", "mypassword"); mysql_select_db("companyDB"); function user_login($username...
[]
[ { "body": "<p>Well, <code>mysql()</code> is being deprecated, so be aware of that. <code>mysqli()</code> and <code>pdo()</code> are the new standards. I'd say continue learning on the old one, everything you learn can be translated to the new.</p>\n\n<p>When connecting to a database, it is best to give that con...
{ "AcceptedAnswerId": "13254", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-02T18:23:45.900", "Id": "13252", "Score": "0", "Tags": [ "php", "beginner", "mysql", "security" ], "Title": "Connect and login to MySQL database" }
13252
<p>I have read about it at a few places and tried to write my own version. I would like to get it reviewed. </p> <pre><code>class Node { private int value; private Node left; private Node right // getters and setters } </code></pre> <hr> <pre><code>public class DeleteNodeBST { Node parent = n...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-02T21:00:38.717", "Id": "21427", "Score": "1", "body": "there are compile errors... missing a semicolon `;` after `right`... missing a return type (`boolean`) before `deleteNodeBST(Node node, int value)`... `node == null;` is a conditi...
[ { "body": "<p>Here is how I would do this. I've sprinkled comments throughout the code, so hopefully this will be helpful.</p>\n\n<pre><code>//generalize the node to work for types other than just int\npublic class Node&lt;T extends Comparable&lt;? super T&gt; &gt;\n{\n private T value; //get; set;\n priv...
{ "AcceptedAnswerId": null, "CommentCount": "7", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-02T20:43:13.363", "Id": "13255", "Score": "4", "Tags": [ "java", "algorithm", "interview-questions", "tree", "binary-search" ], "Title": "Deleting a node from a binary search...
13255
<p>There is a function with bunch of a redundant <code>let</code>s and <code>←</code>s inside a list monad. </p> <pre><code>example ∷ (Int, Int, Int, Int, Int) example = head $ do let list1 = [0,1] e1 ← list1 let list2 = φ list1 e1 e2 ← list2 let list3 = φ list2 e2 e3 ← list3 let list4 = φ list3 e3 e4 ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2016-05-16T19:38:41.083", "Id": "240324", "Score": "0", "body": "I'm not quite sure why this question was closed with such a reason, the code looks pretty real and it could be compiled" } ]
[ { "body": "<p>Hm, this could probably be done using <code>foldM</code> or similar, but that would require you to convert to and from lists. My first impulse would be to try to write the top-level of <code>example</code> using Applicative style:</p>\n\n<pre><code>import Control.Applicative\n\nexample = head $ (,...
{ "AcceptedAnswerId": "13286", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-02T22:07:44.040", "Id": "13256", "Score": "9", "Tags": [ "haskell" ], "Title": "Redundant `let`s in list monadic code" }
13256
<p>Is this JavaScript code robust? It is for an interactive book about a card game. When the reader clicks on the checkbox, an answer is revealed and related text is highlighted. I need to get this right before I write <a href="http://keepcount.net/ebook/01-09/02_tricks.html" rel="nofollow noreferrer">more chapters</a>...
[]
[ { "body": "<p>Here are my thoughts:</p>\n\n<ol>\n<li><p>Most importantly from the first look at the code: Use proper variable names. No one knows what you mean with <code>EEE</code>, <code>xxx</code> or <code>e2</code>. And while you are at it: in JavaScript it's a convention to start variable names with a lowe...
{ "AcceptedAnswerId": "13274", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-02T22:20:11.777", "Id": "13257", "Score": "2", "Tags": [ "javascript", "css" ], "Title": "Click textbox to show answer and highlight related text" }
13257
<p>Below are the bunch of functions which I wrote to determine paths between give coordinates of a square tile-based game. It permits paths between tiles in 4 directions (i.e. not 8 directions/diagonal paths).</p> <p>It can be pretty resource-intensive when the path is long, especially if the target is unreachable (on...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-05T18:58:16.863", "Id": "21687", "Score": "0", "body": "I'm intrigued too, and would love to work on this as well. But without slightly more readable source or a somewhat more instructive problem description, I'm not willing to put in ...
[ { "body": "<p>I know you are asking about performance but I'd like to suggest some readability changes.<br>\nLists are good for lists of things not for keeping properties in. </p>\n\n<p>for example:</p>\n\n<pre><code> var terrain_tile_types = [\n [\"\",[0,0,0,0]], // Not really a tile (invisib...
{ "AcceptedAnswerId": "13297", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-02T23:09:09.977", "Id": "13258", "Score": "4", "Tags": [ "javascript", "pathfinding" ], "Title": "Javascript A* pathfinding function for tile-based game optimisation" }
13258
<p>I'm a few months into learning C++ programming and I want to know if I'm moving generally in the right direction or not with the following code. This is the most advanced thing I've created so far, but it doesn't contain any pointers or references so I'm worried I'm not doing things properly on the memory level. I e...
[]
[ { "body": "<p>I suggest the following: </p>\n\n<ul>\n<li><p>Member variables should be private.Do you really need </p>\n\n<pre><code>std::vector&lt;int&gt; randomIntArray\n</code></pre>\n\n<p>to be public in Randomizer?</p></li>\n<li><p>Be const correct. Declare variables to be const whenever possible. The ff.<...
{ "AcceptedAnswerId": "13268", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-03T04:37:04.610", "Id": "13261", "Score": "3", "Tags": [ "c++", "beginner", "random", "generator" ], "Title": "Simple randomization program" }
13261
<p>This code was posted as answer to <a href="https://codereview.stackexchange.com/questions/13248/async-file-writer-in-net-3-5">Async file writer in .Net 3.5</a>.</p> <p>How would it be done better using Tasks or new features in .Net 4.5?</p> <pre><code>public sealed class Logger : IDisposable { private delegate...
[]
[ { "body": "<p>Before I explain how would I improve that code, I'll first mention two problems I will not try to fix (because I'm not sure how to do it properly):</p>\n\n<ol>\n<li><p>Disposable singleton is a really weird combination. If something should be available anytime and anywhere, it should be a singleto...
{ "AcceptedAnswerId": "13273", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-03T06:32:59.707", "Id": "13263", "Score": "7", "Tags": [ "c#", "asynchronous" ], "Title": "File Async writer using Tasks or new features of .Net 4.5?" }
13263
<p>I'm building a typo correction program. This is the function, which compute the levenshtein distance between two words (a dictionnary word and an input word). I will call this function many times, so it should be fast. I'm looking for therefore some optimizations. I've seen some faster algorithms, but I don't know h...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-10T15:36:17.743", "Id": "21877", "Score": "0", "body": "One problem I see is that you very often call the minimum macro. Try using bit twiddling this part. There is an excellent article about how to obtain the minimum of two numbers wi...
[ { "body": "<p>I see very little space for improvements.</p>\n\n<p>First, your <code>min3</code> macro (btw, <code>max</code> is missing a closing bracket) will, in some cases, execute inside branching more than needed (i.e., if <code>c &gt; min2(a,b)</code>). I'd write it directly:</p>\n\n<pre><code>#define min...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-03T12:02:00.437", "Id": "13267", "Score": "2", "Tags": [ "c", "edit-distance" ], "Title": "Write a typo correction program with Levenshtein distance algorithm" }
13267
<p>This is my first go at genetic algorithms, using PyGame for the visual representation. Is there a way to improve the speed of the code? Click to place a point, press <kbd>↑</kbd> to start looking for the shortest route, or press <kbd>c</kbd> to clear all. </p> <pre><code>import pygame, time, random #Size of next g...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-03T20:54:02.953", "Id": "21474", "Score": "0", "body": "How many vertexes (cities) do you want to process? Do you need a genetic algorithm only, not an exact one?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "201...
[ { "body": "<p>Ok, so here is <strong>exact</strong> ATSP solver, just in order to check your genetic algorithm solution. It's based on pascal code implementing the branch-and- bound algorithm by Little, Murty, Sweeney, and Karel. It's very very fast (30 points in 0.5 sec!).</p>\n\n<pre><code>'''\n\nBranch and b...
{ "AcceptedAnswerId": "13340", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-03T13:30:17.397", "Id": "13272", "Score": "1", "Tags": [ "python", "algorithm", "pygame" ], "Title": "Tackling the TSP with a genetic algorithm" }
13272
<p>Doing graphics in Java, I find myself writing lines like these regularly:</p> <pre><code>Vector3f b = mid.add( a.mult(yOffset + length / 2) ).add( up.cross(a).mult(xOffset) ); </code></pre> <p>It gets even worse when I'm reusing objects.</p> <pre><code>Vector3f vTemp = VarPool.getVector3f(); Vector3f b = VarPool....
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-02T23:59:37.730", "Id": "21443", "Score": "0", "body": "Use an EL? Still Java, can be extended if you need specialized types, etc. Otherwise... Java is Java, and it's Java." }, { "ContentLicense": "CC BY-SA 3.0", "CreationD...
[ { "body": "<p>@DaveNewton Not necessarily, sometimes it's Groovy :-)</p>\n\n<p>Advantage</p>\n\n<ul>\n<li>code/syntax compatible with java.</li>\n<li>Operator overrides allow you to write your code so it looks more like your comment i.e. operators rather than methods</li>\n</ul>\n\n<p>Disadvantage</p>\n\n<ul>\n...
{ "AcceptedAnswerId": "13276", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-02T23:43:30.703", "Id": "13275", "Score": "3", "Tags": [ "java" ], "Title": "Improving readability of 3d math in Java" }
13275
<p>I'm reading a book called <em>JavaScript Web Applications</em>. In first chapter, it introduces an implementation of class library. Here's an intermediate version:</p> <pre><code>var Class = function () { var klass = function () { this.init.apply(this, arguments); } klass.prototype.init = functi...
[]
[ { "body": "<p>There is nothing fundamentally wrong about your class strategy, it is a matter of personal style really. The only suggestion I would have is to add Object.prototype.hasOwnProperty guards in the for-in loops, to avoid extending your classes with bogus properties if someone adds things to Object.pro...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-03T06:01:40.667", "Id": "13278", "Score": "2", "Tags": [ "javascript", "properties" ], "Title": "My implementation of javascript class library" }
13278
<p>I'd like to ask if this PHP/HTML code has any flaws which can be exploited by the potential aggressor:</p> <pre><code>&lt;form method='post' action='&lt;?php echo $_SERVER['PHP_SELF']; ?&gt;'&gt; &lt;input type='text' name='foo' value='&lt;?php echo htmlspecialchars($_POST['foo']); ?&gt;' /&gt; &lt;input type='sub...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-03T15:50:10.583", "Id": "21459", "Score": "2", "body": "You've answered your own question... Though I think `__FILE__` is the preferred way, rather than `$_SERVER[ 'PHP_SELF' ]` although I may be mistaken. Only other thing I can think ...
[ { "body": "<p>For single-quoted attributes, use <code>htmlspecialchars($text, ENT_QUOTES)</code>.</p>\n\n<p>Depending on what this does, you might want to implement some sort of protection against CSRF attacks.</p>\n\n<p>You might also want to check <code>$_SERVER['SCRIPT_NAME']</code>.</p>\n\n<p>Other than tha...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-03T14:55:10.813", "Id": "13282", "Score": "3", "Tags": [ "php", "security" ], "Title": "PHP form XSS vulnerability" }
13282
<h3>The (real life) problem</h3> <p>Following <a href="https://stackoverflow.com/questions/11294307/convert-java-date-to-utc-string">my question on SO</a>, I found out that printing a Java <code>Date()</code> in a custom format is quite tedious:</p> <pre class="lang-java prettyprint-override"><code>final Date date = ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-05T18:31:28.057", "Id": "58816", "Score": "1", "body": "What about [FastDateFormat](http://commons.apache.org/lang/api/org/apache/commons/lang3/time/FastDateFormat.html) in Commons Lang? And [DateFormatUtils](http://commons.apache.org/...
[ { "body": "<p>The thing about <code>Date</code> is that there are so many different time zones, so many different \"standard\" ways of representing the date and even, in some places, completely different calendar systems. As a result, Sun designed <code>Date</code> to not make any assumptions about anything and...
{ "AcceptedAnswerId": "13301", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-03T14:59:59.580", "Id": "13283", "Score": "10", "Tags": [ "java", "strings", "datetime" ], "Title": "Java Date formatter" }
13283
<p>I've been writing some smaller jQuery plugins lately, and I've been thinking of writing up some boilerplate that I can use when writing new ones. I have code that works (for now), but I want to share it and get feedback on things I may be missing as I move to larger plugins.</p> <pre><code>/** * jQuery Plugin Boil...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-03T15:17:27.550", "Id": "21455", "Score": "0", "body": "Do you mean `p = new PluginClass.init(this,options)`? You can't `new` the `PluginClass` itself because it's not a function." }, { "ContentLicense": "CC BY-SA 3.0", "Cr...
[ { "body": "<p>From a once over:</p>\n\n<ul>\n<li>I like how you store both <code>el</code> and <code>$el</code> </li>\n<li>I also like how you expose your defaults</li>\n<li>Not sure about <code>_t</code>, I think generally <code>self</code> is considered to a better name for <code>this</code></li>\n<li>You sho...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-03T15:08:59.027", "Id": "13284", "Score": "2", "Tags": [ "javascript", "jquery", "design-patterns", "plugin" ], "Title": "Creating boilerplate for jQuery plugins" }
13284
<p>This code is intended to take input as a string, do a SHA-256 hash on the string, and return the result.</p> <p>It works correctly for the standard test vectors (test code included at the bottom). I'm particularly interested in your thoughts about whether it would be a good idea for it to accept input in forms othe...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-03T21:19:15.643", "Id": "21475", "Score": "3", "body": "Reinventing the wheel. While it may be fun I do think I would ever use any crypto software that has not come from authoritative crypto site validated by lots of people in the fiel...
[ { "body": "<p>Virtual operator?</p>\n\n<pre><code>struct ternary_operator { \n virtual uint32_t operator()(uint32_t x, uint32_t y, uint32_t z) = 0;\n };\n</code></pre>\n\n<p>Personally I thinks this obfuscates the meaning and makes it harder to see that the call is using virtual dispatch (but that is ...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-03T16:32:42.577", "Id": "13288", "Score": "5", "Tags": [ "c++", "cryptography" ], "Title": "Perform SHA-256 on input" }
13288
<p>Here is my attempt at a PHP class to be used as a base class for typed collections. My goals with this are:</p> <ul> <li>to be able to access collection members with foreach</li> <li>to be able to access collection members using indices (array-like)</li> <li>to ensure that all collection members are objects of the ...
[]
[ { "body": "<p>Instead of recreating methods that perform functions that already exist ( <code>count()</code>, <code>current()</code>, etc...), have you thought of using PHP's magic <code>__toString()</code> method? I've not had much need to play around with it myself, but from my understanding you can use that ...
{ "AcceptedAnswerId": "13291", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-03T18:27:38.273", "Id": "13290", "Score": "1", "Tags": [ "php", "object-oriented", "collections" ], "Title": "PHP Class to Represent a Type Collection" }
13290
<p>I have the following code that converts a couple of bash commands into Windows <code>cmd</code> commands, as well as adding some commands. This is only my second day programming in C++, so any and all suggestions would be helpful.</p> <pre><code>#include "stdafx.h" #include &lt;iostream&gt; #include &lt;string&gt; ...
[]
[ { "body": "<p>Some quick suggestions:</p>\n\n<ul>\n<li><p>Since SetRegexes() does not change the values of your data members, better make the data members constant and initialize them in the constructor's initializer list. Thus you save some runtime in setting the values at initialization.</p>\n\n<pre><code>pri...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-03T22:54:45.493", "Id": "13296", "Score": "1", "Tags": [ "c++", "parsing", "beginner", "shell", "windows" ], "Title": "Converting Bash commands into Windows cmd commands" }
13296
<p>I wrote this script to collect evidence of the number of days worked for the purpose of claiming some government tax credits.</p> <p>I'm looking for some ways to clean it up. I'm especially wondering if there is a cleaner way to uniqueify a list than <code>list(set(my_list)</code> and maybe a better way to do:</p> ...
[]
[ { "body": "<p>For this part:</p>\n\n<pre><code>author_lines = filter(lambda str: str.startswith('Author'), lines)\ndate_lines = filter(lambda str: str.startswith('Date'), lines)\nauthor_lines = map(lambda str: str[8:], author_lines)\ndate_lines = map(lambda str: str[8:18].strip(), date_lines)\n</code></pre>\n\n...
{ "AcceptedAnswerId": "13303", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-03T23:29:15.943", "Id": "13298", "Score": "4", "Tags": [ "python", "git" ], "Title": "Counting the number of days worked for all commiters to a git repo" }
13298
<p>I am using wordpress to allow a client to enter a curriculum vitae and have it output the correct and consistent html formatting:</p> <p><img src="https://i.stack.imgur.com/U4N0S.png" alt="enter image description here"></p> <p>So I have a plain text box custom field and am having them enter in the content in the f...
[]
[ { "body": "<p>Why are you having them write that all in one box? And with custom tags no less!</p>\n\n<p>I'd just create a form with each of these fields in it (section, year, event), with a JS \"add\" button below the event to add additional events to the DOM. Then if you want to give them the option of adding...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-04T02:04:04.210", "Id": "13300", "Score": "1", "Tags": [ "php", "regex" ], "Title": "Improving a shortcode replacement routine PHP and regex" }
13300
<p>Linq already has a set of <a href="http://msdn.microsoft.com/en-us/library/bb534501">GroupBy methods for enumerable</a>, which returns <code>IEnumerable&lt;IGrouping&lt;TKey, TSource&gt;&gt;</code>. I dislike this return type because it means I have to do a where query everytime I want to find a group. I try to make...
[]
[ { "body": "<p>Returning an interface type makes the software very future proof.</p>\n\n<p>Even now, LINQ is works with any number of different providers, and each can implement the grouping in different ways, as long as the interface requirements are met. One example is that a LINQ provider can implement a lazy...
{ "AcceptedAnswerId": "13308", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-04T07:17:01.957", "Id": "13305", "Score": "13", "Tags": [ "c#", ".net", "linq" ], "Title": "What do you think of this improvement of Linq's GroupBy method?" }
13305
<p>I am a newbie programmer learning some C++. One of the exercises in my book asked me to write a basic console calculator that takes 2 numbers and an operation as input. I have done so and the program compiles (both with clang++ and g++) and runs fine.</p> <p>I would like to know if:</p> <ul> <li>I am making mistak...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-03T04:58:13.680", "Id": "21502", "Score": "0", "body": "You can use enum to indicate the status, and move all the duplicate code to output and return to one place." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "20...
[ { "body": "<p>You might want to check that your two numbers coming in are in fact numbers, if someone were to enter a letter, your program will crash. You might also want to split the operations up into other functions, it makes code more readable/ debug-able.\nLastly, when using <code>cout</code> and <code>cin...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-03T04:50:12.213", "Id": "13311", "Score": "7", "Tags": [ "c++", "beginner", "console", "calculator" ], "Title": "Console calculator" }
13311
<pre><code>public static function find_user_tracks($id) { global $mySQL; $sql = "SELECT * FROM `tracks` WHERE account_id = {$id}"; $result_set = $mySQL-&gt;query($sql); $ret = array(); while($row = $result_set-&gt;fetch_assoc()) { $ret[] = $row; } return $ret; } </code></pre> ...
[]
[ { "body": "<p>I think this will work. You'll have to have PHP version 5.3 though, otherwise you'll have to remove the lambda functions and define actual functions in their place. Disclaimer, not to say that this is easier to read or easier to understand, but I think it fits the \"cleaner\" request.</p>\n\n<pre>...
{ "AcceptedAnswerId": "13355", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-04T15:47:20.100", "Id": "13316", "Score": "1", "Tags": [ "php", "array", "mysqli" ], "Title": "Extracting Multiple Associative arrays in PHP" }
13316
<p>What is the common practice to implement attributes that have side effects in Python? I wrote the following class which supposed to save singletons when a variable is going to get a certain value. The background is that my program had sparse data, meaning that there were a lot of objects having empty sets in their a...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-04T18:47:29.497", "Id": "21518", "Score": "1", "body": "Python 2 or Python 3?" } ]
[ { "body": "<p>If you are using python 2, your code doesn't work at all. I'll assume you are using python 3.</p>\n\n<p>There a few cases where this will do unexpected things:</p>\n\n<pre><code>t=Test(set())\nt.a.add(2)\nprint t.a\n</code></pre>\n\n<p>The set will empty.</p>\n\n<pre><code>b = set()\nt = Test(b)\n...
{ "AcceptedAnswerId": "13319", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-04T16:57:18.133", "Id": "13318", "Score": "1", "Tags": [ "python" ], "Title": "Attributes with special behaviour in Python" }
13318
<p>The common lisp function copy-tree is often implemented in a recursive way, and thus is prone to <a href="https://bugs.launchpad.net/sbcl/+bug/998926">stack overflow</a>.</p> <p>Here is my attempt at writing an iterative version, one-pass, no stack, no unnecessary consing, version of copy-tree in common-lisp, work...
[]
[ { "body": "<h2>RE: how to rewrite to make it more readable</h2>\n\n<ol>\n<li>Stop using <code>c[a,d]*r</code>. While I have a soft spot for them your code may be more readable via <code>first</code>, <code>second</code> etc.</li>\n<li>Name the predicates of the <code>cond</code> statement. What are they testing...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-04T19:48:15.673", "Id": "13321", "Score": "5", "Tags": [ "lisp", "common-lisp" ], "Title": "iterative copy-tree in lisp" }
13321
<p>I have a couple of jQuery animations running in a sequence after certain resources are loaded:</p> <pre><code>$(".loading").delay(2600).fadeOut({ useTranslate3d: true, }); $(".zip").delay(1900).slideDown({ useTranslate3d: true, }); $("#zip").delay(2800).slideDown({ useTranslate3d: true, }); </code></p...
[]
[ { "body": "<p>You can use the same <code>options</code> object for all three animations.</p>\n\n<pre><code>var opts = {\n useTranslate3d: true,\n}\n$(\".loading\").delay(2600).fadeOut(opts);\n$(\".zip\").delay(1900).slideDown(opts);\n$(\"#zip\").delay(2800).slideDown(opts);\n</code></pre>\n\n<p>Having <code>...
{ "AcceptedAnswerId": "13326", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-05T00:44:50.810", "Id": "13325", "Score": "1", "Tags": [ "javascript", "jquery" ], "Title": "Combining multiple jQuery animations?" }
13325
<p>I develop an android native application using phonegap and jquery mobile. I've made a function to create a listview style dynamically using looping <code>for..</code>. When I run the function for the first time, it works, the listview style is working, and match with the content. but when I press back button and run...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-05T02:01:33.910", "Id": "21525", "Score": "0", "body": "Where is the code for review? If this is more of a problem of broken code I'd suggest [SO] otherwise please help us by adding some code. Thanks. EDIT:- I should have prefaced that...
[ { "body": "<p>I can't see anything wrong with your code in terms of why it gives you different styles. I would however ensure you have a consistent coding standard.</p>\n\n<p>For example my coding standards usually include:</p>\n\n<ol>\n<li><p>Always declare variables. Variable <code>maks</code> is never declar...
{ "AcceptedAnswerId": "13329", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-05T01:18:29.460", "Id": "13328", "Score": "1", "Tags": [ "javascript", "html" ], "Title": "Why my listview style change when I loop the javascript twice?" }
13328
<p>I have constructed a function that checks whether an element has a scrollbar or not, and can also check individual axes.</p> <p>I don't know if this works in all major browsers and am unsure about the performance. </p> <p>Is there any way to improve upon the code, did I miss anything?<br> How would a javascript eq...
[]
[ { "body": "<p><img src=\"https://i.stack.imgur.com/8Rpkl.jpg\" alt=\"=== everywhere\"></p>\n\n<p><a href=\"https://stackoverflow.com/questions/359494/javascript-vs-does-it-matter-which-equal-operator-i-use\"><code>=== &gt; ==</code></a> (Not that it really matters in this case, but it's still better.)</p>\n\n<p...
{ "AcceptedAnswerId": "13378", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-05T09:08:17.283", "Id": "13338", "Score": "5", "Tags": [ "javascript", "jquery", "optimization", "performance" ], "Title": ".hasScroll function, checking if a scrollbar is vis...
13338
<p>Below is the class which I am using to fill multiple DropDowns on ASP.NET Page Load event:</p> <pre><code>public sealed class getBlocks { public getBlocks(DropDownList dropDownName, string districtId) { returnBlocks(dropDownName, districtId); } public void returnBlocks(DropDownList DropDown...
[]
[ { "body": "<p>Firstly, data access should be separate from your UI logic. Certainly create a new layer, where you'll manage CRUD operations.</p>\n\n<p>Secondly, I'm not really fond of your naming convention of classes. Even though it may be a subjective matter, many people tend to use capitalized names for clas...
{ "AcceptedAnswerId": "13368", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-05T09:49:38.157", "Id": "13342", "Score": "2", "Tags": [ "c#", ".net", "asp.net" ], "Title": "What improvements are needed in this class to fill DropDown using PetaPoco?" }
13342
<p>What I've been working on is some kind of function that can take basically any well constructed multi-dimensional array and remove any and all duplicates within matching key sets.</p> <p>The particular function I've designed provides convenience and functionality but it is far from pretty and seemingly slow compare...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-05T14:12:14.863", "Id": "21558", "Score": "0", "body": "I'd only add that your variables are not very descriptive (ta, tv, tk), which makes reading the function difficult at places. And also that `eval()` is evil. I'd use either of the...
[ { "body": "<p>This is probably better than using <code>eval</code>. This solution touches only keys which are numeric, leaving string keys unchanged:</p>\n\n<pre><code>&lt;?php\n\n$echo['level-one'][] = '1';\n$echo['level-one'][] = '1';\n$echo['level-one'][] = '1';\n$echo['level-one'][] = '1';\n$echo['level-one...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-04T10:14:22.120", "Id": "13343", "Score": "2", "Tags": [ "php" ], "Title": "Can anyone improve my multidimensional array more distinctive?" }
13343
<p>I'm creating a Backbone App, and although everything seems to work i'm afraid i might need to refactor very soon if I keep adding functionalities and views with this approach. I'm using Parse in the backend, meaning that the object Parse is equivalent to the Backbone.Model. I can't control my models since they've be...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-05T13:32:21.310", "Id": "21551", "Score": "0", "body": "Why is `title` inside the response from `steps.fetch`?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-05T14:04:14.140", "Id": "21557", "Score...
[ { "body": "<p>The success function for the user.fetch statement is annoying. Just messing around, I am not sure this is any better as a whole (or if it even works):</p>\n\n<pre><code>var Util = {\n error: function (msg) {\n return function () { new Error({ message: msg }); };\n }\n};\n\nvar control...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-05T10:05:21.210", "Id": "13346", "Score": "1", "Tags": [ "javascript", "jquery", "backbone.js" ], "Title": "Backbone.js App approach not very scalable - nested views" }
13346
<p>This libray was written quite some time ago, and it has so far been used in all sorts of small-ish projects.</p> <p>I'm about to base a more complex, security (Access Control) related, open-source project on this library, so I thought it would be a good moment to ask for a code review.</p> <p><strong>Source:</stro...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-05T14:39:34.877", "Id": "21561", "Score": "0", "body": "Glad to see you have it commented, especially since you mentioned going to OS, they'd eat you alive otherwise :) I went ahead and edited this so that your sources were separated, ...
[ { "body": "<p>Alright, here we go. There's quite a bit so grab a drink, go to the bathroom, etc...</p>\n\n<p><strong>Unsetting Variables</strong></p>\n\n<p>I don't think unsetting the <code>$dbPass</code> was necessary as it only exists in the local scope of the constructor method, so a <code>var_dump()</code> ...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-05T13:28:46.370", "Id": "13352", "Score": "7", "Tags": [ "php", "security", "mysqli" ], "Title": "MySQLi DB library - quality/security review?" }
13352
<p>I knocked this up quickly to allow delayed <code>Invoke</code> on the dispatcher. Along with canceling the existing invocation and replacing with a new one, this allows throttling an action.</p> <pre><code>public static class DispatcherExtensions { private static Dictionary&lt;string, DispatcherTimer&gt; timers...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-05T17:02:13.687", "Id": "21571", "Score": "0", "body": "What kind of improvements are you looking for? Do you think there's something wrong with your code? Also, do you really want to always invoke the actions repeatedly (that's what `...
[ { "body": "<p>I'm not an expert on multithreading at all, but I've attempted refactoring your code a bit.\nFirst of all, to code defensively, I suggest adding the <code>readonly</code> modifier to your lock object. It's not required but will prevent accidental assignments:</p>\n\n<pre><code>private static reado...
{ "AcceptedAnswerId": "13363", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-05T13:59:24.037", "Id": "13354", "Score": "3", "Tags": [ "c#", "multithreading", "wpf" ], "Title": "Delayed dispatcher invoke" }
13354
<p>I came up with the idea of a small utility class that will poll <em>some delegate</em> until the response received meets <em>some condition</em>, upon which it will notify the main thread which can take the appropriate action.</p> <p>This is the first time I've ever done something like this, and I know that in gene...
[]
[ { "body": "<blockquote>\n <p>I want to do this in a way that consumes minimal resources</p>\n</blockquote>\n\n<p>Then don't have a separate thread that's not doing anything most of the time. Each thread in .Net consumes 1 MB of memory (both virtual and physical) and some other resources. A better solution woul...
{ "AcceptedAnswerId": "13366", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-05T14:57:56.183", "Id": "13357", "Score": "5", "Tags": [ "c#", "multithreading", "generics", "delegates" ], "Title": "Polling loop to run in a background thread" }
13357
<p>I live in a country where an electricity blackout happens after every hour, which corrupts the Minecraft save files, so I came up with this auto backup utility which backs up the <em>%appData%.minecraft\saves</em> folder constantly after a specified time.</p> <p>It works fine but I'm still not satisfied with it. T...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-05T19:57:14.053", "Id": "21595", "Score": "3", "body": "Have you considered using [ConfigParser](http://docs.python.org/library/configparser.html)? I think it would simplify your code. Also you could print a triple quote string instead...
[ { "body": "<pre><code>import time\nimport os\nimport sys\n\n#class for parsing settings.ini\nclass parseIni(object):\n</code></pre>\n\n<p>Python style guide recommends names like <code>ParseIni</code></p>\n\n<pre><code> def __init__(self, fileStream):\n</code></pre>\n\n<p>Python style guide recommends argume...
{ "AcceptedAnswerId": "13397", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-05T15:34:57.257", "Id": "13358", "Score": "3", "Tags": [ "python", "file-system", "minecraft" ], "Title": "Minecraft auto-backup utility" }
13358
<p>I need to create a class with two properties:</p> <ol> <li><code>LogOutput</code></li> <li><code>ExceptionOutput</code></li> </ol> <p>These properties (of type <code>Action</code>) send a message or a exception depending on the target function. This target function is set via properties. Currently, I have the foll...
[]
[ { "body": "<p>Yes, I think this is reasonable code. If you want to set more delegates at the same time or unsubscribe a delegate, events would be more appropriate. But if you don't want to do that, delegate properties are fine.</p>\n\n<p>There are some things to think about though:</p>\n\n<ol>\n<li><p>The code ...
{ "AcceptedAnswerId": "13367", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-05T15:56:07.203", "Id": "13359", "Score": "2", "Tags": [ "c#", "delegates", "properties" ], "Title": "Is it correct to use delegates as properties?" }
13359
<p>I need a NumPy matrix with comparisons among all elements in a sequence:</p> <pre><code>from numpy import matrix seq = [0, 1, 2, 3] matrix([[cmp(a, b) for a in seq] for b in seq]) </code></pre> <p>I'd like to know if there is a better way to do this.</p>
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-06T15:02:56.917", "Id": "21653", "Score": "0", "body": "Useful reference for anyone wanting to take this on: http://www.scipy.org/NumPy_for_Matlab_Users" } ]
[ { "body": "<p>Why are you using <code>matrix</code> rather than <code>array</code>? I recommend sticking with <code>array</code></p>\n\n<p>As for a better way:</p>\n\n<pre><code>seq = numpy.array([0, 1, 2, 3])\nnumpy.clip(seq[:,None] - seq, -1, 1)\n</code></pre>\n\n<ol>\n<li><code>seq[:, None]</code>, moves the...
{ "AcceptedAnswerId": "13396", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-05T17:22:07.140", "Id": "13364", "Score": "1", "Tags": [ "python", "matrix", "numpy" ], "Title": "Element-comparison NumPy matrix" }
13364
<p>I've been using this syntax alot recently to keep my class in scope of nested functions. It seems to work well in small to moderately sized class but I'm starting to wonder how efficient it actually is and if there is a better way to handle this. Any suggestions would be really useful.</p> <pre><code>myClass.protot...
[]
[ { "body": "<p>Yes, you can avoid creating functions inside functions entirely and you are correct it would be unmaintainable in the long term.</p>\n\n<pre><code>function MyClass() {\n //Proxy methods in constructor, so that the instance will have fixed context in the callbacks\n this.ajaxSucceeded = $.pro...
{ "AcceptedAnswerId": "13372", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-05T18:32:37.253", "Id": "13370", "Score": "3", "Tags": [ "javascript", "jquery" ], "Title": "var that = this; Keeping a class in scope of nested functions" }
13370
<p>I am putting together an animated drawer from scratch for use but also as a learning experience as I am not very strong with jQuery and would really like to get better.</p> <p>I am hoping that someone here might take a moment to look over my JSFiddle and give me some direction/tips to help me continue to progress?<...
[]
[ { "body": "<p>There are a few issues with your code I've modified it below. Some of the changes I made:</p>\n\n<ol>\n<li><p>cache your jQuery objects</p></li>\n<li><p>reword your <code>slideMessage</code> condition so that it is more readable</p></li>\n<li><p>parameterize the animations and pull them out into m...
{ "AcceptedAnswerId": "13380", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-05T21:28:17.190", "Id": "13377", "Score": "3", "Tags": [ "javascript", "jquery" ], "Title": "jQuery Drawer with Tab" }
13377
<p>I want to call an <code>Action</code> every X cycles (in my case, to a transaction commit every 100 records), so I do:</p> <pre><code>public class CyclicActionCaller { private int _counter; private int _cycleValue; private Action _methodToCall; public CyclicActionCaller() { _counter = 0...
[]
[ { "body": "<p>No, it's not thread-safe. Between the call to <code>Interlocked.Increment()</code> and the <code>if</code> check, another thread could call <code>Interlocked.Increment()</code>. That means both of them could see that <code>_counter</code> is 101, which means a call to <code>_methodToCall</code> wo...
{ "AcceptedAnswerId": "13387", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2012-07-06T06:01:22.587", "Id": "13382", "Score": "2", "Tags": [ "c#", "multithreading" ], "Title": "Call Action every X cycles" }
13382
<p>I was working on the challenge <em><a href="https://www.interviewstreet.com/challenges/dashboard/#problem/4f304a3d84b5e" rel="noreferrer">Save Humanity</a></em> from <a href="http://www.interviewstreet.com" rel="noreferrer">Interviewstreet</a> for a while then gave up, solved a few other challenges, and have come ba...
[]
[ { "body": "<p>1.I would use something like \"APPROXIMATE BOYER-MOORE STRING MATCHING\" described here: </p>\n\n<p><a href=\"http://www.cs.hut.fi/~tarhio/papers/abm.pdf\" rel=\"nofollow\">http://www.cs.hut.fi/~tarhio/papers/abm.pdf</a></p>\n\n<p>2.The second option is the Suffix Tree Solution:</p>\n\n<p><a href=...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-06T06:08:54.077", "Id": "13383", "Score": "8", "Tags": [ "java", "strings", "interview-questions" ], "Title": "Approximate String Matching Interview Question" }
13383
<p>The question was, which is the biggest product you can make from the digits of 1 to 9 (which is 9642*87531, BTW). It is pretty clear that one number starts with 9 and the other with 8, and that you need to append the remaining digits in descending order to one or the other number.</p> <pre><code>buildList x y [] ac...
[]
[ { "body": "<p>Here is a quick try to implement your algorithm using 'foldr'. I did not check in depth whether my solution is correct.</p>\n\n<p>I have divided the problem into parts. First we define a function that takes a list and splits the list into pairs of partitions where the order of elements is preserve...
{ "AcceptedAnswerId": "13392", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2012-07-06T06:57:59.617", "Id": "13385", "Score": "3", "Tags": [ "haskell" ], "Title": "Finding the biggest product of two integers formed by the digits 1-9" }
13385
<p>I need some help improving my code and wondering if I there is a better way to do the following:</p> <pre><code>StringBuilder buf = new StringBuilder(node.length() + 8); for (int i=0, n=node.length(); i&lt;n; i++) { char c = node.charAt(i); String hexadecimal = ""; switch...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-06T10:30:12.593", "Id": "21640", "Score": "2", "body": "I'm not that versed in Java but isn't toHexString('#') == 22? So do you need the switch at all?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-06T11...
[ { "body": "<p>A hash map is often a good idea for avoiding switch statements. It can be used in combination with the Strategy and Abstract Factory patterns, <a href=\"https://codereview.stackexchange.com/a/13347/14561\">such</a> <a href=\"http://www.tomasmalmsten.com/2011/01/create-factory-strategies-ifs/\" rel...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-06T09:45:01.027", "Id": "13389", "Score": "13", "Tags": [ "java" ], "Title": "Hexadecimal converter using a switch statement" }
13389
<p>This is a followup to <a href="https://codereview.stackexchange.com/questions/13357/polling-loop-to-run-in-a-background-thread">this</a> where I was initially using a single thread and <code>Thread.Sleep()</code> to poll a delegate. I was recommended to use a timer and the <code>ThreadPool</code> to minimize resourc...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-06T14:24:33.237", "Id": "21650", "Score": "1", "body": "You don't need to manually queue to the thread pool from the `Elapsed` handler. It already executes on the thread pool." }, { "ContentLicense": "CC BY-SA 3.0", "Creati...
[ { "body": "<p><strong>Technical</strong></p>\n\n<ol>\n<li>I'd use <code>Stop</code> rather than <code>Halt</code> - somehow sounds more natural.</li>\n<li><p>You should make more use of <code>Action</code> rather defining a bunch of delegate types. For instance this:</p>\n\n<pre><code>public delegate T RequestS...
{ "AcceptedAnswerId": "36115", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-06T14:02:59.037", "Id": "13393", "Score": "11", "Tags": [ "c#", "multithreading", "thread-safety", "timer" ], "Title": "Timer to poll a Delegate" }
13393
<p>I'm updating and old project from <a href="http://api.jquery.com/category/version/1.4/" rel="nofollow">jQuery 1.4</a> to <a href="http://api.jquery.com/category/version/1.7/" rel="nofollow">jQuery 1.7</a>.</p> <p>Can this be simplified, thus reducing the amount of code, and perhaps in such reduction, have it improv...
[]
[ { "body": "<p>Your code looks OK to me, very clear and organised.</p>\n\n<p>It's more important to <a href=\"http://en.wikipedia.org/wiki/Minification_%28programming%29\" rel=\"nofollow\">minify</a> your code to decrease load time. There's a whole bunch of minification tools on the Internet.</p>\n", "commen...
{ "AcceptedAnswerId": "13408", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-06T14:13:28.337", "Id": "13394", "Score": "3", "Tags": [ "javascript", "jquery", "dom", "e-commerce" ], "Title": "Showing an item in a shopping cart" }
13394
<p><a href="http://www.w3.org/TR/DOM-Level-2-Core/introduction.html" rel="nofollow">What is the Document Object Model?</a></p> <blockquote> <p>The Document Object Model (DOM) is an application programming interface (API) for valid HTML and well-formed XML documents. It defines the logical structure of documents and ...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-06T18:00:40.147", "Id": "13398", "Score": "0", "Tags": null, "Title": null }
13398
The Document Object Model (DOM) is an application programming interface (API) for valid HTML and well-formed XML documents. It defines the logical structure of documents and the way a document is accessed and manipulated.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-06T18:00:40.147", "Id": "13399", "Score": "0", "Tags": null, "Title": null }
13399
<p>I want to display a table similar to this:</p> <blockquote> <p><img src="https://i.stack.imgur.com/bvdeh.jpg" alt="Desired Table"></p> </blockquote> <p>This table is generated from three tables depending on the student ID:</p> <blockquote> <p><img src="https://i.stack.imgur.com/MIXvr.jpg" alt="Information"></...
[]
[ { "body": "<p>Probably the biggest thing that I would suggest you improve upon, is your spacing. For example, compare the following two code blocks.</p>\n\n<p><strong>Code Block 1</strong></p>\n\n<pre><code>$sj = mysql_query(\"SELECT * FROM subjects\"); \n$dsj=1; \nwhile ($rowsj= mysql_fetch_array($sj)){ \n$sj...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2012-07-06T18:53:16.600", "Id": "13401", "Score": "3", "Tags": [ "php", "mysql" ], "Title": "Student marks report" }
13401
<p>A <a href="https://en.wikipedia.org/wiki/Uniform_Resource_Locator" rel="nofollow noreferrer">Uniform Resource Locator (URL)</a> is a <a href="https://en.wikipedia.org/wiki/Uniform_resource_identifier" rel="nofollow noreferrer">Uniform Resource Identifier (URI)</a> that specifies where an identified resource is avail...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-06T18:55:08.847", "Id": "13402", "Score": "0", "Tags": null, "Title": null }
13402
A Uniform Resource Locator (URL) is a Uniform Resource Identifier (URI) that specifies where an identified resource is available and the mechanism for retrieving it.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-06T18:55:08.847", "Id": "13403", "Score": "0", "Tags": null, "Title": null }
13403
<p>I have the following tables set up:</p> <p><code>t_users</code> table:</p> <pre class="lang-none prettyprint-override"><code>|----------------------------------| |uid | name | email | |----------------------------------| |1 | Maria | maria@example.com | |2 | George | george@example.com | |----...
[]
[ { "body": "<p>At first glance, there are some alarm bells ringing.</p>\n\n<ul>\n<li>You have <code>t_users_settings.t_sid IS NOT NULL AND t_users_settings.t_uid IS NOT NULL</code>. The first seems to imply you might have NULL values in your <code>t_users_settings.t_sid</code> column. The second seems to defeat ...
{ "AcceptedAnswerId": "13419", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-06T20:11:34.083", "Id": "13404", "Score": "7", "Tags": [ "mysql", "sql" ], "Title": "Expanding a working query without adding multiple join statements?" }
13404
<p>I'm trying to optimize this bit of code and I thought I'd throw it out here to see if anyone has any ideas. I've been testing the performance using <code>Benchmark.measure {...}</code> and wrapping the entire function.</p> <p>Yes, the item has a date that is a Ruby <code>Date</code></p> <pre><code> puts Benchmark...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-07T01:21:09.817", "Id": "21697", "Score": "0", "body": "Nope. I'll check that out." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-08T00:58:49.843", "Id": "21698", "Score": "0", "body": "In futu...
[ { "body": "<p>Are you aware of <code>Enumerable#group_by</code>?</p>\n\n<pre><code>def grouped_items\n @items.group_by{|item| item.date}\nend\n</code></pre>\n", "comments": [ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-07T01:41:57.013", "Id": "21672", ...
{ "AcceptedAnswerId": "13411", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-07T01:25:10.530", "Id": "13410", "Score": "5", "Tags": [ "ruby", "performance", "array" ], "Title": "How can I optimize this array.each in ruby?" }
13410
<p><a href="http://williams.best.vwh.net/sunrise_sunset_algorithm.htm" rel="nofollow">This</a> is the algorithm for calculating sun rise/set time at various places on Earth. I took it as an example of multiple functions inside of one top function.</p> <p>This is Ver 0.3:</p> <pre><code>fromDegree deg = deg * pi / 180...
[]
[ { "body": "<p>first thing good question and good observation - the code is ugly ;-), but here it starts getting better; You have a lot duplicate functionality and plain code duplication.</p>\n\n<blockquote>\n <p>Here are my questions:</p>\n \n <p>What should I do with sun arguments? To force all of them to b...
{ "AcceptedAnswerId": "13416", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-07T03:05:22.637", "Id": "13413", "Score": "4", "Tags": [ "haskell", "datetime", "geospatial" ], "Title": "Calculating sun rise/set time at various places on Earth" }
13413
<p>I'm studying Common Lisp on my own. Coming from C++, Common Lisp feels kind of strange sometimes. I'd like to get some feedback on what I understood so far.</p> <p>For learning purposes, I wrote this simple vector class package. The only requirements apart from correctness are non-destructiveness and performance. I...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-08T02:50:22.847", "Id": "21712", "Score": "1", "body": "Start with using the time macro, check out how to disassemble functions, and try to find a good profiler for your lisp implementation" } ]
[ { "body": "<p>Here are a few minor suggestions:</p>\n\n<ol>\n<li>Use uninterned symbols instead of keywords in <code>defpackage</code> (e.g., <code>#:neg</code> instead of <code>:neg</code>) to avoid polluting the keyword package.</li>\n<li>Fix your indentation.</li>\n<li>Add a <code>defgeneric</code> with docs...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-07T08:54:18.533", "Id": "13414", "Score": "4", "Tags": [ "performance", "functional-programming", "common-lisp", "computational-geometry" ], "Title": "First Common Lisp vector ma...
13414
<p>I have an abstract class <code>Entity</code> in my code, which requires a reference to an instance of <code>EntityData</code> to operate. (<code>EntityData</code> provides basic information about the type of the entity).<br/> In the design of my program, every type of entity would have its own class that extends <co...
[]
[ { "body": "<p>I think I personally like the set by constructor method in general. I think it provides a means by which you can better allow for TDD and also implicitly implies the contract all inheriting classes must obey in providing a Entity object if they wish to inherit from the base class. </p>\n\n<p>I t...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-07T16:56:12.560", "Id": "13420", "Score": "5", "Tags": [ "c#", "static" ], "Title": "`Static inheritance` pattern" }
13420
<p>As sort of a follow up to my <a href="https://codereview.stackexchange.com/questions/3212/improving-a-custom-integer-class">previous question</a> from a year ago, what are some suggestions you can think of that will improve this code, whether is directly programming related or algorithm related? I know there are bet...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-08T03:24:45.580", "Id": "21713", "Score": "2", "body": "At a quick glance, operator bool() makes me uneasy. But since this is pretty large, I tried compiling and running it. I did find that evaluating (integer && anything) causes a sta...
[ { "body": "<p>I'm not familiar with the algorithms used (or any in the same category for that matter), but I do have a few notes on style/practices.</p>\n\n<hr>\n\n<p><strong>std::cerr/exit inside of a class</strong></p>\n\n<p>If a value is unexpected or invalid for a parameter, exceptions should be used, not o...
{ "AcceptedAnswerId": "13452", "CommentCount": "16", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-07T23:17:09.547", "Id": "13424", "Score": "5", "Tags": [ "c++", "integer" ], "Title": "Improving a custom integer class 2.0" }
13424
<p>After the purpose and specifications of software are determined, software developers will design or employ designers to develop a plan for a solution. It includes low-level component and algorithm implementation issues as well as the architectural view.</p> <p><strong>Software design topics</strong></p> <ul> <li><...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-07T23:33:14.987", "Id": "13425", "Score": "0", "Tags": null, "Title": null }
13425
Software design is a process of problem solving and planning for a software solution.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-07T23:33:14.987", "Id": "13426", "Score": "0", "Tags": null, "Title": null }
13426
<p>An HTML form is a section of a document containing normal content, markup, special elements called controls (checkboxes, radio buttons, menus, etc.), and labels on those controls.</p> <p>Users generally "complete" a form by modifying its controls (entering text, selecting menu items, etc.), before submitting the fo...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-07T23:56:11.570", "Id": "13427", "Score": "0", "Tags": null, "Title": null }
13427
An HTML form is a section of a document containing normal content, markup, special elements called controls and labels on those controls.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-07T23:56:11.570", "Id": "13428", "Score": "0", "Tags": null, "Title": null }
13428
<p>Programming style aka <em>code style</em> or <em>coding style</em>, is a set of rules or guidelines used when writing the source code for a computer program.</p> <p>It is often claimed that following a particular programming style will help programmers to read and understand source code conforming to the style, and...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-08T00:18:02.497", "Id": "13429", "Score": "0", "Tags": null, "Title": null }
13429
Programming style is a set of rules or guidelines used when writing the source code for a computer program.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-08T00:18:02.497", "Id": "13430", "Score": "0", "Tags": null, "Title": null }
13430
<p><a href="http://en.wikipedia.org/wiki/Comma-separated_values" rel="nofollow">Comma-separated values</a> is a common, relatively simple file format that is widely supported by consumer, business, and scientific applications. Among its most common uses is moving tabular data between programs that natively operate on i...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-08T00:38:39.863", "Id": "13432", "Score": "0", "Tags": null, "Title": null }
13432
A comma-separated values (CSV) file stores tabular data (numbers and text) as plain text, with rows and columns delimited by line terminators and commas, respectively. You may also use this tag for variants where fields are separated by tabs or semicolons.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-08T00:38:39.863", "Id": "13433", "Score": "0", "Tags": null, "Title": null }
13433
<p>I am using an Xbox controller to send data to my computer, and am using the <code>SendInput</code> method to handle keys. I was wondering if there was any other, better way to do this. </p> <pre><code>INPUT Input = { 26 }; Input.type = INPUT_KEYBOARD; Input.ki.dwFlags = VK_UP; SendInput(1, &amp;Input, sizeof(INPUT)...
[]
[ { "body": "<p>Are you wanting to direct this to a specific application? It's usually better to send <a href=\"http://msdn.microsoft.com/en-us/library/windows/desktop/ms646280%28v=vs.85%29.aspx\" rel=\"nofollow\"><code>WM_KEYDOWN</code></a> and/or <a href=\"http://msdn.microsoft.com/en-us/library/windows/desktop...
{ "AcceptedAnswerId": "13440", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-08T02:38:44.577", "Id": "13439", "Score": "1", "Tags": [ "c++" ], "Title": "Is there a better way to use SendInput?" }
13439
<p><em><a href="https://github.com/Onheiron/foRml" rel="nofollow">GitHub project repo</a></em></p> <p>I've been working on this little function to convert an HTML form into a JSON Object having the same structure of the form. Basically it is intended to be useful in those situations where you let your user dynamically...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-09T17:56:17.537", "Id": "21785", "Score": "3", "body": "Have you considered [Knockout.js](http://knockoutjs.com/)? I am working on an answer specifically to this question but modification to handle combos/radios/dates/tabular data/what...
[ { "body": "<p>This is a re-implementation of jQuery's build-in <a href=\"http://api.jquery.com/serialize/\" rel=\"nofollow\">serialize()</a> function. In general I would recommend using the built-in function since the jQuery developers will keep it updated for browser compatibility and use with other jQuery fu...
{ "AcceptedAnswerId": "15373", "CommentCount": "8", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-08T10:51:29.593", "Id": "13443", "Score": "5", "Tags": [ "javascript", "jquery", "html", "json", "form" ], "Title": "jQuery plugin $(node).toJSON() - convert html form to ...
13443
<p>File Transfer Protocol (FTP) is a standard network protocol used to transfer files from one host to another host over a <a href="http://en.wikipedia.org/wiki/Transmission_Control_Protocol" rel="nofollow">TCP</a>-based network, such as the Internet.</p> <p>It is often used to upload web pages and other documents fro...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-08T22:46:25.787", "Id": "13445", "Score": "0", "Tags": null, "Title": null }
13445
File Transfer Protocol (FTP) is a standard network protocol used to transfer files from one host to another host over a TCP-based network, such as the Internet.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-08T22:46:25.787", "Id": "13446", "Score": "0", "Tags": null, "Title": null }
13446
<p>I feel like this structure could be better, but I can't realize how.</p> <pre><code> internal AuthenticationResult ProcessOpenIdResponse(IAuthenticationResponse response) { switch (response.Status) { case AuthenticationStatus.Authenticated: { string ope...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-08T23:29:47.317", "Id": "21729", "Score": "0", "body": "Can you include the whole method that this code is in? There's much more to improve in this and we need to see the whole picture." }, { "ContentLicense": "CC BY-SA 3.0", ...
[ { "body": "<p>I would first start by creating a method for the Authentication failed parts of the code. Something like</p>\n\n<pre><code>private AuthenticationResult AuthenticationFailed(AuthenticationStatus status, string message = \"\", Exception exception = null)\n{\n return new AuthenticationResult\n {...
{ "AcceptedAnswerId": "13449", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-08T22:48:02.783", "Id": "13447", "Score": "3", "Tags": [ "c#" ], "Title": "nested if structure, how could it be improved?" }
13447
<p>I want to get opinions on the code I have put together for a centralized DataContext via a DataHelper class that I have created to be re-used on projects. </p> <p><strong>NOTE</strong> - there is a ton of code here, sorry about that, but I really wanted to layout out the complete approach and uses for my ideas. I'm...
[]
[ { "body": "<p>I don't mean to hurt your feelings, because you've obviously put a lot of work into this, but I personally don't like it. It seems like you've forsaken Inversion of Control and Dependency Injection for a collection of static \"God\" classes and methods. </p>\n\n<p>For example, the <code>Context</c...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-08T23:09:53.187", "Id": "13448", "Score": "2", "Tags": [ "c#", "entity-framework" ], "Title": "Your Thoughts: Entity Framework Data Context via a DataHelper class (centralized context an...
13448
<p>I am fairly new to Entity Framework and I am not sure I am really using it to it's max potential. I have this query, that IMHO seems to take a little longer than I feel it should. I have tried various combinations to retrieve all the data I need making as few connections as possible and so far this query yeilds th...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-09T04:12:21.553", "Id": "21752", "Score": "2", "body": "320ms? Is this called in a loop a million times? That's hardly poor performance. I've seen some EF code take multiple seconds at times on some pretty heavy metal servers. I'd fire...
[ { "body": "<p>First things first. Since we are talking about an SQL backend (unless I'm mistaken) - you need to profile SQL and take each (sub)query seperately, then determine which query takes the longest. It would simply be pure guess work, taking answers out of thin air otherwise, since we have no reference ...
{ "AcceptedAnswerId": "30143", "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-09T00:17:14.130", "Id": "13450", "Score": "2", "Tags": [ "c#", "linq", "entity-framework" ], "Title": "Linq-to-entities query too slow" }
13450
<p>I'm completing exercises in <em>Compilers: Principles, Techniques, and Tools (2nd Edition)</em> in Python. The following code converts:</p> <pre><code>{ int x; char y; { bool y; x; y; } x; y; } </code></pre> <p>to:</p> <pre><code>{ { x:int; y:bool; } x:int; y:char; } </code></pre> <p>I had the following concerns...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-09T03:48:31.447", "Id": "21760", "Score": "0", "body": "It may be worth looking into pylint and pychecker, there are a number of quick fixes and small errors that come up" } ]
[ { "body": "<pre><code>class exercise(object):\n</code></pre>\n\n<p>The python style guide recommends CamelCase for class names</p>\n\n<pre><code> \"\"\"\n program -&gt; block\n block -&gt; { decls stmts }\n decls -&gt; decls decl\n | ∅\n decl -&gt; type id ;\n stmts -&gt; ...
{ "AcceptedAnswerId": "13467", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-09T00:41:02.803", "Id": "13451", "Score": "3", "Tags": [ "python" ], "Title": "Does this code use good Python practices for a context-free grammar implementation?" }
13451
<p>I've been doing MVC for a few months now using the CodeIgniter framework in PHP but I still don't know if I'm really doing things right.</p> <p>What I currently do is:</p> <p><strong>Model</strong> - this is where I put database queries (select, insert, update, delete). Here's a sample from one of the models that ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-09T05:51:45.693", "Id": "21753", "Score": "3", "body": "just a quick note on 'encryption/Bcrypt': BCrypt is a hashing algorithm, so it is not encryption. Encryption is reversible, hashing is intended to be one way. Think of a hashing a...
[ { "body": "<p>Your understanding of MVC seems to be skewed. There are slightly different implementations of MVC, so one person's definition of a certain aspect of it might be slightly different than another's. I'll explain how basic MVC works, and why I think your implementation is not a true implementation of ...
{ "AcceptedAnswerId": "13538", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-09T03:06:02.983", "Id": "13453", "Score": "4", "Tags": [ "php", "mvc", "validation" ], "Title": "Applying MVC to a validation application" }
13453
<p>I've written a short piece of code to get myself familiar with backbone.js. I'm filtering 100 results from the Twitter API. Once those are in, I use a time picker and a hash tag selector to filter my results.</p> <p>I want the filter to work in the following manner:</p> <p>Pick a time range, get a filtered collect...
[]
[ { "body": "<p>From a once over:</p>\n\n<p><strong>Collection</strong></p>\n\n<ul>\n<li>You could merge those 2 if statements into 1</li>\n<li>You should remove commented out code</li>\n<li>You should remove console.log code</li>\n<li>You should try to have 1 chained <code>var</code> block</li>\n<li>You should u...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-09T03:26:19.193", "Id": "13454", "Score": "5", "Tags": [ "javascript", "backbone.js", "twitter" ], "Title": "Filtering a Backbone collection with multiple parameters" }
13454
<p>There is a handful of LinkedIn clients written in C# on the NuGet package library, but as far as I can tell, most only do authentication via LinkedIn. I found a couple which offer a LinkedIn REST API interface. Of those two, <a href="http://djsolid.net/blog/linked-in-oauth-library">one looks like it has gone inactiv...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-16T21:53:08.633", "Id": "87939", "Score": "5", "body": "I really can't find anything to comment on in a review. This is well written code, and obviously well thought out." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDa...
[ { "body": "<p>As @Jeff pointed out, this code is ...beautiful. Well done!</p>\n\n<hr>\n\n<p>I like the fluent interface a lot, but the code itself is at first glance... wow.</p>\n\n<ul>\n<li><p><strong>Naming</strong> </p>\n\n<ul>\n<li>All identifiers follow conventional casing (<code>camelCase</code> for local...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-09T06:26:07.083", "Id": "13458", "Score": "28", "Tags": [ "c#", ".net", "asp.net-mvc-3", "rest", "linkedin" ], "Title": "Fluent LinkedIn REST API client interface design" }
13458
<p>I have a grid that lists products. The grid is three columns wide, but it could grow to be four or five columns wide. I've written my script to count the columns. The markup is something like this:</p> <pre><code>&lt;ul&gt; &lt;li class="item first"&gt;...&lt;/li&gt; &lt;li class="item"&gt;...&lt;/li&gt; ...
[]
[ { "body": "<p>Can't say if this is much faster, but it's more concise</p>\n\n<pre><code>jQuery(document).ready(function($) {\n \"use strict\";\n\n var firstItems = $('.item.first');\n\n firstItems.each(function() {\n var $first, row, headings, heights, maxHeight;\n\n $first = $(this);\n\n...
{ "AcceptedAnswerId": "13460", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-09T09:18:51.673", "Id": "13459", "Score": "0", "Tags": [ "javascript", "jquery" ], "Title": "Iterating through each grid row and matching elements to largest height" }
13459
<p>I have written some code to establish a client and server. I have managed to get a one way communication from client to server. I have added the code below. Can someone please have a look and see it is the right way to do it? If this is good enough, how can I get two communication to work now?</p> <p>Client: </p> ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-09T08:00:36.123", "Id": "21763", "Score": "0", "body": "what i meant to ask if my code was the right way to establish one way communication??\nmy more specific ques is how can i establsih 2-way (duplex communication)?" }, { "Co...
[ { "body": "<p>You can do a two way data transfer here. I have modified your code to show that. Now the \nserver is echoing back to the client the same string which it has received. Now the client \ndisplays the same string, which it receives from the server. Pl. experiment with this. </p>\n\n<p>client main loop...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-09T03:34:04.230", "Id": "13461", "Score": "8", "Tags": [ "c", "networking" ], "Title": "Two-way communication in TCP: server-client implementation" }
13461
<p>Does this piece of code make sense? The idea is to throw any exceptions that may occur but always run the finally block to close the streams. </p> <pre><code>private void streamToFile(HttpResponse transferResponse) throws Exception { OutputStream output = null; InputStream input = null; try { in...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-09T14:29:22.117", "Id": "21765", "Score": "4", "body": "This is what a `finally` block is for." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-09T15:03:15.677", "Id": "21767", "Score": "0", "bod...
[ { "body": "<p>Yes this is the right way to do it but you should check output and input variables for null value before calling on them the close() method.</p>\n", "comments": [ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-06-03T05:06:00.057", "Id": "91651", ...
{ "AcceptedAnswerId": "13466", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-09T13:58:46.877", "Id": "13464", "Score": "2", "Tags": [ "java", "exception-handling" ], "Title": "Throwing the Exception But Using the Finally Block" }
13464
<p>The following works as intended, however is there a more concise way to write this script without changing it too much? It's a simple menu with sub-levels which have a plus/minus icon when each <code>li</code> opens/closes.</p> <p>jQuery:</p> <pre><code>$(document).ready(function() { $li = $('#main &gt; li.exp...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-09T16:46:57.007", "Id": "21777", "Score": "1", "body": "One suggestion, add `var` before your variables." } ]
[ { "body": "<p>Some suggestions:</p>\n\n<ul>\n<li>Use <code>var</code> when declaring variables, unless you <em>really</em> want to make global variables (which you probably don't)</li>\n<li><p>Combine <code>var</code> statements using <code>,</code></p>\n\n<pre><code>var a = 1, b = 2, c = 3;\n</code></pre></li>...
{ "AcceptedAnswerId": "13471", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-09T16:51:30.113", "Id": "13468", "Score": "7", "Tags": [ "javascript", "jquery", "html" ], "Title": "Simple menu with sub-levels" }
13468
<p>This is my very very very first attempt to write anything meaningful in node. The client side is a simple form that has login, workspace, and simply saves them onto the database. It would have been a 5-liner in PHP!</p> <p>My question really is: does this code look sane/good? I am trying to avoid using async.js for...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-09T09:29:00.990", "Id": "21789", "Score": "0", "body": "since you are using mongodb, and i assume a workspace has many users, why dont you embed users in the workspace collection?" } ]
[ { "body": "<blockquote>\n <p>There is a lot of indentation here. I know that it's a known issue with node...</p>\n</blockquote>\n\n<p>In JavaScript you can avoid deep nesting by defining the functions ahead of time. For example:</p>\n\n<pre><code>var userFindOneHandler = function(err, docs) {\n // code here ...
{ "AcceptedAnswerId": "15423", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-09T03:28:10.490", "Id": "13473", "Score": "1", "Tags": [ "javascript", "node.js", "asynchronous" ], "Title": "A server response written in node/express/mongodb: does this look rig...
13473
<p>I've got a class which describes and calculates centrifugal pump impeller properties (dimensions, flow speed etc. ). At the beginning i have created it in this way (since my class is quite large and calculations are complex i will simplify it using cylinder as example):</p> <pre><code>class Cylinder { double he...
[]
[ { "body": "<p>I'm feeling like this isn't a good place to have properties changing. In other words, if your objects are indeed similar to a <code>Cylinder</code>, perhaps they should be immutable. That way, calculations can be a) done once at construction, b) done once, but lazily or c) done every time the prop...
{ "AcceptedAnswerId": "13479", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-09T18:49:26.893", "Id": "13475", "Score": "5", "Tags": [ "c#" ], "Title": "Multiple properties updated by event vs few properties and methods" }
13475
<p>I am learning scheme to get something new from a programming language and this code below is the solution to Project Euler question 21 but the code runs 10x slower than the listed Python code when I use Chibi-Scheme. Can any Scheme craftsman refactor the code into the Scheme idiom for efficiency.</p> <p>Scheme Code...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-12-01T21:10:02.193", "Id": "130392", "Score": "1", "body": "Chibi is meant to be small and easily embedded, not a speed demon. Fast Schemes include Gambit and Chicken (both of which are compilers, and are available for Windows)." } ]
[ { "body": "<p>Well, for one thing, the python code is using a set for its amicable_pair_set, where-as you're using a large vector and setting the n'th element to n when you need to add to the set. It's a reasonable way to imitate a set, if your scheme doesn't have a set library; however, this situation doesn't...
{ "AcceptedAnswerId": "13557", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-09T19:10:23.620", "Id": "13476", "Score": "4", "Tags": [ "python", "optimization", "project-euler", "scheme", "programming-challenge" ], "Title": "A little scheme programm...
13476
<p>I'm writing something that basically takes a bunch of files and renames them into a nice format, such as <code>pic_000.jpeg</code>, <code>pic_001.jpeg</code>, etc. One of the options is to write the incrementation as letters, e.g. <code>pic_aaa.jpeg</code>, <code>pic_aab.jpeg</code>, etc. Also, is they are convert...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-10T19:26:02.747", "Id": "112451", "Score": "0", "body": "Instead of doing it yourself, use this: http://gladman.plushost.co.uk/oldsite/computing/gmp4win.php and http://www.mpir.org/ also see: http://www.exploringbinary.com/how-to-insta...
[ { "body": "<h2>First Point:</h2>\n\n<p>For multiple <code>If</code>/<code>Else</code> blocks, I prefer to use <a href=\"http://msdn.microsoft.com/en-us/library/cy37t14y.aspx\" rel=\"nofollow\"><code>Select Case</code></a>. I would just do this out of habit, though your check is small enough that it may not matt...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-09T21:08:48.460", "Id": "13480", "Score": "3", "Tags": [ "converting", "iterator", "vb6" ], "Title": "Converting base-10 numbers into base-26 letters" }
13480
<p><strong>Question:</strong></p> <hr> <p>I'm attemping to modify a Javascript snippet to more efficiently get the user's current Zipcode. One problem that I am facing however is the lack of understanding around public functions. I am wondering if they are requried, and if they are not, then what would make the code ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-09T21:39:46.113", "Id": "21806", "Score": "0", "body": "What are you getting by making the internal functions here public and available on a global namespace?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07...
[ { "body": "<p>None of this code needs to create any global variables. The pattern you have here is known as <a href=\"http://addyosmani.com/blog/essential-js-namespacing/#beginners\" rel=\"nofollow\">namespace creation</a>.</p>\n\n<p>It often follows the pattern:</p>\n\n<pre><code>var myNamespace = (function ()...
{ "AcceptedAnswerId": "13483", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-09T21:28:56.593", "Id": "13481", "Score": "1", "Tags": [ "javascript", "jquery" ], "Title": "To use or not to use public variables in javascript?" }
13481
<p>This is my second "first" attempt at starting Java. My first was cut short when I had to go back to a PHP project that required my immediate attention. But perhaps that was a good thing. I learned quite a bit more about OOP, better coding practices, and some other topics. So, after this hiatus, I noticed quite a bit...
[]
[ { "body": "<h1>Addressing Questions and Concerns</h1>\n\n<ol>\n<li>What you have so far is typical for a Java view. The ActionListener (or any listener for that matter) should be moved to the Controller.</li>\n<li>Your imports ain't nothing. I'm not familiar with PHP, but in Java, every class is its own file (f...
{ "AcceptedAnswerId": "13487", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-09T22:00:45.423", "Id": "13482", "Score": "7", "Tags": [ "java", "swing", "beginner" ], "Title": "First Project: JFrame Class" }
13482
<p>I have to store some properties in a database properties table which looks like this:</p> <pre><code>CREATE TABLE `property` ( `id` int(11) NOT NULL AUTO_INCREMENT, `computer_name` varchar(64) NOT NULL, `name` varchar(64) NOT NULL, `value` varchar(1024) NOT NULL, PRIMARY KEY (`id`) ); </code></pre> <p>Sa...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-11T01:18:24.683", "Id": "21904", "Score": "0", "body": "Too lazy to write a proper response, but I have a feeling that this may be of use: http://www.scribd.com/doc/2670985/SQL-Antipatterns In particular the section that starts on page...
[ { "body": "<blockquote>\n <p>keep the value in one place which make it more simple to change it</p>\n</blockquote>\n\n<p>You will never change it (why would you?) so this is not a valid reason. And if you did change it then search/replace works fine.</p>\n\n<blockquote>\n <p>keep available property dictionary...
{ "AcceptedAnswerId": "13511", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-10T10:37:31.853", "Id": "13491", "Score": "0", "Tags": [ "php" ], "Title": "How to store option key names" }
13491
<p>I have implemented the "[ ]" operator in a class that I have created to return values associated with a key (the same concept of a dictionary, except that it's possible to have the same key more than one time). However, looking at my code I don't think it is as efficient as it could be.</p> <pre><code>public class ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-10T13:25:25.750", "Id": "21846", "Score": "7", "body": "Read about Generics (http://msdn.microsoft.com/en-US/library/ms379564.aspx) and favor them over storing items of type `object`." } ]
[ { "body": "<p>If you look for performance, you'd better rely on the framework dictionary. You can use the <code>Dictionary&lt;string, List&lt;object&gt;&gt;</code> to do what you need. When you add a new key and value, look if the key already exists. If so, add the value to the array and don't add the key.</p>\...
{ "AcceptedAnswerId": "13493", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-10T13:09:45.290", "Id": "13492", "Score": "1", "Tags": [ "c#", "collections" ], "Title": "Implementing [ ] operator" }
13492
<p>I've got a SQL database that keeps track of which services a client has. I need to create an image using SVG that only displays the services that the client has. The database stores the services in the format <code>1,2,3,6,7,9</code>. Here's what I have:</p> <pre><code> &lt;?php header("Content-type: image/s...
[]
[ { "body": "<pre><code>&lt;?php\n$formats = array(\n '1' =&gt; array(\n 'x1' =&gt; 820,\n 'y1' =&gt; 120\n ),\n '2' =&gt; array(\n 'x1' =&gt; 905,\n 'y1' =&gt; 180\n )\n);\n?&gt;\n\n&lt;?php foreach( $formats as $key =&gt; $format ) : ?&gt;\n &lt;?php if ( in_array( (in...
{ "AcceptedAnswerId": "13505", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-10T13:51:25.743", "Id": "13494", "Score": "3", "Tags": [ "php", "svg" ], "Title": "Best way to create SVG from database? (Using PHP)" }
13494
<p>I have a function called <code>FormatCurrency()</code> which I would like to call on each of the following elements:</p> <pre><code> TextBoxA TextBoxB TextBoxC ... TextBoxN </code></pre> <p>My current function performs the following operation</p> <pre><code> function formatALL() { //get the value into ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-05T23:59:42.270", "Id": "21849", "Score": "3", "body": "are you familiar with jQuery?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-06T00:06:09.633", "Id": "21850", "Score": "1", "body": "yes,...
[ { "body": "<p>stick all the strings into an array and iterate over them?</p>\n\n<p>something like</p>\n\n<pre><code>var myElems=[\"TextBoxA_TextBox\",\"TextBoxB_TextBox\",\"TextBoxC_TextBox\"];\nfor(var i = 0; i &lt; myElems.list; i++) {\n var v = document.getElementById(i).value;\n document.getElementByI...
{ "AcceptedAnswerId": "13497", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-05T23:57:28.667", "Id": "13495", "Score": "1", "Tags": [ "javascript", "formatting", "form" ], "Title": "Calling a FormatCurrency function on multiple textboses" }
13495
<p>All, I have written some code to get the latest files from a directory, the files I am looking for contain the string <code>sProcScript = "sProcScript"</code> and in the selected directory I might have several versions:</p> <pre><code>sProcScriptBigGuns1001.sql sProcScriptBigGuns1007.sql sProcScriptEdAggVal1006.sql...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-10T14:12:18.437", "Id": "21863", "Score": "0", "body": "This is not a code review question. I have demonstrated a viable solution to illustrate I don't want the work done for me. The question could be answered without the code snippet....
[ { "body": "<p>This should do it:</p>\n\n<pre><code>var selectedFileInfos = listFileInfo\n .Where(x =&gt; { \n var filename = Path.GetFileNameWithoutExtension(x.FullName); \n return specialProcList.Any(y =&gt; filename.Contains(y);})\n .OrderByDescending(x =&gt; x.Name)\n .GroupBy(x =&gt; ...
{ "AcceptedAnswerId": "13503", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-10T14:06:46.927", "Id": "13501", "Score": "3", "Tags": [ "c#", "linq" ], "Title": "Alternative way to extract the most recent file using LINQ" }
13501
<p>I have a number of jQuery animation effects applied to certain elements on the page:</p> <pre><code>jQuery("#bgd_balance").animate({ backgroundPositionY: "0px", backgroundPositionX: "0px", 'background-size':'100%' },800,"swing"); jQuery(".balance_left_box").delay(2000).slideDown(200,"easeI...
[]
[ { "body": "<p>The way I see it, you have 2 options; either use Deferreds, or store your delay in a variable:</p>\n\n<pre><code>var delay = 0,\n $left_box = $(\".balance_left_box\");\n\n$(\"#bgd_balance\").animate({\n backgroundPositionY: \"0px\",\n backgroundPositionX: \"0px\",\n 'background-size':'...
{ "AcceptedAnswerId": "13508", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-10T18:04:25.777", "Id": "13507", "Score": "6", "Tags": [ "javascript", "jquery", "animation" ], "Title": "\"Group\" animation events in jQuery" }
13507
<p>I have created a very simple script that will create two columns which are populated by an array. It works, but I am certain that the way that I have gone about it is not the best way. I have been searching for simple, sample scripts which would aide me in understanding how to best approach this, but all of them hav...
[]
[ { "body": "<p>Well, this is more concise, and it should be easy enough to scale:</p>\n\n<pre><code>&lt;?php\n$assets = array('Bag', 'Charger', 'Power Cable', 'Video Cable', 'Mouse', 'Keyboard', 'Test', 'Test 2', 'Test 3');\n\n$half = ceil(count($assets)/2);\n\n$columns = array(\n array_slice($assets, 0, $hal...
{ "AcceptedAnswerId": "13516", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-10T18:50:44.020", "Id": "13510", "Score": "2", "Tags": [ "php", "algorithm", "html" ], "Title": "Dynamic two-column list, \"Vertical Wrap\"" }
13510
<p>I've been advised that when checking the password hash for a user I should use a string comparison function that always takes the same amount of time, to avoid timing attacks.</p> <p><strong>So I wrote this:</strong></p> <pre><code>//this is a constant time string compare, //it does not exit early even if the stri...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-10T21:38:16.740", "Id": "21888", "Score": "0", "body": "How long is the hash? strcmp or === is going to have an extremely small difference between a matching string and an early bail. Have you timed to be sure that the string comparis...
[ { "body": "<p><strong>Disclaimer</strong></p>\n\n<p>I have no formal education in security or cryptography, nor any kind of meaningful experience with either.</p>\n\n<p>This post is basically me rambling, hopefully correctly :-).</p>\n\n<p><strong>Correctness</strong></p>\n\n<p>This is a very informal (and roug...
{ "AcceptedAnswerId": "13525", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-10T19:13:13.150", "Id": "13512", "Score": "14", "Tags": [ "php", "strings", "security" ], "Title": "Constant time string comparision in PHP to prevent timing attacks" }
13512
<p>I have an object array that contains various types of objects (primitives, strings, other object arrays) at arbitrary levels of nesting. I need to pull all objects of type <code>System.Web.UI.Pair</code> from this array and am having a heck of a time writing the method. This is especially difficult because the Pai...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-06T20:35:15.613", "Id": "21881", "Score": "2", "body": "Why are you using this old, forgotten class with a tool like LINQ? You could replace it for example with a [`Tuple<T1, T2>`](http://msdn.microsoft.com/en-us/library/dd268536.aspx)...
[ { "body": "<ol>\n<li><p>You don't need to return anything. The list you initially pass in is a reference, which you can use after the function returns. The function can be of type <code>void</code>.</p></li>\n<li><p>You can recurse on <code>First</code> and <code>Second</code>.</p></li>\n<li><p><code>root.GetTy...
{ "AcceptedAnswerId": "13515", "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2012-07-06T20:26:20.720", "Id": "13513", "Score": "3", "Tags": [ "c#", "linq", "recursion" ], "Title": "Recursively find all objects of type System.Web.UI.Pair in an object array" }
13513
<p>I'm doing a sort of exercise where I'm given a question, and I have to answer it by writing an SQL query using a database that I was given.</p> <p>This is the question:</p> <blockquote> <p>What is the cheapest fare for a one way flight from Boston to Baltimore?</p> </blockquote> <p>Here's what I came up with:</...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-10T21:39:02.043", "Id": "21889", "Score": "1", "body": "I assume you've never heard of a join?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-10T21:39:45.163", "Id": "21890", "Score": "4", "bod...
[ { "body": "<p>If the question is only asking for fares, you select the first result row of the fares allowing one-way tickets where the from airport is in Boston and the to airport is in Baltimore, sorted ascending by one way cost.</p>\n\n<p>Since this is tagged homework, I'll let you translate that to SQL. :-...
{ "AcceptedAnswerId": "13524", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-10T21:21:39.047", "Id": "13520", "Score": "3", "Tags": [ "beginner", "sql", "homework", "sqlite" ], "Title": "Finding the cheapest one-way air flight fare" }
13520
<p>Below are two implementations of the problem "find the characters in common between two strings" - in Clojure without using collections / set operations.</p> <p>Are these approaches sufficiently idiomatic and could the be more concise? (aside from using collections functions).</p> <p>Also, is there a Clojure libra...
[]
[ { "body": "<p>I would create two arrays size ALPHABET (one for each string) and just set the corresponding array element to 1 if a char exists in string (like char_array[c - 'A'] = 1). Then scan two arrays parallel and check if the same element is set for both strings.</p>\n\n<p>Pseudocode in python: </p>\n\n<p...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-10T21:36:32.390", "Id": "13521", "Score": "4", "Tags": [ "clojure" ], "Title": "Find the common characters between two strings without using set operations" }
13521