body
stringlengths
25
86.7k
comments
list
answers
list
meta_data
dict
question_id
stringlengths
1
6
<p>There is a application with a very slow query (listed below), and I have to optimize to run faster. The truth is that I don't know where to start. Any help? Thanks!</p> <pre><code>SELECT DISTINCT v.order_ANC, v.order_ANC2, f.codi_arxiu, f.nom_arxiu, f....
[]
[ { "body": "<p>Optimising an SQL statement generally involves two phases: Understanding how the DBMS has chosen to execute the query in terms of index lookup and join order (called the query plan), and figuring out a way to write a query that gets the same effect, but that the DBMS finds a better query plan for....
{ "AcceptedAnswerId": "2852", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-07T09:22:40.433", "Id": "2843", "Score": "0", "Tags": [ "sql", "sql-server" ], "Title": "Optimize slow SQL query" }
2843
<p>This is my first attempt to create a reusable and tested module. Any comments is highly appreciated.</p> <pre><code>#-*- coding: utf-8 -*- """ Micron: a micro wrapper around Unix crontab. Micron is a thin wrapper around Unix crontab command. It let you add and remove jobs from the crontab file or remove the entire...
[]
[ { "body": "<p>I think it is a pretty good start:</p>\n\n<ul>\n<li>I would like to see a Job class.</li>\n<li>The stderr output would be great in cases of an retcode != 0.</li>\n<li>A validation and/or escaping of timing and program would be great.</li>\n</ul>\n", "comments": [ { "ContentLicens...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-07T11:59:25.433", "Id": "2846", "Score": "3", "Tags": [ "python" ], "Title": "Review request: a simple Cron wrapper in Python" }
2846
<p>I have included the code from a second year project that I would like some advice on. Basically it utilises WMI to query a NIC card from a selection (depending how many are installed in the host machine) and shows various settings such as IP info, DHCP info etc. It also has a ping function.</p> <p>How can I improve...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-07T09:06:51.077", "Id": "4383", "Score": "12", "body": "First casualty would be all those extraneous blank lines." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-07T09:08:41.443", "Id": "4384", "Sco...
[ { "body": "<p>Refactor your <code>comboBox1_SelectedIndexChanged</code> method to just call different functions for each different task it is doing. Passing the correct arguments to your functions as necessary.</p>\n\n<p>Do NOT have empty catch clauses in your code. Shows bad exception handling. If you put co...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-07T09:03:12.650", "Id": "2847", "Score": "14", "Tags": [ "c#", ".net", "networking" ], "Title": "Showing various network information from a NIC card" }
2847
<p>How does this recursive selection sort look to everyone here? Am I missing anything 'pythonic' about the way I have done it?</p> <pre><code>def selection_sort(li, out=None): if out is None: out = [] li = li[:] if len(li) == 0: return out small = min(li) li.remove(small)...
[]
[ { "body": "<pre><code>def selection_sort(li, out=None):\n</code></pre>\n\n<p>I dislike the name \"li,\" I think abbreviations are bad.</p>\n\n<pre><code> if out is None:\n out = [] \n li = li[:]\n</code></pre>\n\n<p>Rather then using the out parameter to do this, I suggest creating a seperat...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-07T18:34:22.767", "Id": "2855", "Score": "4", "Tags": [ "python", "algorithm", "recursion" ], "Title": "Selection sort using recursion" }
2855
<p>I have an account page where I have three forms. A user can change his name, his email address, and his password.</p> <p>There are two difficulties I am having from trying to do this:</p> <p>1) the request.user information is not updating accordingly (e.g., it will lag behind by one change or it will update if the...
[]
[ { "body": "<p>Somewhere on \"Stack Overflow\" was question like your.</p>\n\n<p>Main idea was remove <code>None</code> from form initialization.</p>\n\n<pre><code>if \"change_name\" in request.POST:\n change_name_form = ChangeNameForm(data=request.POST, instance=request.user)\n if change_name_form.is_vali...
{ "AcceptedAnswerId": "2876", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-07T19:20:43.630", "Id": "2857", "Score": "3", "Tags": [ "python", "django" ], "Title": "Multiple forms in django" }
2857
<p>I was reading <em>Mathematics: A Very Short Introduction</em> and it mentioned prime factorization. Being a curious person I had to write my own implementation in Perl.</p> <p>This program outputs the prime factorization of the numbers between 0 and 1001. </p> <p>I don't like listing all of my subroutines before e...
[]
[ { "body": "<p>There are a few things which can improve this logic:</p>\n\n<ul>\n<li>In order to find out whether a number <em>n</em> is prime, you only need to go up to <em>sqrt(n)</em>, not <em>n/2</em>; that will speed up the prime validation considerably for large numbers.</li>\n<li>Also, if you're verifying...
{ "AcceptedAnswerId": "2865", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-07T21:09:00.533", "Id": "2858", "Score": "2", "Tags": [ "primes", "perl" ], "Title": "Prime factorization of numbers up to 1000" }
2858
<p>Looking for a code review, and hopefully to learn something if someone has a nicer solution. Here's what I wrote:</p> <pre class="lang-py prettyprint-override"><code>from __future__ import division, print_function from future_builtins import * import numpy as np def _walk(num_dims, samples_per_dim, max_): i...
[]
[ { "body": "<p>Concatenating numpy arrays isn't a really good idea because that's not how they were designed to be used.</p>\n\n<p>A better way might be this:</p>\n\n<pre><code>def walk(num_dims, samples_per_dim):\n \"\"\"\n A generator that returns lattice points on an n-simplex.\n \"\"\"\n values =...
{ "AcceptedAnswerId": "2868", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-07T22:41:43.537", "Id": "2860", "Score": "2", "Tags": [ "python", "generator" ], "Title": "Python generator to produce lattice points on an n-simplex." }
2860
<p>I've made a quick <code>finally</code> type in C++:</p> <pre><code>template&lt;class F&gt; class finally_type { public: explicit finally_type(F f) : function(f) {} ~finally_type() { try { function(); } catch (...) {} } private: F function; }; template&lt;class F&gt; finally_type&lt;F&gt; finally(F...
[]
[ { "body": "<p>Bear in mind that code inside the function called by <code>finally</code> must not allow exceptions to propagate out, or you end up with problems when the destructor is called while cleaning up an exception in the calling code. You might want to put a <code>catch(...)</code> block in the <code>fin...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-08T01:39:37.210", "Id": "2864", "Score": "5", "Tags": [ "c++", "c++11", "exception" ], "Title": "An implementation of \"finally\" in C++0x" }
2864
<p>I'm creating a chat UI with jQueryUI:</p> <pre><code>$.widget("ui.chatwindow", { options: { nickname: "obama"; }, setNickname: function(nick){ var self = this; var id_pre = 'wchat_' + self.options.nickname; $('#' + id_pre + '\\:name').text(self.options.nickname); }, ...
[]
[ { "body": "<p>I can't say there's anything <em>technically</em> wrong with doing it that way, and maybe some people who are only familiar with \"self\" in certain languages will get the point, but I think \"this\" is just as readable, and it saves you some code (along with some of us wondering where in the worl...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-08T06:12:59.060", "Id": "2867", "Score": "2", "Tags": [ "javascript", "jquery", "jquery-ui", "chat" ], "Title": "jQuery Chat UI Widget" }
2867
<p>I want to write an article giving a Haskell introduction specifically to Java developers, and would like to get feedback on my implementation. Please keep in mind that I don't want to be "too clever", as too advanced Haskell concepts would only confuse the readers. On the other hand I need to show some really intere...
[]
[ { "body": "<ul>\n<li>Java developers prefer intention revealing names as opposed to mathematical single letter identifiers. So it might be better to use <code>edge</code> instead of <code>e</code> and so on.</li>\n<li>Most common type parameter name in Java is <code>T</code> as opposed to <code>a</code>, so may...
{ "AcceptedAnswerId": "3383", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-08T08:15:08.253", "Id": "2870", "Score": "14", "Tags": [ "haskell", "tree" ], "Title": "Prim's algorithm for minimal spanning trees" }
2870
<p>I'm looking for the fastest way to find all neighbours of a vertex in an undirected <code>Graph</code>. Please improve on the code if possible.</p> <pre><code>neighbours[g_Graph, v_] := Module[ {vl = VertexList[g], pos}, pos = Position[vl, v][[1, 1]]; Pick[VertexList[g], AdjacencyMatrix[g][[pos]], 1] ] ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-09T00:51:45.250", "Id": "59399", "Score": "0", "body": "There is a [Neighborhood](http://reference.wolfram.com/mathematica/Combinatorica/ref/Neighborhood.html) function in the Combinatorica package.\nI would expect their implementation...
[ { "body": "<p>As of Mathematica 9.0 we have the function <a href=\"https://reference.wolfram.com/language/ref/AdjacencyList.html\" rel=\"nofollow\"><code>AdjacencyList[g,v]</code></a>.\nSince this is built into Mathematica, I would assume that it is the fastest implementation.</p>\n\n<pre><code>In[1]:= g = Comp...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-08T09:07:44.807", "Id": "2871", "Score": "4", "Tags": [ "graph", "wolfram-mathematica" ], "Title": "Fastest way to find all neighbours of a vertex in a graph" }
2871
<p>This code is executed very often, so I'm wondering if it's already ideal or if it's possible to optimize it further.</p> <pre><code>var highlightLinks = function(e) { var anchors = e.target.getElementsByTagName("a"); let file = Components.classes["@mozilla.org/file/directory_service;1"] .getSe...
[]
[ { "body": "<p>I believe you could improve your code by using prototypes like this:</p>\n\n<pre><code>function handler(anchorIndex, anchor) {\n this.anchorIndex = anchorIndex;\n this.anchor = anchor;\n}\n\nhandler.prototype = {\n handleResult: function(aResultSet) {\n for (let row = aResultSet.ge...
{ "AcceptedAnswerId": "3787", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-08T11:42:01.003", "Id": "2872", "Score": "3", "Tags": [ "javascript", "performance", "firefox" ], "Title": "Firefox link-highlighting extension" }
2872
<p>I'm working on the registration process for new users of a small web app, and as this is largely a learning project I'm doing it from scratch.</p> <p>Here is my user class: <strong>Class_user.php</strong> </p> <pre><code>&lt;?php class User { // The class variables are the same and have the same name ...
[]
[ { "body": "<p>Too much code for a simple thing...why don't you consider working with a framework like <a href=\"http://www.codeigniter.com\" rel=\"nofollow\">CodeIgniter</a>?</p>\n\n<p>Try placing some echoes on your code and see where it is stopping. It will be easier to help you.</p>\n", "comments": [ ...
{ "AcceptedAnswerId": "3992", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-08T23:14:16.453", "Id": "2877", "Score": "3", "Tags": [ "beginner", "php" ], "Title": "PHP - create a new user into a db using MVC framework" }
2877
<p>I have two kinds of lexical analyses of sentences that I need to process. One type of data comes in a "tagged" format, and the other comes in a "parsed" format.</p> <hr> <h2>Tagged</h2> <p>The input (<code>@subsentences</code>) looks like:</p> <pre><code>5.4_CD Passive_NNP Processes_NNP of_IN Membrane_NNP Trans...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-10T03:14:21.827", "Id": "4457", "Score": "0", "body": "Perhaps: instead of splitting, using =~ / ().../ and then having $1 be the output I need?\n\nEx: ` = $1 if ($line =~ /^Parsing \\[(sent. \\d+) len. \\d+\\]/);`" } ]
[ { "body": "<p>Match and substitute are far better suited for this problem than split().\nTo delete all of the _XX things, use a substitute global <code>s/(_\\S+)//g;</code>.\nSo generating your desired output is actually easy.</p>\n\n<p>To see demo of this and how to parse your report, see the code below. Note ...
{ "AcceptedAnswerId": "3288", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-09T05:51:46.120", "Id": "2881", "Score": "2", "Tags": [ "parsing", "perl", "natural-language-processing" ], "Title": "Processing lexical analyses of sentences using the Perl split ...
2881
<p>I am currently doing Encoding on Dropdownlist in our project.</p> <p>Could you please review and provide your comments about the following approach? After the encoding on dropdown, if there are any special characters it is displaying in the form of encoded characters, please let me know is there any better approac...
[]
[ { "body": "<p>A few comments - </p>\n\n<p>It seems that while your code should work fine as is, it could be improved in the following ways:</p>\n\n<p>A. It seems like you have three methods here when only one or two would be necessary. You may have your reasons for doing this, but the \"middle-man\" method \"En...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-09T08:47:51.160", "Id": "2882", "Score": "2", "Tags": [ "c#", "asp.net" ], "Title": "Encoding on Dropdownlist items" }
2882
<p>I wanted to launch a bash script (read: bash not sh script) as a root not as the user calling it, however bash ignore <code>setuid</code> on scripts, so I chose to write a very small script that takes a script/arguments and call it with <code>setuid</code> set.</p> <p>This worked well and I went even further to ver...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-09T09:58:09.577", "Id": "4430", "Score": "3", "body": "Next time don't double post, just use the flag tool on your [original post](http://stackoverflow.com/questions/6290670/need-help-improving-a-small-c-program) and ask a moderator to...
[ { "body": "<p>One thing I'd do is </p>\n\n<p>change </p>\n\n<pre><code>sprintf(command, \"%s %s\", command, argv[i]);\n</code></pre>\n\n<p>to use strcat</p>\n\n<p>while this does work on a number of implementations, it's not considered \"safe\"</p>\n\n<p>refer <a href=\"https://stackoverflow.com/questions/12833...
{ "AcceptedAnswerId": "2936", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-09T09:51:30.983", "Id": "2883", "Score": "3", "Tags": [ "c", "bash" ], "Title": "Calling a script with a setuid set" }
2883
<p>I'm trying to create an app for the Palm Pre. It is a prayer app, more specifically a rosary app. <em>If you are not a Catholic, a rosary is kind of like a necklace on which you count beads.</em> </p> <p><strong>What I'm trying to do:</strong></p> <ul> <li>You click on one of 4 buttons to select one of 4 sets o...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-09T15:42:53.513", "Id": "4436", "Score": "2", "body": "I'd rather not answer this one :O, but I'll give you one hint: **switch**." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-08-31T16:03:24.423", "Id": ...
[ { "body": "<p>You may want to consider indexing some of your variables into an array, with the contents of the array being additional arrays that have the strings that you'll then set.</p>\n", "comments": [], "meta_data": { "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "Creati...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-09T13:59:32.813", "Id": "2885", "Score": "5", "Tags": [ "javascript" ], "Title": "Rosary app for the Palm Pre" }
2885
<p>I have a query like this <code>"abc=1, def=2, ghi=3"</code> and I need to parse it into arrays like this <code>keys = [abc, def, ghi] and values = [1,2,3]</code></p> <p>currently my code is like this</p> <pre><code>String[] terms = query.split(","); int termsCount = terms.length; String[] keys = new String[termsCo...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-16T22:00:51.637", "Id": "33030", "Score": "0", "body": "`String[] values = new Object[termsCount];` should be `String[] values = new String[termsCount];`. Alternatively, you could chuck the whole arrays thing and do what the posters be...
[ { "body": "<p>The code as it is, is fine. The biggest point is that you should perform the <code>.split(\"=\")</code> only once:</p>\n\n<pre><code>String[] parts = terms[i].split(\"=\");\nkeys[i] = parts[0];\nvalues[i] = parts[1];\n</code></pre>\n\n<p>However there is a more general point: Why are you using arr...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-09T14:34:23.483", "Id": "2886", "Score": "5", "Tags": [ "java", "parsing" ], "Title": "Code review - parse a query to arrays" }
2886
<p>Is this code Pythonic?</p> <pre><code>def emit_decorator(method, signal_name): def decorated(self, *args, **kwargs): retval = method(self, *args, **kwargs) getattr(self, signal_name).emit() return retval return decorated class Model(base.Transformer, Node): """ Transformer s...
[]
[ { "body": "<p>Modifying the class after defining it smells. That is, its not necessarily a bad idea but one should explore options before resorting to it.</p>\n\n<p>When \"decorating\" a function you should use the functools.wraps decorator. It will make the decorated function look more like the original.</p>\n...
{ "AcceptedAnswerId": "2893", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-09T20:23:27.413", "Id": "2890", "Score": "5", "Tags": [ "python" ], "Title": "Python subclass method decoration" }
2890
<p>Is there a better way to have a minimal Python plugin mechanism than the following?</p> <p>(This was inspired from <a href="https://stackoverflow.com/questions/487971/is-there-a-standard-way-to-list-names-of-python-modules-in-a-package">this post</a>.)</p> <pre><code>import sys import pkgutil import os.path import...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-29T07:12:54.747", "Id": "4795", "Score": "0", "body": "I personally would go with the route of having the individual plugin hook themselves into the \"plugins\" module. Then you wouldn't have to assume they are anywhere." }, { ...
[ { "body": "<p>Check out how Django apps work:</p>\n\n<ul>\n<li>Plugins are genuine Python packages, so the standard tools can be used to install them</li>\n<li>Plugins that are actually used must be in the PYTHONPATH and listed (only the package name) in the configuration.</li>\n<li>There are scripts to help cr...
{ "AcceptedAnswerId": null, "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-09T21:45:00.437", "Id": "2892", "Score": "11", "Tags": [ "python", "plugin", "modules" ], "Title": "Minimal Python plugin mechanism" }
2892
<p>I've tagged this as homework because it was originally a school project, it was accepted but I'm not satisfied with the code.</p> <p>I've used cramers rule to find the intersection of 3 lines in three dimensional space given the <code>x</code>, <code>y</code> and <code>z</code> coefficients but the code is hideous....
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-09T22:16:46.467", "Id": "4443", "Score": "0", "body": "Definitely there is a cleaner way. This way, it is not extensible to higher numbers without modification. Check out the determinant algorithms using recursion. (See http://wiki.tcl...
[ { "body": "<ol>\n<li>Instead of having variables firstX, secondX, thirdX, replace them with a list X</li>\n<li>Don't put input and calculations in the same function, separate them</li>\n<li><p>You do:</p>\n\n<p>if D == 0:\n some stuff\n if D != 0:\n other stuff</p></li>\n</ol>\n\n<p>use else instead</p>...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-09T22:10:48.773", "Id": "2895", "Score": "3", "Tags": [ "python", "homework" ], "Title": "python: less ugly solution to the intersection of 3 lines in 3 dimensional space" }
2895
<p>How can I refactor this code? I know it's repetitive but I'm not sure how to fix it.</p> <pre><code>$(function() { $('#category-1-button a').bind('click', function() { $(this).css({opacity:'1'}); $('#category-2-button a,#category-3-button a').css({opacity:'0.4'}); $('#blog-headers').css(...
[]
[ { "body": "<p>Give each <code>#category-n-button</code> a class like <code>category_button</code>.</p>\n\n<p>Bind the handler in the <a href=\"http://api.jquery.com/each/\" rel=\"nofollow\"><code>each()</code><sup><i>[docs]</i></sup></a> method so that you can use the index argument to calculate the background...
{ "AcceptedAnswerId": "2902", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-10T01:58:37.033", "Id": "2900", "Score": "6", "Tags": [ "javascript", "jquery" ], "Title": "Showing one category and hiding two others when one of three buttons is clicked" }
2900
<p>I'm making a function that multiplies all numbers between an "a" input and a "b" input with <code>do</code> loop. If you please, check my function and say what's wrong since I don't know loops very well in Scheme.</p> <pre><code>(define (pi-function x y) (let ((result y)) (do ((limI x (+ x 1))) ((= li...
[]
[ { "body": "<p>You can use a <code>do</code> loop without using <code>set!</code>.</p>\n\n<pre><code>(define (product-of-range x y)\n (do ((result 1 (* result i))\n (i x (+ i 1)))\n ((&gt; i y) result)))\n</code></pre>\n", "comments": [ { "ContentLicense": "CC BY-SA 3.0", "C...
{ "AcceptedAnswerId": "2909", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-10T19:15:50.217", "Id": "2908", "Score": "1", "Tags": [ "homework", "scheme", "mathematics" ], "Title": "Function that multiplies all numbers between \"a\" and \"b\" with do loop" ...
2908
<blockquote> <p>Using C#, create a class which gets an action (parameter-less delegate) in its construction and has a single public method <code>bool execute()</code> which does the following:</p> <ul> <li><p>Executes the action only if no other thread is currently executing the action</p></li> <li><p>If...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-11T08:25:42.340", "Id": "4471", "Score": "0", "body": "`wait until thread finished before returning` - I do not see any code which will do it. `create class which get an action (parameter less delegate) in its construction` - you didn'...
[ { "body": "<p>You need to look at how you can make the <code>Execute</code> method both thread-safe and true to the requirements of the method. You say that it only should return true in the case where the delegate is actually called, but you need to make sure that only one thread can call it at a time. That's ...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-11T04:01:34.367", "Id": "2910", "Score": "3", "Tags": [ "c#", "interview-questions", "multithreading" ], "Title": "Determining if current thread is executing" }
2910
<p>I have written this Perl code, and there is still more to add, however I was hoping that I could get some opinions on whether it could be written better.</p> <p>Specifically, there is a central <code>if</code>-<code>elsif</code> structure. Should I make this a subroutine or not? What's best practice? </p> <p>Also,...
[]
[ { "body": "<p>You, sir, need a <a href=\"http://www.perl.com/pub/2003/08/07/design2.html\" rel=\"nofollow\">Strategy</a> pattern -- at least to resolve your if->elseif problem. I find a Gang of Four style reference like <a href=\"http://www.blackwasp.co.uk/Strategy.aspx\" rel=\"nofollow\">http://www.blackwasp....
{ "AcceptedAnswerId": "2919", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-11T05:24:00.373", "Id": "2911", "Score": "3", "Tags": [ "parsing", "perl", "subroutine" ], "Title": "Verb tense parser" }
2911
<p>Conditional parsing (aka read some tokens and return true or false).</p> <p>As a solution to <a href="https://stackoverflow.com/questions/6228935/processing-conditional-statements">this SO question</a>, I wrote following code:</p> <pre><code>bool nectar_loader::resolve_conditional( const std::function&lt;bool(cons...
[]
[ { "body": "<p>A few comments:</p>\n\n<pre><code>bool nectar_loader::resolve_conditional( const std::function&lt;bool(const string&amp;)&gt; &amp;config_contains )\n</code></pre>\n\n<p>I'd generally prefer to turn this into a template, and pass the correct function type (and if I used <code>std::function</code> ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-11T15:55:06.080", "Id": "2914", "Score": "3", "Tags": [ "c++", "parsing" ], "Title": "Conditional parsing, non-standard approach" }
2914
<p>I tried to implement a definitive, reliable URL query string parser that handles every corner case:</p> <ul> <li>it tries to be efficient by avoiding regex</li> <li>it takes full URLs or just query strings (as long as the query string begins with a question mark)</li> <li>it ignores the hash value</li> <li>it handl...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-13T11:53:08.073", "Id": "4493", "Score": "0", "body": "Deleted my answer - I missed that line, sorry! :-) You might still want to take a look at [my other answer over at SO](http://stackoverflow.com/questions/901115/get-query-string-va...
[ { "body": "<p>Is it bug free? No.</p>\n\n<p>These two corner-cases have been missed:</p>\n\n<ol>\n<li>parameter values containing '=', i.e. 'example.com?foo==bar' (double equals) or '?foo=k=v'</li>\n<li>cannot handle parameters called 'toString' and 'valueOf' (amongst others.)</li>\n</ol>\n\n<p>The first may w...
{ "AcceptedAnswerId": null, "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-13T09:05:02.157", "Id": "2924", "Score": "5", "Tags": [ "javascript", "parsing" ], "Title": "Is this query-string parser bug-free?" }
2924
<p>Please review this Android UnitConverter App which has been designed using Strategy Pattern.</p> <pre><code>public class UnitConverter extends Activity implements OnClickListener, AdapterView.OnItemSelectedListener { /** Called when the activity is first created. */ private Spinner SpinnerUnit; pr...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-03T21:08:38.530", "Id": "85832", "Score": "0", "body": "Never am able to point this out on SO, so I am so happy to *finally* be able to mention this: **Whenever Eclipse creates methods, delete the auto-generated method stub comment**. ...
[ { "body": "<p>As the comment says, you should post the code, possibly in smaller parts. Until then some general suggestions:</p>\n\n<ul>\n<li>Clean up the indentation. You are mixing spaces and tabs.</li>\n<li>Clean up the variable/method names. By convention Java variables and method names start with a small l...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-13T15:05:57.073", "Id": "2928", "Score": "4", "Tags": [ "java", "android", "converting" ], "Title": "Unit Converter App" }
2928
<p>Please review the sales tax problem which has been designed using strategy pattern.</p> <p><strong>The Problem:</strong></p> <blockquote> <p>Basic sales tax is applicable at a rate of 10% on all goods, except books, food, and medical products that are exempt. Import duty is an additional sales tax applicable...
[]
[ { "body": "<p>I would use a diferent aproach instead of all this inheritance, I think it is simpler to use just Item class with Rate and ImportedDuty, on the factory just create and configure each item with the desired values.</p>\n", "comments": [], "meta_data": { "CommentCount": "0", "Cont...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-13T15:16:05.590", "Id": "2929", "Score": "7", "Tags": [ "c++", "design-patterns", "finance" ], "Title": "Sales tax calculator" }
2929
<p>I know exactly how I would handle this in PHP, Python, JS, and AS, but I want to confirm that this is the correct approach to Enums in Java.</p> <p>I have a database view which has a status column. It will only ever have one of four values (in MySQL, I would have made it an enum type column, but the type doesn't <e...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-14T07:19:51.327", "Id": "4517", "Score": "0", "body": "Looks good. I'd probably go with something like `ProjectStatus` or `StatusType`. I don't like naming types plural unless each instance holds multiple things. Each instance of an en...
[ { "body": "<p>To start with, this is not good:</p>\n\n<pre><code>COMPLETE(\"opted out\"), \nOPTED_OUT(\"complete\");\n</code></pre>\n\n<p>Otherwise, this is pretty standard code. There are two things I'd note:</p>\n\n<ol>\n<li>If <code>desc</code> is coming from the database, you may have a risk of NullPointerE...
{ "AcceptedAnswerId": "2933", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-13T19:12:42.880", "Id": "2932", "Score": "3", "Tags": [ "java" ], "Title": "Obtaining column status definition" }
2932
<pre><code>public delegate DataTable loadDataTable(); DataTable shops = (cmbShop.Text == "All Shops") ? new loadDataTable(() =&gt; { Program.con.GET_Table_From_DataBase("sh", "select * from shops "); return Program.con.dst.Tables["sh"]; } ).Invoke() : new loadDataT...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-14T13:28:17.563", "Id": "4521", "Score": "4", "body": "Why on earth would you use a lambda expression here?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-14T13:28:28.830", "Id": "4522", "Score": "...
[ { "body": "<p>You don't need any lambda expressions at all.</p>\n\n<p>You can write</p>\n\n<pre><code>if (cmbShop.Text == \"All Shops\")\n Program.con.GET_Table_From_DataBase(\"sh\", \"select * from shops \");\nelse\n Program.con.GET_Table_From_DataBase(\"sh\", \"select * from shops where shopname='\" + ...
{ "AcceptedAnswerId": "2945", "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-14T10:44:54.587", "Id": "2937", "Score": "3", "Tags": [ "c#", "linq" ], "Title": "Loading either all shops or a specifically named shop from a DataTable" }
2937
<p><a href="http://clojure.org/" rel="nofollow">Clojure</a> is a Lisp dialect which targets the Java Virtual Machine (<a href="http://github.com/richhickey/clojure-clr" rel="nofollow">and the CLR</a>). Its main features include a software transactional memory system for coherent updates to data structures, transparent...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-14T11:54:14.283", "Id": "2939", "Score": "0", "Tags": null, "Title": null }
2939
Clojure is a Lisp dialect for the Java Virtual Machine. Its main features include a software transactional memory system for coherent updates to data structures, transparent access to Java libraries, a dynamic REPL development environment, runtime polymorphism, and built-in concurrent programming constructs.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-14T11:54:14.283", "Id": "2940", "Score": "0", "Tags": null, "Title": null }
2940
<p>I'm an experienced programmer, but just a beginner in Python, and would like some input on a small function that's working but which I'm not very happy with.</p> <p>It's used to produce XML tags (strings). The content argument can be a string, a number etc., but if it's a datetime I have to format it properly. Also...
[]
[ { "body": "<p>Always use an XML library to read or write XML.\nStitching XML together with string concatenation misses the point of using XML.</p>\n", "comments": [ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-14T12:12:23.527", "Id": "4519", "Score": "0"...
{ "AcceptedAnswerId": "3313", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-14T12:05:07.070", "Id": "2941", "Score": "2", "Tags": [ "python", "strings", "xml" ], "Title": "XML-tag function" }
2941
<pre><code> &lt;select name="checkInDay" tabindex="3" onchange="calcDay();" class="ffe selectform" id="checkInDate"&gt; &lt;?php for($i=1;$i&lt;=31;$i++) { $value = $i &lt; 10 ? "0".$i : $i; ?&gt; &lt;option value="&lt;?= $value ?&gt;" &lt;?php if($i == 12) {?&gt; selected="selected" &lt;?php } ?...
[]
[ { "body": "<p>I suggest to build a function which can be reused for the options:</p>\n\n<pre><code>function select_options($options, $selected = null) {\n $_options = '';\n foreach ($options as $value =&gt; $content) {\n $_options .= sprintf(\"&lt;option value=\\\"%s\\\"%s&gt;%s&lt;/option&gt;\\n\", $value...
{ "AcceptedAnswerId": "2946", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-14T12:39:12.593", "Id": "2943", "Score": "1", "Tags": [ "php", "datetime", "form" ], "Title": "Generating a selection box for the day of the month" }
2943
<p>i have created simple php engine, i want that this engine used html/php codes from mysql. Here is this php code and please if you find out some mistakes or bugs, please post here. I realy want to use this code for my website but i want to be sure this code safe and bug fixed, so help!</p> <pre><code>&lt;?php sessio...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-07-16T00:17:16.313", "Id": "5205", "Score": "2", "body": "What is the point of this *engine*?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-08-15T10:28:34.797", "Id": "6125", "Score": "0", "body": "...
[ { "body": "<p>I would recommend against storing PHP code for your website in database fields. It will make it very difficult to maintain in the future.</p>\n\n<p>Also, be sure that if someone has an active session from 11:50 PM until 12:05 AM the next day, that your $_SESSION['last-update'] values will work as...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-14T15:04:23.913", "Id": "2947", "Score": "3", "Tags": [ "php", "mysql" ], "Title": "PHP simple engine" }
2947
<p>I'm sure there's a better more 'jQuery' like way of writing this. In particular the selector <code>$(this).closest('div.login-box')</code> being in there twice. Perhaps it's possible to use <code>$(this)</code>?</p> <pre><code>$('.close-box').click(function () { $(this).closest('div.login-box').slideToggle...
[]
[ { "body": "<p>You could combine the calls:</p>\n\n<pre><code>if ($(this).closest('div.login-box')\n .slideToggle(\"400\")\n .attr('id'))\n</code></pre>\n\n<p>However, I do not recommend this.<br>\nAlthough it will work, it's unnecessarily confusing.</p>\n", "comments": [ { ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-14T16:06:48.173", "Id": "2948", "Score": "1", "Tags": [ "javascript", "jquery", "form" ], "Title": "jQuery handler for closing a login box" }
2948
<p>Mostly for the experience (but also so I could waste hours playing it), I made a simple memory card game in JavaScript. I built it so it has a backbone framework that could be easily extended by stripping off my actual implementation. It's the backbone I'd like reviewed here, and mostly:</p> <ol> <li>My OO - anythi...
[]
[ { "body": "<p>I'll start off with some questions, because you are using techniques, that I don't have much experience with.</p>\n\n<ul>\n<li><p>What run time environment are you considering using? (Or in other words, which browsers do you want to support?) <code>Object.create</code> is very, very new and thus s...
{ "AcceptedAnswerId": "2962", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-14T17:25:37.750", "Id": "2949", "Score": "3", "Tags": [ "javascript", "object-oriented", "game" ], "Title": "My Memory Game \"Engine\"" }
2949
<p>I have a ActionScript 3 AIR class that I'd like you to check for robustness. I know it's quite a lot of code and It's not required that you review the full code, but maybe you see general problems in the way I handle exceptions or maybe you spot something that could make troubles.</p> <p>The purpose of the Class is...
[]
[ { "body": "<p>After three and a half years, I guess your code turned out to be robust... even although your question went unanswered.</p>\n\n<p>I can't answer your core question, but here are some side remarks:</p>\n\n<hr>\n\n<pre><code> if(remoteVersion&gt;localVersion)\n updateSWF();\n ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-14T18:51:13.900", "Id": "2952", "Score": "3", "Tags": [ "actionscript-3" ], "Title": "AS3 AIR class robustness check" }
2952
<p>I am terrible with writing JavaScript code that outputs HTML. So, here's how a string literal looks like in a project that I'm working on:</p> <pre><code>tweet = '&lt;div class="h-ui-box"&gt;' + '&lt;table&gt;' + '&lt;tr&gt;' + '&lt;td id="first"&gt;' + '&lt;img src="' + item.profile_image_url + '" alt="' + item...
[]
[ { "body": "<p>Make yourself a \"template\" that you immediately convert into html (using innerHtml or whatever your framework has handy), then use the dom to fix up the few variable bits. You may use ids to locate the tags that need substitution, if you can guarantee they are unique. Otherwise use XPath.</p>\n"...
{ "AcceptedAnswerId": "2955", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-14T21:55:12.010", "Id": "2953", "Score": "1", "Tags": [ "javascript", "html" ], "Title": "JavaScript string that holds HTML code" }
2953
<p>I have one large view function where a user can Add, Edit, Delete, and Update his education. I am currently doing this all in one view because I haven't yet learned how to split up views by function. Here is what I currently have -- </p> <p>I have a single URL pointing to the view -- </p> <pre><code>url(r'^profile...
[]
[ { "body": "<p>Simple way to split it up by block logic (create, edit, remove or else)</p>\n\n<pre><code># app/views.py\ndef create_edit(request, id=None):\n # if id: we should edit instance\n #else: we shoud create new instance\n return ...\n\ndef delete(request, id):\n # remove instance\n return...
{ "AcceptedAnswerId": "2960", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-15T05:11:31.517", "Id": "2957", "Score": "1", "Tags": [ "python", "django" ], "Title": "Separating a view function by action" }
2957
<p>I wanted a good way to move objects back and forth between Lua and C++, and I didn't want to use anything like LuaBind or the other available libraries I could find, so I instead wrote this. It's designed to be similar to the normal Lua API, which has functions like <code>lua_tostring</code> or <code>lua_tonumber</c...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-07-17T19:01:15.247", "Id": "5247", "Score": "0", "body": "Can you elaborate on why this is better than Luabind?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-07-18T00:57:25.783", "Id": "5249", "Score": ...
[ { "body": "<h1><code>#define</code>s</h1>\n\n<p>This is not a good use of <code>#define</code>. This should be a <code>const string</code> instead:</p>\n\n<blockquote>\n<pre><code>#define LUAW_CTOR_KEY \"__ctor\"\n</code></pre>\n</blockquote>\n\n<hr>\n\n<p>And this should be a function:</p>\n\n<blockquote>\n<pr...
{ "AcceptedAnswerId": null, "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-15T05:22:56.163", "Id": "2958", "Score": "27", "Tags": [ "c++", "api", "lua" ], "Title": "C++ API for interfacing with Lua" }
2958
<p>How do I improve this code for reading an epub file? The code is as follow:</p> <pre><code>package org.example.mymenu; import java.awt.print.Book; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; //import java.util.List; //import org.exa...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-15T19:59:02.757", "Id": "4542", "Score": "2", "body": "To be honest, I don't know what to review here. There is virtually no notable code there other than the initialization of a Book object. The only thing think I can think of is: han...
[ { "body": "<ol>\n<li><p>According to the <a href=\"http://www.oracle.com/technetwork/java/codeconvtoc-136057.html\" rel=\"nofollow\">Code Conventions for the Java Programming Language</a>, <em>9. Naming Conventions</em>, I'd call the class <code>EpubReader</code>. The name should be a noun, and try to avoid abb...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-15T12:57:09.500", "Id": "2966", "Score": "4", "Tags": [ "java", "android" ], "Title": "EPUB reader for Android" }
2966
<p><br/> The following code is mainly concerned with the conversion from byte/bit stream to numericals such as int, unsigned int, short int, unsigned short int, float, and etc. These functions are heavily used in my image data decoding program. I feel an insufferably slow when dealing with bigger image. Would please he...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-16T05:43:14.753", "Id": "4548", "Score": "0", "body": "@Lee How does the rest of your program use these functions? Have you profiled your application and the measurements point to these functions to be the bottleneck? I ask because I b...
[ { "body": "<p>Sorry if I'm misunderstanding the code, but here are some ideas of how it can be improved, focusing on performance. Those are the things that immediately came to my mind. I've probably missed things, and there may be higher level optimizations that can be done that I didn't see because I just took...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-15T16:57:54.140", "Id": "2969", "Score": "6", "Tags": [ "c++", "optimization" ], "Title": "Bit-twiddling for a custom image format" }
2969
<p>I'm trying to emulate the default behavior of an ItemsControl in a ContentControl--Bind Content to an <code>object</code> property and use the correct DataTemplate based on that object's type.</p> <p>I've tried to <strike>Reflector</strike> dotPeek at the implementation of the ItemsControl to see how it works, but ...
[]
[ { "body": "<p>I think first of all you should get rid of looking for dataTemplates by type name. Then instead of your method you will be able to use <a href=\"http://msdn.microsoft.com/en-us/library/system.windows.frameworkelement.findresource.aspx\" rel=\"nofollow\">FindResource method</a>:</p>\n\n<pre><code>v...
{ "AcceptedAnswerId": "2980", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-15T17:20:35.540", "Id": "2970", "Score": "5", "Tags": [ "c#", ".net", "wpf" ], "Title": "Trying to un-hack this DataTemplateSelector" }
2970
<p>There is Three Validation Group A,B and No Group.</p> <p>How to get validation result of only the specific validation group.</p> <p>If Group A and No Group is not valid but all of group B is valid, i would like to get result as valid.</p> <p>I have read the article validation in depth but don't find the straightf...
[]
[ { "body": "<p>Linq will make it look better:</p>\n\n<pre><code>protected bool IsGroupB_Valid()\n{\n return Page.GetValidators(\"B\").All(v =&gt; v.IsValid);\n}\n</code></pre>\n\n<p>But probably you should look for something really different</p>\n", "comments": [], "meta_data": { "CommentCount":...
{ "AcceptedAnswerId": "2979", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-16T07:26:44.573", "Id": "2976", "Score": "2", "Tags": [ "c#", "asp.net" ], "Title": "Get Validation result by group" }
2976
<pre><code>&lt;div class="minipassbox" style="margin-top: 5px;"&gt; &lt;?php for($i = 1; $i &lt;= 3; $i++) { $marginRight = ($i &lt; 3 ? "margin-right:4px" : ""); echo "&lt;div style='width:56px;float:left;{$marginRight}'&gt;"; ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-16T10:55:04.673", "Id": "4550", "Score": "0", "body": "Well, it's a loop. Any specific question? Beside, why don't you hard-code it if there isn't any dynamic in it?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "...
[ { "body": "<p>Two advices:</p>\n\n<ol>\n<li><p><strong>Use <a href=\"http://php.net/manual/en/control-structures.alternative-syntax.php\" rel=\"nofollow\">PHP alternative syntax</a></strong></p>\n\n<p>When mixing HTML and PHP, it is a good practice to use <a href=\"http://php.net/manual/en/control-structures.a...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-16T10:08:26.067", "Id": "2977", "Score": "0", "Tags": [ "php" ], "Title": "PHP mini-password-box: Too many loops" }
2977
<p>Following is the code which finds the social network of a friend (i.e. friends of friends and so on). Friends definition is, ff W1 is friend of W2, then there should be Levenshtein distance equal to 1. It is working fine with a smaller dictionary, but is taking a lot of time with a bigger dictionary.</p> <p>Need so...
[]
[ { "body": "<p>My first thought is that you may want to profile the code and see where most of the time is being spent.</p>\n\n<p>My second thought comes from examining the code. You are doing a lot of <code>xxx[i]</code> or similar inside loops where <code>i</code> is simply being incremented. To me, that sug...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-16T11:24:12.000", "Id": "2978", "Score": "2", "Tags": [ "c++", "algorithm", "edit-distance" ], "Title": "Finding social network of a friend" }
2978
<p>I'm making a pong game with SFML and in the process made a function that takes a <code>Time</code>, <code>Speed</code>, <code>Angle</code> of movement, buffer for the movement on the X axis, and buffer for the movement on the Y axis. </p> <p>I then implemented this function into my custom <code>mySprite</code> clas...
[]
[ { "body": "<p>It's often simpler to have a fixed frame rate in a game. Then you don't have to multiply everything by a time factor. In this case, you do not have to lower the frame rate to the lowest value that all computers can handle. You can for example let the position updates run at 200Hz and update the gr...
{ "AcceptedAnswerId": "3048", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-17T01:56:06.677", "Id": "2985", "Score": "2", "Tags": [ "c++", "sfml" ], "Title": "How is my SFML sprite Move() function?" }
2985
<p>So I have started a PHP framework called ExCx and I haven't really had much experience in the professional development business.</p> <p>I was just wondering if my structure/layout/methods are up to scratch?</p> <p>EDIT: Forget the URL, added that. Normally I remember to omit the closing php tag...</p> <p>In tande...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-18T05:05:15.153", "Id": "4560", "Score": "0", "body": "Erm, 404 Not Found." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-21T08:38:59.980", "Id": "4607", "Score": "0", "body": "Please post code...
[ { "body": "<p>I haven't read the source code entirely, but here a few things that came to mind immediately:</p>\n\n<ul>\n<li>Use PHP Docblocks, so my IDE can support me when using your code</li>\n<li>Please break down <code>backtrace()</code> into smaller functions which are understandable in an instant or inse...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-17T04:08:49.290", "Id": "2986", "Score": "5", "Tags": [ "php" ], "Title": "Open source PHP framework" }
2986
<p>I've been playing around with Python off and on for about the past year and recently came up with the following 68 (was 62) lines. I think I'll try making a calculator out of it. I'd really like to know what readers here think of its attributes such as coding style, readability, and feasible purposefulness.</p> <pr...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-17T14:37:04.900", "Id": "4557", "Score": "2", "body": "It would be nice to see some sample input too." } ]
[ { "body": "<p>To allow your module to be loadable by other files, it's customary to write the end of it with a <code>if __name__ == '__main__':</code> conditional like so:</p>\n\n<pre><code>if __name__ == '__main__':\n interp = Interpreter()\n for x in file(__file__.split('/')[-1].split(\".\")[-2] + \".wh...
{ "AcceptedAnswerId": "2994", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-17T05:41:16.843", "Id": "2988", "Score": "6", "Tags": [ "python", "interpreter" ], "Title": "Simple Language Interpreter" }
2988
<p>i have this code that is suppose to work with at starting the minimum number of threads, say 5. when it starts the first five threads, it automatically replaces any thread that is finished making sure that there is always five threads working.</p> <p>the problem here is that, am finding it difficult to manage wher...
[]
[ { "body": "<p>Unfortunately, the whole approach is broken. You should make your parallel <em>tasks</em> explicit in the code so that you don’t need cross-thread communication any more. Secondly, you are writing your own thread scheduler here. – Don’t. Schedulers already exist, take advantage of that.</p>\n\n<p>...
{ "AcceptedAnswerId": "2992", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-17T10:55:39.053", "Id": "2991", "Score": "2", "Tags": [ "multithreading", "vb.net" ], "Title": "multiple threaded program vb.net" }
2991
<p>I wrote program which simulates the work of the restaurant. It works but I would like to change it because I think there is better solution.Thanks for your suggestions.</p> <p>Client.java</p> <pre><code>public class Client implements Runnable { private Restaurant r; public void makeOrder() throws Interrup...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-20T07:53:12.333", "Id": "4570", "Score": "0", "body": "There is very similar demo example [http://code.google.com/p/wing-ding/source/browse/trunk/books/Programming_Scala/src/ch09/sleepingbarber/]. It was written using scala and actor c...
[ { "body": "<p>The main issue here is that everything synchronizes on the restaurant object. This means that the chef cannot prepare food while the client is placing an order, waiters cannot serve while the chef is cooking, etc. The first step would be to add <code>BlockingQueue</code>s to <code>Restaurant</code...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-18T14:36:32.167", "Id": "3001", "Score": "5", "Tags": [ "java", "multithreading" ], "Title": "Simple multithreading task" }
3001
<p>I have the following class that processes a Bitmap to place a fisheye distortion on it. I've run my app through TraceView and found that virtually all the processing time is spent looping through the bitmap. One developer has suggested not using float as this will slow things down where graphics are concerned. Also,...
[]
[ { "body": "<p>This line will eat a lot of performance:</p>\n\n<pre><code>if( Math.sqrt( Math.pow(i - centerX, 2) + ( Math.pow(j - centerY, 2) ) ) &lt;= 150 )\n</code></pre>\n\n<p>First for simple squaring, write your own function:</p>\n\n<pre><code>float sqr(float x) { return x*x; }\n</code></pre>\n\n<p>Second ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-19T16:06:41.550", "Id": "3007", "Score": "8", "Tags": [ "java", "android", "image" ], "Title": "Adding a Fish Eye Distortion to a Bitmap" }
3007
<p>I am fairly new to PHP, and would love to have my code reviewed to see what I am doing wrong and ways to improve it. The code works fine, I just feel like there's an easier way to do this.</p> <p>This is the PHP code at the top of my page - and then the HTML is below it, but I will only paste the PHP code. What t...
[]
[ { "body": "<p>The first part that updates the selected credit card has a lot of code duplication that could be made generic.</p>\n\n<pre><code>// Get Current Credit Cards Value In Database\n$userCards= $result[0]['credit_cards'];\n\n$CARDS = array('visa', 'mastercard', 'discover', 'amex');\n$cardIndex = array_s...
{ "AcceptedAnswerId": "3011", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-20T00:42:05.773", "Id": "3010", "Score": "1", "Tags": [ "php", "mysqli", "finance" ], "Title": "Adding credit cards to a database" }
3010
<p>Over the last months I have been writing a jQuery plugin called <strong>Better Autocomplete</strong> (<a href="https://github.com/betamos/Better-Autocomplete">Code on Github</a>). It originated from another project, a Drupal module called Linkit, but I decided it should be a standalone plugin. I have spent a lot of ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-27T03:03:24.410", "Id": "4738", "Score": "1", "body": "Firstly: I can't help with JSDoc and i'm not a very experienced jQuery plugin Developer but on #2 I think you should be asking the users of your plugin. Provide an email/discussion...
[ { "body": "<p>You should strongly consider using a JS templating language such as Handlebars.js when rendering the interface.</p>\n\n<pre><code> // Add the group if it doesn't exist\n var group = callbacks.getGroup(result);\n if ($.type(group) == 'string' &amp;&amp; !groups[group]) {\n var $groupHeading =...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-20T03:24:04.807", "Id": "3012", "Score": "22", "Tags": [ "javascript", "jquery" ], "Title": "Writing a better alternative to jQuery Autocomplete" }
3012
<p>From <a href="http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-23.html" rel="nofollow">SICP</a>:</p> <blockquote> <p>Exercise 3.47. A semaphore (of size n) is a generalization of a mutex. Like a mutex, a semaphore supports acquire and release operations, but it is more general in that up to n proce...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-20T05:57:36.740", "Id": "3013", "Score": "1", "Tags": [ "lisp", "scheme", "sicp" ], "Title": "Write a definition of a semaphore in terms of mutexes" }
3013
<p>From <a href="http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-23.html" rel="nofollow">SICP</a>:</p> <blockquote> <p>Exercise 3.47. A semaphore (of size n) is a generalization of a mutex. Like a mutex, a semaphore supports acquire and release operations, but it is more general in that up to n proce...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-20T06:06:43.133", "Id": "3014", "Score": "1", "Tags": [ "lisp", "scheme", "sicp" ], "Title": "Write a definition of a semaphore in terms of test-and-set! operations" }
3014
<p>I have a file containing one long line:</p> <pre><code>"name surname" &lt;name.surname@example.com&gt;, 'name surname' &lt;name.surname@example.com&gt;, name surname &lt;name.surname@example.com&gt;, "'name surname'" &lt;name.surname@example.com&gt;, surname, &lt;name.surname@example.com&gt;, name &lt;name.surname@...
[]
[ { "body": "<p>Why are you first removing the quotes and then putting them back?</p>\n\n<p>And why are you removing the brackets and them putting them back?</p>\n\n<p>This does the same thing, except change ' to \". It also doesn't handle commas in names,\nso if you have that it won't work. In that case I'd prob...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-20T09:35:49.410", "Id": "3016", "Score": "1", "Tags": [ "python" ], "Title": "Splitting one line into multiple ones given a separator" }
3016
<p>Here is my program which creates a linked list and reverses it:</p> <pre><code>#include&lt;stdio.h&gt; #include&lt;stdlib.h&gt; struct node { int data; struct node *next; }; struct node *list=NULL; struct node *root=NULL; static int count=0; struct node *create_node(int);//function to create node void trave...
[]
[ { "body": "<p>You should compile with all warnings enabled, e.g. <code>gcc -Wall</code>:</p>\n\n<pre><code>review.c: In function ‘main’:\nreview.c:16: warning: unused variable ‘j’\nreview.c:34: warning: control reaches end of non-void function\n</code></pre>\n\n<p>This tells you that you have an unused variable...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-20T13:17:11.713", "Id": "3018", "Score": "4", "Tags": [ "c", "linked-list" ], "Title": "Creating and reversing a linked list" }
3018
<p>I'm using this pattern for the first time and wanted to check if this is the correct implementation.</p> <p><strong>class.validator.strategy.php</strong></p> <pre><code>abstract class ValidatorStrategy { abstract public function check( $name, $val ); } </code></pre> <p><strong>class.text.validator.php</stron...
[]
[ { "body": "<p>I don't write php, so please bear with me; but I don't care for the isValidate method. In pseudo-code... I usually write something like</p>\n\n<pre><code>foreach(var validator in validatorCollection)\n if validator-&gt;Check = false\n return false\n\nreturn true\n</code></pre>\n\n<p>Als...
{ "AcceptedAnswerId": "3025", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-20T15:30:05.320", "Id": "3021", "Score": "3", "Tags": [ "php", "design-patterns", "validation", "email" ], "Title": "Email text validator" }
3021
<p>I would like your thoughts on my database structure. I am kind of a rookie but I am trying. All of your suggestions, alternatives, ideas, additions are welcome. Thank you.</p> <pre><code>CREATE TABLE `buy` ( `PurchaseID` int(10) unsigned NOT NULL AUTO_INCREMENT, `PurchaseTime` timestamp NOT NULL DEFAULT CURRENT...
[]
[ { "body": "<p>Looking at what you have so far, it seems your tables logically fall into two groups: </p>\n\n<ol>\n<li>entity tables </li>\n<li>relationship tables. </li>\n</ol>\n\n<p>It may be easier to read if you define all the entity tables first, then all the relationship tables.</p>\n\n<p>In general, your...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-20T16:17:34.320", "Id": "3023", "Score": "1", "Tags": [ "sql", "mysql" ], "Title": "Cash Register database structure" }
3023
<p>I'm currently reviewing some standard pieces of code I use a lot in projects.</p> <p>Currently I'm using the following functions for password hashing.</p> <pre><code>function generate_salt($length = 20){ $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz'. '0123456789``-=~!@#$%^&amp;*()_...
[]
[ { "body": "<p>What is the motivation behind hashing and reversing the string multiple times? If you have a secure hash function, then hashing a single time (combined with a sufficient amount of salt data) is perfectly sufficient. If you have an insecure hash function, then hashing multiple times is extraordinar...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-20T19:39:01.777", "Id": "3030", "Score": "2", "Tags": [ "php", "security" ], "Title": "Reviewing password hashing functions" }
3030
<p>I tried a <a href="http://codingdojo.org/cgi-bin/wiki.pl?KataYahtzee" rel="nofollow">Yahtzee kata</a> in Python the other day. I'm not particularly experienced in Python (C# is my main language) so I'd be interested in any feedback as to how I could have done things better. In particular, I wonder whether my <code>C...
[]
[ { "body": "<pre><code>import unittest\n\n#helpers\ndef Count(dice, number):\n</code></pre>\n\n<p>The python style guide recommends lowercase_with_underscores for global functions.</p>\n\n<pre><code> return len([y for y in dice if y == number])\n</code></pre>\n\n<p>This can be written as</p>\n\n<pre><code> ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-20T22:02:40.530", "Id": "3036", "Score": "7", "Tags": [ "python", "game", "programming-challenge", "playing-cards", "dice" ], "Title": "Yahtzee Code Kata in Python" }
3036
<p>I've knocked together a few lines of python to read in stats for a service (haproxy), and store them in an array (to do some analysis on later). It basically takes a multiline output, and splits it into multiple subarrays. This is how I've done it - can anyone offer improvements for me?</p> <pre><code>def build_arr...
[]
[ { "body": "<p><code>build_array</code> uses a global variable, which I don't see any good reason for. Why not just pass the data in as a parameter?</p>\n\n<pre><code>def build_array(data):\n # ...whatever\n</code></pre>\n\n<p>Also, you don't remove the leading whitespace from the first element on each line - ...
{ "AcceptedAnswerId": "3046", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-21T11:29:23.630", "Id": "3040", "Score": "1", "Tags": [ "python", "array" ], "Title": "Multiline Input into Python Arrays" }
3040
<p>I'm creating a function that converts a title, to a URL slug. I'm not all to familiar with regular expressions, but I've done my best. Can you see any problems or improvements with the following function below?</p> <p>The only thing allowed in the slug is letters, numbers and <code>-</code> charchaters.</p> <pre><...
[]
[ { "body": "<p>You should prepare a set of sentences to slugify and verify by yourself if your function is ok.</p>\n\n<p>Below are the step I use to slugify text:</p>\n\n<ol>\n<li><p>Use <code>iconv()</code> if available:</p>\n\n<p><code>$slug = iconv('utf-8', 'us-ascii//TRANSLIT', $text);</code></p></li>\n<li><...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2011-06-21T12:46:50.757", "Id": "3041", "Score": "2", "Tags": [ "php", "regex", "url" ], "Title": "Function to convert a title to a slug" }
3041
<p>So I'm developing a webpage using MVC which will be mainly JavaScript driven.</p> <p>Instead of using global variables, and global functions, I would like to do it right this time. I don't want to use something to complex, because the team and I are new to large JavaScript applications. I tried implementing the Mod...
[]
[ { "body": "<p>You have multiple anonymous functions when you could do one and on the last line return your ui.* object.</p>\n\n<pre><code>var ui = (function($) {\n // local ui ref\n var ui = {};\n\n // other namespaces .. etc\n ui.tabs = {};\n\n return ui;\n})(jQuery));\n</code></pre>\n", "co...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-21T18:16:38.780", "Id": "3047", "Score": "4", "Tags": [ "javascript", "jquery", "jquery-ui" ], "Title": "Organizing page functions and page state using the Module pattern" }
3047
<pre><code>new MethodExecuter() .ForAllInvocationsCheckCondition(!Context.WannaShutDown) .When(shouldRun).ThenInvoke(x =&gt; x.Methods(new Action[] { B.Process, A.Process })) .When(shouldRun).ThenInvoke(x =&gt; x.Method(B.Process).Repeat(100)) .Invoke(x =&gt; x.Method(C.Process)); </code></p...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-21T20:52:42.703", "Id": "4615", "Score": "1", "body": "How enjoyable is it to debug this? Does the fluent syntax make it more difficult? What is this abstraction buying you? Fluent APIs are not better ipso facto. Similar to how a ...
[ { "body": "<p>Fluent APIs in general always make me think back to <a href=\"http://codeutopia.net/blog/2008/01/21/pooquery-the-fluent-php-revolution/\" rel=\"nofollow\">pooQuery</a>. Fluent APIs (in my opinion) are aimed at the same goal that resulted in the creation of <a href=\"http://en.wikipedia.org/wiki/CO...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-21T20:09:40.027", "Id": "3049", "Score": "3", "Tags": [ "c#", "api" ], "Title": "Complexity, Usability and Readability of FluentAPIs - Sample: FluentMethodInvoker" }
3049
<p>I'm testing some methods for checking if an area of the screen changes, can you see any problems with how I'm doing this, and is there a better way for me to do this?</p> <p>the <code>_memoryImage2</code> will not change in the final app, it will be a read only array that I will check the <code>memoryImage</code> a...
[]
[ { "body": "<p>Let's start with your algorithm. You're using <code>Bitmap.GetPixel</code> to convert the entire bitmap image pixel by pixel into matrix of colors. I tried this approach several years ago - it was pretty slow on .Net 2.0 and I suppose it is still slow. You should convert image into <code>byte[]</c...
{ "AcceptedAnswerId": "3058", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-21T22:51:21.867", "Id": "3053", "Score": "4", "Tags": [ "c#" ], "Title": "Checking to see if an area of the screen changes" }
3053
<p>I caught a whiff of a code-smell emanating from one of my tests, in a scenario akin to the following:</p> <pre><code>[TestFixture] public void CarPresenterTests{ [Test] public void Throws_If_Cars_Wheels_Collection_Is_Null(){ IEnumerable&lt;Wheels&gt; wheels = null; var car = new Car(wheel...
[]
[ { "body": "<p>Is a car really a car without wheels? </p>\n\n<p>If not, the check should be done at <code>Car</code> <strong>construction time</strong> and <code>CarPresenter</code> should not have to check for null, it should assume that a good working car is passed to it. (Correction, <code>CarPresenter</code>...
{ "AcceptedAnswerId": "3055", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-22T00:13:20.080", "Id": "3054", "Score": "5", "Tags": [ "c#", "unit-testing" ], "Title": "Car presenter tests" }
3054
<p>I have created a "Wizard" using JavaScript and based on people's answers you get taken to certain results divs. It works the way I want, but this code is VERY repetitive. Is there a way to clean up this JavaScript code?</p> <p>Demo can be seen <a href="http://jsfiddle.net/dswinson/PXp7c/56/" rel="nofollow">here</a>...
[]
[ { "body": "<p>Something like this is probably a good way to start consolidating. Do the buttons share a class by chance?</p>\n\n<pre><code>$('.myButtonClass').click(function () {\n // Extract an id:\n var myid = this.id.substr(1, 3);\n\n switch (myid) {\n case 'reset':\n $('wizard_start').show();\n ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-22T17:08:23.843", "Id": "3060", "Score": "4", "Tags": [ "javascript" ], "Title": "Wizard for displaying results divs based on answers" }
3060
<p>I am trying to take advantage of the reflection built into RouteValueDictionary to add values to the query string of a URL. This is what I came up with. It seems to work, but I thought I would post it to see if anyone has any suggestions. It also uses the super-secret HttpValueCollection returned by ParseQueryString...
[]
[ { "body": "<p>Instead of catching an exception if the url is relative, use the <a href=\"http://msdn.microsoft.com/en-us/library/system.uri.aspx\" rel=\"nofollow\">System.Uri</a> class to see if it is an absolute Uri.</p>\n", "comments": [], "meta_data": { "CommentCount": "0", "ContentLicens...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-22T18:30:42.740", "Id": "3063", "Score": "6", "Tags": [ "c#", "asp.net" ], "Title": "Using RouteValueDictionary to convert anonymous type to query string" }
3063
<p>I have the following code block which I'd like to refactor into a method, I just don't see a good way to get the following code into a method which doesn't have multiple responsibilities. Here is the code block:</p> <pre><code>int maxResults = pageable.getMaxResults(userPrefs); int firstResult; if (pageData.isLas...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-22T22:37:35.153", "Id": "4641", "Score": "0", "body": "How do you know you're on the last page without knowing how many total results you have?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-23T11:11:13.27...
[ { "body": "<p>You could make <code>count</code> a field, then have a function to <code>determineFirstResult()</code>. Then the <code>setPageNumber</code> block can be separated out.</p>\n\n<pre><code>if (pageData.isLastPage()) {\n count = getCountFromDb();\n if (count &gt; 0) {\n boolean isFinalPa...
{ "AcceptedAnswerId": "3065", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-22T18:43:29.830", "Id": "3064", "Score": "2", "Tags": [ "java" ], "Title": "Externalize to a function" }
3064
<p>I started working on a jQuery port for this <a href="http://www.dynamicdrive.com/dynamicindex16/formdependency.htm" rel="nofollow">Form Dependency Manager</a> script. It works fine, and I added a few extra options too.</p> <p>The problem is speed. If you create dependencies between 20+ form elements on a page you g...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-23T10:35:19.923", "Id": "4656", "Score": "0", "body": "Personally I don't like non-standard attributes. I'd prefer using `class`. At least you should use a HTML5 `data-` attribute." }, { "ContentLicense": "CC BY-SA 3.0", "C...
[ { "body": "<p>All the points below I started writing while looking over the code for the performance issue, but aren't related to it. To be honest after the first read over I can't see how one would do it differently to be faster. One would probably have to do some proper profiling. </p>\n\n<p>My best guess how...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-23T01:46:34.793", "Id": "3070", "Score": "2", "Tags": [ "javascript", "jquery", "performance", "form" ], "Title": "Form dependencies, slow javascript" }
3070
<p>What would your preferred loop type be for a case like this:</p> <pre><code>StringBuilder sb = new StringBuilder(); for(Integer id : idList) { sb.append("?,"); } </code></pre> <p>In short: In dependency to the size of a List i want to add stuff to a String. The above example produces a "unused variable" warnin...
[]
[ { "body": "<p>I would go with the first alternative and use <code>@SuppressWarnings</code>.</p>\n\n<p>If you need this pattern more often, how about an object oriented solution:</p>\n\n<pre><code>public static class Repeat&lt;T&gt; implements Iterable&lt;T&gt; {\n private final T[] ts;\n private final int...
{ "AcceptedAnswerId": "3076", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-23T09:19:49.533", "Id": "3073", "Score": "8", "Tags": [ "java" ], "Title": "Simplify a loop" }
3073
<p>I have a custom <code>PropertiesByValueComparer</code> and am fairly happy how it behaves for simple classes. I haven't included comparing by fields yet. Is there anything that is blatantly fail about this, or do you have other recommendations?</p> <pre><code>public class PropertiesByValueComparer&lt;T&gt; : IEqual...
[]
[ { "body": "<p>Some comments / suggestions:</p>\n\n<ul>\n<li>Make the <code>properties</code> / <code>fieldInfos</code> fields static; they don't change for each closed instance of the type PropertiesByValueComparer (i.e., for each T passed to it), so you don't need to initialize them for every new instance of t...
{ "AcceptedAnswerId": "3094", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-23T14:29:42.877", "Id": "3088", "Score": "9", "Tags": [ "c#" ], "Title": "Custom EqualityComparer using IEqualityComparer<> interface" }
3088
<pre><code>using System; using System.Web.UI.WebControls; namespace RideShare.Web { public partial class UserOrganization : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { try { if (!IsPostBack) { ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-07-11T18:23:15.163", "Id": "5099", "Score": "0", "body": "what does this code do Exceptions.CatchException(false, ex);" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-07-13T06:44:17.313", "Id": "5142", "S...
[ { "body": "<p>I'd recommend that you register your methods as event handlers. You have several handlers that merely call more descriptive methods, which clutters up the code a bit. In <code>Page_Load()</code>:</p>\n\n<pre><code>// Register event handlers\nbtn_Search.Click += new EventHandler(this.FilterGrid);\n...
{ "AcceptedAnswerId": null, "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-23T16:40:29.857", "Id": "3089", "Score": "2", "Tags": [ "c#", ".net", "asp.net" ], "Title": "Simple search page." }
3089
<p>This method runs in just under two minutes. I would like to optimize it to run in less than 15 seconds. Using a LAMDA filter on my list before iterating it's elements and removing one conditional statement in the method shaved off 30 seconds. Any ideas to improve performance?</p> <p>c# .net 4.0</p> <pre><code>[S...
[]
[ { "body": "<p>If you are writing this in Visual Studio 2010, it would be worth profiling your code to find out exactly what method calls take the longest.</p>\n\n<p>Here is a link where you can watch a video from Channel9 about using the built in performance analyser tool in Visual Studio 2010 to perform CPU Sa...
{ "AcceptedAnswerId": "3658", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-23T17:50:31.840", "Id": "3090", "Score": "3", "Tags": [ "c#", ".net" ], "Title": "How to improve execution of web service using System.DirectoryServies.AccountManagement that runs very...
3090
<p>Please critique my login and signup validation php files.. login.php;</p> <pre><code>&lt;?php session_start(); require("connect.php"); $email = $_POST['emaillogin']; $password = $_POST['passwordlogin']; $email = mysql_real_escape_string($email); $password = mysql_real_escape_string($password); if(empty($email)...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-25T15:05:54.697", "Id": "4729", "Score": "0", "body": "really,only improvement i can see on that is using PDO for communicating with db" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-29T21:00:57.333", ...
[ { "body": "<p>You should delimit your SQL field and table names because reserved words (e.g. <code>date</code>) can cause problems. Also I would use LIKE for something like an email address so it's not case-sensitive.</p>\n\n<pre><code>$query = \"SELECT `password`, `salt` FROM `users` WHERE `Email` LIKE '$email...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-24T00:51:57.207", "Id": "3093", "Score": "3", "Tags": [ "php", "mysql", "form" ], "Title": "Login and signup validation php critique" }
3093
<p>I have a big string resource (basically the "about" text of the application) which contains styles (such as <code>&lt;b&gt;</code>, <code>&lt;a&gt;</code> etc.). The string resource is written on multiple lines, like this:</p> <pre><code>&lt;string name="about_text"&gt;&lt;big&gt;&lt;b&gt;About&lt;/b&gt;&lt;/big&gt...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-24T14:17:02.010", "Id": "64498", "Score": "0", "body": "How about [assigning](http://developer.android.com/reference/android/widget/TextView.html#setTransformationMethod%28android.text.method.TransformationMethod%29) a [`SingleLineTran...
[ { "body": "<p>This should work:</p>\n\n<pre><code>String aboutText = getText(R.string.about_text).toString();\n\naboutText = aboutText.replace(\"\\n \", \"\\n\");\n</code></pre>\n\n<p><code>toString()</code> is there to convert to a <code>String</code> object.</p>\n", "comments": [ { "ContentL...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-24T12:25:31.607", "Id": "3099", "Score": "13", "Tags": [ "java", "strings", "html", "android" ], "Title": "Remove useless whitespace from styled string" }
3099
<p>I've written some Javascript code with jQuery to display a dialog box on a web page that "floats" in the corder of the page.</p> <p>(1) It has the following features: the dialog follows as the user scrolls the page.</p> <p>(2) If the user holds down the [Ctrl] key, the dialog is hidden so that it doesn't obscure c...
[]
[ { "body": "<p>You can combine your <code>css</code> calls:</p>\n\n<pre><code>this.jQueryObj.css({\n top: newModalTop, \n left: newModalLeft,\n height: this.height,\n width: this.width\n});\n</code></pre>\n\n<p>jQuery automatically inserts <code>px</code> when setting dimension properties.</p>\n", ...
{ "AcceptedAnswerId": "3108", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-24T15:30:42.173", "Id": "3103", "Score": "2", "Tags": [ "javascript", "jquery", "css" ], "Title": "Simple Javascript Widget without cluttering global namespace?" }
3103
<p>I've just released a jQuery plugin that conditionally displays elements based on form values. I would appreciate any suggestions on how to improve both the code and its usefulness.</p> <p><a href="http://natedavisolds.com/workshop/react.js/demo/react.html" rel="nofollow noreferrer">Here's the demo page</a></p> <ol...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-28T20:32:16.807", "Id": "4785", "Score": "0", "body": "looks nice! i would prefer to call it like this: $('.elements_to_display').reactIf( $(\"div\") , SatisfiesFirstCondition)\nif you can provide a jquery element directly, you can be ...
[ { "body": "<ul>\n<li><p>The syntax is nice, but the necessity for the user to declare <code>IS</code> themselves is not ideal. You should look for a different solution. One possibility could be to supply the name of the conditional function as a string and its arguments as additional arguments of <code>reactIf<...
{ "AcceptedAnswerId": "3178", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-24T19:16:45.580", "Id": "3104", "Score": "6", "Tags": [ "javascript", "jquery", "html", "form" ], "Title": "Plugin that conditionally displays elements based on form values" }
3104
<p>Okay, I'll try and keep this as short as I can. First, I need to keep various options available to the user:</p> <pre><code>if ($c_verb eq 'on') { if ($c_enabling) ##if need eq, add || '' at declaration. {$category_id = 'xcomp';} elsif ($c_subject) {$category_id = 'subj';} elsif ($c_...
[]
[ { "body": "<p>In order to provide meaningful help, I would need to know more about your application and what you are trying to accomplish. You are asking about if..else, but I suspect the real question/answer that you need is along the lines of: \"what data structure and approach is appropriate?\". There are a...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-25T03:44:36.363", "Id": "3110", "Score": "2", "Tags": [ "perl" ], "Title": "Ideas on shortening this if-elsif chain with embedded if-elsif" }
3110
<p>This has been tested and compiled under Visual Studio 2010. Are there any serious problems with this implementation?</p> <p>PS. This implementation is fully lambda expression based. If I can make <code>fixpoint::fix</code> a real member function it will be simpler than this.</p> <pre><code>//As decltype(variable):...
[]
[ { "body": "<p>I hav tried the same thing in G++ (version 4.5 from Ubuntu 11.04 original), and the result is quite impressing me. We now do have a lot more features to generise the solution. </p>\n\n<ol>\n<li><p>we can now support any number of parameters without modifying the code.</p></li>\n<li><p>the t2t clas...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-23T11:03:19.930", "Id": "3111", "Score": "6", "Tags": [ "c++", "c++11", "lambda" ], "Title": "Fixed point combinator in C++1x" }
3111
<p>I'm creating a class which uses a custom buffer. I want to offer the possibility to pass an external memory address (for higher interoperability between languages) or (for convenience) to specify a custom <code>allocator</code> type. The following code outlines what I mean:</p> <pre><code>template&lt;typename int_t...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-25T10:49:30.623", "Id": "4714", "Score": "0", "body": "Is this the entire code? Where is the base declaration of `uses_custom_buffers`? And is it an option to follow the STL allocator design?" }, { "ContentLicense": "CC BY-SA 3...
[ { "body": "<p>I think that in order to be a good review candidate, this should be more than an \"outline.\" Like, there should be an example of how you intend to use it.</p>\n\n<p>But here's some stylistic feedback:</p>\n\n<ul>\n<li><code>CamelCase</code> your template parameter names: <code>IntType</code> (or ...
{ "AcceptedAnswerId": null, "CommentCount": "13", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-25T10:37:51.790", "Id": "3112", "Score": "8", "Tags": [ "c++", "design-patterns", "memory-management" ], "Title": "Use of external memory or a custom allocator" }
3112
<p>So I have this array:</p> <pre><code>$arr = ('a' =&gt; 343, 'b' =&gt; 34, 'c' =&gt; 65, 'd' =&gt; 465); </code></pre> <p>which could also be</p> <pre><code>$arr = ('a' =&gt; 343, 'b' =&gt; 34, 'c' =&gt; 65); </code></pre> <p>Can the following code be improved into one line?</p> <pre><code>if(isset($arr['d'])) $...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-25T14:55:47.187", "Id": "4727", "Score": "1", "body": "What is your goal? To always remove elements called 'd'? Or to have a maximum of 3 key / values?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-25T14:...
[ { "body": "<pre><code>if(isset($arr['d'])) $something = $arr['d'];\nunset($arr['d']);\n</code></pre>\n\n<p>Well... If <code>arr['d']</code> is not set, then you don't need to unset it. So this will save an unnecessary call sometimes:</p>\n\n<pre><code>if(isset($arr['d']))\n{\n $something = $arr['d'];\n un...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-25T14:51:48.437", "Id": "3113", "Score": "7", "Tags": [ "php" ], "Title": "Fetching an array value and removing it" }
3113
<p>I want to be able to do <code>/contacts/Matt%20Phillips</code> and <code>/contacts/1</code> and have both of them return a contact. The way I did that was to try and parse an <code>int</code> from the captured parameter and call the <code>Id</code> method instead of the <code>byName</code> method like so:</p> <pre>...
[]
[ { "body": "<p>There is an easier way. You can use uri templates to help you by making both handling methods operations.</p>\n\n<pre><code>[ServiceContract]\npublic class ContactsApi\n{\n [WebGet(UriTemplate=\"{id}\")]\n public string GetById(int id)\n {\n //return by id\n }\n\n [WebGet(Uri...
{ "AcceptedAnswerId": "3118", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-26T05:32:22.517", "Id": "3117", "Score": "4", "Tags": [ "c#", ".net", "linq", "asp.net", "wcf" ], "Title": "Is this a good way to handle Web API UriTemplates?" }
3117
<p>Is this the best way to get access to the parent scope when dealing with complex objects literals?</p> <p>I find this a bit ugly, and obviously the best solution would never be involving calling it by name directly, but by saving the state of the previous scope. I tried it with <a href="https://developer.mozilla.or...
[]
[ { "body": "<p>I understand that you are just experimenting with closures, because your code should be a simple geter like that... </p>\n\n<pre><code>var object = {\n  name : 'foo',\n  getName : function(){ //closure\n return {\n a : 111,\n b : this.name, // variable th is avaliable ...
{ "AcceptedAnswerId": "3122", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-26T11:01:44.253", "Id": "3121", "Score": "3", "Tags": [ "javascript" ], "Title": "this scope for parent object within inner object" }
3121
<p>This is my first attempt to write a simple C++ program:</p> <pre><code>#include &lt;iostream&gt; #include &lt;cstring&gt; #include &lt;vector&gt; using namespace std; class Book { public: char title[30]; Book(char *tit) { strcpy(title,tit); }; char *gettitle() { return title;...
[]
[ { "body": "<p>If you're using C++ instead of C, you should use <code>std::string</code> instead of <code>char</code> arrays. Include <code>&lt;string&gt;</code>.</p>\n", "comments": [], "meta_data": { "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-26T1...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-26T16:26:57.240", "Id": "3123", "Score": "10", "Tags": [ "c++" ], "Title": "Critique my first C++ \"Hello World\" program" }
3123
<p>I need to write some JavaScript code that will take a JSON string, parse it, and return the names of the most-deeply nested properties. For example, for this input:</p> <pre><code>var json = "{\ foo: {\ bar: 'something',\ baz: {\ jack: 'other',\ },\ bob: {\ bill: 'hello',\ bilbo: 11,\ bag...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-08-26T03:29:38.427", "Id": "6599", "Score": "2", "body": "Technically that isn't valid JSON, the keys aren't strings since they don't have quotes around them." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-06-09...
[ { "body": "<p>I'd write it as a recursive descent parser since this is quite simple:</p>\n\n<p><a href=\"http://en.wikipedia.org/wiki/Recursive_descent_parser\" rel=\"nofollow\">http://en.wikipedia.org/wiki/Recursive_descent_parser</a></p>\n\n<p>Actually I already did this a couple of years back, when I wanted ...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2011-06-26T16:59:11.487", "Id": "3124", "Score": "6", "Tags": [ "javascript", "parsing", "json", "reinventing-the-wheel" ], "Title": "Parsing JSON with JavaScript" }
3124
<p>After realizing that I was spending a lot of time getting the latest version of Chromium, I figured I would throw together a quick script. Over time, I wanted to make the script more efficient, cleaner, and pythonic. Here is what I came up with:</p> <pre><code>from zipfile import ZipFile from os import rename, remo...
[]
[ { "body": "<p>I assume you are aware of Chrome Canary, which I gather is able to use binary deltas? I don't think it's pure Chromium though.</p>\n\n<p>Your code is pretty clean. You could be using argparse for parsing the command line, currently you are ignoring flags that don't match. You could wrap the exit c...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-26T19:32:27.297", "Id": "3127", "Score": "2", "Tags": [ "python" ], "Title": "Chromium Nightly Build Downloader" }
3127
<p>It's somewhat odd that Java's collection framework has no iterator for recursive data structures. Since I needed something like this, I wrote my own. First off, I need recursive elements:</p> <pre><code>public interface RecursiveElement&lt;T&gt; { public Iterator&lt;T&gt; getChildrenIterator(); } </code></pre>...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-04-16T17:39:56.750", "Id": "82999", "Score": "0", "body": "I don't think you can. Java's generics doesn't allow compound types such as `Iterator<T | RecursiveElement<T>>`." } ]
[ { "body": "<p>I don't think you can do anything about this. You have to cast here, and in the process you lose all information about the type parameter: The compiler can't know that if you have a <code>RecursiveElement</code>, it's always a <code>RecursiveElement&lt;T&gt;</code>, and \"thanks\" to type erasure ...
{ "AcceptedAnswerId": "3140", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-26T20:54:51.990", "Id": "3130", "Score": "11", "Tags": [ "java", "recursion", "casting", "iterator" ], "Title": "How can I avoid unchecked cast warning in my generic recursive ...
3130
<p>I often argue with the voices about the correctness of having assignments within an <code>if</code> statement (or equivalent), meaning having this:</p> <pre><code>if($thing = someFunction()){ //do stuff } </code></pre> <p>Instead of this:</p> <pre><code>$thing = someFunction(); if($thing){ //Do stuff } </co...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-07-17T00:43:38.027", "Id": "5221", "Score": "0", "body": "Belongs on Programmers.SE" } ]
[ { "body": "<p>I prefer the second way of doing it (not having it in the <code>if</code>-clause):</p>\n\n<blockquote>\n <p>The practice is not that uncommon (C/C++, PHP).</p>\n</blockquote>\n\n<p>There are a lot of bad practices out there. Just being common does not mean it is good.</p>\n\n<blockquote>\n <p>Th...
{ "AcceptedAnswerId": "3146", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-26T23:03:40.017", "Id": "3135", "Score": "5", "Tags": [ "php", "c++", "c" ], "Title": "Truthy assignments" }
3135
<p>From <a href="http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-24.html">SICP</a>:</p> <blockquote> <p>Exercise 3.64. Write a procedure stream-limit that takes as arguments a stream and a number (the tolerance). It should examine the stream until it finds two successive elements that differ in absol...
[]
[ { "body": "<p>Looks good. Is it OK to just say it looks good? If it's not, here are two comments:</p>\n\n<ul>\n<li>Why do you use <code>let*</code> here? Isn't <code>let</code> enough?</li>\n<li>You could define <code>stream-cadr</code>.</li>\n</ul>\n", "comments": [ { "ContentLicense": "CC BY...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-27T01:58:06.500", "Id": "3137", "Score": "7", "Tags": [ "lisp", "scheme", "sicp" ], "Title": "Write a procedure stream-limit that finds" }
3137
<p>I have a simple implementation for a LRU cache using <code>LinkedHashMap</code>. </p> <ul> <li>I want it to be as generic as possible. </li> <li>This is not for production use, just practice, so I don't care if its thoroughly robust as far as it is correct. However, I will welcome any comments, especially the one...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-27T17:25:44.067", "Id": "4748", "Score": "2", "body": "Instead of using a synchronized wrapper for the internal map you could synchronize all methods of LRU cache itself, as shown here: http://www.source-code.biz/snippets/java/6.htm" ...
[ { "body": "<p>First, use generics properly.</p>\n\n<p>Second, why do you track the cache size if when you need it, you get a hardcoded 99? I will assume that was some sort of mistake.</p>\n\n<p>Third, if you really want to annoy most truely professional java developers and course instructors (i.e, not these tha...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-27T02:50:54.250", "Id": "3138", "Score": "11", "Tags": [ "java", "cache", "collections" ], "Title": "LinkedHashMap as LRU cache" }
3138
<p>I have developed a test app that works by getting webpages source and processing it. I have up to 100k URLs in queue and want to use a maximum of 25 threads. Please help me check if the code is good or point out any faults you might find.</p> <pre><code>Public Class frmMain Public Delegate Sub AddItemDelegate(B...
[]
[ { "body": "<ul>\n<li><p>Relying on the max number of thread pool threads to cap the number of concurrent downloads feels ... wrong. It may also cause problems if another component needs a thread pool while all 25 are waiting for a response from web servers.</p>\n\n<p>(slight correction) Although you use semapho...
{ "AcceptedAnswerId": "3143", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-27T08:57:30.710", "Id": "3141", "Score": "5", "Tags": [ ".net", "multithreading", "vb.net" ], "Title": "Processing a webpage source" }
3141
<pre><code>var AgeConvertor = { Age: function (formattedDate) { var now = new Date(); var yearNow = now.getFullYear(); var monthNow = now.getMonth() + 1; var dayNow = now.getDate(); // Calculating in days var ONE_DAY = 1000 * 60 * 60 * 24; var ONE_MONTH = 1000 * 60 * 60 *...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-27T10:18:24.820", "Id": "4742", "Score": "1", "body": "Why is it an object? it only has one method and you never use `this`" } ]
[ { "body": "<ul>\n<li>You should check if <code>formattedDate</code> is actually a <code>Date</code> object before using it (and change the variable name, since it sounds like it contains a formatted string).</li>\n<li>It's strange, if not wrong, to consider months to be exactly <code>30</code> days. </li>\n<li>...
{ "AcceptedAnswerId": "3144", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-27T09:06:45.913", "Id": "3142", "Score": "5", "Tags": [ "javascript" ], "Title": "Age in days, months and years" }
3142
<p>I have a bunch of simple interfaces like this one (pretty enough formed, but not guarantee)</p> <pre><code>package com.example.sources; import com.google.gwt.resources.client.ClientBundle; import com.google.gwt.resources.client.ImageResource; import com.google.gwt.resources.client.ImageResource.ImageOptions; impor...
[]
[ { "body": "<p>Generally what you do is dangerous. More dangerous as you might expect. As soon as you have something odd like a line break in a package or import line, a double semicolon or multiple import statements in a line, the code will break. If your keywords (\"package\", \"import\", \"Generated\") are us...
{ "AcceptedAnswerId": "3152", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-27T18:47:48.863", "Id": "3147", "Score": "8", "Tags": [ "java", "parsing" ], "Title": "Parse Java source code" }
3147
<p>I have an experimental script that makes an animation of a <code>ul</code> list element background-position, when the list element is hovered. Is there another way to manage this task or just optimize this code? </p> <p>I want to make a menu that has elements with an animated background and have an idea about rotos...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-27T23:47:26.463", "Id": "4750", "Score": "2", "body": "since you already use a gif, you could use a animated gif on the hover. it would save you all this code and have the same visual effect." }, { "ContentLicense": "CC BY-SA 3...
[ { "body": "<p>First of all i mention again, that i would use a GIF animation to solve this and not a JS. Its a very suboptimal solution to a simple problem.</p>\n\n<p>Your code in the code block is missing two var declarations you have in you jsFiddle example.</p>\n\n<p>Here are the things i would change:</p>\n...
{ "AcceptedAnswerId": "3167", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-27T19:18:43.230", "Id": "3148", "Score": "3", "Tags": [ "javascript", "jquery", "animation" ], "Title": "Making a ul list element animation on hover" }
3148
<pre><code>;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (defun read-sim-file (filename) "Reads file. File is presumed to be the output from a simulation. Returns lines from the simulation as a list of strings We throw an error if TRAP ET is detected. Lines with DBG_INT are ignored." (let ((file-text-list (split "\\n" ...
[]
[ { "body": "<p>At first glance, you're looking for <code>loop</code>s <code>collect</code> clause.</p>\n\n<pre><code>(defun read-sim-file (filename)\n (let ((file-text-list (split \"\\\\n\" (batteries:read-text-file filename))))\n (loop for line in file-text-list \n when (scan \"TRAP ET\" line)\n ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-27T22:19:23.417", "Id": "3151", "Score": "3", "Tags": [ "common-lisp" ], "Title": "Critique & improve a file reading routine" }
3151