body
stringlengths
25
86.7k
comments
list
answers
list
meta_data
dict
question_id
stringlengths
1
6
<p>i came across <a href="http://www.logicmazes.com/n2mz.html">this fun puzzle</a> while being on vacation. </p> <p>It was designed by Robert Abbott and painted into the grass of a Wisconsin farm. Robert succeeded into making it seem really easy to solve. Well, it is not. I spent hours with my friends wandering the pu...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-11-25T20:56:37.117", "Id": "30327", "Score": "2", "body": "The [shortest path problem](http://en.wikipedia.org/wiki/Shortest_path_problem) can be solved using [Dijkstra's algorithm](http://en.wikipedia.org/wiki/Dijkstra%27s_algorithm)." ...
[ { "body": "<p>You're finding all solutions, but because the code overwrites the <code>&lt;span&gt;</code> for every solution found you only see the last one. Try this:</p>\n\n<pre><code>sp.innerHTML += 'solved in ' + h.length + ' steps&lt;br/&gt;';\n</code></pre>\n\n<p>You're performing a breadth-first search o...
{ "AcceptedAnswerId": "19045", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-11-25T17:59:12.467", "Id": "19000", "Score": "10", "Tags": [ "javascript", "algorithm" ], "Title": "Solving a 7x7 maze puzzle" }
19000
<p>I am writing a package that will provide a light weight wrapper for PyMongo insert (and eventually other methods), in order to perform basic validation, logging, etc.</p> <p>I'm looking for design and code correctness feedback.</p> <p><strong>pymongobean/collection.py</strong></p> <pre><code>import pymongo import...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-11-26T03:39:08.733", "Id": "19008", "Score": "1", "Tags": [ "python", "pymongo" ], "Title": "PyMongo collection wrapper" }
19008
<p>I would like to make the search faster as it takes a long time to retrieve the data that I require. Is there a faster method to do this? I have written the code below to allow me to search through a data table and retrieve data, which currently is fully functional. It's the nested for loops which I am using and wond...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-11-26T11:10:43.887", "Id": "30345", "Score": "4", "body": "You should really run this through a profiler and tell us what exactly takes so long as this totally depends on the data." }, { "ContentLicense": "CC BY-SA 3.0", "Crea...
[ { "body": "<p>The most obvious problem is when there are large number of strings, string concatenation is inherently slow. Try using a StringBuilder instead, like this:</p>\n\n<pre><code> DataTable sqlData = GetConfiguration();\n\n // var q = sqlData.AsEnumerable().Where(data=&gt; data.Field&lt;String&gt;...
{ "AcceptedAnswerId": null, "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-11-26T09:52:09.110", "Id": "19014", "Score": "4", "Tags": [ "c#", ".net-datatable" ], "Title": "Search datatable faster" }
19014
<p><strong>Background</strong></p> <p>I retrieve data from a 3rd party API, over HTTP. It's often slow, and sometimes just fails. I needed a class that would keep getting data from that source, and keep it in memory. </p> <p>So, this "TaskKeeper" class's purpose is:</p> <ul> <li>Have a timer (interval lengths are pa...
[]
[ { "body": "<p>In the dispose why don't you dispose the timer <code>_timer.Dispose();</code>?</p>\n", "comments": [ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-11-26T11:39:45.180", "Id": "30346", "Score": "0", "body": "Thanks, idiotretard (it's your...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-11-26T10:17:54.093", "Id": "19015", "Score": "3", "Tags": [ "c#", "asynchronous" ], "Title": "(async) Task \"Keeper\" for keeping the \"fresh\" data - How do I improve this?" }
19015
<p>I am writing a program in C running on UNIX which counts the number of each letters in a input text file. For a file like this:</p> <p>The cat sat on the green mat</p> <p>The output would be like this:</p> <pre><code> The letter ’a’ occurs 3 times. The letter ’c’ occurs 1 times. The letter ’e’ occurs 4 ti...
[]
[ { "body": "<p>Let just say when I first read the question I was very impressed by the graph.<br>\nWell done.</p>\n\n<p>Small mistake in reading the file:</p>\n\n<pre><code>char c;\nfor (int i = 0; !feof(fp); i++)\n{\n c = fgetc(fp);\n</code></pre>\n\n<p>This is wrong in all languages. The eof is never set un...
{ "AcceptedAnswerId": "19025", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-11-26T11:00:16.690", "Id": "19019", "Score": "5", "Tags": [ "performance", "c", "array" ], "Title": "Counting letters program with ASCII-art graph" }
19019
<p>I had a <a href="https://stackoverflow.com/questions/13552370/tree-view-filtering-does-not-return-all-the-files">question</a> about filtering tree view and returning just first match.</p> <p>I've tried to create <code>list&lt;treenode&gt;</code> and change the code. Is it possible improve the below code for findin...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-11-26T13:10:29.880", "Id": "30352", "Score": "1", "body": "if you are trying to match multiple results, you should always check children, you are only doing that if a node does not match which i believe is wrong" } ]
[ { "body": "<p>Currently you do not search sub nodes it a matching parent is found. This code fixes that problem and also simplifies the code by removing the unnecessary <code>SearchChildNodes</code> function. <br><br>If you only care about the first match use <code>var node = FindNodeByValue(TreeView1.Nodes, fi...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-11-26T13:05:25.337", "Id": "19023", "Score": "2", "Tags": [ "c#", "asp.net", "tree", "search" ], "Title": "Tree node filtering with List<TreeNode>" }
19023
<p>I am trying to reduce the total execution time of my code.</p> <p>I have a GPS system which calculates routes between two points, and returns all points in between them.</p> <p>I did a simple profile and the calculation of the route takes on average 30 ms while, from main thread input to main thread output, it tak...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-11-26T20:02:33.277", "Id": "30373", "Score": "0", "body": "Why don't you use the mutex objects on Windows? It surely does have them and critical section is anything but a mutex." }, { "ContentLicense": "CC BY-SA 3.0", "Creatio...
[ { "body": "<p>I suggest to replace your code with the implementation of <a href=\"http://boost-sandbox.sourceforge.net/doc/html/lockfree.html\" rel=\"nofollow noreferrer\">boost.lockfree</a> and <a href=\"http://www.boost.org/doc/libs/1_52_0/doc/html/thread.html\" rel=\"nofollow noreferrer\">boost.thread</a> to...
{ "AcceptedAnswerId": "19057", "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-11-26T17:23:58.657", "Id": "19027", "Score": "2", "Tags": [ "c++", "optimization", "multithreading", "geospatial", "pthreads" ], "Title": "Multithreaded GPS system" }
19027
<p>I have the following method that has been shortened for the sake of this review. The actual method has many more tasks. Essentially what I am trying to do is to create many tasks, fire them off, wait until they are all finished, and handle any exceptions generated. Does this look correct?</p> <pre><code>public stat...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-11-27T01:52:59.417", "Id": "30403", "Score": "0", "body": "I'm not 100%, but won't the first exception stop the unfinished tasks from running?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-11-27T11:18:04.483", ...
[ { "body": "<p>I suggested to think about following:</p>\n\n<ol>\n<li>Extract every step into the separate asynchronous method</li>\n<li>Think about more careful locking technique. Asynchronous operations by its nature could be long running and using global write lock can degrade performance dramatically. Maybe ...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-11-26T17:27:09.440", "Id": "19028", "Score": "5", "Tags": [ "c#", "multithreading", "exception-handling" ], "Title": "AggregateException and Flatten" }
19028
<p>I started reading about JavaScript patterns, and I really liked module pattern. So I created some module:</p> <pre><code>var App = (function (parent, $) { function myPrivateFunc () { // Some private stuff } return { myPubFunc: myPrivateFunc, publicFunction: function () { ...
[]
[ { "body": "<p>Instead of adding data-properties to the body tag, and waiting for / relying on jQuery, just use an inline script:</p>\n\n<pre><code>&lt;script type=\"text/javascript\"&gt;\n var modules = /* echo the needed modules here */;\n for (var i=0; i&lt;modules.length; i++)\n App[modules[i]](...
{ "AcceptedAnswerId": "19031", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-11-26T16:17:58.480", "Id": "19030", "Score": "4", "Tags": [ "javascript" ], "Title": "Dynamic call of module pattern function" }
19030
<p>I ran into the code below today, and my gut instinct tells me this is an expensive way to do a null check. The point the author was making was that if you changed the name of the object then you don't need to change the value of the string being thrown in the exception.</p> <p>The proposed use would be:</p> <pre><...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-11-26T19:45:51.707", "Id": "30372", "Score": "5", "body": "I have a feeling this will be close to an order of magnitude slower than a simple `null` check. Yes, overly expensive." }, { "ContentLicense": "CC BY-SA 3.0", "Creatio...
[ { "body": "<p>How often do you change parameter names? How often does the code run? Under any normal distribution of those, you should go with a minor code efficiency gain over a programmer efficiency gain. </p>\n\n<p>On the other hand, if you (for some bizarre reason) change the parameter name almost every t...
{ "AcceptedAnswerId": "19039", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-11-26T19:39:21.557", "Id": "19032", "Score": "4", "Tags": [ "c#" ], "Title": "Is this is good way to check for null?" }
19032
<p>I have a class called <code>Task</code> that contain a member boolean variable <code>Completed</code>.</p> <p>I created a list of <code>Task</code> objects in a variable called <code>Tasks</code>. </p> <p>I have the following code, which sorts the objects depending on whether the Task is completed. (I want the inc...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-11-26T20:42:02.250", "Id": "30378", "Score": "1", "body": "Just off the cuff, could you use tasks.OrderBy(p => p.Completed)" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-11-26T20:45:47.193", "Id": "30379", ...
[ { "body": "<p>I think my original comment in regards to using OrderBy could still possibly still even with your latest edits (and BTW that code does not compile, there is no declared task object :)).</p>\n\n<p>How about something like:</p>\n\n<pre><code>var query = from task in tasks\n let helperTask...
{ "AcceptedAnswerId": "19035", "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-11-26T20:32:48.350", "Id": "19033", "Score": "4", "Tags": [ "c#", "optimization", "sorting" ], "Title": "Sort List By Boolean" }
19033
<p>Any suggestions to make this code clearer, more Pythonic, or otherwise better? I'm open to changes to the design as well as the code (but probably won't drop features or error checking since everything still in it has shown worth to me).</p> <pre><code>""" Parsing with PEGs, or a minimal usable subset thereof. Back...
[ { "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2020-02-13T08:35:21.547", "Id": "465034", "Score": "0", "body": "https://medium.com/@gvanrossum_83706/peg-parsing-series-de5d41b2ed60" } ]
[ { "body": "<p>Just last week, I was wondering what you were up to lately. :-)</p>\n\n<p>I've been working on nice PEG parsing for Python lately. I've written an adaptation of <a href=\"http://tinlizzie.org/ometa\" rel=\"nofollow\">OMeta</a>, named <a href=\"http://pypi.python.org/pypi/Parsley\" rel=\"nofollow\"...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-11-26T20:49:15.833", "Id": "19034", "Score": "3", "Tags": [ "python", "parsing" ], "Title": "PEG parser in Python" }
19034
<p><strong>Thought 1</strong> </p> <pre><code>public interface IRepository&lt;T&gt; : IDisposable where T : class { IQueryable&lt;T&gt; Fetch(); IEnumerable&lt;T&gt; GetAll(); IEnumerable&lt;T&gt; Find(Func&lt;T, bool&gt; predicate); T Sin...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-11-26T21:32:43.510", "Id": "30388", "Score": "2", "body": "Why not have both and have your RepositoryBase implement the IRepository interface?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-11-27T05:42:50.847", ...
[ { "body": "<p>You should use <code>Expression&lt;Func&lt;T, bool&gt;&gt;</code> as predicates on your interface and have the <code>RepositoryBase</code> implement that interface.\nBy only using <code>Func</code>, you won't get translation to L2E etc, but will have to enumerate the entire DB table before you can...
{ "AcceptedAnswerId": "19075", "CommentCount": "8", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-11-26T20:58:03.127", "Id": "19037", "Score": "37", "Tags": [ "c#", "design-patterns", "entity-framework" ], "Title": "Entity Framework Generic Repository Pattern" }
19037
<p>I had asked a first question about this class a while ago and got a few answers here which made me rewrite it completely.</p> <p>I removed all statics and globals, added my variables as arguments for the constructor, and pass them again as reference through my constructor (for creating a controller from within a co...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-05T16:48:23.473", "Id": "30957", "Score": "1", "body": "MVC is about separating things in an application so a class names mvc not the best idea. I'm working on a MVC framework, and i have 80+ classes to serve just one request." }, ...
[ { "body": "<p>Don't like it too much.</p>\n\n<p>Passing variables into functions as references always scare me because usually you cannot track anymore what's going on. <code>__construct(&amp;appui,...)</code> is one such thing.</p>\n\n<p>References communicate to me the following: \"I expect this value to be n...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-11-26T23:54:57.730", "Id": "19043", "Score": "3", "Tags": [ "php", "object-oriented", "mvc" ], "Title": "PHP MVC class with controller and nested model" }
19043
<pre><code>a_star = # returns the goal node (or null if path not found). To reconstruct path follow the node.__src till null ( start, # starting node neighbors, # a function that takes in a node and returns list of neighbours h, ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-02-06T02:19:50.423", "Id": "70297", "Score": "0", "body": "Out of curiosity, in what context are you implementing an A* algorithme in coffeescript? Note that \"for fun\" or \"to learn\" are 2 good answers." }, { "ContentLicense": ...
[ { "body": "<p>I am not an expert on the A* algorithm. I'm suggesting changes based on the\n<a href=\"http://www.faqs.org/docs/artu/ch01s06.html\">Rules of Clarity, Simplicity, and Economy</a> and the code you provided,\nnot on an extensive knowlege of graph traversal methods.</p>\n\n<p>Extensive documentation i...
{ "AcceptedAnswerId": "51450", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-11-27T01:46:45.387", "Id": "19046", "Score": "6", "Tags": [ "coffeescript", "pathfinding" ], "Title": "CoffeeScript implementation of A* algorithm" }
19046
<p><strong>Background</strong></p> <p>My project performs software application management; it covers in-app purchasing, product provisioning, account management, etc. I've recently been tasked to add a cost reporting component.</p> <p><strong>Code</strong></p> <p>On the code level, I've spread out my model into a fe...
[]
[ { "body": "<p>First, use interfaces whenever possible and make your Factories return them.\nIf later you decide to change implementation or \"hot plug\" one at run-time, it will be feasible.</p>\n\n<p>I think that looking at frameworks like yii or ZF2 may helps a lot, hunt for design patterns in them !</p>\n\n<...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-11-27T11:49:13.580", "Id": "19053", "Score": "5", "Tags": [ "php", "mvc" ], "Title": "Spreading out model across multiple classes a good idea?" }
19053
<p>I use the code below for filtering a treeview. Can this be improved?</p> <pre><code>private IEnumerable&lt;TreeNode&gt; FindNodeByValue(TreeNodeCollection nodes, string searchstring) { foreach (TreeNode node in nodes) { if (node.Value.IndexOf(searchstring, StringComparison.CurrentCu...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-11-27T19:50:54.557", "Id": "30464", "Score": "0", "body": "What do you mean by \"refresh and populate\"? Do you want to clear the list and just show matching nodes? Do you want to just jump to the matching node and expand down to it?" ...
[ { "body": "<p>What's the problem with your implementation? You clear the tree and add new (filtered) nodes. Somehow, <code>TreeView1.Nodes.Clear();</code> is under comment, so it may be supposed that you want to preserve full node structure. If so, just store it in memory:</p>\n\n<pre><code>var query = FindNode...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-11-27T12:03:56.180", "Id": "19054", "Score": "1", "Tags": [ "c#", "asp.net" ], "Title": "Filtering a TreeView" }
19054
<p>I have a PL/pgSQL function with erratic performance:</p> <pre><code>DECLARE l RECORD; events_for_machine integer; before_event "PRD".events_log; machines_ids integer[]; island_controller RECORD; before_order "PRD".events_log; before_detail "PRD".events_log; before_pallete "PRD".events_log; before_operation "PRD".ev...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-03-11T07:52:03.437", "Id": "36579", "Score": "2", "body": "Parameter definition and other details in the header are essential. Always post a complete function - will help your chances on a response." }, { "ContentLicense": "CC BY-...
[ { "body": "<p>I find this query difficult to read to begin with. Here are my comments:</p>\n\n<ol>\n<li><p>When you <code>DECLARE</code> a bunch of variables it is useful to name them such that they will be easy for another programmer to identify throughout the script. For example adding <code>v_</code> in fron...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-11-27T12:18:06.023", "Id": "19056", "Score": "5", "Tags": [ "performance", "sql", "logging", "postgresql", "stored-procedure" ], "Title": "Selecting and copying event log entrie...
19056
<p>I modified <a href="http://labnol.org/?p=21060" rel="nofollow">Amit Agarwal's script</a> which checks the uptime of one website so that it now checks several sites. The script runs every 5 minutes, however, I kept receiving mails that a site was down and then 5 mins later that it was up again.</p> <p>I adapted my c...
[]
[ { "body": "<p>There is no <code>// try, catch, else</code> in javascript. </p>\n\n<p>Instead I would do:</p>\n\n<pre><code>var success = false, state = null;\ntry {\n response = UrlFetchApp.fetch(url); \n success = true;\n error = \"Up\";\n state = \"Site up: \...
{ "AcceptedAnswerId": "36097", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-11-27T13:36:35.487", "Id": "19061", "Score": "5", "Tags": [ "beginner", "google-apps-script" ], "Title": "Checking site uptime with Google Docs" }
19061
<p>Related:</p> <p><a href="https://codereview.stackexchange.com/questions/18986/please-review-assembly-for-nios-2-interrupts">Nios 2 interrupt handler</a></p> <pre><code>/* * Main C program for nios2int 2012-10-31 * Assignment 6: Interrupts from * timer_1 and de2_pio_keys4 */ /* Include header file for alt_irq_...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-12T09:50:03.760", "Id": "31260", "Score": "1", "body": "It doesn't make sense to declare registers as int, they should be unsigned int, or even better, uint32_t." } ]
[ { "body": "<p>Nick, the code looks very clean and well organised. Nice on the eye.</p>\n\n<p>General comments:</p>\n\n<ul>\n<li><p>make local functions <code>static</code></p></li>\n<li><p>Comment noise. Many comments make the code worse by imparting no useful\ninformation. Your assignment doubtless requires...
{ "AcceptedAnswerId": "19196", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-11-27T14:38:53.297", "Id": "19065", "Score": "0", "Tags": [ "c", "homework", "embedded" ], "Title": "C for Nios-2 IRQ handling" }
19065
<p>I am trying to find all "link" elements that link to RSS feeds in a data structure created by clj-tagsoup. I wrote the following code, which seems to work fine. But: I come from a Java background and I am new to functional programming and clojure, so I am not sure if this is the right way to do it. Could you please ...
[]
[ { "body": "<p>It's not bad, but we can make it a bit more idiomatic. Let's look at this function first:</p>\n\n<pre><code>(defn- matches-attributes [current-attributes required-attributes]\n (reduce #(and %1 (= (second %2) ((first %2) current-attributes)))\n true \n required-attributes)...
{ "AcceptedAnswerId": "19072", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-11-27T15:32:29.870", "Id": "19066", "Score": "2", "Tags": [ "clojure" ], "Title": "Clojure: Find specific element in HTML tree" }
19066
<p><a href="http://projecteuler.net/problem=83" rel="nofollow">Project Euler problem 83</a> asks:</p> <blockquote> <p>In the 5 by 5 matrix below,</p> <pre><code>131 673 234 103 18 201 96 342 965 150 630 803 746 422 111 537 699 497 121 956 805 732 524 37 331 </code></pre> <p>the minimal path sum fro...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-11-27T16:40:09.433", "Id": "30452", "Score": "2", "body": "Why not use a classical Dijkstra?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-11-27T18:23:12.257", "Id": "30457", "Score": "0", "body": "...
[ { "body": "<pre><code>import bisect\nf = open('matrix.txt')\nmatrix = [[int(i) for i in j.split(',')] for j in f]\n</code></pre>\n\n<p>You could consider using the numpy library, it'll handle multidimensional arrays more neatly and efficiently.</p>\n\n<pre><code>def uniformCostSearch(startNode):\n</code></pre>\...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-11-27T15:57:55.223", "Id": "19068", "Score": "2", "Tags": [ "python", "optimization", "algorithm", "project-euler" ], "Title": "optimizing project euler #83 solution" }
19068
<p>I have the following methods in <code>CacheUtil</code> class</p> <pre><code>public void addCacheEntry(String key, Serializable entry) { //add to cache } public void removeCacheEntry(String key) { //remove from cache } public Serializable getCacheEntry(String key) { Serializable entry = // get from cache...
[]
[ { "body": "<p>You could change your CacheUtil class to the following:</p>\n\n<pre><code>public class CacheUtil {\n ...\n public void addCacheEntry(String key, Serializable entry) {\n //add to cache\n }\n\n public void removeCacheEntry(String key) {\n //remove from cache\n }\n\n pu...
{ "AcceptedAnswerId": "19074", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-11-27T16:16:50.613", "Id": "19070", "Score": "0", "Tags": [ "java", "cache" ], "Title": "What is the better way to retrieve value from this cache implementaion?" }
19070
<p>I needed to publish a message across the ESB (MassTransit) that will return a different type of object depending on how the message is processed. I wanted to implement this in a generic way so I could wire up other services with similar requirements in the same way.</p> <p><strong>Publish a request</strong></p> <p...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-10-02T20:38:40.333", "Id": "118232", "Score": "0", "body": "What type is the c variable you get when you publish a request? Is this your response? If so there's a much simpler solution that needs *way* less reflection." } ]
[ { "body": "<p>It's possible, providing <code>c</code> is your response from the bus, to do a lot of this without needing Reflection. Instead we can use a separate method and the joys of implicit typing to work out the type of TResponse for us.</p>\n\n<p><strong>Proposed solution</strong></p>\n\n<pre><code>publi...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-10-31T17:04:18.037", "Id": "19071", "Score": "3", "Tags": [ "c#" ], "Title": "Handling multiple MassTransit response types" }
19071
<p>My goal is to simulate a <a href="http://en.wikipedia.org/wiki/Shuffling#Pile_shuffle" rel="nofollow">Pile shuffle</a> of a vector. It takes 2 optional arguments for the number of piles to use and how many times to perform the shuffle.</p> <p>As this is my first attempt at clojure code, I'm fairly sure I'm doing so...
[]
[ { "body": "<p>You need loop/recur very rarely in most code, and almost never for operating on collections/sequences. Using the standard library sequence functions, it’s possible to do the main pile shuffle with just a handful of expressions:</p>\n\n<pre><code>(-&gt;&gt; (range (dec n) -1 -1) (mapcat #(take-nth...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-11-27T16:49:53.247", "Id": "19073", "Score": "5", "Tags": [ "performance", "functional-programming", "lisp", "clojure", "shuffle" ], "Title": "Pile shuffle of a vector" }
19073
<p>When you click open - a div slides out. If you click on the new div, an additional div slides out from under it. This is working great, but I need two things that I cant figure out!</p> <ol> <li><p>How can I condense the jQuery so I don't have to add a class to it every time I want a new slider? Is it possible to d...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-11-27T19:16:09.867", "Id": "30461", "Score": "0", "body": "I figured out the second part! \n\nNow if you hit the close button, the bottom slider closes first, then the main slider closes second. \n http://jsfiddle.net/avXSd/78/\n\nI still...
[ { "body": "<p>A quick review:</p>\n\n<p><strong>JSHint.com</strong></p>\n\n<ul>\n<li>Your code passes all checks, well done</li>\n</ul>\n\n<p><strong>Naming</strong></p>\n\n<ul>\n<li><code>test</code> and <code>test2</code> are unfortunate names for elements, I am sure you can come up with something better</li>...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-11-27T16:25:16.273", "Id": "19076", "Score": "5", "Tags": [ "javascript", "jquery", "jquery-ui" ], "Title": "jQuery Toggle Animation" }
19076
<p>Here's a solution for a lazy groupBy when the iterator contents are assumed to be clustered (repeated elements next to each other) over the key:</p> <pre><code>def clusteredGroupBy[B](h: Iterator[B])(f: B =&gt; _): Stream[Iterator[B]] = { if (h.hasNext) { val firstValue = h.next() val projection = f(first...
[]
[ { "body": "<p>As far as I know, Scala doesn't have anything like you suggest. Your solution is short and fast.</p>\n\n<p>I tried to think of a solution that doesn't use mutable state and uses existing functions, without examining the structure directly. It is based on <code>Stream</code>s instead of <code>Itera...
{ "AcceptedAnswerId": "28992", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-11-27T18:30:17.213", "Id": "19078", "Score": "5", "Tags": [ "scala" ], "Title": "GroupBy over a clustered iterator in Scala" }
19078
<p>This is my first C++ in many years. It's based on some stuff I found on the internet, including <a href="http://blogs.msdn.com/b/windowsappdev/archive/2012/09/04/automating-the-testing-of-windows-8-apps.aspx" rel="nofollow">a Microsoft article on a similar topic</a>. But I'm sure there are C++ idioms that might make...
[]
[ { "body": "<p>One piece of feedback is that your error handling code is very repetitive. You are calling <code>CoUninitialize</code> in every failure block. That might seem OK for one cleanup task (though I'd tend to disagree), but once you have N things to clean up on failure (or even successful return), it ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-11-27T19:01:04.160", "Id": "19080", "Score": "3", "Tags": [ "c++", "windows" ], "Title": "C++ code to launch a Windows 8 app" }
19080
<p>I'm building a generic flat file reader which looks something like this.</p> <pre><code> public class GenericReader&lt;TComposite, THeader, TData, TTrailer&gt; where TComposite : GenericComposite&lt;THeader, TData, TTrailer&gt;, new() where THeader : new() where TData : new() where TTrailer : new()...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-11-27T19:05:47.510", "Id": "30460", "Score": "1", "body": "What is the thinking behind the Composite and GenericComposite classes? They seem the same to me." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-11-27T...
[ { "body": "<p>Having so many <code>new</code> operations -- seems like you'd want to use some kind of a factory, injected in the constructor, or the instances themselves injected in the constructor, instead of constructing the classes <em>inside</em> the constructor.</p>\n", "comments": [ { "C...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-11-27T19:01:46.267", "Id": "19081", "Score": "1", "Tags": [ "c#", "generics", "type-safety" ], "Title": "Can I somehow tidy up this (overuse?) of generics?" }
19081
<p>I wrote my first jQuery plugin. It counts characters in a similar way to what StackExchange uses for comment entries. You can <a href="http://jsfiddle.net/yHPg7/5/" rel="nofollow noreferrer">see it in action with this fiddle</a>.</p> <p>I feel that it's messy, but I can't explain why. One of the default options is ...
[]
[ { "body": "<p>I suggest storing your defaults in a location that can be reached by the developers, and automatically filling in the minsize if <code>minsize</code> is included in the default text. For example,</p>\n\n<pre><code>(function ($) {\n \"use strict\";\n\n $.fn.counter = function (options) {\n ...
{ "AcceptedAnswerId": "19089", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-11-27T19:41:52.373", "Id": "19083", "Score": "1", "Tags": [ "javascript", "jquery" ], "Title": "jQuery plugin to count characters" }
19083
<p>I'm looking for feedback to improve this function. The purpose is to pass a noun and append the appropriate indefinite article ("a" or "an").</p> <p>A known issue with this code is that it doesn't address words with a vowel sound but a consonant first letter, such as "honor" or "hour". I cannot include 'h' in the l...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-01-08T16:23:17.630", "Id": "32433", "Score": "3", "body": "The logic is flawed. In English, you can't base a/an on written form. You have to base it on word pronuncation. If you don't have the pronunciation for every word, you will neve...
[ { "body": "<p>A tiny improvement to reduce a string concatenation:</p>\n\n<pre><code>function aan ($string) {\n return (\n in_array(\n strtolower(substr($string, 0, 1)),\n array('a','e','i','o','u')\n ) ? 'an ' : 'a '\n ).$string;\n}\n</code></pre>\n\n<p>In order to hel...
{ "AcceptedAnswerId": "37867", "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-11-27T19:58:14.987", "Id": "19085", "Score": "1", "Tags": [ "php", "strings" ], "Title": "Indefinite article a/an" }
19085
<p>I am very much interested in the <a href="http://ciprian-zavoianu.blogspot.de/2009/01/project-bandwidth-reduction.html" rel="nofollow">Reverse Cuthil McKee Algorithm</a>. I have seen Fortran and C or C++ implementations of it, and I decided that it would be a nice exercise to implement it in Python. I know this alg...
[]
[ { "body": "<p>Regarding readability, it is generally a good practice to avoid using unnecessarily shortened forms like <code>adjcncy</code>, as it is only two characters short of adjacency. Also using R for result_queue is discouraged in general (subjective opinion).</p>\n\n<p>If there is no constraint on it be...
{ "AcceptedAnswerId": "54105", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-11-27T20:18:16.160", "Id": "19088", "Score": "6", "Tags": [ "python", "algorithm", "matrix", "numpy" ], "Title": "Implementing the CutHill-McKee Algorithm" }
19088
<p>Here I retrieve a collection of <code>causes</code> from the database. Along with the information from each <code>cause</code>, I want to send the number of <code>users</code> in each <code>cause</code>. This way works, but if experience has told me anything there is probably a much more efficient method to do this...
[]
[ { "body": "<p>You can perform an inner-join on the users table and then group by the causes.id.</p>\n\n<pre><code>@causes = Cause\n .near([params[:lat], params[:lng]], 10)\n .joins('users')\n .group('causes.id')\n .select('causes.*, count(users) as count')\n</code></pre>\n", "comments": [ { ...
{ "AcceptedAnswerId": "19096", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-11-28T03:20:39.557", "Id": "19095", "Score": "2", "Tags": [ "ruby", "ruby-on-rails", "active-record" ], "Title": "ActiveRecord count" }
19095
<p>How can I optimize the <code>if</code> condition in this snippet? The only one difference is <code>&amp;&amp; [self isCurrentPosition:i]</code>. How can I make it a single <code>if</code>, including the condition <code>val</code>?</p> <p>Note: <code>self</code> is a category of <code>NSArray</code>.</p> <pre><code...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-11-28T10:18:33.827", "Id": "30523", "Score": "0", "body": "you cannot merge it go a single if." } ]
[ { "body": "<p>It seems that the code in <code>if</code> will be executed only if <code>i != current</code> and <code>val &amp;&amp; [self isCurrentPosition:i]</code> or <code>!val</code>, so you could merge all the <code>if</code>s into one:</p>\n\n<pre><code>- (void) cleanTextfieldExcluding:(int)current checkP...
{ "AcceptedAnswerId": "19105", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-11-28T09:49:06.907", "Id": "19101", "Score": "6", "Tags": [ "performance", "objective-c" ], "Title": "Cleaning a text field" }
19101
<p>I have written a Python function which matches all files in the current directory with a list of extension names. It is working correctly.</p> <pre><code>import os, sys, time, re, stat def matchextname(extnames, filename): # Need to build the regular expression from the list myregstring = "" for index ...
[]
[ { "body": "<p><a href=\"http://docs.python.org/2/library/stdtypes.html#str.endswith\"><code>.endswith()</code></a> accepts a tuple:</p>\n\n<pre><code>#!usr/bin/env python\nimport os\n\nfileextensions = ('.doc', '.o', '.out', '.c', '.h')\nfor filename in os.listdir(os.curdir):\n if filename.endswith(fileexten...
{ "AcceptedAnswerId": "19108", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-11-28T11:20:29.880", "Id": "19103", "Score": "3", "Tags": [ "python", "regex" ], "Title": "Python function to match filenames with extension names" }
19103
<p>I have the following code in <a href="http://jsfiddle.net/oshirowanen/89uqU/" rel="nofollow">jsfiddle</a>. I have been told this this code is messy and not optimised. My question is, what about this is messy and unoptimised and how can it be tidied up and optimised to reduce file size and so it becomes more respon...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-11-28T18:37:35.673", "Id": "30554", "Score": "2", "body": "There's a lot of code so I haven't gone through it all, but what strikes me is that you're not using classes very efficiently; you're namespacing everything, even when you don't n...
[ { "body": "<p>Messy would imply that the code readability is bad, which is not the case. However...</p>\n\n<ol>\n<li><p>Your HTML is pretty much one big div. Semantics have value, so use\nproper elements for the adequate job. That's why we have semantic elements in\nthe first place. Also, there's little reason ...
{ "AcceptedAnswerId": null, "CommentCount": "13", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-11-28T11:25:48.663", "Id": "19104", "Score": "2", "Tags": [ "javascript", "performance", "jquery", "html", "css" ], "Title": "Web page with draggable boxes in a grid" }
19104
<p>I'm looking for a better way to provide configuration options and improvements in general. I'm using the constructor injection pattern to get access to the Cache and Twitter class. <code>$callback</code> and <code>$params</code> are both part of an <code>$_GET</code> array.</p> <p>I'm not happy with <code>$config</...
[]
[ { "body": "<p>This post is a bit rambly, but here's a few things that jumped out at me:</p>\n<h2>Technicalities</h2>\n<pre><code>private $expiration = &quot;3600&quot;;\n</code></pre>\n<p>Why is 3600 a string?</p>\n<hr />\n<pre><code>public function __construct( $cache, $api, $callback, $params )\n</code></pre>...
{ "AcceptedAnswerId": "19199", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-11-28T15:21:00.290", "Id": "19112", "Score": "2", "Tags": [ "php", "optimization", "object-oriented", "design-patterns" ], "Title": "Optimize PHP Class" }
19112
<p>A multithreaded client server program to download image files. If you want to execute it on your machine you should change the file paths. Since there are four files to download the client makes the same number of connection attempts. The files sent by the FileServer will get repeated after the fourth connection att...
[]
[ { "body": "<p>Nice basic example. I guess your next step is to develop a server that gets a file download request, including a file-name parameter, and sends back the corresponding result. </p>\n\n<p>See here <a href=\"http://www.binarytides.com/java-socket-programming-tutorial/\" rel=\"nofollow\">http://www.bi...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-11-28T15:33:36.487", "Id": "19113", "Score": "3", "Tags": [ "java", "multithreading" ], "Title": "Multithreaded Client-Server file downloading application" }
19113
<p>Please review my classes and give me some advice to improve them. I have also put some additional questions in the code and I hope you can give me an answer for some of them.</p> <p><strong>Database.php</strong></p> <pre><code>&lt;?php class Database { private static $dsn = 'mysql:host=localhost;dbname=knight...
[]
[ { "body": "<p>Let's first create some test code to show how this might all work to say register a new user. In your controller code to register a user which would accept POST :</p>\n\n<pre><code>$name = $_POST['name'];\n$password = $_POST['password'];\n$email = $_POST['email'];\n\n$db = Database::getInstance();...
{ "AcceptedAnswerId": "19240", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-11-28T17:49:16.110", "Id": "19117", "Score": "3", "Tags": [ "php", "object-oriented", "validation", "database" ], "Title": "Database, User and Validator in PHP" }
19117
<p>I have to write a Blackjack game for college using the Processing language. It has to be done in a strict object-oriented approach, so I can't make an object of a class in another class unless there is some connection.</p> <p>We have to use a <code>Player</code> interface:</p> <pre><code>interface Player { //...
[]
[ { "body": "<p>You are beginning to mix up the <em>business logic</em> with the <em>user interface</em>. You should (be able to) design a \"game driver\" class without regard to user interface. You want to keep your GUI code separate from your game logic code. And another OO paradigm is to create new objects sep...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-11-28T18:34:01.370", "Id": "19118", "Score": "1", "Tags": [ "game", "classes", "playing-cards", "processing" ], "Title": "Organizing classes for Blackjack game" }
19118
<p>For a homework assignment we have to write a class that simulates water breaking a floodbank (very simplistic 2D simulation).</p> <p>My implementation works fine but I found that there were many downcasts (in my opinion, a flaw in Greenfoot's API, which should be using generic functions rather than functions that t...
[]
[ { "body": "<p>Downcasting can usually be avoided by using common methods in abstract types.</p>\n\n<pre><code> if (((DoorbraakWorld)getWorld()).stopped) return;\n</code></pre>\n\n<p>Is this the same as <code>getWorld().stopped()</code>?</p>\n\n<pre><code> // The next line looks so incredibly ugly…\n Sa...
{ "AcceptedAnswerId": "19124", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-11-28T18:44:53.120", "Id": "19119", "Score": "2", "Tags": [ "java", "casting" ], "Title": "2D model simulating water breaking a floodbank" }
19119
<p>I've written the following simple filter in Racket as my first Racket program and am wondering if I am writing it in an "idiomatic Racket style".</p> <pre class="lang-scm prettyprint-override"><code>#! /usr/bin/env racket #lang racket (require racket/cmdline) (define a-prolog-mode? (make-parameter #f)) ;; parses...
[]
[ { "body": "<p>Overall, this is very pleasant code to review. Especially given you're new to the language. Your function names are follow convention such as the use of ending predicates with <code>?</code> and indicating conversions with <code>-&gt;</code>. The comments make this code easy to understand. So ...
{ "AcceptedAnswerId": "19157", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-11-29T02:42:40.810", "Id": "19123", "Score": "3", "Tags": [ "scheme", "racket" ], "Title": "A Simple Unix Filter in Racket - Learning the Racket Way" }
19123
<p>I've written a simple accordion using zepto js lib.</p> <p>Looking for advice on how to improve this better.</p> <p><strong>HTML</strong></p> <pre><code>&lt;div class="box"&gt; &lt;span class="learn-more"&gt;&lt;a href="#"&gt;Learn more&lt;/a&gt;&lt;/span&gt; &lt;div class="more"&gt; blah&lt;br&gt; ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-11-29T03:59:33.157", "Id": "30581", "Score": "2", "body": "You last question is more of a javascript question that belongs on StackOverflow right! I don't see a problem with you code. But you never know with edge cases." }, { "Con...
[ { "body": "<p>There are a couple of inconsistencies which you could tidy up. You're toggling classes to show/hide the div but using show/hide directly on the triggers. You're using chaining in one onClick but not in the other. And you're using the class to reference the accordion contents in one case, but the e...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-11-29T03:29:07.607", "Id": "19125", "Score": "1", "Tags": [ "javascript" ], "Title": "Multiple accordion on a page" }
19125
<p>How can I write this PHP code better? It puts together an SQL query string from user input. The task is to return search results based on one or more text fields. The user can determine if partial matches are allowed.</p> <pre><code>$compop = $allowpartial ? "LIKE" : "="; // use LIKE for wildcard matching $any = $a...
[]
[ { "body": "<h2>Use Prepared Statements</h2>\n\n<p>Your code is vulnerable to SQL injection attacks. Use PDO or mysqli prepared statements to avoid this. See <a href=\"https://stackoverflow.com/questions/583336/how-do-i-create-a-pdo-parameterized-query-with-a-like-statement-in-php\">this answer</a> for how to u...
{ "AcceptedAnswerId": "19129", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-11-29T04:09:11.220", "Id": "19128", "Score": "4", "Tags": [ "php", "sql" ], "Title": "Building an SQL query string" }
19128
<p><img src="https://i.stack.imgur.com/61n3w.png" alt="enter image description here"></p> <ol> <li>Delete all matching ID</li> <li><p>Insert new data</p> <p>function <strong>add_date($id,$date)</strong> {</p> <pre><code>mysql_query("DELETE FROM wp_opening_date WHERE Id='$id'"); $dates = explode(",",$date); foreach (...
[]
[ { "body": "<p>Well, there's nothing wrong as far as I can see here. The only thing I would check is that there is a suitable index on the <code>Id</code> field in database, so the delete query can be performed relatively quick.</p>\n\n<p>Another thing to consider is the size of your table. If you have <em>lots<...
{ "AcceptedAnswerId": "19133", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-11-29T08:01:52.143", "Id": "19131", "Score": "1", "Tags": [ "php", "mysql", "sql" ], "Title": "Delete matching ID and insert new data" }
19131
<p>Can I use <code>task.Wait();</code> like that? Note that when I call <code>task.Wait</code> the task is probably already finished.</p> <p>And probably you can suggest better pattern.</p> <pre><code>class A { private Task task1; private Task task2; ... public void Connect() { stayConnected ...
[]
[ { "body": "<p><code>Task.Wait()</code> should just return <code>true</code> if the task is completed, so sure you can. However, you should better use waiting with timeout or <code>TimeSpan</code> parameter if you have actions inside of <code>while { }</code> loop that can possibly cause a freeze.</p>\n", "c...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-11-29T08:18:34.040", "Id": "19134", "Score": "3", "Tags": [ "c#" ], "Title": "Using Task.Wait() for waiting while task is finished (even if it already finished)" }
19134
<p>Using Rails 3.2. I have the following code:</p> <pre><code># photo.rb class Photo &lt; ActiveRecord::Base after_create :associate_current_user after_save :increase_user_photos_count after_destroy :decrease_user_photos_count private def associate_current_user current_user = UserSession.find.user ...
[]
[ { "body": "<p>Remove the callback, and call that code at the level where it's used best.</p>\n\n<p>I.e.:</p>\n\n<p>When you create a batch of records:</p>\n\n<pre><code>#find and cache user\nuser = UserSession.find.user\n# create your 100 records however you want... this is a dumb example\n100.times { Post.crea...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-11-29T08:47:49.143", "Id": "19135", "Score": "1", "Tags": [ "ruby", "ruby-on-rails" ], "Title": "Reuse object in model in Rails" }
19135
<p>Is it possible to write this method in a prettier way?</p> <pre><code>public static string ByteArrayToString(byte[] byteArray) { var hex = new StringBuilder(byteArray.Length * 2); foreach (var b in byteArray) hex.AppendFormat("{0:x2}", b); return hex.ToString(); } </code></pre>
[]
[ { "body": "<p>There are popular topics on StackOverflow that cover this exact question: </p>\n\n<ul>\n<li><p><a href=\"https://stackoverflow.com/questions/311165/how-do-you-convert-byte-array-to-hexadecimal-string-and-vice-versa\">How do you convert Byte Array to Hexadecimal String, and vice versa?</a></p></li>...
{ "AcceptedAnswerId": "19137", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-11-29T08:57:20.923", "Id": "19136", "Score": "2", "Tags": [ "c#", "array" ], "Title": "Best way convert byte array to hex string" }
19136
<p>It work's at Smartphone(Android 2.3.3) but Tablet(Android 4.0) => Force Close!!</p> <pre><code> public String getXmlFromUrl(String url) { String xml = null; try { // defaultHttpClient DefaultHttpClient httpClient = new DefaultHttpClient(); HttpPost httpPost = new HttpPost(url); ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-11-29T15:34:46.017", "Id": "30606", "Score": "0", "body": "Try adding yet another catch block like this: `catch (Throwable t) { t.printStackTrace(); }` Then see what it prints to your error log." }, { "ContentLicense": "CC BY-SA 3...
[ { "body": "<p>You should remember this.</p>\n\n<blockquote>\n <p>From Android 3.x Honeycomb or later, you cannot perform Network IO on\n the UI thread and doing this throws\n android.os.NetworkOnMainThreadException. You must use <strong>Asynctask</strong>\n .</p>\n</blockquote>\n\n<p>You have to put your <c...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-11-29T09:58:48.383", "Id": "19139", "Score": "1", "Tags": [ "java", "android" ], "Title": "Force Stop by Error in httpClient.execute(httpPost);" }
19139
<p>I have 3 nested <code>NSEnumeration</code> loops, which are used to get the textfields of a custom cell, in a custom table in a custom view in a controller.</p> <p>How can I make this code more readable and more optimizated?</p> <pre><code>- (void) textfieldsOperations:(APOperation)op { __block int Valid = 0; ...
[]
[ { "body": "<p>honestly: this code should be replaced completely.</p>\n\n<p>you dont give any informations about how your MyCell and MyTextField look like, so I can just give you a general advice: Let MyTextField have a delegate it can call if a certain operation is triggered on it.</p>\n\n<p>ie it could call <...
{ "AcceptedAnswerId": "19515", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-11-29T10:44:11.670", "Id": "19141", "Score": "1", "Tags": [ "performance", "array", "objective-c" ], "Title": "Optimize nested enumerate blocks?" }
19141
<p>I would like to share my class IDF. Any suggestions/modification?</p> <pre><code>public class IDFMeasure { private readonly string[] _docs; private readonly int _numDocs; private int _numTerms; private List&lt;string&gt; _terms; private float[][] _InverseDocFreq; private int[] _docFreq; ...
[]
[ { "body": "<p>The layout and naming conventions look good. Thank you for that.</p>\n\n<p>_InverseDocFreq should be renamed _inverseDocFreq to keep with conventions and also stay consistent in your code.</p>\n\n<p>I also think _terms should be an IList. This just eliminates a bunch of the unneeded operations.<...
{ "AcceptedAnswerId": "19159", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-11-29T10:50:50.860", "Id": "19143", "Score": "5", "Tags": [ "c#" ], "Title": "Inverse Document Frequency (IDF) implementation" }
19143
<p>My implementation contains a <code>SpriteComponent</code> class which has a <code>Z</code> property; I use this to determine the order in which to draw my entities (higher Z = drawn on top). It's a simple integer.</p> <p>What I'm worrying about (premature optimization, I suspect) is the runtime complexity of the fu...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2015-09-18T15:14:11.920", "Id": "192246", "Score": "0", "body": "I wouldn't worry about this until it becomes a problem, but once it has consider maintaining the list of entities on screen that have `SpriteComponents` (i.e. cache them) so that...
[ { "body": "<blockquote>\n <p>Not sure about Where</p>\n</blockquote>\n\n<p><code>Where</code> method (if applied to <code>IEnumerable&lt;T&gt;</code>) is O(N) operation, and it's a lazy operation so it will do the filtering while consumer reads the result.</p>\n\n<blockquote>\n <p>Should I be worrying about t...
{ "AcceptedAnswerId": "19160", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-11-29T11:54:24.000", "Id": "19147", "Score": "2", "Tags": [ "c#", "xna", "monogame" ], "Title": "Sorting entities by Z in every call to Draw" }
19147
<p>I'm fairly new to Arduino and C++ in general, coming from a heavy Python background. The code below is functional, but my lack of C++ knowledge is keeping me from spotting any errors in style, idioms and other good practices.</p> <p>Not all of the library code is used by the example, as I tried to keep that to the ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-10-31T15:04:14.787", "Id": "53797", "Score": "0", "body": "I am going to have to get back into Arduino again! I miss this stuff" } ]
[ { "body": "<p>I'm going to preface this with the fact that I'm not quite sure what (if any) restrictions the Arduino may impose on the C++ you can use. Since you've tagged it as C++, I'm going to assume you can use C++ as you would on any other platform.</p>\n\n<pre><code>void\n begin(void),\n addLight(void),...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-11-29T12:52:37.720", "Id": "19148", "Score": "3", "Tags": [ "c++", "arduino" ], "Title": "Feedback on Arduino class for LED circle animations" }
19148
<p>I have created a nice url structure for my site.</p> <p>In my .htaccess I have:</p> <pre><code>FallBackResource /index.php </code></pre> <p>And in my router class I have:</p> <pre><code>class init { function __construct($url) { $URLElements = explode('/', $url) ; // Adjust if needed. if($url) { ...
[]
[ { "body": "<p>There's not really much to review here, but a few quick items:</p>\n\n<ul>\n<li>This is going to sound weird at first glance, but you have a route() method that takes a path instead of depending directly on the request uri.\n<ul>\n<li>A router's job is to route. By hard coding the <code>$_SERVER[...
{ "AcceptedAnswerId": "19155", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-11-29T14:04:41.970", "Id": "19152", "Score": "2", "Tags": [ "php", ".htaccess" ], "Title": "Can my router code be improved?" }
19152
<p>See <a href="https://codereview.stackexchange.com/questions/18982/randomizing-and-mutating-algo-class-style">Randomizing and mutating algo class - style</a></p> <p>I'm looking for a review of the functionality of this code, answers to the above question which also describes the code use focus on style instead.</p> ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2014-03-26T12:47:45.550", "Id": "79160", "Score": "1", "body": "\"Below is the updated code since the style feedback\": it still lacks many improvements suggested in the previous feedbacks (`#pragma region` is still there, you stil use `USHRT_...
[ { "body": "<p>It is a bit hard to tell what <code>algo</code> does. For one thing, some of its data members are all <code>public</code>, but they should all be <code>private</code>. There's also quite a bit of inline code, making it hard to read. For this, I'd recommend putting the implementation details in ...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-11-29T15:19:45.190", "Id": "19153", "Score": "5", "Tags": [ "c++", "algorithm", "search", "random", "simulation" ], "Title": "Randomizing and mutating algo class - functionality...
19153
<p>Despite being the clever Java coder I am, I noticed I know way too little about various design patterns. The <a href="http://en.wikipedia.org/wiki/Builder_pattern" rel="nofollow">builder pattern</a> caught my eye as something to learn, as I have certainly seen my fair share of telescopic constructors already.</p> <...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-11-29T17:59:52.193", "Id": "30622", "Score": "1", "body": "Guava uses the builder pattern frequently in their helper/utility classes. These classes are intended to be highly customizable to a user's specific situation while remaining flue...
[ { "body": "<p>The builder pattern really shines when you have complex logic around what you are trying to construct. I use this pattern frequently in my unit test projects. If I need to setup some dependencies that require mocking, but the interactions aren't central to my test, then I don't want to see it in...
{ "AcceptedAnswerId": "19172", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-11-29T15:25:38.267", "Id": "19154", "Score": "0", "Tags": [ "java", "design-patterns" ], "Title": "Am I getting the builder pattern right?" }
19154
<p>This question is related to this thread <a href="https://stackoverflow.com/questions/13630584/the-best-method-for-handling-bibtex-files/13631021#13631021">StackOverflow</a></p> <p>I would like to share with you my code, that is supposed to read a bibtex file and perform some analysis on it.</p> <p>The code works f...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-23T15:06:45.890", "Id": "41100", "Score": "0", "body": "Could you describe in an example what the code is supposed to do?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-05-23T17:08:42.227", "Id": "41110",...
[ { "body": "<p>I would stop using the <code>print &gt;&gt; sys.stderr</code> and use the <a href=\"http://docs.python.org/2/library/logging.html\" rel=\"nofollow\">logging module</a>.</p>\n\n<p>EDIT: Why i suggested the use of the logging module. The reason it is easier to put a timestamp in each message, and wh...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-11-29T18:02:15.393", "Id": "19161", "Score": "5", "Tags": [ "python" ], "Title": "Data structure for handling bibtex files" }
19161
<p>I made a mobile store, with prices in Indian rupees. Now I went for nested switch over functions, because I wanted to try out something new - biggest mistake in my life.</p> <p>Since 3 days I've been trying to perfect it, it just won't happen. I have to make sure the menu shows again if negative number or a charact...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-11-29T19:15:35.117", "Id": "30629", "Score": "1", "body": "Hi Siddharth. What exactly is your problem? Is it that you want a review of the code or it's just not working. If the latter you will likely find more assistance on this on Sta...
[ { "body": "<p>Crikey there's alot of duplicated code in there. Before I would even consider reviewing it too closely you might want to think about refactoring all those copy and pasted case statements into one method</p>\n\n<ol>\n<li><p>Remove code that has very likely been \"<strong>copied and pasted</strong...
{ "AcceptedAnswerId": null, "CommentCount": "5", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-11-29T19:11:04.690", "Id": "19164", "Score": "4", "Tags": [ "java", "console", "e-commerce" ], "Title": "Text menu shopping cart for mobile phone store" }
19164
<p>i am trying to implement factory pattern for getting XML Document from server</p> <p>(using javax.xml.parsers.DocumentBuilder)</p> <p>I have the classes below for now, could you give your opinion ? Does the structure make sense for this pattern? </p> <p><strong>DocumentGeneratorFactory</strong> (abstract factor...
[]
[ { "body": "<p>Makes sense, but you should DRY up your concrete factory at least. Forgive me my rusty Java, but something like this:</p>\n\n<pre><code>public class ProductDocumentGeneratorFactory implements\n DocumentGeneratorFactory {\n\n public Document createDocument(String scheme, String authority,...
{ "AcceptedAnswerId": "19205", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-11-29T22:32:20.077", "Id": "19173", "Score": "1", "Tags": [ "java", "object-oriented", "design-patterns" ], "Title": "Factory pattern for getting xml data" }
19173
<p>My apology, I am quite new to posting a question in this forum.</p> <p>I had a task where I was supposed to write a solution to sort entries(Name, score - in an array/list) in order of score and generate ranking based on higher score to lower scores.</p> <p>I tried doing that, code is working what it was supposed ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-11-30T15:08:05.450", "Id": "30695", "Score": "0", "body": "possible duplicate of [Array sort-rank class](http://codereview.stackexchange.com/questions/19180/array-sort-rank-class)" } ]
[ { "body": "<p>Your biggest problem is that you are using <code>static</code> for everything. Change all of the static variables to instance variables, and all of the static methods (apart from <code>main</code>) into instance methods. Then have your <code>main</code> method create an instance of <code>Journal...
{ "AcceptedAnswerId": "19190", "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-11-30T00:00:24.073", "Id": "19174", "Score": "4", "Tags": [ "java", "array", "unit-testing" ], "Title": "Ranking and sorting on Array/List" }
19174
<pre><code>var WorkflowDialogBuilder = _.once(function () { 'use strict'; var workflowDialog = $('#WorkflowDialog'); var workflowDialogContent = $('#WorkflowDialogContent'); var events = { onApplyChangesSuccess: 'onApplyChangesSuccess', onValidationFailed: 'onValidationFailed', ...
[]
[ { "body": "<p>I would refactor it into a plugin that takes the content as an option. Then you will have two instances of \"dialog controllers\" each with its own events.</p>\n\n<p>Have a look at the \"plugin with data\" example in the jQuery docs.</p>\n\n<p><a href=\"http://docs.jquery.com/Plugins/Authoring#Dat...
{ "AcceptedAnswerId": "19185", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-11-30T00:09:28.747", "Id": "19175", "Score": "0", "Tags": [ "javascript", "jquery" ], "Title": "Created a DialogBuilder object, but having issues with subscribing/unsubscribing to dialog...
19175
<p>I would dearly love some feedback on the model below. It's a basic commenting structure where users can comment on a variety of objects in the model. I have denormalised it to make querying simpler, but I'm not sure if I've over/under done it. The model tests fine, but it all feels a little clunky.</p> <pre><cod...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2015-11-27T00:08:59.853", "Id": "206599", "Score": "0", "body": "I cannot run this code as it is written, as I don't know what `db.*` is. So my question is whether this question is still relevant, and if so what is the `db.*` stuff? Or if it ...
[ { "body": "<pre><code>#####################################################################\n# Comment ###########################################################\n</code></pre>\n\n<p>This sort of stuff is useless noise that adds a lot of maintenance.</p>\n\n<p>If your classes are getting hard to find, move the...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-11-30T03:09:24.860", "Id": "19176", "Score": "1", "Tags": [ "python", "database", "mongodb" ], "Title": "Basic commenting structure for commenting on objects" }
19176
<p>By reading some tutorial i have written some peace of code to do crud operation . I just want to know how is this code is efficient or how can i make better ?</p> <p>Here i am giving code of 3 class 1. EntityManagerProvider : get connection from DB and do crud operation 2. BaseDao : A generalised Dao which uses...
[]
[ { "body": "<p>1.This sample is really ugly :) You can extract method <code>isEmptyTrim()</code> at least.</p>\n\n<pre><code>if( targetGroupsDto.getTgDesc()!= null &amp;&amp; !targetGroupsDto.getTgDesc().trim().equals(\"\"))\n map.put(\"tgDesc\", targetGroupsDto.getTgDesc());\nif( targetGroupsDto.getTgId()!= ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-11-30T05:55:03.373", "Id": "19177", "Score": "4", "Tags": [ "java", "design-patterns", "hibernate", "jpa" ], "Title": "JPA connection : is this code is efficient enough" }
19177
<h2>Forward</h2> <p>I would love any comments you have, any ideas, any flaws you can find, and any suggestions you might have regarding the code below. If this is similar to other implementations, I would love to know about them, since this is something I came up with by myself, after not finding any solution 'out the...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-02T09:43:04.087", "Id": "30758", "Score": "0", "body": "Can you show a use case when `getIsReady` is actually used? Why would you try to acquire the lock when business logic is not ready for it?" }, { "ContentLicense": "CC BY-S...
[ { "body": "<p>While this may work in isolation, the problem here is that it only works if every caller uses your <code>Synced&lt;T&gt;</code> class with the same <code>syncObj</code> as every other caller.</p>\n\n<p>Also, the <code>InnerObject</code> exposes the actual class outside the synchronization wrapper ...
{ "AcceptedAnswerId": "19228", "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-11-30T06:11:49.237", "Id": "19178", "Score": "7", "Tags": [ "c#", "thread-safety", "locking", "generics", "extension-methods" ], "Title": "Synced/Atomic access" }
19178
<p>I had a task where I was supposed to write a solution to sort entries(Name, score - in an array/list) in order of score and generate ranking based on higher score to lower scores.</p> <p>I tried doing that, code is working what it was supposed to do but it seems very ambiguous and tightly coupled, I can't even writ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-11-29T23:45:35.493", "Id": "30660", "Score": "1", "body": "What is your question?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-11-29T23:52:52.263", "Id": "30661", "Score": "0", "body": "My question...
[ { "body": "<p>You could change this:</p>\n\n<pre><code>for (int i = 0; i &lt; count; i++) {\n scoreComparatorOne = (list.get(i)).getScore();\n if (i == 0) {\n scoreComparatorTwo = (list.get(i)).getScore();\n } else {\n scoreComparatorTwo = (list.get(i - 1)).getScore();...
{ "AcceptedAnswerId": "19181", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-11-29T23:44:43.793", "Id": "19180", "Score": "1", "Tags": [ "java" ], "Title": "Array sort-rank class" }
19180
<p>I was trying to solve the Next Palindrome problem listed in SPOJ in Ruby language. Please find the problem statement <a href="http://www.spoj.pl/problems/PALIN/" rel="nofollow">here</a>. Though i came up with the below solution, i could not get the execution time below 1.4s even after tweaking this code numerous tim...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-11-29T23:01:47.690", "Id": "30664", "Score": "0", "body": "First thing I see that's obvious is that you get string ranges over and over and over again." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2017-04-14T00:11:...
[ { "body": "<p>Cache cache cache! :) All those substrings you take should be stored in variables, rather than using the expensive substring methods. Furthermore, comparing strings can also be expensive. When you store the substring in a variable, you could parse the integer and keep it for comparisons later.</p>...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-11-29T22:44:50.180", "Id": "19182", "Score": "4", "Tags": [ "optimization", "algorithm", "performance", "ruby", "palindrome" ], "Title": "The Next Palindrome: Is my code efficie...
19182
<p>Consider the following simple relationship.</p> <p><img src="https://i.stack.imgur.com/fjdmm.png" alt="Class Diagram"></p> <p><strong>Code</strong></p> <pre><code>[DataContract(Name = "Wheel")] public class Wheel { } [DataContract(Name = "OffRoadWheel")] public class OffRoadWheel : Wheel { } [DataContract(Name ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-11-30T17:15:33.627", "Id": "30699", "Score": "1", "body": "I'm a little concerned about having classes to represent off road wheels and wheels. Other than attributes (tread pattern, size, width, max speed, etc.) are there any differences...
[ { "body": "<p>Create constructors that take appropriate wheel collections. then <code>RoadVehicle</code> constructor looks like this <code>public RoadVehicle(Collection&lt;OffRoadWheel&gt; hotWheels) : base(hotWheels) {}</code></p>\n", "comments": [ { "ContentLicense": "CC BY-SA 3.0", ...
{ "AcceptedAnswerId": "19197", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-11-30T14:12:00.263", "Id": "19188", "Score": "3", "Tags": [ "c#", "collections", "generics", "inheritance" ], "Title": "How would you improve this object model design to get arou...
19188
<p>I have the below code which is still under development - but I'm trying to get myself to find the ideal way to move forward.</p> <pre><code>public interface IMemberSubscriptionService { void SelectSubscription(IMember member, IMemberSubscriptionTypePrice subscription, IOrder linkedOrderPaidWith); IMemberSub...
[]
[ { "body": "<p>I see two options:</p>\n\n<ol>\n<li>Test/implement <code>GetCurrentApplicableRenewal</code> first.</li>\n<li>Implement the code you need (which will likely go into <code>GetCurrentApplicableRenewal</code>) in your <code>SelectSubscription</code> method now, imeplement/test <code>GetCurrentApplicab...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-11-30T15:11:38.850", "Id": "19191", "Score": "3", "Tags": [ "c#", "unit-testing" ], "Title": "Test Driven Development, Mocking & Unit-testing" }
19191
<p>Heres the link to the original question . <a href="https://www.interviewstreet.com/challenges/dashboard/#problem/4f2c2e3780aeb" rel="nofollow">Billboards Link</a></p> <p>I initially declared n*k array which led to a <code>Out Of Memory Exception</code>. </p> <p>Then I resorted to using just 2 * k matrix and altern...
[]
[ { "body": "<p>Since we are on a code review forum I would suggest you to give more meaningful names to variables, avoid redundant assignments (e.g. initial array assigned to <code>parts</code> variable is not used), and split the logic into smaller methods that perform distinct functionality. Also you can use <...
{ "AcceptedAnswerId": "19201", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-11-30T19:10:59.450", "Id": "19194", "Score": "2", "Tags": [ "c#", "optimization", "algorithm" ], "Title": "Billboards InterviewStreet - Code Optimization" }
19194
<p>Obviously there are better ways of obtaining Pi, but for educational purposes, how is the code below?</p> <pre><code>(defn leibniz-numerator [x] (* (- (rem x 4) 2) -4.0)) (defn calc-pi-leibniz "Calculate pi with Leibniz formula 4/1 - 4/3 + 4/5 - 4/7 + 4/9 etc Very slow convergence" [terms] (red...
[]
[ { "body": "<p>I'd say your solution is pretty good! Since you probably won't re-use your <code>leibniz-numerator</code> function, you might want to make it private by declaring it with <code>defn-</code>, or you could declare it within the body of your main function using <code>let</code> or <code>letfn</code>....
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-11-30T23:34:54.507", "Id": "19198", "Score": "4", "Tags": [ "beginner", "clojure", "floating-point" ], "Title": "Calculating Pi in Clojure" }
19198
<p>I retrieved 200 tweets using the Jersey API. I want to find two tweets which have the longest common substring.</p> <p><code>tweetList</code> is an <code>ArrayList</code> of <code>Tweet</code> objects. The <code>comapreTweets</code> method compares <code>tweet</code> objects for longest substring.</p> <pre><code>T...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-01T04:08:12.250", "Id": "30714", "Score": "0", "body": "I don't know what's going on inside of the loop, but do strings need to be compared to each other twice? For example, i=5, j=3 and i=5, j=3 will compare tweets 5 and 3 twice. Th...
[ { "body": "<p>The classic solution to this well-known problem is using a <a href=\"http://en.wikipedia.org/wiki/Suffix_array\" rel=\"nofollow\">Suffix array</a> (see also <a href=\"http://en.wikipedia.org/wiki/Suffix_tree\" rel=\"nofollow\">Suffix tree</a> and <a href=\"http://en.wikipedia.org/wiki/Generalized_...
{ "AcceptedAnswerId": "19213", "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-01T03:37:04.850", "Id": "19200", "Score": "6", "Tags": [ "java", "algorithm", "strings", "twitter", "jersey" ], "Title": "Finding the longest common substring between two ...
19200
<p>Here's my first effort at reformation: a business letter I wrote for a friend. I would appreciate a review. (Yes, I know this is a trivial example and it would be much more beneficial to have something reviewed that is more complicated. But I want to nip bad practices in the bud now, before they become embedded i...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-06T09:40:30.067", "Id": "31006", "Score": "0", "body": "Useful: http://www.w3.org/TR/css3-selectors/#selectors" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-05T21:53:13.603", "Id": "179589", "Scor...
[ { "body": "<p>First of all, use external css file. Create style.css, put there all your css code and then link it in html file inside head tags:</p>\n\n<pre><code>&lt;link rel=\"stylesheet\" href=\"style.css\"&gt;\n</code></pre>\n\n<p>There is no need to prefix class with selectors name. It's not semantic and y...
{ "AcceptedAnswerId": null, "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-01T11:59:58.913", "Id": "19204", "Score": "7", "Tags": [ "html", "css" ], "Title": "Business Letter in HTML" }
19204
<p>I created jQuery code to automatically insert new <code>input</code> field when the previous field is focused. The code works well but seems rather lengthy to me.</p> <p>What I'm currently doing is cloning an element and then modifying the clone's attributes. As I add new a element into a DOM, I also need to modify...
[]
[ { "body": "<p>Here's a quick review of your JavaScript code:</p>\n\n<ol>\n<li><p><em>Please</em> remember to <strong>always</strong> cache your selectors.</p></li>\n<li><p>To get the <code>value</code> of an <code>input</code> element, use <code>.val()</code> instead of <code>.attr('value')</code>.</p></li>\n<l...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-01T19:51:16.017", "Id": "19212", "Score": "0", "Tags": [ "javascript", "jquery", "html" ], "Title": "Form field handling" }
19212
<p>Here is the code I am using to apply DCT on 8x8 blocks, which I'm not sure is correct. I have tried to follow <a href="http://en.wikipedia.org/wiki/Discrete_cosine_transform" rel="nofollow">Wikipedia's discrete cosine transformation (DCT) formula</a> as closely as possible. Please let me know if there are any change...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-01T23:02:58.153", "Id": "30744", "Score": "1", "body": "It will be easier to answer your question if you include a link to the Wikipedia article you mentioned, and describe which formula from the article you are trying to implement" ...
[ { "body": "<p>I'll comment on readability as it could use some serious improvements.</p>\n\n<ul>\n<li><p>Your indentation is very inconsistent. Sometimes you indent two spaces, four spaces, eight spaces, or no spaces. Choose a style and keep it consistent throughout the program.</p>\n\n<p>Two common styles (u...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-01T21:26:09.770", "Id": "19216", "Score": "3", "Tags": [ "c++", "algorithm", "image", "compression" ], "Title": "JPEG compression and DCT algorithm verification" }
19216
<p>I often have static classes which uses the <code>DataContext</code> somehow, and they all make a new <code>DataContext</code>, but often I already have one instantiated elsewhere, so why not use that?</p> <pre><code>public static bool SignIn(string email, string password, DataContext db = null) { bool disposeD...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-02T00:01:37.270", "Id": "30745", "Score": "0", "body": "I believe that ... since `db` is not passed in be reference, it should be disposed automatically as it falls out of scope when the function exists. Why do you sometimes pass in an...
[ { "body": "<p>At the very least, you should place the second <code>if</code> statement in a <code>finally</code> block. As things stand, the code is not generally correct from a purely mechanical perspective. I would also phrase it as:</p>\n\n<pre><code>bool dbDispose = db == null;\ndb = db ?? new DataContext...
{ "AcceptedAnswerId": "19224", "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-01T23:56:44.403", "Id": "19217", "Score": "4", "Tags": [ "c#", "entity-framework", "asp.net-mvc-4", "null" ], "Title": "Instantiating if null" }
19217
<p>I want to direct all requests that haven't got a valid controller action to my custom page controller. </p> <p>I.e. I want <code>/pages/new</code> &amp; <code>/users/login</code> etc to work correctly, but a request for <code>/foo</code> or <code>/foo/bar</code> should be directed to <code>/pages/display/$path</co...
[]
[ { "body": "<h2>Use a pattern</h2>\n<p>The general principle is fine, though it won't handle plugin routes (which I assume isn't a problem)</p>\n<p>However instead of a loop (and therefore defining 6 routes per controller) a parameter for the controller name can be used which will be more concise and likely over...
{ "AcceptedAnswerId": "32369", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-02T04:15:25.097", "Id": "19219", "Score": "5", "Tags": [ "php", "cakephp" ], "Title": "CakePHP 2.x Custom PagesController & Routing" }
19219
<p>I'm starting with OOP for php, i get the idea, but don't have someone physical near me to fallback on so I'm hoping i can do that here.</p> <p>The following works but i would like to know if it's good practice, that is something that weights a lot for me.</p> <p>Concept is that you can create an object, the data f...
[]
[ { "body": "<h2>Code base</h2>\n\n<p>I have removed the namespaces for cleaner view of the situation.</p>\n\n<pre><code>class SoapCredentials {\n private $_soapUser;\n private $_soapPassword;\n\n function __construct( $_soapUser, $_soapPassword ) {\n if(empty( $this-&gt;_soapUser ) ) {\n ...
{ "AcceptedAnswerId": "19236", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-02T09:39:40.137", "Id": "19225", "Score": "1", "Tags": [ "php", "object-oriented", "soap" ], "Title": "OO PHP, requesting a look if good practice" }
19225
<p>This is my work to generate an infinite <a href="http://en.wikipedia.org/wiki/Shepard_tone">Shepard Tone</a>. It is written in Clojure and works by generating repeating streams of incrementing frequencies, converting those to values on a sine wave and then adjusting the amplitude to fade in and fade our the audio.</...
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-02T13:01:42.777", "Id": "19229", "Score": "18", "Tags": [ "clojure", "audio" ], "Title": "Shepard Tone stream generation in Clojure" }
19229
<p>I have written a small JavaScript class that makes use of <code>setInterval</code> to create a delayed loop for iterating an array. I've used this technique in the past but never utilised a library to do so (and as a result it produced quite messy spaghetti code), and so I wrote up this:</p> <pre><code>var DelayedL...
[]
[ { "body": "<p>My experience with Javascript isn't quite as developed as it is for other languages, but here's what I have to say about the code.</p>\n\n<p>Why use <code>setInterval()</code> and <code>clearInterval()</code>? You'd use those methods if you wanted to call a function repeatedly. Since all you do ...
{ "AcceptedAnswerId": "19239", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-02T17:38:52.520", "Id": "19235", "Score": "3", "Tags": [ "javascript" ], "Title": "Review my \"delayed for-loop\" in JavaScript" }
19235
<p>This is function, that works correctly, but it seems to be too ugly. <code>panel</code> argument is never used for anything but pushing into <code>refreshGamePanel</code>, and it seems to be too much case statements. How can I cleanup this?</p> <pre><code>runGameLoop :: Game -&gt; Panel -&gt; Curses GameResult runG...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-03T08:31:04.377", "Id": "30797", "Score": "0", "body": "Did you try to use `do` notation? Further, look for more idiomatic ways to deal with `Maybe` (how about `fromMaybe` ?)." } ]
[ { "body": "<p>There is a nice language extension in GHC called <a href=\"http://www.haskell.org/ghc/docs/7.2.1/html/users_guide/syntax-extns.html#view-patterns\" rel=\"nofollow\">ViewPatterns</a>. Together with <a href=\"http://www.reddit.com/r/haskell/comments/wp70x/lambdacase_and_multiway_if_added_to_ghc_head...
{ "AcceptedAnswerId": null, "CommentCount": "1", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2012-12-02T19:13:29.543", "Id": "19238", "Score": "1", "Tags": [ "haskell", "event-handling" ], "Title": "Haskell game loop with keyboard handler" }
19238
<p>As per suggestion on SO, I am posting my code here to be reviewed. It was said I should not be saving and reading from disk so many times when a user selects and deselects a cell in my tableView. </p> <pre><code>@property (nonatomic, strong) IBOutlet UITableView *tableView; @property (nonatomic, strong) NSArray *li...
[]
[ { "body": "<p>you should read the settings plist once in <code>-viewDidLoad:</code> and save the contents as a dictionary to a property.</p>\n\n<p>As you are doing, it is a huge performance hit as the disk will be accessed every time a cell appears on screen during scrolling. </p>\n\n<p>In <code>-tableView:cell...
{ "AcceptedAnswerId": "19245", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-03T03:45:27.367", "Id": "19244", "Score": "1", "Tags": [ "objective-c", "ios" ], "Title": "iOS UITableView; saving cell checkmarks to disk" }
19244
<p>According to this two questions: <a href="https://codereview.stackexchange.com/questions/18160/jquery-different-way-to-write-multiple-click-functions">[1]</a> and <a href="https://codereview.stackexchange.com/questions/17759/jquery-javascript-refactoring-multiple-on-events">[2]</a></p> <p>I need a way to combine th...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-03T12:07:33.280", "Id": "30801", "Score": "1", "body": "I don't agree that `$(document).on().on()` is any less clear than your last example. Also, comments between the handlers don't break the code, as you can see here: http://jsfiddle...
[ { "body": "<ul>\n<li><p>Try placing the comments inside the callback instead to avoid breakage. I also do this on <code>if-else</code> statements as well so comments remain uniform.</p></li>\n<li><p>Event maps are better when appending multiple event handlers to the same selector.</p></li>\n<li><p>If you want a...
{ "AcceptedAnswerId": null, "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-03T11:13:09.643", "Id": "19250", "Score": "2", "Tags": [ "jquery", "array" ], "Title": "Multiple jQuery events on one element with different functions and target selectors" }
19250
<p>As the question reads, I am building a database with 3 tables. Now these tables are going to be used to store names.</p> <ul> <li>Table 1 will store First Names </li> <li>Table 2 will store Last Names </li> <li>Table 3 will be a one to one table linking the First names to the Last names</li> </ul> <p>Now all this ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-03T04:24:37.300", "Id": "30806", "Score": "1", "body": "Any reason why you're implementing the database like this where all you need is one table with a Primary Key, First Name, Last Name columns?" }, { "ContentLicense": "CC BY...
[ { "body": "<p>From the looks of this, you should be using a Stored Procedure, not entirely familiar with how that works in MySQL but I imagine it is similar to SQL Server Stored Procedures.</p>\n\n<p>Using a Stored Procedure would be the easiest way to do this.</p>\n\n<p>You create the stored procedure with the...
{ "AcceptedAnswerId": null, "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-03T04:18:34.887", "Id": "19253", "Score": "2", "Tags": [ "c#", "sql", "mysql" ], "Title": "Building database from file" }
19253
<p>I was searching for a free implementation of a "bounded" priority queue. The algorithm has been discussed many times on <a href="https://stackoverflow.com/questions/5329312/free-implementation-of-bounded-priority-queue-in-c">Stack Overflow</a>. I took a shot and wrote a STL-like bounded_priority_queue class (which...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-01T16:08:36.960", "Id": "30812", "Score": "0", "body": "flipped_compare is actually called `std::more`." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-01T16:30:35.030", "Id": "30813", "Score": "0",...
[ { "body": "<p>First of all: names starting with an underscore followed by a capital letter are reserved for the <strong>implementation</strong>. You <strong>may not use them</strong>. Ever.</p>\n\n<p>You might also want to specify whether you're interested in all advice, or only that relevant to C++03; I don'...
{ "AcceptedAnswerId": "19262", "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-01T15:56:23.460", "Id": "19254", "Score": "2", "Tags": [ "c++", "stl" ], "Title": "Free implementation of “bounded priority queue” in C++" }
19254
<p>I'm working on a site that has to do with movies. I am consuming the Rotten Tomatoes API to get my movie information and using EF5 with a code first approach to get that into the database. I'm using MVC4. I am struggling to come up with a design that makes sense and accomplishes what I need to in an efficient manner...
[]
[ { "body": "<p>This looks really silly to me:</p>\n\n<pre><code> try {\n using (var response = (HttpWebResponse)request.GetResponse()) {\n var serializer = new DataContractJsonSerializer(typeof(MoviesDataContract));\n return (MoviesDataContract)serializer.ReadObject(response.GetRe...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-11-28T17:27:28.670", "Id": "19255", "Score": "11", "Tags": [ "c#", "design-patterns", "entity-framework", "api" ], "Title": "Wrapper class for the Rotten Tomatoes API" }
19255
<p>I would like to improve my preg_replace regex. This is to clean a features list.</p> <p>I want allow for the begining of each line:</p> <ul> <li>alphanumeric characters</li> <li>== and alphanumeric characters</li> <li>-- alphanumeric characters</li> <li>++ alphanumeric characters</li> <li>** alphanumeric character...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-03T14:20:09.873", "Id": "30818", "Score": "0", "body": "Is $features the entire string - or has it already been separated for each line? Based off what I see in your Regexp - it looks like the entire string is in there. You may be bett...
[ { "body": "<p>Maybe this one : <code>#^[^-=+*\\w]{2}\\s*#um</code> (that is <a href=\"http://lumadis.be/regex/test_regex.php?id=1387\" rel=\"nofollow\">~500% faster</a> than yours):</p>\n\n<pre class=\"lang-php prettyprint-override\"><code>&lt;?php\n$list = '\n== Category one\n→ feature 1\n++ feature 2\n-- feat...
{ "AcceptedAnswerId": null, "CommentCount": "3", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-03T14:12:02.697", "Id": "19256", "Score": "1", "Tags": [ "php", "regex" ], "Title": "Preg_replace improvement" }
19256
<p>How can <a href="http://jsfiddle.net/ARTsinn/dxPdw/" rel="nofollow">this</a> be written a bit shorter?</p> <pre><code>jQuery.konami = function(fn, code) { // ↑ ↑ ↓ ↓ ← → ← → B A code = code || [38, 38, 40, 40, 37, 39, 37, 39, 66, 65]; var kkeys = '', i = 0; $(document).keydown(function(e) ...
[]
[ { "body": "<p>This is almost like code golf; this could probably be shortened. You just need to keep track of <code>i</code> and when it's past the end of the array, you know all the keys were hit in the correct order.</p>\n\n<pre><code>jQuery.konami = function() {\n function KonamiCode(kFn, kCode) {\n ...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-11-30T15:08:26.927", "Id": "19259", "Score": "3", "Tags": [ "javascript", "jquery", "event-handling", "plugin" ], "Title": "jQuery plugin to detect Konami cheat code sequence" }
19259
<p>Based on the answer to my <a href="https://stackoverflow.com/a/13629394/298754">question on StackOverflow</a>, I have ended up with the following code:</p> <pre><code>public class ColumnDataBuilder&lt;T&gt; { public abstract class MyListViewColumnData { public string Name { get; protected set; } ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-03T16:52:01.930", "Id": "30841", "Score": "0", "body": "Alternatively, if this is a proper use for `dynamic`, that'd be good to know too... but I'm pretty sure it isn't." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate...
[ { "body": "<p>I don't think you need <code>MyListViewColumnData</code> class there, I would replace it with interface and move the <code>GetDataString</code> implementation to <code>MyListViewColumnData&lt;TOut&gt;</code>. And you don't need <code>dynamic</code> here, just use <code>object</code> instead (yes, ...
{ "AcceptedAnswerId": "19265", "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-03T16:43:28.373", "Id": "19263", "Score": "0", "Tags": [ "c#" ], "Title": "Refactoring to avoid the use of dynamic" }
19263
<p>I wanted to get the boolean status from a function. Here is my sample code, wherein I used return in try and catch, to get the status of function.</p> <pre><code>public static void main(String[] args) { System.out.println(getState() ? "successful" : "failed"); } public static boolean getState() { S...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-03T17:22:15.827", "Id": "30843", "Score": "1", "body": "Which Java version are you using? With Java7 multicatch is available and ideal when you have identical catch blocks but don't want to widen your catch scope. See details at http:/...
[ { "body": "<p>For only 2 or 3 instances, I may use multiple return statements, but only in the case of if-else chains or switches. Returns within a try catch block can be done, but also can become complicated when you start mixing in finally with it. In the case of try-catch blocks or several possible 'return' ...
{ "AcceptedAnswerId": "19272", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-03T16:57:13.637", "Id": "19264", "Score": "4", "Tags": [ "java" ], "Title": "Is using return appropriate here?" }
19264
<p>I need to divide an array in blocks of 6 items max, however I can't find a better way to store the last block.</p> <p>This is my current code and it works. Is there a way to avoid using the <code>if</code> after the <code>.each</code> ? </p> <pre><code> var tabsData = [], tabCtr = 1, lpcCtr = 1; $.each(PAGE...
[]
[ { "body": "<p>It's better to use <code>slice</code> function. It will also correctly process the last block</p>\n\n<pre><code>var size = PAGE_DATA.tableData.length;\nfor (var i = 0; i &lt; size; i += 6){\n var t = PAGE_DATA.tableData.slice(i, i + 6);\n //show block of 6 items (or smaller in case of last...
{ "AcceptedAnswerId": "19267", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-03T18:33:19.253", "Id": "19266", "Score": "3", "Tags": [ "javascript", "jquery" ], "Title": "Dividing an array" }
19266
<p>I have this code to create an inverted index from a directory of text files:</p> <pre><code>(def p (re-pattern #"[^\p{L}&amp;&amp;[^\p{M}]]")) (defn invert[file] (let [f (.getName file) tokens (.split p (lower-case (slurp file)))] (into {} (mapcat #(hash-map % #{f}) tokens)))) (defn build-index[...
[]
[ { "body": "<p>You should be able to use reducers to get a good speed boost as the consumption and building of your index can be parallelized.</p>\n\n<p>I have found the best docs for reducers to be the doc strings themselves:\n<a href=\"https://github.com/clojure/clojure/blob/master/src/clj/clojure/core/reducer...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-03T18:59:37.427", "Id": "19268", "Score": "3", "Tags": [ "performance", "clojure" ], "Title": "Inverted index in Clojure - performance vs. idiomatic code" }
19268
<p>I'm in the midst of writing a custom <code>ListView</code> for our application. </p> <p>In the process of getting <a href="https://codereview.stackexchange.com/questions/19263/refactoring-to-avoid-the-use-of-dynamic">this question</a> answered, I realized I needed to separate my column-generation logic from the da...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2013-11-26T10:13:20.743", "Id": "59046", "Score": "0", "body": "The ListView control is capable of [binding to generic data](http://www.kettic.com/winforms_ui/csharp_guide/listview_data_binding.shtml) to display them through properties, DataSo...
[ { "body": "<p>I've done something like this a few times (a lot even), but most times it was a complete waste of time. You will probably not earn the time you save by not doing WebForms markup, even if it's terribly boring. If you have like 100-200 entity types to display in similar lists, it might be a useful p...
{ "AcceptedAnswerId": "19276", "CommentCount": "2", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-03T19:42:25.650", "Id": "19270", "Score": "2", "Tags": [ "c#" ], "Title": "Generic data for ListView" }
19270
<p>I have a small validation code that needs to make sure that exactly one of two parameter is set</p> <p>I consider two options, the "Naive" that has some repetitions and might look "clumsy" but is very clear, and a second that is a bit more "DRY" but I'm not sure it's as readable / convincing in it's correctness.</...
[]
[ { "body": "<p>I would put all validations first, and then extract to a method. Better, trying using a parsing framework like <a href=\"http://jcommander.org\" rel=\"nofollow\">JCommander</a> that might be able to handle that for you, so that your code is just business logic</p>\n", "comments": [], "met...
{ "AcceptedAnswerId": "19273", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-03T19:46:01.750", "Id": "19271", "Score": "3", "Tags": [ "java" ], "Title": "Which one is more readable for mutually exclusive but mandatory command line parameters validation?" }
19271
<p>I'm currently clearing my console window with this piece of code:</p> <pre><code>void clrScr() { COORD cMap = { 0, 3 }; if(!FillConsoleOutputAttribute(hCon, 0, 2030, cMap, &amp;count)) { std::cout &lt;&lt; "Error clearing the console screen." &lt;&lt; std::endl; std::cout...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-04T07:33:28.407", "Id": "30882", "Score": "2", "body": "Have a look at ncurses for a platform neutral techniques for clearing a console window." }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-04T09:57:06.08...
[ { "body": "<p>How about </p>\n\n<pre><code>system(\"cls\");\n</code></pre>\n\n<p>This clears the entire console nicely</p>\n", "comments": [ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-04T02:21:13.090", "Id": "30877", "Score": "6", "body": "That...
{ "AcceptedAnswerId": "19351", "CommentCount": "3", "ContentLicense": "CC BY-SA 4.0", "CreationDate": "2012-12-03T22:52:02.830", "Id": "19274", "Score": "3", "Tags": [ "c++", "performance", "console", "windows" ], "Title": "Clearing the screen using FillConsoleOutputAttribute()" }
19274
<p>Everyone knows you can't put a <code>Derived</code> in an <code>std::vector&lt;Base&gt;</code>. I decided to implement a collection which does allow you to do this:</p> <pre><code>#pragma once #include &lt;boost/iterator/indirect_iterator.hpp&gt; #include &lt;type_traits&gt; #include &lt;vector&gt; template&lt;ty...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-07T14:37:43.210", "Id": "31061", "Score": "1", "body": "Without having looked at the code in detail, could you please describe what advantage this solution has over just composing over a `std::vector<std::unique_ptr<Base>>` and exposin...
[ { "body": "<p>Interesting.</p>\n\n<p>You should add <code>template &lt;typename D, typename... Args&gt; emplace_back(Args&amp;&amp;...)</code>.</p>\n\n<p>In terms of automatically determining blocksize, you can add a helper function like:</p>\n\n<pre><code>template &lt;typename... Args&gt;\nstd::size_t get_max_...
{ "AcceptedAnswerId": null, "CommentCount": "6", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-03T23:12:15.817", "Id": "19275", "Score": "8", "Tags": [ "c++", "c++11", "vectors", "assertions" ], "Title": "Vector of derived classes" }
19275
<p>I have verified that both of my following functions successfully find prime numbers. I was pretty sure the function called <code>is_prime_new</code> would be faster than <code>is_prime_old</code>; however, after benchmarking (mainly consisting of generating huge lists of primes), I found this to be significantly fal...
[]
[ { "body": "<p>can you test the following (slightly optimized) version?</p>\n\n<pre><code>def is_prime_new(n):\n if n &lt; 2: return False\n if n == 2 or n == 3: return True\n if n%2 == 0 or n%3 == 0: return False\n sqr = math.sqrt(n)\n if sqr == int(sqr): return False\n sqr = int(sqr) + 1\n\n ...
{ "AcceptedAnswerId": "19557", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-04T05:23:42.470", "Id": "19278", "Score": "3", "Tags": [ "python", "optimization", "algorithm", "primes" ], "Title": "Naive prime finder, unexpected behavior in Python" }
19278
<p>I am wondering am I doing the right "Drupal" way in getting formatted value of node's body field. Here is my code:</p> <pre><code>$field = field_get_items('node', $node, 'body'); $body = ''; if (isset($field[0]['value'])) { $body = check_markup($field[0]['value'], $field[0]['format']); } </code></pre>
[]
[ { "body": "<p>The API has the <a href=\"http://api.drupal.org/api/drupal/modules!field!field.module/function/field_view_value/7\" rel=\"nofollow\"><code>field_view_value()</code></a> function which essentially does the same thing as your code, except it applies all of the field/instance settings to the value so...
{ "AcceptedAnswerId": "19317", "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-04T09:55:59.903", "Id": "19282", "Score": "2", "Tags": [ "php", "drupal" ], "Title": "The right way to get formatted node's body field in Drupal 7" }
19282
<p>I have the following in the header.php file which is included in all of my views:</p> <pre><code>$dh = opendir(Vs.get_class($this).'/js') ; while($script = readdir($dh)) { if(!is_dir($script)) { echo '&lt;script type="text/javascript" src="js/'.$script.'"&gt;&lt;/script&gt;' ; } } $dh = opendir...
[]
[ { "body": "<ol>\n<li><p>The way you are scanning the directory is going to get all files. If this is intentional thats cool, but if you are really just looking\nfor js &amp; css files, use glob and scan for them directly. This will be much better in performance, and you can avoid the directory check.</p></li>\n...
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-04T11:42:36.583", "Id": "19283", "Score": "2", "Tags": [ "php", "object-oriented", "mvc" ], "Title": "File loop and logic in controller of view header" }
19283
<p>I have an <code>IWorkflow</code> interface defined as follows:</p> <pre><code>public interface IWorkflow { Task ConfigureAsync(); Task StartAsync(); Task StopAsync(); } </code></pre> <p>And I have an <code>Engine</code> class:</p> <pre><code>public sealed class Engine : IEngine { private readonly ...
[ { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-04T20:06:12.693", "Id": "30908", "Score": "0", "body": "Is there any reason why `Engine` isn't also asynchronous?" }, { "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-05T08:53:13.800", "Id": "30923", "Sc...
[ { "body": "<p>Your code is absolutely correct in case when you want to start workflows only when all of them are configured.</p>\n\n<p>But if you want to start each workflow once it's configured (independently from other workflows) then it might be a good idea to use continuations... In .NET 4.5 it would look l...
{ "AcceptedAnswerId": "19289", "CommentCount": "4", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-04T12:50:12.883", "Id": "19285", "Score": "10", "Tags": [ "c#", "multithreading", "asynchronous", "task-parallel-library" ], "Title": "Correct approach to wait for multiple as...
19285
The Task Parallel Library is part of .NET 4 and .NET 4.5. It is a set of APIs to enable developers to program asynchronous applications.
[]
[]
{ "AcceptedAnswerId": null, "CommentCount": "0", "ContentLicense": "CC BY-SA 3.0", "CreationDate": "2012-12-04T12:50:44.553", "Id": "19287", "Score": "0", "Tags": null, "Title": null }
19287