body stringlengths 25 86.7k | comments list | answers list | meta_data dict | question_id stringlengths 1 6 |
|---|---|---|---|---|
<p>I need help with a simple Google Apps Script I've written. The script finds days on which no all-day events have been scheduled, across multiple calendars.</p>
<p>I'm fairly certain the main issue is the fact that I'm making an API call to get all owned calendars, <em>then</em> I'm making 5 API calls on each of the... | [] | [
{
"body": "<p>I flipped your logic a bit in the example below. I only do one API call per calendar and then do all of the processing in the client. It seems a bit faster for me, but I'm not seeing the 60 second processing time that you are. So your results my vary.</p>\n\n<pre><code>var one_day = 86400000; /... | {
"AcceptedAnswerId": "52195",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-24T17:25:43.657",
"Id": "45242",
"Score": "7",
"Tags": [
"performance",
"datetime",
"google-app-engine",
"google-apps-script"
],
"Title": "Google Apps Script for finding empty... | 45242 |
<p>Ok I am making unit converter and I have attached temperature conversion code below. The problem with this code I think is that I have written function for each and every single unit to convert to another unit.</p>
<p>So in code below there is one function to covert Celsius into Fahrenheit, Kelvin, Renkien and Newt... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-24T18:53:21.640",
"Id": "78816",
"Score": "0",
"body": "Does x have to remain constant?"
}
] | [
{
"body": "<p>There is not much need for a class for what you are after. Storing all the conversion factors in a dictionary, you could simply do something like:</p>\n\n<pre><code>def convert_temp(val, from_, to_):\n if from_[0] == to_[0]:\n return val\n off1, mult, off2 = convert_temp.data[from_[0]... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-24T18:32:49.860",
"Id": "45248",
"Score": "4",
"Tags": [
"python",
"optimization"
],
"Title": "Python Unit Coversion Code Optimization in terms of Space and Time Complexity"
} | 45248 |
<p>I have a macro that makes comparisons and then this macro exports all of the changes based on if the information doesn't match. I have it so that each column gets their own worksheet in the new workbook. I am using 7 different counting integers and it takes a very long time because I am exporting over 60k rows.</p>
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-25T13:46:16.697",
"Id": "78932",
"Score": "1",
"body": "One thing you could do to speed up looping would be dump your sheet into an array and loop that."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-25T13... | [
{
"body": "<p>What are the chances that more than one of your if statements would be true for each row? It looks like you may risk overwriting some of your data if that is the case.</p>\n\n<pre><code>Dim ws As Worksheet\nDim wb2 As Workbook\nSet wb = Application.Workbooks(\"Total Database Update_WORKING.xlsm\"... | {
"AcceptedAnswerId": "46121",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-24T18:59:29.643",
"Id": "45249",
"Score": "6",
"Tags": [
"optimization",
"vba",
"excel"
],
"Title": "More efficient update macro in Excel"
} | 45249 |
<p>After looking through PHP.net documentation for hours, is this the best way to offset an array from start to finish by using <code>array_slice()</code> with <code>array_merge()</code>?</p>
<p>For example: <code>$array = array(1,2,3,4)</code> to offset by 2 to get return <code>$array = array(3,4,1,2)</code>.</p>
<p... | [] | [
{
"body": "<p>If you don't mind modifying the original array, you can shorten the (perfectly adequate code you have) with this:</p>\n\n<pre><code>$head = array_splice($course, 0, $team); // remove and return first $team elements\n$merged = array_merge($course, $head); // append them to the end\n</code></pre... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-24T20:00:21.657",
"Id": "45253",
"Score": "3",
"Tags": [
"php",
"array"
],
"Title": "Array offset without losing values"
} | 45253 |
<p>As a part of my <a href="https://github.com/Kazark/vim-tabv" rel="nofollow">Tabv</a> Vim plugin (which at this stage is nothing more than a pitiful rag-tag assortment of half-baked hacks), I have a function which attempts to guess the directory paths for main source and unit tests. The first working version of this ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2015-08-10T13:45:00.157",
"Id": "183557",
"Score": "0",
"body": "In retrospect I think the whole approach is necessarily a hack."
}
] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-24T20:32:53.790",
"Id": "45254",
"Score": "3",
"Tags": [
"regex",
"vimscript",
"grunt.js"
],
"Title": "Scraping paths from a Gruntfile"
} | 45254 |
<p>I posted this question <a href="https://stackoverflow.com/questions/22620423/creating-dynamic-tables-with-mysqli-securely">here</a>.</p>
<p>And an answer stated that I should <strong>not</strong> do:</p>
<pre><code>$table_name = 'survey_'.$_POST['surveyid'];
</code></pre>
<p>because</p>
<blockquote>
<p>It is e... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-25T03:45:33.460",
"Id": "78867",
"Score": "0",
"body": "A small note: now your code is okay, but when you grow it, with more variables between that if and the assignation of $table_name, it might become a real problem forgetting why th... | [
{
"body": "<p>Since you validate that <code>$_POST['surveyid']</code> contains at least one digit and contains only digits, your query is safe.</p>\n\n<p><em>However,</em> the <code>CREATE TABLE</code> operation that you are trying to do strikes me as a horrible thing to do. <code>CREATE TABLE</code> is a <a h... | {
"AcceptedAnswerId": "45263",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-24T21:49:59.237",
"Id": "45259",
"Score": "4",
"Tags": [
"php",
"sql",
"security"
],
"Title": "Is there a PHP security exploit with $_POST in my code?"
} | 45259 |
<p>I was just reading about ring buffer the other day and I was fascinated by how simple yet efficient it is.</p>
<p>I've implemented a ring (circular) buffer in Ruby and I'm just wondering if there's anything I can improve, and also how to properly measure its performance.</p>
<p>Ring buffer:</p>
<pre><code>class R... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-24T21:46:46.083",
"Id": "78835",
"Score": "0",
"body": "There's a link to github repository."
}
] | [
{
"body": "<p>I'm no ruby guy but just from a general point of view I try to see data structures from an abstract interface point of view. And your interface looks like a fixed size FIFO queue. The fact that you implemented it as a ring buffer is just an implementation detail really. So I'd be inclined to renam... | {
"AcceptedAnswerId": "54002",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-24T21:39:46.420",
"Id": "45260",
"Score": "6",
"Tags": [
"performance",
"ruby",
"circular-list"
],
"Title": "Ring buffer in Ruby"
} | 45260 |
<p>I have a notification system that looks like this:</p>
<pre><code>function notificationMethod(message){
// do stuff
// once everything else is setup, attach a click handler to the "Okay" button
$('#notificationOkay').click(function () {
unBlockScreen();
$(this).off("click"); // once the... | [] | [
{
"body": "<p>For a handler that only fires once using jQuery you can use <a href=\"http://api.jquery.com/one/\">.one()</a>.</p>\n\n<p>A click handler would look something like:</p>\n\n<pre><code>function notificationMethod(message){\n // do stuff\n\n // once everything else is setup, attach a click handl... | {
"AcceptedAnswerId": "45270",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-24T23:15:29.013",
"Id": "45269",
"Score": "6",
"Tags": [
"javascript",
"jquery"
],
"Title": "Better alternative to $(this).off(\"click\")"
} | 45269 |
<p>I was working on a subtype of <code>list</code> in python that acts as a list that should never raise an IndexError (every key you input that's greater than the length of the list gets wrapped around). I was having quite a few problems however implementing it properly for slices, who have a LOT of base cases. I wrot... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-25T02:31:30.120",
"Id": "78860",
"Score": "0",
"body": "Your code is very hard to read. Can you expand your question with a pseudocode algorithm? I don't think everyone here will read into the whole thing."
}
] | [
{
"body": "<p>I'm not doing a lot of Python but one thing leaping out at me is the usage of all these single letter variables which make the code really hard to read. While longer names will make the code a bit longer I think they will improve readability quite a lot:</p>\n\n<ul>\n<li><code>s</code> should be <... | {
"AcceptedAnswerId": "45274",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-24T23:56:52.120",
"Id": "45273",
"Score": "11",
"Tags": [
"python"
],
"Title": "Custom slice() on list subtype"
} | 45273 |
<p>I'm running code which works fast locally, but when it's on Heroku it's slow. Heroku says this is because there is less memory and CPU power on my hosting than locally. I'm trying to rewrite my code so it's more efficient, but I'm not sure how.</p>
<p>This is what they said:</p>
<blockquote>
<p>...[my] method (e... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-25T03:18:29.097",
"Id": "78866",
"Score": "0",
"body": "Section model is added."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-25T06:54:08.313",
"Id": "78873",
"Score": "3",
"body": "Could you ... | [
{
"body": "<p><strong>Read with batches</strong><br>\nLooping over <code>Section.all.to_a</code> is very memory greedy (it reads <em>everything</em> to memory before starting to process it). You will be far better off using <a href=\"http://api.rubyonrails.org/classes/ActiveRecord/Batches.html\" rel=\"nofollow\... | {
"AcceptedAnswerId": "45306",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-25T01:23:57.873",
"Id": "45276",
"Score": "5",
"Tags": [
"performance",
"ruby"
],
"Title": "Speed up long running Ruby code"
} | 45276 |
<p>See the proposed changes in <a href="https://github.com/Freeseer/freeseer/pull/533/files#diff-1c2ac91deea642c6d24c522c834b474fR61" rel="nofollow">this Pull Request</a> under <code>def add_talk</code>.</p>
<pre><code>date = self.talkDetailsWidget.dateEdit.date()
time = self.talkDetailsWidget.timeEdit.time()
presenta... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-25T10:27:18.247",
"Id": "78903",
"Score": "2",
"body": "Had you used Python 3.4, you could have used `functools.singledispatch` to create an overload of `Presentation.__init__` taking a `TalkDetailsWidget` parameter."
},
{
"Con... | [
{
"body": "<p>Your <a href=\"https://github.com/Freeseer/freeseer/blob/54cbe80d577b2fe1632679426f99435da5fafa28/src/freeseer/frontend/talkeditor/TalkDetailsWidget.py\"><code>TalkDetailsWidget</code></a> is underdeveloped, I think. You could say that you have a view but no model, and that is causing you problem... | {
"AcceptedAnswerId": "45282",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-25T03:52:36.693",
"Id": "45280",
"Score": "7",
"Tags": [
"python",
"python-2.x",
"pyqt"
],
"Title": "Creating an object in Python with lots of long arguments"
} | 45280 |
<p>This is a wonky PHP function I came up with to merge some select values from child arrays into the original. It could really use some help simplifying / making it more elegant.</p>
<p>Is there a built-in method I'm overlooking? <code>array_push</code> didn't work for me because the data needed to be flat.</p>
<h... | [
{
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2019-12-19T09:54:44.380",
"Id": "458272",
"Score": "0",
"body": "you can check this solution too: [https://stackoverflow.com/questions/13877656/php-hierarchical-array-parents-and-childs](https://stackoverflow.com/questions/13877656/php-hierarc... | [
{
"body": "<p>What's the criteria for deciding which keys to keep?</p>\n\n<p>Check out the <a href=\"http://www.php.net/manual/en/function.array-walk-recursive.php\" rel=\"nofollow\">array_walk_recursive()</a> function. For example, the following matches any element with a key that starts with \"nice_value\".</... | {
"AcceptedAnswerId": "45372",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-25T04:45:30.640",
"Id": "45281",
"Score": "7",
"Tags": [
"php",
"array"
],
"Title": "Merge some child values back into the parent multidimensional array"
} | 45281 |
<p>This is one way to make a boolean in C. </p>
<pre><code>typedef enum {
false = 1 == 0,
true = 0 == 0
} bool;
</code></pre>
<p>Recently I made some like</p>
<pre><code>typedef enum {
true = ~(int)0, //true is the opposite of false
false = (int)0 //the smallest enum is equal to sizeof int
} bool;
... | [] | [
{
"body": "<p>Well, according to the ANSI book:</p>\n\n<blockquote>\n <p>The identifiers in an enumerator list are declared as constants of type <code>int</code></p>\n</blockquote>\n\n<p>So the cast is redundant:</p>\n\n<pre><code>typedef enum {\n true = ~0,\n false = 0\n} bool;\n</code></pre>\n\n<p>Also... | {
"AcceptedAnswerId": "45286",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-25T06:07:54.887",
"Id": "45284",
"Score": "5",
"Tags": [
"c",
"enum"
],
"Title": "Enumerating a boolean in C"
} | 45284 |
<pre><code>private string ExtractExceptionMesssage(string exceptionMessage)
{
const string startWord = "Message&gt";
int startWordLength = startWord.Length;
const string endWord = "/Message&gt";
var length = exceptionMessage.Length;
int index = 0;
var sb = new StringBuilder();
while... | [] | [
{
"body": "<p><strong>Consistent style</strong><br>\nYou kind of mixing your styles with curly braces - your indentation is inconsistent, and for two duplicate <code>if</code>s with single statement you once omit the braces, and on the other not. Choose a style, and stick to it - it will make your code more rea... | {
"AcceptedAnswerId": "45300",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-25T09:49:03.187",
"Id": "45292",
"Score": "5",
"Tags": [
"c#",
"strings",
"complexity"
],
"Title": "Helper method to extract a specific string from long message"
} | 45292 |
<p>Problem Statement:</p>
<blockquote>
<p>A palindromic number reads the same both ways. The largest palindrome
made from the product of two 2-digit numbers is 9009 = 91 × 99.</p>
<p>Find the largest palindrome made from the product of two 3-digit
numbers.</p>
</blockquote>
<p>This code is in C++ 11, pleas... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-25T22:53:31.037",
"Id": "79078",
"Score": "0",
"body": "Note this meta post concerning this question: [Keeping 'Competitive Results' private](http://meta.codereview.stackexchange.com/questions/1669/keeping-competitive-results-private)"... | [
{
"body": "<p><code>n</code> is an unused variable. Your compiler should have warned you about it (and you should compile with warnings enabled).</p>\n\n<p>Declaring variables with <code>auto</code> and an unsigned integer literal is unconventional. Just <code>int n1 = 999</code> would have been more readable... | {
"AcceptedAnswerId": "45296",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-25T09:50:47.113",
"Id": "45293",
"Score": "10",
"Tags": [
"c++",
"c++11",
"programming-challenge",
"palindrome"
],
"Title": "Project Euler #4 - Largest Palindrome Product"
} | 45293 |
<p>C11 is a standard for the C programming language. It replaces the previous C99 standard. C11 introduces a number of features to the language, most notably a detailed memory model focussed on multi-threaded applications. New keywords <code>_Generic</code>, static assertions, library support for multithreading and uni... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-25T11:00:36.947",
"Id": "45298",
"Score": "0",
"Tags": null,
"Title": null
} | 45298 |
C11 is a standard for the C programming language. It replaces the previous C99 standard. C11 added type-generic expressions, alignment support, static assertions, library support for multithreading and unicode as well as multiple other language and library fixes and additions. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-25T11:00:36.947",
"Id": "45299",
"Score": "0",
"Tags": null,
"Title": null
} | 45299 |
<p>This is a byte stream implementation in C. Its usage and purpose should be evident from main.</p>
<p>Implementation is not finished; this is just start. Comments are still welcome.</p>
<p><strong>.h:</strong></p>
<pre><code>#include <stdint.h>
typedef struct
{
uint8_t * data;
uint32_t length;
... | [] | [
{
"body": "<p>A few things:</p>\n\n<ul>\n<li>You are casting the result of your calls to <code>malloc</code>. That is <a href=\"https://stackoverflow.com/a/605858/1364752\">something you shouldn't do</a> actually.</li>\n<li>If possible, try not to used fixed-size integer types (<code>uint32_t</code>, <code>int3... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-25T12:01:13.453",
"Id": "45302",
"Score": "7",
"Tags": [
"c",
"stream"
],
"Title": "Byte Stream implementation in C"
} | 45302 |
<p>While the MVC4 template provided by Microsoft is useful, I feel there are a few scenarios that should be covered to help out users trying to log in.</p>
<ol>
<li>Allow the user to log in with their email address instead of their user name (they can still choose to use their user name). The former is generally easi... | [] | [
{
"body": "<p>Just a quick comment (my background is mostly C# & VB6 - I never really played with VB.NET): you're hitting the database too often. When you hit it here:</p>\n\n<blockquote>\n<pre><code>Dim username = GetUserNamebyEmail(model.UserName)\n</code></pre>\n \n <p><sub>(isn't that declaration miss... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-25T13:42:47.197",
"Id": "45308",
"Score": "7",
"Tags": [
"asp.net",
"vb.net",
"asp.net-mvc-4"
],
"Title": "Customized Template Login"
} | 45308 |
<p>Some context: I have code that looks like this (minor issue noted <a href="https://stackoverflow.com/q/22636151/14065">here</a>):</p>
<pre><code>Statement select("SELECT * FROM People WHERE ID > ? AND ID < ?");
select.execute(1462, 1477, [](int ID, std::string const& person, double item1, float item2){
... | [] | [
{
"body": "<p>I would have probably applied the following changes:</p>\n\n<ul>\n<li>Make <code>size</code> a <code>static constexpr</code> variable in <code>CallerTraits</code> instead of simply <code>static const</code>.</li>\n<li><p>Wherever a function simply passes variadic arguments whose types have been de... | {
"AcceptedAnswerId": "45334",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-25T14:06:35.640",
"Id": "45310",
"Score": "31",
"Tags": [
"c++",
"c++11",
"template",
"lambda"
],
"Title": "Dynamically call lambda based on stream input"
} | 45310 |
<p>Let's assume I have an enum type</p>
<pre><code>enum ComponentState {
TURNED_OFF,
TURNED_ON,
SUSPENDED,
TO_REPAIR;
}
</code></pre>
<p>This enum describes a state of some component. Now let's assume I want to export my component to as XML file. Then, of course, I'm going to import my component. So:<... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-25T15:21:26.250",
"Id": "78959",
"Score": "0",
"body": "@Vogel612 Sorry. Now it's visible (code was not tagged). Fo example suspended -> sleeping. Making that I'm loosing the backward comaptibility... I cannot import values exported ... | [
{
"body": "<p>A standard way to do this is to introduce a static method in addition to <code>valueOf(...)</code> that goes something like:</p>\n\n<pre><code>import java.util.HashMap;\nimport java.util.Map;\n\n\npublic enum DummyEnum {\n\n TOM, DICK, HARRY;\n\n private static final Map<String, DummyEnum... | {
"AcceptedAnswerId": "45325",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-25T14:40:17.070",
"Id": "45317",
"Score": "7",
"Tags": [
"java",
"enum"
],
"Title": "Saving enum value using name()"
} | 45317 |
<p><a href="http://meta.codereview.stackexchange.com/q/1695">Obsolete</a> tag. Do not use.</p>
| [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-25T15:34:14.603",
"Id": "45318",
"Score": "0",
"Tags": null,
"Title": null
} | 45318 |
Obsolete tag. Do not use. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-25T15:34:14.603",
"Id": "45319",
"Score": "0",
"Tags": null,
"Title": null
} | 45319 |
<p>I have an algorithm for checking whether one line is contained within another. The lines I have are made up of an ordered array of points, which are just data structures with values for x, y and z. The lines are no necessarily straight. The subline does not need to be going in the same direction as the main line.</p... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-25T16:07:36.700",
"Id": "78965",
"Score": "0",
"body": "It's Equal, sorry. I'm away from the computer for an hour or so, but it literally just compares the x's, y's, and z's to within an epsilon."
},
{
"ContentLicense": "CC BY-... | [
{
"body": "<p>Yes it can be done faster. Your algorithm has a \\$O(n^2)\\$ time.</p>\n\n<p>Idea: store the indexes of the points of the line in a dictionary and use the points as key (I assume that two distinct points never have the same coordinates. If this is not the case, then an index list would have to be ... | {
"AcceptedAnswerId": "45338",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-25T16:01:21.623",
"Id": "45320",
"Score": "10",
"Tags": [
"c#",
"performance",
"algorithm"
],
"Title": "Increase performance in sub-line detection"
} | 45320 |
<p>I am stuck to define a generic repository with AutoFac IOC container. I am keeping thing very simple and only showing relevant information. </p>
<p><strong><code>BaseEntity</code></strong></p>
<pre><code>public abstract class BaseEntity
{
public int Id { get; set; }
}
</code></pre>
<p><strong><code>IRepositor... | [] | [
{
"body": "<p>First, I would caution against using the generic repository + unit of work pattern that was super trendy a few years ago because it has problems not unlike the problems you're facing (along with problems stemming from the fact that EF crosses traditional DAL/Domain/BL boundaries). Simply put, I wo... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-25T16:23:03.897",
"Id": "45322",
"Score": "4",
"Tags": [
"c#",
"asp.net",
"entity-framework",
"dependency-injection",
"autofac"
],
"Title": "Generic Repository, UnitOfWork an... | 45322 |
<p>I have an axis-aligned bounding box (AABB) that I've coded, but at the moment it is very redundant. I feel like there are variables that I can get rid of. I need the AABB to be very fast, and I'd like it to be more lightweight than it is.</p>
<pre><code>#pragma once
#include "Engine.h"
// Collision
#include "Vec2... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-25T17:08:34.473",
"Id": "78992",
"Score": "0",
"body": "Please add the definition of your `init` method."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-25T20:49:39.223",
"Id": "79052",
"Score": "0"... | [
{
"body": "<p>adding and halving is cheap, don't bother optimizing it out unless it is a problem</p>\n\n<p>all you need is <code>min</code> and <code>max</code> and derive the rest from that:</p>\n\n<pre><code>double getMinX()const {\n return min.getX();\n}\n\n\ndouble getWidth()const {\n return max.getX(... | {
"AcceptedAnswerId": "45332",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-25T16:25:03.290",
"Id": "45323",
"Score": "5",
"Tags": [
"c++"
],
"Title": "Eliminate axis-aligned bounding box (AABB) variables"
} | 45323 |
<p><strong>Fast Time conversion</strong></p>
<p>I'm trying to write a very fast time-to-string and string-to-time function.</p>
<p>I noticed that on low CPU mobile devices this function has, even if minimal, impact on the performance of the overall canvas animation.</p>
<p><strong>Milliseconds to Time string (HH:MM:... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-25T18:37:04.233",
"Id": "79008",
"Score": "4",
"body": "Obfuscation/minification != optimization. Your code wouldn't run any slower if you made it more readable. Also, you can use [jsperf.com](http://jsperf.com) to benchmark your code"... | [
{
"body": "<p>To start,</p>\n\n<p>I would like to offer an analogy; you have built a really fast car with a hood that wont open ( it's hard to maintain ), and you keep insisting that it's okay, because the car is fast. We keep telling you that you're doing it wrong.</p>\n\n<p>As for \"Don't do it, don't do it ... | {
"AcceptedAnswerId": null,
"CommentCount": "11",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-25T18:00:29.673",
"Id": "45335",
"Score": "2",
"Tags": [
"javascript",
"performance",
"strings",
"datetime",
"converting"
],
"Title": "Milliseconds to Time string & Time str... | 45335 |
<p>I'm currently facing a problem where I have to shift data in a multidimensional JS array in different directions, but I think the first solution I whipped up is not as efficient as it could be (some fancy math I don't know of maybe?).</p>
<p>Let me explain the problem a bit better with some examples of my data.</p>... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-25T22:55:01.493",
"Id": "79080",
"Score": "0",
"body": "Are you always dealing with just 0s and 1s?"
}
] | [
{
"body": "<p>From a once over:</p>\n\n<ul>\n<li><p>You should consider MVC, your data should live in an object you created, you should update your model, and then from your model update the UI</p></li>\n<li><p>If you dont want to do this, then you should at least find all cells and assign each cell to a 2d JS ... | {
"AcceptedAnswerId": "45343",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-25T19:57:44.603",
"Id": "45342",
"Score": "3",
"Tags": [
"javascript",
"algorithm",
"matrix"
],
"Title": "Shift data in multidimensional array"
} | 45342 |
<p>I've written a small webapp in JavaScript, and am now essentially rewriting it to use RequireJS. I'm doing this partly to get more familiar with RequireJS (which I have little experience with), as well as for ease of maintaining and upgrading the app.</p>
<p>I'm hoping to get feedback on whether the structure I'm ... | [] | [
{
"body": "<p>This is honestly pretty good. I usually use <code>requirejs.config</code> to set the paths and configurations on require (it's going to grow a lot as you add things like shims, urlArgs, etc). You will also probably want to reuse it in several places. <a href=\"https://github.com/togakangaroo/Blog/... | {
"AcceptedAnswerId": "45354",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-25T20:13:05.760",
"Id": "45344",
"Score": "4",
"Tags": [
"javascript",
"design-patterns",
"require.js"
],
"Title": "Structure a webapp using RequireJS"
} | 45344 |
<p>I got the following ugly code:</p>
<pre><code>template < class _Coeff,
unsigned _nVars,
typename _Expo=int,
template <class, class> class _Map = _Map >
class Polynomial
: boost::ring_operators< Polynomial<_Coeff,_nVars,_Expo,_Map>
, boost::addable < Pol... | [] | [
{
"body": "<p>Easy, with default template arguments:</p>\n\n<pre><code>template < class _Coeff,\n unsigned _nVars,\n typename _Expo=int,\n template <class, class> class _Map = _Map\n typename Poly = Polynomial<_Coeff,_nVars,_Expo,_Map>,\n typename Pair = std::pair<... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-25T21:03:30.390",
"Id": "45345",
"Score": "4",
"Tags": [
"c++",
"template",
"boost"
],
"Title": "Template with boost::operators extremely verbose and repeating"
} | 45345 |
<p>Below is some code I have written today to test out some bits I have learnt. It isn't much nor is it spectacular. Please critique and let me know what I could/should have done differently or anything I could do to improve it so far.</p>
<pre><code>package easy8;
import java.util.Scanner;
public class song99bottle... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-26T09:31:41.330",
"Id": "79125",
"Score": "0",
"body": "Missing \"one\". \"And the little _one_ said 'I'm lonely'.\""
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-26T09:41:44.450",
"Id": "79127",
... | [
{
"body": "<p>There are a number of improvements you can make, but removing the declaration for <code>peeps</code> in <code>lyrics()</code> and changing the <code>while</code> loop to a <code>for</code> loop would be a good start:</p>\n\n<pre><code>for(int peeps=10;peeps>0;peeps--) {\n System.out.println(... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-25T21:18:31.443",
"Id": "45346",
"Score": "8",
"Tags": [
"java",
"beginner"
],
"Title": "And the little one said \"Roll over\""
} | 45346 |
<p>I am a beginner in C++ and learning from textbook. I find it hard to jump into oops concepts as I have used C a lot. Here is an interview question I came across:</p>
<blockquote>
<p>Problem Statement </p>
<p>Our marketing department has just negotiated a deal with several local merchants that will allow us t... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-25T22:01:40.480",
"Id": "79065",
"Score": "1",
"body": "Sadly, you asked near the end of the day when I am all out of votes... :/"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-25T22:30:57.937",
"Id": ... | [
{
"body": "<p>Reading a unit test:</p>\n\n<blockquote>\n <p>Jareau Wade,Rob Eroh,Mahmoud Abdelkader,Wenyi Cai,Justin Van Winkle,Gabriel Sinkin,Aaron Adelson;Batman No. 1,Football - Official Size,Bass Amplifying Headphones,Elephant food - 1024 lbs,Three Wolf One Moon T-shirt,Dom Perignon 2000 Vintage</p>\n</blo... | {
"AcceptedAnswerId": "45355",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-25T21:49:36.587",
"Id": "45351",
"Score": "5",
"Tags": [
"c++",
"beginner",
"strings",
"interview-questions",
"vectors"
],
"Title": "Calculate Suitability Score program"
} | 45351 |
<p>I found out that in Visual Studio 2012, it is possible to create project of SFML easily with a template. I am not an experienced C# programmer. Hence I wanted to implement a physics component just for practice purposes.</p>
<p><code>PhysicsManager</code> Class contains all the physical objects:</p>
<pre><code>publ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-25T22:46:30.557",
"Id": "79074",
"Score": "3",
"body": "You should be able to simply return the instance on your singleton. Since you initialize it where you declare it, it should never be null. see http://www.yoda.arachsys.com/csharp/... | [
{
"body": "<p>for this little bit of code here</p>\n\n<pre><code>// TODO: Insert Update Code Here\nif (Keyboard.IsKeyPressed(Keyboard.Key.Down))\n MainCircle.AddForce(0, 1.5F);\nif (Keyboard.IsKeyPressed(Keyboard.Key.Up))\n MainCircle.AddForce(0, -1.5F);\nif (Keyboard.IsKeyPressed(Keyboard.Key.Right))\n ... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-25T22:16:31.757",
"Id": "45353",
"Score": "10",
"Tags": [
"c#",
"beginner",
"game",
"collision",
"sfml"
],
"Title": "Design of physics with Collision Detection using SFML"
} | 45353 |
<p>I have a bit of Python source code that I want to recreate in C#. The code is about reading and decrypting a binary file. I have tested the function on an existing file and it runs without errors; while the resulting string is not garbled or anything, it does not appear to be useful to me.</p>
<p>But that is outsid... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-25T23:17:03.017",
"Id": "79085",
"Score": "3",
"body": "This is an interesting question, because unlike most translation questions (which are bad), you've actually tried to do it. This comment is designed to guard against thoughtless d... | [
{
"body": "<p>This section seems wrong:</p>\n\n<pre><code>//The next 2 lines are for parsing the short, equivalent(?) to struct.unpack('h', byte)\ni <<= 8;\ni += file.ReadByte();\n</code></pre>\n\n<p>you're shifting the value in <code>i</code> 8 bits left and then reading another byte. I'm guessing becaus... | {
"AcceptedAnswerId": "45384",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-25T23:12:27.077",
"Id": "45359",
"Score": "11",
"Tags": [
"c#",
"python"
],
"Title": "Are these C# and Python code snippets functionally identical?"
} | 45359 |
<p>I have a method I created which is a custom <code>indexOf()</code>. This code seems ugly to me so I was wondering if anyone could recommend a cleaner and perhaps faster implementation of my method.</p>
<pre><code>public static int myIndexOf(char[] str, char[] substr, int index) {
if (str == null) {
thro... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-26T01:27:16.560",
"Id": "79095",
"Score": "0",
"body": "It seems the Boyer Moore part is missing?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-26T01:43:53.057",
"Id": "79097",
"Score": "0",
"... | [
{
"body": "<p><strong>Naming</strong></p>\n\n<ul>\n<li><p>Choose an existing idiom such as \"find a needle in a haystack\" and consider putting the parameters in that order.</p></li>\n<li><p>The name <code>index</code> implies some generic location within <code>haystack</code>. However, <code>start</code> makes... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-26T00:53:53.167",
"Id": "45362",
"Score": "6",
"Tags": [
"java",
"strings",
"search"
],
"Title": "indexOf() and Boyer Moore methods"
} | 45362 |
<p>For non-plugin code, I generally use the module pattern, but I'm working on a jQuery plugin and decided to try out the "<a href="http://www.addyosmani.com/resources/essentialjsdesignpatterns/book/#jquerypluginpatterns" rel="nofollow noreferrer">lightweight start</a>" pattern. The problem is, I find myself needing <c... | [] | [
{
"body": "<p>You could use a closure to create your own proxy.</p>\n\n<pre><code>Plugin.prototype.init = function() {\n var self = this;\n rows.each(function (groupIndex, group) {\n self.initGroup(groupIndex, group);\n });\n this.container.on(\"click\", this.options.addBtnId, function (ev) {... | {
"AcceptedAnswerId": "45374",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-26T05:25:30.203",
"Id": "45369",
"Score": "8",
"Tags": [
"javascript",
"jquery",
"plugin"
],
"Title": "Private methods and properties in jQuery \"lightweight start\" pattern"
} | 45369 |
<blockquote>
<p>Lets say there are 10 boys and 10 girls in speed date.
10 boys select 4 girls and rank them.
10 girls select 4 boys and rank them.
In the end the winning pairs would be returned.</p>
</blockquote>
<p>Finer details such as tie-breakers, rules of input params etc, are well documented.
Looking f... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-26T08:08:27.047",
"Id": "79114",
"Score": "2",
"body": "Where are 10 boys/girls and where are their 4 choices in your test cases?"
}
] | [
{
"body": "<p>Looks good, I didn't work through the logic of your algorithms, but generally looked if things could be done more efficiently and nothing grabbed my attention.</p>\n\n<p>The one comment I do have is on your validate() method, it checks for null and empty maps, but I believe you have an additional ... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-26T06:07:37.843",
"Id": "45371",
"Score": "12",
"Tags": [
"java",
"algorithm"
],
"Title": "Speed dating algorithm to select the pair of dates"
} | 45371 |
<p>I have the following code which I feel that I must refactor, but not sure how to do it.</p>
<pre><code>List<AlgoTuningData> feedbackScoreDatas;
List<AlgoTuningData> topRatedDatas;
int score1 = 0;
int score2 = 0;
boolean matched1 = false;
boolean matched2 = false;
for (AlgoTuningData topRatedData : topRa... | [] | [
{
"body": "<p>I would <em>not</em> refactor this substantially, except maybe to avoid the reuse of the <code>matched1</code> and <code>matched2</code> variables:</p>\n\n<pre><code>{\n boolean matched1 = false;\n boolean matched2 = false;\n for (...) {\n ...\n }\n}\n\n// and here again\n</code... | {
"AcceptedAnswerId": "45383",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-26T07:43:20.357",
"Id": "45376",
"Score": "1",
"Tags": [
"java"
],
"Title": "Refactoring scoring algorithm"
} | 45376 |
<p>I have written code in C++ 11 and check output with Project Euler site, and it is correct. I am not showing output, just to keep it secret, at least from my end.</p>
<p>Please review my C++ 11 code.</p>
<pre><code>#include <fstream>
#include <string>
#include <algorithm>
#include <iostream>... | [] | [
{
"body": "<p>The code is generally pretty clean, however, the major sticking point is that everything here is just shoved into <code>main</code>. Just breaking this up with a few functions that do one thing would be a good start:</p>\n\n<pre><code>std::vector<std::string> read_file(const std::string&... | {
"AcceptedAnswerId": "45380",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-26T07:43:59.750",
"Id": "45377",
"Score": "7",
"Tags": [
"c++",
"algorithm",
"c++11",
"file",
"programming-challenge"
],
"Title": "Project Euler #22 - Name scores"
} | 45377 |
<p>I'm just started learning TDD with Rails and RSpec. This is my first test for controller. Just plain RESTful UserController that responds with JSON, so it has no <em>new</em> and <em>edit</em> methods. Please review it</p>
<pre><code>require 'spec_helper'
describe UsersController do
let(:users) { 4.times.map { c... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-26T09:45:27.233",
"Id": "79129",
"Score": "0",
"body": "looks pretty to good to me, but you could start by indenting with 2 spaces :)"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-26T09:50:39.017",
"I... | [
{
"body": "<p>It looks really good to me. All I have a very minor quibbles/suggestions.</p>\n\n<p>Since you're using FactoryGirl, you should be able to use <code>create_list :user, 4</code> instead of the <code>4.times.map { ... }</code> block</p>\n\n<p>You might as well check that a new record <code>be_kind_of... | {
"AcceptedAnswerId": "45501",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-26T08:10:07.967",
"Id": "45379",
"Score": "8",
"Tags": [
"ruby",
"ruby-on-rails",
"rspec"
],
"Title": "My first controller rspec test"
} | 45379 |
<p>I have written the following code as the level rendering part of a game engine I am writing. I am very happy how it works but as it is the background / level graphics made up of individual blocks it needs to be quick.</p>
<p>What it does it look take the graphics from a resource loaded elsewhere and scales it onto ... | [] | [
{
"body": "<p>Three things I noticed: </p>\n\n<ol>\n<li><p>Generally speaking, when you have a for with a gigantic if composing the contents of the for, it is because you're checking for a condition in order to do something. If this condition is related to what you're iterating on, then you can modify the for... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-26T08:15:30.847",
"Id": "45381",
"Score": "8",
"Tags": [
"java",
"game"
],
"Title": "Blocktastic optimisation"
} | 45381 |
<p>I have two lists of the same type and I want to be able view a list of both lists:</p>
<pre><code> public List<Page> HeaderPages;
public List<Page> SurveyPages;
public IReadOnlyList<Page> AllPages
{
get
{
List<Page> allPages = new List<Page&g... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-26T10:06:00.923",
"Id": "79132",
"Score": "0",
"body": "Can you post an example of some code which demonstrates the problem? You're asking us to review a hypothetical class which contains a private allPages list, and a hypothetical met... | [
{
"body": "<p>As you said, keep another List which will contains all the elements and when you add an element inside one of the two update the internal List ... you could make List private and make helper method which update the main list and the internal List.</p>\n\n<p>With your code anyway you will create a ... | {
"AcceptedAnswerId": "45391",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-26T09:27:24.230",
"Id": "45386",
"Score": "10",
"Tags": [
"c#",
"properties"
],
"Title": "Inefficient code inside of getter?"
} | 45386 |
<p>I have a piece of code which grabs data from an SQL database and displays it in a DataGridView. This code works perfectly fine for me.</p>
<p>It has been pointed out to me that the below code is bad programming:</p>
<pre><code>Imports System.Data.SqlClient
Public Class Form1
Dim dbConnection As SqlConnection
Di... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-26T10:27:18.777",
"Id": "79136",
"Score": "0",
"body": "It's hard to believe that `\"SELECT [item] FROM [table] WHERE ([item] = 'value')\"` is real code from a real project. How/where is the value of `'value'` specified in the real cod... | [
{
"body": "<p>Three possible problems that I see.</p>\n\n<hr>\n\n<pre><code>dbConnection = New SqlConnection(\"Data Source=connectionhere\\sqlexpress;Initial Catalog=line_log;Integrated Security=True\")\n</code></pre>\n\n<p>You have a hard-coded connection string. If you want a different database location then ... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-26T10:19:08.707",
"Id": "45390",
"Score": "1",
"Tags": [
"sql",
"vb.net"
],
"Title": "Selecting from a database into a DataGridView"
} | 45390 |
<p>Could you give any suggestion on the following unit tests? How to make it more readable, maintainable and trustworthy. If it is not a problem - post some code with the suggestions.</p>
<pre><code>[TestClass]
public class PropertyBagCompositeTests
{
private readonly IFixture fixture;
private readonly Mock<... | [] | [
{
"body": "<p>It's pretty clean. In my oppinion, test parameters should be setup in each test, and not during setup. Setup is for setting up infrastructure bits. You should be able to take advantage of AutoFixture AutoMocking customization to make your tests more resiliant to change (let autofixture create your... | {
"AcceptedAnswerId": "45407",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-26T10:33:30.267",
"Id": "45392",
"Score": "7",
"Tags": [
"c#",
"unit-testing",
"moq",
"fluent-assertions"
],
"Title": "Unit tests using C#, Moq, AutoFixture, FluentAssertions"... | 45392 |
<p>I have this code which runs when an Async HTTP call is made on a <code>HorizontalScrollView</code></p>
<pre><code> //These 3 defined outside of the method
ObjectAnimator animatorR = null;
ObjectAnimator animatorL = null;
boolean loop = true;
Inside the met... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-26T13:58:22.790",
"Id": "79167",
"Score": "1",
"body": "Hi, welcome to CodeReview.SE. Can you please provide the whole class or whatever this snippet was supposed to be in ?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"Creation... | [
{
"body": "<p>The biggest change I can see here would be to extract a class out of the two anonymous inner classes. The two variations are exactly the same except for which <code>ObjectAnimator</code> they should call next, and which logging tag to use. So let's extract a class and pass those values to its cons... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-26T13:05:30.457",
"Id": "45402",
"Score": "6",
"Tags": [
"java",
"android"
],
"Title": "Animated ScrollView"
} | 45402 |
<p>I have a RoR 4 app, and its model have these associations:</p>
<pre><code>has_many :accreditations
has_one :legal, -> { where(kind_cd: Accreditation.legal) }, class_name: 'Accreditation'
has_many :departments, -> { where(kind_cd: Accreditation.department) }, class_name: 'Accreditation'
</code></pre>
<p>So, y... | [] | [
{
"body": "<p>I don't see what you will gain with your hypothetical <code>using</code> syntax, let's say there is one... your code will look like this:</p>\n\n<pre><code>has_many :accreditations\nhas_one :legal, -> { where(kind_cd: Accreditation.legal) }, using: :accreditations\nhas_many :departments, -> ... | {
"AcceptedAnswerId": "45428",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-26T13:20:12.803",
"Id": "45405",
"Score": "3",
"Tags": [
"ruby",
"ruby-on-rails"
],
"Title": "Rails refactoring has_many"
} | 45405 |
<p>I want users to enter their code into my blog and keep original styling tags intact. So I had to develop a function that extracts user's code (between two tags) and convert special characters to HTML entities, then remove unwanted tags using <code>purifyHTML</code>.</p>
<p>I want to know if it is safe to use it lik... | [] | [
{
"body": "<p>\"Extracter\" <a href=\"https://books.google.com/ngrams/graph?content=extracter%2C+extractor\" rel=\"nofollow\">should be spelled \"extractor\"</a>.</p>\n\n<p>It's nice that you broke up the functionality into smaller functions.</p>\n\n<hr>\n\n<p>In <code>get_string_between()</code>, you don't app... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-26T13:42:01.797",
"Id": "45406",
"Score": "5",
"Tags": [
"php",
"algorithm",
"strings",
"security"
],
"Title": "Extract code and convert special characters to HTML entities"
} | 45406 |
<p>I am working on my first HTML5/CSS web site and, like all of my first-time projects, they end up cumbersome, crude, and hard to work with when changes need to be made later in the life cycle. I am attaching some code with a small amount of HTML and CSS. I have read up on CSS and HTML and, after quite alot of effort,... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-26T16:53:26.287",
"Id": "79197",
"Score": "3",
"body": "One quick note, you can save yourself a lot of layout headache, if you leverage a CSS framework like Twitter.Bootstrap (http://getbootstrap.com/2.3.2/) it is drastically easier to... | [
{
"body": "<p>One example of where you should use other HTML Elements</p>\n\n<pre><code> <div id=\"site1Container\">\n <div id=\"site1logo\"></div>\n <div id=\"site1desc\">Site description goes here.</div>\n </div>\n</code></pre>\n\n<p>This should look lik... | {
"AcceptedAnswerId": "45417",
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-26T15:25:33.890",
"Id": "45408",
"Score": "38",
"Tags": [
"html",
"css",
"html5",
"web-services"
],
"Title": "First Time HTML5/CSS Site"
} | 45408 |
<p>I want to group the two very similar jQuery functions into just one. Any idea?</p>
<p><strong>HTML:</strong></p>
<pre><code><input id="progress" type="text" class="spinner-input form-control" maxlength="3" readonly value="<?php echo $progreso['progress'] ?>">
<div class="spinner-buttons input-group-... | [] | [
{
"body": "<p>You could define one function:</p>\n\n<pre><code>function plus_or_minus(event)\n{\n var isPlus = $(this).id === '#plus';\n\n var progress = parseInt($('#progress').val(), 10); \n\n if(isPlus)\n progress += 5;\n else\n progress -= 5;\n\n if(progress > 100)\n p... | {
"AcceptedAnswerId": "45416",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-26T15:42:26.930",
"Id": "45412",
"Score": "3",
"Tags": [
"javascript",
"jquery",
"html"
],
"Title": "Grouping similar jQuery functions"
} | 45412 |
<p>For the over eager people: check out this <a href="http://plnkr.co/edit/YXtVx48q01rrfKu3DEIX" rel="nofollow">plunker</a></p>
<p>I create a directive which has to add buttons on top of input fields, to select the language you want to input.</p>
<p>This is used on forms, such as a product form. A product has transla... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-19T07:30:58.183",
"Id": "83499",
"Score": "1",
"body": "You are basically reading your attributes, then why not simply using `$attrs` provided instead of the fragile `$scope.$parent`?"
}
] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-26T16:19:17.210",
"Id": "45421",
"Score": "1",
"Tags": [
"javascript",
"angular.js"
],
"Title": "Angular directive with use of scope.$parent and $timeout"
} | 45421 |
<p>The problem is to input, divide 2 <code>int</code>s and display the result.<br>
Please, review my program. It worth noting, I've intentionally used <code>goto</code>, not <code>while</code>. </p>
<pre><code>int main(){
int a, b;
ab_input:
cout << "Enter 2 numbers: ";
cin >> a >> b;
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-26T16:31:53.117",
"Id": "79188",
"Score": "12",
"body": "Could you explain why you've intentionally used `goto`?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-26T16:33:10.333",
"Id": "79189",
"Sco... | [
{
"body": "<p>Some alternatives to <code>goto</code>:</p>\n\n<pre><code>int main(){\n int a, b;\n\n for (;;) { // until success\n cout << \"Enter 2 numbers: \";\n cin >> a >> b;\n try {\n if (!cin) throw std::runtime_error(\"Bad input\");\n if (... | {
"AcceptedAnswerId": "45424",
"CommentCount": "9",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-26T16:28:17.213",
"Id": "45423",
"Score": "7",
"Tags": [
"c++",
"exception-handling"
],
"Title": "Dividing 2 numbers"
} | 45423 |
<p>I had to look up some other solutions online because I could not figure it out on my own. I really wish I could have come up with it completely on my own, but that didn't happen. Nevertheless, please review my prime number program and let me know if there are any improvements I should make or advice your would like ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-27T03:59:15.743",
"Id": "79289",
"Score": "1",
"body": "[Trial division](https://en.wikipedia.org/wiki/Trial_division), nice first step! Now try the [Sieve of Eratosthenes](https://en.wikipedia.org/wiki/Sieve_of_Eratosthenes). Too intu... | [
{
"body": "<p>First, let's correct your algorithm (<a href=\"http://www.programmingsimplified.com/c/source-code/c-program-for-prime-number\">using this very similar code</a>) and reformat just a little bit your code (with Fiddle's TidyUp):</p>\n\n<p><a href=\"http://jsfiddle.net/xCX9W/\">JSFIDDLE</a></p>\n\n<pr... | {
"AcceptedAnswerId": "45435",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-26T18:23:59.570",
"Id": "45431",
"Score": "12",
"Tags": [
"javascript",
"beginner",
"primes"
],
"Title": "First attempt at generating prime numbers"
} | 45431 |
<p>I'm trying to write a regular expression to check names for invalid entries. Basically I'm trying to eliminate people entering random junk as their name. I know I can't completely eliminate it but I'm trying to make it a little harder at the very least. Here is what I have so far. It works fine I'm wondering if ther... | [] | [
{
"body": "<p>First off, there is an error: You have the part <code>[b-</code> duplicated at the beginning.</p>\n\n<p>The first section matches five successive consonants, which is possbile. Examples for German words (although not names) with up to eight successive consonants: <a href=\"http://www.duden.de/spra... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-26T21:46:29.627",
"Id": "45443",
"Score": "2",
"Tags": [
"javascript",
"regex"
],
"Title": "Check for invalid name"
} | 45443 |
<p>I have written the following C code for calculating the Shannon Entropy of a distribution of 8-bit ints. But obviously this is very inefficient for small arrays and won't work with say 32-bit integers, because that would require literally gigabytes of memory. I am not very experienced in C and don't know what would ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-27T06:56:21.760",
"Id": "79308",
"Score": "0",
"body": "I believe your code currently contains a bug. Consider what happens in: `for (int i = 0; i < 256; i++) probabilityOfX[x[i]] /= length;`, if `x` has a length of 10 (or anything els... | [
{
"body": "<p>Firstly, you know the size of the number of buckets you want to use here, so there is no reason to use dynamic allocation (specifically, <code>double *probabilityOfX = calloc(sizeof(double), 256);</code>). This could simply be:</p>\n\n<pre><code>double probabilityOfX[256];\nmemset(&probability... | {
"AcceptedAnswerId": "45459",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-26T22:10:04.487",
"Id": "45444",
"Score": "10",
"Tags": [
"c",
"beginner"
],
"Title": "Counting occurrences of values in C Array (Shannon Entropy)"
} | 45444 |
<p>I'm writing a bash script to handle the PPA's on Ubuntu & derivatives. I was wondering how to know if I'm handling this the right way. </p>
<p>So, the script works (flawlessly), but I posted it to a blog and got this feedback : </p>
<blockquote>
<p>The way you wrote you script is the one we all use when we b... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-26T22:58:33.697",
"Id": "79268",
"Score": "0",
"body": "@Jamal : are you sure this is a better title than \"Bash script : how to know if it's written correctly?\" ? Because if the script itself is for PPA's handling, the main reason I'... | [
{
"body": "<h3>User experience</h3>\n\n<ul>\n<li><code>-h</code> or <code>--help</code> should print the usage message to standard output, which you do. However, on any unrecognizable command line, you should print the same (or similar) message to standard error and exit with a non-zero status.</li>\n<li>Simi... | {
"AcceptedAnswerId": "45469",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-26T22:23:08.803",
"Id": "45445",
"Score": "8",
"Tags": [
"bash",
"shell"
],
"Title": "Script for handling PPA's on Ubuntu"
} | 45445 |
<p>Ideally the Code Review would target the correctness of the approach implementing the Swing TreeModel.</p>
<p>In particular, is the structural separation[1], event message passing, threading[2], object synchronisation, etc. all best practice ?</p>
<ul>
<li>[1] My understanding is that the TreeModel should have sep... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-27T10:50:01.240",
"Id": "79331",
"Score": "0",
"body": "I have updated the code on GitHub as per @rolfl suggestions. 1) Node lock is now per node, not static. 2) Listeners don't lead the lock. 3) Replaced weakHashMap with list."
}
] | [
{
"body": "<h2>static</h2>\n<p>What a difference 1 word can make:</p>\n<blockquote>\n<pre><code>/** synchronisation lock */\nprivate static final Object OBJ_LOCK = new Object();\n</code></pre>\n</blockquote>\n<p>That 1 word is <em>'static'</em>.</p>\n<p>In this case, each and every Node shares the exact same OB... | {
"AcceptedAnswerId": "45451",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-26T23:30:53.967",
"Id": "45449",
"Score": "6",
"Tags": [
"java",
"thread-safety",
"tree",
"swing",
"event-handling"
],
"Title": "Correctly implementing the Swing TreeModel... | 45449 |
<p>I'm trying to design a binary relation interface in Java and then implement it, but I'm not sure if I'm doing it right. I'd really appreciate a little feedback just so I know if I'm way in the wrong direction or not.</p>
<p>This is what I've got so far:</p>
<p>Interface:</p>
<pre><code>public boolean compare(Obje... | [] | [
{
"body": "<p>There are a couple of things in here that concern me.... but, the most concerning is:</p>\n\n<p><strong>Use <code>.equals()</code> to compare String values</strong></p>\n\n<p>Code like this:</p>\n\n<blockquote>\n<pre><code>if(basket[i][0]==X){\n</code></pre>\n</blockquote>\n\n<p>will fail when you... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-27T00:44:44.610",
"Id": "45452",
"Score": "5",
"Tags": [
"java",
"interface"
],
"Title": "Binary relation interface"
} | 45452 |
<p>Below is some code which verifies a credit card number using the checksum as well as check if number of digits are appropriate as well if digits start with right numbers. I am not sure if converting the <code>double</code> into a string was the best bet. I wasn't going to at first but had trouble figuring out the mo... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-27T02:49:59.473",
"Id": "79285",
"Score": "5",
"body": "I'd suggest never storing the `number` in a `double` in the first place. The card `number` is really a digit string; note that the format technically allows a leading digit of `0`... | [
{
"body": "<p>As @Keith says, credit card numbers should be treated as strings, not numbers, and definitely not floating-point numbers. If you want to ensure that the input contains only digits (and maybe spaces), use <code>strspn()</code>. Squeeze out any spaces, then validate the length using <code>strlen()... | {
"AcceptedAnswerId": "45474",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-27T01:30:54.523",
"Id": "45455",
"Score": "19",
"Tags": [
"c",
"validation",
"finance"
],
"Title": "Credit card verification: string conversion most optimal?"
} | 45455 |
<p>I've watched quite a few videos and read a couple of articles on unit testing and I've tried my best to make this test case as good as possible. In which areas can it still be improved?</p>
<p>I should probably add that SM2Scheduler is an implementation of the SM2 algorithm, which is used in flashcard software such... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-27T03:58:27.420",
"Id": "79287",
"Score": "1",
"body": "In addition to help here - you can look into a coverage measurement tools, like `coverage.py` to spot branches you did not cover with tests."
}
] | [
{
"body": "<p>Drop one-time use local variables and use libraries such as <a href=\"http://github.com/hamcrest/PyHamcrest\" rel=\"nofollow\">PyHamcrest</a> to improve assertion readability.</p>\n\n<p>Compare</p>\n\n<pre><code>def test_init_last_review_date_is_today(self):\n assert_that(self.scheduler.last_re... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-27T01:58:55.113",
"Id": "45457",
"Score": "12",
"Tags": [
"python",
"unit-testing"
],
"Title": "Do my unit tests follow best practices?"
} | 45457 |
<p>I am trying create an algorithm for finding the zero crossing (check that the signs of all the entries around the entry of interest are not the same) in a two dimensional matrix, as part of implementing the Laplacian of Gaussian edge detection filter for a class, but I feel like I'm fighting against Numpy instead of... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-27T08:18:28.213",
"Id": "79312",
"Score": "0",
"body": "adjacent meaning N,S,W,E or the 8 (or just 3) around the checked? currently it looks like the NSWE solution, but just to make sure."
},
{
"ContentLicense": "CC BY-SA 3.0",... | [
{
"body": "<p>One way to get the neighbor coordinates without checking for (a != 0) or (b != 0) on every iteration would be to use a generator. Something like this:</p>\n\n<pre><code>def nborz():\n l = [(-1,-1), (-1,0), (-1,1), (0,-1), (0,1), (1,-1),(1,0),(1,1)]\n try:\n while True:\n yie... | {
"AcceptedAnswerId": "67662",
"CommentCount": "7",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2014-03-27T02:00:06.057",
"Id": "45458",
"Score": "19",
"Tags": [
"python",
"matrix",
"numpy"
],
"Title": "Finding a zero crossing in a matrix"
} | 45458 |
<p>I had posted this here and was asked to move it to code review since my code works and am looking for the best possible solution : <a href="https://stackoverflow.com/questions/21998312/gae-datastore-join-group-by/21998313#21998313">original post</a></p>
<p><strong>NOTE:</strong> I have seen the JOIN in GAE related ... | [] | [
{
"body": "<p>Just a few generic notes, I'm not familiar with Google App Engine:</p>\n\n<ol>\n<li><p><code>HashMap<...></code> reference types could be <code>Map<...></code>:</p>\n\n<pre><code>public Map<String, List<ListDisplay>> getData() {\n</code></pre>\n\n<p>See: <em>Effective Java,... | {
"AcceptedAnswerId": "46264",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-27T05:31:13.797",
"Id": "45464",
"Score": "6",
"Tags": [
"java",
"google-app-engine"
],
"Title": "GAE datastore JOIN + GROUP BY"
} | 45464 |
<p>This is the stored procedure I'm using to list some places in my website. How can I optimize it to perform well? Which functions in query is taking much time for its execution?</p>
<pre><code>ALTER PROCEDURE [dbo].[PlaceListSelect] @cateID int, @searchTxt varchar(50), @userID int, @RowIndex int, @MaxRows int, @Loca... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-27T10:09:10.747",
"Id": "79327",
"Score": "0",
"body": "Might you get better answers (about performance) if you added the query plan to your questions, and add the DDL which shows what the database indexes are?"
},
{
"ContentLi... | [
{
"body": "<p>It is hard to give an accurate answer without seeing all the code (there are a few functions like GetSearchPlaceCount, and GetFriends, [PrivacyCheck], CheckPlacePermission ...), and without knowing what the indexes are.</p>\n\n<p>Things that i have noticed:</p>\n\n<ol>\n<li><p>In the first block, ... | {
"AcceptedAnswerId": null,
"CommentCount": "8",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-27T05:48:56.737",
"Id": "45466",
"Score": "0",
"Tags": [
"performance",
"sql",
"sql-server",
"stored-procedure"
],
"Title": "A search for reviews of places"
} | 45466 |
<p>Recently I worked on one of the Codility Training - Genomic Range Query (please refer to one of the evaluation report for the detail of <a href="https://codility.com/demo/results/demoYC9TD5-324/" rel="nofollow">this training</a>).</p>
<p>The proper approach for this question is using prefix sum. Here is the impleme... | [] | [
{
"body": "<p><code>strlen</code> takes a linear time in the length of the string. Thus, <code>for(i = 0 ; i < strlen(S) ; i++)</code> will call it <code>n</code> times and the result will be quadratic.</p>\n\n<p>Changing this and a few other details (moving stuff to the smallest possible scope) and you get ... | {
"AcceptedAnswerId": "45473",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-27T06:55:47.577",
"Id": "45467",
"Score": "6",
"Tags": [
"c",
"complexity",
"programming-challenge",
"bioinformatics"
],
"Title": "Genomic Range Query"
} | 45467 |
<p>I start with an array containing some 'ids' and some 'values'.</p>
<p>What I need is to organize the 'ids' in a new array to be, if possible, apart when the 'values' they are associated with are alike.</p>
<p>So I came up with a solution. If there is too much of a value type, the spreading is uneven. So if one o... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-27T08:18:44.263",
"Id": "79313",
"Score": "2",
"body": "I think what you're trying to say is, you want the output to be such that no two consecutive entries are identical?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDa... | [
{
"body": "<p>Maybe this answer is a bit late, but hopefully someone can benefit from it!</p>\n\n<p>First off, very interesting concept... It was a challenge to try and figure this one out! I have come up with another implementation, whether it's truly better or not is for the author to decide. Here it is:</p>\... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-27T07:59:25.330",
"Id": "45471",
"Score": "8",
"Tags": [
"php",
"array",
"sorting"
],
"Title": "Sorting a PHP array in a discontinuous manner"
} | 45471 |
<p>I'm currently having this code & looking for a simpler and shorter way of showing, hiding & disabling my elements...</p>
<pre><code>$("#chReportData").click(function(){
if($(this)[0].checked){
$("#reportDataOptions").show();
} else {
$("#ReportDataStat... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-27T11:20:49.853",
"Id": "79338",
"Score": "0",
"body": "can you share you html?"
}
] | [
{
"body": "<p><strong>Edit: now that you have shared your html I could make a better response ... <a href=\"http://jsfiddle.net/EjBW7/2/\" rel=\"nofollow\">http://jsfiddle.net/EjBW7/2/</a></strong></p>\n\n<p>There is a lot of repeated code, you could write some functions to avoid repeating the code, the bra... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-27T10:12:37.690",
"Id": "45475",
"Score": "4",
"Tags": [
"javascript",
"jquery",
"html"
],
"Title": "Simpler way of showing, hiding & disabling elements"
} | 45475 |
<p>Since my project is getting bigger every day and I am just a starter in the wonderful world of makefiles, I need some help improving mine because, although it works (almost) as I wish, it really started looking like a mess. So it would be nice if someone could help me with it (and of course, advice is welcome).</p>
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-27T10:50:44.517",
"Id": "79332",
"Score": "2",
"body": "If it is not for training purposes I would advice you to use a Makefile generator like autotools, cmake, ..."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2... | [
{
"body": "<p>You have many more <code>.PHONY</code> targets than just <code>clean</code>: <code>all</code>, <code>check</code>, <code>debug</code>, <code>testbenches</code>, <code>run_test_script</code>, <code>createdir</code>, <code>maincpp</code>.</p>\n\n<p>The <code>maincpp</code> rule should be:</p>\n\n<pr... | {
"AcceptedAnswerId": "45486",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-27T10:39:57.063",
"Id": "45478",
"Score": "3",
"Tags": [
"c++",
"optimization",
"makefile",
"make"
],
"Title": "Optimize a Makefile"
} | 45478 |
<p>I currenctly have a class which does several requests to a database with several methods (called from main method) sharing this pattern :</p>
<pre><code>public int getSomething(String id, File file) {
Connection conn = null;
PreparedStatement ps = null;
ResultSet rs = null;
int lines = 0;
try {... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-27T11:49:20.683",
"Id": "79343",
"Score": "2",
"body": "ASIK, create one connection and open it when needed and close it once your DB operations are completed. **There is no need to create new one**."
}
] | [
{
"body": "<p>I have to agree with Praveen's comment that you should open a connection when you need it and close it when your are done with the Database operations.</p>\n\n<p>But first I have to make a <strong>serious objection</strong> to this statement:</p>\n\n<pre><code>ps = conn.prepareStatement(SQL_QUERY.... | {
"AcceptedAnswerId": "45489",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-27T10:46:32.880",
"Id": "45479",
"Score": "5",
"Tags": [
"java",
"jdbc"
],
"Title": "Connection to a database, do I need to create a new one and close it everytime?"
} | 45479 |
<p>I'm sharing C# code with a fellow programmer who is more use to writing C++. He uses <code>#if</code> and <code>#endif</code> directives (which I do not tend to use) and when they occur they have no indentation, for example </p>
<pre><code> private void dumpToDisplay()
{
#if false
ushort[... | [] | [
{
"body": "<blockquote>\n <p>Is indentation of #if & #endif directives an important readability convention?</p>\n</blockquote>\n\n<p>I think you mean outdentation (i.e. the <code>#if</code> is at the start of the line).</p>\n\n<p>I'd say 'yes' because:</p>\n\n<ul>\n<li>It's conventional</li>\n<li>Unlike <c... | {
"AcceptedAnswerId": "45487",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-27T11:29:30.943",
"Id": "45482",
"Score": "12",
"Tags": [
"c#"
],
"Title": "Is indentation of #if & #endif directives an important readability convention?"
} | 45482 |
<p>I have been trying various formats of namespaces and modules patterns, however I have not come across a solution that I would use for all my projects.</p>
<p>I've been developing the following, that would allow me to separate my application through applications, modules, functions and global variables. Possibly I'm... | [] | [
{
"body": "<p>I don't like this approach.</p>\n\n<p>The biggest issue I have with this code is the fact that namespaces are attached to every lookup. Beyond being a bit long and awkward, it's hard to see the difference between two very similar looking symbol names when they start in exactly the same fashion. Th... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-27T11:31:03.617",
"Id": "45483",
"Score": "10",
"Tags": [
"javascript",
"design-patterns",
"namespaces"
],
"Title": "JavaScript Good Patterns - Is this a good example?"
} | 45483 |
<p>Here's the first functional version of my Python 2 script for processing comments in C++ source files. It's a personal project, I expect to expand it later with more advanced options (mainly about replacing comments with whitespace or marking their original positions in the comment-only output).</p>
<p>It's also in... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-27T14:00:56.360",
"Id": "79365",
"Score": "0",
"body": "Did you take '\\' and `//?` into account? :)"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-27T14:02:05.317",
"Id": "79366",
"Score": "0",
... | [
{
"body": "<p>A few brief comments from an initial read through:</p>\n\n<ul>\n<li><p>A lot of your method names are mixed case, but the Python convention is lowercase with underscores. The Python style guide is <a href=\"http://legacy.python.org/dev/peps/pep-0008/\" rel=\"nofollow\">PEP 8</a>:</p>\n\n<blockquot... | {
"AcceptedAnswerId": "45494",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-27T11:34:52.753",
"Id": "45484",
"Score": "12",
"Tags": [
"python",
"parsing"
],
"Title": "Processing C++ comments"
} | 45484 |
<blockquote>
<p>You are given a polynomial of degree n. The polynomial is of the form</p>
<blockquote>
<p>P(x) = a<sub>n</sub> · x<sup>n</sup> + a<sub>n-1</sub> · x<sup>n-1</sup> + … + a<sub>0</sub></p>
</blockquote>
<p>where the <em>a<sub>i</sub></em>‘s are the coefficients. Given an integer
<em>x<... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-27T18:11:18.860",
"Id": "79421",
"Score": "5",
"body": "Do you know about [Horner's method](http://en.wikipedia.org/wiki/Horner%27s_method)?"
}
] | [
{
"body": "<ol>\n<li><p>Recommend a uniform and more indented style. E.g.</p>\n\n<pre><code>for(i=0;i<n;i++)\n{\n sum+=power(x,n-i)*a[i];\n}\n</code></pre></li>\n<li><p>Both <code>a[11]</code> and <code>if(... n>10)</code> rely on the same value. Also to avoid undocumented magic numbers, consider the... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-27T12:13:46.277",
"Id": "45488",
"Score": "6",
"Tags": [
"c",
"mathematics"
],
"Title": "Evaluating a polynomial"
} | 45488 |
<p>I'm the maintainer of the following library on github: <a href="https://github.com/edi9999/docxtemplater/blob/master/coffee/docxgen.coffee" rel="nofollow">https://github.com/edi9999/docxtemplater/blob/master/coffee/docxgen.coffee</a></p>
<p>I want to maintain a library that works on node and in the browser, however... | [] | [
{
"body": "<p>Yeah..</p>\n\n<p>Are you against maintaining 2 repositories or maintaining 2 main files? Honestly I would have 2 main files with a third file ( or more ) containing routines that are host agnostic.</p>\n\n<p><code>docxgen_node.coffee</code> , <code>docxgen_www.coffee</code> and <code>docxgen_commo... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-27T12:44:22.463",
"Id": "45491",
"Score": "1",
"Tags": [
"node.js",
"coffeescript"
],
"Title": "Remove nodejs/browser specific code in library"
} | 45491 |
<p>I have always suffered with too many conditionals in some of my methods. The following is a pseudocode/skeleton of one of my method like that:</p>
<pre><code>private List<ReturnType> DoSth(string name = null)
{
List<ReturnType> names = new List<ReturnType>();
for (int i = 0; i < somear... | [] | [
{
"body": "<p>You could just combine the logic into one statement, assuming there is not other things occurring during your if-else blocks and stuff.\nIf there is, then this won't necessarily work for you, and you should post the real code, because a lot of times these problems are subjective to the code. </p>\... | {
"AcceptedAnswerId": "45493",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-27T12:54:47.303",
"Id": "45492",
"Score": "7",
"Tags": [
"c#",
"asp.net-mvc"
],
"Title": "Refactoring Methods With Conditionals"
} | 45492 |
<p>I've got a Python script which is meant to launch several other shell scripts with the appropriate setup and parameters. I construct the file paths from other variables so that it's easier to change one setting and have it apply everywhere, rather than hardcoding everything.</p>
<p>So, for example:</p>
<pre><code... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-27T13:54:04.060",
"Id": "79362",
"Score": "4",
"body": "Probably not worth an answer but maybe you should use http://docs.python.org/3/library/os.path.html#os.path.join"
}
] | [
{
"body": "<p>You could make a module with two global variables and a class\nthe globals starting as:</p>\n\n<pre><code>HOME_DIRECTORY = None\nEXTENSIONS = dict(\n SHELL_SCRIPT = '.ksh',\n CONFIG_FILE = '.conf',\n STORE_FILE = '.someextension'\n)\n</code></pre>\n\n<p>And a class that has one static met... | {
"AcceptedAnswerId": "45512",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-27T13:32:01.853",
"Id": "45495",
"Score": "7",
"Tags": [
"python",
"python-3.x",
"constants"
],
"Title": "Dynamically generating Strings (or other variables)"
} | 45495 |
<p>I was asked the following interview question over the phone:</p>
<blockquote>
<p>Given an array of integers, produce an array whose values are the
product of every other integer excluding the current index.</p>
<p>Example: </p>
<pre><code>[4, 3, 2, 8] -> [3*2*8, 4*2*8, 4*3*8, 4*3*2] -> [48, 64, 96, ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-27T16:33:26.080",
"Id": "79406",
"Score": "0",
"body": "Thanks everyone for your feedback. I will take all this into account the next time I write any code."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-2... | [
{
"body": "<p>Honestly..... that looks good.</p>\n\n<p>it is pretty much what I would have done. It is <em>O(n)</em> which is smarter than the naive <em>O(n<sup>2</sup>)</em> solution of nested loops, it manages overflow well with the BigInteger... it is good.</p>\n\n<p>The only concern is that the interviewer ... | {
"AcceptedAnswerId": "45522",
"CommentCount": "9",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-27T13:58:45.157",
"Id": "45498",
"Score": "24",
"Tags": [
"java",
"array",
"interview-questions"
],
"Title": "Array whose values are the product of every other integer"
} | 45498 |
<p>I made this bit of code that uses jQuery in a simple HTML file to see if my son would think it is fun/interesting and to help me with my jQuery skills. The thing that was hard was the selectors towards the bottom of the script block. I am wondering if there is a better way to do this. Warning: it auto-refreshes to... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-27T16:14:11.077",
"Id": "79403",
"Score": "0",
"body": "What your code is suppose to do ? Could you make a jsfiddle and link to it ?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-27T16:19:54.613",
"Id... | [
{
"body": "<p>To make them square: </p>\n\n<pre><code>var size = Math.max(window.innerWidth,window.innerHeight)/200;\nvar xbound = Math.floor(window.innerWidth/size);\nvar ybound = Math.floor(window.innerHeight/size);\n</code></pre>\n\n<p>Simply use <code>xbound</code> and <code>ybound</code> as the upper limi... | {
"AcceptedAnswerId": "45572",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-27T15:40:50.990",
"Id": "45518",
"Score": "7",
"Tags": [
"javascript",
"jquery",
"html"
],
"Title": "Father-son project: Drawing on a grid"
} | 45518 |
<p>So I am trying to make a Object oriented Node.js class for store information about riddles.
Please feel free to be harsh as possible. Would love to hear your ideas about how to make this class better!</p>
<pre><code>function RiddleInfo(riddle, answer, hint1, hint2, hint3, ohFactor, difficulty) {
this.riddle = r... | [] | [
{
"body": "<p>From the outset, I'm not sure how useful/necessary this constructor (\"class\") is, to be honest. Everything could seemingly be stored in a simple object literal:</p>\n\n<pre><code>var aRiddle = {\n riddle: \"What gets wetter and wetter the more it dries?\",\n answer: \"A towel\",\n difficulty:... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-27T15:48:19.663",
"Id": "45519",
"Score": "1",
"Tags": [
"javascript",
"object-oriented",
"node.js"
],
"Title": "object oriented Node.js class RiddleInfo.js"
} | 45519 |
<p>I was unable to find how to get current URL so here's what I've made. Brief tests didn't reveal anything bad. Your thoughts, educated opinions, suggestions, and comment on potential bugs or improvements is highly appreciated! </p>
<p>Especially take a look at <code>$_SERVER['HTTPS']</code> marked with <code>// ???... | [] | [
{
"body": "<p>I think this might not be a coincidence:</p>\n\n<blockquote>\n <p>I was unable to find how to get current url so here's what I've made. </p>\n</blockquote>\n\n<p>The webserver could be behind an SSL endpoint or a load balancer, so <code>$_SERVER</code> values might be modified during the request.... | {
"AcceptedAnswerId": "45525",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-27T15:52:06.030",
"Id": "45520",
"Score": "3",
"Tags": [
"php",
"php5",
"url",
"https"
],
"Title": "Return current URL"
} | 45520 |
<p>I've overridden Backbone.Collection.add for my Collection to ensure that the Collection never has two PlaylistItems who share a Song ID. My implementation seems incredibly verbose and I was curious if there's a better way to express my desires:</p>
<pre><code>var PlaylistItems = MultiSelectCollection.extend(_.exten... | [] | [
{
"body": "<p>I've been looking at this since a while, it seems mostly verbose because you want to handle Backbone collections, and arrays, and single songs..</p>\n\n<p>It seems simpler to normalize in all 3 scenario's <code>items</code> to something that you then process once. I am not 100% this works, but you... | {
"AcceptedAnswerId": "47283",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-27T16:01:45.147",
"Id": "45523",
"Score": "2",
"Tags": [
"javascript",
"backbone.js"
],
"Title": "Overriding Backbone.Collection.add to enforce uniqueness on non-id property"
} | 45523 |
<p><strong>Background</strong>: I'm designing a system (VB/WinForms) that uses a database(MS SQL Server 2008 R2) to track people, their stock account #'s, which stocks they are investing in, and the payout of those stocks. </p>
<p>Basically, just reading/writing to the database and some time-elapsed functionality. (On... | [] | [
{
"body": "<p>If you want to learn how to use classes, the best approach is to use them while building a small program. I suggest you do create a Person class and that you stop using dataset. This will be a great learnign experience.</p>\n\n<p>Using numbers instead of const or strings can create a mantenance pr... | {
"AcceptedAnswerId": "46558",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-27T17:02:32.760",
"Id": "45527",
"Score": "4",
"Tags": [
"object-oriented",
"vb.net"
],
"Title": "System for tracking stock information"
} | 45527 |
<p>I have the following 3 different versions of code.
Version 1 is overly verbose and contains redundancy but on the other hand seems easier to read. Version 2 is somewhere in the middle, and Version 3 is shortened and straight to the point.</p>
<p>Their all equivalent in terms of functionality. I am not sure about re... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-27T18:58:53.617",
"Id": "79427",
"Score": "3",
"body": "Asking which version is better is not a good question as it is asking directly for opinion. You could choose one and see the review of it."
},
{
"ContentLicense": "CC BY-S... | [
{
"body": "<blockquote>\n <p>Version 1 is overly verbose and contains redundancy but on the other hand seems easier to read.</p>\n</blockquote>\n\n<p>I'd go with the first one with some modifications. The second one need horizontal scrolling which is hard to read. The third one was made for a computer, for hum... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-27T18:56:14.087",
"Id": "45534",
"Score": "1",
"Tags": [
"java"
],
"Title": "Coding standard and Readability: Verbose/Redundant statements vs Short/Compressed"
} | 45534 |
<p>Now that we have the nice new <code>foreach</code> loop in Java, the old-style loop looks ugly be comparison.</p>
<p>I like the way Python has a <code>range()</code> generator that allows the foreach construct to iterate over a range of integers.</p>
<p>I have written a <code>Range</code> class which allows this. ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-27T21:08:32.460",
"Id": "79450",
"Score": "4",
"body": "While it is tempting to edit and improve your question, it also makes the existing answers look wrong - it invalidates them. [There is a meta post about this here...](http://meta.... | [
{
"body": "<p>For the most part, this appears to be neat, and well structured.</p>\n\n<p>There is a significant bug, though:</p>\n\n<ul>\n<li><code>Iterable<Integer></code> implies an <code>iterator()</code> method. Each time you call that <code>iterator()</code> method you should get a new instance of an... | {
"AcceptedAnswerId": "45553",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-27T19:11:41.590",
"Id": "45535",
"Score": "10",
"Tags": [
"java",
"unit-testing",
"iterator",
"interval"
],
"Title": "Using a Pythonesque range() generator function with the J... | 45535 |
<p>I'm an experienced programmer but not too great at JavaScript so I'm looking to see if I'm doing this 'right'. I want to have several files loaded in (Ajax or really AJAJ) and, once loaded, run some final code. My basic idea is:</p>
<pre><code>var jobsToDo = 2; // global
function getAsync(url, func) {
var clie... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-27T20:19:55.103",
"Id": "79445",
"Score": "0",
"body": "Why you don't do jobsToDo++; inside getAsync() ?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-27T20:47:29.713",
"Id": "79448",
"Score": "0"... | [
{
"body": "<p>1) Nah, the kids still call it JavaScript, but ECMAScript works too. More power to you for knowing both names :)</p>\n\n<p>2) Yes, I'd say you should wait for a less ambiguous state to occur before considering the request done. But there's not really anything better than <code>onreadystatechange</... | {
"AcceptedAnswerId": "45544",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-27T19:44:35.113",
"Id": "45541",
"Score": "8",
"Tags": [
"javascript",
"asynchronous",
"concurrency"
],
"Title": "Wait until all files are loaded asynchronously, then run code"
} | 45541 |
<p>I would like advice if this is a good implementation of an application for maintaining information about people (first name, last name, and age).</p>
<p>The index.html contains an empty div and 2 templates (1 for listing people and the other for entering/editing a user):</p>
<pre><code><div id="app">
</di... | [] | [
{
"body": "<p>All in all, this looks okay to me, proper naming, nothing bizarre, ( no commenting ).</p>\n\n<p>The only thing that bothers me is that you call <code>.setId(id);</code> on the <code>editView</code>.</p>\n\n<p><code>editView</code> should have a data model with 1 person, and the <code>.setId()</cod... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-27T21:19:29.973",
"Id": "45546",
"Score": "6",
"Tags": [
"javascript",
"backbone.js"
],
"Title": "Maintaining information about people"
} | 45546 |
<p>From a <a href="https://codereview.stackexchange.com/q/45310/507">previous question</a> I got <a href="https://codereview.stackexchange.com/a/45334/507">an answer</a> that included some template magic (that to be blunt was mind-boggling (as I could not understand it)).</p>
<p>So I have been trying to achieve the sa... | [] | [
{
"body": "<p>Generally speaking, it's good and works great (version 2 seems better). There are some things that could be changed/added though:</p>\n\n<ul>\n<li><p>In C++, ranges tend to be <code>[begin, end)</code> ranges. Your compile-time integer ranges are actually <code>[begin, end]</code> ranges. The last... | {
"AcceptedAnswerId": "45595",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-27T21:45:02.523",
"Id": "45549",
"Score": "9",
"Tags": [
"c++",
"c++11",
"template",
"template-meta-programming",
"interval"
],
"Title": "C++ template range"
} | 45549 |
<p>My code calculates primes from one to n. I have verified that the code always produces all the primes in that range correctly.</p>
<p>Are there any optimizations that I can make? Are there any bad programming practices besides variable names (e.g. l is close to 1)? Any better normal Windows API? I am using the Siev... | [] | [
{
"body": "<p>The algorithm looks good overall. Here are a few comments :</p>\n\n<hr>\n\n<p><code>using namespace std;</code> is <a href=\"https://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-bad-practice\">sometimes frowned upon</a> : some might say that putting it in a cpp file (b... | {
"AcceptedAnswerId": "45555",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-27T22:18:14.313",
"Id": "45550",
"Score": "8",
"Tags": [
"c++",
"primes"
],
"Title": "Prime generator from one to n"
} | 45550 |
<p>I am just starting to get my feet wet with C; and am rather enjoying myself in doing so. This is sort of a follow up to my last question <a href="https://codereview.stackexchange.com/questions/45284/enumerating-a-boolean-in-c">here</a>. I am posting this ordinate to hopefully getting some feedback on the logic itsel... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-28T06:28:08.840",
"Id": "79528",
"Score": "8",
"body": "If you want bools, consider using the real `bool` datatype. `#include <stdbool.h>`"
}
] | [
{
"body": "<p>Drop the <code>inline</code> and <code>register</code> keywords. The compiler will decide what to do better than you can, despite your personal preference for complete mastery over the machine.</p>\n\n<p>Keep in mind that the default compiler optimization setting is set at <code>-O0</code>. For t... | {
"AcceptedAnswerId": "45610",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-27T22:35:17.420",
"Id": "45551",
"Score": "22",
"Tags": [
"c",
"beginner",
"bitwise"
],
"Title": "Setting and getting bits in C"
} | 45551 |
<p>Using LaTeX creates a bunch of auxiliary files like <code>foo.aux</code>, <code>foo.log</code>, etc. Sometimes, I want to create a clean run of my document. I usually manually execute this in the terminal as</p>
<pre><code>$ ls foo*
foo.tex
foo.aux
foo.log
foo.bbl
foo-blx.bib
$ rm foo{.aux,.log,.bbl,-blx.bib}
</cod... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-27T23:22:46.237",
"Id": "79480",
"Score": "0",
"body": "Which `basename` are you using? I am not familiar with (and can't find) the `-s` option for it."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-27T23:... | [
{
"body": "<p>Mostly minor things:</p>\n\n<ul>\n<li><code>[ -n \"$1\" ]</code> is equivalent to <code>[ \"$1\" ]</code>. I'd go for the shorter one</li>\n<li>Since you are in <code>bash</code>, you can use a variable substitution <code>${1%.tex}</code> instead of <code>basename</code>, which is slightly better<... | {
"AcceptedAnswerId": "45561",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-27T23:05:23.873",
"Id": "45556",
"Score": "11",
"Tags": [
"bash",
"cli"
],
"Title": "Bash script to clear files not matching a given extension"
} | 45556 |
<p>This is my very first program that using threads. I use C++11 standard threads and I run it on Linux.</p>
<p>The program creates two threads that sums all the elements in a vector together. The first created thread sums the left half of the vector and the other thread sums the right part of the vector.</p>
<p>The ... | [] | [
{
"body": "<p>Firstly, it's a good first attempt at writing some threaded code. The major sticking point is that you're passing in an <code>int &</code> and returning <code>void</code>. Of course, <code>std::thread</code> will just run some code and won't return you a result. However, within the C++11 threa... | {
"AcceptedAnswerId": "45569",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-27T23:23:22.007",
"Id": "45557",
"Score": "16",
"Tags": [
"c++",
"c++11",
"multithreading"
],
"Title": "Summing values in a vector using threads"
} | 45557 |
<p>I would like the program to ask the user if they want to add a color. If they say yes, then ask what color to add. Then after that happens, once the program would ask if you want to, run it again. If they say no to add a color, the program ask if you want to remove a color from the list. If they say yes, it would t... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-29T18:31:47.033",
"Id": "79791",
"Score": "1",
"body": "This post is now unlocked but is being monitored by moderators. Please do not make edits that invalidate current answers. See [this meta post for instructions on how to edit your ... | [
{
"body": "<blockquote>\n<pre><code>import socket # imports the socket module \n</code></pre>\n</blockquote>\n\n<p>The comment is completely pointless. But I cannot help it, my eyes naturally read it, my brain processes it, only to realize it says nothing new. Let your code speak for itself, avoid comments as m... | {
"AcceptedAnswerId": "45565",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-27T23:58:41.910",
"Id": "45562",
"Score": "4",
"Tags": [
"python",
"homework"
],
"Title": "Adding/Removing Colors to Lists"
} | 45562 |
<p>Grab the input file, and output the second to last word on every line.</p>
<p>Can I make it shorter and/or more efficient?
I'm surprised by the performance. While the runtime, +2s, is likely dominated by start up, it also requires +40M. </p>
<pre><code>(use 'clojure.java.io)
(use '[clojure.string :only (join split... | [] | [
{
"body": "<p>Are you using Lein to run? Or straight Java? Either way, I think the memory use is normal even for a hello world program. </p>\n\n<p>Following are some naive timings (I didn't run them many times). Here is my baseline hello world (uses about 30M). My computer is quite slow btw :):</p>\n\n<blockquo... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-28T00:52:17.517",
"Id": "45567",
"Score": "5",
"Tags": [
"clojure"
],
"Title": "Second to last word"
} | 45567 |
<p>For the past week I have been studying and improving a ray tracer that I ported from JavaScript. The bare finished port was only exactly what was written in JavaScript and rendered at around 20fps at 100x100 resolution with a scene of just one plane and two spheres, over the week I have implemented very simple frust... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-28T09:46:23.813",
"Id": "84686",
"Score": "0",
"body": "Try to follow some style guides like [Google Java style guide](http://google-styleguide.googlecode.com/svn/trunk/javaguide.html), it will make your code more readable and will gui... | [
{
"body": "<p><strong>Let your code breathe</strong><br>\nYour code is very hard to read - lines are long and crowded together, containing multiple method nesting (<code>direction.subtract(Vector.multiply(2, Vector.multiply(Vector.dot(normal,...</code>). </p>\n\n<p>Reading code is like reading a book. If you d... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-28T01:22:59.050",
"Id": "45573",
"Score": "6",
"Tags": [
"java",
"performance",
"recursion",
"graphics",
"raytracing"
],
"Title": "Ray Tracer main loop"
} | 45573 |
<p>I have a class called <code>Mailer</code> which has some properties like this </p>
<pre><code>public static string Cname
{
get
{
return HttpUtility.HtmlDecode(HttpContext.Current.Server.UrlDecode(HttpContext.Current.Request["cname"]));
}
set
{
HttpUtility.HtmlDecode(HttpContext.Current.Se... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-28T07:29:58.953",
"Id": "79532",
"Score": "0",
"body": "Perhaps you could show more of the code like where you are using this and other surrounding code modules???"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "20... | [
{
"body": "<p><strong>Accessors in C#</strong><br>\nYou should read on <a href=\"http://msdn.microsoft.com/en-us/library/aa287786%28v=vs.71%29.aspx\">accessors in C#</a> - your setter does not do what it should - it should <em>set</em> the value if <code>Cname</code>. If this has no meaning (you can't change th... | {
"AcceptedAnswerId": "45587",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-28T05:43:45.990",
"Id": "45577",
"Score": "3",
"Tags": [
"c#",
"asp.net",
"inheritance"
],
"Title": "Using properties efficiently in inheritance"
} | 45577 |
<p>I wrote a utility method to override <code>equals()</code> using reflection. This works fine, but I wonder if this code will pass all the tests.</p>
<pre><code>public static boolean checkObjectsEqualityFromInstance(Object currentObj,Object otherObj) throws Exception{
if(currentObj==null || otherObj==null){
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-28T09:57:21.523",
"Id": "79546",
"Score": "1",
"body": "This code doesn't deal properly with fields that are arrays of primitives."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-28T10:33:06.377",
"Id":... | [
{
"body": "<ol>\n<li><p>You should check if the references are equal first to save a whole lot of comparing when there is no need to.</p></li>\n<li><p>If both objects are <code>null</code> your method will return false which is probably unexpected.</p></li>\n<li><p>You call <code>getClass()</code> several times... | {
"AcceptedAnswerId": "45584",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-28T06:17:42.030",
"Id": "45579",
"Score": "10",
"Tags": [
"java",
"reflection",
"hashcode"
],
"Title": "Override equals() and hashCode() using reflection"
} | 45579 |
<p>I've noticed I've got quite a few repeated lines in my code.</p>
<pre><code>$start = mktime(0, 0, 0, 3, 1, 2014);
$rate = 1 / 30;
$amount = number_format(floor((time() - $start) * $rate));
$id = array(
array("42706686", "rebel2america"),
array("100004055720670", "marquez.candace"),
array("1000007564924... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-28T06:35:20.287",
"Id": "79530",
"Score": "0",
"body": "you are effectively writting a lot of loops complex - - can you please put it the input ouput of your algorithm so that we can see if we can shorten the code by known what to expe... | [
{
"body": "<p>This part is duplicated:</p>\n\n<blockquote>\n<pre><code>$orderBy = array_map(function() {\n return mt_rand();\n}, range(1, count($id)));\narray_multisort($orderBy, $id);\n</code></pre>\n</blockquote>\n\n<p>You apply the same logic to <code>$id</code>, <code>$status</code>, <code>$online</code>... | {
"AcceptedAnswerId": "45582",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-28T06:29:41.253",
"Id": "45581",
"Score": "2",
"Tags": [
"php",
"php5"
],
"Title": "Any simpler and more efficient way of writing this code?"
} | 45581 |
<p>I've got a piece of code that takes an element, checks where it is, and if it's beyond a set place in the viewport, make the opacity increase to 1. I've made the code so that it only runs the checks if they're needed, the problem is that the code looks atrocious, and I suspect there's a better way for me to be doing... | [] | [
{
"body": "<p>Gah! Thanks for coming here.</p>\n\n<p>Essentially, all your if-statements have the following structure:</p>\n\n<pre><code>if (scrolled > (($wheresThisAt)+(N * 20))){\n $('#salamander-(N + 1)').css('opacity', '1');\n</code></pre>\n\n<p>So we can comfortably roll that into a loop:</p>\n\n<pre... | {
"AcceptedAnswerId": "45598",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-28T11:10:30.350",
"Id": "45596",
"Score": "15",
"Tags": [
"javascript",
"optimization",
"jquery"
],
"Title": "Increasing opacity based on an element's location"
} | 45596 |
<p>What would be the best way to format this code? It looks a bit messy to me in regards to indentation etc.</p>
<pre><code> if (typeof _srwc != 'undefined') {
for (var i=0; i < _srwc.length; i++){
var currentArg = _srwc[i];;
if (typeof window[currentArg[0]] == 'function') {
... | [] | [
{
"body": "<p>How to format code is not really how CodeReview works ;)</p>\n\n<ul>\n<li>You are indenting with 2 and with 4 spaces, pick one, I advocate 2</li>\n<li>It is more common to compare <code>_srwc</code> to <code>undefined</code> itself</li>\n<li><code>_srwc</code> is an unfortunate name, it conveys no... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-28T12:33:49.617",
"Id": "45601",
"Score": "2",
"Tags": [
"javascript"
],
"Title": "How to format embedded if statements in JavaScript"
} | 45601 |
<p>Below I have two players that win or lose and their score fluctuates using the Elo function. I have adapted this code from something closer to my language which is ActionScript. I found <a href="http://jobemakar.wordpress.com/2007/05/18/why-the-elo-rating-system-rocks/" rel="nofollow noreferrer">the functions here</... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-28T13:32:17.240",
"Id": "45608",
"Score": "4",
"Tags": [
"algorithm",
"coldfusion",
"cfml"
],
"Title": "Calculating player ratings"
} | 45608 |
<p>I am not very familiar with JavaScript and I'am a little confused with the object oriented peculiarities of it. I am trying to create a Caesar shift using the concepts of objects, methods and properties in JavaScript. I am using an HTML form to take input from user and OnClick return the encoded cipher text to user.... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-28T14:11:45.923",
"Id": "79599",
"Score": "0",
"body": "Welcome! Does your code works ?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-28T14:28:23.280",
"Id": "79604",
"Score": "0",
"body": "Th... | [
{
"body": "<p>Your code is reviewable, even if it does not work, from a once over:</p>\n\n<ul>\n<li><p>Indent your code (!!), this is bad:</p>\n\n<pre><code>function Caesar(order){\nthis.order = order;\nthis.encode = encode;\nfunction encode(input){\nthis.output = '';\nfor (var i = 0; i < input.length; i++) ... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-28T14:08:15.900",
"Id": "45609",
"Score": "2",
"Tags": [
"javascript",
"beginner",
"html",
"caesar-cipher"
],
"Title": "Caesar cipher implementation"
} | 45609 |
<p>I have this old project I wrote years ago and it's all classes and methods all over the place. I am trying to learn/understand how I can apply a more OOP principle. It is very large and can't paste all the code here. Instead I will demonstrate what I have as a basic.</p>
<p>Checkup.cs </p>
<pre><code>public class ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-28T14:51:35.083",
"Id": "79613",
"Score": "1",
"body": "\"//Contains horrible methods to parse datatables, XML, but needed.\" You could also put up these methods for review ;) Wheter in a separate question or as additional code here is... | [
{
"body": "<p>Just a small observation:</p>\n\n<blockquote>\n<pre><code>public int ColourVisionType { get; set; }\npublic int OutcomeID { get; set; }\n</code></pre>\n</blockquote>\n\n<p>From the names of these properties, it looks like your code could benefit from a few <code>enum</code> types. An enum value is... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-28T14:10:34.813",
"Id": "45611",
"Score": "2",
"Tags": [
"c#",
"object-oriented",
"inheritance"
],
"Title": "Color vision checkup"
} | 45611 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.