body stringlengths 25 86.7k | comments list | answers list | meta_data dict | question_id stringlengths 1 6 |
|---|---|---|---|---|
<p>Using the eclipse formatting on a class with some <code>@NamedQueries</code> created concatenations.</p>
<p>While I have been doing this for years without paying attention I just realised that may be it
is not a good usage.</p>
<p>So basically Which one of these <code>String</code>s inside the <code>query</code>i... | [] | [
{
"body": "<p>Enter the mad world of optimization!</p>\n\n<p>The Java compiler and HotSpot just-in-time compiler are programmed with a great many rules for optimizing performance of Java code.</p>\n\n<p>In general, it is NOT worth your time to fret about the performance impact of these kinds of details as they ... | {
"AcceptedAnswerId": "11964",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-22T05:49:02.673",
"Id": "11963",
"Score": "2",
"Tags": [
"java",
"strings"
],
"Title": "Is this String concatenation creating extra String?"
} | 11963 |
<p>I want to realize an object cache which holds objects loaded from database, file or other slow access source, to make them available quickly with high performance. There will be a lot of accesses to get these objects from the dictionary!</p>
<p>It's not supposed to be Singleton/Static; multiple different object hol... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-23T18:43:26.057",
"Id": "62791",
"Score": "0",
"body": "If you want to test the performance of the ReaderWriterLockSlim, here is a small caching class that I did a while ago that uses it : [Tiny ThreadSafe Cache C#](http://tinythreadsa... | [
{
"body": "<p>You were right about the dictionary, the only thing i would change (i don't know if it is relevant for you, but it is a classic usage in your case) is using ReaderWriterLockSlim - <a href=\"http://msdn.microsoft.com/en-us/library/system.threading.readerwriterlockslim(v=vs.100).aspx\" rel=\"nofollo... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-20T13:35:19.207",
"Id": "11967",
"Score": "5",
"Tags": [
"c#",
"performance",
".net",
"thread-safety"
],
"Title": "Thread-safe object cache, for read, high performance in .NET"
} | 11967 |
<p>It's been a long while since I've done any Python programming so I thought I'd start with a simple Blackjack game. Any comments on how I can make this more readable? Use more methods perhaps?</p>
<pre><code>from sys import exit
from random import randint
class Game(object):
def __init__(self, start):
... | [] | [
{
"body": "<p>One problem I see is that your dealing may result in card repetition, which would be illegal. You are going to need to track which card has already been played and not to use them again.</p>\n",
"comments": [],
"meta_data": {
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-22T14:36:52.973",
"Id": "11972",
"Score": "6",
"Tags": [
"python",
"game",
"playing-cards"
],
"Title": "Blackjack card game"
} | 11972 |
<p>Recently I started working with TinyMVC, wrote a simple menu model and I have few questions for those who are using it... or used before. </p>
<ol>
<li>For the following code should I keep it as Model or as a Plugin? </li>
<li>How should I implement it in the view and use it on every page that is required without b... | [] | [
{
"body": "<p>Sorry you had to wait so long, answers here tend to take some time and I've been on vacation the last week, so I wasn't keeping up with this site the way I usually do. So, here we go...</p>\n\n<p><strong>Q: \"Any improvements to the code?\"</strong></p>\n\n<p>First off, I don't think you quite und... | {
"AcceptedAnswerId": "12144",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-22T15:10:11.653",
"Id": "11974",
"Score": "2",
"Tags": [
"php",
"mysql"
],
"Title": "TinyMVC Model / Plugin how to implement?"
} | 11974 |
<p>I have to implement WMSAuth in C#: <a href="http://wmsauth.org/examples" rel="nofollow noreferrer">http://wmsauth.org/examples</a></p>
<pre><code>// The following function was copied from http://wmsauth.org/examples
public static string BuildProtectedURLWithValidity(string password, string media_url, string ip, int... | [] | [
{
"body": "<p>Well, the problem is that the example code provided effectively does a <code>% 256</code> on the input characters. So it's possible that your version and the example code yield two different values for the same input.</p>\n\n<p>However you said <em>I believe the code above might work for every pos... | {
"AcceptedAnswerId": "36406",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-22T19:17:52.623",
"Id": "11977",
"Score": "3",
"Tags": [
"c#",
"strings",
"datetime",
"cryptography"
],
"Title": "WMSAuth implementation"
} | 11977 |
<p>I did this as an exercise just to practice/improve using generics.</p>
<p>Independent of how useful this implementation of a Singleton is, how is my coding in terms of using generics and any other aspect of class design of code style?</p>
<pre><code>void Main()
{
var a = Singleton<MyClass>.Value;
var... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-23T07:47:49.373",
"Id": "19225",
"Score": "2",
"body": "a little offtopic: those are *not* singletons. As long as class `T` is required to have a public parameterless constructor, anyone can create a new instance of it. Same problem wi... | [
{
"body": "<p>About your locking strategy to create the singleton, I would use a double check to avoid too much locking:</p>\n\n<pre><code>if(x)\n{\n lock(Locker)\n if(x) //again once we got the lock\n DoStuff();\n} \nelse \n{\n FooBar();\n}\n</code></pre>\n\n<p>Like this, you will hopef... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-22T19:45:08.153",
"Id": "11978",
"Score": "4",
"Tags": [
"c#",
"generics",
"singleton"
],
"Title": "Singleton implementation using generics"
} | 11978 |
<p>I am trying to improve my skill in C, and this time by getting away from <code>strtok</code>. The following code splits the <code>input</code> string into a token_list, an array of strings.</p>
<pre><code>#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define MAX_LINE_LEN 256
#define ... | [] | [
{
"body": "<p>I would consider changing the getStr() function a little, as follows:</p>\n\n<pre><code>char *getStr(char *start, char *end)\n{\n int length=end-start;\n if(length <= 0) {\n /* Consider an error msg */\n return NULL;\n }\n\n char *result = (char *)malloc (sizeof (char)... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-23T01:03:04.007",
"Id": "11981",
"Score": "7",
"Tags": [
"c",
"strings",
"reinventing-the-wheel"
],
"Title": "Splitting a string into tokens in C"
} | 11981 |
<p>Please offer some advice for this code. It all works, but I know that its messy and I don't think the Exception catching is doing what I want it to. Thanks in advance for any and all advice...</p>
<pre><code>def main():
# loop over this forever
while True:
print '--- Getting next job for Device: %... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-23T08:34:59.470",
"Id": "19226",
"Score": "0",
"body": "what do you want the exception-catching to do then?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-23T13:37:27.730",
"Id": "19241",
"Score": ... | [
{
"body": "<p>Oh I see a problem. in </p>\n\n<pre><code> perform_job(job)\n job['Status'] = u'Done'\n job['Finished'] = datetime.now()\n db.JobQ.save(job,safe=True)\n</code></pre>\n\n<p>if anything goes wrong, an exception is caught by your <code>except</code> block. in this block, you set the status of all job... | {
"AcceptedAnswerId": "12001",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-23T07:44:06.783",
"Id": "11986",
"Score": "1",
"Tags": [
"python",
"exception-handling"
],
"Title": "I think I'm not using Try Except properly in this Python code"
} | 11986 |
<p>I use jQuery and <code>underscore.js</code>, I have <code>title1-2</code> and I would like to have the action corresponding.</p>
<pre><code>this.items = {
menuItems: [
{ title: 'title1',
data: [
{ title: 'title1-1',
action: 'action1-1'
},
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-23T11:22:51.523",
"Id": "19232",
"Score": "0",
"body": "So I assume that you want to find the object that contains title1-2?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-23T12:37:24.017",
"Id": "1923... | [
{
"body": "<p>Actually the only improvement I think you can make is that you use the chaining sugar, looks a lot better:</p>\n\n<pre><code>var item = _.chain(items.menuItems)\n .pluck('data')\n .flatten()\n .find(function(a){\n return a.title === 'title1-2'\n })\n .value()\n</code></pre>\n",
"commen... | {
"AcceptedAnswerId": "11993",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-23T11:13:42.777",
"Id": "11992",
"Score": "2",
"Tags": [
"javascript",
"jquery",
"performance",
"array"
],
"Title": "Find the object that contains title1-2"
} | 11992 |
<p>Consider the scenario below. It covers multiple methods of my unit under test.</p>
<pre><code>public class OriginalSample
{
public bool Foo(ISomeEntity entity)
{
return entity.IsThatSo ? entity.IsThatSo : Bar(entity);
}
public bool Bar(ISomeEntity entity)
{
return entity.IsThatA... | [] | [
{
"body": "<p><strong>You can't.</strong></p>\n\n<p>You need to ask yourself <em>why</em> it is you want to prevent executing Bar during testing. If it is because you are worried about over-covering Bar during testing, stop worrying. If it is because your real Bar implementation is long-running, then you prob... | {
"AcceptedAnswerId": "12074",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-23T12:40:38.650",
"Id": "11995",
"Score": "6",
"Tags": [
"c#",
"unit-testing",
"moq"
],
"Title": "Mocking the class under test with private method calls"
} | 11995 |
<p>Question originally posted on Stack Overflow <a href="https://stackoverflow.com/questions/10720002/most-elegant-way-to-round-a-date-to-a-dynamic-unit-of-time-using-only-jdk-6">here</a>.</p>
<p>I'm trying to do an elegant round method that only use the JDK methods and leverage the <code>TimeUnit</code> class of that... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-24T13:48:06.847",
"Id": "19295",
"Score": "1",
"body": "Any special reason this has to done with the JDK only? The [Joda Time](http://joda-time.sourceforge.net/) library has rounding features and it's considered to be very reliable."
... | [
{
"body": "<p>One problem you might run into is that some timezone offsets aren't integral hours. For instance, the India timezone offset is UTC +5:30. It appears that your code will probably handle this case correctly, but you probably want to add a couple unit tests to verify this.</p>\n\n<p>You might also ru... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-23T12:57:07.343",
"Id": "11997",
"Score": "4",
"Tags": [
"java",
"unit-testing",
"datetime",
"reinventing-the-wheel"
],
"Title": "Rounding a date to a dynamic unit of time, using... | 11997 |
<p>I am using this code for receiving log messages from my clients. I receive more than 1000 connections per minute and I want to increase my log handling, which I have done with java threading.</p>
<p>What happens if it receive multiple client connections? Is this thread safe?</p>
<pre><code>public class Centralized... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-25T14:33:35.303",
"Id": "19340",
"Score": "0",
"body": "Does this actually log anything? All you seem to be doing is creating a CentralizedLogging instance but then never running it as a thread. It looks like you have the same proble... | [
{
"body": "<p>From what i see, it looks like you got the threads started correctly. You said in your question that you are making 1000 connections per minute or something to that sort, which is 1000 threads every minute. If you want to make your program more memory efficient, you might want to set the threads t... | {
"AcceptedAnswerId": "12232",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-23T13:27:47.763",
"Id": "11998",
"Score": "4",
"Tags": [
"java",
"multithreading",
"thread-safety"
],
"Title": "Alter centralized logging code to be thread safe"
} | 11998 |
<p>In an effort to reduce code duplication, I often use and have used this style to capture handling of exceptions on a boundary of an application:
Given the following extension methods:</p>
<pre><code>public static class FuncExtenstion
{
[DebuggerStepThrough]
public static Action<A> AsAction<A, T>... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-23T14:22:04.020",
"Id": "19242",
"Score": "0",
"body": "I don't know about this kind of pattern, but wouldn't it be more proper to extend the logger class and silence the exceptions you don't need?"
},
{
"ContentLicense": "CC B... | [
{
"body": "<p>This looks like the <a href=\"http://c2.com/cgi/wiki?ExecuteAroundMethod\" rel=\"nofollow\">Execute Around</a> pattern in its static syntax. A thunk is passed around, and then invoked at the appropriate moment.</p>\n\n<p>The intent is however a bit different. In true execute around, the is somethi... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-23T13:50:32.043",
"Id": "11999",
"Score": "10",
"Tags": [
"c#",
"error-handling",
"extension-methods"
],
"Title": "Encapsulating common Try-Catch code. Is this a known pattern? Is it... | 11999 |
<pre><code>this.displayData = function () {
var i;
var $thead = $(thead);
var $tbody = $(tbody);
var numberOfFields = columnDataFields.length;
var numberOfRows = data.length;
// Variables to keep track of even and odd rows.
var evenRowClass = 'EvenBar';
var oddRowClass = 'OddBar';
v... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-23T17:47:28.403",
"Id": "19245",
"Score": "0",
"body": "Your first line on your code block is not indented. I tried to fix it, but it says it is not a valid edit. lol"
}
] | [
{
"body": "<p>Updating tables are one of the hardest things to do since they take a long time to render. That is why people say do not use them for layouts. 1000's of rows are also bad, it would be a lot better to paginate it and only show a smaller subset.</p>\n\n<p>The problem you have is you are adding rows ... | {
"AcceptedAnswerId": "12006",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-23T17:31:48.153",
"Id": "12004",
"Score": "1",
"Tags": [
"javascript",
"optimization",
"dom"
],
"Title": "Can I adjust this code which displays a table to run faster?"
} | 12004 |
<p>I'm using this way to load a combo box with branch names, but it's taking more time if there is more number of data.</p>
<p>Is there a better way to do this, like binding in PHP?</p>
<pre><code><select name="CmbBr" id="CmbBr">
<?php ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-23T12:09:21.843",
"Id": "19253",
"Score": "3",
"body": "Separate your HTML and SQL."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-23T12:11:54.147",
"Id": "19254",
"Score": "1",
"body": "Separa... | [
{
"body": "<p>Yes, there is a better way but it's micro optimization and not really worth it. In php you can unroll the loop like this:</p>\n\n<pre><code> <?php\n $n = $ITERATIONS % 8;\n while ($n--) $val++;\n $n = (int)($ITERATIONS / 8);\n while ($n--) {\n $val++;\n $val++;\n $val++;\n ... | {
"AcceptedAnswerId": null,
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-23T12:08:03.553",
"Id": "12009",
"Score": "3",
"Tags": [
"php"
],
"Title": "Loading a combo box with branch names"
} | 12009 |
<p>I have this code:</p>
<pre><code>var submit = document.getElementById('submit');
var error = document.getElementById('error');
var url;
submit.onclick = function(){
url = document.getElementById('url').value;
if(url == ''){
error.style.display = 'block';
return false;
}
};
</code></p... | [] | [
{
"body": "<p>No. It only adds up after about 10,000 iterations. That is when you will see a savings from caching it. For a single selection you will be fine without caching. In the case of your code, it is definitely more readable to have the definition of error in there though.</p>\n\n<p>Either way, caching o... | {
"AcceptedAnswerId": "12013",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-23T21:56:45.897",
"Id": "12011",
"Score": "1",
"Tags": [
"javascript",
"cache"
],
"Title": "Caching a JS selector then only using it once"
} | 12011 |
<p>I am looking for opinions on this code. I have been experimenting with SASS the last few days and have come up with the following code. The idea was to enable the creation of a fluid grid without having non-semantic markup in the HTML. </p>
<pre><code>$columns: 12; //total number of columns to use
$gutter: 3%; // g... | [] | [
{
"body": "<p>I think you are overcomplicating the whole thing. I have been building responsive design layouts for years, and there are really just not that many scenarios when a robust 'grid-system' isn't more work than it's worth. There isn't ever a 1 column area in a 12 column grid for example.</p>\n\n<p>In ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-24T03:21:33.663",
"Id": "12015",
"Score": "4",
"Tags": [
"css",
"sass"
],
"Title": "SASS based semantic fluid grid"
} | 12015 |
<p>I threw together this C program today to handle a bioinformatics data processing task. The program seems to work correctly, but I wanted to know if anyone has suggestions regarding how the input data are parsed and how I've used control structures in the main processing loop.</p>
<pre><code>#include <assert.h>... | [] | [
{
"body": "<p>Instead of the big indent block you make by doing <code>if(strlen(seqbuffer1) > 0)</code>, do: <code>if (strlen(seqbuffer1) <1) continue;</code>, so the entire rest of the loop can be outdented a level, making it more readable. </p>\n\n<p>Similarly, you can turn the <code>if(!ambiguous)</cod... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-24T03:39:17.667",
"Id": "12016",
"Score": "2",
"Tags": [
"c",
"parsing",
"bioinformatics"
],
"Title": "Data processing task for bioinformatics"
} | 12016 |
<p>I just got through writing a bash script so my friend and I can share snippets of code to a central file via rsync and ssh. What it does is this;</p>
<ol>
<li>Sets up ssh public key auth if not already working.</li>
<li>Makes a local "snippet file" using rsync to copy an exiting file from remote server.</li>
<li>Al... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-24T10:47:36.057",
"Id": "19270",
"Score": "4",
"body": "You should show your code in the question, rather than giving a link to the code, as per [faq]."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-24T22:... | [
{
"body": "<p>Don't hardcode the editor. I happen to prefer vi, so don't force me to use nano.</p>\n\n<pre><code>editor=${VISUAL:-${EDITOR:-nano}}\n</code></pre>\n",
"comments": [],
"meta_data": {
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-24T10:12:... | {
"AcceptedAnswerId": "12046",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-24T04:18:16.737",
"Id": "12017",
"Score": "3",
"Tags": [
"bash"
],
"Title": "Bash script to share snippets of code using rsync"
} | 12017 |
<p>The following is a little JavaScript project to display quotes on a web page. Since I want to use it in a number of different web sites, I read up on good practices for making portable JavaScript code, e.g.:</p>
<ul>
<li>use no global variables</li>
<li>use namespaces</li>
<li>make it easy to plugin</li>
<li>use de... | [] | [
{
"body": "<ul>\n<li><p>Take advantage of jQuery's <code>.ready()</code>. It's an abstraction that includes <code>window.onload</code>. Here's <a href=\"http://api.jquery.com/jQuery/#jQuery3\" rel=\"nofollow\">a shorthand version</a>:</p>\n\n<pre><code>$(function(){\n //DOM ready\n});\n</code></pre></li>\n<l... | {
"AcceptedAnswerId": "12021",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-24T10:56:50.477",
"Id": "12020",
"Score": "2",
"Tags": [
"javascript",
"portability"
],
"Title": "Display quotes on a web page"
} | 12020 |
<p>Alright so this isn't an issue with my program not working, it's more of a fact that I wanna learn to code better. </p>
<p>This is one of 6 if else statements that I use inside of my program. What I'm trying to do is make it shorter (easier) to do. I am learning AS3 with Flex 4.6 (started with Flex 4). </p>
<p>I... | [] | [
{
"body": "<p>Maybe this will help</p>\n\n<pre><code>if (ft.text == \"Woven Acrylic\" && at.text == \"Motorized\"){\n switch (asf.text) {\n case \"10\":\n bap.text = String(Number(1147))\n break ;\n case \"11\":\n bap.text = String(Number(1217))\n ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-24T06:41:02.650",
"Id": "12022",
"Score": "3",
"Tags": [
"actionscript-3",
"actionscript"
],
"Title": "How to simplify my else if statement"
} | 12022 |
<p>Here's an example of a logic structure I've refactored into something more complex on many occasions because I feel like it's wrong to have a side effect in a function that determines a yes/no answer to a question.</p>
<p>If I were to break this into multiple functions I would add to the main logic to call another ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-24T22:48:57.807",
"Id": "19314",
"Score": "0",
"body": "Yes, I agree in that I think a side effect in a Yes/No method is not desirable."
}
] | [
{
"body": "<p>The method name <code>CanAdd</code> implies that it won't have side effects. Therefore you could mistake the method in the future as a read-only method, while it isn't. Also because the relationship between checking whether it can be added to list A and adding it to another list is not strongly re... | {
"AcceptedAnswerId": "12045",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-24T16:03:40.340",
"Id": "12036",
"Score": "3",
"Tags": [
"c#"
],
"Title": "Side effects in functions that find boolean conditions"
} | 12036 |
<p>I want to optimize the performance of this SQL query. If I populate this hashtable with one million keys the query will take around minute. How I can optimize this Java method for faster execution?</p>
<pre><code>private HashMap<String, Boolean> selectedIds = new HashMap<>();
public void deleteSelected... | [] | [
{
"body": "<p>If you look at this in a profiler, I will bet that the most time is being used at this line:</p>\n\n<pre><code>ps.executeUpdate();\n</code></pre>\n\n<p>I would gather all strings to be deleted into one statement like:</p>\n\n<pre><code>DELETE FROM ACTIVESESSIONSLOG WHERE ASESSIONID IN ('A','B','C'... | {
"AcceptedAnswerId": "12044",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-24T16:41:34.977",
"Id": "12038",
"Score": "0",
"Tags": [
"java",
"optimization",
"sql",
"oracle",
"jdbc"
],
"Title": "How to optimize this SQL delete"
} | 12038 |
<p>I have this method inside a class that is responsible for setting up and executing a model:</p>
<pre><code>public FlowJob PrepareAndScheduleFlowModelJob(string coordinates)
{
GeometryCoordinateString coordinateString =
new GeometryCoordinateString(coordinates);
DataSet intersectedWatershedsDataSet ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-24T19:45:50.313",
"Id": "19306",
"Score": "0",
"body": "This method seems small and clean. If you can write an integration test and it is easy to do, then do it. Otherwise, I would not over-test. You could be doing other productive thi... | [
{
"body": "<p>What is supposed to happen when the <code>coordinates</code> parameter is null? And when it is an empty string? And when it does not properly represent a coordinate? You can create unit tests that test for these kind of situations, for example.</p>\n",
"comments": [],
"meta_data": {
... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-24T16:54:06.830",
"Id": "12039",
"Score": "2",
"Tags": [
"c#",
"unit-testing"
],
"Title": "How to unit test this method?"
} | 12039 |
<p>What's the fastest (quality is important too, but a little less important) way to compare two strings?</p>
<p>I'm looking for the most efficient way to compare two strings. Some of the strings I'm comparing can be over 5000 characters long. I'm comparing a list of about 80 strings with another list of about 200 str... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-24T20:03:20.917",
"Id": "19307",
"Score": "2",
"body": "If you really need to compare 80 strings with 200 strings for a total of 80*200 = 10000 comparisons, I see no way around it (try to use C?). But are you sure you need to do that a... | [
{
"body": "<p>A possible suggestions. By looking at your data, I see that the difference between the strings may be small.</p>\n\n<p>Since Levenshtein distance is a costly metric, it may be profitable to compute some other easy metric such that it is not too different from what may be obtained from Levenshtein ... | {
"AcceptedAnswerId": "12047",
"CommentCount": "7",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-24T18:44:30.313",
"Id": "12042",
"Score": "2",
"Tags": [
"java",
"performance",
"strings",
"edit-distance"
],
"Title": "Comparing long lists of strings for the closest match"
... | 12042 |
<p>I had to write a SQL query recently to do a few joins and sums, and at the end of it I realized that I have nearly written a storybook. I know the tools to optimize it, but my trouble is the length of it. I am very sure, it can be shortened up, but my little brain refuses to strengthen this belief.</p>
<p>Basically... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-25T00:39:58.903",
"Id": "19319",
"Score": "1",
"body": "Hm ... you could create, fill and update a temporary table or two to simplify things. I doubt that you have millions of teams and team members. You could also use several CTEs ...... | [
{
"body": "<p>You really should be more consistent with your choice of line breaks and indentation, especially in a query as large as this. Improving the readability should also make it easier to spot areas for improvement. You didn't indicate which DBMS you're using, but if it's supported, the <code>WITH</co... | {
"AcceptedAnswerId": "12185",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-25T00:23:41.260",
"Id": "12048",
"Score": "7",
"Tags": [
"sql",
"sql-server"
],
"Title": "Listing teams by total distance and bonus"
} | 12048 |
<p>I am in between to create JavaScript Boilerplate (collection of best practices around) for low/medium complex project and will host on GitHub in sometime once finalized it.</p>
<p>Have divided the JavaScript modules in 3 parts</p>
<ol>
<li>project.config.js - Would have all the required configuration</li>
<li>proj... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-06-06T06:28:05.267",
"Id": "25674",
"Score": "0",
"body": "BTW JavaScript Boilerplate has been on Git now @ https://github.com/mdarif/JavaScript-Boilerplate where I have integrated the review comments. And again anyone of you, have anythi... | [
{
"body": "<p>Interesting work Arif. I really loved to see different as well as interesting JS patterns you have used. It is looking to me like, it is going in a good and right direction. </p>\n\n<p>Few things that you might consider to do is</p>\n\n<p>I) Create some example of different modules and ensure they... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-25T05:20:22.603",
"Id": "12051",
"Score": "8",
"Tags": [
"javascript",
"design-patterns",
"singleton"
],
"Title": "JavaScript Boilerplate - Review comments required"
} | 12051 |
<p>I've implemented <code>concurrent_blocking_queue</code> for <em>multiple-producers</em> and <em>single consumer</em>.</p>
<p>I intend it to block the producers as well, when the queue is full, which is why I set the capacity of the queue in the constructor. I've provided my own implementation of <code>critical_sec... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-25T10:48:35.027",
"Id": "19329",
"Score": "0",
"body": "Does the implementation you use for condition variables unlock the mutex lock in the call to wait() like it does in Posix? If not, then Ive located a dead-lock."
},
{
"Con... | [
{
"body": "<h3>Basic comments:</h3>\n<p>No point in functions that do nothing.<br />\nAlso avoid <code>void</code> as definition for empty parameter list.</p>\n<pre><code>~condition_variable(void) {}\n</code></pre>\n<p>Why put a member that has no default constructor in the initializer list ( I can go either wa... | {
"AcceptedAnswerId": "12090",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-25T05:33:56.000",
"Id": "12052",
"Score": "5",
"Tags": [
"c++",
"multithreading"
],
"Title": "Implementation of concurrent blocking queue for producer-consumer"
} | 12052 |
<p>This is a simple thread safe queue that is used in a producer-consumer model.</p>
<pre><code>public class ThreadedQueue<TType>
{
private Queue<TType> _queue;
private object _queueLock;
protected ThreadedQueue()
{
_queue = new Queue<TType>();
_queueLock = new object... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-25T07:53:37.357",
"Id": "19326",
"Score": "2",
"body": "What's wrong with `ConcurrentQueue<T>`?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-25T08:14:56.717",
"Id": "19327",
"Score": "0",
"bo... | [
{
"body": "<p>This looks mostly fine by me (ignoring Reflection and other more obscure sources of thread safety failures), but I wouldn't call it a Queue per say (because of the duplicate check there). Does it really matter what order the set of items in this collection are in (if so then the duplicate check in... | {
"AcceptedAnswerId": "12079",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-25T06:39:49.160",
"Id": "12053",
"Score": "3",
"Tags": [
"c#",
"multithreading",
"thread-safety",
"queue"
],
"Title": "Simple generic multithreaded queue"
} | 12053 |
<p>There are two ways I have been using to create links and style them as buttons:</p>
<pre><code>background: url("/images/sing_up_btn.png") no-repeat scroll 0 0 transparent;
font-family: Arial,Helvetica,Sans-serif;
text-shadow: 0 -1px #444444;
text-transform: none;
</code></pre>
<p>Another one is:</p>
<pre><code>a... | [] | [
{
"body": "<p>I like the second option, it is easy to read if you just reformat it a little bit (also corrected your <code>:active</code> selector and fixed the shadow in IE9):</p>\n\n<pre><code>a.btn_link {\n background: #4468b2; /* Old browsers */\n background: -webkit-gradient(linear, left top, left bo... | {
"AcceptedAnswerId": "12068",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-25T06:42:10.747",
"Id": "12054",
"Score": "2",
"Tags": [
"css"
],
"Title": "Which is a better optmized CSS for a button design?"
} | 12054 |
<p>I have a constructor which sets a member variable. The setting of this variable throws an exception. Should I be throwing the exception in the contructor or enclosing the try/catch like below. Is below snippet an example of code smell ?</p>
<pre><code>private NewManager newManager;
public Save(final TheManager... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-29T02:52:59.703",
"Id": "19403",
"Score": "3",
"body": "I am confused about what exactly is a constructor in the supplied code, but my impression is that in this case `manager.getManager(str)` should be called before the constructor ge... | [
{
"body": "<p>Catching an exception and just printing stack trace and proceeding like nothing happened is certainly Very Bad. What if no one is watching the standard error stream (where <code>e.printStackTrace()</code> dumps its output)? In your case, you'll probably end up with <code>NullPointerException</code... | {
"AcceptedAnswerId": "12059",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-25T08:16:46.840",
"Id": "12058",
"Score": "7",
"Tags": [
"java"
],
"Title": "Bad practice to have try / catch in constructor?"
} | 12058 |
<p>I have the following function in a <code>Service</code> class</p>
<pre><code>protected function writeToFile():void{
var destinationFile:File = File.applicationStorageDirectory.resolvePath(_newPath);
var fs:FileStream = new FileStream();
fs.open(destinationFile, FileMode.WRITE);
fs.... | [] | [
{
"body": "<p>FileStream class has its own events which are dispatched when the file operation is successful or not.</p>\n\n<p><a href=\"http://help.adobe.com/en_US/FlashPlatform/reference/actionscript/3/flash/filesystem/FileStream.html#eventSummary\" rel=\"nofollow\">http://help.adobe.com/en_US/FlashPlatform/r... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-25T10:41:34.827",
"Id": "12061",
"Score": "3",
"Tags": [
"exception-handling",
"actionscript-3",
"error-handling",
"actionscript"
],
"Title": "Add events dispatching for ActionSc... | 12061 |
<p>This is a minimal little utility that I've found useful while reorganizing my music and book libraries. Any issues you can see? Anything I could be doing better or more elegantly? Anyone wanna take a crack at the equivalent in Python/Perl?</p>
<p>Take 2:</p>
<pre><code>#!/usr/bin/ruby
require 'optparse'
require '... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-29T18:10:21.557",
"Id": "19427",
"Score": "0",
"body": "I wonder if it might be better for you to add to the question rather than update it based on the review? Here is a [meta discussion](http://meta.codereview.stackexchange.com/quest... | [
{
"body": "<p>Some observations. The space between #! and the path to binary is not needed. (It used to be for some arcane versions of Unix but not anymore AFAIK)</p>\n\n<p>Secondly, I prefer to let env find ruby for portability.</p>\n\n<pre><code>#!/usr/bin/env ruby\n\nrequire 'optparse'\nrequire 'pp'\nrequire... | {
"AcceptedAnswerId": "12083",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-25T15:55:44.810",
"Id": "12070",
"Score": "3",
"Tags": [
"ruby"
],
"Title": "File Renaming with Ruby"
} | 12070 |
<p>See the full calculator with HTML -> <a href="https://gist.github.com/1861120" rel="nofollow">https://gist.github.com/1861120</a>
You should be able to drag that html file from github into a browser and start using it. I'm only putting the js below. The calculator works fine but JS Lint is telling me I have an unexp... | [] | [
{
"body": "<p>It's complaining that you haven't ended your assignment statment, <code>Math.factorial = ...</code>, with a semi-colon. (This is the case for just about every error jslint will throw with your code.)</p>\n",
"comments": [],
"meta_data": {
"CommentCount": "0",
"ContentLicense": ... | {
"AcceptedAnswerId": "12084",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-25T19:47:19.943",
"Id": "12076",
"Score": "3",
"Tags": [
"javascript"
],
"Title": "JSLint says \"unexpected function\" doCalc"
} | 12076 |
<p>I am trying to optimize inserts from a returned JSON which contains data from multiple tables on the remote server. My code is working, but I just want to figure out a way for it to work better. I need the structure to be very dynamic (i.e. fetching the table names from JSON then looping through to complete the inse... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-25T16:53:43.677",
"Id": "19343",
"Score": "0",
"body": "Every real database has a support for something that is called bulk insert. Look for it, check out this blog http://blog.quibb.org/2010/08/fast-bulk-inserts-into-sqlite/"
}
] | [
{
"body": "<p>When in doubt, run SQL statements, of either form:</p>\n\n<ul>\n<li><code>insert into table (col1, col2, ...) values ('val11', 'val12', ...), ('val21', 'val22', ...)</code></li>\n<li><code>insert into table (col1, col2, ...) values (@val1, @val2)</code></li>\n</ul>\n\n<p>Theoretically a proper DBM... | {
"AcceptedAnswerId": "12087",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-25T15:36:53.963",
"Id": "12085",
"Score": "3",
"Tags": [
"java",
"optimization",
"android",
"sqlite"
],
"Title": "Optimizing mass inserts into SQLite"
} | 12085 |
<p>I have a Core Data model with two entities: <code>Video</code> and <code>Playlist</code>.</p>
<ul>
<li>A <code>Video</code> can be a member of many <code>Playlist</code>s</li>
<li>A <code>Playlist</code> can have many <code>Video</code>s, including the same <code>Video</code> multiple times</li>
<li>A <code>Playlis... | [] | [
{
"body": "<p>Perhaps I'm missing something, but it seems that the <code>Video</code> objects don't really need to know about what playlists they belong to, do they?</p>\n\n<p>A playlist is a collection of videos. You don't need a playlist index object. You just need an array on each playlist that keeps track... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-26T00:58:01.077",
"Id": "12089",
"Score": "2",
"Tags": [
"objective-c",
"ios",
"core-data"
],
"Title": "Core Data model of video and entities"
} | 12089 |
<p>I find myself nesting a lot of grids inside grids in WPF. I just found myself 3 Grids deep, and stopped to think: "Should I be doing this?" Is there some kind of performance cost? Is it unmaintainable? (Kind of like heavily nested <code>if</code>s maybe.)</p>
<p>I guess the alternative is to have one grid, and use ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-27T17:24:07.883",
"Id": "19373",
"Score": "0",
"body": "If you asked me, if it makes sense to logically group the content within a grid, then go for it. If they're unrelated then you definitely should rethink what you're doing."
}
] | [
{
"body": "<p>The Grid is the most powerful layout control in XAML technology. Since you use a Grid inside another probably you already considered use another layout control first. But they can't fit where you want. In many cases I will need a layout control I think about some things:</p>\n\n<ol>\n<li>Can I st... | {
"AcceptedAnswerId": "26723",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-26T06:06:02.887",
"Id": "12091",
"Score": "28",
"Tags": [
"c#",
"wpf",
"layout",
"xaml"
],
"Title": "Is nesting grids a good idea?"
} | 12091 |
<p>I took my first stab at a user authentication function. I invented my own way of doing this. Is this a safe and efficient way of giving a user Read/Edit/Delete permission on tables in a MySQL database?</p>
<h2>The Class</h2>
<pre><code>class Personnel {
//set tables that will need permissions and actions
protected... | [] | [
{
"body": "<p>I think storing the serialized php structure to the database is not a good practice.</p>\n\n<p>You can make a separate table like this</p>\n\n<pre><code>permissions\n\n user_id \n\n table_id\n\n read - boolean\n\n update - boolean\n\n delete - boolean\n</code></pre>\n\n<p>Three boolean values... | {
"AcceptedAnswerId": "12152",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-23T23:53:32.697",
"Id": "12092",
"Score": "6",
"Tags": [
"php",
"mysql",
"authentication",
"crud"
],
"Title": "User Authentication/Permissions for PHP MySQL CRUD"
} | 12092 |
<p>I'm working right now in a readers social network. The main points are this:</p>
<ol>
<li>When an user connects with his account I save his user id in the
session variable. </li>
<li>My MVC is working with DTO's all the way, filling the necessary
variables for the presentation in the model.</li>
</ol>
<p>So, every... | [] | [
{
"body": "<ol>\n<li><p>I'd create an <code>UserProfilePageDTO</code> to separate that information:</p>\n\n<pre><code>public class UserProfilePageDTO {\n\n private UserProfileDTO userProfile;\n\n private Boolean isCurrentUser;\n private Boolean isfollowedByCurrentUser;\n ...\n}\n</code></pre></li>\n... | {
"AcceptedAnswerId": "43827",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-26T15:26:32.347",
"Id": "12094",
"Score": "4",
"Tags": [
"java",
"mvc",
"dto"
],
"Title": "Is the \"current connected user\" an information that should be shared with the domain?"... | 12094 |
<p>The code below is for modern browsers only.</p>
<p>Naming conventions are as follows:</p>
<pre><code>m or M - Model
v or V - View
c or C - Controller
/********************************************************************************************
************************************************************... | [] | [
{
"body": "<p>The code within the functions seems clear and simple to me, so my answer mostly focus on the naming conventions:</p>\n\n<ol>\n<li><p>Why call your variables m..., v..., c... when you could call them \"model\", \"view\", \"controller\"? This would make your code immediately clearer to anyone who re... | {
"AcceptedAnswerId": "12102",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-26T20:17:01.477",
"Id": "12098",
"Score": "1",
"Tags": [
"javascript",
"mvc",
"library-design"
],
"Title": "Foo - Control | Naming conventions update"
} | 12098 |
<p>Could you explain to me which code is better (more optimal) and why?</p>
<p>Vesion 1:</p>
<pre><code>while(something){
Runnable task = (Runnable) taskQueue.dequeue();
Throwable ex = null;
...
}
</code></pre>
<p>Version 2:</p>
<pre><code>Runnable task;
Throwable ex;
while(something){
task = (Runnable) taskQueue... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-26T21:06:46.143",
"Id": "19365",
"Score": "6",
"body": "Any compiler worth its salt would move the declaration out for you automatically. Use the second if task and ex are to be accessed outside the block. Otherwise no recommendation h... | [
{
"body": "<p>At the bytecode level, there is no such thing as inner block. All local variables are declared at the scope of the method. As a result, both your variants should produce equivalent bytecode. To make sure, decompile them with javap and look at the bytecode. From the programmer's point of view, vers... | {
"AcceptedAnswerId": "12116",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-26T20:48:31.813",
"Id": "12099",
"Score": "2",
"Tags": [
"java",
"optimization"
],
"Title": "Java - Object declaration out of while loop"
} | 12099 |
<p>I have n-times similar statements</p>
<pre><code> if trigger_data.tt_closed
unless trouble_ticket.changes.key?(:status)
@run = 0
break
end
unless trouble_ticket.changes[:status][1] == "Closed"
@run = 0
break
end
end
if trigger_data.tt_assignee
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-26T22:49:55.827",
"Id": "19367",
"Score": "0",
"body": "Did you forget @run = 0 in the final one?"
}
] | [
{
"body": "<p>Are you inside a loop? Here is a possible way of doing it</p>\n\n<pre><code>def check(td, tt, trigger, key, ticket_changes)\n if td.send(trigger)\n unless tt.changes.key?(key)\n @run = 0\n return true\n end\n unless tt.changes[key][1] == ticket_changes\n @run... | {
"AcceptedAnswerId": "12101",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-26T21:25:46.733",
"Id": "12100",
"Score": "0",
"Tags": [
"ruby"
],
"Title": "Ruby code refactoring"
} | 12100 |
<p>I wrote this algorithm to determine the winning hand of two players going head to head with a hand of One Pair. Note that the hand is sorted once it is given out, and the algorithm has to compare the two hands one pair, if one has a higher one pair such as AA vs 33, there is an obvious winner. If the hands have ma... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-06T12:37:28.240",
"Id": "64559",
"Score": "0",
"body": "I dont wish to post a link as an answer, but look at http://www.suffecool.net/poker/evaluator.html for a fast solution"
}
] | [
{
"body": "<p>I'm not really any good at algorithms as such so my main suggestion would be to remove duplicate code. That is primarily in the creation of your pPairHigh and oPairHigh blocks of code.</p>\n\n<p>I admit they do share a common loop which in my implementation means this will be occurring twice. If... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-27T17:25:57.287",
"Id": "12107",
"Score": "1",
"Tags": [
"java",
"algorithm",
"playing-cards"
],
"Title": "2vs2 Poker Hand One Pair Winner Algorithm"
} | 12107 |
<p>I'm teaching myself BigDecimal and would appreciate a critique. In the code fragment below, I calculate a tip from user input: check and tip percentage (entered as integer): </p>
<pre><code> txt_check = txtcheck.getText().toString();
tpercent = txttippct.getText().toString();
BigDecimal hundred = new BigDecimal... | [] | [
{
"body": "<p>For such a simple calculation, the logic used for the <code>bdtip</code> and <code>bdtotal</code> variables wasnt straight forward. Instead of creating it with the value of one of the operands, then multiplying/adding it by the other operand, why not do something like the following:</p>\n\n<pre><c... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-27T17:58:17.583",
"Id": "12108",
"Score": "3",
"Tags": [
"java",
"android"
],
"Title": "BigDecimal code critique"
} | 12108 |
<p>I've written the following <code>explode</code> function using <code>break</code>. The intended behavior is, that a list is divided into sublists by a predicate function, i.e. those elements which match the predicate are the separators - no empty lists should be returned.</p>
<p>Here are some examples:</p>
<pre><c... | [] | [
{
"body": "<p>grouping list separated by some values intuitively seems like a group by operation. That is, abc,def,ghi => (abc)(def)(ghi)\nSo groupBy seems more intuitive for me, and it results in more concise code.</p>\n\n<pre><code>import Data.List\n\nexplode fn = filter (nfn . head) . gb\n where nfn = not .... | {
"AcceptedAnswerId": "12128",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-27T18:18:57.407",
"Id": "12109",
"Score": "2",
"Tags": [
"haskell"
],
"Title": "Haskell function to explode a list"
} | 12109 |
<p>Inspired by <a href="https://github.com/themattrix/poker_hand" rel="nofollow">this post</a> (along with a number of other people by the looks of it), I created a poker hand identifier with a very similar format. Note that the syntax of the hands is a little different to make parsing easier - rather than "A:C K:C Q:C... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-07-15T07:47:04.070",
"Id": "22124",
"Score": "2",
"body": "Don't forget about the \"wheel\" straight - A 2 3 4 5."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-17T22:37:41.947",
"Id": "72191",
"Score... | [
{
"body": "<p>So here is my version of your program. It took some pragmas, but I hope it is alright?</p>\n\n<pre><code>{-# LANGUAGE FlexibleInstances,IncoherentInstances,ScopedTypeVariables #-}\nimport Data.List (sort, deleteBy, nub)\nimport Data.Maybe (isJust)\nimport Control.Monad (guard)\nimport Data.Functio... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-27T22:39:22.403",
"Id": "12112",
"Score": "4",
"Tags": [
"haskell",
"playing-cards"
],
"Title": "Poker hand identifier"
} | 12112 |
<p><a href="http://en.wikipedia.org/wiki/Bell_number" rel="nofollow noreferrer">Bell number</a> \$B(n)\$ is defined as the number of ways of splitting \$n\$ into any number of parts, also defined as the sum of previous \$n\$ <a href="http://en.wikipedia.org/wiki/Stirling_numbers_of_the_second_kind" rel="nofollow norefe... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2016-11-17T22:31:12.390",
"Id": "276934",
"Score": "1",
"body": "Please check whether your code is indented correctly."
}
] | [
{
"body": "<p>You can use the <a href=\"http://mathworld.wolfram.com/DobinskisFormula.html\" rel=\"noreferrer\">Dobinski</a> formula for calculating Bell numbers more efficiently. </p>\n\n<p>Dobinski's formula is basically something like this line, although the actual implementation is a bit more complicated (t... | {
"AcceptedAnswerId": "12121",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-28T10:21:14.857",
"Id": "12119",
"Score": "2",
"Tags": [
"python",
"combinatorics"
],
"Title": "Printing nth bell number"
} | 12119 |
<p>I have to interface to some old code using nested arrays, so I have to convert my nested Lists to nested arrays. Any idea, suggestions, improvements are warmly welcomed.</p>
<pre><code>public static <E> int getNestedListMaxSize(List<List<E>> list){
int result = 0;
if (list != null &&am... | [] | [
{
"body": "<p>I'd use <a href=\"http://www.codinghorror.com/blog/2006/01/flattening-arrow-code.html\" rel=\"nofollow\">guard clauses</a> to check whether the list parameter is <code>null</code> or not. Furthermore, the <code>list.size() > 0</code> check looks unnecessary in the first two methods, the result ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-28T10:38:51.187",
"Id": "12120",
"Score": "1",
"Tags": [
"java",
"array",
"generics"
],
"Title": "Java generics, convert nested list to array"
} | 12120 |
<p>Im working on a small desktop app which controls services on a server. For controlling services i am using ServiceController class. What i want to do is; testing my code and abstract the ServiceController class from my code. So i did something like below.</p>
<pre><code> public interface IServiceControllerWrapper... | [] | [
{
"body": "<p>If your mocking framework is similar to the one I use, you probably need to stub ServerNameOrIP on your injected IServiceControllerWrapper mock. It is not uncommon for mocked objects to return default(T) for anything not yet stubbed.</p>\n\n<p>As an aside, I would suggest modifying your IServiceC... | {
"AcceptedAnswerId": "12159",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-28T15:25:44.470",
"Id": "12126",
"Score": "1",
"Tags": [
"c#",
"unit-testing"
],
"Title": "Testing ServiceController Class"
} | 12126 |
<p>I want to create lists of the nodes of a binary tree at each depth.<br>
So if the depth is X I would have X lists.<br>
Please see my approach. I think it is correct. Am I right to believe it is correct? Any input is welcome: </p>
<pre><code>public List<List<BinaryNode>> getNodesPerDepth(BinaryNode root... | [] | [
{
"body": "<p>Do you really want to go recursive on this? Binary trees in the worst case may be a linear list. A better idea is to do some thing like this:</p>\n\n<pre><code>getNodesPerDepth(rootNode) {\n list.add(rootNode); // Start with the root node,\n dlst = new List() // depth lit\n while(list.siz... | {
"AcceptedAnswerId": "12132",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-28T17:28:30.900",
"Id": "12127",
"Score": "3",
"Tags": [
"java",
"algorithm"
],
"Title": "List creation of BST's nodes"
} | 12127 |
<p>This is for a plugin I am making for the game called Minecraft. The code is responsible for finding out the blocks placed by the player and if they are in the following sequence as shown in the picture then create an <code>Antenna</code>. <code>block</code> in <code>block.getType()</code> returns the block placed by... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-29T02:22:29.567",
"Id": "19399",
"Score": "0",
"body": "Aren't you creating three antennas there?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-29T02:38:21.833",
"Id": "19400",
"Score": "0",
"... | [
{
"body": "<p>As it is mentioned in the comments, It seems your code is exactly same as the below. So that is the first suggestion. </p>\n\n<pre><code>main = block.getType();\nup1 = block.getRelative(BlockFace.UP, 1).getType();\nup2 = block.getRelative(BlockFace.UP, 2).getType();\ndown1 = block.getRelative(Bloc... | {
"AcceptedAnswerId": "12130",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-29T00:09:33.247",
"Id": "12129",
"Score": "2",
"Tags": [
"java",
"optimization",
"minecraft"
],
"Title": "Plugin for finding placed blocks and if they are in a certain sequence"
} | 12129 |
<p>I'm switching to Ruby from Java and so, for exercise purposes, I wrote this verbose leap year Ruby program. The comments express my concerns about Ruby best practices. I'd be glad if some Ruby experienced programmer could dispel my doubts. Every hint such as <em>"in Ruby you can achieve this thing better this way"</... | [] | [
{
"body": "<p>Nice effort, :) here are a few comments.</p>\n\n<p>unless you are calling this as part of another class, \ndo not use @member syntax. What you really want is a global.</p>\n\n<pre><code>$present = Time.now.year \n</code></pre>\n\n<p>Shorter name :), plus it is better to capture it in case statemen... | {
"AcceptedAnswerId": "12147",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-29T10:47:36.780",
"Id": "12136",
"Score": "3",
"Tags": [
"ruby",
"datetime",
"iterator"
],
"Title": "Leap year program"
} | 12136 |
<p>I needed to build a slider, and this is my first attempt. I'm trying to make it as dynamic as possible. My code works, but I'm wondering if there is a better way and if anyone has any suggestions. I'll be making the width calculated as well. I just have it hardcoded for testing.</p>
<p>Also, I need to make paginati... | [] | [
{
"body": "<p>Some minor improvements you can make:</p>\n\n<ol>\n<li><p>Cache your DOM lookups (e.g. <code>$('.slider img')</code>) to prevent having to parse the DOM multiple times. That's as simple as making a new variable:</p>\n\n<pre><code>var sliderImages = $('.slider img');\n</code></pre></li>\n<li><p>Use... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-25T01:45:39.087",
"Id": "12139",
"Score": "1",
"Tags": [
"javascript",
"jquery"
],
"Title": "Refactoring jQuery slider code suggestions"
} | 12139 |
<p>I have 30 icons, and after hover, different icons are shown. How can I write this shorter?</p>
<p><strong>jQuery</strong></p>
<pre><code>$('#iconTech01').hover(
function() {
$('#iconTechBig01').stop(true, true).fadeIn("slow");
$('#iconTech01 img').stop(true, true).fadeOut("slow");
... | [] | [
{
"body": "<p>Certainly, assign a class to each tech icon (I'm assuming they're divs), use a JQuery selector to select all DOM element with the assigned class and then use <code>each()</code> to step through each item. </p>\n\n<pre><code><div class=\"icon\" id=\"iconTech01\"><img ..../></div>\... | {
"AcceptedAnswerId": "12161",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-29T13:49:57.347",
"Id": "12141",
"Score": "4",
"Tags": [
"javascript",
"jquery",
"html",
"image"
],
"Title": "Showing different icons on hover"
} | 12141 |
<p>The reason why I want to have something like this is to be able to add custom methods/props to certain arrays only. I came up with this little object that works well but I'm wondering if you guys have better way.</p>
<pre><code>(function (scope) {
var target = scope || window;
target.Hurray = function() {
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-25T19:35:45.477",
"Id": "19414",
"Score": "2",
"body": "What's wrong with using regular arrays? How many do you have?"
}
] | [
{
"body": "<p>If you don't need the magic <code>.length</code> property, then how about making a constructor function whose prototype is an object that inherits from <code>Array.prototype</code>?</p>\n\n<pre><code>function Hurray() {}\n\nHurray.prototype = Object.create(Array.prototype);\n</code></pre>\n\n<hr>\... | {
"AcceptedAnswerId": "12143",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-25T19:32:23.907",
"Id": "12142",
"Score": "3",
"Tags": [
"javascript"
],
"Title": "What is a good way create a Javascript array-like object?"
} | 12142 |
<p><strong>Edit</strong></p>
<p>The rest of my code utilises the Command/Query seperation pattern. I'll probably move this out into a command and a query but for now I've written this directly in my MVC controller for brevity.</p>
<p><strong>Original</strong></p>
<p>I'm quite new to Fluent NHibernate and its various... | [] | [
{
"body": "<p>Admittedly I am using a really old version of nhibernate, but I think this is still there (to replace a few lines):</p>\n\n<pre><code>Restrictions.InG(\"Name\", tagNames.ToList())\n</code></pre>\n\n<p>I think I would also bring the using statement outside of the loop:</p>\n\n<pre><code>private IEn... | {
"AcceptedAnswerId": "12163",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-29T18:23:38.980",
"Id": "12150",
"Score": "1",
"Tags": [
"c#",
"asp.net-mvc-3"
],
"Title": "Fluent NHibernate, Getting or Creating a new `Tag`"
} | 12150 |
<p>I need to pass an array of values in Url.Action.</p>
<p>Currently I'm doing:</p>
<pre><code>var redirectUrl = Url.Action("search", new {
q = criteria.Q,
advanced = criteria.Advanced,
salaryfrom = criteria.SalaryFrom,
salaryto = criteria.SalaryTo,
});
if (criteria.JobTypes !=... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-11T13:11:47.583",
"Id": "19433",
"Score": "0",
"body": "If it is few 2-4, It is ok to pass in URL ,But you have lots of values, I would like to pass an ID and get the object again in the next action method. But in your case i guess it ... | [
{
"body": "<ul>\n<li>Concerning the comment you got about passing an ID, note that it's better to put search parameters in the URL, since it allows users to link to that search and refresh the page without having issues. All search engines do that.</li>\n<li>Make sure to test for null without using type coercio... | {
"AcceptedAnswerId": "12158",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-11T13:07:25.370",
"Id": "12151",
"Score": "2",
"Tags": [
"c#",
"asp.net"
],
"Title": "Passing an array of values in UrlAction"
} | 12151 |
<p>I am not experienced in C++, and wrote this code for implementing a stack data structure using a linked list.</p>
<p>Can you please point out any flaws, errors, stupid mistakes, general improvements etc that can make this code better?</p>
<pre><code>#include <iostream> ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-30T06:00:31.673",
"Id": "19447",
"Score": "1",
"body": "If you are using c++, is there any reason you are not using STL containers?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-30T06:01:45.233",
"Id"... | [
{
"body": "<p>A few comments, wrt style.</p>\n\n<pre><code>#include <iostream> \nusing namespace std;\n</code></pre>\n\n<p>You don't need a forward declaration of struct Node.</p>\n\n<pre><code>//struct Node;\n</code></pre>\n\n<p>You could add a constructo... | {
"AcceptedAnswerId": "12157",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-30T05:57:54.337",
"Id": "12155",
"Score": "5",
"Tags": [
"c++",
"stack"
],
"Title": "Simple stack implementation"
} | 12155 |
<p>I was building a quiz module for one website. It is a simple true/false statements where you first choose the answer, the correct answer is displayed, and then you can move forward to the next question. </p>
<p>For better understanding, please find working code snippet <a href="http://jsfiddle.net/ylokesh/Qaf8w/50/... | [] | [
{
"body": "<p>Overall this is already pretty well organized and compact. There isn't a lot of duplication or obvious abstractions that can be made. It would be helpful to see the HTML to see if there are any changes that would make the Javascript easier to write.</p>\n<p>A couple of suggestions:</p>\n<ol>\n<l... | {
"AcceptedAnswerId": "12205",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-30T14:56:44.057",
"Id": "12164",
"Score": "4",
"Tags": [
"javascript",
"jquery",
"html"
],
"Title": "Static quiz module with predefined answers"
} | 12164 |
<p>I wrote a factorial/permutations/combinations program in Java, and I want to do the same in C#. I noticed (from various research) that when you use the <code>ulong</code> variable type, the max value is higher than Java's <code>long</code>. My limitation in the Java version was that the <code>long</code> type was ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-30T15:06:18.713",
"Id": "19469",
"Score": "2",
"body": "Use `double` if you want a greater range."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-30T15:08:34.853",
"Id": "19471",
"Score": "0",
"... | [
{
"body": "<p>Signed 64-bit integer (<code>long</code> in both Java and C#) can have values between approximately -9 · 10<sup>18</sup> and 9 · 10<sup>18</sup>. Unsigned 64-bit integer (<code>ulong</code> in C#) can have values between 0 and approximately 1.8 · 10<sup>19</sup>. The value of 20! is approximately ... | {
"AcceptedAnswerId": "12169",
"CommentCount": "9",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-30T15:00:29.433",
"Id": "12165",
"Score": "3",
"Tags": [
"c#"
],
"Title": "Factorial/permutations/combinations program"
} | 12165 |
<p>I struggled a short while to make this work, so I'm wondering if there are any smarter ways for finding the highest of two values per array element? Uh, hard to explain by words, but by code its easy:</p>
<p>Data (random):</p>
<pre><code> (a) (b) // a and b are both positive values.
10 0.5
13 10.8
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-30T15:33:29.890",
"Id": "19473",
"Score": "0",
"body": "Do you have max_bounds for either a or b? That is other than max_int?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-30T16:02:47.593",
"Id": "194... | [
{
"body": "<p>What you are doing is just normal search for a max pair using <a href=\"http://en.wikipedia.org/wiki/Lexicographical_order\" rel=\"nofollow\">lexicographical</a> ordering.</p>\n\n<p>The issue with your code is that, it is linear O(n). While for a single use, this might be the best way, if you have... | {
"AcceptedAnswerId": null,
"CommentCount": "17",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-30T15:28:00.790",
"Id": "12166",
"Score": "3",
"Tags": [
"c++",
"search",
"sorting"
],
"Title": "Finding the highest values a and b from an array"
} | 12166 |
<p>The Enumeration in question is based on <code>int</code>, so the following Extension returns a <code>Dictionary<int, string></code> of the Enum's Value and Description.</p>
<p>Is there a cleaner way of implementing this?</p>
<pre><code>public enum TeamDepartments
{
[Description("Geschäftsleitung")] Manag... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-31T19:40:24.883",
"Id": "19563",
"Score": "0",
"body": "The method name should be `GetDescription`. Also, the dictionary is unnatural because you lose some of the type-safety, plus you are not wasting THAT much time if you call `GetDes... | [
{
"body": "<p>You should separate the code returning the attributes of a type into another extension method. It would probably prove useful later on, anyway. Perhaps return an IEnumerable<> of attributes, and process it into a dictionary using a LINQ statement.</p>\n",
"comments": [],
"meta_data": {
... | {
"AcceptedAnswerId": "12178",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-30T17:33:35.163",
"Id": "12173",
"Score": "2",
"Tags": [
"c#",
"reflection",
"enum"
],
"Title": "Casting an Enumeration with Descriptions into a Dictionary"
} | 12173 |
<p>I have an extremely simple self-playing Tetris game which I coded up and I am looking to see how it could be improved. It would also be a learning curve for me to see how those much better than I am would go about improving the code.</p>
<pre><code>##################################################################... | [] | [
{
"body": "<p>A few general comments:</p>\n\n<ul>\n<li><p>Python constants should be capitals, for e.g width, height etc should be capitalized in your code since they are constants (declared at the beginning).</p></li>\n<li><p>The places where you have indicated \"constructors and selectors\" probably indicate ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-30T18:15:23.927",
"Id": "12175",
"Score": "13",
"Tags": [
"python",
"game",
"pygame",
"tetris"
],
"Title": "Self-playing Tetris game"
} | 12175 |
<p>I have a Windows application and want to self-host a WCF in it. This <a href="http://msdn.microsoft.com/en-us/library/ms731758.aspx" rel="nofollow">MSDN article</a> walks you through how to self-host WCF in a console. <a href="http://www.codeproject.com/Articles/18789/A-Quick-and-Dirty-WCF-Service-and-Client-Using-W... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-31T05:59:25.737",
"Id": "19516",
"Score": "1",
"body": "That looks pretty simple to me... what exactly do you expect us to _review_?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-31T14:01:21.033",
"Id... | [
{
"body": "<p>You can also start host in another thread:</p>\n\n<pre><code>Task.Factory.StartNew(() =>\n {\n ServiceHost host = new ServiceHost(typeof(MyService));\n host.Open();\n };\n</code></pre>\n\n<p>(or using classic Thread and ThreadStart).</p>\n",
"comments": [
{... | {
"AcceptedAnswerId": "12184",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-31T03:45:10.963",
"Id": "12180",
"Score": "0",
"Tags": [
"c#",
"winforms",
"wcf"
],
"Title": "Self-hosting WCF in Windows Forms without another Windows process"
} | 12180 |
<p>I have a code snippet below and because of habit from other programming languages I wanted to use a <code>do-while</code> loop instead. But Python offers only the construct which I show as a second code snippet instead of a <code>do-while*</code>loop.
What is the best pythonic way to code this?</p>
<pre><code>ch = ... | [] | [
{
"body": "<p>I found a way to do this with <a href=\"http://docs.python.org/tutorial/datastructures.html\" rel=\"nofollow\">Python List Comprehension</a> (chapter 5.1.4) as follows:</p>\n\n<p>(Notice that I used <code>sys.stdin.read(1)</code> instead of <code>getch()</code>)</p>\n\n<pre><code>>>> impo... | {
"AcceptedAnswerId": "12187",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2012-05-31T07:48:36.970",
"Id": "12183",
"Score": "5",
"Tags": [
"python"
],
"Title": "Reading a controll character in a loop in Python"
} | 12183 |
<p>I am creating a skeleton application to demonstrate use of the Strategy design pattern and inversion of control inside a Strategy.</p>
<p>The application is the backend of a simple board game, which also has the capability to save and load the board. Since we can have different types of data stores for saving, I ha... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-31T11:21:07.873",
"Id": "19523",
"Score": "0",
"body": "Thanks for your question! I'm not sure whether this is on-topic or not. Code should already be working according to the faq."
},
{
"ContentLicense": "CC BY-SA 3.0",
"C... | [
{
"body": "<p>For me the question is how the strategy is created. Is it possible to inject the file name during construction of the strategy? That would be the way I would do it.</p>\n\n<p>Else you can create callbacks that are created and injected. When you need the file call this callback and let this decide ... | {
"AcceptedAnswerId": "18511",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-31T10:44:48.700",
"Id": "12190",
"Score": "2",
"Tags": [
"java",
"design-patterns",
"unit-testing"
],
"Title": "How to use inversion of control within a strategy when using the st... | 12190 |
<p>The idea is to take the common-known (and awfully bad performing) Fibonacci(n) recursive method:</p>
<pre><code># recursively computate fibonacci(n)
def fib(n)
n <= 2 ? 1 : fib(n-2) + fib(n-1)
end
</code></pre>
<p>and to optimize it with some Ruby reflection:</p>
<pre><code>require 'benchmark'
def fib(n)
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-31T18:26:42.940",
"Id": "19559",
"Score": "2",
"body": "I would suggest using an array instead of instance variables"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-31T19:44:08.213",
"Id": "19564",
... | [
{
"body": "<p>One possible solution with <code>lambda</code>:</p>\n\n<pre><code>fibp =\n lambda do\n a = [0, 1]\n lambda do |n|\n if n > 1\n a[n] ||= fibp[n - 2] + fibp[n - 1]\n else\n n\n end\n end\n end \\\n .call\n\np fibp[1000]\n</code></pre>\n\n<p>Still prone t... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-31T16:04:43.890",
"Id": "12194",
"Score": "4",
"Tags": [
"beginner",
"ruby",
"recursion",
"reflection",
"fibonacci-sequence"
],
"Title": "Ruby Fibonacci(n) recursive computat... | 12194 |
<p>I am looking into splay trees and I implemented a version. It seems correct. Could someone please let me know if this indeed correct and how to improve it?<br>
I will just show the <code>insert</code> item and <code>splay</code>. It should be enough.</p>
<p>The code is not that big as it seems in the first look. Br... | [] | [
{
"body": "<p>I did not check if the tree is indeed correct, but some comments in your design.</p>\n\n<ul>\n<li><p><code>rotateWithLeftChild</code> and <code>rotateWithRightChild</code> should be collapsed into some thing like</p>\n\n<pre><code>public final static<AnyType> BinaryNode<AnyType> rotat... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-31T16:16:55.630",
"Id": "12195",
"Score": "2",
"Tags": [
"java",
"algorithm",
"tree",
"binary-search"
],
"Title": "Splay tree implementation"
} | 12195 |
<p>The Demo for what I have made is located here: <a href="http://jsfiddle.net/maniator/H5LKy/181/" rel="nofollow noreferrer">http://jsfiddle.net/maniator/H5LKy/181/</a></p>
<p>Basically I am trying to make a Wheel of Fortune type game.</p>
<p>Is there anything I could improve on in the code?</p>
<pre><code>var WOF ... | [] | [
{
"body": "<p>Your array <code>.randomize()</code> isn't really that good. Consider:</p>\n\n<pre><code>var l = 100000, o = {}, a;\n\nwhile( l-- ) {\n a = [1,2,3,4,5,6,7,8,9,10];\n a.randomize();\n if( !o[a[0]] ) {\n o[a[0]] = 0\n }\n\n o[a[0]]++;\n}\n</code></pre>\n\n<p>Result:</p>\n\n<pre... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-31T16:47:01.980",
"Id": "12197",
"Score": "1",
"Tags": [
"javascript",
"game"
],
"Title": "Wheel of Fortune game"
} | 12197 |
<p>I need a way to store and retrieve callbacks in Ruby, so I made a <code>Callbacks</code> class. Any suggestions would be greatly appreciated.</p>
<pre><code>class Callbacks
def initialize
# name: name of callback
# event: event of which it belongs
# callback: block to call
@callbacks = []
end
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-31T18:16:35.467",
"Id": "19556",
"Score": "0",
"body": "Just to be sure, you are returning the callback even if one of the properties does not match. Is this intensional?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDat... | [
{
"body": "<p>Why not use a hashmap as the main DS? That way, you optimize for when name and event are defined, and suffer only a constant penalty and degrades to linear for other cases. (In your solution the cost is always linear). (As below)</p>\n\n<pre><code>class Callbacks\n def initialize\n @callbacks ... | {
"AcceptedAnswerId": "12207",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-31T17:53:00.750",
"Id": "12201",
"Score": "3",
"Tags": [
"ruby",
"callback"
],
"Title": "Ruby Callback System"
} | 12201 |
<p>I am interested in printing all numbers that do not have a match in an array.<br>
Example: <code>1,3,4,5,3,4,5,5,6</code> result <code>1,5,6</code><br>
Please review my solution bellow. What would be a much better way for this? Any input on how to improve this is welcome</p>
<pre><code>public static Integer[] outpu... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-06-13T15:26:51.203",
"Id": "20195",
"Score": "1",
"body": "Are you sure that you have phrased this question correctly? \"am interested in printing all numbers that do not have a match in an array.\" Based on your input, 1 appears once, 3... | [
{
"body": "<p>I think this is the sort of thing for which <code>HashSet</code> is perfect. Your implementation would look something like I have shown below. The advantage is that you don't need a sort so your running time is strictly linear.</p>\n\n<p>(Updated to fix syntax errors)</p>\n\n<pre><code>public stat... | {
"AcceptedAnswerId": "12206",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-31T20:07:53.067",
"Id": "12203",
"Score": "6",
"Tags": [
"java",
"algorithm",
"array"
],
"Title": "Find all single elements in an array"
} | 12203 |
<p>I've written a class for loading a template file and replacing the variables with actual data. Please review my code and suggest improvements.</p>
<pre><code><?php
/**
* This class will helpful for variable replacement from a loaded file
*
* @author V V R
* @version 1.0
*/
class Parser {
public $dir = ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-06-01T07:19:34.340",
"Id": "19574",
"Score": "0",
"body": "Have you considered using an existing solution, such as [Mustache PHP](https://github.com/bobthecow/mustache.php)?"
}
] | [
{
"body": "<p><strong>Note:</strong> I'm sorry if this is completely irrelevant but I'm not entirely sure what you are trying to accomplish. If I'm way off base please let me know.</p>\n\n<p>When I create a template loader I generally use <a href=\"http://php.net/manual/en/book.outcontrol.php\">output buffering... | {
"AcceptedAnswerId": "12216",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-06-01T06:28:57.453",
"Id": "12211",
"Score": "5",
"Tags": [
"php",
"php5"
],
"Title": "Replacing variables with actual data"
} | 12211 |
<p>Callback is a piece of code that is stored or registered in a higher layer or a different object such that the piece of code being stored has access to the information available in the current context. The registrar has the ability to invoke the code later in response to some event so that the action performed has a... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-06-01T15:53:49.267",
"Id": "12218",
"Score": "0",
"Tags": null,
"Title": null
} | 12218 |
Callback is facility to save a piece of code so that it may be invoked later in the current environment (Typically in response to an event) | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-06-01T15:53:49.267",
"Id": "12219",
"Score": "0",
"Tags": null,
"Title": null
} | 12219 |
<p>I did a quick google search, and it didn't show up.</p>
<p>I haven't noticed it posted in pylint.py, or PEP8.py.</p>
<p>My emacs mode doesn't warn me if my <code>import</code>s are listed arbitrarily...does anyone do this?</p>
<pre><code>import longest.modulename.first
import medium.sizename
import short
import s... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-06-05T23:27:38.393",
"Id": "19763",
"Score": "0",
"body": "Interesting ... StyleCop can handle this for C#, and yes - system imports come first."
}
] | [
{
"body": "<p>With a lot of import statements, I usually group imports by use case and origin.</p>\n\n<pre><code>#Standard library modules, grouped by use case\nimport os\nimport sys\n\nimport datetime\nimport time\n\nimport json\n\n\n\n#Third party modules, also grouped by use case\nimport tornado.web\nimport ... | {
"AcceptedAnswerId": "12258",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-06-01T16:04:00.827",
"Id": "12220",
"Score": "4",
"Tags": [
"python"
],
"Title": "Alphabetizing `import` Statements"
} | 12220 |
<p>I have this custom <code>IComparer</code> I use to sort a list of <code>SurveyResponse</code> objects, but it seems really inefficient, both in terms of runtime performance, and code elegance and maintainability. I thought of implementing <code>IComparable</code> for each of these components, and each <code>CompareT... | [] | [
{
"body": "<p>You can use types from <a href=\"https://github.com/jehugaleahsa/ComparerExtensions\" rel=\"nofollow\">ComparerExtensions</a> to make your code more maintainable:</p>\n\n<pre><code>IComparer<SurveyResponse> comparer = KeyComparer<SurveyResponse>\n .OrderBy(sr => sr.Question.Surve... | {
"AcceptedAnswerId": "12223",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-06-01T16:48:50.093",
"Id": "12221",
"Score": "9",
"Tags": [
"c#",
"performance",
"sorting"
],
"Title": "Multi-tiered sorting using custom IComparer"
} | 12221 |
<p>I much prefer the Java enhanced for each loop, but I often find there are certain times where I need to break from a loop, take the following contrived example:</p>
<pre><code>final List<String> strings = new ArrayList<>(
Arrays.asList(new String[] { "test", "new", "break", "notThere","last" }));
b... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-06-07T10:40:57.023",
"Id": "19830",
"Score": "0",
"body": "May I ask what's wrong with just using the `break` statement?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-06-08T17:09:53.183",
"Id": "19949",
... | [
{
"body": "<p>I suppose you feel that foreach is a kind of a map, and that inhibits you from exiting in the middle. In most code that I have seen, the first form is preferred except in the cases where we need to get the index where the break happened.</p>\n\n<p>i.e This is ugly.</p>\n\n<pre><code>int found = 0;... | {
"AcceptedAnswerId": "12230",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-06-01T20:23:43.820",
"Id": "12225",
"Score": "4",
"Tags": [
"java"
],
"Title": "Enhanced for loop"
} | 12225 |
<p>What I'm asking for is the review of a particular implementation of the haversine formula, found under:
<a href="http://blog.julien.cayzac.name/2008/10/arc-and-distance-between-two-points-on.html" rel="nofollow">http://blog.julien.cayzac.name/2008/10/arc-and-distance-between-two-points-on.html</a>
This site is linke... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-06-02T16:23:36.290",
"Id": "19638",
"Score": "0",
"body": "This is also a good time to point out that your code should compile and run and generate the results you claim. It was a good guess by @acraig but you definitely made the situatio... | [
{
"body": "<p>There's nothing wrong with your implementation. There must therefore be something wrong with how you're declaring or populating <code>gp</code>.\nDoing it like this:</p>\n\n<pre><code>double gp[4] = {36.987814, -122.107887, 38.989185, -122.116728};\nprintf(\"%.6f\\n\", getDist(gp));\n</code></pre>... | {
"AcceptedAnswerId": "12229",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-06-01T20:56:37.107",
"Id": "12227",
"Score": "1",
"Tags": [
"c++"
],
"Title": "Distance calculation implementation"
} | 12227 |
<p>My co-worker claims that using a parameterized Like statement is equivalent to dynamic sql and won't have its execution plan cached for reuse. He says that using <code>sp_executesql</code> will allow the execution plan to be cached, increasing the performance of identical searches. However, in the context of this qu... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-06-02T06:12:34.733",
"Id": "19629",
"Score": "1",
"body": "This looks like SQL Server, right? Which version?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-06-02T13:29:51.450",
"Id": "19635",
"Score": "... | [
{
"body": "<p>According to <a href=\"http://technet.microsoft.com/en-us/library/cc293623.aspx\" rel=\"nofollow noreferrer\">this article</a>:</p>\n<blockquote>\n<p>SQL Server can avoid compilations of previously executed queries by using four mechanisms to make plan caching accessible in a wide set of situation... | {
"AcceptedAnswerId": "12241",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-06-01T21:05:40.967",
"Id": "12228",
"Score": "2",
"Tags": [
"optimization",
"performance",
"sql",
"sql-server"
],
"Title": "Which SQL statement is faster"
} | 12228 |
<p>I originally made this as a way to use character strings as a base-256 number, but then realized that I could turn it into a method for encryption instead. The only thing is that since I'm using a basic addition algorithm for the encryption process, I'm iterating through a string by one character at a time (which se... | [] | [
{
"body": "<p>Since you key is const it would be nice to mark it as such (and avoid accidents of changing your key):</p>\n\n<pre><code>void encodeStr(string const& encryptKey, string& inputToEncrypt) {\n// ^^^^^\n</code></pre>\n\n<p>To save the cost of the copy I would also make it a ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-06-02T19:04:57.270",
"Id": "12233",
"Score": "5",
"Tags": [
"c++",
"optimization",
"cryptography"
],
"Title": "Simple encryption algorithm"
} | 12233 |
<p>I'm just starting to experiment with F# (from a C# background). I think I'm starting to get into the right way of thinking, but this code still seems pretty awkward. Is there a better (more terse) way to accoAny comments appreciated. (BTW, this is supposed to sum all even fibonacci numbers up to 4,000,000)</p>
<... | [] | [
{
"body": "<p>I think the solution reads better if you separate concerns a bit more instead of rolling it all into one mega function.</p>\n\n<p>For instance, with these helper functions (that each do one—and only one—thing):</p>\n\n<pre><code>let fib =\n Seq.unfold\n (fun (cur, next) -> Some(cur, (next, ... | {
"AcceptedAnswerId": "12269",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-06-02T23:33:11.363",
"Id": "12235",
"Score": "3",
"Tags": [
"project-euler",
"f#",
"fibonacci-sequence"
],
"Title": "Euler 2 : Simple Fibonacci"
} | 12235 |
<p>I whipped this up last night and was wondering if anyone had any thoughts/comments on it; for example, on:</p>
<ul>
<li>Code organisation</li>
<li>Coding style</li>
<li>Other improvements</li>
<li>Semantic errors</li>
</ul>
<p></p>
<pre><code>(ns tictactoe.core)
(comment "
Author: Liam Goodacre
Date: 03/06... | [] | [
{
"body": "<p>I would put the long <code>(comment ...)</code> as the namespace's docstring. In fact, I would split that in docstrings because you're essentially describing the system by parts in a centralized place, while you could describe it in each part. I would keep the overall \"how this game/namespace wor... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-06-03T07:55:07.387",
"Id": "12238",
"Score": "7",
"Tags": [
"functional-programming",
"tic-tac-toe",
"clojure",
"lisp"
],
"Title": "Clojure TicTacToe (logic, no GUI)"
} | 12238 |
<p>I would like to know how I could improve my C# project. I'm not really sure whether or not I'm allowed to just post a link to the Google Code project here, so sorry if it's not allowed, I'll edit my question if someone tells me so.</p>
<p><a href="http://code.google.com/p/simple-irc/source/browse/#svn%2Ftrunk" rel=... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-06-03T21:29:57.110",
"Id": "19645",
"Score": "0",
"body": "Can we see some pics?"
}
] | [
{
"body": "<p>One thing I noticed at a glance is that the main window code-behind is doing a lot of work that isn't really UI-focused. For example, the code to handle loading plugins from external DLLs is not something I would expect a Window subclass to do. I would highly recommend restructuring the applicati... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-06-03T12:51:54.210",
"Id": "12239",
"Score": "2",
"Tags": [
"c#",
"wpf"
],
"Title": "C# based IRC application (with WPF as UI)"
} | 12239 |
<p>At the moment, I have this code:</p>
<pre><code>(function() {
var lastSelectedIndex = -1;
function onSelTypeSelected() {
// #selType is a <select> tag
// var selType = document.getElementById("selType");
var selType = this;
// finished(onSuccess, onError)
loader.finished(function(data) ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-06-03T22:49:24.310",
"Id": "19650",
"Score": "0",
"body": "The code already works. `lastSelectedIndex` is already in `eventListener`'s context, because they are declared at the same scope."
}
] | [
{
"body": "<p><code>lastSelectedIndex</code> is already visible from eventListener. It is in fact visible from everywhere inside the immediately invoked anonymous function.</p>\n\n<p>Try putting <code>console.log(\"lastSelectedIndex is\", lastSelectedIndex);</code> in there and you'll see.</p>\n\n<p>This is due... | {
"AcceptedAnswerId": "12256",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-06-03T16:19:23.190",
"Id": "12246",
"Score": "7",
"Tags": [
"javascript"
],
"Title": "Store variables function-wide and access them in an anonymous function"
} | 12246 |
<p>As a part of picking up <a href="http://en.wikipedia.org/wiki/Concatenative_programming_language">concatenative programming</a>, I decided to implement the common concatenative operations in PostScript. Here is my attempt at implementing some of the <a href="http://www.latrobe.edu.au/phimvt/joy/html-manual.html">wor... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-24T21:57:46.067",
"Id": "35605",
"Score": "0",
"body": "+1 for introducing me to `rlwrap`! Sorry, I don't know concatenative programming, so the rest is just gibberish to me. :("
},
{
"ContentLicense": "CC BY-SA 3.0",
"Crea... | [
{
"body": "<p>There is an improvement that can be made to the <code>map</code> function. Your version:</p>\n\n<pre><code>/. {bind def} bind def\n\n%...\n\n/rup {3 1 roll}.\n\n%...\n\n/map { [ rup forall ] }.\n% [1 2 3 4] {1 add} map\n</code></pre>\n\n<p>The problem here is building the new array on the stack. W... | {
"AcceptedAnswerId": "69933",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-06-03T19:29:17.057",
"Id": "12249",
"Score": "12",
"Tags": [
"functional-programming",
"postscript"
],
"Title": "Concatenative PostScript library"
} | 12249 |
<p>I have written following small utility to abstract away the lazy initialization logic. (I tend to use lazy variables quite often.)</p>
<p>Are there any issues in this implementation?</p>
<pre><code>// File: F0.java
public abstract class F0<A> {
public abstract A apply();
}
// File: Lazy.java
public class ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-06-03T21:27:28.327",
"Id": "19644",
"Score": "0",
"body": "Samples of how you use it would be appreciated."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-06-03T22:27:43.213",
"Id": "19646",
"Score": "0",... | [
{
"body": "<p>Four notes:</p>\n\n<ol>\n<li><p>It's not thread-safe. <code>init.apply()</code> could be called multiple times from different threads. (I don't know whether it is an issue or not.)</p></li>\n<li><p>The constructor should check <code>null</code> inputs. (<em>Effective Java 2nd Edition, Item 38: Che... | {
"AcceptedAnswerId": null,
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-06-03T21:03:37.703",
"Id": "12250",
"Score": "3",
"Tags": [
"java",
"lazy"
],
"Title": "Are there any issues in this `Lazy` implementation?"
} | 12250 |
<p>I am writing my own website where users sign up. It then saves that data in an array. I want to know if this is effective or if there are better ways to do it.</p>
<pre><code>var isLoggedOn = false;
var numberOfUsers = 0;
var users = new Array();
var correct = false;
var currentUser = new User();
var date = new Arr... | [] | [
{
"body": "<p>Just a few general notes:</p>\n\n<ol>\n<li><p>Instead of using arrow <code>if-else { if-else { ... } }</code> structure you could format the code as guard clauses. For example:</p>\n\n<pre><code>if ((first === empty) || (last === empty) || (email === empty) || (age === empty)\n || (user... | {
"AcceptedAnswerId": "12272",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-06-04T01:34:08.433",
"Id": "12254",
"Score": "2",
"Tags": [
"javascript",
"array",
"validation"
],
"Title": "User data storage"
} | 12254 |
<p>I have files containing data sets which contain 11,000 rows. I have to run a loop through each row, which is taking me 25 minutes for each file.</p>
<pre><code> z <- read.zoo("Title.txt", tz = "")
for(i in seq_along(z[,1])) {
if(is.na(coredata(z[i,1]))) next
ctr <- i
while(ctr < length(z[,... | [] | [
{
"body": "<p>In your code, <code>std_d</code> is not defined. Presumably it is some threshold value, since it is used in a comparison of absolute differences.</p>\n\n<p>First, reformat your code so that I can better determine what it is supposed to do:</p>\n\n<pre><code>for(i in seq_along(z[,1])) {\n if(is... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-06-04T02:55:42.887",
"Id": "12255",
"Score": "2",
"Tags": [
"performance",
"r"
],
"Title": "Looping through rows of data sets in files"
} | 12255 |
<p>I'm an amateur coder writing a geometry library in Python, and would like some feedback regarding my implementation of a class for 3D Vectors.</p>
<p>My priority is to have a really friendly API for beginners who are just starting out writing code, to build it with as few dependencies as possible (no numpy or scipy... | [] | [
{
"body": "<pre><code> for arg in (x, y, z):\n if not isinstance(arg, numbers.Number):\n raise TypeError\n</code></pre>\n\n<p>Don't check types. Just assume that the user passed in the correct types. I am serious. It'll waste time every time you make a Vector3D class. </p>\n\n<p... | {
"AcceptedAnswerId": "12283",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-06-04T12:37:56.560",
"Id": "12261",
"Score": "2",
"Tags": [
"python",
"classes"
],
"Title": "Implementation of a Vector3D class"
} | 12261 |
<p>I'm trying to write a Java program that, given a particular number of groups and number of total participants, creates a list of all possible ways to fill that number of groups <em>evenly</em> using <em>all</em> the participants. The group number/order doesn't matter. For instance, if {} denotes one possible way to ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-06-01T03:33:04.350",
"Id": "19671",
"Score": "0",
"body": "possible duplicate of [All possible combinations of elements](http://stackoverflow.com/questions/1471558/all-possible-combinations-of-elements)"
},
{
"ContentLicense": "CC... | [
{
"body": "<p>First, determine the one or two group sizes that will apply, and how many of each you will have. Define <code>m</code>, the maximum capacity of any one group, as <code>ceil( k / n )</code>. Let <code>i</code> represent the number of groups of size <code>m</code>. Solving for <code>i</code>, we ... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-06-01T03:30:50.117",
"Id": "12262",
"Score": "1",
"Tags": [
"java",
"optimization",
"recursion"
],
"Title": "Create a list of all possible combinations of elements into n-groups from a ... | 12262 |
<p>Is this a reasonable C++ wrapper function for Python's "list.count([character])" method?</p>
<pre><code>int count( char CHAR, string STR ) {
int counter = 0;
for ( int i = 0 ; i < STR.size() - 1 ; i++ ) {
if ( STR[i] == CHAR ) {
counter++;
}
}
return counter;
}
//Edit... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-06-05T05:06:01.857",
"Id": "19710",
"Score": "3",
"body": "you seem confused about what a wrapper function is. A wrapper function should call what it is wrapping, not reimplement it."
}
] | [
{
"body": "<p>When STR is empty, STR.size() returns 0u. As a result, STR.size()-1 becomes maximum value of unsigned size type. i++ < STR.size()-1. This will lead the function to crash.</p>\n\n<p>Also your function will not count CHAR of the first character of STR.</p>\n\n<p>You may want to use standard libra... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-06-04T10:25:01.090",
"Id": "12265",
"Score": "1",
"Tags": [
"c++",
"python"
],
"Title": "C++ wrapper function for Python's \"list.count([character])\" method?"
} | 12265 |
<p>I'm just trying to see if there's a better way to write the code between the asterisk markers.</p>
<pre><code><?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Activate extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->mod... | [] | [
{
"body": "<p>i think a good way to improve the code would be using exceptions and extracting some stuff into reusable code. </p>\n\n<p>you could change </p>\n\n<pre><code>$userID = $this->uri->segment(2);\n</code></pre>\n\n<p>to</p>\n\n<pre><code>$userId = $this->getUserIdByUri($this->uri)\n</c... | {
"AcceptedAnswerId": "12277",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-06-04T15:48:02.983",
"Id": "12268",
"Score": "-1",
"Tags": [
"php",
"codeigniter"
],
"Title": "User registration / activation process for a website"
} | 12268 |
<p>I have files containing data set which contain 11,000 rows. I have to run a loop through each row, this is taking me 25minutes for each file.
I am using following code:</p>
<pre><code>z <- read.zoo("Title.txt", tz = "")
for(i in seq_along(z[,1])) {
if(is.na(coredata(z[i,1]))) next
ctr <- i
while(ctr <... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-06-04T02:53:05.767",
"Id": "19697",
"Score": "0",
"body": "Is `coredata` an array lookup or a function call?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-06-04T02:57:06.413",
"Id": "19698",
"Score": "0... | [
{
"body": "<p>Revised: ...I wonder if this could replace those two loops? Here are the results with the test vector offered in your comments:</p>\n\n<pre><code>set.seed(100); m=rnorm(15); std_d <- sd(m)\nReduce(function(y,xx){ if( abs(tail(y[!is.na(y)], 1) - xx) > std_d ) {c(y,NA)}else{ \n ... | {
"AcceptedAnswerId": "12281",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-06-04T02:44:14.547",
"Id": "12280",
"Score": "1",
"Tags": [
"performance",
"r"
],
"Title": "increase speed for 'for loop'"
} | 12280 |
<p>In my last question on Stack Overflow I was a very confused newcomer about classes and OOP and how to correctly implement everything to make things easier. So I started a different example to practice.</p>
<p>This has the classes of a band and person. The people audition but only some get in and the rest leave to ... | [] | [
{
"body": "<p>Just two quick notes: </p>\n\n<ol>\n<li><p>From Clean Code by Robert C. Martin:</p>\n\n<blockquote>\n <p>A class name should not be a verb.</p>\n</blockquote>\n\n<p>So, <code>Start</code> does not seem a good name. </p></li>\n<li><p>Furthermore, it seems that <code>Band</code> \"is-a\" <code>Star... | {
"AcceptedAnswerId": "12289",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-06-05T05:54:25.993",
"Id": "12284",
"Score": "2",
"Tags": [
"php",
"object-oriented",
"classes"
],
"Title": "Am I utilizing classes and OOP efficiently?"
} | 12284 |
<p>Here's one more controller I'm trying to get reviewed for. Any thoughts?</p>
<pre><code><?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Login extends CI_Controller {
public function __construct()
{
parent::__construct();
$this->load->model('users/usersmodel');
}... | [] | [
{
"body": "<p>I've already reviewed some of your other code, so I will only add new items in an attempt not to repeat posts</p>\n\n<p><strong>Booleans</strong></p>\n\n<p>There is no reason to recreate a feature that already exists. By checking for a <code>\"yes\"</code> or <code>\"no\"</code> or a <code>1</code... | {
"AcceptedAnswerId": "12298",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-06-05T09:08:37.843",
"Id": "12287",
"Score": "2",
"Tags": [
"php",
"codeigniter"
],
"Title": "Login Controller"
} | 12287 |
<p>Assume the following situation: you have an object that can store any object based on a key (basically, <code>IDictionary<string, object></code>). You want to store objects of various types into it that are not directly related. (For example, the dictionary can be an ASP.NET <code>Session</code>, or it can rep... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2018-10-02T16:20:02.997",
"Id": "394964",
"Score": "1",
"body": "Beautiful solution!"
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2019-05-22T19:35:24.933",
"Id": "426553",
"Score": "0",
"body": "I would use ... | [
{
"body": "<p>Your suggestion is not really type-safe as you can still pass a key of the wrong type. Therefore I would just use a normal (string) key. But I would add a generic <code>TryGet</code> method which takes account of the type. The setter needs not to be generic. </p>\n\n<pre><code>static class Diction... | {
"AcceptedAnswerId": "12292",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-06-05T12:29:50.800",
"Id": "12291",
"Score": "28",
"Tags": [
"c#",
".net",
"hash-map",
"type-safety"
],
"Title": "Type-safe Dictionary for various types"
} | 12291 |
<p>I have tried to incorporate comments from my <a href="https://codereview.stackexchange.com/q/12155/13768">previous code review</a> into this. So, I am hoping for less mistakes. If you spot any, please let me know mercilessly!</p>
<pre><code>#include <iostream>
#include <queue>
void printsub(int* p, int... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-06-12T10:29:36.057",
"Id": "20109",
"Score": "0",
"body": "Not enough for an answer but consider whether `if(!len)` makes sense. You are treating a number as a boolean value and while C++ allows this due to weak typing, it’s not a meaning... | [
{
"body": "<p>You could translate <a href=\"https://code.activestate.com/recipes/190465/\" rel=\"nofollow\">this recursive Python code</a>.</p>\n\n<pre class=\"lang-py prettyprint-override\"><code>def xcombinations(items, n):\n if n==0: yield []\n else:\n for i in xrange(len(items)):\n for cc in xco... | {
"AcceptedAnswerId": "12482",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-06-05T13:07:07.220",
"Id": "12293",
"Score": "3",
"Tags": [
"c++",
"algorithm"
],
"Title": "Printing all subsets"
} | 12293 |
<p>I'm attempting to write a bit of code that allows for easy and safe access to objects in a file. It seems to work great but I was curious if there was an easier way to do this or if Java already has something like this. If there isn't anything like this any critiques of my code would be appreciated as I'm trying to ... | [] | [
{
"body": "<ol>\n<li><p>The <code>Loader</code> class could use Java's built-in <a href=\"http://docs.oracle.com/javase/6/docs/api/java/util/concurrent/ExecutorService.html\" rel=\"nofollow noreferrer\">ExecutorService</a> with a <a href=\"http://docs.oracle.com/javase/6/docs/api/java/util/concurrent/Callable.h... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-06-05T15:55:38.973",
"Id": "12299",
"Score": "3",
"Tags": [
"java",
"multithreading",
"thread-safety",
"casting",
"type-safety"
],
"Title": "Loading an Object from File with Typ... | 12299 |
<p><strong>Summary:</strong></p>
<p>I've implemented what I think is a complete Java implementation of the Scala <code>Option</code> class. Could you please review and let me know if I have correctly and completely implemented it? And if not, could you please indicate where I have security, multi-threading, persistenc... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-06-05T19:53:23.553",
"Id": "19757",
"Score": "0",
"body": "Here's a great comment by Daniel Spiewak regarding the proper context and effective use of Scala's Option: http://beust.com/weblog/2010/07/28/why-scalas-option-and-haskells-maybe-... | [
{
"body": "<p>The main problem of your code is that it is written in Java. ;)</p>\n\n<p>Unfortunately Java doesn't support Lambdas, Pattern-Matching and Type-Inference - three main points for effective using Options. Without these features you can't use Option as they should be used.</p>\n\n<p>Option is a Monad... | {
"AcceptedAnswerId": "12314",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-06-05T18:49:58.343",
"Id": "12303",
"Score": "2",
"Tags": [
"java",
"generics"
],
"Title": "Scala Option conversion to Java"
} | 12303 |
<p>My background is with C and python, and Javascript is fairly new to me, so I'm wondering if this is reasonable code.</p>
<p>In particular, is it appropriate to use the higher order function <code>makecb</code> in this context, or is there a better/shorter/clearer way of writing it?</p>
<pre><code>$(function(){
v... | [] | [
{
"body": "<p>While the use of high order functions in JavaScript is fine and normal, your code has other issues.</p>\n<h1>Symptoms</h1>\n<p>Your usage of the <a href=\"http://api.jquery.com/css/\" rel=\"nofollow noreferrer\"><code>$.fn.css</code></a> method here is to do 3 things:</p>\n<ol>\n<li>show the eleme... | {
"AcceptedAnswerId": "12310",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-06-05T20:22:26.527",
"Id": "12304",
"Score": "-1",
"Tags": [
"javascript",
"jquery"
],
"Title": "Is there a better way of writing this JavaScript, or is it idiomatic?"
} | 12304 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.