body
stringlengths
25
86.7k
comments
list
answers
list
meta_data
dict
question_id
stringlengths
1
6
<p>This exercise gave me some trouble, but I think I have a solution here that fulfils the spec. However it's very long compared to what I'm looking at on the solutions page at <a href="http://www.clc-wiki.net/wiki/KR2_Exercise_1-22" rel="nofollow">clc-wiki.net</a>. </p> <p>In the course of solving the problem I loop ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-09-25T19:00:24.723", "Id": "7471", "Score": "1", "body": "I know it's K&R but always give all functions return types. `main()` is just another (special) function and it should have an explicit return type just like any other. You _shoul...
[ { "body": "<p>Instead of reading an entire line, then finding where to break the line, I think I'd read one word, and depending on the length of the line up to that point and the length of the word, decide whether or not to write a new-line before writing that word.</p>\n\n<p>That way, the main loop would come ...
{ "AcceptedAnswerId": "5021", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-09-25T12:06:02.653", "Id": "4997", "Score": "5", "Tags": [ "c" ], "Title": "Learning C: K&R 1-22: 'fold'. Is this solution very unwieldy?" }
4997
<p>Background is <a href="https://codereview.stackexchange.com/questions/4164/can-you-recommend-what-to-prioritize-when-rewriting-this-class">this question</a> and to create something like Craigslist or olx.com i.e. classifieds advertisement webapp / site and I've basically <a href="http://montao.com.br" rel="nofollow ...
[]
[ { "body": "<p>Your imports could use some cleanup, you import that same thing a few different times. I also suspect you aren't using some of the stuff you are importing, so yeah I suggest some effort to clean that up.</p>\n\n<p>Your indentation is messed up on here, making it harder to read. Probably a copy/pas...
{ "AcceptedAnswerId": "5004", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-09-26T10:58:09.410", "Id": "5002", "Score": "2", "Tags": [ "python", "google-app-engine" ], "Title": "Modularizing this file to make it more convenient and more readable" }
5002
<p>My first jQuery plugin is working, but I wonder if my coding is conventional. What can I do better and how can I make it more efficient?</p> <p>I know it's only a small plugin, so efficiency is not a big deal, but I don't want to start with bad habits.</p> <p>What this plugin is doing:</p> <ul> <li>It transforms ...
[]
[ { "body": "<p>Only two small points of improvement:</p>\n\n<pre><code>var defaults = {\n title: 'Widget Title',\n load:'',\n top: '50px',\n left: '400px',\n width: '500px',\n afterLoad: function(){},\n reload:false, //if true the conte...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-09-26T15:29:47.870", "Id": "5005", "Score": "4", "Tags": [ "javascript", "performance", "jquery" ], "Title": "Transforming a div to a widget" }
5005
<p>I've written the following controller and i was looking for some input/advice on how i could go about cleaning this up or rewriting it. I feel like i'm repeating myself a lot or that there might be a better way to do this.</p> <pre><code>namespace WebUI.Controllers { [Authorize(Roles="Administrator,Registrar")]...
[]
[ { "body": "<p>Here the UI model is tightly coupled with the data structures required. Hence the need arises for transfering data from step 1 to step 2 etc. \nInstead the data structures should be based on business objects required - e.g. Person object with nested objects like social security info, personal info...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-09-26T17:49:05.933", "Id": "5006", "Score": "4", "Tags": [ "c#", "asp.net-mvc-3", "controller" ], "Title": "Need help with cleaning up this Controller" }
5006
<p>I previously asked for a review at <a href="https://codereview.stackexchange.com/questions/2669/code-review-count-to-target-with-javascript/2680#2680">Count to target with JavaScript</a>, and it was a great help. I'm now looking for comments on the extended version. This code very simply counts in the direction of a...
[]
[ { "body": "<pre><code>&lt;!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01//EN \"http://www.w3.org/TR/html4/strict.dtd\"&gt; \n&lt;html&gt; \n&lt;head&gt; \n &lt;title&gt;Count to a particular target&lt;/title&gt; \n&lt;/head&gt; \n&lt;body&gt; \n&lt;h1 id=\"myDiv\"&gt;Starting&lt;/h1&gt; \n&lt;script type=\"text/...
{ "AcceptedAnswerId": "5014", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-09-26T21:32:07.710", "Id": "5008", "Score": "1", "Tags": [ "javascript" ], "Title": "Count to target with javascript extended" }
5008
<p>This is a JUnit asserts for this function: </p> <pre><code> assertEquals(0, obj.generateListSize(0)); assertEquals(1, obj.generateListSize(1)); assertEquals(1, obj.generateListSize(2)); assertEquals(3, obj.generateListSize(3)); assertEquals(3, obj.generateListSize(4)); assertEquals(5, obj.gen...
[]
[ { "body": "<p>This looks like a very arbitrary function to me. \nI'm wary of long lists of <code>if</code>-statements, but if the function is indeed arbitrary, I don't know how to improve that.</p>\n\n<p>FWIW I'd move the <code>else if (10 &lt; listSize)</code> up, to make it the second conditional. That way th...
{ "AcceptedAnswerId": "5016", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-09-27T08:33:03.583", "Id": "5011", "Score": "6", "Tags": [ "java", "unit-testing" ], "Title": "Simple function in Java" }
5011
<p>I started creating a Dictionary class that accepts objects as there keys:</p> <pre><code>class Dictionary implements ArrayAccess { private $_keys = array(); private $_values = array(); public function offsetExists( $key ) { return false !== array_search( $key, $this-&gt;_keys, true...
[]
[ { "body": "<p>First, I do have to say that you look like you are re-inventing the wheel. You can get all of that with <a href=\"http://www.php.net/manual/en/class.splobjectstorage.php\" rel=\"nofollow\"><code>SplObjectStorage</code></a>. Since you're using <code>OutOfBoundsException</code>, you're already using...
{ "AcceptedAnswerId": "5020", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-09-27T16:27:40.907", "Id": "5018", "Score": "2", "Tags": [ "php", "optimization", "performance" ], "Title": "PHP Dictionary class accepting objects as keys" }
5018
<p>I have created an extension for unit-testing my own equality implementations. Is it a good approach in general to have such extensions for unit testing? What unit-testing extensions do you use?</p> <pre><code>public static class EqualityExtensions { /// &lt;summary&gt; /// Checks that all variat...
[]
[ { "body": "<p>It's perfectly OK. As an example <a href=\"http://sharptestex.codeplex.com/\" rel=\"nofollow\">SharpTestEx</a> is a whole library with such an extensions.</p>\n", "comments": [], "meta_data": { "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-0...
{ "AcceptedAnswerId": "5022", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-09-27T17:36:13.603", "Id": "5019", "Score": "4", "Tags": [ "c#", "unit-testing" ], "Title": "Unit testing extension for equality testing" }
5019
<p>I'm a complete beginner of <a href="http://factorcode.org/">Factor</a>, but I just managed to solved <a href="http://projecteuler.net/problem=1">Euler Problem #1</a> using it, and would love to have the code reviewed. Anything that can be improved? In particular I'm wondering if there is a cleaner or more idiomatic ...
[]
[ { "body": "<p>I'm a Factor beginner too, but I'd use the <code>zero?</code> word from <code>math</code> in the definition of <code>mult</code>:</p>\n\n<pre><code>: mult? ( x y -- ? ) rem zero? ;\n</code></pre>\n", "comments": [ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-...
{ "AcceptedAnswerId": "12917", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-09-27T20:37:53.587", "Id": "5024", "Score": "10", "Tags": [ "project-euler", "factor-lang" ], "Title": "Project Euler problem 1 in Factor" }
5024
<p>I've created a program that uses <code>System.Graphics</code> to render a simple (small) 2D scene to the screen. The problem is, for some reason, it starts to quickly accumulate memory. In fact, it goes from only 100,000K Mem to <strong>ten times that</strong> and then crashes. As expected, the frame-rate of the pr...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-09-29T19:19:07.973", "Id": "7579", "Score": "0", "body": "So you chose my response as correct, but I'm curious; what was the ultimate cause?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-09-29T20:21:36.630", ...
[ { "body": "<p>First off; Use a good memory profiler. If you can reason about why something like this is happening quickly then fine. Otherwise you are wasting time when there are plenty of great tools out there which can make your life a whole lot easier. I personally use <a href=\"http://www.red-gate.com/pr...
{ "AcceptedAnswerId": "5028", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-09-27T23:04:17.490", "Id": "5027", "Score": "3", "Tags": [ "vb.net", "memory-management" ], "Title": "My program spikes from 100,000K mem to 1,000,000K mem in a matter of minutes in my pr...
5027
<p>I had an efficiency problem like I thought and I didn't have the best solution <a href="https://stackoverflow.com/questions/7552604/should-i-merge-images-in-memory-py-or-in-view-html">here</a>.</p> <p>My solution was \$O(n)\$ and directly a more experienced member told me a solution that is \$O(1)\$, that only fetc...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-09-28T21:07:44.343", "Id": "7536", "Score": "1", "body": "the next thing you do is up to you. There isn't a defined order of how you should do things. What are your priorities? That's how you decide where you should spend your effort." ...
[ { "body": "<pre><code>class CyberFazeHandler(BaseHandler):\n\n def get_random_image(self, category):\n</code></pre>\n\n<p>I'd recommend you consider adding docstrings, to a give quick explanation what your functions are doing.</p>\n\n<pre><code> q = FileInfo.all()\n q.filter('category =', categ...
{ "AcceptedAnswerId": "5060", "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-09-28T12:15:06.907", "Id": "5032", "Score": "1", "Tags": [ "python", "performance", "google-app-engine", "facebook" ], "Title": "CyberFaze app for Facebook" }
5032
<p>This is a INSERT function. It's working... I just pulled out the function from the class, atm to try it out. And improve. I think the code is a bit messy, And I am pretty sure I can improve the code, less code, for example.. Any ideas?</p> <pre><code> $data['test'] = array('username' =&gt; 'john', ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-09-28T14:38:47.283", "Id": "7521", "Score": "0", "body": "inside the `foreach` why the comparation of `$i + 1 == $numItems` if you end up doing the same, be that comparation true or false?" }, { "ContentLicense": "CC BY-SA 3.0", ...
[ { "body": "<p>Why do you not do:</p>\n\n<p>VALUES = <code>implode(\", \", array_values($values))</code></p>\n\n<p>If you can do:</p>\n\n<pre><code>$values = array('username' =&gt; \"'john'\", \n 'password' =&gt; \"'hello'\",\n 'userlevel' =&gt; \"0\");\n</code></pre>\n\n<blockquote>\n <p>...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-09-28T14:04:01.350", "Id": "5033", "Score": "1", "Tags": [ "php", "mysql", "sql", "array" ], "Title": "Php INSERT class function" }
5033
<p>I have written a small template Viewer/Controller esque library that I would like some critiques on.</p> <p>The library is <a href="https://github.com/maniator/SmallFry/tree/f957f3609c1f108c8cd3b79e4d47a57740e85b42">located here</a></p> <p>If you are looking for where to start, check out <code>App.php</code> and <...
[]
[ { "body": "<p>Your code looks acutally great, and it has also good PHP-Doc, but I think the comments inside the methods are a bit confusing, because they have always a different writing style (sometimes uppercase, sometimes lowercase, sometimes sentences sometimes just simple words etc.), so you should cleanup ...
{ "AcceptedAnswerId": "5913", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-09-28T16:03:50.940", "Id": "5039", "Score": "32", "Tags": [ "php", "library" ], "Title": "Small PHP Viewer/Controller template" }
5039
<p>I am working on a small script for a mobile site. Is there any way to improve on the regex here? or remove it completely?</p> <pre><code>function fn_page_change(event) { event.preventDefault(); var activePage = $(".ui-active"); var newPage = $(event.target.getAttribute("href")); activePage.className...
[]
[ { "body": "<p>You will have less code if you use a regex because you need the word boundary detection that is built into regex. I'd suggest putting it in a utility function to make it cleaner and more readable:</p>\n\n<pre><code>function replaceClass(el, oldClass, newClass) {\n el.className = el.className.r...
{ "AcceptedAnswerId": "5042", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-09-28T18:32:05.163", "Id": "5040", "Score": "1", "Tags": [ "javascript", "performance", "regex" ], "Title": "Improve on Regex replacing classnames" }
5040
<p>This <a href="https://stackoverflow.com/questions/7587110/basic-user-input-string-validation">question</a> came up today on StackOverflow. I find it more unfortunate than (as some others said) idiotic. And it recalled an old function I have which I just remembered.</p> <p>I have a user.config file which has some se...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-09-28T18:54:02.977", "Id": "7529", "Score": "3", "body": "Oh my, that question you linked to just killed a part of my soul. Ouch. Your example however, I don't really have a problem with." }, { "ContentLicense": "CC BY-SA 3.0", ...
[ { "body": "<p>First, I think making it a singleton would be a mistake (singleton usually is). At best it would be extra work with zero benefit. At worst, it's a handicap, such as when/if you decide to support two top-level windows with independent settings for each.</p>\n\n<p>Second, I think I'd add a Boolean n...
{ "AcceptedAnswerId": "5043", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-09-28T18:37:20.667", "Id": "5041", "Score": "2", "Tags": [ "c#" ], "Title": "Saving settings in user.config" }
5041
<p>We have interviewees write sample code, but now we want them to modify some simple working code. I came up with the following proposal, which is a syntax-directed interpreter implemented with a table-driven finite state machine. The interpreter simply accepts whitespace-delimited text and outputs "Hello" when it see...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-09-28T19:52:39.330", "Id": "7531", "Score": "3", "body": "Not sure what this will tell you about the candidate. If you asked me to maintain it I would delete it and replace it with a Lex and Yacc file." } ]
[ { "body": "<p>If I were a candidate, I'd judge what I think the quality of your code looks like based on this simple, and I'd have some concerns:</p>\n\n<ol>\n<li>Your transition table depends on the values of the <code>Lexeme</code> <code>enum</code> not changing (say by inserting additional values). If this i...
{ "AcceptedAnswerId": "5046", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-09-28T19:42:59.860", "Id": "5044", "Score": "3", "Tags": [ "c#", "interview-questions", "state-machine" ], "Title": "Sample table-driven finite-state machine" }
5044
<p>The following code is a javascript typeOf function. We aren't here to discuss coding conventions or whether or not extending a native object like I have is kosher or not. I want to know in what cases this would fail to correctly identify an object and hopefully ways to correct it. Or is this sufficient for 99% of ca...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-09-29T05:49:41.013", "Id": "7551", "Score": "0", "body": "In this changed part: `if (o.nodeType && nodeType[o.nodeType]) { r = o.nodeType;}`, I think you mean to use: `r = nodeType[o.nodeType]`" }, { "ContentLicense": "...
[ { "body": "<p>Before evaluating something, you must first establish what the evaluation criteria are. So you must first define what \"correctly identify an object\" means.</p>\n\n<p>The ECMAScript <em>typeof</em> operator returns values as specified in ECMA-262, unfortunately they are different values to the ac...
{ "AcceptedAnswerId": "5052", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-09-29T04:42:11.410", "Id": "5051", "Score": "4", "Tags": [ "javascript" ], "Title": "Javascript typeOf" }
5051
<p>I would like a serious, blunt and cold judgement on this code. Would it be considered 'good' code? In general, is it well written? Is the design reasonable?</p> <pre><code>#include &lt;iostream&gt; // C++ IO library code to include. #include &lt;string&gt; // C++ string functions. using namespace std ; // ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-02-09T23:57:53.920", "Id": "13832", "Score": "2", "body": "Your question title is no good." } ]
[ { "body": "<p>To say the truth, it's bad code, the comments are the only good thing, though they could be better. Here are some ways to improve your code:</p>\n\n<ul>\n<li>use multiple files: the declarations of the class and functions should be in .h, while the implementation should be in a separate file, it w...
{ "AcceptedAnswerId": "5058", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-09-29T09:56:01.637", "Id": "5054", "Score": "5", "Tags": [ "c++" ], "Title": "I would like to know if the following code is 'good'" }
5054
<p>Simple question:</p> <p>What would you rather do?</p> <pre><code>public class FooRepository { public Foo GetById(int id) { Foo foo = null; using (IDataReader data = /* Get Foo's data */) { // Let the Foo object set it's own fields using the data object foo = ...
[]
[ { "body": "<p>Part of the goal for using the Repository pattern is to separate the storage from the domain. By passing the IDataReader in to a Foo object, I feel like the domain gains too much knowledge of the underlying storage mechanism.</p>\n\n<p>So, between the options listed, I prefer setting the object's...
{ "AcceptedAnswerId": "5062", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-09-29T16:51:11.833", "Id": "5061", "Score": "5", "Tags": [ "c#" ], "Title": "Recomendations on where to set an object properties (Repository Pattern)" }
5061
<p>Here is the question. From SPOJ [HS11DIVS]. Now , the problem is that my code works perfectly for small numbers. But when it comes to <strong>Large numbers</strong> , the time limit exceeds. <br>I am not getting any hint on how to make it more efficient. The code is simple enough to understand. I mean its a pretty b...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-08-18T12:01:50.183", "Id": "109222", "Score": "0", "body": "Would you please avoid making changes to the code in the question after the question has been asked? I see in the edit history that you have altered the code repeatedly. This wil...
[ { "body": "<p>First you need to correct first()</p>\n\n<pre><code>unsigned long long int first(unsigned long long int a,unsigned long long int b,int x)\n{\n // Removed b\n return a;\n} ^^^ otherwise the main loop will run through everything in the main loop (from 0).\n</code></pre>\n\n<p>Though first() ...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-09-29T18:53:42.097", "Id": "5064", "Score": "5", "Tags": [ "c", "programming-challenge", "time-limit-exceeded" ], "Title": "Time Limit Exceeds [HS11DIVS] - How to make it faster?" }
5064
<p>I'm not very experienced in test-driven development (TDD), but I'm trying to get into the groove. Here I am making a console app that creates records in a database. I bootstrapped by creating a console app and then let MSTest make a unit test for <code>Main(string [] args)</code>.</p> <p>I know I'm doing at least ...
[]
[ { "body": "<p>You should not use <code>MyEntities</code> in your unit tests. Effectively you are doing integration testing here since each test will use the database and is dependent on the data stored there.</p>\n\n<p>Instead mock out <code>MyEntities</code> or make <code>MyEntities</code> derive from an inte...
{ "AcceptedAnswerId": "5114", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-09-29T18:46:23.577", "Id": "5065", "Score": "7", "Tags": [ "c#", "unit-testing" ], "Title": "What's the right granularity for test-driven development?" }
5065
<p>I'm working on an implementation of the Double-Ended Queue as a Doubly-Linked List (for personal enrichment), and I was wondering if anyone minded taking a look at my Constructor/Destructor and Empty functions to see if I'm on the right track. It should be self-explanatory enough on it's own (I hope).</p> <pre><co...
[]
[ { "body": "<p>I would make it so that you only have one sentanal.</p>\n\n<p>Then the list is empty when head and tail point at the same object.</p>\n\n<pre><code>DeQueue::DeQueue()\n // set up the sentinels\n : head(new QueueItem()) // prefer to use initialize list.\n , tail(head) // Mak...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-09-29T19:27:26.673", "Id": "5067", "Score": "7", "Tags": [ "c++", "queue", "memory-management" ], "Title": "Double-Ended Queue - Have I over-engineered it again?" }
5067
<p>I've been spending a lot of time reading about JavaScript lately, and this is my first piece code that I've tried to apply some of what I've read to. I'm trying to stay clear of using a framework for this so I can have a better understanding of the JavaScript language itself. </p> <p>This code is part of a chrome...
[]
[ { "body": "<p>From a best practices standpoint, more comments will go a long way. Also the use of consistent camelCase is good and appreciated. One good practice which is pretty easy to implement is to declare all your variables at the start of the scope / function.</p>\n", "comments": [], "meta_data": ...
{ "AcceptedAnswerId": "5203", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-09-29T19:41:24.013", "Id": "5068", "Score": "11", "Tags": [ "javascript", "html", "dom" ], "Title": "Application that creates a toolbar to show/hide elements on a page" }
5068
<p>I'd like to get some feedback on a PHP Database Abstraction Layer I've created. It's a little long, but there really wasn't a way to just post part of it. Here is the base <code>DBObject</code> class for MySQL:</p> <pre><code>&lt;?php /** * Description: The DBObject class is the generic database object. It is not ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-09-30T02:09:03.757", "Id": "7594", "Score": "0", "body": "Well, what benefit does this have over the major ORM systems (Or PEAR DB_Object if we want something closer to your implementation)?" }, { "ContentLicense": "CC BY-SA 3.0",...
[ { "body": "<p>Ok, it's a huge work, so, I'll try to do this by iteration, adding then when I've a little time.</p>\n\n<p>I'll start with the form.</p>\n\n<p><strong>Iteration 1</strong><br>\n<em>Readability:</em></p>\n\n<p>Thereafter is the code with some improvements about it's readability.</p>\n\n<p>I've limi...
{ "AcceptedAnswerId": "5240", "CommentCount": "11", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-09-29T20:17:29.623", "Id": "5071", "Score": "12", "Tags": [ "php", "security", "pdo" ], "Title": "PHP PDO Database Abstraction Layer" }
5071
<p>I am trying to make a generic form parser for Javascript. The idea being, a developer could drop the function onto a form and sumbit via AJAX, or do something with a form besides submit it. The result will be in the same format used in a query string.</p> <p>What I have posted works, so I am basically wondering if ...
[]
[ { "body": "<p>I'd change two things. I'd start by declaring your var's in one statement like so:</p>\n\n<pre><code>function test_submit(id){\n var q=[],\n p=$(id).getElementsByTagName('SELECT');\n</code></pre>\n\n<p>Second I'd use more descriptive variable names than i, p, r, n. If you run this code...
{ "AcceptedAnswerId": "5087", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-09-30T19:18:02.937", "Id": "5085", "Score": "7", "Tags": [ "javascript" ], "Title": "Javascript form parser" }
5085
<p>Should I leave in <code>&lt;cfif reFindNoCase( "\.cfc$" , targetPage ) eq 0&gt;</code> or not?</p> <p>Direct CFC calls are flushed when the method returns. Either way, <code>onRequestEnd</code> will stop debug output from being returned for AJAX requests.</p> <p><strong>Keep If Statement</strong></p> <p>Additiona...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-04T18:01:03.970", "Id": "7774", "Score": "0", "body": "I primarily call pages for AJAX requests versus calling CFCs. Removing the conditional may cause a speed bump for edge cases, but a majority of requests will run optimal code. Nice...
[ { "body": "<p>If you're using ColdFusion 9, you can use onCFCRequest to deal with this type of issue. Which version of CF are you using?</p>\n", "comments": [ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-03T12:55:38.287", "Id": "7682", "Score": "0", ...
{ "AcceptedAnswerId": "5112", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-09-30T19:27:09.363", "Id": "5086", "Score": "4", "Tags": [ "coldfusion", "cfml" ], "Title": "Should I treat direct CFC Calls differently than Page Requests?" }
5086
<p>This module makes a doubly linked list and initializes each member. I couldn't do it with a loop, so I gave up and made each node individually.</p> <p>How can I improve it? Can somebody help me make a loop to chain all these lists together? This is from a Checkers game I'm making.</p> <pre><code>#include &lt;...
[]
[ { "body": "<p>Well, <em>some</em> parts can be converted to loops pretty easily. Just for the most obvious example, your series of code like:</p>\n\n<pre><code> pListaA = LIS_CriarLista( PEC_DestruirPEC ) ;\n if ( pListaA == NULL )\n {\n return TAB_CondRetFaltouMemoria ;\n } /* if */\n</code>...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-09-30T19:44:47.577", "Id": "5088", "Score": "5", "Tags": [ "optimization", "c", "design-patterns" ], "Title": "Module for making a doubly linked list" }
5088
<p>Simply put, is this function a correct and safe way to add and/or subtract time to a <code>tm</code> <code>struct</code> (from <code>&lt;time.h&gt;</code>)?</p> <pre><code>void AddTime(int seconds, tm *date) { date-&gt;tm_sec += seconds; mktime(date); } </code></pre> <p><code>seconds</code> could be any va...
[]
[ { "body": "<p>I would add a sanity check on the pointer as well:</p>\n\n<pre><code>void AddTime(int seconds, tm* date) {\n if (date == NULL) return;\n date-&gt;tm_sec += seconds;\n mktime(date);\n}\n</code></pre>\n\n<p>But other than that it looks correct.</p>\n\n<p>Reading some <a href=\"http://www.cp...
{ "AcceptedAnswerId": "5101", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-09-30T21:38:24.903", "Id": "5089", "Score": "9", "Tags": [ "c", "datetime" ], "Title": "Adding time to struct tm" }
5089
<pre><code>def int_to_roman (integer): returnstring='' table=[['M',1000],['CM',900],['D',500],['CD',400],['C',100],['XC',90],['L',50],['XL',40],['X',10],['IX',9],['V',5],['IV',4],['I',1]] for pair in table: while integer-pair[1]&gt;=0: integer-=pair[1] returnstring+=pair[...
[]
[ { "body": "<p>Looks good. I have a few thoughts, every one of them very minor and based in opinion.</p>\n\n<ul>\n<li><p>I think it would be clearer to iterate over roms and nums instead of having pairs and having to remember which is which. This uses a Python feature called 'tuple unpacking':</p>\n\n<pre><cod...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-01T00:18:48.033", "Id": "5091", "Score": "14", "Tags": [ "python", "converting", "integer", "roman-numerals" ], "Title": "Converting Roman numerals to integers and vice versa" }
5091
<p>I've tried to create optimal in terms of performance and memmory consumption. But also I've tried to make it functional and scala way. I want to get you comment on how to make it more 'scala'stic</p> <pre><code>object LifeGame extends App { trait Matrix extends Iterable[(Int, Int)] { def apply(p: (Int, ...
[]
[ { "body": "<p>The main-things I changed:</p>\n\n<ul>\n<li>Matrix is now completely immutable</li>\n<li>Code is more self-documenting (extract complex code to methods, etc.)</li>\n<li>I deleted the unnecessary inheritance</li>\n<li>I don't like apply-methods which are used as contains-methods -> name change</li>...
{ "AcceptedAnswerId": "5099", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-01T13:04:10.517", "Id": "5097", "Score": "6", "Tags": [ "scala", "game-of-life" ], "Title": "Conway life game implementation with scala" }
5097
<p>I am using the following code to run an operation on a .dat file, which is working fine. The .dat file can be treated as a text file. My main concern is improving execution time when you have to run a <code>for</code> loop on 25 Mb of data.</p> <pre><code>$file_name='grid_10min_sunp.dat'; $handle = fopen($file_nam...
[]
[ { "body": "<p>The first thing that comes to mind is that if you expect a lot of duplicate values you can cache. So, for example, in this loop:</p>\n\n<pre><code>for($n=1;$n&lt;=$iteration;$n++) {\n $J = ($m+1)*$n; \n $P = asin(.39795*cos(.2163108 + 2*atan(.9671396*tan(.00860*($J-186)))));\n $value=(sin(0.833...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-01T15:46:17.330", "Id": "5098", "Score": "2", "Tags": [ "php" ], "Title": "Running a loop on a .dat file in a minimum possible time" }
5098
<p>I'm currently writing a mesh generator class, and I'm making a method that generates vertices, normals and texcoords for a cube. But, as you can see, it's incredibly complicated and hard to follow. Is anyone willing to help me making this shorter?</p> <pre><code>public static void GenerateCube(float size, out Vecto...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-01T23:34:57.210", "Id": "7631", "Score": "3", "body": "Well any time you see repeated code like that, it almost always means that you should throw that in a function." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": ...
[ { "body": "<p>You should consider creating a Triangle3D and Rectangle3D classes with associated operations like <code>.Transform(Matrix4 matrix)</code>. Work with these higher level classes.</p>\n\n<p><code>ninety</code> should be a global member of the class and a <code>const</code>.</p>\n", "comments": []...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-01T22:44:57.017", "Id": "5103", "Score": "8", "Tags": [ "c#", "graphics", "coordinate-system" ], "Title": "Shorten up Mesh Generator Class" }
5103
<p>Like many, I started out with procedural programming. Of course, when learning a functional language, old habits may die hard, so I wrote a fairly trivial little thing which takes an integer and returns a list of the english-language representation.</p> <p>A few days later, I re-wrote it to try to take advantage o...
[]
[ { "body": "<p>At first glance, you're trying to be a bit cute here and it's making your code more complex than necessary. For example, why not handle 11 and 12 as part of the teens and why not just type out the teen and decade names in full rather than having extra logic to append a not-quite common suffix (\"...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-01T23:44:02.647", "Id": "5104", "Score": "5", "Tags": [ "beginner", "erlang" ], "Title": "Take a number and return English language representation" }
5104
<p>Could someone please review my code? It seems too convoluted. I am just starting to learn to go from blog to hosting.</p> <pre class="lang-html prettyprint-override"><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; &lt;html xml...
[]
[ { "body": "<p>It's a start, but there are a number of things that could be improved:</p>\n\n<ul>\n<li>Your CSS and JavaScript should almost always be in separate files.</li>\n<li>Most of your CSS looks okay, but you might find it easier to read if you indented the properties.</li>\n<li>The comments between CSS ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-02T03:00:04.130", "Id": "5105", "Score": "3", "Tags": [ "optimization", "beginner", "html", "css" ], "Title": "Personal home page for a court interpreter" }
5105
<p>What follows is the first almost useful C program I've successfully written since an Intro to Programming class in college. I'm hoping to slowly maybe work my way up to Objective-C/Cocoa development, but figured I'd start by re-teaching myself the basics. I write PHP for a living, so some things, particularly pointe...
[]
[ { "body": "<blockquote>\n <p>There's one compiler warning I couldn't get rid of. The line char *tripped = tripify(argv[x]);</p>\n</blockquote>\n\n<p>This means the type you are passing is more constrained then type being used in the function.<br>\nLooking at the types we have:</p>\n\n<ul>\n<li>const char* argv...
{ "AcceptedAnswerId": "5117", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-02T11:16:20.370", "Id": "5110", "Score": "3", "Tags": [ "c" ], "Title": "Tripcode encoding" }
5110
<p>So this was inspired by: <a href="https://codereview.stackexchange.com/questions/1760/whats-your-opinion-on-a-throw-method">this question</a> But doesn't actually answer it: What do you think of:</p> <pre><code>public class Case&lt;TRes&gt; { public Case(bool condition, Func&lt;TRes&gt; result) { Co...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-02T14:04:47.433", "Id": "7639", "Score": "0", "body": "If we swap Func(T) for T, we get rid of the brackets etc, at the expense of nolonger being able to specify things to be done. (so it would be more like the trinary operator than a...
[ { "body": "<p>To be honest, it's pretty much impossible to do elegant pattern matching in a language that doesn't support it (e.g., C#). The problem with what you've written there is it's <em>more</em> complicated than the equivalent if-then-else chain:</p>\n\n<pre><code>if (IsCloudy(skyImage)) {\n ChangeWe...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-02T14:02:43.630", "Id": "5115", "Score": "3", "Tags": [ "c#", "f#" ], "Title": "Using a Function to emulate F# Match in C#" }
5115
<p>I'm working on an android application, but this is basically plain 'ole java. </p> <p>The aim is to do the right thing and not repeat myself.</p> <pre><code>public enum Datafile { ACTIVITIES() { @Override public String filepath() { return "activities.yaml"; } }, OPEN_LOOPS(...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-03T07:07:18.473", "Id": "7671", "Score": "0", "body": "where is/was your Datafile enum used, other than in getDataFile ?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-05T07:58:33.377", "Id": "7809", ...
[ { "body": "<p>Enum are a good way to do this in my opinion if this is really static.</p>\n\n<p>Might I suggest you do:</p>\n\n<pre><code>public enum Datafile {\n ACTIVITIES(\"activities.yaml\"),\n OPEN_LOOPS(\"open_loops.yaml\");\n\nprivate String filepath;\n\nprivate Datafile(String filepath) {\n this...
{ "AcceptedAnswerId": "5134", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-02T17:24:54.030", "Id": "5118", "Score": "6", "Tags": [ "java", "android" ], "Title": "Is using java enums to store filepaths good practice" }
5118
<pre><code>class HtmlLogger:ILogger,IDisposable { private System.IO.StreamWriter _file; private bool _disposed; public HtmlLogger() { _disposed = false; _file = new StreamWriter(@"somepath"); _file.Write("&lt;HTML&gt;&lt;BODY&gt;"); } public void Log(string message) ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-04T02:41:30.677", "Id": "7728", "Score": "0", "body": "You need to encode messages using HTMLEncode or some sort of message encoding to the HTML format i.e. encode <,>,/,\",',& and related symbols. There are already some methods in .NE...
[ { "body": "<p>In my opinion, you should do anything in <code>Dispose</code> except closing Objects.\nMaybe the user of your Library doesn't call <code>Dispose</code> and just sets the reference null. The closing Tags will never be written, but the starttags would. So it would be an invalid XML file, which is t...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-02T18:41:56.560", "Id": "5119", "Score": "4", "Tags": [ "c#", ".net", "stream", "logging" ], "Title": "Is calling file write in the dispose acceptable?" }
5119
<p>This simply pulls data from mysql and creates the html to be sent to the page.</p> <pre><code>class view_html extends database { function __construct($type) { parent::__construct(); switch ($type) { case "bookmraks": $this-&gt;bookmarks(); break; case "tweets":...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-02T23:33:18.320", "Id": "7660", "Score": "0", "body": "Told you you'd be better asking here :)" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-04T16:07:06.073", "Id": "7767", "Score": "0", "body...
[ { "body": "<p>Replace all usages of direct Values.\n<br/>\nTry assiging values first to a named variable and then concating it, so its sustainable in the future like:</p>\n\n<pre><code>return $pieces['scheme'] . '://www.' . $regs['domain'] . '/favicon.ico'; \n</code></pre>\n\n<p>could be:</p>\n\n<pre><code>$pr...
{ "AcceptedAnswerId": "5123", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-02T20:45:07.087", "Id": "5122", "Score": "2", "Tags": [ "php" ], "Title": "MVC Improvement - The View Module - 0 *" }
5122
<p>This class sends "tweet" data to the client in the form of a custom markup language. How can it be improved?</p> <p>It is used in Ajax call and in previous post people have suggested not to echo the result..but this is my primary means of communicating with the server via Ajax responseText.</p> <p>Also <code>&lt;...
[]
[ { "body": "<p>So, this is the PHP that causes you to have your 'aml' processing <a href=\"https://codereview.stackexchange.com/questions/5939/collection-of-ajax-methods\">here</a>.</p>\n\n<p>I think people must have confused you by saying not to echo. You are correct, you do have to communicate by printing som...
{ "AcceptedAnswerId": "5958", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-02T23:59:28.927", "Id": "5125", "Score": "2", "Tags": [ "php", "php5" ], "Title": "class - tweet - 0 - to_do" }
5125
<p>I have an application that has a lot of very complex objects that in most cases I only need to access an id value and a name value from. I'd like to reduce the overhead of serializing these large objects to JSON. This is a simple function I created that takes an array of objects and returns an array of structures t...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-03T06:59:29.877", "Id": "7670", "Score": "0", "body": "I do not see the code to review. To ask a question, there is a http://stackoverflow.com site" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-03T10:23:5...
[ { "body": "<p>Ryan,</p>\n\n<p>Here's how I would do it. Since you're making something backwards compatible with CF8, which does not explicitly have the 'Local' scope, and you've already declared it via the 'var', then we'll put all other function local variables within this struct, and only return that which is...
{ "AcceptedAnswerId": "5140", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-03T02:28:23.343", "Id": "5127", "Score": "2", "Tags": [ "coldfusion", "cfml" ], "Title": "Simple function to turn array of objects to array of key value pairs" }
5127
<p>Now I have a bunch of these methods ( you can tell how ugly it looks like):</p> <pre><code>void ConvertUtility::ConvertEdgeIndexList(const list&lt;EdgeIndex&gt; &amp;edgeIndex) { list&lt;EdgeIndex&gt;::const_iterator sit; for(sit=edgeIndex.begin(); sit!=edgeIndex.end(); sit++) { } } void Con...
[]
[ { "body": "<p>How about:</p>\n\n<pre><code>template&lt;typename C&gt;\nvoid ConvertUtility::ConvertEdgeIndexList(C const&amp; edgeIndex)\n{\n typename C::const_iterator sit;\n for(sit=edgeIndex.begin(); sit!=edgeIndex.end(); ++sit)\n { // ^^ Prefer pre-inc...
{ "AcceptedAnswerId": "5130", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-03T03:08:18.253", "Id": "5129", "Score": "10", "Tags": [ "c++" ], "Title": "How to write a method that takes a general iterator as input argument?" }
5129
<p>I'm trying to get my head in the Scala game, and would welcome feedback on the following code, which produces a table from data.</p> <pre><code>class TabulatorTest extends FunSuite with ShouldMatchers { test("format") { Tabulator.format(List( List("head1", "head2", "head3"), List("one", "two", "t...
[]
[ { "body": "<p>I can't help a lot. Only some syntactic hints:</p>\n\n<pre><code>object Tabulator {\n\n def format(table: Seq[Seq[Any]]) =\n if (table.isEmpty) \"\"\n else {\n def cellSize(cell: Any) =\n cell.toString.length\n\n val cellSizes =\n table map { _ map cellSize }\n ...
{ "AcceptedAnswerId": "5147", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-03T12:49:25.940", "Id": "5138", "Score": "2", "Tags": [ "scala" ], "Title": "Formatting as a table in Scala" }
5138
<p>Due to software constraints, I cannot use the standard libraries, <code>&lt;math.h&gt;</code>, <code>&lt;algorithm&gt;</code>, templates, <code>inline</code>, or Boost. I am also using standard C (ISO C99) such that <code>array</code> is not a reserved keyword like it is in Visual Studio.</p> <p>Is this the "best" ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-03T18:34:36.913", "Id": "7693", "Score": "0", "body": "Can you elaborate a bit on the software constraints you have to work within? I can understand not using boost but not allowing math.h, algorithms, and templates either? That's ruli...
[ { "body": "<p>It's not quite the best. There's some things IMHO that is hindering its performance and usefulness.</p>\n\n<p>There's no point in declaring <code>val</code> as a static variable. In fact, you've killed any chance of it being usable in multi-threaded programs.</p>\n\n<p>The body of the loop is pe...
{ "AcceptedAnswerId": "5146", "CommentCount": "12", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-03T16:33:07.643", "Id": "5143", "Score": "13", "Tags": [ "c++", "algorithm", "array", "reinventing-the-wheel" ], "Title": "Min / Max function of 1D array in C / C++" }
5143
<p>This week-end, I finally found some time to learn unit testing (it's about time, I know).<br> So I've tried to do this in PHP, with <a href="http://www.phpunit.de/manual/current/en/" rel="nofollow">PHPUnit 3.6</a>.</p> <p>I've wrote a small, simple and useless <a href="https://github.com/G-Qyy/Qyy.G.en.PHP.File" re...
[]
[ { "body": "<p>All in all, it looks like you're off to a great start. I'm going to skip around a bit in what I recommend however there are definitely a few things that could be cleaned up.</p>\n\n<pre><code>public function testNewObject3 ()\n{\n // I'm not sure you can define what the exception should\n /...
{ "AcceptedAnswerId": "5239", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-03T07:55:59.363", "Id": "5154", "Score": "4", "Tags": [ "php", "unit-testing" ], "Title": "Reviewing my unit testing (in PHP)" }
5154
<p>I'm very much a beginner and have put together some JavaScript to control a pair of radio buttons which essentially behave as links.</p> <p>I'm doing this as sort of a self-initiated project, or bit of fun. I know I don't have to use radio buttons, but it's something I just wanted to do.</p> <p>It simply checks th...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-04T10:19:28.523", "Id": "7832", "Score": "0", "body": "Have you looked at JQuery? You could probably right this in two or three lines of code..." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-04T10:43:38.1...
[ { "body": "<p>You could probably start by <a href=\"http://en.wikipedia.org/wiki/Indent_style\" rel=\"nofollow\">indenting</a> your code.</p>\n\n<p>My Javascript is a bit rusty, but I would suggest you to rewrite your code so it uses only one function with parameters, instead of 8 functions which all do pretty ...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-04T09:17:20.647", "Id": "5156", "Score": "3", "Tags": [ "javascript", "beginner", "html", "event-handling" ], "Title": "Mouseover effect for radio buttons" }
5156
<p>It always bugged me that you would have to write your private class members inside the header files in C++. This means that everytime you change you implementation, client code has to be rebuild.</p> <p>I found thise site which describes how to hide implementation detail in C++: <a href="http://www.octopull.demon.c...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-04T15:49:22.887", "Id": "7762", "Score": "0", "body": "What you are re-inventing here in PIMPL." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-04T16:14:37.893", "Id": "7769", "Score": "0", "bod...
[ { "body": "<blockquote>\n <p>Is the use of preprocessor macros justified here?</p>\n</blockquote>\n\n<p>To me it seems like overkill. The only non-trivial macro is <code>TL_UTILS_IMPL_START</code>, and that will almost certainly never be useful - usually, the <code>impl</code> class won't need a back-pointer t...
{ "AcceptedAnswerId": "5210", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-04T11:19:23.623", "Id": "5160", "Score": "3", "Tags": [ "c++" ], "Title": "C++: Hiding class implementation detail generic" }
5160
<pre><code>/**************************************************************** VIEW MODULE view, view_database, view_message view_arche_1 (external), view_arche_2 (external) - these are primarily html files ****************************************************************/ /*view*/ class view extends database { ...
[]
[ { "body": "<p>Some random observations:</p>\n\n<ul>\n<li>What does your base class <code>database</code> do? I hope not the stuff it sounds like. Your aim is to separate storage and view logic, not add view logic to your database.</li>\n<li>Having both static and non-static functions in a class should make you ...
{ "AcceptedAnswerId": "5199", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-04T15:42:57.860", "Id": "5173", "Score": "3", "Tags": [ "php" ], "Title": "MVC Improvement - The View Module - 1" }
5173
<p>Due to software constraints, I cannot use the standard libraries, <code>math.h</code>, <code>algorithm</code>, templates, inline, or boost. I am also using standard C (ISO C99) such that array is not a reserved keyword like it is in Visual Studio.</p> <p>I need to duplicate the <a href="http://www.mathworks.com/hel...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-04T19:06:43.727", "Id": "7781", "Score": "0", "body": "So I already recommend that `const int N` should be a `size_t`" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-04T19:51:34.770", "Id": "7787", ...
[ { "body": "<p>Depending on how you compiler implements it.<br>\nIt may potentially be faster to allcoate a block of zero memory and compare it (This of course will be platform dependent). Some instruction sets allow all the following to be done in one op code (each line). But of course any speed improvements yo...
{ "AcceptedAnswerId": "5208", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-04T19:06:18.157", "Id": "5178", "Score": "3", "Tags": [ "c++", "c", "algorithm", "reinventing-the-wheel" ], "Title": "Matlab any function in C / C++" }
5178
<p>So I've been thinking alot about simple/convenient ways to implement simple 2D animation using a bare-bones graphics library I'm using for school (Animation is way out of the scope of the class, I'm just experimenting.)</p> <p>I thought of using a custom function passed to the class to allow the "user" of the code ...
[]
[ { "body": "<p>Too simple? Hardly. That is pretty much a textbook implementation of animation using a callback-based event model. In a production-grade version there would be a few extra null checks and similar to check for programming mistakes, but the basic implemation could be very similar.</p>\n<p>I'm assumi...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-04T20:39:03.993", "Id": "5181", "Score": "5", "Tags": [ "c++" ], "Title": "Animation using function pointers" }
5181
<pre><code>[Bindable] public class ProductsCache { private static var _products:ArrayCollection; public function get products():ArrayCollection{ return _products; } public function set products(value:ArrayCollection):void{ _products = value; } } </code></pre> <p>By the name of the ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-05T07:06:27.797", "Id": "7808", "Score": "0", "body": "Feedback on what? If you should use static variables? If you should do it like that?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-05T14:25:14.683", ...
[ { "body": "<p>Using a static variable will have the same effect as using a singleton!</p>\n<p>Imagine if you had two instances of <code>ProductsCache</code>:</p>\n<pre><code>var a: ProductsCache = new ProductsCache();\nvar b: ProductsCache = new ProductsCache();\na.products = someArrayCollection;\nb.products = ...
{ "AcceptedAnswerId": "49362", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-04T22:43:54.507", "Id": "5184", "Score": "7", "Tags": [ "actionscript-3", "static" ], "Title": "Getting and setting a static variable" }
5184
<p>I wanted to have a python container in which every element is a key (like in a set), but still supports mapping (like a dict) between the elements. To get a container which supports this idea the elements have to be unique like in a set and the mapping between the elements has to be bidirectional. I couldn't find su...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-06T15:59:01.470", "Id": "7851", "Score": "1", "body": "The example confused me a tad, given the class name and behavior of \"network\" I expected to see examples more along the lines of `friends.connect(\"James\", \"Joe\")`" }, { ...
[ { "body": "<pre><code>class network(object):\n</code></pre>\n\n<p>The python style guide recommends CamelCase for class names</p>\n\n<pre><code> \"\"\"\n A network is a container similar to a set in which\n the elements can be mapped to each other (be connected).\n The Elements in a network are call...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-04T23:26:31.897", "Id": "5185", "Score": "3", "Tags": [ "python", "performance" ], "Title": "Review for Python mapping container in which every element is a key" }
5185
<p>As I was trying to demystify the Android AsyncTask functionalities, I wrote this sample app to test it. Please review my code and suggest possible improvements:</p> <pre><code>public class AsyncTaskExampleActivity extends Activity implements OnClickListener{ private Boolean success = true; private static A...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-05-05T15:12:24.397", "Id": "86015", "Score": "0", "body": "Look at the newly inserted code if(isCancelled()){\n break;\n } in the doInBackground function. This is to ensure that the background thread does not continue to ...
[ { "body": "<ul>\n<li>If you rotate the screen, the activity will be restarted, which will restart the task as well (it might even crash because of the ProgressDialog). Eventually, I have found that only services can correctly handle long running operations. But they are more complicated to code.</li>\n<li>You d...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-05T08:26:42.733", "Id": "5191", "Score": "4", "Tags": [ "java", "android", "asynchronous" ], "Title": "AsynTask example" }
5191
<p>I have a block of text where several arrays are printed out, with a name and values:</p> <blockquote> <p>VAL1=10 20 30 40 50</p> <p>VAL2=4 8 15 16 23 42</p> </blockquote> <p>I have a function that looks for the value name, and sets an array of these values:</p> <pre><code>bool FetchValueArray(char* source, char* nam...
[]
[ { "body": "<p>I'm not quite sure what you are asking for, but I guess you are looking for a solution similar to this (not compiled nor tested):</p>\n\n<pre><code>#include &lt;stdio.h&gt; /* sscanf */\n#include &lt;stddef.h&gt; /* NULL */\n#include &lt;stdbool.h&gt; /* C99 bool type */\n\ntypedef enum\n{\n T...
{ "AcceptedAnswerId": "5194", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-05T11:01:27.000", "Id": "5192", "Score": "4", "Tags": [ "c", "array", "memory-management" ], "Title": "Array initialization from text string" }
5192
<p>The following is a function that I wrote to display page numbers as they appear in books.</p> <p>If you enter the list <code>[1,2,3,6,7,10]</code>, for example, it would return:</p> <pre><code>1-3,6-7,10 </code></pre> <p>This seemed like a nice example of how the dictionary data type can be used in Python.</p> <...
[]
[ { "body": "<p>A bit shorter version without using a dictionary:</p>\n\n<pre><code>def formatpagelist(numberlist):\n prev_number = min(numberlist) if numberlist else None\n pagelist = list()\n\n for number in sorted(numberlist):\n if number != prev_number+1:\n pagelist.append([number])...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-05T16:05:07.040", "Id": "5196", "Score": "13", "Tags": [ "python", "clustering", "interval" ], "Title": "Grouping consecutive numbers into ranges in Python 3.2" }
5196
<p>This code connects to COM 3 which has a broadband card and sends a command that returns the RSSI value. I use this program to see patterns in signal strength in certain areas.</p> <pre><code>#include &lt;Windows.h&gt; #include &lt;iostream&gt; #include &lt;string&gt; int main() { HANDLE hSerial = CreateFile("C...
[]
[ { "body": "<p>In all the test that could be an error. Do you really want to continue if there is an error?<br>\nSeems counterproductive to generate an error message and continue running. That will just generate more spurious errors.</p>\n\n<pre><code>if(hSerial==INVALID_HANDLE_VALUE)\n{\n throw std::runtime_...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-05T17:07:57.447", "Id": "5197", "Score": "3", "Tags": [ "c++", "windows", "serial-port" ], "Title": "Serial port communication app" }
5197
<p>I'm refactoring a set of classes which does some price calculations. the calculation is done based on many parameters. The code is :</p> <pre><code>public interface IParcel { int SourceCode { get; set; } int DestinationCode { get; set; } int weight{get;set;} decimal CalculatePrice(); } public abstr...
[]
[ { "body": "<p>Depending on the rest of your design, having a <code>Parcel</code> know how to calculate it's ownworth is perfectly acceptable behaviour. That said, the method of calculation is now tied directly to the parcel class itself (what happens if your local government decides that <code>ExpressParcels</...
{ "AcceptedAnswerId": "5205", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-05T19:18:26.270", "Id": "5201", "Score": "9", "Tags": [ "c#", "design-patterns" ], "Title": "best design pattern for refactoring a set of classes that do calculation base on many param...
5201
<p>I've created a simple asynchronous execution engine and I would like some help identifying places it can be improved. The basic function of the system is to monitor MSMQ and Service Broker queues and execute any tasks that come through on them. </p> <p>Here is the code: </p> <pre><code>using System; using System.C...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-07T05:19:29.277", "Id": "51658", "Score": "0", "body": "Didn't read the whole thing, but GetAsync() is not a good name for that method IMO." } ]
[ { "body": "<ol>\n<li><p><code>GetAsync</code> is a bad name for that method. <code>StartListening</code> seems to express better what it does.</p></li>\n<li><p><code>AsyncLaunch</code> is a bad name for that enum. It seems to describe which target should be listened to so why not call it <code>ListenTarget</cod...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-05T21:06:58.647", "Id": "5204", "Score": "6", "Tags": [ "c#", ".net" ], "Title": "Trying to create a robust task execution engine" }
5204
<p>As a disclaimer, this is the first function I have <em>EVER</em> written in Lisp or ELisp. Please, bash it as much as you would any other piece, but don't judge me for it please! :)</p> <p>So, I realized I wanted a way to rename files without all the hassle of reopening the file etc. I googled and found a function ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-31T04:53:45.040", "Id": "53767", "Score": "0", "body": "Do not use `concat` to build absolute file names. Use `expand-file-name`: `(expand-file-name dir-name new-name)`. That way, Emacs handles file names for different systems automa...
[ { "body": "<p>Judgment circuits deactivated; you have nothing to fear.</p>\n\n<p>I was going to suggest that there must already be a function that you can call to force <code>uniquify</code> a buffer, but <code>M-x apropos RET ^uniq</code> doesn't show any documented functions that would do that for you (take a...
{ "AcceptedAnswerId": "7969", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-06T08:55:07.427", "Id": "5207", "Score": "8", "Tags": [ "elisp" ], "Title": "ELisp function to allow file renaming in Emacs" }
5207
<p>Due to software constraints, <strong>I cannot use the standard libraries, <code>cmath</code>, <code>algorithm</code>, templates, inline, or boost</strong>. I am also using standard C (ISO C99) such that array is not a reserved keyword like it is in Visual Studio.</p> <p>Here is the custom <strong>sine, pow and fact...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-06T18:58:13.420", "Id": "7855", "Score": "0", "body": "Explanation for -1? I don't see a duplicate question, code formatted correctly, and problem statement clearly defined." }, { "ContentLicense": "CC BY-SA 3.0", "Creation...
[ { "body": "<p>Not being able to use the standard libraries suggests you are doing embedded work. A more typical approach for calculating sine in that situation would be to:</p>\n\n<ul>\n<li>Translate angles from a 360 degree system to a 256 degree system;</li>\n<li>Store sine values for all 256 possible degree...
{ "AcceptedAnswerId": "5562", "CommentCount": "11", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-06T18:52:06.267", "Id": "5211", "Score": "15", "Tags": [ "c++", "c", "mathematics", "reinventing-the-wheel", "floating-point" ], "Title": "Sine function in C / C++" }
5211
Branch of mathematics that studies triangles and the relationships between their sides and the angles between these sides.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-06T18:52:57.530", "Id": "5213", "Score": "0", "Tags": null, "Title": null }
5213
<p>I'm working on a small program to add or remove certain entries from the Windows registry, and I'm getting all tangled up in IF and TRY conditions. I've spent hours chasing bugs, usually logical ones, trying to accomplish what is conceptually very simple. The more I work on and "improve" the code so that it works in...
[]
[ { "body": "<pre><code>def remove():\n ''' see if any existing registrations match our python version and register ours if not '''\n\n if CurrentUser:\n</code></pre>\n\n<p>The python style guide reserves CamelCase for class names. If this is a global constant it should be CURRENT_USER. If its not a global ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-06T23:42:53.520", "Id": "5217", "Score": "3", "Tags": [ "python" ], "Title": "All tangled up in IF and ELIF and TRY" }
5217
<p>I'm trying to implement my own A* pathfinder, but the voices in my head scream of better ways to do this. Probably because I'm exceeding Python's default maximum recursion depth of 1000.</p> <pre><code>class PathFinder(): ## grid is a list of 8 sub-lists, each containing 8 nodes. ## start and goal are tup...
[]
[ { "body": "<p>Note: this is a fair distance from being an A* algorithm - perhaps correctly implementing a recursive depth-first search (what your algorithm is currently closest too) would be a good start.</p>\n\n<p>You're right, you should be able to calculate a path through an 8x8 without exceeding the recursi...
{ "AcceptedAnswerId": "5221", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-07T03:27:40.240", "Id": "5219", "Score": "5", "Tags": [ "python" ], "Title": "How can I improve my A* algorithm in Python?" }
5219
<pre><code> internal void ShiftSwapInstrument(SwapCurve shiftedCurve, string swapToShift) { if (SwapExists(shiftedCurve, swapToShift)) { var rateToShift = shiftedCurve.Swaps.Single(r =&gt; r.Description() == swapToShift); rateToShift.Rate = rateToShift.Rate + 1 / 10000.0; return; } ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-07T09:33:01.973", "Id": "7882", "Score": "0", "body": "Your code looks too complicated, look to shorter version in my answer, doing exaclty the same." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-07T09:38...
[ { "body": "<p>Your error handling looks correct to me as long as your application is <code>catch</code>ing <code>PdhSwapRateNotFoundException</code> at some point and logging appropriate warning/error to notify user about this.</p>\n\n<p>A slight cosmetic modification to your code could be like:</p>\n\n<pre><co...
{ "AcceptedAnswerId": "5224", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-07T07:38:29.727", "Id": "5223", "Score": "3", "Tags": [ "c#", "exception-handling" ], "Title": "Is my error handling feasible when dealing items not found in an array?" }
5223
<p>In a homework, there is an exercise in which I have a script that is used to search for a password.</p> <p>One of the questions is if is possible to make it "more intelligent", and I'm stuck on it.</p> <pre><code>#!/bin/bash space1="a b c d e f g h i j k l m n o p q r s t u v w x y z" if [ $# -le 1 ] then ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-09T08:16:25.243", "Id": "7954", "Score": "1", "body": "As suggested, you could use common words first or a dictionary, but brute force is brute force. In this case it's only 3 lower case characters, so it should take no time at all. I ...
[ { "body": "<p>There's no real way to speed up the brute-force enumeration of all possible 3-letter passwords. </p>\n\n<p>Perhaps you could use the dictionary. There's a finite list of 3-letter English words. They may be slightly more common.</p>\n\n<p>Also, if you google for \"most common passwords\", some...
{ "AcceptedAnswerId": "5235", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-07T10:42:34.757", "Id": "5226", "Score": "7", "Tags": [ "security", "homework", "bash", "openssl" ], "Title": "Making this password search more intelligent" }
5226
<p>HTML is a markup language similar to <a href="http://stackoverflow.com/tags/xml/info">XML</a> that is predominantly used to create web pages.</p> <p>HTML standards, as well as those for many other web technologies, are maintained by the <a href="http://www.w3.org/" rel="nofollow">World Wide Web Consortium</a> (W3C)...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-07T13:40:16.310", "Id": "5227", "Score": "0", "Tags": null, "Title": null }
5227
HTML (Hyper Text Markup Language) is the standard content markup language of the web. It is an open standard developed and maintained by W3C (World Wide Web Consortium).
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-07T13:40:16.310", "Id": "5228", "Score": "0", "Tags": null, "Title": null }
5228
<pre><code>def range_find(pageset,upperlimit=1000): pagerangelist=[] for page in range(0,upperlimit): if page in pageset and previouspage in pageset:pagerangelist[-1].append(page) elif page in pageset and not (previouspage in pageset):pagerangelist.append([page]) else: pass p...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-07T15:22:11.620", "Id": "7898", "Score": "0", "body": "(a) Your indentation is wrtong. (b) You didn't reference the previous version of this question. (c) You didn't include the output from your test. (d) You didn't test the `[1, 2,...
[ { "body": "<pre><code>def range_find(pageset,upperlimit=1000):\n\n pagerangelist=[]\n\n for page in range(0,upperlimit):\n</code></pre>\n\n<p>There is no reason to include the 0. Why don't you calculate the upperlimit by max(pageset)?</p>\n\n<pre><code> if page in pageset and previouspage in pagese...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-07T15:07:41.950", "Id": "5229", "Score": "1", "Tags": [ "python" ], "Title": "Grouping consecutive numbers into ranges in Python 3.2 : New version for set" }
5229
<p>Useful sites to improve your code if you're new to node:</p> <ul> <li><a href="http://nodemanual.org/latest/" rel="nofollow">nodemanual</a> - a collaborative effort the node community. Also acts has a handy meta reference for the API and Mozilla's canonical Javascript Reference/</li> <li><a href="http://docs.nodeji...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-07T16:18:56.270", "Id": "5232", "Score": "0", "Tags": null, "Title": null }
5232
Node.js is an event based, asynchronous I/O framework that uses Google's V8 JavaScript engine. Node.js is commonly used for heavy client-server JavaScript applications.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-07T16:18:56.270", "Id": "5233", "Score": "0", "Tags": null, "Title": null }
5233
<p>I'm wondering if there is a simplier regex I could use in my code to remove the beginning and ending char in a line. Maybe combine some regex's? In this instance, it's a comma at the beginning and ending of a line. My output should be the fields seperated into CSV format.</p> <pre><code>#!/usr/local/bin/perl use s...
[]
[ { "body": "<p>I don't know of a tricky regexp, but wouldn't you be better served by creating the string using a combination of split and join?</p>\n\n<p><a href=\"http://perldoc.perl.org/functions/split.html\" rel=\"nofollow\">http://perldoc.perl.org/functions/split.html</a></p>\n\n<p>The examples in the middle...
{ "AcceptedAnswerId": "24592", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-07T16:33:23.530", "Id": "5234", "Score": "5", "Tags": [ "performance", "perl", "regex" ], "Title": "Best way to replace a beginning and end character in Perl using Regular Express...
5234
<p>I don't actually know much about how base32 (or base64) works, but I noticed that there was no official base32 implementation in PHP, so I figured I'd make one.</p> <p>I Googled around a bit to figure out how it works, and found <a href="http://www.garykessler.net/library/base64.html" rel="nofollow">this page</a>. ...
[]
[ { "body": "<p>Your constructor going through all the work to build both alphabets and then throwing one away seems odd. I'd probably have a Base32 base class, and have the two alphabets be subclasses.</p>\n\n<p>Using the binary conversion does seem problematic. This is especially true since the numbers are alre...
{ "AcceptedAnswerId": "5403", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-07T17:32:52.900", "Id": "5236", "Score": "3", "Tags": [ "php", "algorithm" ], "Title": "base32 implementation in PHP" }
5236
<p>If I had many different Models that could all, through logic encapsulated by an adapter, produce items of type T, then I might maintain a producer/consumer component through the techniques demonstrated in the code.</p> <p>When I came up with this, it seemed novel to overlay a producer onto a linked list - the refle...
[]
[ { "body": "<p>I think you have unclear vision of what the design patterns are.</p>\n\n<p>Patterns are an idea (design pattern) or code (code pattern) proven by its effectiveness and adopted for usage and proven by practice behavior.</p>\n\n<p>If this is a method, than you have a very strange vision of what the ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-07T19:42:13.010", "Id": "5237", "Score": "5", "Tags": [ "c#", "design-patterns" ], "Title": "What do you think of this chained producer/consumer/adapter (pattern?)" }
5237
<p>I wrote this palindrome extractor. And even though it works, and I can solve the challenge with it, it feels very Java-like. I was wondering what adjustments I could make in order for it to be more functional.</p> <pre><code>import collection.mutable._ object Level1 { def palindrome(input:String) = input.reve...
[]
[ { "body": "<p>Here's a general idea about how I'd probably approach the problem:</p>\n\n<pre><code>def extractPalindromes(input:String) = \n{\n var minLength = 4;\n val palindromes = new ListBuffer[String]()\n if (palindrome(input)) palindromes += input\n if (input.length &gt; minLength) {\n ...
{ "AcceptedAnswerId": "5245", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-07T21:19:55.653", "Id": "5241", "Score": "7", "Tags": [ "scala", "palindrome" ], "Title": "More functional way of writing this palindrome extractor?" }
5241
<p>Basically, I made a simple app for my Android, where it picks a random question for you, and picks specific answers. Only 1 of the answers is correct, while other's aren't.</p> <p>Also, after editing the <code>QBegin</code> method, it started to give me questions but with wrong answers.</p> <pre><code>TextView qu...
[]
[ { "body": "<p>The (or at least \"One\") obvious approach would be to move most of your data into arrays, and just use the numbers to select values from those arrays. For example:</p>\n\n<pre><code>private void QBegin() {\n question = (TextView) findViewById(R.id.question);\n String[] types = { \"Question ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-07T21:39:21.413", "Id": "5242", "Score": "7", "Tags": [ "java", "android", "random" ], "Title": "Random Q&A system" }
5242
<pre><code>def range_find(pageset): pagerangelist=[] for page in list(pageset): if page in pageset and page-1 in pageset:pagerangelist[-1].append(page) elif page in pageset and not (page-1 in pageset):pagerangelist.append([page]) pagerangestringlist=[] for pagerange in pagerangelist...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-08T00:20:51.897", "Id": "7918", "Score": "0", "body": "why so many versions? and why haven't you learned to format your posts correctly yet?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-08T01:10:26.143",...
[ { "body": "<pre><code>def range_find(pageset):\n\n pagerangelist=[]\n\n for page in list(pageset):\n</code></pre>\n\n<p>There is no point in listifying the set just to iterate over it. I think you meant <code>for page in sorted(pageset)</code> to get access to the page in sorted order.</p>\n\n<pre><code> ...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-07T23:01:16.693", "Id": "5247", "Score": "1", "Tags": [ "python" ], "Title": "Grouping consecutive numbers into ranges in Python 3.2; third version (accepts page numbers as an unsorted set)"...
5247
<p>I deal with hundreds and hundreds of names each week. These names (along with other pedigree information) are stored in a database. Typically, I get these names in all sorts of formats, mainly proper and in all-caps. I needed an easy way to convert the names (especially last names) to their proper format:</p> <ul> ...
[]
[ { "body": "<pre><code>public string ConvertToProperNameCase(string input)\n{\n bool SuffixProcessed = false;\n</code></pre>\n\n<p>You don't use this variable for a long time, move it closer to where it is used.</p>\n\n<pre><code> input = input.Trim();\n\n if (String.IsNullOrEmpty(input))\n {\n ...
{ "AcceptedAnswerId": "5250", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-07T23:32:32.270", "Id": "5248", "Score": "5", "Tags": [ "c#" ], "Title": "Name proper casing" }
5248
<p>What would you do to improve upon this boilerplate empty stored procedure, being mindful of the delicate balance between length, complexity, performance and clarity?</p> <pre><code>-- ============================================= -- Author: The usual suspects -- Create date: 10/06/2011 -- Description: -- -- ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-07T07:55:44.070", "Id": "7942", "Score": "3", "body": "I totally agree with the suggestion not to fiddle about with transaction logic in stored procedures. The main reason for this is that if you write a procedure to be agnostic about...
[ { "body": "<p>All in all it’s a good idea. Have you considered moving your <code>crlf</code> and <code>CATCH</code> logic; or a portion of it; to a reusable function? This would help ensure; wherever it’s used; that it remain consistent and you don’t have the same code all over the place.</p>\n", "comments"...
{ "AcceptedAnswerId": "6979", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-07T07:19:56.580", "Id": "5256", "Score": "10", "Tags": [ "sql", "sql-server", "error-handling" ], "Title": "SQL Server stored procedure boilerplate" }
5256
<p>Please give me any comment about these codes. Does it enough to prevent SQL injection? What I have to do to make the code better?</p> <pre><code>&lt;?php /** * Description of MySql * @name MySQL PDO * @version 1.0 * @author Yauri * */ class MySql { private $mPDO; ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-09T09:36:24.463", "Id": "7955", "Score": "0", "body": "Btw. a little description of what you expect from the code review would not hurt." } ]
[ { "body": "<ul>\n<li>Your <code>BuildInsert</code>-method is the only one which uses <code>mysql_real_escape_string</code>. Why? Why not just use parametrized queries like in your \"select\", \"update\" and \"delete\" cases?</li>\n<li>Your <code>query</code> method uses a variable <code>$data</code> which is no...
{ "AcceptedAnswerId": "5263", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-09T07:50:27.403", "Id": "5262", "Score": "2", "Tags": [ "php", "mysql", "pdo" ], "Title": "MySQL PDO class" }
5262
<p>The following function accepts a list of <code>Topic</code> entities, retrieved from a database using LINQ-to-Entities. Each Topic has an <code>Id</code>, <code>Title</code> and <code>ParentId</code>. </p> <p>I want to populate an ASP.NET TreeView control, and so the function is creating a hierarchy of the Topics ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-10-08T13:25:56.390", "Id": "119320", "Score": "0", "body": "Any final _solution_ with **full source code** sample application ? _IMHO, better samples for minimize learning curve are real applications with full source code and good pattern...
[ { "body": "<p>Just a word of advice, creating a mutable struct which is <em>always</em> a bad idea. It <em>must</em> be a class otherwise you're just leaving yourself open to problems and confusion.</p>\n\n<p>You could improve it much more if you don't restrict your methods to use lists of topics. You could t...
{ "AcceptedAnswerId": "5293", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-09T13:32:17.443", "Id": "5265", "Score": "8", "Tags": [ "c#", ".net", "asp.net", "linq" ], "Title": "Creating a TreeNode hierarchy in C#" }
5265
<p>I wrote a Python method to convert an object and a subset of its attributes into a JSON string with a given field as the key.</p> <p>There's a lot of string concatenation, and I'm not too sure what the best way to do that in Python is.</p> <p>I'm also wondering if <code>attr.replace('"','\"')</code> is sufficient ...
[]
[ { "body": "<p>Firstly, python includes a json module. Use that rather then writing your own.</p>\n\n<p>However, just to give some comments on your style:</p>\n\n<pre><code>def to_json_with_key(nodes, key, fields, insertIndex=False):\n</code></pre>\n\n<p>python recommend words_with_underscores for parameter name...
{ "AcceptedAnswerId": "5267", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-09T17:01:44.690", "Id": "5266", "Score": "2", "Tags": [ "python", "converting", "json" ], "Title": "Converting an object into a JSON string" }
5266
<p>I have this class hierarchy. I want to apply generics to it but don't know how to do. AddWikiTask, ScanTask and RescanTask are subclasses of AbstractWorkerTask. DictionaryScanner has 3 functions to check if all tasks finish. How to prevent duplicate code in 3 those functions?</p> <p>This is class hierarchy</p> <pr...
[]
[ { "body": "<p>You can take the common code in the functions in <code>DictionaryScanner</code> out into a common method:</p>\n\n<pre><code> public boolean didAllRescanTasksFinish() {\n didAllXTasksFinish(rescanTasks);\n }\n\n private boolean didAllXTasksFinish(List&lt;AbstractWorkerTask&gt; tasks...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-09T20:16:28.117", "Id": "5268", "Score": "1", "Tags": [ "java" ], "Title": "Use generic to prevent duplicate code in this case" }
5268
<p>I've written an algebraic notation to use for moves in a game and I'm currently writing code to parse the information from the notation. I'm doing this using regExes. This is coded in HaXe.</p> <p>For example, two functions in the parser would look like this:</p> <pre><code>public function getMoveType(gameText:S...
[]
[ { "body": "<p>The use of regular expressions is an implementation detail.</p>\n\n<p>I think you should continue to structure your API as functions that take a higher level input, such as a game text, and destructure it into the end product that your API's clients want.</p>\n\n<p>That said, you can define a priv...
{ "AcceptedAnswerId": "5271", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-10T00:37:57.723", "Id": "5270", "Score": "3", "Tags": [ "regex", "haxe" ], "Title": "Algebraic notation with RegEx" }
5270
<pre><code>#!/bin/bash # Used to add/remove printers from system (lp) # Copyright Fresh Computer Systems Pty Ltd. GREP_OPTIONS='--color=tty' export GREP_OPTIONS sanity() { # Are we root? if [ $EUID != '0' ]; then exitError "You must be root to run this script." 1 fi if [ ! -x /usr/sbin/lpad...
[]
[ { "body": "<p>To answer your question, yes, it can be improved, but that could be said about any piece of code, right? And perfection is in the eye of the observer, so I'll stick to the things that have proved gotchas for me, and those focus around <a href=\"https://www.gnu.org/s/bash/manual/bash.html#Condition...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-10T04:36:09.560", "Id": "5272", "Score": "3", "Tags": [ "bash" ], "Title": "bash script for printer administration" }
5272
<h1>Detecting types in JavaScript sucks</h1> <p><a href="https://stackoverflow.com/questions/4775722/javascript-check-if-object-is-array">This answer</a> discusses the standard way to check the type of a JavaScript object (specifically, an array):</p> <blockquote> <p>The method given in the ECMAScript standard to f...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-10T04:06:29.180", "Id": "7973", "Score": "0", "body": "One thing to consider: checking to see whether the constructor names are exactly equal (that is, the exact same string) may not work if it's possible for objects to \"drift\" betwe...
[ { "body": "<p>I could not find anything wrong with your code,\nso per Meta I am going to tell you why it is awesome ;)</p>\n\n<ul>\n<li>Checking <code>.toString()</code> is icky, <code>toString()</code> could easily be replaced/enhanced</li>\n<li>Your solution works across frames</li>\n<li>I was not able to bre...
{ "AcceptedAnswerId": null, "CommentCount": "7", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-10T04:01:45.333", "Id": "5278", "Score": "3", "Tags": [ "javascript" ], "Title": "Alternative implementation of isType()" }
5278
<p>So, I wanted to avoid an</p> <pre><code>if (...) { } else if (...) { } else { } </code></pre> <p>scenario to avoid duplicating code. After a little playing, I got the following working (works from the testing i've done). Am wondering if anyone has any feedback on this approach or suggestions on on possible improve...
[]
[ { "body": "<p>How about:</p>\n\n<pre><code>if (!defined(\"MEMBER_LIMIT\") || MEMBER_LIMIT == 0 || $memcount &lt; MEMBER_LIMIT) {\n // will do something\n}\nelse {\n // will do something else.\n}\n</code></pre>\n\n<p>The key is to look for both complementary (multiple items that accomplish the same thing by d...
{ "AcceptedAnswerId": "5281", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-10T09:51:13.910", "Id": "5280", "Score": "0", "Tags": [ "php" ], "Title": "Is this IF ok? Or is there a better way?" }
5280
<p>Here is some code to insert a new line escape sequence after a certain number of characters (for fixed width displays)</p> <pre><code> private string spliceNoteText(string text) { StringBuilder sb = new StringBuilder(); int maxWidth = 70; int blockOfText; for (int i = 0; i &...
[]
[ { "body": "<p>You could already create the StringBuilder with the text you want to 'splice', rather than building it up again. Then you can just determine how many newline characters you want to add (and you should use <code>Environment.NewLine</code> instead of specifying it explicitly), and insert them in the...
{ "AcceptedAnswerId": "5285", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-10T14:48:56.977", "Id": "5283", "Score": "6", "Tags": [ "c#", "strings" ], "Title": "Better way to write a string slicer" }
5283
<p>I have the following code, which gets the data from 3 text files and puts them into 3 variables. How can I refactor this to make it smaller?</p> <pre><code>$handle = fopen($template_filename, "r"); if (filesize($template_filename) &gt; 0) { $email_template = fread($handle, filesize($template_filename)); } fclos...
[]
[ { "body": "<p>For one thing, you can use <a href=\"http://us3.php.net/manual/en/function.file-get-contents.php\" rel=\"nofollow\"><code>file_get_contents</code></a>:</p>\n\n<pre><code>$email_template = file_get_contents($template_filename);\n$subject_template = file_get_contents($subject_filename);\n$footer_tem...
{ "AcceptedAnswerId": "5292", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-10T16:06:20.857", "Id": "5286", "Score": "2", "Tags": [ "php" ], "Title": "Putting data from 3 text files into 3 variables" }
5286
<p>Connection stored in the xml config file.</p> <pre><code>&lt;?xml version='1.0' ?&gt; &lt;database&gt; &lt;connection&gt; &lt;dbtype&gt;mysql&lt;/dbtype&gt; &lt;dbname&gt;shoutbox&lt;/dbname&gt; &lt;host&gt;localhost&lt;/host&gt; &lt;port&gt;3306&lt;/port&gt; &lt;user&gt;admin&lt;/user&gt; ...
[]
[ { "body": "<p>Seeing as there are no other answers I will give a quick review. You seem to have done a good job with this class. Here are some things I would do:</p>\n\n<ol>\n<li>Remove the evil singleton. It is valid to have more than one database connection. Don't limit yourself to a single instance. Use ...
{ "AcceptedAnswerId": "5561", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-10T21:14:34.000", "Id": "5294", "Score": "4", "Tags": [ "php", "pdo" ], "Title": "PDO wrapper class" }
5294
<p>This code is for a simple language quiz. It fetches two words and related audio files via a JSON call, presents the user with an image that matches one of the words, and challenges the user to make the match. My code works but it's a little repetitious and ugly. I'd like to see how the experts would propose rewri...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-11T02:58:52.560", "Id": "7999", "Score": "5", "body": "I can't spot any difference between playAudio1 and playAudio2, so that's a pretty damp area." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-11T03:18:3...
[ { "body": "<p>Wouldn't you just remove playAudio2 and rename playAudio1 to playAudio, then in attachMouseEnter, just call playAudio both times.</p>\n\n<pre><code>function attachMouseEnter(mp31, ogg1, mp32, ogg2) {\n$('#ChoiceA').die('mouseenter.audio1event');\n$('#ChoiceA').live('mouseenter.audio1event', functi...
{ "AcceptedAnswerId": "5299", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-11T02:50:51.297", "Id": "5297", "Score": "5", "Tags": [ "javascript", "jquery", "quiz" ], "Title": "Simple language quiz" }
5297
<p>I am using the following code to add nodes in a treeview. Is there a better or more compact way of doing this by using LINQ?<br /></p> <pre><code>foreach (Plan plan in this.IncomingPlan.Plans) { foreach (Document doc in plan.Documents.Where(d =&gt; d.Name.Equals(this.DocumentName, StringComparison.OrdinalIgnore...
[]
[ { "body": "<p>Looks perfectly fine to me. That's the first time I've looked at your code and I was able to see quickly what it does.</p>\n\n<p>There is no need to overly-compact things if it is going to make it a pain for someone else to understand in future.</p>\n", "comments": [ { "ContentLi...
{ "AcceptedAnswerId": "5312", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-11T11:43:44.287", "Id": "5301", "Score": "4", "Tags": [ "c#", "linq" ], "Title": "Is there a better or more compact way of adding items in treeview using LINQ?" }
5301
<p>I'm working on a small project that does mathematical calculations based on selected data in a JTable. The goal is to make the program fairly adaptable for adding new mathematical calculations in the future. For reference, some of the current calculations are: calculating the mean (average) of a set of data; calcula...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-11T14:21:05.890", "Id": "8003", "Score": "0", "body": "Are you coming from a .net background? You might want to look at the [Java Code Conventions](http://www.oracle.com/technetwork/java/codeconv-138413.html)." }, { "ContentLic...
[ { "body": "<p>First, I get some error messages when I put this in the compiler.\nI had to replace the anonymous inner class that is returned by <code>performAnalysis</code> with a helper class. I'm <em>not</em> a fan of helper classes like this, so it would be nice if someone else had a better idea.</p>\n\n<p>S...
{ "AcceptedAnswerId": null, "CommentCount": "8", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-11T13:27:13.813", "Id": "5303", "Score": "4", "Tags": [ "java" ], "Title": "Super class knowing the type of its children? Surely there is a better way" }
5303
<p>With a <code>DateTime</code> object, it's easy to get, for example, <strong>11 October 2011</strong> by using:</p> <pre><code>d.ToString("d MMMM yyyy"); </code></pre> <p>However, there seems to be no built-in method to get the output <strong>11th October 2011</strong>.</p> <p>So here's a possible extension method...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-11T19:08:54.800", "Id": "8010", "Score": "2", "body": "Don't be lured by the false sense of security that using a string builder gives you here. It's only useful if you're really going to be adding a lot of different strings to it. O...
[ { "body": "<p>You can simplify it a bit and make a trivial improvement to performance <em>(this will be noticeable if you call this method a lot)</em>.</p>\n\n<pre><code>public static string ToStringWithOrdinal(this DateTime d) {\n switch (d.Day) {\n case 1: case 21: case 31:\n return d.ToString(\"dd's...
{ "AcceptedAnswerId": "5310", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-11T14:40:53.427", "Id": "5304", "Score": "5", "Tags": [ "c#", ".net", "strings", "extension-methods" ], "Title": "Convert .NET DateTime to a string using ordinals" }
5304
<p>I've only been coding C# a few weeks and was just hoping for a little constructive criticism of a socket server I've been working on:</p> <pre><code>using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Net.Sockets; using System.Net; namespace NetworkCommunication { ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2015-04-29T21:24:52.443", "Id": "159991", "Score": "0", "body": "I'm interested in your async implementation, can you share the client code and eventArgs code?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2015-09-04T07:...
[ { "body": "<p>My biggest concern is your excessive use of empty try statements. You should either handle any <code>SocketException</code> that may be thrown or let them propagate. As it stands I would not consider this production ready code. </p>\n", "comments": [ { "ContentLicense": "CC BY-...
{ "AcceptedAnswerId": "5900", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-11T16:07:00.527", "Id": "5306", "Score": "13", "Tags": [ "c#", "networking", "socket", "tcp" ], "Title": "TCP Socket Server" }
5306
<p>I am looking a good way to fill up the elements of a lower triangular matrix from a list.</p> <p>I currently have this:</p> <pre><code>PadRight[#, s] &amp; /@ Prepend[Take[elems, # + {1, 0}] &amp; /@ Partition[Accumulate[Range[0, s - 1]], 2, 1], {}] </code></pre> <p>where <code>elems</code> is the elements-...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-16T11:13:51.907", "Id": "8137", "Score": "0", "body": "Lonely over here, isn't it? I have to remember to visit this site more often. The code doesn't appear to be working as I expect. Would you please include a full, directly execut...
[ { "body": "<p>Here are a few methods for your consideration and feedback.</p>\n\n<hr>\n\n<p>This one uses the core of my <a href=\"https://stackoverflow.com/questions/4198961/what-is-in-your-mathematica-tool-bag/5433867#5433867\">\"Dynamic Partition\"</a> function. It is the fastest method I know for this prob...
{ "AcceptedAnswerId": "5430", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-11T16:33:39.543", "Id": "5307", "Score": "2", "Tags": [ "matrix", "wolfram-mathematica" ], "Title": "Fill upper triangular matrix from a list" }
5307
<p>I feel like this isn't the most effective nor efficient way of doing things:</p> <pre><code>line.stop(true, true).show('slide', {direction: whichway}, speed-150, function() { title.stop(true, true).fadeIn(speed-200, function() { sub.stop(true, true).show('slide', {direction: whichway}, speed-50, function() { ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-13T01:34:02.420", "Id": "8043", "Score": "1", "body": "Apart from indentation/Style I don't think there is any other option short of putting it in your own queue ... and that would seem like overkill for this. Are you looking for style...
[ { "body": "<p>For readability, take advantage of jQuery methods that use the jQuery <a href=\"http://api.jquery.com/category/deferred-object/\" rel=\"nofollow noreferrer\">Deferred object</a> to eliminate your deeply nested callback structure.\nExample <a href=\"http://api.jquery.com/jQuery.when/\" rel=\"nofoll...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-11T17:52:20.603", "Id": "5309", "Score": "3", "Tags": [ "javascript", "jquery", "animation" ], "Title": "Animation of multiple text elements in sequence" }
5309
<pre><code>function order_ignore_the($a, $b){ // orders sentences ascending alphabetically, ignoring the work &quot;the&quot; $args = func_get_args(); foreach($args as $k=&gt;$v){ $sort = explode(&quot; &quot;,$v); $args[$k] = (strtolower($sort[0]) == &quot;the&quot; ? $so...
[]
[ { "body": "<p>I'm not sure what you're doing there, but I think it can get shortened to this.</p>\n\n<pre><code>function order_ignore_the($a, $b) {\n return strcmp(\n strcasecmp(substr($a, 0, 3), \"the\") != 0 ? $a : substr($a, 3),\n strcasecmp(substr($b, 0, 3), \"the\") != 0 ? $b : substr($b, ...
{ "AcceptedAnswerId": "5320", "CommentCount": "0", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2011-10-11T21:21:18.210", "Id": "5313", "Score": "0", "Tags": [ "php", "sorting" ], "Title": "Sort an array of sentences alphabetically, ignoring the first word if it equals 'the' (case insens...
5313
<p>Any tips on how to improve this simple recursion program?</p> <pre><code>#include &lt;iostream&gt; #include &lt;cstdlib&gt; using namespace std; int findSum(int*, const int, int, int); int main() { int length = 5, sum = 0, n = 0; int list[length]; for (n; n &lt; length ; n++ ) { list[n] = ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-11T23:04:56.817", "Id": "8018", "Score": "0", "body": "Do you want to improve the recursion or do you want a better technique?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-12T00:30:13.700", "Id": "80...
[ { "body": "<p>I think I'd prefer something like this:</p>\n\n<pre><code>int findsum(int const *list, int length) { \n if (0 == length) \n return 0;\n return list[0] + findsum(list+1, length-1);\n}\n</code></pre>\n\n<p>This follows one of the typical recursive formulations -- basically a function tha...
{ "AcceptedAnswerId": "5315", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-11T22:23:17.633", "Id": "5314", "Score": "4", "Tags": [ "c++", "recursion", "mathematics" ], "Title": "Simple recursive Summing program" }
5314
<p>I want to limit the load so I rewrite the most expensive method and add caching, both memcache and cache-control:</p> <pre><code>class GeoRSS(webapp.RequestHandler): def get(self): start = datetime.datetime.now() - timedelta(days=60) count = (int(self.request.get('count' )) if ...
[]
[ { "body": "<p>You can simplify (and sometimes speed up) things like this</p>\n\n<pre><code>try:\n a = memcache.get('ads')\nexcept KeyError:\n a = Ad.all().filter('modified &gt;',\n start).filter('published =',\n True).order('-modified').fetch(count)\n memcache....
{ "AcceptedAnswerId": "5429", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-12T06:04:26.670", "Id": "5317", "Score": "1", "Tags": [ "python", "cache" ], "Title": "Does this function cache correctly?" }
5317
<p>We have several legacy programs (VB6) generating Excel report. They are scheduled tasks running on a server. Yes, violate <a href="http://support.microsoft.com/kb/257757" rel="nofollow">this</a>.</p> <p>As a result, we've got lots of "dead" instances of Excel on the server. I intend to write a program to clean thes...
[]
[ { "body": "<p>Your code appears to be correct - however, this can be dangerous because it will kill ALL instances of Excel that are running so you run the risk of killing one of your currently running legacy programs. There are proper ways to clean up Excel resources - see my question <a href=\"https://stackov...
{ "AcceptedAnswerId": "5322", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2011-10-12T09:24:15.173", "Id": "5319", "Score": "3", "Tags": [ "c#", "scheduled-tasks" ], "Title": "Kill dead instances of Excel on a server" }
5319