body
stringlengths
25
86.7k
comments
list
answers
list
meta_data
dict
question_id
stringlengths
1
6
<p>I'm trying to write a piece of code that will mimic ASCII keyboard output. It uses the keyboard library from <a href="http://www.pjrc.com/teensy/usb_keyboard.html" rel="nofollow">pjrc</a>, but the application I'm working on requires outputting string sequences rather than individual keys (the <a href="http://www.pjr...
[]
[ { "body": "<p>Don't subtract absolute values:</p>\n\n<pre><code> if (c &gt;= 'a' &amp;&amp; c &lt;= 'z') return c - 93;\n</code></pre>\n\n<p>It makes it hard to understand what you are doing when you subtract integer literals from character codes. I would normally expect some form of value that conveys some ...
{ "AcceptedAnswerId": "6805", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-13T17:34:14.433", "Id": "6796", "Score": "3", "Tags": [ "c", "strings" ], "Title": "Keyboard Printing with Teensy" }
6796
<p>I really need some help removing some duplicated code. I've linked the methods causing me issues. <a href="http://pastebin.com/cZJihM4J" rel="nofollow">http://pastebin.com/cZJihM4J</a></p> <p>As you can see each method does similar things but retrieve different values. i.e one method to insert a string at a certain...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-13T16:53:09.967", "Id": "10646", "Score": "2", "body": "Globals are never the best way to approach anything." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-13T17:23:20.280", "Id": "10647", "Score":...
[ { "body": "<p>In the spirit of 'clean code', you should strive to make your methods as short as possible, and they should do only one thing.</p>\n\n<p>To start with, the following is a candidate for extracting into its own method</p>\n\n<pre><code> int nextLineStart = text.indexOf(NEW_LINE, start + NEW_LINE.l...
{ "AcceptedAnswerId": "6801", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-13T16:50:13.820", "Id": "6797", "Score": "4", "Tags": [ "java" ], "Title": "Struggling to refactor code to remove duplication" }
6797
<p>I was wondering if someone could give some tips as to how improve long strings of if-else statements and redundant if statements. For example, how should I optimize this if statement so it would be more re-usable for maintenance purposes:</p> <pre><code> if (($game == 'DS' &amp;&amp; $eventId == 185) || ($game ==...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-13T02:23:07.533", "Id": "10654", "Score": "3", "body": "You could pair the `$game` and `$eventId` variables together as array members and then do a `if (in_array($game.$eventId, $matches)) blah...`." }, { "ContentLicense": "CC ...
[ { "body": "<p>I would use the most laziest option possible. Use some string concatenation and a comparison list, as you only need to compare pairs anyway:</p>\n\n<pre><code>if (in_array(\"$game,$eventId\", array(\"DS,185\", \"MT,333\", \"HK,51\", \"main,1166\", \"WT,97\"))) {\n</code></pre>\n\n<p>See <a href=\"...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-13T02:20:20.727", "Id": "6802", "Score": "-2", "Tags": [ "php" ], "Title": "Matching pairs of game and event ID" }
6802
<p>Looking for the best way to do this. Currently in 4 different classes I have:</p> <pre><code>textArea = new JTextArea(10, 55) { { setOpaque(false); } @Override protected void paintComponent(Graphics g) { for (int i = 0; i &lt; list.size(); i++) { if(i == lineIndex) ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-14T00:37:32.467", "Id": "10672", "Score": "0", "body": "Might help to have a little bit more of the code, but at the moment I don't see any reason you need to pass the list in (unless it changes size... with is problematic). Why not p...
[ { "body": "<p>Write your own class:</p>\n\n<pre><code>class MyTextArea extends JTextArea{\n\n private final List&lt;Foo&gt; list;\n\n MyTextArea(int row, int col, List&lt;Foo&gt; list) {\n super(row, col); \n this.list = list;\n setOpaque(false);\n }\n\n @Override\n protected...
{ "AcceptedAnswerId": "6836", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-13T20:37:24.817", "Id": "6806", "Score": "7", "Tags": [ "java", "swing" ], "Title": "Refactoring code duplication so the same textArea is not used in 4 different classes" }
6806
<p>I have a function that moves circles out of the way of an expanding circle. It moves them along a ray from the center of the expanding circle through the center of the circle to move. This allows all surrounding circles to move without overlapping.</p> <p>Here's a diagram to better explain this:</p> <p><img src="h...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-14T00:56:12.763", "Id": "10674", "Score": "0", "body": "`a = Math.abs(` is why you have to check. Are you sure you need absolute values?" } ]
[ { "body": "<p>I had two thoughts. One was ... You really only need an angle and a distance. The distance is the amount you expand and the angle can be derived from the x/y coordinates.</p>\n\n<p><a href=\"http://jsfiddle.net/uLu7v/38/\" rel=\"nofollow\">http://jsfiddle.net/uLu7v/38/</a></p>\n\n<p>first you calc...
{ "AcceptedAnswerId": "6817", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-13T21:25:47.683", "Id": "6807", "Score": "3", "Tags": [ "javascript", "jquery", "computational-geometry" ], "Title": "Moving circles along a ray to eliminate location check" }
6807
<p>As of now, I am using this code to open a file and read it into a list and parse that list into a <code>string[]</code>:</p> <pre><code>string CP4DataBase = "C:\\Program\\Line Balancer\\FUJI DB\\KTS\\KTS - CP4 - Part Data Base.txt"; CP4DataBaseRTB.LoadFile(CP4DataBase, RichTextBoxStreamType.PlainText); string[] spl...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-14T14:31:27.063", "Id": "13410", "Score": "0", "body": "What are you trying to accomplish? Perhaps you are trying to replace one type of newlines with another? Or perhaps you want to read a text file into some more useful format (like ...
[ { "body": "<p>If i read this correctly you are reading in some text with newline characters, Splitting on new line characters, adding new line characters back in and then concatenation the lines back together?</p>\n\n<p>why not instead:</p>\n\n<pre><code>CP4DataBaseRTB.Text.Replace('\\n', Environment.NewLine);\...
{ "AcceptedAnswerId": "6819", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-13T21:29:11.037", "Id": "6808", "Score": "2", "Tags": [ "c#", "parsing" ], "Title": "Speedily Read and Parse Data" }
6808
<p>I've not written many shell scripts and cobbled this together from examples. The 'if' condition should check if this is already running and quite if so. The 'wget' call should trigger the php page and write any output to a txt file. The script will be launched by cron. Is this a reasonable approach?</p> <pre><code>...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-14T21:29:28.870", "Id": "10717", "Score": "1", "body": "You might do better to look into `pidof` or `psgrep` rather than parsing the output of `ps`, to avoid potential false positives … ?" } ]
[ { "body": "<p>You should protect the URL with quotation marks since <code>&amp;</code> is a control operator:</p>\n\n<pre><code>wget -q -O /tmp/out.txt \"http://dev.mydomain.biz/system_processdata.php?a=37&amp;b=61\"\n</code></pre>\n\n<p>Furthermore, prevent concurrent calls on the server (PHP) side, it should ...
{ "AcceptedAnswerId": "6857", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-13T22:37:29.367", "Id": "6810", "Score": "2", "Tags": [ "php", "bash", "shell" ], "Title": "Shell script: is it doing what I think it's doing" }
6810
<p>Having been through hundreds of often-conflicting posts on testing with <em>RSpec</em>, <em>Capybara</em>, <em>FactoryGirl</em>, <em>Spork</em>, <em>Guard</em> and <em>Devise</em> without Cucumber, this is the spec_helper which "seems to" work.</p> <p>I'm bracing for it to blow up or not work like the previous atte...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-06T20:44:53.243", "Id": "225743", "Score": "1", "body": "A lot of this seems unnecessary. Many portions of this are done in the background, by the various libraries. Here's what mine looks like: https://gist.github.com/1409074#file_spe...
[]
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-13T13:53:48.643", "Id": "6812", "Score": "7", "Tags": [ "ruby", "ruby-on-rails", "rspec" ], "Title": "spec_helper.rb for RSpec, Capybara, FactoryGirl, Spork and Devise" }
6812
<p>Here is a small script I wrote to get the HNews ask section and display them without using a web browser. I'm just looking for feedback on how to improve my style/coding logic/overall code.</p> <pre><code>#!/usr/bin/python '''This script gets the headlines from hacker news ask section''' import urllib2 import HT...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-14T00:53:22.533", "Id": "10673", "Score": "0", "body": "You'll almost definitely get someone who points out that your indenting is incorrect ... wait that was me! Just check the preview before you submit it so that the code section loo...
[ { "body": "<p>This is how I would modify your script. Comments are inline. This version is PEP8-PyLint-PyFlakes approved. ;-)</p>\n\n<pre><code>#!/usr/bin/python\n\n'''This script gets the headlines from hacker news ask section'''\n\nimport urllib2\nimport HTMLParser\n# remove unused imports\n\n\nclass HNParser...
{ "AcceptedAnswerId": "7085", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-13T23:41:06.660", "Id": "6813", "Score": "2", "Tags": [ "python", "web-scraping" ], "Title": "HNews \"ask section\" page scraping Python script" }
6813
<p>I have a piece of code that get errors from form and display to view:</p> <pre><code>$errors = $form-&gt;getMessages(); $msg = ''; foreach ($errors as $error) { foreach ($error as $err) { $msg .= $err . '&lt;br/&gt;'; } } $this-&gt;view-&gt;error_message = $msg; </code></pre> <p>It look so ugly...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-14T17:32:53.840", "Id": "10709", "Score": "1", "body": "No way to use less foreach loop and get it cleaner." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-15T00:56:00.303", "Id": "10725", "Score": ...
[ { "body": "<p>Im assuming your $errors array looks like this:</p>\n\n<pre><code>$errors = array(array('message 1'), array('message 2'), array('message 3'));\n</code></pre>\n\n<p>Then you could use something like this:</p>\n\n<pre><code>$msg = '';\nforeach($errors as $inner) {\n $msg .= current($inner) . '&lt...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-14T03:30:37.367", "Id": "6818", "Score": "2", "Tags": [ "php", "error-handling", "form", "zend-framework" ], "Title": "Collecting form errors to be displayed" }
6818
<p>This code will be used to map a set of unique keys to a container of objects that are unique to that key. I would like to be able to reuse this code in future projects hence the template, and not hard coding the types into the class. You can also access the code <a href="http://matthewh.me/scripts/browser/c++/c++_i...
[]
[ { "body": "<p>For one thing, you have operators <code>&lt;&lt;</code> and <code>&gt;&gt;</code> reversed for the streams.</p>\n\n<p>I wouldn't recommend overloading ifstream operator, at least not like this. <code>operator&gt;&gt;</code> does not normally open and close files, it reads a value from an already o...
{ "AcceptedAnswerId": "6844", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-14T07:35:57.297", "Id": "6821", "Score": "2", "Tags": [ "c++", "hash-map" ], "Title": "File to map class" }
6821
<p>This is a follow-on from a previous question I posted <a href="https://stackoverflow.com/questions/8403069/looking-to-select-an-undetermined-number-of-rows-in-excel-as-part-of-larger-vba">here</a>.</p> <p>I've got code here that works for what I want, but the problem is the loop takes ages to perform. I was wonderi...
[]
[ { "body": "<p>You should <strong>clean up every <code>Select</code> and <code>Activate</code></strong> and use <strong>objects</strong> instead</p>\n\n<p>You'd better use the <strong>object model</strong> of VBA.<br>\nFor instance, if you only want to copy the <em>value</em> of a cell:</p>\n\n<p><strong>Don't d...
{ "AcceptedAnswerId": "6833", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-14T09:59:35.497", "Id": "6823", "Score": "8", "Tags": [ "vba", "excel" ], "Title": "Managing book of Excel sheets" }
6823
<p>Because I needed to execute some actions one by one in seperate thread (not to block GUI) and I couldn't use <code>Task.ContinueWith</code> from .NET 4.0 I decided to write it by myself.</p> <p>Here is how it evolved thanks to your suggestions.</p> <pre><code>public class ActionQueue { private Thread _thread; ...
[]
[ { "body": "<p>Since the class itself does very little (runs a bunch of methods on a separate thread), there is little justification in using it, IMHO.</p>\n\n<p>This statement would basically do the same thing (on a <code>ThreadPool</code>, that is):</p>\n\n<pre><code>ThreadPool.QueueUserWorkItem(s =&gt;\n{\n ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-14T11:19:43.390", "Id": "6826", "Score": "4", "Tags": [ "c#", ".net", "multithreading" ], "Title": "Action queue in .NET 3.5" }
6826
<p>Is there a cleaner way of checking a dataset for tables/rows before attempting to read them?</p> <pre><code>If ds.Tables.Count &gt; 0 Then If ds.Tables(0).Rows.Count &gt; 0 Then 'do something with the the rows at this point End If End If </code></pre> <p>Edit to clarify - I am talking specificall...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-15T10:12:47.210", "Id": "10744", "Score": "1", "body": "Please define: `Check`? Do you want to check for the existence of columns or that a value was returned?" } ]
[ { "body": "<p>I'm doing a couple of assumptions here, but I hope I'm on target.</p>\n\n<p>If you just want the first column of the first row, you should use SqlCommand.ExecuteScalar instead of reading it into a dataset.</p>\n\n<p>For instance:</p>\n\n<pre><code>using (var cn = new SqlConnection(\"...\"))\n{\n ...
{ "AcceptedAnswerId": "7348", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-14T15:57:00.387", "Id": "6841", "Score": "3", "Tags": [ ".net", "vb.net" ], "Title": "Checking datasets for tables and rows" }
6841
<p>This is related to <a href="https://stackoverflow.com/questions/8476346/java-reading-xml-configuration-and-applying-to-an-object-whats-a-lightweight">a question I posted on Stack Overflow</a>. The consensus was to use JAXB, which is what I did.</p> <p>One of the requirements was that it needed to work with legacy ...
[]
[ { "body": "<p>Two things which are good to know about JAXB:</p>\n\n<ul>\n<li>You can annotate private methods and fields, JAXB can call/modify them. It could help hiding internal data structure from clients.</li>\n<li><a href=\"http://docs.oracle.com/javase/6/docs/api/javax/xml/bind/Marshaller.html#marshalEvent...
{ "AcceptedAnswerId": "6918", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-14T18:11:29.293", "Id": "6845", "Score": "4", "Tags": [ "java", "xml", "jaxb", "configuration" ], "Title": "Reusable configuration reader for Java" }
6845
<p>I'm using the Amazon S3 Java SDK to fetch a list of files in a (simulated) sub-folder. This code is rather standard (<code>AWSConfiguration</code> is a class that contains a bunch of account specific values):</p> <pre><code>String prefix = "/images/cars/"; int prefix_size = prefix.length(); AmazonS3 s3 = new Amazo...
[]
[ { "body": "<p>In the <a href=\"http://docs.amazonwebservices.com/AWSJavaSDK/latest/javadoc/com/amazonaws/services/s3/model/ListObjectsRequest.html\"><code>ListObjectsRequest</code> javadoc</a> there is a method called <code>withDelimiter(String delimiter)</code>. Adding <code>.withDelimiter(\"/\")</code> after...
{ "AcceptedAnswerId": "6850", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-14T19:14:05.353", "Id": "6847", "Score": "21", "Tags": [ "java", "amazon-s3" ], "Title": "List objects in a Amazon S3 folder without also listing objects in sub folders" }
6847
<p>I didn't know this site existed before now... awesome!</p> <p>I just made a thread here: <a href="https://stackoverflow.com/questions/8511620/c-palindrome-finder-optimization">https://stackoverflow.com/questions/8511620/c-palindrome-finder-optimization</a> </p> <pre><code>#include &lt;iostream&gt; #include &lt;os...
[]
[ { "body": "<h3>Reading a file:</h3>\n\n<pre><code>while(fin){ \n\n fin &gt;&gt; str; \n sWords.push_back(str); \n if(!fin){ \n break; \n } \n</code></pre>\n\n<p>You push the value str before checking it worked. It should be:</p>\n\n<pre><code>while(fin)\n{ \n fin &gt;&gt; str; \n if(!fi...
{ "AcceptedAnswerId": "6851", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-14T21:29:38.887", "Id": "6849", "Score": "4", "Tags": [ "c++" ], "Title": "Cross-post from SO- Palindrome finding function" }
6849
<p><strong>Magnus Lie Hetland</strong> in his <strong>Beginning python</strong> wrote a code to replicate the range() built-in.</p> <pre><code>def interval(start, stop=None, step=1): if stop is None: start, stop = 0, start result = [] i = start while i &lt; stop: result.append(i) ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-15T08:55:33.557", "Id": "10740", "Score": "0", "body": "You got **Magnus Lie Hetland**'s version slightly wrong. The line that reads `i = start` is indented one level too far." } ]
[ { "body": "<p>I think your code is more straightforward, but its size is a bit daunting. I actually like the original better. The only real 'trick' it uses is multiple assignment. And while it requires you to think through the different cases of <code>range</code> a bit to realize it works, this isn't something...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-15T05:59:50.693", "Id": "6858", "Score": "3", "Tags": [ "python", "c" ], "Title": "Thinking in python" }
6858
<p>The script takes a string such as this: <code>(15, 176) (65, 97) (72, 43) (102, 6) (191, 189) (90, 163) (44, 168) (39, 47) (123, 37)</code> and breaks it into an array of arrays. It then computes the largest possible number of choices, with the guideline that each selected array has to have both numbers smaller than...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-18T22:01:06.880", "Id": "10888", "Score": "0", "body": "On my machine, the first code takes 10.776s while the second one takes 0.005s. That's 2000x faster !" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-1...
[ { "body": "<p>So, you are generating every possible permutations of the array, which is a O(n!) operation. This is huge.</p>\n\n<p>I think this can be done with an O(n²) algorithm. I would do :</p>\n\n<ul>\n<li>create an array containing the pairs, ordered by the first value</li>\n<li>create another one contain...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-15T06:45:04.980", "Id": "6861", "Score": "5", "Tags": [ "optimization", "ruby" ], "Title": "This script works but keeps timing out with longer inputs. How can I improve its speed? [Ruby]...
6861
<p>I took the Python class at Google code today, and this is what I made for the problem about building a word counter.</p> <p>Please take a look and suggest any improvements that can be done. Please do point out the bad practices if I have used any.</p> <pre><code>import sys def make_dict(filename): """returns...
[]
[ { "body": "<p>I like the way you've broken down the code into functions, I think it makes sense and avoids repetition or duplication of code and functionality.</p>\n\n<p>One slight improvement to consider here is to have <code>print_words</code> and <code>print_top</code> take the dictionary returned from <code...
{ "AcceptedAnswerId": "6865", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-15T12:41:18.810", "Id": "6863", "Score": "6", "Tags": [ "python", "optimization", "programming-challenge" ], "Title": "Optimizing word counter" }
6863
<p>I am writing some code to turn a multi level UL into an accordion:</p> <pre><code>$(document).ready(function () { $('.s4-ql li ul').each(function (index) { $(this).hide(); }); $('.s4-ql ul li ul').each(function (index) { var length = 0; length = $(this).children().length; var CurrentItem = $(this)...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-15T15:13:58.033", "Id": "10752", "Score": "1", "body": "Also, speaking of \"trimming the fat\", please don't write tags in titles and signatures in questions." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12...
[ { "body": "<p>All jQuery mutation methods operate on every element in the set.<br>\nYou can just write <code>$('.s4-ql li ul').hide()</code>; you don't need <code>.each</code>.</p>\n\n<p>Also, you should just write <code>var length = $(this).children().length;</code> in one line.</p>\n", "comments": [], ...
{ "AcceptedAnswerId": "6871", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-15T15:10:27.593", "Id": "6869", "Score": "4", "Tags": [ "javascript", "jquery" ], "Title": "Making an accordion from a multi-level HTML list" }
6869
<p>How I can change this multi-loop to reduce the computation time?</p> <p><code>A</code> is a matrix (5 × 10000) where the fifth line contains values between 1 and 50 corresponding to different events of an experiment. My goal is to find the columns of the matrix which are the same for all possible combinations of 7 ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-14T22:19:27.847", "Id": "10776", "Score": "0", "body": "I'm not sure I understand your problem clearly - does the 5th row of `A` contain a cell for each column, each with 7 values (1-50) in it?" }, { "ContentLicense": "CC BY-SA...
[ { "body": "<p>There's quite a few things that you can do to reduce computation time.</p>\n\n<p>First of all, if you know that an outcome has to be the combination of seven events, you can throw out whatever has fewer of them.</p>\n\n<p>Then, you can preassign the output array (growing in a loop is usually not v...
{ "AcceptedAnswerId": "6879", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-14T21:46:35.777", "Id": "6878", "Score": "0", "Tags": [ "performance", "algorithm", "matrix", "combinatorics", "matlab" ], "Title": "Finding columns of a matrix that are th...
6878
<p>I have a pan control that look like this:</p> <p><img src="https://i.stack.imgur.com/n8lif.png" alt="pan control"></p> <p>Pretty standard Google Mapsish controls, IMO.</p> <p>When the user clicks in the top 3rd of the control, it should pan up (deltaY = +1); right third means it should pan east (deltaX = -1); Dow...
[]
[ { "body": "<p>Well, if you want less repetition, you can do this.\nBut I don't think there's anything wrong with your\napproach (which is more efficient incidentally).</p>\n\n<pre><code>var pan = function(clickx, clicky){\n var delta = function(val){\n return val &lt; 16 ? 1 :\n val &gt;...
{ "AcceptedAnswerId": "6908", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-15T19:47:07.767", "Id": "6883", "Score": "3", "Tags": [ "javascript", "functional-programming", "user-interface" ], "Title": "Handler for a control to pan a map in four directions"...
6883
<p>Are there issues of any kind with this extension method?</p> <pre><code>using System; using System.Web; namespace AccountingBackupWeb.CacheExtensions { public static class Extensions { public static T Get&lt;T&gt;(this System.Web.Caching.Cache cache, string key, Func&lt;T&gt; f) where T : class ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-15T21:25:03.920", "Id": "10788", "Score": "3", "body": "Why do you have `cache` as the first parameter when you don't use it in the method at all?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-15T22:07:21...
[ { "body": "<p>Without some more context on what your goals and/or concerns are its hard to say. This seem ok, although passing delegate functions is relatively expensive so if hyper-performance is required, you should refactor that. Aside from that, the only issue may be <code>HttpContext.Current</code> being n...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-15T20:36:15.490", "Id": "6885", "Score": "6", "Tags": [ "c#" ], "Title": "Extension method to get results of type T from a cache" }
6885
<p><strong>Background information</strong></p> <p>I am building a web application that consumes 3 different WCF services that are hosted internally.</p> <p>Each response object from the service inherits from a base class <code>ResponseBase</code>. This class contains properties <code>int ErrorCode</code> and <code>st...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-16T05:42:36.303", "Id": "96131", "Score": "0", "body": "Well, some things cannot be done right and easy at the same time :)\nI recommend you reading [that article](http://code-magazine.com/Article.aspx?quickid=0809101). It won't make y...
[ { "body": "<p>Peter - a couple of observations:</p>\n\n<ol>\n<li>Since you say \"Each response object from the service inherits from a base class ResponseBase\" the gut reaction is to just use ResponseBase and let the inheritance model in C# handle everything. As you go on to explain, however, ResponseBase is n...
{ "AcceptedAnswerId": "7768", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-06-01T08:49:20.357", "Id": "6886", "Score": "2", "Tags": [ "c#", "wcf" ], "Title": "WCF general response validation for multiple services" }
6886
<p>I'm writing a custom JavaScript converter to deserialize some JSON. Here's a few lines I'm writing:</p> <pre><code>public override object Deserialize(IDictionary&lt;string, object&gt; dictionary, Type type, JavaScriptSerializer serializer) { int NoteID; NotesModel TheObject = new NotesModel(); ...
[]
[ { "body": "<p>you can do </p>\n\n<pre><code>TheObject.NoteID = NoteID;\n</code></pre>\n", "comments": [], "meta_data": { "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-15T21:06:27.727", "Id": "6888", "ParentId": "6887", "Score": "7" ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-15T21:03:05.490", "Id": "6887", "Score": "4", "Tags": [ "c#", "converting", "serialization" ], "Title": "Converter for deserializing JSON" }
6887
<p>I'm working on a function that extracts information from an XML document and compares to what the user has typed in. Can you suggest any ways in which I can improve it? The variables in the XML file are compared against txtSearch.</p> <pre><code>function checkXML() { var s = ""; var albumPages = []; fo...
[]
[ { "body": "<p>I'd create a local variable for <code>albumPages[i]</code> in the second for loop:</p>\n\n<pre><code>for (var i = 0; i &lt; albumPages.length; i++) {\n var albumPage = albumPages[i];\n var searchArtist = albumPage.substring(0, albumPage.indexOf(\":\"));\n ...\n}\n</code></pre>\n\n<p>It wo...
{ "AcceptedAnswerId": "6899", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-15T23:17:54.850", "Id": "6894", "Score": "3", "Tags": [ "javascript", "xml" ], "Title": "Improving search through XML file" }
6894
<p>I am building a web app that needs to access various tables in a given MySQL db. To do that, I have created a generic class, see <code>DAO_DBRecord.php</code> below, and I create children classes for each table I want to access, e.g., <code>DAO_User.php</code> is used to access the <code>users</code> table. The on...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-16T02:18:29.593", "Id": "10799", "Score": "0", "body": "Why not something like http://stackoverflow.com/a/368990/567663 ?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-01-03T22:12:20.443", "Id": "11660",...
[ { "body": "<p><del>If the only difference between subclasses of <code>DAO_DBRecord</code> is the table name I wouldn't use subclasses. I'd just pass the table name to to the constructor of <code>DAO_DBRecord</code> and use different instances for different tables.</del></p>\n\n<p>If the only difference between ...
{ "AcceptedAnswerId": "6901", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-15T23:51:30.800", "Id": "6895", "Score": "2", "Tags": [ "php", "object-oriented", "pdo" ], "Title": "PHP DAO classes inherit from a generic DAO classes and only change the table na...
6895
<p>I am quite new to JavaScript and I wonder if you experts can see any obvious mistakes in this working code, and if any, suggest good improvements.</p> <pre><code>// add iframes to page var normal_sortables = document.getElementById('normal-sortables'); normal_sortables.innerHTML = normal_sortables.innerHTML + '&lt;...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-16T10:20:23.183", "Id": "10810", "Score": "0", "body": "Hope you are also aware of jslint site which is good for syntactical checking." } ]
[ { "body": "<p>If you wanted to retain any event handlers that were already attached to your elements, you could change the first piece of code like this an avoid one of the dangers of setting innerHTML on an element that already has a bunch of HTML in it:</p>\n\n<pre><code>// add iframes to page\nvar normal_sor...
{ "AcceptedAnswerId": "6904", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-16T01:52:32.090", "Id": "6903", "Score": "5", "Tags": [ "javascript", "beginner", "event-handling", "dom" ], "Title": "Altering contents when loading iframes" }
6903
<p>I have tried using jQuery to create an alternative of marquee, and got no success. It flickers and does not stop on hover. I edited and edited again and it finally came out with a jQuery + JavaScript mess.</p> <p>JavaScript:</p> <pre><code>$(document).ready(function(){ marquee(); var timeout=1; ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-27T17:57:27.740", "Id": "11219", "Score": "1", "body": "I wouldn't recommend to put a marquee on a page unless you want to make harder for the user to notice your whole page and not just the marquee, also some users find marquees annoy...
[ { "body": "<p>A few points:</p>\n\n<ul>\n<li><code>$(this).html('')</code> will throw away the contents of <code>#div1</code> (on the first iteration) and <code>#div2</code> (on the second iteration). If you want the marquee to loop, that's not going to work.</li>\n<li>This is a perfect use case for a simple jQ...
{ "AcceptedAnswerId": "7183", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-15T06:08:04.763", "Id": "6905", "Score": "2", "Tags": [ "javascript", "jquery" ], "Title": "jQuery marquee, without flickering, less memory consumption, and no plugin" }
6905
<p>I have this method for searching a DB based on filters I was wondering if anyone thought as I do that this code is excessive, and secondly if you have any suggestions to shorten the code.</p> <pre><code>private const string NO_FILTER = "No filter"; [DataObjectMethod(DataObjectMethodType.Select)] public static List...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-17T09:55:18.660", "Id": "10840", "Score": "0", "body": "Although I've not tried this with these specific constructs, you may want to look into Compilable Linq Expressions. These would be defined, build, and compiled in your constructor...
[ { "body": "<p>I'd try creating a query builder class which stores the join statements and where conditions and later build the whole query from the stored statements. A sample pseudocode:</p>\n\n<pre><code>public class QueryBuilder {\n List&lt;String&gt; joins;\n List&lt;String&gt; whereConditions;\n\n ...
{ "AcceptedAnswerId": "6919", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-16T11:15:58.327", "Id": "6913", "Score": "3", "Tags": [ "c#", "linq" ], "Title": "Search with filters code" }
6913
<p>We're storing the xml communications with an external service in a text in the db and in a <code>before_create</code> I've got the following:</p> <pre><code> # filter opera password def remove_password! self.request.gsub! /UserPassword\&gt;[^\&lt;]*\&lt;\//, 'UserPassword&gt;[FILTERE...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-17T23:04:59.343", "Id": "10854", "Score": "0", "body": "Is the XML always the same schema? Can it be validated with a Schema or DTD?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-18T17:05:42.907", "Id...
[ { "body": "<p>That depends on how confident you are that neither of these cases will be true:</p>\n\n<ul>\n<li>Another tag like will be introduced that you will want to leave unfiltered</li>\n<li>No nested tags will appear within the tag</li>\n</ul>\n\n<p>An example of the last would be:</p>\n\n<pre><code>&lt;...
{ "AcceptedAnswerId": "6935", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-16T11:19:01.370", "Id": "6914", "Score": "4", "Tags": [ "ruby", "regex", "xml" ], "Title": "filter out password in xml string" }
6914
<p>I have written some JavaScript code with jQuery to create collapsible webparts in SharePoint 2010. </p> <p>Can someone suggest some improvements? As I think that the methods I am using for selectors are not ideal. The solution works perfectly as it is, I just want to ensure that I am being as efficient as possibl...
[]
[ { "body": "<pre><code>$('.s4-wpTopTable').find('tr:first h3')...\n</code></pre>\n\n<p>is the same as </p>\n\n<pre><code>$('.s4-wpTopTable tr:first h3')...\n</code></pre>\n\n<p>Only one hit for jQueury goodness instead of two.<br>\nalso you're attaching the click handler after putting it into the DOM. You can do...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-16T14:52:43.547", "Id": "6920", "Score": "4", "Tags": [ "javascript", "jquery" ], "Title": "Can this code be improved? jQuery with SharePoint" }
6920
<p>I was hoping I might get some of the brains in Stack Overflow to take a look at my Python static blogger application. I've been using it a few years in a pretty hacked up form. Lately I decided to clean it up and put it up on Github. I'd love some smarter Python programmers to give me advice and wisdom into ways to ...
[]
[ { "body": "<p>Here are a few suggestions:</p>\n\n<p>String comparisons should be done with <code>==</code> (and <code>!=</code>) instead of <code>is</code> (and <code>is not</code>). <code>is</code> works, but implies you are comparing identity (which is usually a memory address), whereas <code>==</code> is co...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-16T16:39:17.887", "Id": "6923", "Score": "11", "Tags": [ "python", "security", "markdown" ], "Title": "Markdown static blogger program" }
6923
<p>Which version of this code is better?</p> <p>Ver 1.</p> <pre><code>a = 0 for i in xrange( 1000 ): if i % 3 == 0 or i % 5 == 0: a += i print a </code></pre> <p>Ver 2.</p> <pre><code>from operator import add print reduce( add, ( i for i in xrange( 1000 ) if i % 3 == 0 or i...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-16T22:26:40.117", "Id": "10824", "Score": "1", "body": "Version 3: Use the `sum()` function with the generator used in version 2." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-18T01:11:49.140", "Id": ...
[ { "body": "<p>The second version can (and should) be written using <code>sum</code> instead of <code>reduce(add,...)</code>, which is somewhat more readable:</p>\n\n<pre><code>sum(i for i in xrange( 1000 ) if i % 3 == 0 or i % 5 == 0)\n</code></pre>\n\n<p>That is the version that I'd prefer as far as implementa...
{ "AcceptedAnswerId": "6928", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-16T22:19:33.193", "Id": "6927", "Score": "7", "Tags": [ "python" ], "Title": "What is better? For-loops or generator expressions (in cases like this)" }
6927
<p>From <a href="http://perldoc.perl.org/perl.html" rel="nofollow">the Perl documentation</a>:</p> <blockquote> <p><a href="http://www.perl.org" rel="nofollow">Perl</a> is a language optimized for scanning arbitrary text files, extracting information from those text files, and printing reports ...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-17T00:04:50.900", "Id": "6932", "Score": "0", "Tags": null, "Title": null }
6932
Perl is a language optimized for scanning arbitrary text files, extracting information from those text files, and printing reports.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-17T00:04:50.900", "Id": "6933", "Score": "0", "Tags": null, "Title": null }
6933
<p>So today I jumbled together a script that would get data from a database, from different tables and such. I had wanted to just use simple ifs without the whiles, but I couldn't make it possible. The code I posted is useable but randomly times out when testing, and i'm afraid of how it would perform under stress. I...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-19T22:21:44.660", "Id": "10934", "Score": "0", "body": "What is the difference between `conferences.confName` and `2012rlc.name`? Is the schema in [3NF](http://en.wikipedia.org/wiki/Third_normal_form)?" } ]
[ { "body": "<p>First of all, does you tables have indexes? If you run the queries with <a href=\"http://dev.mysql.com/doc/refman/5.0/en/explain.html\" rel=\"nofollow\"><code>EXPLAIN</code></a> on MySql console (for example <code>EXPLAIN SELECT DISTINCT confName, tableName FROM conferences WHERE enabled='1' ORDER...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-17T03:03:34.943", "Id": "6937", "Score": "3", "Tags": [ "php", "optimization", "mysql" ], "Title": "Nested while loop for getting db data. Timing out at random times because of the P...
6937
<p>I have written the below code for quick sort in Java:</p> <pre><code>void quicksort (int[] a, int lo, int hi) { // lo is the lower index, hi is the upper index // of the region of array a that is to be sorted int i=lo, j=hi, h; // comparison element x int x=a[(lo+hi)/2]; // partition do { ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-17T16:19:20.123", "Id": "10844", "Score": "3", "body": "If this is homework, it should be tagged as 'homework'. If it is not homework, then it should be tagged as 'reinventing-the-wheel'." } ]
[ { "body": "<p>Some small notes:</p>\n\n<ol>\n<li><p>Instead of commenting here:</p>\n\n<pre><code>void quicksort (int[] a, int lo, int hi) {\n // lo is the lower index, hi is the upper index\n // of the region of array a that is to be sorted\n int i=lo, j=hi, h;\n</code></pre>\n\n<p>rename the variab...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-17T04:34:31.693", "Id": "6939", "Score": "8", "Tags": [ "java", "sorting", "quick-sort" ], "Title": "Quick Sort Implementation" }
6939
<p>I need a way to build up a sort of stack of places to search for an item.</p> <p>What I would like to do is to have each layer searched for an item, and if it is found at that level, then it should be loaded by each higher level (successively). </p> <p>What I have so far is just a basic framework, but I was wonder...
[]
[ { "body": "<p>How about making <code>inMem</code> &amp; co \"bracket\" functions? Like follows:</p>\n\n<pre><code>import Control.Monad.Writer\n\ntype M a = Writer String a\ntype LoadFunc a b = (a -&gt; M b) -&gt; a -&gt; M b\n\ntype Query = String\ntype Result = ()\n\ninMem :: LoadFunc Query Result\ninMem _ \"h...
{ "AcceptedAnswerId": "6949", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-17T14:16:16.497", "Id": "6947", "Score": "6", "Tags": [ "haskell", "functional-programming" ], "Title": "Chaining method calls and \"bubbling\" the results" }
6947
<p>I'm interested in implementing role based code in C++. I'm also interested in what side effects or barriers (from static strong typing perhaps?) have been added that I am unaware of and if there is a better way.</p> <pre><code>#include &lt;cstdio&gt; #include &lt;vector&gt; #include &lt;string&gt; #include &lt;num...
[]
[ { "body": "<p>In moneyTransferCTX:</p>\n\n<p>You are using pointers. As you never expect these to be NULL (and they can't be changed) you should be using references.</p>\n\n<p>The constructor is casting objects to things that are not necessarily valid.</p>\n\n<pre><code>moneyTransferCTX(IsourceAccount *src, Ide...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-17T23:11:14.343", "Id": "6952", "Score": "7", "Tags": [ "c++", "finance" ], "Title": "Bank transaction implementation - side-effects of barriers" }
6952
<p>I have a requirement to capture a string in a specific format of <code>* [Numeric Digits] *</code>. This is how I have done right now but I think it would be faster with Regular Expressions. I don't have a lot of experience with RegEx, so please help me optimize this code using RegEx.</p> <pre><code>if (string.IsNu...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-18T10:57:53.320", "Id": "10860", "Score": "1", "body": "This free tool is great for testing your expressions http://www.radsoftware.com.au/regexdesigner. I'm not associated with the company, just a grateful user :)" } ]
[ { "body": "<p>Could you possibly provide more samples of your data? In any case, try this </p>\n\n<pre><code>Regex regex = new Regex(@\"^[*]\\d+[*]$\");\n</code></pre>\n\n<p>If you actually expect the brackets (e.g. []) using the following:</p>\n\n<pre><code>Regex regex = new Regex(@\"^[*][\\[]\\d+[]][*]$\");\n...
{ "AcceptedAnswerId": "6958", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-18T09:41:04.387", "Id": "6956", "Score": "3", "Tags": [ "c#", ".net", "asp.net", "regex", "winforms" ], "Title": "Capturing a string in a specific format" }
6956
<p>Reading Jeff Atwood's <a href="http://www.codinghorror.com/blog/2007/02/why-cant-programmers-program.html" rel="noreferrer">"Why Can't Programmers.. Program?"</a> led me to think that almost all of the solutions would not be something I would want in my own code-base. The Fizz Buzz program specification from Imran ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-05T16:59:06.717", "Id": "32262", "Score": "4", "body": "An important part of writing good code is choosing which code *not to write*. The above is an *insanely* over-engineered solution, and it would not hire somebody who produced it. ...
[ { "body": "<blockquote>\n <p>Is it overkill to suggest such a solution? </p>\n</blockquote>\n\n<p>Yes, I think so :-)</p>\n\n<blockquote>\n <p>Under what conditions would you split it into a Model and Views? </p>\n</blockquote>\n\n<p>If you need more than one view. For example, if the specification says that ...
{ "AcceptedAnswerId": "6967", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-18T10:33:55.023", "Id": "6957", "Score": "11", "Tags": [ "php", "interview-questions", "fizzbuzz" ], "Title": "Fizz Buzz interview question code" }
6957
<p>This code is still very naive. I am trying to convert an existing XSD to JSONSchema. Firstly, pardon the variable names (I know some are really just stupid but I will fix them once I get all the functionality to work.) </p> <pre><code>using System; using System.Collections.Generic; using System.Dynamic; using Syst...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2015-11-05T16:08:36.230", "Id": "202431", "Score": "0", "body": "Kind of late, but why not use Json.NET? Just use xsd2code and then JSchemaGenerator generator = new JSchemaGenerator();\n \n JSchema schema = generator.Generate(typeof(...));" ...
[ { "body": "<p>I have not tried or scrutinized your code much, but my immediate impression is that you can clean this up quite a bit.</p>\n\n<p>I recommend getting this book about clean code:\n<a href=\"http://rads.stackoverflow.com/amzn/click/0132350882\" rel=\"nofollow\">http://www.amazon.com/Clean-Code-Handb...
{ "AcceptedAnswerId": "7111", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-18T14:18:07.970", "Id": "6959", "Score": "5", "Tags": [ "c#", "converting", "json", "xsd" ], "Title": "Convert XSD to JSONSchema" }
6959
<p>This code works to copy named capture groups of a Regex to the same named properties of a strongly typed object. However, it's not pretty. Someone mentioned I should use polymorphism to at least remove the five if statements.</p> <p>What should I consider when improving this code? Suggested reading?</p> <pre><c...
[]
[ { "body": "<p>By seeing the structure of your code structure i assume that all those if staements can easily be changed by a 'switch case' - which obviuosly is a <a href=\"http://c2.com/xp/CodeSmell.html\" rel=\"nofollow\">code smell</a>. I think you need to refactor your code. For further details please visit ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-18T08:57:27.790", "Id": "6960", "Score": "3", "Tags": [ "c#", "regex" ], "Title": "Code Improvement: Copy Regex named capture groups to strongly typed object" }
6960
<p>Basically I just wrote this calculator as a sort of JavaScript test for myself. It's a simple calculator with addition, subtraction, and multiplication. I've made some improvements to it before posting this. </p> <p>At this point I was hoping anyone could just point out some ways I could have cleaned this code up ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2017-09-22T14:49:27.600", "Id": "334443", "Score": "0", "body": "Your four function calculator only implements three functions." } ]
[ { "body": "<p>Replace <code>eval(displayNum)</code> with <code>+displayNum</code> - eval executes the value which not only slower it's vulnerable to XSS.</p>\n\n<p>Other than that you would start to look into making you code Object Oriented (OO) to combine code into logical groups and to take the functions and ...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-18T13:02:10.903", "Id": "6963", "Score": "5", "Tags": [ "javascript", "html", "calculator" ], "Title": "Simple four-function calculator" }
6963
<p>I'm looking for a review of my current code. It is supposed to capture a paste in the browser window, regardless of the element with focus. This is not the final form as I will be converting it into a jQuery plugin but I'm looking for a review of the logic behind the code.</p> <p>jfiddle: <a href="http://jsfiddle.n...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-18T19:48:01.500", "Id": "10881", "Score": "0", "body": "Maybe some words about what the code supposed to do would be useful :-)" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-18T19:50:37.873", "Id": "1...
[ { "body": "<p>You need to detect the browser only once, not on each keypress.</p>\n", "comments": [ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-18T22:37:31.603", "Id": "10889", "Score": "0", "body": "I agree ... its not like it will change betwe...
{ "AcceptedAnswerId": "6972", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-18T19:33:05.630", "Id": "6970", "Score": "3", "Tags": [ "javascript", "jquery" ], "Title": "review of work-in-progress javascript - Capture pastes in browser" }
6970
<p>The code below is a good representation of my coding skills. I've been at it for about 6 months. What I am interested in is ways to make the following program faster. I currently have the urlrequests threaded to pull information for 500 stocks, but it is still too slow (around 30 seconds). What python techniques...
[]
[ { "body": "<p>It is difficult to make the program faster because time is mostly expended in IO and url connections. It would help for checking changes if you could provide the csv stock files.</p>\n\n<p>On the other hand the code could be greatly simplified. The following code has not been tested (no csv files ...
{ "AcceptedAnswerId": "6976", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-18T22:14:35.603", "Id": "6973", "Score": "2", "Tags": [ "python", "performance", "multithreading" ], "Title": "threading objects and urlrequests" }
6973
<p>Just wondering if this basic performance test between an untyped array of arrays and a vector (typed array) of arrays in Actionscript 3... is fair and balanced? It's simple, designed to test random access on the collections as well as pushing new items, etc. Here goes:</p> <pre><code>import flash.events.Event; impo...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-19T00:23:29.537", "Id": "10890", "Score": "0", "body": "Note that I tagged as javascript because the two languages are nearly identical anyway." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-19T00:33:41.74...
[ { "body": "<p><strong>Some thoughts</strong></p>\n\n<p>You don't need to use <code>new int</code> (it's very uncommon in actionscript), just cast it to that:</p>\n\n<pre><code>newArray.push(int(Math.random()));\n</code></pre>\n\n<p>You don't need to use <code>new String</code> (it's very uncommon in actionscrip...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-19T00:20:29.370", "Id": "6975", "Score": "2", "Tags": [ "performance", "actionscript-3" ], "Title": "Is there anything biased in this performance test?" }
6975
<p>I'm coding a small web app with no real functionality. It's like a pilot program for something bigger. What I want is construct a program that works as a clock on/off for a restaurant. Actually I'm just trying to simulate one. What I'v done is working but I would like to know whether there is any java class that I c...
[]
[ { "body": "<p>I assume that <code>Hours</code> is a custom class of yours. </p>\n\n<ul>\n<li><p>If you are asking if there is an existing Java class that will automagically calculate the \"difference\" between two instances of your custom class, the the answer is \"No\".</p></li>\n<li><p>If you are asking (mor...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-19T02:45:52.230", "Id": "6977", "Score": "2", "Tags": [ "java" ], "Title": "Improvement of this method" }
6977
<p>I use this piece of code to compute a short-time Fourier transform:</p> <pre><code>// Output pre-allocation std::vector&lt;std::vector&lt;std::complex&lt;T&gt; &gt; &gt; y(nFft, std::vector&lt;std::complex&lt;T&gt; &gt;(nFrames, 0.0)); std::vector&lt;T&gt; xt; std::vector&lt;std::complex&lt;T&gt; &gt; yt; xt.reser...
[]
[ { "body": "<p>The only thing worth commenting on is the identifier names could be more meaningful.</p>\n\n<ul>\n<li>Short identifiers are harder to find when maintaining the code (more false positives).</li>\n<li>Short identifiers make it hard to put meaning to the identifier.</li>\n</ul>\n", "comments": []...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-19T10:54:41.853", "Id": "6980", "Score": "4", "Tags": [ "c++", "vectors", "openmp" ], "Title": "Vectors assignations and operations in a loop and parallelization with OpenMP" }
6980
<pre><code> private static void OnSundayChangedCallBack(DependencyObject sender, DependencyPropertyChangedEventArgs e) { BinaryDataGrid c = sender as BinaryDataGrid; if (c != null) { if (_shouldCallBack) { if (c.Sunday.Length == 4) ...
[]
[ { "body": "<p>What you need to do is:</p>\n\n<ol>\n<li><p>Add a parameter of type <code>System.DayOfWeek</code> called, say, <code>day_of_week</code>.</p></li>\n<li><p>Replace the fields <code>BinaryDataGrid.Sunday</code>, <code>.Monday</code>, etc. with a <code>Dictionary&lt;K,V&gt;</code> that has a key of ty...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-19T12:49:36.190", "Id": "6982", "Score": "2", "Tags": [ "c#" ], "Title": "Duplicate code in day of the week event handlers" }
6982
<p>I have two very similar functions that exist mainly for syntactic sugar.</p> <pre><code>deactivate = (el, seek) -&gt; el.find(seek).removeClass("active") activate = (el, seek) -&gt; el.find(seek).addClass("active") </code></pre> <p>This allows me to write, for example:</p> <pre><code>activate $("#something"), ".c...
[]
[ { "body": "<p>You can use js' bracket notation for this task</p>\n\n<pre><code>alter = (el, seek, method) -&gt; el.find(seek)[method + \"Class\"](\"active\")\n#use like this:\nalter $(\"#something\"), \".child\", \"add\"\n</code></pre>\n\n<p>However, your situation doesn't really call for DRYness. Your method n...
{ "AcceptedAnswerId": "6984", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-19T13:27:43.063", "Id": "6983", "Score": "1", "Tags": [ "javascript", "jquery", "coffeescript" ], "Title": "Similar but slightly different JavaScript functions" }
6983
<p>I am an eighth grader with a school project of creating and application in Java that returns the total permutations of two given numbers. It needs to be light and efficient, for later deployment on a website. I was wondering if there was any way I could improve the code so it would be more efficient.</p> <pre><co...
[]
[ { "body": "<p>First of all, please write a single function instead of expanding what is essentially the same code three times!</p>\n\n<pre><code>long factorialN = n;\nfor (int ForN = n; ForN &lt;= n &amp;&amp; ForN &gt; 1; ForN--) {\n factorialN = factorialN * ForN;\n}\nfactorialN = factorialN / n;\n</code><...
{ "AcceptedAnswerId": "6991", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-19T15:10:19.107", "Id": "6988", "Score": "8", "Tags": [ "java", "performance", "homework", "combinatorics" ], "Title": "Java application for finding permutations efficiently" }
6988
<p>I'm <em>trying</em> to learn Haskell and the mindset of programming functionally. I have started off by trying to understand the basics by writing code without any <code>Monads</code> in it. </p> <p>So far, I think I'm getting used to the type system and how the basics works. </p> <p>I thought to myself, why not t...
[]
[ { "body": "<p>Well, sorry, but it is <strong>really</strong> tempting to note that there is in fact a library routine that can do that, and it is even called the same as your function:</p>\n\n<pre><code>groupBy (\\a b -&gt; b /= '/') \"/hejsan/asdas\"\n</code></pre>\n\n<p>This code with <code>groupBy</code> fro...
{ "AcceptedAnswerId": "7009", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-19T15:46:34.457", "Id": "6992", "Score": "11", "Tags": [ "strings", "haskell" ], "Title": "Approach to string split by character in Haskell" }
6992
<p>The following code is very slow. I was wondering if you can help me speed it up.</p> <pre><code>private void filter(List&lt;CheckBox&gt; boxList) { // refLanguageTabs is a TabControl the Tabcount is 9 for (int i = 0; i &lt; refLanguageTabs.TabCount; i++) { ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2015-05-04T19:01:20.557", "Id": "161811", "Score": "0", "body": "Only state the code purpose in the title, what does it do specifically?" } ]
[ { "body": "<p>Some few thoughts without testing or anything else:</p>\n\n<ul>\n<li>Cache the value of the cell in a local variable.</li>\n<li><a href=\"https://stackoverflow.com/questions/1124753/for-vs-foreach-loop-in-c-sharp\">Replace for-loops if possible with foreach-loops</a>.</li>\n<li>The call of <code>b...
{ "AcceptedAnswerId": "6994", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-19T15:49:30.753", "Id": "6993", "Score": "2", "Tags": [ "c#" ], "Title": "Help reducing loops with filter code" }
6993
<p>I'm generating all combinations of an array, so for instance, <code>["a", "b", "c", "d"]</code> will generate:</p> <pre><code>[ "a", "b", "ab", "c", "ac", "bc", "abc", "d", "ad", "bd", "abd", "cd", "acd", "bcd", "abcd" ] </code></pre> <p><a href="http://jsfiddle.net/BDG/e7sSX/5/">Here...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2021-01-02T01:34:14.460", "Id": "501308", "Score": "0", "body": "I have answered another question like this. I hope it will help you also. Please check: stackoverflow.com/a/65535210/2184182" } ]
[ { "body": "<p>A much faster way to do <code>Math.pow( 2, x )</code> if x is an integer is <code>1 &lt;&lt; x</code>.</p>\n\n<p>A good name for the function might also be 'array_permutator'.</p>\n", "comments": [ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-19T20:33:01.6...
{ "AcceptedAnswerId": "7025", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-19T17:34:08.417", "Id": "7001", "Score": "91", "Tags": [ "javascript", "combinatorics" ], "Title": "Generating all combinations of an array" }
7001
<pre><code>public class BQueue&lt;T&gt; { private Queue&lt;T&gt; q = new LinkedList&lt;T&gt;(); private int limit; public BQueue(int limit) { this.limit = limit; } public synchronized void put (T t) throws InterruptedException { while (isFull()) { wait(); } ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-19T19:44:57.327", "Id": "10924", "Score": "3", "body": "I _think_ it probably is, although I occasionally get tripped up by some threading stuff. Is there a reason you're not implementing any of the interfaces (`Queue`, etc.)? Or eve...
[ { "body": "<p>It looks to me like it is thread-safe. But don't take my word for it; you better consider each answer as a vote, and go with what the majority says. (Multi-threading is tricky!) Note: comments should not be considered as answers.</p>\n", "comments": [], "meta_data": { "CommentCount":...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-19T18:43:08.510", "Id": "7002", "Score": "15", "Tags": [ "java", "multithreading", "queue", "collections", "synchronization" ], "Title": "Java blocking queue" }
7002
<p>I have a <code>xxs</code> list:</p> <pre><code>xxs:: [(([Char], [Char]),([Char], [Char]),[(Double, [Char], [Char])])] xxs = [(("a11","b11"),("a12","b12"), [(0,"a1","b1"),(1.2,"a2","b2"),(2.3,"a3","b3"),(4.2,"a4","b4")]), (("c11","d11"),("a12","b12"),[(1,"a5","b5"),(1.4,"a6","b6"),(1.9,"a7","b7"),(4.4,"a8","b8")])] ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-19T01:01:47.443", "Id": "10940", "Score": "0", "body": "@ehird For me, this is not exactly a \"Code Review\"... is more like: I'm a beginner in Haskell, I solved my homework, but I'm curious about other solutions/approaches to solve it...
[ { "body": "<p>Wow! What an ugly data structure. I suggest making small transformations until you arrive at the form you desire; this is in contrast to your current solution that extracts the exact element you desire (performing all needed computations) without building a new representation.</p>\n\n<p><strong...
{ "AcceptedAnswerId": "7012", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-19T00:49:19.693", "Id": "7011", "Score": "11", "Tags": [ "haskell" ], "Title": "A different code?" }
7011
<p>I think I'm finished writing a multithreaded reader-writer implementation for my Operating Systems course. I would like to verify that my multithreading is correct and that I'm using good C++0x style.</p> <p>PalindromeDatabase.h</p> <pre><code>class PalindromeDatabase : public Utility::Uncopyable { friend void...
[]
[ { "body": "<p>It is very hard to determine if multi threaded code is correct just by looking at it. You should create special tests that simulate concurrent operations and validate shared state for corruption. The test(s) should be run for considerable amount of time and preferably on multi CPU (core) environme...
{ "AcceptedAnswerId": "7039", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-20T08:48:01.323", "Id": "7014", "Score": "4", "Tags": [ "c++", "multithreading", "c++11", "palindrome" ], "Title": "Correct multithreaded reader-writer implementation" }
7014
<p>I have been working on Custom TextBox control, which only allows alphanumeric characters. Note that I have not restricted characters from KeyPress, KeyUp event as I don't want to restrict copy/paste or any other operation that should be allowed generally. I have only trimmed non-alphanumeric character on paste opera...
[]
[ { "body": "<p>Are you reinventing the <a href=\"http://msdn.microsoft.com/en-us/library/system.windows.forms.maskedtextbox.aspx\" rel=\"nofollow\">MaskedTextBox</a>?</p>\n", "comments": [ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-21T12:51:42.757", "Id": "1097...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-20T10:29:00.357", "Id": "7016", "Score": "2", "Tags": [ "c#", "winforms" ], "Title": "C# Winforms: Is there any way to improve this simple custom Textbox code?" }
7016
<p>Below is my code which I use to read data from a remote URL (which is GZipped), convert it to a <code>Map</code>, process the map (remove various unwanted fields, etc), the write it back to a file in JSON format.</p> <p>Unfortunately, it's ugly. I'm doing multiple things in the same method, but can't think of a goo...
[]
[ { "body": "<p>An idea:</p>\n\n<pre><code>private BufferedReader getReader(final String fileUrl) throws IOException {\n final String filename = getFilename(fileUrl) + \".gz\";\n final URL url = new URL(fileUrl);\n final InputStream stream;\n if (new File(filename).isFile()) {\n stream = ClassL...
{ "AcceptedAnswerId": "7030", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-20T18:17:49.283", "Id": "7027", "Score": "2", "Tags": [ "java" ], "Title": "Converting input from a FileReader to JSON and outputting it again" }
7027
<p>I have a data structure that looks like this:</p> <pre><code>a = { 'red': ['yellow', 'green', 'purple'], 'orange': ['fuschia'] } </code></pre> <p>This is the code I write to add new elements:</p> <pre><code>if a.has_key(color): a[color].append(path) else: a[color] = [path] </code></pre> <p>...
[]
[ { "body": "<p>You can use <a href=\"http://docs.python.org/library/collections.html\">collections.defaultdict</a>:</p>\n\n<pre><code>from collections import defaultdict\n\nmydict = defaultdict(list)\n</code></pre>\n\n<p>Now you just need:</p>\n\n<pre><code>mydict[color].append(path)\n</code></pre>\n\n<p><code>d...
{ "AcceptedAnswerId": "7029", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-20T19:15:31.217", "Id": "7028", "Score": "1", "Tags": [ "python" ], "Title": "Shorter way to write list-as-dict-value in Python?" }
7028
<p>On my webform, there are two kinds of address-fields a user can give. But since it's a complex webform (Drupal) it's kind of hard to achieve. Every time a user adds an extra address, the form is regenerated and there will be a new item added to the <code>$address_afl</code> and <code>$address_bev</code>-array. Is it...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-21T01:12:19.763", "Id": "10958", "Score": "2", "body": "Can you merge your two $address_ arrays into a single array? Maybe generalize this code into a function that takes the form name as a parameter, this way your loop is programed o...
[ { "body": "<p>I don't quite exactly understand the logic, but you could extract out at least one method which removes lots of code duplication. I've inverted some conditions (which improves code readability) and placed some comments into the code too.</p>\n\n<pre><code>function processValue(&amp;$form, $value, ...
{ "AcceptedAnswerId": "7056", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-20T19:59:47.317", "Id": "7031", "Score": "4", "Tags": [ "php" ], "Title": "If statement with 2 conditions" }
7031
<p>I often end up working with systems where the data is delivered with some <code>Id</code> property and possibly a <code>parentId</code> prop, but never do anyone tempt to actually give me a nice recursive object to play with.</p> <p>Now, the code below is merely a suggestion in how to solve these kind of "problems"...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-20T23:39:26.780", "Id": "10956", "Score": "4", "body": "Looks beautiful. I would have used the term 'hierarchical' rather than 'recursive' in many places, however. Including the title." }, { "ContentLicense": "CC BY-SA 3.0", ...
[ { "body": "<p>You could, perhaps, derive RecursiveObject from FlatObject.</p>\n\n<p>In the degenerate case in which all objects belong to a single lineage (every object has one and only one child, except the last one) and you have <strong>lots</strong> of objects, then your recursive method will try to use an a...
{ "AcceptedAnswerId": "7054", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-20T23:09:07.797", "Id": "7032", "Score": "5", "Tags": [ "c#", "linq", "recursion" ], "Title": "Recursive method turning flat structure to recursive" }
7032
<p>First time I'm using stackexchange. I'm in 8th standard. I tried to implement Queue in Java. I wrote something like this> Right now I'm not able to test it because I don't have JVM in my machine. So I just wanted to know Is this correct implementation? Am I going in the right direction? </p> <pre><code> import java...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-21T11:01:10.533", "Id": "10970", "Score": "2", "body": "you might find http://ideone.com helpful if you don't have a proper dev environment setup." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-21T15:45:08...
[ { "body": "<p>It needs some improvement but you're definitely in the right direction. There are some typos (<code>string</code> should be <code>String</code>, for example) but I'm sure that you will be able to fix them.</p>\n\n<p>Just two notes:</p>\n\n<p>1, Here maybe you want to read some initial elements:</p...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-21T07:22:02.017", "Id": "7035", "Score": "3", "Tags": [ "java", "queue" ], "Title": "Queue Implementation" }
7035
<p>I am interested in seeing how people would refactor this code to make it more readable, remove local variables, etc. The code checks a string against a number of arrays. The first (0) field of each array is the root word and the rest of the words are its synonyms. The idea is to replace any word in the user-provided...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-21T08:27:36.477", "Id": "10961", "Score": "0", "body": "I'd start with _consistent_ indentation." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-21T08:31:18.393", "Id": "10962", "Score": "0", "b...
[ { "body": "<p>1, You could eliminate the <code>matchFound</code> flag if you create a label for your outer <code>for</code> loop and call <code>break</code> with this label:</p>\n\n<pre><code>matchLoop: for (final String[] synonymArr : mSynonyms) {\n for (int j = 0; j &lt; synonymArr.length; j++) {\n ...
{ "AcceptedAnswerId": "7038", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-21T07:50:10.560", "Id": "7036", "Score": "4", "Tags": [ "java" ], "Title": "Synonymiser refactoring" }
7036
<p>The aim of this code is to return an object which contains all of the movies. Where attributes are not found, they need to return <code>None</code> rather than be undefined and raise an exception.</p> <p><code>attrs</code> is a list of all possible properties for that class. Each class loops through and tries to ge...
[]
[ { "body": "<pre><code>import httplib\nimport xml.etree.ElementTree as ElementTree\n\ndef getUrl(server,url):\n c=httplib.HTTPConnection(server.ip,server.port)\n c.request(\"GET\",url)\n r=c.getresponse()\n return r.read()\n</code></pre>\n\n<p>Firstly, the function doesn't really match its name. getU...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-21T13:06:21.517", "Id": "7044", "Score": "5", "Tags": [ "python", "xml", "parsing" ], "Title": "Parsing XML in Python" }
7044
<p>I am using class "active" to keep track on which child to fade in and fade out in my gallery. Are there any other, better options for doing this?</p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;meta charset="utf-8" /&gt; &lt;title&gt;Untitled Document&lt;/title&gt; &lt;meta http-equiv="Content-Ty...
[]
[ { "body": "<p>Maybe using jQuery's <a href=\"http://api.jquery.com/jQuery.data/\" rel=\"nofollow\"><code>$.data()</code></a> to store a bool variable or something like that. </p>\n\n<p>Also you could store a global variable with the active position (e.g. \"3\" for the 3rd item in the gallery), and then change i...
{ "AcceptedAnswerId": "7053", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-21T14:46:59.630", "Id": "7047", "Score": "2", "Tags": [ "javascript", "jquery" ], "Title": "Keep track on active slide" }
7047
<p>Previous question:</p> <p><a href="https://codereview.stackexchange.com/questions/6988/java-application-for-finding-permutations-efficiently">Java application for finding permutations efficiently</a>></p> <p>I have changed quite a bit of code, and need some more reviews.</p> <pre><code>class Permutations { s...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-21T17:17:13.037", "Id": "10989", "Score": "1", "body": "Are you sure that you pasted it well? It's not compiling, I think the `return` statement of the `factorial` method is in a wrong place." }, { "ContentLicense": "CC BY-SA 3...
[ { "body": "<h2>Code comment:</h2>\n\n<pre><code>static long factorial(int num){\n long factorial = num;\n for (int forBlockvar = num; forBlockvar &gt; 1; forBlockvar--) {\n factorial = factorial * forBlockvar;\n }\n return factorial / num;\n}\n</code></pre>\n\n<p>You are starting your <code>f...
{ "AcceptedAnswerId": "7051", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-21T16:16:43.510", "Id": "7048", "Score": "2", "Tags": [ "java", "homework", "combinatorics" ], "Title": "Permutations Finder Help Number 2" }
7048
<p>Please have a look at the following 2 snippets:</p> <pre><code>var query = _ctx.Notes.Where(...); var searchLower = searchTerms.ToLower(); query = query.Where(a =&gt; a.Comment.ToLower().Contains(searchLower)) </code></pre> <p>vs</p> <pre><code>var query = _ctx.Notes.Where(...); query = query.Where(a ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-29T15:43:19.943", "Id": "11350", "Score": "1", "body": "Note that according to \"Best Practices for Using Strings in the .NET Framework\" you should be converting `ToUpper()`, not `ToLower()`. Link: http://msdn.microsoft.com/en-us/lib...
[ { "body": "<p>Instead of <code>Contains()</code>, use <code>IndexOf()</code> which takes a comparer:</p>\n\n<pre><code>var query = _ctx.Notes.Where(...); \nquery = query.Where(a =&gt; a.Comment.IndexOf(searchTerms, StringComparison.OrdinalIgnoreCase) &gt;= 0)\n</code></pre>\n", "comments": [ { ...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-21T16:26:57.127", "Id": "7049", "Score": "1", "Tags": [ "c#", "linq" ], "Title": "Is there any performance increase converting search term to lower case before LINQ" }
7049
<p>My query is this:</p> <pre><code>UPDATE `phrases` SET `phrases`.`count`=(SELECT COUNT(*) FROM `strings` WHERE `string` LIKE CONCAT('%', `phrases`.`phrase`, '%')) </code></pre> <p>My tables look like this:</p> <pre><code>CREATE TABLE `phrases` ( `hash` varchar(32) NOT NULL, `count` int DEFAULT 0, `phra...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-20T22:09:27.617", "Id": "11009", "Score": "0", "body": "It might be more efficient to have a separate table where you would store the counts per phrase, and then only update this table once a new string is added. Since the number of st...
[ { "body": "<p>Since you're using a <code>LIKE</code> with wildcards, you're going to do a table-scan against both tables, running a total of 18000*1500 = 27000000 substring comparisons.</p>\n\n<p>To optimize this, you need to use some fulltext index technology. I suggest <a href=\"http://sphinxsearch.com/\" re...
{ "AcceptedAnswerId": "7061", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-20T21:57:04.717", "Id": "7060", "Score": "3", "Tags": [ "strings", "sql", "mysql" ], "Title": "Phrases update query" }
7060
<p>I have made a simple scorecard form which uses jQuery to automatically calculate the score of submissions depending on field values. Some fields are "critical" which means if they are a fail they automatically fail. </p> <p>You can see a <a href="http://jsfiddle.net/westieuk/WtDMk/288/" rel="nofollow">jsFiddle exam...
[]
[ { "body": "<p>Personally I wouldn't change anything about the calculation itself. It all quite reasonable the way it is. </p>\n\n<p>There are just two things could be optimized concerning jQuery:</p>\n\n<ul>\n<li>You should be using <code>.closet()</code> instead of <code>.parents()</code> since you only need t...
{ "AcceptedAnswerId": "7086", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-22T12:08:03.897", "Id": "7065", "Score": "1", "Tags": [ "javascript", "jquery" ], "Title": "jQuery score card form to determine pass or fail" }
7065
<p>This is a view as part of a RESTful image handler module, written for Flask, I am sure there is a better/more pythonic way of doing parts of this, maybe using List Comprehensions or Generator Functions. But I am a bit of a Python newbie and cannot spot it. Can any experienced pythonistas take a look?</p> <pre><code...
[]
[ { "body": "<pre><code>@__mod__.route('/', methods=['GET'])\n@__mod__.route('/&lt;filename&gt;', methods=['GET'])\n</code></pre>\n\n<p>Seeing as you end up handling these two routes in completely different ways, why don't you just implement two functions?</p>\n\n<pre><code>def get(filename=None):\n \"\"\" Get...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-22T13:28:28.000", "Id": "7067", "Score": "3", "Tags": [ "python", "image", "flask" ], "Title": "Python RESTful image handler" }
7067
<p>I'm working through an introduction to computer science book, this is not homework for me but me trying to learn in my spare time, I'm not asking for homework help!</p> <p>The output is below, and this is all ok, but I'm just certain there is a more efficient way of doing this. I have been trying for many hours now...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-21T19:35:51.073", "Id": "11018", "Score": "1", "body": "Is this literally a multiplication table generator?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-21T20:54:06.717", "Id": "11019", "Score": ...
[ { "body": "<pre><code>for i in range(10):\n for j in range(10):\n print i*j,\n print \"\"</code></pre>\n\n<p>Something like this, perhaps?</p>\n", "comments": [], "meta_data": { "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-21T19:37:25.313...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-21T19:32:28.160", "Id": "7068", "Score": "4", "Tags": [ "python" ], "Title": "Improving many for loops, any more efficient alternative?" }
7068
<p>Is there a better way to do this without using <code>if</code> or <code>case</code> statements?</p> <pre><code>var val = ui.value, $box = $('#message'); switch(true) { case (val &gt; 50): $box.hide(); animations.animateBox($box.html('you have chosen XN')); break; case (val &l...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-22T12:32:24.793", "Id": "11021", "Score": "0", "body": "Although `switch` can be used with expressions, you should better only use literal/constant values." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-22...
[ { "body": "<p>You <strong>must not</strong> use conditional statements in combination with <code>switch</code>... that is THE DEVIL... because <code>switch/case</code> only interpretates <strong>values</strong> !</p>\n\n<p>Infact, what you did there equals</p>\n\n<pre><code>switch( true ) {\n case true/false...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-22T12:28:56.137", "Id": "7076", "Score": "14", "Tags": [ "javascript", "jquery", "animation" ], "Title": "Animating one of three boxes based on a form value" }
7076
<p>Any suggestions on how I could improve it? </p> <p><a href="http://jsfiddle.net/sambenson/RmkEN/" rel="nofollow">jsFiddle</a></p> <pre><code>(function($){ $.extend({ notify: function(options, duration) { var // Default options object defaults = { inli...
[]
[ { "body": "<p>Some suggestions:</p>\n\n<ul>\n<li><p>rename onClosed to onClose</p></li>\n<li><p>don't declare that group of useful variables at once, declare them as you go. Or, declare once but use a var statement. Some of them are used only in add_notification function, so move them there.</p></li>\n<li><p>br...
{ "AcceptedAnswerId": "7135", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-22T14:12:34.157", "Id": "7080", "Score": "1", "Tags": [ "javascript", "jquery" ], "Title": "jQuery notifications plugin" }
7080
<p>Requirements:<br /> When the page (or in the case of the example Frame) expands, the only column to expand with the table should be 'unfrozen' columns (without the 'freeze' class). </p> <p><a href="http://jsfiddle.net/BZDyr/4/" rel="nofollow">here is the live demo</a> <em>The jQuery is there to show dynamic content...
[]
[ { "body": "<p>IMHO it's completely fine to set the width like this. Table cell widths have always be defined to be a \"minimum width\". </p>\n\n<p>As long the table doesn't have <code>table-layout: fixed</code> or the cells don't have <code>overflow</code> set to anything else than <code>visible</code>, I don't...
{ "AcceptedAnswerId": "7083", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-22T14:54:09.663", "Id": "7081", "Score": "4", "Tags": [ "html", "css" ], "Title": "Is this the best way to collapse a column width?" }
7081
<p>I just rewrote this:</p> <pre><code>if (budgetRemaining != 0 || totalOpenInvoices != 0) { } </code></pre> <p>Like this:</p> <pre><code>if (new[] { budgetRemaining, totalOpenInvoices }.Any(c =&gt; c != 0)) { } </code></pre> <p>If I had seen that before I ramped up on Linq, it would have confused me. Now that I'v...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-22T19:13:05.657", "Id": "11040", "Score": "0", "body": "Does totalOpenInvoices represent the sum of the monetary amount of the open invoices, or is it just the number of invoices that are open?" }, { "ContentLicense": "CC BY-SA...
[ { "body": "<p>Seems to be swatting a fly with a Buick to me. The first form seems pretty concise and the variable names are quite descriptive. The second form creates a new object (the array) which will eventually have to be GC'd and introduces a new lambda variable, <code>c</code> which doesn't seem descriptiv...
{ "AcceptedAnswerId": "7089", "CommentCount": "10", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-22T17:10:46.653", "Id": "7087", "Score": "30", "Tags": [ "c#", "linq" ], "Title": "Are these if-statements too fancy?" }
7087
<p>I wrote a query to run the same query across multiple databases and combine the results. While it seems plenty quick I was wondering if there is a better way to do this.</p> <pre><code>create table #serverlist( ID smallint IDENTITY(1,1), dbName varchar(50) ) create table #browsercounts( ID...
[]
[ { "body": "<p>You could skip the while clause and execute it as one statement - something like</p>\n\n<pre><code>select @SQL = @SQL + ' select Browser, COUNT(Browser) as Counts from ' + \n @database+ '.dbo.Session where Browser is not null group by Browser UNION ALL' from #serverlist\n\n--you should get ...
{ "AcceptedAnswerId": "7098", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-21T18:42:02.547", "Id": "7096", "Score": "2", "Tags": [ "sql", "sql-server", "t-sql" ], "Title": "Query for combining results of same query running across multiple databases" }
7096
<p>Here is my attempt at a floaty Bar module, used in a mobile application. There are several "bars", which stick to the top of the browser window once they are passed. When the next bar is reached, it takes over that sticky position... Based on: <a href="http://googlecode.blogspot.com/2009/09/gmail-for-mobile-html5-se...
[]
[ { "body": "<p>What I tend to do in these situations is have two states for the floaty thing:</p>\n\n<ol>\n<li>When it's not in \"stay on the page\" mode, it has <code>position:relative</code>.</li>\n<li>When the page is scrolled down enough, it gets <code>position:fixed</code> and stays on the page.</li>\n</ol>...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-22T22:41:52.633", "Id": "7099", "Score": "3", "Tags": [ "javascript" ], "Title": "Floaty bars module, need improvement?" }
7099
<p>I'm somewhat new to SQL (using it in the past but only being exposed to it heavily in my current role). Unfortunately nobody at my current company has really given me any advice on formatting. How can I format this better / what should I avoid doing that I may have done below? Any feedback on re-factoring would be g...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-30T15:44:49.230", "Id": "11441", "Score": "0", "body": "FYI, Unless you have a persisted calculated column for upper(lp.lease_status) and upper(lp.section_name), you may want to research the impact of using a function within your where...
[ { "body": "<p>What you've got is pretty readable, but there are a few points to make:</p>\n\n<ol>\n<li>Your sub-query is written with a different indentation style from the main query.</li>\n<li>I prefer to see the keywords in upper-case.</li>\n<li><p>Personally, I dislike spaces before commas intensely (and yo...
{ "AcceptedAnswerId": "7106", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-22T23:00:01.350", "Id": "7101", "Score": "5", "Tags": [ "mysql", "sql", "sql-server", "t-sql" ], "Title": "SQL - How's my formatting?" }
7101
<p>I'm building a web application in Java. I'm new to Java, so before I get too far into this... I'm hoping to take advantage of all the experience here and learn the problems with this setup.</p> <p><strong>My Servlet</strong></p> <pre><code>package cms.content; import java.io.IOException; import javax.servlet.Ser...
[]
[ { "body": "<p>First off, its not clear what you're trying to achieve, so its hard to evaluate. </p>\n\n<p>But, looking a the code there comes after you forward to the view, that could be confusing, because it will still execute. </p>\n\n<p>At a higher level, I also don't really see the need for this complicated...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-23T03:19:38.113", "Id": "7104", "Score": "1", "Tags": [ "java", "html", "mvc", "jsp", "servlets" ], "Title": "Is there a more efficient way of loading views within my java ap...
7104
<p>I have a <code>TreeView</code> called <code>myTreeView</code>. I want to be able to write a single statement after which <code>myTreeView.SelectedNode</code> is <code>null</code>, but <code>TreeView.SelectedNode</code> doesn't have a setter. I've looked at the decompiled source of <code>TreeView</code>, and there <e...
[]
[ { "body": "<p>If you havent already figured it out:</p>\n\n<pre><code>currentSelection.SelectedNode.Checked = false;\n</code></pre>\n\n<p>Hope that helps :)</p>\n", "comments": [ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-29T22:47:36.313", "Id": "11403", ...
{ "AcceptedAnswerId": "7289", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-23T14:12:50.637", "Id": "7112", "Score": "1", "Tags": [ "c#", "asp.net" ], "Title": "Is this really what has to be done to clear the selection of an ASP.NET TreeView?" }
7112
<p>I am writing a script that takes one CSV file searches for a value in another CSV file then writes an output depending on the result it finds.</p> <p>I have been using Python's CSV Distreader and writer. I have it working, but it is very inefficient because it is looping through the 2 sets of data until it finds a...
[]
[ { "body": "<p>One thing that you should avoid is reading the same file multiple times. There isn't any detail about how big are your files in the question, so I guess that they can fit in memory. In that case, I'd recommend to read the files once, work on the data in memory and write the result file.</p>\n\n<p>...
{ "AcceptedAnswerId": "7116", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-22T21:19:37.930", "Id": "7113", "Score": "6", "Tags": [ "python", "beginner", "search", "csv" ], "Title": "Searching for a value from one CSV file in another CSV file" }
7113
<p>I am learning Scala, coming from Java background. Here I have written a small prototype proof of concept program that is a part of concept base for a simple upcoming tutorial game. There are two game objects: a Cell and a Breed of cells (a 1d row). The operations are simple. One can create a breed with a number of c...
[]
[ { "body": "<p>Some improvements:</p>\n\n<ul>\n<li>Try to minimize all mutable state and side effecting methods to single places. Don't divide them through the whole program.</li>\n<li>Scala is object oriented. Therefore use methods of the objects you want to work with instead of global functions.</li>\n<li>use ...
{ "AcceptedAnswerId": "7127", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-23T15:32:15.307", "Id": "7117", "Score": "2", "Tags": [ "object-oriented", "functional-programming", "scala" ], "Title": "Scala object-function balance" }
7117
<p>I had to do a small application using a menu system and Turtle. I have finished it and worked perfect. Just to make sure, can you please check it if it has done properly?</p> <pre><code>#!/usr/bin/python ## draw_shape.py import turtle as t def how_many(): while True: print " How many of then do y...
[]
[ { "body": "<ol>\n<li><p>Why are you using a global? There seems to be no need for it, and in general it's something to avoid.</p></li>\n<li><p>Why not factor out the common stuff? In your main loop you have a bunch of if cases which all start in the same way and then all call methods which are very similar. If ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-23T15:34:42.467", "Id": "7118", "Score": "4", "Tags": [ "python", "homework", "turtle-graphics" ], "Title": "Menu system and Turtle" }
7118
<p>I'm trying to print the top 5 most queried strings from a text file. I can't use other third-party libraries to make it easier w.r.t hashmap implementations.</p> <p>I need to improve on these if possible:</p> <ol> <li>cyclomatic complexity</li> <li>Memory usage</li> <li>Execution time </li> <li>Page faults</li> </...
[]
[ { "body": "<p>Your names could be improved, e.g. <code>hm</code> isn't a good name for a member variable.</p>\n\n<p>You could replace the <code>HashMap</code> by a multiset implementation, e.g. <a href=\"http://code.google.com/p/guava-libraries/source/browse/guava/src/com/google/common/collect/HashMultiset.java...
{ "AcceptedAnswerId": "7137", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-23T17:37:52.907", "Id": "7120", "Score": "5", "Tags": [ "java", "performance", "logging", "statistics" ], "Title": "Extracting the five most frequent queries from a log file" }
7120
<p>Below is a simple "class" for displaying messages. It stores the output html div and then displays messages to it as needed. </p> <p>It works fine. For readability, and encapsulation purposes, I'd like the componenets of the "class" in a contianer of sorts or a javascript object? What is the simplest way to to ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-01-03T21:23:32.920", "Id": "11654", "Score": "0", "body": "Please don't edit the question to make the existing answers meaningless. If you have new versions of the code post a new question. Reference this one (in it's original form) and e...
[ { "body": "<p>You could wrap your whole file in a namespace, as <a href=\"https://stackoverflow.com/questions/881515/javascript-namespace-declaration\">described here</a>.</p>\n\n<p>Of all the possibilities, this is the one I like the most:</p>\n\n<pre><code>var YourNamespace = (function () {\n var Message = ...
{ "AcceptedAnswerId": "7146", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-23T17:39:44.400", "Id": "7121", "Score": "1", "Tags": [ "javascript" ], "Title": "Wrapping a javascript \"class\"?" }
7121
<p>I have a C# WinForms app containing a <code>ListBox</code> control, which I populate with objects of type <code>BukkitServer</code>. When an object is added or removed from the list, I want to write them to an XML file. I have a static method in a helper class that takes an <code>ICollection</code> argument and ac...
[]
[ { "body": "<p>If you don't mind using a little bit of LINQ, it can be simplified (and optimized) as such:</p>\n\n<pre><code>static class BukkitServerDataWriter\n{\n private static readonly XmlSerializer xml = new XmlSerializer(\n typeof(List&lt;BukkitServer&gt;),\n new[] { typeof(BukkitServer) ...
{ "AcceptedAnswerId": "7131", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-23T22:50:05.660", "Id": "7126", "Score": "2", "Tags": [ "c#", "winforms", "collections" ], "Title": "Persisting objects in a ListBox ObjectCollection" }
7126
<p>I'm new to template meta-programming and wrote some code to determine if a number is a perfect square. For example, in my program, <code>SQUARE&lt;1&gt;::value</code> and <code>SQUARE&lt;4&gt;::value</code> evaluate to <code>true</code> while <code>SQUARE&lt;5&gt;::value</code> is <code>false</code>. I'm open to a...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-24T00:22:02.710", "Id": "11103", "Score": "0", "body": "Does your use of `static_assert` indicate that C++11 features are okay in general? Because the code could be much improved by using `constexpr`." }, { "ContentLicense": "C...
[ { "body": "<p>I'd recommend against using ALL_CAPS for class-names. It's not really in accordance with C++ conventions.</p>\n\n<pre><code>template&lt;size_t n, size_t r&gt;\nstruct IS_SQUARE {\n static const bool value = IF&lt;n == r*r,\n true,\n IF&lt;GREATER&lt;n, r*r&gt;::ret,...
{ "AcceptedAnswerId": "7130", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-23T23:37:49.973", "Id": "7128", "Score": "5", "Tags": [ "c++", "c++11", "template-meta-programming" ], "Title": "Meta-program to find square numbers" }
7128
<p>I have been reading about <code>ZF2 EventManager</code> for some time now and I wonder what you'd think about this approach.</p> <pre><code>class Model_Member extends App_Model_Model { protected $_data = array( 'ID' =&gt; null, 'UserName' =&gt; null, 'Password' =&gt; null, 'Email...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-29T14:08:39.380", "Id": "11346", "Score": "0", "body": "I think I chose a very bad time for asking a question? is everyone on holiday :)" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-01-04T12:26:51.493", ...
[ { "body": "<p>I haven't used PHP recently, just a few, mostly minor notes:</p>\n\n<ol>\n<li><blockquote>\n<pre><code>// Encrypt password\n$member-&gt;Password = sha1($member-&gt;Password);\n</code></pre>\n</blockquote>\n\n<p>You might want to use <a href=\"https://crypto.stackexchange.com/q/1776/8221\">a salt</...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-23T03:18:13.473", "Id": "7132", "Score": "5", "Tags": [ "php", "object-oriented", "php5", "zend-framework" ], "Title": "Using ZF2 Event manager to save a model" }
7132
<p>I have a small program where I have a background thread that plays sound, so it needs to run really fast, but it also needs to do a small amount of memory management. I didn't want to use normal new and delete in a time critical area, so I threw this together, but set it up so I could reuse it elsewhere. </p> <pre>...
[]
[ { "body": "<p>This currently will not work.</p>\n\n<p>As every-time you create an object derived from <code>MemoryPool</code> you re-initialize the <code>myUnusedMemory</code> structure thus potentially messing up your management.</p>\n\n<pre><code>struct Game : public ag::util::MemoryPool&lt;Game, 2&gt; {};\n...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-24T06:45:52.973", "Id": "7133", "Score": "9", "Tags": [ "c++", "memory-management" ], "Title": "Super simple templated memory pool in C++" }
7133
<p>How do I make my Python program faster?</p> <p>I have 3 suspects right now for it being so slow:</p> <ol> <li><p>Maybe my computer is just slow</p></li> <li><p>Maybe my Internet is too slow (sometimes my program has to download the html of web pages and then it searches through the html for a specific piece of tex...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-24T16:56:20.190", "Id": "11124", "Score": "1", "body": "What do you mean by \"very slow\"? Does it take hours, days? How long does it take and what were you expecting?" } ]
[ { "body": "<pre><code>from urllib import urlopen\nfrom gzip import GzipFile\nfrom cStringIO import StringIO\nimport re\nimport urllib\nimport urllib2\nimport webbrowser\nimport mechanize\nimport time\nfrom difflib import SequenceMatcher\nimport os\n\ndef download(url):\n s = urlopen(url).read()\n if s[:2]...
{ "AcceptedAnswerId": "7140", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-24T13:39:09.423", "Id": "7136", "Score": "6", "Tags": [ "python", "performance", "io", "web-scraping", "compression" ], "Title": "Slow web-scraping geolocator" }
7136
<p>This is my first attempt at a hash map and I feel it is a great start. Although it does have a certain naive feel that I'm having trouble with.</p> <pre><code>public class HashMap&lt;TKey, TValue&gt; { const int BlockSize = 100000; const int NumberOfBlocks = 42950; readonly Entry[][] _blocks = new Entr...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-25T17:15:19.847", "Id": "11144", "Score": "0", "body": "wouldn't it be a good idea to implement [IDictionary<TKey,TValue>](http://msdn.microsoft.com/en-us/library/s4ys34ea.aspx), and maybe using `KeyValuePair<TKey,TValue>`s as entries ...
[ { "body": "<p>(I'm assuming you're implementing your own hashtable as an exercise/kata instead of using the CLR's, as I haven't seen anything unique here that justifies rolling your own.)</p>\n\n<p>Here's some feedback:</p>\n\n<ol>\n<li><p><code>HashMap</code> should implement core interfaces and functionality ...
{ "AcceptedAnswerId": "7178", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-24T17:12:14.063", "Id": "7139", "Score": "2", "Tags": [ "c#" ], "Title": "Care to review my first hash map?" }
7139
<p>File manipulation code, I've noticed, has two salient properties:</p> <blockquote> <ol> <li>It's everywhere, and vitally important to functional software</li> <li>It has <em>lots</em> of exceptions.</li> </ol> </blockquote> <p>Please give me some pointers on how I can better improve the usability of this r...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-25T02:56:30.703", "Id": "11136", "Score": "0", "body": "What do you mean by \"operating system code\"?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-26T15:01:24.980", "Id": "11165", "Score": "0", ...
[ { "body": "<pre><code>'''create a simple setup folder for a new project\n</code></pre>\n\n<p>The recommendation is to always use \"\"\" not ''' for docstrings</p>\n\n<pre><code>Follows the guide posted at:\nhttp://guide.python-distribute.org/quickstart.html#lay-out-your-project\n\nThe structure built will match...
{ "AcceptedAnswerId": "7148", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-24T19:30:27.710", "Id": "7142", "Score": "3", "Tags": [ "python", "exception-handling", "file-system", "makefile" ], "Title": "Tips for Python build scripts?" }
7142
<p>The goal is displaying the date and time of an article in a humanized and localized way:</p> <blockquote> <pre class="lang-none prettyprint-override"><code>Yesterday 13:21 </code></pre> </blockquote> <p>or if the Swedish language parameter is set it will display:</p> <blockquote> <pre class="lang-none prettypri...
[]
[ { "body": "<pre><code>def datetimeformat_jinja(value, format='%H:%M / %d-%m-%Y', locale='en'):\n now= datetime.now()\n</code></pre>\n\n<p>Put a space after now and before =</p>\n\n<pre><code> info = None\n</code></pre>\n\n<p>Info will always be assigned something later, there is no reason to assign here.<...
{ "AcceptedAnswerId": "7150", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-25T03:41:20.930", "Id": "7147", "Score": "4", "Tags": [ "python", "datetime", "i18n" ], "Title": "Date and time of an article in a humanized and localized way" }
7147
<pre><code>var newObject = keyValuePair.Key; var originalObject = keyValuePair.Value; List&lt;ChargeBITValue&gt; bitValues = new List&lt;ChargeBITValue&gt;(); foreach (var item in originalObject.ChargeBITValues) { ChargeBITValue bitValue = new ChargeBITValue() { ChargeTypeEnumID = item.ChargeTypeEnumID,...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-26T07:19:31.480", "Id": "11154", "Score": "0", "body": "Please include the type of the `KeyValuePair<TKey,TValue>`" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-26T09:19:32.090", "Id": "11155", "S...
[ { "body": "<p>First, if you don't have it already, you need to define a common <strong>Interface</strong> that is implemented by <code>ChargeBITValue</code>, <code>ChargeMoneyValue</code>, <code>ChargeRupeeValue</code> etc (you need to adapt the interface using the actual types of your properties instead of <co...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-26T06:23:50.933", "Id": "7154", "Score": "6", "Tags": [ "c#" ], "Title": "Minimize code in c#" }
7154
<p>I have the following:</p> <pre><code>public interface IBehaviour { event EventHandler Completed; void Execute(); } public interface IBehaviourA : IBehaviour { // Some specific stuff here object A { get; set; } } public interface IBehaviourB : IBehaviour { // Some specific stuff here object...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-28T11:13:23.777", "Id": "11256", "Score": "0", "body": "You will perhaps be interested in how other projects try to handle that, I found that one: http://flit.codeplex.com/" } ]
[ { "body": "<p>If I understand it right, you would want IBehaviourA associated with property A, and IBehaviourB with property B.</p>\n\n<p>If the above is right, could you try something like:</p>\n\n<pre><code>BehaviourQueueItem&lt;T&gt; AddBehaviour() where T : IBehaviour;\n</code></pre>\n\n<p>instead of </p>\n...
{ "AcceptedAnswerId": "8402", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-26T14:02:32.860", "Id": "7159", "Score": "7", "Tags": [ "c#" ], "Title": "Creating simpler fluent interface" }
7159
<p>I'm extremely new to Java, and I had a bit of an attempt at making something that you could call lotto. I've still got a lot more to go on it, but things are becoming tedious, and I am sure there is a simpler way to do what I am doing. How can this code be changed to have less repetitive code/optimized?</p> <pre><...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-26T05:45:15.243", "Id": "11161", "Score": "3", "body": "You could do it using only one `Scanner`" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-26T05:51:32.980", "Id": "11162", "Score": "1", "b...
[ { "body": "<p>What not to do:</p>\n\n<p>Using single numbered variables that have the same function... This works but it becomes tedious as the program gets larger and more complex.</p>\n\n<p>What to do:</p>\n\n<p>-> Favor the use of \"arrays\" instead.</p>\n\n<p>Arrays are explained here for use in Java:\n<a h...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-12-26T05:42:17.600", "Id": "7160", "Score": "4", "Tags": [ "java", "beginner", "random" ], "Title": "Reduce repetitive code in Lotto simulator" }
7160