body stringlengths 25 86.7k | comments list | answers list | meta_data dict | question_id stringlengths 1 6 |
|---|---|---|---|---|
<p>Here is a light command line I built with JavaScript. I would like to ask if there are many stupidities, bad code and such? The only test command right now is <code>add arg1 arg2</code> so writing <code>add 1 1</code> should get you <code>>>> 2</code>. It will print <code>Command *** not found</code> with o... | [] | [
{
"body": "<p>Looks like <code>arguments_to_array()</code> can be removed.</p>\n\n<p>You may want to consider having <code>cli_parse()</code> call <code>cli_remove_blank_words()</code> rather than <code>cli_run()</code>.</p>\n\n<p>Also, depending on the direction you're going with the command line, you can prob... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-15T14:10:21.400",
"Id": "28509",
"Score": "1",
"Tags": [
"javascript",
"optimization"
],
"Title": "Online command line JavaScript optimization"
} | 28509 |
<p>This plugin is initialized like so:</p>
<pre><code>$("#calendar").ksdCalendar({
feedUrl: "http://www.kent.k12.wa.us/site/RSS.aspx?DomainID=275&ModuleInstanceID=4937&PageID=4334",
elemHeight: 750
});
</code></pre>
<p>I would like a review on the code, structure, or anything else that comes to mind. ... | [] | [
{
"body": "<p>This code looks good, I only have 2 minor items from a once over;</p>\n\n<ul>\n<li><p>I would have a constant for <code>-1</code> meaning an all day event</p>\n\n<pre><code>var ALL_DAY_EVENT = -1; // <-- Declared somewhere on top\nif (position === ALL_DAY_EVENT) {\n ...\n</code></pre></li>\n... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-15T15:14:53.003",
"Id": "28511",
"Score": "2",
"Tags": [
"javascript",
"jquery",
"datetime",
"plugin",
"rss"
],
"Title": "RSS Feed Calendar Plugin"
} | 28511 |
<pre><code>$controller = new UserController();
if (isset($_POST['submitform']))
{
$validated = false;
$inputs = array (
'username', 'email', 'password',
'repassword', 'password_f', 'repassword_f',
'display'
);
$i = 0;
foreach ($inputs as $key)
{
if (isset($... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-15T17:45:37.617",
"Id": "44768",
"Score": "1",
"body": "I would discourage you from using flags. Don't set `$validated` in the first place, instead, when you need to, just call the desired function."
}
] | [
{
"body": "<p>I'd do this instead:</p>\n\n<pre><code>function validateForm() {\n if (!isset($_POST['submitform']))\n return false; // Maybe $controller->error = \"Something\"; as well?\n $inputs = array (\n 'username', 'email', 'password',\n 'repassword', 'password_f', 'repassword_... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-15T17:22:52.673",
"Id": "28515",
"Score": "0",
"Tags": [
"php"
],
"Title": "Better way of handling isset/!empty?"
} | 28515 |
<p>I need to crawl web contents from some websites and then do some processing. Note that this is a small application, so the dataset is relatively small (need to crawl about 30,000 pages every time, once a week). The problem is that I can't start too many threads to crawl the pages at the same time. Otherwise my IP wi... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-15T18:35:12.093",
"Id": "44777",
"Score": "1",
"body": "I have several programs doing the same thing and also avoiding DOS detection on the server. For throttling, I use a Semaphore; and for downloading and sleeping I use a Task<T> in... | [
{
"body": "<p>Generally, very well written code. I just have a few suggestions:</p>\n\n<ol>\n<li>In the <code>Start</code> method, I understand why, but I don't like that there are two calls to check if the service is running. It feels kind of redundant, and I don't think you'll get a speed increase by short-... | {
"AcceptedAnswerId": null,
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-15T17:54:16.907",
"Id": "28517",
"Score": "6",
"Tags": [
"c#",
"multithreading",
"thread-safety"
],
"Title": "Class to encapsulate and manage multiple background web crawlers"
} | 28517 |
<p>I have a project from my college. I'm making a site which will display different quotations each time the page is loaded. I use the following code:</p>
<pre><code>$con = mysql_connect("localhost","root","");
if (!$con){
die('Could not connect: ' . mysql_error());
}
mysql_select_db("xlsx_db", $con);
$result = mysql... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-12T13:52:08.613",
"Id": "44778",
"Score": "2",
"body": "Having obtained a random quote ID from the database (`ORDER BY RAND()` will scale very poorly, by the way), you could redirect the browser to a page e.g. `?quote_id=12345` and the... | [
{
"body": "<p>Your link should look like this:</p>\n\n<pre><code><a href=\"http://www.yoursite.com/quotes?q_id=123\">Permalink</a>\n</code></pre>\n\n<p>In your php code, you can grab the selected quote id like this:</p>\n\n<pre><code>$q_id = $_GET['q_id'];\n</code></pre>\n\n<p>To check if the q_id h... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-12T13:48:14.677",
"Id": "28519",
"Score": "0",
"Tags": [
"php",
"mysql",
"random"
],
"Title": "RAND() with a generated link"
} | 28519 |
<p>This is my attempt at <a href="http://projecteuler.net/problem=12" rel="nofollow" title="Problem 12">problem 12 from Project Euler</a>. However, my code freezes my old, linux computer when I run it. I've only got 512MB of RAM and an old Intel Core 2 Duo processor on my machine which, I assume, is why it can't run th... | [] | [
{
"body": "<p>First, you can easily find the bottleneck in your code by running it with the profiler (ran with <code>number_of_divisors = 100</code>):</p>\n\n<pre><code>~> python -m cProfile t.py\nAnswer found: 73920\n 1926 function calls in 0.522 seconds\n\n Ordered by: standard name\n\n ncalls... | {
"AcceptedAnswerId": "28533",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-16T00:40:23.217",
"Id": "28527",
"Score": "1",
"Tags": [
"python",
"project-euler"
],
"Title": "Simple code that finds number of factors crashes my computer. Is there a workaround for... | 28527 |
<p>Consider (simplified)</p>
<pre><code>low_count = 0
high_count = 0
high = 10
low = 5
value = 2
</code></pre>
<p>What is a clean way to check a number <code>value</code> versus a min <code>low</code> and a max <code>high</code>, such that if <code>value</code> is below <code>low</code> <code>low_count</code> increme... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-16T00:39:47.417",
"Id": "44789",
"Score": "4",
"body": "Use `elif` instead of `else:\\nif`."
}
] | [
{
"body": "<p>The pythonic way would be:</p>\n\n<pre><code> for result in site_results:\n if result<low:\n low_count+=1\n elif result>high:\n high_count+=1\n</code></pre>\n",
"comments": [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-16T00:45... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-16T00:38:14.367",
"Id": "28528",
"Score": "2",
"Tags": [
"python"
],
"Title": "Python Clean way to get whether a number is above/below two values and increment accordingly"
} | 28528 |
<p>Sometimes I need to ensure that some references won't be processed while examination from the associated <code>ReferenceQueue</code>. Generally at those moments I don't know reachability status of the referent.</p>
<p>The only way I've came up with:</p>
<pre><code>class MyReference<V> extends SoftReference&l... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-16T03:57:34.457",
"Id": "44857",
"Score": "0",
"body": "This is the best way I can think of to do it."
}
] | [
{
"body": "<p>I believe there is a flaw in your logic that is insurmountable......</p>\n\n<p>SoftReferences, once they are added to the queue, have already lost the Referent instance. I cannot think of any reason why you would want to handle an 'active' queued (the value has been GC'd) softreference in any way ... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-16T03:21:32.480",
"Id": "28534",
"Score": "5",
"Tags": [
"java",
"weak-references"
],
"Title": "“Removing” reference from its ReferenceQueue"
} | 28534 |
<p>A friend of mine wanted an array-to-CSV string function for Node.js, so I came up with this. Basically, it can take in a single object, a 2D array or an array of objects. </p>
<p>If the children or parent is an object then the object properties become the headers, if the children are arrays then the first array is ... | [] | [
{
"body": "<p>There's a few points you can improve on:</p>\n\n<hr>\n\n<h2><code>throw</code>:</h2>\n\n<blockquote>\n<pre><code>throw \"Object is not an Array\";\n</code></pre>\n</blockquote>\n\n<p>You should use <code>throw new Error</code> instead of <code>throw</code> as <code>throw new Error</code> contains ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-16T04:10:46.017",
"Id": "28536",
"Score": "5",
"Tags": [
"javascript",
"csv"
],
"Title": "Correctness of a CSV writer in Node.js"
} | 28536 |
<p>After considerable effort, I've come up with the following code to generate a list of primes of a given length.</p>
<p>I would be very interested to see how an experienced coder would modify my code to make it more readable, more concise, or somehow better. I won't be able to follow fancy-pants coding that doesn't... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-16T04:04:10.643",
"Id": "44798",
"Score": "1",
"body": "See http://stackoverflow.com/questions/567222/simple-prime-generator-in-python?rq=1"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-16T04:07:06.617",
... | [
{
"body": "<p>Other than the few things pointed out above, it might be 'cleaner' to use a helper function to test primality. For example:</p>\n\n<pre><code>import math\n\ndef is_prime(x, primes):\n return all(x % i for i in primes if i < math.sqrt(x))\n\ndef first_k_primes(i, k, my_primes):\n if k <... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-16T03:58:48.117",
"Id": "28537",
"Score": "5",
"Tags": [
"python",
"algorithm",
"primes"
],
"Title": "Generating a list of primes of a given length"
} | 28537 |
<p>I am developing a website and I want to use PDO and MVC.</p>
<p>Before, I was coding in procedural MySQL, but I'm starting to understand the object-oriented programming.</p>
<p>My problem is the following:</p>
<p>If I understand the MVC pattern, there are 3 parts</p>
<ol>
<li>View (It's my Html)</li>
<li>Model (... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-28T13:52:13.697",
"Id": "84947",
"Score": "0",
"body": "Simplified, the controller is the traffic agent that links the correct model(s) and view(s) together."
}
] | [
{
"body": "<blockquote>\n<p><sup>Well .. <strong>you do not understand MVC design pattern</strong>. You seem to got all three parts wrong. Since I am quite lazy person, I will just direct to some older posts of mine that might help you to deal with <a href=\"https://stackoverflow.com/a/11369679/727208\">handlin... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-16T08:13:53.860",
"Id": "28541",
"Score": "2",
"Tags": [
"php",
"object-oriented",
"mysql",
"mvc",
"pdo"
],
"Title": "Structure pages mvc + oop"
} | 28541 |
<p>I was reading more about the <code>instancetype</code> on Stack Overflow and now my question is:</p>
<p>For every convenience constructor that I write, do I need to have the corresponding one using <code>init</code>?</p>
<p>For example:</p>
<p><strong>RandomItem.h</strong></p>
<pre><code>#import <Foundation/F... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-16T11:27:30.590",
"Id": "44816",
"Score": "0",
"body": "I've answered below, but wondering whether this question might be more appropriate for programmers.stackexchange.com, or maybe Stack Overflow?"
},
{
"ContentLicense": "CC ... | [
{
"body": "<p>It's not necessary to match your initialisers with your class convenience constructor, especially in an ARC environment.</p>\n\n<p>Take a look at the class documentation for <a href=\"http://developer.apple.com/library/ios/#documentation/uikit/reference/UICollectionViewLayoutAttributes_class/Refer... | {
"AcceptedAnswerId": "30275",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-16T10:05:28.087",
"Id": "28545",
"Score": "3",
"Tags": [
"objective-c",
"constructor"
],
"Title": "Is this a correct way to write a convenience constructor?"
} | 28545 |
<p>I wanted to create a class to cache dynamic PHP output (or a portion of it from one page) using Memcached key/value story. Basically it checks to see if the file has been cached already, if it has, it grabs it from Memcached and spits it out, otherwise, it outputs the file and stores it in Memcached for three hours.... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-16T13:33:03.653",
"Id": "28553",
"Score": "1",
"Tags": [
"php",
"cache"
],
"Title": "Memcached caching"
} | 28553 |
<p>We have a linklist which is made of alphabets. We have to shift the vowels towards the end of the linklist, without changing the order in which they appear. So,</p>
<pre><code>A->C->E->F->G->O
</code></pre>
<p>should become</p>
<pre><code>C->F->G->A->E->O
</code></pre>
<p>This is th... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-16T14:24:51.490",
"Id": "44830",
"Score": "0",
"body": "Your formatting is really consistent (especially for new lines). Also, can you explain your bit manipulation in `isVowel()` ?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"... | [
{
"body": "<p><strong>Don't do <code>using namespace std</code></strong></p>\n\n<p><a href=\"https://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-bad-practice\">Here's a SO question which should provide you more information about this</a>.</p>\n\n<p><strong><code>For</code> loops ar... | {
"AcceptedAnswerId": null,
"CommentCount": "9",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-16T14:00:19.243",
"Id": "28554",
"Score": "1",
"Tags": [
"c++",
"linked-list"
],
"Title": "Shift vowels towards the end of a Single Linked List"
} | 28554 |
<p>I want to list the contents of a folder and mail the list using a shell script. I Came up with the following script, please let me know if it is okay:</p>
<pre><code>for file in *
do
if [ -f "$file" ]; then
echo "$file" | mail -s "List of files" Someone@somewhere.com
fi
done
</code></pre>
| [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-16T16:06:28.967",
"Id": "44844",
"Score": "2",
"body": "this will send a separate email for *each* file. Is that your intent?"
}
] | [
{
"body": "<p>As @Juaniyyoo already mentioned, <code>ls</code> is the usual way to list all the files in a directory. I'm not sure if you really want to send a separate email for each file. If you do, you can iterate over each file with a <code>while</code> loop.</p>\n\n<pre><code>ls | while read file; do mail ... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-16T14:24:25.807",
"Id": "28555",
"Score": "4",
"Tags": [
"email",
"shell",
"unix"
],
"Title": "List contents of a folder using a shell script and mail the folder"
} | 28555 |
<p>This passes the value of true/false to model which I can use in my controller.</p>
<p>How can this be cleaned up?</p>
<pre><code><div data-role="fieldcontain" class="inline-toggle">
<label for="IsAuto">Auto <a href="#"><img class="smallInfo" src="/sites/dev-demo/mobile/assets/images/in... | [] | [
{
"body": "<p>None. However, it has several issues. Here it is, indented differently to avoid horizontal scroll:</p>\n\n<pre><code><div data-role=\"fieldcontain\" class=\"inline-toggle\">\n <label for=\"IsAuto\">Auto\n <a href=\"#\">\n <img class=\"smallInfo\" src=\"/si... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-16T15:46:54.923",
"Id": "28559",
"Score": "2",
"Tags": [
"html",
"asp.net",
"mvc",
"razor"
],
"Title": "Passing a true/false value to a model used in a controller"
} | 28559 |
<p>I'm making a calendar and this is one part of the larger project. This adds a tooltip with more information when a calendar event is clicked. It then disappears after 10 seconds, or earlier if a click is detected. The exception being if the click in on the tooltip itself. This code works but feels kind of "cheaty" t... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-16T15:58:50.427",
"Id": "44842",
"Score": "0",
"body": "are there any particular lines that look weird to you? all I can think of is, if you're using underscore.js you can use the `delay` function instead of `setTimeout`: http://unders... | [
{
"body": "<p>You could change the close tooltip fade out to use the jquery <a href=\"http://api.jquery.com/delay/\" rel=\"nofollow\">delay</a> method (assuming you're using jQuery 1.4+).</p>\n\n<p>Instead of this:</p>\n\n<pre><code>if(this.closeTool)\n clearTimeout(this.closeTool);\n\nthis.closeTool = setTi... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-16T15:56:25.023",
"Id": "28560",
"Score": "1",
"Tags": [
"javascript",
"jquery",
"optimization",
"object-oriented"
],
"Title": "Placing and removing a dynamic tooltip"
} | 28560 |
<p>Is this a good form validation script?</p>
<pre><code>$(document).ready(function() {
$("form").submit(function() {
var shouldSubmit = true;
$(this).children(":input:not(:button, [type=\"submit\"], [type=\"reset\"])").each(function() {
if ($(this).val() == "")
{
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-16T16:39:09.773",
"Id": "44846",
"Score": "0",
"body": "Have a look at this method: http://api.jquery.com/is/\nYou can save some work by doing something like `if($(\"input:radio\").is(\"checked))`. Also you can just return false right ... | [
{
"body": "<p>The if statements could be cleaner:</p>\n\n<pre><code> if ($(\"input:checkbox\").length > 0 && $(\"input:checkbox:checked\").length == 0)\n {\n shouldSubmit = false;\n }\n\n if ($(\"input:radio\").length > 0 && $(\"input:radio:checked\").length == 0)\n {... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-16T16:08:40.073",
"Id": "28562",
"Score": "1",
"Tags": [
"javascript",
"jquery",
"validation",
"form"
],
"Title": "Basic form validation script"
} | 28562 |
<p>Is this try/catch block written correctly?</p>
<pre><code>public String execute() throws Exception{
try{
//Do blah
return "success"; //Assuming everything goes well, return success.
}catch (Exception e){
e.printStackTrace();
}
return "error";
}
</code></pre>
<p>Should the r... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-16T17:52:48.423",
"Id": "44858",
"Score": "3",
"body": "Why are you not returning a Boolean? Can you elaborate on what this code does? It looks like you should be either returning a bool silently in the case of failure (if the exceptio... | [
{
"body": "<p>My style:</p>\n\n<pre><code>public String execute() throws Exception{\n String result=\"error\";\n try{\n //Do blah\n result=\"success\"; //Assuming everything goes well, return success.\n }catch (Exception e){\n e.printStackTrace();\n }\n return result; \n}\n</... | {
"AcceptedAnswerId": "28594",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-16T17:33:16.167",
"Id": "28570",
"Score": "0",
"Tags": [
"java"
],
"Title": "Try/catch block inside a method that returns String"
} | 28570 |
<p>I'm trying to see if there is a better way to do this when I just need one column with one row. Do not mind the lack of use of a prepared statement, I will put it in.</p>
<pre><code>public <T> T getValueFromDb(String col, String table, String cond, Class<T> returnValueClass) {
T val = null;
tr... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-17T09:04:28.240",
"Id": "44914",
"Score": "0",
"body": "What should one do when a `null` is returned from this method? Does not a value meeting the passed in condition exist? Or did an exception occurred while trying to read from the D... | [
{
"body": "<p>Using polymorphism is the way to get an great solution. You are receiving the class in your method just to infer the the return type while you could abstract the idea of conversion and use it to do the inference too. Let's create an interface to convert the result and its implementations:</p>\n\n<... | {
"AcceptedAnswerId": "28586",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-16T17:42:21.050",
"Id": "28572",
"Score": "1",
"Tags": [
"java",
"jdbc"
],
"Title": "Generic DB Value Getter"
} | 28572 |
<p>I have this data for the knapsack problem:</p>
<ul>
<li>List of product prices = <code>MENU</code></li>
<li>Most popular product count = <code>MOST_POPULAR_COCKTAIL</code></li>
<li>Knapsack price = <code>CASH</code></li>
<li>Knapsack length = <code>CHECK_LEN</code></li>
</ul>
<p>I need get all knapsack combination... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-16T18:00:51.157",
"Id": "28574",
"Score": "3",
"Tags": [
"python",
"performance",
"algorithm",
"combinatorics"
],
"Title": "Python knapsack program"
} | 28574 |
<p>I think the arrays here are slowing down my code due to incorrect usage. </p>
<p>There is a lot of stuff going on here, it's understandable if nobody responds. Just looking for some pointers. Thanks.</p>
<pre><code>for MN in xrange(RowModel,TotalModels):
if(MN%5000==0):print 'Examining models', MN,'to', (MN+5... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-16T19:05:26.670",
"Id": "44875",
"Score": "0",
"body": "Where did you read that?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-16T19:12:09.257",
"Id": "44876",
"Score": "0",
"body": "Looks lik... | [
{
"body": "<p>You should almost never be using <code>np.append</code>, numpy arrays are designed to be used as fixed size arrays. <code>np.append</code> creates a whole new array each time and will thus fairly expensive. </p>\n\n<p>The first thing is that you should create the array at its full size. Then assig... | {
"AcceptedAnswerId": null,
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-16T18:53:43.797",
"Id": "28582",
"Score": "2",
"Tags": [
"python",
"array",
"numpy"
],
"Title": "What would be the optimal way to address these arrays"
} | 28582 |
A weak reference is a reference that does not protect the referenced object from deallocation | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-17T02:04:05.410",
"Id": "28591",
"Score": "0",
"Tags": null,
"Title": null
} | 28591 |
<p><strong>Edit:</strong> The method call discussed is a public extension method in a shared library. I'd like it to be safe for others to call.</p>
<p>A little background: I'm maintaining an ancient system written in ASP.Net Webforms. There are lots of validation groups for different user controls, and we want to... | [] | [
{
"body": "<p>You could filter out the type of controls you do not want to iterate. Let's say for example that you only want to get the validationMessages from only a <code>UserControl</code>, you can filter them out of the <code>Controls</code> property by using a bit of LinQ:</p>\n\n<pre><code>public static I... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-17T14:47:43.060",
"Id": "28602",
"Score": "2",
"Tags": [
"c#",
"asp.net",
"validation"
],
"Title": "Is there a faster way to get ASP.Net Validation messages in a Page or UserControl?... | 28602 |
<p>I'd like some opinions about my approach at using SQLite databases in android. Everything seems to work very well, but there may be something wrong that I hadn't noticed.</p>
<p>I don't like working with create/alter table statements in code, so I prefer creating my database with some SQLite client out there and pu... | [] | [
{
"body": "<p>The code looks fine to me but it is a bit odd because <a href=\"http://developer.android.com/guide/topics/data/data-storage.html#db\">the official docs recommend creating a <code>SQLiteOpenHelper</code> subclass</a> to handle database interaction. And if you use one <code>SQLiteOpenHelper</code> i... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-17T15:21:57.873",
"Id": "28605",
"Score": "5",
"Tags": [
"java",
"android",
"sqlite"
],
"Title": "Android SQLite Database management"
} | 28605 |
<p>I've taken a stab at making a context menu using BackboneJS.</p>
<p>Here's the overall structure:</p>
<blockquote>
<p>Collections:</p>
<ul>
<li>/collection/contextMenuGroups</li>
<li>/collection/contextMenuItems</li>
</ul>
<p>Models:</p>
<ul>
<li>/model/contextMenu</li>
<li>/model/contex... | [] | [
{
"body": "<p>I like the code as is,</p>\n\n<ul>\n<li>Use of <code>'use strict'</code></li>\n<li>JsHint cannot find anything</li>\n<li>Readable, well named variables</li>\n<li>No obvious copy pasting or repeated code</li>\n</ul>\n\n<p>As for events, I would </p>\n\n<ul>\n<li>Wait until everything is rendered</l... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-17T16:45:56.697",
"Id": "28606",
"Score": "3",
"Tags": [
"javascript",
"jquery",
"backbone.js"
],
"Title": "A generic context menu with generically bound events"
} | 28606 |
<p>Is this acceptable for readability or would it be better to refactor it into smaller methods?</p>
<p>Tips? Comments? Examples?</p>
<pre><code>def save_with_payment
if valid?
charge = Stripe::Charge.create(:amount => (self.plan.price * 100).to_i,
:currency => 'usd', :... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-18T03:37:20.617",
"Id": "44959",
"Score": "0",
"body": "Is it a joke?.."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-18T06:51:47.193",
"Id": "44962",
"Score": "0",
"body": "@Nakilon, are you ... | [
{
"body": "<p>I would refactor the <code>Charge.create</code> to a separate class.</p>\n\n<p>Because one the principies that we have respect is \"our code reader should not read the details of the implementation for understand the code\"</p>\n",
"comments": [
{
"ContentLicense": "CC BY-SA 3.0"... | {
"AcceptedAnswerId": "28655",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2013-07-17T16:48:42.710",
"Id": "28607",
"Score": "1",
"Tags": [
"ruby",
"e-commerce"
],
"Title": "Saving a subscription plan with a payment"
} | 28607 |
<p>I frequently write Python scripts that require three command line arguments:</p>
<ol>
<li><code>config_file</code> — A CSV configuration file</li>
<li><code>input_dir</code> — The directory containing the input files to be processed</li>
<li><code>output_dir</code> — The directory where the output files should be s... | [] | [
{
"body": "<p>You can address some of this by subclassing ArgumentParser. This will allow you hide the lambda calls that may turn off some and leave you scratching your head if you come back to that file later.</p>\n\n<p><strong>Your Script</strong> </p>\n\n<pre><code>if __name__ == \"__main__\":\n # Proce... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-17T17:06:31.357",
"Id": "28608",
"Score": "5",
"Tags": [
"python"
],
"Title": "Checking if CLI arguments are valid files/directories in Python"
} | 28608 |
<p>I've got a class with a property <code>TotalCost</code>, which is calculated by some simple math of two other properties, <code>CostOfFood</code> and <code>NumberOfPeople</code>. The code works the way I want it to, but I was wondering if this is a satisfactory method in the long run of application development, a b... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-17T18:11:20.793",
"Id": "44930",
"Score": "2",
"body": "Your incoming parameter to the `CalculateFoodCost()` isn't doing anything, in either case; I'd probably remove it (especially as you're not actually obeying the contract, as your ... | [
{
"body": "<p>The C# property model allows external classes to inspect (or set) a given member as though it were a public 'field', and the implementation details are left to the property's accessor and mutator. In your case, you want to expose TotalCost and hide the implementation details about how it is deriv... | {
"AcceptedAnswerId": "28612",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-17T18:01:07.087",
"Id": "28609",
"Score": "16",
"Tags": [
"c#"
],
"Title": "When one property is calculated from another"
} | 28609 |
<p>Yesterday, I introduced a bug into our codebase by calling <code>#titleize</code> on a string that could possibly come in as <code>nil</code>:</p>
<pre><code>def route
medication.route_name.titleize
end
</code></pre>
<p>This threw an error on production and a coworker fixed this by adding <code>try</code>:</p>
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2016-06-18T20:35:38.720",
"Id": "247176",
"Score": "0",
"body": "Smiley for you :-D just for 'Trying to avoid #try'"
}
] | [
{
"body": "<blockquote>\n <p>I introduced a bug into our codebase by calling #titleize on a string that could possibly come in as nil</p>\n</blockquote>\n\n<p>When a problem is so pervasive, it's usually a sign that there is a conceptual problem with the language itself, some call it <a href=\"http://en.wikipe... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-17T18:06:44.123",
"Id": "28610",
"Score": "8",
"Tags": [
"ruby",
"ruby-on-rails",
"error-handling",
"null"
],
"Title": "Handling nil: Trying to avoid #try"
} | 28610 |
<p>Straight to the point: Can you give me pointers on how to make this code more maintainable? In the future, I want to add more more things to this, but first it should be easy to maintain/read. Should making a library be considered?</p>
<p>What it does:</p>
<p>Takes input from the serial line and converts it to ser... | [] | [
{
"body": "<p>I'll start by breaking the code down into different files. There are a many <code>#define</code> and <code>const int</code> here. If I am correct that will definitely grow with your project. Having all the constants in a different file is always a good idea if you are considering making it even mo... | {
"AcceptedAnswerId": "28618",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-17T18:15:02.473",
"Id": "28611",
"Score": "3",
"Tags": [
"c",
"arduino",
"serial-port",
"device-driver"
],
"Title": "Servo commands based on serial port input"
} | 28611 |
<p>I'm trying to re-learn some JS fundamentals and wondered if anyone knowledgabe could tell me if I'm doing something very wrong in my approach to this simple word counting class. </p>
<p>I want to create a class that takes arbitrary text and returns information about its wordcount, frequency of words, etc. One of th... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-17T21:11:16.757",
"Id": "44939",
"Score": "0",
"body": "I am not sure what you are trying to do really..."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-17T21:14:52.360",
"Id": "44940",
"Score": "0... | [
{
"body": "<p>Conceptually, I feel like you are doing this backwards. You should be storing an array of strings instead of repeatedly splitting a string into an array.</p>\n\n<p>Here's my take on it:</p>\n\n<pre><code>function WordCounter(){\n this.words = []; // You should just use an array. It makes more se... | {
"AcceptedAnswerId": null,
"CommentCount": "7",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-17T20:52:20.477",
"Id": "28615",
"Score": "0",
"Tags": [
"javascript"
],
"Title": "Critique wanted on JS"
} | 28615 |
<p>I like to keep my code organized, usually in several files. It is good for CSS.
For instance:</p>
<p>I have three files:</p>
<ul>
<li>First - <code>layout.html</code>, this is the main template.</li>
<li>Second - <code>grid.css</code> is style sheet where I decribe position of all elements.</li>
<li>Third - <code>... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-18T19:48:44.907",
"Id": "45010",
"Score": "0",
"body": "This question seems a little off topic for CR: [your answer is provided along with the question, and you expect more answers: “I use ______ for ______, what do you use?”](http://... | [
{
"body": "<p>Here is my directory structure:</p>\n\n<pre><code>./\n app/\n theme/\n</code></pre>\n\n<p>Here is my CSS build script:</p>\n\n<pre><code>#!/bin/bash\n\n# Directory to write the minified CSS files.\nOUTPUT_DIR=../css\n\nmkdir -p $OUTPUT_DIR/app\n\nlessc -x ui.less > $OUTPUT_DIR/ui.css\n\n# Cre... | {
"AcceptedAnswerId": "28619",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-17T21:21:13.070",
"Id": "28616",
"Score": "6",
"Tags": [
"html",
"css",
"html5"
],
"Title": "CSS code organizing"
} | 28616 |
<p>I am trying to return a value (<code>a.tnAddress</code>) from a custom class based on a lookup (<code>foreach</code> loop). Depending on the type of transaction, I will need to do the <code>foreach</code> loop based on different properties (<code>sExecID</code>, <code>iMsgSeqNum, or</code>sClOrderID<code>). I pref... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-18T00:39:58.333",
"Id": "44950",
"Score": "0",
"body": "Do you think the performance is poor? Your code seems good."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-18T00:49:53.967",
"Id": "44951",
"... | [
{
"body": "<p>This will add the use of <a href=\"http://msdn.microsoft.com/en-us/library/vstudio/bb397926.aspx\">LINQ</a> to clean up the code the way you want:</p>\n\n<pre><code>private TreeNode GetNodeAddress(cls_Transactions trPassedInTransaction)\n{\n //a predicate to pass to the FirstOrDefault method\n ... | {
"AcceptedAnswerId": "28623",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-18T00:38:11.047",
"Id": "28622",
"Score": "3",
"Tags": [
"c#",
"lookup"
],
"Title": "Returning a value based on a lookup"
} | 28622 |
<p>I am trying to find the best way to structure this. I want to avoid <code>if</code>-<code>else</code> statements and reduce the number of code lines.</p>
<pre><code>def get_parent(relationships,GU)
parent = []
if relationships.class == Array
relationships.each do |y|
if y[:relationship_roles][:relatio... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-18T02:49:40.797",
"Id": "44958",
"Score": "2",
"body": "You say you have a loop, but you have no loop. You must mean something else. If you had a loop, you would have `loop..do..end`. What are you trying to get rid of? Nested if st... | [
{
"body": "<p><em>disclaimer: my ruby knowledge is practically nonexistent so the code below might be completely rubbish ruby-wise.</em></p>\n\n<p>I see two code smells in this code: <a href=\"http://c2.com/cgi/wiki?DuplicatedCode\" rel=\"nofollow\">duplicate code</a> and <a href=\"http://c2.com/cgi/wiki?Switch... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-18T01:50:23.183",
"Id": "28627",
"Score": "1",
"Tags": [
"ruby",
"ruby-on-rails"
],
"Title": "Getting parent relationship"
} | 28627 |
<p>In this code, I'm getting the json from backend. Once I find the json availability, I loop and make 5 columns. Once the columns are made, I append after the legend of my form.</p>
<p>Can this be improved any further?</p>
<pre><code>if(data.hasOwnProperty("allLocales")){
var col0 = $("<fieldset /&... | [] | [
{
"body": "<p>First you should not create on function for each column.\nIn place of :</p>\n\n<pre><code>var col0 = $(\"<fieldset />\"), \n col1 = $(\"<fieldset />\"),\n col2 = $(\"<fieldset />\"),\n col3 = $(\"<fieldset />\"),\n col4 = $(\"<fieldset />\");\n</code></pre... | {
"AcceptedAnswerId": "28643",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-18T11:28:44.283",
"Id": "28640",
"Score": "1",
"Tags": [
"javascript",
"jquery",
"json"
],
"Title": "Object iteration and appending to form"
} | 28640 |
<p>I have the next bilinear resizing algorithm, and even though I use fixed point is still quite slow for my requirements. In the past I tried to cache some values in tables but the improvement was of a few not noticeable milliseconds.</p>
<p>Is any other way I can improve the speed? As this is intended for ARM proces... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-08-10T19:53:26.093",
"Id": "46819",
"Score": "0",
"body": "Why are you declaring all the variables which are only used in the loop at the beginning of the function? You know that this doesn't change anything reagding performance? Parallel... | [
{
"body": "<p>You could be saving important variables that are being used frequently in the register like the following:</p>\n\n<pre><code>register const unsigned int targetWidth\n</code></pre>\n\n<p>Make sure memory accesses are cache-optimized, i.e. clumped together.</p>\n\n<p>Investigate if signed/unsigned f... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-18T13:24:55.490",
"Id": "28645",
"Score": "6",
"Tags": [
"optimization",
"performance",
"c",
"image"
],
"Title": "Bilinear resizing algorithm"
} | 28645 |
<p>As explained in my <a href="http://cfmlblog.adamcameron.me/2013/07/replacewithcallback-udf-for-cflib-and.html">blog article</a>…</p>
<blockquote>
<p>I was looking up the docs for <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String/replace">Javascript's String replace()... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-18T21:48:07.657",
"Id": "45014",
"Score": "2",
"body": "I find it odd that you don't scope your arguments, any reason for that?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-25T12:43:37.123",
"Id": "4... | [
{
"body": "<p>If the idea is to model this function on JavaScript's <code>String.replace()</code>, then there is a \"bug\". In JavaScript, when doing a global replace, the last argument passed to the callback is always the <em>original unmodified string</em>, not the string that may have had some of the replac... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-18T13:27:05.717",
"Id": "28646",
"Score": "6",
"Tags": [
"regex",
"callback",
"coldfusion",
"cfml"
],
"Title": "replaceWithCallback() UDF"
} | 28646 |
<p>I am porting a linear optimization model for power plants from <a href="http://gams.com/" rel="nofollow">GAMS</a> to <a href="https://software.sandia.gov/trac/coopr/wiki/Pyomo" rel="nofollow">Pyomo</a>. Models in both frameworks are a collection of sets (both elementary or tuple sets), parameters (fixed values, defi... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-21T11:18:49.763",
"Id": "45246",
"Score": "0",
"body": "Is there any necessity for it to be an expression?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-22T15:51:30.360",
"Id": "45338",
"Score": "... | [
{
"body": "<p>First of all, use helper functions or explicit for loops.</p>\n\n<p>E.g. you're looping over <code>m.tm</code> four times. This can be done in a single loop. It might need more lines of code, but it will get much more readable.</p>\n\n<p>E.g.</p>\n\n<pre><code>def res_stock_total_rule(m, co, co_ty... | {
"AcceptedAnswerId": "28649",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-18T14:16:10.587",
"Id": "28647",
"Score": "4",
"Tags": [
"python",
"matrix",
"pandas"
],
"Title": "Long expression to sum data in a multi-dimensional model"
} | 28647 |
<p>I've written a little function that iterates over two iterables. The first one returns an object which is used to convert an object of the second iterable. I've got a working implementation, but would like to get some feedback.</p>
<p>A simple use case would look like this:</p>
<pre><code>list(serialize([String(),... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-18T15:25:27.507",
"Id": "44993",
"Score": "0",
"body": "you could be checking to see if the lengths of the two lists match instead of messing around with `izip`?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013... | [
{
"body": "<p>There is no (general) way of telling the difference between an infinite and a finite iterator.</p>\n\n<p><code>types</code> might be a generator that stops yielding after a million items have been yielded. The only fool-proof way of telling would be to consume the generator up to the point where ... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-18T14:30:07.373",
"Id": "28648",
"Score": "1",
"Tags": [
"python",
"serialization"
],
"Title": "Iterating over two iterables"
} | 28648 |
<p>I'm trying to learn how to use threads to generate lots of random numbers. In particular, I'd like know:</p>
<ul>
<li><p>Is the following code thread safe? (I think the histogram class is the only one that requires special attention)</p></li>
<li><p>Are there implication for the 'randomness' of my numbers when they... | [] | [
{
"body": "<p>There are a couple of things to worry about wrt to shared memory.</p>\n\n<p>First, <code>histogram<T>::begin</code> and <code>histogram<T>::end</code> provide unguarded access to the container. You're using them safely here, but you should generally not provide such unguarded access. O... | {
"AcceptedAnswerId": "28711",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-18T15:40:58.613",
"Id": "28650",
"Score": "6",
"Tags": [
"c++",
"multithreading",
"c++11",
"random"
],
"Title": "Generating random numbers in multiple threads"
} | 28650 |
<p>I have an unusual data structure that I need to search - the structure is the result of parsing a JSON file returned from an HTTP request.</p>
<p>The top-level object is an Array, but from top to bottom I have <code>Array->Hash->Array->Hash</code>.</p>
<p>I'm writing code to check the value of a given key... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-18T16:26:42.387",
"Id": "45000",
"Score": "0",
"body": "Please paste a short (but complete) example of that data-structure, otherwise you are forcing everyone to prepare one for testing purposes."
},
{
"ContentLicense": "CC BY-... | [
{
"body": "<p>You can iterate over the hashes/arrays using a custom enumerator (modified from a StackOverflow answer <a href=\"https://stackoverflow.com/a/3748761/1614607\">here</a>):</p>\n\n<pre><code>def dfs(obj, &blk)\n return enum_for(:dfs, obj) unless blk \n yield obj if obj.is_a? Hash\n if obj... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-18T16:00:23.090",
"Id": "28652",
"Score": "2",
"Tags": [
"ruby",
"iteration"
],
"Title": "Eliminating nested each"
} | 28652 |
<p>As a part of a job test, I wrote following implementation of the Actor execution model:</p>
<pre><code>import java.util.LinkedList;
import java.util.Queue;
import java.util.concurrent.Executor;
public abstract class Actor implements Runnable {
private final Executor executor;
/** current token */
private Mes... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-06T13:24:13.990",
"Id": "49136",
"Score": "0",
"body": "You aren't being consistent with when you use `this.` to access a member variable. `run()` does not require `this.` to access message since there is not local variable with that n... | [
{
"body": "<p>I don't see any immediate synchronization issues. However that does not necessarily mean there aren't any. One synchronization design flaw is that you lock on <code>this</code>, which basically allows other classes to also acquire the lock, and screw with the inner workings of your implementation.... | {
"AcceptedAnswerId": "41108",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-18T16:01:51.797",
"Id": "28653",
"Score": "3",
"Tags": [
"java",
"multithreading",
"actor"
],
"Title": "Does this Actor implementation has synchronization problems?"
} | 28653 |
<p>I've got the imperative styled solution working perfectly.
What I'm wondering is how to make a recursive branch and bound.</p>
<p>This is my code below. Evaluate function returns the optimistic estimate, the largest possible value for the set of items which fit into the knapsack (linear relaxation).</p>
<p>For som... | [] | [
{
"body": "<p>Here is a 'wanna-be functional' solution in java which might help you (it has gone through a set of test cases so I believe it works correctly)</p>\n\n<pre><code>private double bestBound;\n\npublic Knapsack.KnapsackResult solve() {\n Cons<Knapsack.Item> list = Cons.from(items);\n bestB... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-18T16:56:02.267",
"Id": "28656",
"Score": "4",
"Tags": [
"recursion",
"scala",
"knapsack-problem"
],
"Title": "Recursive branch and bound Knapsack solution"
} | 28656 |
<p>I have written the following algorithm (for Android/NDK) to apply levels to a bitmap. The problem is that it is really very slow. On a fast device such as the SGSIII, it can take up to 4 seconds for an 8MP image. And on devices with ARMv6 takes ages (over 10 seconds). I know that can be speed up with NEON instructi... | [] | [
{
"body": "<p>Depending on your compiler, this advice might or might not have an effect. As a rule of thumb, let's try to give the compiler and the reader as many hints as possible and let's make things as simple as it can be.</p>\n\n<pre><code>unsigned int pixelIndex = 0;\nfor (int y = 0; y < height; y++)\n... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-18T18:54:22.693",
"Id": "28661",
"Score": "5",
"Tags": [
"c++",
"algorithm",
"performance",
"android",
"image"
],
"Title": "Image-processing algorithm on mobile device"
} | 28661 |
<p>I am currently migrating a large backbone application over to Marionette and am curious as to the opinions on what is a better design for mediating activity between modules.</p>
<p>I have an Application that have several Modules where an action in one module might cause activity to happen in other modules.</p>
<p>... | [] | [
{
"body": "<p>I have the exact same quandary (and found this question googling for answers). On first read through my opinion was that triggering events on the modules themselves was the best approach on the basis that this loosens any coupling between the modules and other components. However, having given it ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-18T21:45:57.763",
"Id": "28663",
"Score": "1",
"Tags": [
"javascript",
"design-patterns",
"backbone.js",
"mediator"
],
"Title": "Marionette.js Mediator ('global' commands vs app ... | 28663 |
<p>I tried to write a naive Bayes classifier to classify OkCupid profiles, and I was wondering if you could give me feedback on my code. The classifier performs no better than chance and the coding style is probably not great either. I had a training set of 20 good profiles and 20 bad profiles, and a test set of 16 g... | [] | [
{
"body": "<pre><code>#!/usr/bin/python\n\n# Naive Bayes classifier for OkCupid data. The features are the words in\n# the profile and the classes are HIGH and LOW. This is used to\n# predict the rating I would give a profile.\n\n# TODO: tweak the classifier so it works better.\n\nfrom subprocess import call\... | {
"AcceptedAnswerId": "28667",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-18T21:48:10.773",
"Id": "28664",
"Score": "0",
"Tags": [
"python"
],
"Title": "Naive Bayes classifier for OKCupid profiles"
} | 28664 |
<p>The code below is designed to deal with this situation:</p>
<blockquote>
<p>There is a <strong>Battle</strong> environment with <strong>Characters</strong>; these Characters obviously have certain characteristics and abilities, and they need to be able to use <strong>Items</strong> from an inventory.</p>
</blockq... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-18T23:07:10.053",
"Id": "45016",
"Score": "2",
"body": "I would structure `Battle` as more of a namespace, right now you have it as a catch-all. I don't have much time to go into more detail now, but I'll try to find some time in the n... | [
{
"body": "<p>As Shmiddty said, you want your <code>Battle</code> object to be more of a namespace providing access to the modules:</p>\n\n<pre><code>var Battle = function () {}\n\nBattle.Character = (function (/* dependencies */) {\n\n // constructor\n var Character = function (name) {\n this.name = name... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-18T22:46:42.253",
"Id": "28666",
"Score": "3",
"Tags": [
"javascript",
"modules",
"closure"
],
"Title": "Correctly dealing with closures and modularity in Javascript"
} | 28666 |
<p>I have inside a Backbone model <code>validate</code> function several <code>if</code> statements:</p>
<pre><code>if(!attrs.firstAttr) errorMsg+="first attr mandatory";
if(!attrs.secondAttr) errorMsg+="second attr mandatory";
</code></pre>
<p>as you can see there is a lot of repetition (I have actually 10 fields to... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-19T14:33:33.997",
"Id": "45061",
"Score": "0",
"body": "Have you tried to use Backbone.Validation plugin? It helps a lot! https://github.com/thedersen/backbone.validation"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDa... | [
{
"body": "<p>I would approach that like this:</p>\n\n<p>Have an array with all the fields you</p>\n\n<pre><code>var mandatoryFields = ['firstAttr','secondAttr'];\n</code></pre>\n\n<p>Then have a validate function that takes <code>attrs</code>, <code>mandatoryFields</code> and <code>errors</code></p>\n\n<pre><c... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-19T01:24:22.450",
"Id": "28670",
"Score": "2",
"Tags": [
"javascript",
"beginner",
"validation",
"backbone.js",
"underscore.js"
],
"Title": "Validator function in Backbone"
} | 28670 |
<p>I'd like to know how this program can be improved. Any comments or critiques are most welcome.</p>
<pre><code>#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <errno.h>
#define MAX 10000
#define FOUND 1
#define NOT_FOUND 0
#define DEAD 0
#define LI... | [] | [
{
"body": "<p>Don't use macros to conditionally change code.<br>\nUse the macros to define appropriate macros that can be used in code:</p>\n\n<pre><code>#ifdef LINUX /*linux version*/\n wordDic = fopen(\"wordDIC\" , \"r\");\n if(wordDic == NULL)\n {\n perror(\"wordDIC\");\n ... | {
"AcceptedAnswerId": "28673",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-19T02:23:39.770",
"Id": "28671",
"Score": "6",
"Tags": [
"beginner",
"c",
"game",
"hangman"
],
"Title": "Improving Hangman game"
} | 28671 |
<p>I am trying to build a simple C#/.Net console application that runs three iterations (see code below). The process runs as intended, but because of how many iterations there are, it can run upwards of 15 to 20 minutes. I intend to run through a list of nodes that would require individual simulations. Therefore requi... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-19T03:35:25.707",
"Id": "45018",
"Score": "1",
"body": "So the first thing that comes to mind is that you could make a queue of numbers that you would plug into a oe.Solver. have a few threads (maybe about 4) work on them in parallel. ... | [
{
"body": "<p>If <code>oe.Solver()</code> is your slowdown, you're not going to be able to get a huge improvement, but you can get some by parallelizing all the calls to it. </p>\n\n<p>Replace your loops with this version:</p>\n\n<pre><code>List<double[]> data = new List<double[]>();\nfor (i = (tC ... | {
"AcceptedAnswerId": null,
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-19T02:40:27.400",
"Id": "28672",
"Score": "3",
"Tags": [
"c#",
"performance",
".net"
],
"Title": "Faster Iteration Functions"
} | 28672 |
<p>Suppose I need to process a list of list of list of many objects, where the data usually comes from third party APIs.</p>
<p>For the sake of an example, lets assume we have many users, and for each user we get many days of data, and for each day you get many events. We want to process all of these objects and store... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-20T15:54:07.330",
"Id": "45166",
"Score": "0",
"body": "Your third example could be rewritten using generators, avoiding the creation of temporary lists. Also using `itertools.chain.from_iterable` could be useful to flatten the iterati... | [
{
"body": "<p>Your third approach is the most pythonic, in the sense that you create a function for each specific purpose, avoiding repetition and giving the user more options (process the users, only the days, etc...) and the option to save or not to save the processed data to the database.</p>\n\n<p><strong>I... | {
"AcceptedAnswerId": "28691",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-19T04:20:59.267",
"Id": "28674",
"Score": "1",
"Tags": [
"python",
"design-patterns"
],
"Title": "Deep iterations with side effects"
} | 28674 |
<p>So, this is a thing. I've got a simple little 2D game where a character can run left and right and jump. My problem here is that I've got two velocities, xVel and yVel, that I need to increment as the character runs in a certain direction, and stop altogether as the player stops moving altogether. Right now, I'm onl... | [] | [
{
"body": "<p>The movement of your character is going to feel a bit unnatural in this setup. When you hit the left key, the character will immediately start moving left at full speed; as soon as you stop hitting the key, the character will stop dead. I suggest modeling the character's velocity as well as its po... | {
"AcceptedAnswerId": "28686",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-19T04:27:36.897",
"Id": "28675",
"Score": "0",
"Tags": [
"java",
"opengl",
"physics"
],
"Title": "Issue regarding game velocity"
} | 28675 |
<p>This is a method which creates an array of all possible consecutive substrings from a string:</p>
<pre><code>def get_seperated_tokens(query)
result = []
length = query.split.count
tokens = query.downcase.strip.split(' ')
length.times do |i|
length.times do |j|
result << tokens[i..j].join(' '... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-19T11:08:32.793",
"Id": "45037",
"Score": "0",
"body": "http://www.ruby-doc.org/core-1.9.3/Array.html#method-i-combination"
}
] | [
{
"body": "<p>Are you familiar with <a href=\"https://en.wikipedia.org/wiki/Functional_programming\" rel=\"nofollow\">functional programming</a>? (my page on the subject: <a href=\"https://code.google.com/p/tokland/wiki/RubyFunctionalProgramming\" rel=\"nofollow\">FP with Ruby</a>). Your code feels clunky becau... | {
"AcceptedAnswerId": "28757",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-19T08:21:22.423",
"Id": "28679",
"Score": "4",
"Tags": [
"strings",
"ruby"
],
"Title": "Creating consecutive words from a string"
} | 28679 |
<p>Following on from a question about <a href="https://codereview.stackexchange.com/questions/582/handling-com-exceptions-busy-codes">handling-com-exceptions-busy-codes</a> I would like to know if the following model is the accepted best practice of handling Excel COM busy messages when accessing the Excel COM object m... | [] | [
{
"body": "<p>You're missing the <code>Thread.Sleep(500);</code> call from the linked post's solution, which is much, much better than what you've posted here:</p>\n\n<pre><code>private void TryUntilSuccess(Action action)\n{\n bool success = false;\n while (!success)\n {\n try\n {\n ... | {
"AcceptedAnswerId": "35469",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-19T08:49:19.300",
"Id": "28680",
"Score": "4",
"Tags": [
"c#",
"exception-handling",
"excel",
"com"
],
"Title": "Is brute force the accepted best practice for handling Excel C... | 28680 |
<p>I'm making my own <em>script editor</em> (in this case for <code>Arma: Cold War Assault</code>) because I want to learn and this is challenging enough. </p>
<p>Let me just get this out of the way: <strong><em>please don't tell me that I should do easier things. I want to do this anyway</em></strong>.</p>
<p>So, ba... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-26T05:55:33.047",
"Id": "45715",
"Score": "0",
"body": "scanner.match().start() returns 0 whenever it starts a new line, so it doesn't know it is in a new line..."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "201... | [
{
"body": "<p>Currently the it's <code>O(n)</code> where <code>n</code> is the length of the text inside the <code>JTextPane</code>.\nYou could reduce it if you process only the modified regions of the document in the event listener.\nI think <a href=\"http://docs.oracle.com/javase/7/docs/api/javax/swing/event/... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-19T09:26:27.580",
"Id": "28681",
"Score": "1",
"Tags": [
"java",
"algorithm",
"performance",
"strings"
],
"Title": "Custom Script Editor"
} | 28681 |
<p>Given a production module like this:</p>
<pre><code>function ($) {
var
showForm = function () {
$.get(url, function (html) {
$('body').append(html);
});
};
return {
showForm: showForm
};
});
</code></pre>
<p>I have written the following unit test:</p>... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-19T11:22:48.053",
"Id": "45041",
"Score": "1",
"body": "First write a failing test. Then make it pass by writing non-test code only. Then you should be sure you haven't faked _everything_."
}
] | [
{
"body": "<p>I'm not quite sure what you mean by \"abstracting out the call...\", but given that the \"production module\" actually looks like that, then I'd say that you have a perfectly valid little test there.</p>\n\n<p>It is good to hear that you really are interested in making sure that your test cases ar... | {
"AcceptedAnswerId": "28738",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-19T10:27:05.563",
"Id": "28684",
"Score": "0",
"Tags": [
"javascript",
"unit-testing"
],
"Title": "Is my JavaScript test actually testing anything worthwhile here"
} | 28684 |
<h1>What?</h1>
<p>I have a reference counted dynamic byte array written in C. I'm currently using this implementation in a FIFO fashion. Particularly reading data from files into the arrays, then parsing the data in the array byte by byte. </p>
<p>I'm looking for feedback on anything! Even the decision to use a dynam... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-19T12:01:29.607",
"Id": "45044",
"Score": "0",
"body": "A quick note. \"memory.h\" contains the functions `assert_malloc` and `assert_calloc`, they are wrapper functions that raises an assertion if `malloc` or `calloc` fails."
},
{... | [
{
"body": "<p>This looks mostly good to me. Your code looks like fairly clean C. I have some comments:</p>\n\n<ul>\n<li><p>I think <code>capacity</code> is a better name than <code>capability</code>.</p></li>\n<li><p>I would avoid calling your header <code>memory.h</code>, since <code>memory</code> is a header ... | {
"AcceptedAnswerId": "28697",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-19T11:50:42.697",
"Id": "28690",
"Score": "2",
"Tags": [
"c",
"array",
"linux"
],
"Title": "Reference counted dynamic byte array"
} | 28690 |
<h1>What?</h1>
<p>I have an algorithm that parses comma separated lists of unsigned 32-bit ints from strings. Here is an example of what a list could look like: </p>
<pre><code>1302,51,2312,2,52
</code></pre>
<p>The algorithm uses a custom data structure called <code>parse_input</code> which is a data structure that... | [] | [
{
"body": "<ul>\n<li><p>Having tests is good. I recommend using a test framework, for example <a href=\"https://code.google.com/p/googletest/\">googletest</a>.</p></li>\n<li><p>You are obviously using C99 (otherwise parts of your code wouldn't compile). C99 does not require variable instantiation at the beginni... | {
"AcceptedAnswerId": "28705",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-19T12:19:17.967",
"Id": "28694",
"Score": "4",
"Tags": [
"c",
"algorithm",
"parsing",
"lookup",
"c99"
],
"Title": "Algorithm (and tests) to parse lists of unsigned 32-bit ... | 28694 |
<p>I am learning about heaps, and I have found two ways of building them from a given array: I am trying to build up a MAX Heap.</p>
<h3>1. Top-down approach</h3>
<p>Here I check for every element to see if it is at the correct position or not. By using a function called <code>restoreUp</code>, in which every key is ... | [] | [
{
"body": "<p>Someone with more expertise on algorithms may provide a more concrete answer to your specific algorithms. However, I would like to point out two things on a general note:</p>\n\n<h3>1. Do the math.</h3>\n\n<p>Mathematically determining the complexity of an algorithm usually isn't <em>that</em> har... | {
"AcceptedAnswerId": "28710",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-19T12:23:54.877",
"Id": "28695",
"Score": "3",
"Tags": [
"optimization",
"c",
"algorithm"
],
"Title": "Build a binary-heap from an array, which method is more efficient and why"
} | 28695 |
<p>I was doing timing with variations of function <code>largest_prime_factor</code>. I was able to write a better one <code>largest_prime_factor2</code>. There were some repetitions in the new function so I wrote another function <code>largest_prime_factor3</code>. </p>
<p>I thought the 3rd one has to be faster than t... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-19T13:45:33.890",
"Id": "45056",
"Score": "0",
"body": "As this question is about time efficiency any discussions for this can take place in [this chat room](http://chat.stackexchange.com/rooms/9695/discussion-about-timing-in-python). ... | [
{
"body": "<p>Usually, splitting your code into different smaller functions is a good idea as it makes things easier to read, to reuse and to test.</p>\n\n<p>However, this comes at a (cheap) price as far as performances are concerned because functions calls are not for free (nor are function definitions). </p>\... | {
"AcceptedAnswerId": "28865",
"CommentCount": "13",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-19T12:53:28.120",
"Id": "28700",
"Score": "1",
"Tags": [
"python",
"optimization",
"primes",
"python-3.x"
],
"Title": "Efficient way of code reuse for finding the largest pri... | 28700 |
It is the practice of reusing existing code to avoid redundancy in code. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-19T12:59:58.727",
"Id": "28702",
"Score": "0",
"Tags": null,
"Title": null
} | 28702 |
<p>Python 3 is the latest version of the Python programming language, released on December 3rd, 2008. It features simplifications and improvements to the syntax of the language. Some of these changes are backwards incompatible, and therefore Python 3 has its own tag.</p>
<p>Although Python 3 itself is ready for primet... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-19T13:05:06.000",
"Id": "28703",
"Score": "0",
"Tags": null,
"Title": null
} | 28703 |
Python 3 is the latest version of the Python programming language and was formally released on December 3rd, 2008. Use this tag along with the main python tag to denote programs that are meant to be run on a Python 3 interpreter only. Do not mix this tag with the python-2.x tag. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2013-07-19T13:05:06.000",
"Id": "28704",
"Score": "0",
"Tags": null,
"Title": null
} | 28704 |
<p>I created this quite important piece of code, but I am not pretty sure is it good enough. </p>
<p><strong>Goal:</strong></p>
<p>I have a big task for a database and have decided to use Django-Celery. I want to go through all objects of a particular model and create monthly statistics for each of them based on othe... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-19T13:08:07.110",
"Id": "28706",
"Score": "2",
"Tags": [
"python",
"django"
],
"Title": "Task for all objects in model with datetime operations"
} | 28706 |
C99 is a standard for the C programming language. It replaces the previous C89 standard, and is succeeded by the C11 standard. C99 added inline functions, C++-style comments, allows intermingled declarations and code, as well as multiple other language and library fixes and additions. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-19T13:25:16.247",
"Id": "28708",
"Score": "0",
"Tags": null,
"Title": null
} | 28708 |
<p>Questions regarding code organization can deal with the topic on various levels:</p>
<ul>
<li><p>how to split parts of a larger project into subprojects (e.g. in Maven modules)</p></li>
<li><p>how to distribute classes in packages</p></li>
<li><p>where to put tests relative to the code that gets tested</p></li>
<li... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-19T14:22:34.383",
"Id": "28713",
"Score": "0",
"Tags": null,
"Title": null
} | 28713 |
Questions that deal with the organization and structure of the code should be given this tag. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-19T14:22:34.383",
"Id": "28714",
"Score": "0",
"Tags": null,
"Title": null
} | 28714 |
<p>This script creates a hierarchy of directories. Is this a good approach or can it be made better? I am mainly concerned with maintainability here, not efficiency. Suppose I wanted to add more directories to this hierarchy. Would this structure of the script make it easier to do?</p>
<p><strong>Hierarchy</strong><... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-19T19:58:10.533",
"Id": "45093",
"Score": "1",
"body": "PEP 8 advices lower case for local variables."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-20T16:37:10.633",
"Id": "45172",
"Score": "1",
... | [
{
"body": "<p>I'm not quite convinced that a python script is required here as a shell one-liner would probably do the trick (<code>mkdir -p codechef/{easy,medium,hard} spoj utilities</code> would be a good starting point).</p>\n\n<p>Your python code could be improved by using <a href=\"http://www.python.org/de... | {
"AcceptedAnswerId": "28719",
"CommentCount": "8",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-19T14:30:32.763",
"Id": "28715",
"Score": "5",
"Tags": [
"python",
"directory"
],
"Title": "Script for creating a hierarchy of directories"
} | 28715 |
<p>Ok, I have written the following but I am sure it can be done better, my two main worries here are the awful use of the if else statements in the check variables and the usage of setinterval to set the i variable. my problem with the i variable is that the check's run after the i has been set forcing the i to always... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-19T16:48:04.847",
"Id": "45081",
"Score": "0",
"body": "Some HTML would help for context."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-19T17:22:04.330",
"Id": "45083",
"Score": "0",
"body": "... | [
{
"body": "<p>The <code>check</code> stuff is very redundant and should be handled by doing something like this:</p>\n\n<pre><code>var check = [];\nfor(var i = 1; i < 10; i++) {\n check[i] = (function(i) {\n return function() {\n console.log(i);\n var empty = $(\"#widgets-righ... | {
"AcceptedAnswerId": "28725",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-19T15:55:43.207",
"Id": "28718",
"Score": "-1",
"Tags": [
"javascript",
"jquery"
],
"Title": "Jquery ajax loader and messy if else statements?"
} | 28718 |
<p>I'm just getting started on GUI programming using swing in Java, and I would love some critiques on my code. I understand there is a danger in using global variables. If someone can hint me on how to get rid of my globals (which will be later registered for event handling), I'd really appreciate it.</p>
<pre><code... | [] | [
{
"body": "<p>A thing I like to do is instead of using four different JButtons is use an array of four JButtons that is initialized in the same method that you build the JPanel this would remove the need to have them as global variables. Also instead of using two different methods to create your JPanels just us... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-19T16:55:03.983",
"Id": "28721",
"Score": "1",
"Tags": [
"java",
"swing",
"gui"
],
"Title": "Eliminating global variables in GUI program"
} | 28721 |
<p>I wrote this code to read text of a file and use it to initialize objects and place them in a multi-tree data structure. The multi-tree has the base node as an object called <code>theTree</code>, which has an <code>ArrayList</code> that contains a bunch of objects called <code>Party</code>. Each <code>Party</code> h... | [] | [
{
"body": "<p>First off, you should use a more sane indentation style. The line where <code>u</code> is set to <code>0</code> is just crazy :-). I prefer <a href=\"http://en.wikipedia.org/wiki/Indent_style#Variant%3a_1TBS\" rel=\"nofollow\">The One True Brace Style</a>.</p>\n\n<p>Beyond that, the code could ben... | {
"AcceptedAnswerId": "28740",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-19T17:16:32.473",
"Id": "28722",
"Score": "2",
"Tags": [
"java",
"tree"
],
"Title": "Initializing a multi-tree data structure"
} | 28722 |
<p>I have been watching <a href="http://www.youtube.com/watch?v=aIHAEYyoTUc" rel="nofollow">Alexander Stepanov</a> programming C++ with components and he, as usual, has some strong opinions. I did like one of his assertions that we use regular, semi-regular and fully ordered types. So I decided to pull together a skele... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-19T22:17:05.963",
"Id": "45113",
"Score": "1",
"body": "Can you provide a definition of *regular*, *semi-regular* and *fully ordered* types? As it stands now, it's a bit hard to understand your question fully without watching the hour ... | [
{
"body": "<p>It is kind of hard to tell what you're really asking. Without knowing what you're asking, it's hard to provide a helpful and meaningful answer. I will try regardless. Feel free to point me in the right direction if I'm missing the point.</p>\n\n<hr>\n\n<blockquote>\n <p><em>Is it valid to refer t... | {
"AcceptedAnswerId": "28739",
"CommentCount": "10",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-19T18:07:40.800",
"Id": "28723",
"Score": "5",
"Tags": [
"c++",
"c++11"
],
"Title": "Is this a valid and correct skeleton class/struct"
} | 28723 |
<p>My biggest problem is attempting to remove a client when the "disconnect" button is hit. It doesn't work properly, and I'm not sure if my approach is best: sending out a list of all the current users to the clients.</p>
<p>Any major logic/coding flaws and any suggestions for improvement would also be welcome.</p>
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-21T11:00:48.753",
"Id": "45243",
"Score": "1",
"body": "This code could use much more advice; but you should implement all of @palacsint's suggestions first, to make other problems _operable_."
}
] | [
{
"body": "<p>(It's not a complete review, just a few random notes.)</p>\n\n<ol>\n<li><p><code>ArrayList<...></code> reference types should be simply <code>List<...></code>. See: <em>Effective Java, 2nd edition</em>, <em>Item 52: Refer to objects by their interfaces</em></p>\n\n<pre><code>private st... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-19T18:19:57.187",
"Id": "28724",
"Score": "2",
"Tags": [
"java",
"server",
"client"
],
"Title": "Implementing a Java server"
} | 28724 |
<p>I need to read <em>n</em> <code>char</code>s from a binary file into a <code>string</code>. Currently, what I do is:</p>
<pre><code>static string Read(istream &stream, uint32_t count)
{
auto bytes = unique_ptr<char[]>(new char[count]);
stream.read(bytes.get(), count);
return string(bytes.get... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-20T13:51:19.147",
"Id": "45160",
"Score": "0",
"body": "I think this is actually quite clean – albeit low-level – code. Nothing really wrong with it, and it’s probably more efficient than ruds’ implementation, although that’s arguably ... | [
{
"body": "<p>First of all, it seems that you've got a <code>using namespace std;</code> somewhere in your code. <a href=\"https://stackoverflow.com/questions/1265039/using-std-namespace\">Don't do that</a>. (<a href=\"https://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-bad-practic... | {
"AcceptedAnswerId": "28759",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-19T18:59:45.980",
"Id": "28727",
"Score": "14",
"Tags": [
"c++",
"c++11",
"memory-management",
"stream"
],
"Title": "Reading n chars from stream to string"
} | 28727 |
<p>I started learning C# a few months ago (so keep in mind that this is all fairly new to me) and I am working on my first real project (WPF / MVVM). I've received conflicting advice on how to handle my backing data. Currently I have everything held in a singleton class (DataManager); some say that's okay, but others s... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-19T22:23:15.200",
"Id": "45114",
"Score": "0",
"body": "The DataManager class actually looks more like a 'Game Container' than my notion of 'DataManager'. Also, the various 'CreateXXX' methods which are marked private would be more am... | [
{
"body": "<p>Following the lengthy commentary on the question, there's one additional point that qualifies as an actual 'answer'. Your classes are built up using the composition model which is fine. But since an Adventurer contains an instance of Guild, what happens to the Guild instance if the Adventurer is... | {
"AcceptedAnswerId": "28744",
"CommentCount": "15",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-19T19:07:43.937",
"Id": "28728",
"Score": "1",
"Tags": [
"c#",
"mvvm"
],
"Title": "Efficient strucure for backing data in MVVM"
} | 28728 |
<p>What are your guys thoughts on the following jQuery plugin?</p>
<pre><code>$.fn.with = function( fn ) {
// Verify function
if( jQuery.isFunction( fn ) ) {
var temp = fn.call(this);
// Check fn for valid response
if( temp instanceof jQuery ) {
return temp;
}
}... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-20T16:19:08.380",
"Id": "45171",
"Score": "2",
"body": "The resulting code is an order of magnitude uglier, even taking an extra indentation level."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-30T22:20:2... | [
{
"body": "<h1>The code</h1>\n\n<p>I'm not quite sure of the purpose of this part:</p>\n\n<pre><code>if( temp instanceof jQuery ) {\n return temp;\n}\n</code></pre>\n\n<p>This seems to be related to the idea of chaining methods, but it prevents me from doing something like this:</p>\n\n<pre><code>var width =... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-19T16:09:02.743",
"Id": "28729",
"Score": "4",
"Tags": [
"javascript",
"jquery"
],
"Title": "jQuery .with() to allow better chaining and flow"
} | 28729 |
<p>Retrieving an instance of (Default) <code>SharedPreferences</code> and then calling the six methods that may be called to put/get a value gets pretty old pretty quickly, so I wrote this:</p>
<pre><code>import android.annotation.SuppressLint;
import android.annotation.TargetApi;
import android.content.Context;
impor... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2015-02-01T18:15:06.887",
"Id": "143531",
"Score": "0",
"body": "Your self-answers were deleted because they contained code dumps, not actual reviews. This may be tolerated on SO, but it's not considered an acceptable answer on CR."
},
{
... | [
{
"body": "<p>I'm not too familiar with Android but I've found an issue with the code: both <code>persist</code> and <code>retrieve</code> methods contains the similar if-else chain. You should replace them with polymorphism:</p>\n\n<ul>\n<li><em>Refactoring: Improving the Design of Existing Code</em> by <em>Ma... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-19T19:58:22.893",
"Id": "28730",
"Score": "5",
"Tags": [
"java",
"android",
"wrapper"
],
"Title": "Wrapper around default shared preferences in Android"
} | 28730 |
<p>This is a class I wrote for parallelising certain parts of my main codebase. How could this code be improved in terms of making it shorter, more secure, and more efficient?</p>
<pre><code>using System;
using System.Collections.Generic;
using System.Threading;
using System.ComponentModel;
namespace System.SMP
{
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-19T20:32:00.127",
"Id": "45102",
"Score": "3",
"body": "What does this do that the [Task Parallel Library](http://msdn.microsoft.com/en-us/library/dd537609.aspx) doesn't?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDat... | [] | {
"AcceptedAnswerId": null,
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-19T20:19:12.343",
"Id": "28733",
"Score": "2",
"Tags": [
"c#",
".net",
"multithreading"
],
"Title": "Improving class for parallelising parts of main codebase"
} | 28733 |
<p>I've made a Bash script to monitor some server log files for certain data and my method probably isn't the most efficient.</p>
<p>One section specifically bugs me is that I have to write a newline to the monitored log so that the same line wont be read over continually.</p>
<p>Feedback would be greatly appreciated... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-19T21:37:14.113",
"Id": "45108",
"Score": "0",
"body": "A minor remark: I think `! -z` is equivalent to `-n`."
}
] | [
{
"body": "<p>I have small suggestions for the function readfile to reduce the number of shell commands you need to run :</p>\n\n<ol>\n<li><p>Save the output of the following into a variable so it can be reused as shown in #2:</p>\n\n<pre><code>last_line=$(tail -1 $serverlog | grep \"[INFO]\")\n</code></pre></l... | {
"AcceptedAnswerId": "29959",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-19T20:39:50.993",
"Id": "28734",
"Score": "6",
"Tags": [
"bash",
"logging",
"awk"
],
"Title": "Bash log monitoring"
} | 28734 |
<p>I'm building this website with PDO and Pattern MVC. I'm currently working on the login page and would like to know if this structure is correct for MVC pattern. I'd also like your opinions and advice on this.</p>
<p>For my <strong>login view</strong> I have:</p>
<pre><code><form action="test.php" name="loginf... | [] | [
{
"body": "<p>Just a minor note: I'd reverse some conditions and use guard clauses to make the code flatten.</p>\n\n<pre><code>if(empty($_POST['login']) || empty($_POST['password'])){\n message::showError('Veuillez remplir tous les champs');\n return;\n}\n\n$auth = new auth();\n$auth->setLogin($_POST['... | {
"AcceptedAnswerId": "28751",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-20T12:16:35.443",
"Id": "28742",
"Score": "1",
"Tags": [
"php",
"object-oriented",
"mysql",
"mvc",
"pdo"
],
"Title": "Look over my code for PDO and MVC"
} | 28742 |
<p>This app is a simple taxi emulator. The only feedback I've got on it was "bad internal architecture", that's why I would be grateful to receive more adequate and humiliating review.</p>
<p>Simply-speaking, it should be a static lib, all the functionality must execute in the same thread (but! thread-safe). There sho... | [] | [
{
"body": "<ul>\n<li>Use standard <code>#include</code> guards, not the non-standard <code>#pragma once</code>.</li>\n<li>Use standard data types, not <code>DWORD</code>.</li>\n<li>Change</li>\n</ul>\n\n<p>this:</p>\n\n<pre><code>static const int NO_ERR = 0;\nstatic const int CAR_IS_BUSY = 1;\nstatic const int ... | {
"AcceptedAnswerId": "28754",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-20T16:11:32.963",
"Id": "28745",
"Score": "5",
"Tags": [
"c++",
"object-oriented",
"design-patterns",
"c++11",
"simulation"
],
"Title": "Simple taxi emulator"
} | 28745 |
<p>I've been asked to attach a C++ code sample to my application for an entry-level C++ programmer position in a videogame company. I've created a simple, yet complete console application to solve Sudoku problems. How can I improve the code that I have?</p>
<p>Please do comment on the algorithm, the code practices, p... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-20T18:41:33.330",
"Id": "45186",
"Score": "2",
"body": "Your commenting and huge amount of unneeded whitespace can be improved. I have suggested Jamal. I think he'll be reviewing that part soon."
},
{
"ContentLicense": "CC BY-S... | [
{
"body": "<ul>\n<li><p>Read <a href=\"https://softwareengineering.stackexchange.com/questions/173118/should-comments-say-why-the-program-is-doing-what-it-is-doing-opinion-on-a-dic\">this</a> and <a href=\"https://softwareengineering.stackexchange.com/questions/119600/beginners-guide-to-writing-comments\">this<... | {
"AcceptedAnswerId": "28752",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-20T16:23:50.873",
"Id": "28746",
"Score": "8",
"Tags": [
"c++",
"recursion",
"sudoku"
],
"Title": "Entry-level recursive Sudoku solver"
} | 28746 |
<p>I have mongoose model:</p>
<pre><code>var mongoose = require('mongoose'),
Schema = mongoose.Schema,
Imager = require('imager'),
env = process.env.NODE_ENV || 'development',
config = require('../../config/config')[env],
imagerConfig = require(config.root + '/config/imager.js');
var LinkSchema = ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-06T18:08:08.610",
"Id": "70452",
"Score": "1",
"body": "As for the \"callbacks pyramid\". You can use the module async https://github.com/caolan/async. There is a bunch of control flow helpers. This one might become one of your new fri... | [
{
"body": "<p>Fun code,</p>\n\n<p>there are a few Mocha / Jasmine submissions on this site, and this one is by far the easiest to follow. Which is all kinds of funny since this is the first time you are writing tests ;)</p>\n\n<p>For your questions:</p>\n\n<ul>\n<li>Your code looks fine, it seems that Mocha and... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-20T20:26:57.263",
"Id": "28758",
"Score": "15",
"Tags": [
"javascript",
"unit-testing",
"node.js",
"mongodb",
"mocha"
],
"Title": "Test mongoose model"
} | 28758 |
<p>I want a task scheduler with some specific capabilities for my application. I've searched for a good library that provides me with the following, but found nothing.</p>
<ul>
<li>Queuing awaitable tasks.</li>
<li>Ability to stop started jobs.</li>
<li>Ability to repeat some jobs.</li>
<li>Ability to cancel repeat e... | [] | [
{
"body": "<p>The issues i see off the bat:</p>\n\n<p>1) In my experience this <code>Scheduler : Queue<Job></code> is almost always a bad idea. If you are not directly overriding a <code>Queue</code> class methods - there is no reason to derive <code>Scheduler</code> from it. Futhermore, adding/removing s... | {
"AcceptedAnswerId": "28812",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-20T21:44:34.150",
"Id": "28760",
"Score": "3",
"Tags": [
"c#",
"library",
"scheduled-tasks"
],
"Title": "Custom Task Scheduler"
} | 28760 |
<p>Please review this:</p>
<pre><code>class KoolDailyReminderAfterWeek(webapp2.RequestHandler):
def get(self):
logging.info('sending reminders')
timeline = datetime.now () - timedelta (days = 7)
edge = datetime.now () - timedelta (days = 8)
ads = Ad.all().filter("published =", True)... | [] | [
{
"body": "<p>I'm not familiar with that framework, so I can only provide some general points:</p>\n\n<ul>\n<li>You can rewrite the <code>if</code> statement to <code>subject = ad.title or 'Reminder'</code> (see <a href=\"https://codereview.stackexchange.com/questions/27461/refactor-python-code-with-lots-of-non... | {
"AcceptedAnswerId": "28770",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-21T04:37:04.267",
"Id": "28768",
"Score": "1",
"Tags": [
"python",
"email",
"google-app-engine"
],
"Title": "Email-sending class for GAE"
} | 28768 |
<p>I have written a sample immutable binary search tree using Scala. However, I am not sure whether or not I was doing it the proper way since I am not an expert at functional programming. Is there a better or more efficient way of, say, traversing the tree or adding an item to it using a purely functional approach?</p... | [] | [
{
"body": "<p>I think it would be an improvement to define an empty element. Currently you have no way to represent an empty collection. But that is required if you would want to integrate your data structure with scala collections.</p>\n\n<p>(In scala collections, you usually build up an immutable data structu... | {
"AcceptedAnswerId": "28775",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-21T10:29:36.160",
"Id": "28773",
"Score": "4",
"Tags": [
"scala",
"tree"
],
"Title": "Immutable binary search tree using Scala"
} | 28773 |
HDL stands for hardware description language. The most common examples are VHDL and verilog. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-21T10:57:07.697",
"Id": "28778",
"Score": "0",
"Tags": null,
"Title": null
} | 28778 |
<p>How could this VHDL counter and its test bench be improved? I am interested in anything you see that could be done better, but especially in the test bench:</p>
<ul>
<li>Is <code>wait for 10 ns</code> better or worse than any other time delay?</li>
<li>The test is very minimal. Should it do more?</li>
</ul>
<p><... | [] | [
{
"body": "<p>Contrary to what Aseem Bansal states, there is no need to use <code>std_logic</code> alone. Your use of <code>std_ulogic</code> is fine.</p>\n\n<p>One place where there is a trade-off to be pondered is on your top-level entity (the one which defines the whole chip). The tools that generate the o... | {
"AcceptedAnswerId": "58908",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-21T16:12:31.523",
"Id": "28784",
"Score": "14",
"Tags": [
"unit-testing",
"vhdl",
"hdl"
],
"Title": "32-bit counter and test bench"
} | 28784 |
<p>The point of my code is to:</p>
<ul>
<li><p>Read in the observed data from the a catalog of stars (whitespace separated table).</p></li>
<li><p>Do some unit conversions on the observed data (math stuff).</p></li>
<li><p>Apply an interstellar correction factor to the observed data (more math).</p></li>
<li><p>Compar... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-21T18:21:34.370",
"Id": "45265",
"Score": "0",
"body": "Ironically, I read the last sentence first."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-21T18:22:06.637",
"Id": "45266",
"Score": "0",
... | [
{
"body": "<p>I am not used to classes till now either but I can offer some other optimizations for your code.</p>\n\n<p>Firstly you should go over <a href=\"http://www.python.org/dev/peps/pep-0008/\" rel=\"nofollow\">PEP8</a>. These are style conventions but they would help you write code that is considered go... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-21T18:19:38.970",
"Id": "28787",
"Score": "4",
"Tags": [
"python",
"inheritance"
],
"Title": "Performing calculations with a catalog of stars"
} | 28787 |
<p>I am new to Python and can't quite make my <code>if</code>-cases any shorter. Any ideas on how to do that?</p>
<pre><code>import csv
fileheader = csv.reader(open("test.csv"), delimiter=",")
# Defines the header of the file opened
header = fileheader.next()
# Loop into the file
for fields in fileheader:
# For ea... | [] | [
{
"body": "<p>I would consider wrapping the conditions up inside a function:</p>\n\n<pre><code>def is_header(pattern):\n if pattern in header:\n pattern_index = header.index(pattern)\n if fields[pattern_index]:\n pattern_key = \"path\" if pattern == \"url_slug\" else \"keyword\"\n ... | {
"AcceptedAnswerId": "28789",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-21T19:01:12.267",
"Id": "28788",
"Score": "2",
"Tags": [
"python",
"beginner",
"csv"
],
"Title": "Loop in a .csv file with IF cases"
} | 28788 |
<p>I'm on the road to prepare for the 70-480 Microsoft exam and I'm learning the basics of jQuery.</p>
<p>Now I wrote the following JavaScript function to create a table dynamically:</p>
<pre><code>function MakeTableJavascript() {
var rows = document.getElementById("rows").value;
var cols = document.getElemen... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-21T10:01:04.707",
"Id": "45270",
"Score": "12",
"body": "Well, you're using jQuery, but that looks nothing like jQuery."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-21T10:02:39.290",
"Id": "45271",
... | [
{
"body": "<p>Well, how about</p>\n\n<pre><code>function MakeTablejQuery(rows, cols) {\n var table = $(\"<table/>\").attr(\"border\", 1);\n for (r = 0; r < rows; r++) {\n var row = $(\"<tr/>\");\n for (var c = 0; c < cols; c++) {\n if (r == 0) {\n ... | {
"AcceptedAnswerId": "28791",
"CommentCount": "10",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-21T09:59:29.433",
"Id": "28790",
"Score": "1",
"Tags": [
"javascript",
"jquery"
],
"Title": "Optimizing dynamic table creation: JavaScript vs. jQuery"
} | 28790 |
<p>So I'm relatively new to programming in general, and I've finally strapped in and started learning Python. This is my first significant project using it and I'm trying to build good habits with layout of my code, readability, comments, when to make functions, when not to etc.</p>
<p>The problem I was solving was th... | [] | [
{
"body": "<p>Don't open files as this. Its a bad habit. It is easy to forget to close it.</p>\n\n<pre><code>to_file = open(destination, 'w')\n</code></pre>\n\n<p>Use it as this.</p>\n\n<pre><code>def do_write(string, destination):\n with open(destination, 'w') as to_file: \n for item in string:\n ... | {
"AcceptedAnswerId": "28853",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-22T00:38:07.403",
"Id": "28794",
"Score": "4",
"Tags": [
"python",
"beginner",
"linux"
],
"Title": "Performing SMART tests on many disks"
} | 28794 |
<p>This is my solution for HackerRank's first "Algorithm Challenge, Insertion Sort Part 1". The challenge is to sort the array from least to greatest, the input being an array in sorted order, except for the last entity, i.e. {2, 3, 4, 5, 6, 7, 8, 9, 1}</p>
<p>It works fine, but it's definitely not an optimal solution... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-22T06:34:44.020",
"Id": "45294",
"Score": "0",
"body": "`if (ar[j] > i)`is wrong then you don't need to check `else if (ar[j] <= i)` because it is going to be true."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "... | [
{
"body": "<p>You could <a href=\"https://en.wikipedia.org/wiki/Binary_search_algorithm\" rel=\"nofollow noreferrer\">binary search</a> the list (without the last element) to get the new position of the last element. The JDK already has a <a href=\"http://docs.oracle.com/javase/6/docs/api/java/util/Arrays.html#... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-22T01:37:19.000",
"Id": "28797",
"Score": "5",
"Tags": [
"java",
"optimization",
"algorithm",
"programming-challenge",
"insertion-sort"
],
"Title": "HackerRank Algorithm Chal... | 28797 |
<p>Would like some assistance in improving my jQuery validation code. I have some repeated code, but I am not sure how to write it in a way so that I don't have to keep repeating the same code over and over again for different variable names etc... (such as the <code>if</code> statement part) My goal is to make it so t... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-23T02:51:18.393",
"Id": "45397",
"Score": "0",
"body": "If you can use plugin, jquery validation plugin comes with email validation. If not, you can have a look at their implementation. You can find it here: http://validation.bassistan... | [
{
"body": "<p>You could replace your if block with: </p>\n\n<pre><code>(name.val() === nameVal || name.val() === '' || name.val().length < 3) ? name.addClass(error) : name.removeClass(error);\n(comment.val() === commentVal || comment.val() === '' || comment.val().length < 3) ? comment.addClass(error) : co... | {
"AcceptedAnswerId": "96822",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-22T02:05:35.140",
"Id": "28798",
"Score": "1",
"Tags": [
"javascript",
"jquery",
"form",
"validation"
],
"Title": "jQuery validation code"
} | 28798 |
<p>This code works nicely for my purposes, but I would like to improve it exponentially.</p>
<p>What are some steps I can take? I'm interested in optimization, refactoring, and clean-code.</p>
<pre><code> def do_GET(self):
qs = {}
path = self.path
print path
if path.endswith('robots.txt'):
sel... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-22T05:00:50.163",
"Id": "45291",
"Score": "1",
"body": "Some explanation of its purpose would be helpful. That way we don't accidentally break it. That is the first feedback. Always use [docstring at the beginning of a function explain... | [
{
"body": "<p>How about using</p>\n\n<pre><code>IS, LTV, EMAIL, TIME, userID, URL = map(\\\n qs.get, ['vID', 'channelID', 'uEmail', 'Time', 'uID', 'contentUrl'])\n\nchannelID, uEmail, ytID, uTime, uID, contentUrl = map(\\\n lambda x : str(x)[2:-2], [LTV, EMAIL, ID, TIME, userID, URL])\n\nfor i in (channe... | {
"AcceptedAnswerId": "28803",
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-22T02:45:04.277",
"Id": "28799",
"Score": "3",
"Tags": [
"python",
"optimization"
],
"Title": "Optimization of \"def do_GET(self)\""
} | 28799 |
<p>I'm sure this has probably been asked before (although I couldn't find a question akin to this one).</p>
<p>I have a canvas "app" that is refreshing persistently, but performance is awful on mobile devices. I just wondered if there was a nice alternative to <code>requestAnimFrame()</code> or the like.</p>
<p>Here ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-22T08:30:08.670",
"Id": "45296",
"Score": "0",
"body": "Are you sure your code is optimized and really appropriate for mobile? Maybe you could show us a little bit more. Accusing requestAnimationFrame is maybe an easy way to not review... | [
{
"body": "<p>As far I understand your code, here's are some bumps:</p>\n\n<h1>Cache your values</h1>\n\n<p>Property access in objects causes a very minor overhead. A very common example of this case is a normal loop. In this version of the loop, you'd be accessing <code>length</code> <code>i</code> times durin... | {
"AcceptedAnswerId": "28808",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-22T08:07:02.167",
"Id": "28806",
"Score": "1",
"Tags": [
"javascript",
"performance",
"canvas"
],
"Title": "Canvas performance and stable frames per second"
} | 28806 |
<p>I've developed this spreadsheet in order to scrape a website's number of indexed pages through Google and Google Spreadsheets.</p>
<p>I'm not a developer, so how can I improve this code in order to have less code, to use less resources, or to go faster?</p>
<p>I've explained everything <a href="http://www.alsaseo.... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-22T09:14:28.507",
"Id": "45299",
"Score": "0",
"body": "I'm afraid somebody who doesn't speak French can't understand your question as the blog, the variable names and the comments are all in French. You should at least translate the v... | [
{
"body": "<h1>Comments</h1>\n\n<ul>\n<li><p>Never place them between the closing parenthesis and the opening bracket of the statement.</p></li>\n<li><p>Comments are meant to be read, and not set aside. Here are suggestions for cleaner comments:</p>\n\n<pre><code>//Before the lines concerned, like this one\nsom... | {
"AcceptedAnswerId": "32979",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-22T08:21:08.210",
"Id": "28807",
"Score": "5",
"Tags": [
"javascript",
"web-scraping",
"google-apps-script",
"google-sheets"
],
"Title": "Spreadsheet function that gives the n... | 28807 |
<p><strong>Method implemented in parent class (<code>extends SherlockFragmentActivity</code>)</strong> <a href="https://github.com/smarek/Simple-Dilbert/blob/master/src/com/mareksebera/simpledilbert/DilbertFragmentActivity.java" rel="nofollow">(source)</a></p>
<pre><code>ViewPager viewPager; // initialized in onCreate... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-22T10:05:21.520",
"Id": "45304",
"Score": "1",
"body": "[Is it a bad idea to use printStackTrace() in Android Exceptions?](http://stackoverflow.com/q/3855187/843804) at Stack Overflow"
}
] | [
{
"body": "<p>Three points:</p>\n\n<ol>\n<li><code>getSupportActionBar()</code> is called four times within the same method. Store it as a local variable and use the variable four times instead, to improve code cleaniness and readability.</li>\n<li>When catching exceptions, <a href=\"https://stackoverflow.com/q... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-22T08:40:57.047",
"Id": "28809",
"Score": "3",
"Tags": [
"java",
"android"
],
"Title": "Toggling ActionBar visibility for SherlockFragmentActivity"
} | 28809 |
<p><a href="http://en.wikipedia.org/wiki/VHDL" rel="nofollow">VHDL</a> (Very High Speed Integrated Circuit HDL) is a hardware description language (<a href="http://en.wikipedia.org/wiki/Hardware_description_language" rel="nofollow">HDL</a>) maintained by the <a href="http://www.eda.org/twiki/bin/view.cgi/P1076/WebHome"... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-07-22T08:54:32.220",
"Id": "28810",
"Score": "0",
"Tags": null,
"Title": null
} | 28810 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.