body stringlengths 25 86.7k | comments list | answers list | meta_data dict | question_id stringlengths 1 6 |
|---|---|---|---|---|
<p>I decided to try making some simple clones of the various user-space Unix utilities in an effort to learn the system-specific headers and improve my C skills. The code that follows is a clone of <code>sleep</code> and I'm curious as to whether there are any pitfalls I'm overlooking (including security vulnerabilitie... | [] | [
{
"body": "<ul>\n<li><p>An error message (\"too few\"/\"too many\") is not helpful. Typically when an Unix utility cannot deal with the command line it prints what it expects:</p>\n\n<p>For example,</p>\n\n<pre><code>fprintf(stderr, \" Usage: %s sleep_duration\", argv[0])\n</code></pre>\n\n<p>It is also customa... | {
"AcceptedAnswerId": "58605",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-31T05:19:15.260",
"Id": "58594",
"Score": "7",
"Tags": [
"c",
"reinventing-the-wheel",
"unix"
],
"Title": "Unix 'sleep' clone - unsure of safety"
} | 58594 |
<p>Sometimes I need to create character vectors like this one:</p>
<pre><code>datanames <- c(
"europe_co2_min",
"europe_co2_max",
"europe_temperature_min",
"europe_temperature_max",
"asia_co2_min",
"asia_co2_max",
"asia_temperature_min",
"asia_temperature_max"
)
</code></pre>
<p>Notice that this is... | [] | [
{
"body": "<p>Your approach is an example of good R code. However, there is a base function that allows creating a cartesian product of strings, <code>interaction</code>. This function creates a factor, and the levels are equivalent to the cartesian product.</p>\n\n<p>Furthermore, instead of <code>paste(..., se... | {
"AcceptedAnswerId": "58627",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-31T05:34:14.763",
"Id": "58595",
"Score": "16",
"Tags": [
"beginner",
"strings",
"combinatorics",
"r"
],
"Title": "Generating Cartesian product of strings in R"
} | 58595 |
<p>I am building a infinite vertical platformer for mobile platforms using Unity3D. I am using the accelerometer to move the character left and right on the screen.</p>
<pre><code>if (Input.acceleration.y > -0.2f && Input.acceleration.y < 0.2f) {
maxSpeed = 17;
}
... | [] | [
{
"body": "<p>I know absolutely nothing about <a href=\"/questions/tagged/c%23\" class=\"post-tag\" title=\"show questions tagged 'c#'\" rel=\"tag\">c#</a> or <a href=\"/questions/tagged/unity3d\" class=\"post-tag\" title=\"show questions tagged 'unity3d'\" rel=\"tag\">unity3d</a>, so if there's... | {
"AcceptedAnswerId": "58600",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-31T05:35:20.837",
"Id": "58596",
"Score": "11",
"Tags": [
"c#",
"performance",
"unity3d",
"mobile"
],
"Title": "Moving character in Unity3D based on accelerometer input"
} | 58596 |
<p>For some reason, I feel like this is a bit messy and could be cleaner. Any suggestions? </p>
<p>I'm selecting any image files ending in <code>.png</code> or <code>.jpg</code>, and removing any image source files that contains avatar (meaning it's a header image or an avatar).</p>
<pre><code>def self.images(url)
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-31T06:26:34.610",
"Id": "105214",
"Score": "0",
"body": "Perhaps some added white space could help"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-31T06:31:13.910",
"Id": "105216",
"Score": "0",
... | [
{
"body": "<p>There is no point in hard-coding <code>proxy_addr</code> and <code>proxy_port</code> separately, then concatenating them using interpolation. On the other hand, it <em>would</em> be useful to make the proxy configurable. One way is to use a default parameter:</p>\n<pre><code>def self.images(url,... | {
"AcceptedAnswerId": "58614",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-31T06:19:09.497",
"Id": "58601",
"Score": "2",
"Tags": [
"ruby",
"web-scraping"
],
"Title": "Find and select image files from webpage"
} | 58601 |
<p>This is a login class I made for my personal website. </p>
<p>What I don't care about, is how secure this login class is, because I know it's not. But it keeps out the rare unwanted guests because I do not want to have my information public. I made this mainly for learning purposes. I want to know how "OOP" this is... | [] | [
{
"body": "<p>Yes, there are several things I can see with your implementation, from most critical to less critical:</p>\n\n<ul>\n<li><strong>SQL Injection</strong> - You has it! Since you're already using mysqli, learn about <strong><a href=\"http://php.net/manual/en/mysqli.prepare.php\">prepared statements wi... | {
"AcceptedAnswerId": "58619",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-31T07:15:04.800",
"Id": "58609",
"Score": "10",
"Tags": [
"php",
"object-oriented",
"mysqli",
"authentication"
],
"Title": "PHP OOP Login Class"
} | 58609 |
<blockquote>
<p>The number, 197, is called a circular prime because all rotations of the digits: 197, 971, and 719, are themselves prime.</p>
<p>There are thirteen such primes below 100: 2, 3, 5, 7, 11, 13, 17, 31, 37, 71, 73, 79, and 97.</p>
<p>How many circular primes are there below one million?</p>
</blockquote>
<p... | [] | [
{
"body": "<p><strong>Style</strong></p>\n\n<p>In Python, there is usual style guide called <a href=\"http://legacy.python.org/dev/peps/pep-0008/\" rel=\"noreferrer\">PEP8</a> : I think you should follow it to make your code more consistent with all the Python code out in the wild out there. If you want to, you... | {
"AcceptedAnswerId": "58622",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-31T07:19:06.873",
"Id": "58610",
"Score": "7",
"Tags": [
"python",
"performance",
"beginner",
"programming-challenge",
"python-3.x"
],
"Title": "Efficiency of Project Eule... | 58610 |
<p>I have written an <code>EmailSession</code> class to connect and get (unread) mail messages. It is all working, but I would like to see your opinions on any enhancements or improvements, as I understood there are lots of bad examples on the Internet and I copy-pasted most of it together.</p>
<p>One issue I already ... | [] | [
{
"body": "<p>I'd expect a <code>WhateverSession</code> to implement <code>AutoCloseable</code>, to be usable in a \"try-with-resources\" statement.</p>\n\n<p>For that you need: Java 7, a void method <code>close()</code> to override the <code>AutoCloseable</code></p>\n\n<p>Your class then would look minimally d... | {
"AcceptedAnswerId": "58663",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-31T07:24:42.133",
"Id": "58611",
"Score": "4",
"Tags": [
"java",
"email"
],
"Title": "EmailSession in Java Webapp"
} | 58611 |
<p>I'm writing a console application where I need to provide detailed error messages in case anything goes wrong. As a result of this, I find myself splitting up my code into many pieces and making sure that every step is handled correctly. While this certainly makes it possible to detail what exactly went wrong, it un... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-31T18:40:27.307",
"Id": "105390",
"Score": "0",
"body": "Exceptions containing an error message and a utility function that checks a boolean success value and throws if it is false."
},
{
"ContentLicense": "CC BY-SA 3.0",
"... | [
{
"body": "<p>Make a function that writes an error message (String) to the console, then exits with failure error code. But I'm not sure whether this would mess up your returns and overall control flow.</p>\n\n<p>Other than that, I don't know. Yes, you can golf the string to <code>\"Unable to open X : \" + x + ... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-31T07:27:30.747",
"Id": "58612",
"Score": "14",
"Tags": [
"c#",
"console",
"error-handling"
],
"Title": "Console application for providing detailed error messages"
} | 58612 |
<p>Given list of pairs (email-date):</p>
<pre><code>['ann_osman@mail.com', '2 august 1976'],
['jz_neo@mail.com', '3 august 2001'],
['keyes_signak@mail.com', '2 october 2001'],
['cassadi_algazi@hotmail.com', '2 october 2001'],
['karmen_algazi@aol.com', '2 august 2001']]
</code></pre>
<p>I need to turn it into dict... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-31T18:21:47.023",
"Id": "105388",
"Score": "1",
"body": "Your code actually does more than advertised: the e-mail addresses are all added as keys to `date_for_emails_dict` as well."
}
] | [
{
"body": "<p>A good function will should accept the data as a parameter and return the resulting data structure. Call <code>print(emails_by_date(email_date_table))</code> to put it all together.</p>\n\n<p>Two Pythonic techniques you want to use are:</p>\n\n<p><ul>\n<li><a href=\"https://docs.python.org/3/libr... | {
"AcceptedAnswerId": "58621",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-31T07:37:07.870",
"Id": "58615",
"Score": "5",
"Tags": [
"python",
"python-3.x"
],
"Title": "Faster way to group email-date pairs by date without many nested for loops?"
} | 58615 |
<p>I want to construct a form builder for an internal project in mvc4. I am using partial views to load the various controls. However I feel that having ten or 20 action-results in my HomeController would not be the best way to go.<br>
So I am wondering how I could do the following more efficiently.</p>
<p>As you see ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-31T12:09:51.793",
"Id": "105293",
"Score": "1",
"body": "A few things. First off, welcome to [codereview.se]! Second. I edited your post for grammar and stuff. Please check that I didn't break anything or change the intent of your ques... | [
{
"body": "<p>I would add \"data-api\" as an attribute to the buttons</p>\n\n<pre><code><input type='button' data-api='Home/HtmlControlTest' />\n</code></pre>\n\n<p>Then you could do this with the js</p>\n\n<pre><code>$('input[data-api]').click(function () {\n\n $.ajax({\n url: $... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-31T09:48:41.880",
"Id": "58637",
"Score": "4",
"Tags": [
"c#",
"asp.net-mvc-4"
],
"Title": "FormBuilder Code Make More Genereic"
} | 58637 |
<p>I am checking if there are any rows in a table with some conditions. If there are more than 1 row, it should filter again with some more conditions.</p>
<pre><code>DECLARE @Matches AS int
DECLARE @Result AS int
SET @Matches =
(
Select COUNT(*)
FROM Houses
INNER JOIN Houses_Access ON Hou... | [] | [
{
"body": "<p>Create a view vw_HousesAccess which will contain following query and then</p>\n\n<pre>\n<code>\n Create View vw_HousesAccess \n as \n Select * --TODO specify columns where \n FROM Houses \n INNER JOIN Houses_Access ON Houses.ID = Houses_Access.DoorKey\n ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-31T10:19:13.090",
"Id": "58640",
"Score": "2",
"Tags": [
"sql",
"sql-server"
],
"Title": "Reusing select statement"
} | 58640 |
<p>The purpose of this SQL query would be to extract the record 10192 only, because the <code>end_time</code> is both in the past and its foreign counterpart in the Node table still has the <code>status</code> 1. I don't want to select the record 10111 because it hasn't expired.</p>
<p>I've just finished writing this ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-31T11:53:30.173",
"Id": "105290",
"Score": "0",
"body": "Welcome to Code Review!"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-01T02:45:28.190",
"Id": "105494",
"Score": "0",
"body": "And the ... | [
{
"body": "<p>First thing's first. The indentation is all jacked up. There's not really a standard for formatting SQL, but as a rule of thumb, <code>Select</code>, <code>From</code>, and <code>Where</code> for any (sub)query should be at the same indentation level. </p>\n\n<pre><code>SELECT MAX(l.id) AS highest... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-31T10:43:27.367",
"Id": "58643",
"Score": "5",
"Tags": [
"sql",
"mysql"
],
"Title": "Extracting certain records"
} | 58643 |
<p>I am rewriting a VB.NET app into C#. I won't subject you to the original code. I am mainly looking for a better way to handle all the join statements that are being done. I am dealing with a legacy database that I cannot currently change the structure of. (Though I am making my arguments for it)</p>
<p>I am wonderi... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-31T12:26:26.547",
"Id": "105296",
"Score": "0",
"body": "Keep in mind, that each join-query has their own properties. We will most probably not be able to give advice on things you didn't show us :("
},
{
"ContentLicense": "CC ... | [
{
"body": "<p>I'm not sure what you mean by a 'cleaner way'. The syntax you're using is known as query syntax and is by far the best for readability when you have multiple joins.</p>\n\n<p>If you use method syntax to express the same query you'll quickly see what I mean.</p>\n\n<p>However, if you use method syn... | {
"AcceptedAnswerId": "58652",
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-31T12:22:15.130",
"Id": "58649",
"Score": "3",
"Tags": [
"c#",
"linq"
],
"Title": "Is there a better way to handle multiple join statements in a linq query?"
} | 58649 |
<p>I have a piece of code which follows this form. Is this correct or is there a better way?</p>
<pre><code>for i, c in enumerate(contacts):
fullname = c['Person__FirstName'] + ' ' + c['Person__LastName']
contacts[i]['fullname'] = create_a_tag('/contact/'+str(c['PersonSk']), fullname)
</code></pre>
| [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-31T20:46:45.037",
"Id": "105438",
"Score": "0",
"body": "I don't see why this should be closed. Short entries of code, that do follow Code Review rules, [are on-topic](http://meta.codereview.stackexchange.com/a/1588/35559)."
},
{
... | [
{
"body": "<p>I have the feeling that there's some context information missing. Anyway, note that <code>list_of_dictionaries[i]</code> is actually the same object as <code>r</code>.</p>\n\n<p>The same code with some variables renamed would be as follows:</p>\n\n<pre><code>for index, dictionary in enumerate(dict... | {
"AcceptedAnswerId": "58655",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-31T13:27:45.883",
"Id": "58653",
"Score": "-1",
"Tags": [
"python",
"beginner",
"python-2.x"
],
"Title": "Update a field in a list of dictionaries"
} | 58653 |
<p>The below function uses Javascript to validate a Belgian telephone number and format it according to the guidelines for phone number formatting.</p>
<pre><code>function acm_mscrm2011_psa_FormatPhoneNumber(executioncontext) {
//get the phone number from the field that starts the validation
var telefoonnummer... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-31T13:59:38.523",
"Id": "105313",
"Score": "2",
"body": "At least use `[0-9]` and `\\d` consistently. And I'd personally replace `\\d\\d\\d` with `\\d{3}`. As to the number of expressions, I think you're fine. Fewer, more complex ones... | [
{
"body": "<p>For one, I wouldn't worry about the number of regexps here. There's nothing terribly complex going on here. I'd say regular expressions are the right tools for this job, so no reason to change that.</p>\n\n<p>I do have some other comments though:</p>\n\n<ol>\n<li><p>I'd advice you to always use En... | {
"AcceptedAnswerId": "58669",
"CommentCount": "8",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-31T13:54:30.080",
"Id": "58654",
"Score": "5",
"Tags": [
"javascript",
"regex"
],
"Title": "Do I have too many regexes in my validation logic?"
} | 58654 |
<p>I was looking at some Linq queries with multiple join statements. I was thinking that they could be cleaned up using extension methods that hide away the join / where statements.</p>
<p>For example:</p>
<pre><code>(from myObject in _context.MyObject
join myObjectGroupName in _context.MyObjectGroupNames on myObject... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-31T15:07:29.320",
"Id": "105333",
"Score": "2",
"body": "Not sure if your ORM supports this, but in general you can remove the need for a lot of joins altogther by fixing your entity mappings. ie instead of joining MyObjectGroupNames, ... | [
{
"body": "<p>Have you considered using in Interface on MyObject?</p>\n\n<pre><code>public static IQueryable<T> JoinWhere(this IQueryable<T> initialObject, IQueryable<TJoinOn> joinOn, IEnumerable<string> types) \nwhere T : IMyObject\n{\n return (from myObject in initialObject\n ... | {
"AcceptedAnswerId": "66428",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-31T14:35:34.423",
"Id": "58656",
"Score": "2",
"Tags": [
"c#",
"generics"
],
"Title": "Convert Extension methods to generic methods"
} | 58656 |
<p>Should I be putting Linq statements inside of an objects properties? Is that a best practice or is that a no no? Also if that is ok, where do I draw the line with this? I assume db access is probably too far but is there a line, or just a gray area? Do you see any issues with my usage of Linq?</p>
<pre><code>[X... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-31T16:37:17.753",
"Id": "105357",
"Score": "1",
"body": "I don't know much about Linq, so I'll refrain from answering, but I don't see any issues with this kind of abstraction. In fact, I think it's a good thing."
},
{
"Content... | [
{
"body": "<p>Methods <code>Set</code> and <code>Get</code> Properties through their <code>Get</code> and <code>Set</code> methods, so it isn't a really good idea to perform operations on properties inside their get and set methods.</p>\n\n<p>you should use the object methods to do this.</p>\n\n<blockquote>\n<p... | {
"AcceptedAnswerId": "58680",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-31T15:51:36.520",
"Id": "58667",
"Score": "19",
"Tags": [
"c#",
"linq",
"properties"
],
"Title": "Using C# properties for simple operations, where should I draw the line?"
} | 58667 |
<p>Just trying out my T-SQL foo.</p>
<p>Wrote a script to get the average time (in seconds) to first answer for a specified language.</p>
<pre><code>-- Could not get this so that the user entered
-- the language in a box at the bottom working.
-- so you have to edit the code here.
declare @Language nvarchar(20) = 'ph... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-31T16:55:56.417",
"Id": "105366",
"Score": "0",
"body": "I took the liberty to get your parameter up and running ;)"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-31T17:55:17.160",
"Id": "105382",
... | [
{
"body": "<p>The one thing that jumped out at me was</p>\n\n<pre><code>WHERE Q.Id = A.ParentId\n</code></pre>\n\n<p>You could <code>JOIN</code> the tables on that link instead.</p>\n\n<hr>\n\n<p>Formatting wise, (and you probably already know this, most people find it a bit tedious to do) is to make sure that ... | {
"AcceptedAnswerId": "58677",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-31T15:52:56.590",
"Id": "58668",
"Score": "26",
"Tags": [
"sql",
"datetime",
"sql-server",
"stackexchange"
],
"Title": "Average time to first answer"
} | 58668 |
<p>This is a solution to <a href="http://www.cprogramming.com/challenges/permute.html" rel="nofollow">this problem</a>. The problem statement:</p>
<blockquote>
<p>write a program to display all possible permutations of a given input
string--if the string contains duplicate characters, you may have
multiple repea... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-01T23:47:45.513",
"Id": "105735",
"Score": "0",
"body": "Look at `std::next_permutation()` The number of permutations of a string is `factorial(string.size())`"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-0... | [
{
"body": "<ul>\n<li><p>Technically, the code doesn't meet the requirements: displaying number of permutations is not requested. You may add an option to display it as well, but a <em>simple</em> invocation <code>permute string</code> shall display <em>only</em> the permutations.</p></li>\n<li><p>Returns from <... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-31T17:03:21.573",
"Id": "58675",
"Score": "4",
"Tags": [
"c++",
"strings",
"c++11",
"combinatorics"
],
"Title": "Another permutator"
} | 58675 |
<p>Suppose we're implementing an interpreter for the bytecode of some stack machine. Let every element of the stack be a <code>Word8</code>, and let the stack be represented by a list:</p>
<pre><code>type Stack = [Word8]
</code></pre>
<p>We'll need opcodes for addition, subtraction, and unary negation. However, apa... | [] | [
{
"body": "<p>I'm not familiar with using Data.Word so I switched to using ints. I think your solution looks to be overkill. How does my solution match your specification? </p>\n\n<pre><code>import Control.Monad.State\nimport Data.Maybe\nimport Control.Applicative\nimport Data.List\n\n\ntype Stack = [Int]\n\nda... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-31T18:39:38.927",
"Id": "58685",
"Score": "3",
"Tags": [
"haskell",
"polymorphism"
],
"Title": "Type dispatch based on runtime value"
} | 58685 |
<p>I'm starting with Elixir and as exercise I wrote the <a href="http://agilekatas.co.uk/katas/berlinclock-kata.html" rel="noreferrer">Berlin Clock kata</a>:</p>
<ul>
<li>The clock is made up of 5 rows.</li>
<li>On the very top of the clock is a lamp that blinks to show the seconds. It turns on for one second, then of... | [] | [
{
"body": "<p>First: <strong>I have to admit, I do not know a single line Elixir.</strong></p>\n\n<p>But on the other hand, I think I get, what the code does. \nI can not give you advice, how to implement the improvements, but I hope to help you anyway.</p>\n\n<p>In the description you have the following defini... | {
"AcceptedAnswerId": "59982",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-31T20:14:59.050",
"Id": "58690",
"Score": "9",
"Tags": [
"datetime",
"elixir"
],
"Title": "Berlin clock kata in Elixir"
} | 58690 |
<p>I am building a ticket management system for a state server we use at work. Back end is node.js with multiple front ends. I am rewriting my back end to be more maintainable as the scope grows.</p>
<p>For this particular function I start with this:</p>
<pre><code>[
{
"id": 4993,
"ticket": "A14... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-31T20:37:00.887",
"Id": "105429",
"Score": "4",
"body": "Well, if `arr` is an array, you're using the wrong loop, instead of `for..in` you should use a regular `for`."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": ... | [
{
"body": "<p>It seems like you are using underscore library. so why you need to do it manually?</p>\n\n<pre><code>var groupeddata = _.groupBy(data, function (row) {\nvar from = row.sort.split(\"/\");\nvar dateparse = new Date(from[2], from[0] - 1, from[1]);\nreturn dateparse;\n});\n</code></pre>\n\n<p>I hope t... | {
"AcceptedAnswerId": null,
"CommentCount": "7",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-31T20:33:19.710",
"Id": "58692",
"Score": "7",
"Tags": [
"javascript",
"array",
"sorting",
"json"
],
"Title": "Ticket management system"
} | 58692 |
<p>The code below works for very small dictionary files I used to test (two words). However when I run this using a more typical dictionary file, my machine slows to the point of near crash. I would like a review of what the potential bottleneck may be which I believe to be in the <code>load()</code> function. Of cou... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-31T22:44:14.903",
"Id": "105463",
"Score": "1",
"body": "It would be a whole lot easier to profile your code for the bottleneck if you included *everything* and not just this little bit."
},
{
"ContentLicense": "CC BY-SA 3.0",
... | [
{
"body": "<p>A few notes:</p>\n\n<ul>\n<li><p><code>typedef struct</code> names are commonly written in <a href=\"http://c2.com/cgi/wiki?PascalCase\" rel=\"nofollow noreferrer\">PascalCase</a> today.</p>\n\n<pre><code>Node* current = NULL;\n</code></pre></li>\n<li><p>Initialize your variables on the lowest sco... | {
"AcceptedAnswerId": "58702",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-31T22:05:47.973",
"Id": "58699",
"Score": "4",
"Tags": [
"performance",
"c",
"trie"
],
"Title": "Loading dictionary using trie in C very slow with large data set"
} | 58699 |
<p>One thing nagged me about the compass vertical rhythm module; in the case the headline is too long and it occupies more than one line the line-height between the two lines looks way too massive and off.</p>
<p>Based on the following <a href="http://www.smashingmagazine.com/2011/03/14/technical-web-typography-guidel... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-31T22:17:03.647",
"Id": "58700",
"Score": "2",
"Tags": [
"sass",
"mixins"
],
"Title": "Modification of the headline line-height in the Compass vertical rhythm module"
} | 58700 |
<p>I'm working on an implementation of Rainbow tables as part of a project. I understand the main principles behind it had have a working solution. Unfortunately the reduction function portion of my project is the slowest part I'm hoping that someone might be able to point out places that I can speed it up.</p>
<p>The... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-01T06:28:24.690",
"Id": "105518",
"Score": "0",
"body": "I don't see the `chainWalkFromPositionToEnd` function code. Is it in the question? Have you profiled the code? Your bottleneck guess is probably right, but I think it would be a ... | [
{
"body": "<p>A few suggestions (not really a complete answer):</p>\n\n<ul>\n<li><p>Do not reinvent the wheel. Use the <code>bisect</code> module from the standard library to perform a binary search.</p></li>\n<li><p>Use a hash sign (<code>#</code>) to start comments. When triple quotes are used, what happens i... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-31T23:15:44.603",
"Id": "58705",
"Score": "3",
"Tags": [
"python",
"optimization",
"python-2.x",
"numpy"
],
"Title": "Reduction function in Rainbow tables implementation"
} | 58705 |
<p>I smell something wrong here, but am not quite sure what the most <em>idiomatic</em> way to solve the problem.</p>
<p>I have a controller for (job)<code>listings</code> and it has a method called <code>apply</code>. This method is used when someone has a resume and is clicking to apply for the job associated with ... | [] | [
{
"body": "<p>Given the current setup, the simplest thing would probably be to raise an exception using <a href=\"http://api.rubyonrails.org/classes/ActiveRecord/Persistence.html#method-i-save-21\" rel=\"nofollow\"><code>#save!</code></a>:</p>\n\n<pre><code>def apply_to(listing)\n jobapp = Jobapp.new(resume: s... | {
"AcceptedAnswerId": "58707",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-31T23:30:48.693",
"Id": "58706",
"Score": "2",
"Tags": [
"ruby",
"ruby-on-rails"
],
"Title": "Checking if an associated object has failed to save/create"
} | 58706 |
<p>My main goal with this refactor was to change instance methods that should have been class methods in the first place into class methods. My secondary goal was to add singletons to these classes because they are Model classes and I feel that there should only be one instance at any given time.</p>
<p><strong>HALAdd... | [] | [
{
"body": "<blockquote>\n <p>Do I have too many class methods? Do I have class methods that should/could be instance methods?</p>\n</blockquote>\n\n<p>There's not a specific number of class methods you should have. Don't try counting your class methods or your instance methods. Class methods do class level t... | {
"AcceptedAnswerId": "58710",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-01T00:20:17.817",
"Id": "58708",
"Score": "5",
"Tags": [
"object-oriented",
"objective-c",
"singleton"
],
"Title": "Address book with singletons"
} | 58708 |
<p>I just learned about dependency injection/dependency injection containers, and I realize that the controller in my MVC web application is hard to test.</p>
<p>My original controller class: </p>
<pre><code>class Controller
{
protected $db;
private $article;
private $nav;
public function __construct... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-01T12:56:32.623",
"Id": "105583",
"Score": "0",
"body": "Your controller is hard to test because it instantiates the objects it depends on instead of asking for them."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": ... | [
{
"body": "<p>You are not even doing Dependency Injection here. In your controller constructor for example</p>\n\n<pre><code>public function __construct($db) \n{\n $this->db = $db;\n $this->article = new Article($this->db);\n $this->nav = new Nav($this->db);\n}\n</code></pre>\n\n<p>sure ... | {
"AcceptedAnswerId": "58757",
"CommentCount": "8",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-01T00:43:45.340",
"Id": "58709",
"Score": "1",
"Tags": [
"mvc",
"php5",
"dependency-injection"
],
"Title": "Dependency injection/dependency injection containers in MVC web app"
} | 58709 |
<p>Which algorithm do you think is better in regards to readability and efficiency?</p>
<p><strong><code>selection()</code>:</strong></p>
<pre><code>public static int[] selection(int[] tab) {
int minor;
int aux;
for (int i=0; i<tab.length-1; i++) {
minor = tab[i];
for (int j=i+1; j<=... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-01T02:02:58.197",
"Id": "105480",
"Score": "0",
"body": "I think you'll have better luck with this question [Programmers Exchange](http://programmers.stackexchange.com/)"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate... | [
{
"body": "<p><strong>Readability:</strong></p>\n\n<p>The first one is far more readable because it can be translated at so:</p>\n\n<pre><code>selection(tab) \n for each value of tab: i = (0->size-1) \n minor = tab[i]\n for each value of tab: j = (i->size-1) \n if (tab[j] < ... | {
"AcceptedAnswerId": "58715",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-01T01:59:06.903",
"Id": "58714",
"Score": "2",
"Tags": [
"java",
"sorting",
"comparative-review"
],
"Title": "Java sort by selection: which is better in regards to readability and... | 58714 |
<p>As an exercise, I was asked to design a database schema (for MS SQL Server) for a tabletop game. The requirements were simple: players compete in matches and there are specific match types (e.g. 1v1 or 2v2). A hypothetical web site that would make use of this database would include things like player match history, ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-01T04:15:21.123",
"Id": "105506",
"Score": "0",
"body": "One of the requirements for questions on this site is that the posted code must work. If it's \"not tested\", then how can it be known whether or not it works?"
},
{
"Con... | [
{
"body": "<h1><strong>Good work on schema</strong></h1>\n\n<p>Overall, I think your schema is clean, easy to follow, and makes sense (in the limited scope of your scenario). Granted the overarching or \"whole\" schema for something like this would be much larger, but if you kept following this sort of normaliz... | {
"AcceptedAnswerId": "58721",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-01T04:02:59.947",
"Id": "58718",
"Score": "5",
"Tags": [
"game",
"sql",
"sql-server"
],
"Title": "Relational schema and query for multiplayer tabletop game"
} | 58718 |
<p>You can find here a <a href="https://codereview.stackexchange.com/q/58989/29371">Follow-up question</a></p>
<p><strong>Description</strong></p>
<p>A <code>List<UnrelatedObects></code> is returned by a 3rd party webservice, which will then be transformed to a <code>List<ArchiveDefinition></code>. These ... | [] | [
{
"body": "<ul>\n<li><p>You could use the <code>AddRange</code> combined with the <code>Except</code> method inside of Build:</p>\n\n<pre><code>public static List<ArchiveTreeEntry> Build(List<ArchiveDefinition> entries)\n{\n List<ArchiveTreeEntry> rootArchiveTreeEntries = new List<Archiv... | {
"AcceptedAnswerId": "58780",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2014-08-01T08:09:51.807",
"Id": "58727",
"Score": "6",
"Tags": [
"c#",
"design-patterns",
"tree"
],
"Title": "Building tree structure based on flat objects"
} | 58727 |
<p>I am catching exceptions to provide better information for the logs to make debugging easier in production. Does this code follow best practices, since I'm not really handling the error but just logging extra information? I was also considering creating a custom <code>RazorException</code>, and throwing that instead... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-01T10:06:04.597",
"Id": "105534",
"Score": "3",
"body": "Yes this is correct, only you can restrict logging by not saying throw, raise some other exception with inner exception message"
}
] | [
{
"body": "<p>Exceptions have <code>Message</code> property, which you should use, if you want to tell someone what went wrong in human language. You can then use <code>String.Format(\"Razor parse failed: {0}\", ex.Message)</code> for all your exceptions. This will allow you, for example, to throw multiple <cod... | {
"AcceptedAnswerId": "58820",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-01T09:48:23.427",
"Id": "58732",
"Score": "7",
"Tags": [
"c#",
"error-handling"
],
"Title": "Handling exceptions for providing log information while debugging"
} | 58732 |
<p>I have a question to find the <em>N</em> th number in the sequence. </p>
<blockquote>
<pre><code> 1
11
21
1211
111221
312211
13112221
1113213211
</code></pre>
</blockquote>
<p>The next number is obtained by saying out loud the number of digits in the previous number.</p>
<... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-01T10:40:55.383",
"Id": "105540",
"Score": "2",
"body": "Any repeating patterns that you could make use of? Because one thing that strikes me as potentially dangerous is \"Eleven 1\". If something prevents that from happening, do you e... | [
{
"body": "<p>This is one of those times when working backwards helps... but, before we get to that...</p>\n\n<h2>Nit Picks</h2>\n\n<ul>\n<li><p>Unless you have a really good reason, do not use <code>StringBuffer</code>. Use <code>StringBuilder</code> instead. There are two times to use StringBuffer, when you a... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-01T10:32:19.593",
"Id": "58733",
"Score": "11",
"Tags": [
"java",
"interview-questions"
],
"Title": "Finding the next number in sequence"
} | 58733 |
<p>Below is the code for my login page. I haven't really used MySQL (especially OOP) before, so I'd like to know if I'm doing something inherently wrong. The code is working as expected, but I don't trust my knowledge of SQL so much that I'd use this code publicly before asking someone to review it.</p>
<p>So please, ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-01T11:29:56.310",
"Id": "105551",
"Score": "0",
"body": "In production, dont print `$stmt->error` if something fails.."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-01T11:31:10.340",
"Id": "105552",
... | [
{
"body": "<p>Some recommendations:</p>\n\n<ul>\n<li><p>In production, don't print <code>$stmt->error</code> if something fails.</p></li>\n<li><p>Don't print different output depending on if it's wrong password, or username doesnt exists.</p></li>\n<li><p>If you don't use <a href=\"http://en.wikipedia.org/wi... | {
"AcceptedAnswerId": "58779",
"CommentCount": "9",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-01T10:42:04.237",
"Id": "58735",
"Score": "4",
"Tags": [
"php",
"security",
"mysqli",
"authentication",
"error-handling"
],
"Title": "PHP and MySQLi login script - is it s... | 58735 |
<p><img src="https://i.stack.imgur.com/MuVuK.png" alt="enter image description here"></p>
<pre><code> var s = player.getSurrounding();
if (vY > 0) {
if ((s[0] || (s[7] && xLocal < LOCAL_LEFT) || (s[4] && xLocal > LOCAL_RIGHT)) && (yLocal + vY * dt) > LOCAL_RIGHT) {
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-01T11:46:30.917",
"Id": "105559",
"Score": "1",
"body": "Which language is this? Looks like C# to me right now, but it could be ActionScript as well."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-01T11:47... | [
{
"body": "<p>I'll let someone smarter than myself help you with your actual problem. I'm going to talk about naming a little bit. Naming, you see, <em>it's important</em> (and <em>hard</em>). If your variables had more descriptive names, you might not have had to write several paragraphs explaining what they a... | {
"AcceptedAnswerId": "58746",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-01T11:43:49.947",
"Id": "58739",
"Score": "7",
"Tags": [
"javascript",
"game",
"array",
"collision"
],
"Title": "Square grid collision detection"
} | 58739 |
<p>If you have an interface served by a NodeJS API, what is the most clean way to propagate status changes to the interface?</p>
<p>For example, I have a page that has 2 statuses, user logged in and guest. How would you send to the interface that information, without rendering the page server side? Same thing applies... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-01T13:02:15.317",
"Id": "105588",
"Score": "0",
"body": "Doesn't the same thing apply to processes? I have applications working as described and I'm looking for a more clean/\"correct\" way of doing that... Isn't that and the code revi... | [] | {
"AcceptedAnswerId": null,
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-01T11:54:10.643",
"Id": "58741",
"Score": "2",
"Tags": [
"javascript",
"node.js",
"reinventing-the-wheel",
"interface"
],
"Title": "NodeJS, status propagation to interface"
} | 58741 |
<pre><code>public static int min(int a, int b, int c)
{
int result = 0 ;
if( a < b && a < c && b < c) result = a ;
else if( a < b && a < c && b > c) result = a ;
else if( a > b && a < c && b < c) result = b ;
else if( a <... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-01T14:57:40.973",
"Id": "105649",
"Score": "2",
"body": "If if and and and *look* readable to you, try reading the code outloud. In before buffalo buffalo buffalo and james while john."
},
{
"ContentLicense": "CC BY-SA 3.0",
... | [
{
"body": "<p>I'd suggest using ternary operator, which is quite readable for me:</p>\n\n<pre><code>public static int min(int a, int b, int c) {\n return (a < b) ? (a < c) ? a\n : c\n : (b < c) ? b\n : c;\n}\n</code></pre>... | {
"AcceptedAnswerId": "58753",
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-01T12:36:44.770",
"Id": "58747",
"Score": "34",
"Tags": [
"java"
],
"Title": "Find min of 3 numbers hardcoded"
} | 58747 |
<p>I've built an image/content slider using JavaScript and as I've added to it and built in new functionality I've found myself writing several if statements in order to achieve the required response.</p>
<p>I'm now going over it again and I want to refactor it to make it shorter (if possible) and to increase performa... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-03T21:07:33.753",
"Id": "106003",
"Score": "1",
"body": "You have a considerable amount of repeated code in with `this.container.css`"
}
] | [
{
"body": "<p>I wouldn't use switch statements, they are generally slower than if else so what you have here is fine.</p>\n\n<p>You should swap the <code>typeof this.offset != \"undefined\"</code> for the faster <code>this.offset !== undefined</code>. <code>Typeof</code> is only needed if there is a chance the ... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-01T14:41:20.507",
"Id": "58762",
"Score": "1",
"Tags": [
"javascript",
"image"
],
"Title": "Image/content slider"
} | 58762 |
<p>I've used quite a lot of <code>foreach</code> loops to achieve this type of HTML table that has titles in the first cell of each row:</p>
<pre><code> <table>
<thead>
<tr>
<th></th><th><img src='img.jpg'>Product 1</th><th><img src='img.jp... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-01T16:21:54.850",
"Id": "105666",
"Score": "0",
"body": "Are you sure that the html is the result of this code ? I have spottet `$similar_com .= \"</thead></tbody><tr><td>Width</td>\";` especially `</tbody>`"
}
] | [
{
"body": "<ul>\n<li><p>Is it critical that your product be the top row? It seems like you would benefit tremendously if your table was structured like this:</p>\n\n<pre><code><table>\n <thead>\n <tr>\n <th>Product</th>\n <th>Width</th>\n... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-01T16:10:51.610",
"Id": "58764",
"Score": "5",
"Tags": [
"php",
"html"
],
"Title": "Foreach loop to generate HTML table with title in first cell of each row in PHP"
} | 58764 |
<blockquote>
<p>Introduction to the problem </p>
<p>You are free to implement any mechanism for feeding input into your solution. You should provide sufficient evidence with unit tests that your solution is complete. As a minimum, please use the provided test data to indicate that the solution works correctly. A... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-01T16:48:22.643",
"Id": "105669",
"Score": "3",
"body": "Always use {} to prevent future bugs (see your `foreach` statements)"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-01T19:39:55.460",
"Id": "105... | [
{
"body": "<ul>\n<li><p>I don't like the naming of <code>consoleListener()</code>. These should contain verbs; maybe <code>listenOnConsole()</code></p></li>\n<li><p><code>controller()</code> is not only named poorly, it also does too much. This should be split to <code>parseInput()</code> and <code>renderCanvas... | {
"AcceptedAnswerId": "58772",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-01T16:33:27.247",
"Id": "58767",
"Score": "3",
"Tags": [
"php",
"programming-challenge"
],
"Title": "Programming Challenge: Drawing Tool"
} | 58767 |
<p>I wrote a function for checking if a <code>Map[(String, String)]</code> contains an element with a matching key and value:</p>
<pre><code> def findDupes(map: Map[String, String], key: String, value: String):
Option[(String, String)] = {
val dupes = map.collect { case (x, y) if(x == ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-01T17:31:23.180",
"Id": "105677",
"Score": "1",
"body": "Is it just me or I don't see the definition of the values of `map` in your example of use?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-01T17:33:0... | [
{
"body": "<p>Use <code>map get key contains value</code>, to test if a given key-value-pair is already part of a <code>Map</code>.</p>\n\n<p>Your solution is extremely inefficient, because you iterate through the entire <code>Map</code> (with <code>collect</code>) just to find one value. <code>get</code> retur... | {
"AcceptedAnswerId": "58777",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-01T16:37:31.403",
"Id": "58769",
"Score": "1",
"Tags": [
"scala"
],
"Title": "Finding Duplicate (Key, Value) in Map"
} | 58769 |
<p>I've been working on a project to take data from csv files, re-format it, and display it as charts. I'm working for a company over the summer and <em>when I leave, I would like my code to be <strong>readable/editable</strong> by whoever takes over in the future</em>.</p>
<p>This code reads in two files, formats th... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-01T17:43:20.473",
"Id": "105679",
"Score": "0",
"body": "Don't use perl. (just kidding)"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-01T17:46:25.103",
"Id": "105680",
"Score": "0",
"body": "... | [
{
"body": "<p>All in all I can understand it OK, it reads fairly well. There are a few structures I would recommend you change.... for a start, I would separate the category definitions from the counters, as it would be easier to maintain:</p>\n\n<p>Note, I am defining <code>@categories</code> as a simple array... | {
"AcceptedAnswerId": "58782",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-01T17:36:52.480",
"Id": "58774",
"Score": "3",
"Tags": [
"perl",
"csv"
],
"Title": "Creating two output files from two formatted files"
} | 58774 |
<p>Below is the problem:</p>
<blockquote>
<p>Little Timmy is exceptionally good at math tables, so his teacher decided to make things a bit more interesting. His teacher gave him two numbers, A and B, and told him to merge the tables of A and B in order (ascending order), removing the duplicates and thus supertable ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-01T18:59:46.127",
"Id": "105691",
"Score": "0",
"body": "Please edit the problem statement."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-01T19:00:03.187",
"Id": "105692",
"Score": "2",
"body"... | [
{
"body": "<p>The TreeSet is a problem because it has a significant time-complexity (and storage size). Adds to the TreeSet are \\$O(\\log{n})\\$. As the dataset grows, it gets noticeably slower. You can be sure that the test software will do something like: <code>3 11 5000000</code> as input, and that will tak... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-01T18:57:20.357",
"Id": "58785",
"Score": "3",
"Tags": [
"java",
"optimization",
"programming-challenge"
],
"Title": "Calculating the Nth number in the supertable of two numbers"
} | 58785 |
<p>I'm creating a client-side pie chart in XSLT 1.0, without extensions or external dependencies (i.e., cannot use FXSLT, EXSLT, JavaScript, etc.).</p>
<p>The code is slow; at least fifteen iterations are necessary to get the correct precision required for the angles used by the pie chart. (I'm looking for help that d... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-01T19:10:02.783",
"Id": "105696",
"Score": "0",
"body": "If your goal is to create a pie chart, why not post the XSLT and example XML input for that? Perhaps we could reduce the use of sine altogether."
}
] | [
{
"body": "<p>Do not use power and factorial. Notice that</p>\n\n<blockquote>\n <p>$$x - \\frac{x^3}{3!} + \\frac{x^5}{5!} - \\frac{x^7}{7!} + \\ldots = x(1 - \\frac{x^2}{2*3}(1 - \\frac{x^2}{4*5}(1 - \\frac{x^2}{6*7}(1 - \\ldots))) \\ldots) $$</p>\n</blockquote>\n\n<p>Now calculate it backwards from the inner... | {
"AcceptedAnswerId": "58787",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-01T19:02:46.333",
"Id": "58786",
"Score": "2",
"Tags": [
"performance",
"recursion",
"mathematics",
"xslt"
],
"Title": "Calculation of trigonometric sine function"
} | 58786 |
<p>Just started learning how to use the canvas today as I wanted to copy an animated GIF.</p>
<p>The GIF I tried to copy is below.</p>
<p><img src="https://i.stack.imgur.com/QtGYF.gif" alt="Gif"></p>
<p>The animation does work but I've hacked it left and right. There's obviously alot of refactoring to do but am I go... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-02T13:22:35.743",
"Id": "105767",
"Score": "0",
"body": "What is the expected behaviour if maxPercentage is not 100?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-02T13:56:48.650",
"Id": "105773",
... | [
{
"body": "<p>The programme is rather mixed up at the moment although I can't see any obvious 'hacks' as such. You are calling <code>draw</code> and <code>requestAnimationFrame</code> from multiple places, sometimes unnecessarily. I would rewrite it to separate the actual drawing from the underlying logic of th... | {
"AcceptedAnswerId": "58829",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-01T19:19:18.783",
"Id": "58788",
"Score": "6",
"Tags": [
"javascript",
"canvas"
],
"Title": "Canvas animation"
} | 58788 |
<p>I need to create an HTML unordered list (to display with <a href="http://www.jstree.com/" rel="noreferrer" title="jstree">jstree</a>) to display the hierarchy of users, along with a list underneath the user's "subusers" of their comments. Each user could have many users underneath him, and each of those users could ... | [] | [
{
"body": "<p>First of all, you can move the first <code><li></code> out of the first <code>if</code> condition. That allows you to totally get rid of the last <code>else</code>:</p>\n\n<pre><code>html = \"<li id='user-\" + str(user.id) + \"'>\" + user.name\nif len(user.subusers.all()) > 0:\n ... | {
"AcceptedAnswerId": "58795",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-01T19:34:11.213",
"Id": "58791",
"Score": "5",
"Tags": [
"python",
"recursion",
"django"
],
"Title": "Recursive Django filter to output a list from user hierarchy"
} | 58791 |
<p>I have not used Springs stored procedure class before to return data and I was hoping someone would be able to check this for me.. </p>
<p>If it will A. Return data, B. Can be improved. C. If I wanted to return multiple rows how would this need to be changed?</p>
<pre><code>public class AccountAddress extends Stor... | [] | [
{
"body": "<p>Something I noticed:</p>\n\n<pre><code> Map<String,Object> params = new HashMap<~>();\n Map<String,Object> results = new HashMap<~>();\n List<String> data = new LinkedList<~>();\n try{\n params.put(\"accountId\",accountId);\n results = ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-01T21:53:35.643",
"Id": "58797",
"Score": "1",
"Tags": [
"java",
"spring"
],
"Title": "Intended to return account address using account ID, which uses Spring Stored Procedure class"
} | 58797 |
<p>I am trying to build something that will allow us to configure "custom" validation for each customer. So if a customer wants to see a value contain a specific char, be specific length, or equal something else they just add a pre-created option. I wrote something that seems to be very primitive, but works. I would... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-01T22:42:19.413",
"Id": "105727",
"Score": "1",
"body": "First, I think this sounds more appropriate for Programmers. Second, I cannot understand why I would use `Magic.Validate(\"yes\", new Operation() { value = \"yes\", perform = OMa... | [
{
"body": "<p>Well there is multiple solution to this problem , </p>\n\n<ul>\n<li><p>Using delegate: </p>\n\n<pre><code>public bool Validate<T1,T2>(T1 value, T2 compareValue, Func<T1,T2,bool> operation)\n{\n return operation(value, compareValue);\n}\nmagic.Validate(1, 2, (a, b) => a > b);\n... | {
"AcceptedAnswerId": "58823",
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-01T22:11:49.827",
"Id": "58798",
"Score": "1",
"Tags": [
"c#",
"dynamic-programming"
],
"Title": "Making operations more dynamic"
} | 58798 |
<p>I have two functions that are used to prompt and recieve input from the user. One is for <code>int</code> and the other is for <code>boolean</code>. They work somewhat similar to each other, one uses try/catch and the other doesn't. Can they be improved upon or is one better than the other? I'm having trouble with t... | [] | [
{
"body": "<blockquote>\n <p>If the user is non-technical they may not know what an integer is, but\n I can't think of better wording.</p>\n</blockquote>\n\n<p><code>[Positive] Number</code> or <code>[Positive] Whole Number</code> would be alternatives. </p>\n\n<p>Another possibility: <code>Enter a Number bet... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-01T22:22:21.437",
"Id": "58800",
"Score": "3",
"Tags": [
"java",
"io",
"user-interface"
],
"Title": "Making sure user inputs correct type"
} | 58800 |
<p>I'm very new to Python and would like some feedback on my script. I'm fairly clueless to best practices, code correctness etc. so if there's anything at all that looks wrong, isn't 'pythonic' or could be done in a simpler way, I'd love if you could point me in the right direction. </p>
<pre><code>#!/usr/bin/env pyt... | [] | [
{
"body": "<p>You have an error in <code>check_user</code>:</p>\n\n<pre><code>def check_user(...):\n if (...):\n rel = api.user_relationship(...)\n if (...):\n return True\n else:\n return False\n</code></pre>\n\n<p>If the first check passes but the second doesn't, this wil... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-01T23:09:54.473",
"Id": "58804",
"Score": "6",
"Tags": [
"python",
"python-2.x",
"web-scraping",
"instagram"
],
"Title": "Instagram bot script"
} | 58804 |
<p>I finished answering <i>Exercise 3.3.1</i> of <i>How to Design Programs</i> where:</p>
<blockquote>
<p>Exercise 3.3.1. The United States uses the English system of
(length) measurements. The rest of the world uses the metric system.
So, people who travel abroad and companies that trade with foreign
partne... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-02T03:21:24.180",
"Id": "105747",
"Score": "1",
"body": "Instead of using the `print` function, utilize `check-expects` (built into racket) or some other unit testing framework"
}
] | [
{
"body": "<p>I see a few points that seem open to improvement. </p>\n\n<p>First of all, in some cases you document the \"contract\" based on the type of the input and output (\"number -> number\") but in others the unit of measure (\"Miles -> furlongs\").</p>\n\n<p>The units of measure are already documented d... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-01T23:52:57.703",
"Id": "58805",
"Score": "4",
"Tags": [
"converting",
"scheme",
"racket"
],
"Title": "Converting English Measurements to Metric and vice versa"
} | 58805 |
<p>This is my first code. I would really appreciate a critique for it, if anyone can spare the time. </p>
<pre><code>def wedcost(hours):
print " "
try:
hours = int(hours)
except ValueError:
print "Invalid input"
new_hours = raw_input("Please use only numeric characters. ")
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-02T01:07:21.167",
"Id": "105740",
"Score": "2",
"body": "`# only method I could get to work properly` -- Is this code functional?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-02T01:23:24.997",
"Id": ... | [
{
"body": "<p>Well, this code has a few problems:</p>\n\n<ol>\n<li><p>Typing non-numbers twice in a row causes a ValueError.</p></li>\n<li><p>It is not quite <a href=\"http://legacy.python.org/dev/peps/pep-0008/\" rel=\"nofollow\">PEP-8</a> compliant (the official python style guide)</p></li>\n<li><p>No docstri... | {
"AcceptedAnswerId": "58807",
"CommentCount": "7",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-02T01:05:52.980",
"Id": "58806",
"Score": "6",
"Tags": [
"python",
"beginner",
"python-2.x"
],
"Title": "Wedding Photography Cost Calculator"
} | 58806 |
Tool Command Language was invented by John Ousterhout as a way to make it easy to write little languages for configuring EDA tools, but it has grown far beyond those humble beginnings to become a general scripting language with built-in asynchronous I/O and Unicode strings while supporting paradigms such as object-orie... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-02T03:14:59.163",
"Id": "58809",
"Score": "0",
"Tags": null,
"Title": null
} | 58809 |
<p>I am trying to use decorator pattern to decode and encode packet layers in my application. I've supposed my packet has three layers: Header, Level2, Level3. So far I've come up with the following code. For the sake of simplicity, I've supposed that the data of each layer is the first 10 bytes of the input packet. I'... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-03T17:07:38.000",
"Id": "105952",
"Score": "0",
"body": "*\"I've also intentionally ignored memory leak problems.\"* There is really no excuse to do that in C++. Even if you don't have access to smart pointers, you could still wrap you... | [
{
"body": "<p>I don't know about the decorator pattern, but there are things you can improve anyway:</p>\n\n<ul>\n<li><p>Identifiers that begin with an underscore followed by a capital letter are <a href=\"https://stackoverflow.com/a/228797/1364752\">reserved identifiers</a> in C++. Therefore, <code>_DECODER_H_... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-02T06:38:58.570",
"Id": "58816",
"Score": "6",
"Tags": [
"c++",
"design-patterns"
],
"Title": "Decoding and Encoding packet layers using decorator pattern"
} | 58816 |
<p>I'm trying to solve the SPOJ primes problem:</p>
<blockquote>
<p>Peter wants to generate some prime numbers for his cryptosystem. Help
him! Your task is to generate all prime numbers between two given
numbers!</p>
<p><strong>Input</strong></p>
<p>The input begins with the number <code>t</code> of te... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-02T12:25:45.383",
"Id": "105762",
"Score": "0",
"body": "Is it allowed for you to use a pre-computed list of primes? Since it is something that computer can compute, it seems to me that it should rather be generated at run-time."
},
... | [
{
"body": "<p>Your solution is, in fact, conceptually quite clever. There are some style issues, some bugs, and some optimizations...</p>\n<h2>So ... Magic numbers</h2>\n<p>You have the prepared list of primes, and you declare the array as length 3402. Why specify the length when if you leave it blank, the comp... | {
"AcceptedAnswerId": "58825",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-02T08:39:08.977",
"Id": "58818",
"Score": "4",
"Tags": [
"performance",
"beginner",
"c",
"programming-challenge",
"primes"
],
"Title": "List primes within an interval"
} | 58818 |
<p>The code below prints sum from 1 to 10:</p>
<blockquote>
<p>\$1\$<br>
\$1+2 =\$<br>
\$1+2+3 =\$<br>
\$1+2+3+4 =\$<br>
\$......\$<br>
\$1 + ... 10 = 55\$</p>
</blockquote>
<pre><code>public class Solution{
public static void print_sums(){
int sum = 0 ;
for(int i = 1 ; i <= 10 ;... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-02T21:42:30.210",
"Id": "105857",
"Score": "1",
"body": "Clearly it is possible to do without any loops."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-06T10:10:24.780",
"Id": "106627",
"Score": "0... | [
{
"body": "<p>Yes, it is possible.</p>\n\n<pre><code>public static void printSums() {\n int sum = 0;\n for (int i = 1; i <= 10; i++) {\n sum += i;\n System.out.println(sum);\n }\n}\n</code></pre>\n\n<p>The key is simply to calculate the sum of the first \\$N\\$ digits. It is easy if yo... | {
"AcceptedAnswerId": "58831",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-02T14:40:55.973",
"Id": "58830",
"Score": "4",
"Tags": [
"java"
],
"Title": "Printing the sums of numbers from 1 to 10 with only 1 loop"
} | 58830 |
<p>Following is a function that takes a long matrix of states and corresponding values (every row is a state), and collects optimal solutions given those values from an interpolating function (<code>getV()</code>) of a grid that contains the optimal solutions (<code>V</code>). </p>
<p>I'm looking for suggestions to cl... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-02T23:09:43.607",
"Id": "105869",
"Score": "0",
"body": "If you are not sure where is the bottleneck, then you need to profile the code."
}
] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-02T14:55:33.217",
"Id": "58832",
"Score": "2",
"Tags": [
"python",
"performance"
],
"Title": "Collect interpolated values"
} | 58832 |
<p>I have to convert positive numbers, that are less than 1000, to words. A quick search didn't find anything that looked good to my eye, so I came up with the following. While I was at it I expanded the conversion. I am looking for comments, suggestions, or errors I am missing.</p>
<pre><code>Public Class NumberTo... | [] | [
{
"body": "<p>The function name <code>Convert</code> doesn't seem particularly helpful to me. Convert how? From what to what? In fact, we're not converting anything... we're representing the same unconverted value in a different format.</p>\n\n<hr>\n\n<pre><code>Dim wnum As Integer = num 'working number\n</c... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-02T14:56:56.460",
"Id": "58833",
"Score": "10",
"Tags": [
"converting",
"vb.net",
"numbers-to-words"
],
"Title": "Number to Words"
} | 58833 |
<p>This is an answer to <a href="https://stackoverflow.com/questions/25095278/change-position-of-an-exact-number-of-elements-in-an-array">this problem</a>.</p>
<p>Basically, given an array, swap the given number of elements in the array.</p>
<p>The solution that came to my mind: since we always swap at least two elem... | [] | [
{
"body": "<p><em>Always</em> put <code>srand()</code> in <code>main()</code>, not in another function or anywhere else. This is to ensure that it's called only once, which is important so that the seed is not reset. If this happens, then you'll get the same number each time, defeating the purpose of even acq... | {
"AcceptedAnswerId": "58847",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-02T16:18:01.880",
"Id": "58837",
"Score": "4",
"Tags": [
"c",
"array",
"shuffle"
],
"Title": "Shuffling array elements in C"
} | 58837 |
<p>I've tried to create an implementation of a tree for comments. I want use it in Django to store comments. Please tell me how to implement it much simpler, without recursion, to find child nodes.</p>
<pre><code>class commentTree(object):
def __init__(self, id, data, parentId = 0, childrens = None):
"Represents o... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-02T18:45:45.923",
"Id": "105818",
"Score": "0",
"body": "Obligatory suggestion to follow [the style guide](http://legacy.python.org/dev/peps/pep-0008/) (also, please review the indentation)."
}
] | [
{
"body": "<p>A few comments regarding style:</p>\n\n<ul>\n<li><p>As pointed out by @jonrsharpe</p>\n\n<ul>\n<li>Please have a look at <a href=\"http://legacy.python.org/dev/peps/pep-0008/\" rel=\"nofollow\">PEP8</a></li>\n<li>Use for spaces for each indentation level</li>\n</ul></li>\n<li><p>Naming</p>\n\n<ul>... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-02T16:25:23.267",
"Id": "58839",
"Score": "3",
"Tags": [
"python",
"tree",
"python-2.x",
"django"
],
"Title": "Try to implement comments tree for Django"
} | 58839 |
<p>I'm building a small web app primarily for mobile use. I have some widgets that need to handle tap gestures in the expected way, and I don't feel this one feature is reason enough to include JQuery mobile. </p>
<p>I've written the following function for making an element respond to "tap" events:</p>
<pre><code>fun... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-02T16:53:35.797",
"Id": "105799",
"Score": "0",
"body": "have you tried this http://benhowdle.im/touche/"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-02T21:33:10.587",
"Id": "105855",
"Score": "0... | [
{
"body": "<p>For your purposes, you can treat <code>touchleave</code> and <code>touchcancel</code> the same way. The difference is <code>touchleave</code> happens when the touch point leaves the element and moves somewhere else in the document, and <code>touchcancel</code> happens when the touch point leaves t... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-02T16:37:16.060",
"Id": "58840",
"Score": "2",
"Tags": [
"javascript",
"html5",
"event-handling",
"mobile"
],
"Title": "Best way to handle tap gestures"
} | 58840 |
<p>I'm trying to simplify our unit tests with hand written DSL's. So far I have DSL's that walk developers through processing a service after setting up all preconditions and the construction of an <a href="https://stackoverflow.com/questions/22909717/is-this-monster-builder-a-good-builder-factory-pattern-for-abstract... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-06T04:45:10.663",
"Id": "106586",
"Score": "0",
"body": "It feels like you are trying to reinvent Objective C method calls in Java."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-06T06:27:43.203",
"Id"... | [
{
"body": "<p>A few thoughts...</p>\n\n<ol>\n<li><p>It's not at all obvious how the user gets started. <code>new PersonBuilder().blahblahblah()</code>?</p>\n\n<p>A common alternative idiom is to use a public static method as the bootstrap point. <code>PersonBuilder.newInstance()</code>, <code>PersonBuilder.cr... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-02T16:55:21.740",
"Id": "58842",
"Score": "4",
"Tags": [
"java",
"dsl"
],
"Title": "Learning to write DSL utilities for unit tests and am worried about extensibility"
} | 58842 |
<p>I am trying to improve my coding skills. As a result, I solved the T9 Spelling question from the Google Code Jam dashboard. I will appreciate it if anyone could critique the code, and provide illustrations (if possible) of how I could make my code clean and simple. For me, simple is really beautiful.</p>
<p>Google ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-02T19:30:36.773",
"Id": "105835",
"Score": "0",
"body": "As you've now acquired 15 rep on this site, please be sure to upvote any answer you've found helpful. After a while (whatever you choose), you may accept the *most helpful* answ... | [
{
"body": "<p>Use <code>std::array</code> (C++11):</p>\n\n<pre><code>#include <iostream>\n#include <array>\n\nstd::string nums = \"123456789*0#\";\nstd::array<std::string, 12> keys = {\"\" , \"abc\", \"def\",\n \"ghi\" , \"jkl\", \"mno\",\n ... | {
"AcceptedAnswerId": "58857",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-02T18:33:03.377",
"Id": "58848",
"Score": "12",
"Tags": [
"c++",
"programming-challenge"
],
"Title": "Google Code Jam - T9 Spelling with C++"
} | 58848 |
<p>Following is the main file in the project (executing tasks). It uses the <code>mpi4py</code> module, and multiple processes execute the same code. Please review the code and post your suggestions on making it more efficient and pythonic.</p>
<pre><code>from mpi4py import MPI
from Peers import Peers
from SegmentHand... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-02T19:18:23.733",
"Id": "105833",
"Score": "1",
"body": "Obligatory suggestion to follow [the style guide](http://legacy.python.org/dev/peps/pep-0008/) (also, please review the indentation)."
}
] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-02T18:51:18.837",
"Id": "58851",
"Score": "2",
"Tags": [
"python",
"python-2.x",
"mpi"
],
"Title": "Microcast algorithm"
} | 58851 |
<p>I am writing a C++AMP library, and as one of my utility methods I am implementing a parallel reduction algorithm based on the cascade method documented on <a href="https://docs.microsoft.com/en-us/archive/blogs/nativeconcurrency/parallel-reduction-using-c-amp" rel="nofollow noreferrer">this blog post</a> with slight... | [] | [
{
"body": "<p>I only see some possible stylistic/reusability improvements:</p>\n\n<ul>\n<li><p>You use <code>decltype(std::declval<T>() + std::declval<T>())</code> five times in the function (plus the one in the return type). You could probably <code>typedef</code> that to improve readability. I don... | {
"AcceptedAnswerId": "58926",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2014-08-02T19:33:47.627",
"Id": "58858",
"Score": "4",
"Tags": [
"c++",
"c++11",
"concurrency",
"amp"
],
"Title": "Parallel Reduction method with C++AMP"
} | 58858 |
<p>To understand the basic workings of PHP I wrote a test page where one can create, load and edit entries (name-info-pairs) in a list.</p>
<p>It would be cool if you could give me some advice on that to improve.</p>
<pre><code><?php
class User {
public $name;
public $info;
Public function __construct($name,... | [] | [
{
"body": "<p>First of all, welcome to the world of PHP. It seems you are on the right track. I have a few pointers I can give you though:</p>\n\n<ul>\n<li><p>I don't know if you pasted this all together for the question, but all that code should not be in a single file. While it is fine for this 'test' page, i... | {
"AcceptedAnswerId": "58868",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-02T21:09:01.503",
"Id": "58860",
"Score": "3",
"Tags": [
"php",
"html"
],
"Title": "Basic form to create, load and edit entries (server-sided stored in a text file)"
} | 58860 |
<p>For now, I have two views using Twig:</p>
<ul>
<li>messages.html.twig</li>
<li>item.html.twig</li>
</ul>
<p>The first one is the view which displays all of the users' posts in my forum. When a user post a new message, it's done via Ajax so the server returns a view with the posts information. That view is item.htm... | [] | [
{
"body": "<p>I would strongly recommend you to go for the <code>include</code> solution. You will probably take a small performance hit, but that should not outweigh the benefits of having code that is much easier to maintain. Whenever you have to duplicate code, you are doing something wrong.</p>\n\n<p>Also, ... | {
"AcceptedAnswerId": "58866",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-02T22:03:24.627",
"Id": "58862",
"Score": "1",
"Tags": [
"php",
"html",
"twig"
],
"Title": "Should I include a view for each message?"
} | 58862 |
<p>I have a prime-finding class here that needs improvement.</p>
<p>Sample result:</p>
<blockquote>
<pre class="lang-none prettyprint-override"><code>Number of primes?
10
2 3 5 7 11 13 17 19 23 29
Total calculation time: 6 milliseconds
Calculation time per number: 0.6 milliseconds
</code></pre>
</blockquote>
<... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-04T12:21:27.520",
"Id": "106114",
"Score": "0",
"body": "This post [was mentioned on meta](http://meta.codereview.stackexchange.com/q/2206/41243)."
}
] | [
{
"body": "<blockquote>\n <p>Is there a better way of doing this? If so, how?</p>\n</blockquote>\n\n<p>Yes, there is. Your current algorithm is \\$O \\left( n + \\left( n \\times \\dfrac{n}{2} \\right) + \\left( \\dfrac{n}{2} \\right) \\right) \\$, or \\$ O(n^{2}) \\$. (The first \\$n\\$ is the iterating of th... | {
"AcceptedAnswerId": "58874",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-02T22:08:18.620",
"Id": "58864",
"Score": "8",
"Tags": [
"java",
"primes"
],
"Title": "Finding Primes in Java"
} | 58864 |
<p>The code below is used to check if there are tags or categories in the database. If they exist, they are not added to the database, otherwise they are added.</p>
<p>Is this code efficient and easy to read?</p>
<pre><code>private void CreateTagCategoryBlog(string Tags, string category)
{
int lastInserte... | [] | [
{
"body": "<ul>\n<li><a href=\"http://msdn.microsoft.com/en-us/library/vstudio/ms229043(v=vs.100).aspx\" rel=\"nofollow\">Parameters should be camelCased</a>, so <code>Tags</code> should be <code>tags</code>. As far as I can tell though only one tag is passed in, so it should be the singular <code>tag</code>. <... | {
"AcceptedAnswerId": "58892",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-02T22:16:23.743",
"Id": "58865",
"Score": "1",
"Tags": [
"c#",
"linq",
"entity-framework"
],
"Title": "Checking if there are tags or categories in the database"
} | 58865 |
<p>I have class <code>House</code> and module <code>Lockable</code>. Locking and unlocking <code>House</code> should reflect the real world, so you can't lock twice.</p>
<p>Do you think this is a good approach to using a module and raising an exception?</p>
<pre><code>module Lockable
attr_reader :locked
def loc... | [] | [
{
"body": "<p>I would define domain specific error classes like so:</p>\n\n<pre><code>module Lockable\n Error = Class.new StandardError\n AlreadyLocked = Class.new Error\n AlreadyUnlocked = Class.new Error\n\n def lock!\n raise AlreadyLocked if locked?\n @locked = true\n end\n\n def unlo... | {
"AcceptedAnswerId": "58870",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-02T09:46:16.640",
"Id": "58869",
"Score": "3",
"Tags": [
"ruby",
"locking",
"exception"
],
"Title": "Good approach to raise an exception"
} | 58869 |
<p>I have this obsession with esoteric programming languages. So I decided to spiff up my <a href="https://codereview.stackexchange.com/questions/58071/basic-brainfuck-interpreter">previous Brainfuck interpreter</a>. </p>
<pre><code># Simple BrainF*** interpreter
# Class that stores lang variables
class Lang(object):... | [] | [
{
"body": "<p>In a word: <strong>dictionaries</strong>. </p>\n\n<p>You have a class that only has class attributes and lacks any methods; that could just be a dictionary:</p>\n\n<pre><code>lang = dict(\n step = 0,\n cell = [0] * 30000,\n test_cell = [0] * 30000,\n pos = 0,\n test_pos = 0,\n lo... | {
"AcceptedAnswerId": "58896",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-03T00:20:38.900",
"Id": "58873",
"Score": "4",
"Tags": [
"python",
"python-2.x",
"interpreter",
"brainfuck"
],
"Title": "Basic Brainfuck interpreter (part 2)"
} | 58873 |
Twig is a modern, fast, flexible, and secure templating engine for PHP. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-03T00:56:37.207",
"Id": "58876",
"Score": "0",
"Tags": null,
"Title": null
} | 58876 |
<p>This code was inspired by this question: <a href="https://codereview.stackexchange.com/questions/58833/number-to-words"><strong>Number to Words</strong></a></p>
<pre><code>import Foundation
extension Int {
func plainEnglish (negativeSign: String = "negative") -> String {
func singleNumberName (numbe... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-03T11:21:01.653",
"Id": "105910",
"Score": "0",
"body": "I think you've forgotten to use the `negativeSign` argument for anything. Near the bottom of the function (`let initial = …`), you just have a hard-coded `\"negative\"`. (By the ... | [
{
"body": "<p>Seems fine to me. Here's some thoughts:</p>\n\n<ul>\n<li>You will need to put some sort of limit on the int, or provide all the words (thousand, million, billion, etc) up to the int's natural limit. Or return \"A really big number greater than a quadrillion\" or something like that if there's no l... | {
"AcceptedAnswerId": "59548",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-03T01:26:06.930",
"Id": "58878",
"Score": "15",
"Tags": [
"strings",
"swift",
"extension-methods",
"rags-to-riches",
"numbers-to-words"
],
"Title": "Int extension for tran... | 58878 |
<p>Following along with some previous questions:</p>
<ul>
<li>The @dbasnett original here: <a href="https://codereview.stackexchange.com/questions/58833/number-to-words"><strong>Number to Words</strong></a></li>
<li>@nhgrif's here: <a href="https://codereview.stackexchange.com/questions/58878/int-extension-for-transla... | [] | [
{
"body": "<p>I would define <code>DECADES[0]</code> as \"\" instead of \"zero\" so that the <code>if (tens>0)</code> can be removed. Notice that <code>DECADES[0]</code> was never used and its value \"zero\" was a repetition with respect to <code>SUBTWENTY[0]</code>.</p>\n\n<p>Also there is a repetition in t... | {
"AcceptedAnswerId": "58887",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-03T04:33:07.713",
"Id": "58884",
"Score": "8",
"Tags": [
"java",
"strings",
"converting",
"rags-to-riches",
"numbers-to-words"
],
"Title": "Converting a number to the text... | 58884 |
<p>I am trying to compare the <code>RemoveAt()</code> function performance in an array and linked list.</p>
<p><strong>For array:</strong></p>
<pre><code>public T RemoveAt(int index)
{
if (index >= this.count || index < 0)
{
throw new ArgumentOutOfRangeException(
"Invalid index: " + ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-03T13:44:41.600",
"Id": "105926",
"Score": "5",
"body": "This question appears to be off-topic because it is not about reviewing and improving code, it's about analyzing a specific aspect of it."
}
] | [
{
"body": "<p>If you time just removing the item from the list, it probably will be faster.</p>\n\n<p>What you're timing is <em>traversing</em> the list to the correct point, <em>then</em> removing the item. Apparently, traversing the list is slow enough to (more than) make up for the time you're saving on the ... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-03T05:47:43.327",
"Id": "58886",
"Score": "0",
"Tags": [
"c#",
"performance",
"array",
"linked-list"
],
"Title": "Linked list vs array performance for RemoveAt() function"
} | 58886 |
<p>I have a function: </p>
<pre><code>Private Function getbyte(s As String, ByVal place As Integer) As String
If place < Len(s) Then
place = place + 1
getbyte = Mid(s, place, 1)
Else
getbyte = ""
End If
End Function
</code></pre>
<p>For extracting a character at a particular place in a string, how can I shorten th... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-03T08:16:58.967",
"Id": "105898",
"Score": "2",
"body": "Welcome to Code Review! Please place the appropriate language tag on your question."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-03T11:38:05.567",... | [
{
"body": "<p>According to <a href=\"http://msdn.microsoft.com/en-us/library/ms234766.aspx\" rel=\"nofollow noreferrer\">MSDN</a>, this function is already implemented:</p>\n\n\n\n<pre><code>' Code from MSDN\n'\nDim myString As String = \"ABCDE\" \nDim myChar As Char \n' The value of myChar is \"D\".\nmyChar = ... | {
"AcceptedAnswerId": "58909",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-03T08:03:29.103",
"Id": "58895",
"Score": "4",
"Tags": [
"strings",
"vb.net",
"vba",
"vb6"
],
"Title": "Extract a character at particular place in a string"
} | 58895 |
<p>I'm quite new to Python and have been experimenting. So far I have made a simple hangman type game which creates a random word and the user then guesses it. I'd like to know if I've committed any bad practices so I can learn early on what to and not-to do.</p>
<pre><code>#Word Game Python
from random import randint... | [] | [
{
"body": "<p>The first thing that strikes me with your code are the comments: there are way too many comments. There are especially too many comments considering that your code rather well <a href=\"http://en.wikipedia.org/wiki/Self-documenting\" rel=\"nofollow\">self-documented</a>. For example, you could rem... | {
"AcceptedAnswerId": "58902",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-03T09:28:05.110",
"Id": "58899",
"Score": "5",
"Tags": [
"python",
"beginner",
"game",
"console",
"hangman"
],
"Title": "Python Hangman Console"
} | 58899 |
<p>I've created a PDO wrapper. I understand PDO could be used on it's own, and I'm reinventing the wheel as there are solutions like Laravel's Eloquent that would do a better job.</p>
<p>I'd like advice on best practices used here, which would be much appreciated. The idea is to have a central Database class and separ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-04T15:35:00.377",
"Id": "106171",
"Score": "1",
"body": "What you call \"PDO Wrapper\" is called Query Builder, therefore PDO is just a dependency here, but not an extension"
},
{
"ContentLicense": "CC BY-SA 3.0",
"Creation... | [
{
"body": "<p><em>Standard disclaimer:</em><br>\nI realize that some of the things I write here can come across as offensive. You should know that, IMHO, that's what code review has to be. It needs to be harsh, and blunt. Just keep in mind that I'm not trying to put you down. My only goal is to provide helpful,... | {
"AcceptedAnswerId": "59008",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-03T12:37:46.123",
"Id": "58911",
"Score": "4",
"Tags": [
"php",
"mysql",
"php5",
"pdo",
"reinventing-the-wheel"
],
"Title": "Extendable PDO Wrapper Class"
} | 58911 |
<p>I am making a Python program that does math and physics calculations for you. This is my first programming project and is a work in progress. The SymPy library was used for some portion of it.</p>
<pre><code>import math
import turtle
import webbrowser
from sympy import *
Planck_constant = 6.626176 * (10 ** -34)
Re... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-03T14:48:26.630",
"Id": "105934",
"Score": "0",
"body": "What exactly *are* you using `sympy` for? Also, consider adding input validation - see e.g. [here](http://stackoverflow.com/a/23294659/3001761)."
},
{
"ContentLicense": "... | [
{
"body": "<p>There are a few things that stick out to me Omer:</p>\n\n<p>You should learn the more advanced usage of the <code>print</code> statement (and potentially begin using the <code>print</code> function instead). In may places you have the value of a computation stored in a variable, e.g., <code>var</c... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-03T13:04:24.933",
"Id": "58912",
"Score": "6",
"Tags": [
"python",
"mathematics",
"physics",
"turtle-graphics",
"sympy"
],
"Title": "Math, Geometry, & Physics Library"
} | 58912 |
<p>Is this a better way to validate a text box for mobile number only?</p>
<p>Validation:</p>
<ul>
<li>allow only numbers</li>
<li>will not allow to paste string including characters</li>
<li>allow copy from the box</li>
<li>length is set to 10 without country code</li>
<li>allow back space</li>
</ul>
<p>Suggest som... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-03T15:54:48.677",
"Id": "105937",
"Score": "3",
"body": "Please indent your code as I already told you in [another review](http://codereview.stackexchange.com/a/58909/12691). It's even unreadable for a review!"
},
{
"ContentLic... | [
{
"body": "<p><a href=\"https://codereview.stackexchange.com/a/58910/41243\">Again, properly indent the code.</a> The code was unreadable to the point that we broke our own rules and edited the code in question <em>just to be able to review it</em>.</p>\n\n<p>Other than that, the biggest issue with this is all ... | {
"AcceptedAnswerId": "58927",
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-03T15:46:06.327",
"Id": "58921",
"Score": "1",
"Tags": [
"vb.net",
"validation"
],
"Title": "Is this a better way to validate a text box for mobile number only?"
} | 58921 |
<p>Since XSLT 1.0 doesn't have a lot of convenience functions, I have had to cobble them myself. The below capitalizes "words" in a string as defined by a string of delimiters. Is there any way to improve it?</p>
<pre><code><?xml version="1.0"?>
<xsl:stylesheet xmlns:xsl="http://www.w3.org/1999/XSL/Transform"... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-03T16:25:32.550",
"Id": "105943",
"Score": "0",
"body": "Are you using c# or vb.net?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-03T16:28:03.353",
"Id": "105944",
"Score": "0",
"body": "I'm ... | [] | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-03T16:03:18.070",
"Id": "58922",
"Score": "2",
"Tags": [
"strings",
"xslt"
],
"Title": "Capitalize words in XSLT 1.0"
} | 58922 |
<h2>Problem Description</h2>
<blockquote>
<p>A profiler is a tool which provides information about run-time
performance of an application. Lets say. you are given output file
format of a profiler called Jensor. Jensor captures response times of
methods executed by capturing method entry and exit events. The en... | [] | [
{
"body": "<h3>Unit testing</h3>\n\n<p>It's good to convert that <code>main</code> method to make your implementation testable:</p>\n\n<pre><code>public static String perform(Scanner sc) {\n try {\n String logFileName = sc.nextLine();\n int functionNumber = sc.nextInt();\n\n return new J... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-03T16:30:24.290",
"Id": "58923",
"Score": "5",
"Tags": [
"java",
"programming-challenge"
],
"Title": "Log file processor - Programming Contest"
} | 58923 |
<p>This method takes a text file of my work schedule and parses it. It works, but is kind of kludgey, and I'm looking for feedback and suggestions. My first attempt at a file parser, and my first look at Python (I have dabbled in Java/Android and JavaScript). I'm hoping that between the pseudocode and the comments i... | [] | [
{
"body": "<p>As a recommendation for readability i suggest you replace</p>\n\n<pre><code>if len(tempList) > 0:\n</code></pre>\n\n<p>with</p>\n\n<pre><code>if tempList:\n</code></pre>\n\n<p>as the Empty List resolves to False.</p>\n\n<p>It's also recommended to use the \"<strong><em>with statement</em></stro... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-03T16:46:43.443",
"Id": "58924",
"Score": "4",
"Tags": [
"python",
"beginner",
"parsing",
"python-2.x",
"file"
],
"Title": "Parse text file function"
} | 58924 |
<p>I've written up some generic code for a card-game and would like to hear any and all suggestions for how to improve this code further, in any way shape or form.</p>
<p>The code is on <a href="https://github.com/mleyfman/abstract-card-game" rel="nofollow">github</a> or pasted directly below:</p>
<h2>Card class:</h2... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-03T16:53:41.230",
"Id": "105948",
"Score": "0",
"body": "This looks interesting. Any simple example you could implement with this to show how the different pieces fit together?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"Creat... | [
{
"body": "<p>In your <code>AbstractDeck</code> class, you:</p>\n\n<pre><code>from random import *\n</code></pre>\n\n<p>This is unwise - it pollutes the namespace with many names you aren't using, and makes it harder to tell where the one you are using came from. In this case, you only want one name from <code>... | {
"AcceptedAnswerId": "58933",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-03T16:47:51.043",
"Id": "58925",
"Score": "6",
"Tags": [
"python",
"python-3.x",
"playing-cards"
],
"Title": "Abstract card game code in Python3"
} | 58925 |
AMP is an RPC protocol for sending multiple asynchronous request/response pairs over the same connection. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-03T17:49:58.667",
"Id": "58931",
"Score": "0",
"Tags": null,
"Title": null
} | 58931 |
<p>I am dealing with the following problem:</p>
<blockquote>
<p>Write a method for the <code>Queue</code> class in the queue.java program (Listing 4.4) that displays the contents of the queue. Note that this does not mean simply displaying the contents of the underlying array. You should show the queue contents fr... | [] | [
{
"body": "<p>The <code>!isEmpty()</code> check is duplicated. You can simplify the conditions a bit if you move the <code>isEmpty()</code> check before the others:</p>\n\n<pre><code>public void display() {\n System.out.println(\"First Inserted Item to Last Inserted Item\");\n\n if (isEmpty()) {\n ... | {
"AcceptedAnswerId": "58938",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-03T18:28:07.660",
"Id": "58934",
"Score": "3",
"Tags": [
"java",
"queue",
"circular-list"
],
"Title": "Displaying items in a circular queue"
} | 58934 |
<p>The following three source files is to define and test a class <code>StackLayer</code>.</p>
<p>While it was written in a need for scalable layer-based architecture design, it was also a practice for <code>std::shared_ptr</code> (I'm new to C++11).</p>
<p>I'm not sure if I'm understanding the concept and best pract... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-03T19:23:45.083",
"Id": "105967",
"Score": "2",
"body": "Just a quick comment; you have declared your Singleton copy and copy-assignment operators as private and not implemented them to prevent copying; but the C++11 way to do this wou... | [
{
"body": "<p>Some minor things:</p>\n\n<ul>\n<li><p>Include guard names don't need an <code>_INCLUDE_GUARD</code> at the end. They should not be confused with macros anyway, although you won't have very many of them in C++.</p></li>\n<li><p>Consider organizing your library <code>#include</code>s, such as alph... | {
"AcceptedAnswerId": "58942",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-03T18:44:09.513",
"Id": "58936",
"Score": "7",
"Tags": [
"c++",
"c++11",
"inheritance",
"stack",
"smart-pointers"
],
"Title": "Layer Stack class to practice std::shared_pt... | 58936 |
<p>I am building my first application based on the OOP model. The application basically responsible for sending XML Soap requests. Model contains couple classes - Server.cs which contain servers IPs, Query.cs for XML soap texts, Message.cs which will contain list of queries put to specific message to be send, and Send... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-03T20:22:36.757",
"Id": "105988",
"Score": "0",
"body": "I looked into second version, if server is part of the message why message instance is passed into server instance? I dont see any usage over there"
},
{
"ContentLicense"... | [
{
"body": "<pre><code>Utilities<Query>.AddToList(Query1);\nUtilities<Query>.AddToList(Query2);\nUtilities<Query>.RevertList();\n\nUtilities<Query>.RemoveFromList(Query1);\n</code></pre>\n\n<p>Please, don't do this. Why have a global list of queries that can be accessed from anywhere? <a ... | {
"AcceptedAnswerId": null,
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-03T18:54:04.650",
"Id": "58937",
"Score": "4",
"Tags": [
"c#",
"object-oriented"
],
"Title": "Program structure to be checked according to OOP"
} | 58937 |
<p>This seems like a popular topic lately, so I took a crack at it.</p>
<p>Related questions are <a href="https://codereview.stackexchange.com/questions/58833/number-to-words">Number to Words</a> and <a href="https://codereview.stackexchange.com/questions/58884/converting-a-number-to-the-text-representation">Convertin... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-03T19:28:53.117",
"Id": "105971",
"Score": "0",
"body": "Minor bug: `nameTripletTail` doesn't account for a trailing zero so `nameNumber(\"20\")` returns `\"twenty-\"`."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate"... | [
{
"body": "<p>Interesting question, impressive code.</p>\n\n<p>I only found one thing that could be considered a bug:\n<code>nameNumber('15.000')</code> will return <em>\"one hundred fiftyundefined thousand\"</em>, this could be fixed by changing your regex to </p>\n\n<pre><code>if (!number.match(/^(-?)... | {
"AcceptedAnswerId": null,
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-03T18:58:39.120",
"Id": "58939",
"Score": "13",
"Tags": [
"javascript",
"strings",
"converting",
"numbers-to-words"
],
"Title": "Naming numbers in American English"
} | 58939 |
<p>I have this method that is working perfectly fine, but it's very slow, and sometimes I have to wait 15 minutes to get a good result, which is ok. I'm wondering if I can make it faster.</p>
<p>Basically I'm running best fleet simulations, and I pre-calculate the possible ship combinations for specific voyages, but ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-03T19:54:19.790",
"Id": "105981",
"Score": "0",
"body": "How do you compute `Ship.Rate`? Is `Variance` computed on the rate?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-03T19:58:08.720",
"Id": "1059... | [
{
"body": "<p>I have implemented some code to compare two ships. By doing this, you will avoid using that long statement of filtering of data. There was also a condition which was wrong.</p>\n\n<p>I am still not sure why you need the explicit three loops (you know your requirements better).</p>\n\n<pre><code>... | {
"AcceptedAnswerId": null,
"CommentCount": "9",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-03T19:14:42.067",
"Id": "58940",
"Score": "6",
"Tags": [
"c#",
"algorithm",
"combinatorics"
],
"Title": "How can I optimize this combination method?"
} | 58940 |
<p>So I needed very basic state management and notification for a small game-like thing I'm building. I decided to implement something like a finite state machine (but not quite, it doesn't transition upon <em>events</em>, but instead is told to transition). This is mostly used for changing visual behavior and animatio... | [] | [
{
"body": "<p>I can't find a semicolon anywhere in your code. Sure, it'll work without them, but it's still a bad habit. Sooner or later, you'll write some lines of code that <em>do</em> require semicolons to parse correctly, or you'll feed the script to a minifier that just removes whitespace, and all of sudde... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-03T19:21:00.133",
"Id": "58943",
"Score": "3",
"Tags": [
"javascript",
"classes",
"state-machine",
"state"
],
"Title": "Simple Javascript state management class"
} | 58943 |
<p>I have a problem where you have a bunch of probabilities associated with a number.</p>
<p>In this case:</p>
<ul>
<li>any number between 0 - 0.3 should return 0,</li>
<li>any number between 0.3 - 0.7 should return 1,</li>
<li>any number between 0.7 - 1.0 should return 2</li>
</ul>
<p>Is there a better way I can ac... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-03T19:36:44.907",
"Id": "105975",
"Score": "0",
"body": "I would advise inverting your probabilities and having a random number generator that picks between 0, 1, 2 with weights of 3, 4, 3 respectively. The random module has a small ex... | [
{
"body": "<p>What you are basically asking is for a way to generate values with different weights.</p>\n\n<p>In this case, you want 0 to be generated 30% of the time, 1 to be generated 40% of the time and 2 to be generated 30% of the time. Rather than checking intervals, it is much easier to generate a sequenc... | {
"AcceptedAnswerId": "59173",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-03T19:24:39.303",
"Id": "58945",
"Score": "5",
"Tags": [
"python",
"algorithm",
"random"
],
"Title": "Checking if a random number exist within an interval efficiently"
} | 58945 |
<p>I don't understand the concept of autoloaders, other than the bare minimum, which is that to load a class file when the class is being called. Or as the PHP manual cites it, to avoid having to <code>require</code> multiple time. </p>
<p>I get that, but what I don't understand is the complexity behind almost all the... | [] | [
{
"body": "<p><strong>Comments on your code</strong></p>\n\n<ul>\n<li><p>The access modifier for your constructor is missing.</p>\n\n<pre><code>function __construct...\npublic function __construct\n</code></pre>\n\n<p>Although no specified access modifier on methods means that PHP chooses <em>public</em> automa... | {
"AcceptedAnswerId": "58951",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-03T20:05:39.317",
"Id": "58948",
"Score": "1",
"Tags": [
"php",
"object-oriented"
],
"Title": "How can this autoloader be improved?"
} | 58948 |
<p>I have this working function <code>circuitFind</code> that I really don't find nice because I feel there is a better and simpler way to accomplish what it does. </p>
<pre><code>circuitFind :: Circuit -> Tile -> Maybe Position
circuitFind c t = unpack . find (\ p -> fst p /= Nothing) . enumerate . map findT... | [] | [
{
"body": "<p>Disclaimer: I'm rusty with Haskell, there may be a cleaner way to do this.</p>\n\n<p>Code review: your code looks fine to my eyes, it's just that <code>circuitFind</code> is overly complex, as you suspected. Also note that <code>findIndex (==t)</code> can be written as <code>elemIndex t</code> (<a... | {
"AcceptedAnswerId": "58971",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-03T20:46:46.587",
"Id": "58954",
"Score": "5",
"Tags": [
"haskell"
],
"Title": "Getting the index (x,y) of a char in a \"2D\" list in Haskell"
} | 58954 |
<p>I thought of this algorithm today. It seems fast, but how can I know?</p>
<pre><code>#include <string.h>
#include <stdlib.h>
#include <stdio.h>
#include <assert.h>
/*
* Reverse a string
* the caller has to free dynamic memory allocated
*/
char *mon_string_rev(char *string)
{
char *ou... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-05T13:00:50.607",
"Id": "106341",
"Score": "0",
"body": "To compare the real time your algorithm/program needs in execution, call it with time (on linux machines), like this:\n\n `time ./myprogram \"my irreversed string.\"\n ti... | [
{
"body": "<p>Over all, this is good, but there's unfortunately some very major performance problems, and I have a few minor design suggestions.</p>\n\n<hr>\n\n<p>A string can be reversed quite trivially in linear time. Your algorithm is quadratic.</p>\n\n<p>You can just do a single backwards loop over the inpu... | {
"AcceptedAnswerId": "58961",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-03T21:30:10.393",
"Id": "58959",
"Score": "12",
"Tags": [
"performance",
"algorithm",
"c",
"strings"
],
"Title": "Is this a fast implementation of reversing a string?"
} | 58959 |
<p>I'm interested in seeing different ways the proc can be expressed inside a method that takes args.</p>
<p>This method is meant to be a sort of FizzBuzz that will dynamically replace "Fizz" or "Buzz" as well as the traditional divisors 3 & 5.</p>
<pre><code>def fizz_buzz_custom(string_1="Fizz", string_2="Buzz",... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-03T23:58:09.593",
"Id": "106044",
"Score": "0",
"body": "Have you searched Code Review (and SO) for \"Ruby Fizzbuzz\"? One gets umpteen hits."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-04T00:51:04.547... | [
{
"body": "<p>To answer your question directly, you can express a proc/block/lambda as</p>\n\n<pre><code>Proc.new do |...|\n# or\nlambda do |...|\n# or\n-> (...) do\n</code></pre>\n\n<p>Either syntax (and your current one) should work fine for this. To invoke the block, you can use square brackets like now, ... | {
"AcceptedAnswerId": "58972",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-03T22:22:05.360",
"Id": "58963",
"Score": "1",
"Tags": [
"ruby",
"fizzbuzz"
],
"Title": "Ways to express proc inside a method"
} | 58963 |
<p>I'm writing a method to throttle duplicate requests taking place within multiple <code>HttpModule</code> instances within a web application.</p>
<p>Currently, I have the following setup:</p>
<pre><code>// Container for semaphores
private static readonly ConcurrentDictionary<string, SemaphoreSlim>
SemaphoreS... | [] | [
{
"body": "<p>Semaphore has a bigger overhead than a traditional lock pattern, aside being too complex for what you need. You could use a class such as this: </p>\n\n<pre><code>public class DeDuper : IDisposable\n{\n private static readonly ConcurrentDictionary<String, Object> currentRequests = new Con... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-03T22:34:47.167",
"Id": "58964",
"Score": "3",
"Tags": [
"c#",
"asp.net",
"asynchronous",
"async-await"
],
"Title": "Throttling duplicate requests in an HttpModule"
} | 58964 |
<p>As a sequel from my previous question, I decided to solve the next problem statement from the GCJ dash board. Any thorough critique, this time, with much attention to skill and technicalities would be much appreciated.</p>
<p>I have few questions:</p>
<ol>
<li><p>According to the problem statement, the number of ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-04T04:40:44.360",
"Id": "106054",
"Score": "0",
"body": "You could ask about the segmentation fault on Stack Overflow. We cannot address that here."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-04T19:00:... | [
{
"body": "<ul>\n<li><p>You report errors if any of the files fails to open, but continue execution anyway. If either of them fails to open, you should also return <code>EXIT_FAILURE</code>. In addition, you should be writing the errors to <code>cerr</code> instead of <code>cout</code>.</p>\n\n<p>On those sam... | {
"AcceptedAnswerId": "58980",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-04T04:34:51.467",
"Id": "58977",
"Score": "5",
"Tags": [
"c++",
"programming-challenge"
],
"Title": "Google Code Jam - reverse words"
} | 58977 |
<p>I don't use Ruby on a regular basis, but I felt inspired to write an extensible, object-oriented version of FizzBuzz to sharpen my skills. I welcome all feedback.</p>
<p>The main class:</p>
<pre><code>class FizzBuzzer
def initialize(*tests)
@tests = tests
end
def run(values)
result = []
values.e... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-04T05:27:41.347",
"Id": "106058",
"Score": "1",
"body": "I like your idea of passing test classes into the constructor for FizzBuzzer. I recommend having ModuloTester and SquareRootTester inherit from one class, and using [`Enumerable`... | [
{
"body": "<p>I'd like to suggest two changes to your interface.</p>\n\n<ul>\n<li><strong>Implement <code>Enumerable</code>.</strong> Your object accepts an <code>Enumerable</code>; it would be nice if it also acted as an <code>Enumerable</code>. All you have to do is <code>include Enumerable</code> and renam... | {
"AcceptedAnswerId": "58986",
"CommentCount": "8",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-04T05:12:23.510",
"Id": "58981",
"Score": "10",
"Tags": [
"object-oriented",
"ruby",
"fizzbuzz"
],
"Title": "Object-Oriented FizzBuzz in Ruby"
} | 58981 |
<p>How could I take this code and optimize it so that I could possibly run Conway's Game of Life on a large grid at 15 frames per second?</p>
<pre><code>public partial class MainWindow : Window
{
Cell[,] activeCells;
//List<Cell> nextGenCells;
static Timer time;
bool onOff = true;
int columnNum = 10;
int rowN... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-04T06:01:26.267",
"Id": "106061",
"Score": "1",
"body": "Could you post the code for your `Cell` class?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-04T06:06:55.863",
"Id": "106064",
"Score": "0"... | [
{
"body": "<pre><code> if (rand.Next(0, 3) == 1)\n {\n activeCells[i, j].IsAlive = true;\n }\n else\n {\n activeCells[i, j].IsAlive = false;\n }\n</code></pre>\n\n<p>I'd assign the variable like <code>activeCells[i, j].IsAlive = (rand.Next(0, 3) ==... | {
"AcceptedAnswerId": "58992",
"CommentCount": "7",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-08-04T05:21:20.617",
"Id": "58982",
"Score": "3",
"Tags": [
"c#",
"performance",
"game-of-life"
],
"Title": "Optimizing Conway's Game of Life code to run faster"
} | 58982 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.