body
stringlengths
25
86.7k
comments
list
answers
list
meta_data
dict
question_id
stringlengths
1
6
<p>I am playing with different ways to do database interaction in PHP, and one of the ideas I have been playing with is connecting to the DB in the constructor and disconnecting in the destructor. This is the code from my <code>Database</code> class.</p> <pre><code>function __construct() { $this-&gt;link = mysql_con...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2020-11-18T07:49:12.973", "Id": "496986", "Score": "0", "body": "Look at the URL number. This is the first question humanity ever asked here!" } ]
[ { "body": "<p>You could use MySQLi (PHP extension) which is class based by default instead of MySQL. It \nis very easy to set up multiple connections. You are, however, required to know the connection you are querying always.</p>\n\n<hr>\n\n<p>Congrats with the first question.</p>\n", "comments": [], "m...
{ "AcceptedAnswerId": "5", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-01-19T21:02:47.183", "Id": "1", "Score": "39", "Tags": [ "php", "mysql", "constructor" ], "Title": "Database connection in constructor and destructor" }
1
<p>I'd like suggestions for optimizing this brute force solution to <a href="http://projecteuler.net/index.php?section=problems&amp;id=1">problem 1</a>. The algorithm currently checks every integer between 3 and 1000. I'd like to cut as many unnecessary calls to <code>isMultiple</code> as possible:</p> <pre><code>''...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-01-19T21:06:48.893", "Id": "3", "Score": "1", "body": "Are you trying to optimize the algorithm or the code itself?" }, { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-01-19T21:07:15.663", "Id": "5", "Score":...
[ { "body": "<p>I think the best way to cut out possible checks is something like this:</p>\n\n<pre><code>valid = set([])\n\nfor i in range(3, end, 3):\n valid.add(i)\n\nfor i in range(5, end, 5):\n valid.add(i)\n\ntotal = sum(valid)\n</code></pre>\n\n<p>There's still a bit of redundancy (numbers which are mult...
{ "AcceptedAnswerId": null, "CommentCount": "7", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-01-19T21:04:27.573", "Id": "2", "Score": "56", "Tags": [ "python", "optimization", "algorithm", "programming-challenge" ], "Title": "Project Euler problem 1 in Python - Multiples of...
2
<p>Basically, I had written this class a little while ago to ease autoloading of our local libraries. </p> <p>The premise is that everything is split by packages into multiple layers of sub-packages. Classes are named using CamelCasing. So, a class' name is related to its package as follows: <code>PackageSubpackageS...
[]
[ { "body": "<p>The first problem I see is that there are a lot of cases where someone will want to create a class with more than one word in the name (DataMapper), and the autoloader you have provided won't allow for that. I would recommend using another character to delimit between package names. The Zend Fra...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-01-19T21:07:43.573", "Id": "4", "Score": "27", "Tags": [ "php", "library" ], "Title": "PHP Autoloader Library" }
4
<p>I started programming with Java and C++, so I'm used to having a 'main' function that calls other functions that do the actual work. At university I was always told that doing actual computation in the main function is bad practice. I'm currently playing around with Python, and I have trouble figuring out how to wri...
[]
[ { "body": "<p>In most of the Python code I've ever seen, there is normally a main function defined that you call from the condition you put to establish the script was executed and not imported. I believe that's the standard way of doing things in Python, but I don't believe its actually a written rule anywher...
{ "AcceptedAnswerId": "8", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-01-19T21:16:08.443", "Id": "7", "Score": "60", "Tags": [ "python", "programming-challenge" ], "Title": "Using separate functions for Project Euler 1" }
7
<p>I have a method that has a lot of loops:</p> <pre><code>private void update(double depth) { Console.WriteLine("update with level " + depth); this.Dispatcher.Invoke(System.Windows.Threading.DispatcherPriority.Normal, new Action(delegate() { List&lt;Grid...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-01-19T21:26:50.047", "Id": "29", "Score": "17", "body": "tl;dr. You'll likely have a better response if you remove a lot of the boilerplate or focus on the part you're really interested in. I think pseudo-code would help a lot here." ...
[ { "body": "<p>Break this down into several methods - it's very long, meaning it's not easy to read.</p>\n", "comments": [ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-01-20T00:28:01.803", "Id": "67", "Score": "1", "body": "Actually it is even longer...
{ "AcceptedAnswerId": "13", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-01-19T21:19:59.470", "Id": "9", "Score": "34", "Tags": [ "c#", "performance", "algorithm" ], "Title": "Too many loops in Drawing App" }
9
<p>I use <a href="https://codeigniter.com/" rel="nofollow noreferrer">CodeIgniter</a> at work, and one of our model files had a lot of subqueries in it. I originally had to manually write each subquery, and wondered if I could use active records instead.</p> <p>So, to make my life easier, I made a subquery library for...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-01-19T21:50:27.920", "Id": "42", "Score": "1", "body": "Why is $db an array?" }, { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-01-19T21:55:41.490", "Id": "46", "Score": "0", "body": "@Time Machine: `$db...
[ { "body": "<p>I may be missing something here,\nBut to me it seems that you have a class that you pass a pre-built query into?</p>\n\n<p>I am thinking would it not be beneficial to have a subquery built the same way as the top level queries?</p>\n", "comments": [ { "ContentLicense": "CC BY-SA ...
{ "AcceptedAnswerId": "277", "CommentCount": "10", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2011-01-19T21:24:11.093", "Id": "12", "Score": "29", "Tags": [ "php", "mysql", "codeigniter" ], "Title": "CodeIgniter Active Record Subqueries" }
12
<p>So I've had a problem where I need to compare data in 2 different tables on two different servers. Now, I know MySQL supports <code>CHECKSUM TABLES</code>, but from my testing and understanding, it's not reliable across server instances and versions. </p> <p>So I created this query:</p> <pre><code>$part = '@CRC ...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-01-19T21:37:10.357", "Id": "35", "Score": "1", "body": "It may be overkill for your problem but have you looked at MYSQL clusters to handle mirroring and distributing of data. It would offer other features that may be useful." }, { ...
[ { "body": "<p>We use <a href=\"http://www.maatkit.org/doc/mk-table-checksum.html\"><code>mk-table-checksum</code></a>. </p>\n\n<p>It works really great in Master-Slave context where it also allows to sync differences in both directions depending on your choice.</p>\n\n<p>Saidly from what i've seen most people i...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-01-19T21:28:43.283", "Id": "16", "Score": "9", "Tags": [ "php", "mysql", "sql" ], "Title": "Comparing data in 2 tables on different servers with CHECKSUM" }
16
<p>A while back, I reverse-engineered a checksum algorithm from an <a href="http://en.wikipedia.org/wiki/Massively_multiplayer_online_game" rel="noreferrer">MMO</a> used to check the validity of an item that's linked to chat (similar to <a href="http://en.wikipedia.org/wiki/World_of_Warcraft" rel="noreferrer"><em>WoW</...
[]
[ { "body": "<p>The only things I can see having problems are your acronym variable names i.e. (eax, ecx, ebx, and edi) don't explain what the variables are storing clearly for someone not experienced with doing checksums.</p>\n\n<p>The other thing I can see for readability issues is your all lowercase variable n...
{ "AcceptedAnswerId": "30", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-01-19T22:02:29.033", "Id": "22", "Score": "20", "Tags": [ "c++", "checksum" ], "Title": "Custom checksum algorithm" }
22
<p>I'm generating CSV strings for various 3rd party utilities and this section of code gets repeated in many classes. Is there a better way to generate this string?</p> <pre><code>public override string CsvString() { return ( string.Format("\u0022{0}\u0022,\u0022{1}\u0022,\u0022{2}\u0022,\u0022{3}\u0022,\u...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-01-19T23:02:53.407", "Id": "56", "Score": "0", "body": "I would use a StringBuilder if this was for Java. There might be a C# equivalent?" }, { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-01-19T23:37:37.547", "...
[ { "body": "<p>Use a <code>StringBuilder</code>:</p>\n\n<pre><code>sbuilder.AppendFormat(\"\\u0022{0}\\u0022,\\u0022{1}\\u0022,\\u0022{2}\\u0022,\\u0022{3}\\u0022,\\u0022{4}\\u0022,\\u0022{5}\\u0022,\\u0022{6}\\u0022,\\u0022{7}\\u0022,\\u0022{8}\\u0022,\\u0022{9}\\u0022,\\u0022{10}\\u0022,\\u0022{11}\\u0022,\\u0...
{ "AcceptedAnswerId": "74", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-01-19T22:56:59.883", "Id": "36", "Score": "23", "Tags": [ "c#", "csv", "strings" ], "Title": "Generating CSV strings for various 3rd party utilities" }
36
<p>A few functions to let me manage TAGS files more easily. Typically, my projects contain at least one sub-folder. I got sick of manually updating, so I wrote this to help me update a single TAGS file per project (always in the projects' root directory).</p> <p>Please share your thoughts (aside from "Why are you usin...
[]
[ { "body": "<h3>General notes</h3>\n\n<ul>\n<li>Always prefix your functions with the name of your package or project, e.g. <code>tagariffic-create-tag-table</code> and so on. Emacs has no package scoping.</li>\n<li>Whenever possible (i.e. in the absence of mutual recursion), define your functions before using t...
{ "AcceptedAnswerId": "3633", "CommentCount": "0", "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-01-20T00:10:13.883", "Id": "45", "Score": "16", "Tags": [ "elisp" ], "Title": "Emacs Etags Shortcut Functions" }
45
<p>This shows a test case for an old caching library that I use for a project. It features simple save/load/delete functions (sadly static calls) but what I want to focus on is the test code written for this class.</p> <p>In my opinion the unit tests for a class should show how all functions in the class work and what...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-01-20T19:19:00.860", "Id": "162", "Score": "0", "body": "This looks like the long-code-questions version of Stack Overflow" } ]
[ { "body": "<p>I lack the syntax knowledge to say I understand the class. I can say reading it is a bit hard due to long lines and the fact that the dominant patterns are repetitive method/variable names. Test names are descriptive enough </p>\n\n<p>Maybe if you could extract methods like <code>DatenCache::load<...
{ "AcceptedAnswerId": "62", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-01-20T00:42:35.173", "Id": "47", "Score": "12", "Tags": [ "php", "unit-testing", "cache" ], "Title": "Test case for a caching library" }
47
<p>I am currently developing a custom CMS being built on top of Codeigniter and was wondering if you can spot any flaws in my page fetching model code. The page fetching model is not entirely complete but the main functionality for retrieving a page is done, as well as retrieving modules assigned to a page (a module is...
[]
[ { "body": "<p>I don't know Codeigniter so i can't comment on \"is this a propper model\". For my answer i'm just going to assume it is.</p>\n\n<p>It's not much code so i'm going to focus on some details: </p>\n\n<hr>\n\n<pre><code> public function __construct()\n {\n parent::__construct();\n }\n</code><...
{ "AcceptedAnswerId": "289", "CommentCount": "0", "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-01-20T00:51:36.533", "Id": "48", "Score": "7", "Tags": [ "php", "codeigniter", "mvc" ], "Title": "Critique My Codeigniter Custom CMS Pages Model" }
48
<p>Here's my <code>bootstrap.php</code> for my PHP/MySQL/Doctrine app. It's my first PHP app so I'm interested in learning from the experience of others how this could be improved - security-wise, performance-wise, or otherwise.</p> <pre><code>//------------------------------------------------------------------------...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-01-20T01:30:57.793", "Id": "73", "Score": "0", "body": "How different is this from the default template? Can you link to it?" }, { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-01-20T03:30:06.800", "Id": "80", ...
[ { "body": "<p>Here are a few lines that might be useful to add if you would like to use these options:</p>\n\n<pre><code>/**\n * Needed for SoftDelete to work\n */\n$manager-&gt;setAttribute(Doctrine::ATTR_USE_DQL_CALLBACKS, true);\n\n/**\n * Tell doctrine to look for custom ___Table classes in the models folde...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-01-20T00:52:25.113", "Id": "49", "Score": "6", "Tags": [ "php", "mysql", "doctrine" ], "Title": "PHP/Doctrine bootstrap for review" }
49
<p>I'm making a "guess that tune" game in Visual Basic 6 that is supposed to play each song in a random order:</p> <pre><code>' from frmGuessGame.frm Private Sub Swap(ByRef Value1 As Variant, ByRef Value2 As Variant) Dim Temporary As Variant Temporary = Value1 Value1 = Value2 Value2 = Temporary End Sub Private Sub Sh...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-01-20T00:55:48.870", "Id": "70", "Score": "0", "body": "Aside: [My question from the proposal](http://area51.stackexchange.com/proposals/11464/code-review/25308#25308). I actually wrote this code years ago (2004) before I knew any better....
[ { "body": "<p>I would probably do something like this:</p>\n\n<p>I don't know VB so this is pseudo code.</p>\n\n<pre><code>Private Function Shuffle(playlist) as Playlist\n{\n Dim PlayList as NewPlayList\n Dim RandomIndex as Integer\n\n while(playlist has elements)\n {\n RandomIndex = (Random n...
{ "AcceptedAnswerId": "98", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-01-20T00:54:38.853", "Id": "50", "Score": "19", "Tags": [ "algorithm", "vb6", "random", "shuffle" ], "Title": "Shuffling algorithm for a \"guess that tune\" game" }
50
<p>I implemented the Shamos-Hoey algorithm to check if a closed shape is self-intersected. Is this algorithm ok in terms of performance?</p> <pre><code>public boolean isSelfIntersected() { Set&lt;Line2D&gt; plines = new HashSet&lt;Line2D&gt;(); for (Path2D ps : this.getPath()) { PathIterator p_it = ps....
[]
[ { "body": "<p>The question of whether your code is performant enough is something your profiler can better answer for you. But from looking through the code above I notice quite a bit of duplication along with some rather deeply nested if's which you should try to refactor. Take this for example:</p>\n\n<pre><c...
{ "AcceptedAnswerId": "127", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-01-20T05:20:50.317", "Id": "69", "Score": "17", "Tags": [ "java", "algorithm", "computational-geometry" ], "Title": "Shamos-Hoey algorithm for checking the self-intersection of a close...
69
<p>I've implemented a PID controller, but seeing as I'm not an expert in control theory, have I missed any edge cases?</p> <pre><code>public class PIDController { public enum PIDMode { Manual, Auto, } public enum PIDAction { Indirect, Direct, } public PIDMo...
[]
[ { "body": "<p>It looks reasonable, but I don't see why you need to make the Proportional term a member of the class, it doesn't need to be saved, at best it might make sense to be able to query it with a get, but a set seems misleading.</p>\n\n<p>I'd be reluctant to allow public setting of the Integral and Deri...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-01-20T06:31:36.730", "Id": "72", "Score": "13", "Tags": [ "algorithm", "c#" ], "Title": "Implementation of a PID Controller" }
72
<p>This plugin is written in jQuery and is made to support <a href="http://codeigniter.com" rel="nofollow">the codeigniter framework</a>. It is an ajax powered table pagination plugin designed to provide only that. You should be able to use almost any other table scripts with this plugin.</p> <pre><code>(function($){ ...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-01-20T12:10:59.513", "Id": "119", "Score": "2", "body": "I don't have time to take a bigger look at the code right now but I can point out some obvious issues. Not using the strict equals operator (`===`) may lead to subtle bugs. Not usi...
[ { "body": "<p>That's a large piece of code.</p>\n\n<p>I highly recommended to use lower camel case for variables.</p>\n\n<p>Here are some hints from me, just only micro-refactoring.</p>\n\n<blockquote>\n<pre><code>if(term.length &gt;= 3) {\n if(replaced)\n load_data(1, term, true, false);\n else\n load_...
{ "AcceptedAnswerId": "327", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-01-20T09:21:34.217", "Id": "77", "Score": "7", "Tags": [ "javascript", "performance", "jquery", "ajax", "pagination" ], "Title": "Pagination plugin" }
77
<p>Is this the best way to implement this pattern in C#?</p> <pre><code>public sealed class Singleton { private static readonly Singleton instance = new Singleton(); public static Singleton Instance { get { return instance; } } static Singleton() {} private Singleton() {} } </code></pre>
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-05-07T02:53:33.217", "Id": "18504", "Score": "8", "body": "[Singleton is an antipattern](http://thetechcandy.wordpress.com/2009/12/02/singletons-is-anti-pattern/)." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-...
[ { "body": "<p>I always use this solution if I have to implement a Singleton in C#</p>\n\n<pre><code>public sealed class Logging\n {\n static Logging instance = null;\n static readonly object lockObj = new object();\n\n private Logging()\n {\n }\n\n public static Logg...
{ "AcceptedAnswerId": "81", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-01-20T10:02:03.633", "Id": "79", "Score": "67", "Tags": [ "c#", "singleton" ], "Title": "Implementing a Singleton pattern in C#" }
79
<p>I'm listing elements with a <code>foreach</code>, and I would like to enclose items in something tag <code>n</code> by <code>n</code>:</p> <pre><code>$i = 0; $open = $done = TRUE; $n = 3; $opening = "&lt;div&gt;"; $closing = "&lt;/div&gt;"; $names = array("Doc", "Marty", "George", "Lorraine", "Einstein", "Biff"); ...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-01-20T11:03:10.900", "Id": "104", "Score": "1", "body": "@albert can you also add what n and the condition is suppose to represent? Does it get it's value from another part of the code?" }, { "ContentLicense": "CC BY-SA 2.5", ...
[ { "body": "<p>One problem with your solution is that it won't print the last closing <code>&lt;/div&gt;</code> tag if there are less than <code>$n</code> elements inside the last <code>&lt;div&gt;</code>.</p>\n\n<p>An approach which fixes that problem and also simplifies the conditional logic for deciding when ...
{ "AcceptedAnswerId": "90", "CommentCount": "7", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-01-20T10:25:28.040", "Id": "82", "Score": "7", "Tags": [ "php" ], "Title": "Loop with enclosing items every 'n' steps" }
82
<p>I was wondering for quite some time how to clean up the below code without blowing it up any further. The extension of the classes is the main concern here, it looks a bit too much like magic. That's mainly because it has to handle all the different cases, and I haven't figured out a way to reduce the code in a mean...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-01-26T23:40:36.333", "Id": "391", "Score": "2", "body": "Don't emulate classes. This is ECMAScript." }, { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-02-10T23:32:30.313", "Id": "1335", "Score": "0", "bo...
[ { "body": "<p>A few tips:</p>\n\n<ul>\n<li>Make sure your using good indentation</li>\n<li>Do not create a function that runs a native method\n<ul>\n<li>so: <code>if(is(\"Function\",ext))</code> becomes <code>if(typeof ext == \"Function\")</code></li>\n</ul></li>\n<li>remove unnecessary comments and comments sh...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-01-20T10:56:43.527", "Id": "85", "Score": "19", "Tags": [ "javascript", "classes" ], "Title": "Cleaning up class creation / extension" }
85
<p>I'm new to Postgres and PostGIS, but not to geospatial applications.</p> <p>I have a table loaded up with graph data in the form of links (edges). The link database has about <strong>60,000,000</strong> rows. I am trying to extract the nodes to allow for quicker searching. For some of my proof-of-concept work I was...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-01-21T00:40:10.920", "Id": "173", "Score": "0", "body": "Yes Postgres doesn't like the VACUUM ANALYZE in a script like that. However the rest appears to have worked okay." } ]
[ { "body": "<p>Check out <a href=\"http://www.postgresql.org/docs/8.2/static/populate.html\" rel=\"noreferrer\">PostgreSQL's tips on adding a lot of data into a table</a>. In particular, are you sure that you need that index before <code>INSERT</code>ing all that data? It might speed things up if you create the ...
{ "AcceptedAnswerId": "254", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-01-20T13:55:23.193", "Id": "92", "Score": "8", "Tags": [ "sql", "postgresql" ], "Title": "Extracting nodes from a graph database" }
92
<p>I have written a method to tokenize HTTP request paths such as <code>/employee/23/edit</code>:</p> <pre><code>protected void compile(String path){ int mark=0; for(int i=0; i&lt;path.length(); ++i){ if(path.charAt(i)==DELIM){ if(mark!=i) tokens.add(path.substring(mark,i));...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-01-20T18:23:19.373", "Id": "155", "Score": "1", "body": "Wouldn't String.split() work better for tokenizing a String (http://download.oracle.com/javase/1.4.2/docs/api/java/lang/String.html#split(java.lang.String))?" }, { "ContentL...
[ { "body": "<p>Your first <code>compile</code> method can be replaced by a single call to <code>String.split</code>.</p>\n\n<p>Assuming the intended behavior for the second <code>compile</code> method is such that \"/foo/b[a]r/baz\" will compile to <code>{\"foo\", \"?\", \"baz\"}</code>, it can be replaced by a ...
{ "AcceptedAnswerId": "110", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-01-20T18:14:40.340", "Id": "109", "Score": "14", "Tags": [ "java", "parsing", "url" ], "Title": "HTTP request path parser" }
109
<p>I have written this (truncated) code to fetch some tweets:</p> <pre><code> dispatch_async(dispatch_get_global_queue(0, 0), ^{ [[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES]; NSString *JSONStr = [NSString stringWithContentsOfURL:[NSURL URLWithString:@"http://search.twitter.com/s...
[]
[ { "body": "<p>you don't necessarily have to call -setNetworkActivityIndicatorVisible: from the main thread. I didn't find anything in the documentation about UIApplication not being thread safe, and since your application's main thread doesn't have anything in common with the system, you are free to call it whe...
{ "AcceptedAnswerId": "195", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-01-20T19:19:39.800", "Id": "112", "Score": "14", "Tags": [ "multithreading", "objective-c", "twitter" ], "Title": "Fetching tweets" }
112
<p>I have a Perl application that allows the user to choose between two different formats for data output (and there will likely be more in the near future). In the heart of the algorithm, the code makes a call to a print subroutine.</p> <pre><code>my $stats = analyze_model_vectors( $reference_vector, $prediction_vect...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-05-30T18:26:59.350", "Id": "4224", "Score": "1", "body": "Big if/elsif/else chains are ugly. The canonical method of handling this case in Perl is to use a dispatch table: a hash containing subroutine references. See Charles Bailey's re...
[ { "body": "<p>I try to avoid Perl if I can, so this is more of a general answer: I've coded like this in an old VB6 app. Each output function had a wrapper function that then called the required implementation using a series of IFs. Sometimes a particular output method wouldn't need anything - eg. \"Start New L...
{ "AcceptedAnswerId": "118", "CommentCount": "2", "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-01-20T20:31:26.477", "Id": "115", "Score": "14", "Tags": [ "perl", "subroutine" ], "Title": "Subroutine to call other subroutines" }
115
<p>So I have a series of objects, which I will call Impl1, Impl2, and Impl3. They each implement an interface, called IImpl. I have a Factory class who's task is to retrieve the ImplX which is appropriate for a given circumstance, and pass it on to its callers. So the code in the factory looks like:</p> <pre><code>...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-01-22T13:52:27.023", "Id": "245", "Score": "0", "body": "I think either we need more information, or you're expectations can't be met: if you are required to pass different kinds of parameters to this factory for it to work properly, then...
[ { "body": "<p>How about some kind of intermediary blackboard that the client code constructs before calling the factory, and each concrete Impl can poll to construct itself?</p>\n\n<pre><code>// client code:\n\nBlackboard blackboard = new Blackboard();\nblackboard.pushCollectionB(collectionB);\nblackboard.pushC...
{ "AcceptedAnswerId": "129", "CommentCount": "1", "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-01-21T14:07:09.330", "Id": "128", "Score": "23", "Tags": [ "c#", ".net", "design-patterns" ], "Title": "Best way to pass parameters to Factory class?" }
128
<p><em>Inspired by <a href="https://codereview.stackexchange.com/q/97">this question</a>, but hopefully not a duplicate.</em></p> <p>I understand that the Law of Demeter is very useful in case of services interacting with other services, for example it's much easier to mock the other services in unit tests. What about...
[]
[ { "body": "<p>I'd say that it isn't cluttering the model personally. You are actually protecting yourself by not exposing internal implementation of your document class. The entire idea is to put all of your behavior into your class instead of having external code modify the class in such a way that it may no...
{ "AcceptedAnswerId": "153", "CommentCount": "0", "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-01-21T16:26:15.320", "Id": "131", "Score": "27", "Tags": [ "java", "design-patterns" ], "Title": "Law of Demeter and data models?" }
131
<p>Code Review - Stack Exchange is for <strong>sharing code from projects you are working on</strong> for peer review. If you are looking for feedback on a specific working piece of code from your project in the following areas&hellip;</p> <ul> <li>Best practices and design pattern usage</li> <li>Security issues</li> ...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-01-21T18:08:20.040", "Id": "135", "Score": "0", "Tags": null, "Title": null }
135
<p>Would this function be sufficient enough to remove all malicious code and foreign characters from a string?</p> <pre><code>//Clean the string $out = ltrim($do); $out = rtrim($out); $out = preg_replace('/[^(\x20-\x7F)]*/','', strip_tags($out)); </code></pre> <p>This data is not going into a SQL database, so I dont...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-01-21T18:09:36.597", "Id": "211", "Score": "2", "body": "How are you using this string that you are worried about it being an attack vector? Where is the string coming from? What do you expect it to contain? Please add that to the quest...
[ { "body": "<p>That one is quite simple (for me at least) since there is a very general answer :)</p>\n\n<h2>NO</h2>\n\n<p>There is no way you can ever really safely \"repair\" user input.</p>\n\n<blockquote>\n <p>\"Please provide a list of everything you shouldn't to with a hammer\" </p>\n</blockquote>\n\n<p>i...
{ "AcceptedAnswerId": "137", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-01-21T18:08:22.390", "Id": "136", "Score": "11", "Tags": [ "php", "strings", "security", "regex" ], "Title": "Is this a sufficient way to prevent script injections and other bad st...
136
<p>I don't like the fact that I am selecting all the points, even though I only care about the count of them.</p> <p>Which of the <code>from</code> parts should appear first, if it even matters?</p> <pre><code>var count = (from type in ValidTypes() from point in GetData(type) where point.Radius &gt; reference...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-01-21T19:28:47.677", "Id": "218", "Score": "1", "body": "Is this a Linq to sql query or linq to objects?" }, { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-01-21T19:56:25.033", "Id": "222", "Score": "0", ...
[ { "body": "<p>First, your query is written fine. Its structure is not a concern; the order of the froms is clearly correct, the select is appropriate. Where you could look for improvement that could change the query (code and possibly performance) would be in the <code>GetData</code> method. If, for example, <c...
{ "AcceptedAnswerId": "144", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-01-21T19:10:07.230", "Id": "138", "Score": "13", "Tags": [ "c#", "linq" ], "Title": "Counting the number of points that have both a larger theta and a larger radius than a given point" }
138
<p>This is a function I wrote yesterday and have tested with lots of input. It's been committed and is in use, but no review was done, so it seems like a good candidate for Code Review: it could be more readable and maybe refactored into simpler functions.</p> <p>Its purpose is to give the longest common path and a st...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-09-05T05:12:09.947", "Id": "49000", "Score": "0", "body": "nice bit of code" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2017-12-15T09:31:37.710", "Id": "347859", "Score": "0", "body": "Starting with Py...
[ { "body": "<pre><code>dirname = os.path.dirname\nbasename = os.path.basename\n</code></pre>\n\n<p>This can be written as:</p>\n\n<pre><code>from os.path import dirname, basename\n</code></pre>\n\n<p>The from..import will check that os.path is imported (and import it if not), but is otherwise identical. I find ...
{ "AcceptedAnswerId": "266", "CommentCount": "2", "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-01-21T20:09:42.960", "Id": "142", "Score": "15", "Tags": [ "python", "unit-testing" ], "Title": "Function for finding longest common path and formatting it along with filenames" }
142
<p>I do most of my programming in C/C++ and Perl, but I currently learning Fortran. I began by coding up a simple program, something that took me &lt; 5 minutes in Perl (see <a href="http://biostar.stackexchange.com/questions/4993/extracting-set-of-numbers-from-a-file" rel="noreferrer">this thread</a> from BioStar). Af...
[]
[ { "body": "<p>I've seen some pretty nasty Fortran in my time: Research departments seem to be the worse source! Your code is far, far superior to their code!</p>\n\n<p>In those days we were using an extended form of Fortran 77 with some structured extensions and formatting niceties. There was no avoiding GOTOs ...
{ "AcceptedAnswerId": "269", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-01-21T20:28:47.330", "Id": "145", "Score": "14", "Tags": [ "file", "fortran" ], "Title": "Extracting a set of numbers from a file" }
145
<p>It's a little bit more code but I wanted to show the full class. I highlight the points I'd like input after the source.</p> <p>I've cut comments since they where not in English and translated the important ones.</p> <p>The class is inspired by PearDb (too old) and Zend_DB (to cluttered / unfinished at the time) a...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-01-21T21:14:24.183", "Id": "227", "Score": "3", "body": "This is one of the most readable bits of PHP I've ever seen, should be even better with the original comments. Maybe you could extract the common massaging before `call_user_func_ar...
[ { "body": "<p>Maybe you could extract the common massaging before call_user_func_array in <code>_execute</code> and <code>_prepareFetch</code> into a helper?</p>\n\n<pre><code>private function _execute($aArgs) {\n/// [...]\n $aRefArgs = array();\n foreach(array_keys($aArgs) as $mIndex) {\n ...
{ "AcceptedAnswerId": "211", "CommentCount": "4", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2011-01-21T20:58:41.327", "Id": "146", "Score": "19", "Tags": [ "php", "mysql", "mysqli" ], "Title": "A take on DB Abstraction" }
146
<p>I want to have fast cache in which I want to keep all my nomenclature data. I don't want to go with Memcached because I have to do serialize/de-serialize on each object which is slow.</p> <p>So I choose to be less effective in memory and keep the cache in each server instance. I am sure I am doing it in the wrong w...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-01-22T14:31:28.477", "Id": "246", "Score": "0", "body": "what is you really question ?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-04T06:30:03.687", "Id": "51447", "Score": "0", "body": "I like...
[ { "body": "<p>The ActiveSupport::Cache is not mandatory in Memcached, there are a cache in memory if you use the :memory_store ( <a href=\"http://api.rubyonrails.org/classes/ActiveSupport/Cache/MemoryStore.html\" rel=\"nofollow\">http://api.rubyonrails.org/classes/ActiveSupport/Cache/MemoryStore.html</a> )</p>\...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-01-21T21:27:07.623", "Id": "147", "Score": "7", "Tags": [ "ruby", "ruby-on-rails", "cache" ], "Title": "Object cache storage for Rails" }
147
<p>I'm working on a personal project to keep different snippets/examples/small projects of mine organized. I want to make the most of my page width, so I decided to write a navigation menu that slides out. It works as expected, but the code is kinda big.</p> <p>I provided the HTML/CSS just in case that helps, but I'm ...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-01-27T00:26:29.440", "Id": "401", "Score": "4", "body": "I'd recommend that you always start with jslint.com which would have caught your non-declared variable and the braceless control statement referenced in the Answer." }, { "C...
[ { "body": "<p>First, it seems that <code>isCtrl</code> is not declared anywhere in your code. Put <code>var isCtrl = false;</code> as your first line inside the ready function. Otherwise, you will get a JavaScript error when the first key the user presses is <em>not</em> the <kbd>Ctrl</kbd> key. Also, <code>== ...
{ "AcceptedAnswerId": "149", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-01-22T00:59:16.190", "Id": "148", "Score": "16", "Tags": [ "javascript", "jquery", "html", "css" ], "Title": "Using a navigation menu to help keep material organized" }
148
<p>I have a class with quite a few attributes, most of which are known when I create an instance of the object. So I pass all the values in the constructor:</p> <pre><code>$op = new OpenIdProvider($imgPath . $name . $ext, 'openid_highlight', 0, 0, 108, 68, 6, $info[0], $info[1], $name); </co...
[]
[ { "body": "<p>Martin Fowler's <strike>bible</strike> book <a href=\"http://rads.stackoverflow.com/amzn/click/0201485672\"><em>Refactoring</em></a> does identify a smell called \"<a href=\"http://c2.com/cgi/wiki?LongParameterList\">Long Parameter List</a>\" (p78) and proposes the following refactorings:</p>\n\n<...
{ "AcceptedAnswerId": "152", "CommentCount": "0", "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-01-22T02:37:01.583", "Id": "150", "Score": "45", "Tags": [ "php", "constructor" ], "Title": "Instantiating objects with many attributes" }
150
<p>I installed settingslogic and in the configuration file I put the regex for the email as follows:</p> <pre><code>#config/settings.yml defaults: &amp;defaults email_regex: /^([\w\.%\+\-]+)@([\w\-]+\.)+([\w]{2,})$/i development: &lt;&lt;: *defaults # neat_setting: 800 test: &lt;&lt;: *defaults production:...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-02-02T19:09:03.610", "Id": "973", "Score": "0", "body": "the solution is for getting the regex from a yaml, while if you have it in a regular string this could help you http://stackoverflow.com/questions/4840626/handle-a-regex-getting-its...
[ { "body": "<p>I would definately not put the regex in the comment. That means that it needs to be changed in two places, one of which doesn't matter and will be misleading. Place a comment on the declaration of <code>email_regex</code> that explains what it is filtering. That way if it ever changes, all the pla...
{ "AcceptedAnswerId": "251", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-01-22T18:09:18.930", "Id": "159", "Score": "25", "Tags": [ "ruby", "ruby-on-rails", "regex", "converting" ], "Title": "Use of a regex stored inside a YAML file" }
159
<p>Is this code good enough, or is it stinky? </p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.IO; namespace DotNetLegends { public class LogParser { /// &lt;summary&gt; /// Returns a populated Game objects that has a list of pl...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-01-23T03:12:41.193", "Id": "264", "Score": "1", "body": "Is there a reason that you are converting the length back to a string?" }, { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-01-23T02:39:07.880", "Id": "6448...
[ { "body": "<ol>\n<li>Remove the code responsible for retrieving the log file contents. If this is a type that is just responsible for parsing log files than that is all it should do. Think about either passing in the file contents to this method or using Dependency Injection so that you can mock out the <code...
{ "AcceptedAnswerId": "167", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-01-23T02:24:12.317", "Id": "164", "Score": "17", "Tags": [ "c#", "game", "parsing" ], "Title": "Parsing a file for a game" }
164
<p><strong>Note:</strong> This file is out of my hands. I cannot change the format or type of file I have to parse.</p> <p>Here is some sample data that I'm trying to parse. This is information for just <strong>one</strong> player:</p> <pre><code>[0] (com.riotgames.platform.gameclient.domain::PlayerParticipantStatsSu...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-01-23T19:52:28.650", "Id": "281", "Score": "0", "body": "Just a minor point, you should always return the most specific type while requiring the least specific as parameter. So I'd return a List rather than an IEnumerable in this case so ...
[ { "body": "<p>Some rules of thumb that should improve your code:</p>\n<ul>\n<li>If you have variables with names resembling <code>varOne</code>, <code>varTwo</code>, <code>varThree</code>, etc - no matter what the number you should probably be using an array.</li>\n<li>If you are doing several identical actions...
{ "AcceptedAnswerId": "173", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-01-23T14:33:21.713", "Id": "172", "Score": "9", "Tags": [ "c#", "parsing" ], "Title": "Parsing a game file" }
172
<p>The code below is a plugin I wrote for <code>Ext.grid.GridPanel</code>, which basically allows you to have a bit more control over how rows are striped in the grid. By default you can only have every other row in alternate colour. With this plugin you an have for example 5 in basic color, 5 in alternate and so on.</...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-01-24T18:17:37.610", "Id": "284", "Score": "0", "body": "Relevant links: docs http://dev.sencha.com/deploy/dev/docs/?class=Ext.grid.GridPanel and source: http://dev.sencha.com/deploy/dev/docs/source/GridPanel.html#cls-Ext.grid.GridPanel (...
[ { "body": "<p>I don't see how to improve the duplication much: you're extending code that unfortunately wasn't meant to be extended. </p>\n\n<p>What you could do to help anyone finding your code in the wild is to highlight changes and maybe explain why you're doing the calculations you're doing. How would you g...
{ "AcceptedAnswerId": "212", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-01-23T19:46:34.387", "Id": "174", "Score": "12", "Tags": [ "javascript", "plugin", "ext.js" ], "Title": "ExtJS Grid Plugin" }
174
<p>Here's a class I'm designing:</p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Data; using System.Data.SqlClient; namespace Artworking.classes { // A group permission level public class PermissionGroup { public int ID; ...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-01-29T21:07:49.150", "Id": "703", "Score": "0", "body": "Comments are not bad, but why not go ahead and use the XML comments (http://msdn.microsoft.com/en-us/magazine/cc302121.aspx) and let them flow back through IntelliSense®?" }, { ...
[ { "body": "<p>I know nothing about C#, so this is just a comment based on the design. Is there any reason those members aren't private? Why don't you provide accessors, or (as I've said in many comments on this site already) actually move behavior into this class rather than exposing each individual data memb...
{ "AcceptedAnswerId": "180", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-01-24T17:05:50.147", "Id": "177", "Score": "11", "Tags": [ "c#", "sql", "asp.net", "classes" ], "Title": "Simple ASP.NET C# class design" }
177
<p>In <a href="https://codereview.stackexchange.com/questions/9/how-to-improve-very-loopy-method">this question</a> I answered with this Linq. While it does what I was looking for, I am not sure how easy the linq queries are for others to follow. So I am looking for feedback on formating, what comments would be helpful...
[]
[ { "body": "<p><strong>No</strong></p>\n\n<p>Your code looks pretty messy and that last linq statement is just a killer. To top it off the triple-nested foreach statement looks like serious code smell. I'd suggest breaking your code up into smaller methods that each do one thing which might reduce the perceived ...
{ "AcceptedAnswerId": "329", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-01-24T18:28:37.577", "Id": "182", "Score": "9", "Tags": [ "c#", "linq" ], "Title": "Update grid from source hierarchy" }
182
<p>This is performance critical. I measured and determined that using the <code>sqrt</code> is faster then using the <code>cos</code> method.</p> <p>I am aware that this code only works for some points, so that is not an issue.</p> <p><code>Point</code> is <code>System.Drawing.Point</code>. <code>_offset</code> is al...
[]
[ { "body": "<p>Yes I think that is going to be pretty quick. It might be tempting to move the cos calc so that it does a full Pythagoras with the radius. This will save an assignment, but I thi it requires an additional multiplication (1*1 being known already in your current version).</p>\n\n<p>As a matter of pe...
{ "AcceptedAnswerId": "184", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-01-24T19:36:29.233", "Id": "183", "Score": "21", "Tags": [ "c#", "performance", "converting", "coordinate-system" ], "Title": "Converting from polar coordinates to rectangular coor...
183
<p>I am unsure if my use of <code>Monitor.Wait</code> and <code>Monitor.Pulse</code> is correct. It seems to work alright, but there is a nagging doubt I am doing something wrong.</p> <p>Am I dealing with a timeout OK, or is there a better way to do it?</p> <p>All examples I have seen use <code>Monitor.Wait</code> wi...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-01-26T23:04:09.687", "Id": "382", "Score": "1", "body": "Just skimmed your question, but thought you might be interested in http://www.albahari.com/threading/part4.aspx#_WaitPulseVsWaitHandles. Joe Albahari is the creator of LINQPad and c...
[ { "body": "<p>I believe you are using them correctly as-is, but if I was working on your team, I would deny you a commit on basic principal:</p>\n\n<p><code>Monitor.Wait</code> and <code>Monitor.Pulse</code> are amazingly low-level constructs with very difficult semantics to try to figure out after you've writt...
{ "AcceptedAnswerId": "575", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-01-24T20:58:58.610", "Id": "185", "Score": "21", "Tags": [ "c#", ".net", "winforms", "synchronization", "timeout" ], "Title": "Determining if a connection has been made to a co...
185
<p>Imagine that I need a color palette for my Winforms application to have a consistent look.</p> <p>What I did was create a static helper class and helper methods that I can call from anywhere in my code, and invoke what I need from the <code>App.settings</code> file.</p> <p>Here for example, I am getting the school...
[]
[ { "body": "<p>The presented code seems okay, there aren't any obvious problems with it. <code>CustomizationHelper</code> could probably use a better name though to indicate what's being customized. If this is part of a larger project, putting a comment to indicate which classes are suppose to use <code>Customiz...
{ "AcceptedAnswerId": "237", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-01-24T21:58:21.663", "Id": "186", "Score": "75", "Tags": [ "c#", "winforms", "configuration" ], "Title": "Getting/setting default values from my App.config" }
186
<p>I'm learning Django as I go. I know this model is missing user authentication, registration, comments/comment threading, and voting. But this is my starting code for my model. What are some of the things I can improve on, modify, rewrite, etc?</p> <pre><code>from django.contrib.auth.models import User from django.d...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-01-24T23:16:06.700", "Id": "288", "Score": "1", "body": "I suggest you highlight places you want feedback on. Other than that, sorting imports and (maybe) field names will make your life easier on the long run." }, { "ContentLicen...
[ { "body": "<p>Disclaimer: I'm not a Django guru. Here are my thoughts, for what it's worth.</p>\n\n<ul>\n<li><p><strong>Common fields</strong>: <code>user</code>, <code>created</code>, and <code>nodes</code> occur in almost every class. I'd consider creating an <a href=\"http://docs.djangoproject.com/en/dev/t...
{ "AcceptedAnswerId": "196", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-01-24T22:35:07.103", "Id": "187", "Score": "25", "Tags": [ "python", "beginner", "django" ], "Title": "Music info model" }
187
<p>I've recently assembled some jQuery that allows a user to build out a bulleted list in MS Word with hyperlinks and turn that into a HTML unordered list. Ideas for uses are website menu systems where the user may not have a clue about HTML. You can also extend this with jQuery UI plugins for effects. Looking for ed...
[]
[ { "body": "<p>Looks fine (maybe some stricter formatting could help readibility, but not an issue), so I'll suggest completely optional improvements that might help spotting important improvements.</p>\n\n<p>As a general principle, try to <a href=\"http://en.wikipedia.org/wiki/Robustness_principle\" rel=\"noref...
{ "AcceptedAnswerId": "213", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-01-25T00:13:26.037", "Id": "190", "Score": "7", "Tags": [ "javascript", "jquery", "xml", "ms-word" ], "Title": "Build menu from MS Word XML" }
190
<p>I'm looking into Administration Elevation and I've come up with a solution that seems like it's perfectly sane, but I'm still in the dark about the professional methods to accomplish this.</p> <p>Is there a better way to do this or is this fine? </p> <pre><code>using System; using System.Diagnostics; using System....
[]
[ { "body": "<p>You can create a manifest file and set the app to require administrative privileges. This will trigger the UAC user prompt with the dimmed screen when your application is run without requiring any code on your part.</p>\n\n<p>See <a href=\"http://msdn.microsoft.com/en-us/library/bb756929.aspx\">MS...
{ "AcceptedAnswerId": "208", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-01-25T12:11:42.320", "Id": "197", "Score": "33", "Tags": [ "c#", "authorization" ], "Title": "Administration Elevation" }
197
<p>I have a database class that in <code>__construct()</code> initialize a PDO connection and insert the instance into a $db private var. Now i'm working on a method that can be used to query in this way:</p> <pre><code>$db = new db; $db-&gt;query(array( 'select' =&gt; 1, 'from' =&gt; 'table', 'where' =&gt; array('...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-01-25T16:24:21.633", "Id": "307", "Score": "1", "body": "Code like this is why I prefer ORM offerings like Doctrine." }, { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-01-25T16:31:33.867", "Id": "308", "Scor...
[ { "body": "<p>That query method (and the db class) has a lot of responsibilities:</p>\n\n<ul>\n<li>Do the PDO stuff, connection handling</li>\n<li>Be a query builder</li>\n<li>be a query executor</li>\n<li>Handle the params and possibly execute the same statement with different params (it would to that too)</li...
{ "AcceptedAnswerId": "207", "CommentCount": "3", "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-01-25T14:57:14.420", "Id": "200", "Score": "9", "Tags": [ "php", "mysql", "pdo", "object-oriented", "php5" ], "Title": "Database method to query" }
200
<p>I found that in PHP (or I probably can't find it) a proper <code>is_numeric_array($array)</code> function is missing. So I created one. The problem is that I don't think it's great and I don't know how to improve it.</p> <p>Any suggestion?</p> <p><strong>My first function</strong></p> <pre><code>function is_numer...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-01-27T15:46:23.483", "Id": "450", "Score": "0", "body": "Im just curious, can you provide a use case for this?" }, { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-01-27T18:10:26.727", "Id": "478", "Score": "0...
[ { "body": "<p>This will drop out as soon as an element is found that is not an int, making the function more efficient for large arrays.</p>\n\n<pre><code>function is_numeric_array($array) {\n foreach ($array as $a=&gt;$b) {\n if (!is_int($a)) {\n return false;\n }\n }\n return true;\n}\...
{ "AcceptedAnswerId": "204", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-01-25T16:13:34.917", "Id": "201", "Score": "32", "Tags": [ "php", "php5", "array" ], "Title": "is_numeric_array() is missing" }
201
<p>I want to get empty string or the string value of the object</p> <p>Which code you will use and why?</p> <pre><code>value = object.to_s </code></pre> <p>or this</p> <pre><code>value = object.nil? ? "" : object </code></pre>
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-01-25T22:50:58.253", "Id": "345", "Score": "2", "body": "The second alternative doesn't result in a string, so I guess there's a typo?" }, { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-01-26T23:33:20.200", "Id"...
[ { "body": "<p>I've read in <a href=\"http://rubyglasses.blogspot.com/2007/08/actsasgoodstyle.html\" rel=\"nofollow\">here(act_as_good_style)</a> (search for <code>.nil?</code> first occurrence) that you should not check for <code>.nil?</code> unless you really want to check that, while if you want to know if th...
{ "AcceptedAnswerId": "218", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-01-25T22:41:18.287", "Id": "214", "Score": "3", "Tags": [ "ruby" ], "Title": "Avoiding null in variable assignment" }
214
<p>This is part from an <a href="https://stackoverflow.com/questions/4706151/python-3-1-memory-error-during-sampling-of-a-large-list/4706317#4706317">answer to a Stack Overflow question</a>. The OP needed a way to perform calculations on samples from a population, but was hitting memory errors due to keeping samples in...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-01-31T15:04:51.737", "Id": "800", "Score": "1", "body": "But you keep the samples in memory too, so this isn't an improvement, over the solution you gave him, namely not keeping the samples around but calculating each mean directly." } ...
[ { "body": "<p>Making a generator version of <code>random.sample()</code> seems to be a much better idea:</p>\n\n<pre><code>from __future__ import division\nfrom random import random\nfrom math import ceil as _ceil, log as _log\n\ndef xsample(population, k):\n \"\"\"A generator version of random.sample\"\"\"\...
{ "AcceptedAnswerId": "485", "CommentCount": "1", "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-01-25T23:27:25.303", "Id": "217", "Score": "8", "Tags": [ "python", "random" ], "Title": "Randomly sampling a population and keeping means: tidy up, generalize, document?" }
217
<p>The requirements for this one were (<a href="https://stackoverflow.com/q/4630723/555569">original SO question</a>):</p> <ul> <li>Generate a random-ish sequence of items.</li> <li>Sequence should have each item N times.</li> <li>Sequence shouldn't have serial runs longer than a given number (longest below).</li> </u...
[]
[ { "body": "<p>A couple of possible code improvements that I noticed:</p>\n\n<pre><code>sourcelen = len(values) * n\n</code></pre>\n\n<p>This seems unnecessarily complicated to me. I mean, after a second of thinking the reader of this line will realize that <code>len(values) * n</code> is indeed the length of <c...
{ "AcceptedAnswerId": "243", "CommentCount": "0", "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-01-25T23:41:23.607", "Id": "219", "Score": "14", "Tags": [ "python", "random" ], "Title": "Quasi-random sequences: how to improve style and tests?" }
219
<p>I got this as an implementation of "get me the median of those values". But it sort of doesn't feel right (too long, too many branch points) so I thought I'll post it here to see what you think.</p> <pre><code>&lt;?php private function calculateMedian($aValues) { $aToCareAbout = array(); foreach ($aValues a...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-11-21T18:26:12.477", "Id": "30129", "Score": "0", "body": "`$iCount` in 1st iteration should be `$count`." } ]
[ { "body": "<p>I'm wondering if you can just compact the above to this:</p>\n\n<pre><code>private function calculateMedian($aValues) {\n $aToCareAbout = array();\n foreach ($aValues as $mValue) {\n if ($mValue &gt;= 0) {\n $aToCareAbout[] = $mValue;\n }\n }\n $iCount = count(...
{ "AcceptedAnswerId": "223", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-01-26T00:28:19.200", "Id": "220", "Score": "28", "Tags": [ "php", "statistics" ], "Title": "Calculate a median" }
220
<p>According to the Doctrine <a href="http://www.doctrine-project.org/projects/orm/1.2/docs/manual/working-with-models/en#fetching-objects" rel="noreferrer">docs</a>, you should use Array hydration rather than record hydration when retrieving data for read-only purposes.</p> <p>Unfortunately, this means I have to use ...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-01-26T10:03:23.660", "Id": "360", "Score": "0", "body": "from what i understand if you would fetch an object you would to $comment->text; or would you do $comment->getText() ? (Not to familiar with the \"old/current\" doctrine ;) )" }, ...
[ { "body": "<p>Scary? In what way? I don't really get that.</p>\n\n<p>It's just syntax. If you really care, just cast the arrays as stdClass objects</p>\n\n<pre><code>foreach ( $p['PostComment'] as $comment )\n{\n $comment = (object) $comment;\n $this-&gt;Controls-&gt;Add( new CommentPanel(\n $comment-...
{ "AcceptedAnswerId": "247", "CommentCount": "4", "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-01-26T04:04:45.080", "Id": "222", "Score": "10", "Tags": [ "php", "doctrine" ], "Title": "Php/Doctrine array hydration" }
222
<p>I was trying to create a lock-free queue implementation in Java, mainly for personal learning. The queue should be a general one, allowing any number of readers and/or writers concurrently.</p> <p>Would you please review it, and suggest any improvements/issues you find?</p> <p>(<a href="https://stackoverflow.com/q...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-01-27T14:18:58.873", "Id": "434", "Score": "0", "body": "There's a race in getObject()'s head.get().next versus putObject()'s prevTailNode.next = newNode. I wish the codereview site had line numbers. After the tail.getAndSet(newNode) ha...
[ { "body": "<p>Yes.</p>\n\n<ul>\n<li>The combination of volatile and compare-and-swap operations is enough to make sure that the Node objects are safely published.</li>\n<li>The compare-and-swap must be before the assignment to a <code>volatile</code> variable in both methods, so you're fine there. They do not n...
{ "AcceptedAnswerId": "255", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-01-26T11:12:35.660", "Id": "224", "Score": "48", "Tags": [ "java", "multithreading", "thread-safety", "locking", "lock-free" ], "Title": "Thread-Safe and Lock-Free - Queue Impl...
224
<p>In our production code, we cannot use Boost or C++0x. Formatting strings using <code>sprintf</code> or <code>stringstream</code> is annoying in this case, and this prompted me to write my own little <code>Formatter</code> class. I am curious if the implementation of this class or the use of it introduces any Undef...
[]
[ { "body": "<p>Looks fine. Don't worry too much and end up over-engineering a simple solution :)</p>\n\n<p>Edit:</p>\n\n<p>Actually, I would make the parameters to <code>operator&lt;&lt;</code> into const references.</p>\n", "comments": [ { "ContentLicense": "CC BY-SA 2.5", "CreationDa...
{ "AcceptedAnswerId": "263", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-01-26T21:57:46.423", "Id": "226", "Score": "27", "Tags": [ "c++", "formatting" ], "Title": "Formatter class" }
226
<p>I'm creating some sort of "portfolio" website for my self (a ton of placeholder content right now...) and I was wondering if I could improve the semantics of the HTML<del>5</del> any further, especially the <code>article</code> stuff.</p> <p>I'm not completely sure if I should use <code>section</code> elements insi...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-01-26T23:30:03.630", "Id": "387", "Score": "1", "body": "Ah! Lowercase your doctype, please!" }, { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-01-26T23:32:40.620", "Id": "388", "Score": "0", "body": "@D...
[ { "body": "<p>In my opinion A <em>section</em> element is basically an <em>important <strong>sub</strong> div</em> by this I mean,\nA section element is used to designate a notable division in your content.</p>\n\n<p>One of the best ways I have found to think about if you should use a certain element in a certa...
{ "AcceptedAnswerId": "271", "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-01-26T22:57:09.310", "Id": "239", "Score": "16", "Tags": [ "html", "twitter" ], "Title": "Twitter client portfolio website" }
239
<p>How can I clean this up?</p> <pre><code>std::wstring LinkResolve::ResolveLink( const std::wstring&amp; source ) const { HRESULT errorCheck; wchar_t linkTarget[MAX_PATH]; wchar_t expandedTarget[MAX_PATH]; wchar_t arguments[INFOTIPSIZE]; ATL::CComPtr&lt;IPersistFile&gt; ipf; errorCheck = ipf.CoCreateIn...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-01-28T20:14:17.250", "Id": "602", "Score": "1", "body": "This makes me think of Haskell's maybe monad, but I don't think that will help you. Still this would totally work with it." }, { "ContentLicense": "CC BY-SA 3.0", "Crea...
[ { "body": "<p>If I find my self writing the same thing over and over again I usually put it in a function somewhere. Even if that function in your case is as simple as this:</p>\n<pre><code>void check(HRESULT result) {\n if (FAILED(result)) {\n throw _com_error(result);\n }\n}\n</code></pre>\n<p>I ...
{ "AcceptedAnswerId": "261", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-01-27T07:26:21.437", "Id": "259", "Score": "38", "Tags": [ "c++", "error-handling", "atl" ], "Title": "Resolving a link" }
259
<p>I'm trying to design a well defined yet simple interface for the unit of work and repository patterns. My UoW's are exposed to services and services then "get repositories" that it needs to query. I know returning <code>IQueryable&lt;T&gt;</code> for repositories is a religious war. Because repositories are only exp...
[]
[ { "body": "<p>Your interface breaks the <a href=\"http://en.wikipedia.org/wiki/Law_of_Demeter\" rel=\"nofollow\">Law of Demeter</a>. Or said simply I cannot use <code>IUnitOfWork UnitOfWork { get; }</code> on <code>IRespository</code> without understanding <code>IUnitOfWork</code>.</p>\n\n<p>I would change IRe...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-01-27T14:52:33.480", "Id": "276", "Score": "25", "Tags": [ "c#", "design-patterns" ], "Title": "Interface for unit of work pattern and repository pattern" }
276
<p>I've got a flat array of &lt; 1000 items and I need to find the indices of a smaller tuple/array within the array. The tuple to find can be a varying length (generally between 2 and 5 items, order is important). </p> <p>This is my initial naive implementation. My main concerns are:</p> <ol> <li>This seems like...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-01-27T23:57:05.590", "Id": "528", "Score": "1", "body": "What about the \"overlapping\" case, i.e: should searching for \"AA\" in \"AAA\" return 0 and 1 as \"start\" indices? As it presently is in your code, it should, but if it is not a ...
[ { "body": "<p>As a quick tip, I would suggest you skip the step of finding possible start indexes.</p>\n\n<p>Instead, as you are already iterating over the whole list to find possible start indexes, then why don't you check that index right away when you find it? Would be something like:</p>\n\n<pre><code>publi...
{ "AcceptedAnswerId": "330", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-01-27T15:08:44.323", "Id": "278", "Score": "14", "Tags": [ "java", "array", "search" ], "Title": "Finding subtuple in larger collection?" }
278
<p>Similar piece of code to that I recently posted as:</p> <p><a href="https://codereview.stackexchange.com/questions/259/the-same-if-block-over-and-over-again-oh-my">Resolving a link</a></p> <p>I have another piece of code which cannot be as easily extracted out into a method:</p> <pre><code>#define THROW_LAST_WIND...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-01-27T18:12:01.247", "Id": "479", "Score": "0", "body": "So you're looking for a way to put the `if` and it's controlled block both within a single macro?" }, { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-01-27T18:...
[ { "body": "<p>This answer is not the best one, but you could create a new variable for each time you're assigning a value to rpmError and have one if statement where the last one is to check if any of them are equal to 0.</p>\n\n<p>Note: This will not work if it is absolutely necessary that those errors are thr...
{ "AcceptedAnswerId": "331", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-01-27T15:45:58.250", "Id": "281", "Score": "11", "Tags": [ "c++", "macros" ], "Title": "Resolving a link - follow-up" }
281
<pre><code>void removeForbiddenChar(string* s) { string::iterator it; for (it = s-&gt;begin() ; it &lt; s-&gt;end() ; ++it){ switch(*it){ case '/':case '\\':case ':':case '?':case '"':case '&lt;':case '&gt;':case '|': *it = ' '; } } } </code></pre> <p>I used this functi...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-01-27T17:22:02.660", "Id": "462", "Score": "0", "body": "If a char isn't forbidden, then we leave it be." }, { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-01-27T17:30:09.770", "Id": "465", "Score": "1", ...
[ { "body": "<p>Declare a string containing the illegal characters: <code>\"\\\\/:?\"&lt;&gt;|\"</code>. All you need to do is check if the char is in the array, so use a native function for that, or write a method <code>CharInString(char* needle, string* haystack)</code> which loops through the contents of the p...
{ "AcceptedAnswerId": "285", "CommentCount": "5", "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-01-27T16:07:55.520", "Id": "283", "Score": "23", "Tags": [ "c++", "strings" ], "Title": "Function for removing forbidden characters" }
283
<p>This is some of the code I have:</p> <pre><code>[window setLevel:kCGScreenSaverWindowLevel]; [window setOpaque:NO]; [window setStyleMask:0]; [window setBackgroundColor:[NSColor colorWithCalibratedWhite:0.0 alpha:0.3]]; [window setAlphaValue:0]; [window setFrame:[window frameRectForContentRect:[[window screen] fram...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-01-27T17:43:53.143", "Id": "64522", "Score": "0", "body": "Off the top of my head: can any of it be done in interface builder?" }, { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-01-27T18:02:55.873", "Id": "64523...
[ { "body": "<p>This is a highly readable style, and simple. You might be able to make a loop and run through the list in some fashion, but it's unlikely to actually lower complexity, just shift it around a bit.</p>\n", "comments": [ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2...
{ "AcceptedAnswerId": "304", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-01-27T16:21:45.617", "Id": "286", "Score": "4", "Tags": [ "objective-c", "cocoa" ], "Title": "Initializing a window in Cocoa" }
286
<p>I have created this code for user error logging, and I am wondering if there is anything that can be improved. The point is that this error handler would ONLY catch user errors created in-code by trigger_error(), and would display, log, and/or email the error, depending on the config settings. The error logging clas...
[]
[ { "body": "<p>Personally I think that working with 50% native and 50% your code does not work very well, because of things such as trigger_error does not allow custom bits to be sent.</p>\n\n<p>That being said if you named your class <code>Error</code> and created it to be abstract that implements a logger inte...
{ "AcceptedAnswerId": "312", "CommentCount": "0", "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-01-27T16:58:46.913", "Id": "294", "Score": "6", "Tags": [ "php", "error-handling", "php5" ], "Title": "User error logging" }
294
<p>I've just started learning CSS/HTML a week ago and I made a quick site today. It looks pretty good, but I think that I reused/wrote some really messy CSS. This is because I haven't used the <code>float</code> property in CSS too well, so I keep using <code>position:relative</code> and <code>top</code> to offset the ...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-01-27T18:36:55.407", "Id": "488", "Score": "10", "body": "Could you post the relevant HTML and CSS for us to see? Most people are not going to follow your link." }, { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-01-...
[ { "body": "<p>Your CSS doesn't handle what happens if the reader closes down the window to smaller than your planned size.</p>\n\n<pre><code>Test: resize window to less than 900px.\nResults: Window is cut off.\n</code></pre>\n\n<p>This is a design issue, more than a coding issue.</p>\n", "comments": [], ...
{ "AcceptedAnswerId": null, "CommentCount": "7", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-01-27T17:17:24.273", "Id": "296", "Score": "16", "Tags": [ "beginner", "html", "css" ], "Title": "Personal website, done after one week of learning HTML and CSS" }
296
<p>I am in the process of learning Clojure. I am fairly new to functional programming and would like to know if my code smells or if there are any performance implications with my approach.</p> <pre><code>; Returns the the given sequence with the given item appended to it. (defn snoc [xs x] (concat xs [x])) ; Returns...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-07-24T21:08:12.427", "Id": "63121", "Score": "0", "body": "You can generate the even-valued terms directly, rather than generating all terms and discarding the odd ones. The direct approach takes a bit less time to generate the sequence u...
[ { "body": "<pre><code>(defn snoc [xs x] (concat xs [x]))\n</code></pre>\n\n<p>There is a reason <code>snoc</code> is not defined by default in clojure: Since appending at the end of a singly linked list takes O(n) time, this is actually quite expensive. When building up non-lazy lists tail-recursively in a func...
{ "AcceptedAnswerId": "316", "CommentCount": "1", "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-01-27T17:43:18.330", "Id": "300", "Score": "25", "Tags": [ "functional-programming", "project-euler", "clojure", "fibonacci-sequence" ], "Title": "Project Euler Problem 2 in Clojur...
300
<p>I wrote a BST in C a while back and may use it at some point. </p> <pre><code> search_tree tree_make_empty( search_tree tree ) { if ( tree != NULL ) { tree_make_empty( tree-&gt;left ); tree_make_empty( tree-&gt;right ); free( tree ); } return NULL; } tree_position tree_find( CHA...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-01-28T07:44:59.120", "Id": "560", "Score": "0", "body": "I would say it is not going to work (if CHAR_DATA* is a string). You are comparing pointers. So unless all the data is static the comparisons using < and > are meaningless." }, ...
[ { "body": "<p>In <code>tree_find</code> and <code>tree_find_min</code> [edit: and even in <code>tree_insert</code>] you're not really gaining anything from using recursion. For example, I think <code>tree_find_min</code> would probably be clearer something like:</p>\n\n<pre><code>tree_position tree_find_min( se...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-01-27T18:47:23.210", "Id": "311", "Score": "4", "Tags": [ "performance", "c" ], "Title": "How does this Binary Search Tree look?" }
311
<p>Oftentimes I find myself wanting the total number of rows returned by a query even though I only may display 50 or so per page. Instead of doing this in multiple queries like so:</p> <pre><code>SELECT first_name, last_name, (SELECT count(1) FROM sandbox.PEOPLE WHERE trunc(birthday) = trunc(sysdate)...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-01-27T20:56:27.947", "Id": "511", "Score": "2", "body": "Do you have a specific question?" }, { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-01-27T20:58:51.533", "Id": "512", "Score": "0", "body": "Reall...
[ { "body": "<p>The latter query will be much more efficient-- it only requires hitting the table once. You can do a quick test yourself to confirm this.</p>\n\n<p>I'll create a simple two-column table with 1 million rows where the second column is one of 10 distinct values</p>\n\n<pre><code>SQL&gt; create table...
{ "AcceptedAnswerId": "3738", "CommentCount": "7", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-01-27T20:48:43.133", "Id": "326", "Score": "6", "Tags": [ "sql", "oracle" ], "Title": "Returning total number of rows in query" }
326
<p>This JS function is intended to retrieve or place a value into an object with the nested keys as a string.</p> <p>For example</p> <pre><code>var obj = {a: {b: [4]}}; parse_obj_key(obj, "a.b.0") should equal 4. parse_obj_key(obj, "a.c", 2) should add another element to "a" named "c" with value 2. </code></pre> <p>...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-01-28T13:25:46.623", "Id": "574", "Score": "0", "body": "I would suggest providing two different methods, one to get and one to set values (maybe both calling a common private method to retrieve the property)." } ]
[ { "body": "<p>Here is what's wrong with your code:</p>\n\n<ul>\n<li><p>Do not use variable names like <code>_o</code>. Get an editor with good auto-completion.</p></li>\n<li><p><code>typeof _o != 'object'</code> does not do what you think it does: <code>typeof([1,2]) // \"object\"</code>.\nIn general, doing tho...
{ "AcceptedAnswerId": "353", "CommentCount": "1", "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-01-27T23:39:15.980", "Id": "340", "Score": "6", "Tags": [ "javascript", "parsing" ], "Title": "Javascript Object Placement / String Parsing Method" }
340
<p>This works but there must be a better way:</p> <pre><code>txtBox.InputScope = new InputScope { Names = { new InputScopeName { NameValue = InputScopeNameValue.Text } } }; </code></pre>
[]
[ { "body": "<p>I'm not really sure what you want from this, if all you want is to make it more readable, then a few well placed new-lines will make a world of difference. If you want to reduce the amount of code, I don't think there is much room for that other than switching constructors for <code>InputScopeName...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-01-27T23:57:41.817", "Id": "341", "Score": "3", "Tags": [ "c#" ], "Title": "Better way of setting input scope on text box in WP7" }
341
<p>I started out with the best of intentions, but this form got hacky real fast.</p> <p>It's purpose is to serve as a create new Student form. Also, if you want to view an existing Students information.</p> <p>Think of it as the CRU of CRUD.</p> <p>Here it is:</p> <pre><code>using System; using System.Collections.G...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-01-28T01:16:03.153", "Id": "531", "Score": "1", "body": "I like to line up the equal signs. It makes the code easier to read for me." }, { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-01-28T09:38:12.610", "Id": ...
[ { "body": "<p>Look at your code within this block inside the <code>SaveInformation</code> method.</p>\n\n<pre><code>if (IsCreating) \n{\n // code here\n}\nelse\n{\n // and here\n}\n</code></pre>\n\n<p>Start refactoring with this. How many lines of code are actually different here? Outside of a different obj...
{ "AcceptedAnswerId": "345", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-01-28T01:09:00.223", "Id": "343", "Score": "14", "Tags": [ "c#", ".net", "winforms" ], "Title": "Form to create new students or view existing student information" }
343
<p>It's clever, but makes me vomit a little:</p> <pre><code>file = '0123456789abcdef123' path = os.sep.join([ file[ x:(x+2) ] for x in range(0,5,2) ]) </code></pre>
[]
[ { "body": "<p>Is there are reason you're not just doing:</p>\n\n<pre><code>path = os.sep.join([file[0:2], file[2:4], file[4:6]])\n</code></pre>\n\n<p>I think that my version is a little easier to parse (as a human), but if you need to extend the number of groups, your code is more extensible.</p>\n\n<p>Edit: an...
{ "AcceptedAnswerId": "349", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-01-28T01:28:04.327", "Id": "346", "Score": "0", "Tags": [ "python" ], "Title": "Generating filesystem paths from a fixed string" }
346
<p>I wrote a bunch of Ruby code for a book project I've just finished. One criticism is that it is fine code but not very "ruby like". I agree my style was simplified for communication reasons, and although it's procedural code, it still feels "ruby-like" to me. </p> <p>For the representative example below, any ideas ...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-01-28T07:17:46.503", "Id": "555", "Score": "6", "body": "Looked at your book, algorithm-wise - good explanations. but you should've asked a rubyist to take a look at the code before it got published :(" }, { "ContentLicense": "CC ...
[ { "body": "<p>An easy one is to remove the <code>return</code> at the end of each method. Ruby automatically does a return of the last value. It's actually an extra method call to use <code>return</code>.</p>\n\n<p><strike>The only time you specifically need to use return is</strike> You don't even need to use ...
{ "AcceptedAnswerId": "372", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-01-28T05:33:47.420", "Id": "354", "Score": "18", "Tags": [ "ruby", "genetic-algorithm" ], "Title": "Genetic algorithm for Clever Algorithms project" }
354
<p>I'm new to Hibernate so I need some advice/direction on doing Transactions.</p> <p>I have a DAO like</p> <pre><code>public class MyDao extends HibernateDaoSupport implements IMyDao { @Override public Foo getFoo(int id) { return (Foo)getHibernateTemplate().load(Foo.class, id); } } </code></pre> <p>With thi...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-01-28T14:04:41.497", "Id": "577", "Score": "0", "body": "Belongs on stackoverflow?" }, { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-01-28T15:04:44.883", "Id": "580", "Score": "2", "body": "Yup, the que...
[ { "body": "<p>In general, you should never handle transactions in dao code, as you never know where the transaction boundary is. You should let whoever wants to control the transactions control them.</p>\n\n<p>Code that starts and commits a transaction in every dao method is likely to be problematic.</p>\n\n<p>...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-01-28T05:55:18.000", "Id": "356", "Score": "2", "Tags": [ "java", "hibernate" ], "Title": "Hibernate transaction advice" }
356
<p>I want to write an Android <a href="http://developer.android.com/reference/android/widget/ListAdapter.html" rel="nofollow"><code>ListAdapter</code></a> to serve data from a database that look like this:</p> <pre><code>CREATE TABLE note (_id integer primary key autoincrement, content text not null...
[]
[ { "body": "<p>I would suggest using the built-in <a href=\"http://developer.android.com/reference/android/widget/CursorAdapter.html\" rel=\"nofollow\">CursorAdapter</a> together with a <a href=\"http://developer.android.com/reference/android/database/sqlite/SQLiteCursor.html\" rel=\"nofollow\">SQLiteCursor</a>....
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-01-28T07:56:03.023", "Id": "359", "Score": "7", "Tags": [ "java", "android", "sqlite" ], "Title": "Android ListAdapter design advice" }
359
<p>Should my class pass parameters internally or reference class level scoped variables?</p> <p>I'm not sure on the best approach or style for procedure calls that have parameters. Should I go with the class level scoped variables?</p> <pre><code>public class YouOweTheGovernment { public float AmountToPay { get; ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-12-16T09:28:50.150", "Id": "134117", "Score": "2", "body": "Don't use binary floating point numbers (`float`/`double`) for money. Either use integers or `decimal`." } ]
[ { "body": "<p>Since this is Code Review, I will first start with mentioning that you are not validating the logical correctness of your numbers, salary can't be negative, for example (Unless you're an evil employer). You may have left it out to shorten the question, but consider it a reminder.</p>\n\n<p>If the ...
{ "AcceptedAnswerId": "375", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-01-28T11:14:15.870", "Id": "362", "Score": "13", "Tags": [ "c#", "comparative-review", "classes", "finance" ], "Title": "\"Do you owe the government?\" classes" }
362
<p>I've built a custom control that generates a tab style navigation. Each page might have different tabs to display, the aim was to modularise it so I can make global changes to all the tabs.</p> <p><strong>TabMenu.ascx</strong></p> <pre><code>&lt;%@ Control Language="C#" AutoEventWireup="true" CodeFile="TabMenu.as...
[]
[ { "body": "<p>Yes the design looks good but it would be really better if you could replace that ArrayList with a Generic Collection.</p>\n", "comments": [], "meta_data": { "CommentCount": "0", "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-01-28T17:03:20.863", "Id": "379...
{ "AcceptedAnswerId": "384", "CommentCount": "0", "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-01-28T12:15:44.040", "Id": "364", "Score": "10", "Tags": [ "c#", "asp.net" ], "Title": "ASP.net custom user control design" }
364
<p>I've had to make several functions to turn some structures into strings. I am a still green when it comes C so I am unsure if I am doing this a very awkward way. The system I am coding for does not have snprintf, I know that would be far more elegant, however I cannot use it. Any advice?</p> <pre><code>int device_t...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-01-28T12:39:07.527", "Id": "570", "Score": "0", "body": "I assume that since your system doesn't have `snprintf` that you also don't have `sprintf` (http://www.cplusplus.com/reference/clibrary/cstdio/sprintf/)?" }, { "ContentLicen...
[ { "body": "<p>Yeah, without <code>snprintf</code> and <code>sprintf</code> it gets a bit tedious, but I think this code is actually quite clear. You use your horizontal and vertical whitespace very well, and it's clear what you're doing with each block of code. You have also controlled for any possible issues t...
{ "AcceptedAnswerId": "367", "CommentCount": "4", "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-01-28T12:26:13.537", "Id": "365", "Score": "8", "Tags": [ "c", "strings" ], "Title": "Struct to web style string" }
365
<p>I've been doing a simple Tic-Tac-Toe with PHP, generating only HTML code.</p> <p>A few notes:</p> <ul> <li>I didn't bother yet to give an AI to the opponents (the Os), and it is intentional. </li> <li>There is no CSS style to it, I intend to append it with a css file. </li> <li>tictactoe.php is naturally the name...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-01-28T13:59:25.403", "Id": "575", "Score": "4", "body": "Brings back memories - TTT was one of the first games I built in C." } ]
[ { "body": "<p>There isn't really a reason to make this \"more object-oriented\" if you don't need to. To add more AI constructs, for example, you can do:</p>\n\n<pre><code>switch ($aiLevel) {\n case 1: $values = $OsTurn($values);\n case 2: $values = $betterAi($values);\n case 3: $values = $unbeatableAi($v...
{ "AcceptedAnswerId": "373", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-01-28T12:30:47.890", "Id": "366", "Score": "16", "Tags": [ "php", "game", "tic-tac-toe" ], "Title": "Simple Tic-Tac-Toe PHP/Pure HTML" }
366
<p>In our console app, the parsing of application arguments is done like so:</p> <pre><code>using System.Linq; namespace Generator { internal class Program { public static void Main(string[] args) { var param1 = args.SingleOrDefault(arg =&gt; arg.StartsWith("p1:")); if ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-03-24T11:22:49.830", "Id": "58715", "Score": "0", "body": "Also, [the FubuCore library](https://github.com/DarthFubuMVC/fubucore) has a pretty powerful and self-documenting command line args parser, that I briefly described [here](http://...
[ { "body": "<p>You could use foreach for iterating through the agruments and then for your argument with index 1 you could use regular expression to retrieve parsed text after p1: </p>\n", "comments": [ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-01-28T18:36:29.500", ...
{ "AcceptedAnswerId": "387", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-01-28T13:13:39.513", "Id": "369", "Score": "31", "Tags": [ "c#", "parsing", "console" ], "Title": "Parsing console application arguments" }
369
<p>Here is the skeleton of my (first!) Django app:</p> <pre><code># models.py class Task(models.Model): description = models.CharField(max_length = 200) ... # forms.py class AddTaskForm(forms.ModelForm): class Meta: model = Task </code></pre> <p>I then created two views using <code>AddTaskForm</c...
[]
[ { "body": "<p>I have looked at your code and I think that it actually looks pretty clean and straight forward. However, I would suggest that you make it more DRY by using <a href=\"http://docs.djangoproject.com/en/dev/topics/http/urls/#reverse\" rel=\"nofollow\">reverse()</a> to figure out what action to assign...
{ "AcceptedAnswerId": "392", "CommentCount": "0", "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-01-28T14:08:51.607", "Id": "374", "Score": "11", "Tags": [ "python", "django" ], "Title": "An idiom to use the same view function to create or edit an object?" }
374
<p><strong>Goal:</strong> To create a countdown to our next available live stream.</p> <p><strong>Details:</strong> We live stream six times a week all (PST). 1. Sunday at 8:00 a.m. 2. Sunday at 10:00 a.m. 3. Sunday at 12:00 p.m. 4. Sunday at 6:30 p.m. 5. Wednesday at 7:00 p.m. 6. Saturday at 10:00 a.m.</p> <p><stron...
[]
[ { "body": "<p>I don't have time to look over everything, but I noticed you only set <code>$min</code> to something other than <code>0</code> once. You could add the following above <code>$build_date</code>, and then remove all the <code>$min = 0;</code>s, and you'd clear up a few lines:</p>\n\n<pre><code>if($mi...
{ "AcceptedAnswerId": "402", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-01-28T19:52:59.890", "Id": "383", "Score": "11", "Tags": [ "php", "datetime" ], "Title": "Checking date & time in PHP" }
383
<p>I would like to solicit advice on everyone's thoughts on how best to combat the <a href="http://en.wikipedia.org/wiki/Anemic_Domain_Model" rel="nofollow">Anemic Domain Model anti-pattern</a> when building out a system based on web services.</p> <p>One of our goals is to build a set of core web services that expose ...
[]
[ { "body": "<p>You're adding a lot of complexity here. Plus, you're going against the point of a <a href=\"http://martinfowler.com/eaaCatalog/serviceLayer.html\" rel=\"nofollow\">Service Layer</a> and Domain Model. Your Domain Model should probably use either <a href=\"http://martinfowler.com/eaaCatalog/activeRe...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-01-28T23:26:01.420", "Id": "395", "Score": "11", "Tags": [ "java", "design-patterns" ], "Title": "Pattern Against Anemic Domain Model" }
395
<p>I've made a SPL-based class named "Recordset" that wraps both MySQLi_STMT and MySQLi_Result objects and allows treating either as a 3-dimensional array. It requires PHP5.3+.</p> <p>I'm pretty bummed about the slow foreach loop over my Recordset object, by the slower internal seek and fetch speeds within Recordset,...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-01-29T17:26:20.997", "Id": "682", "Score": "0", "body": "Please put the relevant code in the question. We are trying to discourage pastebins as they segment the website. Also, not everyone is going to be able to click on your link if th...
[ { "body": "<p>bob-the-destroyer withdrew the question in a comment above:</p>\n\n<blockquote>\n <p>taking from a comment on PHP's man page on Mysqli classes, apparently\n you can extend them. Who knew? So, I've scrapped this idea and\n extended Mysqli_stmt to auto-handle param and result binding on\n constr...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-01-29T03:33:00.837", "Id": "401", "Score": "7", "Tags": [ "php", "php5", "mysqli", "spl" ], "Title": "MySQLi_Recordset: blending SPL and Statement/Query results" }
401
<p>Theme-swap functionality will be done via a better-looking <code>&lt;div&gt;</code> at the top of the page, but for right now, it's just thrown on the button. The theme preference should persist through page refreshes through the use of cookies. </p> <p>I'm going to do five different themes, each in two different ...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-01-29T13:26:48.247", "Id": "670", "Score": "4", "body": "You use jQuery for the DOM but then don't use it to handle ajax in a cross-browser compliant manner for you? I would use `$.ajax` rather then messing with XMLHRObj manually. If your...
[ { "body": "<p>This may just be me nit picking.</p>\n\n<p>But using this approach I can see getting very very messy.\nIf you decide to have say 40 theme's. That's a heck of a lot of javascript!\nand especially if you decide that you are going to support things like mobile or tablet.</p>\n\n<p>You are changing th...
{ "AcceptedAnswerId": null, "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-01-29T05:37:09.230", "Id": "403", "Score": "3", "Tags": [ "javascript", "jquery", "ajax" ], "Title": "Skin/theme swap" }
403
<p>I'm thinking about how to do a color transition for a line in WPF. I'm looking for this to be as simple and succinct as possible, and also the "correct" way in the WPF world.</p> <p>This is what I have, taking the line from it's previous color to <code>Colors.LightGreen</code> in 0.1 seconds.</p> <pre><code>Line T...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-01-29T05:39:30.943", "Id": "633", "Score": "1", "body": "By the way I don't yet have the 150 rep to tag this properly so if anyone wants to step in it'd be appreciated." } ]
[ { "body": "<p>1) I believe it is not a good practice to give variables one-letter names. <code>Storyboard story = ...</code><br>\n2) I believe you can specify <code>Duration</code> in <code>ColorAnimation</code> only. And do not set it for <code>Storyboard</code>.<br>\n3) I would introduce variable for <code>Co...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-01-29T05:39:15.903", "Id": "404", "Score": "9", "Tags": [ "c#", "wpf" ], "Title": "Animating the color of a line in WPF" }
404
<p>Consider the following method that I have for checking write permissions on a directory path:</p> <pre><code>/// &lt;summary&gt; /// Check existence and write permissions of supplied directory. /// &lt;/summary&gt; /// &lt;param name="directory"&gt;The directory to check.&lt;/param&gt; protected static void CheckPe...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-01-29T17:28:39.467", "Id": "683", "Score": "1", "body": "This is probably a question better suited for StackOverflow based on the FAQs guidelines for what is an applicable question." }, { "ContentLicense": "CC BY-SA 2.5", "Cre...
[ { "body": "<p>This FxCop warning is basically asking you to make sure (\"Review\") that that non-constant you are passing (<code>directory</code>) to the security permission does not change while the permission is in effect. Basically, FxCop isn't sure if it is possible for the code (or some rogue module that ...
{ "AcceptedAnswerId": "457", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-01-29T09:56:55.847", "Id": "413", "Score": "2", "Tags": [ "c#", "security", "file-system" ], "Title": "Directory write permissions check" }
413
<p>I have a stored procedure that looks up an article based on the article's title. But I also need to increment a column in the same table that counts the number of times the article has been viewed.</p> <p>Trying to be as efficient as possible, I wanted a way to do this without performing multiple lookups. Someone p...
[]
[ { "body": "<p>I would optimize by not storing meta data along with the data. How does the view count really affect the article itself? Not at all.</p>\n\n<p>It's a different thing... So store it in a different place.</p>\n", "comments": [ { "ContentLicense": "CC BY-SA 2.5", "CreationDa...
{ "AcceptedAnswerId": "1017", "CommentCount": "0", "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-01-29T15:45:27.830", "Id": "415", "Score": "7", "Tags": [ "sql", "sql-server", "lookup" ], "Title": "Return Data and Update Row without Multiple Lookups?" }
415
<p>This system has to manage students, teachers, staff and grading. This is for production and is not a school assignment. As such, please let me know if I can improve on any aspect. :)</p> <p>My main concern is automation. I'd like my software to be able to run regardless if I still exist. </p> <p>I'm using SQLite a...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-01-29T22:09:21.320", "Id": "709", "Score": "0", "body": "Are you sure sqlite is what you want to use? What do you expect the number of concurrent users to be (reading & writing)? What are expected # of rows in each table? How will you ...
[ { "body": "<p>Comments</p>\n\n<ol>\n<li><p>All your ID (unique ID's) are called ID (this is OK and it works for you)<br>\nBut I have found when you start doing joins this may become hard to read. Thus I like to name the unique key after the table. eg <code>User_ID</code> on the User Table etc.</p></li>\n<li><p>...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-01-29T16:30:59.507", "Id": "418", "Score": "37", "Tags": [ "sql", "sqlite" ], "Title": "Database design for a school system" }
418
<p>While researching ways to convert back and forth between <code>std::wstring</code> and <code>std::string</code>, I found <a href="http://social.msdn.microsoft.com/Forums/en/Vsexpressvc/thread/0f749fd8-8a43-4580-b54b-fbf964d68375">this conversation</a> on the MSDN forums.</p> <p>There were two functions that, to me,...
[]
[ { "body": "<p>I don't do any Windows development, so I can't comment on the <code>WideCharToMultiByte</code> part being safe.</p>\n\n<p>The one thing I would say though is to ensure you are using the proper types for everything. For example, <code>string.length()</code> returns a <code>std::string::size_type</...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-01-29T17:04:41.087", "Id": "419", "Score": "40", "Tags": [ "c++", "strings", "converting" ], "Title": "Converting between std::wstring and std::string" }
419
<p>Having coded in Java and C# for quite some years, I'm currently learning Ruby. I'm working my way through the <a href="http://rubykoans.com/" rel="noreferrer">Ruby Koans tutorial</a>. At some point, you are to implement a method that calculates the game-score of a dice-game called Greed.</p> <p>I came up with this ...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-01-29T22:19:14.650", "Id": "710", "Score": "1", "body": "The second revision of the code looks good to me. Using a hash is a nice idea (though it doesn't make use of the fact that for `[x,x,x]` with `x != 1` the score is `x*100`, but I gu...
[ { "body": "<p>There are a few issues with the code:</p>\n\n<ol>\n<li>Do not check for <code>== nil</code> when it is not specified as a valid value for the method. Here,checking for it and returning 0 might mask another problem.</li>\n<li>Do not use return statements unless necessary. In ruby, almost everything...
{ "AcceptedAnswerId": "426", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-01-29T17:57:54.140", "Id": "423", "Score": "24", "Tags": [ "ruby", "programming-challenge", "dice" ], "Title": "Ruby Koans' Greed Task" }
423
<p>I have been developing this class, and was wondering if anyone had any thoughts on how I can improve the performance of it.</p> <pre><code>&lt;?php class Something { private $APIUsername, $APIPassword; private $APIurl = 'somesite.com'; function __construct ($APIUsername = '', $APIPassword = '') { ...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-01-30T01:41:12.257", "Id": "719", "Score": "0", "body": "like agentile, I originally answered with \"combine all methods into one\". agentile actually proposes a better way than I though. My question would be, what area of performance a...
[ { "body": "<p>Some things I noticed.</p>\n\n<p>It seems like a lot/all of your public functions are simply doing the same thing, setting the functions params into an array, calling <code>setJSON</code> which simply appends the <code>APIusername</code> and <code>APIpassword</code> and then you fetch and catch an...
{ "AcceptedAnswerId": "439", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-01-29T19:31:05.860", "Id": "427", "Score": "6", "Tags": [ "php", "object-oriented", "php5" ], "Title": "JSON API for some bank account" }
427
<p>I wrote the following little shell script and published it on <a href="https://github.com/Basphil/random-xkcd-wallpaper/" rel="nofollow" title="My github repo">GitHub</a>. In the repo there's also a README file that explains how to use it in more detail.</p> <p>This is the first time I open-sourced/published someth...
[]
[ { "body": "<pre><code>#!/bin/bash\n</code></pre>\n\n<p>The shebang line has no effect unless it's on the very first line, so you should put it before the copyright notice.</p>\n\n<pre><code>echo $(pwd)\n</code></pre>\n\n<p><code>echo $(command)</code> is almost always the same as just writing <code>command</cod...
{ "AcceptedAnswerId": "437", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-01-29T20:54:09.183", "Id": "428", "Score": "13", "Tags": [ "bash", "http", "shell" ], "Title": "Was this shell script ready for open-source? (Random XKCD wallpaper)" }
428
<p>This weekend I've been having one heck of a time getting WPF Ribbon v4 working with MVVM and Prism (using unity). After much trial and error, I believe I have it working. I was hoping someone could take a look at it and give me some feedback.</p> <p>RibbonRegionAdapter.cs</p> <pre><code>public class RibbonRegionAd...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-06-02T05:55:15.417", "Id": "41653", "Score": "0", "body": "Scott, could you please tell in which problem scenario you have used RibbonRegionAdapter, or Why we need to have one when developing Apps using Ribbon control with prism ?" } ]
[ { "body": "<p>Not sure whether we have many Prism specialists on Code Review and I haven't worked with it for a while, so maybe my comments are incorrect at points. </p>\n\n<ol>\n<li>I do not really like the way you're handling <code>region.Views.CollectionChanged</code> event. This event provides a lot of inf...
{ "AcceptedAnswerId": "432", "CommentCount": "1", "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-01-29T21:10:01.687", "Id": "429", "Score": "21", "Tags": [ "c#", "wpf" ], "Title": "MVVM, WPF Ribbon V4, with Prism" }
429
<p>I am working on a project where I have to calculate the totals of a transaction. Unfortunately, coupons have proven to be quite an issue. There are four types of coupons: transaction percentage, transaction dollar amounts, item percentage and item dollar amounts.</p> <p>I ended-up with this beast of a method, and...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-01-30T06:19:49.790", "Id": "733", "Score": "3", "body": "I dont know c#, but too many comments?" } ]
[ { "body": "<p>The first thing that I noticed is that you're using <code>?? 0</code> a lot. If you could restructure your code to ensure that the prices won't be <code>null</code> that would allow you to remove those, which would clean up your code a bit.</p>\n\n<p>Further you're often using the pattern:</p>\n\n...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-01-30T00:40:52.877", "Id": "438", "Score": "12", "Tags": [ "c#", "linq", "finance" ], "Title": "Calculating totals of a transaction" }
438
<p>I'm working on a simple star rating system, and before I move on to actually "tallying" the votes, which I figure I'll just do with <code>$.ajax</code>, I wanted to make sure what I've done so far has been done as well as it can be.</p> <p><strong>JavaScript</strong></p> <pre><code>//max number of stars var max_st...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-02-04T18:24:52.837", "Id": "137410", "Score": "0", "body": "Using Namespaces for your global variables as well as methods is a good practice." } ]
[ { "body": "<p>The obvious improvement to the code you have here is that you should package it up as a jQuery plugin, to improve code reusability and reduce the number of global variables created. </p>\n\n<p>You'll also want to use a <code>class</code> instead of <code>id</code>, to improve reusability (if you c...
{ "AcceptedAnswerId": "447", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-01-30T01:55:18.230", "Id": "444", "Score": "13", "Tags": [ "javascript", "jquery" ], "Title": "Simple star rating system" }
444
<p>Can I make my template syntax simpler? I'm hoping to eliminate the <code>if</code> and maybe also the <code>for</code> block. </p> <p>This worked in the shell but I can't figure out the template syntax.</p> <pre><code>recipes[0].recipephotos_set.get(type=3).url </code></pre> <p>model.py</p> <pre><code>class Reci...
[]
[ { "body": "<p>I'll refer you to a <a href=\"https://stackoverflow.com/questions/223990/how-do-i-perform-query-filtering-in-django-templates\">Stack Overflow post</a> that pretty much nails the answer.</p>\n\n<p>I assume that you want to display all recipes that have \"Sub Featured Photos\".</p>\n\n<p>The call <...
{ "AcceptedAnswerId": "451", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-01-30T01:57:55.443", "Id": "445", "Score": "6", "Tags": [ "python", "django", "django-template-language" ], "Title": "Django query_set filtering in the template" }
445
<p>I have the following method:</p> <pre><code>private void removeUnnecessaryLines(List&lt;ScatterViewItem&gt; list) { List&lt;Line&gt; remove = new List&lt;Line&gt;(); foreach (Line line in lines) { SourceFile destination = (line.Tag as Call).getCallee(); foreach (ScatterViewItem svi in l...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-01-30T16:24:33.983", "Id": "747", "Score": "0", "body": "This looks like C# (though you should mention that in the tags). Can you use LINQ?" }, { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-01-30T16:26:34.233", ...
[ { "body": "<p>The most obvious improvement would be to use LINQ's <code>Where</code> method to filter the <code>lines</code> list instead of building up a list of to-be-deleted items and then deleting them. In addition to being easier to read and understand it will have the benefit of its runtime not being quad...
{ "AcceptedAnswerId": "464", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-01-30T15:59:41.270", "Id": "462", "Score": "10", "Tags": [ "c#", "casting" ], "Title": "Loops for removing unnecessary lines" }
462
<p>I have a very simple PHP MVC library for my auto-didactic pedagogical purposes. I'm having a little trouble figuring out how to add in the observer patterns as show in <a href="http://en.wikipedia.org/wiki/File:ModelViewControllerDiagram2.svg" rel="nofollow noreferrer">this UML diagram from Wikipedia</a>.</p> <p><c...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2017-12-15T09:54:42.697", "Id": "347868", "Score": "0", "body": "@Abbas I've rolled back you last edit, see this [meta](https://codereview.meta.stackexchange.com/questions/762/should-you-edit-someone-elses-code-in-a-question)" }, { "Co...
[ { "body": "<p>Unlike other SPL interfaces, I'm not finding that this pair of built-in interfaces has any intrinsic value other than to provide a template. It would be nice if Observer can automatically trigger its <code>update()</code> method any time Subject properties are modified in any way, but this isn't ...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-01-30T17:12:36.653", "Id": "465", "Score": "4", "Tags": [ "php", "mvc", "spl" ], "Title": "Simple MVC in PHP" }
465
<p>I'm new into Javascript, and I'm not sure that is a good approach. The code works, and does what I need it to do but I'm sure I didn't do the things the right way.</p> <p>Can you give me feedback about the implementation idea and code?</p> <p>So, let's say that in index.html I have the following code into body sec...
[ { "ContentLicense": "CC BY-SA 2.5", "CreationDate": "2011-01-31T13:11:52.120", "Id": "792", "Score": "0", "body": "For what purpose are you using document.write? I doubt that you need to insert an internal script in this way." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2...
[ { "body": "<p>I think you want to take out the document.writes and add</p>\n\n<pre><code>&lt;body onload=\"loaded()\"&gt;\n</code></pre>\n\n<p>(or whatever function you need to run first) to index.html</p>\n", "comments": [], "meta_data": { "CommentCount": "0", "ContentLicense": "CC BY-SA 2....
{ "AcceptedAnswerId": "468", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-01-30T18:45:47.833", "Id": "466", "Score": "5", "Tags": [ "javascript" ], "Title": "Need a feedback on my Javascript code and app implementation idea" }
466