body stringlengths 25 86.7k | comments list | answers list | meta_data dict | question_id stringlengths 1 6 |
|---|---|---|---|---|
<p>Having scoured the web and found little helpful information regarding the implementation of an overridable <code>compareTo()</code> method, I determined myself to find a solution. In another thread I was pointed to some information pertaining to an overridable <code>equals()</code> method, however <code>compareTo()<... | [] | [
{
"body": "<p>Nice question! Some thoughts about it:</p>\n\n<p>If <code>B</code> and <code>C</code> are subclasses of <code>A</code> (in separate hierarchical branches) they usually should not know about each other even in the <code>compareToExactType</code> method. It leads to tight coupling which we try to av... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-01T06:52:29.483",
"Id": "14189",
"Score": "4",
"Tags": [
"java"
],
"Title": "Cleanly overridable/modifiable compareTo() method?"
} | 14189 |
<p>I have two Java classes with very similar code. Basically they are almost the same except for a few method calls etc, i.e. replace <code>ip</code> with <code>msisdn</code> in the classes and they would be identical.</p>
<p>How can I refactor them to remove the duplication? Or maybe if there is a Design Pattern I s... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-01T13:00:11.907",
"Id": "22971",
"Score": "0",
"body": "I think it would be useful to remove the multiple blank lines from the above"
}
] | [
{
"body": "<p>If I'm right the only difference is this line:</p>\n\n<pre><code>final PayLoad cacheQueryResponsePayLoad \n = cacheQueryRequester.queryCacheForSessionWithMsisdn(msisdnToQueryCacheFor, \n pccaHostToQuery);\n</code></pre>\n\n<p>ant the <code>CacheQueryRequester</code> class could b... | {
"AcceptedAnswerId": "14198",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-01T09:44:27.817",
"Id": "14191",
"Score": "1",
"Tags": [
"java"
],
"Title": "Two Java classes to perform similar queries with caching"
} | 14191 |
<p>Since I don't know how LINQ works under the hood, I can't decide what version is best to use in term of <strong>rapidity of execution</strong>. I've done some testing with my testing data (Point Cloud) but I can't see a clear difference between the 2. The only thing I know is that the real life data will be a larger... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-01T12:44:50.630",
"Id": "22970",
"Score": "4",
"body": "This might help: http://programmers.stackexchange.com/questions/80084/is-premature-optimization-really-the-root-of-all-evil"
},
{
"ContentLicense": "CC BY-SA 3.0",
"Cr... | [
{
"body": "<p>I don't think it will run faster on LINQ. The function <code>cylindre.IsPointInside</code> would still have to be called on each item of Vertices.</p>\n",
"comments": [],
"meta_data": {
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-01T13:... | {
"AcceptedAnswerId": "14200",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-01T12:23:39.227",
"Id": "14197",
"Score": "27",
"Tags": [
"c#",
"performance",
"linq",
"comparative-review"
],
"Title": "Is the LINQ version faster than the foreach one?"
} | 14197 |
<p>I am working on a Rails 3 application, and am having some trouble with my user/edit view. In this application, Users can subscribe to Categories. Users and Categories have a <code>has_and_belongs_to_many</code> relationship through a join table (<code>categories_users</code>).</p>
<p>In my user/edit view, I need to... | [] | [
{
"body": "<p>When you load the user, you can include the categories using eager loading. </p>\n\n<pre><code>@user = User.includes(:categories).find(params[:id])\n</code></pre>\n\n<p>or </p>\n\n<pre><code>@user = User.find(params[:id])\n@categories = @user.categories.all\n</code></pre>\n",
"comments": [
... | {
"AcceptedAnswerId": "14247",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-01T13:40:40.827",
"Id": "14201",
"Score": "1",
"Tags": [
"performance",
"html",
"mysql",
"ruby-on-rails"
],
"Title": "Allowing users to subscribe to categories"
} | 14201 |
<p>I’m trying to learn as much as I can on my own by reading lots of examples, documentations, and asking here. I would like to improve my style to write efficient code and adhere to Java standards.</p>
<p>In this small sample of code I would like to get feedback on a few things:</p>
<ul>
<li>Exception throwing</li>
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-01T07:51:13.127",
"Id": "22976",
"Score": "0",
"body": "You code is Ok but do you use java 6 or java 7 ?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-01T07:53:09.160",
"Id": "22977",
"Score": "5"... | [
{
"body": "<p>Consider in the following:</p>\n\n<pre><code>public Database(String dbName) {\n this.dbName = dbName;\n}\n</code></pre>\n\n<ol>\n<li>I would check for a null <code>dbName</code> being passed in. Note that you pass this reference and then simply store it. Consequently, if it's null, you won't fi... | {
"AcceptedAnswerId": "14205",
"CommentCount": "14",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-01T07:48:48.380",
"Id": "14203",
"Score": "7",
"Tags": [
"java",
"file-system",
"error-handling",
"database",
"sqlite"
],
"Title": "Storing .h files in SQLite using SQLJe... | 14203 |
<p>I followed <a href="http://tomszuszai.com/content/articles/tutorials/how_to_write_a_simple_sql_factory_in_php" rel="nofollow">this tutorial</a> to create an SQL "factory".</p>
<p>The link shows how to make a class who's methods will output SQL statements based on the arguments you pass to it, and I've expanded on i... | [] | [
{
"body": "<p>Long wall of text incoming. Hope it helps :)</p>\n\n<p>First a comment on your file extensions. PHP doesn't care what a file's extension is, it could be an HTML file, text file, or anything. It's just convention that makes us use \".php\". Eventually it was determined that adding the \".inc\" exte... | {
"AcceptedAnswerId": "14227",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-01T16:49:01.623",
"Id": "14213",
"Score": "4",
"Tags": [
"php",
"beginner",
"object-oriented",
"sql"
],
"Title": "Efficiently accessing the database"
} | 14213 |
<p>This is just a program to show the use of conditional variables when two threads are involved. One thread wants a non-zero value of <code>count</code>, and other thread is responsible for signaling it when the count is non-zero.</p>
<p>Is there something in this code which still needs an improvement? Is there somet... | [] | [
{
"body": "<p>Couple of issues:</p>\n\n<p>The code is not exception safe.<br>\nAny resource that has an open/close symantic should be handled via RAII</p>\n\n<pre><code>{\n pthread_mutex_lock (&mutexA);\n\n // Code\n // This may throw an exception thus will\n // cause the code to miss the unlock... | {
"AcceptedAnswerId": "14221",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-01T16:53:06.267",
"Id": "14214",
"Score": "5",
"Tags": [
"c++",
"synchronization",
"pthreads"
],
"Title": "Maintaining a count with two threads using conditional variables"
} | 14214 |
<p>I'm only just beginning in programming. </p>
<p>The goal of the program is to check to make sure images are properly rendered within a program(within a VM)</p>
<p>. Below is the code, and I am asking what I can do to clean it up.</p>
<p>I don't think you can tell much without the .png's, but I would appreciate it... | [] | [
{
"body": "<p>One way to get started improving your script is to find repeated code, then create a function to hold it.</p>\n\n<p>For example, if your code starting with #BEGIN IMAGE CHECK 1 is duplicated for subsequent image checks, it could become a function that takes a Sikuli image file name - define it som... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-31T20:26:49.303",
"Id": "14215",
"Score": "4",
"Tags": [
"python"
],
"Title": "How do I refine my code in Sikuli? Seems very long and redundant"
} | 14215 |
<p>First of all, I came up with that question on SO already. But I am offered different solution which are "better" in some ways. The goal is to improve this specific version, not to create another one.</p>
<p>Here is what it is about:</p>
<p>Reading <em>Coding Horror</em>, I just came across the FizzBuzz another t... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-01T18:15:01.877",
"Id": "23014",
"Score": "2",
"body": "Here's a way: http://code.google.com/p/fizzbuzz/"
}
] | [
{
"body": "<p>Since you are printing at the same time as you are trying to figure out if it was found, then no, you cannot. If you do not mind using higher level approach such as Linq, then here is my version below. It just might be a tad faster for large number of combinations if <code>Console.Write</code> and... | {
"AcceptedAnswerId": "14288",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-01T17:59:15.107",
"Id": "14216",
"Score": "6",
"Tags": [
"c#",
"optimization",
"interview-questions",
"fizzbuzz"
],
"Title": "Writing FizzBuzz"
} | 14216 |
<p>I am having difficulty deciding how to implement an exception handling strategy.</p>
<p>I am using an observer pattern to allow "plugin" programmers to subscribe to <code>Message</code>s. These subscribers generally log a unique error (and do some other stuff) under an exceptional circumstance during handling the m... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-01T17:40:23.097",
"Id": "23007",
"Score": "0",
"body": "What does `m.reply(boolean)` do?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-01T17:42:18.553",
"Id": "23008",
"Score": "0",
"body": "I... | [
{
"body": "<h1>Allow throwing exceptions</h1>\n\n<p>Do you really think your user is capable of handling all the exceptions?</p>\n\n<pre><code>interface IMessageListener {\n void onMessage(Message m) throws Exception;\n}\n</code></pre>\n\n<p>Of course if some plugin wants to handle the exception, nothing prev... | {
"AcceptedAnswerId": "14218",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-01T17:37:38.727",
"Id": "14217",
"Score": "5",
"Tags": [
"java",
"exception-handling"
],
"Title": "Allowing \"plugin\" programmers to subscribe to messages"
} | 14217 |
<p>I wrote / modified two scripts to count Facebook and Twitter reactions. Anything I can do to improve these?</p>
<p>Count Facebook Reactions</p>
<pre><code> class FacebookReactions
{
public $url;
function __construct($url)
{
$query = 'SELECT like_count, total_count FROM link_stat W... | [] | [
{
"body": "<p>Both classes have undefined or unused class properties. The first class does not use the <code>$url</code> property and never defines the <code>$total</code> or <code>$like</code> properties. The second class just doesn't use the <code>$total</code> property. If these properties really aren't bein... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-01T19:49:52.360",
"Id": "14225",
"Score": "2",
"Tags": [
"php",
"facebook"
],
"Title": "Counting Facebook and Twitter Reactions"
} | 14225 |
<p>I am writing a WPF application that needs to access information from a database (I am currently using Entity Framework code first, so data access is via <code>DbContext</code>). </p>
<p>My ViewModels directly instantiate my <code>DbContext</code> derived class and query this to obtain the information they require. ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-02T01:15:52.883",
"Id": "23025",
"Score": "0",
"body": "The implementations seem pretty standard to me. However I'm not sure of the usage of these within viewmodels. I always tended to go down the track that other objects were repons... | [
{
"body": "<p><strong>NOTE</strong>: After Ben correctly commented that he was doing this from the WPF not MVC approach my answer was biased to MVC so although I'll leave it here it it may not have much relevance to what he is actually looking for.</p>\n\n<hr>\n\n<p>Typically I worked on the assumption that as... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-01T19:59:07.790",
"Id": "14226",
"Score": "24",
"Tags": [
"c#",
"design-patterns",
"entity-framework"
],
"Title": "Generic repository and unit of work code"
} | 14226 |
<p>I coded this because it seemed like a fun project, would be awesome if someone reviewed this.</p>
<p>Thanks!</p>
<pre><code>#! /bin/sh
#function that checks if dependencies are installed
check_software() {
#check if md5sum is installed
if [ $(command -v md5sum) > /dev/null 2>&1 ]; then
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-01T23:38:54.580",
"Id": "23018",
"Score": "2",
"body": "The convention in codereview.se is that the code being reviewed is pasted. We insist on that so that we can always see the history of changes even if an external site goes down."
... | [
{
"body": "<p>I'll start with your entry point and will go through you code step by step.\nThe last code block will contain an updated version. </p>\n\n<p>The key elements in my changes are split your functions and only do one specific task, e.g. extra function for getting a checksum of a file and another one c... | {
"AcceptedAnswerId": "14243",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-01T21:44:14.820",
"Id": "14231",
"Score": "5",
"Tags": [
"bash",
"shell"
],
"Title": "Shell script that verifies checksums when moving between filesystems"
} | 14231 |
<p>I have made this class that runs a query. I want to optimize my code and want to have some expert advice.</p>
<p>Here is the class:</p>
<pre><code>class testClass extends Model
{
protected $_var1;
protected $_var2;
protected $_var3;
public function __construct($var1,$var2, $var3)
{
$t... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-02T00:59:26.057",
"Id": "23022",
"Score": "3",
"body": "Welcome to CR, we don't have \"expert\" advice, but I'll see what I can do for you. 32bitfloat did a pretty good job already, I just want to add a few things. First, variable name... | [
{
"body": "<p>I'm not sure what you want to achieve with the constructor.</p>\n\n<pre><code>public function __construct($var1,$var2, $var3)\n {\n $this->_var1= $this->$var1;\n $this->_var2= $this->var2;\n $this->_var3= 8; // i need this 8 if no value is passed\n\n }\n<... | {
"AcceptedAnswerId": "14237",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-01T22:51:39.787",
"Id": "14234",
"Score": "1",
"Tags": [
"php",
"php5"
],
"Title": "Class that runs a query"
} | 14234 |
<p>Please review my database design:</p>
<p><img src="https://i.stack.imgur.com/ftdd7.png" alt="flowchart"></p>
<p>I think it is quite self-explanatory, but to be absolutely clear:</p>
<p>My goal is to make an application which has a super flexible user management (which is why the groups are in tree-form and the gr... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-03-06T14:24:55.250",
"Id": "36312",
"Score": "0",
"body": "In my experience, the terms most flexible and best / right / optimal rarely belong in the same sentence ;)"
}
] | [
{
"body": "<p>I'm not a database designer so I can only speak to the question as an application developer.</p>\n\n<ol>\n<li><p>I don't see any mechanism for limiting access to pages or groups of pages. It would seem like one use of user groups would be to give all members of a group certain privileges for certa... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-01T22:55:52.727",
"Id": "14235",
"Score": "2",
"Tags": [
"sql",
"database",
"cakephp"
],
"Title": "Flexible and modular CMS with user management in CakePHP"
} | 14235 |
<p>Was the best way to implent this? For example it will only say "It's nice I know." If you first ask "hat" and then answer "yes".</p>
<p>This is how I'm thinking:</p>
<pre><code>Topic = 0
local messages = {
{"name", "I'm Bob, the owner of this little shop."},
{"job", "I sell stuff."},
{"hat|head", "You... | [] | [
{
"body": "<p>I see a lot of problems here...</p>\n\n<ul>\n<li>are the answers selectable in the GUI? If not such predefined answers are not quite user-friendly, prone to typos etc.</li>\n<li>You might have to escape strings with \"|\" then unescape them. Yes chances are low, but that's how bugs start.</li>\n<l... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-01T23:44:06.947",
"Id": "14236",
"Score": "7",
"Tags": [
"lua"
],
"Title": "Very basic chatbot"
} | 14236 |
<p>I'm trying to get some feedback on my code for the lexicon exercise (#48) in <em>Learn Python the Hard Way</em>. I have only recently started learning Python and want to make sure I have my fundamentals down before progressing. I have some experience coding (only with kdb+/q in my work environment) but none in Pytho... | [] | [
{
"body": "<pre><code>verb=['go','kill','eat']\ndirection=['north','south','east','west']\nnoun=['bear','princess']\nstop=['the','in','of']\n</code></pre>\n\n<p>There is not a lot of point in storing these in separate variables only to stick them inside <code>vocab</code> just put the list literals inside <code... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2012-08-02T01:37:03.527",
"Id": "14238",
"Score": "9",
"Tags": [
"python",
"beginner",
"parsing",
"python-2.x"
],
"Title": "Learn Python the Hard Way #48 — lexicon exercise"
} | 14238 |
<p>I changed some methods used previously, and I am wondering if I need to do the multiple for loops over and over again. How do I convert my arrays to lists to use in nested <code>for</code> loops?</p>
<pre><code>using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using Sys... | [] | [
{
"body": "<p>First off, add a </p>\n\n<pre><code>using OneWayAnovaClassLibrary;\n</code></pre>\n\n<p>to the top of your partial class. That way you can change all of the calls from the library from:</p>\n\n<pre><code>OneWayAnovaClassLibrary.OneWayAnova(...)\n</code></pre>\n\n<p>into:</p>\n\n<pre><code>OneWayA... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-02T10:06:05.330",
"Id": "14248",
"Score": "4",
"Tags": [
"c#",
"performance",
".net",
"statistics"
],
"Title": "Two-way ANOVA table"
} | 14248 |
<p>I have the following control structure that I would like to improve:</p>
<pre><code>if(number >= 100) then doSetInc(id, 8, 20)
elseif(number >= 91) then doSetInc(id, 8, 30)
elseif(number >= 81) then doSetInc(id, 8, 50)
elseif(number >= 7) then doSetInc(id, 8, 70)
elseif(number >= 1) then doSetIn... | [] | [
{
"body": "<p>Kinda hard to know what you mean with better since you don't specify in what regard.</p>\n\n<p>In regards to cleaner code:</p>\n\n<ul>\n<li><p>FunctionName doSetInc is a bit weird, what does it do?</p></li>\n<li><p>You are sending in 3 variables into the function, it's common practice to use as fe... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-02T11:37:12.443",
"Id": "14249",
"Score": "8",
"Tags": [
"lua"
],
"Title": "Is there a better way of implementing this control structure?"
} | 14249 |
<p>Below is some code that I've been working to simplify, however I feel there is more that can be done. Please note that I did clean up the <code>articles.search</code> method.</p>
<pre><code>class HomeController < ApplicationController
@@articles_per_page = 6
def index
@paged_articles = articles.... | [] | [
{
"body": "<p>You can move urls and titles to helpers and articles search to separate method</p>\n\n<pre><code>class HomeController < ApplicationController\n # this methods can be used in view template\n helper_method :next_page_url, :page_title\n\n @@articles_per_page = 6\n @@first_page_articles_options... | {
"AcceptedAnswerId": "14254",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-02T12:37:21.647",
"Id": "14250",
"Score": "0",
"Tags": [
"ruby",
"ruby-on-rails",
"pagination",
"active-record"
],
"Title": "Pagination and Controller setup"
} | 14250 |
<p>Following is the code that I'm currently using to validate the user given IP address (IPV4 and IPV6). It makes use of apache commons-validator's <code>InetAddressValidator</code>. However, their function validates only IPV4 address and not IPV6. </p>
<pre><code>public static boolean isValidInetAddress(final String ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-09-27T07:03:41.407",
"Id": "50871",
"Score": "0",
"body": "Keep in mind that `InetAddress.getByName` can do DNS lookups."
}
] | [
{
"body": "<p>It seems fine if there is not any simpler Java or Apache Commons API.</p>\n\n<p>I'd modify a few small things:</p>\n\n<ul>\n<li>The <code>isValid</code> boolean would be unnecesary if you return immediately when you know the return value. (<a href=\"http://www.codinghorror.com/blog/2006/01/flatten... | {
"AcceptedAnswerId": "14291",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-02T13:14:44.033",
"Id": "14252",
"Score": "9",
"Tags": [
"java",
"validation",
"networking",
"ip-address"
],
"Title": "Validate IP address in Java"
} | 14252 |
<p>I have the following SQL query I am trying to use (save/make easy future modifications to) that is essentially the same query over and over and over, <code>UNION</code>ed each time, with only minor changes to the <code>WHERE</code> clause. </p>
<p>I am more familiar with MS Access, which allows me to use an <code>I... | [] | [
{
"body": "<p>first of all you must avoid using \"or\" in where clause.</p>\n\n<p>second, I understand that your sql code is not full, but still I think that you can get rid of all unions and use case/decode instead.</p>\n\n<p>third, I would suggest not to use tables in \"from\" which fields not used in \"selec... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-02T13:23:42.857",
"Id": "14253",
"Score": "0",
"Tags": [
"sql",
"oracle"
],
"Title": "Simplify Oracle SQL Unions"
} | 14253 |
<p>I have a program that displays colorful shapes to the user. It is designed so that it is easy to add new shapes, and add new kinds of views.</p>
<p>Currently, I have only two shapes, and a single text-based view. In the near future, I'm going to implement a <code>Triangle</code> shape and a <code>BezierCurve</code>... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-03T19:48:32.090",
"Id": "23144",
"Score": "0",
"body": "Not sure if you are just exclusively using this pattern for your example, but the O(n) search pattern in `render()` can be replaced by a O(1) search pattern with a `dict`. (e.g. ... | [
{
"body": "<p>Here's one approach:</p>\n\n<pre><code>SHAPE_RENDERER = {}\n\ndef renders(shape):\n def inner(function):\n SHAPE_RENDERER[shape] = function\n return function\n return inner\n\n@renders(Circle)\ndef draw_circle(circle, view):\n ...\n\n@renders(Triangle)\ndef draw_triangle(tri... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-02T14:16:45.080",
"Id": "14257",
"Score": "2",
"Tags": [
"python",
"mvc"
],
"Title": "Displaying colorful shapes to the user"
} | 14257 |
<p>JUnit is a unit testing framework for the Java language. It was created by Kent Beck, Erich Gamma, and David Saff.</p>
<p>It's official site is <a href="http://junit.sourceforge.net" rel="nofollow">http://junit.sourceforge.net</a> </p>
<p>JUnit tasks can be started from ANT with the <junit> tag. JUnit can al... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-02T14:28:34.537",
"Id": "14259",
"Score": "0",
"Tags": null,
"Title": null
} | 14259 |
JUnit is a unit testing framework for the Java language. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-02T14:28:34.537",
"Id": "14260",
"Score": "0",
"Tags": null,
"Title": null
} | 14260 |
<p>I'm thinking about the usage of percent, example, in margins.</p>
<p>We can use overlay to separate our layout by DPI sizes, but why can't we use percentage?</p>
<p>Something like that:</p>
<pre><code>Display display = getWindowManager().getDefaultDisplay();
float width = display.getWidth();
float height = displ... | [] | [
{
"body": "<p>You can simplify math whenever possible. No reason to multiply by 20 then divide by 100. Just multiply by .20. If you needed a result that was twenty percent in addition to 100 percent of what you already had you could multiply by 1.2. It saves a process making your code just a tad more efficient!... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-02T17:29:06.080",
"Id": "14265",
"Score": "2",
"Tags": [
"java",
"android"
],
"Title": "What about percentage usage?"
} | 14265 |
<p>I have made a custom login form for my site, with the help of PDO (until now I used simple MySQL connection and sanitizing), and it looks like this:</p>
<pre><code>session_name('NEWCOOKIE');
session_start();
require_once "config.php";
$member_username = $_POST['username'];
$member_password = $_POST['password'];
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-02T17:28:30.170",
"Id": "23062",
"Score": "0",
"body": "You might want to read [*this*](http://www.codinghorror.com/blog/2005/04/encryption-for-dummies.html)"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-... | [
{
"body": "<p>Well, let's see:</p>\n\n<ul>\n<li>You're using PDO and prepared statements, no risk of SQL injection there. Great!</li>\n<li>Your PDO code may throw an Exception (Specifically, a <code>PDOException</code>) <strong>at any time</strong>, so the whole database code block should be kept inside of the ... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-02T17:24:44.337",
"Id": "14267",
"Score": "4",
"Tags": [
"php",
"security",
"pdo",
"authentication"
],
"Title": "Custom login system (PDO, sanitizing, hash)"
} | 14267 |
<p>This doesn't seem quite right, but it's the best I could do. Is there a way to do this better? My goal is to use DEBUG when I'm developing by doing a 'cc -DDEBUG' at the prompt.</p>
<pre><code>#ifndef DEBUG
#define ptrValues ptrvaluesRemote
#else
#define ptrValues ptrValuesLocal
#endif
ptrLinks = (struct sLinkDesc... | [] | [
{
"body": "<p>Not much prettier, but maybe preferable depending on how you need to use it later:</p>\n\n<pre><code>#ifdef DEBUG\n#define DEBUG_FLAG 1\n#else\n#define DEBUG_FLAG 0\n#endif\n\nptrLinks = (struct sLinkDescriptionLayout*) DEBUG_FLAG?ptrValuesLocal():ptrValuesRemote();\n</code></pre>\n\n<p>The C prep... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-02T19:54:11.760",
"Id": "14273",
"Score": "2",
"Tags": [
"c"
],
"Title": "Doing #ifdef DEBUG and #define func() right?"
} | 14273 |
<p>I am building a JSON restful web api in Node.js and so far I only got the main structure, however I am not 100% sure I am doing this correct from scratch, I still have to get used to the fact that Node.js is event driven.</p>
<p><strong>Directory structure:</strong></p>
<pre><code>1. main.js
2. modules
a. router... | [] | [
{
"body": "<p>Sorry if I'm not answering your specific question, but are asking about overall style, or something else? There's no \"right/wrong way\" for many things in node.</p>\n\n<p>For example, I would have used <a href=\"http://expressjs.com/\" rel=\"nofollow\">http://expressjs.com/</a> for this:</p>\n\n... | {
"AcceptedAnswerId": "14280",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-02T20:10:23.687",
"Id": "14274",
"Score": "2",
"Tags": [
"javascript",
"node.js"
],
"Title": "Node.js building a JSON restful web api structure"
} | 14274 |
<p>I've got a simple sinatra webapp that pulls data from <a href="http://pinboard.in" rel="nofollow">Pinboard</a>'s RSS api, parses the info, and re-displays it. There are 4 tasks I need to perform with the data:</p>
<ol>
<li>I need to remove all instances of a specific tag from all items (in this case, <code>want</co... | [] | [
{
"body": "<p>The second version is undoubtedly better, more readable, even if you iterate multiple times over the data. </p>\n\n<p>The problem is: both versions, specially the first, suffer from a common problem: imperative style (\"do this, do that\"). Are you familiar with the difference between imperative (... | {
"AcceptedAnswerId": "14298",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-03T03:25:03.990",
"Id": "14283",
"Score": "3",
"Tags": [
"ruby",
"json",
"comparative-review"
],
"Title": "Filtering Pinboard API results by tags"
} | 14283 |
<p>I am running a scheduled script on my iPhone that logs in to a website, downloads a PDF, adds it to iBooks and uploads it to dropbox. All of this happens only when it has WiFi access.</p>
<p>I want to make it as error proof as possible. So I am open for criticism and tipps since it is my first bash script.</p>
<pr... | [] | [
{
"body": "<p>I don't have time to look through everything, but here's some low-hanging fruit:</p>\n\n<pre><code>if [ -e /path/title.jpg ]\nthen\n rm /path/title.jpg\nfi\n</code></pre>\n\n<p>can be reduced to:</p>\n\n<pre><code>rm -f /path/title.jpg\n</code></pre>\n\n<p>Because <code>man rm</code> says about... | {
"AcceptedAnswerId": "14307",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-03T09:10:49.937",
"Id": "14287",
"Score": "2",
"Tags": [
"bash",
"ios"
],
"Title": "Tips on good practice in my bash script that logs in to a website, downloads a PDF, adds it to iBoo... | 14287 |
<p>I want to load some CSV columns or contents in my Ajax code. Please help me or improve my code. This will be live API code for me.</p>
<p>Data will be downloaded from Yahoo Finance in CSV format on an interval, and updated into this chart code. The values will be updated and chart will continue to be updated.</p>
... | [] | [
{
"body": "<p>Did you read or even try this code before posting it? Sorry if this seems rude, but it just seems obvious that if this was run you would immediately notice something was wrong. I'm mostly looking at the PHP code here, as it is full of issues. The JS appears to be fine, except I would consider movi... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-03T10:36:01.103",
"Id": "14289",
"Score": "2",
"Tags": [
"javascript",
"php",
"html",
"csv"
],
"Title": "Updating a chart from Yahoo Finance CSV files"
} | 14289 |
<p>I am interested in the community opinion about the following approach for the synchronization.
Generally it is based on the idea to have a configurable way to apply locking on some logic parts.</p>
<p>Any comments and review is appreciated :) .</p>
<p><code>lock.properties</code> keeps configuration:</p>
<pre><c... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2017-01-31T20:20:21.227",
"Id": "291557",
"Score": "0",
"body": "What do you think you are accomplishing with this?"
}
] | [
{
"body": "<p><a href=\"http://docs.oracle.com/javase/1.5.0/docs/api/java/util/concurrent/Semaphore.html\" rel=\"nofollow\">Java 5 Semaphore</a> is ready made, tested, and secure tool for your problem. </p>\n\n<p>You certainly find something on the Net searching \"<code>semaphore java lock</code>\"</p>\n",
... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-03T10:45:42.123",
"Id": "14290",
"Score": "3",
"Tags": [
"java",
"multithreading",
"locking",
"synchronization"
],
"Title": "Configurable synchronization approach in Java"
} | 14290 |
<p>I have a table with forms in two colors - the first row is one color, the second is the other. Can you please tell me if there is a way to optimize my code (such as with <a href="https://github.com/symfony/symfony/blob/master/src/Symfony/Bridge/Twig/Resources/views/Form/form_table_layout.html.twig" rel="nofollow">th... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-06T14:52:09.090",
"Id": "23253",
"Score": "0",
"body": "ewww... Tables and CSS together, what blasphemy!"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-06T16:06:48.787",
"Id": "23255",
"Score": "1"... | [
{
"body": "<p>Depending on your requirements (is javascript allowed, which browsers can be used), I'd go for a CSS only solution.</p>\n\n<p><strong>CSS:</strong></p>\n\n<pre><code>table.zebra tr:nth-child(odd) { \n background-color: #EFF4FA; \n}\n\ntable.zebra tr:nth-child(even) { \n background-color: #... | {
"AcceptedAnswerId": "14301",
"CommentCount": "9",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-03T12:48:09.490",
"Id": "14294",
"Score": "4",
"Tags": [
"php",
"css",
"twig"
],
"Title": "Optimizing a table - Twig, CSS"
} | 14294 |
<p>I have 2 tables. One holds only first column of my "data table" rest is stored in another table, that is placed right to first. What I need to do is to get all the data from specific row to pass it to jqplot.</p>
<p>My tables look like <a href="http://jsfiddle.net/Misiu/eajpy/1/" rel="nofollow noreferrer">this</a>.... | [] | [
{
"body": "<p>I'll start with your selectors:</p>\n\n<p>First off, you should never have a selector with anything left of an id - searches for ids are about the fastest you can get on the DOM.</p>\n\n<p>Second, if you don't want to wrap other tables in your tables (I assume you don't), get rid of the immediate ... | {
"AcceptedAnswerId": "14303",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-03T13:42:08.163",
"Id": "14295",
"Score": "8",
"Tags": [
"javascript",
"jquery"
],
"Title": "Select row based on another table row index"
} | 14295 |
<p>I have been working on a little project to tidy up my log table which has exceeded the shared host provider limits:) So I have done some script that is working except one thing at the end: optimise DB.</p>
<p>This script will run in cron so I hope security should not be issue.</p>
<p>My questions are:</p>
<ol>
<l... | [] | [
{
"body": "<ol>\n<li><p>Your Select statement.</p>\n\n<pre><code>SELECT azon FROM $db ORDER BY azon ASC/DESC LIMIT 1\n</code></pre>\n\n<p>you could simplify the statement like this:</p>\n\n<pre><code>SELECT MAX(azon)/MIN(azon) AS 'azon' FROM $db\n</code></pre>\n\n<p>There are some discussions about the gain of ... | {
"AcceptedAnswerId": "14314",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-03T14:08:01.267",
"Id": "14296",
"Score": "5",
"Tags": [
"php",
"optimization",
"mysql"
],
"Title": "PHP backup log table from MySQL"
} | 14296 |
<p>I have the following redundant-feeling design to convert between <code>enum</code>s and strings regarding a class that stores <code>enum</code>s. The approach doesn't scale if there are more <code>enum</code>s and in any event, less-redundant code is also better.</p>
<h3>Questions</h3>
<ol>
<li><p>If there will be... | [] | [
{
"body": "<p>I would use some template logic to achieve the affect in a more scalable way:</p>\n\n<pre><code>#include <iostream>\n#include <sstream>\n#include <string>\n#include <algorithm>\n\n// This is the type that will hold all the strings.\n// Each enumeration type will declare its... | {
"AcceptedAnswerId": "14315",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-03T20:16:49.937",
"Id": "14309",
"Score": "26",
"Tags": [
"c++",
"c++11",
"converting",
"enum",
"namespaces"
],
"Title": "Conversion between enum and string in C++ class h... | 14309 |
<p>I'm working on a custom CMS and I'm primarily a PHP/database guy. This is my first real project using jQuery in any complexity. I've got it all functioning, but needless to say, it's pretty messy and I know jQuery veterans would frown at the code.</p>
<p>What can I do to clean up my jQuery? What bad practices am I ... | [] | [
{
"body": "<p>You'll want to think in terms of javascript rather than jQuery when you develop. jQuery is just a toolkit, not a framework. You may want to review some JS design patterns (Google, Essential JS Design Patterns) and make sure to check out the MV* chapter. </p>\n\n<p>Moving forward with your code,... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-03T20:53:08.740",
"Id": "14311",
"Score": "1",
"Tags": [
"javascript",
"jquery"
],
"Title": "Cleaning up jQuery"
} | 14311 |
<p><em><strong>Edit</em></strong> <em>Just did some further reading around the website and have come to the conclusion that this method leads to <a href="http://www.joelonsoftware.com/articles/LeakyAbstractions.html" rel="nofollow">Leaky Abstraction</a>, sorry for wasting peoples time. Time to head back to the drawing ... | [] | [
{
"body": "<p>Abstractions rarely result in optimizations, but that doesn't mean they aren't useful. Whether this a good idea or not depends upon whether you have a large number of tables that can be treated the same, and whether that helps you.</p>\n\n<p>In general it's not a good idea not because there are c... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-03T23:56:29.717",
"Id": "14313",
"Score": "2",
"Tags": [
"php",
"optimization",
"sql",
"codeigniter"
],
"Title": "Is having preset queries prone for disaster?"
} | 14313 |
<p>I have implemented an STL-like graph class. Could someone review it and tell me things that I could add to it?</p>
<p><strong>File graph.hpp</strong></p>
<pre><code>#include <vector>
#include <list>
using std::vector;
using std::list;
#ifndef GRAPH_IMPL
#define GRAPH_IMPL
namespace graph {
struct ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-18T19:22:54.280",
"Id": "83437",
"Score": "1",
"body": "Take a look at my blog post where it says how can we create a C++ graph using STL:\nhttp://theunixshell.blogspot.in/2014/02/creating-graph-using-stls-in-c.html"
}
] | [
{
"body": "<ul>\n<li>your <code>node</code> type doesn't seem to be a node, but an <em>edge</em> (or an adjacency relationship, or something). Unless this implementation is based on some literature which describes entries in the adjacency list as <em>nodes</em>, I'd consider renaming it</li>\n<li>I have no idea... | {
"AcceptedAnswerId": "14454",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-04T10:34:56.480",
"Id": "14322",
"Score": "5",
"Tags": [
"c++",
"classes",
"graph",
"stl"
],
"Title": "STL-like graph implementation"
} | 14322 |
<p>I wrote a predicate used in a <code>remove_if</code> call that deletes shared_ptr's of type StemmedSentence from an vector of sentences. </p>
<p>The predicate:</p>
<pre><code>class EraseSentenceIf {
ArrayStemmedSnippet * m_ass;
public:
EraseSentenceIf(ArrayStemmedSnippet *ass)
: m_ass(ass) {
}
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-04T03:01:20.667",
"Id": "23176",
"Score": "0",
"body": "`tmp.reset();` only resets `tmp`, not the object inside of `sentences`."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-04T03:15:44.947",
"Id": "2... | [
{
"body": "<p>Within the predicate you make a copy of the <code>shared_ptr</code> hence incrementing the reference count:</p>\n\n<pre><code> std::shared_ptr<ArrayStemmedSnippet::StemmedSentence> tmp = s;\n</code></pre>\n\n<p>A few lines later you explicitly reset <em>this copy</em> (note that this does... | {
"AcceptedAnswerId": "14326",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-04T02:58:17.447",
"Id": "14325",
"Score": "2",
"Tags": [
"c++",
"c++11"
],
"Title": "Is this predicate valid to delete single shared_ptr's?"
} | 14325 |
<p>If I have an array:</p>
<pre><code>var names = ['John', 'Jim', 'Joe'];
</code></pre>
<p>and I want to create a new array from names which afterwards will look like:</p>
<pre><code>newNames = ['John John', 'Jim Jim', 'Joe Joe']
</code></pre>
<p>What I came up with is the following:</p>
<pre><code>var newNames = ... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2019-10-28T12:20:06.710",
"Id": "451341",
"Score": "0",
"body": "Since then, JavaScript has added `String.repeat()`."
}
] | [
{
"body": "<p>You could use the native <code>Array.map</code> method in modern browsers (<a href=\"https://developer.mozilla.org/en-US/docs/JavaScript/Reference/Global_Objects/Array/map\" rel=\"nofollow noreferrer\">see MDN</a>)</p>\n\n<p><div class=\"snippet\" data-lang=\"js\" data-hide=\"false\" data-console=... | {
"AcceptedAnswerId": "14334",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-04T12:34:06.090",
"Id": "14330",
"Score": "3",
"Tags": [
"javascript",
"jquery"
],
"Title": "Javascript Array processing"
} | 14330 |
<p>I have pieced together some code that works for my project. However, it is pretty long, but self-similar. I am a jQuery beginner and I tried to shorten the code by using variables, but it didn't work so far. I guess I should use some <code>for()</code>-statement. Could you help me to simplify this code?</p>
<pre><c... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-04T12:25:30.063",
"Id": "23198",
"Score": "0",
"body": "we can guess at the purpose of the function however it would be good if you could specifically state the requirememnts for your function. Also it would be good to see what you hav... | [
{
"body": "<p>I assume you have set up the links in the menu properly, i.e. they reference the elements they correspond to, something like</p>\n\n<pre><code><ul id=\"menu\">\n <li><a href=\"#home\">Home</a></li>\n <li><a href=\"#referenzen\">Referenzen</a>&l... | {
"AcceptedAnswerId": "14337",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-04T12:21:24.333",
"Id": "14336",
"Score": "1",
"Tags": [
"javascript",
"beginner",
"jquery",
"animation"
],
"Title": "Animation effects for menu items"
} | 14336 |
<p>I am trying to learn C and have written a very basic socket library. I would be interested in any general design and coding comments.</p>
<p>Note that at this stage I am not bothered about implementing the most efficient networking model. I just want to get a simple synchronous model working then I can progress f... | [] | [
{
"body": "<p>If you have not done anything with linux then don't even include the header files.<br>\nThis gives a user a false sense that this is correct which is unknowable until you test it.</p>\n\n<pre><code>#if WIN32\n#include <winsock.h>\n#else\n/* Not doing anything with linux yet */\n#error \"Unte... | {
"AcceptedAnswerId": "14345",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-04T22:19:20.740",
"Id": "14340",
"Score": "3",
"Tags": [
"c",
"library",
"socket",
"callback"
],
"Title": "Basic socket library in C"
} | 14340 |
<p>I wrote this recently for one of my projects. Are there any error you can spot or a feature which could be implemented without eating up resources or some optimisations? Also, this isn't meant for multi-cores.</p>
<pre><code>/*******************************************************************************
* @file ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-09T10:08:21.460",
"Id": "23520",
"Score": "0",
"body": "How are `TRUE` and `FALSE` defined? Unless they have weird definitions (and I’d question that), their use in the above code is totally redundant. You can simply write `return mute... | [
{
"body": "<p>Does this really work? You call <code>cpu_atomic_cmpxchg</code> without taking any notice of its return value. I guess the function must return true or false (1 or 0 etc) according to whether the lock was already taken or not and it seems likely that you should take notice of that. </p>\n\n<p>Al... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-05T01:09:07.627",
"Id": "14342",
"Score": "3",
"Tags": [
"c",
"thread-safety",
"locking"
],
"Title": "Mutex implementation for a uniprocessor bare metal embedded OS"
} | 14342 |
<p>I actually feel bad posting "yet another singleton"... I wrote the following one many years ago and had recently found another application for it. We had many threads, each running the same function that requires the use of a <code>boost::asio::io_service</code> instance. It was best that all threads shared the same... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-08T11:31:00.333",
"Id": "23398",
"Score": "0",
"body": "Konrad mentioned that someone in the C++ chat had some other solution. That was me: https://gist.github.com/3284629. However that solution doesn't allow for reinitialization, whic... | [
{
"body": "<p>Well, the first objection to this code is that it’s not actually a singleton. It provides a centralised way of acquiring a a shared instance, true, but it doesn’t <em>ensure</em> that this is the only way an instance can be retrieved.</p>\n\n<p>On the contrary – the code requires that the class is... | {
"AcceptedAnswerId": "14455",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-05T01:15:52.290",
"Id": "14343",
"Score": "7",
"Tags": [
"c++",
"singleton"
],
"Title": "C++ shared_singleton"
} | 14343 |
<p>My inclination is to make these methods static:</p>
<pre><code>package net.bounceme.dur.usenet.driver;
import java.util.List;
import java.util.logging.Logger;
import javax.mail.Folder;
import javax.mail.Message;
import javax.persistence.*;
import net.bounceme.dur.usenet.model.Article;
import net.bounceme.dur.usene... | [] | [
{
"body": "<p>Actually the object contains an entity manager which has state. In a simple application having only one shared entity manager might work but if you made this into an EJB in a Java-EE application you would definitely want each request to use it's own entity manager.</p>\n",
"comments": [
... | {
"AcceptedAnswerId": "14354",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-05T10:08:43.407",
"Id": "14347",
"Score": "3",
"Tags": [
"java",
"object-oriented",
"static"
],
"Title": "What's wrong with static utility classes, versus beans?"
} | 14347 |
<p>As part of a question designed to help us understand the relationship between pointers and arrays in C, I've been asked to write an inner product function that doesn't use any array subscripting. Here's what I came up with, but it looks like the kind of complicated 'clever' coding that we've traditionally been told ... | [] | [
{
"body": "<p>Just a point, that code will error on compilation: p++ and q++ are not permitted operations if you have a const int.</p>\n\n<p>Now, to write it more cleanly (I know next to nothing about inner products, and google hasn't been much help):</p>\n\n<pre><code>int inner_product(const int *a, const int ... | {
"AcceptedAnswerId": "14363",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-05T11:48:07.933",
"Id": "14348",
"Score": "3",
"Tags": [
"c",
"homework"
],
"Title": "C inner product function without using array subscripting"
} | 14348 |
<p>I needed to find away to left shift a number on a platform with buggy <code><<</code> and <code>>></code> bitwise operators. I came up with a rudimentary solution, but it looks ugly and inefficient. What's a better way to do this?</p>
<pre><code>float leftShift8(int value) {
return value * 2 * 2 * 2... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-05T14:05:38.650",
"Id": "23220",
"Score": "2",
"body": "buggy shift operators? Are you sure? That sounds very suspect."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-05T14:13:56.410",
"Id": "23222",
... | [
{
"body": "<p>If I understand well, you are using a computer that have \"broken\" bit-wise operators? That is odd but maybe you can try this?</p>\n\n<pre><code>float leftShift8(int value)\n{\n return pow(2, 8) * value;\n}\n</code></pre>\n\n<p>This code simply do a power of 8 on the base that is 2. After that... | {
"AcceptedAnswerId": "14377",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-05T12:02:37.260",
"Id": "14349",
"Score": "-4",
"Tags": [
"c++",
"bitwise"
],
"Title": "Multiplying many times"
} | 14349 |
<p>The page is assigning <code>$gid</code> to the url paramater gid. It then reads an XML file that looks like this:</p>
<pre><code><games>
<game>
<name>name 1</name>
<appID>1234</appID>
</game>
<game>
<name>name 2</name>
<appID>5678</appI... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-05T01:58:05.403",
"Id": "23216",
"Score": "3",
"body": "I would suggest you try to get [this solution](http://stackoverflow.com/a/11813250/142162) working instead."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "20... | [
{
"body": "<p>Probably the only thing you can do to make it faster is to limit the number of results returned at one time. Could you maybe use pagination or something? Is there a reason you need to get all of them at once? Even if it was coming from a database, if there were enough records, it would take a coup... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-05T01:56:00.623",
"Id": "14351",
"Score": "0",
"Tags": [
"php"
],
"Title": "Is there more efficient way of processing my XML file in PHP?"
} | 14351 |
<p>I have the following code:</p>
<pre><code>from Bio import AlignIO
import itertools
out=open("test.csv","a")
align = AlignIO.read("HPV16_CG.aln.fas", "fasta")
n=0
def SNP(line):
result=[]
result.append(str(n+1))
result.append(line[0])
result.append(align[y].id.rsplit("|")[3])
result.append(x)
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-12-03T22:02:21.873",
"Id": "30872",
"Score": "1",
"body": "If you do not read PEP8 in its entirety, you can still run `pep8 myfile.py` and `pylint myfile.py` and `pyflakes myfile.py` (and there may be others) in order to have cleaner code... | [
{
"body": "<p>First of all, read <a href=\"http://www.python.org/dev/peps/pep-0008/\" rel=\"nofollow\">PEP8</a> (all of it!) and adhere to it. This is the de facto standard of Python code.</p>\n\n<p>In the following, I’ll tacitly assume PEP8 as given.</p>\n\n<p>Secondly, it would help if you had actually writte... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-05T16:09:17.473",
"Id": "14357",
"Score": "5",
"Tags": [
"python"
],
"Title": "Using Biopython, I would like to optimize this code"
} | 14357 |
<p>I have a hard time adapting to jQuery and chaining. I think it's really neat at times, but how do I know when to use it and when to indent? I may suffer from some kind of OCD-ish behaviour, and this is not your concern, but I would like your input on what needs refactoring in this ol' bit of code:</p>
<pre><code>$(... | [] | [
{
"body": "<p>Your code looks pretty decent IMHO. Here is how I prefer to do it:</p>\n\n<pre><code>(function($) { // Note that $ is now a parameter of the function and jQuery is added at the end - this is known as a \"wrapping method\" and avoids any potential conflicts with other libraries that may use the dol... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-05T16:25:13.920",
"Id": "14358",
"Score": "1",
"Tags": [
"javascript",
"jquery"
],
"Title": "Modifying a menu"
} | 14358 |
<p>I've done some programming in the past, but I'm new to MIPS, which I'm trying to learn on my own. This program lists the first five perfect numbers. It uses the Lucas-Lehmer and Miller-Rabin primality tests. Any suggestions on how I could improve will be most appreciated.</p>
<pre><code> .data ... | [] | [
{
"body": "<p><strong>Comments</strong></p>\n\n<p>Overall, I think you do a really great job with your comments. You clearly separate each section of code, state its purpose, list the register usage (very important for assembly), and do <em>not</em> have many obvious comments spread throughout. You pretty muc... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-06T04:23:59.280",
"Id": "14366",
"Score": "8",
"Tags": [
"beginner",
"primes",
"random",
"assembly"
],
"Title": "Listing the first five perfect numbers in MIPS assembly"
} | 14366 |
<p>In python2.7:
2 for loops are always a little inefficient, especially in python. Is there a better way to write the following filter function?
It tags a line from a log file, if it is useful. Otherwise the line will be ignored. Because there are different possible interesting lines, it tries different compiled regex... | [] | [
{
"body": "<p>I wouldn’t worry about performance of the loop here. The slow thing isn’t the loop, it’s the matching of the expressions.</p>\n\n<p>That said, I’d express the nested loops via list comprehension instead.</p>\n\n<pre><code>def filter_lines(instream, filters):\n return ((line, regex) for regex in... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-06T12:38:30.100",
"Id": "14368",
"Score": "4",
"Tags": [
"python",
"python-2.x",
"regex",
"logging"
],
"Title": "Filtering lines in a log file using multiple regexes"
} | 14368 |
<p>When you click on a span it enters the value into the input. That works fine, but as you can see the JS code is very big and there must be a better way to do this, but like I said I'm still learning. Maybe someone can give me a pointer in the right direction.</p>
<p>I suppose I have to use a variable somewhere but ... | [] | [
{
"body": "<p>First off, <code>this</code> refers to the element you clicked on, so we can simplify your code a bit my replacing your second <code>#spanval</code> like so:</p>\n\n<pre><code>$(\"#spanval1\").click(function(){\n $('#hourvalue').val($(this).text());\n});\n</code></pre>\n\n<p>Next, you can extra... | {
"AcceptedAnswerId": "14385",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-06T13:35:17.097",
"Id": "14374",
"Score": "2",
"Tags": [
"javascript",
"jquery"
],
"Title": "Entering a span value into the input"
} | 14374 |
<p>I've setup up a nice, little parent class that I can extend easily to do Http request to servers offering some sort of data with JSON/XML/whatever output.</p>
<p>You can see the <code>init()</code> function that is defined in the child class. The request URl builder is defined in the parent class, as the callback i... | [] | [
{
"body": "<p>I'm not sure I entirely understand what this is doing. But I'll give you my two cents.</p>\n\n<p>If the scheme were HTTPS, would that instead append the <code>$request_uri</code> with \"HTTPSservice?\"? In which case you could do something like the following.</p>\n\n<pre><code>$this->scheme ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-06T17:48:33.627",
"Id": "14381",
"Score": "2",
"Tags": [
"php",
"performance"
],
"Title": "Improving a \"Http request URl builder\" to be shorter, faster, easier to read"
} | 14381 |
<p>This downloads content from YouTube either as whole playlists or single videos. I find it very useful but would like to know if it's something close to a program that others could maintain. I also wanted to show it off a bit and get some feedback as I've been learning on my own from the net and would be helpful to k... | [] | [
{
"body": "<p>One suggestion I would make is to reduce the length of your functions, and reduce the amount of nesting / indentation. This will make your code easier to follow, and easier to maintain.</p>\n\n<p>As one example, you've got a function to respond to user commands. I would probably approach this by... | {
"AcceptedAnswerId": "14396",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-06T18:12:02.073",
"Id": "14383",
"Score": "6",
"Tags": [
"python",
"youtube"
],
"Title": "Downloading content from YouTube"
} | 14383 |
<p>I'm new to bash scripting and need some help improving a script I made for working with reverse-engineering Android applications.</p>
<p>I wrote comments in the script itself to explain what I want to do. Some of the code/functions are missing/broken, but I hope that you can help me out with it.</p>
<pre><code>#!/... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-07T03:10:24.580",
"Id": "23293",
"Score": "1",
"body": "The convention in cr.se is that the script in question is added inline. This protects us against the changes in the external hosting parties."
}
] | [
{
"body": "<p>Good first effort, here are a few general comments.</p>\n\n<ul>\n<li><p>You can replace multiple echos with one cat. that is</p>\n\n<pre><code>echo \"one\"\necho \"two\"\n</code></pre>\n\n<p>is equivalent to</p>\n\n<pre><code>cat <<EOF\none\ntwo\nEOF\n</code></pre>\n\n<p>and is much more cle... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-06T19:05:43.827",
"Id": "14384",
"Score": "1",
"Tags": [
"beginner",
"android",
"bash"
],
"Title": "Bash script for reverse-engineering Android applications"
} | 14384 |
<p>I have written this sample code to fetch a web page in C++ using libcurl. Please review it.</p>
<pre><code>#include <iostream>
#include <iostream>
#include <string>
#include <exception>
extern "C"
{
#include <curl/curl.h>
#include <stdlib.h>
}
//Exception class for curl excepti... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2015-03-04T11:27:27.950",
"Id": "149564",
"Score": "0",
"body": "Good job guys! I put this code on\nhttps://github.com/asashnov/tinycurl So everyone can use the latest version and improve it."
},
{
"ContentLicense": "CC BY-SA 3.0",
... | [
{
"body": "<p>You should probably derive from std::runtime_error.<br>\nIt takes a string in the constructor as the message and stored it for use with what() in a way that is safe even in low memory situations:</p>\n\n<p>Your exception class is then simplified too:</p>\n\n<pre><code>class CurlException : public ... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-06T21:53:23.463",
"Id": "14389",
"Score": "3",
"Tags": [
"c++",
"curl"
],
"Title": "Tiny Curl C++ wrapper"
} | 14389 |
<p>I wrote a failback for the fairly new CSS <code>calc()</code> rule. It works fine but I want to use it in a production environment and would appreciate feedback. Please recommend anything regarding weird/wrong code, possible optimizations, or a way to reduce code size.</p>
<pre><code>// CSS calc() replacement
func... | [] | [
{
"body": "<p>Am not very familiar with CSS, but I have a few comments on strictly the JS related parts:</p>\n\n<hr>\n\n<p><strong>calcfailback</strong></p>\n\n<p>I would call this <code>calcFailback</code> or <code>calc_failback</code>.</p>\n\n<hr>\n\n<p><strong>one var statement</strong></p>\n\n<p>It's fairly... | {
"AcceptedAnswerId": "14393",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-07T00:50:07.130",
"Id": "14392",
"Score": "3",
"Tags": [
"javascript",
"beginner",
"css"
],
"Title": "calc() fallback script"
} | 14392 |
<p>I have written a small Windows application that draws India's flag in the window. I am very new to using Visual C++ and I want to understand if my code can be improved further.</p>
<pre><code>#include "afxwin.h"
#include <math.h>
class CMyApp : public CWinApp
{
public:
virtual BOOL InitInstance ();
};
... | [] | [
{
"body": "<p>IMO, this code seems ok!</p>\n\n<p>To have a better clarity, you could create some functions for the drawing parts so that you India flag is made of smaller function. For example, for the inda flag, I would create a \"drawColoredRectangle\" and \"drawCircleStar\" just to make in clearer.</p>\n\n<p... | {
"AcceptedAnswerId": "14415",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-07T04:45:42.520",
"Id": "14397",
"Score": "4",
"Tags": [
"c++",
"windows"
],
"Title": "Windows application that draws India's flag"
} | 14397 |
<p>I'm one of those coder/designers that has been at it since day one, but is still getting the hang of several important coding nuances (e.g. OOP for PHP, and concepts such as <a href="http://nikic.github.com/2011/12/27/Dont-be-STUPID-GRASP-SOLID.html" rel="nofollow">this</a>).</p>
<p>In this case, I'm migrating my t... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-07T10:53:47.743",
"Id": "23315",
"Score": "0",
"body": "Some notes from the link above: I've made UTF8 and FETCH_ASSOC static because I've never needed anything else. Also, the run() function only works with un-named parameters. I real... | [
{
"body": "<p>I agree with Corbin, this probably shouldn't extend the PDO class. What he means by this is that its too limiting. You are using PDO now, but what if, as he asks, you don't want to use MySQL in the future? then you are stuck rewriting this entire database class because it is entirely hardcoded for... | {
"AcceptedAnswerId": "14408",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-07T10:51:36.310",
"Id": "14402",
"Score": "1",
"Tags": [
"php",
"pdo"
],
"Title": "PHP PDO wrapper class"
} | 14402 |
<p><a href="http://projecteuler.net/problem=11" rel="nofollow">Project Euler #11</a> asks to find the largest product of four numbers of a grid, where the four numbers occur consecutive to each other vertically, horizontally, or diagonally.</p>
<p>Here is my solution in Python. In addition to the usual code review, I... | [] | [
{
"body": "<p>The problem is pretty trivial and you should only check the index ranges and don't use </p>\n\n<pre><code>for x in xrange(0, 20):\n for y in xrange(0, 20):\n</code></pre>\n\n<p>but </p>\n\n<pre><code>for x in xrange(16):\n for y in xrange(16):\n</code></pre>\n\n<p>My version:</p>\n\n<pre><co... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-07T11:30:40.377",
"Id": "14405",
"Score": "5",
"Tags": [
"python",
"programming-challenge",
"matrix"
],
"Title": "Finding the largest product of four consecutive numbers in a grid"
} | 14405 |
<p>As a beginner, I wrote the following python script that solves warrant 1 of <a href="http://mutcd.fhwa.dot.gov/pdfs/2009r1r2/part4.pdf" rel="nofollow">this document - pp 436-438</a>.</p>
<p>My solution, although works, seems to me as poorly designed and highly unmaintanable. I was thinking of putting talbe 4C-1 con... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-07T16:42:33.347",
"Id": "23332",
"Score": "0",
"body": "Well, I like the functional style. The only question is - can one use less code to compute the same result."
}
] | [
{
"body": "<p><code>lanes_maj >= lanes_min >= 2</code> means <code>lanes_maj >= lanes_min and lanes_min >= 2</code> and it is different from <code>lanes_maj >= 2 and lanes_min >= 2</code>.</p>\n\n<p>You should probably raise ValueError if none of the conditions met instead of returning None im... | {
"AcceptedAnswerId": "14509",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-07T15:39:35.963",
"Id": "14409",
"Score": "2",
"Tags": [
"python",
"numpy"
],
"Title": "Simple arithmetic in Python"
} | 14409 |
<p>I'm working on a simple time sheet webapp. I have created the following query (simplified - I actually have several mapped columns of a similar type to <code>project_id</code>) to generate test data:</p>
<pre><code>INSERT INTO `entries` (`entry_id`, `user_id`, `project_id`, `date`, `comment`, `hours`)
VALUES
( null... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-07T17:12:22.653",
"Id": "23341",
"Score": "0",
"body": "Stored procedures? http://net.tutsplus.com/tutorials/an-introduction-to-stored-procedures/"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-08T18:43:05... | [
{
"body": "<p>It feels like <code>(SELECT project_id FROM projects ORDER BY RAND() LIMIT 1)</code> stands for \"get random but still valid project_id\". You could probably just iterate over all of your projects (with no randomness) and for every project add a random number of records. I don't think it affects y... | {
"AcceptedAnswerId": "14463",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-07T16:41:11.527",
"Id": "14411",
"Score": "3",
"Tags": [
"performance",
"sql",
"mysql",
"unit-testing"
],
"Title": "Creating many random test database entries"
} | 14411 |
<p>I wrote a script to remove .vb code files when there are corresponding .cs files in a certain directory structure. But I felt like there were some extra statements that I had to put in there that didn't feel natural. Is there a better way to do this check and then action?</p>
<p>Specifically, having to do the <co... | [] | [
{
"body": "<p>You could <a href=\"http://rkeithhill.wordpress.com/2007/11/24/effective-powershell-item-10-understanding-powershell-parsing-modes/\" rel=\"nofollow\">combine expression vs. command mode</a> in PowerShell, process only files (<code>!$_.PSIsContainer</code>) and use regex instead of <code>ChangeExt... | {
"AcceptedAnswerId": "14414",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-07T16:44:45.683",
"Id": "14412",
"Score": "3",
"Tags": [
"powershell"
],
"Title": "Script to remove .vb files from a directory"
} | 14412 |
<p>Anyone can play Google Hurdles today. Here is my score: 1.1 second. Is there are way of improving this score and running faster than a second?</p>
<p><a href="http://www.google.com/doodles/hurdles-2012" rel="nofollow">http://www.google.com/doodles/hurdles-2012</a></p>
<pre><code>import java.awt.AWTException;
impor... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-07T16:55:48.707",
"Id": "23334",
"Score": "1",
"body": "OK, this was originally [on StackOverflow](http://stackoverflow.com/questions/11850048/google-hurdles-game-gold-medal), and I asked the same thing there: what does the sentence \"... | [
{
"body": "<p>There are some general notes about the code, not really performance improvements (however, I have not tested their performance). I guess the real bottleneck could be in the browser/OS/hardware which can't handle more key events.</p>\n\n<p>Anyway, these do not need any other thread:</p>\n\n<ol>\n<l... | {
"AcceptedAnswerId": "15026",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-07T16:45:59.577",
"Id": "14413",
"Score": "2",
"Tags": [
"java",
"performance"
],
"Title": "Can this Google Hurdles code be made to run any faster?"
} | 14413 |
<p>I am writing a lightweight JSON API, and I come from a PHP background, so I have some questions/reviews about async node.js code.</p>
<p>This is my code so far:</p>
<p><strong>main.js</strong></p>
<pre><code>var http = require('http');
var api = require('./api.js');
api.addRoute({
'method': 'POST',
'url'... | [] | [
{
"body": "<p>From a once over:</p>\n\n<ul>\n<li>Not sure why you are not parsing the querystring for <code>GET</code> requests? It seems wrong</li>\n<li><code>if(data.length < postMaxSize && postTotalReceived < postMaxSize)</code> could be <code>if(data.length + postTotalReceived < postMaxSize... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-07T17:39:26.827",
"Id": "14416",
"Score": "3",
"Tags": [
"javascript",
"regex",
"node.js",
"asynchronous"
],
"Title": "Asynchronous lightweight JSON API"
} | 14416 |
<p>I have a shell script to mount different remote systems. While it does work, the area I struggle with (not being a programmer) is the logic of the script: it feels quite stilted and there seems to be some unnecessary duplication.</p>
<p>I would appreciate any comments as to how I could improve it - both in terms of... | [] | [
{
"body": "<p>Your functions shouldn't depend on variables but use specified\nparameters. You always specified variables before calling your function instead of just specifying them as parameters, e.g:</p>\n\n<pre><code>DIR=Box1\nHost=192.168.1.100\nmnt\n</code></pre>\n\n<p>but you can easily write it as</p>\n\... | {
"AcceptedAnswerId": "14428",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-07T21:50:37.180",
"Id": "14424",
"Score": "4",
"Tags": [
"shell",
"sh"
],
"Title": "Mount different remote systems"
} | 14424 |
<p>This is really not a question. I was looking up this solution but couldn't find it anywhere. Thought of posting it here so it may save someone's time.</p>
<p>Here was my issue: I had a JSON coming from server which was not nested. Lets take example of Movies:</p>
<pre><code>var movies = [
{"name":"Ice Age 3", "l... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-07T19:39:18.773",
"Id": "23368",
"Score": "0",
"body": "details: { languages: [{}], other: undefined }"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-07T19:39:49.897",
"Id": "23369",
"Score": "2",
... | [
{
"body": "<pre><code>var found = false;\n</code></pre>\n\n<p>Using flag is not good practice. </p>\n\n<p>This is better solution:</p>\n\n<pre><code>var movies = [\n {\"name\":\"Ice Age 3\", \"language\":\"English\", \"year\":\"2012\"},\n {\"name\":\"Ice Age 3\", \"language\":\"French\", \"year\":\"2011\"},\n... | {
"AcceptedAnswerId": "14431",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-07T19:37:58.143",
"Id": "14429",
"Score": "3",
"Tags": [
"javascript",
"jquery",
"json"
],
"Title": "Convert JSON to a different format (nested json)"
} | 14429 |
<p>I have 4 text columns, a mix of Varchar and Text. I need to find rows in a table where all words searched for are present across the 4 columns.</p>
<p>The 4 columns are:</p>
<ul>
<li>name</li>
<li>type</li>
<li>keywords</li>
<li>description</li>
</ul>
<p>So if someone searches for "london wildlife museum", it wo... | [] | [
{
"body": "<p>Easy! Change your ORs to ANDs so that the final statement reads:</p>\n\n<p>Your statement essentially needs to look like this:</p>\n\n<p>SELECT * FROM table </p>\n\n<p>WHERE (vname LIKE '%value1%' OR vtype LIKE '%value1%' OR vdesc LIKE '%value1%')</p>\n\n<p>AND (vname LIKE '%value2%' OR vtype LIKE... | {
"AcceptedAnswerId": "14435",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-07T23:55:39.173",
"Id": "14432",
"Score": "2",
"Tags": [
"php",
"sql",
"mysql",
"search"
],
"Title": "Multi column search"
} | 14432 |
<p>I am new to modular JavaScript code, and after reading an article on the Internet, I wrote a very basic calculator. This works fine, but due to some unknown reason, I feel that this code is not well written. I will appreciate it if someone could improve my code below so that it will be helpful with learning modular ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-10T03:17:45.947",
"Id": "23559",
"Score": "0",
"body": "Why are you checking for `y == 0` in `division`? Javascript's Numbers can have a value of `Infinity` (or `-Infinity`), which is returned when you divide by 0 and works as you'd ex... | [
{
"body": "<p>I've done this only for addition to make it more readable -</p>\n\n<pre><code>var Calculator = function() { \n\n this.calculate = function(eq, valone, valtwo, op) {\n\n var val1 = parseInt($(valone).val());\n var val2 = parseInt($(valtwo).val()); \n\n var eqCtl = $('... | {
"AcceptedAnswerId": "14439",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-08T08:57:57.967",
"Id": "14438",
"Score": "3",
"Tags": [
"javascript",
"beginner",
"jquery",
"calculator"
],
"Title": "Basic modular calculator"
} | 14438 |
<p>I am maintaining an application and have seen something like this</p>
<pre><code>Permission p = new UserModel().GetPermission(userToTestPerrmission, permissionWeCheck);
if(p.CanChange)
//sometihing
else
//something else
</code></pre>
<p>This approach looks a little "dirty" to me. The part I have problems wit... | [] | [
{
"body": "<blockquote>\n <p>Is this a typical way to write something like</p>\n</blockquote>\n\n<p>If that’s all the information that is required – yes, why not? I see no problem at all with this approach.</p>\n\n<p>On the other hand, if code lik this is prolific this is a sure sign that the original class de... | {
"AcceptedAnswerId": "14443",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-08T09:49:37.700",
"Id": "14440",
"Score": "2",
"Tags": [
"c#"
],
"Title": "new Class().Function() pattern"
} | 14440 |
<p>This is an OOP Rock, Paper, Scissors program I wrote in Python. I am just learning about using classes and I'd appreciate some advice on improving it.</p>
<pre><code># rock.py
# example of OOP
import random
class Rock:
def main(self):
self.Make_players()
print("Best of Five - Let's play!\n")
... | [] | [
{
"body": "<p>I would change <code>check</code> to this</p>\n\n<pre><code>def check(self, p_a, p_b):\n messages = {\"rock\":\"Rock breaks scissors.\",\n \"paper\":\"Paper wraps stone.\",\n \"scissors\":\"Scissors cut paper.\",\n }\n if p_a.go == p_b.go:\n ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-08T10:29:59.037",
"Id": "14441",
"Score": "2",
"Tags": [
"python",
"object-oriented",
"game",
"rock-paper-scissors"
],
"Title": "OOP in Rock, Paper, Scissors program"
} | 14441 |
<p>For <a href="http://projecteuler.net/problem=14" rel="nofollow">Project Euler problem 14</a> I wrote code that runs for longer than a minute to give the answer. After I studied about <a href="http://en.wikipedia.org/wiki/Memoization" rel="nofollow">memoization</a>, I wrote this code which runs for nearly 10 seconds ... | [] | [
{
"body": "<p>I think you're over complicating your solution, my approach would be something along these lines:</p>\n\n<pre><code>def recursive_collatz(n):\n if n in collatz_map:\n return collatz_map[n]\n if n % 2 == 0:\n x = 1 + recursive_collatz(int(n/2))\n e... | {
"AcceptedAnswerId": "14446",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-08T10:33:42.567",
"Id": "14442",
"Score": "5",
"Tags": [
"python",
"optimization",
"project-euler"
],
"Title": "Optimizing Code for Project Euler Problem 14"
} | 14442 |
<p>I created a simple todo kind of app using JavaScript. It is working fine but the code which I wrote is not proper. Please review my code and improve it if it is needed.</p>
<pre><code>$(function () {
var todo = new Todo('contents');
$('.addBtn').on('click', function() {
var name = $(this).parent().... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-09T12:43:21.613",
"Id": "23523",
"Score": "2",
"body": "You have leaking globals because of the semi-colon after `name;` (replace it with `,`)."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-10T03:12:54.45... | [
{
"body": "<p>As I read it, you want:</p>\n\n<ul>\n<li>one <code><div class=\"names\"></code> per todo (in this case inside <code>.contents</code>) surrounding the todo text in a <code>span</code> and the buttons \"Edit\" / \"Remove\"</li>\n<li>on clicking \"Edit\", the <code>span</code> is exchanged for ... | {
"AcceptedAnswerId": null,
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-08T11:13:36.660",
"Id": "14444",
"Score": "1",
"Tags": [
"javascript",
"jquery",
"to-do-list"
],
"Title": "To-do list app using jQuery"
} | 14444 |
<p>I'm new to coding and have written a script from scratch to do an auto-correlation function. It's too slow and I have to run it on a few thousand files over the next few days. I'm sure it's terribly written (and you can see my brain ticking in basic ways through it) and can be faster.</p>
<p>I know that Python has ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-08T14:19:39.673",
"Id": "23405",
"Score": "0",
"body": "For a beginner this is incredibly well-written, clean code. I see very few points that can be trivially improved, besides the suggestions made in the answers below."
}
] | [
{
"body": "<p>My first suggestion is to look into parallelization. I believe your problem is one that can be made <a href=\"http://en.wikipedia.org/wiki/Embarrassingly_parallel\" rel=\"nofollow\">embarassingly parallel</a>. Each iteration of your loop is independent of each other iteration, so you could run all... | {
"AcceptedAnswerId": "14450",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-08T11:43:18.607",
"Id": "14447",
"Score": "4",
"Tags": [
"python",
"optimization"
],
"Title": "Optimisation of auto-correlation function"
} | 14447 |
<p>I have following code on my login page (now i use it for preventing POST variable resubmit on page refresh):</p>
<pre><code><?php
$cleaner = md5(uniqid(rand(), TRUE));
$_SESSION["cleaner"]=(empty($_SESSION["cleaner"])) ? $cleaner : $_SESSION["cleaner"];
if($_POST['login_button'] && !empty($_POST['clean... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-09T17:49:37.860",
"Id": "23539",
"Score": "1",
"body": "This looks like the OWASP \"Synchronizer Token Pattern\", which should help against CSRF attacks. But because you're using session you may run into problems if the user uses the \... | [
{
"body": "<p>I haven't had the need to worry about this kind of thing before, so I can't claim that this will answer your question, but maybe it will help. It looks simple enough, but <code>rand()</code> may not be the best tool here. I know that, at least with Java, the random function is easily beaten becaus... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-08T13:54:55.890",
"Id": "14453",
"Score": "2",
"Tags": [
"php",
"security"
],
"Title": "Will this code make some attacks (XSS, CSRF...) harder to do?"
} | 14453 |
<p>Currently on my ASP.NET website when I define a new user I write their data to a .txt file like this:</p>
<pre><code>public class User
{
public string UserName;
public string PassWord;
public string Email;
public string FirstName;
public string LastName;
public string Twitter;
public string FaceBook;
public int Age... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-14T01:45:47.637",
"Id": "23752",
"Score": "3",
"body": "Public fields are an idiomatic no-no: http://stackoverflow.com/a/379058/3312"
}
] | [
{
"body": "<p>You don't have to write the file and read it again. You can change the byte array to a string internally using an Encoding and GetString() and split it by new line. Or you can do DownloadString directly and split by line. Reading/writing seems wasteful. Note that you might want to have some securi... | {
"AcceptedAnswerId": "14459",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-08T17:21:20.153",
"Id": "14458",
"Score": "2",
"Tags": [
"c#",
"asp.net"
],
"Title": "Is WebClient.DownloadData acceptable for getting data from a website?"
} | 14458 |
<p>I'm sorry if I have not worded the question title to well, so let me explain.</p>
<p>I am creating a game, actually a few and I see that most of the time when painting ect I use a JPanel, so I went and found a good method of painting (i.e it has great performance when multiple sprites etc are being painted) see her... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-08T14:18:26.367",
"Id": "23417",
"Score": "0",
"body": "I may be wrong, but this seems more of a code-review type question than a specific single answer stackoverflow type question."
},
{
"ContentLicense": "CC BY-SA 3.0",
"... | [
{
"body": "<p>It's a rather interesting piece of code, I'm going to enjoy reading it further when I have more time ;)</p>\n\n<p>About the only things that jump out at me is how you are scaling your graphics. I'd suggest having a read through <a href=\"http://today.java.net/pub/a/today/2007/04/03/perils-of-imag... | {
"AcceptedAnswerId": "14461",
"CommentCount": "9",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-08T14:16:03.953",
"Id": "14460",
"Score": "8",
"Tags": [
"java",
"performance",
"swing"
],
"Title": "What more can be done to add quality to Swing JPanel drawings?"
} | 14460 |
<p>I have an array of values of the form:</p>
<pre><code>configs = ["26W", "27W", "28W"...]
</code></pre>
<p>They correspond to <em>some</em> of the <code>a</code> elements in a list:</p>
<pre><code><ul id="value-list"><li><a data-value="26W">...</a></li>
<li><a data-value="27W... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-08T21:38:46.627",
"Id": "23450",
"Score": "0",
"body": "What's `configs`? Do you mind about cross browser compatiblity?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-08T21:57:31.573",
"Id": "23457",
... | [
{
"body": "<p>A good general performance rule of thumb is to avoid hitting the DOM (the HTML-manipulating stuff) more than necessary. Most DOM properties aren't just static properties that get set from somewhere else as things change. Invoking them tends to involve buildup and tear-down and examining of interna... | {
"AcceptedAnswerId": "14467",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-08T21:18:43.423",
"Id": "14465",
"Score": "2",
"Tags": [
"javascript",
"jquery",
"iteration"
],
"Title": "jQuery iterate or two-step?"
} | 14465 |
<p>Can anyone refactor this code without the for loop?</p>
<pre><code><?php
function lorem($paragraph_count = 1, $times = 1, $content = '')
{
$paragraph = array(
"Lorem ipsum dolor sit amet ......... Fusce a ante.",
"Praesent sit amet est. Vestibulum quis elit ......... consectetuer quis, quam.... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-09T01:34:33.923",
"Id": "23500",
"Score": "0",
"body": "Is your end goal readability/maintainability, or performance (or both)?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-09T02:58:01.650",
"Id": "2... | [
{
"body": "<p>Use <code>array_slice</code> to return a narrow selection from an array:</p>\n\n<pre><code>function random_paragraphs (array $chunks, $length=1) {\n shuffle($chunks);\n return '<p>'.\n implode(\n '</p><p>',\n array_slice(\n $chunks, \n ... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-08T22:19:45.440",
"Id": "14468",
"Score": "0",
"Tags": [
"php"
],
"Title": "Can anyone take the for loop out of this code?"
} | 14468 |
<p>Yes, I'm bad at conditionals. I don't use them so much and I feel a bit lost with them. How would you (if possible) refactor or change this little piece of code?</p>
<p><strong>Second improved version</strong>:</p>
<pre><code>$MAX_FNAME_LEN = 255;
$clientFilename = $this->file->getClientOriginalName();
$c... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-09T04:29:50.670",
"Id": "23503",
"Score": "0",
"body": "is this php? wow, i've never used endif; before, I've always traditionally used { braces and if else statements. What are the benefits to this approach? (this is just a general... | [
{
"body": "<p>Use early exit: reverse the null-checking conditional and return.</p>\n\n<pre><code>if(is_null($clientFilename))\n return;\n</code></pre>\n\n<p>If your code isn’t in a function, <em>change that</em>.</p>\n\n<p>Next, use consistent indentation for the <code>else</code>: it belongs on the same le... | {
"AcceptedAnswerId": "14485",
"CommentCount": "11",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2012-08-09T01:36:41.897",
"Id": "14474",
"Score": "2",
"Tags": [
"php",
"php5"
],
"Title": "Conditionally truncating a filename to a max length without damaging the file extension"
} | 14474 |
<p>As a learn-by-doing project to learn Java webapps, I'm creating a website for registering and displaying happenings using JSP/Servlets, Apache Tomcat server, JDBC and a MySQL database.</p>
<p>I use JSP for views, Servlets for controller functionality and business logic, and I've created ONE DBManager.java class (my... | [] | [
{
"body": "<p>Just a quick note: <code>ArrayList<...></code> return 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",
"comments": [],
"meta_data": {
"CommentCount": "0",
"Conten... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-07T19:24:01.510",
"Id": "14475",
"Score": "4",
"Tags": [
"java",
"database"
],
"Title": "DAO for happenings registration website"
} | 14475 |
<p>I'm doing exercise 11.8 from Scala for impatient, asking to write a matrix class: </p>
<blockquote>
<p>Provide a class <code>Matrix</code> - you can choose whether you want to implement 2
x 2 matrices, square matrices of any size, or m x n matrices. Supply operations + and *. The latter should also work with s... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-10T18:11:02.287",
"Id": "23590",
"Score": "0",
"body": "It's curious how you use a function as part of the constructor parameters. Is that proposed by the book? If so, could you give more details? If not, then I think you went the wron... | [
{
"body": "<p>Remove all <code>var</code>. Doesn't the book show <code>for...yield</code> by that point? For example:</p>\n\n<pre><code>(i,j) => { \n var sum = 0.0; \n for (k <- matrix(i).indices) sum += matrix(i)(k) * another(k)(j); \n sum \n}\n</code></pre>\n\n<p>Can be replaced with:</p>\n\n<pre><co... | {
"AcceptedAnswerId": "14537",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-09T13:42:36.020",
"Id": "14483",
"Score": "4",
"Tags": [
"scala",
"matrix"
],
"Title": "Producing a matrix class that supports any size"
} | 14483 |
<p>Is there a better way to do this? I'm kinda ending up having a lot of <code>if</code> statements.</p>
<pre><code>if params[:custom_url] || params[:user_id]
if !params[:user_id].blank?
@user = User.find(params[:user_id]).first
@url = @user.custom_url
else
@url = params[:custom_url]
@u... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-11T12:23:17.017",
"Id": "23617",
"Score": "1",
"body": "instead of `!params[:user_id].blank?`, you can write `params[:user_id].present?` which reads more nicely."
}
] | [
{
"body": "<p>Not a big fan of <code>case..when</code>:</p>\n\n<pre><code>@user = User.find_first(params[:user_id]) if params[:user_id]\n@user ||= User.find_by_custom_url(@url)\n\n@url = params[:custom_url] || @user.custom_url\n</code></pre>\n",
"comments": [
{
"ContentLicense": "CC BY-SA 3.0"... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-09T15:34:36.987",
"Id": "14487",
"Score": "1",
"Tags": [
"ruby",
"ruby-on-rails"
],
"Title": "Checking custom URLs and user IDs"
} | 14487 |
<p>I calculate a highscore and find the users current rank like shown <a href="https://stackoverflow.com/questions/2195257/ranking-entries-in-mysql-table">here</a>. This is the query:</p>
<pre><code>SELECT * FROM (SELECT q.*, @r := @r + 1 AS rank
FROM ( SELECT @r := 0 ) vars,
(
SELECT p.*, MAX(punkte) AS max_po... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-08T16:12:23.370",
"Id": "23533",
"Score": "0",
"body": "Since rank is calculated on the outer query, is it really necessary here? Could this be calculated in php instead."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDat... | [
{
"body": "<p>What about this query:</p>\n\n<pre><code>SELECT COUNT(*) + 1 as user_rank\n FROM olympia_punkte_alle p\n WHERE markt_id = 1\n GROUP BY fb_id\n HAVING \n MAX(punkte) > (SELECT MAX(punkte)\n FROM olympia_punkte_alle\n WHERE markt_id = 1\n GROUP ... | {
"AcceptedAnswerId": "14489",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-08T16:01:44.030",
"Id": "14488",
"Score": "2",
"Tags": [
"php",
"mysql",
"optimization"
],
"Title": "Speed up highscore rank calculation"
} | 14488 |
<p>I wrote a quick function to create a set of radio buttons, three per table row. I would like some feedback about how I can shorten this bit of code using algebraic functions, or different jQuery functionality.</p>
<pre><code>var arr = [ "earth", "mars", "jupiter", "saturn", "venus", "argus", "pluto", "janus", "cana... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-09T19:59:30.177",
"Id": "23545",
"Score": "0",
"body": "Is this question suitable for CR.se? The code as is does not produce the intended result."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-09T20:08:30.... | [
{
"body": "<p>Here are some points to consider:</p>\n\n<ol>\n<li><p>Your <code>end</code> variable is declared without a <code>var</code>, so that it's leaking into the global namespace. Don't do that.</p></li>\n<li><p>As it stands now, your <code>obj</code> isn't used anywhere in the code. I'll assume it's not... | {
"AcceptedAnswerId": "14500",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-09T18:56:21.440",
"Id": "14497",
"Score": "3",
"Tags": [
"javascript",
"jquery"
],
"Title": "Set of radio buttons"
} | 14497 |
<p>I was asked to implement a hash map in this phone interview (screen-share), so time was limited and this is what I came up with. I'd appreciate if someone can take a minute to critique/review it and help me improve.</p>
<p><a href="http://rextester.com/YJX95968" rel="nofollow">Here</a> is an online version of the c... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-10T10:14:27.267",
"Id": "23570",
"Score": "3",
"body": "A destructor is not enough. You have forgotten the rule of three."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-10T10:39:05.723",
"Id": "23571",... | [
{
"body": "<p><strong>Some obvious problems</strong></p>\n\n<ol>\n<li>It leaks memory (every <code>new</code>ly allocated <code>Node</code>) when the Hashmap leaves the scope.</li>\n<li>A delete/remove function is missing.</li>\n<li><strike>It doesn't replace the value within the existing <code>Node</code> on r... | {
"AcceptedAnswerId": null,
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-09T19:24:11.130",
"Id": "14498",
"Score": "7",
"Tags": [
"c++",
"interview-questions",
"hash-map"
],
"Title": "Implementation of hash map"
} | 14498 |
<p>I saw <a href="https://stackoverflow.com/questions/11886977/how-to-wait-current-thread-execution-and-execute-another-thread-completedly">How to wait current thread execution and execute another thread completedly?</a> on StackOverflow, and I <a href="https://stackoverflow.com/questions/6058395/how-to-pause-thread-ex... | [] | [
{
"body": "<p>The implementation looks fine. Some small notes:</p>\n\n<ol>\n<li>Consider using <a href=\"http://docs.guava-libraries.googlecode.com/git/javadoc/com/google/common/util/concurrent/Uninterruptibles.html#sleepUninterruptibly%28long,%20java.util.concurrent.TimeUnit%29\" rel=\"nofollow noreferrer\">Gu... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2012-08-09T19:52:55.697",
"Id": "14502",
"Score": "1",
"Tags": [
"java",
"multithreading"
],
"Title": "Thread pausing/resuming implementation"
} | 14502 |
<p>I'm very very fresh to programming. This is one of my first experiments with Python and I'm wondering in what ways I could have made this program less clunky. Specifically, is there a way that I could have used classes instead of defining my x, y, and z variables globally?</p>
<pre><code>def getx():
try:
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-09T19:50:05.233",
"Id": "23548",
"Score": "1",
"body": "This belongs on codereview, but I don't see how classes would help. You might want to get rid of the global variables, however and just pass things in via function arguments."
}... | [
{
"body": "<p>Do you have objects, \"things\" that have state and behaviour? I don't see any. So use functions as you do (perhaps improve the code format).</p>\n",
"comments": [],
"meta_data": {
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-09T19:48:52... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-09T19:46:02.923",
"Id": "14503",
"Score": "1",
"Tags": [
"python",
"beginner",
"calculator"
],
"Title": "Python beginner's body fat calculator"
} | 14503 |
<p>I'd like to use lock objects that are specific to the person I'm updating. In other words, if thread A is updating Person 1, thread B is blocked from also updating Person 1, but thread C is not blocked from updating Person 2.</p>
<p>99% of the time, I don't really need the locks since I'm working with different Per... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-17T19:27:48.610",
"Id": "24061",
"Score": "0",
"body": "Are the person objects stored in some data structure that all threads have access to? If they are, then can't you just lock the person object itself?"
},
{
"ContentLicense... | [
{
"body": "<p>Your code would do just fine, in terms of functionality.</p>\n\n<p>However, note that such design holds as long as everybody knows that they should acquire the lock before performing any process on the person object.</p>\n\n<p>Perhaps you should consider re-design your data objects (such as the pe... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-10T03:40:43.483",
"Id": "14519",
"Score": "11",
"Tags": [
"c#",
".net",
"multithreading",
"cache"
],
"Title": "Using different instances of an object to lock threads"
} | 14519 |
<p>I've just finished a week long adventure of creating an <a href="http://jsfiddle.net/MtypZ/64/" rel="nofollow">HTML5 Drag and Drop scheduler</a>. As the prototype stands it works fine, but I'm curious if some of the code can be optimized. I mostly focused on it being readable and well documented, but I'm curious if ... | [] | [
{
"body": "<p>I don't really address the concrete questions you made; I hope someone else does. :)</p>\n\n<hr>\n\n<blockquote>\n <p>As the prototype stands it works fine</p>\n</blockquote>\n\n<p>Famous last words! You have at least two bugs:</p>\n\n<ol>\n<li>Drag D on top of B, and B is lost forever.</li>\n<li... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-10T07:04:43.687",
"Id": "14522",
"Score": "4",
"Tags": [
"javascript",
"jquery",
"html5"
],
"Title": "Drag and drop script"
} | 14522 |
<p>I an a newcomer in the Scala world, and I would like some advice from more experienced people to find out whether what I am writing goes in the direction of idiomatic code.</p>
<p>In particular, I have to write a simple algorithm that will do the following. We are given an integer number of, say, candies to be dist... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-10T14:52:43.207",
"Id": "23575",
"Score": "0",
"body": "Arguably it should be 5, 3, 9 -- the second group has a smaller piece than the last one, so it should be the last one to get it. What's the criteria for distributing remains?"
}... | [
{
"body": "<p>Ok, I'm changing the answer now that I understand what you are doing.</p>\n\n<p>The main problem here is <code>@/</code> -- while Scala people, in general, don't mind special operators, they don't add operators just because they can either. You can replace <code>@/</code> with the existing <code>/... | {
"AcceptedAnswerId": "14531",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-10T10:12:32.407",
"Id": "14524",
"Score": "2",
"Tags": [
"algorithm",
"scala",
"beginner"
],
"Title": "First steps in Scala: does this look idiomatic?"
} | 14524 |
<p>I have been writing a jQuery widget for a couple of days now. Originally I needed this functionality for something I am writing at work, but I felt like I could abstract it a little more so here I am. I think it's about finished for now, I may add some features depending on how It gets used (if it does).</p>
<p>Thi... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-13T10:49:11.017",
"Id": "29556",
"Score": "1",
"body": "Just skimmed through it, and it seems well-structured and nicely commented. Kudos! I also tried running it through [jshint](http://jshint.com/) which found a few things like missi... | [
{
"body": "<p>From a once over:</p>\n\n<ul>\n<li><p>Do not do this:<br></p>\n\n<pre><code>if(options.selectable != null)\n</code></pre>\n\n<p>do either</p>\n\n<pre><code>if(options.selectable)\n</code></pre>\n\n<p>or</p>\n\n<pre><code>if(options.selectable !== null) //Notice the ==\n</code></pre></li>\n<li>You ... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-10T12:34:33.993",
"Id": "14525",
"Score": "3",
"Tags": [
"javascript",
"jquery"
],
"Title": "jQuery list widget"
} | 14525 |
<p>I find this code quite ugly, but in fact, I can't find a finer way of achieving the goal.</p>
<pre><code>private static final String TABLE_NAME = "table_name";
private static final String[] allNeededColumns = {"col_id","col_one","col_two"};
public int[] getItemIds(int category_id) {
ArrayList<Integer> id... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-12T10:07:28.527",
"Id": "23647",
"Score": "0",
"body": "blame java for the way primitives are handled. you can use a library such as [Guava](http://docs.guava-libraries.googlecode.com/git/javadoc/com/google/common/primitives/Ints.html#... | [
{
"body": "<p>If you were going to use the above you could still utilise Java's autoboxing feature, but there is a shorter form as hinted at by Darth Beleg.</p>\n\n<p>Untested:</p>\n\n<pre><code>int[] ret = new int[c.getCount()];\nif (c.moveToFirst())\n for (int i = 0; i < c.getCount();) {\n ids[i+... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-10T13:06:54.937",
"Id": "14526",
"Score": "2",
"Tags": [
"java",
"array",
"android",
"collections",
"integer"
],
"Title": "Get int array from database Cursor"
} | 14526 |
<p>Inspired by another thread on here I was wondering if I could have an expert eye passed over this script?</p>
<p>If I run the script with App1, App2 or App3 individually it takes about 3 mins per run. However when I invoke the ALL option that time increases to an hour. I'm no doubt managing my memory awfully so a... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-10T15:27:13.607",
"Id": "23576",
"Score": "1",
"body": "Where is the profiler output?"
}
] | [
{
"body": "<p>This may not account for everything, but notice that you're doing more work in <code>ALL</code> than in the sum of the other options.</p>\n\n<p>See <code>App1</code> for example - you iterate over [SM1, SM2, SM3] x [IL2CMS, IL2FORMS, IL2PORTAL, IL3FORMS, IL3COMMS] which is 15 combinations of (envi... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-10T13:41:04.437",
"Id": "14528",
"Score": "1",
"Tags": [
"python",
"ant"
],
"Title": "Ant database and configuration manager"
} | 14528 |
<p>I like the modular aspect of AMDs (Asynchronous Module Definition; see this <a href="https://stackoverflow.com/a/8127152/270274">Stack Overflow reply</a>) and it's quite neat to structure JS.</p>
<p>But I typically compile all my JS files into one JS file. Therefore I don't really need the asynchronous part. So I t... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-10T15:41:18.203",
"Id": "23577",
"Score": "0",
"body": "\"see this StackOverflow reply\" -> That's not a reply. That's an user profile."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-03T21:37:31.800",
... | [
{
"body": "<p>I re-read your code several things, I can't say I would want to use it.</p>\n\n<ul>\n<li><p>Requiring the parameters to be modules seems neat with 1 module or 2. For larger applications, that would become silly.</p></li>\n<li><p>The most common use case with require is <code>var xxx = load(\"Xxx\"... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-10T14:49:44.190",
"Id": "14530",
"Score": "3",
"Tags": [
"javascript",
"asynchronous"
],
"Title": "A little \"infile\" Asynchronous Module Definition"
} | 14530 |
<p>I'm wrote a simple function <code>isBalanced</code> which takes some code and returns <code>true</code> if the brackets in the code are balanced and <code>false</code> otherwise:</p>
<pre><code>function isBalanced(code) {
var length = code.length;
var delimiter = '';
var bracket = [];
var matching =... | [] | [
{
"body": "<p><code>The function must not operate on brackets inside strings and comments.</code></p>\n<p>If that's the case then why not just compare the number of opened vs closed symbols?</p>\n<p>Example:</p>\n<pre><code>var haveSameLength = function(str, a, b){\n return (str.match(a) || [] ).length === (... | {
"AcceptedAnswerId": "15339",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-10T15:38:34.833",
"Id": "14532",
"Score": "7",
"Tags": [
"javascript",
"balanced-delimiters"
],
"Title": "Checking for balanced brackets in JavaScript"
} | 14532 |
<p>Example of a C++ function which removes duplicates from a string:</p>
<pre><code>string remove_duplicates(string subject)
{
string no_duplicates("");
for(int i = 0; i < (int) subject.length(); i++) {
bool found = false;
for(int j = 0; j < (int) no_duplicates.length(); j++) {
if (no_dupli... | [] | [
{
"body": "<p>If you don't need to modify a parameter always use <code>const</code> and try to take references. For your exact problem try to create a simple boolean function, e.g. which checks if a character is already in the string. This simplifies things a lot and improves the readability.</p>\n\n<p>In your ... | {
"AcceptedAnswerId": "14540",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-08-10T21:54:27.663",
"Id": "14539",
"Score": "5",
"Tags": [
"c++"
],
"Title": "Optimize loop check"
} | 14539 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.