body stringlengths 25 86.7k | comments list | answers list | meta_data dict | question_id stringlengths 1 6 |
|---|---|---|---|---|
<p>I recently have given a coding test in a reputable IT company. There were three coding questions. </p>
<p>They refused me by saying that</p>
<blockquote>
<p>as we felt they didn't demonstrate the level of technical depth we're
seeking from candidates</p>
</blockquote>
<p>Please help me understanding what type... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-23T15:44:17.180",
"Id": "89067",
"Score": "0",
"body": "Can you give a bit more context on the task? Was it related to any real system or just imaginary? And what did the original code look like?"
},
{
"ContentLicense": "CC BY-... | [
{
"body": "<blockquote>\n <p>as we felt they didn't demonstrate the level of technical depth we're seeking from candidates</p>\n</blockquote>\n\n<p>This is a stock response. The engineers who interviewed you probably said something like “nah, not good enough”, so someone in HR sent you their stock response. Do... | {
"AcceptedAnswerId": "51551",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-23T13:57:54.030",
"Id": "51526",
"Score": "6",
"Tags": [
"java",
"interview-questions",
"iteration"
],
"Title": "Missing level of technical depth (Recursive to Iterative)"
} | 51526 |
<p>This code is a slot machine simulator that uses elements of both HTML and JavaScript. Please pardon the lack of comments.</p>
<pre><code><!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
<title>www.loseloselose.c... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-23T14:47:10.030",
"Id": "89036",
"Score": "0",
"body": "why do you reload the page?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-23T14:48:29.563",
"Id": "89038",
"Score": "0",
"body": "It is ... | [
{
"body": "<p>Some improvements: </p>\n\n<p>Use of refresh() as a function used to generate the number values, which generate the values AND writes into the DOM element.</p>\n\n<p>Use of a function to manage all user messages, write_message()</p>\n\n<p>Remove of all the old fashion HTML tags, and change it for ... | {
"AcceptedAnswerId": null,
"CommentCount": "7",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-23T14:26:28.057",
"Id": "51532",
"Score": "8",
"Tags": [
"javascript",
"html",
"simulation",
"svg"
],
"Title": "HTML / JS Slot Machine Simulator"
} | 51532 |
<p>I decided to refactor the code for <a href="https://codereview.stackexchange.com/questions/48177/how-could-i-have-approached-this-responsive-image-gallery-differently">a responsive image gallery</a>, that I setup not too long ago. Following the suggestions @joseph-the-dreamer made, and some other best practices, I c... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-30T20:33:58.397",
"Id": "90263",
"Score": "0",
"body": "Will you post a fiddle (or similar) of this so the intended functionality is explicit?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-30T21:00:50.510... | [
{
"body": "<p>First, I think you'd be better off if you had a representation of the gallery\nas data (following the <a href=\"http://www.faqs.org/docs/artu/ch01s06.html\" rel=\"nofollow noreferrer\">Rule of Representation</a>).\nIt would go something like this:</p>\n\n<h2>A Simpler Method</h2>\n\n<p>Get your ob... | {
"AcceptedAnswerId": "52135",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-23T14:55:17.160",
"Id": "51540",
"Score": "10",
"Tags": [
"javascript",
"jquery"
],
"Title": "Responsive Foundation Orbit Image Gallery"
} | 51540 |
<p>Is there a way to use <a href="http://en.wikipedia.org/wiki/Continuation-passing_style" rel="noreferrer">CPS</a> in this code to make the two insert functions tail-call optimized?</p>
<pre><code>defmodule BTree do
defstruct tree: {node: nil, left: nil, right: nil}
def new(element), do: %BTree{tree: {node: elem... | [] | [
{
"body": "<p>I would like to slightly rewrite the problem before making it continuation based because it will make it clearer and avoid duplication:</p>\n\n<pre><code>defmodule BTree do\n defstruct tree: nil\n def new(e), do: %BTree{tree: {e, nil, nil}}\n\n def insert(%BTree{tree: root}, element) do\n %B... | {
"AcceptedAnswerId": "51548",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-23T14:55:40.873",
"Id": "51541",
"Score": "5",
"Tags": [
"elixir"
],
"Title": "How could this be written using continuation passing style?"
} | 51541 |
<p>I recently have given a coding test in a reputable IT company. There were three coding questions.</p>
<p>They refused me by saying that</p>
<blockquote>
<p>as we felt they didn't demonstrate the level of technical depth we're seeking from candidates</p>
</blockquote>
<p><strong>Question 1 :</strong> <a href="ht... | [] | [
{
"body": "<p>For an interview question, I would consider this to be \"Way Overkill\". I'm going to assume it works (it looks functional), but it has a lot of abstraction that is not necessary.</p>\n\n<p>Some of the significant items I see are:</p>\n\n<ul>\n<li><p>Your Tree interface has an inner static-final c... | {
"AcceptedAnswerId": "51578",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-23T15:13:52.183",
"Id": "51545",
"Score": "6",
"Tags": [
"java",
"interview-questions",
"tree",
"depth-first-search"
],
"Title": "Missing level of technical depth (Flatten Tre... | 51545 |
<p>I recently have given a coding test in a reputable IT company. There were three coding questions.</p>
<p>They refused me by saying that</p>
<blockquote>
<p>as we felt they didn't demonstrate the level of technical depth we're seeking from candidates</p>
</blockquote>
<p><strong>Question 1 :</strong> <a href="ht... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-11-28T01:21:34.597",
"Id": "129850",
"Score": "0",
"body": "I don't think you should post coding test questions or answers online unless you're sure they are no longer being used by recruiters. In any case, this is a good test of algorit... | [
{
"body": "<p>The <code>while</code> loop in <code>addToCommitPath</code> could be extracted to another method like:</p>\n\n<pre><code>private int getIndex(int beginingIndex, String hash, String[] commitHashes) {\n for(int index = beginingIndex; index < commitHashes.length; index++) {\n if(hash.equ... | {
"AcceptedAnswerId": "51561",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-23T15:15:40.113",
"Id": "51547",
"Score": "10",
"Tags": [
"java",
"interview-questions",
"graph",
"git"
],
"Title": "Missing level of technical depth (Common Ancestor)"
} | 51547 |
<p>I made a function to find the element that yields the largest value when put into a custom functor.</p>
<p>I think this is missing from the STL. I can think of three ways to do this in STL:</p>
<ul>
<li>Transform the container by the functor. Find the maximum in the transformed version. Take the corresponding elem... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-23T16:18:15.340",
"Id": "89081",
"Score": "0",
"body": "While the standard does not offer applying functors before comparing it allows to specify a custom comparator. This makes it easy to implement a custom comparator that takes a fun... | [
{
"body": "<p>Setting aside the std::accumulate discussion, I have one recommendation. The signature</p>\n\n<pre><code>template<typename Iterator, typename UnaryFun>\nauto maxElementBy(Iterator first, Iterator last, UnaryFun criterion)\n -> Iterator\n</code></pre>\n\n<p>seems to be more flexible. It... | {
"AcceptedAnswerId": null,
"CommentCount": "8",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-23T16:10:32.347",
"Id": "51552",
"Score": "5",
"Tags": [
"c++",
"algorithm",
"c++11"
],
"Title": "Find element yielding the largest value w.r.t. custom function"
} | 51552 |
<p>In this project (C# Win forms) I'm supposed to calculate wages of employees.</p>
<p>These are the steps:</p>
<ol>
<li><p>Calculate earnings from Attendance data. Here all regular earnings like <code>BasicSalary</code>, <code>OverTimeAmount</code> etc will be calculated.</p></li>
<li><p>Then these earning details w... | [] | [
{
"body": "<p>It seems there is enough missing here it is hard to determine intent of some of your code so I just made assumptions and changed as I thought some good practices would dictate the code to be.</p>\n\n<p>I think the usage of public members is really bad. It allows for anyone to modify them in any wa... | {
"AcceptedAnswerId": "51761",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-23T17:21:26.667",
"Id": "51558",
"Score": "2",
"Tags": [
"c#",
"winforms",
"mvp"
],
"Title": "Employee wage/salary calculation MVP solution"
} | 51558 |
<p>I'm trying to read data from an array. I manage to get the information I want but my code is extremely inefficiently written.</p>
<p>My array looks like this:</p>
<pre><code>var arTab:Array = new Array();
arTab[0] = new Array(2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011, 2012);
var promilleTab:Array ... | [] | [
{
"body": "<p>Sure,</p>\n\n<p>you are basically copy pasting to keep accessing <code>arTab</code> and <code>promilleTab</code>, you might instead just derive the indexes in <code>arTab</code> from <code>bruddListe</code> and <code>arListe</code>, like this:</p>\n\n<pre><code>function skrivUt(Event:MouseEvent)\n... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-20T11:39:54.230",
"Id": "51563",
"Score": "8",
"Tags": [
"array",
"actionscript-3"
],
"Title": "Reading code from array efficiently"
} | 51563 |
<p>I have a multidimensional array of house properties:</p>
<pre><code>$array = array(
array('apn' => 345345353, 'sqft' => 1121, 'address' => '12 Lincoln Ave.'),
array('apn' => 345345351, 'sqft' => 1643, 'address' => '13 Lincoln Ave.'),
array('apn' => 345345352, 'sqft' => 1222, 'add... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-21T21:55:54.983",
"Id": "89100",
"Score": "1",
"body": "I can see the need to sort here, but considering that you have to group by street name first there's no need to sort any multidimensional array. Just break up the original into ar... | [
{
"body": "<p>While this task can be written as a single loop over your data, it would involve unnecessarily convoluted conditionals and temporary variables which will likely be an irritation to future developers (that person might actually be you) that may need to read your code.</p>\n\n<p>I respect your desir... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-21T21:51:07.953",
"Id": "51564",
"Score": "3",
"Tags": [
"php",
"array",
"sorting"
],
"Title": "Sort by value in multidimensional array"
} | 51564 |
<p>This is the first time I tried to solve a problem and wrote code for it, rather than learning some code and trying out to see what I might be able to do with it. As such, it's not much, but I'd like any tips and help about how I wrote this. Basically, I tried to write a program to find the biggest number in a list o... | [] | [
{
"body": "<p>The most obvious thing I can see is that you <em>wrote a loop</em> when one was not needed.</p>\n\n<pre><code>largest = max(n)\n</code></pre>\n\n<p>Also, check your boundary conditions. What happens if no numbers are entered?</p>\n",
"comments": [
{
"ContentLicense": "CC BY-SA 3.... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-21T03:50:14.820",
"Id": "51565",
"Score": "1",
"Tags": [
"python",
"beginner"
],
"Title": "Finding the biggest number in a list of numbers"
} | 51565 |
<pre><code>data =
[ { 'name' => 'category1',
'subCategory' => [ {'name' => 'subCategory1',
'product' => [ {'name' => 'prodcutName1',
'desc' => 'desc1'},
{'name' => 'prodcutName2',
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-16T04:34:56.017",
"Id": "89106",
"Score": "0",
"body": "Are you able to change the source data hash to a different format?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-16T04:44:46.330",
"Id": "89107"... | [
{
"body": "<p>Here's a nice recursive solution, that creates <code><key>value</key></code> from <code>'key'=>'value'</code> entries in your hash. If the value is an array, it instead recurses, using the key name as a wrapper element.</p>\n\n<pre class=\"lang-ruby prettyprint-override\"><code>requ... | {
"AcceptedAnswerId": "51570",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-16T02:35:07.677",
"Id": "51569",
"Score": "5",
"Tags": [
"ruby",
"xml"
],
"Title": "Building XML by enumerating through array & hashes"
} | 51569 |
<p>I'm trying to make sure I understand how to write clean and robust idiomatic Scala, so I wrote a custom generic implementation <code>sequence</code> of type <code>A[B[C]] => B[A[C]]</code> (instead of <code>TraversableOnce[Future[A]] => Future[TraversableOnce[A]]</code> -- I know something like this exists in ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2015-01-04T20:24:55.197",
"Id": "137674",
"Score": "1",
"body": "Core Scala lacks the abstractions you are looking for (it contains only function types in this regard)."
}
] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-23T18:18:36.213",
"Id": "51571",
"Score": "4",
"Tags": [
"scala"
],
"Title": "Custom Scala implementation of generic Future.sequence"
} | 51571 |
<p>I'm working on some precompilation operations for a world compiler. Currently to identify flags placed by the level designer I need recognize when a specific entity exists at specific coordinates from the flag's origin. I need to generate a list of offset coordinates from the origin(and include the origin) in string... | [] | [
{
"body": "<p>This code is effectively calculating a set of offsets from the origin and adding them in turn to get the final co-ordinates. However, you're calculating the offsets each time for every flag and the question implies that this is done many times. Better to calculate them up-front, then iterate thro... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-23T18:54:41.087",
"Id": "51575",
"Score": "6",
"Tags": [
"c#",
"strings",
".net"
],
"Title": "Tight loop, string manipulation and calculations"
} | 51575 |
Pawn, formerly known as Small, is an open source scripting language primarily intended as an embeddable scripting language. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-23T20:40:43.450",
"Id": "51580",
"Score": "0",
"Tags": null,
"Title": null
} | 51580 |
<p>I want to understand how to properly unit test a function such as this. The function doesn't return anything, but it does call other functions that themselves have already been unit tested. My understanding is that in order to properly unit test this method I will have to shim the dependant methods - otherwise this ... | [] | [
{
"body": "<p>There was no need to delete the post on Stack Overflow, it belonged there just fine; perhaps even better than here.</p>\n\n<p>You don't have to shim anything. Integration tests are tests that use an external dependency (system time, external API, filesystem, etc). In your case all your \"dependenc... | {
"AcceptedAnswerId": "51584",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-23T20:44:22.960",
"Id": "51581",
"Score": "4",
"Tags": [
"c#",
"unit-testing"
],
"Title": "Using shims to turn my integration tests into unit tests"
} | 51581 |
<p>How does it look? Comments, code correctness, etc.</p>
<pre><code>//Function Prototypes
void buildArray(int anArray[]);
void printArray(int anArray[], int start, int end);
void sortArray(int start, int end, int masterArray[], int tempArray[]);
void mergeArray(int start, int split, int end, int masterArray[], int ... | [] | [
{
"body": "<ul>\n<li><p>The comment about the globals is noisy, but at least you're aware that they're bad. You can reduce the possibility of bugs by removing them, which is always good idea. Otherwise, it could suggest that this implementation needs reworking, especially if you do encounter some bugs.</p>\n\... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-23T21:12:36.440",
"Id": "51585",
"Score": "5",
"Tags": [
"c++",
"array",
"sorting",
"mergesort"
],
"Title": "Count array inversions merge sort"
} | 51585 |
<p>I have some .csv files compressed in .bz2 format. I need to take a subset of the records (and data) and switch to .gz.</p>
<p>I am not happy with the performance. Is there a more efficient way to do it?</p>
<pre><code>//For each file in a folder:
try (BufferedReader br = new BufferedReader(new InputStreamReader(
... | [] | [
{
"body": "<p>Well, your code is neat, and you use the Try-with-resources structures well. There is one potential bug, which is that there may be lines whihc have a 'successful' <code>part[0]</code>, but no <code>part[3]</code> which would cause an IndexOutOfBoundsException.</p>\n\n<p>As for the performance, th... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-23T21:21:20.227",
"Id": "51586",
"Score": "5",
"Tags": [
"java",
"csv",
"compression"
],
"Title": "Processing compressed .csv files"
} | 51586 |
<p>This little function can make object creation much easier.
Sometimes you need to switch between representing your data as objects vs. having the members in separate containers.</p>
<p>Example:</p>
<pre><code>class Foo {
public:
Foo(int a_, double b_): a(a_), b(b_){}
int a;
double b;
};
</code></pre>
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-24T02:39:43.673",
"Id": "89156",
"Score": "0",
"body": "Couldn't `Foo` just be a `struct`?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-24T12:56:20.853",
"Id": "89181",
"Score": "0",
"body": ... | [
{
"body": "<p>I see one error:</p>\n\n<pre><code>assert(std::all_of(sizes.begin(), sizes.end(), [&](size_t s){return s=sizes[0];}));\n ^\n</code></pre>\n\n<p>This is an assignment, not a test. You probably meant <code>s == sizes[0]</code>.<... | {
"AcceptedAnswerId": "51627",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-24T02:25:46.670",
"Id": "51594",
"Score": "4",
"Tags": [
"c++",
"c++11",
"constructor"
],
"Title": "Zip-like construction of objects from parameter collections"
} | 51594 |
<p>I want to compare the values in two arrays. The order of the values doesn't matter. Basically they are two Sets. This function returns true if the values are the same in both arrays, or false otherwise.</p>
<pre><code>function compareSets(a1, a2) {
if (a1.length !== a2.length) {
return false;
}
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-24T03:12:48.567",
"Id": "89158",
"Score": "0",
"body": "You could use [actual `set` functionality like here](https://github.com/jfriend00/Javascript-Set/blob/master/set.js) which has an `.equals()` and `.diff()` method and others for c... | [
{
"body": "<p>You can use one loop and compare each other on each iteration. You can use <code>indexOf</code> to check for one value on the other.</p>\n\n<pre><code>function compareSets(a1, a2) {\n //length check (you said it was safe to assume different lengths is not the same set)\n if (a1.length !== a2.len... | {
"AcceptedAnswerId": "51600",
"CommentCount": "7",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-24T02:59:18.537",
"Id": "51595",
"Score": "5",
"Tags": [
"javascript",
"array"
],
"Title": "JavaScript Array Comparison (aka Set Comparison)"
} | 51595 |
<p>I am starting an angular app and I was wondering if I am on the right track with this. I worked on my last angular app when I was just a youngun who didn't understand the important of designing the code properly. I failed so hard at keeping the code clean and maintainable, mostly due to not understanding directives ... | [] | [
{
"body": "<p>This is a funny question because</p>\n\n<ol>\n<li>One of the most readable Angular submissions on CR</li>\n<li>There is probably too much logic in the controller indeed</li>\n</ol>\n\n<p>Some observations:</p>\n\n<ul>\n<li>It seems the controller knows too much, it should not know that <code>5</co... | {
"AcceptedAnswerId": "56571",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-24T03:05:11.200",
"Id": "51596",
"Score": "14",
"Tags": [
"javascript",
"angular.js",
"controller"
],
"Title": "AngularJS Todo List - too much controller logic?"
} | 51596 |
<pre><code>(define (tridiagonal n)
(build-list n
(lambda (x)
(build-list n
(lambda (x)
(cond
[(= x n) 2]
[(or (= x (- n 1))
(= x ... | [] | [
{
"body": "<p>Your code doesn't actually work, because your two lambdas both used <code>x</code> as the parameter name, and the inner one shadows the outer one. Here's a fixed version:</p>\n\n<pre><code>(define (tridiagonal n)\n (build-list n\n (lambda (x)\n (build-list n\n ... | {
"AcceptedAnswerId": "51602",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-24T05:34:09.000",
"Id": "51599",
"Score": "2",
"Tags": [
"matrix",
"lambda",
"racket"
],
"Title": "Tridiagonal Lists in Scheme"
} | 51599 |
<p>This is not "real life" code. I'm trying to expand upon the well known <code>Sakila</code> sample database for MySQL to make it more complex. Step 7 (or 6) is running surprisingly slow.</p>
<p>PS: Note these are all separate queries executed against the same database in the order specified. </p>
<ol>
<li><p>Add c... | [] | [
{
"body": "<p>I've never played with <a href=\"/questions/tagged/mysql\" class=\"post-tag\" title=\"show questions tagged 'mysql'\" rel=\"tag\">mysql</a>, so this may be completely wrong, but if I get it right the <code>WHILE</code> loop would be the equivalent of a T-SQL <code>CURSOR</code>, which is i... | {
"AcceptedAnswerId": "51856",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-24T08:13:22.090",
"Id": "51603",
"Score": "7",
"Tags": [
"performance",
"sql",
"mysql",
"mysqli"
],
"Title": "Modifying `sakila` database"
} | 51603 |
<p>I wrote a function to convert a hexadecimal string representation (like 0x00) of some binary data to the data itself.</p>
<p>How can I improve this code?</p>
<pre><code>QByteArray restoreData(const QByteArray &data, const QString prepender = "x")
{
QByteArray restoredData = data;
return QByteArray::fr... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-25T12:53:04.230",
"Id": "89309",
"Score": "1",
"body": "Why you need to improve this code? If you really need to do this, try to find way to create QByteArray without copying source data..."
}
] | [
{
"body": "<p>Try to avoid deep copying of source array, this can be achived with <code>right</code> method:</p>\n\n<pre><code>QByteArray restoreData(const QByteArray &data, char prepender = 'x')\n{\n return QByteArray::fromHex(data.right(data.size() - data.indexOf(prepender) - 1);\n}\n</code></pre>\n",
... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-24T08:27:31.190",
"Id": "51605",
"Score": "1",
"Tags": [
"c++",
"optimization",
"converting",
"qt"
],
"Title": "Optimization of a Qt QByteArray conversion"
} | 51605 |
<p>I'm try to create array of strings from a text file. I need a review from experienced programmers about my program. (MinGW gcc, Win7)</p>
<pre><code>#include <stdio.h>
#include <string.h>
#include <stdlib.h>
main()
{
FILE *file;
char *fname = "lines.txt";
file = fopen(fname, "r");
if(file == NU... | [] | [
{
"body": "<p>If you are truly coding in C then all variables should be declared at the start of the function. This has traditionally been how the C language worked and what C coders expect.</p>\n\n<p>C has also traditionally not allowed for runtime declarations of array sizes. You should <code>malloc</code> th... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-24T10:02:18.373",
"Id": "51606",
"Score": "2",
"Tags": [
"c",
"beginner"
],
"Title": "Creating an array of strings from a text file"
} | 51606 |
<p>Can someone check my Merge Sort implementation on Java? Is it good/bad and can it be improved further?</p>
<pre><code>public class MyMergeSort {
private int [] data;
public MyMergeSort(int[] data){
this.data = data;
}
public int[] sort(int[] data){
if (data.length < 2){
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-24T12:36:44.407",
"Id": "89179",
"Score": "2",
"body": "I spent some time reformatting your code to get the tabs to work. Would be nice if you could do that yourself next time. You can find some help on formatting [here](http://coderev... | [
{
"body": "<ul>\n<li><p>Be consistent with your formatting. Sometimes you have a space between keywords like <code>if</code> and <code>else</code> and the opening parenthesis and the closing parenthesis and the opening brace, sometimes not. Pick one (I prefer a space) and stick with it. I also put spaces around... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-24T10:21:03.073",
"Id": "51607",
"Score": "2",
"Tags": [
"java",
"reinventing-the-wheel",
"mergesort"
],
"Title": "Merge Sort Java Implementation"
} | 51607 |
<p>I'm using Express 4 to provide routes to HTML/Jade files, and as well to provide an API.</p>
<p>I want to separate routes from server file, and go even further- separate API from WWW. My code now looks like this:</p>
<p>server.js</p>
<pre><code>//================== ROUTES ======================================
r... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-12-03T21:36:59.850",
"Id": "130833",
"Score": "0",
"body": "Shouldn't it be `res.send({ some: 'json' });`"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-12-04T08:50:24.627",
"Id": "130906",
"Score": "0",... | [
{
"body": "<p>As none answered, and I did some research and debugging:</p>\n\n<p>All app routes acts like middleware - so you can pass <code>app</code> and <code>express</code> into their files many times, but bear in mind, that in express 4 <strong>ORDER OF MIDDLEWARES IS IMPORTANT.</strong>\nDon't forget this... | {
"AcceptedAnswerId": "52238",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-24T12:45:08.280",
"Id": "51614",
"Score": "16",
"Tags": [
"javascript",
"node.js",
"modules",
"express.js"
],
"Title": "Exporting routes in node.js Express 4"
} | 51614 |
<p>I've created a Views Counter in Python, Gevent and MongoDB (Flask is also included in the full stack as you can see from the context issue in the code).</p>
<p>My gut still tells me that it can be still somehow improved though.</p>
<p>What the code does is initializing a dict "buffer" (just a <strong>shelve</stron... | [] | [
{
"body": "<p>Instead of using a list comprehension, I would simply use a for-loop. It will do the exact same thing and save having to allocate a temporary <code>list</code>.</p>\n\n<p>Also, in <code>run_buffer_op</code>, you first check the number of views. If that value isn't <code>>5000</code> (almost a D... | {
"AcceptedAnswerId": "51639",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-24T13:14:54.467",
"Id": "51615",
"Score": "2",
"Tags": [
"python",
"asynchronous",
"mongodb",
"pymongo"
],
"Title": "Views Counter made in Python, Gevent and MongoDB"
} | 51615 |
<p>Here's part of code in Java for battleships game I'm working on: </p>
<pre><code> lblGrid2 = new JLabel(new ImageIcon(myPicture));
lblGrid2.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
for (int i = 0; i < shipList.size(); i++)
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-24T17:19:06.423",
"Id": "89205",
"Score": "0",
"body": "My rule of thumb is: If the programmer has an attached debugger which breaks when an exception is thrown, that programmer shouldn't be annoyed by the breaks. Debugger breaks on mo... | [
{
"body": "<p>Yes, absolutely, you should be concerned.</p>\n\n<p>Exceptions should be exactly that, exceptional. and should never be part of the regular code path. If there are circumstances that you know would be normal (like not yet being connected to a server) then you should code in a condition that repre... | {
"AcceptedAnswerId": "51618",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-24T13:24:41.557",
"Id": "51616",
"Score": "7",
"Tags": [
"java",
"exception-handling"
],
"Title": "Is it bad when my code is throwing exceptions, but doesn't crash during runtime?"
} | 51616 |
<p>I defined a function that multiplies its argument by 3:</p>
<pre><code>coffee> foo = (x) -> x * 3
[Function]
</code></pre>
<p>We can call it with an input of 1:</p>
<pre><code>coffee> foo(1)
3
</code></pre>
<p>However, when I tried with a non-Number type:</p>
<pre><code>coffee> foo("3")
9
</code></p... | [] | [
{
"body": "<p>CoffeeScript is, in the end, just JavaScript with a nicer syntax. So the string-interpreted-as-number behavior is expected and normal. You write:</p>\n\n<blockquote>\n <p>This behavior appears wrong to me since a String cannot be multiplied by a Number.</p>\n</blockquote>\n\n<p>Yet, due to type c... | {
"AcceptedAnswerId": "51631",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-24T13:44:42.013",
"Id": "51619",
"Score": "2",
"Tags": [
"coffeescript"
],
"Title": "Cleaner Way to Test for Types?"
} | 51619 |
<p>In Kernighan and Ritchie (the C programming language):</p>
<blockquote>
<p>Write a program to copy its input to its output, replacing each string of one or more blanks by a single blank.</p>
</blockquote>
<p>I wrote the following code. Do you have advice to improve it?</p>
<pre><code>#include <stdio.h>
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-24T17:52:46.267",
"Id": "89212",
"Score": "1",
"body": "Have you used scanf yet? That would make this really easy."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-25T02:31:06.270",
"Id": "89265",
"S... | [
{
"body": "<p>Instead of declaring <code>otherBlank</code> and then assigning to it, just initialize it right away:</p>\n\n<pre><code>char otherBlank = 'f';\n</code></pre>\n\n<p>This is a bit cleaner and keeps the variable within a lower scope.</p>\n\n<p>Also, <code>nc</code> is declared but unused, so it shoul... | {
"AcceptedAnswerId": "51634",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-24T14:17:26.123",
"Id": "51621",
"Score": "5",
"Tags": [
"c",
"beginner",
"strings"
],
"Title": "Replacing strings to have a single blank"
} | 51621 |
<p>There's a new version of this as <a href="https://codereview.stackexchange.com/questions/52149/v2-adding-a-duplicate-entry-randomly-into-a-list-in-haskell-using-random-monad">v2 - Adding a duplicate entry randomly into a list in haskell using random monad</a></p>
<p>I wrote this trying to set up a Haskell testcase.... | [] | [
{
"body": "<p>It's very good that you structured your code into several smaller functions.</p>\n\n<p>Some ideas for improvement:</p>\n\n<ul>\n<li><p>Style: It's very useful to stick to a particular style guide and maximum line width. Also I'd recommend to avoid</p>\n\n<pre><code>name = do exp1\n exp2\n... | {
"AcceptedAnswerId": "51675",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-24T15:22:57.210",
"Id": "51624",
"Score": "4",
"Tags": [
"haskell",
"random",
"monads"
],
"Title": "Adding a duplicate entry randomly into a list in haskell using random monad"
} | 51624 |
<p>I have 3 tables, 1 where voters information is stored, 2 where their address is stored and 3 where voter <code>id</code>s are matched with address <code>id</code>s. I thought this approach was best as several voters can occupy the same address. </p>
<p>Now I have Query that selects all the voters on a given street ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-24T17:49:39.380",
"Id": "89210",
"Score": "0",
"body": "Would be nice if you described the schema. (ie tables and attributes marking the keys)."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-24T17:59:09.36... | [
{
"body": "<p>OK Assuming you need the \"Assigned Table\" to support the many to many relationship of a voter to address.</p>\n\n<pre><code>`assigned_id` int(11) NOT NULL AUTO_INCREMENT,\n`voter_id` int(11) NOT NULL,\n`address_id` int(11) NOT NULL,\nPRIMARY KEY (`assigned_id`)\n</code></pre>\n\n<p>You don't nee... | {
"AcceptedAnswerId": "51646",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-24T16:45:37.017",
"Id": "51628",
"Score": "1",
"Tags": [
"performance",
"sql",
"mysql",
"search"
],
"Title": "Searching for voters by address"
} | 51628 |
<p>This <a href="https://codereview.stackexchange.com/questions/50918/problem-traffic-flow">problem</a>:</p>
<blockquote>
<p>The Shallow Alto city council has organized a special committee to review the traffic situation in the city. Despite the fact that there is nothing whatsoever to do in the city, citizens still... | [] | [
{
"body": "<p>This looks very clean and simple, which is always* a good thing when programming. First, you don't save state, nor do you have long functions--each function does what says in a couple lines. One nitpick is your naming:</p>\n\n<blockquote>\n<pre><code>let isGreen currentTime switchItme\n</code></... | {
"AcceptedAnswerId": "151697",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-24T16:54:26.213",
"Id": "51630",
"Score": "4",
"Tags": [
"f#"
],
"Title": "Traffic Flow functional way"
} | 51630 |
<p>I'm taking user input from a file in form <code>(1, 2, 3)</code> to create a color, and I just wanted to know if I was taking most cases into account, and if there is any way I could improve this method in terms of being robust and readable. </p>
<pre><code>private Color getColorFromString(String rgb) throws Malfor... | [] | [
{
"body": "<p>I only have a few minor suggestions, but none are hard-line.</p>\n\n<ul>\n<li><p>You have a space between the <code>else if</code> and open parenthesis. I don't like this style of removing spaces around keywords and from between <code>)</code> and <code>{</code> as it becomes hard to read without ... | {
"AcceptedAnswerId": "51643",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-24T18:48:22.317",
"Id": "51642",
"Score": "7",
"Tags": [
"java",
"exception-handling",
"validation"
],
"Title": "Scrubbing user input"
} | 51642 |
<p>I am working on a bookmarker project for replacing storage of bookmarks in a web browser. It will be storing bookmarks as per categories in a database. I have written some jQuery for the WIP search page. </p>
<p><strong>A bit about functionality</strong></p>
<ul>
<li>There is a search box for categories with autoc... | [] | [
{
"body": "<p>I know that this comes a few years late and the code doesn't appear to exist on the github repository anymore. Perhaps you have learned much more about jQuery and the autocompletes since posting this but none-the-less here is a review of it.</p>\n\n<p>It is great that the DOM reference for the cat... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2014-05-24T18:59:46.030",
"Id": "51645",
"Score": "1",
"Tags": [
"javascript",
"jquery",
"html",
"autocomplete"
],
"Title": "Adding, deleting elements as per autocomplete results"
} | 51645 |
<p>I've just started to play around with Python and I've decided to create a little script that post tweets every hour (cronjob on Ubuntu) telling what time it is.</p>
<p>I'm not sure if I follow best practices or if I can make the code even shorter/cleaner/nicer? I'm a C# developer so I miss a few things in Python, l... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-25T02:02:46.847",
"Id": "89264",
"Score": "1",
"body": "To answer your other questions: the idiom for checking if a string is empty in Python is `if not foo:`, because only non-empty strings evaluate to `True`. As for getting the first... | [
{
"body": "<pre><code>from twitter import * \n</code></pre>\n\n<p>Importing <code>*</code> is generally considered bad practice, because you don't know what's being imported into your local namespace. For you case, I believe you can get away with just doing <code>import twitter</code>. In the general case, if y... | {
"AcceptedAnswerId": "51653",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-24T20:01:38.317",
"Id": "51650",
"Score": "2",
"Tags": [
"python",
"beginner",
"twitter"
],
"Title": "Small Twitter bot made in Python"
} | 51650 |
<p>I'm wondering what the best approach might be.</p>
<p>One approach is to chain <code>cachedPromise</code> and "regular", thus, if <code>cachedPromise</code> fails, we call a regular one (and caching results).</p>
<p>The second is to have a wrapper function, something like a decorator in python, and being able to w... | [] | [
{
"body": "<p>Code looks fine - but it strikes me as somewhat unnecessary.</p>\n\n<p>A promise can only be resolved/rejected once, so if you just keep the promise object itself around, its result is automatically cached within. I.e. if you call <code>.then()</code> on an already-resolved/already-rejected promis... | {
"AcceptedAnswerId": "51658",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-24T20:07:10.283",
"Id": "51651",
"Score": "10",
"Tags": [
"javascript",
"node.js",
"promise"
],
"Title": "Caching/memoizing promise results"
} | 51651 |
<p>I was given an assignment, it was as follows:</p>
<p>Give a JS code snippet which writes to the console from:
"0" to "ZZZZZ" all the combination of the characters of a-z, 0-9 and A-Z.</p>
<p>Is my solution correct?
I am sure there are better ways to achieve the same, can anybody show some?
My code is:</p>
<pre><... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-24T21:33:16.827",
"Id": "89242",
"Score": "0",
"body": "Any reason why the title of your question is so different from the actual task you were given?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-24T23:0... | [
{
"body": "<p>Minor observations:</p>\n\n<ol>\n<li><p>I'd just hardcode the <code>charset</code> in this case. Doing so is faster to write (and a lot more explicit) than building it with a bunch of loops.</p></li>\n<li><p>The modulo operator <code>%</code> is a good friend to have for this, as it'll let you \"w... | {
"AcceptedAnswerId": "51666",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-24T20:41:54.293",
"Id": "51652",
"Score": "7",
"Tags": [
"javascript",
"optimization",
"algorithm"
],
"Title": "Iterate from \"0\" to \"ZZZZZ\""
} | 51652 |
<p>I have a very basic OpenGL instanced rendering setup, which is compiling and running, however it is super slow, and even though I spent days of asking and reading how to fix it, I still have no clue, what causes the problem..</p>
<p><img src="https://i.stack.imgur.com/E3b4T.png" alt="Overlapping small window"></p>
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-24T21:05:29.667",
"Id": "89238",
"Score": "0",
"body": "Don't pass around `void*` unless you have to (e.g. because it can be any kind of pointer). In your case you know what it is so you can use the proper type."
},
{
"ContentL... | [
{
"body": "<h3>Disclaimer: This is the first time I have ever really looked into using OpenGL</h3>\n\n<p>Keep in mind that my review may contain code that is not fully included in the question (such as the simplified <code>main()</code> function).</p>\n\n<h1>Bugs</h1>\n\n<ul>\n<li><p>I found that when I tried t... | {
"AcceptedAnswerId": null,
"CommentCount": "8",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2014-05-24T20:50:23.987",
"Id": "51654",
"Score": "14",
"Tags": [
"performance",
"c",
"graphics",
"opengl"
],
"Title": "OpenGL Instanced Rendering"
} | 51654 |
<p>I am building TiKZ files, one pdf for each image I have. The purpose is to add text to each separately. The images are legion, so I created a script to generate the text files instead of generating each TeX using copy/paste. </p>
<p>So I created a tree mapping the section to the images. </p>
<p><img src="https://i... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-24T21:15:33.383",
"Id": "51656",
"Score": "1",
"Tags": [
"python",
"python-2.x",
"generator"
],
"Title": "A class with a function pointer instead of a generator"
} | 51656 |
<p>Please critique this CoffeeScript code. Is it idiomatic?</p>
<pre><code>MoneyAccount = (balance = 0) ->
obj = {
withdraw: (x) ->
if balance < x
throw new Error("not enough funds in account")
else
balance -= x
console.log "withdrew funds."
x
deposit: (x)... | [] | [
{
"body": "<p><em>This seems closely tied to <a href=\"https://codereview.stackexchange.com/q/51619/14370\">your other question</a>. I posted <a href=\"https://codereview.stackexchange.com/a/51631/14370\">an answer</a> for that one, which I'll incorporate/reference here.</em></p>\n\n<p>Calling it <code>MoneyAcc... | {
"AcceptedAnswerId": "51663",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-24T23:57:12.620",
"Id": "51661",
"Score": "1",
"Tags": [
"coffeescript"
],
"Title": "Implementing a Simple \"MoneyAccount\" in CoffeeScript"
} | 51661 |
<p>I am to use VBA code to simply retrieve certain data from all Excel files in certain folder and paste it in working spreadsheet. I am not sure that this is the most efficient (which matters as I would like to learn how to write the most possible efficient codes).</p>
<p>I am using simple copy/paste actions but mayb... | [] | [
{
"body": "<p>There is a few things I would fix:</p>\n\n<p>find a better way to grab the path - don't let the user type the path manually as he can easily make a typo and you procedure would fail as you're not currently really checking if the path provided is correct/(<em>exist</em>). Remember not to ever trust... | {
"AcceptedAnswerId": "51809",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-25T01:04:48.457",
"Id": "51662",
"Score": "7",
"Tags": [
"optimization",
"performance",
"beginner",
"vba",
"excel"
],
"Title": "Retrieving data from files in the folder"
} | 51662 |
<p>I was recently working on a project where I had the following setup:</p>
<pre><code>from stargaze.sg import SGObject
from stargaze.constants import NegInf, Infinite, PATH_CLAMPED, PATH_REVERSIBLE, PATH_ACCELERATABLE
from stargaze.utils import clamp
__all__ = [
'PathIdentifier', '_basePath', '_clampedPath', '_r... | [] | [
{
"body": "<p>This certainly seems like an odd structure for the code; I've never seen anything implemented like this. I would suggest either:</p>\n\n<ol>\n<li>If you need to have those classes stand-alone (e.g. you also create a <code>_clampedPath()</code> instance directly) you could make them inherited super... | {
"AcceptedAnswerId": "51695",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-25T01:57:51.737",
"Id": "51664",
"Score": "3",
"Tags": [
"python",
"object-oriented"
],
"Title": "General pathfinder in Python"
} | 51664 |
<p>I have both the regular for each loop and its equivalent paralleled version. The loop simply iterates through a collection, looking for the rate key in a local <code>db</code> instance and then updating the topic code.</p>
<pre><code>using (var db = new SomeEntities())
{
foreach (var measure in measures)
{... | [] | [
{
"body": "<p>No, when you use the lock like that, it's completely useless. Each lock would get its own identifier, so none of he locks would keep any other thread out. To make the lock work at all, you need to use the same identifier for all locks. Demonstration:</p>\n\n<pre><code>object sync = new Object();\n... | {
"AcceptedAnswerId": "51682",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-25T02:09:44.357",
"Id": "51665",
"Score": "6",
"Tags": [
"c#",
"task-parallel-library"
],
"Title": "Simple parallel foreach loop code correctness"
} | 51665 |
<p>I ran into a problem recently where I had to decide whether a set of sum types was homogeneous (all the same). In itself, this is a pretty simple problem. However, there were a few complicating factors:</p>
<ol>
<li>There exists a type within the types (call it <code>Id</code>) that is ignored in the comparisons.</... | [] | [
{
"body": "<p><code>homogeneous</code> could also be defined using pattern matching, though that would not necessarily be an improvement.</p>\n\n<p>However, <code>homogeneousButOne</code> can definitely be simplified using pattern matching, with no need for <code>Data.Map</code> or <code>Data.List</code>.</p>\n... | {
"AcceptedAnswerId": "52369",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-25T04:05:38.060",
"Id": "51668",
"Score": "4",
"Tags": [
"haskell"
],
"Title": "Deciding whether a list of sum types is homogeneous"
} | 51668 |
<p>I need a lock-free queue which is implemented by doubly linked list.</p>
<p>Is my code correct? Are there any errors? Are there any improvements to be made?</p>
<p>linkedlist.h</p>
<pre><code>/*
* linkedlist.h
*
* Created on: 2014. 5. 10.
* Author: dlaru_000
*/
#ifndef LINKEDLIST_H_
#define LINKEDLI... | [] | [
{
"body": "<h1>C11 atomic library</h1>\n\n<p>I you want to avoid the \"legacy\" functions, one solution would be to use the C11 <a href=\"http://en.cppreference.com/w/c/atomic\" rel=\"nofollow\">atomic operations library</a>. It is not widely supported yet. I know that GCC has been working on it, but I don't kn... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-25T04:10:02.210",
"Id": "51669",
"Score": "5",
"Tags": [
"c",
"linked-list",
"queue",
"lock-free"
],
"Title": "Lock-free queue with doubly linked list correctness"
} | 51669 |
<p>I've been designing UIChessboardView in the likeness of UITableView using protocols and delegates. </p>
<p><strong>UIChessboardView.h</strong></p>
<pre><code>@interface UIChessboardView : UIView
@property (retain) id chessdelegate;
-(void) selectChesstileWithID:(NSInteger) tileID;
-(void) deselectChesstileWithID... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-25T08:19:36.193",
"Id": "89280",
"Score": "0",
"body": "While its not much code I vote for reopen the question. The code shall compile and there can be a little review done."
},
{
"ContentLicense": "CC BY-SA 3.0",
"Creation... | [
{
"body": "<pre><code>@property (retain) id chessdelegate;\n</code></pre>\n\n<p>There are several things wrong with this line.</p>\n\n<ul>\n<li><code>retain</code> - While this technically still is a property attribute, it has been replaced by <code>strong</code>. It does the exact same thing as <code>strong</... | {
"AcceptedAnswerId": "51766",
"CommentCount": "7",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-25T05:12:41.267",
"Id": "51670",
"Score": "8",
"Tags": [
"game",
"objective-c",
"ios",
"cocoa-touch"
],
"Title": "iOS7 ChessGame UIChessboardView Design"
} | 51670 |
<p>I was attempting to write my own simple version of the Piano Tiles game app in Java just as a fun exercise.</p>
<h3>GameLogic.java</h3>
<pre><code>import javax.swing.*;
import java.awt.*;
import java.awt.event.*;
import java.util.*;
public class GameLogic extends JPanel
{
Tile[][] tileArray = new Tile[4][10]... | [] | [
{
"body": "<h1>Reviewing the code.</h1>\n\n<p>At first sight it look all nice and clean.<br/>\nNice formatting of the code.<br/>\n<b>Java standarts are a little differtent then you use, </b>but you are consistent and that is good.<br/>\nThe deviation is where you set your <code>{</code>. <br/>This is normally d... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-25T05:31:12.490",
"Id": "51671",
"Score": "5",
"Tags": [
"java",
"game",
"swing",
"event-handling"
],
"Title": "MouseListener Lag in Piano Tiles game"
} | 51671 |
<p>I understand that using <code>goto</code> in C++ code is strictly unadvised, but sometimes, it really reduces the number of lines of code like in the following case.</p>
<p>This is my code for <a href="http://www.spoj.com/problems/BEENUMS/">SPOJ</a>. I know this does not reduce too many lines of code, but in a big ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-25T06:24:44.583",
"Id": "89276",
"Score": "1",
"body": "It's not a valid C program as written, so I've removed the [tag:c] tag as well as mentions in the title and body."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate... | [
{
"body": "<p>Your use of <code>goto</code> is wholly unjustified, not just because <code>goto</code> is taboo, but because your code has flow-of-control that is hard to follow. Furthermore, the use of <code>goto</code> is not even an effective way to achieve your goal of compactness.</p>\n\n<hr>\n\n<p>Before ... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-25T05:32:40.863",
"Id": "51672",
"Score": "11",
"Tags": [
"c++",
"mathematics",
"programming-challenge"
],
"Title": "Beehive numbers - using goto in C++"
} | 51672 |
<p>The following is my solution to <a href="http://www.spoj.com/problems/JAVAC/" rel="nofollow">Java vs C++</a>. I think the way I have used the re library is inefficient, and possible erroneous as I am getting tle. </p>
<pre><code>import sys
import re
cpp = re.compile("^[a-z]([a-z_]*[a-z])*$")
java= re.compile("^[a-z... | [] | [
{
"body": "<p>When using the <code>re</code> module, make sure to use strings marked with a leading 'r' as I do in the code below. This tells the interpreter to not try and interpolate any escaped strings.</p>\n\n<p>By using <code>findall</code> to test for matches too we end up with more succinct code that sti... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-25T07:50:24.423",
"Id": "51676",
"Score": "4",
"Tags": [
"python",
"strings",
"regex",
"python-2.x",
"programming-challenge"
],
"Title": "Efficient use of regular expression ... | 51676 |
<p>I wrote a program for downloading files in concurrent / parallel (GOMAXPROCS > 1) manner.</p>
<p>This is my 2<sup>nd</sup> (non-toy) program written in Go. Please point out areas for improvement:</p>
<pre><code>package main
import (
"errors"
"fmt"
"github.com/kennygrant/sanitize"
... | [] | [
{
"body": "<p>It's super fine to use globals (like <code>log</code>) in a small one-file program you've written. To make them more visible declare them at the very top of your file right after your types.</p>\n\n<p>The global <code>read_chunk</code> doesn't follow Go naming convention. <code>readChunk</code> or... | {
"AcceptedAnswerId": "201670",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-25T11:39:46.017",
"Id": "51686",
"Score": "7",
"Tags": [
"http",
"go",
"concurrency"
],
"Title": "Concurrent download in Go"
} | 51686 |
<p>I'm designing a simple GUI using tabs to separate each 'window' of the application. There are 3 main tabs, each with 2 sub-tabs.</p>
<p>In one class I create the entire hierarchy of panes and panels:</p>
<pre><code>mainPane = new JTabbedPane();
mainPane.setBounds(0, 0, WIDTH, HEIGHT);
//instantiate main tabs, get... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-25T15:03:03.067",
"Id": "89316",
"Score": "0",
"body": "Your question would be clearer if you could provide the entire `CreateEntity` class."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-25T15:29:46.433",... | [
{
"body": "<p>I don't see anything wrong with it. You are creating an object that is going to use that data, at construction time, to set itself up. I don't see anything objectionable if that data happens to be a UI Panel. I would think it would be (very slightly) worse to force a programmer to first use the... | {
"AcceptedAnswerId": "51697",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-25T14:30:48.593",
"Id": "51693",
"Score": "1",
"Tags": [
"java",
"swing",
"gui"
],
"Title": "Simple GUI using tabs to separate application windows"
} | 51693 |
<p>I know using global variables in JavaScript is bad practice. Here I am using config, host and port as global variables as I have added a watch function to watch for the changes in the config.json file. Is the use of global variables in this example a bad practice or is it ok to use them?</p>
<p>config.json file</... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-25T17:13:10.870",
"Id": "89331",
"Score": "1",
"body": "You don't really need globals to accomplish this. Globals should be reserved to variables you want to expose to the environment."
}
] | [
{
"body": "<p>You say you're using globals because \"I have added a watch function to watch for the changes in the config.json file\". You don't need globals for this. If you declare the variables at the top level, like you've done with <code>http</code> and <code>server</code>, they'll be accessible everywhere... | {
"AcceptedAnswerId": "51713",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-25T16:26:05.513",
"Id": "51700",
"Score": "4",
"Tags": [
"javascript",
"node.js"
],
"Title": "Using global variables in my node.js program configuration"
} | 51700 |
<pre><code>#include <stdio.h>
#define MAXLINE 1000 /* Maximum length of a line */
#define TABSTOP 4 /* Length of tabstop */
int getLine(char line[], int limit);
int lookAhead(char line[], int start, int end);
/*
* Exercise 1-21
* Write a program entab that replaces strings of blanks
... | [] | [
{
"body": "<p>I don't think a proper <code>getline()</code> function should return an <code>int</code>, whether it's based on the attempted read (a boolean) or something else.</p>\n\n<p>I believe you're trying to imitate <a href=\"http://en.cppreference.com/w/cpp/io/c/fgets\" rel=\"nofollow\"><code>fgets()</cod... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-25T16:36:15.303",
"Id": "51702",
"Score": "4",
"Tags": [
"c",
"strings",
"formatting"
],
"Title": "Replacing strings of blanks by tabs and blanks to achieve same spacing"
} | 51702 |
<p>In the Python library, sklearn is implemented the algorithm for SparsePCA.</p>
<p>I have written the code for a another version of this algorithm that is much faster in some situations. I have not enough experience with Python and sklearn in order to write code that could be loaded in the sklearn repositories. </p... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-26T10:04:20.000",
"Id": "89410",
"Score": "1",
"body": "Do you want to contribute this back? I imagine the best thing to do is ask about it on their mailing list or issues page, and ask for a code review."
},
{
"ContentLicense"... | [
{
"body": "<p>Thank you for posting this.</p>\n\n<p>You didn't include any result timings. CPU performance and error performance on an available dataset would be of interest, for evaluating against sklearn's baseline code. Highly correlated inputs would be more interesting than uniform random numbers.</p>\n\n<p... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-25T18:35:06.490",
"Id": "51708",
"Score": "8",
"Tags": [
"python",
"algorithm",
"numpy",
"machine-learning"
],
"Title": "Implementation of a new algorithm for sklearn"
} | 51708 |
<h2>Background</h2>
<p>I was writing a promises/a+ implementation, just for fun. About halfway through I decided it wasn't that fun after all, so I decided to do something a little different.</p>
<p>Thinking of promises as a pattern (and not a contract), I figured they basically amount to the following (if I'm missin... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-25T19:58:10.693",
"Id": "89346",
"Score": "1",
"body": "Why `Pledge['create']` vs. `Pledge.create`? Since they are method names, they must be valid JS identifiers and thus don't need to be quoted. Personal style?"
},
{
"Content... | [
{
"body": "<p>Very interesting question.</p>\n\n<p>From a high level perspective, the code gets a bit hairy from <code>Internal stuff</code> on, which means the API is quite clear.</p>\n\n<p>I really only have nitpickings;</p>\n\n<ul>\n<li><p>This code could have been shorter if the Pledge constructor could tak... | {
"AcceptedAnswerId": "55697",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-25T19:27:14.107",
"Id": "51710",
"Score": "12",
"Tags": [
"javascript",
"callback",
"promise"
],
"Title": "Pledge: Promise-like entities design goals experiment"
} | 51710 |
<p>I'm using passport to setup login in an express site. The site is just a playground for me to learn. The code inside login was exhibiting the <a href="http://c2.com/cgi/wiki?ArrowAntiPattern" rel="nofollow">arrow anti pattern</a> so I decided it was time to learn to use promises.</p>
<p>But I don't know if what I'v... | [] | [
{
"body": "<p>Define all your error types globally in some file for convenience, like the built-in errors are defined.</p>\n\n<p>Mixing promises and callbacks is a big anti-pattern, just think in promises and let .nodeify handle the mapping to callback equivalent at the end.</p>\n\n<pre><code>var passport = req... | {
"AcceptedAnswerId": "51742",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-25T19:59:40.150",
"Id": "51712",
"Score": "1",
"Tags": [
"javascript",
"node.js",
"promise"
],
"Title": "Is this a reasonable way to implement promises in node.js?"
} | 51712 |
<p>I am trying to print a board <strong>exactly</strong> like this with the multidimensional array.</p>
<pre><code>char score[10][10] = {' '};
</code></pre>
<p></p>
<pre><code> a b c d e f g h i j
+-------------------+
0| |
1| |
2| |
3| ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-25T22:21:13.633",
"Id": "89358",
"Score": "4",
"body": "Does your code do what yuou say it should do? I am suspicious that you have both the `j` loop, and also print all the blanks in the `if(i == 0){..} else {...}` blocks. i.e. why ar... | [
{
"body": "<h1>Bugs</h1>\n\n<p>You say:</p>\n\n<blockquote>\n <p>I am trying to print a board exactly like this with the multidimensional array.</p>\n</blockquote>\n\n<p>But, in reality, you are not... you only print the first item from the 2D array, and the rest of the board is printed from the constant strin... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-25T21:50:23.793",
"Id": "51716",
"Score": "4",
"Tags": [
"c++",
"array",
"formatting"
],
"Title": "Shortest possible way of printing a specific board"
} | 51716 |
<p>This is the first time I've actually made my own jQuery script from scratch, because I couldn't find exactly what I was looking for. My code works how I want it to, although I don't know if I did it correctly. Just something about it is screaming to me, and although it works, I didn't do it properly. So I figured... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-27T10:20:41.597",
"Id": "89591",
"Score": "0",
"body": "To be honest, this is difficult to criticize, because you aren't saying what you are doing here and why - you are just executing two seemingly unrelated animations.\n\nWhat is the... | [
{
"body": "<p>Interesting concept, and I do see some improvements that could be made.</p>\n\n<p>First off though, it's true that the semicolons aren't <em>necessary</em> in JavaScript. It's a matter of preference really. If you think the people who will read your code would prefer semicolons, then use them wher... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-25T22:53:00.547",
"Id": "51717",
"Score": "5",
"Tags": [
"javascript",
"jquery",
"beginner"
],
"Title": "jQuery animate opacity, fade, & slide up page load effect"
} | 51717 |
<p>I feel like there is too much repetitive code going on here. All I am doing is doing a basic regex match for a string in the URL.</p>
<p>If a match is found, I find a <code>li</code> with a class (<code>.index</code>, <code>.grid</code> or <code>.type</code>) and add the active class. This is just for my main <code... | [] | [
{
"body": "<pre><code>$(document).ready(function () {\n\n // use single var per function, \n // good for minimizing and other stuff\n var\n\n i,\n\n // new string literal, not String object\n convertURL = '' + window.location,\n\n // the array of strings keeps only the difference \n // f... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-26T00:34:55.973",
"Id": "51720",
"Score": "5",
"Tags": [
"javascript",
"jquery",
"regex"
],
"Title": "Regex match for a string in a URL"
} | 51720 |
<p>Please let me know if you see any performance improvements, bugs, or anything you'd change and why.</p>
<pre><code> public static bool TrySpeculativeUpdate(ref int field, out int result,
Func<int, int> update, Func<int, bool> shouldAbort)
{
SpinWait spinWait = new SpinWait();
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-26T03:10:34.647",
"Id": "89381",
"Score": "0",
"body": "FYI, I tested this against locks and it's about 300%-350% faster on my machine."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-24T13:38:53.627",
... | [
{
"body": "<p>I'm not sure I like the method's signature:</p>\n\n<pre><code>public static bool TrySpeculativeUpdate(ref int, out int, Func<int, int>, Func<int, bool>)\n</code></pre>\n\n<p>It's probably just me, but I like pushing <code>ref</code> and <code>out</code> parameters to the end of the par... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-26T01:28:38.943",
"Id": "51725",
"Score": "4",
"Tags": [
"c#",
".net",
"concurrency"
],
"Title": "Try a speculative, concurrent, lock free, atomic update until abort condition matche... | 51725 |
<p>I have this JavaScript excerpt, and I was wondering if this (primarily the usage of switch case) would be considered good practice. One item of note is that I have it separated into two similar parts to not evaluate the same boolean check over and over again when it is static the whole time.</p>
<pre><code>if (st... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-27T11:12:40.243",
"Id": "89593",
"Score": "0",
"body": "I have rolled back your recent edits. Even though the edit did not massively change your initial code (it did fix one bug though), it *did* make the current answer seem incomplete... | [
{
"body": "<p>For one, I'm wondering about <code>strict</code> vs <code>sawGetSet</code>, and why it's an <code>if...else if</code> structure (instead of just using one of the two variables, and an <code>if...else</code>). But without knowing the rest of the code, I won't get into that.</p>\n\n<p>Anyway, I see ... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-26T01:31:20.090",
"Id": "51726",
"Score": "4",
"Tags": [
"javascript",
"comparative-review"
],
"Title": "Code to initialize, set, or get node properties"
} | 51726 |
<p>Please help in code reviews for readability, optimizing it, functionality etc.</p>
<pre><code>import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.math.BigInteger;
import java.util.ArrayList;
public class Merge {
static BigInte... | [] | [
{
"body": "<p>For performance reasons, in Merge Sorts, it is common to have just one temporary array for the data, and then you use positions and lengths to work inside the relevant parts of the data.</p>\n\n<p>The above is hard to describe without a code exammple, so the following will have to do.... a typical... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-26T02:34:38.870",
"Id": "51728",
"Score": "6",
"Tags": [
"java",
"sorting",
"mergesort"
],
"Title": "Algorithm for finding inversions in Merge Sort"
} | 51728 |
<p>I wrote a simple class that substitutes all file inputs in an HTML for a more complex template and set some actions on it. The code is rather small, but I'm not used to write JavaScript. </p>
<p>I wonder if there is a design pattern or extensively used way to set the callbacks? Of course, overall improvements are w... | [] | [
{
"body": "<p>You're instantiating a <code>PhotoInput</code> object but never assigning it to a variable. This implies that there's no need for a class at all. You're only instantiating it for its side-effects; you're not interested in the instance itself.</p>\n\n<p>This works, but it's bad form.</p>\n\n<p>Even... | {
"AcceptedAnswerId": "51749",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-26T03:00:23.083",
"Id": "51729",
"Score": "4",
"Tags": [
"jquery",
"event-handling",
"coffeescript"
],
"Title": "Initializing events on class"
} | 51729 |
<p>I have a WPF MVVM Application. I have a Customer Model which is generated by an entity framework (Database first approach) and one <code>CustomerViewModel</code> where I created an instance of a Customer Model and used Model members inside the <code>ViewModel</code> property get and set.</p>
<p>Here is my Customer... | [] | [
{
"body": "<h3>Entity</h3>\n<blockquote>\n<pre><code>public partial class TblCustomer\n</code></pre>\n</blockquote>\n<p>The <code>Tbl</code> prefix belongs in the database, <em>if it belongs anywhere at all</em>. You have plenty of ways with Entity Framework, to map an entity type to a specific table, there's n... | {
"AcceptedAnswerId": "51758",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-26T06:37:13.033",
"Id": "51735",
"Score": "4",
"Tags": [
"c#",
"entity-framework",
"wpf",
"mvvm"
],
"Title": "Insert Model object effectively using entity framwork"
} | 51735 |
<p>The backend supplies an attribute called <code>content</code> which clashes with the controller <code>content</code>, so I'm remapping it:</p>
<pre><code>App.Webinar = DS.Model.extend({
body: DS.attr('string')
});
/**
* Remap content -> body so it doesn't clash with the controller.
*/
App.EventSerializer = ... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-26T07:16:33.370",
"Id": "51738",
"Score": "3",
"Tags": [
"javascript",
"ember.js"
],
"Title": "A nicer way of remapping the model attribute name with ember-data"
} | 51738 |
<p>I am trying to learn the clean architecture by Uncle Bob. I wanted some basics and following this good <a href="http://blog.groupbuddies.com/posts/20-clean-architecture" rel="nofollow">post</a> I tried to implement it in python with some minor differences.</p>
<pre><code>class ValidationError(Exception):
pass
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-26T09:48:04.680",
"Id": "89407",
"Score": "0",
"body": "Guys, I would like to remind again that its not a production application, I just tried to make a toy app and obviously it will have some missing features. Please try to remain stu... | [
{
"body": "<p>I'm skeptical of the value of this design pattern, for two reasons:</p>\n\n<ul>\n<li>The <code>Repository</code> class is basically just a Python dictionary. You never use <code>Repository.all()</code> anyway.</li>\n<li><code>Repository</code> is actually a glorified namespace. It's a disguised ... | {
"AcceptedAnswerId": "51740",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-26T07:53:38.683",
"Id": "51739",
"Score": "0",
"Tags": [
"python",
"design-patterns"
],
"Title": "Improvements in repository pattern"
} | 51739 |
<p>I've been working with jQuery for a few days now and starting to get the hang of it (it does the thing that I want to do).</p>
<p>I've made an accordion, and the header of each accordion item has an arrow that points up (for being open) or down (for being closed). This code works fine, does what it has to do. When ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-26T09:56:54.293",
"Id": "89409",
"Score": "0",
"body": "can you please show html structure"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-26T10:09:47.417",
"Id": "89411",
"Score": "0",
"body": ... | [
{
"body": "<p>First off, don't use the <code>onclick</code> attribute. You have jQuery, so use it to set the appropriate event handler:</p>\n\n<pre><code>$(\".accordionHeadingDiv\").click(function (event) {\n ...\n});\n</code></pre>\n\n<p>That will add a click-event handler to all the headings.</p>\n\n<p>Now, ... | {
"AcceptedAnswerId": "51762",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-26T09:51:15.133",
"Id": "51741",
"Score": "2",
"Tags": [
"javascript",
"jquery",
"html",
"jquery-ui"
],
"Title": "Multiple jQuery statements in one function"
} | 51741 |
<p>By any means, if any can tell me if this code can be more optimized than it already is, please say so. It's a select statement to my PDO class. When I glare over my code, I'm certain there is a lot of easy improvements.</p>
<pre><code> public function select($table, $where = array(), $Innerjoin = array(), $group... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-26T13:55:12.177",
"Id": "89435",
"Score": "5",
"body": "You should give a little more context about your code. What's the real goal of this code, it's a simple select statement but in what context. In the first reading of the code, it'... | [
{
"body": "<p>As you use <code>$vowels</code> in several different methods, let's start by making that a static member of your class:</p>\n\n<pre><code>class PDO\n{\n private static $vowels = array(\"a\", \"e\", \"i\", \"o\", \"u\", \"y\", \"A\", \"E\", \"I\", \"O\", \"U\", \"Y\");\n}\n</code></pre>\n\n<p>Yo... | {
"AcceptedAnswerId": "51773",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-26T11:03:10.540",
"Id": "51746",
"Score": "4",
"Tags": [
"php"
],
"Title": "Optimize PHP foreach loops"
} | 51746 |
<p><a href="http://www.spoj.com/problems/NY10A/" rel="nofollow">The SPOJ problem</a>:</p>
<blockquote>
<p>Given a 40 character string representing outcomes of 40 coin tosses,
find the frequency destribution of all the possible outcome triplets.
So, for string like : HHHH....40 Hs ,the result is HHH : 38 and the
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-26T14:30:55.350",
"Id": "89440",
"Score": "0",
"body": "Please give details about the problem rather than posting where's described.\nWe would also appreciate if you told us how you decided to solve it."
},
{
"ContentLicense": ... | [
{
"body": "<p>You could start by replacing the <code>#define</code>s with an <code>enum</code>:</p>\n\n<pre><code>typedef enum { TTT, TTH, THT, THH, HTT, HTH, HHT, HHH } Combination;\n</code></pre>\n\n<p>As for mapping strings to macros, I suppose this could work with a <code>toString()</code> function. It cou... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-26T11:09:59.200",
"Id": "51747",
"Score": "4",
"Tags": [
"c",
"strings",
"game",
"programming-challenge",
"macros"
],
"Title": "Penney Game - mapping macros to strings"
} | 51747 |
<p>I have a script used for installing few rpms depending on operating system type. Here in this example, the script will install packages on two system "centos" and "suse". The system names are listed in nodes.txt and read as an input while executing the script.</p>
<p>For example:</p>
<pre><code>~]# cat systems.txt... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-15T01:18:48.887",
"Id": "101794",
"Score": "0",
"body": "one factor that will make a difference is that `case` will be doing pattern matching, and `[ x == y ]` is checking for string equality. With no wildcards, `case` may well be opti... | [
{
"body": "<p>This problem has me perplexed. Frankly, I don't believe you ;-) !!!</p>\n\n<p>There is no logical reason for this code to be so different from each other. There must be something else going on.... For a start, the bash process itself is probably taking almost no time at all, and all the time will ... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-26T12:16:57.220",
"Id": "51750",
"Score": "2",
"Tags": [
"performance",
"bash",
"shell"
],
"Title": "Comparing if-else and case condition"
} | 51750 |
<p>I am a big fan of one-liners using <code>sed</code> <code>awk</code> <code>perl</code> and other tools. But there are that are things hard to do in one-liner, such as when you working with a CSV file and there are commas between quotes, or when you want to print a centralized field with <code>printf</code>.</p>
<p>... | [] | [
{
"body": "<p><code>column(1)</code> is a Unix tool with a similar purpose, but does not draw box borders using ASCII art.</p>\n\n<p>There may not be a standard command to draw tables with box borders, but as always, <a href=\"http://search.cpan.org/search?query=Text%3A%3ATable&mode=dist\" rel=\"nofollow\">... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-26T16:52:04.500",
"Id": "51765",
"Score": "6",
"Tags": [
"perl",
"csv",
"formatting"
],
"Title": "Command line tools to format tables"
} | 51765 |
<p>I'm just looking for some review for my code. This is a script that checks for outbound links in posts in vBulletin forums, and if it is an external link it will redirect to a template which will load the external site in an iFrame that I also coded, inspired by themeforest and stumbleupon's way of showing external... | [] | [
{
"body": "<p>Here's how I optimized your code:</p>\n\n<pre><code>$curdir = getcwd();\nchdir('./');\ndefine('NO_REGISTER_GLOBALS', 1);\ndefine('THIS_SCRIPT', 'drc-redirect');\n$globaltemplates = array('drc_redirect');\nrequire_once('./global.php');\n\nif (isset($_GET['l'])) {\n //format passed url\n $pass... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-26T16:58:32.570",
"Id": "51767",
"Score": "3",
"Tags": [
"php"
],
"Title": "Framed external link redirect - vBulletin"
} | 51767 |
<p>This is my first real web project and I have never touched JavaScript (barely touched CSS), so I just skipped that and went to dart for fun. <a href="http://mikhailstudios.com/sudoku/">Here's a live demo</a></p>
<p>The code for the dart file is down below. If you could help me improve the code in any way, that woul... | [] | [
{
"body": "<p>First, try running the code through the <a href=\"https://www.dartlang.org/tools/dartfmt/\">Dart Formatter</a>.</p>\n\n<p>Second, try putting all of the game logic into one or more classes. Most CS professors – and development professionals – hate to see top-level, mutable state.</p>\n\n<p>Finally... | {
"AcceptedAnswerId": "51789",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-26T20:19:19.783",
"Id": "51778",
"Score": "5",
"Tags": [
"homework",
"sudoku",
"dart"
],
"Title": "A Sudoku game made from Google's Dart language"
} | 51778 |
<p>sh, aka <a href="http://en.wikipedia.org/wiki/Bourne_shell" rel="nofollow">Bourne Shell</a>, is the Unix Shell, the standard shell since v7 Unix. POSIX has standardized the shell, and portable shell scripts should conform to <code>/bin/sh</code> syntax.</p>
<p>The successor to the Bourne Shell (sh) is <a href="/qu... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-26T21:16:20.533",
"Id": "51780",
"Score": "0",
"Tags": null,
"Title": null
} | 51780 |
sh, aka Bourne Shell, is the Unix Shell, the standard shell since v7 Unix. POSIX has standardized the shell, and portable shell scripts should conform to /bin/sh syntax. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-26T21:16:20.533",
"Id": "51781",
"Score": "0",
"Tags": null,
"Title": null
} | 51781 |
<p>I have some lines that form triangles. I'd like to challenge the fastest way to find all triangles.</p>
<p><img src="https://i.stack.imgur.com/w8oIA.png" alt="enter image description here" /></p>
<p>In particular the code should take an ArrayList of Line2D object and return an ArrayList of Triangle2D. The only const... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-26T22:11:30.467",
"Id": "89494",
"Score": "2",
"body": "Can two or more lines that form a line themselves (parallel with same endpoint) be used as the side of a triangle?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDat... | [
{
"body": "<p>I suggest that you start by considering what it means for two points to be the same vertex.</p>\n\n<p>In the toxiclibs library, a <a href=\"http://hg.postspectacular.com/toxiclibs/src/689ddcd9bea39d1f8dddad26e971ae4c12b1198e/src.core/toxi/geom/Vec2D.java?at=default\" rel=\"nofollow\">Vec2D</a> con... | {
"AcceptedAnswerId": null,
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-26T21:54:19.127",
"Id": "51783",
"Score": "1",
"Tags": [
"java",
"performance",
"combinatorics",
"computational-geometry"
],
"Title": "Find triangles from line"
} | 51783 |
<p>I have created a PHP to change the user's login password:</p>
<pre><code><?php require_once('Connections/conexion.php'); ?>
<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
if (PHP_VERSION < 6) {
... | [] | [
{
"body": "<p>I can think of several things that can be improved:</p>\n\n<ol>\n<li>Separate logic from presentation</li>\n<li>Don't use <code>mysql_*</code></li>\n<li><code>MD5</code> for hashing is not safe</li>\n<li>Trying to escape/validate everything the same way is impractical and dangerous.</li>\n</ol>\n\... | {
"AcceptedAnswerId": "51816",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-26T22:57:16.310",
"Id": "51785",
"Score": "2",
"Tags": [
"php",
"security"
],
"Title": "Checking PHP security on my file"
} | 51785 |
<p>I'm new to CSS and HTML and while I've achieved a centering of the logo and navigation links, it feels wrong. I'm developing a site for a small non-profit for a side project. I have a logo next to a few navigation links. I put the logo and navigation links in a list.</p>
<p>Could someone take a look at this and ... | [] | [
{
"body": "<p>There is no real \"correct\" way to go about it; it all depends on how you want it to look. I can't quite speak to that, only the code you posted, and how it fares.</p>\n\n<p>Anyway: Review.</p>\n\n<h3>General cleanliness</h3>\n\n<p>You should clean up your code (preferably before posting it, sinc... | {
"AcceptedAnswerId": "51799",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-26T23:29:01.013",
"Id": "51787",
"Score": "3",
"Tags": [
"beginner",
"html",
"css",
"html5"
],
"Title": "Correct way to center logo and navigation"
} | 51787 |
<p>I implemented <code>std::stack</code> from the STL for deeper understanding of the language and memory since I still am only a beginner. I implemented the stack using a singly linked list.</p>
<p>Header file:</p>
<pre><code>/* Header file for abstract data type "STACK" implemented using a linked list */
#ifndef ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-27T01:55:29.803",
"Id": "89527",
"Score": "0",
"body": "As a beginner, one of the first things you should work on is consistent indentation. Everything within curly braces (or under `public` and `private`) should be indented, preferab... | [
{
"body": "<p>As noted by @Jamal in the comments.<br />\nYou should probably move to a more standard indentation scheme.</p>\n<h3>Looking at <code>node</code></h3>\n<p>It is common to name types with a leading capitol letter (to distinguish them from objects).</p>\n<pre><code>struct node {\n</code></pre>\n<p>Al... | {
"AcceptedAnswerId": "51892",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-27T01:43:18.470",
"Id": "51794",
"Score": "8",
"Tags": [
"c++",
"beginner",
"memory-management",
"template",
"stack"
],
"Title": "STL Stack Implementation"
} | 51794 |
<p>Mixins are related to inheritance in that an object receives properties or methods from another object but are typically not limited in number. They are often used as a way to "tack on" behavior to objects rather then to say that objects are related to each other. </p>
<p>For example, we may have an <code>Album</co... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-27T02:07:25.873",
"Id": "51797",
"Score": "0",
"Tags": null,
"Title": null
} | 51797 |
A mixin is a way to enhance an object with properties or methods from another object. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-27T02:07:25.873",
"Id": "51798",
"Score": "0",
"Tags": null,
"Title": null
} | 51798 |
<p>I have the following code that splits a combination of names on either the word <code>and</code> or the <code>&</code> ampersand:</p>
<pre><code> var name = 'Ron & Peggy Sue'; //or 'Ron and Peggy Sue';
if ( name.indexOf('&') > -1 ){
names = name.split(/ & /g);
}
if ( name... | [] | [
{
"body": "<p>You were almost there. You can use pipe (<code>a|b</code>) to designate the regex to look for both <code>a</code> <strong>and</strong> <code>b</code>. With that knowledge your split is as easy as:</p>\n\n<pre><code>var name = 'Ron & Peggy Sue and Darin Douglass';\nnames = name.split(/\\s(?:and... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-27T03:12:40.013",
"Id": "51800",
"Score": "6",
"Tags": [
"javascript",
"regex"
],
"Title": "Combining two indexOf and regex in to one"
} | 51800 |
<p>This is a follow-up to <a href="https://codereview.stackexchange.com/questions/51558/employee-wage-salary-calculation-mvp-solution-updated-code">this post</a>.</p>
<p>In this project (C# Win forms) I'm supposed to calculate wages of employees.</p>
<p>These are the steps:</p>
<ol>
<li><p>Calculate earnings from At... | [] | [
{
"body": "<p>I don't know which variant of MVP you are attempting to use (<a href=\"http://martinfowler.com/eaaDev/SupervisingPresenter.html\" rel=\"nofollow\">Supervising Controller</a> or <a href=\"http://martinfowler.com/eaaDev/PassiveScreen.html\" rel=\"nofollow\">Passive View</a>), but this:</p>\n\n<pre><... | {
"AcceptedAnswerId": "51815",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-27T05:42:53.633",
"Id": "51803",
"Score": "3",
"Tags": [
"c#",
"object-oriented",
".net",
"mvp"
],
"Title": "Employee wage/salary calculation MVP solution - follow-up"
} | 51803 |
<p>The problem statement can be found <a href="http://www.spoj.com/problems/PSYCHON/" rel="nofollow">here</a>. In short, here's what the problem is about:</p>
<blockquote>
<p>You're given a set of numbers and you need to find whether the the numbers are ordinary or psycho. For a number to be psycho, its number of pr... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-27T07:22:12.860",
"Id": "89562",
"Score": "0",
"body": "hint : see that you have a collection/array of only primes in stead of a big array with booleans. Iterating over all booleans takes longer then over a collection/array that contai... | [
{
"body": "<h2>Do not use namespace std:</h2>\n<p>There is <a href=\"https://codereview.stackexchange.com/search?q=%5Bc%2B%2B%5D+%22using+namespace+std%22+is%3Aanswer\">multiple reviews on that</a> here on this site already, so I'll just sum it up shortly:</p>\n<blockquote>\n<p>using namespace std pollutes glob... | {
"AcceptedAnswerId": null,
"CommentCount": "11",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-27T06:59:41.157",
"Id": "51805",
"Score": "5",
"Tags": [
"c++",
"performance",
"primes",
"complexity",
"sieve-of-eratosthenes"
],
"Title": "Psycho and ordinary numbers"
} | 51805 |
<p>Here is the piece of my controller action that takes a <code>session[:auth]</code> hash and then assigns the values to the ActiveRecord object represented by <code>@user</code> whilst the key names happen to be the same.</p>
<pre><code>def new
@user = User.new
if session[:auth].present?
@user.first_name = ... | [] | [
{
"body": "<p>This should do</p>\n\n<pre><code>def new\n attrs = %w(first_name last_name username email).map do |param|\n [param, session[:auth].extra.raw_info.send(param)]\n end\n @user = User.new Hash[attrs]\nend\n</code></pre>\n",
"comments": [],
"meta_data": {
"CommentCount": "0",
... | {
"AcceptedAnswerId": "51811",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-27T08:37:56.837",
"Id": "51808",
"Score": "2",
"Tags": [
"ruby",
"ruby-on-rails"
],
"Title": "Refactor mass assigning from a hash"
} | 51808 |
<p>In a wage processing system which employees MVP pattern We have Model classes <code>WageInfo</code>, <code>EarningInfo</code>, <code>DeductionInfo</code> and <code>AdvanceInfo</code> and entity class <code>Advance</code>. (With several other classes)</p>
<p><code>EarningInfo</code> and <code>DeductionInfo</code> h... | [] | [
{
"body": "<h1>Answers</h1>\n\n<ol>\n<li><p>No. You have one class that needs another classes Properties for it's own Properties, <strong>Why aren't they the same Class/Object?</strong> take parameters from a constructor for filling in this information.</p></li>\n<li><p>Why Aggregate <code>DeductionInfo</code... | {
"AcceptedAnswerId": "51929",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-27T12:30:02.287",
"Id": "51819",
"Score": "4",
"Tags": [
"c#",
".net",
"winforms",
"mvp"
],
"Title": "Using built-in type Decimal or Entity type Advance, to hold AdvanceAmount... | 51819 |
<p>Assumptions:</p>
<ul>
<li>The array is sorted. </li>
<li>There is only one duplicate. </li>
<li>The array is only populated with numbers [0, n], where n is the length of the array. </li>
</ul>
<p>Example array: [0,1,2,3,4,5,6,7,8,8,9] </p>
<p>Here is my implementation:</p>
<pre><code>public static int Dupl... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-27T13:30:24.703",
"Id": "89620",
"Score": "5",
"body": "To be exact: If you have an array of length `n`, filled with numbers starting at 0 and incrementing by 1 (besides one duplicate) then the largest element is `n-2` (as can be seen ... | [
{
"body": "<p>A binary search is a very nice solution to this problem and you implementation is quite simple and clean. The only issue I find with this code is your style.</p>\n\n<p>Your function <code>DuplicateBinaryFind</code> could be named better. Currently the name feels backwards (<code>IfNotNullCheck</co... | {
"AcceptedAnswerId": null,
"CommentCount": "9",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-27T13:25:31.217",
"Id": "51822",
"Score": "10",
"Tags": [
"c#",
"algorithm",
"binary-search"
],
"Title": "Find the duplicate in a sorted array In less-than O(n)"
} | 51822 |
<p>I'm a beginner in MVP design pattern and In a MVP triad, I have</p>
<p><strong>Model</strong> - <code>AdvanceInfo</code></p>
<p><strong>View</strong> - <code>AdvanceForm</code></p>
<p><strong>Presenter</strong> - <code>AdvancePresneter</code></p>
<p>and <strong>Entity class</strong> <code>Advance</code> as follo... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-27T14:27:07.397",
"Id": "89633",
"Score": "0",
"body": "I'm a \"noob\" in .net, what `VS` stand for ?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-27T16:01:28.817",
"Id": "89652",
"Score": "0",
... | [
{
"body": "<p>It's not clear exactly what you're referring to as <em>Model classes</em>, I think you're over-thinking it.</p>\n\n<p>I'd go with the <em>else</em> snippet, the POCO (<em>Plain Old CLR Object</em>) that does nothing but exposing auto-properties. The snippet that exposes a <code>public Advance</cod... | {
"AcceptedAnswerId": "51853",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-27T13:33:16.317",
"Id": "51823",
"Score": "1",
"Tags": [
"c#",
"object-oriented",
".net",
"winforms",
"mvp"
],
"Title": "Using Models and Entities in MVP pattern"
} | 51823 |
<p>I have wrote a program that lets the user open up their text file that would look something like this:</p>
<pre><code>1
2
3
4
5
6
</code></pre>
<p>It would then let the user enter a name for the list such as "numbers" The program would then let the user choose where they want to save the list. The user would then ... | [] | [
{
"body": "<h2>Structure</h2>\n\n<p>Firstly, try not to use the <code>global</code> keyword. This keyword should really be used only if you <strong>HAVE</strong> to. A simple solution for this is to implement a class that wraps around all of the functions:</p>\n\n<pre><code>class MyFileManager(object):\n def... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-27T13:38:33.540",
"Id": "51824",
"Score": "4",
"Tags": [
"python",
"python-3.x",
"file",
"tkinter"
],
"Title": "Making a list from user input"
} | 51824 |
<p>I want to insert all rows of an SQL server Table into a BigQuery Table having the same schema.</p>
<p>The streaming insert row by row is very slow: to insert 1000 rows the execution of the code below took about 10 minutes.</p>
<p>In this code I loop over the first 10 files in a certain folder, and I insert the con... | [] | [
{
"body": "<h1><strong>Wrong Approach</strong></h1>\n<p>I think what you are trying to do makes sense, however I think that your row-by-row approach is what is making this so slow. Anything you do row-by-row with SQL (e.g., a cursor or loop) will be slow because you are executing the whole section of query anew... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2014-05-27T14:37:53.373",
"Id": "51828",
"Score": "3",
"Tags": [
"sql-server",
"coldfusion",
"cfml",
"google-bigquery"
],
"Title": "Insert an SQL Server Table rows into a Bigquery table ... | 51828 |
<p>I am trying to write binary values in a file using <code>fputc</code>. In my case it is a <code>short int</code>.
The file must be opened in "w" mode.</p>
<p>I'm using this function, which is working. I need to know if I'm doing it right or if there are cases that I hadn't anticipated.</p>
<pre><code>void writeLis... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-26T16:27:12.450",
"Id": "89648",
"Score": "2",
"body": "1) must be opened in \"wb\" mode. 2)not x86 has alignment problem. `short int* positionp = (short int*)posChar;short int position = (*positionp);` 3) fwrite & fread is better."
... | [
{
"body": "<p>Using <code>malloc()</code> and <code>free()</code> in <code>readListPos()</code> seems like overkill. You could use:</p>\n\n<pre><code>short s;\nchar *posChar = (char *)&s;\n\nfor (int i = 0; i < sizeof(s); i++)\n{\n int c;\n if ((c = fgetc(comp->inputFile)) == EOF)\n …hand... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-26T16:16:54.760",
"Id": "51834",
"Score": "2",
"Tags": [
"c",
"file",
"integer",
"io"
],
"Title": "Write int, short int or any integer value in a file in binary form using fputc"... | 51834 |
<p>There many other better ways to parse BLAST output in .xml format, but I was curious to try using regex, even if it is not so straightforward and common. Here is the code how to extract translated query sequences from BLASTX output in fasta format.</p>
<pre><code>################
fasta_out = True
#################
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-27T16:36:42.287",
"Id": "89666",
"Score": "0",
"body": "FYI : It is considered a bad idea to (try to) parse languages like XML with regexp. You'll find loads of interesting explanations online like http://blog.codinghorror.com/parsing-... | [
{
"body": "<h2>Redundancy</h2>\n\n<p>You have a lot of redundant code that you repeat several times. </p>\n\n<ol>\n<li><p>You can move these lines:</p>\n\n<pre><code>line = line.strip()\nline = line.rstrip()\n</code></pre>\n\n<p>to immediately after <code>for line in xml:</code>. This saves you from having to <... | {
"AcceptedAnswerId": "51848",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-27T15:58:13.350",
"Id": "51836",
"Score": "1",
"Tags": [
"python",
"regex",
"bioinformatics"
],
"Title": "Parsing BLAST output in XML format using Regular Expression"
} | 51836 |
<p>This loops through a vector of vector of A and adds a smaller array to a bigger one at a specified position+random shift. Then it is checked if it is a better solution, and if yes, it is stored, else it is discarded. I have already parallelized it.</p>
<p>Can this be improved to run faster?</p>
<p>I am not sure ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-27T16:25:26.593",
"Id": "89660",
"Score": "0",
"body": "Maybe you could also state the problem which you are trying to solve, so we could propose better algorithms (without needing to guess what you want to do first :)"
},
{
"C... | [
{
"body": "<p>To see where the bottleneck is, you need to <strong>profile your code</strong>!</p>\n\n<p>Here something which may be a little improvement:</p>\n\n<p>replace:</p>\n\n<pre><code>inline void addArray(double *arr1, double *arr2, int size2, int pos)\n{\n for (int i = 0; i < size2; i++)\n {\n a... | {
"AcceptedAnswerId": null,
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-27T15:58:15.047",
"Id": "51837",
"Score": "7",
"Tags": [
"c++",
"optimization",
"multithreading",
"array",
"c++11"
],
"Title": "Optimize a parallelized program to optimize tr... | 51837 |
<p>Is there anyway to simplify this code so there aren't so many redundant <code>w = File.AppendText(filePath)</code> and <code>w.flush()</code> and <code>w.close()</code> in each if statement?</p>
<p>Anything else I have tried ends up locking the file, and crashing the site because to text file is in use by another p... | [] | [
{
"body": "<p>What you could do is just move that outside of the if statement like this</p>\n\n<pre><code>Dim logLoginError As New Thread(\n Sub()\n w = File.AppendText(filePath)\n If (CurrentUser IsNot Nothing) Then\n If (CurrentUser.IsLockedOut = True) Then\n w.Write... | {
"AcceptedAnswerId": "51859",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-27T16:21:35.873",
"Id": "51838",
"Score": "4",
"Tags": [
"asp.net",
"vb.net"
],
"Title": "Simplify ASP.Net StreamWriter for appendtext to file"
} | 51838 |
<p>I recently handed in a test assignment for a job application, which I was declined, with the motivation that it had scalability issues.</p>
<p>The test was to setup a REST-like backend for a hypothetical game, with three methods:</p>
<ol>
<li>create session with a given user id (implicitly creating the user if it ... | [] | [
{
"body": "<p>The only unscalable portion I see is the getHighScoresForLevel() method, which has to scan the entire table of existing scores (which becomes more of a burden with each new score, of course). Couldn't you store a <code>Map<Long, List<Score>></code> of the current 15 high scores for eac... | {
"AcceptedAnswerId": "51966",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-27T16:36:52.827",
"Id": "51842",
"Score": "4",
"Tags": [
"java",
"interview-questions"
],
"Title": "Scalability issues, storing scores for users on a particular level for later retrie... | 51842 |
<p>I have made the changes that people have suggested from my <a href="https://codereview.stackexchange.com/questions/51824/making-a-list-from-user-input">previous question</a>. I want to try and make it even tidier if possible. What can I change to make it more optimized? My <code>import</code>s are quite messy and ... | [] | [
{
"body": "<p>The PEP8 document I linked to in my answer on your previous question has <a href=\"http://legacy.python.org/dev/peps/pep-0008/#imports\" rel=\"nofollow noreferrer\">a section around imports</a> and how you should structure them. Some of the main points:</p>\n<pre><code># This is ok.\nfrom tkinter.... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-27T16:46:37.707",
"Id": "51844",
"Score": "2",
"Tags": [
"python",
"python-3.x",
"file",
"tkinter"
],
"Title": "Making a list from user input - follow-up"
} | 51844 |
<p>In an attempt to begin properly programming in Haskell, I wrote two functions for calculating numbers and sequences with Collatz's conjecture. I also commented the program quite a lot, because it helps me with my remembering of certain things.</p>
<pre><code>-- The Collatz sequence takes in a number, and either
-- ... | [] | [
{
"body": "<p>There's nothing wrong with your code in terms of functionality, but there are a number of things we can do to make it more stylish and idiomatic.</p>\n\n<p>The #1 most important thing you have missed is to always provide a type signature for top-level definitions. Just reading the type signature o... | {
"AcceptedAnswerId": "51858",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-27T17:00:58.827",
"Id": "51845",
"Score": "6",
"Tags": [
"algorithm",
"haskell"
],
"Title": "Haskell Collatz Conjecture"
} | 51845 |
<p>Convert a sorted linkedlist into a balanced binary search tree. Looking for code-review, optimizations, and best practices. </p>
<pre><code>public class SortedLinkedListToBalancedBST<T> {
private TreeNode<T> root;
private static class TreeNode<T> {
TreeNode<T> left;
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-07T15:53:21.310",
"Id": "92412",
"Score": "0",
"body": "Is this class supposed to **be** a BalancedBST or just **convert** to and from a BalancedBST?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2016-01-20T06:02... | [
{
"body": "<p>I'm going to post a simpler review than I would if I fully understood this class, but hopefully if you clarify some things, I (or others) can come back and review it more in-depth.</p>\n\n<p>My main problem with this code, is that I don't know what it is trying to do. The class is called <code>Sor... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-05-27T18:50:54.417",
"Id": "51852",
"Score": "1",
"Tags": [
"java",
"linked-list",
"tree"
],
"Title": "Convert sorted linkedlist into balanced binary search tree"
} | 51852 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.