body stringlengths 25 86.7k | comments list | answers list | meta_data dict | question_id stringlengths 1 6 |
|---|---|---|---|---|
A tree-like data structure used to hold an associative array, also called a Prefix Tree. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-14T09:18:17.137",
"Id": "41634",
"Score": "0",
"Tags": null,
"Title": null
} | 41634 |
<p>My main DLL is a .Net one that has an async running method and fires an event when it's done:</p>
<pre><code>public class LicenceVerifier
{
private readonly ILicence _licence;
private readonly int _programkey;
public delegate void LicencedCheckedEventHandler(object sender, LicenceVerifierResultArgs ar... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-14T10:06:05.433",
"Id": "41637",
"Score": "4",
"Tags": [
"c++",
"asynchronous",
"windows",
"callback"
],
"Title": "Aysnc call back to UI Thread"
} | 41637 |
<p>I would like to heat some feedback on this. I'm coming from a Java background and this is my first program in Scala. I solved <a href="http://en.wikipedia.org/wiki/Range_Minimum_Query" rel="nofollow">Range Minimum Query</a> problem.</p>
<pre><code>object Solution {
def main(args: Array[String]){
val readInfo... | [] | [
{
"body": "<p>For starters,\n your spacing is rather inconsistent: <code>val j =0</code> <code>val i=from</code>,\n typos abound: <code>storeEleme<b>n</b>ts</code>, <code>number<b>O</b>fElements</code> <code>numberOfQuer<b>ies</b></code>,\n and you terminate some statements with <code>;</code>.</p>\n\n<p>Be ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-14T10:48:14.767",
"Id": "41640",
"Score": "3",
"Tags": [
"optimization",
"performance",
"scala"
],
"Title": "Range Minimum Query Implementation in Scala"
} | 41640 |
<p>Something that bothers me a lot when coding is best practice. I am completely self taught and I find it difficult to know whether I am doing things in the 'right way'.</p>
<p>Let's say I have a Gridview on a page which displays data from the following list:</p>
<pre><code>(from foo in someContext.foobars select fo... | [] | [
{
"body": "<p>First, you should separate the UI logic (with terms like GridView, databinding etc.) from the business and/or data logic (with terms like queries, DbContext etc.). So your second approach with a helper class is the more correct approach. In general this kind of helper classes are called the <a hre... | {
"AcceptedAnswerId": "41645",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-14T12:02:47.690",
"Id": "41643",
"Score": "2",
"Tags": [
"c#",
"asp.net"
],
"Title": "Where to databind a GridView?"
} | 41643 |
<p>I needed a script to import repositories from other Bitbucket accounts to my own Bitbucket account. I have some 250 repositories in my account and I wanted them to move under Team (which is same as Organization in Github). Though Bitbucket has APIs, I couldn't find any API to import, and instead they provide a HTML ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-14T19:02:54.963",
"Id": "71674",
"Score": "1",
"body": "One suggestion: perhaps consider using the [`keyring`](https://pypi.python.org/pypi/keyring) module rather than storing Bitbucket credentials in `settings.py`."
}
] | [
{
"body": "<p>Its actually very simple, there is no need to write complex scripts. </p>\n\n<p>What I did was, complete one import process using BitBuckets HTML form, and record the post request that form makes using chrome. The chrome will give you the request in cURL form. Then use a simple nodejs script to ru... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-14T12:45:09.853",
"Id": "41647",
"Score": "2",
"Tags": [
"python"
],
"Title": "Script to import repositories to Bitbucket"
} | 41647 |
<p>In my db MySQL, I have a table <code>ranks</code> with many fields, one for each page I want limit access for the user in the menu application with PHP control:</p>
<pre><code> <?php if ($row_ranks['padric'] == '1' ) {
echo ('<li><a href="padroncini_ric.php">Ricerca</a></li>');
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-14T14:32:06.317",
"Id": "71630",
"Score": "2",
"body": "The very first thing you can do is stop using `mysql_query`. It has been deprecated for a while now, and only dinosaurs, \"24 hours\" noobs, and w3schools dropouts still use it."... | [
{
"body": "<h1><a href=\"https://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php\">DO NOT USE THE mysql_* FUNCTIONS!</a></h1>\n<p>They are DEPRECATED.</p>\n<hr />\n<pre><code><?php if ($row_ranks['padric'] == '1' ) {\n echo ('<li><a href="padroncini_ric.php"... | {
"AcceptedAnswerId": "41740",
"CommentCount": "8",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-14T12:52:30.503",
"Id": "41648",
"Score": "4",
"Tags": [
"php",
"mysql"
],
"Title": "How can I improve this PHP MySQL rank query?"
} | 41648 |
<p>I split my implementation of this sequence alignment algorithm in three methods. Where NeedlemanWunsch-method makes use of the ScoringFunction and the Traceback methods. Further I decided to go with two matices. One matrix is for the scoring, the second contains data to make the traceback easier.</p>
<pre><code>pub... | [] | [
{
"body": "<p>First of all, your method \"TraceBack\" does not return anything (what should it return, both strings?). You can also simplify your first method to use this instead:</p>\n\n<pre><code>public static int ScoreFunction(char a, char b, int matchScore, int mismatchScore)\n{\n return a == b ? matchSc... | {
"AcceptedAnswerId": "41731",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-14T13:32:49.110",
"Id": "41652",
"Score": "4",
"Tags": [
"c#",
"algorithm",
"bioinformatics"
],
"Title": "How to improve this Needleman-Wunsch implementation in C#?"
} | 41652 |
<p>I am trying to implement <a href="http://www.drdobbs.com/database/the-squarelist-data-structure/184405336">squarelist</a> by using iteration that points to the head element. I've create this iterator class to make my iterator id directional. I just want to see if I implemented it correctly.</p>
<pre><code>class i... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-17T10:42:19.703",
"Id": "72046",
"Score": "0",
"body": "Its hard to tell without more information. How do you define the `end` marker. Are member guaranteed to be laid out in contiguous memory (unlikely but possible)? Show us how you ... | [
{
"body": "<p>You almost got the <code>bool operator < (iterator const& rhs) const</code> (same for other operators overloading) right.</p>\n\n<p>The idea is to make the left operand behave semantically equals to the right operand.</p>\n\n<p>You went one step forward with this idea by defining the argume... | {
"AcceptedAnswerId": "41904",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-14T14:57:09.793",
"Id": "41655",
"Score": "8",
"Tags": [
"c++",
"c++11",
"iterator"
],
"Title": "Iterator class using a square list"
} | 41655 |
<p>I have this code to edit certain cells in my Excel file using Apache POI, but it is really slow. How can I improved the performance?</p>
<p>Ideally I would like to edit 20000 rows in less than one minute. At the moment it does ~100/min. Any suggestions would be great.</p>
<pre><code>public static void main(String[... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-14T15:35:44.270",
"Id": "71635",
"Score": "3",
"body": "Keep in mind that `System.out.println(i)` could slow your application. If you don't need it, I would suggest you to remove it."
},
{
"ContentLicense": "CC BY-SA 3.0",
... | [
{
"body": "<p>First thing you should do is only write the file out once, not 20,000 times ;-)</p>\n\n<p>Move the <code>wb.write(fileOut);</code> to be outside the loop.....</p>\n\n<p>Additionally, there may be some improvement by reversing the loop:</p>\n\n<pre><code>for(int i=2;i <20002;i++){\n</code></pre>... | {
"AcceptedAnswerId": "41657",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-14T15:17:52.990",
"Id": "41656",
"Score": "6",
"Tags": [
"java",
"performance",
"excel"
],
"Title": "Fast edit of Excel file"
} | 41656 |
<p>A question was asked <a href="https://stackoverflow.com/questions/19733364/is-it-possible-to-use-reflection-with-linq-to-entity/19733636">here</a> about reflection and LINQ to entity. I'm trying to modify the code that was presented to fit my needs.</p>
<p>Here's what I am trying to accomplish: I'm writing back-en... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-14T16:50:31.760",
"Id": "71646",
"Score": "1",
"body": "Welcome to the CR First Post review! +1 for a beautiful first post, I hope you enjoy your CR experience [and become addicted mwahahahaha] :)"
}
] | [
{
"body": "<blockquote>\n <p>String requires string.Compare</p>\n</blockquote>\n\n<p>Not true. There's a more generic option:</p>\n\n<pre><code> if (typeof(IComparable).IsAssignableFrom(newSelector.Type))\n {\n switch (condition.Item2)\n {\n case CompareTypes.Equals:\n ... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-14T16:08:45.317",
"Id": "41661",
"Score": "7",
"Tags": [
"c#",
"entity-framework",
"reflection",
"linq-to-sql",
"lambda"
],
"Title": "A generic way to use LINQ to Entity with... | 41661 |
<p><strong>What is MDX?</strong></p>
<blockquote>
<p>"Multidimensional Expressions (MDX) is a query language for OLAP
databases, much like SQL is a query language for relational databases.
It is also a calculation language, with a syntax similar to spreadsheet
formulas." <strong>Source: Wikipedia</strong... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-14T16:17:56.423",
"Id": "41663",
"Score": "0",
"Tags": null,
"Title": null
} | 41663 |
Multidimensional Expressions (MDX) is a query language for OLAP databases. It was developed by Microsoft but has later gained widespread support from other OLAP vendors. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-14T16:17:56.423",
"Id": "41664",
"Score": "0",
"Tags": null,
"Title": null
} | 41664 |
<p>I have a file that seems to mix encoding in it. It seems like a Unicode encoded file, but the character length string is encoded like a UTF8 or similar. Here is an example:</p>
<pre><code>05 41 00 72 00 69 00 61 00 6C 00
5 A . r . i . a . l .
</code></pre>
<p>In this example it stores the string like Uni... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-14T17:54:01.523",
"Id": "71661",
"Score": "0",
"body": "As far as I can see, that looks like UTF-16 encoding."
}
] | [
{
"body": "<p>To me it looks like somebody just used <a href=\"http://msdn.microsoft.com/en-us/library/yzxa6408%28v=vs.100%29.aspx\" rel=\"nofollow\"><code>BinaryWriter.Write(String)</code></a> and you should be able to extract those strings with a UTF16 encoded <code>BinaryReader</code> using <a href=\"http://... | {
"AcceptedAnswerId": "42520",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-14T16:24:42.847",
"Id": "41666",
"Score": "3",
"Tags": [
"c#",
"unicode"
],
"Title": "Custom encoding for BinaryReader"
} | 41666 |
<p>I am currently using this C# method to retrieve MAC addresses from a user's computer as a sort of unique identification. It retrieves the MAC address based on the fact that the physical card is connected to the PCI interface.</p>
<pre><code>public static string returnMAC()
{
ManagementObjectSearcher searcher = ... | [] | [
{
"body": "<pre><code>public static string returnMAC()\n</code></pre>\n\n<p>The <a href=\"http://msdn.microsoft.com/en-us/library/ff926074.aspx\" rel=\"nofollow\">C# coding conventions</a> state that functions should be UpperCamelCase. Additionally that function name is not optimal, <code>returnMAC</code>, retu... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-14T16:33:50.767",
"Id": "41667",
"Score": "3",
"Tags": [
"c#",
"sql"
],
"Title": "Retrieving MAC addresses based on PCI interface connections and SQL queries"
} | 41667 |
<p>I have implemented a method to compute a convex quadrilateral area in R3. The method works fine, but I am having numerical precision problems in the 8th decimal place. Take a look on the method:</p>
<pre><code>internal static double GetTriangleArea(double ax, double ay, double az,
double bx, double by, ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-14T17:51:55.450",
"Id": "71659",
"Score": "2",
"body": "No, use `Decimal`. ... Okay, I'm sure there would be ways, hacky and complicated ways, but I think the only appropriate solution is to use `Decimal`. Also, this question seems kin... | [
{
"body": "<p>Debugging <a href=\"https://stackoverflow.com/questions/753948/why-is-floating-point-arithmetic-in-c-sharp-imprecise\">floating-point precision issues</a> is, as @Bobby mentioned, off-topic for this site, so this is going to be <em>just a code review</em> :)</p>\n\n<p>The first thing that strikes ... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-14T16:53:37.483",
"Id": "41668",
"Score": "2",
"Tags": [
"c#",
".net"
],
"Title": "Numerical precision of implementation for convex quadrilateral area"
} | 41668 |
<p>I just want an indication as to whether or not I'm on the right track regarding PHP OOP, at least on a basic level. Positive criticism welcome.</p>
<p>P.S. Excuse the visuals of the code. This is how I usually remember code.</p>
<pre><code><html>
<?php
//Blueprint
class Human{
// properties of hu... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-15T00:05:56.147",
"Id": "71734",
"Score": "4",
"body": "The Human class must be abstract. Think it like this, you can \"create\" a Female or a Male, even a Transgender :P, but they are Humans. You **can not create** such thing as **a h... | [
{
"body": "<p>Your modeling approach seems right so far for me. Yet some minor remarks in general:</p>\n\n<ul>\n<li>I'd consider it good practice to start class names in upper-case. Either way, you should decide and stick for one way: <code>Human <-> female</code> </li>\n<li>I'm no native speaker. Yet as ... | {
"AcceptedAnswerId": "41681",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-14T17:03:46.447",
"Id": "41669",
"Score": "13",
"Tags": [
"php",
"object-oriented",
"beginner"
],
"Title": "Human class implementation"
} | 41669 |
<p>I've updated code from a couple weeks back so I've come back to get more feedback. The original post can be found over here:</p>
<p><a href="https://codereview.stackexchange.com/questions/41021/approximating-sorting-groups-of-dates-into-buckets-general-js-patterns-style">Approximating/Sorting groups of dates into b... | [] | [
{
"body": "<p>For this</p>\n\n<pre><code>if (rangeDifference >= 80) {\n approximaterMod = 10;\n console.log(\"=========== range is 80+\");\n} else if (rangeDifference >= 60) {\n approximaterMod = 8;\n console.log(\"=========== range is 60+\");\n} else if (rangeDifference >= 45) {\n approximaterMod... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-14T17:24:52.247",
"Id": "41671",
"Score": "3",
"Tags": [
"javascript",
"performance",
"datetime",
"d3.js"
],
"Title": "Approximating Date for a D3.js timeline"
} | 41671 |
<p>Recently I started learning programming and I created this program. I've added something to it with every new lesson.</p>
<p>How is my code-writing? Do I make mistakes I shouldn't make?</p>
<p><a href="https://docs.google.com/file/d/0B2KzxpPhm9AQalZ2YXViVkZ4Q1k/edit" rel="nofollow">The program itself</a></p>
<pr... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-14T19:40:08.797",
"Id": "71681",
"Score": "1",
"body": "Hey there. How about putting up specific parts of your code you would like reviewed. I think you will find this question will get closed otherwise. If there are lots of parts y... | [
{
"body": "<p>One thing that I don't like about your code is the recursive call to <code>Main();</code> inside of <code>Main()</code>.</p>\n\n<p>I don't think this is healthy, if the application is run for an extended period of time, or run over and over again you will have issues with memory management. </p>\... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-14T19:32:57.013",
"Id": "41680",
"Score": "5",
"Tags": [
"c#",
"beginner",
"console"
],
"Title": "Console-based menu system"
} | 41680 |
<p>I have a SQL query that returns a recordset with between 2 and 5 million records and I need to write that to a .csv file.</p>
<p>I wrote the following procedure and I'm curious to see if there is a better / more efficient way to do this.</p>
<pre><code>Dim conn As New OracleConnection()
...
Sub DBExecuteQueryWrite... | [] | [
{
"body": "<p>My suggestion would be to break the code that writes to the file out into a separate thread. This would allow you to read the next 25,000 rows while simultaneously writing the 25,000 rows that you've already retrieved. There is a caveat here though that you will want to wait until the previous f... | {
"AcceptedAnswerId": "41746",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-14T19:42:02.817",
"Id": "41683",
"Score": "4",
"Tags": [
"vb.net"
],
"Title": "Efficent way to Query a DB and write to text file - Large Recordset"
} | 41683 |
<p>I know of <code>BlockingCollection</code> in .net, but this is rather for my understanding of the pattern. Is this implementation correct ?</p>
<p><strong>Consumer</strong></p>
<pre><code>class Consumer
{
readonly Queue<int> _q;
public Consumer(Queue<int> q)
{
this._q = q;
}
... | [] | [
{
"body": "<p>The bigest problem is that code <code>while(true){}</code> will eat up all CPU that is available for the thread. Try running your program on a single core machine (it will run fine because you are only producing 10 items but try producing infinite number - they should still be consumed properly). ... | {
"AcceptedAnswerId": "41745",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-14T19:50:34.330",
"Id": "41684",
"Score": "5",
"Tags": [
"c#",
"multithreading",
"reinventing-the-wheel"
],
"Title": "Lock-free producer/consumer implementation"
} | 41684 |
<p>This code is for Android but I guess anyone can take a chance at it.</p>
<p>It does what I want it to do. Just that I am not comfortable with its deep level of nesting and too much of value swapping.</p>
<p>Can this be optimized for readability or in compactness?</p>
<pre><code>for(int imagenum, imagenum <76, ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-13T18:29:31.643",
"Id": "71689",
"Score": "0",
"body": "What type does `orientation` have?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-13T18:31:01.610",
"Id": "71690",
"Score": "0",
"body": ... | [
{
"body": "<p>This doesn't save many lines of code, but I think it's more readable and maintainable:</p>\n\n<pre><code>boolean landscape = orientation.contains(\"landscape\");\n\nfor(int imagenum = 0; imagenum <76; imagenum++){\n\n /* Missing code that assigns params and imageButton using imageNum? */\n\n... | {
"AcceptedAnswerId": "41686",
"CommentCount": "7",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-13T18:23:36.063",
"Id": "41685",
"Score": "1",
"Tags": [
"java",
"optimization",
"android"
],
"Title": "Setting image margins and location based on orientation"
} | 41685 |
<p>For educational purposes I wrote a little piece of code to rotate greyscale images as "low level" as possible, that is, not using any <code>rotate()</code> function, but doing the math. I was wondering if it could be improved in any way, specially in order to achieve better performance. I'm not concerned with the li... | [] | [
{
"body": "<h3>1. Comments on your code</h3>\n\n<ol>\n<li><p>For most of your functions, you've written a comment describing what it does. It's usual in Python to put this in a docstring, so that a user can get at it from the interactive interpreter using the <a href=\"http://docs.python.org/3/library/functions... | {
"AcceptedAnswerId": "41903",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-14T20:23:12.220",
"Id": "41688",
"Score": "15",
"Tags": [
"python",
"optimization",
"algorithm",
"image"
],
"Title": "Rotating greyscale images"
} | 41688 |
<p>This is a variant of the solution posted <a href="https://codereview.stackexchange.com/questions/40686/state-pattern-c-template-short-and-elegant-hierarchical-fsm-solution">here</a>, without state creation/destruction penalty.</p>
<p>Note that my comment in the original question about the simplification provided by... | [] | [
{
"body": "<p>I'm not too familiar with inheritance, but here are some stylistic things I've noticed:</p>\n\n<ul>\n<li><p>There is no need to use the <code>public</code>, <code>private</code>, and <code>protected</code> keywords repeatedly in the same class declaration. It just makes it harder to read and adds... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-14T20:43:29.480",
"Id": "41690",
"Score": "6",
"Tags": [
"c++",
"inheritance",
"state-machine",
"state"
],
"Title": "A variant of state pattern + C++ template FSM without state c... | 41690 |
<p>I'm currently using the following code to manage calls to WCF services that are unreliable, and or suffer performance load issues due to contention.</p>
<p>Right now this code is limited to solving issue with types that return <code>void</code>. It exponentially backs off from a subsequent call from the server, pre... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2017-01-26T21:51:40.823",
"Id": "290843",
"Score": "0",
"body": "May be [Polly](https://github.com/App-vNext/Polly) could help: > Polly is a .NET resilience and transient-fault-handling library that allows developers to express policies such a... | [
{
"body": "<p>One clean up is to consolidate the common code in the catch blocks, by putting it into a function. Other ideas:</p>\n\n<ul>\n<li>5 tries is not many for WCF in general. I would increase it to 50 or so. If you do this, you need a ceiling to multiple applied to to the minimum sleep time.</li>\n<li>T... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-14T21:36:40.680",
"Id": "41692",
"Score": "5",
"Tags": [
"c#",
"error-handling",
"wcf"
],
"Title": "Consistent way to handle transient timeouts with WCF calls (timeouts, unreliable n... | 41692 |
<p>I took a training challenge on Codility that checks for the proper nesting of brackets in a string. The brackets to be checked are <code>{,},(,),[,]</code>. I have written the following Java program which passes in O(n) time and space, but I have a feeling that the extra space I use can be reduced. Also I think that... | [] | [
{
"body": "<h3>Naming</h3>\n\n<ul>\n<li>Class name: <code>Solution</code> A solution for what?</li>\n<li>Method name: <code>solution</code> - again I ask: <strong>Solution for what?</strong></li>\n<li>Parameter name: <code>S</code> - And what on earth is <code>S</code>? Parameter names are by convention named b... | {
"AcceptedAnswerId": "41695",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-14T21:38:03.837",
"Id": "41693",
"Score": "10",
"Tags": [
"java",
"algorithm",
"strings",
"programming-challenge"
],
"Title": "Checking brackets nesting in a string"
} | 41693 |
<h1>Description</h1>
<p>This code is for 'fighting' two objects against each other. I am normally using it to <a href="http://chat.stackexchange.com/transcript/message/13543046#13543046">make my AIs fight each other</a> in one game or another.</p>
<p>In case you are wondering: Yes, I am using this in my <a href="http... | [] | [
{
"body": "<p>A couple things I would say:</p>\n\n<ul>\n<li><code>int FIRST_FIGHT = 1</code> is\n<ul>\n<li>declared improperly; it should be <code>public static final</code> (it will <em>act</em> this way without the explicit declaration, but I think it makes it clearer to add those modifiers; less to think abo... | {
"AcceptedAnswerId": "41701",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-14T23:19:33.893",
"Id": "41698",
"Score": "16",
"Tags": [
"java"
],
"Title": "Ready? Set. Fight!"
} | 41698 |
<p>This random generator uses cryptographically secure numbers/chars instead of <code>Math.random()</code>. The Javascript code with jQuery works well but I affect clean code ;) It would be great if you could help me to optimize the code (e.g. in speed).</p>
<pre><code>(function () {
var $length, $result, $new, $c... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-15T19:11:56.943",
"Id": "71813",
"Score": "1",
"body": "If you're concerned that the generation should be cryptographically secure, then you should not simply default to a \"non-safe\" behavior without informing the user about it."
}... | [
{
"body": "<p>I agree with @Bobby. If the function can silently fall back to a less secure source of randomness, then it's not really offering any extra security, and you might as well not bother with <code>mscrypto</code> at all.</p>\n\n<p>Verbesserungsvorschlag:</p>\n\n<pre><code>function randomString(length,... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-15T00:23:00.587",
"Id": "41700",
"Score": "10",
"Tags": [
"javascript",
"jquery",
"performance",
"random",
"cryptography"
],
"Title": "Can this secure, random generator be im... | 41700 |
<p>In a project, I have a lot of HTML forms without validation and I want to add a front end validation, in a quick way. I start looking for a library and I met <a href="http://parsleyjs.org/" rel="nofollow">Parsley.js</a>. It's a good library, but if I decided to use it I would have to modify all the forms in my appli... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-19T02:40:10.880",
"Id": "72435",
"Score": "0",
"body": "I'd recommend keeping the old code embedded here. That's more important than keeping the new code as the answers are based on the old code."
},
{
"ContentLicense": "CC BY... | [
{
"body": "<p>From a once over:</p>\n\n<ul>\n<li><p>The following is not DRY at all, you have to find a way to not do this:<br></p>\n\n<pre><code>//Types\n'alphanum': { 'parsley-type': 'alphanum' },\n'email': { 'parsley-type': 'email' },\n'url': { 'parsley-type': 'url' },\n'number'... | {
"AcceptedAnswerId": "41768",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-15T00:55:42.120",
"Id": "41703",
"Score": "5",
"Tags": [
"javascript",
"jquery",
"validation"
],
"Title": "jQuery wrapper of Parsley.js"
} | 41703 |
<p>For example, suppose in a view class we need to instantiate some UI components and then populate the fields. Something like:</p>
<pre><code>var View = function() {
this._initUI();
this._populateFields();
};
View.prototype = {
_initUI: function() {
this.textField = new TextField();
this.comboBox = new... | [] | [
{
"body": "<p>You could have a flag that is set when <code>_initUI</code> is called. The first line of <code>_initUI</code> would check the flag and exit if it's already set; the second line would set it. Then any method which needs <code>_initUI</code> to have been called can simply, safely, call it without ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-15T00:56:17.563",
"Id": "41705",
"Score": "7",
"Tags": [
"javascript"
],
"Title": "What is the best way to refactor out “temporal dependence” of instance methods?"
} | 41705 |
<p>What is an island?
A group of connected 1s forms an island. For example, the below matrix contains 5 islands:</p>
<pre><code>{{1, 1, 0, 0, 0},
{0, 1, 0, 0, 1},
{1, 0, 0, 1, 1},
{0, 0, 0, 0, 0},
{1, 0, 1, 0, 1}}
</code></pre>
<p>I'm looking for code review, best practices, optimizations etc.</p>
<pre><code>pub... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-15T02:06:03.170",
"Id": "71737",
"Score": "5",
"body": "You've been on this site for a while now, and you ask pretty good question's. I haven't seen you on our [chat room](http://chat.stackexchange.com/rooms/8595/the-2nd-monitor), you ... | [
{
"body": "<p>So, I looked at the problem spec, expecting to see a 3-word description o the title of the problem, and not much else, followed by 'Looking for optimizations, and confirmation that compelxity is <em>O(n log(n) )</em>.</p>\n<p>Fortunately, I was disappointed ;-) Your description is improved over pr... | {
"AcceptedAnswerId": "41709",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-15T01:18:58.250",
"Id": "41707",
"Score": "14",
"Tags": [
"java",
"matrix"
],
"Title": "Count the one islands in the matrix"
} | 41707 |
<p>I'm still at a very beginner level and I'm constantly working on small things to try and develop my skills. I'm hoping someone could just give me a quick review if there's anything obviously horrible about the code from my main PHP class. It's not feature-complete, but I'm hoping at this point I should be able to ge... | [] | [
{
"body": "<ul>\n<li><code>$this->isWindows = strtoupper(substr(PHP_OS, 0, 3)) === 'WIN' ? true : false;</code> : Your check already evaluates to true. Essentially this reads as <code>if (true) then true else false</code>. It could be shorted to <code>$this->isWindows = strtoupper(substr(PHP_OS, 0, 3))</c... | {
"AcceptedAnswerId": "41724",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-15T03:44:29.433",
"Id": "41711",
"Score": "5",
"Tags": [
"php",
"beginner"
],
"Title": "GIF to HTML5 video conversion"
} | 41711 |
<p>I'd like to see how I can improve this code, as I know it's bad practice to have cell reuse identifiers like this, but I could not find any other way to keep the cells that contain images from calling the server again instead of reading the cached image.</p>
<pre><code>- (UITableViewCell *)tableView:(UITableView *)... | [] | [
{
"body": "<p>So, first thing's first... we definitely need to break this down into groups of smaller methods which are all called from the <code>cellForRowAtIndexPath:</code>. The general rule of thumb is that you should be able to fit an entire method on your screen at the same time without the need to scrol... | {
"AcceptedAnswerId": "41716",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-15T04:44:09.847",
"Id": "41713",
"Score": "4",
"Tags": [
"objective-c",
"ios"
],
"Title": "UITableView cellForRowAtIndexPath"
} | 41713 |
<p>Trying to get an understanding of proper unit testing, I've read up quite a bit and found myself writing tests like the ones that follow. Based on "best practices" etc., how am I doing as far as naming the tests, ensuring that each test is correctly limited in what it does, and providing good test coverage? Followin... | [] | [
{
"body": "<p>There's not a universal answer to your question. Instead it's more a matter of finding the point along the continuum that you like and get the most benefit from. If you're testing something extremely complex, fiddly, and prone to updates, it can be well worth splitting out individual tests. If it'... | {
"AcceptedAnswerId": "41733",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-15T04:57:06.697",
"Id": "41714",
"Score": "8",
"Tags": [
"c#",
"unit-testing"
],
"Title": "Are these the right type of unit tests to write?"
} | 41714 |
<p>I have a class called <code>Machine</code>. It contains a list of parts and a list of actions. The list of parts will contain instances of the <code>Part</code> class subclasses and the list of actions will contain instances of my <code>Action</code> class subclasses. Each <code>Part</code> subclass will have its co... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-15T14:18:23.637",
"Id": "71785",
"Score": "4",
"body": "Just a question. How do you know class Gear and class Lever in the GenericsTests when you said that the Gear and Lever are somewhere else?"
},
{
"ContentLicense": "CC BY-S... | [
{
"body": "<p>I don't understand exactly the purpose of the code but having two similar object inheritance tree (<code>Action</code>s and <code>Part</code>s) smells a little bit. It also seems a sample code and I guess it violates the single responsibility principle (the behaviour of a part is separated to two ... | {
"AcceptedAnswerId": "41743",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-15T11:26:18.503",
"Id": "41725",
"Score": "6",
"Tags": [
"java",
"design-patterns",
"beginner",
"generics"
],
"Title": "Factory for classes unknown at compile time"
} | 41725 |
<p>I have a condition in my code where I need to put a lot of nested <code>else if</code> statements. However, I have managed to reduce some <code>if</code> cases by applying ternary operator, so that code looks nice and is readable. But still I am not satisfied with the result. I would like to remove rest of the <cod... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-15T12:52:15.053",
"Id": "71770",
"Score": "1",
"body": "Is the class EventStatus under your control or is it a framework class? Also what is a type of eventDetails?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2... | [
{
"body": "<p>Let's take a look at the input and output you have in that code segment:</p>\n\n<p>Input:</p>\n\n<ul>\n<li><code>rb</code>, or technically only the <code>EventStatus</code> of rb, which becomes <code>eventStatus</code>.</li>\n<li><code>eventDetails</code></li>\n</ul>\n\n<p>Output:</p>\n\n<ul>\n<li... | {
"AcceptedAnswerId": "41729",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-15T11:54:04.980",
"Id": "41727",
"Score": "16",
"Tags": [
"c#"
],
"Title": "Reduce code complexity by applying ternary operator"
} | 41727 |
<p>I tried to check if my vector struct is normalized, and I ended up with this code:</p>
<pre><code>public bool IsNormalized
{
get
{
double len = Length; // Math.Sqrt ((X * X) + (Y * Y) + (Z * Z)); -- X, Y, Z are in double format
const double min = 1 - 1e-14;
const double max = 1 + 1e... | [] | [
{
"body": "<p>This seems ok, depending on how precise you want it to be (some margin of error will always be needed since this <em>is</em> floating-point, but how much will depend on your needs)</p>\n\n<p>Alternatively, you could check <code>Math.Abs(1 - len) < 1e-14</code>, but I suspect the same precision ... | {
"AcceptedAnswerId": "41736",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-15T13:47:09.480",
"Id": "41732",
"Score": "4",
"Tags": [
"c#",
"floating-point"
],
"Title": "Checking if vector is normalized"
} | 41732 |
<p>Is this bad practice? Also, how can it be improved?</p>
<pre><code>#!/usr/bin/env bash
RUBY_VERSION=2.1.0
printf "Installing Ruby $RUBY_VERSION\\n"
if [ -d ruby_build ]; then
rm -Rf ruby_build
fi
if [[ `command -v ruby` && `ruby --version | colrm 11` == "ruby $RUBY_VERSION" ]] ; then
echo "You a... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2015-10-28T18:01:30.683",
"Id": "200576",
"Score": "0",
"body": "It really seems like this is a job for [rvm](https://rvm.io/) unless there is some other logic you can't show us. It can be set to build from source."
}
] | [
{
"body": "<p>First,I would like to point out that not all .deb-based distributions are as fond of <code>sudo</code> as Ubuntu is. For example, Debian doesn't use <code>sudo</code> out of the box.</p>\n\n<p>It appears that you're trying to build a newer version of Ruby than is available in the stock package rep... | {
"AcceptedAnswerId": "41753",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-15T15:18:22.743",
"Id": "41734",
"Score": "2",
"Tags": [
"bash",
"installer"
],
"Title": "Ruby install script; packages+installs as a .deb or .rpm from source"
} | 41734 |
<p>I'm trying to model a puzzle in order to resolve it with the Choco solver.</p>
<p>One of the constraint I'm coding is cyclical (it's triplet which follow themselves) like the following example:</p>
<pre><code>s.post(LogicalConstraintFactory.ifThen(
IntConstraintFactory.member(mvt[i], new int[]{1, 2, 3}),
I... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-15T15:47:49.813",
"Id": "71794",
"Score": "0",
"body": "How consistent are your int values... is it always triples, and always starting from 1 (i.e. always `[1,2,3],[4,5,6],[....],...` )"
},
{
"ContentLicense": "CC BY-SA 3.0",
... | [
{
"body": "<p>If the process is consistently 123, then 456, etc. and the check is always 'if a value is in one triplet, then the next value is not allowed in the same triplet, then you can have the following simple function:</p>\n\n<pre><code>int thisval = mvt[i];\n// because thisval triplets are 1-based, you n... | {
"AcceptedAnswerId": "41741",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-15T15:38:38.063",
"Id": "41737",
"Score": "6",
"Tags": [
"java",
"optimization",
"mathematics"
],
"Title": "Code reduction possible with modulo operator?"
} | 41737 |
<p>This one time pad encryption program I have written (basically just an XOR "encryption" program) seems to be working fine, compiling nicely (gcc -o ./OTP.c), and doing what it's supposed to. However I would like to improve it as much as possible which is why I am posting this.</p>
<p>I am particularly insecure abou... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2017-04-18T13:44:44.183",
"Id": "305368",
"Score": "0",
"body": "Sorry, but I don't understand why did you initialize the `buf` variable but have never used it?"
}
] | [
{
"body": "<p>When you \"remove\" a file, its contents still reside on disk; only its directory entry is removed. Instead of just unlinking the source file, consider overwriting it with random bytes first. (These days, with SSD wear leveling, filesystem snapshots, and log-structured filesystems, it's harder t... | {
"AcceptedAnswerId": "41758",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-15T19:54:03.373",
"Id": "41748",
"Score": "15",
"Tags": [
"c",
"beginner",
"memory-management",
"cryptography"
],
"Title": "Small one time pad encryption program"
} | 41748 |
<p>I'm trying to implement a system of restricted access. Right now I'm focusing on the "<a href="http://en.wikipedia.org/wiki/Session_fixation" rel="nofollow">session fixation</a>". I am concerned about the following aspects:</p>
<ol>
<li><p>Control of a "fingerprint" of the user created by mixing UserAgent, IPAddres... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-15T21:17:25.610",
"Id": "71827",
"Score": "1",
"body": "Welcome! On this site, reviewers are allowed to comment on any aspect of the code. While it is still good to have your primary request addressed, code reviews can still be done.... | [
{
"body": "<p>Preferably, you would generate a random salt. Add a function to generate random salt, then be sure to call it in your constructor. If a user discovers you salt, that is a major security hole right now. </p>\n\n<p>In my opinion, it would be best to separate this class into a separate file for easie... | {
"AcceptedAnswerId": "41985",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-15T19:56:06.433",
"Id": "41749",
"Score": "2",
"Tags": [
"php",
"session"
],
"Title": "PHP session fixation"
} | 41749 |
<p>My domain model consists mostly of simple DTOs, i.e. 'Data Transfer Objects' which <a href="http://rlacovara.blogspot.fr/2009/03/what-is-difference-between-dto-and-poco.html" rel="nofollow noreferrer">this article distinguishes from 'Plain Old C# Objects'</a>, like this one:</p>
<pre><code>public class Settings
{
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-15T20:22:24.133",
"Id": "71818",
"Score": "4",
"body": "Congratulations on asking question 12,000 on CodeReview, and a good question at that!"
}
] | [
{
"body": "<p>I would say that one of the major differences between a DTO and a POCO is the fact that a DTO should be immutable because it is meant to be used for transferring only. See what are the differences between a POCO and a DTO in this <a href=\"https://stackoverflow.com/q/725348\">SO question</a>. That... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-15T20:13:18.623",
"Id": "41750",
"Score": "6",
"Tags": [
"c#",
"object-oriented",
"ddd",
"dto",
"poco"
],
"Title": "Implementing a domain model"
} | 41750 |
<p>I have the following class: </p>
<p>MyProtocolClass.h</p>
<pre><code>#import <Foundation/Foundation.h>
@protocol MyExampleProtocol <NSObject>
@required
- (void)someRequiredMethod:(NSInteger)someValue;
@end
@interface MyProtocolClass : UIView
// interface stuff
@end
</code></pre>
<p>MyProtocolClass... | [] | [
{
"body": "<p>You're right. There is a simpler way.</p>\n\n<p>First of all, instead of giving every interactive element its own method, let's give them all the same method.</p>\n\n<pre><code>- (IBAction)buttonPressed:(id)sender;\n</code></pre>\n\n<p>If they're not all buttons, a different method name is in lin... | {
"AcceptedAnswerId": "41762",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-15T21:58:57.210",
"Id": "41761",
"Score": "8",
"Tags": [
"objective-c",
"ios",
"event-handling"
],
"Title": "How can I condense several IBAction methods in a class with a delegate... | 41761 |
<p>I've solved <a href="http://projecteuler.net/problem=15" rel="nofollow">Project Euler #15</a> in Haskell, but I feel like there might be a better way to express my solution that I'm not seeing. I start out defining my types:</p>
<pre><code>import qualified Data.Map.Strict as Map
import Data.List
data Position = Po... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-18T14:13:56.827",
"Id": "72283",
"Score": "1",
"body": "*Efficiency Review:* [Optimize the code using mathematical](https://www.youtube.com/watch?v=gENVB6tjq_M) concepts. I suggest you study some [***combinitorics***](https://en.wikipe... | [
{
"body": "<p>There's no need to list all the moves. Here is an unmemoized solution:</p>\n\n<pre><code>naiveWays :: Position -> Int\nnaiveWays (Position 0 _) = 1\nnaiveWays (Position _ 0) = 1\nnaiveWays (Position x y) = (naiveWays (Position (x - 1) y)) +\n (naiveWays (Position x (y... | {
"AcceptedAnswerId": "41766",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-15T22:11:00.870",
"Id": "41764",
"Score": "5",
"Tags": [
"haskell",
"project-euler",
"combinatorics",
"programming-challenge"
],
"Title": "Project Euler #15 in haskell"
} | 41764 |
<p>In particular, if someone could describe a better way to go from the tokenized list to the Expression tree, it would be super helpful. I would like to get rid of the casting in the parser but am not sure how.</p>
<p><a href="https://github.com/MindDesigns/bwscalc" rel="nofollow">Full code here</a></p>
<pre><code>... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-16T09:14:50.047",
"Id": "71876",
"Score": "0",
"body": "In regard to the casting, I do not know Java enough, but I think that since it has no support for multiple derivation, it probably will be difficult. One way is to create a node t... | [
{
"body": "<p>Before I begin, let me say, it looks like a well engineered project. You've separated the work into a tokenizer, parser, and calculator, which is excellent. The unit tests were helpful as well. Congratulations.</p>\n\n<hr>\n\n<p>Before you begin to write a parser, you should define the grammar,... | {
"AcceptedAnswerId": "41776",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-16T01:25:47.273",
"Id": "41769",
"Score": "5",
"Tags": [
"java",
"parsing",
"recursion",
"math-expression-eval"
],
"Title": "Numeric expression parser - calculator"
} | 41769 |
<p>For class, I had to use Java to draw a triangle and some concentric circles:</p>
<pre><code>import javax.swing.*;
import java.awt.*;
import java.awt.geom.*;
public class JComponentDemo {
private static final JComponent triangleComponent = new JComponent() {
private static final long serialVersionUID =... | [] | [
{
"body": "<blockquote>\n <p>Is it a good practice just to import everything so I don't have to go back and add stuff?</p>\n</blockquote>\n\n<p>In a modern IDE (e.g. NetBeans) you can just type in the class you intend to use and quick-fix the import. I usually do this so that I don't have spare imports laying ... | {
"AcceptedAnswerId": "41771",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-16T01:44:28.410",
"Id": "41770",
"Score": "8",
"Tags": [
"java",
"object-oriented",
"swing",
"graphics"
],
"Title": "Drawing a triangle and some concentric circles"
} | 41770 |
<p>I have two registration paths in my app. They are very similar and I am curious if I should simplify 4 associated actions down into two actions that handle the same amount of work.</p>
<p>Here are my controller actions:</p>
<pre><code>def employer_registration
@employer_signup = EmployerSignup.new
end
def emplo... | [] | [
{
"body": "<p>Your setup is going to eventually be working around Rails configurations, which are built for the canonical <code>index, new, create, show, edit, update, delete</code>.</p>\n\n<p>Rails does resource routing for this very reason (read more in <a href=\"http://guides.rubyonrails.org/routing.html\" r... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-16T04:16:42.427",
"Id": "41774",
"Score": "0",
"Tags": [
"ruby",
"ruby-on-rails",
"controller"
],
"Title": "Employer registration"
} | 41774 |
<p>As C# doesn't have generic specialisation like C++ template specialisation and I wanted a way to be able to do it, I came up with a little hack that goes a bit like this:</p>
<pre><code> public sealed class Specialisation<T>
{
private Specialisation() { }
private static Specialisation... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-16T05:11:56.090",
"Id": "71867",
"Score": "2",
"body": "\" are there any possible side effects that could happen as a result of this horrible hack?\" Do you mean like unemployment?"
},
{
"ContentLicense": "CC BY-SA 3.0",
... | [
{
"body": "<p>I don't think that there any nasty hidden downsides to it. As you noted C# doesn't have real specialisations and the only way to have the same method just differing by return type is the way you chose - so if that's what you need then that's what you have to do.</p>\n<p>Only note is that I'd consi... | {
"AcceptedAnswerId": "41857",
"CommentCount": "13",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-16T05:01:22.023",
"Id": "41775",
"Score": "14",
"Tags": [
"c#",
"c++",
"generics"
],
"Title": "Is this C# 'hack' a bad idea?"
} | 41775 |
<p>The application I'm building can accept two types of updates: Application Update and Parameter Updates. If there is an application update, then parameter updates can be ignored. This is the code that I've written, and it's messy. How can I clean this up?</p>
<pre><code>mContext = this.getApplicationContext();
//ex... | [] | [
{
"body": "<p>I assume that the code in the question is a method. If not extract it out to a method.</p>\n\n<ol>\n<li>\n\n<pre><code>boolean appUpdatesAccepted = Parameters.load(mContext).getUpdateType() == UpdateType.BOTH\n || Parameters.load(mContext).getUpdateType() == UpdateType.APPLICATION;\nboolean... | {
"AcceptedAnswerId": "41791",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-16T08:01:24.350",
"Id": "41780",
"Score": "4",
"Tags": [
"java",
"android"
],
"Title": "How can I reduce the number of nested if statements in this code?"
} | 41780 |
<p>It was a part of my coding challenge and the last one, but I failed because it failed to yield a result in two seconds for some of sample inputs (out of six samples, three passed but three failed for not meeting the time constraint). </p>
<p>Basically, you are supposed to find the maximum deviation from given numb... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-16T11:19:09.517",
"Id": "71886",
"Score": "1",
"body": "link to the code challenge to get the samples?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-17T08:32:17.957",
"Id": "72026",
"Score": "0",
... | [
{
"body": "<p>Some notes:</p>\n\n<ul>\n<li><p><code>find_deviation(v, d)</code>: Try to write more meaningful names for variables. Specially, I'd give a plurar name to <code>v</code>, since it's a collection.</p></li>\n<li><p><code>max = 0</code>, <code>each</code>, inline <code>if</code>: All of this denote yo... | {
"AcceptedAnswerId": null,
"CommentCount": "7",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-16T08:17:42.800",
"Id": "41781",
"Score": "11",
"Tags": [
"performance",
"ruby",
"array"
],
"Title": "Finding maximum deviation"
} | 41781 |
<p>I'm an intensive user of AWS EC2 instances, many instances are launched, stopped, repurposed, etc.</p>
<p>To connect to any instance using <code>SSH</code> I must keep track of their IPs.</p>
<p>The bash script I wrote (following the <a href="https://stackoverflow.com/questions/21424849/is-there-an-easy-way-to-con... | [] | [
{
"body": "<p>It's mostly fine, but I would suggest some minor improvements.</p>\n\n<p>Give a proper name to <code>$1</code> early on, for example:</p>\n\n<pre><code>host=$1\nif [ -z $host ]; then\n echo \"Please enter machine name\"\n return 1\nfi\n</code></pre>\n\n<p>You use it in several places later and i... | {
"AcceptedAnswerId": "48011",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-16T08:21:23.157",
"Id": "41782",
"Score": "8",
"Tags": [
"bash",
"amazon-web-services"
],
"Title": "Connecting to EC2 instances using the instance name instead of IP"
} | 41782 |
<p>After asking a <a href="https://stackoverflow.com/questions/21642731/is-this-a-monad-in-java">similar question on Stack Overflow</a>, I'm picking up on the answer there to improve my monad. I'm not trying to solve the general case, just come up with one to see how it works. If I'm right, then I really like this pat... | [] | [
{
"body": "<p>Well, lets find out by checking the <a href=\"https://en.wikipedia.org/wiki/Monad_%28computer_science%29#Monad_laws\"><em>monad laws</em></a>.</p>\n\n<ol>\n<li><p><code>(unit x) >>= f ≡ f x</code>, which translates to the Java</p>\n\n<pre><code>new FriendSpace<...>().unit(x).bind(.... | {
"AcceptedAnswerId": "41803",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-16T08:24:49.477",
"Id": "41783",
"Score": "6",
"Tags": [
"java",
"generics",
"monads"
],
"Title": "A monad in Java (FriendSpace and People)"
} | 41783 |
<p>I have a interface with the following implementation</p>
<pre><code>public abstract class PersonInterface
{
public abstract void Update(PersonModel person);
public abstract void Delete(int id);
public virtual PersonModel Find(int id)
{
return new List<PersonModel>(... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-16T15:11:59.370",
"Id": "71916",
"Score": "0",
"body": "I'd recommend making the `Find` and `GetAll` methods in abstract base class `abstract` as well. They current implementations provide no useful shared functionality."
},
{
... | [
{
"body": "<p>Yes. When some classes have things in common but common things different having a abstract base class is a good way to go.</p>\n\n<p>Having a common base class gives you a number of advantages:</p>\n\n<ul>\n<li><p>Reuse between the classes. Your <code>Find</code> and <code>GetAll</code> methods do... | {
"AcceptedAnswerId": "41798",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-16T12:30:26.340",
"Id": "41794",
"Score": "4",
"Tags": [
"c#"
],
"Title": "Abstract Person with Employees and Clients"
} | 41794 |
<p>In my first iterative algorithm, I do this</p>
<pre><code>for (auto &widget : controls.getWidgets())
{
if (!widget->visible) continue;
widget->draw();
for (auto &widget_component : widget->components)
{
if (!widget_component->visible) continue;
widget_component... | [] | [
{
"body": "<p>You can modify the recursive code to use an explicit stack:</p>\n\n<pre><code>#include <stack>\n\nvoid display_widgets(control& controls)\n{\n std::stack<widget*> widgets;\n for(auto &widget : controls.getWidgets()) {\n widgets.push(widget);\n }\n\n while(!wi... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-16T12:38:36.110",
"Id": "41795",
"Score": "6",
"Tags": [
"c++",
"optimization",
"c++11",
"recursion",
"iteration"
],
"Title": "Iteration to recursive function"
} | 41795 |
<p>This is Part 1 of a question about performance and general best practices. Part 2 is located <a href="https://codereview.stackexchange.com/questions/41835/entity-framework-6-0-2-performance-of-auditable-change-tracking-part-2-of-2">here</a>. The body of the messages are the same to illustrate their similarity, the... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-16T17:05:27.190",
"Id": "71926",
"Score": "0",
"body": "Please include the code you want reviewed, in your post - don't just link to it. Link to *on-the-side* stuff, not to the code you want reviewed. As it currently stands, this quest... | [
{
"body": "<p>I'm not familiar with template coding but I could follow this script all along, except this one-liner:</p>\n\n<pre><code>public <# WriteLine(string.Format(\"{3}{0} {1} {{ get; {2}set; }}\", string.Format(\"{0}{1}\", property.Value.DataType, (nullableTypes.Contains(property.Value.DataType) &... | {
"AcceptedAnswerId": null,
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-16T12:45:57.103",
"Id": "41796",
"Score": "3",
"Tags": [
"c#",
"performance",
"entity-framework"
],
"Title": "Entity Framework 6.0.2 - Performance of Auditable Change Tracking Part 1... | 41796 |
<p>I have this code I am using in a private project. The following is a snippet of code I use to retrieve and load playlists from YouTube:</p>
<pre><code>for (feedEntry in a.feed.entry) {
if (a.feed.entry.hasOwnProperty(feedEntry)) {
feedTitle = a.feed.entry[feedEntry].title.$t.replace('] - ', ']').replace(' : ',... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-16T14:25:11.480",
"Id": "71905",
"Score": "0",
"body": "You could look at using better [regular expressions](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp) as they are _very_ fast."
},
{
... | [
{
"body": "<p>The freezing comes primarily from the fact that JavaScript is single-threaded so when your loop is busy-looping everything else will wait until the scope has finished before the browser can continue to poll on the event queue.</p>\n\n<p>To solve this you can convert your code to <em>asynchronous</... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-16T14:21:42.980",
"Id": "41804",
"Score": "4",
"Tags": [
"javascript",
"performance",
"youtube"
],
"Title": "Retrieve and load playlists from YouTube"
} | 41804 |
<p>I am writing my own tooltip plugin for my portfolio website that I am currently working on. It works rather well, however, I feel that there is a lot I could improve. This is one of my bigger jQuery plugins that I have written.</p>
<pre><code>(function($) {
// Used as a template for addTooltip()
var tooltipDefau... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-16T14:45:12.590",
"Id": "71911",
"Score": "0",
"body": "`new Array()` -> `[]`"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-16T14:52:45.677",
"Id": "71912",
"Score": "0",
"body": "`if (element... | [
{
"body": "<p>From a once over:</p>\n\n<ul>\n<li><p>There seems to be a ton of overkill with regards to <code>id</code>, since the user will never look at the id of a tooltip, you can simply use:<br></p>\n\n<pre><code>function generateUniqueId()\n{\n var id = generateUniqueId.id = ( generateUniqueId.id || 0) +... | {
"AcceptedAnswerId": null,
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-16T14:43:55.417",
"Id": "41807",
"Score": "5",
"Tags": [
"javascript",
"jquery",
"html",
"plugin"
],
"Title": "Tooltip plugin for portfolio website"
} | 41807 |
<p>I would like to know whether I'm going in a correct way or not in building my Poker game. So far, I've implemented card and deck classes and I would like to see your feedback about my work. Feel free to criticize the code of any regard (organization, order, comments ... etc) </p>
<p><strong>card.h</strong> </p>
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-16T17:48:32.213",
"Id": "71932",
"Score": "0",
"body": "I happen to be personally interested in playing card representations in C++. You may take a look at my latest posted version [here](http://codereview.stackexchange.com/questions/... | [
{
"body": "<p>I come from Java world, but here are just a few thoughts:</p>\n\n<ul>\n<li><code>generate_suit</code> and <code>generate_rank</code> methods should probably not subtract 1 from MAXes and also adding zero at the end is unnecessary. E.g. <code>rand() % (SUIT_MAX-1)</code> is <code>rand() % 3</code> ... | {
"AcceptedAnswerId": "41816",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-16T15:53:21.387",
"Id": "41810",
"Score": "15",
"Tags": [
"c++",
"classes",
"playing-cards"
],
"Title": "Card and Deck classes"
} | 41810 |
<p>I've written a List monad as an example for a <a href="https://codereview.stackexchange.com/q/41783/21609">related question</a>. This is a rather frustrating experience as I wanted to use Java, which (as of Java 7) still lacks lambda expressions and lacks higher-order type parameters, which is one reason why this</p... | [] | [
{
"body": "<p>This is pretty decent code. A few things seem noteworthy:</p>\n\n<ul>\n<li><p>The spacing is inconsistent. This could have happened if <code>size</code> was a boolean <code>isEmpty</code> in a previous incarnation…</p></li>\n<li><p>There are a lot more opportunities to declare variables to be <cod... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-16T16:21:18.563",
"Id": "41811",
"Score": "8",
"Tags": [
"java",
"functional-programming",
"linked-list",
"generics",
"monads"
],
"Title": "Monadic Immutable Linked List in t... | 41811 |
<p>I have some JavaScript code that allows users to select a plan which triggers the second select box to populate with options. The code works, however, it seems to be very inefficient. Any advice on improving the efficiency? </p>
<p>JavaScript: </p>
<pre><code>var term = 0;
var price = 0;
var additional = 0;
var fi... | [] | [
{
"body": "<p>For starters, you can remove a lot of duplicate code from the <code>populateBilling()</code> function like this:</p>\n\n<pre><code>function populateBilling(planName) {\n var options = {\n basic: { \n \"Option\" : [\"$200/month for 1-yr\", \"$250/month\"],\n \"Value\... | {
"AcceptedAnswerId": "41817",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-16T17:38:57.217",
"Id": "41814",
"Score": "5",
"Tags": [
"javascript"
],
"Title": "Varying a second drop-down's options based on a first selection"
} | 41814 |
<p>I'm new to programming and also to Java and working on problems in <em>Intro to Java</em> by Robert Sedgewick. Here is my question:</p>
<blockquote>
<p>Connect Four: Given an N-by-N grid with each cell either occupied by
an 'X', an 'O', or empty, write a program to find the longest sequence
of consecutive 'X... | [] | [
{
"body": "<p>I'm not a Java programmer, so I won't attempt to mislead you with any specific information. However, I'd really like to address the issues with indentation and whitespace, as a basic thing to writing code. I'll address this using example code.</p>\n\n<hr>\n\n<p><em>Please</em> keep your indentat... | {
"AcceptedAnswerId": "41820",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-16T17:39:50.360",
"Id": "41815",
"Score": "11",
"Tags": [
"java",
"beginner",
"connect-four"
],
"Title": "Find longest sequence horizontally, vertically or diagonally in Connect F... | 41815 |
<p>I have a population (<code>Pop</code>) which has an attribute which is a list of individuals (<code>Ind</code>) where each individual has an attribute which is a list of chromosomes (<code>Chromo</code>). Each chromosome is a list of numbers which tells about the fitness (=reproductive success, the fitness is obtain... | [] | [
{
"body": "<p>Some advice here:</p>\n\n<ul>\n<li>You should try to follow the PEP 8 guidelines whenever it's possible. In your case, the naming convention is not followed.</li>\n<li>You should try to keep things simple. For instance, in <code>WalkerRandomSampling.__init__()</code>, it seems like you are doing a... | {
"AcceptedAnswerId": "41865",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-16T18:28:14.923",
"Id": "41821",
"Score": "5",
"Tags": [
"python",
"object-oriented",
"bioinformatics"
],
"Title": "Case study with a biological populations: a list of lists of li... | 41821 |
<pre><code>types = [
{ name: "Feature"}
{ name: "Enhancement"}
{ name: "Bug"}
{ name: "Spike"}
]
buildIndex = (source, property) ->
array = []
array[prop[property]] = prop for prop in source
array
buildIndex types, 'name'
</code></pre>
<p>Result:</p>
<pre><code>[Feature: Object, Enhanceme... | [] | [
{
"body": "<p>There's something fishy here. You're creating an array, but you're not using it as one. You're simply adding named properties to it, like you can with any object. In the end, you're left with an array that still has a length of zero. So I'm betting you don't actually want an array at all.</p>\n\n<... | {
"AcceptedAnswerId": "41839",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-16T18:44:35.413",
"Id": "41822",
"Score": "4",
"Tags": [
"coffeescript"
],
"Title": "Refactor array for loop result"
} | 41822 |
<p>I'm currently creating a ASP.NET MVC page in C#.</p>
<p>I want to hide everything regarding the creation of our "models" and "viewmodels". </p>
<p>I have seen much of the fancy stuff regarding Dependency Injection as well as Action Filters, Custom Controllers and so on! But the people I work with are pretty new to... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-16T21:11:57.237",
"Id": "71944",
"Score": "1",
"body": "How complex is the ViewModel -> Model mapping? Mapping tools such as AutoMapper can typically do most of what you are after."
},
{
"ContentLicense": "CC BY-SA 3.0",
"... | [
{
"body": "<p><strong>Var</strong></p>\n\n<p>Use <code>var</code> for method-scope declarations when the right-hand side of the declaration makes the type obvious. This gives you the convenience during refactoring of being able to change the type in just one place.</p>\n\n<p>e.g.</p>\n\n<pre><code>IViewModel<... | {
"AcceptedAnswerId": "74035",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-16T20:29:18.323",
"Id": "41825",
"Score": "3",
"Tags": [
"c#",
"design-patterns",
"asp.net-mvc-4",
"controller"
],
"Title": "What can I do better in this ViewModel Creator?"
} | 41825 |
<p><img src="https://i.stack.imgur.com/mckF3.png" alt="Banner"></p>
<p>Some time ago I started with a small Ruby project. I call it <code>social_aggregator</code>.
This software aggregates information from different networks to one xml-stream, which you can reuse. For instance on your personal website to show some of ... | [] | [
{
"body": "<p>You can see the answer to <a href=\"https://codereview.stackexchange.com/questions/41830/implementing-plugins-in-my-ruby-social-aggregator-app\">Implementing plugins in my Ruby social aggregator app</a> to see some general observations on your code style.</p>\n\n<p>The most important thing I have ... | {
"AcceptedAnswerId": "41895",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-16T22:11:34.983",
"Id": "41828",
"Score": "3",
"Tags": [
"ruby"
],
"Title": "Booting up my Ruby social aggregator app"
} | 41828 |
<p><img src="https://i.stack.imgur.com/mckF3.png" alt="Banner"></p>
<p>Some time ago I started with a small Ruby project. I call it <code>social_aggregator</code>.
This software aggregates information from different networks to one xml-stream, which you can reuse. For instance on your personal website to show some of ... | [] | [
{
"body": "<p>Most of your code is not here, but some general points:</p>\n\n<ol>\n<li>File naming conventions: in ruby, file name convention is <a href=\"http://en.wikipedia.org/wiki/Snake_case\" rel=\"nofollow noreferrer\">snake case</a> - your files should be named as the name of your class, but as snake cas... | {
"AcceptedAnswerId": "41886",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-16T22:20:26.923",
"Id": "41830",
"Score": "1",
"Tags": [
"ruby",
"plugin"
],
"Title": "Implementing plugins in my Ruby social aggregator app"
} | 41830 |
<p>I have made a method which takes two parameters: the value to convert and the base. Based upon those two parameters my method is adjusted (with several helper methods) to change the desired decimal number to a number with a different base.</p>
<p>Is this code practical and clean? If not, what should I change to mak... | [] | [
{
"body": "<p>A few random notes:</p>\n\n<ol>\n<li><p>It returns an empty string with <code>0</code> as input <code>value</code>. I guess it's a bug.</p></li>\n<li>\n\n<pre><code>int countLength = 0, countFit = 0;\n</code></pre>\n\n<p>I'd put the variable declarations to separate lines. From Code Complete, 2nd ... | {
"AcceptedAnswerId": "41838",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-16T22:23:23.993",
"Id": "41831",
"Score": "10",
"Tags": [
"java",
"converting",
"reinventing-the-wheel"
],
"Title": "Is decimal, hexadecimal, octadecimal, binary converter efficie... | 41831 |
<p>I had a small technical C# task using SOLID principle and TDD. But I failed to prove my coding skill through the test.</p>
<p>Can anyone offer any small advice for me? I am really eager to learn what my faults are and how I can improve.</p>
<p>The interview question is <a href="https://github.com/JustGiving/Recrui... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-17T13:39:39.287",
"Id": "72070",
"Score": "1",
"body": "Did you submit a pull request from your public repo? \"If you have a paid GitHub account, feel free to create a **private repo** . . . and send us a pull request.\" [their emphasi... | [
{
"body": "<ol>\n<li><p><code>TaxCalculator</code> and <code>TaxCalculatorByDB</code> contains the same logic:</p>\n\n<pre><code>var gaRatio = _taxRepo.GetTaxRate() / (100 - _taxRepo.GetTaxRate());\nreturn dAmount * gaRatio;\n</code></pre>\n\n<p>Furthermore, it seems that <code>TaxCalculator</code> and the <cod... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-16T23:45:33.157",
"Id": "41834",
"Score": "23",
"Tags": [
"c#",
"object-oriented",
"interview-questions",
"tdd"
],
"Title": "Interview task - SOLID Principle and TDD"
} | 41834 |
<p>This is Part 2 of a question about performance and general best practices. Part 1 is located <a href="https://codereview.stackexchange.com/questions/41796/entity-framework-6-0-2-performance-of-auditable-change-tracking-part-1-of-2">here</a>. The body of the messages are the same to illustrate their similarity, the... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-18T06:19:17.127",
"Id": "72235",
"Score": "0",
"body": "You should probably narrow down your question. I can hardly imagine someone scrolling through this unreadable wall of code."
},
{
"ContentLicense": "CC BY-SA 3.0",
"Cr... | [] | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-16T23:53:17.853",
"Id": "41835",
"Score": "1",
"Tags": [
"c#",
"performance",
"entity-framework"
],
"Title": "Entity Framework 6.0.2 - Performance of Auditable Change Tracking Part 2... | 41835 |
<ol>
<li>An N-Drome is a string that is the same forwards and backwards when split into n-character units. </li>
<li>For example, a string would be a 1-drome if and only if it were a standard palindrome. </li>
<li>An example of a 2-drome would be <code>abcdab</code> since its 2-character units are <code>ab</code>, <cod... | [] | [
{
"body": "<p>I'm not a Java programmer, but I'll point out some familiar syntactical things I see:</p>\n\n<ul>\n<li><p>You should separate the logic by putting the checking code into a separate function, leaving <code>main()</code> to call the function, handle the input/output, and terminate when needed.</p></... | {
"AcceptedAnswerId": "41860",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-17T01:37:33.313",
"Id": "41840",
"Score": "5",
"Tags": [
"java",
"optimization",
"palindrome"
],
"Title": "Is my N-drome (variation of palindrome) checking program efficient?"
} | 41840 |
<p>Implemented iterator for a binary tree and "pre" "in" and "post" order flavors. I'm looking for code review, best practices, optimizations etc.</p>
<pre><code>public class IterateBinaryTree<E> {
private TreeNode<E> root;
/**
* Takes in a BFS representation of a tree, and converts it into ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2015-06-11T05:45:46.343",
"Id": "169628",
"Score": "0",
"body": "you might be interested in this post http://techieme.in/postorder-node-iterator-of-binary-tree/"
}
] | [
{
"body": "<p>I haven't checked the correctness of the implementation, just some notes about the code:</p>\n\n<ol>\n<li><p><code>Stack</code> seems more or less deprecated. <a href=\"http://docs.oracle.com/javase/7/docs/api/java/util/Stack.html\" rel=\"nofollow\">Javadoc says the following</a>:</p>\n\n<blockquo... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-17T02:29:18.747",
"Id": "41844",
"Score": "2",
"Tags": [
"java",
"tree",
"iterator"
],
"Title": "Iterator for binary tree - pre, in, and post order iterators"
} | 41844 |
<p>This is a programming practice that our teacher gave us, and I would appreciate if someone can look over my program and tell me if I did a good job.</p>
<p>Basically, the context is I joined a company and am supposed to write a program in C that takes three inputs (ft of steel, number of ball bearings, and lbs of b... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-17T04:07:01.170",
"Id": "71994",
"Score": "1",
"body": "Forgot to add, the instructor wants the PrintLine() functions for the output."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-17T12:17:16.207",
"I... | [
{
"body": "<p>Roughly 50% of all programming is about dealing with errors. You say your code works, but it doesn't handle errors and therefore doesn't work.</p>\n\n<p><strong>Example 1</strong>:</p>\n\n<pre><code>How many feet of steel was received today: four\n</code></pre>\n\n<p>Program doesn't say \"Error, ... | {
"AcceptedAnswerId": "41849",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-17T02:58:15.560",
"Id": "41845",
"Score": "24",
"Tags": [
"c",
"beginner",
"homework"
],
"Title": "Feedback on a programming practice problem in C"
} | 41845 |
<p>This program connects all nodes of the binary tree at the same level. A node of a tree contains a left, right and a sibling pointer which would connect it to the next node at the same level. This connection is from left to to right. Example: consider a binary tree with parent as node A and left and right child as no... | [] | [
{
"body": "<p>My observations:</p>\n\n<p><strong>Use properties - do not expose raw members</strong> - your <code>TreeNode</code> implementation exposes raw members. You should use getters and setters instead.</p>\n\n<p><strong>Unused parameters</strong> - in your <code>TreeNode</code> constructor you declare 4... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-17T03:25:17.937",
"Id": "41848",
"Score": "3",
"Tags": [
"java",
"algorithm",
"tree"
],
"Title": "Join/ connect all levels of Binary tree without any aux storage"
} | 41848 |
<p>Are these classes properly guarded for thread safety? Do you see any issues with any of the classes?</p>
<pre><code>@ThreadSafe
public class RetirementAccount {
public static final int TYPE1 = 0;
public static final int TYPE2 = 1;
@GuardedBy("this")
private final int accountType;
@Guarded... | [] | [
{
"body": "<p>Not a guru in the Concurrency yet, but I'll try to be helpful.</p>\n\n<p>First thing I notice is that in the <code>addToAccount</code> method you synchronize the access to the <code>buySell</code> list, which is redundant because it's already synchronized in the constructor. The only time you woul... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-17T04:49:05.143",
"Id": "41852",
"Score": "6",
"Tags": [
"java",
"thread-safety",
"concurrency",
"finance",
"locking"
],
"Title": "Thread-safe retirement account class"
} | 41852 |
<p>I haven't been able to find an existing tool that does this, so I'm attempting to create one. If anyone knows of one that already exists, I'd appreciate a pointer to it. I plan on using this primarily for cleaning up old backup copies and was hoping for a review of its correctness or suggestions for improvement. Par... | [] | [
{
"body": "<ul>\n<li>Yes, <code>filecmp.cmp</code> compares the contents of the files with <code>shallow=False</code></li>\n<li>Breaking <code>main</code> into more functions still gives better structure</li>\n<li>Making <code>get_dir_file_paths</code> a generator reduces memory use when building <code>size_to_... | {
"AcceptedAnswerId": "42188",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-17T05:59:51.160",
"Id": "41853",
"Score": "6",
"Tags": [
"python",
"file-system"
],
"Title": "Byte by byte directory comparison ignoring folder structures and file name differences"
} | 41853 |
<p>I have a method that returns a list from a HTML page:</p>
<pre><code>private List<HtmlNodes> GetRelevantNodes(HtmlDocument aHtmlDoc, string aID)
{
List<HtmlNode> nodes = new List<HtmlNode>();
HtmlNode currentDiv = aHtmlDoc.GetElementbyId(aID);
if (currentDiv == null)
retur... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-17T11:24:15.287",
"Id": "72049",
"Score": "0",
"body": "No, you don't want to expand your question. We're here to do code reviews, not answer questions. Your question is already borderline because of the wording (hence you already have... | [
{
"body": "<p>You're right, this is not the best thing to do. The correct way would be to return an empty list.</p>\n\n<pre><code>private List<HtmlNodes> GetNodes(HtmlDocument aHtmlDoc, string aID)\n{\n List<HtmlNode> nodes = new List<HtmlNode>();\n\n HtmlNode currentDiv = aHtmlDoc.GetEl... | {
"AcceptedAnswerId": "41875",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-17T09:46:08.347",
"Id": "41867",
"Score": "4",
"Tags": [
"c#",
"null"
],
"Title": "Return value when the requested variable returns null"
} | 41867 |
<p>I have a concept based polymorphism example listed below. I allow the user to provide any type that implements the draw method and then I add it into a vector of <code>unique_ptr</code> to concept base. If I have a pointer or reference I want to be able to deal with that even though the solution has value semantics ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-17T13:37:28.847",
"Id": "72069",
"Score": "3",
"body": "Be careful with the wording. Your `drawable_concept` is an interface. Concepts relate to a template mechanism that might come in C++14."
},
{
"ContentLicense": "CC BY-SA 3... | [
{
"body": "<p>There is not much to be said actually, the concept-based polymorphism seems to be well implemented. You can slightly improve your <code>push_back</code> method by having it <code>emplace_back</code> the <code>std::unique_ptr</code>. It will be a little bit less verbose:</p>\n\n<pre><code>template&... | {
"AcceptedAnswerId": "44101",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-17T13:34:36.720",
"Id": "41879",
"Score": "11",
"Tags": [
"c++",
"c++11",
"polymorphism"
],
"Title": "Concept based polymorphism"
} | 41879 |
<p>After watching <a href="https://twitter.com/raymondh" rel="nofollow">Raymond Hettinger</a>s talk <a href="http://www.youtube.com/watch?v=OSGv2VnC0go" rel="nofollow">Transforming Code into Beautiful, Idiomatic Python</a> I got back to a function I wrote.</p>
<p>I'm not quite sure how to make it more pythonic but I t... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-17T19:43:17.317",
"Id": "72171",
"Score": "0",
"body": "There shouldn't be a leading underscore in the function name. By convention, a leading underscore would indicate that it is a private member of a class."
}
] | [
{
"body": "<p>Removing the logging and using <a href=\"http://docs.python.org/2/tutorial/datastructures.html#sets\" rel=\"noreferrer\">set comprehension</a> :</p>\n\n<pre><code>def _mounted_drives(possible_device_letters=string.ascii_uppercase):\n return {l for l in possible_device_letters if os.path.exists(... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-17T15:03:30.327",
"Id": "41885",
"Score": "2",
"Tags": [
"python",
"functional-programming",
"file-system",
"windows",
"logging"
],
"Title": "Loop filling a set with logging"... | 41885 |
S.O.L.I.D is a set of principles used for designing object oriented solutions:
S - Single Responsibility principle
O - Open Closed principle
L - Liskov Substitution principle
I - Interface Segregation principle
D - Dependency Inversion principle | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-17T16:14:34.130",
"Id": "41892",
"Score": "0",
"Tags": null,
"Title": null
} | 41892 |
<p>A bowling score calculator is my go-to exercise for learning the basics of a language. I recently had to pick up Perl so I did this.</p>
<p>I'm concerned that I'm doing subroutines wrong. I had a hard time figuring out the syntax for dealing with arguments and what <em>exactly</em> <code>@_</code> is.</p>
<p>I'm j... | [] | [
{
"body": "<p>It's nice that you're using <code>strict</code> and <code>warnings</code>.</p>\n\n<h1>Subroutine Arguments</h1>\n\n<p>A subroutine should first unpack the argument list, e.g. like <code>my ($foo, $bar) = @_;</code>, then do some processing, and explicitly <code>return</code> a value. While we can ... | {
"AcceptedAnswerId": "41898",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-17T16:15:09.223",
"Id": "41893",
"Score": "10",
"Tags": [
"perl"
],
"Title": "Bowling calculator in Perl"
} | 41893 |
<p>I have fairly simple collision checking and handling Python code which is currently bottlenecking my performance quite a bit. I haven't done too much coding in python and I'm quite sure there's something that could be done better:</p>
<p>Assuming I read this profiler correctly, <code>get_nearby_entities</code> is t... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-17T20:42:09.130",
"Id": "72176",
"Score": "0",
"body": "It is difficult to improve the performance of code without a runnable test case whose performance we can measure. You could help us out here by making a self-contained runnable te... | [
{
"body": "<p>Looking at your profiling information you spend a total of 14.5s in handle_collision() out of which 3.8s is spent in get_nearby_entities. So your culprit may actually be somewhere else (I can't tell without the rest of your source).</p>\n\n<h2>Precalculate/Cache nearby status</h2>\n\n<p>You are ca... | {
"AcceptedAnswerId": null,
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-17T20:00:56.273",
"Id": "41907",
"Score": "8",
"Tags": [
"python",
"performance",
"collision",
"sfml"
],
"Title": "Performance of collision detection in a grid"
} | 41907 |
<p>I'm doing a program for a course in school (intro software development) and I'm looking for some general feedback as well as any ways this bit of code could be cleaner. I'm also wondering if it is bad practice to use <code>%=</code> as I've talked with some people and have been told it's not good to use any operator... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-17T20:58:24.607",
"Id": "72181",
"Score": "7",
"body": "You might not want to be so hasty to choose an accepted answer. Give people time to answer, and then make a selection. Selecting an answer so soon may also ward off some answers... | [
{
"body": "<p>I have no problem with <code>+=</code>, <code>-=</code> and even <code>*=</code>. But for <code>/=</code> and <code>%=</code>... perhaps I am just not used to them enough to like seeing them. I would recommend not using <code>%=</code>, but that is mostly my personal preference.</p>\n\n<p>Other co... | {
"AcceptedAnswerId": "41911",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-17T20:27:38.923",
"Id": "41909",
"Score": "15",
"Tags": [
"java"
],
"Title": "Java %= and general feedback"
} | 41909 |
<p>I am making a simple counter in assembly. It counts to a billion and exits. However, the performance of this is really horrible. A Java application (that does the same) outperforms it by around 10x. How can I optimize this code?</p>
<pre><code>include 'include/win32ax.inc'
section '.data' Data readable writeable
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-17T23:12:33.343",
"Id": "72197",
"Score": "0",
"body": "I edited my answer after you accepted it."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-18T20:50:42.027",
"Id": "72375",
"Score": "0",
"... | [
{
"body": "<p>Load <code>[incr]</code> into a register instead, for example <code>eax</code>, and increment the register.</p>\n\n<p>Instead of <code>cmp [incr], 1000000000</code> and <code>jne</code>, try loading 1000000 into the <code>ecx</code> register and using the <a href=\"http://en.wikibooks.org/wiki/X86... | {
"AcceptedAnswerId": "41919",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-17T22:33:48.103",
"Id": "41916",
"Score": "4",
"Tags": [
"optimization",
"performance",
"assembly"
],
"Title": "Counter in FASM assembly"
} | 41916 |
<p>I have a class that serves to carry data between my JavaScript evaluation class and the player, via the Bukkit Conversations API, available in full <a href="https://github.com/Saposhiente/EvalJS/blob/master/src/com/github/Saposhiente/EvalJS/CodePrompt.java">on GitHub</a> (you will need <a href="http://dl.bukkit.org/... | [] | [
{
"body": "<p>Your code is actually pretty good overall. I have one very big question, though: <em>why</em> do you want all these to be inner classes? Normally, we use inner classes only for a very specific reason and only if the class in question is a <em>critical component</em> of the outer class and someho... | {
"AcceptedAnswerId": "42457",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-18T00:14:37.670",
"Id": "41920",
"Score": "11",
"Tags": [
"java",
"console"
],
"Title": "Using Bukkit conversations for a coding console"
} | 41920 |
<p>Any major security risks? And please don't get angry over my novice log system.</p>
<pre><code><?php
function makesalt($lg)
{
$chars = 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789!@#$%^&*()-';
$sz = strlen( $chars );
$str = '';
for( $i = 0; $i < $lg; $i++ ) {
... | [] | [
{
"body": "<p>You home brewed security hashes and such are a big <strong>NO</strong>. Please, <a href=\"https://security.stackexchange.com/questions/25585/is-my-developers-home-brew-password-security-right-or-wrong-and-why\">check here</a> and <a href=\"https://security.stackexchange.com/questions/211/how-to-se... | {
"AcceptedAnswerId": "41925",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-18T00:21:26.953",
"Id": "41921",
"Score": "4",
"Tags": [
"php",
"security",
"hashcode"
],
"Title": "A PHP Toolkit of some functions"
} | 41921 |
<p>A (long) while ago I set up a file server in my basement running Linux. I am OCD when it comes to backups.</p>
<p>I set the server up with (remember, this was a while ago):</p>
<ul>
<li>disk for OS</li>
<li>disk for 'valuable' things</li>
<li>disk for backups</li>
</ul>
<p>The idea was that if any one disk failed... | [] | [
{
"body": "<p>Well, this is actually pretty decent code. There still is a lot of stuff that could be improved, I tried to focus on some more relevant ones.</p>\n\n<h2>Subroutine Prototypes</h2>\n\n<p>In a declaration like <code>sub foo ($@&*) { ... }</code>, we call the weird thing in parens a <em><a href=\... | {
"AcceptedAnswerId": "42357",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-18T02:00:18.627",
"Id": "41928",
"Score": "21",
"Tags": [
"perl",
"linux",
"file-system"
],
"Title": "Regular backup/snapshots"
} | 41928 |
<p>How can I improve this code (elegance, best practices, etc)?</p>
<pre><code>""" Simple in-memory database as a response to the Thumbtack coding challenge. """
class SimpleDb(object):
""" Simple in-memory database as a response to the Thumbtack coding challenge. """
def __init__(self):
""" Initia... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-18T02:30:20.917",
"Id": "72220",
"Score": "3",
"body": "Do you want to add http://www.thumbtack.com/challenges/software-engineer#simple-db to the question as a definition of the program's specification?"
},
{
"ContentLicense": ... | [
{
"body": "<p>I find your treatment of transactions odd. I would expect that when a transaction is in progress, data modifications commands get buffered; queries would consult the state stored in the current transaction for any relevant data, then any stacked transactions, then finally consulting the \"real\" ... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-18T02:08:46.853",
"Id": "41930",
"Score": "3",
"Tags": [
"python",
"database",
"python-2.x"
],
"Title": "Simple in-memory database"
} | 41930 |
<p>I have lots of external shell commands to run.</p>
<p>So I gave every command a name and then run it.</p>
<pre><code>tar_report_cmd = 'zip -r {0} {1} '%(report_file, _export_dir)
exec_proc(tar_report_cmd)
mv_report_cmd = "mv {0} {1}".format(report_file,report_dir)
exec_proc(mv_report_cmd)
</code></pre>
<p>But it... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-18T13:20:47.550",
"Id": "72272",
"Score": "0",
"body": "For the examples given, I would suggest using the library support for zip files and moving files. It's more cross-platform and gives you better precision and error recovery option... | [
{
"body": "<p><strong>No, it is a security risk</strong>, and furthermore, <code>os.popen()</code> has been <a href=\"http://docs.python.org/2/library/os.html#file-object-creation\">deprecated</a> since Python 2.6. The replacement is to use the <a href=\"http://docs.python.org/2/library/subprocess.html#replaci... | {
"AcceptedAnswerId": null,
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-18T05:40:35.610",
"Id": "41936",
"Score": "3",
"Tags": [
"python",
"python-2.x"
],
"Title": "Is it a good style to run external commands in Python?"
} | 41936 |
<pre><code>public static void streamReport(this Report report, Stream stream)
{
using (var streamWriter = new StreamWriter(stream))
{
//some logic that calls streamWrite.Write()
streamWriter.Flush();
}
//Should "return stream;" here ?
}
</code></pre>
<p>I am writing an extension ... | [] | [
{
"body": "<ol>\n<li>Do you <em>need</em> the <code>Stream</code> reference in outer scope? I doubt it. After all, you already pass this same reference as parameter, so you should <em>already have</em> it. Also pay attention to <code>StreamWriter</code>. When you dispose it in <code>using</code> block - you dis... | {
"AcceptedAnswerId": "41942",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-18T07:32:27.283",
"Id": "41939",
"Score": "6",
"Tags": [
"c#",
"asp.net",
"stream"
],
"Title": "Extension method that writes to a stream"
} | 41939 |
<p>Can someone review my code which I put on exercism.io for the word-count exercise (found <a href="https://github.com/exercism/exercism.io/blob/master/assignments/python/word-count/word_count_test.py">here</a>)?</p>
<pre><code>class Phrase:
def __init__(self, phrase):
self.phrase = phrase.strip().lower()... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-18T09:57:38.187",
"Id": "72247",
"Score": "0",
"body": "I understand this is a Python exercise, but note that in real text word counting is not that easy. 'fish/meat' should be two words but 'A/C' only one. 'Los Angeles' should possibl... | [
{
"body": "<p>My first advice is <a href=\"http://www.youtube.com/watch?v=o9pEzgHorH0\" rel=\"nofollow noreferrer\">stop writing classes</a> if you don't need to : your class has only two methods an <code>init</code> and a proper method. This could probably be written as a simple function.</p>\n\n<pre><code>def... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-18T08:12:01.600",
"Id": "41941",
"Score": "6",
"Tags": [
"python",
"exercism"
],
"Title": "Exercism assignment word-count in Python"
} | 41941 |
<p>I have used <code>INotifyPropertyChanged</code> for both Model and ViewModel. Is it correct?
First of all I was trying to use <code>INotifyPropertyChanged</code> only with Model, but for that I had to use observable collections in UI class.</p>
<p>Please comment on my design.</p>
<p><strong>MainPage.xaml</strong><... | [] | [
{
"body": "<p>Only your viewmodel should implement <code>InotifyPropertyChanged</code>. That's kind of the whole point of mvvm. Normally, your viewmodel properties wrap your model properties. Also, it is your model, that should contain all the business logic. Viewmodel should know nothing about <code>Storage</c... | {
"AcceptedAnswerId": "41948",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-18T10:02:48.547",
"Id": "41945",
"Score": "2",
"Tags": [
"c#",
".net",
"mvvm",
"event-handling",
"xaml"
],
"Title": "MVVM implementation using C# and XAML"
} | 41945 |
<p>I have written a script that sits on the admin portion on my website. </p>
<p>Here I assume the user is valid as I have code that checks that already.</p>
<p>The below code is checks if the user is Admin. If they are Admin they will be flagged with a "Y" on the database (this will be a "1" for optimization later b... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-18T11:25:24.517",
"Id": "72255",
"Score": "0",
"body": "If you want to edit the code, put your edited code after (not replacing) the existing code; otherwise that invalidates existing answers: see [Can I edit my own question to include... | [
{
"body": "<p>I see you're not using the <a href=\"http://msdn.microsoft.com/en-us/library/5k850zwb.ASPX\" rel=\"nofollow\">role manager</a> built into .NET (together with a built-in membership provider). If you were, then this could be codeless and configured in the <code>Web.config</code>.</p>\n\n<p>For examp... | {
"AcceptedAnswerId": "41950",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-18T10:21:14.343",
"Id": "41946",
"Score": "4",
"Tags": [
".net",
"vb.net",
"authentication"
],
"Title": "Login script check"
} | 41946 |
<p>I have spent the last 6 months as I am studying web development in college to build a website template that is responsive and accessible from as many devices and browsers as possible. </p>
<p>I would really appreciate it if someone reviewed my HTML structure, CSS and share their opinion with me, my aim is to make t... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-19T20:52:14.820",
"Id": "72654",
"Score": "1",
"body": "The .inc ext is not used anymore. Switch to .php as it can introduce some security issues."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-06-06T09:43:16... | [
{
"body": "<p><strong>HTML:</strong></p>\n\n<ol>\n<li><p>Depending on the language on your website, you should add the <code>lang</code> attribute to your <code>html</code> tag:</p>\n\n<pre><code><html lang=\"en\">\n</code></pre></li>\n<li><p>You're missing the important viewport and charset meta tags in ... | {
"AcceptedAnswerId": "41952",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-18T10:32:58.543",
"Id": "41947",
"Score": "15",
"Tags": [
"php",
"html",
"css",
"html5",
".htaccess"
],
"Title": "Portable website template"
} | 41947 |
<p>because Arduino platforms are fairly limited in its capacities, I wrote a small process scheduler. I append a function to an array and define a tickrate. After this tickrate elapses, the function should be called. Additionally I set a small delay. If several function share the same tickrate, this delays hinders them... | [] | [
{
"body": "<p>Just a few minor notes: <a href=\"http://www.codinghorror.com/blog/2006/01/flattening-arrow-code.html\">guard clauses</a> (inverting a few conditions and using <code>continue</code>) would make the code flatten and easier to read:</p>\n\n<pre><code>for(uint8_t i = 0; i < iSize_N; i++) {\n ui... | {
"AcceptedAnswerId": "42019",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-18T11:52:04.593",
"Id": "41954",
"Score": "5",
"Tags": [
"c++",
"arduino"
],
"Title": "Simple and fair scheduler for function calls on Arduino"
} | 41954 |
<p>I am new user of CodeIgniter and I am trying to build an application that there are lots of jQuery dynamical content.</p>
<p>Below I provide a code that I am using in order to be precise. The code below is running and I cannot see any problem. However, since I will be using pieces of code like this in several diffe... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-19T01:59:10.167",
"Id": "72430",
"Score": "0",
"body": "I would suggest that you use a templating framework (ex: handlebar just to name one) in the client side and simply send json instead of html in your ajax calls/ api.Also, I really... | [
{
"body": "<p>You are right with your concerns regarding the model rendering the output. But you're almost there ain't you? Why don't you let your model return the data instead of the HTML-Code and let the controller call <code>writeHtmlSearchPeople</code>: </p>\n\n<pre><code>class MSearchPeople extends CI_Mode... | {
"AcceptedAnswerId": "42027",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-18T13:25:17.137",
"Id": "41959",
"Score": "3",
"Tags": [
"php",
"jquery",
"html",
"mvc",
"codeigniter"
],
"Title": "Best practice for generating jQuery dynamical content"
... | 41959 |
<p>I have been collecting snippets from all over the place and then put them all together creating the following .htaccess file.</p>
<p>I really don't understand if what I have done below is good/should work as expected, so your opinion is really appreciated.</p>
<p>I also don't understand the bit just after <code>#L... | [] | [
{
"body": "<p>Leverage browser caching is designed to prevent browsers from using a cache for too long. If your website is dynamic, this is necessary to prevent users' browsers from storing your website for too long.</p>\n\n<p>The way your file does this is by checking the type of file, and making a browser's c... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-18T14:35:48.770",
"Id": "41964",
"Score": "3",
"Tags": [
"cache",
".htaccess",
"compression"
],
"Title": "htaccess for URL remapping, caching, and compression"
} | 41964 |
<p>I want to parse a command line using <a href="http://www.boost.org/doc/libs/1_55_0/doc/html/program_options.html" rel="nofollow"><code>boost.program_options</code></a>. Most of my command line arguments will be intervals, which I could implement as something like <code>--x-min=2000</code> and <code>--x-max=2500</cod... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-18T15:04:39.897",
"Id": "41967",
"Score": "4",
"Tags": [
"c++",
"parsing",
"console",
"stream",
"boost"
],
"Title": "Reading Intervals from command line"
} | 41967 |
<p>This code works. It is designed to retrieve website data directly, parse it, and open it as normal. I will develop it further later. Right now I want to know if there is any way to improve efficiency, such as not using a file etc. I would also like to know if my code could be made more pythonic (this would include P... | [] | [
{
"body": "<p><strong>1.</strong> Make sure your variable names are both short and to the point, using a parameter called junk is pointless. Also, this could cause conflicts if you ever write other code and import this.</p>\n\n<pre><code>def parse(junk):\n ugly = str(junk)[2:-1]\n lines = ugly.split('\\\\... | {
"AcceptedAnswerId": "41976",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-18T15:40:00.723",
"Id": "41970",
"Score": "4",
"Tags": [
"python",
"file-system",
"http"
],
"Title": "Proxy evasion browser in Python"
} | 41970 |
<p>I would appreciate some insights / comments from Clojure regulars out there about my submission <a href="https://github.com/exercism/exercism.io/tree/master/assignments/clojure/word-count" rel="nofollow">here</a>.</p>
<pre><code>(ns phrase)
(require '[clojure.string :as s])
(defn word-array
[phrase]
(-> (s/... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-18T18:32:17.790",
"Id": "72347",
"Score": "0",
"body": "It seems like a copy of the example code provided in the linked repository. What kind of feedback would you like about it ?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"Cr... | [
{
"body": "<p>I would format it like this:</p>\n\n<pre><code>(ns phrase\n (:require [clojure.string :as s]))\n\n(defn word-array [phrase]\n (s/split (s/lower-case phrase) #\"\\W+\"))\n\n(defn word-count [phrase]\n (frequencies (word-array phrase)))\n</code></pre>\n\n<p>Notice that I included the <code>requir... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-18T16:31:23.503",
"Id": "41978",
"Score": "4",
"Tags": [
"clojure",
"exercism"
],
"Title": "Exercism assignment for word-count in Clojure"
} | 41978 |
exercism.io is intended to be a conversation about what good code might look like.
The point is to pass the provided unit tests with expressive, readable code. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-18T16:36:49.607",
"Id": "41980",
"Score": "0",
"Tags": null,
"Title": null
} | 41980 |
<p>I created the following HtmlHelper extension method for my Asp.Net MVC Razor views because the ternary syntax sucks when you need to use it intermixed with markup.</p>
<p>Is there a better way to write this and are there any potential type safety issues with it?</p>
<pre><code>public static string GetValueTernary(... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-18T16:51:11.767",
"Id": "72326",
"Score": "4",
"body": "Main issue I can see is that all arguments will be evaluated no matter what. Also your code could be factorised out : `return (a.Equals(b) ? valueIfEqual : valueIfNotEqual).ToStri... | [
{
"body": "<p>Your code will throw an exception when <code>a</code> is <code>null</code>. A safe way to compare values is <a href=\"http://msdn.microsoft.com/en-us/library/w4hkze5k\">the static version of <code>object.Equals()</code></a>:</p>\n\n<pre><code>object.Equals(a, b)\n</code></pre>\n",
"comments": ... | {
"AcceptedAnswerId": "41991",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-18T16:39:34.697",
"Id": "41982",
"Score": "7",
"Tags": [
"c#",
"asp.net-mvc-4",
"extension-methods",
"razor"
],
"Title": "Ternary extension method"
} | 41982 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.