body stringlengths 25 86.7k | comments list | answers list | meta_data dict | question_id stringlengths 1 6 |
|---|---|---|---|---|
<p>I've been running through <em>The Little Schemer</em>, and have hit the example of Peano multiplication. The solution is given in TLS (reproduced below) -- however what interests me is the order of the algorithm. </p>
<pre><code>(define mX
(lambda (n m)
(cond
((zero? m) 0)
(else
(+ n (mX ... | [] | [
{
"body": "<p>Let's look at a simpler problem first: counting the length of a list. Here's the recursive way to do it:</p>\n\n<pre><code>(define (length lst)\n (if (null? lst)\n 0\n (+ 1 (length (cdr lst)))))\n</code></pre>\n\n<p>Okay, so, what would it look like if instead of recursing, we kept a ru... | {
"AcceptedAnswerId": "37009",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-10T02:00:11.447",
"Id": "37008",
"Score": "1",
"Tags": [
"recursion",
"scheme"
],
"Title": "Linear Peano multiplication in Scheme?"
} | 37008 |
<p>Several of my Python 2.7 programs need to access server tasks via our server Apache instance.
The 'client' programs will run on Windows in various environments. They may be run on systems that do not use a proxy, or on systems that use a proxy with no authentication, or enterprise systems that use an authenticated ... | [] | [
{
"body": "<p>I know you said the error handlers weren't done, but don't use <code>except Exception, err</code>. It's syntax that was removed in Python 3.x because it muddied the waters when you want to accept multiple exceptions, ie. <code>except ValueError, IndexError</code>. It is possible to do that, but yo... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-10T05:10:49.230",
"Id": "37010",
"Score": "3",
"Tags": [
"python",
"networking",
"python-2.x"
],
"Title": "urllib proxy access function"
} | 37010 |
<p>I've just stumbled upon something today that seemed "unethical" in PHP. What I originally thought as malpractice, turned out to work just fine. Basically what I was wondering is if pushing an instantiated class in an array was considered proper?</p>
<p>Example:</p>
<pre><code>$array = array();
array_push($array, ... | [] | [
{
"body": "<p>That example looks like a very simple \"chain of command\" implementation.\nLooks fine to me, nothing unusual (though YYMV depending on the code-base).</p>\n\n<p>You'll see things like this as an alternative to long blocks of procedural code, often when there's a bunch of distinct actions to perfo... | {
"AcceptedAnswerId": "37039",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-10T05:25:59.530",
"Id": "37012",
"Score": "1",
"Tags": [
"php",
"array"
],
"Title": "Pushing instantiated class in an array"
} | 37012 |
<p>I have written this code which adds a <code>querystring</code> to a URL:</p>
<pre><code>exports.addQueryString = function(url, queryString) {
var isQuestionMarkPresent = url && url.indexOf('?') !== -1,
separator = '';
if (queryString) {
separator = isQuestionMarkPresent ? '&' : '?';
url... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-09T14:27:04.737",
"Id": "65068",
"Score": "0",
"body": "Have you considered proper encoding of query string values? From your code it looks like it might be a separate operation since you already pass in a full query string but may be ... | [
{
"body": "<p>What happens when you just want to add a single <code>queryString</code> to and already long <code>queryString</code>? You would need to know the entire <code>queryString</code> to do that, just to add a single new value.</p>\n\n<p>What your function should do is take a single <code>queryString</c... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-10T06:15:42.050",
"Id": "37013",
"Score": "2",
"Tags": [
"javascript",
"url"
],
"Title": "Add query string to a URL"
} | 37013 |
<p>I've tried using CRTP, but the forces the class to befriend CRTP Base.</p>
<pre><code>template <typename T>
class SharedConstructable
: public std::enable_shared_from_this<T>
{
typedef std::shared_ptr<T> ptr_type;
public:
struct Ptr
: ptr_type
{
template<typena... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-12T03:44:24.510",
"Id": "61317",
"Score": "0",
"body": "To do what exactly - inherit privately from `SharedConstructable<T>` (more or less as given) and not expose a constructor? Or was that just an attempted means to accomplish anothe... | [
{
"body": "<p>If I follow you correctly, you're looking for a clean way to have a private constructor that can only be invoked by std::make_shared or std::allocate_shared. Unfortunately this does not appear to be <a href=\"http://www.drdobbs.com/befriending-templates/184403853\" rel=\"nofollow\">portable</a> or... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-10T06:56:39.287",
"Id": "37014",
"Score": "0",
"Tags": [
"c++",
"c++11",
"pointers"
],
"Title": "Extract code that makes class shared_ptr construct-able only"
} | 37014 |
<p>Thanks for taking the time to read this.
I submitted a code screening for a company I really wanted to work for and spent a decent amount of time on their programming assignment. Pretty bummed when they just said thanks but no thanks. </p>
<p>Could you guys take a look and see why that might be? I was hoping to at ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-10T15:07:04.940",
"Id": "60995",
"Score": "0",
"body": "What was the specification of the task?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-10T15:22:41.673",
"Id": "60998",
"Score": "2",
"bo... | [
{
"body": "<p>First, I'd start with </p>\n\n<pre><code>#!/usr/bin/env bash\n</code></pre>\n\n<p>to indicate the shell.</p>\n\n<p>Next, I don't know how much bash you must use, but I think you can at least replace a serious portion of the code by using some other tools (i.e. more UNIX style).</p>\n\n<p>E.g. chec... | {
"AcceptedAnswerId": "37048",
"CommentCount": "7",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-10T07:15:11.563",
"Id": "37015",
"Score": "2",
"Tags": [
"interview-questions",
"bash"
],
"Title": "Spell check interview problem in Bash"
} | 37015 |
<p>I've been chewing through a bit of <em>The Little Schemer</em> and the Peano examples got me thinking about operation size and time. </p>
<p>I got some <a href="https://codereview.stackexchange.com/questions/37008/linear-peano-multiplication-in-scheme">help</a> on making Peano Multiplication linear -- however <code... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-11T03:10:31.433",
"Id": "61134",
"Score": "1",
"body": "This doesn't address your question, but just as a point of interest: all the functions above are lexically scoped and in fact Scheme is always lexically scoped. What distinguishes... | [
{
"body": "<p>In <code>exxp-aux</code>, you call <code>(mX-let b prod)</code> and <code>(mX-lex b prod)</code>. You probably meant the two calls to be identical.</p>\n\n<p>In <code>exxp-let</code>, you call <code>(mX-let prod b)</code>.</p>\n\n<p><code>mX-lex</code> and <code>mX-let</code> are both implemented... | {
"AcceptedAnswerId": "37072",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-10T08:38:08.143",
"Id": "37018",
"Score": "2",
"Tags": [
"performance",
"recursion",
"scheme",
"iteration"
],
"Title": "lexical scope v let in scheme functions"
} | 37018 |
<p>In this, we are given an array of numbers, say 1 2 3 4.</p>
<p>We start from a given position, let's say the 1st position.
We cancel that number and move forward that many non-cancelled numbers. The number on which we stop again has the same procedure.This is repeated until only one number is left. That is the luck... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-10T11:01:55.933",
"Id": "60960",
"Score": "0",
"body": "Your current code doesn't work as you have described. The array `1 2 3 4` and the starting number `1` returns `2`, not `3` as you have described."
}
] | [
{
"body": "<p>Yes, there is a more elegant way of doing this. (That's all you wanted to know, isn't it?)</p>\n\n<p>First of all, here's some general comments about your code:</p>\n\n<ul>\n<li>Your <code>Scanner</code> should be closed when you are done with it. <code>sc.close();</code></li>\n<li>You use in tota... | {
"AcceptedAnswerId": "37024",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-10T08:49:42.217",
"Id": "37019",
"Score": "3",
"Tags": [
"java",
"array"
],
"Title": "Optimising Lucky Number Program"
} | 37019 |
<p>I have this query:</p>
<pre><code>SELECT * FROM
(SELECT u.id,u.email,u.verified,u.verified_on,u.created_on,ca.html AS age,cg.html AS gender,cs.html AS state
FROM users u
LEFT JOIN combo ca ON ca.combo_group='age' AND ca.value =u.age
LEFT JOIN combo cg ON cg.combo_group='gender' AND cg.value =u.gender
LEFT JOIN comb... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-10T12:23:16.477",
"Id": "60972",
"Score": "5",
"body": "Cross-posted from http://stackoverflow.com/q/20492709/398670. Please do NOT duplicate your questions across multiple sites; if you really feel you must, link between them to avoid... | [
{
"body": "<p>Your query doesn't do what you think it does. It discards the original ordering when it re-sorts. It might, depending on the sorting algorithm chosen, happen to come out how you want, but there's no guarantee.</p>\n\n<blockquote>\n <p>I am using sub query because i want sort created_on DESC and e... | {
"AcceptedAnswerId": "37031",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-10T10:40:06.380",
"Id": "37025",
"Score": "2",
"Tags": [
"performance",
"sql",
"mysql",
"sorting",
"postgresql"
],
"Title": "Query of users for some age, gender, and state... | 37025 |
<p>I have a pretty simple problem. A large set of unique strings that are to various degrees not clean, and in reality they in fact represent the same underlying reality. They are not person names, but they could be. So for example Dr. John Holmes and Dr. Jon Holms are more than likely the same person. From the list of... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-10T11:32:31.273",
"Id": "60962",
"Score": "1",
"body": "(i) Do you have any test data? (ii) Can you explain in more detail why you decided not to use any of the methods in [`scipy.cluster.hierarchy`](http://docs.scipy.org/doc/scipy/ref... | [
{
"body": "<p>Here's a quick illustration of how to use <a href=\"http://docs.scipy.org/doc/scipy/reference/generated/scipy.cluster.hierarchy.linkage.html#scipy.cluster.hierarchy.linkage\" rel=\"noreferrer\"><code>scipy.cluster.hierarchy.linkage</code></a> to hierarchically cluster a group of strings according ... | {
"AcceptedAnswerId": null,
"CommentCount": "7",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-10T10:59:07.433",
"Id": "37026",
"Score": "12",
"Tags": [
"python",
"strings",
"edit-distance",
"clustering"
],
"Title": "String Matching and Clustering"
} | 37026 |
<p>I was trying to make my life easier making a class or something that would create HTML tags in a faster way. I ended up with something that I wouldn't consider the best practice. Take a look:</p>
<pre><code>/**
* Add HTML to the page
*
* Add HTML to the page based on arrays with the tag names. It's gonna open an... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-01T11:43:22.683",
"Id": "68467",
"Score": "1",
"body": "This is very similar to http://codereview.stackexchange.com/questions/10809/code-readability-vs-code-length. I have an answer there which you might want to look at."
}
] | [
{
"body": "<p>When it comes to outputting HTML from PHP, there are a couple of alternatives:</p>\n\n<ul>\n<li>Using a MVC framework which will separate the logic (Controller) from the data (Model) and the output (View).</li>\n<li>Include files that contains HTML, and that can use some PHP as well (\"Templates\"... | {
"AcceptedAnswerId": "37029",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-10T11:40:03.577",
"Id": "37027",
"Score": "5",
"Tags": [
"php"
],
"Title": "Add HTML to the page using a PHP Class"
} | 37027 |
<p>During work, I was given this task: to group elements with similar properties in the array.</p>
<p>In general, the problem is as follows:</p>
<pre><code>var list = [
{name: "1", lastname: "foo1", age: "16"},
{name: "2", lastname: "foo", age: "13"},
{name: "3", lastname: "foo1", age: "11"},
{name: "... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2016-02-10T10:26:32.417",
"Id": "222507",
"Score": "0",
"body": "There is npm module named [group-array](https://www.npmjs.com/package/group-array) that matches the same requirement."
},
{
"ContentLicense": "CC BY-SA 3.0",
"Creatio... | [
{
"body": "<p>I find the functional aspect of JavaScript to be a big advantage. When it comes to looping, <code>Array.prototype.forEach</code> and cousins can help your code be more descriptive:</p>\n\n<pre><code>Array.prototype.defineProperty('groupByProperties', {\n value : function(properties){ ... | {
"AcceptedAnswerId": "37132",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-10T11:44:11.493",
"Id": "37028",
"Score": "62",
"Tags": [
"javascript",
"sorting",
"properties"
],
"Title": "Grouping elements in array by multiple properties"
} | 37028 |
<p>I need to write code for the given problem:</p>
<p>I'm provided with a word and I need to find all the possible combination of it that matches with a given list of words in a file.</p>
<p>Here's my code. Can I make it much better? I'm sure it can be done. Please offer suggestions.</p>
<pre><code>dict = {} ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-10T14:40:13.640",
"Id": "60990",
"Score": "0",
"body": "You may want to handle some special characters, like apostrophe, more directly. It's quite possible that you'd want to let `sit` find anagrams including both `its` and `it's`, and... | [
{
"body": "<p>Hum, first of all, there are way too many comments. People simply won't read them, you should only keep the meaningful ones. For example, you could remove:</p>\n\n<pre><code>if sorted_word in dict: #Check if sorted_word is already a key\n</code></pre>\n\n<p>Anybody who knows how Python dictionarie... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-10T13:08:51.303",
"Id": "37034",
"Score": "4",
"Tags": [
"python",
"algorithm"
],
"Title": "Jumble solver algorithm"
} | 37034 |
<p>The goal of this code was to create a table from an associative array.</p>
<ul>
<li>I need to create horizontal rows where the keys need to be used as "headers" while the values are posted below each header. </li>
<li>I need to be able to reuse the code with associative arrays of unknown lengths and varying numbe... | [] | [
{
"body": "<p>Use <a href=\"http://www.php.net/manual/en/function.array-chunk.php\" rel=\"nofollow\"><code>array_chunk()</code></a> to split <code>$rows</code> into rows. Each <em>row</em> will be double high <code>$doubleRows</code>, so store the values in a small multi-dimension array <code>$tablerows</code> ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-10T13:16:32.183",
"Id": "37035",
"Score": "2",
"Tags": [
"php"
],
"Title": "Using a variable in a for loop: is it proper practice or is there a better approach"
} | 37035 |
<p>Assume the server is sending data to our app at regular intervals, at least once per second. The received data is parsed and stored in memory as a POJO. A blocking queue is processing data in a worker thread.</p>
<p>Suppose I want to use a very simple object pool, so I don’t have to create a new POJO for each serve... | [] | [
{
"body": "<p>I have to question whether this makes any sense in your application:</p>\n<blockquote>\n<p>Assume the server is sending data to our app at regular intervals, at least once per second</p>\n</blockquote>\n<p>Have you done any testing/metrics that indicate that the current system you have is actually... | {
"AcceptedAnswerId": "37044",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-10T14:20:31.700",
"Id": "37040",
"Score": "2",
"Tags": [
"java",
"android"
],
"Title": "Simple object pool on Android"
} | 37040 |
<p>Being new to raw JavaScript, intervals and times this was not the easiest script to come up with, and thus, although it seems to be working as I want it too the code looks very clunky.</p>
<p>The timer counts down to one of 4 times of day: 8am, 2pm, 8pm or 2am depending on which is the closest. Because they are at ... | [] | [
{
"body": "<blockquote>\n <p>Because they are at six hour intervals there can either be one or a maximum of 2 times that are currently in the future.</p>\n</blockquote>\n\n<p>True, <em>BUT</em> there is still only 1 hour that is closes</p>\n\n<p>This should do the same thing, and you could add more hours to th... | {
"AcceptedAnswerId": "37049",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-10T14:52:53.063",
"Id": "37047",
"Score": "1",
"Tags": [
"javascript",
"php",
"timer"
],
"Title": "Countdown timer"
} | 37047 |
<p><em>This is a copy of <a href="https://stackoverflow.com/questions/20498825/converting-a-32bit-number-in-a-proprietary-timestamp-with-php">a posting I made on SO</a>, it was suggested I post it here all I've changed from that post is I'm now doing the bitwise AND using a decimal number rather than using bindec("111"... | [] | [
{
"body": "<p>Not being a PHP expert, but messing with bitwise operations a lot, I have some advice for you:</p>\n\n<p>First, the specification for your operations <strong>should be embedded with the code</strong> as a comment. Having to look up a specification that may or may not be the same as the one you use... | {
"AcceptedAnswerId": "37057",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-10T16:06:28.253",
"Id": "37051",
"Score": "4",
"Tags": [
"php"
],
"Title": "Converting a 32bit number in a proprietary timestamp with PHP"
} | 37051 |
<p>Think of a set of text lines starting with a common string, e.g. indented code.</p>
<pre><code>my $preamble = reduce {
my $len = min(length $a, length $b);
--$len while substr($a, 0, $len) ne substr($b, 0, $len);
return substr($a, 0, $len);
} @lines;
</code></pre>
<p>Note that after the first invocatio... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-10T17:23:30.453",
"Id": "61023",
"Score": "1",
"body": "Can you provide `@lines` and `$preamble` sample?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-10T19:31:04.340",
"Id": "61059",
"Score": "0"... | [
{
"body": "<p>First of all, I think it is very good that you used <code>reduce</code>, as it clearly shows how the algorithm works. At least, to a reader who understands functional idioms.</p>\n\n<p>One problem in your code is that you keep using <code>$a</code> and <code>$b</code>. These two names do not conve... | {
"AcceptedAnswerId": "37074",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-10T16:44:39.473",
"Id": "37054",
"Score": "4",
"Tags": [
"strings",
"perl"
],
"Title": "Find common preamble of a list of strings"
} | 37054 |
<p>I'm new to Java and am trying to solve a scenario. Even though I've succeeded and it works, I've just wondered if there was a more practical way of doing this task. Is there a quicker or more efficient way of solving the task, or is this fine?</p>
<blockquote>
<p><strong>Task:</strong></p>
<p>Given a strin... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-11T01:20:20.477",
"Id": "61118",
"Score": "0",
"body": "Worth noting, there's `charAt(int)` for the single char checks, which expresses your intent far clearer than `substring`."
}
] | [
{
"body": "<p>Yes, some of the things you are doing is redundant and quite messy. As this seems to be a homework assignment I will only provide hints for you here.</p>\n\n<p>What you can do is:</p>\n\n<ul>\n<li>If the string is empty, return an empty string immediately</li>\n<li>Store the first character in a v... | {
"AcceptedAnswerId": "37056",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-10T16:48:38.130",
"Id": "37055",
"Score": "11",
"Tags": [
"java",
"strings",
"beginner",
"homework"
],
"Title": "Return a string without the first two characters"
} | 37055 |
<p>I wrote this program for an assignment, thus I had some requirements as far as the format of the cfg.txt file and some basic other classes that we had to use. Other than that, I am curious if there is a way to drastically simplify this code. Although the program runs fine and produces the desired output, is there a ... | [] | [
{
"body": "<ul>\n<li><p>It is said that \"a method should do one thing, and it should do that one thing well\". Your iterateData method is being used to do two separate things, depending on the parameter you send it.</p></li>\n<li><p>If your <code>ArrayUnsortedList</code> is <a href=\"https://github.com/ckoch78... | {
"AcceptedAnswerId": "37060",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-10T17:16:44.143",
"Id": "37058",
"Score": "3",
"Tags": [
"java",
"performance",
"design-patterns",
"parsing"
],
"Title": "Very basic Context Free Grammar in Java"
} | 37058 |
<p>so this is my code and I just want to improve it, I'm a beginner so I think there are some better and short ways to do what I did here. Any Ideas?
The code:</p>
<pre><code>class Table:
def __init__(self,path,sep):
self.path=path
self.sep=sep
self.g=[]
self.count=0
self.h... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-10T18:56:34.003",
"Id": "61047",
"Score": "0",
"body": "Did you consider using the built-in [`sqlite3`](http://docs.python.org/3/library/sqlite3.html) module instead?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": ... | [
{
"body": "<p>Here are a number of suggestions that would help the readability and usability of your code. Most of these are fairly high level suggestions that apply almost anywhere, but some do get into the details of your implementation.</p>\n\n<ul>\n<li>Comment on the blocks that make up your <code>Table.__i... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-10T18:46:01.780",
"Id": "37067",
"Score": "1",
"Tags": [
"python",
"database"
],
"Title": "Data table class"
} | 37067 |
<p>I'm trying to write a simple game. I have an <code>Entity</code> object, that has a list of <code>Sprite</code> objects. Each <code>Sprite</code> has a position property where it is drawn on the screen. Sometimes, an entity can contain a lot of <code>Sprite</code>s in which case it is much easier to set the position... | [] | [
{
"body": "<p>Another approach would be to make the positions of sprites relative to the position of the entity. That way, the default of zero comes up naturally and when you move an entity, all of its sprites are automatically moved too.</p>\n\n<p>One more advantage is that this means position zero now becomes... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-10T19:19:32.693",
"Id": "37069",
"Score": "7",
"Tags": [
"c#",
"design-patterns",
"collections"
],
"Title": "Cascading a property for a game"
} | 37069 |
<p>Coming from an imperative background, I have written the following code in Scala. I need to attempt to find a value in a map. If the value exists, I need to pass the value to another function and return the result, otherwise I need to return None.</p>
<pre><code>def foo(index: Int): Option[FooBar] = {
val myloo... | [] | [
{
"body": "<pre><code>myLookup.get(index).orElse(myLookup.get(static_value)).map { doSomeCall(_).makeFooBar }\n</code></pre>\n\n<p>From the Scala doc of <a href=\"http://www.scala-lang.org/api/current/index.html#scala.Option\" rel=\"nofollow\"><code>Option.map</code></a>: </p>\n\n<blockquote>\n <p>Returns a sc... | {
"AcceptedAnswerId": "37079",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-10T20:21:54.683",
"Id": "37070",
"Score": "4",
"Tags": [
"scala"
],
"Title": "What is a better approach for operating on an arbitrary map value in Scala?"
} | 37070 |
<p>I am trying to re-factor (improve design of existing working code) with the following principals:</p>
<ul>
<li>Switch statements removal.</li>
<li>Encapsulate Field</li>
<li>Extract Class</li>
<li>Extract Interface</li>
<li>Extract Method</li>
<li>Extract Subclass</li>
<li>Extract Super Class</li>
<li>Form Template... | [] | [
{
"body": "<ol>\n<li><p>It's better to use <code>enum { TRUEFALSE, FREEFORM }</code> instead of hard coding arbitrary <code>int</code> values.</p></li>\n<li><p>It's better to declare your variables as <code>List<TriviaQuestion> data</code> and only use <code>ArrayList</code> when you instantiate them. Yo... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-10T20:36:03.967",
"Id": "37073",
"Score": "1",
"Tags": [
"java",
"game"
],
"Title": "Trivia game refactoring"
} | 37073 |
<p>The context is Weekend Challenge #2 (Poker hand evaluation).</p>
<pre><code>Hand.prototype.isStraight = function()
{
for( var i = 1 ; i < this.cards.length ; i++ )
if( this.cards[i].value + 1 != this.cards[i-1].value )
return false;
return true;
}
</code></pre>
<p><code>cards</code> is an array wi... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-10T21:13:25.200",
"Id": "61088",
"Score": "2",
"body": "Ugh. You have no idea how much I wish it were *that* simple."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-10T21:15:55.523",
"Id": "61089",
... | [
{
"body": "<p>It's not that hard. </p>\n\n<p>Instead of sorting the cards, looping over them and skipping double results, let's convert them to a more useful format:</p>\n\n<pre><code>var bitmap = 0;\n\nfor(var i = 0; i < cards.length; i++)\n{\n var value = cards[i].value;\n\n // set i+1 bit in the bit... | {
"AcceptedAnswerId": "37082",
"CommentCount": "9",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-10T21:08:42.387",
"Id": "37077",
"Score": "10",
"Tags": [
"javascript",
"playing-cards",
"weekend-challenge"
],
"Title": "isStraight evaluation function"
} | 37077 |
<p>This is one of my Haskell solutions to a variation of the N-Queens problem, where the queens can move like knights in addition to their normal moves. It has been optimized somewhat to avoid investigating redundant combinations.</p>
<pre><code>place :: Int -> [[Int]]
place 0 = [[]]
place n = go $ take n $ repeat... | [] | [
{
"body": "<pre><code>notK q = map (uncurry filter) . (zip (kFilters q))\n</code></pre>\n\n<p>is equivalent to</p>\n\n<pre><code>notK q rows = zipWith filter (kFilters q) rows\n</code></pre>\n\n<p>Onto making above Haskell less <em>idiomatic</em> and less <em>pointfree</em> and more <em>readable</em>.</p>\n\n<p... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-10T21:40:22.837",
"Id": "37081",
"Score": "9",
"Tags": [
"haskell",
"recursion",
"functional-programming",
"linked-list",
"higher-order-functions"
],
"Title": "Better or more... | 37081 |
<p>I'm working on <a href="https://github.com/benjamin-hodgson/Contexts" rel="nofollow">an open-source test framework</a> which needs to dynamically import Python source modules from a given directory.</p>
<p>I can't just use <code>importlib.import_module()</code> or <code>__import__()</code>, because it's a black box... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-10T22:44:10.730",
"Id": "61103",
"Score": "0",
"body": "Did you consider subclassing [`importlib.SourceLoader`](http://docs.python.org/3/library/importlib.html#importlib.abc.SourceLoader) and providing an implementation of the `get_cod... | [
{
"body": "<p>I took @GarethRees's advice and subclassed <code>importlib.abc.SourceLoader</code>. After reading <code>importlib</code>'s source code, I arrived at the following implementation:</p>\n\n<pre><code>import importlib.abc\n\ndef import_module(dir_path, module_name):\n filename = resolve_filename(di... | {
"AcceptedAnswerId": "37167",
"CommentCount": "7",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-10T22:24:35.287",
"Id": "37083",
"Score": "4",
"Tags": [
"python",
"import"
],
"Title": "Dynamically importing Python source modules from a given directory"
} | 37083 |
<p>My Game class has a property of type Player, which inherits from Entity:</p>
<pre><code>player = new Player( "knight.png" );
</code></pre>
<p>It also has a property of type World, which has a collection of Entities (Robot inherits from Entity):</p>
<pre><code>world = new World( new List<Entity>
{
new Ro... | [] | [
{
"body": "<p>Your vision about what is an auto-property is correct. Your first question is essentially whether you should use an auto-property or a property instead, which I answer this way:</p>\n\n<p>Is the property implementation likely to change?</p>\n\n<p>Example:</p>\n\n<pre><code>public class Person{\n ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-10T22:53:11.373",
"Id": "37085",
"Score": "4",
"Tags": [
"c#",
"design-patterns",
"game",
"xna"
],
"Title": "Using the observer pattern with collision detection"
} | 37085 |
<p>I started a Chess in Python for fun. I learned Python in my free time but I've been doing it for a while. The code works but I just want to know if there's anything non-pythonic in my code. The functions calculate all potentially possible moves (ignoring game state).</p>
<pre><code>from itertools import product
fro... | [] | [
{
"body": "<p>The implementation of your <code>move</code> decorator is a little schizophrenic. On the one hand, it carefully allows any and all arguments to be passed to it by declaring itself <code>def wrapper(*args, **kwargs)</code>. However it then requires exactly two positional arguments which it then pas... | {
"AcceptedAnswerId": "37153",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-10T23:34:32.487",
"Id": "37089",
"Score": "3",
"Tags": [
"python",
"python-3.x",
"chess"
],
"Title": "Calculating potential Chess moves"
} | 37089 |
<p>Here is some code of mine that prints out the relative date according to the current time:</p>
<pre><code>#include <stdio.h>
#include <stdlib.h>
#include <time.h>
int main (int argc, char *argv[])
{
int i = 1;
struct tm date = {0};
char relativeDays[80];
char* temp = strtok(argv[1], "/");... | [] | [
{
"body": "<p>I've commented your code: </p>\n\n<pre><code>#include <stdio.h>\n#include <stdlib.h>\n#include <time.h>\n\nint main(int argc, char *argv[])\n{\n int i = 1;\n struct tm date = {0};\n char relativeDays[80];\n</code></pre>\n\n<p>Check For Proper Input</p>\n\n<pre><code> ... | {
"AcceptedAnswerId": "37116",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-11T02:04:56.980",
"Id": "37096",
"Score": "9",
"Tags": [
"performance",
"c",
"datetime"
],
"Title": "Printing out relative date from current time"
} | 37096 |
<p>This code is supposed to delete every node from a linked list with a given value. </p>
<p>Are there any logical errors with this implementation? Did I do anything wrong or is there an area of this implementation that needs significant improvement. Any suggestions? </p>
<pre><code>public boolean delete(int d) {
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-11T03:20:26.830",
"Id": "61137",
"Score": "0",
"body": "You need to give some more detail on what the delete is supposed to do... like, at the moment it keeps searching even after it's deleted a node... is that intentional?"
},
{
... | [
{
"body": "<p>Your code is buggy, if you have two Nodes with the same value in succession it will corrupt the list.... </p>\n\n<p><code>prevNode</code> will be set to the deleted node <code>tempNode</code>, and if the next value also matches the input value you will be working with the wrong node as <code>prevN... | {
"AcceptedAnswerId": "37101",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-11T03:00:40.717",
"Id": "37099",
"Score": "5",
"Tags": [
"java",
"linked-list"
],
"Title": "Linked List Delete Node Function"
} | 37099 |
<p>I'm using PHP, MySQL, Smarty, jQuery, etc. for my website. I'm using an MVC architecture to develop the website. Now in one of the functionality I'm fetching a large amount of data and perform some processing on it. Then I'm returning the finally processed data from model to the controller and assigning it to the Sm... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-03T17:51:21.043",
"Id": "68759",
"Score": "0",
"body": "One note on `$request = empty( $_GET ) ? $_POST : $_GET ;` is that it's really bad practice to do this. It makes the `$_POST`/`$_GET` abstract, I would rather use (don't, really d... | [
{
"body": "<p>I would remove your very performance heavy <code>GetSimilarQuestionsBySubjectIdTopicId</code> from PageLoad and call/load it asynchronously with AJAX.</p>\n\n<p>I would also try and redesign it so you do not execute a SQL query in a loop.</p>\n",
"comments": [
{
"ContentLicense":... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-11T04:56:47.157",
"Id": "37105",
"Score": "2",
"Tags": [
"performance",
"mysql",
"mvc",
"php5",
"smarty"
],
"Title": "Reducing the loading time of a page"
} | 37105 |
<p>I'm new to Scala, and would appreciate any notes about a better approach, correctness, or style.</p>
<pre><code>/**
* Call proc(f) for each file in the directory tree rooted at dir.
*
* proc will not be called for directories, just for files.
*/
def traverse(dir: File, proc: File => Unit): Unit = {
dir.... | [] | [
{
"body": "<p>Your code is fine. Nevertheless, removing unnecessary braces can increase readability:</p>\n\n<pre><code>def traverse(dir: File, proc: File => Unit): Unit =\n dir.listFiles foreach { f => if (f.isDirectory) traverse(f, proc) else proc(f) }\n</code></pre>\n",
"comments": [],
"meta_da... | {
"AcceptedAnswerId": "37110",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-11T05:05:19.967",
"Id": "37106",
"Score": "3",
"Tags": [
"beginner",
"scala",
"file-system"
],
"Title": "Processing files in a directory tree"
} | 37106 |
<p>I have an array of 1000 numbers, randomly generated. 10 of those numbers must be between 0-9 (including 0 and 9), and 10 of those numbers must be between 991 and 1000 (including 991 and 1000). This is what I came up with:</p>
<pre><code>arr = []
980.times do
arr << (11..989).to_a.sample
end
arr2 = []
10.ti... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-14T17:45:17.720",
"Id": "61790",
"Score": "0",
"body": "Is it only 10 for ranges at the end or \"at least 10\"?"
}
] | [
{
"body": "<p>Some notes:</p>\n\n<ul>\n<li><p>Try to learn some functional programming, you shouldn't write Ruby as it were a low-level language (like C). Favor expressions over statements. My 2-cents on the matter, I hope it helps: <a href=\"http://www.slideshare.net/tokland/functional-programming-with-ruby-99... | {
"AcceptedAnswerId": "37114",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-11T05:51:16.697",
"Id": "37107",
"Score": "2",
"Tags": [
"ruby",
"random"
],
"Title": "rand number generator with limits in ruby"
} | 37107 |
<p>Please review the code and suggest better algorithm to efficiently extract key/value from files using multithread.</p>
<p><strong>Input</strong> : FormNGFAddTab:First add Tab control inside Tabs control.परीक्षण</p>
<p><strong>Output</strong> : </p>
<p><strong>Key</strong> : FormNGFAddTab</p>
<p><strong>Value</st... | [] | [
{
"body": "<ol>\n<li>You should use multithreading for reading if you are after performance, so solution which uses <code>Parallel.ForEach()</code> is definetely better.</li>\n<li>For really big files, you should not read all the text into memory. Instead you should create multiple file streams, split your file... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-11T07:27:09.787",
"Id": "37109",
"Score": "1",
"Tags": [
"c#",
"asp.net"
],
"Title": "How to efficiently extract Key Value and load to C# dictionary/HashMap from large files [File Size g... | 37109 |
<p>I'm writing a code for my application: you can create a task, and you can choose the moment when you want to send this task (to some kind of user):</p>
<ul>
<li>Send now</li>
<li>Send later</li>
<li>Repeat</li>
</ul>
<p><img src="https://i.stack.imgur.com/CdSLW.jpg" alt="Send options"></p>
<p>You can select from ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-11T13:07:41.680",
"Id": "61180",
"Score": "0",
"body": "Does this pertain to all of these versions, or do you just need a single [asp.net-mvc] tag?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-11T16:09:2... | [
{
"body": "<p>Well one UI suggestion is where you can select to Repeat -> Daily -> Every working day. </p>\n\n<ul>\n<li><p>This is very culture specific e.g., a Swede will work on the 4th of July while an American won't.</p></li>\n<li><p>It also depends on the year as some holidays do not fall on the same date,... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-11T09:13:13.077",
"Id": "37115",
"Score": "0",
"Tags": [
"c#",
"asp.net-mvc"
],
"Title": "Task send options: Send Now, Send Later, Repeat (viewmodel)"
} | 37115 |
<p>I am creating a string extension to validate some input.</p>
<p>My scenario is when we have a string it will format it according to following guideline.
If the sample string is “One Two Three Four Five” and the length is <=20 return same. If more than 20 then “One Two Three F Five”. If still length is more than ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-11T15:31:28.043",
"Id": "61200",
"Score": "0",
"body": "As a side note, I would expect \"validation\" to return a true/false (or valid/invalid), rather than to return a possibly modified string. You may want to call this something else... | [
{
"body": "<p>You should remove this</p>\n\n<pre><code>length = length + namelist.Count() - 1;\n</code></pre>\n\n<p>because length already includes the spaces.</p>\n\n<p>This </p>\n\n<pre><code>length = length - namelist[i].Length;\n</code></pre>\n\n<p>should be</p>\n\n<pre><code>length -= namelist[i].Length - ... | {
"AcceptedAnswerId": null,
"CommentCount": "7",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-11T11:04:48.813",
"Id": "37121",
"Score": "3",
"Tags": [
"c#",
".net",
"strings",
"recursion"
],
"Title": "String Extension improvement"
} | 37121 |
<p>Higher-order functions are functions which either</p>
<ol>
<li>take functions as arguments or</li>
<li>return them as output</li>
</ol>
<p>(or both). Functions which do neither of these are known, in contrast, as <em>first-order functions</em>.</p>
<p>Higher-order functions are a cornerstone of the functional pr... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-11T11:56:13.123",
"Id": "37124",
"Score": "0",
"Tags": null,
"Title": null
} | 37124 |
Higher-order functions are functions which either take functions as arguments or return them as output (or both). They are a cornerstone of functional programming. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-11T11:56:13.123",
"Id": "37125",
"Score": "0",
"Tags": null,
"Title": null
} | 37125 |
<p>I have often encountered the following situation. I want to call a method in a Loop, but want to skip the call at the first run. It do not have to be a method, it also can be some lines of code that I want to skip. Here is one example:</p>
<p>I have a file which looks like that.</p>
<pre><code>headline:headline1
c... | [] | [
{
"body": "<p>One elegant way to handle this is to parse the input into a more usable structure before transforming it to HTML. For example, each section could be represented as:</p>\n\n<pre><code>private class Section {\n final String headline;\n final List<String> contents = new ArrayList<String>... | {
"AcceptedAnswerId": "37131",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-11T13:14:04.467",
"Id": "37127",
"Score": "7",
"Tags": [
"java",
"parsing",
"iteration"
],
"Title": "Looping Strategy: Change behaviour after first iteration"
} | 37127 |
<p>How can I write this shorter (while keeping the same functionality and outputs to console)?</p>
<pre><code>def review():
v1 = value_of_current_cards(hand_one)
v2 = value_of_current_cards(hand_two)
v3 = value_of_current_cards(hand_three)
vd = value_of_current_cards(hand_dealer)
if number_of_hands... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-11T14:31:24.757",
"Id": "61190",
"Score": "1",
"body": "You forgot to handle the case `v1 < 18 and vd == 18`"
},
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2019-03-11T16:25:45.000",
"Id": "416162",
"Score"... | [
{
"body": "<p>You can/shuold extract repeating code, e.g. into into functions (see my example)</p>\n\n<p>example:</p>\n\n<pre><code>def evaluate_hand(value_of_hand, hand_no, hand_of_dealer):\n \"\"\"\n Evalutates ....\n\n @param value_of_hand the value for the current hand.\n @param hand_no the num... | {
"AcceptedAnswerId": "37148",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-11T13:50:15.563",
"Id": "37130",
"Score": "1",
"Tags": [
"python",
"game",
"playing-cards"
],
"Title": "Conditional statements in Hot 18 card game"
} | 37130 |
<p>What are the better solutions possible?</p>
<p>I have a character array with different strings. There is a max size for the strings. In case a string is smaller than max size remaining places are filled with '-'.
Sorting has to be done on this.</p>
<blockquote>
<p>Example:</p>
<p>maxStringSize = 5</p>
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-11T15:44:16.983",
"Id": "61204",
"Score": "1",
"body": "Can you please provide more context to your code?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-11T15:48:40.390",
"Id": "61206",
"Score": "0... | [
{
"body": "<p>How about the simple process of converting the chars to separate strings, sorting the Strings, then copying the results back to an array?</p>\n\n<p>It would look something like:</p>\n\n<pre><code>String source = new String(input);\nString[] values = new String[input.length / blocksize];\nfor (int ... | {
"AcceptedAnswerId": null,
"CommentCount": "14",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-11T15:43:02.293",
"Id": "37140",
"Score": "4",
"Tags": [
"java",
"strings",
"array",
"homework",
"sorting"
],
"Title": "Sorting strings in a one dimensional array"
} | 37140 |
<p>I'm trying to improve my javascript coding style and want to start writing my code more object-oriented. The code below is getting a JSON-stringified list of locations from a cookie and appending a <code>li</code> to a list for each location. I would appreciate some helpful critique and any general pointers. I have ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-11T19:11:18.367",
"Id": "61247",
"Score": "0",
"body": "Would jQuery's $.proxy help here? You can wrap everything the a function and use this as the target in the second argument."
},
{
"ContentLicense": "CC BY-SA 3.0",
"Cr... | [
{
"body": "<p>Some things to consider (after a first, superficial look at your code):</p>\n\n<ul>\n<li>Stick to the conventions: A constructor starts with an UpperCase, and is camelCased from their on. <code>Favourites</code> would be a better var name, because it signals a constructor, and requires the <code>n... | {
"AcceptedAnswerId": "37204",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-11T16:35:28.063",
"Id": "37146",
"Score": "3",
"Tags": [
"javascript",
"object-oriented"
],
"Title": "Learning OOP javascript - critique my class that creates a 'favourites' list"
} | 37146 |
<p>Please only post contest questions that abide by the <a href="https://codereview.stackexchange.com/help/on-topic">site policy</a>. Namely, questions <em>must not</em> correspond to code-golf, obfuscation, "spaghetti code," or other requests that do not seek any kind of improvement.</p>
| [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-11T18:07:45.960",
"Id": "37151",
"Score": "0",
"Tags": null,
"Title": null
} | 37151 |
This tag is for questions with code that you have written for a competition. CODE MUST STILL COMPILE AND RUN. Code that fails because of the time constraint may, however, still be on-topic. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-11T18:07:45.960",
"Id": "37152",
"Score": "0",
"Tags": null,
"Title": null
} | 37152 |
<p>I'm making a little Python script that reads a text file and puts it on a HTML page. I haven't finished that part yet, but I've been working on the GUI with tkinter. Is my code sloppy?</p>
<pre><code>from Tkinter import *
import time
from datetime import datetime
#init variables
global r
r = 0
global delay
delay ... | [] | [
{
"body": "<blockquote>\n <p>Is my code sloppy?</p>\n</blockquote>\n\n<p>It is, but there are very specifics things you can do to address that. Good news! First, use <a href=\"http://pep8online.com/\" rel=\"nofollow\">http://pep8online.com/</a> to make sure that your code follows <a href=\"http://www.python.or... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-11T18:43:51.960",
"Id": "37154",
"Score": "6",
"Tags": [
"python",
"tkinter"
],
"Title": "Python tkinter GUI"
} | 37154 |
<p>This was the most humerus coding I've ever done. It's for my string library in C. It detects if the user is angry to various degrees, namely <code>str_isHeated()</code>. </p>
<p><strong>Why?</strong></p>
<p>Ever play a text-based game and you're swearing at the computer by typing, typing multiple <code>!!!</code>,... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-11T19:18:27.257",
"Id": "61248",
"Score": "8",
"body": "My initial thought was \"lol\" :)"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-11T19:49:27.937",
"Id": "61252",
"Score": "2",
"body": "... | [
{
"body": "<p>Use a hash table! Something like this would work: </p>\n\n<pre><code>#include <stdio.h>\n#include <ctype.h>\n#include <stdlib.h>\n#include <string.h>\n#include <math.h>\n#include <stdbool.h>\n#include <sys/resource.h>\n#include <sys/time.h>\n\n\n// ... | {
"AcceptedAnswerId": null,
"CommentCount": "9",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-11T19:15:54.963",
"Id": "37155",
"Score": "15",
"Tags": [
"c",
"strings",
"game"
],
"Title": "C String - new function to detect user's anger"
} | 37155 |
<p>I wrote my first AJAX script that brings content from other pages without refreshing the entire page. I just want to see if improvements can be added to it, or if I'm doing something not recommended.</p>
<pre><code>$(function(){
// content container content loader
$("#nav-tabs-list a").click(function() {
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-11T20:03:09.057",
"Id": "61254",
"Score": "0",
"body": "I assume this is jQuery? What javascript library are you using?"
}
] | [
{
"body": "<p>You seem to have some copy pasted code there.</p>\n\n<p>How about</p>\n\n<pre><code>function enableLinks( selector , path , container )\n{\n /* Allow ajax to work */\n $( selector ).click( function()\n {\n var page = this.hash.substr(1);\n $.get( path + page + \".php\", function( html ) \... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-11T19:32:28.347",
"Id": "37157",
"Score": "4",
"Tags": [
"javascript",
"ajax"
],
"Title": "Bringing content from other pages without refreshing the entire page"
} | 37157 |
<p>I'm considering releasing a library as a bower module. Are there issues with code quality, missing test cases, that need to be addressed first? Perhaps it's not a good candidate for public release. If so, why not? </p>
<p>What level of documentation would you want for something like this? I've seen some open sou... | [] | [
{
"body": "<p>The code looks good (make sure to replace <code>new Function</code> quickly :), and it's a great candidate for a public release.</p>\n\n<p>It is short enough to deserve annotated documentation that would explain how it works which is useful for debugging. But that should not replace the actual API... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-11T20:06:01.163",
"Id": "37161",
"Score": "7",
"Tags": [
"javascript",
"angular.js",
"couchdb"
],
"Title": "Open source angularjs pouchdb model persistence layer - release ready?"
} | 37161 |
<p>I have created a program which rolls a die according to the number of sides that the user enters:</p>
<pre><code>def var():
import random
dicesides = int(input("Please enter the amount of sides you want the dice that is being thrown to have. The dice sides available are: 4, 6 and 12: "))
script(dicesi... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-11T23:51:19.070",
"Id": "61297",
"Score": "0",
"body": "Given that you are using a computer random number generator, why not accept any number of sides? Anything wrong with a d23? At least 8 and 20 seem like they should be acceptable... | [
{
"body": "<p>Your variables <code>dice4</code>. <code>dice6</code> and <code>dice12</code> are essentially the same variables, so let's give them the same name. It now happens that three of the cases are identical, and can be shortened to:</p>\n\n<pre><code>if dicesides != 4 or dicesides != 6 or dicesides != 1... | {
"AcceptedAnswerId": "37170",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-11T20:13:18.833",
"Id": "37163",
"Score": "5",
"Tags": [
"python",
"random",
"dice"
],
"Title": "Roll a die according to the number of sides that the user enters"
} | 37163 |
<p>I'm late to this weekend challenge (sorry), but since it's all in good fun, I hope that's ok. I'm no poker player, though, so I may have completely overlooked something.</p>
<p>The <code>Hand</code> class does the evaluation, and calculates (among other things) a <code>score</code> array which is ordered for possib... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-17T01:17:22.997",
"Id": "62175",
"Score": "0",
"body": "Looks like we need more ruby coders..."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-17T02:12:59.150",
"Id": "62186",
"Score": "1",
"bod... | [
{
"body": "<p>I think your example is well structured, I hope my review does it some justice. There are your concerns and some additional points I want to discuss:</p>\n\n<p><a href=\"https://gist.github.com/beatrichartz/06c3142d8a0dae8dae84\"><em>You'll find a working implementation of the following code here<... | {
"AcceptedAnswerId": "37618",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-11T20:26:22.900",
"Id": "37165",
"Score": "22",
"Tags": [
"ruby",
"weekend-challenge",
"playing-cards"
],
"Title": "Weekend Challenge: Ruby Poker Hand Evaluation"
} | 37165 |
<h1>Normalization pertaining to Databases</h1>
<p>In SQL, normal forms are defining characteristics of relational databases. SQL forms get classified according to the types of modification anomalies they're subject to. First, second, and third normal forms (1NF, 2NF, 3NF) serve as remedies to the three main sources of... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-11T20:37:25.243",
"Id": "37168",
"Score": "0",
"Tags": null,
"Title": null
} | 37168 |
normalizing a Database to remove redundant information and produce an efficient database.
normal forms are defining characteristics of relational databases | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-11T20:37:25.243",
"Id": "37169",
"Score": "0",
"Tags": null,
"Title": null
} | 37169 |
<p>I had to work in the Transport Problem and we're asked to try to make the fastest code for big matrices, so we're advised to try to avoid loops. And the only one I've got and I cannot imagine how to simplify it is this one for making an incidence matrix (with 1s, 0s and -1s) like that:</p>
<pre><code>b<-diag(-1,... | [] | [
{
"body": "<p>I can't think of anything faster than:</p>\n\n<pre><code>a <- matrix(diag(-1, n2), nrow = n2, ncol = n1 * n2)\n</code></pre>\n\n<p>The <code>n2 * n2</code> values inside <code>diag(-1L, n2)</code> will be recycled <code>n1</code> times to fill the final matrix of dimensions <code>n2-by-n1*n2</c... | {
"AcceptedAnswerId": "37183",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-11T21:55:30.787",
"Id": "37175",
"Score": "3",
"Tags": [
"r",
"matrix"
],
"Title": "Simplifying loop for Incidence Matrix"
} | 37175 |
<p>I write a metric ton of queries for an Oracle environment every day. These are reports that often require multiple separate queries that no end of joins and sub-queries will satisfy, hence lots of separate queries.</p>
<p>I find myself rewriting this bit of code all too often:</p>
<pre><code>try
{
using (Oracl... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-11T23:38:37.493",
"Id": "61294",
"Score": "3",
"body": "Have you considered using an ORM, like Entity Framework?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-12T18:13:34.550",
"Id": "61421",
"Sco... | [
{
"body": "<p>It's very easy to get started with EF, especially for CRUD operations, Plus, you always have the flexibility of executing native SQL queries to accomplish complicated tasks.</p>\n\n<p>Entity Framework has gobs of hours of optimization effort put into it, it's really quite remarkable in that respec... | {
"AcceptedAnswerId": "37251",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-11T22:29:30.760",
"Id": "37176",
"Score": "4",
"Tags": [
"c#",
".net",
"oracle",
"wrapper"
],
"Title": "Creating a reusable C#.NET Oracle Query Builder"
} | 37176 |
<p>To detect <code>int</code> overflow/underflow in C, I use this code. What might be a simpler and more portable way of coding this (that is, fewer conditions)?</p>
<p>Assume 2's complement and don't use wider integers.</p>
<pre><code>int a,b,sum;
sum = a + b;
// out-of-range only possible when the signs are the sam... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-12T00:44:09.053",
"Id": "61304",
"Score": "0",
"body": "I think you're misunderstanding underflow ... or am I? Let's say, as an example, the smallest number a `float` can represent is `0.001`. `1.0 / 10000` would result in a value of... | [
{
"body": "<p>It's not possible to avoid undefined behaviour by testing for it after the fact! If the addition overflows then there is already undefined behaviour here:</p>\n\n<pre><code>sum = a + b;\n</code></pre>\n\n<p>so attempting to test afterwards is too late. You have to test for possible overflow <em>be... | {
"AcceptedAnswerId": "37178",
"CommentCount": "9",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2013-12-11T22:45:52.610",
"Id": "37177",
"Score": "26",
"Tags": [
"c",
"integer"
],
"Title": "Simple method to detect int overflow"
} | 37177 |
<p>I've got a homework that is about methods. So first part is </p>
<blockquote>
<p>Write a method that prompts the customer for the car type. There are
three acceptable car types (E: Economy, M: Midsize, F: Fullsize). Your
method will return a valid car type.</p>
</blockquote>
<p>But the thing that I don't und... | [] | [
{
"body": "<p>From the way you describe the problem, it is clear that there only needs to be one method. That method is supposed to: \"... prompts the customer for the car type. ... Your method will return a valid car type\".</p>\n\n<p>What you have presented here, is the guts of some code which prompts the use... | {
"AcceptedAnswerId": "37182",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-11T22:57:29.323",
"Id": "37179",
"Score": "1",
"Tags": [
"java",
"homework"
],
"Title": "Which way should I use while writing this method?"
} | 37179 |
<p>I have been working on this code for quite a while and just want to make sure it is up to good standards. I know many of you will have questions, so as they come up, I will edit my initial question to provide you answers. So any ways to make this code more concise would be great. Be gentle on me, I am only a beginne... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-11T23:12:23.417",
"Id": "61284",
"Score": "0",
"body": "Not a question, but I'd appreciate it if you could put the code's intent as the title. That would help us and help you attract more reviewers."
}
] | [
{
"body": "<p>This got a bit longer than expected.</p>\n\n<ul>\n<li><p>Don't use <code>-w</code> in the shebang line. it serves no purpose if you already <code>use warnings</code>.</p></li>\n<li><p>Instead of doing error handling for <code>open</code> etc. yourself, you should <code>use autodie</code>. This is ... | {
"AcceptedAnswerId": "37184",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-11T23:03:07.917",
"Id": "37180",
"Score": "1",
"Tags": [
"array",
"beginner",
"regex",
"perl"
],
"Title": "TCPDUMP file (part of a real capture)"
} | 37180 |
<pre><code>//rename files
if(!empty($_FILES[$desktop_fieldname_1280x800]['name'])){
file_exists($desktop_filename_1280x800 = mb_strtolower($desktop_dir_1280x800 . 'wall_desktop_1280x800_' .
$_FILES[$desktop_fieldname_1280x800]['name']));
}
if(!empty($_FILES[$de... | [] | [
{
"body": "<p>The code does not rename any files, it modifies the values of certain variables.</p>\n\n<p>Using assignments as a parameter to your functions is confusing.</p>\n\n<p>You call <code>file_exists</code> but do nothing with it. It is supposed to be used to check for the existence of a file. Something... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-12T01:13:32.993",
"Id": "37188",
"Score": "2",
"Tags": [
"php",
"array"
],
"Title": "Make code more memory efficient, or shorter"
} | 37188 |
<p>According to Donald Knuth in <em>"The Art Of Computer Programming"</em>, the following is how to find the greatest common divisor of two positive numbers, <em>m</em> and <em>n</em>, using Euclid's Algorithm.</p>
<blockquote>
<ol>
<li>Divide <em>m</em> by <em>n</em> and let <em>r</em> be the remainder.</li>
<l... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-12T04:41:13.113",
"Id": "61318",
"Score": "8",
"body": "Well if `r` is never 0 and the loop never exits, blame Euclid."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-12T09:25:53.513",
"Id": "61334",
... | [
{
"body": "<p>Firstly, your implementation is (arguably) not quite correct:</p>\n\n<pre><code> else if((m < 0) || (n < 0))\n return -1;\n</code></pre>\n\n<p>The GCD of two negative numbers is perfectly well defined. However, if you really don't want the user to pass in negative numbers, make it explic... | {
"AcceptedAnswerId": "37196",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-12T01:24:43.583",
"Id": "37189",
"Score": "17",
"Tags": [
"c",
"algorithm",
"mathematics",
"error-handling"
],
"Title": "Euclid's Algorithm (Greatest Common Divisor)"
} | 37189 |
<p>I have this class for use in sorting strings such that if strings have a number in the same position it will order the numbers in increasing order.</p>
<p>Alphabetical gives:</p>
<ul>
<li>file1</li>
<li>file10</li>
<li>file2</li>
</ul>
<p>What I'm calling "number aware" string sorting should give:</p>
<ul>
<li>f... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-12T07:24:39.307",
"Id": "61324",
"Score": "0",
"body": "You want to compare digits no matter their place in the string, correct? For instance, given strings `file1img`, `file10img`, `file2img`, you want them sorted `file1img`, `file2im... | [
{
"body": "<p>In general, I think this solutions is doing the right thing, and the algorithm, in a broad sense is doing it the right way.</p>\n\n<p>There are two specific areas where I think it can be improved:</p>\n\n<ol>\n<li><p>Regular Expressions can be compiled and reused. This compareTo method is splittin... | {
"AcceptedAnswerId": "37249",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-12T02:21:20.620",
"Id": "37192",
"Score": "12",
"Tags": [
"java",
"strings",
"sorting"
],
"Title": "Number aware string sorting with comparator"
} | 37192 |
<p>Below is a script I wrote today to use CURL to monitor the length of various HTTP server outputs and output a response if this is different than 103 characters.
This is my first bash script, so I had some reading/experimenting to do and it is quite rough.
The idea is that if there are no errors, my php script will o... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-12T23:07:31.783",
"Id": "61539",
"Score": "0",
"body": "Checking for a 103-byte response is rather weird. I would recommend that you check either the HTTP status code (the return value of `curl --fail --silent`) or verify if the output... | [
{
"body": "<pre><code>#!/bin/bash\n</code></pre>\n\n<p>Minor, still good to know, <a href=\"http://en.wikipedia.org/wiki/Shebang_%28Unix%29#Portability\" rel=\"nofollow\">this is not portable</a>, f.e. BSDs will choke on it. This might not be an issue if you only intent to use it on Linux, but if you ever relea... | {
"AcceptedAnswerId": "37205",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-12T03:23:07.973",
"Id": "37199",
"Score": "2",
"Tags": [
"bash",
"curl"
],
"Title": "Bash script to monitor Webserver php script"
} | 37199 |
<p>I have the following code that gives me the indices of an array's largest value:</p>
<pre><code>public static void main(String[] args) {
float[] elementList = new float[7];
elementList[0] = 8F;
elementList[1] = 5F;
elementList[2] = 4F;
elementList[3] = 3F;
elementList[4] = 0F;
elementLi... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-13T07:55:55.820",
"Id": "61601",
"Score": "0",
"body": "What would you like the behaviour to be for an empty input? What if any of the numbers is `Float.NaN`?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12... | [
{
"body": "<p>Your code doesn't just find the largest number's index. It finds the largest <em>number</em>, then searches again for any indices that match that value.</p>\n\n<p>Here's a method that uses less searching (pseudocode):</p>\n\n<pre><code>largestValue = numbers[0];\nvector largestIndices; // Will sto... | {
"AcceptedAnswerId": "37231",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-12T06:58:41.823",
"Id": "37201",
"Score": "8",
"Tags": [
"java",
"optimization",
"array",
"floating-point"
],
"Title": "Finding all indices of largest value in an array"
} | 37201 |
<p>I wrote a simple <code>Polynomial</code> class:</p>
<pre><code>class Polynomial
def initialize(coefficients)
@coefficients = coefficients.reverse
end
def to_s
return '0' if @coefficients.all?(&:zero?)
@coefficients.map.with_index do |k, index|
" #{Polynomial.sign(k)} #{k.abs}x^#{index}... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-12T09:34:59.743",
"Id": "61335",
"Score": "1",
"body": "some bugs: a power of `x^10` will be replaced with `x0`, just like `11x` will be replaced with `1x`. In other words you never account for multi digit coefficients or powers"
},
... | [
{
"body": "<blockquote>\n <p>Is it bad that I wrote the short comments explaining what each gsub does?</p>\n</blockquote>\n\n<p>In my opinion, no. Given the complexity Regular Expressions can reach, it is wise to comment them in one way or the other so that somebody who can not instantly parse/read Regular Exp... | {
"AcceptedAnswerId": "37209",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-12T09:22:37.330",
"Id": "37207",
"Score": "4",
"Tags": [
"ruby",
"regex"
],
"Title": "Representing a long regular expression in a Polynomial class"
} | 37207 |
<p>For a WPF application, I have to sort the items in <code>ObservableCollection</code> after Added new item. </p>
<pre><code>public void UpdateSource(ObservableCollection<SomeType> source, SomeType newItem)
{
source.Add(newItem);
SortSource(source, newItem);
}
private void SortSource(ObservableCollecti... | [] | [
{
"body": "<p>Your code unnecessarily sorts the whole collection on each insert (which is likely going to be O(n log n)). It also produces two events for each insert (one for <code>Add</code> and one for <code>Move</code>), which also isn't necessary.</p>\n\n<p>What I would do:</p>\n\n<ol>\n<li>Find the index w... | {
"AcceptedAnswerId": "37211",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-12T09:32:51.680",
"Id": "37208",
"Score": "19",
"Tags": [
"c#",
"wpf"
],
"Title": "Sort ObservableCollection after added new item"
} | 37208 |
<p>Please review my code and let me know of any additions or modifications that would make this even more useable.</p>
<p>The initial idea was to create a simple Time class that has only one function: To represent an instant in time. </p>
<p>I've created this mainly because I found NodaTime to be way more than I need... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-12T12:11:52.783",
"Id": "61360",
"Score": "0",
"body": "Why are you doing this when there's already the System.DateTime type in C#?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-12T12:14:18.810",
"Id"... | [
{
"body": "<pre><code>private int _hour, _minute, _second;\n</code></pre>\n\n<p>I'd suggest to not declare multiple variables in the same line for clarity.</p>\n\n<pre><code>private int _hour;\nprivate int _minute;\nprivate int _second;\n</code></pre>\n\n<p>In case you prefixed them so that they don't collide i... | {
"AcceptedAnswerId": null,
"CommentCount": "13",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-12T12:10:45.587",
"Id": "37215",
"Score": "6",
"Tags": [
"c#",
"unit-testing",
"datetime"
],
"Title": "Class that represents an instant in Time"
} | 37215 |
<p>I received this question at a C++ programming interview:</p>
<pre><code>void memcpy(char* dst, const char* src, int numBytes)
{
int* wordDist = (int*)dst;
int* wordSrc = (int*)src;
int numWords = numBytes >> 2;
for (int i = 0; i < numWords; i++)
{
*wordDist++ = *wordSrc++;
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-12T17:40:27.463",
"Id": "61415",
"Score": "0",
"body": "Use % instead of shift/subtract to get `whatisleft`. Shifts are best for logical operations not sums. The compiler may of course choose to use a shift at the machine level."
},
... | [
{
"body": "<ul>\n<li>You are trying to re-assign a const.</li>\n<li>bit shift operator should be switched (and the whole <em>count bytes left</em>-algorithm is off)</li>\n</ul>\n",
"comments": [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-12T13:50:34.970",
"Id"... | {
"AcceptedAnswerId": "37223",
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-12T13:39:29.710",
"Id": "37221",
"Score": "5",
"Tags": [
"c++",
"algorithm",
"interview-questions"
],
"Title": "Are there any problems with this memcpy() implementation?"
} | 37221 |
<p>Based on ASP.NET, ASP.NET MVC allows software developers to build a web application as a composition of three roles: </p>
<ol>
<li>Model
<ul>
<li>A model represents the state of a particular aspect of the application.</li>
</ul></li>
<li>Controller
<ul>
<li>A controller handles interactions and updates the model t... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-12T15:30:04.463",
"Id": "37229",
"Score": "0",
"Tags": null,
"Title": null
} | 37229 |
Model-View-Controller for the ASP.NET framework | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-12T15:30:04.463",
"Id": "37230",
"Score": "0",
"Tags": null,
"Title": null
} | 37230 |
<p>This is a console app I wrote for an end-of-chapter assignment in <em>Jumping into C++</em>. The parameters were for it to have a basic password system, and if you are eager, a multiple password / username system. I am going through this book completely on my own free will. It's not through a school assignment or ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-12T18:39:06.987",
"Id": "61426",
"Score": "0",
"body": "is this `int n = sizeof(usrnam) / sizeof(string);` division, or are you initializing two variables on the same line?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationD... | [
{
"body": "<ul>\n<li><p>Try using <code>std::vector</code> instead of arrays. As a result, you'll not be required to keep track of the <code>array_size</code> in a separate variable like <code>n</code> in your case.</p>\n\n<p>Something like this:</p>\n\n<pre><code>std::vector<std::string> username;\nusern... | {
"AcceptedAnswerId": null,
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-12T18:03:25.813",
"Id": "37235",
"Score": "11",
"Tags": [
"c++",
"beginner",
"console",
"authentication"
],
"Title": "Basic password authentication system app"
} | 37235 |
<p>Our instructor told us to create a basic Java program using everything we've learned in class thus far (basic prints, selection structures, looping, GUI, arrays, etc) and being a Pokemon fan, I decided to make a basic GUI Pokedex that lets the user search for the details of a particular starter Pokemon.</p>
<p>This... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-12T18:24:17.600",
"Id": "61422",
"Score": "2",
"body": "Have you learned about methods and classes?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-12T18:32:47.423",
"Id": "61423",
"Score": "5",
... | [
{
"body": "<p>Your first problem that everything takes place in the <code>main</code> method. Much of the user interaction and initialization should be separated out into seperate methods to remove clutter.</p>\n\n<p>Then, you are confusing <em>data</em> with <em>code</em>. You have about a dozen snippets like:... | {
"AcceptedAnswerId": null,
"CommentCount": "7",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-12T18:06:07.557",
"Id": "37238",
"Score": "13",
"Tags": [
"java",
"beginner",
"pokemon"
],
"Title": "Basic Pokedex using if-else statements"
} | 37238 |
<p>Another script that is used as a token to extract information from a 3rd party application, the application does other things in the background that I don't specifically know about. </p>
<p>This code does work inside the parent application and produces the expected output.</p>
<p>Is there a nicer way to write th... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-13T02:08:46.217",
"Id": "61570",
"Score": "0",
"body": "What's `MD`? Is it declared anywhere?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-13T03:14:38.663",
"Id": "61574",
"Score": "0",
"body... | [
{
"body": "<h3>Joined declaration & assignment</h3>\n<p>This isn't necessarily a <em>bad</em> use of the <code>:</code> instruction separator, but it did surprise me. Actually, I'd even give you a star on that one:</p>\n<blockquote>\n<pre><code>Dim Age : Set Age = Parameters.Item( Bookmark , "Age"... | {
"AcceptedAnswerId": "37547",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-12T20:20:17.647",
"Id": "37254",
"Score": "2",
"Tags": [
"vbscript"
],
"Title": "pulling specific data from XML from inside 3rd party application"
} | 37254 |
<p>Minecraft is a game which also has multiplayer capabilities. You need to have an account (which needs to be verified) for playing on servers. The authentication procedure looks like this:</p>
<ol>
<li>Authenticate at the Mojang (creators of Minecraft) server with username and password</li>
<li>Retrieve a session id... | [] | [
{
"body": "<p>The logic and data encapsulation are a little disconnected here. I think it may because I have misunderstood where this class fits in to your class hierarchy.... but I don't think so. There are a few things I don't like:</p>\n\n<ul>\n<li>This Authenticate is really a 'AuthenticatedSession' and not... | {
"AcceptedAnswerId": "37270",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-12T21:51:48.770",
"Id": "37259",
"Score": "7",
"Tags": [
"java",
"authentication"
],
"Title": "Authenticating with the official Mojang (Minecraft) server"
} | 37259 |
<p>The following is used to create a masonry effect with varying height rectangles. How can I simplify and make this more elegant in Unity?</p>
<pre><code>private float startX = 0.0f;
private float startY = 0.0f;
private float posX = 0.0f;
private float posY = 0.0f;
private float prevWidth = 0;
private float prevHeigh... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-20T05:52:09.030",
"Id": "62870",
"Score": "0",
"body": "A couple of questions before answering: Do you want gaps? It looks like the taller cards at the end (#3 and #7) will lift the next row by 100 units leaving a gap. Is it possible ... | [
{
"body": "<p>Consider splitting the code that increments the column into a separate method that can be called manually. Now you do not have to pass in column or row, and index can be incremented by the <code>AddCard</code> method. This greatly simplifies usage and allows you to make use of a for loop.</p>\n\n<... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-12T22:07:52.920",
"Id": "37260",
"Score": "4",
"Tags": [
"c#",
"unity3d"
],
"Title": "Creating a masonry effect with varying height rectangles"
} | 37260 |
<p>In various projects I need to enumerate all files and folders from a specific root folder, either on a local drive or across a network. I've broken the task down into two <code>IEnumerable</code> implementations as follows:</p>
<pre><code>static IEnumerable<string> EnumeratePaths(string root)
{
if (root ... | [] | [
{
"body": "<p>Why don't you use <a href=\"http://msdn.microsoft.com/en-us/library/dd383571%28v=vs.110%29.aspx\"><code>Directory.EnumerateFiles</code></a> and <a href=\"http://msdn.microsoft.com/en-us/library/dd383462%28v=vs.110%29.aspx\"><code>Directory.EnumerateDirectories</code></a> methods? There is an overl... | {
"AcceptedAnswerId": "37269",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-12T23:08:50.010",
"Id": "37264",
"Score": "9",
"Tags": [
"c#",
"file-system"
],
"Title": "Need advice on file/directory enumeration code"
} | 37264 |
<p>I'm building pretty big application and I wonder how should I share the code between asp.net mvc website and standalone (self running) server application.
I've got some idea how I should do this but I'm not sure if I'm doing this right.
I've got Domain Entities, Services and Repositories that will be shared betwee... | [] | [
{
"body": "<p>Instead of an <code>ApplicationException</code>, your application would be better off throwing an <code>InvalidOperationException</code>, since that actually tells someone who uses your library a bit more about the problem.</p>\n\n<p>Why do you even have a variable <code>_disposed</code> if it is ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-12T23:32:19.103",
"Id": "37266",
"Score": "4",
"Tags": [
"c#",
"asp.net"
],
"Title": "Sharing domain between ASP.NET and self running application"
} | 37266 |
<p>Building a 'card' database: I'm simply learning to take input data and store to database. Incorporating JSON, PDO, SQL, and enforcing my general coding skills through PHP, hopefully.</p>
<pre><code>$query = $dbh->prepare("SELECT * FROM " . $table);
$query->execute();
$result = $query->fetchAll(PDO::FETCH_... | [] | [
{
"body": "<p>Yes, there sure is. Effectively, what you seem to be doing can be reduced to this:</p>\n\n<pre><code>$stmt = $dbh->query(\"SELECT * FROM \" . $table);\n$data = $stmt->fetchAll(PDO::FETCH_ASSOC);\necho json_encode($data);\n</code></pre>\n\n<p>I'll explain how I got to those three lines above,... | {
"AcceptedAnswerId": "37290",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-13T02:00:26.257",
"Id": "37275",
"Score": "4",
"Tags": [
"php",
"sql",
"beginner",
"json",
"pdo"
],
"Title": "Converting entire table to JSON data. Is there a better way?"... | 37275 |
<p>I've written this code in an attempt to create the Monty Hall problem and check the ratios. I would like someone to check the logic on it. I know it isn't organized well at all; I just need to see if I'm performing correctly.</p>
<p><a href="http://en.wikipedia.org/wiki/Monty_Hall_problem" rel="nofollow">If you don... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-13T03:58:09.643",
"Id": "61579",
"Score": "5",
"body": "`if (doors[newGuess] == true)` is equivalent to `if (doors[newGuess])`"
}
] | [
{
"body": "<p>You know it is not running correctly, the ratio is supposed to be 66%, not 50%.... what you really want is some help debugging it.....</p>\n\n<p>Your issue is in your random number generation.... you are only ever setting, and choosing 2 of the three doors. Have a look at this common problem:</p>\... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-13T02:19:16.667",
"Id": "37276",
"Score": "1",
"Tags": [
"java",
"simulation"
],
"Title": "Correct logic in Monty Hall Problem?"
} | 37276 |
<p>I've made a working calendar program, BUT I believe it's extremely inefficient. I think I have way too many <code>else if</code> statements: </p>
<pre><code>import java.util.*;
public class MyOwnCalendar {
public static void main(String[] args) {
Scanner keyboard = new Scanner(System.in);
Sys... | [] | [
{
"body": "<p>This is a classic example of where the Modulo operator is useful.</p>\n\n<p>The modulo allows you to determine where in a sequence you hit a repeating part of the pattern. For example, you are processing thousands of lines of data, so you want to log some output, you print a message every 1000 lin... | {
"AcceptedAnswerId": "37282",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-13T02:25:26.000",
"Id": "37278",
"Score": "3",
"Tags": [
"java",
"optimization",
"datetime",
"formatting"
],
"Title": "How to make this calender program simpler/optimized?"
} | 37278 |
<p>Using the <a href="http://www.1stwebdesigner.com/tutorials/flat-web-design-tutorial/">Flat Web Design Tutorial</a> offered at 1webdesigner I tried converting the resulting PSD file to HTML5 and CSS3. While attempting to use sectioning elements in the markup I quickly found myself lost in how to maintain semantic cod... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-13T08:14:08.463",
"Id": "61607",
"Score": "0",
"body": "Well the reason why there is so much use of elements is because they use the a grid layout. This way much of the element positions are defined with padding and margin. To exclude ... | [
{
"body": "<p>I find the CSS too low level for a good design.</p>\n\n<p>Do you really want to declare the same style for all 'h2' tags?\nThen you may not like it for some of them and will redeclare.\nThen redeclare again. Then the mess will grow over you. :)</p>\n\n<p>I rather prefer semantic approach. Give you... | {
"AcceptedAnswerId": "37361",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-13T04:59:33.680",
"Id": "37284",
"Score": "7",
"Tags": [
"html",
"css",
"html5"
],
"Title": "How can I improve the following code using HTML5 and CSS3?"
} | 37284 |
<p>I wanted to write a human readable datetime.timedelta that can be used in log files.</p>
<p>Eg, "Report issued 1 hour, 44 minutes, 20 seconds ago"</p>
<p>I noticed that casting a timedelta to str() generates something almost like what I want, but not quite.</p>
<p>To this end I wrote this:</p>
<pre><code>def ver... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-26T16:12:56.853",
"Id": "61584",
"Score": "0",
"body": "Use `xrange` instead of `range` and `str.format` instead of the `%` operator. But these are just side notes ;)"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": ... | [
{
"body": "<ul>\n<li>Use a <a href=\"http://docs.python.org/2/reference/expressions.html#conditional-expressions\" rel=\"nofollow\">ternary operator</a> in <code>\"s\"[seconds==1:]</code>.</li>\n<li>Use a generator expression to replace the <code>xstr = \"%s...</code> lines.</li>\n<li>The two for loops should u... | {
"AcceptedAnswerId": "37286",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-26T16:08:40.283",
"Id": "37285",
"Score": "5",
"Tags": [
"python",
"optimization",
"datetime",
"formatting"
],
"Title": "Efficient human readable timedelta"
} | 37285 |
<p>I've some classes (<code>Derived1</code>, <code>Derived2</code>, etc.) derived from class <code>Base</code>. All of derived classes have a following methods (reduced sample):</p>
<pre><code>void Derived1::handleTimer(const StatusType &st) {
if (!st.isOk()) {
m_timer->WakeUpPeriod(10); // wait for 10 se... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-13T08:50:46.273",
"Id": "61612",
"Score": "3",
"body": "Why would the derived classes have to override `handleTimer()`? Couldn't they just inherit it?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-13T09:5... | [
{
"body": "<p>The use of <code>doSomeSpecific</code> inside of <code>handleTimer</code> is remarkably similar to the <a href=\"http://en.wikipedia.org/wiki/Template_method_pattern\" rel=\"nofollow\">Template Pattern</a>.</p>\n\n<p>If there is no base implementation of <code>doSomeSpecific</code> you might consi... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-13T08:46:07.447",
"Id": "37294",
"Score": "7",
"Tags": [
"c++",
"inheritance",
"boost"
],
"Title": "Moving method from derived class to base"
} | 37294 |
<p>I am trying to import a .csv file, clean the contents, and make sure all the errors are eliminated.</p>
<ul>
<li>IO error</li>
<li>file format error</li>
<li>data error</li>
</ul>
<p>I am using the snippet below. Could someone help me clean it and make it more pythonic?</p>
<pre><code>try:
fl = request.FILES... | [] | [
{
"body": "<p>Firstly, you should <code>raise</code> not <code>return</code> your errors.</p>\n\n<p>Secondly, <code>try:</code> with a bare <code>except:</code> is bad practice (e.g. <a href=\"http://blog.codekills.net/2011/09/29/the-evils-of--except--/\" rel=\"nofollow\">http://blog.codekills.net/2011/09/29/th... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-13T10:18:28.193",
"Id": "37298",
"Score": "6",
"Tags": [
"python",
"django",
"csv"
],
"Title": "Creating a pythonic snippet to read and clean .csv files"
} | 37298 |
<p>I'm working on a website on ASP.NET MVC4 and EF5. I want to ensure that only modified values are updated in the database. I'm using a unit of work pattern and repositories for data work. Here's the code for a generic repository. I've two questions, and need a code review for the following code.</p>
<ol>
<li><p><em... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-13T19:14:45.243",
"Id": "61675",
"Score": "0",
"body": "So this is assuming the T entity is not already an object obtained directly from the dbcontext already?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-1... | [
{
"body": "<p>Why bother checking if the value/property has been changed? You are just adding additional complexity for no reason. Sure, it might be <em>slightly!</em> faster to only update modified values, but in return you are adding an overhead to keep track of the modified values, which will diminish whatev... | {
"AcceptedAnswerId": "37306",
"CommentCount": "7",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-13T12:57:24.690",
"Id": "37304",
"Score": "35",
"Tags": [
"c#",
"entity-framework",
"asp.net-mvc-4"
],
"Title": "Update only modified fields in Entity Framework"
} | 37304 |
<p>I have many small but similar classes like these:</p>
<pre><code>class DepartmentSerializer < Serializer
self.root = false
attributes :id, :name
has_many :employees, serializer: EmployeeSerializer
has_one :location, serializer: LocationNameSerializer
end
class DepartmentWithManagersSerializer < Seria... | [] | [
{
"body": "<p>Using inheritance, first you can clean up your structure as following:</p>\n\n<pre><code>class DepartmentNameSerializer < Serializer\n self.root = false\n attributes :id, :name\nend\n\nclass DepartmentSerializer < DepartmentNameSerializer\n has_many :employees, serializer: EmployeeSeriali... | {
"AcceptedAnswerId": "37444",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-13T13:49:56.223",
"Id": "37305",
"Score": "5",
"Tags": [
"object-oriented",
"ruby",
"serialization",
"active-record"
],
"Title": "Classes to serialize departments and their em... | 37305 |
<p>The specific issue is this: I am writing to a file and want to output a new line after each line written. If I use a normal loop without any further checks, this will create a blank line at the very end of the file for no reason. So I need to do this every time <em>except</em> the last one.</p>
<p>Despite the fac... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-13T19:36:14.340",
"Id": "61680",
"Score": "7",
"body": "*Somebody has to say this... a text file is a series of lines. A line includes a newline terminator. A file that does not have a newline as its final character **is not a text fil... | [
{
"body": "<p>I presume <code>lines</code> is a Collection of some sort. One option that has slightly less of a smell (although it still is odoriferous), is to use an iterator, which will essentially do the same work, but will be more readable:</p>\n<pre><code>for (Iterator<String> it = lines.iterator(); ... | {
"AcceptedAnswerId": "37310",
"CommentCount": "11",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-13T14:38:49.163",
"Id": "37309",
"Score": "38",
"Tags": [
"java",
"iteration"
],
"Title": "Perform instruction in loop every time except the last time?"
} | 37309 |
<p>I have this JavaFX code which is used for listing groups by ID and name:</p>
<pre><code>import java.util.List;
import javafx.application.Application;
import javafx.beans.value.ChangeListener;
import javafx.beans.value.ObservableValue;
import javafx.scene.Scene;
import javafx.scene.control.ComboBox;
import javafx.sc... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-13T20:32:14.450",
"Id": "61687",
"Score": "0",
"body": "What do you mean by \"easy for use\"? Are you planning on letting other people use this code as (part of) a library?"
}
] | [
{
"body": "<p>I have to admit that I don't know much about JavaFX, but I do know Java so I can help you with the things I can come up with:</p>\n\n<p>If by \"more compact\" you mean \"less number of lines\" there are several things that you can do:</p>\n\n<ul>\n<li>Use Java coding conventions and don't put <cod... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-13T20:24:49.627",
"Id": "37320",
"Score": "4",
"Tags": [
"java",
"javafx"
],
"Title": "Listing groups by ID and name"
} | 37320 |
<p>Basically, this function returns a list of flights for an airline. But if the airline doesn't exist, I want to throw some custom runtime exception. If that airline does exist, I want to return a list of flights (which could potentially be empty).</p>
<p>Is this is the standard way of doing things in Scala, or is th... | [] | [
{
"body": "<ol>\n<li><p>The <code>maybeAirline</code> variable isn't necessary. Note that the type annotation in the declaration is optional, and can easily be inferred by the compiler. So I would change that to:</p>\n\n<pre><code>def getFlightsForAirline(id: Long): Try[Option[List[Flight]]] =\n Airline.getByI... | {
"AcceptedAnswerId": "37347",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-13T20:30:31.440",
"Id": "37321",
"Score": "8",
"Tags": [
"beginner",
"scala",
"error-handling",
"null"
],
"Title": "Idiomatic Scala try option code block"
} | 37321 |
<p>In my code I declared a dictionary to store various counters</p>
<pre><code>let counters = Dictionary<Type, int>()
</code></pre>
<p>Later, I need to generate several labels using these counters, like this:</p>
<ul>
<li>First type a label is generated for a given type, it should consist of the type name itse... | [] | [
{
"body": "<p>You can indeed use <code>match</code>, together with the fact that F# converts methods with <code>out</code> parameters (like <code>Dictionary.TryGetValue()</code>) to methods returning tuples:</p>\n\n<pre><code>let label =\n match counters.TryGetValue(t) with\n | (true, counter) ->\n ... | {
"AcceptedAnswerId": "37334",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-13T20:55:08.070",
"Id": "37323",
"Score": "4",
"Tags": [
"functional-programming",
"f#"
],
"Title": "Improving F# conditional assignment with match expression"
} | 37323 |
<p>I'm starting with object oriented programming, but I know PHP procedural style "pretty well" I'd say. I'm working on a ticket support site for this website.</p>
<p>This <code>mysqliSingleton</code> class was in a question I previously visited. I only added the <code>set_charset()</code> method to feet my database. ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-13T16:07:43.180",
"Id": "61702",
"Score": "1",
"body": "Question: why are you applying `htmlentities` on a string before you store it in a database? That function (or rather: `htmlspecialchars`) is for *outputting* text in an HTML cont... | [
{
"body": "<p>Well, although this code belongs to Codereview@stackexchenge, but as nobody cares to follow any rules here - so I would.</p>\n\n<p>There are too much problems with your code, ut to outline most:</p>\n\n<ol>\n<li>It seems you don't quite understand what singleton is and why use it.</li>\n<li><a hre... | {
"AcceptedAnswerId": "37329",
"CommentCount": "9",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-13T16:03:00.373",
"Id": "37327",
"Score": "1",
"Tags": [
"php",
"object-oriented",
"mysqli",
"singleton"
],
"Title": "OOP MySQLi singleton"
} | 37327 |
<p>I have a concept of the user having many API keys, but the API key belongs to the user, so I did the following:</p>
<p><strong>config/routes.rb</strong></p>
<pre><code> resources :users do
resources :api_keys, path: '/developmentcenter'
end
</code></pre>
<p><strong>app/models/api_key.rb</strong></p>
<pre>... | [] | [
{
"body": "<p>Quite a few things sprang to mind immediately, but as I delved deeper I realized that, well, there are a lot of issues. So here goes.</p>\n\n<h2>Outright bugs, I think</h2>\n\n<p><code>User.apikeys</code> - what? Shouldn't that be <code>@user.api_keys</code>? But I notice you don't test the <code>... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-13T23:40:11.340",
"Id": "37335",
"Score": "2",
"Tags": [
"beginner",
"ruby",
"ruby-on-rails",
"api"
],
"Title": "Rails 4.0 api_key implementation"
} | 37335 |
<p>This Caesar cipher can take any integer and it will wrap around the correct number of times and still perform the encryption/decryption.</p>
<p>Let's say we have a text file named <code>dog</code>.</p>
<blockquote>
<p>~$ cat dog<br>
The quick brown fox jumps over the lazy dog...</p>
</blockquote>
<p><br>
If t... | [] | [
{
"body": "<ol>\n<li>Macros in C are typically named in <code>UPPERCASE</code>.</li>\n<li><p>You can reduce some code duplication in this block:</p>\n\n<pre><code> if(islower(ec)) {\n wrap = (ec + offset - lstart) % nalpha;\n wrap = (wrap < 0) ? nalpha + wrap : wrap; \n\n } else {\n ... | {
"AcceptedAnswerId": "37431",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-14T02:49:10.323",
"Id": "37336",
"Score": "10",
"Tags": [
"c",
"caesar-cipher"
],
"Title": "Caesar Cipher that takes an arbitrary offset"
} | 37336 |
<p>I have written a simple desk accessory in Proccessing called Trip, you can see it below. It is working, but it is very simple, and needs more features.</p>
<pre><code>import processing.pdf.*;
PImage tardis;
int flash = 0;
void setup() {
size(256, 256);
frame.setResizable(true);
tardis = loadImage("TARDIS1.j... | [] | [
{
"body": "<p>How about something where if you change the background to a particular color, something cool happens? </p>\n\n<p>Like if it turns full black,<code>(0,0,0)</code>, it causes an image to pop up on screen. </p>\n",
"comments": [
{
"ContentLicense": "CC BY-SA 3.0",
"Creation... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-14T07:23:06.020",
"Id": "37340",
"Score": "0",
"Tags": [
"processing"
],
"Title": "New features for Processing game/desk accessory"
} | 37340 |
<p>Is this a good C program for splitting a command line without doing any expansion on it? Don't worry too much about <code>main()</code> and the output -- those are for testing.</p>
<pre><code>#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include <assert.h&... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-14T14:25:51.900",
"Id": "61757",
"Score": "0",
"body": "No, it's a [lexer](http://stackoverflow.com/q/2842809/89999) :)"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-14T16:17:14.430",
"Id": "61765",
... | [
{
"body": "<p>I doubt that this code actually works. Especially <code>pullwhitespace</code> doesn't do what you probably intended (hint: it doesn't modify the argument, it makes a copy of the pointer and advances it). Have you tested it before submitting it for review here?</p>\n\n<p>Anyway: You might want to h... | {
"AcceptedAnswerId": null,
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-14T07:37:33.420",
"Id": "37341",
"Score": "3",
"Tags": [
"c",
"parsing"
],
"Title": "Splitting a command line in C"
} | 37341 |
<p>Here's my attempt at <a href="https://codereview.meta.stackexchange.com/q/1245/9357">Weekend Challenge #3</a>.</p>
<p>Key characteristics of this Python entry are:</p>
<ul>
<li>The strategy is to alternate between "auto-complete" (making simple deductions such as naked singles and hidden singles) and recursive gue... | [] | [
{
"body": "<p>Looping over the rows and columns in <code>naked_singles</code> and <code>hidden_singles</code> is costing a lot of time. You can achieve those effects more efficiently by tracking the possible values available to each cell, row, column, and box. The last three can be modeled using a <code>Group</... | {
"AcceptedAnswerId": "37436",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-14T09:06:31.647",
"Id": "37343",
"Score": "12",
"Tags": [
"python",
"game",
"recursion",
"sudoku",
"community-challenge"
],
"Title": "Sudoku solver using simple deductions... | 37343 |
<p>I have a small program which makes uses of pycparser to parse C header files. The code, unfortunately, kinda sprawls out everywhere to handle the different cases (example below).</p>
<p>What's the best way to make this more Pythonic? I thought about case-statements, but those don't exist in Python. Is splitting the... | [] | [
{
"body": "<p>I don't think you're going to fundamentally be able to solve the sprawl, as you have a problem composed of lots of small details. These won't go away no matter how well you organize them, but there are options that help you organize them in ways with lesser algorithmic performance hits.</p>\n\n<p>... | {
"AcceptedAnswerId": "37351",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-14T13:47:38.540",
"Id": "37348",
"Score": "6",
"Tags": [
"python",
"parsing",
"recursion"
],
"Title": "Using pycparser to parse C header files"
} | 37348 |
<p>I am writing a cron job to manipulate and transfer remote data.
I need to cache data from a table, process it, merge with previous table, iterate the process, and eventually send the result data to remote database.</p>
<p>Here is a basic in-memory cache storage with thin simple CRUD type API.
It has to store hashes... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-14T20:56:43.720",
"Id": "61826",
"Score": "0",
"body": "Actually I can not understand why do you call it ***cache***?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-15T01:23:14.750",
"Id": "61851",
... | [
{
"body": "<p>Ok, since there is no answer, I'll write it myself what would have been really a great help and what I have discovered:</p>\n\n<p>The main problem with this code is the usage of many expensive operations responsible for slow execution. It seems the split into keys and values before storing as well... | {
"AcceptedAnswerId": "37663",
"CommentCount": "18",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-14T15:21:57.800",
"Id": "37349",
"Score": "5",
"Tags": [
"php",
"database",
"api",
"cache"
],
"Title": "In-memory data cache architecture for data transfer"
} | 37349 |
<pre><code>#!/usr/bin/python3
# Description: Python script that will mount FTP-Server via SSHFS protocol
import sys
import os
import subprocess
def mount():
#Function for mounting the networked drive
if os.path.exists('/home/user/MNT/MEDIA/'):
print('Network drive is mounted')
un = input("To unm... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-14T16:40:15.043",
"Id": "61771",
"Score": "0",
"body": "Please provide some more context. Looking at the code tells us one what you are actually doing, but having a general description of what you want to do may give some opportunity t... | [
{
"body": "<p>Efficiency is just not an issue in this kind of task. As \"glue\" code, it's not computationally intensive. There are, however, some maintainability issues.</p>\n\n<ul>\n<li><p>In <code>mount()</code>, the basic outline is:</p>\n\n<pre><code>def mount():\n if os.path.exists('/home/user/MNT/ME... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-14T15:31:22.247",
"Id": "37350",
"Score": "3",
"Tags": [
"python",
"linux"
],
"Title": "Is this an efficient way of mounting a file-system via SSH (SSHFS)?"
} | 37350 |
<p>I would like to increase my performance of js code write a clean code... can you tell me how to do it... providing my fiddle below with js code...</p>
<p><a href="http://jsfiddle.net/YYg8U/" rel="nofollow">http://jsfiddle.net/YYg8U/</a></p>
<pre><code>var myNumbersToSort = [-1, 2, -3, 4, 0.3, -0.001];
function ge... | [] | [
{
"body": "<p>In code you posted, you pass through array three times instead of one:</p>\n\n<ul>\n<li><p>1st pass when pushing absolute values to auxillary array</p></li>\n<li><p>2nd pass when searching for minimum value (in <code>Math.min</code>)</p></li>\n<li><p>3rd pass when you get the index of minimum valu... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-14T15:46:38.803",
"Id": "37352",
"Score": "4",
"Tags": [
"javascript",
"jquery",
"performance"
],
"Title": "cleaning up and increasing performance of js code"
} | 37352 |
<p>I have this code:</p>
<pre><code>switch (c) {
case '-': break;
case '0': e = expr(j).reduce(C1); e=not(e); a = and(a, e); break;
case '1': e = expr(j).reduce(C1); a = and(a, e); break;
default: throw new Exception("Unexpected cube value, " + c);
}
</code></pre>
<p>The cases 0 and 1 are only differe... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-14T16:40:11.217",
"Id": "61770",
"Score": "1",
"body": "Could you provide some more context about this code? What is `a` and `e`? What does `and` though? What does `expr(j).reduce(C1)` do? You don't need to provide the code for them, j... | [
{
"body": "<p>There are two significantly different ways I can think of to rewrite your code. </p>\n\n<p>The first is to put <code>case '0'</code> and <code>case '1'</code> together by letting one case 'fall through', and then using the ternary operator with in the code to see if we should invert or not.</p>\n\... | {
"AcceptedAnswerId": null,
"CommentCount": "8",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-14T16:23:39.063",
"Id": "37357",
"Score": "-2",
"Tags": [
"java"
],
"Title": "Common factor in some cases"
} | 37357 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.