body stringlengths 25 86.7k | comments list | answers list | meta_data dict | question_id stringlengths 1 6 |
|---|---|---|---|---|
Yii is a high-performance, MVC architecture based, open source PHP framework best for developing Web 2.0 applications. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-14T06:31:13.013",
"Id": "56976",
"Score": "0",
"Tags": null,
"Title": null
} | 56976 |
<p>This is my second attempt (<a href="https://codereview.stackexchange.com/questions/56900/simple-parsing-for-string-formatting">version 1</a>) at writing a string formatting utility which uses parsing. This time I more explicitly designed it as a finite state machine. I have very little experience with writing FSMs. ... | [] | [
{
"body": "<p>I think CS subjects like automata are too much for this problem, thats more something you have to deal with when implementing a regular expressions engine. Here is some code in C# that I've written to replace tags in a string, its absolutely not optimal because the state is checked every iteration... | {
"AcceptedAnswerId": "56992",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2014-07-14T08:01:12.570",
"Id": "56978",
"Score": "9",
"Tags": [
"c++",
"c++11",
"formatting",
"boost",
"state-machine"
],
"Title": "Simple parsing for string formatting (version ... | 56978 |
<p>I tried to implement the idea given in the <a href="http://www.elasticsearch.org/guide/en/elasticsearch/guide/current/reindex.html" rel="nofollow">elasticsearch doc about reindexation</a> albeit I think they must code it inside ElasticSearch and expose it as an API.</p>
<pre><code>#!/usr/bin/env python
from __futu... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-14T09:34:42.427",
"Id": "101624",
"Score": "0",
"body": "As you don't say anything specific about what you are looking for, I assume you just want a general review about all of the aspects?"
},
{
"ContentLicense": "CC BY-SA 3.0... | [] | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-14T08:19:02.953",
"Id": "56979",
"Score": "2",
"Tags": [
"python",
"elasticsearch"
],
"Title": "Little script to change the mapping of an existing ElasticSearch index while reindexing it... | 56979 |
<p>I'm trying to write a function which will cache objects in memory.</p>
<p>The function below works, but performance is unbearable. What would you recommend to improve performance?</p>
<pre><code> public void SerializeInsertCache(object item)
{
//Get type of item object item
Type typ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-12T00:35:44.810",
"Id": "101633",
"Score": "3",
"body": "Reflection is slow. Make sure you never use Reflection more than once for the same data. Use a Dictionary or something to store results, so you can do a lookup and avoid using ... | [
{
"body": "<p>Vast swaths of this code have no apparent use. Cutting out the code that does not appear to have an effect, you seem to be left with:</p>\n\n<pre><code>public void SerializeInsertCache(object item)\n{\n Type type = item.GetType();\n PropertyInfo[] properties = type.GetProperties();\n... | {
"AcceptedAnswerId": "56986",
"CommentCount": "8",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-12T00:32:07.817",
"Id": "56985",
"Score": "2",
"Tags": [
"c#",
".net",
"performance",
"recursion"
],
"Title": "improve performance of recursive function in c# method"
} | 56985 |
<p>Does someone know of a better way to get proper grammar in sentences than this method of mine? I don't want to continue with this for my entire huge program if there is a much more elegant way.</p>
<pre><code>#include <iostream>
#include <string>
enum Gender {Male, Female};
enum Capitalized {Capital, N... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-13T15:30:07.093",
"Id": "101642",
"Score": "0",
"body": "All of those pointers should be `Person`s."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-13T15:33:04.210",
"Id": "101643",
"Score": "1",
... | [
{
"body": "<p>It seems like you would need to write 3 different sentences for every out you want.\nFormat strings can help here (maybe not in the edge cases - however you have given no example of those)</p>\n\n<p>\"%s rock%s!\".\nThe first string is then either \"You\", \"He\", or \"She\".\nThe second one is fo... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-13T15:28:48.810",
"Id": "56989",
"Score": "2",
"Tags": [
"c++"
],
"Title": "Getting correct English grammar"
} | 56989 |
<p>I have written the following code for looping through <code>WebElement</code>s in Selenium. </p>
<p>Can someone please provide me with feedback on how to improve my code?</p>
<pre><code> public static void checkAbsentSearchResult(String title, String Testgoal) throws IOException{
try{
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-14T14:39:24.487",
"Id": "101699",
"Score": "0",
"body": "I transalated the boolean"
}
] | [
{
"body": "<h2>Naming</h2>\n\n<p>As the method is writing state messages in each case, you should consider to rename the method to <code>exportAbsentSearchResult</code>.</p>\n\n<h2>Duplicate code</h2>\n\n<pre><code>WriteToXSL.WriteTo(goal, state, message);\nWriteToPDF.addRow(goal, state, message);\n</code></pre... | {
"AcceptedAnswerId": "57023",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-14T12:33:50.103",
"Id": "56996",
"Score": "2",
"Tags": [
"java",
"dom",
"selenium"
],
"Title": "List of search results using Selenium"
} | 56996 |
<p>I have this code which I wrote to parse arithmetic expressions.</p>
<p>However, many people say there are problems with it but don't tell me what the problem is. Please let me know if you see any.</p>
<p>Note that I know there is another way to do this. But I did it specifically this way as I am influenced by NLP ... | [] | [
{
"body": "<p>Is this homework? Or just for fun? If it is for real work, I would suggest using an existing framework. I have not done parsing myself, but it is a common use-case and there are many frameworks. I vaguely know of antlr.</p>\n\n<p>I am not a specialist in the domain, so I can't realy comment on... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-14T13:49:33.713",
"Id": "56999",
"Score": "7",
"Tags": [
"java",
"parsing",
"math-expression-eval"
],
"Title": "Parsing arithmetic expressions like (x + y * a + b *z)"
} | 56999 |
<p>I'm building a GameClient-Class in Python which handles user input and has to read from a database (MongoDb). I want to know if that is the best practice to implement it, so that I can use it with Python's <code>with</code> statement. </p>
<p>Because I want to use different functions of my <code>Client</code> class... | [] | [
{
"body": "<p>The reason to use a <code>with</code> clause is 1) clarity and 2) exception handling. Clarity because you have explicitly called out \"right here, I am working with the object\" and exception handling because you are guaranteed to have the exit handler called and any cleanup accomplished.</p>\n\n<... | {
"AcceptedAnswerId": "57050",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-14T13:54:27.230",
"Id": "57000",
"Score": "1",
"Tags": [
"python",
"object-oriented",
"game"
],
"Title": "Implementing use of 'with CustomClass() as foo' in own class with DB-Conn... | 57000 |
<p>I've isolated this function, <code>cons</code>, for <a href="http://en.wikipedia.org/wiki/Hash_consing" rel="nofollow">hash-consing</a> in C. It is where the bottleneck of my program is. How could its performance be improved?</p>
<pre><code>var32 cons(var32 x, var32 y){
var32 ptr;
uid id, hashedId;
map ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-10-25T14:31:28.643",
"Id": "123875",
"Score": "0",
"body": "Your code link has gone dead, so I cannot see the complete source."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-10-26T00:07:26.633",
"Id": "12397... | [
{
"body": "<p>Your code here is hard to follow because your code style and format are inconvenient. </p>\n\n<p>Structures like this:</p>\n\n<blockquote>\n<pre><code>currentMap = mapByHashedId[hashedId];\nif (currentMap) do {\n if (mapId[currentMap] == id)\n return mapPtr[currentMap];\n #ifdef __DEB... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-14T14:22:27.577",
"Id": "57002",
"Score": "6",
"Tags": [
"optimization",
"performance",
"algorithm",
"c"
],
"Title": "Hash-consing: running slow"
} | 57002 |
<p>I'd like to see if my code follows common practice, or is already efficient or fast enough.</p>
<pre><code>from random import randint
w=[[2,0,0,0,0],[0,0,2,0,0],[0,0,1,0,0],[0,0,0,0,0],[0,0,0,0,0]] #1 represent Mr.Pacman, #2 represent food.
for y in xrange(len(w)): #Finding the coordinate of Mr.Pacman
for x in ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-14T15:53:29.953",
"Id": "101715",
"Score": "1",
"body": "How efficient is \"efficient enough\"? And it certainly doesn't follow [common practice](http://legacy.python.org/dev/peps/pep-0008/)."
},
{
"ContentLicense": "CC BY-SA 3... | [
{
"body": "<p>About your code following common practices, you may read about <a href=\"http://legacy.python.org/dev/peps/pep-0008/\" rel=\"nofollow\">PEP8</a>.</p>\n\n<p>You have far too many lines with more than 80 characters, you even have a line with 180+ characters: Does not fit my screen.</p>\n\n<p>You may... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-14T14:35:42.057",
"Id": "57004",
"Score": "2",
"Tags": [
"python",
"python-2.x",
"pathfinding"
],
"Title": "Is this Python pathfinder efficient enough?"
} | 57004 |
<p>I have wrote some animation code, and it's what I class as old school. As you can see, there is a lot of repeating code. Ideally, I would like to be able to take the delay and left or right position from a data attribute set on the button itself:</p>
<pre><code>$(".click").click(function(){
$(this).delay(400).ani... | [] | [
{
"body": "<p>It would be nice if there was a JsFiddle to go along with this. Below is the code you posted refactored to utilize event delegation so you don't need to repeat the click handlers. Plus <code>data-*</code> HTML attributes are used to parameterize certain things. Lastly we should be able to utilize ... | {
"AcceptedAnswerId": "57091",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-14T15:06:27.437",
"Id": "57008",
"Score": "3",
"Tags": [
"javascript",
"jquery",
"animation"
],
"Title": "Animation delay"
} | 57008 |
<blockquote>
<p><strong>The problem:</strong> </p>
<p>Start with two arrays of strings, a and b, each in alphabetical order,
possibly with duplicates. Return the count of the number of strings
which appear in both arrays.</p>
<p><code>commonTwo({"a", "c", "x"}, {"b", "c", "d", "x"})</code> → <strong>2</... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-14T15:43:52.147",
"Id": "101713",
"Score": "2",
"body": "Would `{\"a\", \"a\"}, {\"a\"}` be expected to return 1 or 2? What about `{\"a\", \"a\"}, {\"a\", \"a\"}`?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "20... | [
{
"body": "<p>Java is not my strong-point, but there are a few things that stand out.</p>\n\n<ul>\n<li>Spacing is non-standard.</li>\n<li><p>There are unnecessary parentheses, e.g. in</p>\n\n<blockquote>\n<pre><code>(i<a.length)&&(j<b.length)\n</code></pre>\n</blockquote>\n\n<p>and</p>\n\n<blockqu... | {
"AcceptedAnswerId": "57064",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-14T15:20:33.747",
"Id": "57010",
"Score": "6",
"Tags": [
"java",
"strings",
"programming-challenge"
],
"Title": "Finding common strings among 2 arrays of strings of length 1, sort... | 57010 |
<p>I'm new to PHP and just wrote a bunch of <code>if</code> statements to display content based on the current time.</p>
<p>Is there a better way of writing the following block of code to easily be maintainable? The only thing that changes in each <code>if</code> statement is the <code>if</code> variables, <code>h4</c... | [] | [
{
"body": "<p>You are repeating a lot of HTML, which I guess you know could be condensed down, you can also make use of <a href=\"http://php.net/manual/en/control-structures.elseif.php\" rel=\"nofollow\"><strong>elseif</strong></a> this way it will execute the first <strong>TRUE</strong> statement and skip the ... | {
"AcceptedAnswerId": "57015",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-14T15:33:24.050",
"Id": "57011",
"Score": "6",
"Tags": [
"php",
"optimization",
"beginner",
"datetime"
],
"Title": "Displaying content based on the current time"
} | 57011 |
<p>For my <a href="/questions/tagged/rags-to-riches" class="post-tag" title="show questions tagged 'rags-to-riches'" rel="tag">rags-to-riches</a> submission, I've decided to improve this code:</p>
<p><a href="https://codereview.stackexchange.com/questions/27986/text-based-rpg-game-using-classes">Text-based RPG... | [] | [
{
"body": "<p>As it is, I can see an oversight in the <code>level_up</code> function: imagine that you need 5xp to level up. You gain 50xp, you level up, and your xp is 0 again. You just wasted 45xp! Here is the corrected function:</p>\n\n<pre><code>void level_up()\n{\n level++;\n exp -= req_EXP; // ... | {
"AcceptedAnswerId": "57039",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-14T15:47:47.603",
"Id": "57013",
"Score": "15",
"Tags": [
"c++",
"c++11",
"inheritance",
"rags-to-riches",
"battle-simulation"
],
"Title": "Encapsulated text-based RPG usi... | 57013 |
<p>I'm just looking for advice on how I can get my code to operate faster. It's pretty quick right now with searching through 30 3-page PDFs, but I imagine once there gets to be thousands of files to search that it will take longer than I'd like. I can change <code>SearchOption.AllDirectories</code> to <code>TopDirecto... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2016-04-20T07:44:14.237",
"Id": "235629",
"Score": "0",
"body": "You can also read an interesting c# acrobat remove text from pdf on this page http://www.rasteredge.com/how-to/csharp-imaging/pdf-text-edit-delete/"
}
] | [
{
"body": "<p>The major bottleneck is most likely in the <code>ReadPdfFile</code> method as we are dealing with a <code>PDF</code> file.</p>\n\n<p>In your <code>ReadPdfFile</code>method, a PdfReader is created to read through <strong>every</strong> page of the document to find the <code>searchText</code> and th... | {
"AcceptedAnswerId": "57048",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-14T16:49:37.747",
"Id": "57018",
"Score": "4",
"Tags": [
"c#",
"asp.net",
"search",
"pdf"
],
"Title": "Searching through various PDF files"
} | 57018 |
<p>This is based on my first review and the suggested points in "<a href="https://codereview.stackexchange.com/questions/56485/multiple-dispatch-decorator-in-python">Multiple dispatch decorator in Python</a>":</p>
<pre><code>import inspect
from functools import wraps, update_wrapper, partial
class multi_dispatch(obj... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-14T17:49:17.967",
"Id": "101731",
"Score": "0",
"body": "Obligatory suggestion to follow the [Python style guide](https://www.python.org/dev/peps/pep-0008)."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-1... | [
{
"body": "<p>The code itself looks quite pretty and overall readable, considering that the topic itself requires some knowledge about the Python language internals. Some suggestions in descending order of urgency:</p>\n\n<ol>\n<li><p>You should either document that <code>@classmethod</code> and <code>@staticme... | {
"AcceptedAnswerId": "58901",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-14T16:49:42.520",
"Id": "57019",
"Score": "9",
"Tags": [
"python",
"python-3.x",
"meta-programming",
"overloading"
],
"Title": "Multiple dispatch decorator classes in Python"
... | 57019 |
<p>I have a lot of data in separate files generated from a simulation program. All data is clear and formatted via a single space to read in 4 columns. I can open and store data from each file one at a time, but that will get so impossible once I hit more than, say, 10 files of data with the same simulation data column... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-14T18:49:12.823",
"Id": "101736",
"Score": "0",
"body": "I'm sorry, but request regarding adding new implementation is off-topic."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-14T18:55:43.800",
"Id": ... | [
{
"body": "<p>As you're new to C++, you should be aware that implementing an entire program in <code>main()</code> can make things difficult, especially when the code is already complex.</p>\n\n<p>As it appears, you have declare and initialize variables at the top, open the file, perform the operations, then ou... | {
"AcceptedAnswerId": "57037",
"CommentCount": "13",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-14T18:46:20.007",
"Id": "57025",
"Score": "3",
"Tags": [
"c++",
"beginner",
"file-system"
],
"Title": "Looping over files in C++ and changing their names to store data into a sin... | 57025 |
<p>I have decided to create a dashboard view of a number of running processes/programs/applications, because it became tedious to monitor a bunch of applications, which I had to boot up manually.</p>
<p>Please keep in mind that the .fxml files have been autogenerated using <em>JavaFX SceneBuilder 2.0</em> and hence ma... | [] | [
{
"body": "<h1>JavaFX Related</h1>\n\n<ol>\n<li><p><strong>main() method :</strong> in <em>Dashboard.java</em> You do not need it. It's an IDE bug, It's only required for old IDEs. (I recommend using the latest NetBeans, version 8) from <a href=\"http://docs.oracle.com/javase/8/javafx/get-started-tutorial/hello... | {
"AcceptedAnswerId": "59574",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-14T19:19:22.477",
"Id": "57026",
"Score": "10",
"Tags": [
"java",
"java-8",
"javafx"
],
"Title": "Dashboard for running programs in JavaFX 8"
} | 57026 |
<p>I just created 2 model class for my iOS app:</p>
<ol>
<li><p><code>HALUserDefaults</code> represents the persisted data in my app. It has the ability to both retrieve persisted data and store new data.</p></li>
<li><p><code>HALParseConnection</code> represents the connection to my Backend service Parse.com</p></li>... | [] | [
{
"body": "<h1><code>HALUserDefaults</code></h1>\n<p>First of all, the calls to <code>synchronize</code> can probably be eliminated. It's quite rare that you actually have to make this call in order for the data to properly persist, and making the call every time you store something in defaults completely elim... | {
"AcceptedAnswerId": "57051",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-14T19:20:39.643",
"Id": "57028",
"Score": "4",
"Tags": [
"mvc",
"objective-c",
"ios"
],
"Title": "Classes representing backend service and persisted data in iOS app"
} | 57028 |
<p>When using MVC 4 Razor (I am new to web development), I get concerned about my understanding of interactions between the database and the client. Much like all appilications these days, there is a lot of data that is presented to the user and in different fashions. I have looked around, and I can't find a concrete C... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-25T14:14:48.667",
"Id": "104022",
"Score": "1",
"body": "You're forgetting about the **M** in MVC. Put your data into a model, and pass that to a view. You don't have to use JSON and jQuery to put your data into the table."
},
{
... | [
{
"body": "<p>I really feel bad about recommending this, but based on what you're doing you should investigate the use of <a href=\"http://www.asp.net/web-forms\" rel=\"nofollow\">Webforms in ASP.NET</a>. </p>\n\n<p>Webforms are the most straightforward way to provide easy CRUD operations on a database in C# wh... | {
"AcceptedAnswerId": "57994",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-14T19:24:45.023",
"Id": "57029",
"Score": "2",
"Tags": [
"c#",
"jquery",
"json",
"ajax"
],
"Title": "Interacting with database in MVC"
} | 57029 |
<p>I have a somewhat unwieldy IF statement and am wondering if anyone has any suggestions on how to make it more readable.</p>
<p>One one line it was all but impossible to understand, so I broke it up into multiple lines:</p>
<pre><code>if (
empty($row) ... | [] | [
{
"body": "<p>I've used the second snippet since I've found that much easier/faster to understand:</p>\n\n<ol>\n<li><p>Here you could omit the <code>else</code> keyword:</p>\n\n<blockquote>\n<pre><code>if (empty($row)) { // if the row doesn't exist\n return $this->updateRow($id);\n}\nelse { // the row doe... | {
"AcceptedAnswerId": "57035",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-14T19:28:47.847",
"Id": "57030",
"Score": "3",
"Tags": [
"php"
],
"Title": "Formatting options for a long IF statement?"
} | 57030 |
<p>This question is a partial followup from my <a href="https://codereview.stackexchange.com/questions/55205/organization-data-class">previous question</a>, however the requirements have changed: I now need to be able to store multiple data entries for some fields.</p>
<p>I also have added two hooks into the <code>Org... | [] | [
{
"body": "<p>There are a number of things here to comment on. First up, you don't ask for anything in particular to be reviewed. So, I just scanned the code, looking for 'oddities'.</p>\n\n<p>There are some aspects which concern me.</p>\n\n<p>Marker interfaces are seldom a good idea. Why do you have <code>Orga... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-14T19:29:53.343",
"Id": "57031",
"Score": "5",
"Tags": [
"java",
"serialization"
],
"Title": "Robust organization data class (partial followup)"
} | 57031 |
<p>I have a written a quadtree program in Python 2.7 to cross-correlate large catalogs with each other i.e. find the common objects in the catalogs based on their position. The problem is that it's still quite slow. Accuracy is my primary goal (No throwing out real matches, no erroneous matches, and getting the true cl... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-14T20:33:47.520",
"Id": "101760",
"Score": "0",
"body": "Did you consider using [`scipy.spatial.KDTree`](http://docs.scipy.org/doc/scipy/reference/generated/scipy.spatial.KDTree.html)?"
},
{
"ContentLicense": "CC BY-SA 3.0",
... | [] | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-14T19:40:52.183",
"Id": "57033",
"Score": "1",
"Tags": [
"python",
"optimization",
"recursion",
"tree",
"python-2.x"
],
"Title": "Optimizing Recursive Quadtree"
} | 57033 |
<p>So I was playing with writing FizzBuzz in Elixir; this is my first, naive implementation:</p>
<pre><code>defmodule FizzBuzz do
def getFB(n) do
cond do
rem(n,15) == 0 ->
IO.puts "FizzBuzz"
rem(n,3) == 0 ->
IO.puts "Fizz"
rem(n,5) == 0 ->
IO.puts "Buzz"
... | [] | [
{
"body": "<p>The use-case you came up with looks like a very clear candidate to be a <a href=\"http://elixir-lang.org/docs/stable/elixir/GenServer.html\"><code>GenServer</code></a>.</p>\n\n<p>A <code>GenServer</code> implementation will eliminate your need to manage the serving process, and using its client-si... | {
"AcceptedAnswerId": "60010",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-14T19:59:25.493",
"Id": "57034",
"Score": "13",
"Tags": [
"fizzbuzz",
"elixir"
],
"Title": "Multi-process FizzBuzz in Elixir"
} | 57034 |
<p>This is a Python 2 script to take in a file in one of two formats (unknown), and standardize it.</p>
<p>The data are coordinates in the <em>xy</em>-plane. They represent airfoils in the first and fourth quadrants: <em>x</em> should always be positive, and <em>y</em> may be positive or negative. The magnitude o... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-14T20:45:36.297",
"Id": "101764",
"Score": "0",
"body": "Just saying, why not using the PEP8 style ?"
}
] | [
{
"body": "<ul>\n<li>don't use <code>is</code> to compare numbers</li>\n<li>don't use <code>\"\"\"</code> string literal as comments</li>\n<li>you don't need to use lambda with filter, just use <code>filter</code> with a validator function if you want list comprehension instead of explicit for loop. </li>\n</ul... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-14T20:17:16.000",
"Id": "57038",
"Score": "3",
"Tags": [
"python",
"parsing"
],
"Title": "More idiomatic way to write this Python coordinate parser?"
} | 57038 |
<p>I wrote a little code sample which:</p>
<ul>
<li>load images</li>
<li>manipulate DOM (replace images)</li>
<li>store/retrieve related data using
localStorage</li>
</ul>
<p></p>
<pre><code>$(document).on('ready', function(){
$('#chooseFile').on('click', function (e) {
url = $('#image-url').val();
// ch... | [] | [
{
"body": "<p>Interesting question,</p>\n\n<ol>\n<li><p>You should indeed put some things together</p>\n\n<ol>\n<li>But I would keep 3 distinct properties for a project of this small size</li>\n<li><code>updateBackgroundDimensions()</code> could know the URL from the <code>localStorage</code>..</li>\n<li><code>... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-14T20:32:05.443",
"Id": "57040",
"Score": "3",
"Tags": [
"javascript",
"image",
"http",
"url",
"callback"
],
"Title": "Load images, manipulate DOM, store/retrieve data using ... | 57040 |
<p>This is a wrapper for an API. For now all it does is get a certain document or search for relevant documents from a document store -- although I plan to build out more features later. I'm new to PHP and want to both improve my PHP skills and develop "idiomatic" PHP style. It depends on <code>HTTPFUL</code>, which, f... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-14T23:09:10.360",
"Id": "101782",
"Score": "0",
"body": "Are you sure you need those `json_decode()` calls? [Their website](http://phphttpclient.com/#json) says the `send()` call will return the json decoded response on its own."
}
] | [
{
"body": "<p>I am not a PHP developer so I can't give you an expect implementation but I do notice some things that will make handling the API easier.</p>\n\n<hr>\n\n<p><code>PHPDocumentCloud</code> does not need to contain 'PHP' since that's a given for any class you create. Unless that is the actual name of ... | {
"AcceptedAnswerId": "57066",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-14T21:01:01.137",
"Id": "57045",
"Score": "1",
"Tags": [
"php",
"beginner",
"http"
],
"Title": "Simple wrapper for an API"
} | 57045 |
<p>I have a large number of plain text files (north of 20 GB), and I wish to find all "matching" "bigrams" between any two texts in this collection. More specifically, my workflow looks like this: for each text, for each sentence in that text, for each possible combination of two non-stop-words ("bigram") in that sente... | [] | [
{
"body": "<h3>1. Introduction</h3>\n\n<p>This code is not ready to be optimized because it is such a mess. It is hard to read, hard to follow and hard to understand. I've written some detailed comments below, but really I've just scratched the surface.</p>\n\n<p>Your best bet is to rewrite the code so that the... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-14T21:07:48.950",
"Id": "57046",
"Score": "2",
"Tags": [
"python",
"performance",
"strings",
"natural-language-processing"
],
"Title": "Identifying \"Matching Bigrams\" in Large ... | 57046 |
<p>My goals are to make this code:</p>
<ul>
<li>faster</li>
<li>more idiomatic C++</li>
</ul>
<p>What the code does:</p>
<ul>
<li>take an integer command-line argument <code>N</code></li>
<li>make a vector of <code>N</code> random floating point values</li>
<li>make a matrix of <code>N*N</code> random floating point... | [] | [
{
"body": "<ul>\n<li><p>Since <code>outputName</code> is only used in <code>main()</code>, you can just keep it in there.</p></li>\n<li><p>With C++11, you should no longer use <code>rand()</code> because <a href=\"http://channel9.msdn.com/Events/GoingNative/2013/rand-Considered-Harmful\" rel=\"nofollow\">it's c... | {
"AcceptedAnswerId": "57055",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-14T23:46:35.840",
"Id": "57052",
"Score": "6",
"Tags": [
"c++",
"performance",
"c++11",
"matrix",
"vectors"
],
"Title": "Inner product of random floats written to file"
} | 57052 |
<p>I am writing a <code>TCP</code> client app using netty</p>
<p><strong>NettyConnectionManager.scala:</strong></p>
<pre><code>class NettyConnectionManager(val config : NettyConfig) extends ConnectionManager {
@volatile private var connection: Option[Connected] = None
def get() = {
if(isConnected) {
co... | [] | [
{
"body": "<ol>\n<li><p>A netty Channel can be open and not connected so your <code>NettyConnection.isConnected</code> is not correct. See <a href=\"https://stackoverflow.com/a/5714980/448141\">this</a>.</p></li>\n<li><p>and 3.</p></li>\n</ol>\n\n<p>It's pointless to write such code in scala. What you need is j... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-15T02:40:30.447",
"Id": "57060",
"Score": "3",
"Tags": [
"scala",
"thread-safety",
"networking",
"netty"
],
"Title": "Netty-based safely network reconnection"
} | 57060 |
<blockquote>
<p><em>You're running a jeans company. Your system is collecting detailed orders' data, but it's a bit archaic and it's storing the number of units ordered per size in a delimited string with 20 "fields", each taking up 4 characters. You want to normalize this data to make it easier to eventually analyze... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-15T04:10:04.463",
"Id": "101805",
"Score": "0",
"body": "This field of fields is stored in the database this way, or it's coming in from a text file?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-15T04:12... | [
{
"body": "<h3>The Good:</h3>\n<p>The code itself is pretty clean. You used clear and concise names and some of the best indentation I've ever seen in SQL. I would prefer that keywords like <code>substring</code> and <code>select</code> be ALLCAPS to differentiate them from fields and variables, but you were co... | {
"AcceptedAnswerId": "57087",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-15T04:03:15.600",
"Id": "57061",
"Score": "7",
"Tags": [
"performance",
"sql",
"parsing",
"sql-server"
],
"Title": "Put it in a bucket"
} | 57061 |
<p>I've been playing around with porting a simple strategy game over to Javascript, the idea being to run it in a browser for testing. I've done some simple Javascript code in the past, but this is my first model/view setup. I'd love to get feedback on following Javascript best practices and avoiding pitfalls. I kno... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-29T15:14:17.233",
"Id": "104813",
"Score": "0",
"body": "Is this really MVC?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-29T15:20:07.513",
"Id": "104814",
"Score": "0",
"body": "By MVC I jus... | [
{
"body": "<p>From a once over:</p>\n\n<ul>\n<li>HTML looks clean, though your title should not be blank per the HTML spec</li>\n<li>Your objects look fine, old skool JS OO, which is nice to read</li>\n<li>When you write <code>for (obj in this.towerFloors) {</code> you are polluting the global namespace, either... | {
"AcceptedAnswerId": "69864",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-15T04:55:21.990",
"Id": "57063",
"Score": "6",
"Tags": [
"javascript",
"game",
"html",
"mvc",
"d3.js"
],
"Title": "Strategy Game in Javascript with Three.JS"
} | 57063 |
<p>I made this code to change the background color for a <code>div</code> in a set of <code>div</code>s while disabling the rest of the <code>div</code>s in the background. It works fine, but I wanted the code reviewed for more improvements since I am new to jQuery and JavaScript.</p>
<pre><code><div id="singleProj... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-15T14:54:10.607",
"Id": "101886",
"Score": "1",
"body": "BTW Don't edit your question http://meta.codereview.stackexchange.com/questions/1763/for-an-iterative-review-is-it-okay-to-edit-my-own-question-to-include-revised-c"
}
] | [
{
"body": "<p>im not sure why you would want the length or count of the class..<br />\nYou could simply use this to highlight the divs:</p>\n\n<pre><code> $(\".ProjectMainLink\").click(function() {\n $(\".ProjectMainLink\").css(\"background-color\",\"\");\n $(this).css(\"background-color\",... | {
"AcceptedAnswerId": "57111",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-15T10:05:33.130",
"Id": "57069",
"Score": "1",
"Tags": [
"javascript",
"jquery",
"beginner",
"html",
"event-handling"
],
"Title": "Menu selector that changes the backgroun... | 57069 |
<p>I have <code>UserGroups</code> for <code>Users</code> to be assigned to in a ListBox in HTML form. Items from listbox can be multi-selected or completely unselected.</p>
<p>In summary currently, I am getting a <code>int[]</code> of <code>GroupId</code> from client into my action and I am pulling existing assigned u... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-15T11:01:52.573",
"Id": "101846",
"Score": "1",
"body": "Just want to check I'm guessing correctly: you're using an ORM like Entity Framework, Users and Groups are each entities with their own table, and because they're in a many-to-ma... | [
{
"body": "<p><strong>Small Code duplication</strong></p>\n\n<pre><code>var existUserGroups = db.Users.Where(u => u.ID == user.ID).Single().UserGroups;\nvar existUserGroupsIds = db.Users.Where(u => u.ID == user.ID).Single().UserGroups.Select(ug => ug.ID).ToArray<int>();\n</code></pre>\n\n<p>can b... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-15T10:20:00.303",
"Id": "57070",
"Score": "5",
"Tags": [
"c#",
"optimization",
"linq",
"asp.net-mvc"
],
"Title": "ListBox Update Handling"
} | 57070 |
<p>In a header I have something like:</p>
<pre><code>#define OPENGL_TARGET_VERSION_MAJOR 4
#define OPENGL_TARGET_VERSION_MINOR 0
#define OPENGL_TARGET_VERSION ( OPENGL_TARGET_VERSION_MAJOR * 10 \
+ OPENGL_TARGET_VERSION_MINOR * 1 )
</code></pre>
<p>And then a lot of checks like:</p>
<p... | [] | [
{
"body": "<p>While it's somewhat uncertain whether you'll like it (some compilers warn about doing so) it's entirely permissible to <code>#undef</code> a value that wasn't defined to start with, so you can consolidate these down to something like:</p>\n\n<pre><code>#if OPENGL_TARGET_VERSION < 44\n #undef... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-15T10:22:10.023",
"Id": "57071",
"Score": "5",
"Tags": [
"c++",
"c++11"
],
"Title": "Better way to un-define a set of defines based on version numbers in C++?"
} | 57071 |
<p>I wrote a custom decorator to check whether user is in particular group of not. Please provide the feedback on optimizing code. I currently moved from Java to Django-Python so I wasn't able to optimize the logic.</p>
<p>Check whether student is in <code>labsheet_collector</code>, <code>assignment_collector</code> o... | [] | [
{
"body": "<p>I'm not a django expert, but from what I see, you could add one more wrapping level to avoid repeating the same code in multiple decorators that are the same except for the group name:</p>\n\n<pre><code>from functools import wraps\n\ndef check_group(group_name):\n def _check_group(view_func):\n... | {
"AcceptedAnswerId": "57088",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-15T11:18:48.273",
"Id": "57073",
"Score": "4",
"Tags": [
"python",
"django"
],
"Title": "Django Custom Decorator for user group check"
} | 57073 |
<p>I have written an interface system for iOS that allows interface elements to be moved around on the screen as actors move around on stage. It can operate within a <code>ViewController</code> environment. It relies on messaging through the Notification Centre (obviously not <code>LocalNotification</code>).</p>
<p>Th... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-15T15:08:46.750",
"Id": "101891",
"Score": "0",
"body": "Hi. The code works, but I'm running up against some performance issues with what I want to do. I was wondering if anyone more experienced than me would have any ideas about how t... | [
{
"body": "<p>There is one performance issue that can be addressed quite easily, and that is when we're even bothering to respond to the notification.</p>\n\n<p>This <code>if</code> statement can be completely eliminated:</p>\n\n<pre><code>if ([notification.name isEqualToString:State] && [self.stateDict... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-15T11:39:46.110",
"Id": "57075",
"Score": "3",
"Tags": [
"objective-c",
"ios",
"interface"
],
"Title": "Potentially superfluous iOS interface system"
} | 57075 |
<p>I currently have an MGF file containing MS2 spectral data (QE_2706_229_sequest_high_conf.mgf). The file template is <a href="http://www.matrixscience.com/help/data_file_help.html" rel="nofollow">here</a>, as well as a snippet of example:</p>
<blockquote>
<pre class="lang-none prettyprint-override"><code>BEGIN ION... | [] | [
{
"body": "<p><em>Disclaimer : I have very limited skill/knowledge for anything related to np. Also, I haven't run your code to identify bottleneck which should be the very first thing to do before trying to perform optimisations.</em></p>\n\n<p>Common ways to make things faster are :</p>\n\n<ul>\n<li>not to do... | {
"AcceptedAnswerId": "57092",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-15T11:41:21.803",
"Id": "57076",
"Score": "1",
"Tags": [
"python",
"performance",
"bioinformatics"
],
"Title": "Faster way to parse file to array, compare to array in second file,... | 57076 |
<p>I have a <code>HashMap<Token, Integer></code>, which counts occurrences of <code>Token</code>. Each time <code>Token</code> is found, the value in the map should be incremented.</p>
<pre><code>Map<Token, Integer> occurrences = new HashMap<Token, Integer>();
// ...
public void tokenFound(Token tok... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-15T20:01:31.620",
"Id": "101941",
"Score": "0",
"body": "[Functors](http://en.wikipedia.org/wiki/Functor)... if your weren't `Java` bound..."
}
] | [
{
"body": "<p>Guava's <a href=\"https://google.github.io/guava/releases/21.0/api/docs/com/google/common/collect/Multiset.html\" rel=\"nofollow noreferrer\"><code>Multiset</code></a> and its <a href=\"https://google.github.io/guava/releases/21.0/api/docs/com/google/common/util/concurrent/AtomicLongMap.html\" rel... | {
"AcceptedAnswerId": "57080",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-15T11:44:50.563",
"Id": "57078",
"Score": "44",
"Tags": [
"java",
"integer",
"hash-map"
],
"Title": "Incrementing Integers in Map"
} | 57078 |
<p>I have a small open source library called <strong>Equ</strong> that I've been using already on several projects. After a rework of the internals I thought I'd ask here for opinions on improvement possibilities.</p>
<p>At the core of my library is a class that generates equality functions, i.e. <code>bool Equals<... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-15T13:14:23.833",
"Id": "101866",
"Score": "0",
"body": "Have you considered supporting `IComparable<T>` too?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-15T13:21:03.420",
"Id": "101867",
"Score... | [
{
"body": "<p>You should add XML comments, especially for important items (like <code>EqualityFunctionGenerator</code>) and potentially confusing items (like <code>fieldSelector</code>). </p>\n\n<hr>\n\n<pre><code>typeof(object).GetMethod(\"Equals\", BindingFlags.Static | BindingFlags.Public)\n</code></pre>\n\n... | {
"AcceptedAnswerId": "57094",
"CommentCount": "8",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-15T12:32:54.313",
"Id": "57082",
"Score": "6",
"Tags": [
"c#"
],
"Title": "Equality Function Generator"
} | 57082 |
<p>I was looking for long time around to have a portable robust solution for multiprocessing synchronization. Who touche this things know that good solution are boost::iterprocess named sync objects.</p>
<p>When your process have a <code>named_mutex</code> locked and your process die (there are many normal situations ... | [] | [
{
"body": "<p>I can't say for the thing as a whole, but there are a few things that you may improve:</p>\n\n<ul>\n<li><p>First, this macro:</p>\n\n<pre><code>#if defined(_DEBUG) && defined(_ROBUST_MUTEX_TRACE) \n#define IPC_DBG_TRACE(msg) { std::stringstream __str; __str << bipc::ipcdetail::get_cu... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-15T12:33:53.367",
"Id": "57083",
"Score": "9",
"Tags": [
"c++",
"locking",
"synchronization",
"boost",
"multiprocessing"
],
"Title": "Portable C++ boost::interprocess::mutex"... | 57083 |
<p>Basically is a script to export a table from Google Sheets and send it via email. But it's not a clean script, although it works.</p>
<p>If there is any way of making it more simple, or instead of get all the values get the complete table and then export, that would be much more clean.</p>
<pre><code>function send... | [] | [
{
"body": "<p>You're in desperate need of a <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for\" rel=\"nofollow\">loop</a>. Anytime you start numbering your variables, you should consider whether a loop would be appropriate. I'm sure you did, but you probably got hung up ... | {
"AcceptedAnswerId": "57189",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-15T13:45:07.770",
"Id": "57089",
"Score": "5",
"Tags": [
"javascript",
"email",
"google-apps-script",
"google-sheets"
],
"Title": "Exporting a table from Google Sheets and sen... | 57089 |
<p>I am using a combination of the following two classes to achieve a quite simple task. I have Users in my application. These Users can be assigned Roles. And these Roles need to be assigned Rights.</p>
<p>Currently I do this with a primefaces <code>selectCheckboxMenu</code>. This menu requires the entries to be Stri... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-15T14:15:18.637",
"Id": "101875",
"Score": "0",
"body": "I would move the creation of the `HashSet<String>` to the top of the method and then check if the collection parameter ! null (talking about the converter class) (from my phone)"... | [
{
"body": "<p>I think you complicated the wrong things.</p>\n\n<p>Your root issue seems to be</p>\n\n<ol>\n<li>Given a string, get the matching item (items?)</li>\n<li>Given an item, get the matching string</li>\n</ol>\n\n<p>So you should probably write that bit of functionality, as clearly as you can, first, t... | {
"AcceptedAnswerId": "57396",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-15T13:59:16.020",
"Id": "57093",
"Score": "7",
"Tags": [
"java"
],
"Title": "EditController and ModelConverter - Does this make my ass look fat?"
} | 57093 |
<p>I was wondering if my code is safe for sql injection.
This code just checks if the username exists in my db or not.</p>
<pre><code>$username = $_POST['username'];
$stmt = mysqli_stmt_init($con);
$query = "SELECT username FROM users WHERE username = ?" ;
mysqli_stmt_prepare($stmt, $query);
mysqli_stmt_bind_param($st... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-15T14:39:19.537",
"Id": "101879",
"Score": "0",
"body": "Looks safe enough. If you're going to have lots of users at some point you may consider making a SQL stored procedure, but otherwise I don't think you will have any problems."
... | [
{
"body": "<p>SQL Injection-wise, this is completely safe. <strong>You don't run any risk of SQL Injection.</strong></p>\n\n<p>However, some parts of your code is not optimal:</p>\n\n<pre><code>mysqli_stmt_execute($stmt);\nmysqli_stmt_bind_result($stmt, $user['username']);\nmysqli_stmt_execute($stmt);\n</code><... | {
"AcceptedAnswerId": "57097",
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-15T14:27:56.087",
"Id": "57095",
"Score": "11",
"Tags": [
"php",
"mysqli",
"sql-injection"
],
"Title": "SQL injection safety check"
} | 57095 |
<p>I've created a function that uses binary search to insert an element into an array (similar to <a href="https://codereview.stackexchange.com/questions/36221/binary-search-for-inserting-in-array">this question</a>). I haven't benchmarked it, but based on my knowledge it should get \$O(1)\$ in the best case (i.e., ap... | [] | [
{
"body": "<p>Here are some thoughts:</p>\n\n<p>For benchmarking there are two modules folks usually use:</p>\n\n<p>cProfile</p>\n\n<p><a href=\"https://pypi.python.org/pypi/bettertimeit/1.1.2\" rel=\"nofollow noreferrer\">bettertimeit</a></p>\n\n<p>I put an example in a previous post located here:</p>\n\n<p><a... | {
"AcceptedAnswerId": "57120",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-15T15:25:17.543",
"Id": "57100",
"Score": "1",
"Tags": [
"python",
"optimization",
"algorithm",
"binary-search"
],
"Title": "Binary Insert Method - handling edge cases"
} | 57100 |
<p>I am currently creating a game engine for educational purposes.</p>
<p><strong>ECS Design Pattern</strong></p>
<p>The first design pattern I've included is the Entity/Component/System pattern. Therefore I've got a base singleton class called <code>cEngine</code>, which contains all systems (<code>PhysicsSystem</co... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-12-20T13:01:30.960",
"Id": "135058",
"Score": "0",
"body": "Sorry for being late to pay attention to this, but it is virtually impossible to make a good answer here without doing a lot of guesswork and \"reading between the lines\". I hav... | [
{
"body": "<p>Not having seen a given pattern usually means that you didn't use exactly the right search string, or you've modified a pattern that already exists enough so it looks different, so I wouldn't worry about finding solutions that you haven't seen before.</p>\n\n<p>Having a class handling input is the... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-15T16:00:56.417",
"Id": "57102",
"Score": "3",
"Tags": [
"c++",
"performance",
"design-patterns",
"game",
"entity-component-system"
],
"Title": "Game Engine :: Entity Compone... | 57102 |
<p>I'm little frustrated because I don't know how well I can refactor this script. I wrote the authentication function but it's too complicated, maybe too large in one function, and seems like spaghetti code. How will I be able to make this a little better? </p>
<p>I'm using Restify framework for NodeJS. There are a f... | [] | [
{
"body": "<p>Interesting question,</p>\n\n<p>I think the first thing to do is read <a href=\"http://blog.codinghorror.com/flattening-arrow-code/\" rel=\"nofollow\">this</a>.</p>\n\n<p>You could replace this:</p>\n\n<pre><code>if (req.url.indexOf(API_PATH) == 0){\n //Lots of code\n}else{\n next();\n}\n</code>... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-15T16:19:30.807",
"Id": "57104",
"Score": "3",
"Tags": [
"javascript",
"node.js",
"authentication",
"logging",
"redis"
],
"Title": "User-logging authentication"
} | 57104 |
<p>I've been making an interpreter for my own programming language that I've been working on as a hobby. I made an expression evaluator that can evaluate simple mathematical expressions.</p>
<p>It understands <code>+</code>, <code>-</code>, <code>/</code>, <code>*</code>, brackets and the order of operations. I haven't... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-15T19:03:37.140",
"Id": "101927",
"Score": "0",
"body": "Are you able to use C++11 features? I'm working on a (rather lengthy) answer, but some of the things I do require C++11."
},
{
"ContentLicense": "CC BY-SA 3.0",
"Crea... | [
{
"body": "<h3>Common beginner mistakes</h3>\n\n<p>Stop doing this:</p>\n\n<pre><code>using namespace std;\n</code></pre>\n\n<p>See <a href=\"https://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-bad-practice\">Why is “using namespace std;” considered bad practice?</a></p>\n\n<h3>Nam... | {
"AcceptedAnswerId": "57126",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-15T16:42:11.223",
"Id": "57107",
"Score": "10",
"Tags": [
"c++",
"math-expression-eval",
"interpreter"
],
"Title": "Four-function expression evaluator"
} | 57107 |
<p>A programming paradigm often used in games</p>
<ul>
<li>Entity: A game object which is composed out of components.</li>
<li>Component: The raw data for one aspect of an entity.</li>
<li>System: Each system performs actions on entities by adding, removing or modifying their associated components.</li>
</ul>
| [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-15T16:43:41.870",
"Id": "57109",
"Score": "0",
"Tags": null,
"Title": null
} | 57109 |
A programming paradigm in which game-objects (entities) are composed out of components, and are operated upon by systems. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-15T16:43:41.870",
"Id": "57110",
"Score": "0",
"Tags": null,
"Title": null
} | 57110 |
<p>I'm using XML to store data and I need to store a string array in it. The best way (that I can think of) to store a string array is by converting it to a single string. In order to do that, I'm using <code>string.Join</code> to join the strings with <code>\0</code> and then use Base64 so that the <code>\0</code> (an... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-15T18:45:36.093",
"Id": "101925",
"Score": "0",
"body": "You need to get familiar with [System.XML namespace](http://msdn.microsoft.com/en-us/library/System.Xml%28v=vs.110%29.aspx). In particular `XMLReader`, `XMLWriter`, `XMLDocument`... | [
{
"body": "<p>My first reaction is: <strong>don't do this</strong>.</p>\n\n<p>By creating your own encoding for an array of strings, your XML is not going to be (easily) consumable by other programs. By Base64 encoding your strings, your XML is not going to be human-readable.</p>\n\n<p>These are two major benef... | {
"AcceptedAnswerId": "57155",
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-15T18:29:53.790",
"Id": "57116",
"Score": "4",
"Tags": [
"c#",
"strings",
"array",
"xml"
],
"Title": "Converting string array to string (and vice-versa) for storing via XML"
} | 57116 |
<p>Is this example of an escape - unescape function correct?</p>
<pre><code>ESCAPE = '/'
def escape(s):
rv = s
rv = rv.replace(ESCAPE, ESCAPE + ESCAPE)
rv = rv.replace('+', ESCAPE + 'PLUS')
rv = rv.replace('-', ESCAPE + 'MINUS')
return rv
def unescape(s):
rv = s
rv = rv.replace(ESCAPE + '... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-15T19:57:37.620",
"Id": "101938",
"Score": "0",
"body": "Is this from your own code, or is it purely an example? The latter is off-topic."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-15T20:01:48.087",
... | [
{
"body": "<p>Performing string substitutions using multiple passes is almost always a bad idea, not only for performance, but for correctness. In this case, there is indeed a bug: <code>unescape('//PLUS/PLUS')</code> should produce <code>'/PLUS+'</code>, but instead produces <code>'/++'</code>.</p>\n\n<p>Ther... | {
"AcceptedAnswerId": "57185",
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-15T19:55:25.640",
"Id": "57121",
"Score": "6",
"Tags": [
"python",
"escaping"
],
"Title": "Is this escape unescape function pair correct?"
} | 57121 |
<p><a href="http://redis.io/" rel="nofollow">Redis</a> is an open source, advanced key-value store. It is often referred to as a data structure server since keys can contain strings, hashes, lists, sets and sorted sets.</p>
| [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-15T20:32:33.320",
"Id": "57122",
"Score": "0",
"Tags": null,
"Title": null
} | 57122 |
Redis is an open-source, networked, in-memory, key-value data store. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-15T20:32:33.320",
"Id": "57123",
"Score": "0",
"Tags": null,
"Title": null
} | 57123 |
<p>Escaping is used for many purposes, such as providing representations of unprintable characters, changing font colors in terminals, or allowing the inclusion in a string of a character normally used to terminate the string, as well as allowing to output a character to user when that character can be used as a contro... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-15T20:36:32.440",
"Id": "57124",
"Score": "0",
"Tags": null,
"Title": null
} | 57124 |
Escaping is the process of applying an alternate meaning to a character or set of characters. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-15T20:36:32.440",
"Id": "57125",
"Score": "0",
"Tags": null,
"Title": null
} | 57125 |
<p>I am implementing generic repository and unit of work for the first time. I would be glad if someone can correct me if I am doing something wrong here.</p>
<p>This is how I communicate with my DAL from controller:</p>
<pre><code>public class HomeController : Controller
{
private UnitOfWork unitOfWork ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-18T20:41:04.897",
"Id": "102663",
"Score": "1",
"body": "Are there any specific areas you want more detail in?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-18T20:46:20.723",
"Id": "102665",
"Scor... | [
{
"body": "<p>Yes, you need a IOC container to maintain your instances. No, your Unit of Work should not create them.</p>\n\n<p>With an IOC Container, you centralize the control over the objects and their lifetime. This is extremely powerful.</p>\n\n<p>Never should you have an instantiation of unit of work, rep... | {
"AcceptedAnswerId": "57171",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-15T21:04:49.230",
"Id": "57127",
"Score": "13",
"Tags": [
"c#",
"design-patterns",
"entity-framework",
"dependency-injection",
"ninject"
],
"Title": "Do I need ninject whe... | 57127 |
<p>I am trying to get over my fear of multithreading programming and teaching myself to code using POSIX. I wrote a small version of the consumer producer problem. I am hoping I can get some feedback if it works (I think it does, as I traced the threads when my <code>for</code> loop was at 20 and it made sense) and wha... | [] | [
{
"body": "<p><strong>General note</strong></p>\n\n<p>It is very hard to tell if this program works or not: I don't know what is supposed to be a correct behaviour. I can only speculate that you didn't want to see a semaphore value ever to exceed 4. If it is the case, than it is a pure coincidence -- caused by ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-15T23:26:48.043",
"Id": "57133",
"Score": "3",
"Tags": [
"c",
"multithreading",
"pthreads"
],
"Title": "Consumer producer implementation involving POSIX, semaphores, and locks"
} | 57133 |
<p>I have a simple calculator program that needs some reviewing. Is this as efficient as it can get, or is there a better way?</p>
<pre><code>public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.println("Welcome to the Calculator!");
do {
System.out.println("\nTy... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-17T11:31:26.050",
"Id": "102336",
"Score": "1",
"body": "After having received answers, please do not add revised versions of your code to your question or modify your previous code in such a way that it invalidates answers. See our me... | [
{
"body": "<p>It started off pretty well: <code>main</code> and <code>doAgain</code> are very reasonably sized.</p>\n\n<p><code>calculate</code> is a monster though. It's so crippled I don't even want to imagine what maintaining that code would be. <s>Reviewing</s> <em>reading</em> it is hard, for several reaso... | {
"AcceptedAnswerId": "57146",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-15T23:28:47.913",
"Id": "57134",
"Score": "9",
"Tags": [
"java",
"calculator"
],
"Title": "Simple calculator that seems inefficient"
} | 57134 |
<p>I am trying to create a webpage that will read RSS feeds from the TED talk website and display it on a page. I am using Google's Feed API for this.</p>
<p><a href="http://challengereceived.netii.net">Here</a> is the link to view the code online.</p>
<p>Could someone please tell me if there is a better way to displ... | [] | [
{
"body": "<p>There are a couple things you could improve here. First, you should specify a character encoding for the document, like this:</p>\n\n<pre><code><head>\n <meta charset=\"utf-8\">\n <title>Page Title</title>\n</head>\n</code></pre>\n\n<p>Next, your indentation is... | {
"AcceptedAnswerId": "77193",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-15T23:57:47.773",
"Id": "57138",
"Score": "7",
"Tags": [
"javascript",
"jquery",
"css",
"html5",
"rss"
],
"Title": "Feed API to display RSS feeds Ted talk"
} | 57138 |
<p>I have written a simple GUI Tic Tac Toe Application and since this is my first shot, I think it can be improved a lot.</p>
<p>Please tell me what you think about it and what you see I made wrong so I can avoid those mistakes the next time.</p>
<p>Is there code redundancy I don't see? Is everything declared and imp... | [] | [
{
"body": "<p>That's some nice code! And welcome to Code Review.</p>\n\n<ol>\n<li><p>It's <a href=\"https://google-styleguide.googlecode.com/svn/trunk/javaguide.html#s5.2.2-class-names\" rel=\"nofollow\">customary</a> to name variables and methods starting with lowercase and classes starting with uppercase. T... | {
"AcceptedAnswerId": "57211",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-16T00:50:49.250",
"Id": "57141",
"Score": "15",
"Tags": [
"java",
"beginner",
"object-oriented",
"game",
"tic-tac-toe"
],
"Title": "Tic Tac Toe game in Java OOP"
} | 57141 |
<p>My application needs to read a file, which includes a list of cars from different factories, and calculate the prices (by this I mean mean add up their prices).</p>
<p>I suppose my solution is efficient. Is there any better approach to it?</p>
<blockquote>
<pre class="lang-none prettyprint-override"><code>Compa... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-16T04:05:57.023",
"Id": "101993",
"Score": "1",
"body": "sorry but I have rollbacked your latest revision as your code has changed significantly. I think it'll be better if you can mark this answered and then ask a new question with th... | [
{
"body": "<p>Your <code>ArrayList</code> and <code>HashMap</code> declarations are missing type arguments. Assuming if you're developing on Java 7 then all you're missing is just the diamond operator, e.g. <code>ArrayList<>()</code>.</p>\n\n<pre><code>Company t = new Company();\nt.setName(\"Benz\");\nt.s... | {
"AcceptedAnswerId": "57153",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-16T02:08:59.093",
"Id": "57149",
"Score": "3",
"Tags": [
"java"
],
"Title": "Calculating multiple car prices from a file"
} | 57149 |
<p>This query performs a FizzBuzz in SQLite 2.8.17 without creating any tables or sprocs.</p>
<p><em>First attempt:</em></p>
<pre><code>select case when fb <> '' then fb else n end from (
select g + f * 2 + e * 4 + d * 8
+ c * 16 + b * 32 + a * 64 as n,
coalesce(fizz, '') || coalesce(buzz, '') ... | [] | [
{
"body": "<p>I will have to admit I personally prefer the <em>First attempt</em>, but both seem like they would run fast and deliver as expected. </p>\n\n<p>The only piece I don't like so much, which is found in both attempts, is this:</p>\n\n<blockquote>\n<pre><code> select g + f * 2 + e * 4 + d * 8 \n ... | {
"AcceptedAnswerId": "57176",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-16T02:15:02.390",
"Id": "57150",
"Score": "9",
"Tags": [
"sql",
"fizzbuzz",
"sqlite"
],
"Title": "FizzBuzz in SQLite 2"
} | 57150 |
<p>My application needs to read a file, which includes a list of cars from different factories, and calculate the prices (by this I mean mean add up their prices).</p>
<p>I suppose my solution is efficient. Is there any better approach to it?</p>
<pre><code> String factories = "Benz,10000,BMW,3000,Benz,5,Toyota,500,... | [] | [
{
"body": "<pre><code>List<Company> trn = new ArrayList();\n</code></pre>\n\n<p>You're missing the <code><></code> (or <code><Company></code> if you're using JDK6 or below) on the right, which means the right side is a raw type and not a generic. Your IDE should be configured to warn you about... | {
"AcceptedAnswerId": "57158",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-16T04:27:26.373",
"Id": "57157",
"Score": "2",
"Tags": [
"java"
],
"Title": "Calculating multiple car prices from a file - follow-up"
} | 57157 |
<p>The function asks the user for a value to search for, then deletes all matching values in the list.</p>
<p>The program runs flawlessly, but I can't figure out a simple/elegant way of separating cases for 'first node', 'last node', and 'intermediate node'.</p>
<p>Please help me make it more elegant and readable.</p... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-16T05:05:25.820",
"Id": "102013",
"Score": "0",
"body": "I'll kick this off by telling you your first two functional lines of code in `main()` leak memory. Not a good start."
}
] | [
{
"body": "<p>You're making that specific task considerably more difficult than it needs to be. I've taken liberty to post an alternate to the entire function, and it should become obvious why. Regarding the specifics of the code you highlighted:</p>\n\n<ul>\n<li><p>This is the big one: You're already given a p... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-16T04:54:35.417",
"Id": "57160",
"Score": "3",
"Tags": [
"optimization",
"c",
"linked-list",
"search"
],
"Title": "Simplifying linked list \"search and delete\" function"
} | 57160 |
<p>This is a JavaScript function that returns ALL the possible combinations of whatever word the user enters. I am looking to clean this code up a bit...any and all suggestions are welcome!</p>
<pre><code> function allAnagrams (word) {
if (word.length < 2) {
return [word];
} else {
var allAnswers = [... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-16T06:32:25.287",
"Id": "102023",
"Score": "0",
"body": "I have two suggestions. **1:** Separate words in variable- and function names with an underscore. `allanagrams` -> `all_anagrams`, `shorterword` -> `shorter_word` etc. **2:** Ind... | [
{
"body": "<p>As I worked on a better solution, I figured out a great use for the new <a href=\"https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Iterators_and_Generators\" rel=\"nofollow noreferrer\">JS Iterators & Generators</a>, which I've been reading about. I spent probably 6 hours today fi... | {
"AcceptedAnswerId": "57893",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-16T04:56:48.100",
"Id": "57161",
"Score": "20",
"Tags": [
"javascript",
"strings",
"combinatorics"
],
"Title": "Generate all possible combinations of letters in a word"
} | 57161 |
<p>Polymer is comprised of two efforts:</p>
<ol>
<li>A set of core platform features (Shadow DOM, Custom Elements, MDV). Initially, these core features will be enabled with a set of polyfills. As browsers begin to implement these new primitives, the polyfill platform layer becomes smaller and better over time.</li>
<l... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-16T05:00:19.320",
"Id": "57163",
"Score": "0",
"Tags": null,
"Title": null
} | 57163 |
Polymer is a library for web development, built on top of Web Components, and designed to leverage the evolving web platform on modern browsers. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-16T05:00:19.320",
"Id": "57164",
"Score": "0",
"Tags": null,
"Title": null
} | 57164 |
<p>I'm building this as part of a larger class to rapidly search for smaller images inside larger images. This is my first serious F# project so comments especially concerning style and organization are appreciated.</p>
<pre><code>module imagesearch =
type BitmapSearchClass() =
// Largely inspired by thi... | [] | [
{
"body": "<pre><code>module imagesearch = \n</code></pre>\n\n<p>All types should use <code>PascalCase</code>, this includes modules. So the correct name would be <code>ImageSearch</code>.</p>\n\n<hr>\n\n<pre><code>type BitmapSearchClass() = \n</code></pre>\n\n<p>That's a weird name, names of classes shouldn't ... | {
"AcceptedAnswerId": "57187",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-16T06:55:02.797",
"Id": "57167",
"Score": "1",
"Tags": [
"image",
"f#"
],
"Title": "Load bitmap object data into array of byte values"
} | 57167 |
<p>I am slowly moving through Project Euler, and have reached problem #10:</p>
<blockquote>
<p>The sum of the primes below 10 is 2 + 3 + 5 + 7 = 17.</p>
<p>Find the sum of all the primes below two million.</p>
</blockquote>
<p>I did a naive implementation first, which was very slow (15+ minutes runtime). But ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-16T07:55:13.487",
"Id": "102029",
"Score": "5",
"body": "There are already many prime sieves in C++ on this site. Your should check them out. (1) [Prime Gen](http://codereview.stackexchange.com/questions/4267/prime-generator) (2) [unde... | [
{
"body": "<p>First of all some stylistic remarks:</p>\n\n<h2>Unnecessary vertical whitespace</h2>\n\n<p>You have many empty lines that don't improve readability (and actually hurt because the reader needs to do more scrolling)</p>\n\n<h2>Inconsistent indentation</h2>\n\n<p>You need to stick to one indentation ... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-16T07:09:12.940",
"Id": "57168",
"Score": "7",
"Tags": [
"c++",
"performance",
"primes",
"programming-challenge",
"sieve-of-eratosthenes"
],
"Title": "Modified Sieve of Erato... | 57168 |
<p>I have an abstract <code>PersonDao</code> class, extended by several other DAO classes, for example <code>EmployeeDao</code>, <code>StaffDao</code>. </p>
<p>The non-abstract DAOs correspond to different tables. The tables have some common fields, and also some unique fields. Operations on the common fields are impl... | [] | [
{
"body": "<h1>Smelly code</h1>\n\n<p>The parent method smells:</p>\n\n<pre><code>public void setDataSource(DataSource dataSource) {\n this.simpleJdbcTemplate = new SimpleJdbcTemplate(dataSource);\n}\n</code></pre>\n\n<p>You ask a DataSource, but in fact you need a SimpleJdbcTemplate. this smells...\nLet's a... | {
"AcceptedAnswerId": "57175",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-16T08:19:11.510",
"Id": "57172",
"Score": "3",
"Tags": [
"java",
"object-oriented",
"inheritance",
"spring"
],
"Title": "DAOs for Person, Employee, Staff, etc"
} | 57172 |
<p>Here is a small C++11 utility collection to store any object that satisfies a given interface. Only the basic concepts are provided, I did not try to create a full collection:</p>
<pre><code>#include <memory>
#include <utility>
#include <vector>
#include <boost/iterator/indirect_iterator.hpp>... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-16T09:21:32.817",
"Id": "102041",
"Score": "0",
"body": "Is this a try in modeling what Sean Parent talked about here: http://channel9.msdn.com/Events/GoingNative/2013/Inheritance-Is-The-Base-Class-of-Evil"
},
{
"ContentLicense... | [
{
"body": "<p>As usual with your code, I can only come up with very minor nitpicks.</p>\n\n<p>With both <code>push</code> functions, there is a small chance of a memory leak. After the construction of a new <code>Adapter<T></code> using:</p>\n\n<pre><code>auto ptr = new Adapter<T>{ std::forward<A... | {
"AcceptedAnswerId": "60341",
"CommentCount": "8",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-16T08:20:14.407",
"Id": "57173",
"Score": "8",
"Tags": [
"c++",
"c++11",
"collections",
"polymorphism"
],
"Title": "Interface-based polymorphic collection"
} | 57173 |
<p>I have these two methods on a class that differ only in one method call. Obviously, this is very un-DRY, especially as both use the same formula. Could anyone give me advice on how to tidy this up?</p>
<pre><code>public class PlayerCharacter {
int level;
public int getAttack() {
int attack = 1 + lev... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-16T11:19:42.050",
"Id": "102072",
"Score": "0",
"body": "Does Java support functional programming at all?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-16T11:32:16.050",
"Id": "102073",
"Score": "... | [
{
"body": "<p>A few things, bad messages first…</p>\n\n<h2>Double and Int</h2>\n\n<blockquote>\n<pre><code>return Math.sqrt(level);\n</code></pre>\n</blockquote>\n\n<p>Math.sqrt returns a double. That is a floating point number, probably something like: \\$2.352561\\$. If you now \"cast\" that to an int (becaus... | {
"AcceptedAnswerId": "57179",
"CommentCount": "8",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-16T10:26:16.380",
"Id": "57177",
"Score": "14",
"Tags": [
"java"
],
"Title": "DRY attack and defense"
} | 57177 |
<p>I often write something like this in my code:</p>
<pre><code>try {
obj.doSomething();
} catch (Throwable exception) {
// there is no need to interrupt application
String exceptionMessage = String.valueOf(exception.getMessage());
Log.e("Name of my app", exceptionMessage, exception);
// and may be... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-16T11:13:39.220",
"Id": "102070",
"Score": "4",
"body": "Yes, most definitely not needed. You're creating a lot of overhead that saves you.. 0 lines of code."
}
] | [
{
"body": "<ol>\n<li><p>You could use <a href=\"http://docs.oracle.com/javase/7/docs/api/java/util/concurrent/Callable.html\"><code>Callable</code></a> instead of <code>RunnableAbleToThrowCheckedException</code>. Its call method could <code>throw Exeption</code>s and has a return value too. You can use <code>V... | {
"AcceptedAnswerId": "57188",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-16T10:41:39.490",
"Id": "57178",
"Score": "5",
"Tags": [
"java",
"android",
"error-handling",
"logging"
],
"Title": "Class for catching error and logging"
} | 57178 |
<p>I wrote a method that closes 3 closeable types:</p>
<ul>
<li><code>java.sql.Connection</code></li>
<li><code>java.sql.PreparedStatement</code></li>
<li><code>java.sql.ResultSet</code></li>
</ul>
<p></p>
<pre><code> public static void closeAll(final Connection connection,
final Prepa... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-16T11:05:16.847",
"Id": "102069",
"Score": "5",
"body": "You should look into the *try-with-resources* statement first, introduced in Java 7, it will take care of closing your resources that implement `AutoCloseable`."
},
{
"Co... | [
{
"body": "<p>A <code>ResultSet</code> is closed automatically when the <code>Statement</code> that created it is closed.\nA <code>Statement</code> is closed automatically when the <code>Connection</code> that created it is closed.</p>\n\n<p>If you want to close everything, just close the <code>Connection</code... | {
"AcceptedAnswerId": null,
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-16T11:00:12.823",
"Id": "57182",
"Score": "3",
"Tags": [
"java",
"jdbc"
],
"Title": "Method to close a lot of closeable objects"
} | 57182 |
<p>My goal has been to learn <code>Polymer</code> so I started developing a complex combo-box element.</p>
<p>I did my development on Plunker. Here is <a href="http://plnkr.co/edit/ucRDan5GgXee0bK9NVGc" rel="nofollow"><strong>link to my plunk</strong></a>.</p>
<p>I'm happy with my <code>.scss</code> file, but I would... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-16T13:19:05.907",
"Id": "102092",
"Score": "0",
"body": "@Vogel612 Edit coming up!"
}
] | [
{
"body": "<p>Just wanted to let you know that</p>\n\n<pre><code>function getNodeIndex(node) {\n var index = -1;\n\n while ((node = node.previousSibling)) {\n if (node.nodeType != 3 || !/^\\s*$/.test(node.data)) {\n index++;\n }\n }\n return index;\n}\n</code></pre>\n\n<p><a... | {
"AcceptedAnswerId": "57216",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-16T13:03:20.833",
"Id": "57192",
"Score": "1",
"Tags": [
"javascript",
"html",
"sass",
"polymer"
],
"Title": "How can I organize polymer-element structure in order to embrace ... | 57192 |
<h2> Why this thing : </h2>
<p>I work on a project where I need to call many asynchronous functions to get data, chain them, execute them if conditions are met,.. and I ended up having unreadable code. <br>
At some point, I looked at promises library like Q.js but even with such tools my code was complicated, so I de... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-17T13:48:34.857",
"Id": "102365",
"Score": "0",
"body": "Do a search for: \"javascript async await semantics,\" these tools are great for solving the problem of deeply nested callback functions. Eg: https://github.com/bjouhier/galaxy"
... | [
{
"body": "<p>Interesting question,</p>\n\n<p>I find this code hard to read, I wonder what you consider <em>unreadable code</em>.</p>\n\n<p>Some remarks on </p>\n\n<pre><code>pp_chain_function = function (fname,condition_string) {\nvar queue=this;\nvar prec_result = 'result_'+queue.queue_length;\nqueue.queue_st... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-16T13:22:33.057",
"Id": "57197",
"Score": "3",
"Tags": [
"javascript",
"jquery"
],
"Title": "Idea of 'parser' to make the writing of asynchronous functions chains easier"
} | 57197 |
<h1>Use Case</h1>
<p>Creating a generic and reusable predicate with closures that supports Float, Double, Integer, float, double, and integer.</p>
<h2>Problem</h2>
<p>Extending "Number" doesn't allow for the modulo operator. </p>
<h3>Code</h3>
<p>Below is the form I'd like the code to be. However, Number doesn't s... | [] | [
{
"body": "<p>Even though <code>Number</code> doesn't provide any methods to check for divisibility directly, it does provide a method to make the <code>Number</code> into a <code>double</code>, and as we all know, doubles <em>do</em> support the <code>%</code> operator.</p>\n\n<p>Other slight modifications:</p... | {
"AcceptedAnswerId": "57247",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-16T13:39:30.397",
"Id": "57200",
"Score": "5",
"Tags": [
"java"
],
"Title": "Generic predicate in Java 8"
} | 57200 |
<p>I am new to oriented object paradigm and I work on Android using Java project for an internship.<br>
I must be able to locate the user and some around buildings I read stuff about how to setup LocationListener and all, and decided that I better write a class that manage everything for me. </p>
<pre><code>public cl... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-16T13:48:35.217",
"Id": "102102",
"Score": "1",
"body": "I change your title, I hope I express what the code do. (that's what we want in the title) It's Java and not JAVA."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDa... | [
{
"body": "<p>It is good practice to mark as many fields as possible as <code>final</code>.</p>\n\n<pre><code>private final Activity activity;\nprivate final LocationManager locationManager;\nprivate final LocationListener locationListener;\n</code></pre>\n\n<p>I assume that <code>freshLocation</code> will be c... | {
"AcceptedAnswerId": "57203",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-16T13:46:34.280",
"Id": "57202",
"Score": "3",
"Tags": [
"java",
"classes",
"android",
"interface"
],
"Title": "Locate user of an Android device"
} | 57202 |
<p>I have created a custom web server control that will have a bool property 'RenderAsLabel' so that I can convert TextBoxes to Labels, for read-only forms. I was wondering if there is any reason why this code should not be safe, or work as intended. Upon initial testing it seems fine, but I just want to make sure I'm ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-16T14:48:18.227",
"Id": "102126",
"Score": "0",
"body": "Is there a reason you can't just set the `ReadOnly` property to `true`?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-16T15:31:15.303",
"Id": "... | [
{
"body": "<p>I would probably have a custom control that wrapped instances of the controls instead of directly inheriting from one of two possible controls, if that makes sense.</p>\n\n<p>This approach leaves your code more open in the future and allows you to add additional features as part of your control (l... | {
"AcceptedAnswerId": "57238",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-16T14:24:32.200",
"Id": "57206",
"Score": "3",
"Tags": [
"c#",
"asp.net"
],
"Title": "TextBox rendered as Label"
} | 57206 |
<p>I wrote this class to perform simple template-set operations on <code>boost::unordered_set</code>. These operations are part of a larger code base. Calling them will be explicit with <code>SetUtilities::set_intersection(setA, setB)</code>.</p>
<p>The main reason I wanted this was to optimize intersection operations... | [] | [
{
"body": "<h3>Fix compiler errors</h3>\n\n<p>Your <code>set_difference</code> function does not compile. You have declared it returning <code>bool</code>, but then <code>return differenceSet;</code> in the function body. This is a type mismatch: your function should return a <code>boost::unordered_set</code>.<... | {
"AcceptedAnswerId": "57226",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-16T15:23:29.617",
"Id": "57212",
"Score": "1",
"Tags": [
"c++",
"boost",
"set"
],
"Title": "A class for simple and efficient operations on boost::unordered_set"
} | 57212 |
<p>I have an bit array <code>var data = []; ...</code> and I have the following function:</p>
<p><a href="http://jsperf.com/fastest-bit-compressing/7" rel="nofollow">jsPerf</a></p>
<pre><code>function getBit(n) {
return (data[~~(n / 32)] >> (n % 32)) & 1;
}
</code></pre>
<p>Because this is a bottleneck... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-14T14:16:18.370",
"Id": "102145",
"Score": "0",
"body": "You're right that a `TypedArray` is generally much faster for such things. Have you tried using one and compared speeds?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"Crea... | [
{
"body": "<p>I tried to speed up your formula : </p>\n\n<pre><code>return (data[n >> 5] >> (n & 31)) & 1;\n</code></pre>\n\n<p>.... All results are very close anyway : jsperf.com/fastest-bit-compressing/7. </p>\n\n<p>• notice that you can inline the function by yourself (replace functio... | {
"AcceptedAnswerId": "57218",
"CommentCount": "7",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-14T14:14:29.627",
"Id": "57217",
"Score": "3",
"Tags": [
"javascript",
"optimization",
"performance",
"algorithm",
"compression"
],
"Title": "Bit compressing in JavaScript... | 57217 |
<p>This is a follow up question to: <a href="https://codereview.stackexchange.com/questions/55822/admin-page-select-function">Admin page select function</a></p>
<p>Here, <code>index.php</code> does the following:</p>
<ul>
<li>Checks for a login status using sessions and a cookie</li>
<li>If logged in, allow the use o... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-18T15:43:08.383",
"Id": "102592",
"Score": "0",
"body": "Honestly, looks ok to me."
}
] | [
{
"body": "<p>This looks like a \"<a href=\"http://en.wikipedia.org/wiki/Rewrite_engine\" rel=\"nofollow\">Router</a>\" to me. If you haven't already studied URL rewriting, almost every PHP framework implements it, and I think you should take a look at what's been made.</p>\n\n<p>I haven't ever used it, but it ... | {
"AcceptedAnswerId": "57433",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-16T16:01:42.070",
"Id": "57220",
"Score": "2",
"Tags": [
"php",
"authorization"
],
"Title": "Admin page select"
} | 57220 |
<p>This is a follow up question to: <a href="https://codereview.stackexchange.com/questions/55549/login-system-pdo-and-me">Login system, PDO and me</a></p>
<p>Is this considered secure for a login script?</p>
<pre><code>if (filter_input(INPUT_POST, "login", FILTER_UNSAFE_RAW)) {
$usercookie = 'Admin-'.uniqid(mt_r... | [] | [
{
"body": "<p>You're probably sick of having me answer your questions, but I couldn't help myself on this one!</p>\n\n<p><strong>Basically, yes</strong> this is safe. However, you never specified what you wanted to protect against, so I'm assuming you mean from just a normal person who might try a couple tricks... | {
"AcceptedAnswerId": "57228",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-16T16:17:18.563",
"Id": "57222",
"Score": "3",
"Tags": [
"php",
"security",
"pdo",
"authentication"
],
"Title": "Login system, PDO and me - Part 2"
} | 57222 |
<p>I have a URL that is hardcoded via a config which I extract into a config:</p>
<pre><code>$url = 'http://www.example.com/api/v1/all/limit/{limit}/offset/{offset}'
// this is stored as a string inside a config file
</code></pre>
<p>then <code>$limit = 10; $offset = 0;</code></p>
<p>I currently use the following <... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-17T14:28:22.393",
"Id": "102373",
"Score": "1",
"body": "I suspect that by `[A-Z, a-z]`, you really mean `[A-Za-z]`. The former will match characters as well as commas and spaces. In general, recall that `a-d` is short for `abcd` in ch... | [
{
"body": "<p>You could simplify to something such as:</p>\n\n<pre><code>$url = 'http://www.example.com/api/v1/all/limit/%d/offset/%d';\n\n$newURL = sprintf($url, $limit, $offset);\n</code></pre>\n\n<p>We use <a href=\"http://php.net/manual/en/function.sprintf.php\" rel=\"nofollow\"><code>sprintf()</code></a> f... | {
"AcceptedAnswerId": "57241",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-16T16:32:35.790",
"Id": "57224",
"Score": "7",
"Tags": [
"php",
"optimization",
"regex",
"url"
],
"Title": "Cleaner or better readability in URL composition"
} | 57224 |
<p>I've been developing a page that is designed like this:</p>
<blockquote>
<pre><code>______________
| | |
| | |
| | |
--------------
</code></pre>
</blockquote>
<p>Everything is wrapped in a wrapper, then there are 2 divs inside it, menu and content. They're both floated to the left so th... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-16T17:32:12.677",
"Id": "102177",
"Score": "3",
"body": "So instead of doing the resize in CSS via media queries, you're opting to do it with JavaScript? What if I have JS turned off? Seems to me that you're going about this the wrong ... | [
{
"body": "<p>The code below approximates the current functionality of the site that you linked to, using only CSS percentages. You can target certain screen sizes (for example, this code below breaks at 830px) by utilizing media queries. </p>\n\n<pre><code><html>\n<head>\n <style>\n ... | {
"AcceptedAnswerId": "57231",
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-16T16:50:29.553",
"Id": "57227",
"Score": "10",
"Tags": [
"javascript",
"jquery",
"html",
"css"
],
"Title": "Wrapping my head around these wrappers"
} | 57227 |
<p>I have two types of event labels. The HTML markup is: </p>
<pre><code><article>
<time class="reg-day">Mo</time>
<time class="reg-time">13:00-14:30 Uhr</time>
<p class="reg-location">Regent Street</p>
</article>
<article>
<time class="work-mon... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-16T19:25:37.090",
"Id": "102212",
"Score": "0",
"body": "how robust do you want this to be? what happens when an event line is more than one? these are events, so how semantic do you want it to be? i can help, but idk what you want"
... | [
{
"body": "<p>There's a difference between <em>magic numbers</em> and values derived from calculations. A lot of your numbers aren't really magic, you just don't know the formula to get those values. You can start by creating variables of the things you know are going to impact your values (eg. font-size, lin... | {
"AcceptedAnswerId": "57296",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-16T17:58:51.317",
"Id": "57233",
"Score": "2",
"Tags": [
"html",
"css",
"datetime",
"html5"
],
"Title": "Layout of two different styles of event labels with CSS"
} | 57233 |
<p>My Java app converts its modal object to JSON (using the GSON Library).</p>
<p>This is just fine, but I have to get it back into a modal in PHP. Now I've created a modal (in my case it's, for example, <code>GeoLocation</code>) which has several getters and setters.</p>
<p>Example:</p>
<pre><code>class GeoLocation... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-17T07:35:41.387",
"Id": "102309",
"Score": "1",
"body": "Quick question: should it be Model instead of Modal throughout the question or is Modal a specific data type?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": ... | [
{
"body": "<p>It's secure, but it's really chunky and tedious to write. I'd do this by overriding the <a href=\"http://php.net/manual/en/language.oop5.overloading.php#object.call\" rel=\"nofollow\"><code>__call()</code></a> magic method to trick GSON into thinking the methods exist, like so:</p>\n\n<pre><code>c... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-16T19:13:42.143",
"Id": "57240",
"Score": "2",
"Tags": [
"php",
"json",
"geospatial"
],
"Title": "Filling modal from JSON (dynamically)"
} | 57240 |
<p>I've written my first OOP program (194 lines including docstring and comments) in Python that uses Tkinter as GUI and Threads. The program shows a window and displays a scrolling stock exchange ticker in a line.</p>
<p>I've created the following classes:</p>
<ul>
<li>A class that draws the GUI layout with Tkinter... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-17T07:45:01.123",
"Id": "102310",
"Score": "2",
"body": "I have just taken a quick look at the code, but I wanted to share my first impression. I see that the docstrings are in English, but that many variables names are written in Span... | [
{
"body": "<p>One suggestion is to change the <code>stock_market</code> structure from a list to a dictionary. </p>\n\n<pre><code>stock_market = {'GOOG': {'Value': 587.25, 'Change': 12.14},\n 'APPL': {'Value': 237.14, 'Change': 7.25}\n } \n</code></pre>\n\n<p>You also don't need t... | {
"AcceptedAnswerId": "57758",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-16T20:08:35.920",
"Id": "57243",
"Score": "7",
"Tags": [
"python",
"object-oriented",
"multithreading",
"classes",
"tkinter"
],
"Title": "Displaying a scrolling stock exch... | 57243 |
<p>I have the following code, it takes a list of maps representing bands and transforms the band properties via the <code>pipeline_each</code> method. </p>
<p>As you can see in the code, I am dealing with a lot of <code>Option</code>s being returned when I modify the band data in the map - I am using an immutable map ... | [] | [
{
"body": "<p>You might consider using <code>map</code> on <code>Option</code> to more cleanly access the values.</p>\n\n<pre><code> def set_canada_as_country(band: Map[String, Any]): Map[String, Any] = {\n band.get(\"name\").map( name => band.get(\"active\").map(active => \n Map(\"name\" -> n... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-16T21:06:41.020",
"Id": "57249",
"Score": "1",
"Tags": [
"scala"
],
"Title": "Transforming a list of maps representing bands"
} | 57249 |
<p>This simple program uses <code>Scanner</code> to obtain a radius from the user, then calculates and outputs the circumference and area.</p>
<p>Questions:</p>
<ol>
<li>Is it customary in Java to place a function call inside of a <code>println()</code>, or is it better to put the returned value into a separate varia... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-16T21:31:05.787",
"Id": "102237",
"Score": "2",
"body": "1. Could you attach some sample output? 2. Why restrict the radius to `int`? The class name, `Circle`, suggests something more general."
},
{
"ContentLicense": "CC BY-S... | [
{
"body": "<blockquote>\n <p>Is it customary in Java to place a function call inside of a println(), or is it better to put the returned value into a separate variable and then display that?</p>\n</blockquote>\n\n<p>This is something I would say is primarily opinion based. For this little app, I think it's fin... | {
"AcceptedAnswerId": "57254",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-16T21:24:38.940",
"Id": "57251",
"Score": "21",
"Tags": [
"java",
"beginner"
],
"Title": "Calculating the circumference and area of a circle"
} | 57251 |
<p>I have just finished a simple GUI stopwatch, but some of its code looks like it needs replacing. This is the code:</p>
<p>Clock class (extends Thread):</p>
<pre><code>static int hr = 0;
static int min = 0;
static int sec = 0;
static double milisec = 0;
static int rotation = 0;
static long l = 0;
static long m = 0;... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-16T21:44:48.430",
"Id": "102244",
"Score": "3",
"body": "When you say: \"point out some errors and explain how to fix them\" you make it sound like the code is not working properly. I find however that your code is working as you want ... | [
{
"body": "<pre><code>class Clock extends Thread\n</code></pre>\n\n<p>In most cases, this is not a good idea -- there's no particular reason for <code>Clock</code> to be its own thread, rather than running in a thread managed by something else (like an <code>ExecutorService</code>). The more common approach wo... | {
"AcceptedAnswerId": "57264",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-16T21:30:07.643",
"Id": "57252",
"Score": "5",
"Tags": [
"java",
"multithreading",
"datetime",
"swing",
"timer"
],
"Title": "Inefficient Stopwatch"
} | 57252 |
<p>I'm doing some practice problems on Khan Academy. The current one is Prime factorization. I came up with this:</p>
<pre><code>require 'prime'
def prime_factorization(n, primes = nil)
return [n] if Prime.prime? n
primes ||= Prime.take_while { |p| p < n/2 }
factorization = []
prime = primes.detect { |p| ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-16T23:31:52.050",
"Id": "102264",
"Score": "1",
"body": "Definitely *not* a stupid question."
}
] | [
{
"body": "<h2>Reinventing the wheel</h2>\n\n<p>There is an easier solution, considering that you are using the <code>Prime</code> class, which already has a <a href=\"http://www.ruby-doc.org/stdlib-1.9.3/libdoc/prime/rdoc/Prime.html#method-i-prime_division\" rel=\"noreferrer\"><code>Prime.prime_division()</cod... | {
"AcceptedAnswerId": "57280",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-16T21:52:29.277",
"Id": "57256",
"Score": "6",
"Tags": [
"ruby",
"primes",
"complexity"
],
"Title": "Is this a good Ruby implementation of Prime Factorization?"
} | 57256 |
<p>This takes a string input like <code>1,2,3,4,5</code>, splits it using <code>,</code> delimiter, converts each char to int and output it in a single line like this : <code>12345</code></p>
<pre><code>#include <stdio.h>
#include <string.h>
#include <stdlib.h>
int* createIntArray(char* numbersInStr... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-16T23:15:51.827",
"Id": "102260",
"Score": "1",
"body": "I spy an [**integer overflow exploit**](http://phrack.org/issues/60/10.html)!"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-16T23:43:00.537",
"... | [
{
"body": "<ul>\n<li><p>Since you have <code>main()</code> below the other function, you don't need the prototype for that function. It's only needed if <code>main()</code> is defined before a function that it calls.</p></li>\n<li><p>There's no need to declare a variable and then assign to it:</p>\n\n<blockquo... | {
"AcceptedAnswerId": "57260",
"CommentCount": "8",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-16T21:55:33.613",
"Id": "57257",
"Score": "7",
"Tags": [
"beginner",
"c",
"strings"
],
"Title": "Output int from string input"
} | 57257 |
<p>I am trying to solve <a href="https://oj.leetcode.com/problems/two-sum/" rel="noreferrer">this problem</a>:</p>
<blockquote>
<p>Given an array of integers, find two numbers such that they add up to a specific target number.</p>
</blockquote>
<p>and this is my strategy:</p>
<blockquote>
<p>For each <code>i</co... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-17T01:35:13.617",
"Id": "102279",
"Score": "3",
"body": "Use [`docstrings`](http://legacy.python.org/dev/peps/pep-0257/#what-is-a-docstring) properly instead of inventing your own documentation format."
}
] | [
{
"body": "<p>I used Python's built in binary search (via the <code>bisect</code> module) using your basic idea and it worked, with a few minor modifications. I went with the built in search because I am too lazy to write my own, and it is implemented in native code, and so is screaming fast compared to even th... | {
"AcceptedAnswerId": "57263",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-16T22:00:12.260",
"Id": "57258",
"Score": "7",
"Tags": [
"python",
"performance",
"algorithm",
"programming-challenge"
],
"Title": "Improving efficiency for two sum"
} | 57258 |
<p>Python has by far the best slice implementation I've ever used. As a quick evening project I felt like trying to implement Python's slice construct in a JavaScript function (thinking about sending a pr to a certain library with Python's slice semantics). I came up with the code below, and I'm trying to improve my co... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-17T04:38:07.490",
"Id": "102291",
"Score": "0",
"body": "I had an answer here, but I think it can be reduced to a comment: 1) throw errors and not strings, and 2) that `start == null` might confuse people. It confused me (and I'm not n... | [
{
"body": "<h1>Throwing errors</h1>\n\n<p>You should only throw errors, not strings.</p>\n\n<pre><code>throw new Error(\"Slice step cannot be zero\");\n</code></pre>\n\n<h1>Leveraging existing API</h1>\n\n<p>What you're doing looks very similar to the existing <code>slice</code> except for the last parameter, <... | {
"AcceptedAnswerId": null,
"CommentCount": "10",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-17T03:14:54.660",
"Id": "57268",
"Score": "3",
"Tags": [
"javascript"
],
"Title": "Implementing Python-like slice in JavaScript"
} | 57268 |
<blockquote>
<p>Prototype-based programming is a style of object-oriented programming
in which classes are not present, and behavior reuse (known as
inheritance in class-based languages) is accomplished through a
process of decorating existing objects which serve as prototypes. This
model is also known as cla... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-17T04:17:42.213",
"Id": "57271",
"Score": "0",
"Tags": null,
"Title": null
} | 57271 |
Prototype-based programming is a style of object-oriented programming in which behavior reuse is performed via a process of cloning existing objects that serve as prototypes. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-17T04:17:42.213",
"Id": "57272",
"Score": "0",
"Tags": null,
"Title": null
} | 57272 |
<p>I know that my <code>let configFilePath = Prelude.head args</code> is unsafe and was wondering how I could handle it better. My deployment almost always has a file at <code>~/config.cfg</code> so I suppose I could have used <code>mayHead</code> then later <code>maybe</code> to safely default the filepath to <code>~/... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2018-03-30T14:47:18.280",
"Id": "366306",
"Score": "0",
"body": "It has been almost four years. Do you want to review your own code by now?"
}
] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-17T05:38:14.200",
"Id": "57273",
"Score": "6",
"Tags": [
"haskell"
],
"Title": "Website using Persistent, Blaze-html, and Scotty"
} | 57273 |
<p>I wrote a program to calculate <a href="http://en.wikipedia.org/wiki/Collatz_conjecture#Cycles">Collatz sequences</a> for initial numbers between 1 and a given integer <code>i</code>, then find the one with the largest cycle length. My code is pretty fast, but I want to increase the speed more. Please have a look ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-17T07:11:08.737",
"Id": "102304",
"Score": "0",
"body": "What is the definition of the cycle length?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-17T08:31:38.707",
"Id": "102314",
"Score": "5",
... | [
{
"body": "<h1>Formatting</h1>\n<h1>USE PROPER INDENTATION - Please!</h1>\n<p>If you're using Eclipse, press Ctrl + Shift + F.</p>\n<p>If you're using Netbeans or IntelliJ, press Alt + Shift + F.</p>\n<p>If you're not using any IDE, <strong>start doing so!</strong></p>\n<hr />\n<h3>Braces</h3>\n<p>Once your cod... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-07-17T06:11:58.113",
"Id": "57274",
"Score": "8",
"Tags": [
"java",
"performance",
"array",
"homework"
],
"Title": "Finding the longest Collatz sequence cycle"
} | 57274 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.