body stringlengths 25 86.7k | comments list | answers list | meta_data dict | question_id stringlengths 1 6 |
|---|---|---|---|---|
<p>So I got this query from another analyst here and I'm a little stumped as to why a cursor was used instead of just joins. Could I please have some help trying to refactor it? I am using MSSQL 2008.</p>
<pre><code>SET NOCOUNT ON;
DECLARE @myCur AS CURSOR;
DECLARE @totalCdes AS INT;
DECLARE @SysOjb AS SMALLINT;
DECL... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-08T22:35:59.850",
"Id": "18637",
"Score": "0",
"body": "Check out Jeff Atwood's post on Rubber Duck problem solving:\nhttp://www.codinghorror.com/blog/2012/03/rubber-duck-problem-solving.html"
},
{
"ContentLicense": "CC BY-SA 3... | [
{
"body": "<p>Refactoring complex cursor procedures into proper SQL queries is Hard. That's why so many people here would rather not have to think about it. Take a look at this series of article (<a href=\"http://www.sqlservercentral.com/articles/T-SQL/66097/\" rel=\"nofollow\">There Must Be 15 Ways to Lose Yo... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-08T21:39:40.870",
"Id": "11616",
"Score": "1",
"Tags": [
"sql",
"sql-server"
],
"Title": "Is there a way to refactor this Cursor?"
} | 11616 |
<p>I have created the value type below to represent the desired size for an image. The <code>Size.Default</code> is used in situations where the image is required in the size it was supplied in, i.e. the image shouldn't be resized.</p>
<p>Is this a good implementation of a value type, especially regarding the <code>IE... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-09T12:45:54.990",
"Id": "18641",
"Score": "0",
"body": "What's wrong with [this](http://msdn.microsoft.com/en-us/library/system.drawing.size.aspx) or [this](http://msdn.microsoft.com/en-us/library/System.Windows.Size.aspx)?"
},
{
... | [
{
"body": "<p>Other than needing to override <code>GetHashCode()</code>, it looks pretty darn tip-top (adapted from <a href=\"https://stackoverflow.com/a/263416/3312\">Jon Skeet</a>):</p>\n<pre><code>public override int GetHashCode()\n{\n // Overflow is fine, just wrap.\n unchecked\n {\n var has... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-09T12:37:44.160",
"Id": "11617",
"Score": "5",
"Tags": [
"c#",
".net",
"reinventing-the-wheel"
],
"Title": "Is this a good implementation of a simple \"Size\" value type"
} | 11617 |
<p>I am creating a step-by-step form (it only shows in step-by-step and is not a multi state form) and the parts slide in and out (similar to GitHub but without the browser's back buttons). I have written the following code to implement this. Could you please review my code and suggest flaws:</p>
<p><div class="snippe... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-09T13:54:07.720",
"Id": "18649",
"Score": "0",
"body": "The code is working fine BTW :) But still, I feel that using so many methods in just a single statement shouldn't be the right approach, because I have never seen anyone use it so... | [
{
"body": "<p>jQuery was designed so you can chain function calls together like that. If you're worried about readability, then break them up into logical parts. You can either use variables, or keep the chaining and use whitespace to split them up. Instead of:</p>\n\n<pre><code>$('.visible').removeClass('visib... | {
"AcceptedAnswerId": "11674",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-09T13:50:00.767",
"Id": "11618",
"Score": "2",
"Tags": [
"javascript",
"jquery",
"html",
"form"
],
"Title": "Step-by-step form"
} | 11618 |
<p>I'm wondering if it is possible or if it is correct to proceed in such a way: </p>
<pre><code>var initiate_shop = function(shop_navigation, shop_container_id, items_per_page) {
return $(shop_navigation).jPages({
containerID : shop_container_id,
first : false,
previous ... | [] | [
{
"body": "<p>Looks good to me, if you always want those 3 params and never want to send anything else.</p>\n\n<p>Otherwise, you could improve it by receiving the non-mandatory params in an options object:</p>\n\n<pre><code>\"use strict\";\nvar initiate_shop = function(container_id, options) {\n var default_... | {
"AcceptedAnswerId": "11634",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-09T14:43:26.807",
"Id": "11623",
"Score": "3",
"Tags": [
"javascript",
"jquery"
],
"Title": "Can I return an object on which a function is applied?"
} | 11623 |
<p>I have some simple tests written, however, the names are not good...I think, any suggestions on better names? I'm not really sure how these tests should be named.</p>
<p>I'm looking for a format or pattern I can follow.</p>
<pre><code>[TestClass]
public class DoorTests
{
[TestMethod]
public void DoorIsNot... | [] | [
{
"body": "<p>I find that <a href=\"http://osherove.com/blog/2005/4/3/naming-standards-for-unit-tests.html\">Roy Osherove's test naming convention</a> is easy to apply and provides suggestive names for the test methods.</p>\n\n<p>Roy proposes that the test method names should be composed of three parts:</p>\n\n... | {
"AcceptedAnswerId": "44122",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-09T20:58:38.733",
"Id": "11635",
"Score": "11",
"Tags": [
"c#",
"unit-testing"
],
"Title": "Better test names"
} | 11635 |
<p>I have a <code>getValue</code> function which just grabs some numbers from an HTML page.</p>
<p>How can I access those variables in later functions without passing them down the entire chain of functions? As they sit within a function they are not global?</p>
<p>When I call the addition function, it will need to a... | [] | [
{
"body": "<p>Yes, you are right, <code>decimal</code>, <code>a</code>, <code>b</code> and <code>c</code> are not accessible by other functions because they are local to getValue(). To make them global, you need to declare them outside of your function, like this: </p>\n\n<p><strong>Solution #1</strong></p>\n\n... | {
"AcceptedAnswerId": "11642",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-09T21:09:12.567",
"Id": "11637",
"Score": "6",
"Tags": [
"javascript"
],
"Title": "JavaScript functions and global variables"
} | 11637 |
<p>Do you have any suggestions to improve or extend this script? Any ideas for removing or adding comments/docstrings?</p>
<pre><code>import dbm
import subprocess
import time
subprocess.call("clear")
try:
# Tries to import cPickle, a faster implementation of pickle.
import cPickle as pickle
except ImportError:... | [] | [
{
"body": "<pre><code>import dbm\nimport subprocess\nimport time\nsubprocess.call(\"clear\")\n</code></pre>\n\n<p>This isn't cross-platform. Sadly, there isn't really a cross-platform alternative</p>\n\n<pre><code>try:\n # Tries to import cPickle, a faster implementation of pickle.\n import cPickle as pic... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-09T22:49:27.703",
"Id": "11641",
"Score": "0",
"Tags": [
"python",
"optimization",
"database"
],
"Title": "How to Improve This Program, Add Comments, etc.?"
} | 11641 |
<p>Here is my window tiling script for rio window manager in Plan 9. It fetches the current screen size and calculates the locations based on the layout given. How can I improve this program? Am I missing any idioms in rc?</p>
<pre><code>#!/bin/rc
# Usage:
# First save the current windows
# ./tile.rc save >saved.s
... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-10T03:45:14.907",
"Id": "11643",
"Score": "3",
"Tags": [
"rc"
],
"Title": "Plan 9 rio script to tile windows"
} | 11643 |
<p>Plan9 is a distributed operating system with many advanced ideas. These include per process namespaces, all resources in the system exposed as files, a single protocol 9p to communicate with other distributed resources instead of multiple protocols like HTTP, FTP, etc.</p>
<p>Quite a few of these ideas found its wa... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-10T03:47:54.060",
"Id": "11644",
"Score": "0",
"Tags": null,
"Title": null
} | 11644 |
<p>Rio is the window manager for Plan9 Operating system. It is a simple window manager that makes its controls and the windows it controls available as file system resources mounted under /dev. The unix window manager wmii takes its inspiration from Rio.</p>
| [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-10T03:49:33.917",
"Id": "11646",
"Score": "0",
"Tags": null,
"Title": null
} | 11646 |
Rio is the window manager for Plan9 Operating System. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-10T03:49:33.917",
"Id": "11647",
"Score": "0",
"Tags": null,
"Title": null
} | 11647 |
Rc is the shell for Plan9 Operating System. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-10T03:50:07.363",
"Id": "11649",
"Score": "0",
"Tags": null,
"Title": null
} | 11649 |
<p>I have to write a comparison logic.</p>
<p>Following is the code to refactor (as it is looking bad).</p>
<pre><code> // 1. item has filter criteria
// 2. return true if current matches filter criteria
// 3. Criteria -> 3 fields should be matched ( Security, OrderType, CounterType)
// 4. Criteria -> Us... | [] | [
{
"body": "<p>This is a subjective opinion, but I find it useful to extract methods for the three types of matches you are checking in your code. </p>\n\n<p>I refactored your code and extracted the methods: </p>\n\n<ul>\n<li><code>bool OrderPartyMatches(Item item, Item current)</code></li>\n<li><code>bool Order... | {
"AcceptedAnswerId": "11654",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-10T04:51:43.870",
"Id": "11651",
"Score": "0",
"Tags": [
"c#"
],
"Title": "Refactor c# comparision/filter logic"
} | 11651 |
<p>After reading <a href="https://stackoverflow.com/questions/2129214/backup-a-local-git-repository/10458663">this Stack Overflow question</a> I decided to write a backup utility for local git repositories.</p>
<p>The result is on <a href="https://github.com/najamelan/git-backup" rel="nofollow noreferrer">GitHub</a>.<... | [] | [
{
"body": "<p>There is a great deal of vertical white space; probably more than is good for readability. Unless it is an artifact of cut and paste, you might consider removing some of it.</p>\n\n<p>The usual indent level for Ruby is 2 spaces. You don't have to do what's usual, of course, but it will make life... | {
"AcceptedAnswerId": "11764",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-10T14:11:06.030",
"Id": "11660",
"Score": "2",
"Tags": [
"beginner",
"ruby",
"git"
],
"Title": "Backup utility for local git repositories"
} | 11660 |
<p>I am building a library and I need suggestions on how to improve it (security, performance, etc).</p>
<pre><code><?php
/**
* Authentication Library
*
* @author John Svensson
*/
class Auth
{
public $captchaCount;
protected $db;
protected $PasswordLib;
private $message;
public function _... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-15T01:34:01.603",
"Id": "18868",
"Score": "0",
"body": "Not sure if this got mentioned below but I'd separate any DB/SQL stuff into a separate class and pass and instance of that DB class instead of PDO."
},
{
"ContentLicense":... | [
{
"body": "<p>Want to know about security? Don't claim that I'm paranoid sociopath.</p>\n\n<p><code>$this->db = $db;</code> So, you agree to accept (and use later) any DB connection? Don't even mention that it may be simply <code>NULL</code> (in the best case?)</p>\n\n<p><code>$_SESSION</code> do you really ... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-10T16:00:44.370",
"Id": "11661",
"Score": "3",
"Tags": [
"php",
"performance",
"security",
"library",
"authentication"
],
"Title": "Authentication library"
} | 11661 |
<p>I Needed a method to randomly sample an IEnumerable collection without replacement. I'm using this for writing behavioral acceptance tests.</p>
<p>For example, in the test code, I write:
<code>GetElements("#SearchResults > li").Sample(3);</code></p>
<p>Here's the how I implemented it:</p>
<p>I welcome any feed... | [] | [
{
"body": "<p>Make the <code>Random</code> generator a class-level member so you're not generating a new one with the default seed each time. Also, check your <code>population</code> for null:</p>\n\n<pre><code>/// <summary>\n/// random number generator for the enumerable sampler.\n/// </summary>\n... | {
"AcceptedAnswerId": "11665",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-10T18:58:44.937",
"Id": "11664",
"Score": "1",
"Tags": [
"c#",
"linq"
],
"Title": "LINQ style Sample method"
} | 11664 |
<p>I'm not too used to working with arrays in javascript, so was wondering if there is a good way to condense this down.</p>
<p>Any pointers much appreciated!</p>
<p>you can see it in action @ <a href="http://www.productionlocations.com/locations" rel="nofollow">http://www.productionlocations.com/locations</a></p>
<... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-11T06:52:32.090",
"Id": "18723",
"Score": "0",
"body": "What are the intended effects of this code? Do you just want to call the appropriate `$('#s').val()` and `inputReplace()` if necessary, or do you also want to keep `searchval` and... | [
{
"body": "<pre><code>//use array literal\nvar searchval = [];\n\n//cache length, if ever it's needed more than once\nvar filterLength = $('.filters').length;\n\n//cache the condition, for readability\nvar url = url === 'http://www.productionlocations.com/locations' || url === 'http://www.productionlocations.co... | {
"AcceptedAnswerId": "11676",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-10T22:02:16.847",
"Id": "11669",
"Score": "0",
"Tags": [
"javascript",
"array"
],
"Title": "Help me condense a series of lengthy javascript conditional arrays"
} | 11669 |
<p>I'm writing a <a href="https://github.com/kentcdodds/Java-Helper" rel="nofollow noreferrer">Java-Helper library</a>. I want to include a method to zip files together, and this is what I've come up with. I'm using the <code>java.util.zip.*</code> library (<a href="http://docs.oracle.com/javase/1.4.2/docs/api/java/uti... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-11T11:25:56.100",
"Id": "18729",
"Score": "1",
"body": "Why don't you benchmark that?"
}
] | [
{
"body": "<p>Well, I benchmarked it and found that a buffer size of 10485760 (10 MB) was fastest... Kind of surprised about that and I'm thinking that's not the most efficient. I think I'll leave it at 1 MB unless someone else has any thoughts.</p>\n",
"comments": [
{
"ContentLicense": "CC BY... | {
"AcceptedAnswerId": "11680",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-11T00:55:00.390",
"Id": "11671",
"Score": "1",
"Tags": [
"java",
"performance",
"compression"
],
"Title": "Java-Helper library for compressing (zipping) files"
} | 11671 |
<p>I am programing in C language and have created the below functions to read files. There are two functions that I can use to read files. I wanted to know how I can further improve these two in terms of efficiency and out of these two which one would be better to use for reading files. </p>
<p>First is:</p>
<pre><co... | [] | [
{
"body": "<p>In your first <code>read_data_from_file()</code>, you're filling in the out parameter <code>fsz1</code> with zero, or with <code>-1</code>, depending, when things go wrong. However, your caller isn't going to be able to DO anything with that number. Don't fill it in, just return <code>NULL</code>.... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-11T04:09:08.497",
"Id": "11675",
"Score": "3",
"Tags": [
"optimization",
"c",
"performance",
"linux",
"file-system"
],
"Title": "Improving C file reading function"
} | 11675 |
<p>One day I realised that my Android project utilizes AlertDialogs here and there in very ineffective way. The heavily duplicated portion of code looked like this (actually, copied and pasted from some documentation):</p>
<pre><code>AlertDialog.Builder builder = new AlertDialog.Builder(context);
builder.setMessage("A... | [] | [
{
"body": "<p>for a confirmation dialog use setCancelable(true) to make the user able to cancel the dialog using the back button. This is the native way and you don't have to implement anything.</p>\n\n<p>Note: in Android you are not supposed to close the application. The operating system will close it when it ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-11T09:02:40.943",
"Id": "11677",
"Score": "3",
"Tags": [
"java",
"android",
"callback"
],
"Title": "Efficient implemetation of AlertDialog callback in Android"
} | 11677 |
<p>The Qt documentation recommend an iterator-based solution to iterate over an associative container like QMap and QHash, and I always wondered if there really isn't a (nice) solution using a <code>foreach</code> loop like in PHP:</p>
<pre class="lang-php prettyprint-override"><code>foreach($container as $key =>... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-09T21:31:12.733",
"Id": "18733",
"Score": "0",
"body": "Actually I think the best place would be [qt-project.org/contribute](http://qt-project.org/contribute). It would definitely be useful for code clarity."
},
{
"ContentLicen... | [
{
"body": "<p>You can probably do something simpler to avoid making this a special case macro, e.g. using <code>std::tie</code> or <code>boost::tie</code> if that's not available:</p>\n\n<pre><code>#include <map>\n#include <functional>\n#include <boost/foreach.hpp>\n#include <iostream>\n... | {
"AcceptedAnswerId": "11682",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-09T19:53:04.933",
"Id": "11681",
"Score": "4",
"Tags": [
"c++",
"macros",
"qt"
],
"Title": "Qt foreach-like alternative to iterate over value AND key of an associative container"
... | 11681 |
<p>I am trying to have a <code>ReentrantLock</code> with another way to determinate which thread will have the lock in the waiting queue. <code>ReentrantLock</code> implementation manages a Fair/Unfair policy, that's not what I want.</p>
<p>I would like to give a priority when I call the <code>.lock()</code> method, a... | [] | [
{
"body": "<p>After calling shutdown(), the shutdown boolean may never get checked. The Thread may be stuck in waitingQueue.take().</p>\n\n<p>It's probably not a good idea to catch and swallow InterruptedException.</p>\n\n<p>Considering those two points together, it makes sense to remove the Thread and use <a h... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-07T15:26:27.653",
"Id": "11683",
"Score": "1",
"Tags": [
"java",
"multithreading",
"locking"
],
"Title": "ReentrantLock with priorities for waiting threads"
} | 11683 |
<p>I have this function which is pretty easy to read and works just fine. I'm looking to advance my coding abilities by writing more concise code, though.</p>
<p>Does anyone know of an elegant way to condense this down? Any pointers very much appreciated! Thank you! </p>
<pre><code>var $_GET = {};
documen... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-11T16:01:36.090",
"Id": "18751",
"Score": "0",
"body": "what language is this? you have `$_GET[]`, PHP? but you also have variables with no `$`, JS?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-11T16:10:... | [
{
"body": "<p>What's the idea of having those OR checking, when you check them again individually? </p>\n\n<pre><code>if(area || type || style || feature){...\n</code></pre>\n\n<p>If none hold true, they never run anyway. If one exists, all of your 4 <code>if</code>s run also, <em>and checking again</em></p>\n\... | {
"AcceptedAnswerId": "11692",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-11T15:10:06.250",
"Id": "11686",
"Score": "1",
"Tags": [
"javascript"
],
"Title": "Refactoring and condensing a Javascript function with many repeat conditions, strings, and variables"
} | 11686 |
<p>The c# newbie is back :) I have another problem with my threads. Here is what i am trying to achieve:</p>
<p>I am starting 5 threads which are performing the same task but on different URLs. So i am keeping a "masterLogFile.txt" to keep track of what URLs have already been visited.
Each thread compares its own "th... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-10T13:25:00.403",
"Id": "18754",
"Score": "0",
"body": "Ah no, sorry. I just wanted to ask if my logic for comparing data in files from different threads can be improved"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate... | [
{
"body": "<p>I'd use a dictionary (or a HashSet if you don't need the ID information) for coordination.</p>\n\n<pre><code>class UrlLog {\n private Dictionary<string, int> visited = new Dictionary<string, int>();\n public bool HasUrlBeenVisited(string Url) {\n lock(visited) return visit... | {
"AcceptedAnswerId": "11690",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-10T13:20:45.040",
"Id": "11689",
"Score": "1",
"Tags": [
"c#",
"multithreading"
],
"Title": "Threads and logfiles"
} | 11689 |
<p>How can I improve the performance of this method or is it already good?</p>
<pre><code>private static void LoadAssembliesWithInjectorModule(IEnumerable<FileInfo> files)
{
var moduleType = typeof (InjectorModule);
foreach (var file in files)
{
try
{
var assembly = Assem... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-11T19:30:21.673",
"Id": "18778",
"Score": "2",
"body": "How can we know? Is it good enough for your intended usage? Is this method a bottleneck in your program?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-... | [
{
"body": "<p>I would suggest swapping the checks on this line from</p>\n\n<p><code>where moduleType.IsAssignableFrom(assemblyType) && !assemblyType.IsAbstract</code></p>\n\n<p>to</p>\n\n<p><code>where !assemblyType.IsAbstract && moduleType.IsAssignableFrom(assemblyType)</code></p>\n\n<p>Checkin... | {
"AcceptedAnswerId": "11878",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-11T18:26:19.953",
"Id": "11696",
"Score": "1",
"Tags": [
"c#",
"performance",
".net",
"linq"
],
"Title": "Load assemblies with injector module"
} | 11696 |
<p>I feel like I can vastly improve this. Any ideas?</p>
<pre><code>// get orientation of device
getOrientation();
// animate
var num = 400;
if( $('body').hasClass("landscape") ) {
$('.example').animate({'bottom', 0});
} else {
$('.example').animate({'bottom', num});
}
function getOrientation(){
switc... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-11T20:16:43.067",
"Id": "18785",
"Score": "0",
"body": "I think that your `window.onorientationchange` will never trigger any change."
}
] | [
{
"body": "<p>Use ternary operators, something like:</p>\n\n<pre><code> // get orientation of device\ngetOrientation();\n\n// animate\nvar num = 400;\n\n$('.example').animate({'bottom', $('body').hasClass(\"landscape\") ? 0 : num});\n\nfunction getOrientation(){\n $('body').removeAttr('class'); //Removing al... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-11T18:39:11.417",
"Id": "11697",
"Score": "1",
"Tags": [
"javascript",
"jquery"
],
"Title": "Get device orientation"
} | 11697 |
<p>I have various strings that contain codes, e.g. like this:</p>
<pre><code>"file = new JarFile(new File()" + "\nSystem.out.println(file"
</code></pre>
<p>but also</p>
<pre><code>"args"
</code></pre>
<p>Now I want to find the substring that is in the beginning and in the end of the string. E.g. in the first case t... | [] | [
{
"body": "<p>I'm not completely sure about the requirements, but what about the following?</p>\n\n<pre><code>public static String findWord2(final String text) {\n for (int i = text.length() - 1; i > 0 ; i--) {\n final String first = text.substring(0, i);\n final String last = text.substring... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-11T21:49:55.227",
"Id": "11705",
"Score": "1",
"Tags": [
"java",
"algorithm",
"strings"
],
"Title": "Find two equal substrings in a string"
} | 11705 |
<p>A Java desktop application exposes the class/containment hierarchy of its Swing GUI through RPC. I'm building a Haskell client that connects to the application. The objective is to be able to perform queries like "find all the buttons of width less than <strong>w</strong>, located within screen rectangle <strong>r</... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-09T13:19:43.707",
"Id": "38481",
"Score": "0",
"body": "BTW, if you like mucking around with dynamic types, you might try `Data.Dynamic`, which builds atop `Data.Typeable`."
}
] | [
{
"body": "<p>EDIT: Faithfully representing OO semantics in Haskell is currently impossible. In particular, method resolution can be simulated (but not easily, and not quite faithfully) via type classes and instances. This <a href=\"https://research.microsoft.com/en-us/um/people/simonpj/papers/oo-haskell/\" rel... | {
"AcceptedAnswerId": "24902",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-12T09:55:44.820",
"Id": "11715",
"Score": "6",
"Tags": [
"haskell"
],
"Title": "Representing a Java Swing containment hierarchy in Haskell"
} | 11715 |
<p>I need to pass an array of values in <code>Url.Action</code>.</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 (criteri... | [] | [
{
"body": "<p>I assume you \"own\" the controller?\nIf so, I'd serialize and deserialize the list as a comma separated string on each side.\nIt'd also be nice if criteria.JobTypes is an empty list instead of a possible null, then you don't need the ?? below.</p>\n\n<pre><code>var redirectUrl = Url.Action(\"sear... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-12T10:00:47.660",
"Id": "11716",
"Score": "9",
"Tags": [
"c#",
"asp.net-mvc-3"
],
"Title": "Passing an array of values in Url.Action"
} | 11716 |
<p>I have a program where it takes the students name and last name and score and saves it. When checking to see if a <code>textbox</code> has information in it, I use <em>a lot</em> of <code>if</code> statements. Is there a cleaner way to do this?</p>
<pre><code>public void CheckData()
{
if (first1.Text !=... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-12T14:26:07.360",
"Id": "18797",
"Score": "4",
"body": "You should have the textboxes and the students in a collection, not have fifteen variables."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-12T14:39:5... | [
{
"body": "<p>First things first, that nesting is horrible! You could revert the conditions on the <code>if</code>s, and use a return to avoid using an <code>else</code>.</p>\n\n<pre><code>public void BadNesting() {\n if(cond1) {\n //...\n if(cond2) {\n // ...\n if(cond3) {\n //...\n ... | {
"AcceptedAnswerId": "11721",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-12T14:10:22.013",
"Id": "11718",
"Score": "4",
"Tags": [
"c#",
"wpf"
],
"Title": "Saving student scores"
} | 11718 |
<p>The problem can be <a href="http://mitpress.mit.edu/sicp/full-text/book/book-Z-H-15.html#%_sec_2.2.3" rel="nofollow">found online here</a>.</p>
<p>In short, we're given the following function definition, that will recursively generate all the possible solutions for the "eight-queen-problem". </p>
<pre><code>(defin... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-16T20:28:26.543",
"Id": "18960",
"Score": "1",
"body": "srfi-1 provides some of the utility functions you define. Look at `list-ref`, `every`, and `any`. Your particular dialect of scheme may also provide them without having to requi... | [] | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-12T17:56:50.803",
"Id": "11719",
"Score": "1",
"Tags": [
"scheme",
"sicp"
],
"Title": "SICP ex. 2.42 \"eight queens puzzle\""
} | 11719 |
<p>I have the following script that I'm part way through and I'm not happy with it at all, it feels messy:</p>
<pre><code><?php
class Process {
public $search = 'http://api.themoviedb.org/2.1/Person.search/en/json/xxx/';
public $info = 'http://api.themoviedb.org/2.1/Person.getInfo/en/json/xxx/';
public... | [] | [
{
"body": "<p>I'd start firstly by moving your <code>urlencode()</code> into the class... You should assume that everything passed to a method is unclean and therefore act appropriately.</p>\n\n<p>Secondly, I'd give the class a meaningful name - <code>Process</code> isn't entirely descriptive.</p>\n\n<p>Throw s... | {
"AcceptedAnswerId": "11733",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-12T19:09:59.123",
"Id": "11722",
"Score": "2",
"Tags": [
"php",
"object-oriented",
"api"
],
"Title": "Two similar API calls PHP optimisation and structure"
} | 11722 |
<p>This falls straight into the same category with the recent "<em><a href="https://codereview.stackexchange.com/questions/11544/is-it-better-practice-to-return-if-false-or-execute-an-if-statement-if-true">Is it better practice to return if false or execute an if statement if true?</a></em>" question.</p>
<p>Often, wh... | [] | [
{
"body": "<p>There's quite a few questions about this on stackoverflow but I think my general rule tends to be leave exceptions for exceptional circumstances and booleans for where failure occurances is an accepted/known possible behaviour. </p>\n\n<p>So I personally probably prefer your option 2 (interested ... | {
"AcceptedAnswerId": "11725",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-12T22:28:02.763",
"Id": "11724",
"Score": "16",
"Tags": [
"java",
"validation",
"exception"
],
"Title": "Is it better practice to have void method throw an exception or to have th... | 11724 |
<p>I created a small Android project with an AsyncTask. It simulates a time consuming task.</p>
<p>Please review my code and tell me what you would do on a different way and why. Comments not specific to Android but general software development are welcome.</p>
<p>CounterTask.java:</p>
<pre><code>package my.tasks;
... | [] | [
{
"body": "<p>Looks good. You could put the progressDialog creation and show in onPreExecute: <a href=\"http://developer.android.com/reference/android/os/AsyncTask.html#onPreExecute\" rel=\"nofollow\">http://developer.android.com/reference/android/os/AsyncTask.html#onPreExecute</a>() . It will run in the UI th... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-13T07:05:26.933",
"Id": "11730",
"Score": "2",
"Tags": [
"java",
"android"
],
"Title": "Small Android AsyncTask project"
} | 11730 |
<p>I have a list of resources which can be voted on. There are 3 voting states: upvoted, downvoted and no vote.</p>
<p>In a fashion identical to Stack Exchange voting, it follows these rules:</p>
<ol>
<li>If you upvote a post you've already upvoted, it will set it to 'no vote'</li>
<li>If you upvote a post set to 'no... | [] | [
{
"body": "<p>Both portions of code could be simplified if you use numbers, instead of words, to represent upvotes and downvotes. So I would change your calls to <code>sendVote</code> to look like this:</p>\n\n<pre><code>sendVote(this.parentNode, 1);\nsendVote(this.parentNode, -1);\n</code></pre>\n\n<p>When mod... | {
"AcceptedAnswerId": "11739",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-13T18:21:44.133",
"Id": "11732",
"Score": "3",
"Tags": [
"javascript",
"jquery",
"state-machine"
],
"Title": "State machine for upvoting/downvoting"
} | 11732 |
<p>The goal is to</p>
<ul>
<li>make an object that persists upon page reloads,</li>
<li>have an interface as close as possible to the <code>Object</code> class.</li>
</ul>
<pre><code>function PersistentObject(key,initial_value)
//use for(..in data.keys()) instead of for(..in data)
{
var ret;
if(localStorage[key... | [] | [
{
"body": "<p>It is impossible to know the variable name without passing it separately because the name is not part of the object itself, but only one (of potentially many) signs pointing to that object. Expecting the object to know that variable name is like expecting a building to know which road you drove in... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-14T13:50:28.813",
"Id": "11747",
"Score": "6",
"Tags": [
"javascript",
"browser-storage"
],
"Title": "Persistent Object using localStorage"
} | 11747 |
<p>This is a fairly trivial example of a question I come up to often. In the example below I tend to think that allowing duplication sometimes results in clearer code.</p>
<p>Does anyone agree/disagree on this point?</p>
<p>First way: an additional local variable is used so <code>method.Invoke</code> is called just ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-14T23:04:01.043",
"Id": "18866",
"Score": "0",
"body": "I personally like your first option in this case as for me it reads easier and is actually less logic in my view to decode as such"
}
] | [
{
"body": "<p>I think this would be even better, in this case.</p>\n\n<pre><code>private static void Invoke<T>(string[] args, MethodInfo method) where T : new()\n{\n T target = new T();\n target.InvokeMethod(\n \"Initialize\", errorIfMethodDoesNotExist: false, accessNonPublic: true);\n str... | {
"AcceptedAnswerId": "11756",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-14T16:47:46.337",
"Id": "11753",
"Score": "4",
"Tags": [
"c#"
],
"Title": "Duplicate method call or add logic to set local variables as parameters?"
} | 11753 |
<p>I have 12 games that I need to sort through that each have a date and img string. I'm fairly new to jQuery and was wondering what is the best way to accomplish this. Is there a way that I can run this through a loop of some sort rather than having 12 <code>else</code>-<code>if</code> statements like I currently hav... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-14T19:36:28.510",
"Id": "18860",
"Score": "0",
"body": "@j08691: The moderators prefer that you flag such things for their attention, that way they can move the question and avoid duplicate posts on different sites."
},
{
"Cont... | [
{
"body": "<p>Try something like this:</p>\n\n<pre><code>if (now.getTime() < boise.date.getTime() ) {\n banner.attr('src', imgDir+boise.img+'.jpg');\n}\n.....\n</code></pre>\n\n<p>In total,</p>\n\n<pre><code>var now = new Date();\n objs = { \n // here I change your 12 variables to a single objec... | {
"AcceptedAnswerId": "11758",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-14T19:03:04.197",
"Id": "11757",
"Score": "0",
"Tags": [
"javascript",
"jquery",
"datetime"
],
"Title": "Finding image by date"
} | 11757 |
<p>In my Backbone.Collection I need to parse the response before to render it in Backbone.View. The following code works, but it will be great to have some suggestions:</p>
<pre><code>// response is array of object
// [{id:1, prop: null },{id:2, prop: "bar" }]
// the output parsed_response can be
//[{id:1, prop: n... | [] | [
{
"body": "<p>Based on the way your <code>parse</code> function works you're worried about mutability. Your code can be much shorter. Also, your use of <code>_.clone</code> is wasted since it's only a shallow copy. I've rewritten <code>parse</code> code and now it looks like this:</p>\n\n<pre><code>// response ... | {
"AcceptedAnswerId": "11761",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-14T20:56:59.567",
"Id": "11759",
"Score": "2",
"Tags": [
"javascript",
"backbone.js"
],
"Title": "How to parse a collection of objects in Backbone?"
} | 11759 |
<p>I have written this code which precisely calculates the nth power of x by a recursive method.</p>
<p>I compared my program with Java's <code>pow(double, double)</code> function, and most of the time I get comparable results, although sometimes <code>pow</code> is slow and the other times this program is slow.</p>
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-15T03:23:58.140",
"Id": "18870",
"Score": "0",
"body": "http://gizmoworks.wordpress.com/sicp-exercises/ is the simplest to comprehend, but probably is not the fastest."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate":... | [
{
"body": "<p>The Java implementation of <code>pow</code> is implemented for double, rather than long, and probably uses logarithms. This makes direct comparison difficult - <code>pow</code> should have a more or less constant factor time, but double precision arithmetic can be expensive.</p>\n\n<p>Otherwise, i... | {
"AcceptedAnswerId": null,
"CommentCount": "8",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-15T03:15:59.727",
"Id": "11762",
"Score": "7",
"Tags": [
"java",
"algorithm",
"performance",
"mathematics"
],
"Title": "Calculating nth power of x"
} | 11762 |
<p>I'm attempting to implement various data structures and algorithms to better learn C. I would appreciate comments on style, correctness of the implementation, memory management, etc.</p>
<p>One specific question is how to address an error case where either the table or key is null in the hash function. In get or ... | [] | [
{
"body": "<p>Regarding the problem of the error case where either the table or key is null in hash_code, you might pass in ht->size instead of ht, thus halving the problem. If you redefine the 'contract' so that a NULL key is treated the same as an empty string \"\", then you no longer have an error case.</p>... | {
"AcceptedAnswerId": "11788",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-15T05:14:06.613",
"Id": "11766",
"Score": "3",
"Tags": [
"c",
"hash-map"
],
"Title": "Open addressed hash table"
} | 11766 |
<p>I'm attempting to implement driver-layer (shared library) from top-level app to hardware.</p>
<p>In the first, I extracted interface functions, which further will be called from "extern "C" SHARED" wrappers to separate class <code>IDriverInterface</code>.</p>
<p>In the second, I want to hot-test some functions bef... | [] | [
{
"body": "<p>I do not really understand what you mean by <em>first</em> and <em>second</em>. Does this source code go all into one single module/dll/exe? Or is there an intended hierarchy? </p>\n\n<p>There are a few (more general) suggestions I can give:</p>\n\n<ul>\n<li><p><strong>avoid include-file name clas... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-15T14:33:26.340",
"Id": "11770",
"Score": "1",
"Tags": [
"c++",
"object-oriented",
"inheritance",
"qt"
],
"Title": "Driver-layer from top-level app to hardware"
} | 11770 |
<p>I am currently writing an embedded application for audio streaming purposes. The embedded app will receive audio packets being sent over WiFi, buffer the packets, then send the audio data over to a decoder chip. I have a ring buffer implementation written, but am getting some weird behavior sometimes. In terms of au... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-06-14T04:15:07.810",
"Id": "20237",
"Score": "0",
"body": "For small embedded systems, it's a good old trick to align the buffer on a `2 << (n+1)` boundary, and then after each increment operation on head/tail pointers to and them with `~... | [
{
"body": "<p>If I'm right you need some synchronization/locking to make visible every data change properly for every thread since two threads use the ring buffer at the same time: <code>AppAudioStream_BufRecv</code> and <code>AppAudioStream_DecoderCb</code>.</p>\n\n<p>Two posts from SO which look useful: </p>\... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-15T18:44:45.787",
"Id": "11774",
"Score": "3",
"Tags": [
"c",
"audio",
"circular-list"
],
"Title": "Ring buffer in C tail pointer issue (for audio streaming)"
} | 11774 |
<p>I have an app that does a fair bit of text-parsing based on free-form user inputs. In this, I run searches on the whole string, and then on the last value of the string separate from the rest of the string. Here is a pair of functions I wrote to <code>getLast</code> and <code>getSubString</code>.</p>
<pre><code>&... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-05-08T21:29:33.967",
"Id": "62809",
"Score": "0",
"body": "I didn't look here to see if there are UDFs exactly for this, but before I write UDFs, I always check here: http://cflib.org/"
}
] | [
{
"body": "<p>I believe ColdFusion already has similar function to your first:\nListLast() - Gets the last item in a list\n<a href=\"http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=functions_l_14.html\" rel=\"nofollow\">http://livedocs.adobe.com/coldfusion/8/htmldocs/help.html?content=function... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-15T20:37:31.667",
"Id": "11776",
"Score": "2",
"Tags": [
"strings",
"coldfusion",
"cfml"
],
"Title": "A couple of basic string parsing functions"
} | 11776 |
<p>I have a Visual Studio 2008 C++03 project where I need a timer. I have an implementation that works well, but I'd like any general suggestions from the community on how to improve it. (More generic, lower cost of creating timers, etc...)</p>
<pre><code>class Timer
{
public:
typedef boost::function< void( ) &... | [] | [
{
"body": "<p>I think that you can create one thread to handle all timers. When a new timer is created, you should add it in a (synchronized) queue of \"timers to trigger\". The background thread must wait for the closest timer to be triggered. Also you should wake it up each time you modify the queue of timers... | {
"AcceptedAnswerId": "11782",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-15T20:42:06.990",
"Id": "11777",
"Score": "1",
"Tags": [
"c++",
"timer"
],
"Title": "Timer implementation"
} | 11777 |
<p>Is this the best way to prevent that <code>foreach</code> loop from happening if <code>$terms</code> doesn't exist?</p>
<pre><code>$terms = get_the_terms( $postid, 'fecha' );
if(!empty($terms)) {
foreach($terms as $term) {
$myterm = $term->slug;
if(in_array($myterm, $queried_terms)) {continue... | [] | [
{
"body": "<p>The loop won't be executed if <code>$terms</code> is <code>false</code>/<code>null</code>/an empty array.</p>\n\n<p>As such: you don't need the empty check. It doesn't hurt, but it's simply not required.</p>\n\n<p><strong>If <code>$terms</code> is sometimes not an array</strong></p>\n\n<p>You can ... | {
"AcceptedAnswerId": "11781",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-15T22:03:16.523",
"Id": "11779",
"Score": "5",
"Tags": [
"php"
],
"Title": "!empty() check before a foreach statement"
} | 11779 |
<p>The program is supposed perform discrete mathematics operations on a number of conjunctive statements (see lines 34 - 50). Currently I just have it so they print out the tables in 0's and 1's, but I'll be adding a compare functionality shortly. </p>
<p>Even though I'm sure this work leaves much to be desired I'm cu... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-16T00:31:01.937",
"Id": "18899",
"Score": "2",
"body": "If there's repetition, you need to show more of it so we can get an idea of how it repeats. And while you're at it, explain to us what this code is used for. It looks like you're ... | [
{
"body": "<p>I don't know if you are generating the conditions or if they will just be in your code. If you have to write them all out, you can at least factor the logic out in a function. If you can generate the conditions, use a loop within my_function, then you only have to call it once.</p>\n\n<p>I haven't... | {
"AcceptedAnswerId": "11879",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-16T00:09:31.700",
"Id": "11783",
"Score": "3",
"Tags": [
"python"
],
"Title": "Performing discrete mathematics operations on conjunctive statements"
} | 11783 |
<p>I am about to >explode< :) due to amount of reading on this subject...
My head hurts, and I need some honest opinions...
There is a <a href="https://codereview.stackexchange.com/q/9091">similar question/review</a> that I noticed, but I believe my approach is bit different so I wanted to ask.</p>
<p>We are embark... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-10-22T23:24:00.960",
"Id": "28369",
"Score": "4",
"body": "I don´t like the relationship you have between the Unit of Work and the repositories.\nEvery time you need to add a repository you need to touch the UnitOfWork class, that for me ... | [
{
"body": "<p>It looks good except filter for paging will through error . </p>\n\n<p>The method 'Skip' is only supported for sorted input in LINQ to Entities. The method 'OrderBy' must be called before the method 'Skip'.</p>\n",
"comments": [
{
"ContentLicense": "CC BY-SA 3.0",
"Creati... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-16T01:22:47.173",
"Id": "11785",
"Score": "65",
"Tags": [
"c#",
"design-patterns",
"asp.net-mvc-3"
],
"Title": "EF Code First with Repository, UnitOfWork and DbContextFactory"
} | 11785 |
<p>I'm developing a <a href="https://github.com/kentcdodds/Java-Helper">Java Helper Library</a> which has useful methods developers don't want to type out over and over. I'm trying to think of the best way of checking whether a string is a valid number.</p>
<p>I've always just tried something like <code>Integer.parseI... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-16T02:15:23.067",
"Id": "18900",
"Score": "1",
"body": "http://stackoverflow.com/questions/8391979/does-java-have-a-int-tryparse-that-doesnt-throw-an-exception-for-bad-data"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationD... | [
{
"body": "<p>Well, my first instinct would be to apply a refactoring - specifically <a href=\"http://c2.com/cgi/wiki?ReplaceConditionalWithPolymorphism\">Replace Conditional With Polymorphism</a>.</p>\n\n<p>To do this, create an interface with one method (<code>isValidNumber</code> works). Create four implemen... | {
"AcceptedAnswerId": "11799",
"CommentCount": "9",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-16T01:59:49.457",
"Id": "11786",
"Score": "11",
"Tags": [
"java",
"strings",
"validation"
],
"Title": "Checking whether a string is a valid number"
} | 11786 |
<p>I have two icon animations that pretty much do the same thing, the only difference between them is positioning... one is left and the other right.</p>
<p>I would like to use one block of code for both left and right icon animations.</p>
<pre><code>//////////// Left Icon Animation ////////////
$('.recent .left-icon... | [] | [
{
"body": "<p>Make a function with one parameter, depending on the direction (right or left), copy a block of code and replace the key word there. </p>\n",
"comments": [],
"meta_data": {
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-16T03:42:49.440",
... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-16T03:31:31.090",
"Id": "11789",
"Score": "0",
"Tags": [
"javascript",
"jquery",
"animation"
],
"Title": "Two icon animations — one on the left, one on the right"
} | 11789 |
<p>I've written a program that creates the (minimal unique) directed acyclic graph from the tree structure of an XML-document. The program prints a Bplex-Grammar to cout. I'm interested in all kinds of remarks, and especially performance optimization. </p>
<pre><code>#include <iostream>
#include <sstream>... | [] | [
{
"body": "<p>You don't need the semi-colon(';') here (it looks weird).</p>\n\n<pre><code> TreeNode(){;}\n</code></pre>\n\n<p>The default destructor also does nothing.<br>\nIf you are not doing anything use the one provided.</p>\n\n<pre><code> ~TreeNode(){;}\n</code></pre>\n\n<p>You TreeNode methods are n... | {
"AcceptedAnswerId": "11810",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-16T09:57:18.670",
"Id": "11801",
"Score": "2",
"Tags": [
"c++",
"optimization",
"xml"
],
"Title": "Create Directed Acyclic Graph (DAG) from XML-Tree"
} | 11801 |
<p>I have translated the following F# code to C# and would appreciate constructive criticism. This code computes the symbolic derivative of the expression f(x)=x³-x-1:</p>
<pre><code>type Expr =
| Int of int
| Var of string
| Add of Expr * Expr
| Mul of Expr * Expr
let rec d f x =
match f with
| Var y whe... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-06-18T18:46:45.453",
"Id": "20559",
"Score": "1",
"body": "I think that's as good as it gets in C# (sigh)."
}
] | [
{
"body": "<p>First, there are some code naming and formatting standards in C# that you should follow:</p>\n\n<ul>\n<li>Interfaces begin with I</li>\n<li>Method names are Pascal-cased</li>\n</ul>\n\n<p>And here are a small smattering of my personal standards:</p>\n\n<ul>\n<li>Specify access modifiers at all tim... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-16T13:42:25.877",
"Id": "11804",
"Score": "6",
"Tags": [
"c#",
"f#"
],
"Title": "Symbolic derivative in C#"
} | 11804 |
<p>This is <a href="http://htdp.org/2003-09-26/Book/curriculum-Z-H-16.html#node_sec_12.4" rel="nofollow">HtDP Excercise 12.4.2</a>:</p>
<blockquote>
<p>Develop a function insert-everywhere. It consumes a symbol and a list
of words. The result is a list of words like its second argument, but
with the first argume... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-03-07T07:10:55.157",
"Id": "36338",
"Score": "0",
"body": "You may have misunderstood the question. Also use standard procedures as much as possible. e.g. `length` instead of `find-len`."
},
{
"ContentLicense": "CC BY-SA 3.0",
... | [
{
"body": "<p>Check <a href=\"https://stackoverflow.com/questions/20125784/insert-everywhere-procedure/\">this Stack Overflow question</a> out, which has a solution to the same problem. A simplified version would look like this</p>\n\n<pre><code>(define (insert-at pos elmt lst)\n (if (empty? lst) (list elmt)\n ... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-16T14:06:46.247",
"Id": "11805",
"Score": "5",
"Tags": [
"scheme",
"racket"
],
"Title": "Insert-everywhere function"
} | 11805 |
<p>I've used this PHP/AJAX method of validation for a bit, but I think it could use a little peer review. The basic idea was to create a way of verifying forms in a nice manor using AJAX, but also fall-back to PHP when the user disables JavaScript.</p>
<p>One extra note: jQuery is used throughout the JavaScript files.... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-16T18:26:38.917",
"Id": "18942",
"Score": "1",
"body": "I'm feeling too lazy at the moment to write a proper answer, so a few pointers: Don't compare a boolean to it's string equivalent. Either do `if ($a)` or `if ($a === true)` or `... | [
{
"body": "<p><strong>Code Separation</strong></p>\n\n<p>Break up your functions! That has got to be the largest function I've ever seen!</p>\n\n<p>There's no reason to type that MySQL block over and over again. Make it a function and it will go a long way towards cleaning this up.</p>\n\n<pre><code>function al... | {
"AcceptedAnswerId": "11844",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-16T15:28:28.837",
"Id": "11807",
"Score": "1",
"Tags": [
"javascript",
"php",
"validation",
"ajax"
],
"Title": "Form validation using AJAX with PHP fallback"
} | 11807 |
<p>I have a user class comprised of the code below. It has functions to insert a user, update a user, delete a user, look up a user, and search for users. What I'm wondering is if I this class would pass the Single Responsibility Principle as stated here (http://en.wikipedia.org/wiki/Single_responsibility_principle).</... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-16T18:07:01.920",
"Id": "18941",
"Score": "0",
"body": "Can you post an example usage of this class? I'm not quite sure I understand how you're using it. Why does the constructor accept an array? What is in the array the constructor... | [
{
"body": "<p>I don't think the user class you provided satisfies the Single Responsibility Principle.</p>\n\n<p>I can see a few situations that may require changes to the user class. </p>\n\n<ol>\n<li><p>You want to change what information about the user is stored. This could happen if you need to allow a titl... | {
"AcceptedAnswerId": "11827",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-16T16:18:19.823",
"Id": "11809",
"Score": "3",
"Tags": [
"php",
"classes"
],
"Title": "PHP, would this class pass the single responsibility principle?"
} | 11809 |
<p>I am trying to create a simple factory pattern demo in PHP. I am not sure if my codes are the best practice. It seems that I have some duplicated codes but I am not sure how to improve it. Basically, I want to create 3 types of accounts (basic, premium and vip). Please advise. Thanks a lot.</p>
<p>abstract class</p... | [] | [
{
"body": "<p><strong>Switch Statement</strong></p>\n\n<p>Inside your <code>UserFactory::create()</code> method I would do away with the \"basic\" case as it is the same as default. You can continue passing 'basic' as an argument with no change if you wish, or just stop passing the second argument for basic use... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-16T20:50:39.633",
"Id": "11818",
"Score": "1",
"Tags": [
"php",
"object-oriented"
],
"Title": "Simple Factory Pattern Demo"
} | 11818 |
<p>I feel that I am repeating myself a lot with this HTML/PHP code. Am I right, and is there a maintainable way of reducing the amount of repetition in the code?</p>
<p>mydomain/index.php:</p>
<pre><code><!DOCTYPE HTML>
<?php $root="/mywebdir"; ?>
<html>
<head>
<?php include("$root/inc/meta... | [] | [
{
"body": "<p>Consider using existing template systems to help you that support inheritance. Template inheritance isn't a strict requirement, but is a powerful feature that makes maintaining templates a lot easier. <a href=\"http://twig.sensiolabs.org/\" rel=\"nofollow\">Twig</a> is easy to use, and feature-ric... | {
"AcceptedAnswerId": "11822",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-16T21:00:12.243",
"Id": "11819",
"Score": "4",
"Tags": [
"php",
"html",
"html5"
],
"Title": "Is this violating the DRY principle?"
} | 11819 |
<p>I'm teaching myself how to program Haskell, and I decided to make a find function in Haskell. What it does is it takes two strings, such as <code>"hello"</code> and <code>"he"</code>, and it counts how many times <code>"he"</code> appears in <code>"hello"</code>. In addition, it also uses the <code>*</code> characte... | [] | [
{
"body": "<h2>Update</h2>\n\n<p>Yes, that's better.</p>\n\n<p>Here is a version of your code that uses pattern matching more and guards less. I think it is clearer.</p>\n\n<pre><code>ssearch _ [] = 0\nssearch [] _ = 0\nssearch ('*' : _) _ = error \"no '*' allowed in hay\" --no confusion with wildcard things\ns... | {
"AcceptedAnswerId": "11824",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-16T21:11:40.280",
"Id": "11820",
"Score": "1",
"Tags": [
"haskell"
],
"Title": "Search Function With Wildcard in Haskell"
} | 11820 |
<p>I have a linearized 2D array <code>u</code> (<code>block_height * block_width</code>) containing the values of a physical quantity over a regular 2D mesh. I need to downsample boundaries (top, bottom, left, right) of this array for communication with another process. I've refactored some code that does this, and I'd... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-16T23:56:06.993",
"Id": "18974",
"Score": "0",
"body": "This should also be tagged 'pointer', but not enough rep transfered over from SO to let me create that."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-0... | [
{
"body": "<p>I think the first one is more understandable to a reader, while the second is more efficient and or more easily adapted to higher dimensions. Have you thought about something like:</p>\n\n<pre><code>if (dir == LEFT || dir == RIGHT){ \n int x = dir == LEFT ? 1 : block_width-1;\n double *bo... | {
"AcceptedAnswerId": "11831",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-16T23:55:50.067",
"Id": "11826",
"Score": "1",
"Tags": [
"c++",
"array"
],
"Title": "Downsampling boundaries of a 2D array"
} | 11826 |
<p>This function takes a URL structure which is most often a query string (but sometimes not) and generates filters to remove query variables from the URL.</p>
<p>If you're looking at an archive like</p>
<blockquote>
<p><a href="http://example.com/?genre=rock&band=deep-purple" rel="nofollow">http://example.com/... | [] | [
{
"body": "<p><strong>Breaking Up Is Hard To Do</strong></p>\n\n<p>My first suggestion would be to break up your one function into many. No need to do all of that in just one function. The best way to do this would be to go about it logically. That is to say, break up your function by their purpose. For instanc... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-17T02:40:18.287",
"Id": "11828",
"Score": "1",
"Tags": [
"php",
"url"
],
"Title": "Generating filters to remove query variables from a URL"
} | 11828 |
<p>My application has a thread for handling database inserts and updates. Data is added by other threads to a generic queue in the DB thread. The contents of this queue is retrieved and is sequentially inserted to the database by the thread. </p>
<p>To improve performance, I am planning to bring in a priority mechanis... | [] | [
{
"body": "<ol>\n<li>I don't like that you're treat <code>PQMsgPriority.None</code> in a special way in <code>Dequeue()</code>. If somebody tried to enqueue something with this priority, the code wouldn't work as expected.</li>\n<li>I think your <code>Peek()</code> wouldn't work correctly in some cases. Specifi... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-17T10:30:08.670",
"Id": "11836",
"Score": "5",
"Tags": [
"c#",
".net",
"priority-queue"
],
"Title": "Priority queue implementation in C#"
} | 11836 |
<p>As this community is full of experienced JavaScript developers, and I'm a newbie in JavaScript, I would like if some of you could look over my code for a website I'm building (personal portfolio) and give some insight on how I can improve it, maybe make it more readable and clean, things I may be doing wrong or I mi... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-18T15:26:49.100",
"Id": "19066",
"Score": "1",
"body": "For a \"newbie in JavaScript\" your web page uses JavaScript awfully heavily. Most importantly it's completely broken with JavaScript disabled. If it were a \"web application\", I... | [
{
"body": "<p>Why is <code>Cluster</code> a function? You only instantiate it once, and you don't export anything (as far as I have seen). Use a simple object instead.</p>\n\n<p>If you want to export the <code>Cluster</code>, you should not do it onDOMReady, but as soon as your code executes.</p>\n\n<pre><code>... | {
"AcceptedAnswerId": "11898",
"CommentCount": "12",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-17T11:35:30.450",
"Id": "11838",
"Score": "1",
"Tags": [
"javascript",
"jquery"
],
"Title": "JavaScript initialization for a personal portfolio website"
} | 11838 |
<p>I've been programming in C++ again (after switching to web languages) for about 2 weeks now. I wrote this simple <code>Node</code> class from which all other objects within the Tree will be derived from. Any critique is very welcome here, however please use clear explanations, don't just point out flaws.</p>
<pre><... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-17T19:06:31.480",
"Id": "19019",
"Score": "2",
"body": "My immediate reaction is that the interface is at too low a level of abstraction for most purposes. What do you really want this to accomplish?"
}
] | [
{
"body": "<p>OK. I complain about this every time. Please don't do this.</p>\n\n<pre><code>using namespace std;\n</code></pre>\n\n<p>It may be in every C++ book but in real programs (more than 100) lines it causes more problems than it is worth. You can easily get tangled up in all sorts of problems with name ... | {
"AcceptedAnswerId": "11843",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-17T14:56:29.690",
"Id": "11841",
"Score": "7",
"Tags": [
"c++",
"tree"
],
"Title": "C++ tree base node"
} | 11841 |
<p>These days I read a lot here on SO about password hashing and data encryption. It's a real mess, I mean, deciding what the best practice is. I need a very simple class that can be reused anywhere and that provide a <strong><em>decent-but-not-paranoic</em></strong> security level for my PHP applications (I do not han... | [] | [
{
"body": "<p>Your salt generation mechanism does not seem sufficiently random. You will end up with a very small set of salts.</p>\n\n<p>First of all, <code>time()</code> is not random at all. In second place, <code>rand(0, 1023)</code> is not only a relatively weak random number generator, but also generates ... | {
"AcceptedAnswerId": "15964",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-17T15:48:42.330",
"Id": "11842",
"Score": "4",
"Tags": [
"php",
"security",
"cryptography"
],
"Title": "Am I using crypt and mcrypt well in this simple encryption class?"
} | 11842 |
<p>I'm developing applications using Qt which highly make usage of the JSON language to communicate, store and load data of different types. I often need a simple viewer similar to the <a href="http://www.softwareishard.com/blog/firebug/json-explorer-for-firebug/" rel="noreferrer">Firebug JSON explorer</a> to <strong>v... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2015-01-23T21:10:24.080",
"Id": "142129",
"Score": "0",
"body": "With Qt5 , QJson module are embedded inside the framework. I made a treemodel from Qt model view perspective. https://github.com/dridk/QJsonmodel"
},
{
"ContentLicense": ... | [
{
"body": "<p>I only see minor suggestions so far.</p>\n\n<pre><code>bool hoverEffects();\n</code></pre>\n\n<p>should be</p>\n\n<pre><code>bool hoverEffects() const;\n</code></pre>\n\n<p>and likewise for <code>isExpandable</code>, <code>isExpanded</code>.</p>\n\n<p>Depending on your version of C++, there is som... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-17T19:30:20.293",
"Id": "11849",
"Score": "25",
"Tags": [
"c++",
"json",
"gui",
"qt"
],
"Title": "QJsonView: A QWidget-based json explorer for Qt"
} | 11849 |
<p>This is a class that downloads files in a smart way: it tries to download from different sessions. This do speed up things. How can I Improve it?</p>
<pre><code>import os
import urllib2
import time
import multiprocessing
import string, random
import socket
from ctypes import c_int
import dummy
from useful_util imp... | [] | [
{
"body": "<pre><code> url = url.replace(' ', '%20')\n</code></pre>\n\n<p>has codesmell. You probably want to use the general-case URL encoding method here.</p>\n\n<pre><code> f = open(path, 'wb')\n</code></pre>\n\n<p>should probably be using the 'with' context manager to make sure the filehandle gets cl... | {
"AcceptedAnswerId": "11944",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-17T20:15:34.653",
"Id": "11850",
"Score": "2",
"Tags": [
"python",
"optimization"
],
"Title": "How to improve this SmartDownloader?"
} | 11850 |
<p>I was looking to do this with <code>sizeof()</code> and I just gave up. As minimal as I can make it, I was wondering if there was a less crude way of doing the <code>const char *</code> as a convenience. I thought about doing this as a template, but I thought having another bit of generated code every time it is cal... | [] | [
{
"body": "<p>What about:</p>\n\n<pre><code>std::cout << ::strlen(\"Plop Poop\") << \"\\n\";\n</code></pre>\n\n<p>While we are at it:</p>\n\n<pre><code>// use std::size_t to represent a size of something in memory\n// It is non negative and is explicitly designed so it can represent\n// the biggest ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-18T02:32:52.797",
"Id": "11853",
"Score": "3",
"Tags": [
"c++",
"strings"
],
"Title": "Determining length of a char* string in C++"
} | 11853 |
<p>I currently have a selection sorting algorithm, but need some help turning it into a insertion sort, I understand a insertion sort if faster? The hand array is full, and it needs to sort from lowest to highest rank. </p>
<pre><code>private void sort(PlayingCard[] hand)
{
PlayingCard temp;
for(... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-18T10:37:39.587",
"Id": "19045",
"Score": "5",
"body": "While it’s true that insertion sort is generally faster, both algorithms are inefficient except on almost-sorted or very small input. I’d therefore like to ask what your use-case ... | [
{
"body": "<p>Here is a sort that I put together after some research:</p>\n\n<pre><code>private void sort(PlayingCard[] hand)\n{\n int i, j;\n PlayingCard temp; \n for (i = 1; i < hand.length; i++) {\n temp = hand[i];\n j = i;\n while (j > 0 && hand[j - 1].getRank(... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-18T03:18:54.337",
"Id": "11855",
"Score": "1",
"Tags": [
"java",
"homework",
"sorting"
],
"Title": "Insertion vs Selection"
} | 11855 |
<p>These are the steps to determine coordinates of the 4 points (P1, P2, P3, P4) that make up a tangential trapezoid connecting to circles. Another way of looking at it is to think of the tangential segments of being the parts of a belt that would not be wrapped around the pulleys. The math should work regardless of th... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-18T10:59:52.807",
"Id": "19047",
"Score": "0",
"body": "Great question but [pseudo code is off-topic](http://codereview.stackexchange.com/faq#im-confused-what-questions-are-on-topic-for-this-site)"
},
{
"ContentLicense": "CC BY... | [
{
"body": "<ol>\n<li>It's not clear to me what are <code>buffer0</code> and <code>buffer1</code>? If these represent the radius values (like C1-P1 line for <code>buffer1</code>), then perhaps <code>radius0</code> (and <code>radius1</code>) would be a better name here.</li>\n<li>I'd create and use a data class f... | {
"AcceptedAnswerId": null,
"CommentCount": "15",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-18T05:41:40.023",
"Id": "11858",
"Score": "8",
"Tags": [
"c#",
"computational-geometry"
],
"Title": "C# code to derive tangential points between two circles to create a trapezoid"
} | 11858 |
<p>I have a function named <code>InserUpdateRecords(int flag)</code> to which I pass integer variable which indicates the type of operation it has to perform , if <code>flag==1</code> then insert , if <code>flag==2</code> then update. Here is my code:</p>
<pre><code>public void InsertUpdateRecords(int flag)
{
Data... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-18T10:58:32.190",
"Id": "19046",
"Score": "0",
"body": "Using `catch{}` is a terrible idea. You should only catch exceptions that you know about."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-18T11:04:32.... | [
{
"body": "<p>I would probably pass in the customer log as a parameter to the method and then have it deal with just the database insertion. If you wanted to keep a InsertOrUpdate type of approach I would branch on perhaps something like the object ID if it has one. This way you can have a variety of ways tha... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-18T06:57:23.670",
"Id": "11859",
"Score": "3",
"Tags": [
"c#",
"linq"
],
"Title": "Inserting and updating record using LINQ by calling a common function"
} | 11859 |
<p>I'm very new to C++ and would like you all to review the source code I wrote for a program that calculates the user's BMI and loops the program back to the start if the user needs to do additional calculations.</p>
<pre><code>#include <iostream>
#include <stdlib.h>
using namespace std;
float bmiNumber(... | [] | [
{
"body": "<ul>\n<li><p><code>stdlib.h</code> doesn’t exist in C++. The correct header is <code>cstdlib</code> although most (but not all!) compilers will also find the former.</p></li>\n<li><p><code>using namespace std</code> is generally discouraged since it may cause prolific name clashes. Instead, import ju... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-18T08:25:20.407",
"Id": "11860",
"Score": "5",
"Tags": [
"c++",
"beginner"
],
"Title": "BMI calculation"
} | 11860 |
<p>I have some data in a database, organized like (time, category, value), and basically, I want to show it in a histogram. But the library I use to draw historgrams only works properly if every value is filled. </p>
<p>For instance, this does not work:</p>
<pre><code>bin category value
1 A 5
2 B 3
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-19T19:29:08.787",
"Id": "19111",
"Score": "0",
"body": "You might want to do it all in the database with the help of a view ... for example http://stackoverflow.com/questions/2033535/creating-view-from-complicated-select"
}
] | [
{
"body": "<p>Have you considered linq? Something like:</p>\n\n<pre><code> var j = from i in new[] {1, 2}\n from s in new[] {\"a\", \"b\"}\n select new {i, s};\n</code></pre>\n\n<p>or in method syntax:</p>\n\n<pre><code> var j = new[] {1, 2}.SelectMany(i => new[] {... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-18T09:45:44.123",
"Id": "11862",
"Score": "2",
"Tags": [
"c#"
],
"Title": "Fill a collection from a database with all values filled"
} | 11862 |
<p>My code does what I need it to do, but I think I am missing the "right" way to do this with comparing the arrays. Essentially what I need this to do is compare a textbox entry against two different arrays and redirect based on which value matches. </p>
<pre><code>Protected void Button1_Click(object sender, EventArg... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-17T23:41:49.850",
"Id": "19050",
"Score": "1",
"body": "I'd prefer `List<string>` to arrays, and use the [`Contains`](http://msdn.microsoft.com/en-us/library/bhkz42b3.aspx) method instead of looping. Other than that... what *exactly* a... | [
{
"body": "<p>Would you not be better using the array.Contains(..) method?\nFor example: str1.Contains(TextBox1.Text); should suffice to check whether the string is within the array.\nIt might be worth also storing the two string arrays as HashSet also for speed.</p>\n",
"comments": [
{
"Conte... | {
"AcceptedAnswerId": "11869",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-17T23:37:26.903",
"Id": "11865",
"Score": "7",
"Tags": [
"c#",
"asp.net",
"array"
],
"Title": "Comparing string arrays"
} | 11865 |
<p>We developed a potential solution for the double form submit prevention and we need some review on it. To be able to execute this code on asp.net we needed to add our function call directly into the <code>onsubmit</code> event of the form. This cannot be handled by jQuery because asp.net use a <code>dopostback</code... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-18T15:40:56.920",
"Id": "19071",
"Score": "1",
"body": "Couldn't you just disable the Submit button after the user clicks on it?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-18T16:07:40.657",
"Id": "... | [
{
"body": "<p>Can't you just overwrite the <code>onsubmit</code> handler with the first submission?</p>\n\n<pre><code>function preventDoubleSubmit(e) {\n e = e || window.event;\n var form = e.target || e.srcElement;\n\n form.onsubmit = function() {\n return false;\n };\n}\n</code></pre>\n",
... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-18T13:43:30.350",
"Id": "11874",
"Score": "4",
"Tags": [
"javascript",
"asp.net",
"form",
"event-handling",
"cross-browser"
],
"Title": "Cross-browser double form submit prev... | 11874 |
<p>I am implementing the Factory pattern for creating my objects and am trying to compose the factories using the <code>AssemblyCatelog</code> from MEF.</p>
<p>The problem I have is that while the Import of the <code>InspectionFactory</code> works the Import of the <code>InspectionPhotoFactory</code> does not.</p>
<p... | [] | [
{
"body": "<blockquote>\n <p>If I call the AddPhoto method on an InspectionFault object I can see that the PhotoFactory is null.</p>\n</blockquote>\n\n<p>MEF will never silently fail to compose an object in this way. It will either create the object with all required imports, or fail with a <code>CompositionEx... | {
"AcceptedAnswerId": "11885",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-18T08:58:49.720",
"Id": "11876",
"Score": "2",
"Tags": [
"design-patterns",
".net",
"vb.net"
],
"Title": "MEF composition with nested factories"
} | 11876 |
<p>So this is a lot more confusing than it has to be (I could just stick all of this in the main class with the ui event handlers) but I wanted to decouple this class for learning purposes.</p>
<p><strong>Basic information:</strong></p>
<p>I pulled out a bunch of code and put it in a separate class. This separate cla... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-18T15:37:41.503",
"Id": "19070",
"Score": "2",
"body": "Not a direct answer to your question, so a comment: your approach hides useful information from the caller. You handle the exception, which has lots of information in it, by pass... | [
{
"body": "<p>Answer to question 5: you should use <code>Stringbuilder</code> to create your strings.</p>\n\n<p>Because strings are immutable, whenever you concatenate two strings you create a third. This will quickly ramp up the resources used, as you duplicate longer and longer strings.<br>\nSo, for more than... | {
"AcceptedAnswerId": "11883",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-18T15:34:28.450",
"Id": "11880",
"Score": "3",
"Tags": [
"c#",
"mvc"
],
"Title": "Best practices for decouple classes in C#"
} | 11880 |
<p>After hours of working, I've finally finished my first C log parsing program! (previously was a bash script, now it is C).</p>
<p>Although I think I've gotten most everything, I was just wondering if you saw any possible buffer/memory overflow dangers in the coding?</p>
<pre><code>#include <stdio.h>
#include... | [] | [
{
"body": "<p>An even quicker way to find buffer overflow or memory issues would be to use something like <a href=\"http://valgrind.org\" rel=\"nofollow\">valgrind</a> (Linux, free, open source) or <a href=\"http://www-01.ibm.com/software/awdtools/purify/\" rel=\"nofollow\">Purify</a> (multiplatform, not free) ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-18T23:21:59.570",
"Id": "11886",
"Score": "4",
"Tags": [
"c",
"strings",
"parsing",
"logging"
],
"Title": "Possible buffer overflow dangers in C log parsing program"
} | 11886 |
<p>I'd like to improve the readability of the following code. The aim of this code is to apply formatting to row(s) in a <code>WinForms DataGridView</code> based on the Priority of an item, determined either by its <code>currentPriorityValue</code> or its <code>dueDate</code> property.</p>
<p>Because I've got tiger st... | [] | [
{
"body": "<p>Concentrating on the <code>ConditionallyFormatRowsForUrgency</code> method, I see three times <code>rowStyles = new Tuple<int, Tuple<Color, Color, Font>>(rowIndex, ...)</code> so that is something I would move to a common place. In fact, only its last argument -- lets call it <code>sty... | {
"AcceptedAnswerId": "11900",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-18T23:41:15.680",
"Id": "11887",
"Score": "3",
"Tags": [
"c#",
"unit-testing",
"formatting"
],
"Title": "Formatting rows based on priority"
} | 11887 |
<p>I'm working with two remote APIs: one which manages customers and the other (a Paypal API interface) which manages billing. To delete an account, I must delete the records from both.</p>
<pre><code>function deleteAccount($account_id) {
try {
$api1->deleteAccount( $account_id );
} catch (Exception... | [] | [
{
"body": "<p>Do you have access to the customer API? If so, I think the deletion of the Paypal account should be handled by it.</p>\n\n<p>If you do not have access to it, it seems the most important call is the Paypal one, so you should first make sure that one succeeds. Once it does, you can delete the custom... | {
"AcceptedAnswerId": "11893",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-19T01:22:10.967",
"Id": "11889",
"Score": "1",
"Tags": [
"php",
"error-handling",
"api",
"finance"
],
"Title": "Fail-safe remote API operations for managing customers and bill... | 11889 |
<p>I try to avoid using classes in Python as much as possible; if I don't plan on building on it, I don't build it in the first place. It helps me avoid Java-like classes like <code>FileDownloader()</code>, when I could build <code>download_file()</code> instead.</p>
<p>That being said, I wanted to discuss getter and ... | [] | [
{
"body": "<p>Well, this kind of stuff is usually context dependent and all, but in general your approach is pretty good. Many times I'd put my package's top level functions in it's <code>__init__.py</code> (if it's small) or reimport them there from the package submodules, like your <code>main.py</code> (only,... | {
"AcceptedAnswerId": "11942",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-19T03:06:09.913",
"Id": "11890",
"Score": "18",
"Tags": [
"python",
"functional-programming"
],
"Title": "Replacing Python Classes with Modules"
} | 11890 |
<p>I made an object wrapper/parameter injector and I hope it will be useful. I made it for a project I am working on but then decided to try polishing it a bit.</p>
<p>The use case is for wrapping objects such that you can inject parameters into their methods by calling the wrapper as a function. I was heavily inspire... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-23T23:42:30.527",
"Id": "35575",
"Score": "0",
"body": "I don't know if this is useful advice but you could use some common CoffeeScript conventions like implicit returns, and `=>` to bind a function to the current value of `this`. You... | [
{
"body": "<p>Looks quite good.\nNevertheless here are some thoughts:</p>\n\n<h2>Parameter Names</h2>\n\n<p>You might get problems when calling <code>utils.parameterNames</code> without arguments. E.g. <code>func.toString()</code> would fail if <code>func</code> is undefined.\nMoreover you'll get an array with ... | {
"AcceptedAnswerId": "32265",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-19T04:34:45.997",
"Id": "11891",
"Score": "3",
"Tags": [
"javascript",
"coffeescript"
],
"Title": "Object wrapper/parameter injection module"
} | 11891 |
<p>For practice I tried implementing a bubble sort algorithm in Ruby. I'm especially interested in creating clean DRY and KISS code and keeping things readable, but efficient. Any hints to improve things would be very much appreciated. The code looks like this:</p>
<pre><code>class Sorter
def initialize
end
def... | [] | [
{
"body": "<p>Just a note about the tests: I'd create a test method for every assert call. For example, </p>\n\n<pre><code> def test_StackWithTwoElements\n stack = [2, 1]\n sorted_stack = [1, 2]\n assert_equal(sorted_stack, @sorter.sort(stack), \"sorting stack with two elements: 1, 2 failed\")\n st... | {
"AcceptedAnswerId": "11947",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-19T08:31:36.473",
"Id": "11894",
"Score": "3",
"Tags": [
"ruby",
"unit-testing",
"sorting"
],
"Title": "Bubble sort implementation with tests"
} | 11894 |
<p>Some time ago I've written a small parser (about 250 LoC) which is capable of executing the four arithmetic operators <code>+-*/</code> as well as a dice-roll operator, <code>NdM</code>, which "rolls a dice", DnD style. The source contains only integers, but of course due to division, not only integers are handled. ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-20T00:07:48.987",
"Id": "19121",
"Score": "0",
"body": "Why is \"2d3d4\" considered illegal? Wouldn't that just mean \"roll two 3-sided dice, sum the results, roll that many 4-sided dice, and sum the results\"?"
}
] | [
{
"body": "<p>There are a couple of issues I notice when I look at the code style of your code.</p>\n\n<p>You could hide your internal variables by using the <a href=\"http://www.adequatelygood.com/2010/3/JavaScript-Module-Pattern-In-Depth\" rel=\"nofollow\">module pattern</a>. Information hiding is a very impo... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-19T09:01:13.433",
"Id": "11895",
"Score": "4",
"Tags": [
"javascript",
"parsing",
"dice"
],
"Title": "DnD dice roll parser"
} | 11895 |
<p>I'm building a form dynamically in a web app where I'm using <code>product_id</code> to keep track which product I'm reading and then <code>product_<id>_property</code> to grab the value of it. Then in my view I end up with this:</p>
<pre><code>for product_id in request.POST.getlist('product_id'):
Product... | [] | [
{
"body": "<p>Your code is quite ok and I have no idea how to improve this particular piece. </p>\n\n<p>You have used several identical forms and processed it manually. Django have <a href=\"http://django.me/formsets\" rel=\"nofollow\">formsets</a> for this purpose. Why don't you use them?</p>\n\n<p>Then I don'... | {
"AcceptedAnswerId": "11910",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-19T14:29:11.050",
"Id": "11902",
"Score": "2",
"Tags": [
"python",
"html",
"django"
],
"Title": "Building and getting a form of objects that have multiple properties"
} | 11902 |
<p>I have a hierarchy of types in my program and need to be able to create them dynamically at runtime. The solution I've come up with below is not the most elegant solution. Are there ways of improving it?</p>
<p>Specifically would it be possible to have the method <code>getBuilderFor(...)</code> not need to instanti... | [] | [
{
"body": "<p>Why not use a map of types (<code>CImpl</code> concrete instances) that are instantiated upon <code>Factory</code> initialization? The values of the map would be instances of <code>BImpl</code>, <code>DImpl</code>, etc, and the respective keys would be the types. The function <code>getBuilderFor()... | {
"AcceptedAnswerId": "11905",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-19T14:56:28.500",
"Id": "11903",
"Score": "3",
"Tags": [
"java"
],
"Title": "Factory-like pattern implementation"
} | 11903 |
<p>I'm a JavaScript newbie who was first introduced to JavaScript by jQuery. I'm trying to switch over some of the small things I've written in jQuery to JavaScript as a way of learning. I was wondering how I could make my code cleaner and if there were any bad habits which I am guilty of doing.</p>
<pre><code>functio... | [] | [
{
"body": "<ul>\n<li><p>First step to making the code look good is proper indentation. <a href=\"http://jsbeautifier.org/\" rel=\"nofollow\">JSBeautifier</a> can do that for you. </p></li>\n<li><p>Next is consistency. If you use jQuery, you can go all-out with jQuery to make it as neat and uniform. Of course, y... | {
"AcceptedAnswerId": "11909",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-19T17:33:42.673",
"Id": "11906",
"Score": "1",
"Tags": [
"javascript"
],
"Title": "getTweets in JavaScript"
} | 11906 |
<p>So, first time I try PHP. Thought I'd set a goal for myself, divide it up in smaller problems and start googling. So yes I got it to work, very happy.</p>
<p>But, it is rather crude and ugly. So now I would like to know how it should look.
Proper regex, proper formatting in the array, keeping the links as links and... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-20T05:57:53.210",
"Id": "19126",
"Score": "1",
"body": "I really can't see any problem with this code. What it does is clear, the variable names are good, etc."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-0... | [
{
"body": "<p>Generally, RegExps are a bad choice to deal with HTML code. You're better of with DOM parser: parse the tree and then use XPath to find desired elements, i.e. the ones containing the torrent name and the magnet link. I'm not posting any code because I've never done it in PHP though, but as a point... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-20T03:25:32.373",
"Id": "11917",
"Score": "1",
"Tags": [
"php",
"regex"
],
"Title": "Pirate Bay name and magnet mailer"
} | 11917 |
<p>I am looking for a more efficient or shorter way to achieve the following output using the following code:</p>
<pre><code>timeval curTime;
gettimeofday(&curTime, NULL);
int milli = curTime.tv_usec / 1000;
time_t rawtime;
struct tm * timeinfo;
char buffer [80];
time(&rawtime);
timeinfo = localtime(&raw... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-24T00:49:02.690",
"Id": "19266",
"Score": "2",
"body": "You want to use `%03d` to format `milli` so you get leading zeros. And since your format is so close to ISO-8601, you might want to continue with it and use \".\" instead of \":\"... | [
{
"body": "<p>When you call <code>gettimeofday</code> it gives you the number of seconds since EPOCH too, so you don't need to call <code>time</code> again. And when you use output of <code>localtime</code> as input of <code>strftime</code>, you may omit the intermediate variable (not a very useful point though... | {
"AcceptedAnswerId": "11922",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-20T12:45:01.930",
"Id": "11921",
"Score": "10",
"Tags": [
"c++",
"datetime"
],
"Title": "Getting current time with milliseconds"
} | 11921 |
<h2>I was asked to submit my request for code review on <a href="https://stackoverflow.com/questions/10672046/defining-transpose-on-a-collection-of-irregular-collections">https://stackoverflow.com/questions/10672046/defining-transpose-on-a-collection-of-irregular-collections</a> here.</h2>
<p>This is a follow-up to th... | [] | [
{
"body": "<p>Yes, <code>traspose</code> defined such that it shrings the result to the size of the shortest list isn't an <a href=\"https://en.wikipedia.org/wiki/Involution_%28mathematics%29\" rel=\"nofollow\">involution</a>. Your idea of viewing lists as maps is nice, but I suppose once you leave <code>List</... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-20T13:30:57.190",
"Id": "11924",
"Score": "3",
"Tags": [
"functional-programming",
"scala",
"collections"
],
"Title": "Defining transpose on a collection of irregular collections"
} | 11924 |
<p>When we select the 'info' list in the select field, the article with type 'info' characteristic automatically showed up, and when we select 'Berita' list in the select field, the articles with type 'Berita' characteristic automatically show up.</p>
<p>This is a long script that uses a post method. Can you help me m... | [] | [
{
"body": "<p>Well... First we can shorten your if-construct a lot:</p>\n\n<pre><code>$sql = 'SELECT * FROM artikel_tbl';\nif ($_POST['type'] == 'Info' || $_POST['type'] == 'Berita')\n $sql .= \" WHERE type = '{$_POST['type']}'\";\n$sql .= ' ORDER BY id';\n</code></pre>\n\n<p>In my opinion this also increases ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2012-05-20T14:47:18.370",
"Id": "11925",
"Score": "2",
"Tags": [
"php",
"mysql"
],
"Title": "Present database results based on form submission"
} | 11925 |
<p>I have following code for a content scroller. This has been implemented with basic jquery. Iam trying to convert the same using advanced javascript concepts. Guide me to implement the same.</p>
<p>Working Code : </p>
<pre><code>$(document).ready(function() {
var currentPosition = 0,
slideWidth = 112,
slid... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-20T18:34:33.867",
"Id": "19136",
"Score": "2",
"body": "I don't intend to troll, but do you have a definition of what's _advanced_ and what's not in JavaScript?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-... | [
{
"body": "<p>I can't post a full answer about the \"advanced JavaScript\" part of your question, but here's what I would change in the actual code:</p>\n\n<ul>\n<li><p><strong>Use <code>jQuery.fn.find</code> method</strong></p>\n\n<p>You could optimize this <code>$('#scroller ul li')</code> with this <code>$('... | {
"AcceptedAnswerId": "11932",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-20T17:04:47.570",
"Id": "11926",
"Score": "1",
"Tags": [
"javascript",
"jquery"
],
"Title": "basic javascript to advanced javascript"
} | 11926 |
<p>I wrote <code>QJson</code>, a utility class in/for Qt, I need you to take a look at. It is both a JSON parser and serializer, but with extended functionality (going beyond the <a href="http://json.org" rel="nofollow">JSON specification</a>) (see first section of this post).</p>
<h2>Features</h2>
<p>QJson uses QVa... | [] | [
{
"body": "<h2>In general</h2>\n<p>I like that you didn't try and force OO on something that works very well without it, but it would be simpler, cleaner if you were to just put all those functions in a namespace instead of a class (IIRC the metadata-generating macros for enums work outside classes, too). you c... | {
"AcceptedAnswerId": "11931",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-20T17:17:04.790",
"Id": "11927",
"Score": "6",
"Tags": [
"c++",
"parsing",
"json",
"qt"
],
"Title": "Yet another JSON parser and serializer for Qt, but with additional feature... | 11927 |
<p>Quite some time ago I started this question: <a href="https://codereview.stackexchange.com/questions/5856/looking-for-more-knowledge-on-how-to-make-my-c-vector2-class-better">Mathematical Vector2 class implementation</a> and have since improved on it. I've been using it and it seems to work fine, but I'm always loo... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-21T13:39:51.100",
"Id": "19165",
"Score": "0",
"body": "How are you planning on forcing the inlining? Via compiler options?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-21T21:51:56.513",
"Id": "19192... | [
{
"body": "<pre><code>float32 Vector2::Length() const { return sqrt(x * x + y * y); }\nfloat32 Vector2::LengthSq() const { return x * x + y * y; }\n</code></pre>\n\n<p>Don't dup the code. You already have the functionality for calculating LenSq use it instead of writing it again.</p>\n\n<pre><code>float32 Vecto... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-21T10:28:42.983",
"Id": "11934",
"Score": "5",
"Tags": [
"c++",
"optimization"
],
"Title": "C++ Vector2 Class Review"
} | 11934 |
<p>I messed a little bit with pthreads and needed an alternative to the C++11 function <code>std::lock</code> (2 args are enough), and this is what I came up with: </p>
<pre><code>void lock(pthread_mutex_t* m1, pthread_mutex_t* m2) {
while(1) {
pthread_mutex_lock(m1);
if(pthread_mutex_trylock(m2) == 0) { //... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2015-07-17T15:00:33.860",
"Id": "177874",
"Score": "1",
"body": "Downvoter please explain!"
}
] | [
{
"body": "<p>It does not look like your code will deadlock.<br />\nThat said, I am not very keen on the spin lock like attempt, as I can see situations where it may not be great in efficiency.</p>\n<p>It (<code>std::lock</code>) guarantees that no matter what order you specify the locks in the parameter list y... | {
"AcceptedAnswerId": "11956",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-21T10:33:39.577",
"Id": "11935",
"Score": "6",
"Tags": [
"c++",
"c",
"pthreads",
"locking"
],
"Title": "std::lock implementation in C with pthreads"
} | 11935 |
<p>The following counts the number of page loads and then does something if < <code>MIN_PAGE_VIEWS</code>.</p>
<p>Can anyone give me any pointers to improve both this function and my JavaScript in general? Both in terms of patterns, design and algorithm.</p>
<pre><code>// Call on body onload event.
// Checks to se... | [] | [
{
"body": "<p>If you want to improve your JavaScript, run your code through <a href=\"http://www.jslint.com/\" rel=\"nofollow\">http://www.jslint.com/</a><br>\nWhere it complaints about something, try to understand why - more often than not, it is a valid complaint. :)</p>\n\n<hr>\n\n<ol>\n<li><p>Start the Java... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-21T13:15:13.260",
"Id": "11939",
"Score": "3",
"Tags": [
"javascript"
],
"Title": "Page visit counter"
} | 11939 |
<p>I have a query to return the ids of failed logins that are newer than a supplied date, and also newer than the last successful login.</p>
<p>Table:</p>
<pre><code>#######################################################
# user_attributes #
########################################... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-22T03:13:22.460",
"Id": "19199",
"Score": "0",
"body": "Looks pretty good to me. Have you run Explain against it to ensure you are using indexes?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-22T11:19:12... | [
{
"body": "<p>The code looks good to me as well except if you are looking for the ids of the failed logins you would not want to count the ids (SELECT count(id)) but instead just select the id (SELECT id).</p>\n",
"comments": [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-... | {
"AcceptedAnswerId": "11985",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-21T13:49:26.953",
"Id": "11940",
"Score": "1",
"Tags": [
"performance",
"sql",
"mysql"
],
"Title": "Return the ids of failed logins"
} | 11940 |
<p>The main class (<code>SMSHelper</code>) is responsible of query a REST web service which in turn returns an XML string. This helper is going to return a new <code>SMSCreditInfo</code> instance (merely a data <strong>container</strong>), with the help of a parser (<code>SMSCreditParser</code>):</p>
<pre><code>class ... | [] | [
{
"body": "<p>I hope you're still watching this. Answers here at codereview tend to take a while. I've been on vacation, else I would have answered sooner. Hope this answer satisfies :)</p>\n\n<p>\"i think it's not following the loose coupling pattern at all.\" - You'd be correct.</p>\n\n<p>\"not DRY too\" - Al... | {
"AcceptedAnswerId": "12146",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-21T13:59:53.203",
"Id": "11943",
"Score": "1",
"Tags": [
"php",
"design-patterns",
"parsing"
],
"Title": "Parsing credit info"
} | 11943 |
<p>Well this was a simplest code competition at my work.
I tried a couple things, they accepted but none of them is I wanted.
Because both are always giving same result.</p>
<p>I tried to randomize like this</p>
<pre><code>var list = $(".content li").sort(Math.round(Math.random())-0.5);
</code></pre>
<p>and this</p>... | [] | [
{
"body": "<p>Here is a version that is working, but I'm not sure if it is the best way to do it (<strong>this is not the best way, look below</strong>)</p>\n\n<pre><code>var $elements = $('.your-selector');\n\n// print it once to see its content\nconsole.log( $elements.get() );\n\n// get all DOM elements in te... | {
"AcceptedAnswerId": "11957",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-21T09:34:11.403",
"Id": "11948",
"Score": "-1",
"Tags": [
"javascript",
"jquery",
"performance",
"random"
],
"Title": "Randomize a jQuery object list"
} | 11948 |
<pre><code>let binsearch ~arr ~cmp x = (
let cmpx = cmp x in
(* Assuming arr is ordered according to cmp, then (bs min max) is an *)
(* index of a value v in arr such that ((cmp x value) = 0) between *)
(* min (inclusive) and max (exclusive). *)
let rec bs min ma... | [] | [
{
"body": "<p>Generally speaking, yes. I only have a couple of minor remarks.</p>\n\n<pre><code>let cmpx = cmp x in\n</code></pre>\n\n<p>Using partially-applied functions is actually slightly slower with the native-code compiler. The <code>cmp</code> function (like most functions) isn't going to do anything unt... | {
"AcceptedAnswerId": "11958",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-21T18:40:16.750",
"Id": "11952",
"Score": "3",
"Tags": [
"binary-search",
"ocaml"
],
"Title": "Is this binary search close to idiomatic OCaml?"
} | 11952 |
<p>I would like to refactor a large Python method I wrote to have better practices.</p>
<p>I wrote a method that parses a design file from the FSL neuroimaging library. Design files are text files with settings for the neuroimaging software. I initially wrote the code to do all the processing in a single loop though t... | [] | [
{
"body": "<p>Your function acts widely different depending on the value of the <code>type</code> parameter. In fact, it basically acts like different functions depending on that parameter. It returns completely different sets of values depending on the value of <code>type</code>. The function would be better o... | {
"AcceptedAnswerId": "11982",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-05-21T23:58:39.273",
"Id": "11961",
"Score": "4",
"Tags": [
"python",
"parsing",
"configuration"
],
"Title": "Parse a text file containing settings for neuroimaging software"
} | 11961 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.