body
stringlengths
25
86.7k
comments
list
answers
list
meta_data
dict
question_id
stringlengths
1
6
<p>I'm learning C from the K.N. King book and just arrived at a question to reverse the words in a sentence.</p> <p>Here is the output:</p> <blockquote> <p>Enter a sentence: you can cage a swallow can't you?</p> <p>Reversal of sentence: you can't swallow a cage can you?</p> </blockquote> <p>Though I've done t...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-20T22:07:33.743", "Id": "35290", "Score": "0", "body": "Just a note - your reversal is incorrect; it should be \"you can't **swallow** a **cage** can you?\"" } ]
[ { "body": "<p>I'm not quite sure if you are aiming only for smaller length or also for better code/readability. Depending on the answer, you can take the following style comments into account (which are somehow pretty personal except for the last one):</p>\n\n<ul>\n<li>In C code, I find it easier to have bigger...
{ "AcceptedAnswerId": "22925", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-20T07:48:24.753", "Id": "22914", "Score": "4", "Tags": [ "c", "strings" ], "Title": "Reverse a string without the <string.h> header" }
22914
<p>I have written a lock free MPMC FIFO in C based on a ring buffer. It uses gcc's atomic built-ins to achieve thread safety. The queue is designed to return -1 if it's full on enqueue or empty on dequeue. </p> <p>After some feedback, I've changed by design. I have tested this code to work, but testing multithreaded c...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-21T18:54:29.420", "Id": "73066", "Score": "0", "body": "Also check out Relacy for thread-safeness-testing. No guarantees on its accuracy -- http://www.1024cores.net/home/relacy-race-detector" } ]
[ { "body": "<p>Did you test it? </p>\n\n<p>I think you have a problem if a thread calls <code>enqueue</code> and is interrupted\njust before the <code>memcpy</code>, having calculated <code>pos</code> to be slot-1. If another\nthread now calls <code>enqueue</code> and completes it will write to slot-2 and incr...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-20T08:10:15.767", "Id": "22915", "Score": "4", "Tags": [ "c", "multithreading", "thread-safety", "circular-list" ], "Title": "Lock free MPMC Ring buffer implementation in C" }
22915
<p>I'm querying a MySQL database and displaying the info in order of timestamp (DESC). Essentially, I'm grabbing the last record in the database, displaying it's date and year as the header of it's section and then going backwards from there. I've put together these if and else if statements to display the appropriate ...
[]
[ { "body": "<p>One possible solution would be to let your DB do the work. </p>\n\n<pre><code>SELECT DATE_FORMAT(´timestamp´, '%M') FROM user ORDER BY timestamp DESC LIMIT 1 \n</code></pre>\n\n<p>see <a href=\"http://dev.mysql.com/doc/refman/5.1/de/date-and-time-functions.html\" rel=\"nofollow\">http://dev.mysql....
{ "AcceptedAnswerId": "23049", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-20T08:48:08.000", "Id": "22917", "Score": "1", "Tags": [ "php", "mysql", "array" ], "Title": "Looking For a More Efficient/Elegant Way To Write a MySQL Query" }
22917
<p>I thought about three (now four) different ways how to execute forks with PHP. What is the faster, maybe better solution and why?</p> <ol> <li><p>PHP script included</p> <pre><code>foreach($tasks as $task) { $pid = pcntl_fork(); if($pid == -1) { exit("Error forking...\n"); } else if($pid =...
[]
[ { "body": "<p>you have an option to do forking using pcntl yourself, or by using something more robust like PHP-Daemon on GitHub.\nThere is also an option of background workers, which is the best option in my opinion (<a href=\"http://blog.anorgan.com/2013/02/22/dont-do-now-what-you-can-put-off-until-later/\" r...
{ "AcceptedAnswerId": "23162", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-20T09:44:12.320", "Id": "22919", "Score": "14", "Tags": [ "php", "comparative-review", "child-process" ], "Title": "Forking with PHP (4 different approaches)" }
22919
<p>I have this set of functions - it works, but I'm concerned about the use of <code>let</code>s.</p> <pre><code>(defn- create-counts [coll] "Computes how many times did each 'next state' come from a 'previous state'. The result type is {previous_state {next_state count}}." (let [past coll present ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-25T00:36:50.830", "Id": "35608", "Score": "1", "body": "Just a note that the Haskell equivalent of the clojure `let` is `let`. `where` is a different beast" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-25...
[ { "body": "<p>First of all, you could use abstract structural binding (a.k.a. destructuring) to reduce the number of <code>let</code> bindings:</p>\n\n<pre><code>(defn- create-counts_org [[_ &amp; present :as coll]]\n \"Computes how many times did each 'next state' come from a 'previous state'.\n The result ...
{ "AcceptedAnswerId": "23256", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-20T16:48:58.750", "Id": "22934", "Score": "7", "Tags": [ "haskell", "clojure" ], "Title": "Excessive use of let a problem in Clojure?" }
22934
<p>I'm creating a small extension to the JDBC API, with the hope of automating some common tasks and avoid boilerplate code.</p> <p>One of its features will be a <em>basic</em> support for named parameters in prepared statements (that JDBC does not support natively).<br> Since this is a vital part of the library, <str...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-20T23:26:35.313", "Id": "35292", "Score": "1", "body": "If possible, I would completely avoid dealing with raw String for SQL. This is error prone. There are some alternatives in the java world, like hibernate or method chaining (a qui...
[ { "body": "<p>If possible, I would completely avoid dealing with raw String for SQL. This is error prone. There are some alternatives in the java world, like hibernate or method chaining (a quick google search reveals jooq). If we stick to your approach, I would get rid of this state machine.</p>\n\n<p>There ar...
{ "AcceptedAnswerId": "22975", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-20T18:44:45.750", "Id": "22935", "Score": "4", "Tags": [ "java", "parsing" ], "Title": "Custom parser for named parameters in prepared statement" }
22935
<p>I had been working on a project for some time, and then it went on the way back burner after my daughter was born. I'm back to it, and now I discover that I'm best off using PDO over MySQLi. So, I'm working on the conversion, and I'd like to get some confirmation that I'm handling things well. Essentially: <stron...
[]
[ { "body": "<p><strong>The Good</strong></p>\n\n<p>You use bound parameters. You handle errors.</p>\n\n<p><strong>The Bad</strong></p>\n\n<p>You filter the email address but then pass the unfiltered value to the select and update queries. What are you trying to achieve with the check of the filtered email?</p>\n...
{ "AcceptedAnswerId": "23084", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-20T20:31:12.627", "Id": "22938", "Score": "3", "Tags": [ "php", "mysql", "security", "pdo" ], "Title": "Converting from MySQLi to PDO account activation" }
22938
<p>Say I have this type of code I'd like to execute. There's some data encapsulated around a big Javascript object containing methods &amp; properties that I'd like to extract based on comparing some other data in said object. The object includes associative (hash?) arrays where I don't know the array IDs at runtime so...
[]
[ { "body": "<ol>\n<li>You should cache all methods calls - JS is interpreting language and\nthere is no optimizers to help you, therefore, each time you call\nmethod, get element from array etc, you are actually asking JS\nengine to DO this for you.</li>\n<li>Concluding that someObjArry is an array, should avoid...
{ "AcceptedAnswerId": "22948", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-21T02:38:29.710", "Id": "22947", "Score": "1", "Tags": [ "javascript", "json" ], "Title": "Can this iterating javascript code be optimized?" }
22947
<p>I realize that there is a surfeit of posts on SE/SO about optimizing one's R for() loops. I'm afraid, though, that I don't understand all of the guidance in the answers there, or how to apply their lessons to the loop I'm working on.</p> <p>First, the code:</p> <pre><code>HHCovarEvals &lt;- data.frame() for(k in ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-20T18:24:41.753", "Id": "35308", "Score": "0", "body": "Tried to post a short answer here but, due to formatting issues, I'll post it as an answer. If you need help with it let me know." }, { "ContentLicense": "CC BY-SA 3.0", ...
[ { "body": "<p>Instead of using a <code>for</code> loop you could write a function <code>fitModels</code> that executes all the tasks with any given model, and call it from</p>\n\n<pre><code>lapply(X=hhcovarmodels, FUN=fitModels)\n</code></pre>\n\n<p>Also, since it seems that each fit is independent of the rest,...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-20T18:09:49.943", "Id": "22949", "Score": "1", "Tags": [ "r", "optimization" ], "Title": "Which components of this r loop are inefficient?" }
22949
<p>Here I have some simple code that worries me, look at the second to last line of code, I have to return spam in order to change spam in the global space. Also is it bad to be writing code in this space and I should create a function or class to call from that space which contains most my code?</p> <p>I found out ve...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-21T05:07:22.220", "Id": "35318", "Score": "0", "body": "Well, I am not a python expert and this is more like my general convention than python convention. You should not reuse variable name. For example, set(spam) and list(spam) should...
[ { "body": "<blockquote>\n <p>I also have a tendency to do things like spam = fun() because I do not\n know how to correctly make Python call a function which changes a\n variable in the scope of where the function was called.</p>\n</blockquote>\n\n<p>You can't. You cannot replace a variable in an outer scope...
{ "AcceptedAnswerId": "22952", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-21T04:57:04.963", "Id": "22951", "Score": "2", "Tags": [ "python" ], "Title": "What parts of my Python code are adopting a poor style and why?" }
22951
<p>I needed short, unique, seemingly random URLs for a project I'm working on, so I put together the following after some research. I believe it's working as expected, but I want to know if there's a better or simpler way of doing this. Basically, it takes an integer and returns a string of the specified length using t...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-21T08:18:10.170", "Id": "35328", "Score": "1", "body": "Without knowing your concrete requirements: What do you think about hashing your value and take the first x characters? Maybe you will need some additional checking for duplicates...
[ { "body": "<p>The trouble with using a pseudo-random number generator to produce your shortened URLs is, <em>what do you do if there is a collision?</em> That is, what happens if there are values <code>v</code> and <code>w</code> such that <code>v != w</code> but <code>genkey(v) == genkey(w)</code>? Would this ...
{ "AcceptedAnswerId": "22957", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-21T05:51:44.350", "Id": "22954", "Score": "6", "Tags": [ "python" ], "Title": "Unique short string for URL" }
22954
<p>I'm currently working on a system using WCF to communicate between a Windows Service and one or multiple clients. Service is required to answer clients calls, as well as notify them of certain events, which is why I implemented a callback feature using simplified subscriber model. Callback interface has methods with...
[]
[ { "body": "<p>Why not expose a lambda expression like this (assuming that <code>_subscribers</code> is a field of type <code>List&lt;ICallback&gt;</code>):</p>\n\n<pre><code>private void InvokeCallbacks(Action&lt;ICallback&gt; callbackFunc)\n{\n _subscribers.ForEach(callbackFunc);\n}\n</code></pre>\n\n<p>and...
{ "AcceptedAnswerId": "22962", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-21T12:22:28.473", "Id": "22958", "Score": "2", "Tags": [ "c#", "reflection" ], "Title": "Multiple target method invocation wrapper" }
22958
<p>This code loads the data for <a href="http://projecteuler.net/problem=18" rel="nofollow">Project Euler problem 18</a>, but I feel that there must be a better way of writing it. Maybe with a double list comprehension, but I couldn't figure out how I might do that. It is a lot more difficult since the rows to split ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-21T13:28:28.237", "Id": "35340", "Score": "0", "body": "Also there's no need to `list()` the `trianle.split(\",\")`, `split` will *always* return a list." } ]
[ { "body": "<ol>\n<li><p>Avoid the need to escape the newlines by using Python's <a href=\"http://docs.python.org/2/reference/lexical_analysis.html#string-literals\" rel=\"nofollow\">triple-quoted strings</a> that can extend over multiple lines:</p>\n\n<pre><code>triangle = \"\"\"\n75\n95 64\n17 47 82\n18 35 87 ...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-21T12:25:39.773", "Id": "22959", "Score": "2", "Tags": [ "python", "programming-challenge" ], "Title": "Organizing a long string into a list of lists" }
22959
<p>In my Rails app I need to import some files from CSV and Excel files. I needed it in 2 models so I have written <code>lib/importable.rb</code>:</p> <pre><code>module Importable def self.included(base) base.send :extend, ActAsMethods end module ActAsMethods def act_as_importable(&amp;block) @imp...
[]
[ { "body": "<p>Notes:</p>\n\n<ul>\n<li><p>Your code looks pretty good, but I personally wouldn't have written it as a mixable module, this code seemps completely independent from <code>ActiveRecord</code>. I'd write a <code>SpreadSheetReader</code> class and just use it from wherever you want (this way the code ...
{ "AcceptedAnswerId": "22964", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-21T12:58:43.320", "Id": "22961", "Score": "2", "Tags": [ "ruby", "ruby-on-rails" ], "Title": "Ruby ActiveRecord importing library" }
22961
<pre><code>private String GetFacilityName(String facilityHexID) { if (facilityHexID.equals(FACILITY_AIRCON_HEX_ID)) { return FACILITY_AIRCON_NAME; } else if (facilityHexID.equals(FACILITY_FAN_HEX_ID)) { return FACILITY_FAN_NAME; } return facilityHexID; } </code></pre> <p>Or</p> <pre...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-21T17:35:32.640", "Id": "35380", "Score": "2", "body": "What about using a Map?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-22T10:46:18.973", "Id": "35457", "Score": "0", "body": "How about ...
[ { "body": "<p>I'd remove both <code>else</code>s:</p>\n\n<pre><code>private String getFacilityName(String facilityHexId) {\n if (FACILITY_AIRCON_HEX_ID.equals(facilityHexId)) {\n return FACILITY_AIRCON_NAME;\n }\n if (FACILITY_FAN_HEX_ID.equals(facilityHexId)) {\n return FACILITY_FAN_NAME;\...
{ "AcceptedAnswerId": "22965", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-21T14:18:07.963", "Id": "22963", "Score": "3", "Tags": [ "java" ], "Title": "Which is a better style to write default return case in if-else" }
22963
<p>I have a grid as </p> <pre><code>&gt;&gt;&gt; data = np.zeros((3, 5)) &gt;&gt;&gt; data array([[ 0., 0., 0., 0., 0.], [ 0., 0., 0., 0., 0.], [ 0., 0., 0., 0., 0.]] </code></pre> <p>i wrote a function in order to get the ID of each tile.</p> <pre><code>array([[(0,0), (0,1), (0,2), (0,3), ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-21T18:28:44.323", "Id": "35382", "Score": "2", "body": "Good question. The only thing I'd suggest is actually having `get_IDgrid` in the class rather than saying that it will be embedded." } ]
[ { "body": "<p>Numpy has built in functions for most simple tasks like this one. In your case, <a href=\"http://docs.scipy.org/doc/numpy/reference/generated/numpy.ndindex.html\" rel=\"nofollow\"><code>numpy.ndindex</code></a> should do the trick:</p>\n\n<pre><code>&gt;&gt;&gt; import numpy as np\n&gt;&gt;&gt; [j...
{ "AcceptedAnswerId": "22973", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-21T16:33:57.390", "Id": "22968", "Score": "1", "Tags": [ "python", "optimization", "performance" ], "Title": "python Improve a function in a elegant way" }
22968
<p>Is there any point in wrapping this code in the self executing function declaring window and undefined? I've read that it improves performance etc... (NOTE I will be making use of the window at some point).</p> <pre><code>(function (window, undefined) { // THIS BIT HERE! var App = { init: (function () { ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-21T19:25:59.710", "Id": "35391", "Score": "0", "body": "If all you ask is why are those two arguments declared, then I think @dystroy's answer puts it simply. If you're also asking why the self-executing function in the first place: it...
[ { "body": "<p>There is only one positive result that I know : it lets minifiers replace <code>window</code> and <code>undefined</code> with shorter names.</p>\n", "comments": [], "meta_data": { "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-21T16:50:36....
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-21T16:46:42.093", "Id": "22969", "Score": "1", "Tags": [ "javascript" ], "Title": "Name-spaced JavaScript wrapped in self executing function" }
22969
<p>I wrote function to generate nearly sorted numbers:</p> <pre><code>def nearly_sorted_numbers(n): if n &gt;= 100: x = (int)(n/10) elif n &gt;= 10: x = 9 else: x = 4 numbers = [] for i in range(1,n): if i%x==0: numbers.append(random.randint(0,n)) ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-21T19:58:55.010", "Id": "35394", "Score": "0", "body": "What's the purpose of this code?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-21T20:26:58.053", "Id": "35398", "Score": "0", "body": "I...
[ { "body": "<pre><code>def nearly_sorted_numbers(n):\n if n &gt;= 100:\n x = (int)(n/10)\n</code></pre>\n\n<p>Use <code>int(n//10)</code>, the <code>//</code> explicitly request integer division and python doesn't have casts</p>\n\n<pre><code> elif n &gt;= 10:\n x = 9\n else:\n x = ...
{ "AcceptedAnswerId": "22982", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-21T17:33:46.550", "Id": "22974", "Score": "2", "Tags": [ "python" ], "Title": "Function to generate nearly sorted numbers" }
22974
<p>I have the following jQuery click functions:</p> <pre><code>$childCheckbox.click(function(){ if(!$(this).hasClass('checked') &amp;&amp; !$parentCheckbox.hasClass('checked')){ $(this).attr('checked', 'checked').addClass('checked'); $parentCheckbox.prop('indeterminate',true); } else i...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-04-16T23:27:57.737", "Id": "38919", "Score": "0", "body": "Tip: Store the result of `$(this)` in a temporary variable to avoid repeated calls to jQuery: `var $this = $(this);`" } ]
[ { "body": "<p>Here are 3 - there are more, no doubt</p>\n\n<ol>\n<li><p>Give both checkboxes a class and use that as the selector </p>\n\n<pre><code>$(\".someClass\").click( ... )\n</code></pre></li>\n<li><p>Declare the event handler elsewhere, and use it anywhere: </p>\n\n<pre><code>function checkboxClick(ev...
{ "AcceptedAnswerId": "22980", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-21T18:07:37.620", "Id": "22976", "Score": "2", "Tags": [ "javascript", "jquery" ], "Title": "Two click functions doing the same thing with difference the selector" }
22976
<p>first of all sorry for this easy question. I have a class</p> <pre><code>class Grid(object): __slots__= ("xMin","yMax","nx","ny","xDist","yDist","ncell","IDtiles") def __init__(self,xMin,yMax,nx,ny,xDist,yDist): self.xMin = xMin self.yMax = yMax self.nx = nx self.ny = ny ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-21T18:40:58.530", "Id": "35384", "Score": "0", "body": "Ideally, you should write your whole Grid class and then show it to us. Then we'd suggest all the ways in which it could be improved rather then asking lots of specific questions....
[ { "body": "<pre><code>class Grid(object):\n __slots__= (\"xMin\",\"yMax\",\"nx\",\"ny\",\"xDist\",\"yDist\",\"ncell\",\"IDtiles\")\n def __init__(self,xMin,yMax,nx,ny,xDist,yDist):\n</code></pre>\n\n<p>Python convention says that argument should be lowercase_with_underscores</p>\n\n<pre><code> self...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-21T18:17:04.027", "Id": "22977", "Score": "1", "Tags": [ "python", "optimization" ], "Title": "Python right position for a Error message in a class" }
22977
<p>I'm starting to learn Python and am trying to optimize this bisection search game.</p> <pre><code>high = 100 low = 0 guess = (high + low)/2 print('Please think of a number between 0 and 100!') guessing = True while guessing: print('Is your secret number ' + str(guess) + '?') pointer = raw_input("Enter ...
[]
[ { "body": "<p>Some things I think would improve your code, which is quite correct:</p>\n\n<ul>\n<li>Having variables for <code>high</code> and <code>low</code>, you shouldn't hard code their values in the opening <code>print</code>.</li>\n<li>You should use <code>//</code> to make sure you are getting integer d...
{ "AcceptedAnswerId": "22992", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-21T22:01:04.830", "Id": "22984", "Score": "6", "Tags": [ "python", "beginner", "number-guessing-game" ], "Title": "Bisection search game" }
22984
<p>Often I need to clean a file name using <code>Path.GetInvalidFileNameChars()</code>, however I do not know of a way to search for any of the invalid letters (except by using Regex) in one pass.</p> <pre><code>public string LoopMethod() { StringBuilder sb = new StringBuilder(fileName); foreach(var invalidCha...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-21T23:28:16.723", "Id": "35416", "Score": "0", "body": "Related: http://forums.asp.net/t/1185961.aspx/1" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-22T00:11:01.787", "Id": "35423", "Score": "0",...
[ { "body": "<pre><code>foreach(var c in Path.GetInvalidPathChars())\n path = path.replace(c, '_')\n</code></pre>\n\n<p>That's a bit inefficient as it can allocate a string on every itteration, but usually not a problem. Alternative:</p>\n\n<pre><code>var chars = Path.GetInvalidPathChars()\npath = new string(p...
{ "AcceptedAnswerId": "22999", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-21T22:18:59.657", "Id": "22986", "Score": "4", "Tags": [ "c#", "strings" ], "Title": "Replacing from a list chars in a string" }
22986
<pre><code>CREATE PROCEDURE dbo.foo AS BEGIN DECLARE @true BIT, @false BIT; SET @true = 1; SET @false = 0; IF (some condition) Select @true; ELSE Select @false; END </code></pre> <p>SQL is not the language that I'm strongest in now, but the above stored procedure seems to be produce the desired functionin...
[]
[ { "body": "<p>Since SQL Server has no Boolean data type, and since the bit values 1 and 0 are widely used and understood to represent true and false in many programming languages, I would simply return <code>0x1</code> or <code>0x0</code> as appropriate. I don't think that actually declaring <code>@true</code> ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-21T23:25:26.223", "Id": "22989", "Score": "3", "Tags": [ "sql", "sql-server" ], "Title": "SQL stored procedure that returns a boolean value?" }
22989
<p>I have developed a jQuery slider and I want to implement it in WordPress (it will be a Featured Posts slider).</p> <p>This is my slider logic:</p> <ul> <li>If there are 1 or 3 posts, show them but hide the <strong>prev</strong> and <strong>next</strong> buttons.</li> <li>If there are more than 3 posts but <strong>...
[]
[ { "body": "<p>Here's how I would have written the slider. For a small project like this, you probably don't need to use <a href=\"http://msdn.microsoft.com/en-us/magazine/ff852808.aspx\" rel=\"nofollow noreferrer\">Prototypal Inheritance</a>. However, if you wanted to scale or add new functionality it would be ...
{ "AcceptedAnswerId": "23035", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-21T23:30:19.160", "Id": "22990", "Score": "4", "Tags": [ "javascript", "jquery", "html" ], "Title": "jQuery slider for WordPress" }
22990
<p>I wrote some Java code for Spotify's <a href="https://www.spotify.com/us/jobs/tech/reversed-binary/" rel="nofollow" title="Reversed Binary Numbers">Reversed Binary Numbers</a> puzzle and I tested it on my machine and I am almost positive that it behaves as expected. However, when I send it to puzzle AT spotify.com i...
[]
[ { "body": "<p>I do not see any problems inside the given range. I would have used already existing methods:</p>\n\n<pre><code>public static int reverse2(final int n) {\n return Integer.valueOf(new StringBuilder(Integer.toBinaryString(n)).reverse().toString(), 2);\n}\n</code></pre>\n\n<p>Which is probably to ...
{ "AcceptedAnswerId": "23032", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-21T23:34:52.637", "Id": "22991", "Score": "0", "Tags": [ "java", "integer", "bitwise", "contest-problem" ], "Title": "Spotify's \"Reversed Binary Numbers\" Problem" }
22991
<p>I'm trying to become more proficient in Python and have decided to run through the Project Euler problems. </p> <p>In any case, the problem that I'm on (<a href="http://projecteuler.net/problem=17" rel="nofollow">17</a>) wants me to count all the letters in the English words for each natural number up to 1,000. In ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-21T22:36:38.837", "Id": "35424", "Score": "0", "body": "Your question isn't very specific; it's pretty open ended. We like specific programming questions here with a clear answer." }, { "ContentLicense": "CC BY-SA 3.0", "Cr...
[ { "body": "<p>The more pythonic version:</p>\n\n<pre><code>for i in range(1, COUNTTO + 1):\n container = num2eng(i).replace(' ', '')\n length += len(container)\n if i % 100:\n length += 3 # account for 'and' in numbers over 100\n\nprint length\n</code></pre>\n\n<p>code golf:</p>\n\n<pre><code>...
{ "AcceptedAnswerId": "22996", "CommentCount": "7", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-21T22:34:46.893", "Id": "22993", "Score": "1", "Tags": [ "python", "programming-challenge" ], "Title": "Number letter counts" }
22993
<p>Write a method to compute the difference between two ranges. A range is defined by an integer low and an integer high. A - B (A “minus” B) is “everything in A that is not in B”.</p> <p>This is an interview question and here is my code: </p> <pre><code>void findDiff(int a1,int a2, int a3, int a4) { cout&lt;&lt;"...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-22T06:00:33.610", "Id": "35449", "Score": "0", "body": "You flaged this with unit testing, so where are they? (Don't post all, just your inputs for `a` that you have tested.)" } ]
[ { "body": "<p>Make sure this is the signature they want. e.g. they do not expect the function to return vector, iterator or sthg. Also make sure they do not expect you to validate input. e.g. a1 &lt;= a2 etc... after that you can remove redundant conditionals, they are already present in the for loops. And you ...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-22T01:44:16.953", "Id": "22997", "Score": "1", "Tags": [ "c++", "algorithm", "interview-questions" ], "Title": "Calculate difference of two ranges given" }
22997
<p>I've been learning C#/XNA in an attempt to make a game for the past few weeks so maybe this is an obvious newbie thing, but here goes:</p> <p>I've been making a fairly simple 2D game, so I have a list of ~1000 objects (NPC's), and I'm iterating through them extremely frequently to do distance checking on each one. ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-22T10:08:15.020", "Id": "35456", "Score": "2", "body": "Hello, and thanks for your detailed question. :) Did you profile your code to see where the time is spent? The issue is surprising, so you might be surprised by the reason too." ...
[ { "body": "<p>Let me start by agreeing with the comments that have been posted. It is really strange that you're getting this behavior. In fact, it seems like it should be the opposite.</p>\n\n<h2>I Could Not Reproduce the Performance Delay</h2>\n\n<p>I started off by trying to recreate the problem you're descr...
{ "AcceptedAnswerId": "30956", "CommentCount": "7", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-22T03:23:57.943", "Id": "23001", "Score": "4", "Tags": [ "c#", "performance", "xna" ], "Title": "Distance checking of normalized vectors?" }
23001
<p>I've been working on a project where I am importing a large document of documents and tokenizing each document. I then make a hashset of the tokens I have, and for each of these unique tokens I am looking to find their frequency in each of the documents I have. There are about 130000 documents total.</p> <p>I've ru...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-22T11:34:24.947", "Id": "35458", "Score": "5", "body": "Have you profiled your code? This should _always_ be the first step when optimising." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-22T12:14:04.433",...
[ { "body": "<p>Since the tokens array doesn't change in the while loop, you can pull out the check for LastIndexOf so that it doesn't get called on every loop.</p>\n\n<p>The only other thing I can suggest is grab a copy of dottrace performance (or ANTS performance) and see exactly where you have a problem.</p>\n...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-22T03:28:35.293", "Id": "23002", "Score": "4", "Tags": [ "c#", "performance", "parsing" ], "Title": "Tokenizing each document in a large document of documents" }
23002
<p>I have a function that needs to return the call to another function that have some parameters. Let's say, for example, the following:</p> <pre><code>def some_func(): iss = do_something() example = do_something_else() return some_long_name('maybe long string', {'this': iss, 'an': example, 'dictionary': 'wi...
[]
[ { "body": "<p>PEP-0008 suggests this approach (see the first example group there):</p>\n\n<pre><code>return some_long_name(\n 'maybe long string',\n {'this': iss,\n 'an': example,\n 'dictionary': 'wich is very long'})\n</code></pre>\n\n<p>As for the dict formatting style, in my opinion, not having...
{ "AcceptedAnswerId": "23014", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-22T07:05:59.650", "Id": "23006", "Score": "1", "Tags": [ "python" ], "Title": "Python Line continuation dictionary" }
23006
<p>This function takes in a number and returns all divisors for that number. <code>list_to_number()</code> is a function used to retrieve a list of prime numbers up to a limit, but I am not concerned over the code of that function right now, only this divisor code. I am planning on reusing it when solving various Pro...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-22T09:38:25.387", "Id": "35455", "Score": "0", "body": "I've changed the bottom for loop to be `for i in range(1, len(divisors) - 2):\n for j in range(i + 1, len(divisors) - 1):\n if not orig_num % (i * j):\n ...
[ { "body": "<p><code>num/2</code> should be <code>sqrt(num)</code>. And this should also be recalculated in your loop, or at least check to leave the for earlier.</p>\n\n<p>A better prime candidates algorithms might also improve overall performance.</p>\n\n<p>See also <a href=\"https://stackoverflow.com/question...
{ "AcceptedAnswerId": "23015", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-22T08:55:46.097", "Id": "23008", "Score": "4", "Tags": [ "python", "primes" ], "Title": "Returning a list of divisors for a number" }
23008
<p>Im using Foundation by Zurb as a front-end framework. Below is the SCSS used to generate the basic layout of the homepage using the Semantic Grid Mixins Foundation supplies (<a href="http://foundation.zurb.com/docs/sass-mixins.php" rel="nofollow">http://foundation.zurb.com/docs/sass-mixins.php</a>). </p> <p>The pro...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-01-27T07:11:35.777", "Id": "67461", "Score": "0", "body": "I suggest not selecting `div[role=\"main\"]`, you simply could use a class like `.site-content` instead. Also using `body.homepage` is overqualified. `.homepage` is enough." } ]
[ { "body": "<p>The CSS that was created (i.e. the position, min-height, and padding) is not anything you have specified in your SCSS. So it must be boilerplate generated by the mixins you're using, e.g. innerRow() and column(). I expect if you look at the Foundation source SCSS for those mixins you will see t...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-22T11:51:17.170", "Id": "23012", "Score": "4", "Tags": [ "css", "sass" ], "Title": "Innefficient scss selectors being generated" }
23012
<p>Python doesn't remove the variables once a scope is closed (if there's such a thing as scope in Python, I'm not sure). I mean, once I finish a <code>for variable in range(1, 100)</code>, the <code>variable</code> is still there, with a value (<code>99</code> in this case).</p> <p>Now I usually indent a whole block ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-22T15:25:34.500", "Id": "35470", "Score": "0", "body": "Do you have a more real concrete example? That's a trivial (and unrealistic) example. The motivations for choosing one approach over the other may be different depending on what i...
[ { "body": "<p>Yes, ideally, you close the <code>with</code> block as soon as possible, that way the file gets closed quickly - which means you are not (potentially) blocking access to it, having less file handles in use, etc...</p>\n\n<p>Python does have scoping, it just doesn't make new scopes very often - onl...
{ "AcceptedAnswerId": "23019", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-22T13:36:28.633", "Id": "23016", "Score": "0", "Tags": [ "python" ], "Title": "Pythonic indenting `with` statement blocks" }
23016
<p><strong>Background</strong></p> <p>I like to code JavaScript in a typical style with "classes" and inheritance. My goal was to create an easy way to make inheritance available and keep classes that inherits from others clean. Also I like to use the module pattern and uses its look and feel.</p> <p><strong>My solut...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-22T13:56:02.067", "Id": "35466", "Score": "1", "body": "Reinventing the wheel. jQuery and underscore for example both have .extend methods that take care of inheritance see how those are implemented. Also, look at how TypeScript handle...
[ { "body": "<p>From some staring at your code:</p>\n\n<ul>\n<li><p>Do not declare <code>var</code> in an <code>if</code> block, it gives the wrong impression. I would just declare it on top, something like this:</p>\n\n<pre><code>//Define namespace\nvar SimpleJSLib;\nSimpleJSLib = SimpleJSLib || {}; \n</code></p...
{ "AcceptedAnswerId": null, "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-22T13:38:50.707", "Id": "23017", "Score": "1", "Tags": [ "javascript", "inheritance" ], "Title": "Inheritance selfmade or reinventing wheel" }
23017
<p>My user defined comparison compare function is defined with an array:</p> <pre><code>$boardkey_to_values=Array(19=&gt;2601248,23=&gt;2601248,39=&gt;2603445, 43=&gt;2256319,47=&gt;2632006,59=&gt;2603445,63=&gt;2232152,67=&gt;2260713,71=&gt;2632006,...) </code></pre> <p>so <code>23&gt;19</code> EDIT:<code>23=19<...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-26T22:00:49.350", "Id": "37670", "Score": "0", "body": "Why is 23 > 19 when they both map to the same value? Shouldn't they be equal?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-27T07:16:26.757", "I...
[ { "body": "<p>You could try doing it this way:</p>\n\n<pre><code>$min_key = null;\nasort($boardkey_to_values);\n\nforeach(array_count_values($boardkey_to_values) as $val) {\n $min_key = array_slice( array_keys($boardkey_to_values), $val );\n break;\n}\n</code></pre>\n\n<p>I believe that would accomplish what ...
{ "AcceptedAnswerId": "24400", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-22T14:28:05.140", "Id": "23018", "Score": "5", "Tags": [ "php", "array" ], "Title": "Array find min value with user-defined comparison compare function" }
23018
<p>I have the async code that implements cancellation token. It's working but Im not pretty sure if this is the right way to do it so I just want feedback about it.</p> <p>Here is the actual code:</p> <pre><code>/// &lt;summary&gt; /// /// &lt;/summary&gt; private async void SaveData() { if (GetActiveServiceReq...
[]
[ { "body": "<p>It's better to use <a href=\"http://msdn.microsoft.com/en-us/library/hh139229.aspx\" rel=\"nofollow\"><code>CancellationTokenSource(TimeSpan)</code></a> constructor to set the cancellation after 5 seconds.</p>\n\n<p>Also, <code>Task.Run</code> method is a recommended way to run compute-bound tasks...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-22T15:39:22.107", "Id": "23020", "Score": "8", "Tags": [ "c#", "task-parallel-library", "async-await" ], "Title": "C# 5 Async Await .Task.Factory.StartNew cancellation" }
23020
<p>This was a homework assignment that I'm now done with - I submitted it as is. However the fact that I needed to use the same code twice bugged me... The double code is:</p> <pre><code>printf("Enter a distance in inches (0 to quit): "); scanf("%f",&amp;input); </code></pre> <p>Is there a better way to do the same t...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-21T14:29:48.757", "Id": "35471", "Score": "13", "body": "there is a codereview.SO where questions like are better suited" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-22T15:41:33.333", "Id": "35472", ...
[ { "body": "<p>Use <code>do-while</code> instead <code>while</code>.</p>\n\n<pre><code>#include &lt;stdio.h&gt;\nint main()\n{\n float inches, floatFeet, input;\n int feet;\n\n do\n {\n printf(\"Enter a distance in inches (0 to quit): \");\n scanf(\"%f\",&amp;input);\n if (input ...
{ "AcceptedAnswerId": "23024", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-21T13:44:23.900", "Id": "23021", "Score": "18", "Tags": [ "c" ], "Title": "Converting inches to feet" }
23021
<p>I'm reading the awesome Head First Design Patterns book. As an exercise I converted first example (or rather a subset of it) to Python. The code I got is rather too simple, i.e. there is no abstract nor interface declarations, it's all just 'classes'. Is that the right way to do it in Python? My code is below, origi...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-24T20:04:40.450", "Id": "35602", "Score": "0", "body": "This looked [very familiar](http://codereview.stackexchange.com/questions/20718/the-strategy-design-pattern-for-python-in-a-more-pythonic-way/20719#20719) - you might want to take...
[ { "body": "<pre><code>class QuackBehavior():\n</code></pre>\n\n<p>Don't put <code>()</code> after classes, either skip it, or put <code>object</code> in there</p>\n\n<pre><code> def __init__(self):\n pass\n</code></pre>\n\n<p>There's no reason to define a constructor if you aren't going to do anything...
{ "AcceptedAnswerId": "23044", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-22T17:46:59.227", "Id": "23033", "Score": "5", "Tags": [ "python", "object-oriented", "design-patterns" ], "Title": "Strategy Design Pattern in Python" }
23033
<p>I have a Swing application with no real design pattern. I want to start learning to design Swing or any types of application properly. Here is the main <code>JFrame</code> class.</p> <pre><code> import java.awt.Component; import java.awt.Dimension; import javax.swing.JFrame; import javax.swing.JT...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-25T03:03:15.890", "Id": "35614", "Score": "1", "body": "This appears to be a pretty clean implementation of the top frame. Seeing the code for the tabs (Inbox/Contact/etc) would shed more light on what's going on here and maybe more op...
[ { "body": "<p>One thing would be to separate view from functionality (you may even make the business logic invocation asynchronous). You can also make your code cleaner and smaller by creating widgets that support templating and using them.</p>\n", "comments": [], "meta_data": { "CommentCount": "0...
{ "AcceptedAnswerId": "24500", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-22T22:48:53.337", "Id": "23042", "Score": "3", "Tags": [ "java", "design-patterns", "swing" ], "Title": "Design Pattern for Swing application" }
23042
<p>I want to know if there is a way to improve my code. It finds the two highest values in an array, and these numbers need to be distinct.</p> <p>I don't want to sort the values; I just want to find them.</p> <p>My idea is to create a new array if the length is even and compare the pair of values to find the minimu...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2016-09-22T22:41:17.957", "Id": "266524", "Score": "0", "body": "You present uncommented code - I, for one, am neither going to guess how it is supposed to work, nor even read it in earnest. If you determine the highest value _H_ \"tournament ...
[ { "body": "<p>I'd be somewhat surprised if the code is correct, but even if it is, it has a lot of pointless stuff - comparing in pairs, aux array, minValue. A much better way is to find the max value, and the max value that's smaller than the first max. The naive way is to iterate through the array twice, but ...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-22T23:56:58.530", "Id": "23045", "Score": "6", "Tags": [ "java", "algorithm", "array" ], "Title": "Find the 2 distinct highest values in an array" }
23045
<p>This code takes text from the standard input, maps it to a struct (if possible), and creates a JSON string from that.</p> <p>I'm using a barcode scanner for the input, and I've attempted to use goroutines to ensure that <strong>if something goes wrong with the parsing or JSON-marshalling, the program will continue ...
[]
[ { "body": "<p>It seems reasonable to start a goroutine for each input, but I'm not sure you need separate goroutines for parsing and sending. After all, one is just waiting for the other to finish. They might as well be the same goroutine. Then you don't need either of the channels because they were just to ...
{ "AcceptedAnswerId": "23124", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-23T01:26:57.497", "Id": "23050", "Score": "3", "Tags": [ "design-patterns", "go" ], "Title": "Am I using Golang concurrency correctly to increase reliability?" }
23050
<p>Is the subroutine <code>test1</code> ugly?/uglier than the others?</p> <pre><code>#!/usr/bin/env perl use warnings; use strict; use 5.10.1; use Data::Dumper; my $ref = { one =&gt; 1, two =&gt; 2, three =&gt; 3 }; sub test1 { my ( $ref ) = @_; $ref-&gt;{three} = 4; } test1( $ref ); sub test2 { $ref-&...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-19T15:18:20.503", "Id": "35543", "Score": "3", "body": "The argument in `test2( $ref );` is ignored." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-19T17:04:48.540", "Id": "35544", "Score": "1", ...
[ { "body": "<p>Here are some considerations when writing such functions:</p>\n\n<ul>\n<li><p>By passing the function all of the variables it needs (<code>test1</code>), you don't need to rely on global variables. This makes the function <strong>easier to test</strong>, more <strong>predictable</strong> (no side ...
{ "AcceptedAnswerId": "23052", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-19T15:07:53.427", "Id": "23051", "Score": "2", "Tags": [ "perl" ], "Title": "Code style: passing a reference to subroutine" }
23051
<p>I made this small program to demonstrate to myself an example of interface. I wanted to confirm whether it is correct and if there is anything more I should know about interfaces other than the importance of implementing polymorphism and multiple inheritance.</p> <pre><code>//program.cs class Program { static ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-23T16:14:49.050", "Id": "35551", "Score": "0", "body": "If you want to know more about interfaces, Code Review is not the right site." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-23T16:17:08.363", "I...
[ { "body": "<p>Your code is quite simple and works, there is not much to review.</p>\n\n<p>Few points:</p>\n\n<ol>\n<li>You shouldn't use variable names like <code>oDog</code>. If the <code>o</code> is meant to indicate that it's an object, then that information already contained in the type of the variable, so ...
{ "AcceptedAnswerId": "23061", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-23T15:29:18.497", "Id": "23057", "Score": "6", "Tags": [ "c#", ".net", "inheritance", "interface", "polymorphism" ], "Title": "Understanding interface with animal classes"...
23057
<p>I'm writing a function to increase a string so, for example, "aac" becomes "aad" and "aaz" becomes "aba". The result is horribly inelegant, I can't get it simple enough and I feel I'm missing something. How to improve that code?</p> <pre><code>function inc_str(str){ var str = str.split("").map(function(a){ retu...
[]
[ { "body": "<p>A recursive approach is much more elegant in this case:</p>\n\n<pre><code>function inc_str(str) {\n var last = str[str.length - 1],\n head = str.substr(0, str.length - 1);\n if (last === \"z\") {\n return inc_str(head) + \"a\";\n } else {\n return head + String.fromCharCode(last.charCo...
{ "AcceptedAnswerId": "23064", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-23T16:59:35.400", "Id": "23063", "Score": "1", "Tags": [ "javascript", "strings" ], "Title": "Elegant function to \"increase\" a JavaScript string - for example, turning \"aac\" into ...
23063
<p>I'm trying to output aggregate information about a directory tree (file extension plus accumulative count and size per file type) with PowerShell.</p> <p>This is as far as I've got.</p> <pre><code>gci -r -ea Si ` | group { if ($_.PSIsContainer) {""} else {$_.Extension} } ` | select Name, Count, @{n="Measure"; e={$...
[]
[ { "body": "<p>You are running your select twice and saving an unused Average from your Select-Object</p>\n\n<pre><code>gci -r -ea Si `\n| group { if ($_.PSIsContainer) {\"\"} else {$_.Extension} } `\n| sort Count -desc `\n| ft Name, Count, @{n=\"SizeMB\"; e={\"{0:N1}\" -f (($_.Group | measure Length -Sum).Sum /...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-23T22:32:40.273", "Id": "23068", "Score": "2", "Tags": [ "powershell" ], "Title": "Summarize a directory with PowerShell" }
23068
<p>Does my main class have too much code? For some reason i have the feeling that I should put all of my thread starts and joins in a for loop just to reduce the amount of code. I dunno if that will hurt readability on this class? Also is it normal for a main class to be initialize just to call one method? I only did t...
[]
[ { "body": "<p>I would add some structure. As a general statement I'd say that good structure(s) helps reduce code. Make collections (list, array, whatever) for each of Smokers and Threads.</p>\n\n<p>I would also look into string formatting so you can loop through the Smoker collection and do your output. You do...
{ "AcceptedAnswerId": "23073", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-24T02:37:20.727", "Id": "23069", "Score": "-1", "Tags": [ "java", "multithreading", "simulation" ], "Title": "Launching a multithreaded simulation of smokers" }
23069
<p>I've written a short library for manipulating matrices for 3D drawing. I've tried to strike a balance between speed and readability. Anything to improve?</p> <pre><code>%! %mat.ps %Matrix and Vector math routines /ident { 1 dict begin /n exch def [ 1 1 n { % [ i [ exch % [ [ i 1 1 n { % [ [...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2015-09-16T21:31:03.483", "Id": "191941", "Score": "1", "body": "Current version: https://github.com/luser-dr00g/xpost/blob/master/data/mat.ps" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2016-01-30T07:25:28.743", "...
[ { "body": "<p>I just noticed some issues with the <code>vop</code> procedure. It's not nestable the way it's written. So you can't use it to add two matrices like <code>m1 m2 { {add}vop }vop</code>. I've got a favorite trick using <code>token</code> that'll fix this. But I've got serious versioning issues, beca...
{ "AcceptedAnswerId": "25091", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-24T05:52:48.013", "Id": "23074", "Score": "4", "Tags": [ "performance", "matrix", "postscript" ], "Title": "Manipulating matrices for 3D drawing" }
23074
<p>I'm trying to migrate from JavaScript to CoffeeScript. However I'm not sure about the best way to optimize the code generated by js2coffee. </p> <p>Below is the original JavaScript source :</p> <pre><code>var async = require('async'); var context = {}; context.settings = require('./settings'); async.series([setu...
[]
[ { "body": "<p>The CoffeeScript looks fine to me. You'll still need the <code>context</code> var just as in plain JS, because you're not dealing with <code>this</code>. If you were, you could maybe use the fat arrow to preserve the <code>this</code> context, but even so it'd require some refactoring, and end up ...
{ "AcceptedAnswerId": "23077", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-24T11:13:52.487", "Id": "23076", "Score": "3", "Tags": [ "javascript", "coffeescript", "callback" ], "Title": "Passing Context in CoffeeScript" }
23076
<p>I have to perform an IF statement in my Javascript code. I utilised the first method shown below:</p> <pre><code>(someVar1 !== "someString") &amp;&amp; (someVar2[i].disabled = (someVar3.find("." + someVar4).length == 0)); </code></pre> <p>Is the shortening of an if like this ok to do if my code is to be viewed by ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-24T12:45:07.823", "Id": "35587", "Score": "3", "body": "`someVar && doThis` is sometimes okay. In your case, I'd definitely go with option #2" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-24T13:09:07.693"...
[ { "body": "<p>The second part of the condition in the first method (someVar2[i].disabled = (someVar3.find(\".\" + someVar4).length == 0)) is only an assignment and is always evaluated to true.</p>\n\n<p>It is clearer to use only the first part of the condition as a condition in if (someVar1 !== \"someString\") ...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-24T12:33:38.813", "Id": "23078", "Score": "3", "Tags": [ "javascript", "jquery" ], "Title": "If statement, is the shortened version readable enough?" }
23078
<p>I didn't realize I am not a very good programmer at recently. I just come out from Uni, I want to become a reliable teammate. Please help me to improve my coding style/habbits. I have carefully re-written a file indexer class which I didn't do very well in my work. I come here, hope I can improve it in terms of code...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-24T13:56:05.413", "Id": "62777", "Score": "0", "body": "You should certainly get rid of `\"stdio.h\"` and `\"stdlib.h\"`" } ]
[ { "body": "<p>Here's a few things you may want to consider:</p>\n\n<ol>\n<li><p>Remove commented out code and statements right away. Particularly the ones that seems to be left in there for educational purposes are just noise.</p></li>\n<li><p>Wrap your class into a namespace, if this is part of a project you s...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-24T12:40:05.967", "Id": "23079", "Score": "6", "Tags": [ "c++", "file-system", "file" ], "Title": "Simple C++ File Indexer" }
23079
<p>My task was similar to <a href="https://codereview.stackexchange.com/questions/20961/java-multi-thread-file-server-and-client/">my last assignment</a> but this time I had to do it with UDP instead of TCP. This basically means I had to <code>emulate TCP over UDP</code>.</p> <p>Multithreading was an interesting probl...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-30T11:42:26.217", "Id": "51151", "Score": "0", "body": "I tried compiling your code. It works fine for file size less than 512 bytes. For everything else I am getting [this](http://ideone.com/OYcGMq) exception. I am not sure what's wro...
[ { "body": "<ul>\n<li><p>You shouldn't do work in the constructor let alone ALL the work. You can move everything except <code>this.socket = socket;</code>\nfrom <code>UDPFileReceiver</code> constructor to a method <code>receive()</code>, like the <code>sendFile</code> method of <code>UDPFileSender</code>.</p></...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-24T20:14:15.757", "Id": "23088", "Score": "5", "Tags": [ "java", "multithreading", "homework", "network-file-transfer" ], "Title": "Java multithreaded file server and client - em...
23088
<p>I'm writting a mark up for: <br> <a href="https://i.stack.imgur.com/8Nyli.jpg" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/8Nyli.jpg" width="355" height="400"></a> <br> And here is my HTML:</p> <pre><code>&lt;div id="container"&gt; &lt;header&gt; &lt;h1&gt;&lt;img src="images/l...
[]
[ { "body": "<h3><code>#categories</code></h3>\n\n<p><code>#categories</code> needs to be a <code>section</code> element (instead of <code>div</code>), otherwise the <code>nav</code> would be in scope of the whole page (but it is only for the categories). Besides that, you shouldn't overjump heading levels.</p>\n...
{ "AcceptedAnswerId": "23104", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-24T23:02:46.233", "Id": "23090", "Score": "3", "Tags": [ "html", "html5" ], "Title": "Semantically correct markup at practice" }
23090
<p>I have 2 strings for example:</p> <p><strong><code>abcabc</code></strong> and <strong><code>bcabca</code></strong></p> <p>or</p> <p><strong><code>aaaabb</code></strong> and <strong><code>abaaba</code></strong></p> <p>I checked that second string is the same or not like first string but shifted. <code>bcabca</cod...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-25T00:22:11.530", "Id": "35606", "Score": "2", "body": "I would return a `bool` `true`/`false` instead of `\"yes\"`/`\"no\"`. You should be able to time the bottleneck yourself." }, { "ContentLicense": "CC BY-SA 3.0", "Crea...
[ { "body": "<p>First, as mentioned in the comments, you should return the boolean values <code>true</code>/<code>false</code> instead of the string values <code>\"yes\"</code>/<code>\"no\"</code>. This should be faster, and is cleaner and more correct.</p>\n\n<p>Second, <code>int.Parse()</code> can be dangerous...
{ "AcceptedAnswerId": null, "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-25T00:16:03.450", "Id": "23091", "Score": "5", "Tags": [ "c#", "strings" ], "Title": "Slow two-strings comparer" }
23091
<p>I'm a newb at C++ and I was wondering whether I used pointers correctly and whether it was appropriate to use them in this context.</p> <p>Any other tips/information would be appreciated.</p> <pre><code>#include &lt;iostream&gt; using namespace std; int euclideanAlgorithm(int *a, int *b); int main() { int x...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-25T00:59:19.480", "Id": "35610", "Score": "0", "body": "Just FYI, this prints out the lowest common multiple of the two integers input." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-25T04:37:54.610", ...
[ { "body": "<p>If you come from C and you start using C++, you might be use to have pointers whenever you want a function to be able to update one of its parameter.\nIn C++, if you want to do so, you can use references which gives you a clearer and slightly safer result. Please refer to the <a href=\"http://en.w...
{ "AcceptedAnswerId": "23096", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-25T00:53:15.907", "Id": "23093", "Score": "2", "Tags": [ "c++" ], "Title": "Am I using pointers correctly?" }
23093
<p>You can see a working example <a href="http://jsfiddle.net/ShaShads/GuL5K/1/embedded/result/" rel="nofollow">here</a>. Be sure to click on the canvas or the key inputs will not be detected!</p> <p>Are there any ways I could improve upon this? Anything that should have been done differently? Any best practices I ha...
[]
[ { "body": "<p>Haven't looked at the code in detail, but here are some thoughts on the overall structure:</p>\n\n<p>Right now, there's some mixing of concerns and tight coupling going on. The engine calls update on the active block, but the block then calls back to the engine to check for collisions. In other wo...
{ "AcceptedAnswerId": "23105", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-25T01:33:05.460", "Id": "23095", "Score": "3", "Tags": [ "javascript", "collision", "canvas" ], "Title": "Canvas spatial grid collision" }
23095
<p>I'm using Struts2 and Google App Engine. Below is my program for getting the country based on the IP of the visitor of the website.</p> <p>In my Struts2 action:</p> <pre><code>HttpServletRequest request = ServletActionContext.getRequest(); String IP = request.getRemoteAddr(); String countryCode = Utilities.fetchUr...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-25T07:34:25.687", "Id": "35627", "Score": "1", "body": "Have a look in http://docs.oracle.com/javase/1.5.0/docs/api/java/util/EnumMap.html , and at Item 33 of Joshua Bloch's Extreme Java book" }, { "ContentLicense": "CC BY-SA 3...
[ { "body": "<p>The slowest part will be the request to the remote server. There is not much you can do to make this faster. You may want to cache the results you get back from hostip, or you may want to have a local database.</p>\n\n<p>Furthermore, the API seems to return <code>XX</code> if it does not know the ...
{ "AcceptedAnswerId": "23107", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-25T07:01:03.527", "Id": "23102", "Score": "6", "Tags": [ "java", "google-app-engine", "url", "struts2" ], "Title": "Getting country based on IP" }
23102
<p>I programmed a little log engine in C I plan to use in my project and maybe some others in future. I am very novice C programmer and would like to have feedback of some experienced ones on this. It's spawned over few files but I've joined them so it's easier to compile. Thank you.</p> <pre><code>#include &lt;stdarg...
[]
[ { "body": "<p>Overall, the program is fairly well-written and clear. One particular good thing is that you have grasped the concept of private encapsulation in C, by placing the static keyword in all the right places. You also use const correctness for your function parameters. All of that is excellent program ...
{ "AcceptedAnswerId": "23178", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-25T14:20:25.580", "Id": "23110", "Score": "5", "Tags": [ "c", "logging" ], "Title": "Little log engine in C" }
23110
<p>I wrote a function for creating all possible translations of a source string, based on a multiple translation map. It works, but generates a lot of intermediate maps (see line marked with <em>*</em>). Is there a better solution? Maybe a more general solution to the "all possible combinations" problem?:</p> <pre><co...
[]
[ { "body": "<p>You are using the Map more like a list...</p>\n\n<p>EDIT: this is NOT working:</p>\n\n<p>You could create an object to hold one translation ({X => {\"cake\",\"egg\"}) then instead of all the Maps you could use a List (of those translations) and always remove and use the first element and pass the ...
{ "AcceptedAnswerId": "23112", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-25T15:08:41.333", "Id": "23111", "Score": "2", "Tags": [ "java", "recursion", "combinatorics" ], "Title": "multi-recursive replacement function" }
23111
<p>Please review <code>unique_list</code>:</p> <p><code>unique_list</code> implements a <code>list</code> where all items are unique. Functionality can also be described as <code>set</code> with order. <code>unique_list</code> should behave as a python <code>list</code> except:</p> <ul> <li>Adding items the end of ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-25T15:56:47.033", "Id": "35648", "Score": "0", "body": "Not sure why but the code is cut half way through. Maybe it's too long? Is there a way to make sure all the code is displayed?" }, { "ContentLicense": "CC BY-SA 3.0", ...
[ { "body": "<pre><code>class unique_list(list):\n</code></pre>\n\n<p>I recommend not inheriting from list. You don't gain a whole lot from it as you need to overload pretty much all the methods anyways. By inheriting from list you might also get some methods you didn't think of or were added later and thus behav...
{ "AcceptedAnswerId": "23116", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-25T15:54:47.860", "Id": "23113", "Score": "2", "Tags": [ "python", "python-2.x" ], "Title": "unique_list class" }
23113
<p>I am a little new/rusty to this C++ stuff. Is this bad code? Can it be improved?</p> <pre><code>#include &lt;windows.h&gt; #include &lt;string&gt; #include &lt;iostream&gt; #include &lt;cstdlib&gt; #include &lt;ctime&gt; bool _initialized_time = false; void Wait() { std::cout &lt;&lt; "Prease any key to continue ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-26T04:52:41.817", "Id": "35699", "Score": "0", "body": "Before using leading underscores in your identifiers. Read this: http://stackoverflow.com/questions/228783/what-are-the-rules-about-using-an-underscore-in-a-c-identifier/228797#22...
[ { "body": "<p>Here are some suggestions for you:</p>\n\n<pre><code>bool _initialized_time = false;\n\nint ReturnRandomNumber(int _start, int _end) {\n if(_initialized_time == false) {\n _initialized_time = true;\n srand(time(0));\n }\n int n = rand() % _end + _start;\n return n;\n}\n</code></pre>\n\n<...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-25T16:19:18.600", "Id": "23115", "Score": "3", "Tags": [ "c++", "beginner", "game", "playing-cards" ], "Title": "Blackjack game with many conditionals and switches" }
23115
<p>So i have a super class that has a 3 child classes. Those 3 child classes have multiple classes of their own. I was having troubles saving this into XML, so I decided to parse it out and do a little bit of maths to return the correct subclass type and make an instance of it. So after a little bit of digging it appea...
[]
[ { "body": "<p>There are a few things I notice:</p>\n\n<ul>\n<li><code>tasktype1</code> is redundant, since <code>single</code> is already of type <code>System.Type</code>, so\nthere is no need to do the <code>Type.GetType(single.ToString());</code> call. You can use <code>single</code> directly.</li>\n<li>The ...
{ "AcceptedAnswerId": "23123", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-25T17:29:29.060", "Id": "23118", "Score": "-2", "Tags": [ "c#", "linq", "reflection" ], "Title": "New to LINQ, not sure this is best practice" }
23118
<p>How could I make this code shorter and faster?</p> <pre><code>'Sheets("Summary(FG)") ComboBox1 items For b = 3 To Sheets("CustomerList").Cells(3, 2).SpecialCells(xlLastCell).row If Sheets("CustomerList").Cells(b, 2) &lt;&gt; "" Then Worksheets("Summary(FG)").ComboBox1.AddItem (Sheets("CustomerList").Cel...
[]
[ { "body": "<p>For a faster version of the code you could add your range to an array and loop through that instead of looping through cells.</p>\n\n<p>For example:</p>\n\n<pre><code>Dim varray as Variant\nvarray = Sheets(\"CustomerList\").Range(\"B3:B\" &amp; Cells(Rows.Count, \"B\").End(xlUp).Row).Value\n\nfor ...
{ "AcceptedAnswerId": "23961", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-25T17:33:42.533", "Id": "23119", "Score": "2", "Tags": [ "vba", "excel" ], "Title": "Populate ComboBox" }
23119
<p>Can I somehow make this a bit cleaner using <code>Math.[Something]</code>, without making a method for it?</p> <pre><code>int MaxSpeed = 50; if (Speed.X &gt; MaxSpeed) Speed.X = MaxSpeed; if (Speed.X &lt; MaxSpeed * -1) Speed.X = MaxSpeed * -1; if (Speed.Y &gt; MaxSpeed) Speed.Y = MaxSpeed; if (Spee...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-25T23:49:32.330", "Id": "35680", "Score": "3", "body": "hmmm - please note: if you're using this to control speed in a 'non-grid' environment, the moving object will move faster than `MaxSpeed` in a diagonal direction (by about 40%)." ...
[ { "body": "<p>I'm afraid there is no such built-in method. There is a similar question <a href=\"https://stackoverflow.com/questions/3176602/how-to-force-a-number-to-be-in-a-range-in-c\">here</a> where an extension method is proposed to force the number to be in range (copy-pasting it with cosmetic changes here...
{ "AcceptedAnswerId": "23130", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-25T21:27:06.087", "Id": "23126", "Score": "7", "Tags": [ "c#", "integer", "interval", "xna" ], "Title": "Determine if an int is within range" }
23126
<p>Thought I share this piece of code to the world. But be aware, I am not sure if this piece of code is safe and efficient. Feel free to improve it or give some feedback and suggestions.</p> <pre><code>#pragma region DOCUMENTATION ON: STD_COPY_VECTOR_TO_ARRAY //////////////////////////////////////////////////////////...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-26T01:40:18.160", "Id": "35694", "Score": "0", "body": "This site is not for sharing code, it's for requesting review. And since that doesn't seem to be the primary reason you posted, I think this “question” is off topic." }, { ...
[ { "body": "<p>Basically, there are very few places in C++ where you want to use Macros. A lot of old C code used function-like macros because of performance reasons - calling a function requires creating a new stack frame. They were also used to get away from C's type system. With C++, <code>inline</code> funct...
{ "AcceptedAnswerId": "23138", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-26T00:32:09.623", "Id": "23136", "Score": "4", "Tags": [ "c++", "macros" ], "Title": "A defined macro to copy selected values of std::vector to an array using std::copy" }
23136
<p>We've got a "catch-all" in <code>app.js</code> that renders a <code>.jade</code> file if it exists:</p> <pre><code>app.get('*', routes.render); </code></pre> <blockquote> <p>index.js</p> </blockquote> <pre><code>render: function(req, res) { fs.exists('views' + req.url + '.jade', function(exists) { if (exi...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-01T19:34:50.853", "Id": "35954", "Score": "0", "body": "I guess this is only for static pages?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-01T19:45:21.283", "Id": "35955", "Score": "0", "bod...
[ { "body": "<p>Here are some examples of how most apps do:</p>\n\n<ul>\n<li>Apache renders everything in the folder. If you want to hide access to a subfolder, you do that with an htaccess in this subfolder.</li>\n<li>Define each route yourself. This'd mean having a whitelist in your case. (In some array or some...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-26T00:59:22.343", "Id": "23139", "Score": "1", "Tags": [ "javascript", "node.js", "express.js" ], "Title": "Render arbitrary jade in express" }
23139
<p>I am trying to combine two programs that analyze strings into one program. The result should look at a parent string and determine if a sub-string has an exact match or a "close" match within the parent string; if it does it returns the location of this match </p> <p>i.e. parent: abcdefefefef sub cde is exact and ...
[]
[ { "body": "<p>Firstly, a quick review of what you've done:</p>\n\n<p><code>import string</code> is unnecessary really. You utilize <code>string.find</code>, but you can simply call the find method on your first argument, that is, <code>seq.find(sub, n, len(seq))</code>. </p>\n\n<p>In your second method, you hav...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-26T01:35:09.573", "Id": "23141", "Score": "2", "Tags": [ "python" ], "Title": "Python: Combing two programs that analyze strings" }
23141
<p>I've been using this code for quite some time, but am wondering if there's any improvements I can make to it. Basically it's just code that runs when the page loads or if the code is run after page load, it will run right away. Do you see any cross browser compatibility issues or any more efficient ways of writing t...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-26T08:28:28.380", "Id": "35712", "Score": "2", "body": "I suggest you take a look at jQuery's implementation of `.ready()`" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-26T15:47:59.600", "Id": "35729"...
[ { "body": "<p>Just for dealing with <code>ready</code> alone I use <a href=\"http://jquery.com/\" rel=\"nofollow\">jQuery</a> -- it does the cross-browser heavy lifting, is well-tested and maintained. Minified, it's only 32K, and included from a CDN, you get fast delivery that may already be cached in your user...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-26T03:42:33.317", "Id": "23145", "Score": "2", "Tags": [ "javascript" ], "Title": "Add event listener when window loads" }
23145
<p>I am working on a project in which I have two tables in a different database with different schemas. So that means I have two different connection parameters for those two tables to connect using JDBC-</p> <p>Let's suppose below is the config.property file-</p> <pre><code>TABLES: table1 table2 #For Table1 table1....
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-26T08:11:08.393", "Id": "35711", "Score": "1", "body": "According to the FAQ the code should work but I'm afraid this one does not compile (`preparedStatement` is not declared anywhere, `while (System.currentTimeMillis() <= 60 minutes)...
[ { "body": "<p>In summary, you have 2 shared resources: the <code>tableList</code> variable and the database.</p>\n\n<p>Regarding <code>tableList</code>, if:</p>\n\n<ul>\n<li><code>tableList</code> is fully populated <em>before</em> you submit the tasks to the executor service AND</li>\n<li>it is populated in th...
{ "AcceptedAnswerId": null, "CommentCount": "5", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2013-02-26T05:05:19.190", "Id": "23147", "Score": "3", "Tags": [ "java", "multithreading", "thread-safety" ], "Title": "Thread Safety issues in the multithreading code" }
23147
<p>I made a simple form validation. It's working alright. The thing is I want my code to be optimized. Can somebody show me some pointers to improve my code? Thanks in advance.</p> <pre><code>$(document).ready(function(){ $('.submit').click(function(){ validateForm(); }); function validateForm(){ var ...
[]
[ { "body": "<ul>\n<li><p>First of all, you shouldn't use <code>$('.submit').click()</code> but <code>$('#myForm').submit()</code> as you will be able to submit forms by pressing <kbd>enter</kbd> too.</p></li>\n<li><p>To check if a string is a number, use <code>!isNan(string)</code> (see <a href=\"https://stackov...
{ "AcceptedAnswerId": "23176", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-26T08:56:22.230", "Id": "23152", "Score": "3", "Tags": [ "javascript", "jquery" ], "Title": "Form Validation (JQuery)" }
23152
<p>After posting my first question and my first attempt which you can see here:</p> <p><a href="https://codereview.stackexchange.com/questions/23095/my-first-attempt-at-canvas-spatial-grid-collision-please-be-honest">Canvas spatial grid collision</a></p> <p>I have re-written it to try and implement what the person ga...
[]
[ { "body": "<p>Just as a general point to consider, you're making <em>everything</em> public. Consider your Block</p>\n\n<pre><code>function block() {\n this.x = 500; // x coord\n this.y = 0; // y coord\n this.size = 50; // size of block squared\n this.getSize = function() { // returns size of the bl...
{ "AcceptedAnswerId": "23480", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-26T09:15:25.207", "Id": "23154", "Score": "0", "Tags": [ "javascript", "canvas", "collision" ], "Title": "Second attempt at canvas spatial grid collision" }
23154
<p>I've tried to improve my code: separate HTML/PHP, much clear, next time change will be easier. After doing research on MVC/OOP, I've made the below code to learn.</p> <p>I understand this is not the MVC pattern now. Can anybody help me fix it to become actual MVC?</p> <ol> <li>get the result from db (list all)</...
[]
[ { "body": "<p><strong>SQL Injection</strong></p>\n\n<p>You don't have to use PDO, but you have to use something to defend against SQL injection, and <code>mysql_real_escape_string</code> isn't it (for one because MySQL is deprecated, and also because it's way too easy to forget to put <code>'</code> around the ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-26T11:20:05.583", "Id": "23160", "Score": "5", "Tags": [ "php", "mvc" ], "Title": "mvc example: form post" }
23160
<p>I want to check if the length of phone number is appropriate for specified country (let's consider that only some countries have restriction, another countries accept phone number with various length). I have a Map, where the correct pairs are defined so this map can be used as a reference in the condition:</p> <pr...
[]
[ { "body": "<pre><code>public static ErrCode checkStatePhoneLen(final String state, final String phoneNo) \n{\n String stateTmp = state.trim();\n String phoneTmp = phoneNo.trim();\n</code></pre>\n\n<p>The issue is that <code>stateTmp</code> is less readable than <code>state.trim()</code>, so if you want ...
{ "AcceptedAnswerId": "23165", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-26T14:17:34.980", "Id": "23163", "Score": "5", "Tags": [ "java", "optimization" ], "Title": "Defining of new, temporary, variables or usage of already known ones?" }
23163
<p>What is the difference between this two way and Which one is best? What do you suggest?</p> <p><strong>1.</strong><br> Use of query (db) directly in CI_Controller. as:</p> <pre><code>$id = $this-&gt;input-&gt;post('id'); $query = $this-&gt;db-&gt;get_where('table1', array('id' =&gt; $id))-&gt;row(); $this...
[]
[ { "body": "<blockquote>\n <p>What is the difference between this two way and Which one is best? What do you suggest?</p>\n</blockquote>\n\n<p>The difference is that you seperate the concerns in the second example. This means that you can change from database type (e.g. a SQL database, a XML file, an array, ect...
{ "AcceptedAnswerId": "23166", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-26T14:48:25.087", "Id": "23164", "Score": "0", "Tags": [ "php", "codeigniter" ], "Title": "A good example of codeigniter MVC?" }
23164
<p>I can't get a peer review where I work, I was wondering how my code was and how could it be improved.</p> <p><a href="https://github.com/lamondea/uploader" rel="nofollow">https://github.com/lamondea/uploader</a></p> <p>Is it a good practice to use functions in classes or should it be replaced by external function ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-26T17:53:27.283", "Id": "35752", "Score": "0", "body": "I really never used peer review and I just started using classes, so I guess the whole /class/uploader.class.php would be the important for that matter. I will add a part, but sti...
[ { "body": "<p>I'm not sure if using classes is better or worse but I am starting to see files being called as functions more than a single file with function within. This is a more common upload script.</p>\n\n<pre><code>$allowedExts = array(\"gif\", \"jpeg\", \"jpg\", \"png\");\n$temp = explode(\".\", $_FILES[...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-26T17:14:02.243", "Id": "23177", "Score": "3", "Tags": [ "php" ], "Title": "File uploader in php" }
23177
<p>A <a href="https://stackoverflow.com/a/15090751/1968">post by Yakk</a> alerted me to the idea of named operators in C++. This look splendid (albeit <strong>very</strong> unorthodox). For instance, the following code can be made to compile trivially:</p> <pre><code>vector&lt;int&gt; vec{ 1, 2, 3 }; cout &lt;&lt; "...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-26T18:25:07.807", "Id": "35755", "Score": "8", "body": "Now C++ has `<tothepowerof>` operator" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-01T19:46:27.223", "Id": "35957", "Score": "4", "body...
[ { "body": "<p>I would add rvalue reference support with moving of temporaries.</p>\n\n<p><code>&lt;op&gt;</code> seems to be too low precidence to be practical - you end up having to <code>(bracket)</code> everything (as demonstrated above). % at least binds tightly.</p>\n\n<p>I do like <code>a &lt;op&gt;= b</...
{ "AcceptedAnswerId": "23195", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-26T18:21:20.023", "Id": "23179", "Score": "52", "Tags": [ "c++", "c++11", "operator-overloading" ], "Title": "Named operators in C++" }
23179
<p>I like the radix function and found a really neat way to compute its inverse in Python with a lambda and <code>reduce()</code> (so I really feel like I'm learning my cool functional programming stuff):</p> <pre><code>def unradix(source,radix): # such beauty return reduce(lambda (x,y),s: (x*radix,y+s...
[]
[ { "body": "<p>The reverse operation to folding is unfolding. To be honest, I'm not very\nfluent in python and I couldn't find if python has an unfolding function.\n(In Haskell we have\n<a href=\"http://hackage.haskell.org/packages/archive/base/latest/doc/html/Data-List.html#v%3afoldr\" rel=\"nofollow\">foldr</...
{ "AcceptedAnswerId": "23188", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-26T18:25:39.303", "Id": "23180", "Score": "3", "Tags": [ "python", "functional-programming", "lambda" ], "Title": "Removing hackery from pair of radix functions" }
23180
<p>I've written a SELECT statement that creates a List of all objects that depend on a single object, so that if I wanted to DROP that object I could DROP all referenced objects first without using CASCADE.</p> <p>It's a long script and I'm not sure if it's gonna work in every situation, so I just wanted to ask if I'v...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2016-07-21T08:16:14.270", "Id": "253824", "Score": "0", "body": "I'm having difficulties to make this work on version 9.2.x. I have no result, this seems to be tied to dependent object name format. Could you give some example ? I'm trying to u...
[ { "body": "<p>Looks good! Seemed to work for me, except in postgres 9.3 (harmless in previous) add:</p>\n\n<pre><code> WHEN 'm' THEN 'MATERIALIZED VIEW'::text\n</code></pre>\n\n<p>in the classType subquery.</p>\n", "comments": [ { "ContentLicense": "CC BY-SA 3.0", "Creati...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-25T15:06:30.643", "Id": "23181", "Score": "7", "Tags": [ "sql", "recursion", "postgresql" ], "Title": "Get all recursive dependencies of a single database object" }
23181
<p>My objective is to make an array of unique keys from a list of objects.</p> <p>Example:</p> <p>Input:</p> <pre><code>var input = [{"a":1, "b":2}, {"a":3, "c":4}, {"a":5}] </code></pre> <p>Output:</p> <blockquote> <pre><code>[ "a", "b", "c" ] </code></pre> </blockquote> <p>Current approach:</p> <pre><code>var ...
[]
[ { "body": "<p>You could clean it up a bit by using <code>reduce</code> and <code>forEach</code> instead of map (especially as you don't need <code>map</code>'s return value, but are just using it as an iterator)</p>\n\n<pre><code>function uniqueKeys(objects) {\n var keys = objects.reduce(function (collector, o...
{ "AcceptedAnswerId": "23184", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-26T19:52:06.477", "Id": "23183", "Score": "4", "Tags": [ "javascript", "array" ], "Title": "Finding unique values in an array" }
23183
<p>I am creating a game that contains a Board and Pieces. The Board is basically a 2D array of Pieces. [Think smaller chess board]</p> <p>One of the things that I want to accomplish is to be able to retrieve the left piece of a given.. (Also want to be able to retrieve the right, up, and down).</p> <p>The easiest way...
[]
[ { "body": "<p>The first location of the <code>leftOf</code> method is the way to go. Putting it in <code>Piece</code> isn't very <a href=\"http://en.wikipedia.org/wiki/Cohesion_%28computer_science%29\" rel=\"nofollow\">cohesive</a>. The latter would be just as ugly or uglier (<code>b.pieceAt(3,3).getLeftPiece(b...
{ "AcceptedAnswerId": "23189", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-26T21:21:41.373", "Id": "23186", "Score": "1", "Tags": [ "java", "array" ], "Title": "2D Array: Retrieve the \"Left\" Item" }
23186
<p>I am looking for feedback on this compact Python API for defining bitwise flags and setting/manipulating them. </p> <p>Under the hood, FlagType extends <code>int</code> and all operations are true bitwise, so there is little to no performance impact. Also, because they are all <code>int</code>, any standard bitwi...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-26T23:23:33.850", "Id": "35775", "Score": "0", "body": "I would argue this isn't a Pythonic interface. Set attributes on an object instead of using flags, or use a `dict`." } ]
[ { "body": "<p>One real-world use-case might be to pass such \"flags\" values to some ffi code, where these are used for efficiency, but in python it seem inefficient (as each instance basically introduces a dict plus an object struct) and much less readable.</p>\n\n<p>Imagine encountering such lines in someone'...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-26T21:36:42.243", "Id": "23187", "Score": "4", "Tags": [ "python", "bitwise" ], "Title": "Bitwise Flag code for Python" }
23187
<p>I have a web application where I connect with a MySQL database using PDO and in some scripts there are a lot of queries one after the other which don't necessarily concern the same tables. i.e I will execute a SELECT statement in one, and then depending on some values I will UPDATE another and finally go and DELETE ...
[]
[ { "body": "<p>You're on the right track, what you're looking for is a DAL (Data Abstraction Layer), a class that represents a database connection.<br>\nThis will allow you to move your common code into the class so you can simply construct your SQL statement and pass it in, with the method returning the expecte...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-26T23:05:17.680", "Id": "23191", "Score": "5", "Tags": [ "php", "mysql", "pdo", "formatting" ], "Title": "Thoughts on organizing code for multiple mysql queries in php scripts" }
23191
<p>I would love to show you one of my bigger scripts to improve my technique. This script is some kind of Itempicker. You choose your <code>Item</code> first (<code>toprow</code>), then pick a color. The color of the active Item (basically the image) changes.</p> <p>A big deal for me was actually to design the script ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-27T01:40:41.197", "Id": "35778", "Score": "4", "body": "Per the [FAQ], if you want your code to be reviewed, you need to paste it here, not just link to it." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-2...
[ { "body": "<p>Your script is quite long, so I'll see how far I can get. Maybe I'll add more later.</p>\n\n<ul>\n<li>Your fiddle is lacking the images, so I'm not 100% sure I understand the \"keep the color\" feature.</li>\n<li>Your comments should be in English if you post the code for review like this.</li>\n<...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-26T23:35:38.537", "Id": "23192", "Score": "4", "Tags": [ "javascript", "performance", "jquery" ], "Title": "Item-picker script" }
23192
<p>I wonder which is better practice when I need to return the primary key value of a newly inserted record from a SQL stored procedure. Consider the following implementations:</p> <p><strong>As Return Value</strong></p> <pre><code>CREATE PROCEDURE [CreateRecord] ( @value NVARCHAR(128) ) AS BEGIN INSERT [Records]...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-05T00:16:44.473", "Id": "36191", "Score": "0", "body": "I don't understand what the problem is with the XML output--parsing's not that difficult, and besides you can join XML to other data just like it's a RS." }, { "ContentLic...
[ { "body": "<p>I think you've already answered your own question to some degree: there are multiple options for returning data from a stored procedure and they all behave differently so there is no single answer. But there are definitely some general guidelines and common practices.</p>\n\n<p><code>RETURN</code>...
{ "AcceptedAnswerId": "23450", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-26T23:37:44.487", "Id": "23193", "Score": "5", "Tags": [ "sql", "sql-server" ], "Title": "Returning Key Values from Stored Procedures" }
23193
<p>I'll try to provide exactly the amount of context that is necessary to understand the construct.</p> <p>I built an API (well, a small part of one) that works and is kind of usable, but rather unpretty and badly testable, and most of all unpretty. Testability is also an issue.</p> <p>The problem domain has the conc...
[]
[ { "body": "<ol>\n<li>Why can't a <code>StepStage</code> contain a collection of <code>IImageRule</code>? Then there can be a collection of <code>StepStage</code>. This provides an abstraction level that I think is missing.</li>\n<li>Have <code>StepStage</code> implement <code>IEquatable</code>. Now the <code>St...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-27T01:00:12.153", "Id": "23196", "Score": "6", "Tags": [ "c#", "unit-testing", "api", "dependency-injection" ], "Title": "Doubts about the quality of an API designed for use with...
23196
<p>This is based (somewhat loosely) on the code written in <a href="http://railscasts.com/episodes/88-dynamic-select-menus-revised" rel="nofollow">this railscast.</a> I'm planning to re-use it in different places throughout the site, so I made it a bit more generic rather than based on IDs. However, I'm certain there's...
[]
[ { "body": "<p>I see a couple of small ways to improve this.</p>\n\n<ol>\n<li><p>DRY (Don't Repeat Yourself) the code. The code that runs on load is identical to the <code>change</code> event handler. So make it a function you can call from both places.</p></li>\n<li><p>Decouple it completely from the markup by ...
{ "AcceptedAnswerId": "23202", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-27T02:21:20.023", "Id": "23199", "Score": "1", "Tags": [ "jquery", "coffeescript" ], "Title": "Dynamic dropdown update for site reuse" }
23199
<p>I'm an experienced programmer but relatively new to Python (a month or so) so it's quite likely that I've made some gauche errors. I very much appreciate your time spent taking a look at my code.</p> <p>My intention is to do some experimentation with 1D cellular automata. For now, just totalistic ones (rules only...
[]
[ { "body": "<p>This is the slow bit of your program:</p>\n\n<pre><code>for j in xrange(self.radius, self.width - self.radius):\n self.cells[i, j] = self.table[self.cells[i - 1, j - self.radius:j + self.radius + 1].sum()]\n</code></pre>\n\n<p>The key to making faster numpy code is to vectorize. You want to get...
{ "AcceptedAnswerId": "23207", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-27T02:31:33.337", "Id": "23200", "Score": "2", "Tags": [ "python", "beginner", "numpy", "cellular-automata" ], "Title": "Performance problems with 1D cellular automata experim...
23200
<p>I'm new to using NUnit and have written a test to check for the existence of a database table. I have the below code that should check whether a new table named NewTable has been created in the database. It works correctly but I can't help feeling there's probably a better way of doing this. Thanks.</p> <pre><code>...
[]
[ { "body": "<p>I would do something like this instead -</p>\n\n<pre><code>using(var conn = context.NewConnection()) {\n var table = conn.GetSchema(\"Tables\");\n var tableNames = table.Rows.Cast&lt;DataRow&gt;()\n .Select(x =&gt; x[\"TABLE_NAME\"].ToString())\n ...
{ "AcceptedAnswerId": "23206", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-27T04:22:41.100", "Id": "23203", "Score": "2", "Tags": [ "c#", "database", "unit-testing", "nunit" ], "Title": "Testing database table creation with NUnit" }
23203
<p>I have a booking with a method <code>total</code> which calculates the total price of the booking from the sum of all the prices of activities that belong to appointments. A booking has many appointments and the following seems to give the right answer, but it seems horrid. How can I improve this?</p> <pre><code> ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-27T07:21:54.077", "Id": "35783", "Score": "0", "body": "Hello, and welcome to Code Review! I don't know RoR enough to answer, but yes you need to understand how to do a sum query, which will avoid both the loop and the `nil` handling."...
[ { "body": "<p>You can do this:</p>\n\n<pre><code>def total\n self.appointments.joins(:activity).sum(:price)\nend\n</code></pre>\n\n<p>You could perhaps simplify it a little, by making an explicit 2nd order <code>has_many</code> on your booking model:</p>\n\n<pre><code>has_many :appointments\nhas_many :activiti...
{ "AcceptedAnswerId": "23223", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-27T04:26:05.420", "Id": "23204", "Score": "4", "Tags": [ "ruby", "ruby-on-rails" ], "Title": "Calculate sum of price on distant relation" }
23204
<p>How do I make this more Ruby like? I want to return the host, for example if the URL is "<a href="http://www.facebook.com" rel="nofollow">http://www.facebook.com</a>" then I want to get 'facebook.com'.</p> <p>Any other sub-domains without 'www' should give the subdomin as well. If the URL is "<a href="http://gist....
[]
[ { "body": "<p>This is looking like a custom requirement. By looking at your code, you want to remove http(s) and www. part of the url</p>\n\n<pre><code>def get_custom_domain\n @url.gsub(/^((https?:\\/\\/)?(www\\.)?)/, '')\nend\n</code></pre>\n\n<p>But it will be better if you give more example of what you exac...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-27T06:35:49.980", "Id": "23205", "Score": "4", "Tags": [ "ruby", "https" ], "Title": "Refactor Ruby method for getting domain?" }
23205
<p>I have a calculator created using C# that is running on a console. </p> <p>The calculator accepts a string input (e.g. 5+5) then produces the result (5+5=10). It will then prompt the user to enter another operator which will continue the evaluation (e.g. 10+5=15). To terminate the program, one can type the string...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-27T07:43:49.460", "Id": "35789", "Score": "4", "body": "I would recommend you reading a good article about math expressions evaluation with C#: http://www.codeproject.com/KB/recipes/expressions_evaluator.aspx" }, { "ContentLice...
[ { "body": "<p>From your last comment, what you're actually looking for is not more efficiency (which is difficult to measure anyway), but more quality, and I think we can do that.</p>\n\n<p>The biggest problem is that the program is very hard to read and follow, and thus hard to maintain. This is for several re...
{ "AcceptedAnswerId": "23328", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-27T07:23:32.073", "Id": "23209", "Score": "1", "Tags": [ "c#", "console", "calculator", "math-expression-eval" ], "Title": "Calculator application running on a console" }
23209
<p>i just wanted to confirm if my codes below is correct. Feel free to make corrections.</p> <pre><code>&lt;?php class createConnection { var $host="localhost"; var $username="root"; var $password=""; var $database="wilbert"; var $myconn; function connectToDatabase() { $conn = mysql_connect($his-&gt;host,$this-&gt;...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-27T18:20:53.713", "Id": "35811", "Score": "5", "body": "I'd probably avoid using a deprecated library (i.e. `mysql_*`) too." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-05T21:09:34.560", "Id": "36257...
[ { "body": "<p>I am a fan of loose coupling so I would suggest that you take the values of host, username, password and database out of your class. Pass the values through the constructor and set them in the constructor. This makes it easier to reuse your code.</p>\n\n<p>Second, in classes such as one that creat...
{ "AcceptedAnswerId": "23213", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-27T07:54:21.237", "Id": "23210", "Score": "2", "Tags": [ "php" ], "Title": "class and object in php" }
23210
<p>I'm working on my larger project to date, and on top of that I'm using underscore for the first time. All is working perfectly but I'd like some criticism on the use of underscore templating and underscore after function.</p> <p>The goal of the app is to generate on the dom a messaging interface starting from an em...
[]
[ { "body": "<p>Since you asked to review only the underscore part,</p>\n\n<p>Just had one remark that I would suggest to move the templates to a script tag \"text/template\" rather than defining them as a variable.</p>\n\n<p>eg:</p>\n\n<pre><code>&lt;script type=\"text/template\" id=\"msg_container\"&gt;\n &l...
{ "AcceptedAnswerId": "23244", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-27T13:41:42.420", "Id": "23215", "Score": "1", "Tags": [ "javascript", "jquery", "underscore.js" ], "Title": "Underscore and general app design review" }
23215
<p><a href="//underscorejs.org" rel="nofollow">Underscore</a> is a utility-belt library for JavaScript that provides a lot of the functional programming support that you would expect in <a href="http://prototypejs.org/api" rel="nofollow">Prototype.js</a> or <a href="/questions/tagged/ruby" class="post-tag" title="show ...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-27T14:32:43.197", "Id": "23217", "Score": "0", "Tags": null, "Title": null }
23217
Underscore is a library for JavaScript that provides functional programming support.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-27T14:32:43.197", "Id": "23218", "Score": "0", "Tags": null, "Title": null }
23218
<p>I want to find out if there are any improvements I can make to this code. How can I make it better, faster and use less queries? Or is it fine the way I wrote it?</p> <pre><code>&lt;?php if ( $user_ID ) : ?&gt; &lt;?php global $user_identity; ?&gt; &lt;div id="boxtop"&gt; &lt;div class="boxtop"&gt; &lt;div class="b...
[]
[ { "body": "<p>Ok, a few things of note. Not really related to perfomance, but readability. To be fair though these are just details for better readability, your code is not so bad.</p>\n\n<p>This code is not expensive process wise, I was curious as to where <code>$User_id</code> comes from, because that is whe...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-27T15:44:20.273", "Id": "23220", "Score": "3", "Tags": [ "php" ], "Title": "User Registration compress to use less querry, CPU posible" }
23220
<p>Could you please critisize the logger class below? Can it be used in a multi threaded web environment? If not how can I improve it? Is there anything wrong with locking in WriteToLog method or multithreading in FlushLog method?</p> <pre><code>public class Logger { private static Logger instance; private sta...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-27T18:41:55.920", "Id": "35813", "Score": "3", "body": "This is one of those areas where there are so many available (free and otherwise) mature and proven logging frameworks that attempting to create a robust performant one from scrat...
[ { "body": "<p>This code is not thread safe. You synchronize (lock) while adding to the queue, but your code which removes from the code does not lock the queue, and will always run on a background thread, which is going to cause potential race conditions.</p>\n\n<p>If you really must write your own logging, I ...
{ "AcceptedAnswerId": "23236", "CommentCount": "9", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-27T18:32:31.580", "Id": "23229", "Score": "2", "Tags": [ "c#", "design-patterns", "multithreading", "thread-safety", "locking" ], "Title": "Designing a better logger class...
23229
<p>I just started to learn Haskell, and i wrote a function that walks the directory tree recursively and pass the content of each directory to a callback function:</p> <ul> <li>The content of the directory is a tuple, containing a list of all the sub-directories, and a list of file names.</li> <li>If there is an error...
[]
[ { "body": "<p>You might be interested in the concept of iteratees/pipes that can be used to solve this problem. It allows you to separate producing the tree and consuming it somewhere else without direct callback functions: You create a producer that enumerates the directory tree, perhaps some filters that modi...
{ "AcceptedAnswerId": "23233", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-27T19:00:39.790", "Id": "23231", "Score": "7", "Tags": [ "haskell", "recursion", "directory" ], "Title": "Is there a better way to walk a directory tree?" }
23231
<p>This code computes the function <code>(3x^2-4x+16) / (5x^2+2x-4)</code>. I ran the program and it works, but I am fairly new to assembly language and am not quite sure how to make the most efficient use of the registers. Does this look ok or is there a better way to do it?</p> <pre><code>.text .globl main main: ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-28T00:25:10.560", "Id": "35845", "Score": "0", "body": "I won't provide you any assembly advice but would it be relevant to compile some simple C/C++ code and check the corresponding assembly code. Here's my attempt : \nint main(int x,...
[ { "body": "<p>There are multiple issues:</p>\n\n<p>first, try to make the program work: These two lines are contradictory</p>\n\n<pre><code>ori $8, $0, 3 #put x into $8\nori $8, $0, 1 #put x into $8\n</code></pre>\n\n<p>Perhaps the real idea is to move a function parameter to $8.</p>\n...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-27T22:53:33.363", "Id": "23245", "Score": "5", "Tags": [ "optimization", "beginner", "assembly" ], "Title": "Computing a mathematical function in MIPS assembly" }
23245
<p>As part of my data collection, I have to run multiple kinds of coverage processing on multiple Java projects. Below is my main <code>Makefile</code> intented only for gmake. Portability is not a requirement for me (for this project), but DRY and following make best practices are. Please comment on my code, and if th...
[]
[ { "body": "<pre><code>.PHONY: checkout all clobber clean $(checkout.all)\n</code></pre>\n\n<p>There's no <code>clobber</code> target, so I <em>think</em> that will be ignored.</p>\n\n<hr>\n\n<p>The <code>root</code> variable is unnecessary (<code>CURDIR</code> should be well known by anyone using <code>make</co...
{ "AcceptedAnswerId": "23313", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-27T23:03:06.307", "Id": "23246", "Score": "7", "Tags": [ "java", "git", "make", "maven" ], "Title": "Coverage processing on multiple Java projects with gmake" }
23246
<p>I'm new to PHP and had to put together a function that loads a random image from an array (it works fine). Here's what I came up with. Could it be improved? Any feedback would be appreciated.</p> <pre><code>&lt;?php function displayRandomPhotoArea() { $photoAreas = array("imageURL1", "imageURL2", "imageURL3", "...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-28T08:52:30.080", "Id": "35862", "Score": "1", "body": "I don't think this can be improved that much. You could make it more generic by passing the url-array as a parameter and return a random image-tag instead of directly displaying i...
[ { "body": "<p>Try to use <strong>array_rand</strong> function, code will look cleaner: </p>\n\n<pre><code>&lt;?php\nfunction displayRandomPhotoArea() \n{\n $photoAreas = array(\"imageURL1\", \"imageURL2\", \"imageURL3\", \"imageURL4\", \"imageURL5\");\n\n $randomNumber = array_rand($photoAreas);\n $ran...
{ "AcceptedAnswerId": "23255", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-28T08:24:29.460", "Id": "23253", "Score": "4", "Tags": [ "php", "array", "random", "image" ], "Title": "Function that Loads a Random Image from an Array" }
23253