body
stringlengths
25
86.7k
comments
list
answers
list
meta_data
dict
question_id
stringlengths
1
6
<p>I wrote this because I need to store an unknown bundle to a database. Most everyone suggested to <code>Parcel</code> it. The problem is the android docs specifically say not to use <code>parcel</code> for persistent storage. With some help from <code>palacsint</code> I was able to refactor my original code to the...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-01T11:29:02.100", "Id": "21397", "Score": "0", "body": "Could you edit the question in a way that does not make existing answers meaningless, please? I think it would be better to ask a new question with the refactored code. Maybe some...
[ { "body": "<ol>\n<li><p>Try to minimize the scope of local variables. It's not necessary to declare them at the beginning of the method, declare them where they are first used.</p>\n\n<p>See <em>Effective Java, Second Edition, Item 45: Minimize the scope of local variables</em>. (Google for \"minimize the scope...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-05T20:37:58.990", "Id": "12305", "Score": "1", "Tags": [ "java", "android" ], "Title": "I am trying to manually serialize an android.Bundle. Any thoughts on the implementation?" }
12305
<p><strong>Problem Statement:</strong></p> <blockquote> <p><strong>First Case:</strong> Where inclusion and exclusion both are not empty so that means inclusion overrides anything in exclusion so for that algorithm is like this:</p> <p>If key is either equal to 155 or 156 and if temp is there in inclusion the...
[]
[ { "body": "<p>Your logic seems good. The problem statement was a tough to understand, but I think I got it. </p>\n\n<p>Since <code>inclusion</code> and <code>exclusion</code> do not change, we should extract that checking from the loop and place it before the loop. </p>\n\n<p>Furthermore, to reduce programmer e...
{ "AcceptedAnswerId": "12315", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-05T21:28:09.927", "Id": "12307", "Score": "1", "Tags": [ "java", "performance" ], "Title": "Inclusion and exclusion" }
12307
<p>This is my first attempt at BDD and RSpec. I'm more of a C# xUnit kind of guy. </p> <p>I wrote this class while developing a 2D random tile map generator (just for fun). The project is still ongoing.</p> <p>I would particularly like some review on:</p> <ul> <li>Test granularity/scope in relation to BDD</li> <li>U...
[]
[ { "body": "<p>A small hint: the count method could clean up one of your test case, more or less as such:</p>\n\n<pre><code>it \"should have more than half the tiles be landmass\" do \n map = @map_factory.make(40, 40)\n number_of_water_tiles = map.tiles.count{|tile| tile.type == :water}\n number_of_lan...
{ "AcceptedAnswerId": "12341", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-05T23:49:46.753", "Id": "12309", "Score": "4", "Tags": [ "ruby", "rspec", "bdd" ], "Title": "First BDD/RSpec tests, would like some review regarding idioms, conventions and style"...
12309
<h2>Learning Scala</h2> <p>I'm trying to learn Scala and I'm interested in criticism about how to make my code more idiomatic. I've programmed a simple Connect-four game. Can I get some feedback?</p> <p><a href="https://github.com/jamiely/connect-four-scala">https://github.com/jamiely/connect-four-scala</a></p> <p>T...
[]
[ { "body": "<p>Nice code! You did the most things correct only some hints:</p>\n\n<ul>\n<li>Use case classes. They bring you some nice methods (like copy or apply) and result in easier maintainable code. There is no need any more to instantiate objects directly with <code>new</code> - instead it is possible to u...
{ "AcceptedAnswerId": "12327", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-06T00:47:06.683", "Id": "12312", "Score": "5", "Tags": [ "scala" ], "Title": "Connect Four In Idiomatic Scala" }
12312
<p>I need some advice\suggestions on how to create\handle database connections for a project I'm working on. I'm creating a simple work order system for my company using PHP 5.4.3, right now there isn't any type of authentication as I'm not ready for that complexity.</p> <p>So far I'm planning on the following structu...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-06T05:45:16.003", "Id": "19792", "Score": "0", "body": "You can use opensource classes http://code.google.com/p/digg/wiki/PDB" } ]
[]
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-06T03:47:46.603", "Id": "12313", "Score": "1", "Tags": [ "object-oriented", "php5", "database" ], "Title": "Using database connections in PHP classes" }
12313
<p>I have an interface named <code>ICodeRunner</code>, defined like this:</p> <pre class="lang-cs prettyprint-override"><code>public interface ICodeRunner { ExecutionResult Run(string code); } </code></pre> <p>I have more classes that implement <code>ICodeRunner</code>, but regardless of which one is used, ...
[]
[ { "body": "<p>This is actually a stab in the dark but could you use the .NET 4 System.Threading.Task object for this. Something like:</p>\n\n<pre><code>var task = Task.Factory.StartNew(() =&gt; _wrapped.Run(code) });\n\n// Wait returns true if the task finished within the allocated timeframe\n// http://msdn.mi...
{ "AcceptedAnswerId": "12323", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-06T08:46:57.737", "Id": "12321", "Score": "3", "Tags": [ "c#", "timeout" ], "Title": "Time Limit decorator" }
12321
<p>I am trying to get user's current location base on the accuracy and less battery consumption. </p> <p>Please review my code to help determine if I am going in right direction.</p> <pre><code>Location location = null; Criteria criteria = new Criteria(); criteria.setAccuracy(Criteria.ACCURACY_FINE); criteria.setAlti...
[]
[ { "body": "<p>The last know location could be null. So you need a further check for this, then ask for a quick update:</p>\n\n<pre><code> if(location == null){\n String provider = locationManager.getBestProvider(criteria, true);\n if (provider != null){\n locationManager.r...
{ "AcceptedAnswerId": "13335", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-06T09:05:30.280", "Id": "12322", "Score": "1", "Tags": [ "java", "android" ], "Title": "Getting user's current location" }
12322
<p>I have this function takes a long time to complete. Is there a way i can improve it to quicken the procedure</p> <pre><code>function do_updatebonus() { global $site_config; $res200 = SQL_Query_exec("SELECT DISTINCT userid FROM peers WHERE seeder = 'yes'"); while ($row200 = mysql_fetch_assoc($res200)) ...
[]
[ { "body": "<p>Yeah, you can optimize your query,</p>\n\n<pre><code> $res201 = SQL_Query_exec(\"SELECT COUNT(torrent) FROM peers WHERE seeder = 'yes' AND userid = $userid\");\n</code></pre>\n\n<p>As this query will first check for seeder which has 'yes' and then for userid. So you can first check for userid, the...
{ "AcceptedAnswerId": "12325", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-04T18:27:01.797", "Id": "12324", "Score": "1", "Tags": [ "php" ], "Title": "can this php function be written to perform better?" }
12324
<p>I would like to execute a series of events at the time at which they occur.</p> <p>The events are stored in a list and always sorted by time of execution.</p> <pre><code>volatileEvents.Sort(SortScriptEventAscending.Comparer); </code></pre> <p>I would like to have my update method execute the following points.</p>...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-06T13:48:02.907", "Id": "19789", "Score": "0", "body": "Why does an event have to stay in the list while it's executing? And it really should stay there even after it's finished?" }, { "ContentLicense": "CC BY-SA 3.0", "Cre...
[ { "body": "<p>My simplified answer (without interpolation or looping):</p>\n\n<pre><code> int numEvents = events.Count;\n\n // Check if there are any events to execute\n if (eventIndex == numEvents)\n {\n return;\n }\n\n // Check if the current event has yet ...
{ "AcceptedAnswerId": "12406", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-06T13:32:25.347", "Id": "12328", "Score": "2", "Tags": [ "c#", "algorithm", "timer" ], "Title": "Timed series of events. Logic for organizing events based on time?" }
12328
<p>In view of the recent LinkedIn breach, would anyone care to review my data access routines relating to user access?</p> <p>This is a standard node.js module, accessing a Postgres database.</p> <pre><code>(function () { 'use strict'; var crypto = require('crypto'), hash = function (pass, salt) { ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-06T14:33:20.667", "Id": "19794", "Score": "1", "body": "The code looks fine to me, but I wouldn't use the email as the hash salt because it doesn't provide enough entropy. I always use a GUID as a salt because it ensures that `bits(pas...
[ { "body": "<p>I do not see anything immediately wrong with your <code>addUser()</code> and <code>getUser()</code> implementations.<br>\nYour <code>hash()</code> implementation could be improved in two areas though.</p>\n\n<ol>\n<li><p><strong>Salt</strong><br>\nAs already indicated by Bill Barry in the comments...
{ "AcceptedAnswerId": "15635", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-06T14:22:45.187", "Id": "12330", "Score": "11", "Tags": [ "javascript", "node.js", "postgresql" ], "Title": "Node.js password salting/hashing" }
12330
<p>I am using this <a href="http://onsetsds.sourceforge.net/" rel="nofollow">onset source code</a> and <a href="http://courseware.ee.calpoly.edu/~jbreiten/C/" rel="nofollow">this fft file</a> to try to perform onset detection. Currently the code is working, but as my DSP and C skills are subpar I could use some advice ...
[]
[ { "body": "<p>The link in the post to your fft file is broken, so I can't see the function\nprototype. This is a pity, because it is otherwise difficult to know what to\nmake of your arrays:</p>\n\n<pre><code>double (*vocalData)[2] = malloc(2 * 512 * sizeof(double));\n</code></pre>\n\n<p>This says <code>vocal...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-06T15:22:16.260", "Id": "12331", "Score": "4", "Tags": [ "c", "signal-processing" ], "Title": "Onset detection using FFT" }
12331
<blockquote> <p>Consider an 8-bit complier, in which we have an integer of size, say 2-words i.e. 16-bits or 2 bytes. You need to store three integer values which are supposed to be as:</p> <blockquote> <pre class="lang-none prettyprint-override"><code>Name Range Size Required ------------...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-07T06:36:55.020", "Id": "19821", "Score": "0", "body": "Checked this code in both little endian and big endian machines." } ]
[ { "body": "<p>Some ideas:</p>\n\n<ol>\n<li><p>I'd try encapsulating the position and mask parameters to one parameter. Maybe a struct would be fine for this. It is easy to mix up the parameters of <code>ret</code>, for example, somebody could call it accidentally with </p>\n\n<pre><code>`ret(output, secondnum_p...
{ "AcceptedAnswerId": "12422", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-06T17:17:18.377", "Id": "12332", "Score": "4", "Tags": [ "algorithm", "c", "unit-testing", "homework", "integer" ], "Title": "Storing three integer values" }
12332
<p>I have implemented a socket listener that runs on my Linux Ubuntu server accepting connections and then starting up a new thread to listen on those connections (classic socket listener approach). The socket listener is persistant and the way it is restarted is by restarting the server.</p> <p>I have implemented a...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-09T21:06:11.787", "Id": "20012", "Score": "2", "body": "For loggging, I suggest you to adopt an existing logging framework they take care of issues faced by you.have a look into log4j and slf4j." }, { "ContentLicense": "CC BY-S...
[ { "body": "<p>Here are some ideas:</p>\n\n<ul>\n<li>For better granularity of logs, if you're looking at high performance, write on a minutely, or hourly basis. Use the idea of writing to logs as jobs, each dispatched to a thread. This makes searchability of log files inherently parallelizable.</li>\n<li>Use a ...
{ "AcceptedAnswerId": "13885", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-06T20:27:00.897", "Id": "12336", "Score": "4", "Tags": [ "java", "multithreading", "unit-testing", "queue", "logging" ], "Title": "Robust logging solution to file on disk ...
12336
<p>I have a simple atomic access class designed to work with Windows threads:</p> <pre><code>template &lt;class aa_type&gt; class AtomicAccess{ private: CRITICAL_SECTION lock; aa_type value; public: AtomicAccess(){ InitializeCriticalSection(&amp;lock); } ~AtomicAccess(){ DeleteCrit...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-08-03T10:18:37.950", "Id": "23116", "Score": "0", "body": "Doing this just for simple integer ops seems like overkill. You should look into CAS/intrinsic ops (InterlockedIncrement & associated functions)." } ]
[ { "body": "<p>I'm pretty bad at concurrency, and by no means a C++ expert, but this question has gotten surprisingly little attention, so I'll take a stab at it. Note that I've focused mostly on coding style rather than thread safety. Once I've had some more time to think about the code, I'll edit and post mo...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-06T23:33:35.727", "Id": "12340", "Score": "4", "Tags": [ "c++", "multithreading", "windows", "atomic" ], "Title": "Win7 atomic access class" }
12340
<p>I am working through the exercises in the book Accelerated C++. I wanted to get some feedback on proper use of the Standard Library, correctness, overall style, portability, etc.</p> <pre><code>/******************************************************************************* Accelerated C++ Chapter 3 Write a progr...
[]
[ { "body": "<p>You could cut your code in half if you used a map:</p>\n\n<pre><code>typedef std::map&lt;std::string, unsigned int&gt; Map;\n\nMap tMap;\nwhile(std::cin &gt;&gt; word)\n{\n // When accessing a map with `[]` If the value does not exist\n // it is created and initialized to zero.\n //\n ...
{ "AcceptedAnswerId": "12343", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-07T01:14:23.700", "Id": "12342", "Score": "5", "Tags": [ "c++" ], "Title": "Exercise from Accelerated C++" }
12342
<p>I have been tasked with creating financial reports. I am looking for any suggestions on improving performance, readability/formatting or best practices. </p> <pre><code>/*setting dummy parameters */ SET DATEFORMAT dmy DECLARE @startProduct NVARCHAR = '' DECLARE @endProduct NVARCHAR = 'zzzzzzzzzzzzzzzzzzzzzz' DECLA...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-08T07:24:26.533", "Id": "19877", "Score": "0", "body": "Which database (SQL Server, Oracle, other?) and version?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-08T09:15:52.420", "Id": "19890", "Sco...
[ { "body": "<p>It appears that you're using the same expressions for the <code>GroupCode</code> and <code>GroupDescription</code> columns in the <code>GROUP BY</code> clause. That's asking for trouble later on if someone needs to modify either expression, especially given their size. Instead, use a subquery:</...
{ "AcceptedAnswerId": "12375", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-07T06:14:44.557", "Id": "12345", "Score": "3", "Tags": [ "performance", "sql", "finance" ], "Title": "Financial report query" }
12345
<p>I am a PHP newbie, gone through a couple starter tutorials which went ok, so I thought I'd try creating a more complex project to get some experience. It is a NetBeans PHP project where I try to replicate some of the functionality from Microsoft's CodeDOM technology and Zend_CodeGenerator. Basically it is a class li...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-07T07:49:38.927", "Id": "19823", "Score": "0", "body": "Please post your code here and specify what kind of feedback you're looking for: code correctness, best practices and design pattern usage, application UI, security issues, etc." ...
[ { "body": "<p>as i do not know the technologies you try to implement i will focus on general stuff. </p>\n\n<p>first:</p>\n\n<pre><code>public function __construct()\n{\n $this-&gt;Comments = new CommentStatementCollection();\n}\n</code></pre>\n\n<p>it would be better to inject \"CommentStatementCollection\"...
{ "AcceptedAnswerId": "12350", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-07T06:17:47.487", "Id": "12346", "Score": "2", "Tags": [ "php", "object-oriented", "unit-testing" ], "Title": "PHP class library" }
12346
<p>I have a particular if statement that could be written in different ways, and I'm curious as to whether there's any significant difference in readability that I should prefer one over the other:</p> <p>The flow can be boiled down to</p> <pre><code>if string does not begin with '_' do stuff else throw error...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-07T15:54:24.343", "Id": "19843", "Score": "1", "body": "@palacsint, The title is the question, please don't change my question." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-08T17:53:37.650", "Id": "1...
[ { "body": "<p>The first one is the most clear, to me. You're only testing one character so the patterns in the 3rd and 4th are a little overkill. The second one is OK, but still not as clear as the first.</p>\n", "comments": [], "meta_data": { "CommentCount": "0", "ContentLicense": "CC BY-SA...
{ "AcceptedAnswerId": "12354", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-07T15:12:48.997", "Id": "12352", "Score": "4", "Tags": [ "javascript" ], "Title": "poh-tay-toh poh-tah-toh, does writing the same code a different way affect readability?" }
12352
<p>I just started learning Haskell, and I must say it is unlike anything else. As my first not-entirely-trivial piece of code I tried to write a simple Bayes Classifier. It is in two parts, a classifier module and a cli.</p> <p>What could be done to improve it? Is it entirely awful? Is it too imperative? Any and all f...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-08T02:18:46.217", "Id": "19865", "Score": "0", "body": "what is (More Stop Words)? Is that a comment? I think it is, but your capitalization is throwing me off :)." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "20...
[ { "body": "<p>The most obvious problem to me is formatting. Cut down on line width by putting <code>let</code> and <code>case</code> expressions down:</p>\n\n<pre><code>probabilityOfWordInCategory (Classifier training) word category =\n let allInCategory = filter (\\(cat, _) -&gt; cat == category) training\...
{ "AcceptedAnswerId": "12371", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-07T20:16:42.613", "Id": "12359", "Score": "10", "Tags": [ "optimization", "haskell", "functional-programming" ], "Title": "Naive Bayes classifier" }
12359
<p>I have two string variables <code>site_inclusion</code> and <code>site_exclusion</code>. If <code>site_inclusion</code> has some values, then I don't care what values <code>site_exclusion</code> contains. This means <code>site_inclusion</code> overrides <code>site_exclusion</code> if <code>site_inclusion</code> ha...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-07T22:10:48.913", "Id": "19861", "Score": "0", "body": "Your [question on SO](http://stackoverflow.com/questions/10940360/remove-repeated-code) should probably be merged into this one." } ]
[ { "body": "<p>Please spinning it to a separate function. Here is what I think is a little more simpler implementation.</p>\n\n<pre><code>public boolean checkInclusion(String site_i, String site_e, Regex re) {\n if (site_i != null)\n return site_e.matches(re);\n else if(site_e != null)\n retu...
{ "AcceptedAnswerId": "12364", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-07T21:45:12.860", "Id": "12361", "Score": "2", "Tags": [ "java" ], "Title": "Check site inclusion and exclusion" }
12361
<p>The program finds the first non repeating character in a character array, array contains only small case letters. </p> <pre><code>#include&lt;iostream&gt; #include&lt;cstring&gt; using namespace std; int main() { char a2z[26]={0};//Hash char input[100] = "abcbbbcdegh";//sample input, only small case english alpha...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-08T06:13:05.623", "Id": "19875", "Score": "0", "body": "Add the output of the program too. It makes it easier for people without access to a compiler right now to look at your code." }, { "ContentLicense": "CC BY-SA 3.0", "...
[ { "body": "<p>The same program with a few changes. first, try to refactor your functions so that they are small, second, Often, using a case statement is more clearer to using cascading ifs. third, 'using namespace std' is a bad habit. It is probably ok to use in a small one off program like this, but avoid pol...
{ "AcceptedAnswerId": "12377", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-08T03:41:57.090", "Id": "12372", "Score": "0", "Tags": [ "c++", "array" ], "Title": "Searching first non repeating character" }
12372
<p>I am having a popup which is styled to match the page and am using that single popup to display messages to the user. My popup contains one h1 element and an ASP.NET Label.</p> <p>The h1 element and Label contents and color change according to the operation: if the information was successfully inserted the h1 text ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-08T08:38:24.183", "Id": "19886", "Score": "1", "body": "Next time, care about your grammar/spelling. It's ok not to speak english perfectly, but at least give some air to your text." }, { "ContentLicense": "CC BY-SA 3.0", "...
[ { "body": "<p>A few ideas:</p>\n\n<ul>\n<li>Your three javascript functions could easily be combined into one with some simple arguments, like headerText, statusMessage, statusType.</li>\n<li>In your description you list some success text, but this isn't in the javascript, so I guess this is set in the code-beh...
{ "AcceptedAnswerId": "12411", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-08T08:22:29.217", "Id": "12378", "Score": "0", "Tags": [ "javascript", "jquery" ], "Title": "Using a popup to display messages to the user" }
12378
<p>I just answered the question on project euler about finding <a href="http://projecteuler.net/problem=35" rel="nofollow">circular primes below 1 million</a> using python. My solution is below. I was able to reduce the running time of the solution from 9 seconds to about 3 seconds. I would like to see what else can be...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-08T10:21:37.733", "Id": "19907", "Score": "0", "body": "do you have any idea which region takes the most time? the getPrimes method looks like it's going to be expensive, as you're building two very large sets then subtracting one from...
[ { "body": "<p>Python 2.7: <strong>100 ms</strong>, pypy 1.8.0: <strong>60 ms</strong> (Intel Core i7-3770K, 4x 3.50GHz):</p>\n\n<pre><code>import time\n\ndef rwh_primes2(n):\n # http://stackoverflow.com/questions/2068372/fastest-way-to-list-all-primes-below-n-in-python/3035188#3035188\n \"\"\" Input n&gt;...
{ "AcceptedAnswerId": "12389", "CommentCount": "10", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-08T10:12:17.230", "Id": "12383", "Score": "4", "Tags": [ "python", "optimization", "project-euler", "primes" ], "Title": "Improving runtime of prime generation" }
12383
<p>I needed a singleton in JavaScript in order to make a DataManager which is called multiple times, but I just want it to load its data only the first time it is called, then give pieces of the data out view public methods, never loading the initial data again.</p> <p>I found a number of approaches to building single...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-08T14:57:33.613", "Id": "19932", "Score": "0", "body": "Is that java factory?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-08T16:16:51.847", "Id": "19946", "Score": "0", "body": "Is there a r...
[ { "body": "<ul>\n<li><p>Once you start to chain properties or function calls, you incur performance penalty due to scope differences. It's best you keep the property/function depth to a minimum. This ain't Java or AS3 that needs deep namespacing.</p></li>\n<li><p>What's the idea of <code>getInstance()</code>? C...
{ "AcceptedAnswerId": "12409", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-08T14:53:43.763", "Id": "12388", "Score": "1", "Tags": [ "javascript", "singleton" ], "Title": "Can this JavaScript singleton be improved?" }
12388
<p>I'm a beginner programmer and I'm hoping someone would be willing to take a look at my code and tell me how to improve my coding style and development approach. Sorry about not commenting, I will try to get into the habit of commenting.</p> <p><strong>board.h</strong></p> <pre><code>#include &lt;iostream&gt; #incl...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-08T16:43:50.423", "Id": "19948", "Score": "0", "body": "I am curious. Why do you use _parameter names? I have usually seen Object._member convention, (The given reason is that object members are from a non-local scope, and hence need t...
[ { "body": "<p>Just a few things I noticed which may be of use in the future. All these items come from the amazing book by Scott Meyers' <a href=\"http://www.amazon.co.uk/Effective-Specific-Addison-Wesley-Professional-Computing/dp/0321334876/ref=sr_1_1?s=books&amp;ie=UTF8&amp;qid=1339173771&amp;sr=1-1\" rel=\"n...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-08T16:19:36.883", "Id": "12391", "Score": "4", "Tags": [ "c++", "beginner", "pathfinding", "sliding-tile-puzzle" ], "Title": "Sliding block puzzle, A*" }
12391
<p>I'm beginning to learn HTML and CSS, and since our lead developer is busy finishing up our project, I was asked to code the landing page.</p> <p>I read up on some tutorials and beginning books, so I have a general grasp of things. But I'm curious as to how I use HTML and CSS to layout images efficiently. </p> <p>...
[]
[ { "body": "<p>A good tip is to layout in columns and not rows, similar to a newspaper. That is, divide the page into columns and stack the contents as rows, similar to <a href=\"http://pinterest.com/\" rel=\"nofollow noreferrer\">Pinterest</a>. So, in your site, that makes the iPhone 1 column, and the rest in a...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-08T19:47:13.360", "Id": "12402", "Score": "3", "Tags": [ "html", "css" ], "Title": "Laying out images for a landing page" }
12402
<p>In order to do its work, a DataProcessor needs Data and otherData.</p> <p>One instance of Data will be shared over a set of DataProcessor, but each DataProcessor has its own otherData.</p> <p>For sharing Data instances, fields of Data could not be defined inside DataProcessor, thus, there are two hierarchies: Data...
[]
[ { "body": "<p>Well, given the examples, i'd avoid inheritance and implement an interface for the DataProcessor.</p>\n\n<pre><code>package net.icodeapps.examples.ooad;\n\npublic interface DataProcessor&lt;T, OtherData&gt; {\n\n T processData();\n}\n</code></pre>\n\n<p>This could be implement by any class like...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-09T05:15:45.097", "Id": "12412", "Score": "1", "Tags": [ "java", "design-patterns" ], "Title": "Two related hierarchies of classes" }
12412
<p>I'm trying to create a generic function that takes a data structure as input and then sends each non-empty item—e.g.: str, int—individually:</p> <pre><code>def print_this(v, delim1="", delim2=""): print v, delim1, delim2 def pass_many(vals, some_funct, args=None): if vals: if type(vals) == list or ...
[]
[ { "body": "<p>I'd make a few changes: </p>\n\n<p>1) Take the <code>if v</code> check out of the inner loop into the function body (<code>if not vals: return</code>) - seems more consistent that way, unless you want <code>pass_many(0,print)</code> to print something but <code>pass_may([0], print)</code> not to?<...
{ "AcceptedAnswerId": "12421", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-09T11:34:48.273", "Id": "12414", "Score": "2", "Tags": [ "python", "generics" ], "Title": "Generic pass_many(vals, pass_one) to unroll and call pass_one(val)" }
12414
<p>I know this may be very time consuming for you as the answerer of this question, but I have recently been looking into C# and I decided that I would try to develop a pinging application, so that I did. I have all the functionality. I just have a question regarding readability and how to set up the individual documen...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-09T15:41:44.260", "Id": "20009", "Score": "3", "body": "Run StyleCop on it, learn about `StringBuilder`, String.Format, about `static`, `readonly` modifiers. http://www.codinghorror.com/blog/2006/01/flattening-arrow-code.html. Run Styl...
[ { "body": "<p>You have a 338 character line, find a way to split up your long lines.</p>\n\n<hr>\n\n<p>You don't need to fully qualify things that you have a using statement for: <code>System.IO.StreamWriter</code> could be <code>StreamWriter</code> because you have a <code>using System.IO;</code> at the start ...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-09T12:49:49.527", "Id": "12415", "Score": "2", "Tags": [ "c#", ".net" ], "Title": "Pinging application" }
12415
<p>I'm trying declare a string in ANSI C and am not sure of the best way to do it.</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;stdlib.h&gt; #include &lt;string.h&gt; #include &lt;stdarg.h&gt; char *InitStr(char *ReturnStr){ ReturnStr = NULL; ReturnStr = realloc( ReturnStr, strlen("") +1 ); ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-09T23:25:14.247", "Id": "20023", "Score": "3", "body": "for a beginner, this is reasonable source code. the `char *InitStr(char *ReturnStr){\n ReturnStr = NULL; ...} however, makes no sense. Why give an argument to a function, knowi...
[ { "body": "<p>This question might be more appropriate for programmers or codereview, but, this is what a code review of mine, probably with at least one controversial statement inside somewhere, would go like. Hopefully you will find some advice in here that answers your questions.</p>\n\n<p>1) Make sure you ...
{ "AcceptedAnswerId": "12430", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-09T23:19:00.373", "Id": "12428", "Score": "3", "Tags": [ "c", "strings" ], "Title": "String in ANSI C?" }
12428
<p>As a learning process I created 'reverse' function in a few different ways. Tinkering with 'reverse' made currying, folds and other stuff easier to understand. Almost natural!</p> <p>I know these are trivial things for someone who had years of Haskell practice. Try to look at if from the perspective of real beginne...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-10T04:08:18.387", "Id": "20036", "Score": "0", "body": "Let's try [codereview.se] since you appear to have functional code already." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-10T08:21:55.790", "Id"...
[ { "body": "<p>I do not know much about performance of each versions because GHC has various optimizations built in, and I have not kept up to date with them. The best option for checking that is to benchmark the code in question.</p>\n\n<p>Here are my updates,</p>\n\n<pre><code>import Test.HUnit\n\n-- revA1 [] ...
{ "AcceptedAnswerId": "12434", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-10T02:14:48.300", "Id": "12432", "Score": "3", "Tags": [ "haskell", "recursion" ], "Title": "Haskell recursions, level zero" }
12432
<p>I need to write a service to return objects in pages of size 20. The caching of these objects is done in pages of size 60.</p> <p>To abstract the logic of streaming differently-sized pages, I wrote this <code>PagingAdapter</code> class:</p> <pre><code>public abstract class PagingAdapter&lt;T&gt; implements Iterabl...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-10T06:48:07.207", "Id": "20040", "Score": "0", "body": "This is my first time posting on code review - let me know if/how I can improve the question at all." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-08-3...
[ { "body": "<p>I like your usage of Guava, and overall your code seems really good. I might actually use it myself somewhere.</p>\n<p>The code could use some more Javadoc though, especially on the class itself and the constructor. Explaining those <code>callerPageSize</code> and <code>sourcePageSize</code> param...
{ "AcceptedAnswerId": "37617", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-10T06:47:07.410", "Id": "12433", "Score": "8", "Tags": [ "java", "optimization", "pagination" ], "Title": "Streaming pages of a different size than a cache's pages" }
12433
<p>This is my first VBScript I have ever written and I would like to know if there is any obvious blunders in the code. All the code should do is check if file exists then change the Yahoo URL to the Google URL in the XML file. Note: The code seems to function properly.</p> <pre><code>Dim objFSO Set objFSO = CreateObj...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-10T12:51:15.477", "Id": "20055", "Score": "5", "body": "This isn’t an answer but I *strongly* suggest you drop VBScript, which is old, unmaintained and a horrible, hacky mess, and use a modern scripting language (such as Python) instea...
[ { "body": "<p>I reworked your VBScript a bit with comments, see below. In response to the comment from Konrad, I can agree with him for 90% of the cases. VBScript stays interesting for system management, logon scripts, etc., but I myself am replacing it with Ruby which isn't a big step up from VBScript, and on ...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-10T12:31:25.137", "Id": "12439", "Score": "7", "Tags": [ "vbscript" ], "Title": "Check if an XML file exists then change URLs in it" }
12439
<p>I have to list a integers from a text file separated by newlines into a python list. I ended up with the code above which works (for my case) but certainly is far form optimal.</p> <pre><code>def readIntegers(pathToFile): f = open(pathToFile) contents = f.read() f.close() tmpStr = "" integers...
[]
[ { "body": "<p>No need for <code>split</code> (you can use <a href=\"http://docs.python.org/library/stdtypes.html#file.readlines\"><code>readlines</code></a>). But no need for <code>readlines</code>, for that matter:</p>\n\n<pre><code>def read_integers(filename):\n with open(filename) as f:\n return ma...
{ "AcceptedAnswerId": "12449", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-10T16:17:53.333", "Id": "12443", "Score": "8", "Tags": [ "python" ], "Title": "Reading ints line from a file in Python" }
12443
<p>Every shim I have seen for this function has used the IE-only CSS <code>expression</code> trick. While there's no denying it's effective, it's made useless if the browser is not IE and doesn't support <code>querySelectorAll</code> either.</p> <p>jQuery is out of the question, since I don't want to get a whole frame...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-10T17:02:38.810", "Id": "20060", "Score": "1", "body": "Just a quick note: is it really necessary to `querySelectorAll` when you just want to `querySelector`? It seems highly inefficient." }, { "ContentLicense": "CC BY-SA 3.0",...
[ { "body": "<h2>Overal</h2>\n\n<p>I am not sure which non IE-browser doesn't support querySelectorAll. Regardless, the code seems very performant, if a little Golfic ( reminds me of code golf ).</p>\n\n<h2>Nitpickings</h2>\n\n<p>If you wish this source to be maintained / debugged /reviewed by others, there are s...
{ "AcceptedAnswerId": "37805", "CommentCount": "10", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-10T16:24:14.723", "Id": "12444", "Score": "11", "Tags": [ "javascript", "cross-browser" ], "Title": "querySelectorAll shim for non-IE browsers" }
12444
<p>I am not sure the square brackets are correct (although it has not yet failed some simple tests). I would also like to reduce and simplify this code to one line if practical. I think the code is self explanatory.</p> <pre><code> str = str.replace(/[\n]/g,'&lt;br&gt;') str = str.replace(/[\t]/g,'&amp;nbsp;&amp;nb...
[]
[ { "body": "<p>The square brackets are technically correct, but unneeded:</p>\n\n<pre><code>str = str.replace(/\\n/g, \"&lt;br&gt;\");\n</code></pre>\n\n<p>Also, since a new string is returned, you can chain the methods:</p>\n\n<pre><code>str = str.replace(/\\n/g, \"&lt;br&gt;\").replace(/\\t/g, \"&amp;nbsp;&amp...
{ "AcceptedAnswerId": "12457", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-11T02:30:36.303", "Id": "12454", "Score": "4", "Tags": [ "javascript", "regex" ], "Title": "JavaScript replace" }
12454
<p>I have been programming a simple number guessing game and I am wondering if there is any way of making my code more efficient and cleaner. I have spent some time on it implementing error checking to make it as safe as I know how. I feel as if the way's that I have done this may be 'long winded' so if you know of a s...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-11T19:23:56.030", "Id": "20092", "Score": "0", "body": "May I suggest that you modify the question title to include more information about your specific issue (because \"help me make my code better\" is *everyone's* goal here :) )." ...
[ { "body": "<p>Here some of my language-focused remarks, not touching the actual program design.</p>\n\n<h2>usings</h2>\n\n<pre><code>// Include the standard namespace for easy use of cout/cin\nusing namespace std;\n</code></pre>\n\n<p>Very nice to list what you need by adding the comment. But instead of pulling...
{ "AcceptedAnswerId": "12461", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-11T11:23:12.563", "Id": "12460", "Score": "4", "Tags": [ "c++", "optimization", "game" ], "Title": "How can I make a simple number guessing game more efficient?" }
12460
<p>I have a small social networking site built in CodeIgniter. Any registered user can send messages to others by visiting their profile.</p> <p>Today I noticed that one user sent bulk messages to 200 users. How he was able to do that?</p> <p>Suggestions to make the code secure are welcome.</p> <p>I have a textarea ...
[]
[ { "body": "<p>First of all you should use site_url() in your jquery code instead of base_url() as it provides url flexibility. For more info visit <a href=\"http://codeigniter.com/user_guide/helpers/url_helper.html\" rel=\"nofollow\">http://codeigniter.com/user_guide/helpers/url_helper.html</a></p>\n\n<p>And in...
{ "AcceptedAnswerId": "12473", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-11T05:45:03.077", "Id": "12462", "Score": "3", "Tags": [ "php", "jquery", "mysql", "security", "codeigniter" ], "Title": "CodeIgniter AJAX messages submission security iss...
12462
<p>I just got back from my interview where I had to solve the following problem:</p> <blockquote> <p>Write a C++ program that prints the following pattern using nested <code>for</code> loops.</p> </blockquote> <pre><code>* *** ***** *** * </code></pre> <p>Here is my solution:</p> <pre><code>int inc = 2; for (int ...
[]
[ { "body": "<p><strong>Edit</strong> Oh well, not using nested for... Sorry about that</p>\n\n<pre><code>int inc = 2;\nfor (int i = 1; i &gt;= 1; i += inc){\n std::cout&lt;&lt;std::string(i,'*')&lt;&lt;endl;\n if ( i == 5 )\n inc = -2;\n}\n</code></pre>\n", "comments": [], "meta_data": { ...
{ "AcceptedAnswerId": "12467", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-11T16:20:40.257", "Id": "12465", "Score": "10", "Tags": [ "c++", "algorithm", "interview-questions" ], "Title": "Printing stars using nested loops" }
12465
<p>Question is short. Assuming that I don't need reference itself, would this cast</p> <pre><code>((TextView) findViewById(R.id.someTextView)).setText("lala"); </code></pre> <p>be better (or at least not worse) than:</p> <pre><code>TextView tv=(TextView) findViewById(R.id.someTextView); tv.setText("lala"); </code></...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-12T00:33:09.820", "Id": "20096", "Score": "1", "body": "I would say not worse from what's actually occurring point of view but defo second option IMHO for readability" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": ...
[ { "body": "<p>The latter would be my preferred method. It enhances readability, and allows you to use that object more than once without casting it every time (more efficient). </p>\n\n<p>Though, if you are only casting to use one function inside the object, then there's no point in doing the latter (you would ...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-11T20:54:12.997", "Id": "12471", "Score": "2", "Tags": [ "java", "android", "casting" ], "Title": "Nice way to using cast on TextView" }
12471
<pre><code>/******************************************************************************************** * ToDo - Make CIO and IServer basic functions....complete break down to functions. *******************************************************************************************/ /***********************************...
[]
[ { "body": "<p>The singleton pattern <code>(function(x){...})(bar)</code> is useful for performing some complex set of actions once, without putting a bunch of members in the global namespace (or some other scope), and/or allowing the argument <code>bar</code> to be aliased as <code>x</code> within the outer fun...
{ "AcceptedAnswerId": "12476", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-11T22:56:47.803", "Id": "12474", "Score": "-1", "Tags": [ "javascript" ], "Title": "Foo - No Globals | Remove identifier if no return" }
12474
<p>I need a singleton that can safely operate in a multi-thread environment. Threading and concurrency is new to me, so I'm not sure if this implementation holds. Take a look:</p> <pre><code>public class ObserverSingleton { private static ObserverSingleton _instance; private ArrayList&lt;OnRequestFinishedList...
[]
[ { "body": "<p>The <code>notifyListeners()</code> method is private, and is never called anywhere. It should be synchronized on the same lock than the other methods using the list of listeners.</p>\n\n<p>Unless lazy instantiation is really needed, I wouldn't use it. Just use the following code:</p>\n\n<pre><code...
{ "AcceptedAnswerId": "12485", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-12T11:22:28.333", "Id": "12484", "Score": "4", "Tags": [ "java", "multithreading", "singleton" ], "Title": "Is this a good implementation of a thread-safe singleton using the obse...
12484
<p>I've just written this function for a test, but now I want to rewrite it for production.</p> <p>I would like to know the best way to do this, or if this is "best practice" I think it's too long for the minimal stuff it does.</p> <p>The whole idea is something like this: I have a one page with three sections floate...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-12T15:12:22.317", "Id": "20122", "Score": "3", "body": "Could you maybe post an example on jsfiddle and link it here or post your html? I think having your page markup will help significantly." } ]
[ { "body": "<p>Well, there's a few basic best practice tips I can give to start without really looking at the logic.</p>\n\n<p>First, you can declare multiple variables in one statement, like so:</p>\n\n<pre><code>var projectCount = $('.current &gt; .project').size(),\n subcounter = $('.current &gt; .page').s...
{ "AcceptedAnswerId": "12505", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-12T14:41:54.533", "Id": "12492", "Score": "1", "Tags": [ "javascript", "jquery" ], "Title": "Page indicator - can it be smaller?" }
12492
<p>This is my first real Cocoa app that I am writing. The first version of this app was just one long applescript. So in my app <a href="http://code.gogle.com/auto-git" rel="nofollow">auto git,</a> I have an NSTask instead of Tell terminal. My code looks like this:</p> <pre><code>-(void) runScript:(NSString *) path:(N...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-23T14:03:17.377", "Id": "73401", "Score": "0", "body": "In regards to your question about errors, what kind of errors could happen? I see nothing relating to error handling in here. Also, your link doesn't work" } ]
[ { "body": "<p>First of all, I don't care for this style of method naming in the slightest. This is Objective-C. Our method names should be verbose and descriptive. If the method name is too long, code completion will help us out. But if it's too short, and we have other methods that perform similar tasks, w...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-12T15:21:34.497", "Id": "12494", "Score": "4", "Tags": [ "objective-c", "git", "child-process" ], "Title": "NSTask with Git" }
12494
<p>I have a switch statement that checks whether or not one string matched another that was stored in an array. However, there are multiple cases in which the same result is returned for multiple matches. I originally had a large amount of if/else checks, but tried to shorten that down with the switch statement. I was ...
[]
[ { "body": "<p>You can convert it to two array. The first will normalize multiple \"aliases\" of the same key into one and second will have your address values.</p>\n\n<pre><code>var aliases = {\n \"hyde\" : \"hydepark\",\n \"uofc\" : \"hydepark\",\n \"uchicago\" : \"hydepark\",\n \"wttw\" : \"willis\"\n};\n...
{ "AcceptedAnswerId": "12498", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-12T15:26:58.747", "Id": "12495", "Score": "2", "Tags": [ "javascript" ], "Title": "jQuery Shorten Switch Statement" }
12495
<p>The <code>.htaccess</code> file redirects all requests to this file and the <code>$_REQUEST['path']</code> variable contains the url after the base url.</p> <pre><code>$url = ''; $urlSegments = []; $resource = ''; $action = ''; $parameters = []; if(isset($_REQUEST['path'])){ $url = $_REQUEST['path']; $urlS...
[]
[ { "body": "<p>This example:</p>\n\n<pre><code>$uri = '/users/create';\n$regex = '~^/(?P&lt;resource&gt;.*?)/(?P&lt;action&gt;.*?)/?$~';\n\nif (preg_match($regex, $uri, $matches)) {\n print_r($matches);\n}\n</code></pre>\n\n<p>Will produce following result:</p>\n\n<pre><code>Array\n(\n [0] =&gt; /users/cre...
{ "AcceptedAnswerId": "12497", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-12T16:04:48.323", "Id": "12496", "Score": "4", "Tags": [ "php", "parsing" ], "Title": "Parsing URL segments" }
12496
<p>The "vectorizing" of fancy indexing by Python's NumPy library sometimes gives unexpected results.</p> <p>For example:</p> <pre><code>import numpy a = numpy.zeros((1000,4), dtype='uint32') b = numpy.zeros((1000,4), dtype='uint32') i = numpy.random.random_integers(0,999,1000) j = numpy.random.random_integers(0,3,100...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-12T16:39:59.470", "Id": "20140", "Score": "0", "body": "I'm not quite sure I understand the question. Wouldn't that always be the length of i and j? Is there a case where it isn't?" }, { "ContentLicense": "CC BY-SA 3.0", "C...
[ { "body": "<p>This is what I came up with (see the <code>flat</code> function at the bottom):</p>\n\n<pre><code>from timeit import timeit\nimport numpy\n\n# Dimensions\nROWS = 1000\nCOLS = 4\n\n# Number of times to run timeit\nTEST_COUNT = 100 \n\n# Matrices\na = numpy.zeros((ROWS, COLS), dtype='uint32')\nb = n...
{ "AcceptedAnswerId": null, "CommentCount": "6", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2012-06-12T16:34:47.097", "Id": "12503", "Score": "2", "Tags": [ "python", "numpy" ], "Title": "Compound assignment operators in Python's NumPy library" }
12503
<p>I have been setting multiple variables like this </p> <pre><code>function doSomething() { var FirstName = $FirstName.data("ov"); var LastName = $LastName.data("ov"); var Company = $Company.data("ov"); var Website = $Website.data("ov"); } </code></pre> <p>I just read some reviewed code and both re...
[]
[ { "body": "<p>There should be no noticeable difference in performance (even if there was, it would most likely be negligible) and they mean the same.</p>\n\n<p>It's just a matter of picking the one that's most readable. Frankly, I don't find the second example more readable than the first, but this is subjectiv...
{ "AcceptedAnswerId": "12509", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-12T20:53:11.807", "Id": "12506", "Score": "2", "Tags": [ "javascript" ], "Title": "How to set multiple variables at once in JavaScript?" }
12506
<p>I have many pages with functions that appear only once, which I am sure is really typical. I read that it's the best idea to use the local scope for functions when possible because the local scope is searched first, thereby making the function found sooner.</p> <p>If I have no intention of reusing a function, is t...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-12T22:58:18.277", "Id": "20162", "Score": "0", "body": "Your examples are likely identical in scope (though there will be some differences: http://stackoverflow.com/questions/1013385/what-is-the-difference-between-a-function-expression...
[ { "body": "<p>Global versus local scope:</p>\n\n<p>It depends on what you are working with. If you are in a framework or the javascript you are using could possibly collide with another javascript then you should localize it. Other than that, if it is a single page site, then there is no need to worry. I try to...
{ "AcceptedAnswerId": "12516", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-12T21:30:46.597", "Id": "12511", "Score": "6", "Tags": [ "javascript" ], "Title": "Should I put a JavaScript function in a local or global scope?" }
12511
<p>Inspired by Don Stewart's article on <a href="https://donsbot.wordpress.com/2010/08/17/practical-haskell/" rel="nofollow">Scripting with Haskell</a> I tried a rewrite of a shell-script I did the other day. I was really astonished how easily it worked but as a whole it is about double the size of my shell script and ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-13T03:23:47.480", "Id": "20164", "Score": "1", "body": "Please do consider adding a unit test suite (HUnit or Quickcheck) for your script, it is a tremendous help when refactoring." } ]
[ { "body": "<p>You have produced rather nice code, so my review is restricted to just the peripherals.</p>\n\n<pre><code>import System.IO (readFile, appendFile)\nimport System.Exit (exitSuccess)\nimport System.Directory (doesFileExist, getHomeDirectory)\nimport Data.Time (getZonedTime)\nim...
{ "AcceptedAnswerId": "12518", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-13T00:14:12.783", "Id": "12515", "Score": "4", "Tags": [ "haskell", "networking", "logging", "curl", "ip-address" ], "Title": "Dynamic IP-address logging" }
12515
<pre><code>#!/bin/bash # Change the environment in which you are currently working. # Actually, it calls the relevant 'lettus.sh' script if [ "${BASH_SOURCE[0]}" == "$0" ]; then echo "Try running this as \". chenv $1\"" exit 0 fi usage(){ echo "Usage: . ${PROG} -- Shows a list of user-selectable en...
[]
[ { "body": "<p>In <code>showEnv</code>, why do you need to check that <code>envList</code> is empty when you define it right in the program?</p>\n\n<p>I'd write the array elements one-per-line with:</p>\n\n<pre><code># Show all elements in array\nfor elem in \"${envList[@]}\"; do \n echo \"$elem\"\ndone\n</co...
{ "AcceptedAnswerId": "12521", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-13T04:27:12.330", "Id": "12520", "Score": "3", "Tags": [ "bash" ], "Title": "Bash arrays and case statements - review my script" }
12520
<p>The goal with this function is to find one DNA sequence within another sequence, with a specified amount of mismatch tolerance. For example:</p> <ul> <li><code>dnasearch('acc','ccc',0)</code> shouldn't find a match, while</li> <li><code>dnasearch('acc','ccc',1)</code> should find one.</li> </ul> <p><strong>EDIT:<...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-13T08:42:02.887", "Id": "20170", "Score": "1", "body": "Do you mean http://en.wikipedia.org/wiki/Levenshtein_distance (insertion, deletion, or substitution of a single character)?" }, { "ContentLicense": "CC BY-SA 3.0", "Cr...
[ { "body": "<p>This is a solved problem in bioinformatics and there are specific algorithms depending on your specific use-case:</p>\n\n<ul>\n<li>Do you allow gaps?</li>\n<li>How many mismatches do gaps incur?</li>\n<li>… etc.</li>\n</ul>\n\n<p>In the general case, this is a <a href=\"http://en.wikipedia.org/wik...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-13T08:19:34.183", "Id": "12522", "Score": "12", "Tags": [ "python", "bioinformatics" ], "Title": "Simple DNA sequence finder w/ mismatch tolerance" }
12522
<p>This is my code for sending mail in HTML format:</p> <pre><code>import java.util.Properties; import javax.mail.Authenticator; import javax.mail.Message; import javax.mail.Message.RecipientType; import javax.mail.MessagingException; import javax.mail.PasswordAuthentication; import javax.mail.Session; import javax.ma...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-13T11:46:52.847", "Id": "20178", "Score": "0", "body": "here is a similar question: http://stackoverflow.com/questions/322298/how-to-send-html-email-to-outlook-from-java" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate...
[ { "body": "<ol>\n<li><p>Try to minimize the scope of local variables. It's not necessary to declare them at the beginning of the method, declare them where they are first used.</p>\n<p>See <em>Effective Java, Second Edition, Item 45: Minimize the scope of local variables</em>. (Google for &quot;minimize the sco...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-13T11:43:47.680", "Id": "12529", "Score": "7", "Tags": [ "java", "email" ], "Title": "Sending HTML-formatted mail in Java" }
12529
<p>I have scoring system where I want to change icon color by changing CSS classes.</p> <p>How can I optimize this jQuery? After testing, I found this the only alternative, but I trust there is a more simplified method.</p> <pre><code>// Count scores $('#bodyScore').text((90 / myarray.length) * bodyScore + '/90'); ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-13T13:38:38.330", "Id": "20182", "Score": "0", "body": "Remove all classes first, then just add the one class in each statement." } ]
[ { "body": "<p>Both the <a href=\"http://api.jquery.com/removeClass/\"><code>removeClass</code></a> and <a href=\"http://api.jquery.com/addClass/\"><code>addClass</code></a> methods will accept a space-separated list of class names to add/remove, and both can be chained.</p>\n\n<p>You can cache the selector so y...
{ "AcceptedAnswerId": "12532", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-13T13:35:52.147", "Id": "12530", "Score": "4", "Tags": [ "javascript", "jquery" ], "Title": "removeClass and addClass optimization in a scoring system" }
12530
<p>I feel like I should not be duplicating the code to gather the credit card number, but I am not sure how best to do it. Any suggestions?</p> <pre><code>$('input[name="payment\[cc_number\]"]').keyup(function() { var ccNum = $(this).val(); ccNum = ccNum.replace(/[^\d]/g, ''); setSelectValue(ccNum); }); $...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-13T13:36:13.677", "Id": "20184", "Score": "1", "body": "There is a [nice jQuery plugin](https://github.com/PawelDecowski/jQuery-CreditCardValidator) to handle credit card validation which might be easier than writing your own." } ]
[ { "body": "<pre><code>$(function() {\n // Always select a context and use it as the second parameter \n // it will make everything far faster and less prone to errors\n var form = $('form'); \n var stripCcNum = function(el) {\n return $(this).val().replace(/[^\\d]/g, '');\n }\n\n $('input[name=\"paym...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2012-06-13T13:32:30.477", "Id": "12538", "Score": "3", "Tags": [ "javascript", "jquery", "validation", "form" ], "Title": "Calling a Luhn check function when a credit card field changes"...
12538
<p>I have written this basic <a href="http://en.wikipedia.org/wiki/Heroes_of_Might_and_Magic_III">Heroes of Might and Magic 3</a> Battle Simulator. I am decent at procedural, C-style code and I am trying to get better at Object Oriented Programming. (I know procedural code be better suited for this problem, but I am ...
[]
[ { "body": "<p>Must say I completely disagree with:</p>\n\n<blockquote>\n <p>I know procedural code be better suited for this problem</p>\n</blockquote>\n\n<p>Global mutable state is bad so I cringe when I see</p>\n\n<pre><code>//Global Variables\n</code></pre>\n\n<p>Fortunately all your global members are cons...
{ "AcceptedAnswerId": "12544", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-13T15:38:29.193", "Id": "12543", "Score": "7", "Tags": [ "c++" ], "Title": "Heroes of Might and Magic 3 battle simulator" }
12543
<p>We are building a interactive tile-based (32x32 px) (game) map where the user can move around. However we experience lag (some sort of a delay on the movement) and we need to work around this problem. The "hack/lag" also happen on a local server so it's not because of the traffic yet. Any suggestions how we can make...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-13T17:01:41.617", "Id": "20200", "Score": "0", "body": "I'll take another look at it in a bit, but maybe this will get you started. Maybe its `ob_start()`. I don't use it myself, mostly because I do not like the way it lets you have HT...
[ { "body": "<p>Besides what I already mentioned about output buffering, I don't really see anything wrong. And I can't prove output buffering is the culprit. You could try escaping the HTML, what I was calling \"PHP injection\" (sorry I had the wrong term) to see if that fixes it, but that would require some rew...
{ "AcceptedAnswerId": null, "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-13T16:35:29.470", "Id": "12545", "Score": "1", "Tags": [ "php", "performance", "mysql", "ajax" ], "Title": "Improve the performance of jquery/php generated map" }
12545
<p>I'm trying to parse addresses out of blocks of text, and have the following expression to do so:</p> <pre><code>/\d+\s(?:[sewnSEWN]\.?\s)?[\d\w]+\s(?:(?:[\d\w]+\s){0,3})?\w+\.?/ </code></pre> <p>It will currently parse addresses such as:</p> <p>300 E. Randolph St. Chicago, IL >> Returns 300 E. Randolph St.</p> <...
[]
[ { "body": "<p>I don't know which implementation you are using, so translate this to relevant language when needed.</p>\n\n<p><code>\\w = [a-zA-Z0-9]</code> so <code>[\\d\\w]</code> is same as <code>[\\w]</code></p>\n\n<p>Note that <code>(?(?:[\\w]+\\s){0,3})?</code> is same as <code>(?:[\\w]+\\s){0,3}</code> be...
{ "AcceptedAnswerId": "12549", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-13T17:44:58.987", "Id": "12548", "Score": "1", "Tags": [ "regex", "search" ], "Title": "Regex Refinement" }
12548
<p>i am new on java and i have not more knowledge about java. please help me for optimizing it as much as possible</p> <pre><code>public void q1(String str, int[] arr) { String local = "findnumber"; for(int i=0; i&lt;arr.length; i++) { if(str.equals(local) &amp;&amp; arr[i] * 2 &gt; 10) { I...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-13T07:43:41.640", "Id": "20221", "Score": "2", "body": "Can u tell that what u r doing in this function so that picture may be more clear." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-13T08:09:13.483", ...
[ { "body": "<p>You can extract the check if str.equals(local) out of the loop. This will safe most of the operations performed in the loop:</p>\n\n<pre><code>public void q1(String str, int[] arr) {\n String local = \"findnumber\";\n boolean string_matches = str.equals(local);\n for(int i=0; i&lt;arr.len...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-13T07:38:13.447", "Id": "12551", "Score": "-3", "Tags": [ "java", "optimization" ], "Title": "java Optimize this function as much as possible" }
12551
<p>Note, I choose not to use the Factory Pattern out of preference.</p> <p>This is a ( M ) odel class in the MVC pattern.</p> <p>Private functions return Booleans and public functions return strings which I then output to the browser from the Controller. The class returns a string from the invoke call. </p> <p>Here...
[]
[ { "body": "<p>Where do I begin?</p>\n\n<p>Simplest first. Make sure you assign your constructor a state (public, private, or protected). Most likely public.</p>\n\n<p>Now... Where are all these extra properties coming from? <code>$ISharedObject</code> is not even remotely similar to anything else, so it isn't a...
{ "AcceptedAnswerId": "12583", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-13T20:02:52.847", "Id": "12560", "Score": "2", "Tags": [ "php" ], "Title": "class MUserNew | Add DRY, remove constants to mysql defaults" }
12560
<p>I usually program in python/javascript and am very new to php. I would appreciate some advice on how to improve the following form script.</p> <p>Since this is for a highly trafficked website, I want it to be extremely secure, reliable and optimized.</p> <p>Feel free to point out minor issues as well.</p> <pre><c...
[]
[ { "body": "<p>I've tried to address as many things as I could think of, though I'm not sure how relevent a lot of them will be :).</p>\n\n<p>Anyway, on a lot of things I just glossed over the subject for brevity, however, if you have any questions or want me to defend any statements, I gladly will if prompted.<...
{ "AcceptedAnswerId": "12571", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-13T20:04:00.013", "Id": "12561", "Score": "2", "Tags": [ "php", "form" ], "Title": "Need help optimizing & improving this php form script" }
12561
<pre><code>import System.Environment (getArgs) import Random main = do args &lt;- getArgs let len = length args let n = if len &lt; 1 then 10000 else read (args !! 0) :: Int let fileName = if len &lt; 2 then show n ++ "-output.txt" else args !! 1 str &lt;- rndStr n writeFile fileName (str) -- writeFile ...
[]
[ { "body": "<p>Congratulations on your progress, :) Welcome to monads</p>\n\n<p>First thing you have to keep in mind is to restrict the time spent in imperative world. So take out as much stuff as you can from the do ..., and refactor them into smaller non-IO code.</p>\n\n<pre><code>import System.Environment (ge...
{ "AcceptedAnswerId": "12567", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-14T03:12:45.253", "Id": "12566", "Score": "1", "Tags": [ "strings", "haskell", "random" ], "Title": "Haskell: rndFile and [Char] vs IO String error" }
12566
<p>I have this if else statement where I don't know how to remove the code duplication</p> <pre><code>if(array_key_exists($key,$cachetable)) { if($cachetable[$key] != $newdata[$key]) { //data existed but is not valid //update the cachetable $cachetable[$key] == $newdata[$key] } } else { //data di...
[]
[ { "body": "<p>Modify the code to this:</p>\n\n<pre><code>//just use the AND operator (&amp;&amp;) to check if it's both existing AND valid\n//use strict comparison (===) whenever possible\nif(array_key_exists($key,$cachetable) &amp;&amp; $cachetable[$key] === $newdata[$key]){\n //data exists and valid\n} els...
{ "AcceptedAnswerId": "12569", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-14T06:46:35.857", "Id": "12568", "Score": "2", "Tags": [ "php", "cache" ], "Title": "Updating or adding data to an associative array as a cache" }
12568
<p>This is a recursive descent parser for simple language with following grammar:<br> PROGRAM &lt;- {STATEMENT ';'}* RETURN_STMT ';'<br> STATEMENT &lt;- NAME_BINDING | TYPE_DECLARATION<br> TYPE_DECLARATION &lt;- named_param identifier<br> NAME_BINDING &lt;- identifier '=' EXPRESSION<br> EXPRESSION &lt;- (simple arithme...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-16T03:20:51.343", "Id": "20363", "Score": "0", "body": "Are your operators all supposed to have equal precedence? I think your code could be made to look much better if a little more order could be placed on `foldExpr`, `exprS`, `expr`...
[ { "body": "<p>A suggested change, </p>\n\n<pre><code>data MyType = TValue | TIdent | TNamedParam\n\ntermX :: MyType -&gt; ParserState -&gt; Result ParserState\ntermX t state = case (t, rest state) of\n (TIdent, Identifier x:xs) -&gt; vstate' x xs\n (TNamedParam, NamedParam x:xs) -&gt; vstate' x xs\n (TValue,...
{ "AcceptedAnswerId": "12611", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-14T07:55:35.617", "Id": "12572", "Score": "2", "Tags": [ "haskell", "parsing" ], "Title": "Language parser in haskell" }
12572
<p>I want to write better code. This is a simple controller class for an administrator login.</p> <p>Are there conventions or tips in PHP to rewrite this code and improve it?</p> <pre><code>&lt;?php class Administrators extends CI_Controller { public function __construct() { parent::__construct(); }...
[]
[ { "body": "<ul>\n<li><p>the very first characters should be <code>&lt;?</code> to avoid whitespace from being sent in the response. This saves you from issues with header redirects. You should also omit the closing <code>?&gt;</code> for the same reason (whitespaces).</p>\n<blockquote>\n<p><a href=\"http://code...
{ "AcceptedAnswerId": "12578", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-14T10:59:19.600", "Id": "12573", "Score": "1", "Tags": [ "php", "performance", "object-oriented", "mvc", "codeigniter" ], "Title": "Controller for an Administrator User, c...
12573
<p>First off, I'm just learning Haskell and I'm not proficient in that language yet.</p> <p>I wrote this Haskell module to look for files in a Linux filesystem. It can use regular expressions as search patterns. I wrote two variants: one of them sends the search results to stdout, the other (shown here) gives a list w...
[]
[ { "body": "<p><code>mapWriterT</code> is for transforming one <code>WriterT</code> into another. Its type is painfully generic, but allows you to transform pretty much everything about a WriterT.</p>\n\n<pre><code>mapWriterT :: (m (a, w) -&gt; n (b, w')) -&gt; WriterT w m a -&gt; WriterT w' n b\n</code></pre>\n...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-14T17:29:00.817", "Id": "12584", "Score": "3", "Tags": [ "haskell" ], "Title": "Can I use mapWriterT instead of mapM/mapM_ (Haskell)?" }
12584
<pre><code>SELECT p.name,m.name FROM parts p INNER JOIN Manufacturers m ON p.man_id=m.id ORDER BY p.name DESC </code></pre> <p>If not, what should be done for its optimization?</p> <p>Here is the two tables:</p> <pre><code>CREATE TABLE `Manufacturers` ( `id` int(11) NOT NULL AUTO_INCREMENT, `name` varchar(30...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-13T15:36:37.700", "Id": "20259", "Score": "3", "body": "Looks fine to me. Just make sure you have indexes on the `parts.man_id` and `Manufacturers.id` fields." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-0...
[ { "body": "<pre><code>CREATE TABLE Manufacturers ( id int(11) NOT NULL AUTO_INCREMENT, \nname varchar(30) NOT NULL, PRIMARY KEY (id) ) ENGINE=InnoDB \n\nCREATE TABLE parts ( id int(11) NOT NULL AUTO_INCREMENT, name varchar(30) NOT NULL, \nman_id int(11) NOT NULL, PRIMARY KEY (id) ) ENGINE=InnoDB\n</code></pre>\...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-13T15:35:48.210", "Id": "12585", "Score": "6", "Tags": [ "optimization", "mysql", "sql" ], "Title": "Has the following query been made in the optimum way?" }
12585
<p>Is there a way to speed up the following python code:</p> <pre><code>auxdict = {0:0} divdict = {} def divisors(n): divisors = [] for i in range(1, int(n**0.5) + 1): if (n % i == 0): divisors.extend([i, n/i]) divisors = list(set(divisors)) divisors.sort() return divisors def...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-14T16:22:19.933", "Id": "20262", "Score": "5", "body": "Um, that first for loop will go over `10 ** 10 / 2` values; even if you could get each call to `aux` down to a millisecond that'd take two months. You'll need a different algorith...
[ { "body": "<p>You can improve your divisors function:</p>\n\n<p><strong>Version 1:</strong> (not includes n)</p>\n\n<pre><code>def divisors(n):\n \"\"\"Return the divisors of n (including 1)\"\"\"\n if(n == 1):\n return (0)\n\n divs = set([1])\n r = floor(sqrt(n))\n if(r**2 == n):\n ...
{ "AcceptedAnswerId": "12588", "CommentCount": "20", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-14T16:19:07.707", "Id": "12587", "Score": "3", "Tags": [ "python" ], "Title": "Speeding up an algorithm for finding the number of distinct lines" }
12587
<p>I am writing my first Android application and have mainly been using code examples online. However, I have been going hard at it for a while now and realize that I have some overlapping methods and such in my code.</p> <p>I have three classes:</p> <ol> <li><code>AndroidBluetooth</code> (main activity)</li> <li><co...
[]
[ { "body": "<p>Things you can do :\n1) First follow a fixed convention to name your functions. Ex: CheckBlueToothState should be checkBlueToothState (notice small case) in your main activity\n2)BluetoothModel is doing lot of other stuff than just being a model. Things like estabilishing the connections should b...
{ "AcceptedAnswerId": "12606", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-14T19:21:32.687", "Id": "12590", "Score": "2", "Tags": [ "java", "android", "bluetooth" ], "Title": "Android Bluetooth device application" }
12590
<p>I denotes independent, no dependencies.</p> <pre><code>&lt;?php /** *Input - One Dimensional Non-Empty Post Array *Ouput - Boolean on pass or fail */ class IText { private $text_array = array(); private $patterns = array( 'domain' =&gt; '/:\/\/(www\.)?(.[^\/:]+)/', 'prefix_url'...
[]
[ { "body": "<p>I've tried to cover as many things I could. A few of my explanations are rather brief, so if you want me to explain or defend anything, let me know. And hopefully it doesn't read too ramble-y :).</p>\n\n<p><strong>IText</strong></p>\n\n<p>IName typically denotes an interface. It's not a naming ...
{ "AcceptedAnswerId": "12595", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-14T20:08:52.943", "Id": "12592", "Score": "0", "Tags": [ "php" ], "Title": "class IText - Validates text from Ajax POST | Add consistent return type, defensive coding, functional focus" }
12592
<p>I had a task for a programmer position which I failed. I am a newbie programmer and I accept that. The only problem is that employer never told me what the actual problem with the code is. So maybe community will be able to give few hints on how to improve it.</p> <p>The task was to write code which would parse a g...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-21T20:22:35.240", "Id": "20799", "Score": "9", "body": "Most \"newbie programmers\" wouldn't be able to write the code that you did. You probably don't want to work for these people anyway! (Unless the job was something other than entr...
[ { "body": "<p>I'm not familiar with Ruby, just a hint: If I'm right the code creates one thread for every <code>img</code> tag which could be too much. For example, the source of yahoo.com contains more than one hundred <code>img</code> tags which means 100+ threads and 100+ connections to the same host. You sh...
{ "AcceptedAnswerId": "12599", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-14T20:42:27.023", "Id": "12593", "Score": "22", "Tags": [ "beginner", "ruby", "parsing", "interview-questions" ], "Title": "Parse webpage and save fetched images to a director...
12593
<p>I have some code here that changes the font size depending on what link you clicked and it works perfectly, I now want to add another feature but need some help. I want to add current font size which changes as you press bigger or smaller.</p> <p>jQuery:</p> <pre><code>$(document).ready(function() { function ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-14T22:35:36.827", "Id": "20312", "Score": "0", "body": "I'm a bit confused on what the post is saying. Is the problem that it doesn't work? Or that you're looking for suggestions on how to improve the code? The code looks like it sh...
[ { "body": "<p>I felt that this code would be good as a jQuery plugin, so I went ahead and altered your code until I was satisfied. I left in some comments that are applicable to your code, but I would encourage someone else (and may do it myself still, I don't know yet) to give an actual review.</p>\n\n<pre><co...
{ "AcceptedAnswerId": "12604", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-14T22:21:58.360", "Id": "12601", "Score": "1", "Tags": [ "javascript", "jquery", "html" ], "Title": "jQuery Font Switcher" }
12601
<p>So I am using the following</p> <pre><code>&lt;?php function LuhnCalc($number) { $chars = array_reverse(str_split($number, 1)); $odd = array_intersect_key($chars, array_fill_keys(range(1, count($chars), 2), null)); $even = array_intersect_key($chars, array_fill_keys(range(0, count($chars), 2), null)); $even...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-17T07:01:11.257", "Id": "20399", "Score": "2", "body": "This may get better traction on StackOverflow where there's a much larger user base. (And this is off topic for CR as CR questions are expected to contain code that currently wor...
[ { "body": "<p>First off, welcome to CodeReview, where your questions may take a while to get answered. Hang in there, we'll get to them. I had to look this up because I've never heard of it before, but my math isn't half bad, so I'm confident in my answer.</p>\n\n<p>Your check numbers are mostly fine. I'd be mo...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-15T02:13:12.170", "Id": "12605", "Score": "2", "Tags": [ "php" ], "Title": "Luhn - bPAY mod10v5" }
12605
<p>I want to realize caching in WCF web service. I'm using the following code:</p> <pre><code>public interface ICache&lt;T&gt; : IDisposable where T : class { string Name { get; } CacheItemPolicy CacheItemPolicy { get; set; } long Count { get; } bool IsDisposed { get; } void...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-22T01:36:33.293", "Id": "20818", "Score": "0", "body": "Are you self-hosting the service or are you using IIS to host the service?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-26T11:51:55.913", "Id":...
[ { "body": "<p>I think you have created an unuseful abstraction. Mostly your methods only calling the underlaying MemoryCache instance and you have created something weird: IDisposable wrapper over a static instance. Of yourse the MemoryCache can be disposed but not this way. You have a service with InstanceCont...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-15T08:38:16.513", "Id": "12610", "Score": "3", "Tags": [ "c#", "cache", "wcf" ], "Title": "caching in WCF web service" }
12610
<p>I wanted to make a class that connects to my server and returns a value, a URL in this case. As Android 4.0 doesn't let me run network task on the main UI thread (rightly so) I have made this.</p> <p>Please give me your feedback as to if it is thread safe or not and ways to improve it. I have never used <code>Execu...
[]
[ { "body": "<p>Your method seems thread safe, but you are blocking <code>getDownloadURL()</code> because <code>task.get()</code> will only return once the underlying job finishes. Try reading up on Java's <code>future</code> and see how you can use them more efficient and correct.</p>\n\n<p>Your executor servic...
{ "AcceptedAnswerId": "12614", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-15T09:40:34.120", "Id": "12613", "Score": "1", "Tags": [ "java", "multithreading", "android", "thread-safety" ], "Title": "Thread Safe Server Querier" }
12613
<p>I have a list view which display in each view a Album's name, the associated Artist and the album art. </p> <p>Here is the code of my <code>ListFragment</code> which display this list:</p> <pre><code>public class AlbumsFragment extends ListFragment implements LoaderManager.LoaderCallbacks&lt;Cursor&gt; { AlbumsAd...
[]
[ { "body": "<p>Your lag will be coming from this line:</p>\n\n<pre><code> Bitmap coverBitmap = BitmapFactory.decodeFile(cursor.getString(holder.column3));\n</code></pre>\n\n<p>Your right about doing it asyncrhonously.\nYou could also scale the image.</p>\n\n<p>What you'll want to do is:</p>\n\n<ul>\n<li>spawn a ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-15T11:10:40.160", "Id": "12615", "Score": "3", "Tags": [ "java", "optimization", "performance", "android", "asynchronous" ], "Title": "Efficient Album Cover loading for ListV...
12615
<p>I have <code>Polygon</code>s on Google Maps API V3, and I would like to write this shorter:</p> <pre><code>var myCoordinates = [ new google.maps.LatLng(52.210722,21.007330), new google.maps.LatLng(52.211695,21.007030), new google.maps.LatLng(52.212707,21.006718), new google.maps.LatL...
[]
[ { "body": "<p>How about:</p>\n\n<pre><code>// Just the raw data ...\nvar myCoordinates = [\n [52.210722, 21.007330],\n [52.212707, 21.006718],\n [52.214166, 21.006246],\n [52.215152, 21.005957],\n [52.215889, 21.005796],\n [52.216986, 21.005442],\n [52.217085, 21.007201],\n [52.217098, 21.007781],\n [5...
{ "AcceptedAnswerId": "12617", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-15T11:20:01.117", "Id": "12616", "Score": "3", "Tags": [ "javascript", "google-maps" ], "Title": "Polygons on Google Maps" }
12616
<p>I am currently writing my first Android application, and am having trouble grasping how to structure it. From my previous programming experience I was planning on using a MVC design but now I don't know if I can implement that. </p> <p>My program consists of several different activities which all need access to a s...
[]
[ { "body": "<p>You should be able to add the instantiated object to your intents. This way, you should be able to access it in other Activities or Services.\nYou might want to investigate on services if you want the app to do something consistently and should be able to get information from the service via inten...
{ "AcceptedAnswerId": "12633", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-15T12:28:56.023", "Id": "12618", "Score": "1", "Tags": [ "java", "android", "bluetooth" ], "Title": "MVC in Android development for Bluetooth application" }
12618
<p>I have learned a little Python for a few projects at work. This is my first <em>finished</em> application and I was hoping someone would take a look at it. I would love some tips on the mistakes I've made.</p> <pre><code>################################################################################ #Monthly Rollo...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-15T19:31:56.883", "Id": "57446", "Score": "1", "body": "you had better change your Database username and password. that is my first review" } ]
[ { "body": "<p>Some really obvious stuff popped up in a casual pylint check over your code. As well as some further, more advanced ideas for changing your code below.</p>\n\n<pre><code>db = QtSql.QSqlDatabase.addDatabase(\"QMYSQL\");\n</code></pre>\n\n<p>The semi-colon is not necessary in python.</p>\n\n<pre><co...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-15T13:47:15.337", "Id": "12619", "Score": "3", "Tags": [ "python", "sql", "mysql" ], "Title": "Monthly rollover system" }
12619
<p>I have two <code>.on()</code> functions for separate dynamically added elements, they are:</p> <pre><code>$('body').on('click', 'img', function() { modal(content[$('li.active a').attr("href")].images[$("img").index(this)]); }); $('body').on('click', 'img', function() { closeM(); }); </code></pre> <p>The seco...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-15T18:23:25.080", "Id": "20352", "Score": "0", "body": "[JsFiddle: example of using selector for event map style of `on` method](http://jsfiddle.net/LU38z/)" } ]
[ { "body": "<p>You could just do both operations inside the anonymous function (that you are sending as third parameter).</p>\n\n<pre><code>$('body').on('click', 'img', function() {\n modal(content[$('li.active a').attr(\"href\")].images[$(\"img\").index(this)]);\n closeM();\n});\n</code></pre>\n\n<p>Also, I...
{ "AcceptedAnswerId": "12621", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-15T16:10:26.617", "Id": "12620", "Score": "0", "Tags": [ "javascript", "jquery" ], "Title": "Consolidate .on function" }
12620
<p>I've created a simple daily task scheduler but I'd like to change this to a general task scheduler accepting more advanced schedules.</p> <p>I'd like to have some critiques from other sets of eyes on my current implementation before I continue.</p> <pre><code>public class ScheduleJob { #region PRIVATE VARIABLE...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-15T21:57:58.577", "Id": "20353", "Score": "1", "body": "How about you start by running StyleCop on this and correcting the problems. This will find lots of stuff for sure." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDa...
[ { "body": "<p>Just a small comment from me. I'm not so sure about the need for the method SetJob(). It seems like there is a requirement for this method to be called before the Start() and once called you wouldn't call it again? </p>\n\n<p>Hence perhaps I might look at moving this to the constructor that wou...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-15T21:04:31.063", "Id": "12625", "Score": "7", "Tags": [ "c#", "scheduled-tasks" ], "Title": "Simple Job Scheduler Class" }
12625
<p>Can this time converter be written more efficiently? I'm new to Java, and I would like to know.</p> <h2>main</h2> <pre><code>import javax.swing.JFrame; public class main { public static void main(String[] args) { window wn = new window(); wn.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); ...
[]
[ { "body": "<pre><code>hours.getText() != null &amp;&amp; minutes.getText() != null\n</code></pre>\n\n<p>You should also assert if the string is empty using method <code>hours.getText().isEmpty()</code></p>\n", "comments": [], "meta_data": { "CommentCount": "0", "ContentLicense": "CC BY-SA 3....
{ "AcceptedAnswerId": "12665", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-15T21:38:54.420", "Id": "12626", "Score": "1", "Tags": [ "java", "beginner", "datetime", "converting" ], "Title": "Time converter in Java" }
12626
<p>I have been using a slightly modified Hamming Distance algorithm for approximate String Matching for patterns and wondering if there is something better out there. The <em>t</em> being the length of the text and <em>p</em> being the length of the pattern the worst case is roughly O(t*p). Which from looking at other ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-16T09:12:06.083", "Id": "20364", "Score": "0", "body": "Please describe your slight modification: Hamming distance is only defined for equal-length strings." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-1...
[ { "body": "<p>It looks fine. Some readability improvements:</p>\n\n<ol>\n<li><p>I'd rename some variables first:</p>\n\n<ul>\n<li><p><code>mismatches</code> should be <code>tolerance</code>, <code>mismatchTolerance</code> or <code>allowedMismatches</code>. For me <code>mismatches</code> sounds like a counter bu...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-16T06:08:30.930", "Id": "12632", "Score": "2", "Tags": [ "java", "strings" ], "Title": "Pattern Matching with Mismatch" }
12632
<p>I created my first Ruby program. Even though it works, I wondered whether I could do something different/better?</p> <pre><code>#!/usr/bin/ruby class LuhnyBinChecker def initialize(number) @number = number end def check createNumberArray doubleSecond sumNumbers getResult end def cre...
[]
[ { "body": "<p>Welcome to ruby :), here are a few changes you might want to consider.</p>\n\n<pre><code>#!/usr/bin/ruby\n\nclass LuhnyBinChecker\n\n def initialize(number)\n @number = number\n end\n</code></pre>\n\n<p>Try to keep your methods pure without i/o, and collect the i/o in some portion that is ded...
{ "AcceptedAnswerId": "12637", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-16T14:10:47.170", "Id": "12634", "Score": "2", "Tags": [ "ruby" ], "Title": "LuhnyBin - my first Ruby script" }
12634
<p>My web application is simply supposed to take a search query, run a script on it that returns product information and then post it in an "endless" fashion on a web page, making one page with no pagination that is "infinitely" scrollable.</p> <p>The web scraper I use, called Fletcher, which helps return usable resul...
[]
[ { "body": "<p>You can't do this without javascript because Rails is a server side language while you should work client side where the language to be used is Javascript.</p>\n\n<p>Basically you should:</p>\n\n<p>1-)Know when an user is near to the bottom of the page</p>\n\n<p>2-)Send an ajax request to the url ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-16T15:15:09.413", "Id": "12635", "Score": "1", "Tags": [ "ruby", "ruby-on-rails", "web-scraping", "pagination" ], "Title": "Infinitely scrolling display of web-scraped search res...
12635
<p>I have been writing a small extension to the <a href="http://www.google.com/recaptcha" rel="nofollow">reCaptcha library</a>.</p> <pre><code>class Captcha { private $config; public $error; public function __construct(array $config) { include './library/recaptchalib.php'; $this-&gt;c...
[]
[ { "body": "<ol>\n<li><p>The <code>$error</code> field should be <code>private</code> (<a href=\"https://stackoverflow.com/questions/1568091/why-use-getters-and-setters\">Why use getters and setters?</a>). Currently users of the <code>Captcha</code> class can modify the value of the <code>$error</code> field dir...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-16T15:32:33.980", "Id": "12636", "Score": "3", "Tags": [ "php", "object-oriented", "captcha" ], "Title": "A small extension to the reCaptcha library" }
12636
<p>I am wondering if anyone has any ideas for improving the following. Personally I am 'happy' with it, apart from the first <code>for</code> loop. I was thinking of another way of writing this, but perhaps it is ok.</p> <pre><code>def findnodepaths(nodepaths, graph, *nodes): # nodepaths == list() # graph == defaul...
[]
[ { "body": "<p>I have no way to test this, but is this what you are looking for?</p>\n\n<pre><code>def findnodepaths(nodepaths, graph, *nodes):\n\n nodeset = set(nodes) &amp; set(graph.keys())\n nodepaths = [(nodeA,weight,nodeB) for nodeA in nodeset\n for (nodeB,weight) in graph[nodeA]]\n\n newnp...
{ "AcceptedAnswerId": "12645", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-16T20:40:44.093", "Id": "12641", "Score": "1", "Tags": [ "python", "pathfinding" ], "Title": "Finding node paths" }
12641
<p>I would appreciate some quick comments on this basic mergesort code. Am I missing a big block in the langage?</p> <h2>First solution</h2> <pre><code>open System open System.Windows open System.Collections.Generic let shuffle (l:'a array) = let ileft = LinkedList&lt;int&gt;(seq { 0 .. (l.Length - 1)}) let r...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-17T05:00:26.343", "Id": "20393", "Score": "1", "body": "I'd put the code that does the split in a separate function. Though something about your merge code rubs me the wrong way." }, { "ContentLicense": "CC BY-SA 3.0", "Cre...
[ { "body": "<p>I'm just learning F# myself, but here is what I currently notice:</p>\n\n<ol>\n<li><p>Your <code>merge</code> function is very large. It should be split into multiple small functions that are responsible for a single action.</p></li>\n<li><p><code>match</code> is preferred to <code>if</code>:</p>...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-16T21:32:28.800", "Id": "12643", "Score": "4", "Tags": [ "sorting", "comparative-review", "f#", "mergesort" ], "Title": "Three implementations of mergesort in F#" }
12643
<p>I've just completed a JavaScript module and I've got a strong feeling that this is borderline spaghetti code. My task was to build a tagging form which adds selected tags to hidden outputs to be sent to a server.</p> <pre><code>var tags = []; var createdTags; var addedTags = []; var isNewTag, selectedTag, i; $("#c...
[]
[ { "body": "<ul>\n<li><code>.attr('value')</code> is bad. Always. You should use <code>.val()</code> instead.</li>\n<li><code>var i;</code> can go into the callback function instead of whatever scope you are in at the very beginning.</li>\n</ul>\n", "comments": [ { "ContentLicense": "CC BY-SA 3...
{ "AcceptedAnswerId": "12655", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-17T00:45:08.840", "Id": "12646", "Score": "2", "Tags": [ "javascript", "beginner", "jquery", "modules", "autocomplete" ], "Title": "Module to support autocomplete for movi...
12646
<p>I have a dynamic form that users can add extra fields too. The group of fields are added and the input name stays the same but gets a incremental number attached to it. So for my insert php file I just check to see if the next value is set and if so it inserts all the required info. But this code doesn't look very '...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-17T02:05:29.677", "Id": "20387", "Score": "3", "body": "Before you think about optimisation it would be a good idea to read up on [SQL injection](http://php.net/manual/en/security.database.sql-injection.php). Your code is wide open to ...
[ { "body": "<p><strong>Array based approach</strong></p>\n\n<p>Instead of appending a number to the field, use an array based approach:</p>\n\n<pre><code>&lt;form action=\"\" method=\"POST\"&gt;\n &lt;b&gt;Product 1&lt;/b&gt;&lt;br\n &lt;label&gt;Product Id &lt;input type=\"text\" name=\"products[0][id]\"&...
{ "AcceptedAnswerId": "12649", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-17T01:56:10.747", "Id": "12647", "Score": "5", "Tags": [ "php", "mysql" ], "Title": "PHP dynamic insert - mysql. Is there a better way than this?" }
12647
<p>This question is always on my mind. I usually alter the array while looping through its keys, based on my gut feelings:</p> <pre><code>foreach (array_keys($array) as $key) { $array[$key] = perform_changes_on($array[$key]); } </code></pre> <p>I'm aware of other methods, though. The array item can be passed by ref...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-06T10:11:40.893", "Id": "70368", "Score": "0", "body": "http://stackoverflow.com/questions/10057671/how-foreach-actually-works is helpful." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2016-12-22T02:11:02.493", ...
[ { "body": "<p>I can't really help you with the performance bit, only tell you to wrap them in <code>microtime()</code> tags and see which one performs better for you. Systems are slightly different. The one suggestion I can give you is to remove <code>array_keys()</code> from your code.</p>\n\n<p><strong>!!UPDA...
{ "AcceptedAnswerId": "12756", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-17T07:16:18.363", "Id": "12652", "Score": "34", "Tags": [ "php", "object-oriented", "array", "php5" ], "Title": "Modifying an array during a foreach loop" }
12652
<p>This is the code I'm using at the moment</p> <pre><code>/* * Adjust content height so that it always fills browser height * * written by Tom Jenkinson */ jQuery(document).ready(function() { refreshContentSize(); //run initially $(window).resize(function() { //run whenever window size changes ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2016-10-08T04:21:14.163", "Id": "269349", "Score": "1", "body": "From my understanding, you're trying to resize the height of your content. What I would use is VH (viewport height) and VW (viewport width) units for the contents container. For ...
[ { "body": "<p>I can't really verify what the code does since when I checked, the filler is always 0px. But I assume your code checks for the surrounding elements in an interval and updates the filler height accordingly. </p>\n\n<p>I have some tips for your code:</p>\n\n<pre><code>//shorthand .ready using the jQ...
{ "AcceptedAnswerId": "12658", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-17T12:01:51.020", "Id": "12656", "Score": "1", "Tags": [ "javascript", "jquery", "html", "html5", "dom" ], "Title": "Detecting when the contents of a web page changes" }
12656
<p>I am playing around with brute force attack on my home network. I wrote the following script with Python. However progress is a little slow. Does anyone have a suggestion how to make this faster?</p> <pre><code>import socket import urllib2, base64 import sys import time def afunction(password_start): #------...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-20T17:44:16.203", "Id": "123124", "Score": "0", "body": "Instead of that nested mess of for-loops, check out [itertools](http://docs.python.org/library/itertools.html) ; I suspect a usage of [.product()](http://docs.python.org/library/...
[ { "body": "<ul>\n<li>move the code that generates passwords and makes connections, retry logic to separate functions</li>\n<li>make multiple requests using the same tcp connection (urllib doesn't support persistent connections, you could use httplib directly instead)</li>\n<li>make multiple connections in para...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-17T14:06:15.117", "Id": "12659", "Score": "3", "Tags": [ "python", "performance", "http", "authentication" ], "Title": "Brute force HTTP with Python" }
12659
<p>I think it is quite OK already, but from a design-pattern perspective, it would be interesting to hear if I have done it right. I'm also interested to know whether the implementation is OK from a best-practice C++ point of view.</p> <p>I made a helper class in order to easily position objects in cocos2d-x. The cli...
[]
[ { "body": "<p>This is kind of a cross between an actual answer, and a really extended comment to @LokiAstari's.</p>\n\n<p>As far as the \"fluent interface\" (I <em>really</em> hate that phrase) goes, I think you need to look at two things: the average case and the worst case. I'd agree with @Loki's statement th...
{ "AcceptedAnswerId": "12684", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-17T15:19:06.120", "Id": "12662", "Score": "2", "Tags": [ "c++", "design-patterns" ], "Title": "Helper class for easily positioning objects in cocos2d-x" }
12662
<p>I'm preparing for an interview so I'm trying to solve some problems to stretch my mind. Here is one:</p> <blockquote> <p>Describe how you could use a single array to implement three stacks.</p> </blockquote> <p>And here is my implementation:</p> <pre><code>class StackUnderflowError extends RuntimeException { ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-08-20T06:47:11.973", "Id": "24117", "Score": "0", "body": "Do not forget to add `break` in your `switch`" } ]
[ { "body": "<p><em>How can I improve this?</em></p>\n\n<p>This question is a rather interesting one. By upping the count of stacks to three, we can no longer be assured of an optimal utilization of the array (for two, each stack could start from one of the ends).</p>\n\n<p>So the problem here is that of optimal ...
{ "AcceptedAnswerId": "12668", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-17T15:51:08.580", "Id": "12663", "Score": "3", "Tags": [ "java", "interview-questions" ], "Title": "Describe how you could use a single array to implement three stacks" }
12663
<pre><code>(define (merge-sort lst (lt? &lt;)) (define (truthy=? a b) (eq? (not a) (not b))) (let sort ((lst lst) (size (length lst)) (flip #f)) (define (merge l r (res '())) (cond ((null? l) (append-reverse r res)) ((null? r) (append-reverse l res)) ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-18T19:53:01.093", "Id": "20569", "Score": "0", "body": "I'm not entirely certain of the protocol here, but are you actually asking a question, or do you just want a general critique?" }, { "ContentLicense": "CC BY-SA 3.0", ...
[ { "body": "<p>Four years, 1400 views, and two dozen upvotes before a review on a site dedicated to code reviews points toward unreviewability as a prominent feature of the code. What hinders reviewability is, I think, the high level of cognitive load the code places on anyone reading it. </p>\n\n<h2>Reading</h2...
{ "AcceptedAnswerId": null, "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-17T18:29:22.890", "Id": "12666", "Score": "26", "Tags": [ "sorting", "scheme", "mergesort" ], "Title": "Merge sort in Scheme" }
12666
<p>This class holds message types that are sent to the client which knows what to do with them. It is basically a small registry pattern where I can consolidate message types. <code>|P|</code> and <code>|F|</code> are read by the client...and I use these for simple data passing when I don't need the complexity of JSON...
[]
[ { "body": "<p>Well, you are doing this a little redundantly...</p>\n\n<pre><code>$keys = array(\n 'name',\n 'email',\n //etc...\n);\n\n$messages = array(\n 'PASS' =&gt; $this-&gt;PASS,\n);\n\nforeach( $keys AS $key ) { $messages[ $key ] = $this-&gt;FAIL . $key; }\n\n$this-&gt;messages = $messages;\n...
{ "AcceptedAnswerId": "12705", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-17T20:59:45.550", "Id": "12669", "Score": "1", "Tags": [ "php" ], "Title": "class IMessge - returns user message types | loop similar items" }
12669
<p>I have a file with an specific format. It's divided in stripes of 1058816 bytes:</p> <ul> <li>4096 bytes with only a 64 bit unsigned integer.</li> <li>An array of 512 64 bit unsigned integer.</li> <li>An array of 512 32 bit unsigned integer.</li> <li>An array of 512 elements with 2048 bytes each one.</li> </ul> <p...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-16T02:28:28.717", "Id": "20448", "Score": "0", "body": "@user315052 Sorry, my example is broken, I'll fix it." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-16T02:33:03.397", "Id": "20449", "Score"...
[ { "body": "<p>Placement <code>new</code> is probably the way to go, but you're invoking undefined behaviour because your data buffers may have a different alignment than what you create with placement <code>new</code> and force in there.</p>\n\n<p>By using these sort of members:</p>\n\n<pre><code>class Stripe {...
{ "AcceptedAnswerId": "12676", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-16T02:02:32.027", "Id": "12674", "Score": "2", "Tags": [ "c++" ], "Title": "Writing structured file in C++" }
12674
<p>I am trying to use jQuery to make calculations with a table containing football data. Can I improve what I have done here? Is my code well-structured and executed, or does it need improvements?</p> <p><a href="http://jsfiddle.net/userdude/kCanv/" rel="nofollow">http://jsfiddle.net/userdude/kCanv/</a></p> <p><stron...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-18T06:07:39.347", "Id": "20466", "Score": "3", "body": "You need to use classes where you've got all of those `id`s being repetitively called. If you use a class, you can use DOM traversal techniques like `$.siblings('.summary_w_d')` i...
[ { "body": "<p>If you see lines that look awfully similar in your code, usually it's a strong smell and cry for some refactoring. Much of your code could be generalize to be handled by a few helper functions.</p>\n\n<p>Also, using some arrays (or other data structures) to list the elements to watch and modify, y...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-18T04:03:07.287", "Id": "12679", "Score": "2", "Tags": [ "javascript", "jquery", "html", "css" ], "Title": "Calculations with a table containing football data" }
12679
<p>Please review the following code and list all the coding errors and poor coding practices that you can see in this code.</p> <pre><code>function output() { // Check authorization if(is_authorized()) { $authorized = true; include('/path/to/' . $_REQUEST['module'] . '.php'); } echo...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-18T04:55:30.047", "Id": "20451", "Score": "0", "body": "Will post a proper answer later, but a few things jump out at me. Namely, SQL injection, your `include` is open to cross directory including, you don't check that any of the keys...
[ { "body": "<ul>\n<li>magic strings,</li>\n<li>DB connection not closed,</li>\n<li>DB errors not handled,</li>\n<li>no prepared statements with safe query parameters,</li>\n<li>injectable request and query parameters,</li>\n<li>mix of UI and logic code,</li>\n<li>no HTML encoding,</li>\n<li>2 of the 3 comments a...
{ "AcceptedAnswerId": "12926", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-18T04:44:13.587", "Id": "12680", "Score": "3", "Tags": [ "php", "mysql", "security" ], "Title": "Database output function" }
12680