body
stringlengths
25
86.7k
comments
list
answers
list
meta_data
dict
question_id
stringlengths
1
6
<p>I have this messy helper method:</p> <pre><code>def gesture(klass, item, text, desc) element_class = klass.to_s + " gesture" content_tag :li do if klass == :sell link_to new_reply_path(item_id: item.id), title: desc, data: {qtip: desc}, class: element_class do content_tag(:div, nil, class: e...
[]
[ { "body": "<p>I'd write:</p>\n\n<pre><code>def gesture(klass, item, text, desc)\n element_class = [klass.to_s, \"gesture\"]\n url = case klass\n when :sell\n new_reply_path(item_id: item.id)\n when :alternative\n new_reply_path(item_id: item.id, alternative: true)\n when :join\n new_item_affiliati...
{ "AcceptedAnswerId": "23267", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-28T10:45:33.183", "Id": "23257", "Score": "2", "Tags": [ "ruby", "ruby-on-rails" ], "Title": "Rails helper method refactor" }
23257
<p>I came up with <a href="http://ideone.com/a8hcbp" rel="nofollow noreferrer">this code</a> whilst answering <a href="https://stackoverflow.com/q/15124432/1084416">this question</a>.</p> <p>Is there a simpler way of doing this using standard library?</p> <p>I want to iterate over every object and do something with e...
[]
[ { "body": "<p>It would be possible to write as <code>for_each</code> call to a functor writing <code>for_each</code> again, but I don't think it would actually be shorter.</p>\n\n<p>I don't think <code>pair_wise</code> is a good name. There are two many things that it could mean. I'd suggest something with <cod...
{ "AcceptedAnswerId": "23287", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-28T11:50:11.763", "Id": "23262", "Score": "10", "Tags": [ "c++", "algorithm", "library" ], "Title": "Using standard library to simplify pairwise iteration of container values" }
23262
<p>I put the full code at the rear of this post. </p> <p>I've recently answered a question, and the detail explanation is posted in </p> <ul> <li><a href="https://stackoverflow.com/questions/15051660/physical-disk-size-not-correct-ioctldiskgetdrivegeometry">Physical disk size not correct (IoCtlDiskGetDriveGeometry)</...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-28T18:17:55.887", "Id": "35883", "Score": "2", "body": "I like what you have. It is much cleaner than what I did. I'm usually not a fan of recreating C++ names match in C# (since they are different languages) but it makes sense in this...
[ { "body": "<p>As most people in the comments suggest, it is missing a few conventions that are pretty generally accepting across all C# developers. This will mostly be looking at stylistic points as there isn't really much in wrong with the implementation.</p>\n\n<p><strong>General notes</strong></p>\n\n<p>Most...
{ "AcceptedAnswerId": "23528", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-28T11:53:21.463", "Id": "23264", "Score": "6", "Tags": [ "c#" ], "Title": "Expecting working sample of DeviceIoControl reviewed" }
23264
<p>I had developed an application in which I hit several URLs and show data on mobile. But the problem is that it requires more time. If I check the same URL on Firebug tool I get a response in 2-3 seconds, but the same URL requires 8-15 seconds on mobile. In my Android application I am using HTTP get and post method ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-28T13:54:37.347", "Id": "35874", "Score": "0", "body": "Without inspecting the code: Could it be that your mobile is slower in bandwidth and hardware processing power?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate":...
[ { "body": "<p>I personally haven't used anything HTTP-related in Java yet, and thus can't talk about your performance. What I can see though is the following code:</p>\n\n<pre><code>if(protocol.startsWith(\"https\"){\n securedConnection = true;\n} else {\n securedConnection = false;\n}\n</code></pre>\n\n<...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-28T13:04:48.287", "Id": "23266", "Score": "4", "Tags": [ "java", "android", "http", "https" ], "Title": "HTTP Get & Post code with slow performance" }
23266
<p>Should the equals sign be alined on protocol buffers? I am having a huge discussion with a colleague and we can't get to decide on what's the best practice.</p> <pre><code>message foobar { optional bool var_one_short = 1; optional bool var_two_looooooooong_name = 2; optional bool another_var...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-07-02T13:39:43.303", "Id": "98125", "Score": "0", "body": "This question appears to be off-topic because it is about formatting data, not code (although code can be generated *from* a .proto file, the .proto file itself doesn't contain an...
[ { "body": "<p>I like more the first solution because it visually groups together the variables on the left side of the <code>=</code> and the value on the right side.\nUnfortunately I can't back this preference with a strong reason other than personal taste.</p>\n\n<p>In your situation I'd struggle for uniformi...
{ "AcceptedAnswerId": "23273", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-28T15:09:42.520", "Id": "23270", "Score": "7", "Tags": [ "protocol-buffers" ], "Title": "Aligning '=' on protocol buffers .proto files" }
23270
<p>I posted this on SO and would appreciate any ideas on it's stability.</p> <p>Much like the old double-buffering algorithm, this uses a <code>List&lt;T&gt;</code> to which are added entries. You can also take the list at any time, it will be atomically replaced with a new empty one.</p> <p>Both adding and removing ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-28T19:01:00.927", "Id": "35888", "Score": "0", "body": "What is the specification of a Double Buffered List? I did not find a clear reference for this." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-28T19:...
[ { "body": "<p>Old question, new review.... I think, in general, I don't believe you are actually building anything better than what can be done with regular locking..... let me rephrase that to: the risk of spin-looping during an add is a significant drawback over regularly locked systems.</p>\n\n<p>So, while A...
{ "AcceptedAnswerId": "35808", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-28T16:26:10.117", "Id": "23275", "Score": "3", "Tags": [ "java", "lock-free" ], "Title": "Lock-free DoubleBufferedList" }
23275
<p>I have some code that needs to update 2 separate databases with user credentials. The first database, I just use standard sql to do it. The second database, I have to use command line scripts to update a specific table. What I'm worried about is what to do if the first update fails, or if any of the updates fail....
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-28T16:31:36.620", "Id": "23276", "Score": "3", "Tags": [ "lua" ], "Title": "How can i make this code more robust, fail proof?" }
23276
<p>I am trying to grab the ffprobe values from the video file into a variable that I can compare against others or move the value into a database. The question I have; Is there a better way of doing it than below?</p> <p>I don't like the multiple if/elif/line.startswith statements and I am not sure of split is the bes...
[]
[ { "body": "<pre><code>#!/usr/bin/python\nimport os, sys, subprocess, shlex, re, fnmatch\nfrom subprocess import call \n\nvideoDrop_dir=\"/mnt/VoigtKampff/Temp/_Jonatha/test_drop\"\n</code></pre>\n\n<p>Python convention is to ALL_CAPS for global constants</p>\n\n<pre><code>for r,d,f in os.walk(videoDrop_dir):\n<...
{ "AcceptedAnswerId": "23278", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-28T16:56:14.337", "Id": "23277", "Score": "3", "Tags": [ "python" ], "Title": "Trying to get output of ffprobe into variable" }
23277
<p>Trying to implement a deep-iteration function with some constraints, I've noticed the faster solution is iterating it twice! Any attempt to avoid this resulted in slower code. So, the challenge: can you redesign the function below removing the code duplicate and doubled iteration, without making it slower?</p> <p>C...
[]
[ { "body": "<p>Let me start by asking how would you like to iterate over your object? Because what you are doing is not the same as calling a function for every property of an object.</p>\n\n<blockquote>\n<pre><code>function iter(obj,fn,iter_pos){\n var ret, iter_pos = iter_pos || [];\n for (var i=0; i&lt;...
{ "AcceptedAnswerId": "23292", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-28T18:24:36.770", "Id": "23280", "Score": "6", "Tags": [ "javascript", "optimization", "algorithm", "design-patterns" ], "Title": "Challenge: solution for this deep-iteration ...
23280
<p>The code realizes producer/consumer problem with multiple producers and consumers. Have this code any potential deadlock or races?</p> <pre><code>//RandomDataProvider.cs namespace MyNamespace.Core { using System; /// &lt;summary&gt; /// Provides randomly generated data. /// &lt;/summary&gt; pu...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-28T18:50:51.570", "Id": "35886", "Score": "0", "body": "What .NET framework do you use?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-28T19:21:10.927", "Id": "35890", "Score": "0", "body": "@a...
[ { "body": "<p>The main issue in this code is that several classes rely on each other's proper behaviour in order to work correctly. I'm talking about sharing the instance of <code>Queue&lt;int&gt;</code> and requirement for proper locking on it in all places. See remarks to <a href=\"http://msdn.microsoft.com/e...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-28T18:46:10.763", "Id": "23281", "Score": "2", "Tags": [ "c#", "multithreading", "synchronization", "producer-consumer" ], "Title": "Producer/Consumer with some limitations" }
23281
<p>The facade pattern is used to abstract adding events. Should support IE5+ as stands.</p> <p>Looking for minor improvements. Don't need to support prior to IE5.</p> <p>I choose not to use a library.</p> <pre><code>/*addEL ** dependencies - none ** browser - IE5+ ** notes - improved per answer */ NS.addEL = (...
[]
[ { "body": "<ul>\n<li><p>Why does binding have parameters? The closure isn't passing any.</p></li>\n<li><p>As far as I know, 75% of browsers (including IE9+) actually support <code>addEventListener</code>. If you check for <code>attachEvent</code> first, you are wasting that 75% assurance. Instead, check for <co...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-28T19:27:23.820", "Id": "23282", "Score": "3", "Tags": [ "javascript" ], "Title": "addEventListener - v0" }
23282
<p>*Originally posted this on stackoverflow but was told that it would be better suited here. </p> <p>So I'm looking for a better way to setup how an application talks with a database. I'm sure this question has been asked many times, and I dug through a few of the similar ones but couldn't find one that really flushe...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-28T20:34:18.183", "Id": "35896", "Score": "0", "body": "You code does look clean on the surface but does suffer from a copy-paste problem. In the past I have written my own ORM-ish classes on top of an ODBC layer. I would gladly not ha...
[ { "body": "<p>It seems that you are looking for <a href=\"http://en.wikipedia.org/wiki/Object-relational_mapping\">object-relational mapping</a> (ORM) framework. ORM framework is a recommended way to talk to the database. There are several frameworks out there including most known <a href=\"http://msdn.microsof...
{ "AcceptedAnswerId": "23360", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-28T20:09:21.517", "Id": "23283", "Score": "2", "Tags": [ "c#", ".net", "sql" ], "Title": "Improving the way a C# application communicates with a SQL database (Via SqlConnection)" ...
23283
<p>I have recently implemented my SQLite helper class that supports SQLite in a memory class to be opened to not to be lost. Please review it and tell me if there is a coding problem and tell me what to do to prevent\fix it.</p> <pre><code>using System; using System.Collections.Generic; using System.Data; using System...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-28T20:56:50.047", "Id": "35899", "Score": "1", "body": "`throw new Exception(e.Message);` is just bad. I no longer have Visual Studio, so I cannot list all of the problems. You do have a few." }, { "ContentLicense": "CC BY-SA 3...
[ { "body": "<p>In <code>Dispose()</code>:</p>\n\n<ol>\n<li>You are calling <code>GC.Collect()</code> which isn't necessarily need unless it is very important to collect all inaccessible memory when disposing.</li>\n<li><code>GC.SuppressFinalize(this)</code> isn't need because the class don't have a finalizer/dec...
{ "AcceptedAnswerId": null, "CommentCount": "9", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-28T20:42:05.087", "Id": "23284", "Score": "3", "Tags": [ "c#", "sqlite" ], "Title": "SQLite helper class" }
23284
<p>I'm going to have a lot of integer values, and at any value change I might need to update any number of UI elements, other values which are computed from the first ones, etc. Sounds like time for the Visitor pattern, but I'm new to Java (more comfortable in C++). I have:</p> <pre><code>import java.lang.ref.WeakRe...
[]
[ { "body": "<p><strong>Addressing your specific questions</strong></p>\n\n<blockquote>\n <ul>\n <li>Is this a good and correct way to use WeakReferences, or is there a simpler way? I don't want the Value to prevent its listeners from getting cleaned up, or to manually break links when a listener is no longer n...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-28T21:59:31.163", "Id": "23288", "Score": "2", "Tags": [ "java", "design-patterns", "weak-references" ], "Title": "Observer pattern in Java" }
23288
<p>I am working on a multithreaded project in which each thread will <code>randomly find columns for that table</code> and I will be using those columns in my <code>SELECT sql query</code> and then I will be executing that SELECT sql query. AFter exectuing that query, I will be looping through the result set and will a...
[]
[ { "body": "<p>I am not that familiar with JDBC, but I think the method you search for is: <a href=\"http://docs.oracle.com/javase/7/docs/api/java/sql/ResultSet.html#isBeforeFirst%28%29\" rel=\"nofollow\">isBeforeFirst</a>: \"true if the cursor is before the first row; false if the cursor is at any other positio...
{ "AcceptedAnswerId": "23326", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-01T02:30:37.170", "Id": "23293", "Score": "1", "Tags": [ "java", "optimization", "multithreading" ], "Title": "Looping through the ResultSet efficiently and the add the values for...
23293
<p>I am tring to <code>count</code> the number of <code>exceptions</code> happening and log those <code>exceptions</code> as well. So what I did is, I created one method <code>addException</code> in which I am counting all the exceptions. </p> <p><code>addException</code> method accepts two parameters, <code>one is th...
[]
[ { "body": "<blockquote>\n <p>Is there any more cleaner way of doing the same thing? Meaning right now I am counting the exceptions in a method and then printing out the exceptions in the next line inside the catch block. \n Is it possible to do the both of the things in the same addException method?</p>\n</bl...
{ "AcceptedAnswerId": "23325", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-01T05:20:10.977", "Id": "23296", "Score": "1", "Tags": [ "java", "multithreading" ], "Title": "Log and Count the exception in a Single method" }
23296
<p>This question was put forward by my senior to draw a hollow rectangle in C#, and with the condition that the rows and column would be specified by the user. I was stuck at first, but tried to code and after several hours I realized how it would be done, and then I accomplished the task.</p> <p>I would like to share...
[]
[ { "body": "<pre><code> static void DrawLine(int w, char ends, char mids)\n {\n Console.Write(ends);\n for (int i = 1 ; i &lt; w-1 ; ++i)\n Console.Write(mids);\n Console.WriteLine(ends);\n }\n\n static void DrawBox(int w, int h)\n {\n DrawLine(w, '*', '*');\...
{ "AcceptedAnswerId": "23299", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-01T05:41:41.690", "Id": "23298", "Score": "3", "Tags": [ "c#", "console" ], "Title": "Drawing a hollow rectangle of rows and column provided by the console application" }
23298
<p>I'm new to PHP and I would like to redirect the visitors of my website based on their operating system. Below is my solution. Is there anything that needs to be optimized?</p> <pre><code>&lt;?php // MOBILE $android = strpos($_SERVER['HTTP_USER_AGENT'],"Android"); $blackberry = strpos($_SERVER['HTTP_USE...
[]
[ { "body": "<p>Before anything, I'll let you search on the web why this might not be such a good idea and I'll just focus on the code.</p>\n\n<ul>\n<li>You probably should retrieve <code>$_SERVER['HTTP_USER_AGENT']</code> and store it in a variable in order to avoid repeated code. Also, you might want to check i...
{ "AcceptedAnswerId": "23307", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-01T12:20:17.967", "Id": "23306", "Score": "1", "Tags": [ "php", "optimization" ], "Title": "PHP - Redirect based on OS optimization" }
23306
<p>I wrote something to the effect of a <code>try</code> <code>catch</code> <code>finally</code> statement helper in functional style so that I can shorten much of the code I'm writing for my Service Layer that connects to an SQL database.</p> <p>Because of that, I found myself needing to code up a lot of <code>try</c...
[]
[ { "body": "<p>There are some smaller issues in your code, which I will mention later. But the main issue I see is that it's quite useless, since it doesn't make your code any shorter.</p>\n\n<p>If you compare:</p>\n\n<pre><code>try\n{\n /* some code */\n}\ncatch (SomeException ex)\n{\n /* more code */\n}\...
{ "AcceptedAnswerId": "23327", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-01T14:51:57.853", "Id": "23310", "Score": "7", "Tags": [ "c#", "functional-programming", "error-handling" ], "Title": "Functional exception handling with TryCatchFinally statement...
23310
<p>A console is an interactive text-mode or text-based user interface to a software application or operating system. It may be implemented as a character-mode application or embedded in a graphical user interface. </p> <p>It may be used as the main user interface or as a secondary interface for debugging and administr...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-01T15:01:47.980", "Id": "23314", "Score": "0", "Tags": null, "Title": null }
23314
A mechanism for interacting with a computer operating system or software by typing commands to perform specific tasks.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-01T15:01:47.980", "Id": "23315", "Score": "0", "Tags": null, "Title": null }
23315
<p>I have three sliders with different min, max values, everything is working fine from following the tutorials on the jQuery UI website.</p> <pre><code>$("#yield").slider({ range: true, min: 15.2, max: 308, step: 0.3, values: [75.8, 241.4], slide: function (event, ui) { $("#yield-valu...
[]
[ { "body": "<p>When you have code that repeats itself like that, you want to try and separate the logic from the values. Something like this would work, and you just have to add more to the settings object when needed. It's not jQuery that's badly written, you just have to change the way you're using it. <a href...
{ "AcceptedAnswerId": "23322", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-01T15:12:40.347", "Id": "23316", "Score": "4", "Tags": [ "javascript", "jquery", "jquery-ui" ], "Title": "Multi jQuery Sliders, Help me write this in better code" }
23316
<p>By <code>browser unknown</code>, i mean i don't know how far back support goes for this.</p> <p>Also, I'm wondering when I can delegate to typeof.</p> <p>I've heard typeof is faster but the method below is more widely supported and also mentioned in ES5. </p> <pre><code>/*isType ** dependencies - none ** browse...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-16T21:52:58.437", "Id": "37006", "Score": "0", "body": "http://jsperf.com/constructor-vs-typeof-vs-tostring" } ]
[ { "body": "<p>I think you can run into issues when checking arrays across frames in IE 7 and older, so if you want to make it accurate for that case, check out <a href=\"https://stackoverflow.com/a/4029057\">this answer on StackOverflow</a>.</p>\n", "comments": [], "meta_data": { "CommentCount": "...
{ "AcceptedAnswerId": "23329", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-01T15:45:26.073", "Id": "23317", "Score": "2", "Tags": [ "javascript" ], "Title": "isType(obj) / getType(obj) - v0" }
23317
<p>I've coded this function where you read all text file in a directory and you save in a temporary file all values. The text files are <code>x</code>, <code>y</code> and <code>z</code> format. The function returns </p> <ul> <li>the name of the temporary file</li> <li>the bounding box</li> <li>the origin (top-left cor...
[]
[ { "body": "<p>Without going into implementation details, I would suggest looking into the following performance optimisations.</p>\n\n<ol>\n<li>Use buffered reads. If you actually read a line at the time it's pretty time consuming.</li>\n<li>Use buffered writes. Instead of writing each new line, collect in a bu...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-01T15:52:54.100", "Id": "23318", "Score": "3", "Tags": [ "python", "optimization" ], "Title": "Merge all text files in a directory and save a temp file" }
23318
<p>My main method (<code>remove-random-edge</code>) looks quite difficult to read. I'm new to list, so would appreciate <em>any</em> advice on how to improve the code.</p> <pre><code>(defun find-node (node graph) (find-if #'(lambda (i) (eql node (first i))) graph)) ;; Input, graph, is in form ((from-1 to-1 to-2 to-...
[]
[ { "body": "<h2>Superficial</h2>\n\n<p>Your <code>find-node</code> is actually (almost) <a href=\"http://www.lispworks.com/documentation/HyperSpec/Body/f_assocc.htm\" rel=\"nofollow\"><code>assoc</code></a> or, if you prefer, <code>(find node graph :key #'first)</code>.</p>\n\n<p>Use <a href=\"http://www.lispwor...
{ "AcceptedAnswerId": "23342", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-01T16:11:09.943", "Id": "23320", "Score": "2", "Tags": [ "lisp", "common-lisp" ], "Title": "How to improve readability of a big lisp function" }
23320
<p>I made my first script of MySQLi. I have just learnt it from 3rd party website. So, I am not sure I am using functions which are not deprecated or outdated. I should start to practice good scripts to access databases. So, I have posted here. Any mistake you see, please point it out.</p> <pre><code>&lt;?php include...
[]
[ { "body": "<p>mysqli is somewhat outdated, you should see PDO that is much better both with security and database support (12 drivers vs. 1).</p>\n\n<p>You can see here details of mysqli vs. PDO: <a href=\"http://net.tutsplus.com/tutorials/php/pdo-vs-mysqli-which-should-you-use/\" rel=\"nofollow\">http://net.tu...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2013-03-01T16:18:32.143", "Id": "23321", "Score": "1", "Tags": [ "beginner", "php", "mysqli" ], "Title": "MySQLi script to print the name of a user" }
23321
<p>I'm implementing a checkers engine for a scientific experiment. I found out through profiling that this is one of the functions that takes up a lot of time. I'm not looking for an in-depth analysis, because I don't expect you to dive super deep into my code.</p> <p>Just: <strong>are there any obvious inefficiencies...
[]
[ { "body": "<p>A couple of little things that caught my eye:</p>\n\n<p>You could simplify this</p>\n\n<pre><code>dist = 1 \nwhile True:\n jx, jy = px + dist * dx, py + dist * dy \n dist += 1\n</code></pre>\n\n<p>to this:</p>\n\n<pre><code>jx, jy = px, py\nwhile True:\n jx += dx\n jy += dy\n</code></p...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-01T16:31:35.090", "Id": "23323", "Score": "3", "Tags": [ "python", "recursion", "generator", "checkers-draughts" ], "Title": "Efficiency of Recursive Checkers Legal Move Generato...
23323
<p>I made a Python function that takes an XML file as a parameter and returns a JSON. My goal is to convert some XML get from an old API to convert into Restful API.</p> <p>This function works, but it is really ugly. I try to clean everything, without success.</p> <p>Here are my tests:</p> <pre class="lang-python pr...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-06T19:07:29.333", "Id": "36326", "Score": "0", "body": "Could you explain the intent, and add some comments?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-11T14:33:47.853", "Id": "36596", "Score":...
[ { "body": "<p>There is a structural issue with your code: the recursive function works at two levels. 1) It constructs a dict representing a node, and 2) it does some work in constructing the representation for the children. This makes it unnecessarily complicated. Instead, the function should focus on handling...
{ "AcceptedAnswerId": "23551", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-01T16:36:00.630", "Id": "23324", "Score": "5", "Tags": [ "python", "unit-testing", "xml", "json", "recursion" ], "Title": "Recursive XML2JSON parser" }
23324
Constants in programming are definitions whose value is fixed throughout a program's execution. Literals in most languages are constants, for example. In referentially transparent programming styles, all definitions are constant.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-01T18:10:09.720", "Id": "23332", "Score": "0", "Tags": null, "Title": null }
23332
<p>I have a text file with lines that look like this:</p> <pre><code>Robot(479.30432416307934|98.90610653676828) Robot(186.42081184420528|213.11277688981409) Robot(86.80794277768825|412.1359734884495) </code></pre> <p>or, more general:</p> <pre><code>Robot(DOUBLE|DOUBLE) </code></pre> <p>How should I parse it in Ja...
[]
[ { "body": "<p>I would suggest the use of parethensis to store these values:</p>\n\n<pre><code>String regexp = \"Robot\\((\\d+\\.\\d+)|(\\d+\\.\\d+))\";\n\nPattern pattern = Pattern.compile(regexp);\nMatcher m1 = pattern.match(line);\n\nwhile (m1.find()) {\n final int count = m1.groupCount();\n // group 0 ...
{ "AcceptedAnswerId": "23336", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-01T18:13:20.143", "Id": "23333", "Score": "1", "Tags": [ "java", "parsing", "regex" ], "Title": "How should I read coordinates from a text file?" }
23333
<p>This my 3rd question on the same exercise, but by no means a duplicate. The two previous questions were posted on <strong>StackOverflow</strong> <a href="https://stackoverflow.com/questions/15100254/sql-query-for-time-intervals-syntax-errors">here</a> and <a href="https://stackoverflow.com/questions/15123351/oracle...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-01T22:00:09.840", "Id": "35968", "Score": "0", "body": "Always put your units. Never reference columns numerically, always do it by name (this saves you from re-ordered columns in the select surprising you). Recent versions of Oracle...
[ { "body": "<ul>\n<li><p>You have a bug. Change the row <code>('u3', 100, 500, 125)</code> to <code>('u3', 99, 500, 125)</code>, and try again. You will see that <code>u3</code> row disappears.</p>\n\n<p>You can fix it with the following minimal change:</p>\n\n<pre><code>rm.reading_time = (SELECT MAX(r2.reading_...
{ "AcceptedAnswerId": "23377", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-01T21:03:40.540", "Id": "23341", "Score": "3", "Tags": [ "sql", "oracle" ], "Title": "Self Join Exercise. Have I over-complicated it?" }
23341
<p>Question</p> <blockquote> <p>Given a binary search tree, design an algorithm which creates a linked list of all the nodes at each depth (eg, if you have a tree with depth D, you’ll have D linked lists)</p> </blockquote> <p>Here is my attempt at a solution. I haven't test it, but I was trying to get feedback on w...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-01T22:32:36.163", "Id": "35970", "Score": "9", "body": "`I haven't test it` then do it." } ]
[ { "body": "<p>Your return types and the types left of the assignments should be as general as possible, so you only need to change the instantiation if you want to change the implementation to an other type of list.</p>\n\n<pre><code>List&lt;Node&gt; \nList&lt;List&lt;Node&gt;&gt;\n</code></pre>\n\n<p>In genera...
{ "AcceptedAnswerId": "38216", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-01T21:23:52.547", "Id": "23343", "Score": "2", "Tags": [ "java", "algorithm" ], "Title": "Creating an Array of Linked Lists from a BST" }
23343
<p>I have a list of boxes, and wish to group them into unconnected sets of overlapping boxes. (Note that two boxes A and B may not overlap each other, but if they are both overlapped by a box C, they will still be grouped together).</p> <p>The following works ok, but I feel like it could be made a lot more concise wit...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-01T23:33:03.650", "Id": "35975", "Score": "3", "body": "Can you please add the `Box` implementation, and maybe a few examples of input and expected output? This could be quite helpful." }, { "ContentLicense": "CC BY-SA 3.0", ...
[ { "body": "<p>I've made a first attempt at shortening and simplifying the code with LINQ. First, I created a helper method for moving items from one <code>List</code> to another based on this <a href=\"https://stackoverflow.com/a/1029297/116614\">StackOverflow question</a>.</p>\n\n<pre><code>private int MoveIt...
{ "AcceptedAnswerId": "23348", "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-01T23:22:59.360", "Id": "23347", "Score": "3", "Tags": [ "c#", "algorithm", "linq" ], "Title": "Finding unconnected sets" }
23347
<p>I want to create a program(in Java) which simulates the functionality of Arithmetic Logistic Unit(ALU). </p> <p>Here is my code. Please check is this correct. Can I implement it better? </p> <pre><code> public class ALU { public static final int NOP = 0; public static final int SEQ = 1; public st...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-05T12:35:39.587", "Id": "36224", "Score": "0", "body": "Please consider using a BitSet. It is provided by Java and you can abstract from all of this booleans. Then, you should only work with universal gates. For example, a NAND is univ...
[ { "body": "<ol>\n<li>Enum might be the real solution to define the different possible operations.</li>\n<li>The implementation of the XOR method could be more concise :\n<code>private boolean XOR(boolean src1,boolean src2){ return (src1 != src2 );}</code> and you probably don't need it anyway because Java has a...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-02T09:08:33.360", "Id": "23352", "Score": "3", "Tags": [ "java" ], "Title": "Simulating ALU in java" }
23352
<p>I wrote a tail-recursive list-flattening function, but I'm not too happy with it.</p> <p>a) Is tail-recursion necessary here, or will the function be optimized without it?<br> b) It's ugly how many clauses there are, and that I have to call out to <code>flatten</code> in the expression of the first clause of <code>...
[]
[ { "body": "<p>Little smaller than yours.</p>\n\n<pre><code>% flatten a list\nmy_flatten([])-&gt;\n [] ;\nmy_flatten([[]|T])-&gt;\n my_flatten(T);\nmy_flatten([[H|T]|T2])-&gt;\n my_flatten([H|[T|T2]]);\nmy_flatten([H|T])-&gt;\n [H|my_flatten(T)].\n</code></pre>\n\n<p><a href=\"http://erlang99.wordpre...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-02T10:07:13.633", "Id": "23354", "Score": "1", "Tags": [ "functional-programming", "recursion", "erlang" ], "Title": "List-flattening function in erlang feels too wordy" }
23354
Git is an open-source DVCS (Distributed Version Control System).
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-02T11:59:27.170", "Id": "23356", "Score": "0", "Tags": null, "Title": null }
23356
<p>This question is about code style.</p> <p>I have this line in one of my models:</p> <pre><code>has_many :owning_artists, :through =&gt; :artist_tracks, :source =&gt; :artist, :conditions =&gt; { :artist_tracks =&gt; { :artistic_role_id =&gt; 1, :another_memeber =&gt; 42 } } </code></pre> <p>What is the best way t...
[]
[ { "body": "<p>This is what I would do:</p>\n\n<pre><code>has_many :owning_artists, {\n :through =&gt; :artist_tracks,\n :source =&gt; :artist,\n :conditions =&gt; {\n :artist_tracks =&gt; {\n :artistic_role_id =&gt; 1,\n :another_memeber =&gt; 42\n }\n }\n}\n</code></pre>\n", "comments":...
{ "AcceptedAnswerId": "23362", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-26T15:50:09.330", "Id": "23361", "Score": "1", "Tags": [ "ruby-on-rails", "ruby" ], "Title": "What is the best way to format a large has_many through line?" }
23361
<p>I believe this is essentially the same method as the <code>itertools.combinations</code> function, but is there any way to make this code more more perfect in terms of speed, code size and readability :</p> <pre><code>def all_subsets(source,size): index = len(source) index_sets = [()] for sz...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-02T23:53:25.477", "Id": "36021", "Score": "0", "body": "Why aren't you using itertools.combinations? It's reasonable to do this for learning purposes, but if you are actually doing a bigger project you'll want to use the itertools vers...
[ { "body": "<p>This type of problems lend themselves very well to <a href=\"http://en.wikipedia.org/wiki/Recursion\" rel=\"nofollow\">recursion</a>. A possible implementation, either in list or generator form could be:</p>\n\n<pre><code>def all_subsets(di, i) :\n ret = []\n for j, item in enumerate(di) :\n...
{ "AcceptedAnswerId": "23371", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-02T19:38:14.427", "Id": "23363", "Score": "1", "Tags": [ "python", "functional-programming", "combinatorics" ], "Title": "Any way to optimize or improve this python combinations/s...
23363
<p>I am new to Python and not very familiar with advanced Python data structures.</p> <p>I have written a function to receive data from a socket in Python and perform string manipulations on it. The basic purpose of the code is to get the metadata from an Icecast radio stream based on suggestions I found elsewhere.</p...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-02T19:53:31.587", "Id": "36004", "Score": "0", "body": "Repeated string concatenations are a bad idea - instead build a list and then use `\"\".join()`." } ]
[ { "body": "<pre><code>def radioPoller():\n</code></pre>\n\n<p>Python convention says that function names should be lowercase_with_undescores. Also, they should be verb, so: <code>poll_radio</code> would be better</p>\n\n<pre><code> s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)\n s.connect((HOST, P...
{ "AcceptedAnswerId": "23365", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-02T19:47:51.017", "Id": "23364", "Score": "4", "Tags": [ "python", "strings", "parsing", "networking" ], "Title": "Get metadata from an Icecast radio stream" }
23364
<p>Is there a better way to get the underscore-case version of an ActiveRecord model's name? So far this works, but it's far from ideal:</p> <pre><code>my_active_record_instance.class.name.underscore </code></pre>
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-02T22:36:22.963", "Id": "36017", "Score": "0", "body": "What do you need the name for? For certain situations, there may be shortcuts. Nothing wrong with your solution though." }, { "ContentLicense": "CC BY-SA 3.0", "Creati...
[ { "body": "<p>You can use the <code>singular</code> method of <a href=\"http://api.rubyonrails.org/classes/ActiveModel/Naming.html\">ActiveModel::Naming</a>:</p>\n\n<pre><code>ActiveModel::Naming.singular(my_active_record_instance)\n</code></pre>\n\n<p>Alternatively, you can use the <code>model_name</code> meth...
{ "AcceptedAnswerId": "23376", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-02T21:30:49.583", "Id": "23369", "Score": "5", "Tags": [ "ruby", "ruby-on-rails", "formatting", "active-record" ], "Title": "Underscore-case version of ActiveRecord model's na...
23369
<p>I made a program that allows you to assign stats. However it uses some fairly complex if-else statements. Also, someone told me that <code>goto</code> statements were bad, but why is that? I know that switch might have been a better solution, but I cannot get <code>switch</code> statements to work for string variabl...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-03T01:57:25.323", "Id": "36026", "Score": "4", "body": "Please copy/paste your code into the question as per the FAQ. Otherwise, we'll be forced to close your question." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate"...
[ { "body": "<p>You would have to refactor this a few times to make it perfect, these are my suggestions for starters.</p>\n\n<ul>\n<li><p>Naming your variables a,b,c,d,e,s is bad form. You could have called them strength, agility, endurance, etc.</p></li>\n<li><p>One way to avoid your long if statement is using ...
{ "AcceptedAnswerId": "23399", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-03T00:37:20.650", "Id": "23372", "Score": "5", "Tags": [ "c++", "game" ], "Title": "Assigning stats in a game" }
23372
<p>I got a ton of helpful tips last time I posted some code, so I thought I would come back to the well.</p> <p>My function is deciding whether or not the <code>secretWord</code> has been guessed in my hangman game. I am trying to accomplish this by taking a list, <code>lettersGuessed</code>, and comparing it to the ...
[]
[ { "body": "<p>Because we always return from the inside of the while, we'll never perform the loop more than once. Thus, your while actually acts like an <code>if</code>. Thus the value of <code>place</code> is not really used and you can get rid of it : <code>if place &lt; chars</code> becomes <code>if 0 &lt; c...
{ "AcceptedAnswerId": "23378", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-03T05:01:59.713", "Id": "23375", "Score": "5", "Tags": [ "python", "hangman" ], "Title": "In my Hangman game, one of my functions is correct but messy" }
23375
<p>This is my python solution to the first problem on Project Euler:</p> <pre><code>n = 1 rn = 0 while n &lt; 1000: if n%3 == 0 or n%5 == 0: rn += n n = n + 1 print(rn) </code></pre> <p>I would like to find a way to keep everything in this python code to as little number of lines as possible (maybe ev...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-12-29T21:28:10.807", "Id": "63715", "Score": "1", "body": "`sum(n for n in range(1000) if not n%3 or not n%5)`" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2016-04-04T08:50:05.540", "Id": "232506", "Score":...
[ { "body": "<p><strong>Python hint number 1:</strong></p>\n\n<p>The pythonic way to do :</p>\n\n<pre><code>n = 1\nwhile n &lt; 1000:\n # something using n\n n = n + 1\n</code></pre>\n\n<p>is :</p>\n\n<pre><code>for n in range(1,1000):\n # something using n\n</code></pre>\n\n<p><strong>Python hint number...
{ "AcceptedAnswerId": "23380", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-03T11:41:15.993", "Id": "23379", "Score": "5", "Tags": [ "python", "project-euler" ], "Title": "Project Euler Problem 1" }
23379
<p>Here is my method:</p> <pre><code>public JsonResult ValidateAll(string toys) { Dictionary&lt;string, object&gt; res = new Dictionary&lt;string, object&gt;(); List&lt;string&gt; result_check = new List&lt;string&gt;(); string[] lines = toys.Split(new string[] { "\n" }, StringSplitOptions.RemoveEmptyEntr...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-03T13:25:03.057", "Id": "36038", "Score": "1", "body": "What is it supposed to do, and what are you looking for? What does the input look like? A bit more context might be helpful here." }, { "ContentLicense": "CC BY-SA 3.0", ...
[ { "body": "<p>Well without any context I am going to go out on a limb and take a stab at this anyway. </p>\n\n<p>First is if you are using a database, and have the ability to check for toy ID's instead of the toy names you won't have as many checks. it would require a little more work to pass in the string, but...
{ "AcceptedAnswerId": "23411", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-03T13:03:03.623", "Id": "23381", "Score": "0", "Tags": [ "c#", "optimization", "entity-framework" ], "Title": "How to optimize/refactor this method?" }
23381
<p>You might have read my question on shortening my code to a one-liner for Problem 1. So, I was wondering, is there any more tricks of the trade to shorten my <a href="http://projecteuler.net/problem=2" rel="nofollow">Problem 2</a> solution:</p> <pre><code>fib = [0, 1] final = 1 ra = 0 while final &lt; 4000000: f...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-03T15:59:51.477", "Id": "36044", "Score": "5", "body": "Writing everything in a single line is rarely a good idea. Why not strive for the most expressive, readable version, regardless of the number of lines?" }, { "ContentLicen...
[ { "body": "<p>The first few are probably OK, but you really shouldn't be publishing solutions to Project Euler problems online: don't spoil the fun for others!</p>\n\n<p>This said, there are several things you could consider to improve your code. As you will find if you keep doing Project Euler problems, eventu...
{ "AcceptedAnswerId": "23387", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-03T13:44:49.857", "Id": "23383", "Score": "2", "Tags": [ "python", "project-euler", "fibonacci-sequence" ], "Title": "Project Euler - Shortening Problem 2" }
23383
<p>I have to implement a class with has parent and child fields. The problem is that by adding a child it must immediately keep reference to its' parent. I implemented it and it seems to work but I am not quite sure if I did it right. Any advice will be useful!</p> <pre><code>namespace DocumentToDocument { public cl...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-03T15:08:38.600", "Id": "36040", "Score": "0", "body": "I can't test it right now, but I think this will only work as long as the list of children is explicitly referenced as `MyList<>` - when used as `List<>` or `IList<>` the original...
[ { "body": "<p>Here's how I might restructure it (note, I've removed many of the generics since it seems to be tied to <code>Document</code> - if you do need those classes to go for other types, go back to the generics, otherwise, YAGNI):</p>\n\n<pre><code>namespace DocumentToDocument\n{\n using System;\n ...
{ "AcceptedAnswerId": "23396", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-03T15:00:43.373", "Id": "23385", "Score": "5", "Tags": [ "c#", ".net" ], "Title": "Child/Parent relationship by adding an element to list" }
23385
<p>In the following piece of code I use the same trick three times. But cannot figure out how to write a common function that will do it for all of them. I know there is a toggle method in jQuery that does something similar but in this situation I wasn't able to get it do the job for me, so I wrote this:</p> <pre><cod...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-03T16:30:23.957", "Id": "36046", "Score": "2", "body": "First off, before trying to DRY up your code, I'd suggest applying some more important concepts. For once, I'd suggest using proper feature detection instead of sniffing the `appN...
[ { "body": "<p>Here's how to DRY it up:</p>\n\n<pre><code>var flag = true,\n isIE = navigator.appName == \"Microsoft Internet Explorer\";\n\n$(\".right-arrow\").click(function () {\n if (isIE) {\n $(\".slider-frame\").animate({ left: flag ? \"-130px\" : \"236px\" }, 1000);\n }\n else {\n ...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-03T16:15:58.043", "Id": "23386", "Score": "1", "Tags": [ "javascript", "jquery", "authentication", "animation" ], "Title": "Toggling animations" }
23386
<p>I have been working on translating some code from C to C# but since I haven't been coding in C / C++ for many years now plus I do not want to resort to the unsafe keyword. I have made an attempt and would like some verification &amp; optimisation suggestions.</p> <p>Here is the code in C/C++.</p> <pre><code>#ifdef...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-03T17:41:33.530", "Id": "36053", "Score": "0", "body": "Welcome! Feel free to post the entire algorithm if you like — context can make a big difference." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-03T17...
[ { "body": "<p>From a micro-optimization perspective I have found that C# and the JIT tend to like things from left to right (<a href=\"http://mediocresoft.com/Blog/simple-readable-csharp-micro-optimization-expression-operand-ordering\" rel=\"nofollow\">post</a>).\nEx: <code>(((size - 1) &amp; size) != 0)</code>...
{ "AcceptedAnswerId": null, "CommentCount": "7", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-03T17:23:58.520", "Id": "23392", "Score": "3", "Tags": [ "c#", "c" ], "Title": "Translate from C to C#" }
23392
<p>As you can see below, I have a method which executes statements based on the first letter of a component firing an <code>ItemEvent</code>:</p> <pre><code>public void itemStateChanged(ItemEvent ie) { if(ie.getSource() == rRadioButton) { currentScale = "r"; ((DefaultEditor) rSpinner.getEditor()).g...
[]
[ { "body": "<p>You repeat the line</p>\n\n<pre>((DefaultEditor) bSpinner.getEditor()).getTextField().requestFocus();</pre>\n\n<p>in every branch of the if/then. So you could easily shorten it by having the if/then look up of the currentScale be one thing and then have that line after it.</p>\n\n<p>Speaking of lo...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-03T20:26:37.263", "Id": "23398", "Score": "3", "Tags": [ "java" ], "Title": "Shortening method based on an argument name" }
23398
<p>I have implemented changes from a question I asked on this widget here:</p> <p><a href="https://codereview.stackexchange.com/questions/21131/android-widget-code-review">Android widget code</a></p> <p>I've added and changed a few things, so I would love some more coding advice!</p> <pre><code>public class SacWidge...
[]
[ { "body": "<ol>\n<li><blockquote>\n<pre><code>try {\n FileInputStream input = new FileInputStream(file);\n bitmap = BitmapFactory.decodeStream(input);\n try {\n input.close();\n } catch (IOException e) {\n // TODO Auto-generated catch block\n Log.e(TAG, e.getMessage());\n }\n...
{ "AcceptedAnswerId": "44099", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-03T21:31:32.063", "Id": "23401", "Score": "2", "Tags": [ "java", "android" ], "Title": "Homescreen Widget Service" }
23401
<p>I wrote a productivity app for Android. It lets you switch system settings, like Bluetooth, wife, screen brightness, volumes, ringtones, mobile data, airplane mode, etc. Unfortunately I have discovered that device manufacturers modify the OS in every possible way, disabling functionality, requesting additional permi...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-03T23:11:12.273", "Id": "36073", "Score": "4", "body": "I would catch as many specific exceptions as possible and add the pokemon exception at the end to account for unknown problems. This should give you general error handling while a...
[ { "body": "<p>When the called API throws unknown exceptions I don't think that there is other way than catching all exceptions (sometimes <code>Throwable</code>s too). +1 <em>Jeroen Vannevel</em>'s comment too.</p>\n\n<p>Anyway, a common interface might be able to improve the code a little bit:</p>\n\n<pre><cod...
{ "AcceptedAnswerId": "23421", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-03T21:54:56.567", "Id": "23402", "Score": "12", "Tags": [ "java", "android", "error-handling" ], "Title": "Productivity app for Android" }
23402
<p>A <a href="http://en.wikipedia.org/wiki/Node_%28computer_science%29" rel="nofollow">node</a> is a record consisting of one or more fields that are links to other nodes, and a data field. The link and data fields are often implemented by pointers or references although it is also quite common for the data to be embed...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-03T22:43:29.047", "Id": "23404", "Score": "0", "Tags": null, "Title": null }
23404
Nodes are the basic units used to build data structures such as linked lists and trees.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-03T22:43:29.047", "Id": "23405", "Score": "0", "Tags": null, "Title": null }
23405
<p>The <em>batch</em> tag is used for Windows batch file questions.</p> <p>Batch files are scripts executed by the Windows command processor (cmd.exe) or, in older times, by the DOS shell (command.com). While many people mistakenly believe that everything that has light gray text on a black background is DOS, pretty m...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2013-03-03T22:55:10.727", "Id": "23407", "Score": "0", "Tags": null, "Title": null }
23407
The batch tag is used for Windows batch file questions.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2013-03-03T22:55:10.727", "Id": "23408", "Score": "0", "Tags": null, "Title": null }
23408
<p>I am working on a project in which I have two tables in a different database with different schemas. So that means I have two different connection parameters for those two tables to connect using JDBC-</p> <p>Let's suppose below is the config.property file.</p> <pre><code>NUMBER_OF_THREADS: 10 TOTAL_RUNNING_TIME: ...
[]
[ { "body": "<ol>\n<li><p>It looks thread-safe for me, I've not found any concurrency-related issue except that you might want to to use a <a href=\"http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/ThreadLocalRandom.html\" rel=\"nofollow noreferrer\"><code>ThreadLocalRandom</code></a> or use separate...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-03T23:56:53.433", "Id": "23409", "Score": "4", "Tags": [ "java", "multithreading", "json", "jdbc" ], "Title": "Finding potential thread safety issues and race conditions in my mu...
23409
<p>I'm having performance issues with this query. If I remove the <code>status</code> column, it runs very fast; but adding the subquery in the column section delays the query way too much (1.02 min execution). How can I modify this query so it runs faster while still getting the desired data?</p> <p>The reason I put...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-04T10:52:15.360", "Id": "36091", "Score": "0", "body": "Please provide [DDL](http://en.wikipedia.org/wiki/Data_definition_language) query for the tables and execution plan" } ]
[ { "body": "<p>Your code is calling several tables multiple times when it doesn't seem like it needs to. Can you pull out your Activities related tables into common table expressions and just link to those in your main query. Rough example:</p>\n\n<pre><code>;with created as\n(\n select establishment_fk, max...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-04T01:40:12.810", "Id": "23410", "Score": "1", "Tags": [ "performance", "sql", "sql-server" ], "Title": "Subquery performance too slow" }
23410
<p>Is this an ideal use of if..else or can this code be simplified/beautified further?</p> <pre><code> // If any image found and bigger than thumbnail settings, get that one if ( isset( $matches ) &amp;&amp; !empty( $matches[1][0] ) ) { $image_found = $matches[1][0]; $image_dimensions = getimag...
[]
[ { "body": "<p>One of the points that should raise a query is the amount of repeated code - you have a duplicate for every if. This suggests creating a function to handle it instead. Personally, I would end up with something like the following:</p>\n\n<pre><code>function is_better_image( $image, $thumbnail_width...
{ "AcceptedAnswerId": "23417", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-04T04:46:27.843", "Id": "23412", "Score": "4", "Tags": [ "php", "image" ], "Title": "If any image found and bigger than thumbnail settings, get that one" }
23412
<p>I'd like to know any ways of shortening this UI window for Maya, at the moment, because I couldn't find very detailed documentation and not very skilled with python, I have just built this UI with the knowledge that I have already, I know it's not the best way of doing it (using empty text elements to fill gaps etc)...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-30T13:59:48.320", "Id": "51163", "Score": "0", "body": "You have alot of cmds.separator lines in a group of 3. Put them in for loops. Allmost everytime when the code looks repetetive, there can be used a loop to shorten it." } ]
[ { "body": "<p>It's not easy to answer this question, since:</p>\n\n<ol>\n<li>it applies to very specific Maya Embedded Language commands that aren't well documented,</li>\n<li>it's difficult to run the software ourselves.</li>\n</ol>\n\n<p>Anyway, based on other GUIs I've worked with, you don't need to worry to...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-04T06:02:07.410", "Id": "23413", "Score": "2", "Tags": [ "python" ], "Title": "Shorten Python/Maya Window UI code" }
23413
<p>This script extracts all urls from a specific HTML div block (with BeautifulSoup 4) : </p> <pre><code>raw_data = dl("http://somewhere") links = [] soup = BeautifulSoup(raw_data) data = str(soup.find_all('div', attrs={'class' : "results"})) for link in BeautifulSoup(data, parse_only = SoupStrainer('a')): links.a...
[]
[ { "body": "<p>AFAIK, you can use <a href=\"http://docs.python.org/2/tutorial/datastructures.html#list-comprehensions\" rel=\"nofollow\">List comprehension</a> to make it more efficient </p>\n\n<pre><code>raw_data = dl(\"http://somewhere\")\nsoup = BeautifulSoup(raw_data)\ndata = str(soup.find_all('div', attrs={...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-04T09:40:40.713", "Id": "23416", "Score": "1", "Tags": [ "python" ], "Title": "URLs extraction from specific block" }
23416
<p>I've got this code</p> <pre><code>Double best = nodes.get(edge.getToNodeId()); if (best == null || (best &gt; g+h)) { nodes.put(edge.getToNodeId(), g+h); if (best == null) { open.add(new State(edge.getToNodeId(), g, h, top)); } else { open.modify(new State(edge.getToNodeId(), g, h, top))...
[]
[ { "body": "<p>I think it's a matter of taste and preference. In either case, you would have to duplicate something. But, there's something that drew my attention. I don't claim it to be correct or be a solution to your problem. Hard to say without knowing the context and data structures that you use. Anyways, h...
{ "AcceptedAnswerId": "23419", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-04T09:56:10.607", "Id": "23418", "Score": "4", "Tags": [ "java" ], "Title": "Nested condition subset of the top one" }
23418
<p>So I create 3D tree like structures using L-systems. Basically this means I generate a string like this:</p> <pre><code> "FFFFFFFF-[[FFFF-[[FF-[[F-[[X]+X]+F[+FX]-X]+F]]]]]" </code></pre> <p>This string is then interpreted by a turtle performing certain actions for each character in the string. The problem is how t...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-05T00:33:20.100", "Id": "36192", "Score": "0", "body": "Have you considered that sometimes more than one character chained together can have a different meaning. Or more than one character can mean one instructions." }, { "Cont...
[ { "body": "<p>The design flaw <strong>would have been</strong> the use of this switch case with 11 entries. That's already a lot. By the way I warn you, you have forgotten 9 <code>break</code> out of 11 cases.</p>\n\n<p>However, in your case, each case relates to a single action. I mean, there is not a lot new ...
{ "AcceptedAnswerId": "23439", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-04T11:00:56.893", "Id": "23420", "Score": "2", "Tags": [ "c++" ], "Title": "Is there a better way to translate a string into methods?" }
23420
<p>I wrote some code which compares numbers of all datatypes with each other. The standard Comparer which is implemented by every number Type only compares numbers of the same type.</p> <p>I cast to decimal because this is the largest possible number type and should cover everything.</p> <ol> <li>What do you think ab...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-04T16:03:22.123", "Id": "36149", "Score": "0", "body": "Have you even tried your code? It won't work unless both values are `decimal`. Also, what about `BigInteger`?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "...
[ { "body": "<p>Some thoughts:</p>\n\n<ul>\n<li>There's no point in testing whether <code>x</code> or <code>y</code> is null, because when <code>null</code> is passed, <code>IsNumber()</code> returns <code>false</code>.</li>\n<li>If you do want to keep that code, perhaps by modifying <code>IsNumber()</code> to ac...
{ "AcceptedAnswerId": null, "CommentCount": "9", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-04T11:31:30.037", "Id": "23422", "Score": "5", "Tags": [ "c#" ], "Title": "Universal number comparer" }
23422
<p>I am learning C# and I have made my way through the entire C# 101 course on buzz3D. The last project they have you do is create a product inventory system that must be split up between classes and only the Main() method can be in the Program class. It was listed that all methods had to be as close to or below 25 lin...
[]
[ { "body": "<p>That's a lot of code to look through :) I haven't analyzed all of it, but after looking at the first couple of classes, here are some ideas to get you started.</p>\n\n<p>In your <code>Input.GetKey</code> method, you have a bunch of <code>if</code> statements to check the value of the <code>choice...
{ "AcceptedAnswerId": "23434", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-04T13:01:52.593", "Id": "23428", "Score": "5", "Tags": [ "c#" ], "Title": "C# product inventory. How would you refactor this?" }
23428
<p>So I am essentially a complete newbie to programming, and have been attempting to learn Python by completing the Project Euler problems. I haven't gotten very far, and this is my code for <a href="http://projecteuler.net/problem=3" rel="nofollow">problem #3</a> :</p> <blockquote> <p>The prime factors of 13195 are...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-04T14:06:48.310", "Id": "36112", "Score": "0", "body": "You should replace `while a < x:` with `while a < math.sqrt(x):` You can also check whether x is even and > 2, in that case it is not a prime, also google for 'prime sieve'." } ...
[ { "body": "<p>You can save quite a bit time on your prime generation. What you should keep in mind is that a prime is a number which is no multiple of a prime itself; all other numbers are.</p>\n\n<p>So in your <code>isPrime</code> function you can just go through your primes list and check if each prime is a d...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-04T13:17:46.433", "Id": "23429", "Score": "8", "Tags": [ "python", "project-euler", "primes" ], "Title": "Project Euler #3 - how inefficient is my code?" }
23429
<p>Can anyone help me speed up this query? At present, it returns 1200 rows in 5 secs. I've notice that it is looking at 240000 response records. I think this is where the issue may be.</p> <p>I've created the following indexes:</p> <pre><code>CREATE INDEX idx_eventid ON `action` (eventid); CREATE INDEX idx_action...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-01T09:21:21.353", "Id": "36097", "Score": "0", "body": "The index on response.date cannot be used because you are using a function on the column." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-02T12:40:32....
[ { "body": "<p>In your Select statement you are doing this</p>\n\n<pre><code>WHERE UCASE(response.reasonid) &lt;&gt; 'FIRST' \n AND UCASE(response.reasonid) &lt;&gt; 'CANCELLED' \n AND UCASE(response.reasonid) &lt;&gt; 'WEBSITE' \n AND DATE(response.date) = '20130228' \n</code></pre>\n\n<p>Which is about the ...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-01T09:10:12.313", "Id": "23430", "Score": "4", "Tags": [ "optimization", "performance", "mysql", "sql" ], "Title": "Slow MySQL query - 1200 rows in 5secs" }
23430
<p>I am studying about how to use an interface for decoupling, and I wrote a program. Does it actually implemented decoupling? Are there any possible modifications to make it better?</p> <pre><code>public partial class MainPage { // Constructor public MainPage() { InitializeComponent(); ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-25T09:59:31.913", "Id": "36102", "Score": "2", "body": "Still you can decopule your actual code MainPage class by delegating some other type to create the concrete objects. For which you can refer to Inversion of Control and Creational...
[ { "body": "<p>Yes that's it, that is decoupled.</p>\n\n<p>However, the benefits of this are not visible in your example because the look of SQL and IDBInteraface are the same.</p>\n\n<p>It would become obvious if your example was of that kind:</p>\n\n<pre><code>interface IDBInterface\n{\n void Update(string ...
{ "AcceptedAnswerId": "23436", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-02-25T09:56:25.837", "Id": "23435", "Score": "8", "Tags": [ "c#", "interface" ], "Title": "Using an interface for decoupling" }
23435
<p>I have tried to build my first MVC sign up form.</p> <p>Here is the user controller method <code>register</code>:</p> <pre><code>public function register() { if($this-&gt;isPost()) { $user = new UserModel(); $result = $user-&gt;add($_POST); if(!$result) { $this-&gt;redirect(...
[]
[ { "body": "<p>I'm not a PHP expert but:</p>\n\n<p>The <code>Register</code> method is too long. Extract each branch of the top-level conditional into separate methods.</p>\n\n<p>The line <code>$this-&gt;view-&gt;addTemplate('header'...</code> is too long. Assign the array to an intermediate variable first.</p>\...
{ "AcceptedAnswerId": "23455", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-04T14:25:47.183", "Id": "23437", "Score": "1", "Tags": [ "php", "design-patterns", "mvc", "form" ], "Title": "Simple sign up form" }
23437
<p>I have a few hundred files in a directory that I need to read in parallel. Namely, the files that have the same name, but different file extensions (.a and .b), but they're pretty much plain text files. The corresponding .a and .b files have the same number of lines. I need to read each line into cell arrays x and y...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-04T10:15:21.113", "Id": "36124", "Score": "0", "body": "Are you sure that it's the reading of the files which takes too long? I see that you're not preallocating memory for the cell arrays `x` and `y`... this may also be a reason for a...
[ { "body": "<p>Performing this in parallel using <code>PARFOR</code> should be straightforward if you have the Parallel Computing Toolbox installed. Whether it goes any faster or not depends entirely on the size of your data, the speed of your disks etc. Here's how I would approach it:</p>\n\n<pre><code>function...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-04T09:44:32.053", "Id": "23438", "Score": "1", "Tags": [ "matlab" ], "Title": "Matlab - Fastest way to parallel read many files line by line?" }
23438
<p>I have this function containing some loops and a double for loop. What it does is set up a matrix first to store results in (the task at hand is comparing genomes) and then with sliding window, calculate the differences between sequences. It's very slow for very long sequences, I was hoping somebody know how to spee...
[]
[ { "body": "<p>Can't see exactly what's going with the sliding windows but it looks like you're calculating the full distance matrix: (i,j) and (j,i). If so, you probably only need half (usually lower) but you can make both with <code>Distances[n1,n2] &lt;- Distances[n2,n1] &lt;- sum ...</code> If this is correc...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-04T15:21:15.030", "Id": "23440", "Score": "3", "Tags": [ "optimization", "r" ], "Title": "Vectorize or otherwise speed up a double for loop" }
23440
<p>This is a simple repeatable question regarding the usage of Python3's comprehensions:</p> <p><strong>Could the Python3 syntax be used in another way to speed up the process, further so the gap between Python3 and numpy would be reduced?</strong> (see chart below).</p> <p>The results &amp; code: <img src="https://i...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-04T14:18:57.917", "Id": "36131", "Score": "0", "body": "Similar, though not the same:\nhttp://stackoverflow.com/questions/9708783/numpy-vs-list-comprehension-which-is-faster?rq=1" }, { "ContentLicense": "CC BY-SA 3.0", "Cre...
[ { "body": "<pre><code>def listexpression(n): #LE\n return [x * x * (1 + x) for x in range(n)]\n</code></pre>\n\n<p>is over 3 times faster than your version with <code>x**2+x**3</code> (from 8.47 ms to 2.31 ms with n = 10000).</p>\n\n<p>Though, NumPy will also benefit from regrouping the expression this way....
{ "AcceptedAnswerId": "23442", "CommentCount": "11", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-04T14:15:48.850", "Id": "23441", "Score": "3", "Tags": [ "python", "performance", "numpy" ], "Title": "Are these list-comprehensions written the fastest possible way?" }
23441
<p>I have a method that parses XML into an array of hashes.</p> <p>Here is the original XML:</p> <pre class="lang-xml prettyprint-override"><code>&lt;rowset name="skillqueue" key="queuePosition" columns="queuePosition,typeID,level,startSP,endSP,startTime,endTime"&gt; &lt;row queuePosition="0" typeID="20495" level...
[]
[ { "body": "<p>Notes:</p>\n\n<ul>\n<li>Use functional <code>Enumerable#map</code> instead of imperative pattern <code>obj = []</code> + <code>Enumerable#each</code> + <code>Array#&lt;&lt;</code>.</li>\n<li>Use <a href=\"http://ruby-doc.org/core-2.0/Kernel.html#method-i-Hash\" rel=\"nofollow\">Kernel#Hash</a> to...
{ "AcceptedAnswerId": "23452", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-04T17:53:00.983", "Id": "23449", "Score": "3", "Tags": [ "ruby", "ruby-on-rails", "parsing", "xml" ], "Title": "Parsing data from XML using Ruby and Nokogiri" }
23449
<p>I wrote the following function that takes a string and returns a new string with each word capitalized: first letter uppercase, following letters lower-cased.</p> <p>It works, but I would be interested in seeing how a more sophisticated Haskell programmer would do this (if there is already a built-in, great, but st...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-05T11:00:00.640", "Id": "36219", "Score": "1", "body": "FIY, I asked a question concerning the `capitalize` function: http://stackoverflow.com/questions/15222013/how-to-abstract-over-a-back-and-forth-transformation" } ]
[ { "body": "<p><code>head</code> and <code>tail</code> are <a href=\"http://www.haskell.org/haskellwiki/Partial_functions\">partial functions</a>, meaning that they are only defined for non-empty lists and will fail on empty ones. Because of this your <code>capWord</code> function is also partial and its strongl...
{ "AcceptedAnswerId": "23459", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-04T19:51:51.103", "Id": "23456", "Score": "5", "Tags": [ "beginner", "strings", "haskell" ], "Title": "Capitalizing a string" }
23456
<p>I have an upload form on my site and I'm trying to sanitize and transform input data.</p> <p>I will be straight forward to you - this is my first object-oriented style code! The reason I don't just want to use regular function, is that I would like to keep my codes divided in logical blocks. I called this one <em>...
[]
[ { "body": "<p>OK...first off: this isn't OOP. OOP is about objects talking to each other, delegating tasks to each other to get stuff done. What you're doing here is just using classes as modules. There's nothing inherently wrong with that, but it doesn't automatically make your code <em>object oriented</em...
{ "AcceptedAnswerId": "23465", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-04T20:29:14.683", "Id": "23457", "Score": "2", "Tags": [ "php" ], "Title": "Filter Class to sanitize and transform input data - Improvements?" }
23457
<p>I wrote a simple SPI Master implementation to send characters to a LCD screen. Only the output is actually implemented in this so there is no rx register. This only sends a character out when write is asserted. I would appreciate any feedback and wanted to test out stackexchange for HDL. </p> <pre><code>library IEE...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-05T13:19:37.043", "Id": "36226", "Score": "2", "body": "Please at least indent your code consistently!" } ]
[ { "body": "<p>Never saw HDL before, but the following came to mind</p>\n\n<ol>\n<li><p>Indentation seems wrong, I would have expected <code>case state</code> to be indented</p>\n\n<pre><code>elsif rising_edge(clk) then\n\ncase state is\n</code></pre></li>\n<li><p><code>mosi &lt;= 'Z';</code> &lt;- Why 'Z', that...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-04T20:36:11.850", "Id": "23458", "Score": "2", "Tags": [ "hdl", "vhdl" ], "Title": "Simple SPI Master" }
23458
<p>I wrote a script to perform <code>svn update</code> on all the SVN repositories inside a folder. It would have been great if the folder containing all these repositories itself was a repository, but it was not setup like that, which is why I opted to write this script.</p> <pre><code>$timestamp = get-date -f "yyyy-...
[]
[ { "body": "<p>Personally, I would look to use:</p>\n\n<pre><code>$FullPaths = $RepositoryList | %{ Join-path $BaseDir $_ }\n</code></pre>\n\n<p>vs.</p>\n\n<pre><code>$FullPaths = $RepositoryList | %{ $BaseDir+$_}\n</code></pre>\n\n<p>You could alternatively also do something like:</p>\n\n<pre><code>$FullPaths =...
{ "AcceptedAnswerId": "26060", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-05T04:10:42.847", "Id": "23468", "Score": "8", "Tags": [ "powershell" ], "Title": "Updating multiple svn repositories using powershell" }
23468
<p>School HABTM AthleticDirector</p> <p>I am building a tool for assigning athletic directors (ADs) to schools. The tool has a school menu/filter which, when selected, shows a list of ADs already assigned to the school, and those yet to be assigned.</p> <p>The tool can be used in two ways:</p> <ol> <li>in a stand-al...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-05T05:37:34.820", "Id": "23469", "Score": "3", "Tags": [ "php", "cakephp" ], "Title": "CakePHP Best strategy for getting HABTM data in multiple ways within the same tool" }
23469
<p>I encountered a problem at <a href="http://regexone.com/example/6" rel="nofollow">http://regexone.com/example/6</a>? You can view the problem by clicking the link. There was required a regular expression to extract the method name, filename and the line number from a particular stack trace in an android development...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-05T11:50:50.407", "Id": "36222", "Score": "0", "body": "If you want to actually solve the problem rather than merely pass the test cases then you also need to take into account that packages can contain multiple components separated by...
[ { "body": "<p>If you wish to include the hat <code>^</code> and dollar <code>$</code> signs, then the regex can be rewritten as:</p>\n\n<pre><code>^.*\\s+at widget\\.List\\.(\\w+)\\((\\w+\\.java)\\:(\\d+)\\)$\n</code></pre>\n\n<p>Ofcourse, you can still use <code>\\d{3,4}</code> instead of <code>\\d+</code> but...
{ "AcceptedAnswerId": "23472", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-05T11:20:34.653", "Id": "23471", "Score": "2", "Tags": [ "regex" ], "Title": "To extract specific information in the stack trace using regular expression" }
23471
<p>The <a href="http://www.doctrine-project.org/" rel="nofollow">Doctrine Project</a> is a collection of open source libraries and tools for dealing with database abstraction and Object-Relational Mapping written in PHP.</p> <h1>Doctrine 2</h1> <p>When we say <em>Doctrine 2</em> it usually refers to Doctrine ORM Proj...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-05T11:48:21.780", "Id": "23473", "Score": "0", "Tags": null, "Title": null }
23473
The Doctrine Project is a collection of open source libraries and tools for dealing with database abstraction and Object-Relational Mapping written in PHP.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-05T11:48:21.780", "Id": "23474", "Score": "0", "Tags": null, "Title": null }
23474
<p><a href="http://en.wikipedia.org/wiki/Test-driven_development" rel="nofollow">Test-driven development</a> (TDD) is a software development process that relies on the repetition of a very short development cycle: first the developer writes a failing automated test case that defines a desired improvement or new functio...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-05T11:50:23.777", "Id": "23475", "Score": "0", "Tags": null, "Title": null }
23475
Test Driven Development involves writing a failing automated test to specify what is to be built. The test is then made to pass by writing code which satisfies the tested condition. Finally, the code is refactored.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-05T11:50:23.777", "Id": "23476", "Score": "0", "Tags": null, "Title": null }
23476
<p>Excerpt from the <a href="http://en.wikipedia.org/wiki/Unix" rel="nofollow">Wikipedia page</a>:</p> <blockquote> <p>Unix is a multitasking, multi-user computer operating system originally developed in 1969 by a group of AT&amp;T employees at Bell Labs. Today, it is a modern OS with many commercial flavors and...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-05T11:52:28.377", "Id": "23477", "Score": "0", "Tags": null, "Title": null }
23477
<p>I am a young programmer with the ability to learn more. I created a public site where a user can upload multiple pictures at once. The code works successfully and inserts the images into a MySQL database. As I improved the code further by reducing the size of multiple uploaded pictures at once, only one picture was ...
[]
[ { "body": "<p>In your HTML View you can use this\n<code>&lt;file name=\"upload[]\" accept=\"image/*\" multiple&gt;</code> <strong>multiple</strong> and <strong>accept</strong> attribute is only available in HTML5 dosen't work in old browsers.</p>\n\n<pre><code>&lt;?php\n $files = null;\n $errors = null;\n...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-05T12:59:29.370", "Id": "23481", "Score": "2", "Tags": [ "php" ], "Title": "Reduce size of multiple uploaded images" }
23481
<p>The working hours are saved in Database like</p> <pre><code>{"1" : "11:00 - 14:30", "2" : "17:30 - 23:00"} </code></pre> <p>Now i wrote a function like, which test is the shop is opened or close at the moment. Can someone please suggest if there is a better way to do this? And how i can check if the timing are lik...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-05T21:07:14.997", "Id": "36256", "Score": "0", "body": "OK, you've convinced me that NoSQL is a really bad idea." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-06T08:30:11.767", "Id": "36288", "Sco...
[ { "body": "<p>If 02:00 consider the next day, then you'll need to decide on some cut-off for what's considered 'today' and what's considered 'tomorrow'.</p>\n", "comments": [ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-05T15:31:41.147", "Id": "36234", "...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-05T13:07:18.650", "Id": "23482", "Score": "4", "Tags": [ "php", "datetime" ], "Title": "Check if the shop is open or closed" }
23482
<p>I have three functions (out of a medium 2 digit number of functions) which use up 80% of CPU time, so I kind of wonder if there are points for optimization that I am missing.</p> <p>Function 1, Extracting a bilinear interpolated point from a width * height float value image:</p> <pre><code>float ExtractBilinear(fl...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-08-14T10:17:01.787", "Id": "47040", "Score": "0", "body": "From a language use standpoint, things like `if (cond) var = thing; else var = other_thing;` can be shortened using the ternary operator, making your code shorter and scan better ...
[ { "body": "<p>How often is the third function called? </p>\n\n<p>The allocation of the images could be a bottleneck. You could try to reuse the memory for the images by passing them to the function instead of reallocating and freeing them every time.</p>\n\n<p>Also things like <code>Width/2.0f</code>, <code>Hei...
{ "AcceptedAnswerId": "29735", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-05T13:39:07.563", "Id": "23485", "Score": "3", "Tags": [ "c++", "optimization", "performance" ], "Title": "Not sure if I missed some obvious CPU brakes" }
23485
<p>I wrote <a href="http://jsfiddle.net/abitdodgy/7rFb6/6/" rel="nofollow noreferrer">this code</a> to allow users to select multiple images, and each image can be selected multiple times. It feels convoluted, though, and prone to errors, such as forgetting to do something associated with an action.</p> <p>How can I m...
[]
[ { "body": "<p>Your code is actually very good. </p>\n\n<p>I'd advice against using OOP there. It's an overused tool which, when not necessary, only makes things more complex. JavaScript works very well without it. I'd recommend a more functional style. So, if you want to make your code more reusable, you could ...
{ "AcceptedAnswerId": "23496", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-05T15:50:01.700", "Id": "23489", "Score": "5", "Tags": [ "javascript", "beginner", "jquery", "image" ], "Title": "Selecting multiple images" }
23489
<p>I have this little utility/helper which serializes a form into a javaScript object.</p> <pre><code>$.fn.serializeObject = function(fn) { var o = {}, a = this.serializeArray(), that; $.each(a, function() { that = this; if($.isFunction(fn)){ that = fn(that.name, that.value); } ...
[]
[ { "body": "<p>First of all, I'm barely even sure what's going on here:</p>\n\n<pre><code>if(o[this.name] !== undefined) {\n val = that.value || '';\n if(!o[that.name].push) {\n o[that.name] = [o[that.name]];\n }\n o[that.name].push(that.value);\n} else {\n o[that.name] = that.value;\n}\n</code></pre>\n\...
{ "AcceptedAnswerId": "23510", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-05T16:20:17.497", "Id": "23491", "Score": "3", "Tags": [ "javascript", "jquery", "api", "serialization" ], "Title": "Object serializer" }
23491
<p>I've never had a serious attempt at writing an encryption algorithm before, and haven't read much on the subject. I have tried to write an encryption algorithm (of sorts), I would just like to see if anyone thinks it's any good. (Obviously, it's not going to be comparable to those actually used, given that it's a fi...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-05T16:49:41.997", "Id": "36238", "Score": "0", "body": "usually an encryption algo takes input `data` and a `key`(private/symmetric) then outputs `cipher`. What's with `fakes` and `keys` in your case?" }, { "ContentLicense": "C...
[ { "body": "<p>Firstly, your encryption is useless. Just run this one line of python code:</p>\n\n<pre><code>print reduce(fractions.gcd, map(eval, encoded))\n</code></pre>\n\n<p>And it will tell you what your user key is (with a pretty high probability). </p>\n\n<p>Your algorithm is really obfuscation, not encry...
{ "AcceptedAnswerId": "23506", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-05T16:42:35.983", "Id": "23492", "Score": "4", "Tags": [ "python", "algorithm" ], "Title": "Is this a good encryption algorithm?" }
23492
<p>I have a files search function that iterates over a given directory until a given depth is reached and returns the found files. I did this via the <em>Enumerate</em> methods of the Directory class and yield return the results. Since it's very likely that I hit a directory that I can't access (e.g. system directories...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-05T17:39:35.867", "Id": "36243", "Score": "1", "body": "http://msdn.microsoft.com/en-us/library/bb513869.aspx" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-05T18:43:33.687", "Id": "36247", "Score"...
[ { "body": "<p>I would use Linq methods to simplify the code. Also I've extracted 2 methods to simplify the main method. And please rename <code>GetFilesWeAreLookingFor</code> to whatever your find appropriate :).</p>\n\n<pre><code>private static IEnumerable&lt;string&gt; GetFilesWeAreLookingFor(string currentDi...
{ "AcceptedAnswerId": "23834", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-05T17:08:28.383", "Id": "23494", "Score": "7", "Tags": [ "c#", "exception-handling" ], "Title": "Simplifying exception handling on Enumerators" }
23494
<p>I'm currently creating a client/server application (using Java) and I want to make it fully controllable by an input stream (currently the console). At the moment only one class have to be controlled, but I want my code to stay easy to develop.</p> <p>I found a solution but I think I can do better, so that's why I ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-07T16:26:11.377", "Id": "36346", "Score": "2", "body": "Just so it's said, classes with names like \"...Manager\", \"...Handler\", etc are generally frowned upon; they hint toward a class that either does too much or isn't clear about ...
[ { "body": "<p>CommandManager referes to a CommandControllable, and CommandControllable refers to a set of CommandManagers. Who controls who? Such loops in dependency graph should be avoided.</p>\n\n<p>Then, think if the Actor model can be applied in your case.</p>\n", "comments": [], "meta_data": { ...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-05T20:19:02.790", "Id": "23497", "Score": "0", "Tags": [ "java", "object-oriented" ], "Title": "Oriented-object approach on how to control different classes cleanly" }
23497
<p>Thats my method to test:</p> <pre><code> public LessonplannerRequest GetWeeklyLessonplanner(int schoolyearId) { Schoolyear schoolyear = _unitOfWork.SchoolyearRepository.GetById(schoolyearId); DayOfWeek firstDayOfWeek = schoolyear.FirstDayOfWeek; DateTime ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-05T21:01:18.247", "Id": "36255", "Score": "0", "body": "My very first impression is that your `GetWeeklyLessonPlanner()` method and its class might be doing too much. How much more than the method to test is there in the class? Is it j...
[ { "body": "<p>Almost everything is perfect. Some notes:</p>\n\n<ul>\n<li>Do use <code>var</code> to avoid repeating in cases like <code>Mock&lt;IUnitOfWork&gt; unitOfWorkMock = new Mock&lt;IUnitOfWork&gt;()</code></li>\n<li>Move mocks initialisation and wiring up to <code>SetUp</code> method to avoid copy-pasti...
{ "AcceptedAnswerId": "23511", "CommentCount": "8", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-05T20:47:11.503", "Id": "23498", "Score": "5", "Tags": [ "c#", "unit-testing" ], "Title": "Do I unit test the correct thing" }
23498
<p>The objective of the following PHP function is simple: given an ASCII string, replace all ASCII chars with their Cyrillic equivalents.</p> <p>As can be seen, certain ASCII chars have two possible equivalents.</p> <p>For example: if the function is fed the string "dvigatel" it should get you "двигател". </p> <p>Th...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-04T17:34:51.980", "Id": "36258", "Score": "0", "body": "1. If there are 2 options .. how do you resolve witch one to select ... 2. Why not do a simple replace instead of a recursive function ???" }, { "ContentLicense": "CC BY-...
[ { "body": "<p>Why a recursive function for such a simple task?</p>\n\n<pre><code>$in = 'This is your input';\n$map = 'your char translation array here';\n$out = '';\nfor($i = 0; $i &lt; strlen($in); $i++) {\n $char = $in[$i];\n if (isset($map[$char])) {\n if (is_array($map[$char])) {\n $newc...
{ "AcceptedAnswerId": "23502", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-04T17:30:24.197", "Id": "23501", "Score": "1", "Tags": [ "php", "optimization", "recursion" ], "Title": "Given an ASCII string, replace all ASCII chars with their Cyrillic equival...
23501
<p>I have the main form with a list inside and i need to open another form and edit the list in the main. Generally i'm doing something like ...</p> <pre><code> public class Form1 : Form { List&lt;objectType&gt; obj = new List&lt;objectType&gt;(); private void button_EDIT...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-05T18:05:05.560", "Id": "36261", "Score": "1", "body": "First you should really work on your naming conventions. Class names should start with an upper case letter, not be in full caps, and use camel casing to denote words, rather tha...
[ { "body": "<p>You should only pass the list to the second form. If you pass the entire first form you are exposing somethings that wouldn't be best, and coupling the two forms tightly.</p>\n", "comments": [], "meta_data": { "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "Creati...
{ "AcceptedAnswerId": "23504", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-05T18:00:49.593", "Id": "23503", "Score": "1", "Tags": [ "c#", "winforms" ], "Title": "Get Set vs passing class at init?" }
23503
<pre><code>String slm = status.getHeader("last-modified"); SimpleDateFormat sdf = new SimpleDateFormat( "EEE, dd MMM yyy HH:mm:ss zzz"); Date serverLastMod = null; try { serverLastMod = sdf.parse(slm); } catch (ParseException e) { Log.e("SAC XML l...
[]
[ { "body": "<p>Well, if it works, it works. There is not much to say about this small part of the code without any context. You should know this by yourself, because you should have some tests.</p>\n\n<hr>\n\n<p>For the code:</p>\n\n<p>The first catch is not suitable. If it happens, you will get a <code>NullPoin...
{ "AcceptedAnswerId": "23533", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-06T00:10:38.147", "Id": "23512", "Score": "3", "Tags": [ "java", "android" ], "Title": "Is my logic correct checking for a newer remote file?" }
23512
<p>I have the following snippet of code that redirects a user to a specific page on successful login to the application.</p> <pre><code>if(isset($this-&gt;params['url']['next'])) { $url = parse_url(urldecode($this-&gt;params['url']['next']), PHP_URL_HOST); if( $_SERVER['SERVER_NAME'] != $url || $url == false )...
[]
[ { "body": "<p>There is no need to <code>urldecode()</code> the url parameters, Cake does this for you. In fact, you are decoding twice, which is usually a bug.</p>\n\n<p><code>$url</code> actually contains the hostname. That is very confusing and you should rename that.</p>\n\n<p>Also, that is really deep nest...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-06T00:12:38.633", "Id": "23513", "Score": "2", "Tags": [ "php", "cakephp" ], "Title": "CakePHP return url validator" }
23513
<p>I define a <code>Pixel</code> data with different size like this.</p> <pre><code>data Pixel = RGB8 Word8 Word8 Word8 | RGBA8 Word8 Word8 Word8 Word8 | RGB16 Word16 Word16 Word16 | RGBA16 Word16 Word16 Word16 Word16 | Empty deriving (Eq) </code></pre> <p>and <c...
[]
[ { "body": "<p>Above all, such an instance doesn't make any sense. A composite entity can't have much in common with a number, which the fact that your instance consists of just partial and undefined functions is only the evidence of. </p>\n\n<hr>\n\n<p>With regards to your concern about the verbosity of the ins...
{ "AcceptedAnswerId": "23517", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-06T01:39:50.757", "Id": "23516", "Score": "4", "Tags": [ "haskell", "functional-programming" ], "Title": "Is there a way to simple Haskell class instance?" }
23516
<p>This code works but is there a simple / better way to do this?</p> <p>It starts from a particular point (<code>starthere</code>) in the array, looks for first <code>stop</code> value to the left of start point, and the first <code>stop</code> to the right side.</p> <p>Basically returns the closest values' position...
[]
[ { "body": "<p>There is an overload of <code>.indexOf</code> that takes a second parameter indicating the starting location for the search. That can be used to find the <code>stop</code> after <code>starthere</code>. Then you can use <code>.slice</code> to grab the part of the array before <code>starthere</code...
{ "AcceptedAnswerId": "23520", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-06T03:49:22.550", "Id": "23519", "Score": "3", "Tags": [ "javascript" ], "Title": "Searching for the closest \"stop\" elements surrounding a start point" }
23519
<p>So I wrote an asynchronous version of <code>AutoResetEvent</code>:</p> <pre><code>public sealed class AutoResetEventAsync { private readonly Task&lt;bool&gt; falseResult = Task.FromResult(false); private readonly ConcurrentQueue&lt;Handler&gt; handlers = new ConcurrentQueue&lt;Handler&gt;(); private rea...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-06T22:11:01.317", "Id": "36331", "Score": "0", "body": "The code is missing any public documentation, so one is left to wonder what exactly is the intended behavior. For example: it `WaitAsync()` supposed to be FIFO?" } ]
[ { "body": "<p>Your code does have race conditions, so it won't work correctly. I think your main problem is that you make some “destructive” operation (e.g. dequeue a handler from the queue) without knowing that the followup operation will actually succeed and not handling the eventual failure in any way.</p>\n...
{ "AcceptedAnswerId": "23557", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-06T06:50:10.537", "Id": "23522", "Score": "6", "Tags": [ "c#", ".net", "asynchronous" ], "Title": "AutoResetEventAsync, am I missing something?" }
23522
<p>I need to select all checked checkboxes, <strong>except</strong> checkboxes having a class <code>.checkall</code>.</p> <p>HTML:</p> <pre><code>&lt;input type="checkbox" value="1961" class="checkbox"&gt; &lt;input type="checkbox" name="checkall" class="checkbox checkall"&gt; </code></pre> <p>Script:</p> <pre><cod...
[]
[ { "body": "<p>I just posted on your other post about this, use:</p>\n\n<pre><code>$(\"input[type=checkbox]:checked:not(.checkall)\")\n</code></pre>\n\n<p>This is the 'regular' way to check for input tags of a particular type, it's much clearer than your way. I'm not sure what the significance of the <code>.chec...
{ "AcceptedAnswerId": "23526", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-06T07:32:20.890", "Id": "23523", "Score": "4", "Tags": [ "javascript", "jquery", "html" ], "Title": "Limited checkbox selection" }
23523