body stringlengths 25 86.7k | comments list | answers list | meta_data dict | question_id stringlengths 1 6 |
|---|---|---|---|---|
<p>My User model has multiple roles (utilizing CanCan). Each role's dashboard view is different enough to warrant a partial for each role (admins get big-picture reports of users and app activity, students get big-picture overviews of grades, current courses, and lessons to be taken).</p>
<p>At first I had a case stat... | [] | [
{
"body": "<p>You can override <code>ActiveModel#to_partial_path</code> if you want - same as how you might override <code>to_param</code>. See <a href=\"http://api.rubyonrails.org/classes/ActiveModel/Conversion.html\" rel=\"nofollow\">the documentation</a> (and be sure to check <a href=\"https://github.com/rai... | {
"AcceptedAnswerId": "18629",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-14T19:48:35.223",
"Id": "18627",
"Score": "1",
"Tags": [
"ruby",
"ruby-on-rails"
],
"Title": "Rendering partials dynamically in Rails 3"
} | 18627 |
<p>I have two scripts written by my co-workers for auto-filling a form with information from the Facebook graph-api. I am trying to figure out which has been coded in a more efficient style?</p>
<p>This is the first one. <a href="http://jsfiddle.net/TcGGZ/30/" rel="nofollow">http://jsfiddle.net/TcGGZ/30/</a></p>
<pre... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-19T14:36:53.047",
"Id": "29976",
"Score": "0",
"body": "On the second one, I would consider to do it reversed: for each input, if `facebook_data[input.getAttribute('name')]` has anything, then fill in the input."
}
] | [
{
"body": "<p>The first one will be slow because of all the jQuery selection.</p>\n\n<p>The second one will be slow because of the two loops. It keeps looping over what was already found. BUT it is going to be faster than the first one.</p>\n\n<p>I made a basic jSPerf with a basic object: <a href=\"http://jsper... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-14T20:30:11.870",
"Id": "18631",
"Score": "2",
"Tags": [
"javascript",
"jquery",
"facebook"
],
"Title": "Javascript coding wager"
} | 18631 |
<blockquote>
<p>Given an array of words, print all anagrams together. For example, if
the given array is {“cat”, “dog”, “tac”, “god”, “act”}, then output
may be “cat tac act dog god”.</p>
</blockquote>
<p>My idea is to sort individual words firstly. And then sort the array of words.
In this way, the anagrams wil... | [] | [
{
"body": "<p>FiHopZz, your concept seems fine. A few comments:</p>\n\n<ul>\n<li><p>in general, don't typedef pointers. It is confusing.</p></li>\n<li><p>your functions are not const-correct. In other words they cast const values\nto non-const values. The compiler will warn you of this if you enable\nwarning... | {
"AcceptedAnswerId": "18641",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-15T01:57:23.680",
"Id": "18640",
"Score": "1",
"Tags": [
"c",
"algorithm",
"strings",
"interview-questions"
],
"Title": "Given a sequence of words, print all anagrams together... | 18640 |
<pre><code>start:
try
{
oleDbDataAdapter1.Fill(myDataTable);
}
catch (Exception ex) {
DialogResult res = MessageBox.Show("Can't load data:\n" + ex.Message, "Error",
MessageBoxButtons.RetryCancel, MessageBoxIcon.Error);
if (res == DialogResult.Retry)
{
goto start;
}
}
</code></pre>
<... | [] | [
{
"body": "<p>I'm personally not a fan of goto's and to be honest I don't even know if I've ever used on in c#. I tend to find they are a bit hard to follow as you have to jump around a bit too much and the natural flow of the code is potentially broken. </p>\n\n<p>Here's an idea for using a different approac... | {
"AcceptedAnswerId": "18647",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-15T06:04:38.557",
"Id": "18643",
"Score": "17",
"Tags": [
"c#",
"exception-handling"
],
"Title": "Is it ok to use goto in catch?"
} | 18643 |
<p>Here is a problem from the book <em>Programming Challenges</em> by Skiena and Revilla:</p>
<blockquote>
<p><strong>The Trip</strong></p>
<p>A number of students are members of a club that travels annually to
exotic locations. Their destinations in the past have included
Indianapolis, Phoenix, Nashville, ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-15T17:27:10.820",
"Id": "29723",
"Score": "0",
"body": "My C++ is very rusty, but I can suggest some possible test cases which might break it. What happens if one student doesn't have any expenses? More than one? What if one student ... | [
{
"body": "<p>Your algorithm seems to be correct though a bit overcomplicated.\nBut the code is not correct. consider:</p>\n\n<pre><code>9999.1\n9999.1\n9999.0\n9999.1\n\n$0.05\n</code></pre>\n\n<p>And the correct answer is $0.07</p>\n\n<p>This is due to lack of precision in float implementation. It does not me... | {
"AcceptedAnswerId": null,
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-15T09:05:35.973",
"Id": "18652",
"Score": "3",
"Tags": [
"c++",
"programming-challenge"
],
"Title": "\"The Trip\" challenge from Programming Challenges"
} | 18652 |
<p>I have a function in App Engine Java where I compare two patterns stored in an int array:</p>
<pre><code>public static int patternMatch(int [] pattern1, int [] pattern2, int range) {
int max = range * pattern1.length;
int match = (pattern1.length - pattern2.length) * range;
for(int i = 0; i < patt... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-15T19:05:27.360",
"Id": "29727",
"Score": "0",
"body": "Maybe the development server runs in client mode while the deployment runs in client mode. http://stackoverflow.com/questions/198577/real-differences-between-java-server-and-java-... | [
{
"body": "<p>It's hard to say anything without profiling <em>the whole</em> application. Two possible scenarios about this point:</p>\n\n<blockquote>\n <p>If I were to not have any logic in this code and directly return any integer, my overall code takes 100 ms to complete on an average.</p>\n</blockquote>\n\... | {
"AcceptedAnswerId": null,
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-15T09:06:26.807",
"Id": "18653",
"Score": "3",
"Tags": [
"java",
"performance",
"array",
"google-app-engine"
],
"Title": "Sum the difference of two arrays"
} | 18653 |
<p>I've created a create a console app that would:</p>
<ol>
<li>Call a method to check an email account (I've done this step)</li>
<li>Convert the attachment to pdf (I've done this step)</li>
<li>Then once the conversion is complete wait 30 seconds</li>
<li>Repeat the previous 3 steps continuously</li>
</ol>
<p>I've ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-15T16:50:51.000",
"Id": "29718",
"Score": "2",
"body": "Why are you calling `CG.Collect();`?"
}
] | [
{
"body": "<p>I would rather do smth. like that (I added CancellationToken in case you would want to be able to cancel email parsing while it's in progress):</p>\n\n<pre><code>private static TimeSpan timeToWait = TimeSpan.FromSeconds(30);\n\n//somewhere in your code:\n_cancellationTokenSource = new Cancellation... | {
"AcceptedAnswerId": "18662",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-15T09:23:25.333",
"Id": "18654",
"Score": "3",
"Tags": [
"c#",
"asynchronous"
],
"Title": "Polling a email using async / await"
} | 18654 |
<p>I have the following concise-ish (and working) approach to getting all the forward permutations of a list of string. So with the list: </p>
<blockquote>
<p>w = ["Vehicula", "Sem", "Risus", "Tortor"]</p>
</blockquote>
<p>the results should be:</p>
<blockquote>
<p>['Vehicula', 'Vehicula Sem', 'Vehicula Sem Risu... | [] | [
{
"body": "<p>This should work. I don't know if it is more readable than your approach though.</p>\n\n<pre><code>w = [\"Vehicula\", \"Sem\", \"Risus\", \"Tortor\"]\nresults = [' '.join(w[i:i+j+1]) for i in range(len(w)) for j in range(len(w)-i)]\n</code></pre>\n",
"comments": [],
"meta_data": {
"C... | {
"AcceptedAnswerId": "18659",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-15T12:50:35.500",
"Id": "18656",
"Score": "3",
"Tags": [
"python",
"algorithm",
"combinatorics"
],
"Title": "Getting all (forward) permutations of a list of strings"
} | 18656 |
<p>I have a <code>Customer</code> class:</p>
<pre><code>public class Customer
{
public Guid Id { get; set; }
// Some other properties...}
</code></pre>
<p>And three transactions classes that have a reference to <code>Customer</code>: </p>
<pre><code>public class Order
{
public Guid CustomerId { get; set;... | [] | [
{
"body": "<p>If they all implemented a common interface then you could simplify it.</p>\n\n<pre><code> public interface ICustomerItem\n {\n Guid CustomerId {get;}\n }\n</code></pre>\n\n<p>Concat the the items together</p>\n\n<pre><code>var items = invoices.Concat(payments).Concat(orders);\n</code... | {
"AcceptedAnswerId": "18678",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-15T13:03:51.857",
"Id": "18657",
"Score": "6",
"Tags": [
"c#",
"linq"
],
"Title": "Group collections by their elements property"
} | 18657 |
<p>I have a class that has a method which takes a user as an argument and performs several validation checks on the user and returns a boolean to indicate if theyare valid. </p>
<p>I want to be able to get error messages back from the validation method along with the boolean return value.</p>
<p>I was thinking of do... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-16T09:32:04.293",
"Id": "29786",
"Score": "0",
"body": "An `Appendable` or `CharSequence` parameter instead of a `StringBuffer` would be more flexible and allow e.g. `StringBuilder`s."
}
] | [
{
"body": "<p>I quite like the idea when implementing error handlers to do stuff through an interface to remove any dependencies on modules. Sometimes I've used that in conjunction with a global static Log method. I've typically done this in c# but the theory is the same across to Java I believe.</p>\n\n<p>So... | {
"AcceptedAnswerId": "18672",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-15T18:28:20.533",
"Id": "18671",
"Score": "3",
"Tags": [
"java"
],
"Title": "Is it good practice in Java to pass a StringBuffer to a method to get error messages"
} | 18671 |
<p>This program will filter the input by replacing matching bad words with "Bleep!". I'd like the code to be more concise and C++ style where possible. One thing that bugs me is the <code>was_bad</code> flag I think is needed to skip printing a word that has matched one of my bad words - if there was some better way to... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-16T00:08:15.090",
"Id": "62773",
"Score": "3",
"body": "so I *can't* say poop, but I *can* say POOP and pooop p00p I would recommend looking at c++11 regular expressions.\nhttp://www.cplusplus.com/reference/std/regex/"
}
] | [
{
"body": "<p>Instead of iterating over a vector I'd use <code>std::find()</code>.\nEven better, instead of <code>std::vector</code> I'd use <code>std::set</code>:</p>\n\n<pre><code>#include <iostream>\n#include <set>\n#include <string>\n\nusing namespace std;\n\nint main(int argc, const char ... | {
"AcceptedAnswerId": "18681",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-15T19:15:43.007",
"Id": "18673",
"Score": "5",
"Tags": [
"c++"
],
"Title": "Filtering out rude words"
} | 18673 |
<p>I am a self-taught programmer who has been programming for a long time, but mainly just for personal projects. I would like to improve my skills and am open to any suggestions that you may have, but am particularly interested in your thoughts about:</p>
<ul>
<li>The number of methods in this class: Too few/too ma... | [] | [
{
"body": "<p>I'm not that much experienced in iOS development, but I can give a great deal about code formatting. These are my suggestions, which are mostly my own opinion and in no way the only way of doing things.</p>\n\n<p>I'll start by saying that in your situation (working on your own), formatting your co... | {
"AcceptedAnswerId": "18712",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-15T20:36:31.133",
"Id": "18676",
"Score": "10",
"Tags": [
"objective-c",
"ios"
],
"Title": "Custom numberpad on an iPad"
} | 18676 |
<p>The following is my code for printing all the substrings of an input string. For example, with "abc", it would be "a","ab","abc","b","bc","c". Could someone please review it for efficiency (and possibly suggest alternatives)?</p>
<pre><code>void findAllSubstrings(const char *s){
int x=0;
while(*(s+x)){
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-16T08:31:02.947",
"Id": "29777",
"Score": "0",
"body": "one problem with this code is you have the for loop inside a while loop which is O(n^2)"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-16T08:35:22.13... | [
{
"body": "<p>Your problem is in O(n²), at least. This seems not to be optimizable. If you want only distinct substrings, then you will have to use a table of already encountered strings, which will make your code slower.</p>\n\n<p>However, you can switch the algorithm from recursive to iterative, which is usua... | {
"AcceptedAnswerId": "18715",
"CommentCount": "10",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-16T00:03:07.013",
"Id": "18684",
"Score": "8",
"Tags": [
"c++",
"algorithm"
],
"Title": "Find All Substrings Interview Query in C++"
} | 18684 |
<p>I use some basic cryptography in a project of mine. Because I want my application to run cross-platform and because it seems pretty sophisticated I decided to go with the Java Cryptography Architecture.</p>
<p>I'm pretty fresh with crypto in general, so I'd like to hear someone's opinion who has some experience wit... | [] | [
{
"body": "<p>The thing that jumps out at me is that you've got an issue with encoding strings. Use <code>getBytes(\"UTF8\")</code> instead of <code>getBytes()</code>. Why? Well, otherwise, the locale of the operating system can affect how a password gets hashed. </p>\n\n<p>I'm going to list possible issues now... | {
"AcceptedAnswerId": "18695",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-16T06:33:02.613",
"Id": "18694",
"Score": "2",
"Tags": [
"java",
"security",
"cryptography"
],
"Title": "Cipher and passphrase classes using Java cryptography"
} | 18694 |
<p>This function runs very often. <code>cudaMemcpy</code> is at the start and works very slowly. How can I change this function to avoid this? I already have <code>inputs</code> in device memory.</p>
<pre><code>void OpenNNL::calculateNeuronsOutputsAndDerivatives(double * inputs, double * deviceOutputs, double * devic... | [] | [
{
"body": "<p>Try to minimaze memory allocations.</p>\n\n<p>Allocate memory for <code>deviceTemp</code> and <code>deviceInputs</code> only once (in the constructor, for example):</p>\n\n<pre><code>cudaCall(cudaMalloc ( (void**)&deviceInputs, some_big_value * sizeof(double) ));\ncudaCall(cudaMalloc((void**)&... | {
"AcceptedAnswerId": "18699",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2012-11-16T09:31:48.347",
"Id": "18698",
"Score": "4",
"Tags": [
"c++",
"performance",
"memory-management",
"neural-network",
"cuda"
],
"Title": "Calculating neuron outputs and de... | 18698 |
<h2>Definition (Wikipedia):</h2>
<blockquote>
<p>E<strong>x</strong>tensible <strong>A</strong>pplication <strong>M</strong>arkup <strong>L</strong>anguage is a declarative XML-based language developed by Microsoft that is used for initializing structured values and objects.</p>
</blockquote>
<h2>Definition (MSDN):... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-16T13:32:22.857",
"Id": "18704",
"Score": "0",
"Tags": null,
"Title": null
} | 18704 |
Extensible Application Markup Language (XAML) is an XML language used for defining user interfaces in WPF and Silverlight. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-16T13:32:22.857",
"Id": "18705",
"Score": "0",
"Tags": null,
"Title": null
} | 18705 |
<p>I'm trying to write a portable CMake script for a simple Qt application. The target platforms are Win and Mac OSX. But as you can see, it's quite a monster already.</p>
<p>Are there any CMake profs? Can you see any essentially wrong approaches used in this script? I bet there are a few.</p>
<pre><code>CMAKE_MINIM... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-19T01:24:52.503",
"Id": "57896",
"Score": "0",
"body": "Would [Win x64] fall under the `Win32` branch?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-11-19T09:54:25.647",
"Id": "57921",
"Score": "0",
... | [
{
"body": "<p>My CMake-fu is a bit rusty - probably as old as this question -, but I still see some things that could be trivially improved:</p>\n\n<ul>\n<li><p>CMake doesn't require <code>else()</code> and <code>endif()</code> to contain the original <code>if()</code> expression anymore. It seems that this res... | {
"AcceptedAnswerId": "74202",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-16T14:40:28.503",
"Id": "18706",
"Score": "23",
"Tags": [
"c++",
"makefile",
"portability"
],
"Title": "Portable CMake script"
} | 18706 |
<p>I am using this query to generate a conversation stream between user 184 and 192- </p>
<pre><code>SELECT events.event_time, messages . *
FROM events , messages
WHERE events.global_id=messages.global_ref_id AND
(messages.to =184 AND messages.from =192) OR
events.global_id=messages.global_ref_id... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-14T09:37:13.650",
"Id": "29802",
"Score": "3",
"body": "Please try making your title more descriptive. As it stands, users have no idea what this question contains."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2... | [
{
"body": "<p>I would use a syntax like this:</p>\n\n<pre><code>SELECT events.event_time, messages .*\nFROM events , messages\nWHERE events.global_id=messages.global_ref_id \nAND ((messages.to = 184 AND messages.from = 192) OR (messages.to = 192 AND messages.from = 184))\nAND messages.global_ref_id < 495\... | {
"AcceptedAnswerId": "18710",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-14T09:35:42.060",
"Id": "18709",
"Score": "1",
"Tags": [
"php",
"mysql"
],
"Title": "How should I format my code to make it easier to read and understand in the future"
} | 18709 |
<p>CMake is a cross-platform, open-source build system. It generates native makefiles and project files that can be used from the command line or integrated development environment of your choice.</p>
<h2>Official</h2>
<ul>
<li><a href="http://www.cmake.org/" rel="nofollow">Homepage</a> </li>
<li><a href="http://www.... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-16T16:01:36.960",
"Id": "18713",
"Score": "0",
"Tags": null,
"Title": null
} | 18713 |
CMake is a cross-platform, open-source build system. It generates native makefiles and project files that can be used from the command line or integrated development environment of your choice.
| [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-16T16:01:36.960",
"Id": "18714",
"Score": "0",
"Tags": null,
"Title": null
} | 18714 |
<p>I've made a python script to properly organise D&D monster stats in a directory. The script brings up the stats as instance variables of a Monster (class) instance.</p>
<p>For those unfamiliar with the game, keeping track of monsters (to me at least) is cumbersome and prone to many dead trees. You have to flip ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-16T18:28:03.683",
"Id": "29812",
"Score": "0",
"body": "You may want to adopt a consistent code style: the obvious suggestion for this is [PEP8](http://www.python.org/dev/peps/pep-0008/). The [pep8 - Python style guide checker](http://... | [
{
"body": "<h3>1. Comments on your code</h3>\n\n<ol>\n<li><p>What you are doing here is <em>creating and querying a persistent database</em>, so it's a good idea to use an existing relational database rather than trying to implement your own in an ad-hoc fashion.</p>\n\n<p>In particular, with a relational datab... | {
"AcceptedAnswerId": "18848",
"CommentCount": "7",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-16T16:37:31.903",
"Id": "18717",
"Score": "10",
"Tags": [
"python",
"object-oriented"
],
"Title": "D&D Monster Organiser"
} | 18717 |
<p>I just started coding in Objective-C and would like to know if my simple implementation of a Stack is acceptable & what ways would you improve the Stack code, or the Main code? i'm curious of things such as (but not limited to):</p>
<ol>
<li>formatting</li>
<li>edge cases</li>
<li>run time (like one part where ... | [] | [
{
"body": "<pre><code>-(id)pop{\n id lastObj = [stack lastObject];\n [stack removeLastObject];\n return lastObj;\n}\n</code></pre>\n\n<p>Not sure if you are using ARC, but without ARC this is a potential use-after-free bug. If you are not using ARC you should consider:</p>\n\n<pre><code>-(id)pop{\n ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-16T19:51:45.883",
"Id": "18718",
"Score": "2",
"Tags": [
"objective-c",
"stack"
],
"Title": "Objective-C Stack implementation"
} | 18718 |
<p>I have a project for solving Diophantine equations, where a solution exists if</p>
<p>$$A^5 + B^5 + C^5 + D^5 + E^5 = F^5$$</p>
<p>where \$0 < A <= B <= C <= D <=E <= F <= N\$</p>
<p>The program will take an input N and first generate all values from 1 to \$N^5\$. Then it will get all possibl... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-17T00:09:17.743",
"Id": "29817",
"Score": "1",
"body": "As a general piece of advice, when you're stuck, use a profiler like `jvisualvm`."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-17T02:11:43.217",
... | [
{
"body": "<p>The most important point is the comment in the accepted answer in your related post in SO: You are not using that the lists are ordered. Instead of checking every value in <code>list1</code> and <code>list2</code> you could move along them at the same time.</p>\n\n<p>Rough idea:</p>\n\n<blockquote... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-17T00:08:28.847",
"Id": "18720",
"Score": "2",
"Tags": [
"java",
"algorithm",
"mathematics"
],
"Title": "Solving Diophantine equations"
} | 18720 |
<p>In <code>java.util.Random</code> the Oracle implementation of <code>nextInt(int)</code> is as follows:</p>
<pre><code>public int nextInt(int n) {
if (n <= 0)
throw new IllegalArgumentException("n must be positive");
if ((n & -n) == n) // i.e., n is a power of 2
return (int)((n * (lo... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-17T05:20:21.287",
"Id": "29846",
"Score": "0",
"body": "You can find some alternatives on SO."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-18T13:24:30.297",
"Id": "29900",
"Score": "0",
"body... | [
{
"body": "<p>You just need to test, It's that simple.<br>\nI've tested your code on C#, minus the <code>& 0x7FFFFFFFL; // make nextLong non-negative</code> </p>\n\n<p>(I didn't need that, C# rands are positive)</p>\n\n<p>The results look well distributed on [0,N-1].\nSo I think code is fine, except for the... | {
"AcceptedAnswerId": "18766",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-17T05:04:06.860",
"Id": "18727",
"Score": "4",
"Tags": [
"java",
"random"
],
"Title": "Extending java.util.Random.nextInt(int) into nextLong(long)"
} | 18727 |
<p>I would love to hear feedback on my <a href="https://github.com/eranation/mixpanel-java" rel="nofollow">first open source project</a> (a very simple async API for Mixpanel).</p>
<p>It implements a REST client for <a href="https://mixpanel.com/docs/api-documentation/http-specification-insert-data" rel="nofollow">thi... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-17T10:27:35.447",
"Id": "29854",
"Score": "3",
"body": "Just 2 comments: (1) You could put `if (ip == null || ip.length() == 0 || \"unknown\".equalsIgnoreCase(ip)) {return xxx;}` in its own method to avoid the code repetition in your `... | [
{
"body": "<ol>\n<li><p>I'd implement <code>Closeable</code>, <code>AutoCloseable</code>:</p>\n\n<pre><code>public class MixpanelAPI implements Closeable, AutoCloseable {\n ...\n}\n</code></pre>\n\n<p>See: <a href=\"https://stackoverflow.com/a/13141382/843804\">implements Closeable or implements AutoCloseabl... | {
"AcceptedAnswerId": "43842",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-17T07:52:55.743",
"Id": "18732",
"Score": "3",
"Tags": [
"java",
"multithreading",
"api",
"asynchronous"
],
"Title": "Very simple async MixpanelAPI"
} | 18732 |
<p>In C#, passing a parameter by reference can't be ignored:</p>
<pre><code>// C#
void foo(ref int p_value) ; // passing an int by reference
void bar()
{
int i = 0 ;
foo(ref i) ;
}
</code></pre>
<p>In C++ (and as far as I am concerned, it is a good thing), the passing by reference is only marked in the functio... | [] | [
{
"body": "<p>I can't see anything I would do majorly different.</p>\n\n<ul>\n<li>I would make the member <code>T & m_value</code> private. </li>\n<li>I would change the name of the method <code>byRef()</code> to just <code>ref()</code>\n<ul>\n<li>Note you still have a difference in identifiers.<br>\nThe c... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-17T11:42:28.907",
"Id": "18736",
"Score": "3",
"Tags": [
"c++"
],
"Title": "Explicitely passing a parameter by reference in C++03"
} | 18736 |
<p>I'm new to Zend Framework. Can you help me optimize this function, which gets a list of <code>Manufactures</code> with some conditions from a database?</p>
<pre><code>private function Manufactures(
$Condition = array(),
$Order = array('name' => 'ASC'),
$Strict = TRUE,
$Limit = NULL)
{
$Reques... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-17T12:38:34.397",
"Id": "18738",
"Score": "3",
"Tags": [
"php",
"performance",
"mysql",
"zend-framework"
],
"Title": "Getting a list of manufacturers from a database"
} | 18738 |
<p>I rarely write multithreaded code, and am on shaky ground when doing so. I make mistakes. I would like a sanity check of something I am going to introduce in one of my apps.</p>
<p>There will be exactly one running instance of the <code>Thread</code> class below in my application. (It will be stored in a servlet... | [] | [
{
"body": "<ol>\n<li><p>The <code>_boStop</code> and the <code>_boIsSleeping</code> fields are accessed by multiple threads, so you should synchronize them. You could use <code>volatile</code> fields or <code>AtomicBoolean</code>s too.</p>\n\n<p>Make sure that you do read operations in <code>synchronized</code... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-17T13:26:56.913",
"Id": "18740",
"Score": "5",
"Tags": [
"java",
"multithreading",
"thread-safety"
],
"Title": "Multithreading correctly done?"
} | 18740 |
<p>Is there a way to improve this SQL query? It involves multiple cross join and joins.</p>
<p>I have 3 tables, and I want to compute the cardinal product:</p>
<pre><code>table N:
N
-
4
table sums:
i S
-----------
1 22
2 26
3 22
table mults:
i j M
--------------... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-17T17:33:01.303",
"Id": "29865",
"Score": "0",
"body": "Does it have to be done in SQL? I would suck the data out and do it in memory instead. There are some powerful matrix and numeric libraries out there."
},
{
"ContentLicens... | [
{
"body": "<p>This SQL, for what it does, is neat, and concise. There is no obvious place where any optimizations can be made. With the data size as small as it is, there is no reason to recommend indexes, or other improvements.</p>\n\n<p>The only glaring issue has been pointed out already: There are tools othe... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-17T16:37:42.460",
"Id": "18742",
"Score": "5",
"Tags": [
"sql",
"join"
],
"Title": "SQL cross join and multiple joins"
} | 18742 |
<p>I'm doing <a href="http://projecteuler.net/problem=5" rel="nofollow noreferrer">Project Euler problem 5</a> as a kata, focussing on TDD and code readability. The challenge is:</p>
<blockquote>
<p>What is the smallest positive number that is evenly divisible by all of the numbers from 1 to 20?</p>
</blockquote>
<... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-17T22:45:14.377",
"Id": "29882",
"Score": "0",
"body": "In what world is a LINQ query more readable than a for loop?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-18T00:46:35.367",
"Id": "29890",
... | [
{
"body": "<p>How about breaking it across two functions:</p>\n\n<pre><code>private boolean IsDivisibleBy1to20(int solution)\n{\n for (int j = 1; j <= 20; j++)\n {\n if (solution % j != 0)\n return false;\n }\n return true;\n}\n\npublic int Solution_GotoVersion()\n{\n int sol... | {
"AcceptedAnswerId": "18763",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-17T16:39:32.137",
"Id": "18743",
"Score": "7",
"Tags": [
"c#",
"performance",
"linq",
"programming-challenge"
],
"Title": "Keeping Linq's readability (e.g. over goto statement... | 18743 |
<p>I've recently had to print some national symbols in windows console using <code>Mingw</code> and found, that I got nothing in the output, if I use wide strings.</p>
<p>So, I studied the problem and found out that it is locale problem. I was unable to find somewhere complete solution, so I had to write something, th... | [] | [
{
"body": "<p>This is a somewhat old question, but I have an alternative that may work for this. Related to <a href=\"https://stackoverflow.com/questions/26387054/how-can-i-use-stdimbue-to-set-the-locale-for-stdwcout\">this question</a>, if you turn off the synchronization with the underlying <code>stdio</code... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-17T18:38:22.110",
"Id": "18746",
"Score": "7",
"Tags": [
"c++",
"windows",
"io",
"i18n"
],
"Title": "Mingw, wcout and locales"
} | 18746 |
<p>I am writing a simple-ish c# CLI app to improve our telephony reporting system. </p>
<p>At present, I have a nightly DTS package which dumps a couple of tables from the Cisco telephony box into a database on our corporate cluster. An hour later, I have a SQL Server Agent job that runs a variety of messy stored proc... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-17T23:23:25.623",
"Id": "29886",
"Score": "1",
"body": "I've added the code from the URL. Don't want to seem as if I'm going off-topic :("
}
] | [
{
"body": "<p>Your task falls into ETL (Extract-Tranform-Load) category, and SQL Server Integration Services (SSIS) is the service dedicated to ETL. You can actually implement all the processing described here using the SSIS package (next version of DTS), at it might result in faster and more reliable solution ... | {
"AcceptedAnswerId": "18819",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-17T18:51:03.100",
"Id": "18748",
"Score": "1",
"Tags": [
"c#",
"sql",
"sql-server"
],
"Title": "How to dump UCCX stored procedure results via c# to SQL Server"
} | 18748 |
<p>The following is code from a university practical I am doing. It reads in a txt file of twenty clients, whose information is stored in the txt file like this:</p>
<pre><code>Sophia Candappa F 23 00011
</code></pre>
<p>As per my lecturer's instructions, I have stored this information in a class called Client ... | [] | [
{
"body": "<ol>\n<li><p>You should extract out at least two methods:</p>\n\n<pre><code>boolean isMatchingClients(final Client client, final Client otherClient) { ... }\nint calculateCommonInterests(final String clientInterests, \n final String otherClientInterests) { ... }\n</code></pre>\n\n<p>It would impro... | {
"AcceptedAnswerId": "18752",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-17T19:17:49.413",
"Id": "18750",
"Score": "2",
"Tags": [
"java"
],
"Title": "Rewriting nested for loops to give better formatted output"
} | 18750 |
<p>I recently started game development, but one of the things that I never put much thought to was the loading of images. I'm curious as to advice for improving my current code on loading images. I'm using cocos2d in iOS code, but if you know of optimization techniques in other languages I'd like to hear that as well.<... | [] | [
{
"body": "<blockquote>\n <p>is this slow or a bad way to load images?</p>\n</blockquote>\n\n<p>Actually, yes and no. Cocos-2d goes the smart route and caches your sprite image internally, which makes the sprite's image not only re-useable, but it drastically speeds up the next time the method is called durin... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-18T05:42:18.417",
"Id": "18757",
"Score": "1",
"Tags": [
"performance",
"image",
"objective-c",
"ios"
],
"Title": "Loading of images"
} | 18757 |
<p>First off, I will try to explain the problem and then I will show you the code I have come up with so far.</p>
<p>I've got a list of properties. Each property has a tag of type int and a value of one of the following types: (bool, string, int, long).
some sample properties:</p>
<blockquote>
<p>tag: 1, value: "so... | [] | [
{
"body": "<p>I would get rid of the if-else statement in operator() of Rule, and replace it with a stored <code>apply_visitor</code> functor, or move the <code>apply_vistor</code> from operator() of Rule into StartsWith and make all of your checkers have the same signature.</p>\n\n<p>Suppose we go with moving ... | {
"AcceptedAnswerId": "18782",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-18T10:55:14.963",
"Id": "18762",
"Score": "1",
"Tags": [
"c++"
],
"Title": "Comparing sets of different types using variants"
} | 18762 |
<p>I need some guidance on making the following code more idiomatic:</p>
<pre><code>(ns cheaterpress.algorithm
(:use [clojure.string :only [split lower-case]])
(:use [clojure.test]))
(def words (split (slurp "words") #"\s"))
(defn string-to-letter-hash [string]
(loop [letters (seq string) letter-hash {}]
(... | [] | [
{
"body": "<p>Well there is a standard library function: frequences :)</p>\n\n<pre><code>user> (doc frequencies)\n-------------------------\nclojure.core/frequencies\n([coll])\n Returns a map from distinct items in coll to the number of times\n they appear.\n</code></pre>\n\n<p>Since in Clojure many many t... | {
"AcceptedAnswerId": "18769",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-18T13:33:49.137",
"Id": "18767",
"Score": "1",
"Tags": [
"clojure"
],
"Title": "Idiomatic letterpress cheater"
} | 18767 |
<p>Please help me check the correctness of this c# iterative implementation of <a href="http://chessprogramming.wikispaces.com/Negamax" rel="nofollow">negamax</a>! Thank you! Your help highly appreciated! Also, please help me out how to add <a href="http://chessprogramming.wikispaces.com/Alpha-Beta" rel="nofollow">alph... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-18T15:29:25.613",
"Id": "29917",
"Score": "2",
"body": "I think your question does not fit well on this site. This site is for requests to improve code that you think works, not to check whether it works at all and certainly not to wri... | [
{
"body": "<p>Some quick suggestions:</p>\n\n<ul>\n<li>Split the code into smaller methods, with understandable names - it will become simpler!</li>\n<li>Use clear variable names (even if they are longer) and try to avoid \"shortenings\";</li>\n<li><strong>Never</strong> use less than 3 characters for variable ... | {
"AcceptedAnswerId": "18847",
"CommentCount": "9",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-18T15:05:52.767",
"Id": "18770",
"Score": "1",
"Tags": [
"c#"
],
"Title": "Iterative Implementation of Negamax Alpha-Beta"
} | 18770 |
<p>I have a list of images that are used as links and at the bottom of each image there is another image to show/hide. So far all the images show at the same time because they have the same class.</p>
<p>Is there any way to get around that? I don't know how to give them all the unique ID.</p>
<pre><code> <div id="... | [] | [
{
"body": "<p>You need to find the <code>.name</code> item that is in the same block of HTML as the one being hovered. One way to do that is to go up the parent chain from the one begin hovered to get the <code>li</code> tag and then use <code>.find()</code> from thereto find that <code>.name</code> item in th... | {
"AcceptedAnswerId": "18772",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-18T15:23:13.240",
"Id": "18771",
"Score": "4",
"Tags": [
"javascript",
"jquery",
"html"
],
"Title": "Show/hide image in each list individually with same class"
} | 18771 |
<p>In my C# program, I have a class defined as follows:</p>
<pre><code>public class DbResult
{
public bool bSuccess { get; private set; }
public String Message { get; private set; }
private DbResult(bool success, string message)
{
this.bSuccess = success;
this.Message = message;
}
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-19T17:35:23.897",
"Id": "29980",
"Score": "3",
"body": "Just a comment on your code, using Hungarian Notation is not a standard naming convenction, especially on public properties. http://stackoverflow.com/questions/309205/are-variabl... | [
{
"body": "<p>Can I try to convince you that you don't actually need such a <code>Result</code> class at first place?</p>\n\n<p>How do you actually use the string <code>Message</code> value of this class? Do you show it to user? If yes, then what would you do when you need to make it multilingual? What I'm tryi... | {
"AcceptedAnswerId": "18793",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-18T16:26:12.507",
"Id": "18775",
"Score": "0",
"Tags": [
"c#",
"optimization",
"classes",
"entity-framework"
],
"Title": "Making a Custom class less specialized but just as un... | 18775 |
<blockquote>
<p>Given an array of words, print all anagrams together. For example, if
the given array is {“cat”, “dog”, “tac”, “god”, “act”}, then output
may be “cat tac act dog god”.</p>
</blockquote>
<p>The following is my c++ code. I use raw pointer to implement varying number of children
for practice. Actual... | [] | [
{
"body": "<pre><code>#include <cstring>\n</code></pre>\n\n<p>Avoid including C headers when programming C++.</p>\n\n<pre><code>struct Index_node_base\n{\n Index_node_base* next;\n Index_node_base():next(NULL){} \n};\n\nstruct Index_node : public Index_node_base\n{\n int index;\n Index_node(i... | {
"AcceptedAnswerId": "18778",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-18T16:39:58.533",
"Id": "18776",
"Score": "1",
"Tags": [
"c++",
"trie"
],
"Title": "use trie data structure to solve the problem of clustering anagrams"
} | 18776 |
<p>This is my code that works:</p>
<pre><code>foreach (var r in rlist)
{
if (r.IndexOf("_") != -1)
{
int id = int.Parse(r.Split('_')[1]);
var x_tmp = (from x in db.tblX where x.x_id == my_id && x.x_id == id select x).First();
x_tmp.order = someNumber;
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-19T08:59:20.937",
"Id": "29955",
"Score": "0",
"body": "Is it supposed to set the same order for all the items? Shouldn't you be incrementing the order?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-19T09... | [
{
"body": "<p>Seems you are calling the query a few times with <code>id</code>, so let's just call it only once with all of them.</p>\n\n<pre><code>(from x in db.tblX where x.x_id == my_id && ids.Contains(x.x_id) select x)\n</code></pre>\n\n<p>There you go, now <code>IEnumerable</code>'s <code>Contains<... | {
"AcceptedAnswerId": "18779",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-18T17:10:57.980",
"Id": "18777",
"Score": "-3",
"Tags": [
"c#",
"linq"
],
"Title": "How to refactor sql query in a foreach"
} | 18777 |
<p>I've created a logging system with one-use passwords (sent via SMS API). What I would like to know is if it's "safe". I know it is hard to estimate safety but I am curious if it is safer than regular password. I would appreciate any advice to improve following code.</p>
<p>Scheme is:</p>
<p>Logging:</p>
<p>Loggin... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-18T21:33:58.593",
"Id": "29928",
"Score": "0",
"body": "Why have you decided to split this up into two scripts? It seems that everything taking place in the \"api\" script could replace the curl stuff in the log in script (not \"loggin... | [
{
"body": "<ol>\n<li><p>This probably makes integration and debugging harder:</p>\n\n<blockquote>\n<pre><code>if ($_GET['api']!=$apiKey) {\n header('HTTP/1.0 404 Not Found');\n die();\n}\n</code></pre>\n</blockquote>\n\n<p>The error message is misleading, if someone use an older or wrong API key they probab... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-18T21:26:27.907",
"Id": "18781",
"Score": "3",
"Tags": [
"php",
"logging"
],
"Title": "Logging system safety"
} | 18781 |
<p>I have some experience with PHP but I have never even try to do this wit pure PHP, but now a friend of mine asked me to help him with this task so I sat down and write some code. What I'm asking is for opinion if this is the right way to do this when you want to use only PHP and is there anything I can change to mak... | [] | [
{
"body": "<p>Just two small notes:</p>\n\n<ol>\n<li><p>I think </p>\n\n<pre><code><DCTYPE! html>\n</code></pre>\n\n<p>should be</p>\n\n<pre><code><!DOCTYPE html>\n</code></pre></li>\n<li><p>From <em>Code Complete, 2nd Edition</em>, p761:</p>\n\n<blockquote>\n <p><strong>Use only one data declarati... | {
"AcceptedAnswerId": "18784",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-18T21:44:28.147",
"Id": "18783",
"Score": "1",
"Tags": [
"php",
"form"
],
"Title": "Checking form input data on submit with pure PHP"
} | 18783 |
<p>I've used the Trie data structure to solve the following problem:</p>
<blockquote>
<p>Given an array of words, print all anagrams together. For example, if the given array is {"cat", "dog", "tac", "god", "act"}, then output may be "cat tac act dog god".</p>
</blockquote>
<p>The following is my C++ implementation... | [] | [
{
"body": "<p>Your code does several things more complex than required. In no particular order:</p>\n\n<ul>\n<li>What purpose does <code>Trie_node_base</code> serve? You don’t need a base class here since you only inherit from it once.</li>\n<li>Worse, your base class doesn’t have a virtual destructor.</li>\n<l... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-19T00:30:35.187",
"Id": "18785",
"Score": "11",
"Tags": [
"c++",
"algorithm",
"interview-questions",
"trie"
],
"Title": "Implementation of Trie data structure accommodating varyi... | 18785 |
<p>How can I combine these <code>if</code> statements to make this a little cleaner and be less repetitive?</p>
<pre><code>$(document).keydown(function(e){
if (e.keyCode == 38) {
if($html.hasClass('client-loading') || canAnim === false) {
return false;
}
var $prevProj = $('.proj... | [] | [
{
"body": "<p>This is about as concise as i think it will reasonably get. There might be a better way to handle double presses then a global variable timeout.</p>\n\n<pre><code>if ( e.keyCode == 38 || e.keycode == 40 ) \n{\n if( $html.hasClass('client-loading') || canAnim === false ) return false;\n\n if ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-19T13:16:01.127",
"Id": "18792",
"Score": "3",
"Tags": [
"javascript",
"jquery"
],
"Title": "Keypress function conditional"
} | 18792 |
<p>I run a small server, and to check whether clients are being hosted on my server, I wrote this. I'm new to object oriented programming. How stratified should my programs really be? Do I want to have every possible variable and piece in their own function? Also, how am I doing in general? Any recommendations?</p>
... | [] | [
{
"body": "<p>Some observations:</p>\n\n<ul>\n<li><p>Regarding the \"stratification\". It's hard to give practical advice, this is something that comes from experience and personal taste. Some basics to start with: a) write classes/modules with low coupling to achieve real modularization, b) write fairly short ... | {
"AcceptedAnswerId": "18797",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-19T15:16:11.153",
"Id": "18796",
"Score": "3",
"Tags": [
"beginner",
"ruby"
],
"Title": "Checking host status for clients on server"
} | 18796 |
<p>I wrote a little code to list a number's prime factors:</p>
<pre><code>import java.util.Scanner;
import java.util.Vector;
public class Factorise2
{
public static Vector<Integer> get_prime_factors(int number)
{
//Get the absolute value so that the algorithm works for negative numbers
i... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-17T18:54:36.073",
"Id": "29981",
"Score": "1",
"body": "By a glance: you have nested loops in second version."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-17T18:55:41.130",
"Id": "29982",
"Score"... | [
{
"body": "<p>Q: Do you know if it's a) \"consuming a lot of CPU cycles\", or b) just \"taking a long time\"?</p>\n\n<p>I suspect the latter - that you're <em>underutilizing</em> the CPU ... because you're using (legacy, Java 1.0) \"Vector\" instead of an ArrayList.</p>\n\n<p>Try ArrayList, and benchmark the di... | {
"AcceptedAnswerId": "18801",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-17T18:52:34.920",
"Id": "18799",
"Score": "3",
"Tags": [
"java",
"performance",
"beginner",
"primes"
],
"Title": "Listing a number's prime factors"
} | 18799 |
<p>I am not a DBA nor do I play one on TV. </p>
<p>My application is retrieving information from Facebook and storing it into our own database. I want to retrieve the Location Post information of <code>Id and AuthorId</code>. <code>AuthorId</code> is a foreign key to another table. I was told by a DBA that foreign... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-19T21:26:35.803",
"Id": "29999",
"Score": "1",
"body": "Generally, the way I see the whole \"don't allow external primary key\" bit, is when an external entities are attempting to declare internal primary keys that _your_ system has to... | [
{
"body": "<ol>\n<li>I'd rather use the <code>FacebookAuthorId</code> and <code>FacebookLocationPostId</code> as primary keys, because your logic ensures them to be unique. In case of your current solution you would still require (unique) indexes on these fields (in order for lookups to be efficient) so there i... | {
"AcceptedAnswerId": "18806",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-19T17:59:47.437",
"Id": "18803",
"Score": "3",
"Tags": [
"sql",
"sql-server"
],
"Title": "Review Insert/Update stored procedure"
} | 18803 |
<p>I'm evaluating a <code>meeting_type</code> value that determines what kind of pricing structure I should be using. Currently, if my <code>meeting_type</code> value is a <code>w</code>, we charge one price for every 10 registrants. If the <code>meeting_type</code> is anything else, it's a price per registrant model. ... | [] | [
{
"body": "<p><strong>Removing intermediate variable <code>$webinar_count</code></strong></p>\n\n<pre><code>$total_price = ($_POST['meeting_type'] == 'w')\n ? (ceil($guests / 10) * $price)\n : ($guests * $price);\n</code></pre>\n\n<p>OR</p>\n\n<pre><code>if ($_POST['meeting_type'] != 'w'... | {
"AcceptedAnswerId": "18843",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-19T18:44:12.690",
"Id": "18805",
"Score": "3",
"Tags": [
"php"
],
"Title": "Calculating a total price with group pricing"
} | 18805 |
<p>I'm looking for advice and ways on making it better.</p>
<p><a href="https://github.com/Prashles/Validation" rel="nofollow">Code</a></p>
<pre><code><?php
Class Validate {
private $_errors = array();
public function __construct()
{
require_once 'errors.php';
$this->errorText = $... | [] | [
{
"body": "<p>Judging your interface: Nice!</p>\n\n<p>You could have provided some static method for simpler checking:</p>\n\n<pre><code>if( Validate::check($email, 'Email', 'required|email') ){ ... }\n</code></pre>\n\n<p>or and check-all-at-once method</p>\n\n<pre><code>$errors = Validate::checkall( array(\n ... | {
"AcceptedAnswerId": "18824",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-19T21:22:48.460",
"Id": "18814",
"Score": "7",
"Tags": [
"php",
"object-oriented",
"validation"
],
"Title": "PHP Validation Class"
} | 18814 |
<p>This is a start on a multi-threaded game loop and I just wish to confirm my code is going in the correct direction, and if not, if there is any way it can be improved. I have good experience in game development and C++ in general, but limited experience when it comes to multi-threaded environments.</p>
<pre><code>#... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-20T05:51:59.907",
"Id": "30023",
"Score": "0",
"body": "Maybe I'm misunderstanding what's going on in your code but what's the point in having multiple threads if you're just going to have them wait on the same mutex? You've essentiall... | [
{
"body": "<p>Yes you have added enough explicit locks to make it safe (under normal situations).</p>\n\n<p>But it is not exception safe and not written in C++ style. You are writing the code as if it was Java (maybe). Which is causing all sorts of problems.</p>\n\n<p>Why do you need the start() and stop() func... | {
"AcceptedAnswerId": "19619",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-19T22:19:19.327",
"Id": "18817",
"Score": "8",
"Tags": [
"c++",
"multithreading",
"c++11"
],
"Title": "Multi-threaded game loop"
} | 18817 |
<p>I wanted to see if I fully understood recursion so I attempted the <a href="http://imranontech.com/2007/01/24/using-fizzbuzz-to-find-developers-who-grok-coding/" rel="nofollow">FizzBuzz</a> challenge and applied recursion to it. </p>
<p>Did I do it correctly? Is this good code? Is there a more efficient way of doin... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2016-04-23T10:38:50.863",
"Id": "236279",
"Score": "0",
"body": "Hello! You have received four answers. Would you please [accept](http://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work) one of them? This gives you and t... | [
{
"body": "<ol>\n<li><p>It's worth to mention a disadvantage of recursion: the possibility of stack overflow. Calling <code>recurse(1, 6500)</code> throws a <a href=\"http://docs.oracle.com/javase/6/docs/api/java/lang/StackOverflowError.html\" rel=\"nofollow noreferrer\"><code>StackOverflowError</code></a> on m... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-19T22:57:14.650",
"Id": "18820",
"Score": "7",
"Tags": [
"java",
"recursion",
"fizzbuzz"
],
"Title": "What do you think of my Recursive FizzBuzz?"
} | 18820 |
<p>The Resource Pool is similar to the implementation of a semaphore. It takes the class type of the resource and number of resource pools associated with it as the constructor parameters. There is a small ambiguity here, when the <code>Resource</code> instance is created it uses reflection, but when we require the res... | [] | [
{
"body": "<ul>\n<li><p>No need to use synchronization in the constructor - at the moment of creation the object is not yet visible to any concurrent thread.</p></li>\n<li><p>Declare a field <code>Constructor<R> resourceConstructor</code> and in the constructor, initialize it with <code>resourceClass.getD... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-20T06:29:47.777",
"Id": "18826",
"Score": "3",
"Tags": [
"java",
"locking"
],
"Title": "Resource Pool implementation with ReentrantLock and Condition"
} | 18826 |
<p>This does the job, but is not especially elegant.</p>
<p>What is the preferred Pythonic idiom to my childish nests?</p>
<pre><code>def bytexor(a, b):
res = ""
for x, y in zip(a, b):
if (x == "1" and y == "0") or (y =="1" and x == "0"):
res += "1"
else:
res += "0"
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-20T07:52:44.243",
"Id": "30024",
"Score": "0",
"body": "What is the code supposed to be doing? You're apparently trying to get all combinations of 4-bit binary numbers... but what are you trying to get from that?"
},
{
"Content... | [
{
"body": "<p>Depending on what you are ultimately doing, probably the neatest way is to use a standard module, <code>itertools</code>. Using <code>get_all</code> as an example:</p>\n\n<pre><code>import itertools\n\ndef get_all_bitpatterns():\n res = []\n bit = [ \"0\", \"1\" ]\n for z in itertools.pr... | {
"AcceptedAnswerId": "18835",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-20T07:17:35.717",
"Id": "18828",
"Score": "14",
"Tags": [
"python",
"combinatorics",
"bitwise"
],
"Title": "Exhaustive search for encryption keys"
} | 18828 |
<p>I'm looking for alternative ways to do it and in general parts that don't look write on this code.</p>
<pre><code>using System.Collections.Generic;
namespace Algorithms
{
public class SudokuPuzzleValidator
{
readonly int[,] _board;
public SudokuPuzzleValidator()
{
... | [] | [
{
"body": "<p>This looks way overcomplicated. There are a lot of solutions on the web, for example:\n<a href=\"https://stackoverflow.com/questions/723213/sudoku-algorithm-in-c-sharp\">https://stackoverflow.com/questions/723213/sudoku-algorithm-in-c-sharp</a></p>\n\n<p>Regarding your code:</p>\n\n<ul>\n<li>You h... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-20T10:40:59.563",
"Id": "18831",
"Score": "2",
"Tags": [
"c#"
],
"Title": "I could use a review of my sudoku validation"
} | 18831 |
<p>I didn't make the math myself since I'm an idiot. I did however try to make it more versatile and usable for my multilingual page, which involves making it simple to use for advanced plural forms such as Polish and Russian.</p>
<p>Is this code any good to use on a website? or is it overkill?
I'm using the laravel f... | [] | [
{
"body": "<p>I've not coded any PHP in last five years but if I'm right the following is the same:</p>\n\n<pre><code>$tokens = array (\n 31536000 => array('msgid1' => \"Last visit: %d year ago\", \n 'msgid2' => \"Last visit: %d years ago\"),\n 2592000 => array('msgid1' => \"Last vis... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-20T11:53:26.477",
"Id": "18834",
"Score": "2",
"Tags": [
"php",
"datetime",
"static"
],
"Title": "PHP: multilingual Time::since() static class"
} | 18834 |
<p>How can I simplify this code?</p>
<pre><code> if (directory.Exists)
{
smallFileNames = directory.GetFiles("*.csv").Select(i => i.FullName).ToList();
if(smallFileNames.Count == 0)
smallFileNames = DivideIntoFiles(fileName);
}
else
smallFileNames = DivideIntoFiles(fileName);
</code></pre... | [] | [
{
"body": "<p>...and you could simplify the second conditional by initializing <code>smallFileNames</code> :</p>\n\n<pre><code>List<string> smallFileNames = new List<string>\n\nif (directory.Exists)\n{\n smallFileNames = directory.GetFiles(\"*.csv\").Select(i => i.FullName).ToList();\n}\n\nif ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-20T12:51:01.013",
"Id": "18837",
"Score": "6",
"Tags": [
"c#"
],
"Title": "Simplify 'if' condition"
} | 18837 |
<p>I'm working with lots of code that looks like this:</p>
<pre><code>-(void)switchToPercent{
int tmp;
tmp = (statisticsObject.idag3_orig != 0) ? statisticsObject.idag3_orig : [self compareValue:statisticsObject.idag2 withValue:statisticsObject.idag3];
statisticsView.idag3.text = [NSString stringWithForma... | [] | [
{
"body": "<p>I can't really judge if it's a good idea, but one way could be creating an NSArray (or NSSet) containing NSDictionaries with the keypaths that should be compared, and then enumerating through that. Something like this:</p>\n\n<pre><code>#define keyOriginal = \"original\"\n#define keyComparisonItem... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-20T14:15:59.903",
"Id": "18841",
"Score": "2",
"Tags": [
"objective-c"
],
"Title": "Iterating over object properties"
} | 18841 |
<p>here is my implementation to find the lowest common ancestor in a binary tree. It works but i would like to know if i could have done anything better or if i have missed an specific case. would really appreciate ur feedback:</p>
<pre><code>//The function findOrQueue is to enqueue all elements upto target node to a ... | [] | [
{
"body": "<p>I would simplify the <code>findOrQueue</code> function to make sure it stays <a href=\"http://en.wikipedia.org/wiki/Don%27t_repeat_yourself\" rel=\"nofollow\">DRY</a></p>\n\n<pre><code>public void findOrQueue(Node target, Node top, LLQueue q) {\n int cmp = target.getData().compareTo(top.getData... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-20T01:55:26.470",
"Id": "18845",
"Score": "3",
"Tags": [
"java"
],
"Title": "Lowest Common Ancestor"
} | 18845 |
<p>I have written a JavaScript API that loads and houses libraries of code to do all sorts of things on websites.</p>
<p>Effectively, this is (will be) the base JavaScript for all the websites I build.</p>
<p>The aim of this API is to load the required libraries (<code>SM.load()</code>) needed for a particular page, ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-20T15:54:38.410",
"Id": "30052",
"Score": "1",
"body": "SM? [Really](http://en.wikipedia.org/wiki/Sadomasochism)?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-20T15:56:16.390",
"Id": "30053",
"Sc... | [
{
"body": "<p>From a once over:</p>\n\n<ul>\n<li>I like <code>use strict</code> in an IIFE</li>\n<li>However, the second <code>use strict</code> in <code>indexOf</code> is overkill</li>\n<li>You are not using the variable <code>oldSM</code></li>\n<li>Lots of comments are good as well</li>\n<li><p>The below code... | {
"AcceptedAnswerId": "40876",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-20T15:46:12.907",
"Id": "18846",
"Score": "2",
"Tags": [
"javascript",
"jquery",
"api"
],
"Title": "JavaScript API that loads and houses libraries of code"
} | 18846 |
<p>Please help me improve this Google Apps Script for reminding the user to contact people they haven't contacted in a while:</p>
<p><strong>Purpose:</strong></p>
<ul>
<li>Creates tasks for you to contact people you haven't talked to for a while.</li>
<li>Adds a 'Touch Frequency (Days)' field to contacts - make a sch... | [] | [
{
"body": "<p>A couple of points to make this more readable and maintainable:</p>\n\n<hr>\n\n<p>It has <strong>Magic Numbers</strong> everywhere:</p>\n\n<pre><code>switch ($state) {\n case 20:\n</code></pre>\n\n<p>Use constants / comment what the values mean. You will probably come back to this and it will... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-20T18:11:46.467",
"Id": "18850",
"Score": "2",
"Tags": [
"email",
"google-apps-script",
"google-contacts-api"
],
"Title": "Google Apps Email, Contacts, Tasks, ScriptDB services integ... | 18850 |
<p>This code solves the problem of FizzBuzz. Is it possible in any way to improve it?</p>
<pre><code>main = main' 1 where
main' n = do
(putStrLn . choose) (show n, "Fizz", "Buzz", "FizzBuzz", n)
if n < 100 then main' (succ n) else putStrLn "End!"
where
choose (n0, n3, n5, n15, n)
|... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-24T19:33:28.507",
"Id": "30264",
"Score": "0",
"body": "Which definition of FizzBuzz are you using? Based on the [first Google result](http://c2.com/cgi/wiki?FizzBuzzTest) the #s are fixed at [1..100], so there shouldn't be any inputs.... | [
{
"body": "<p>You could separate your I/O from the pure code:</p>\n\n<pre><code>fizzBuzz :: Int -> String\nfizzBuzz n | mod n 3 == 0 && mod n 5 == 0 = \"FizzBuzz\"\n | mod n 5 == 0 = \"Buzz\"\n | mod n 3 == 0 = \"Fizz\"\n | otherwise ... | {
"AcceptedAnswerId": "18898",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-20T20:05:49.010",
"Id": "18852",
"Score": "5",
"Tags": [
"haskell",
"fizzbuzz"
],
"Title": "FizzBuzz up to 99 in Haskell"
} | 18852 |
<p>This replaces numbers with the character that appears next to them ('number' times). Is there a a more elegant or shorter way to do this?</p>
<pre><code>var decode = function(str, result) {
var regex = /\d+/,
number = regex.exec(str);
if (number === null) {
return str;
}
var start ... | [] | [
{
"body": "<p>From my answer on Stack Overflow: <a href=\"https://stackoverflow.com/a/13481139/538551\">https://stackoverflow.com/a/13481139/538551</a></p>\n\n<p>Simply use String.replace():</p>\n\n<pre><code>function decode(str) {\n return str.replace(/(\\d+)([a-zA-A])/g, function (match, num, letter) {\n ... | {
"AcceptedAnswerId": "18855",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-20T20:06:53.977",
"Id": "18853",
"Score": "2",
"Tags": [
"javascript",
"strings",
"compression"
],
"Title": "Run-length decoder"
} | 18853 |
<h2>My problem is I need to know</h2>
<ul>
<li>is my code in my CRUD functions structured well and effectively? I plan to implement CRUD for Locations entity too. hopefully without redundant code.</li>
<li>you see how one CRUD function in the program class calls the other CRUD function in the DataAccess Class? I"m t... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-21T15:05:21.923",
"Id": "30110",
"Score": "0",
"body": "I definitely think there's something wrong here, but I'm having a hard time articulating what it is. Are these the default EF-generated classes, or did you apply another code gen... | [
{
"body": "<p>This is hard, because you're writing an application which is <em>specifically</em> a pure CRUD app, so the distinction between the business logic and the database logic isn't as clear as it usually is. Most applications don't let you just create a new <strong>_</strong>, they do that for you behi... | {
"AcceptedAnswerId": "19058",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-20T20:56:52.650",
"Id": "18858",
"Score": "4",
"Tags": [
"c#",
"entity-framework"
],
"Title": "Trying to clearly seperate my logic in my program"
} | 18858 |
<p>I'd like to improve my router.</p>
<p>This is the current code for my autoloading action within my MVC application:</p>
<pre><code>spl_autoload_register(function ($className) {
if (file_exists(ROOT . DS . 'library' . DS . 'intranet' . DS . 'classes' . DS .strtolower($className) . '.php')){
require_once(ROOT... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-20T23:21:16.790",
"Id": "30083",
"Score": "0",
"body": "Any particular reason why you're not using namespaces?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-20T23:23:06.267",
"Id": "30084",
"Score... | [
{
"body": "<p>What you've written is more or less the standard implementation of <code>spl_autoload()</code>.</p>\n\n<p>This is an equivalent approach:</p>\n\n<pre><code>$paths = array(\n get_include_path(),\n ROOT . DS . 'library' . DS . 'intranet' . DS . 'classes',\n ROOT . DS . 'application' . DS... | {
"AcceptedAnswerId": "18868",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-20T21:59:00.697",
"Id": "18861",
"Score": "2",
"Tags": [
"php",
"url-routing"
],
"Title": "Improving my PHP autoloader"
} | 18861 |
<p>I have a lot of variables that I need to check for exceptions and output the empty field in case of a null returned value (I am reading a calender list from Sharepoint and my program is supposed to send email notifications if some of the conditions are met).</p>
<p>I surrounded my variables with a try-catch with a ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-21T14:26:15.953",
"Id": "30105",
"Score": "0",
"body": "What is the type if `item`?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-21T16:09:32.283",
"Id": "30121",
"Score": "0",
"body": "@ANeve... | [
{
"body": "<p>Refactor into a method:</p>\n\n<pre><code>var name = this.GetVariable(\"Name\"); \nvar dueDate= this.GetVariable(\"Due Date\");\n.\n.//more variables\n. \nvar Title= this.GetVariable(\"Title\"); \n\nprivate string GetVariable(string name)\n{\n try\n {\n return item[name].ToString... | {
"AcceptedAnswerId": "18863",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-20T22:42:46.840",
"Id": "18862",
"Score": "6",
"Tags": [
"c#",
"object-oriented",
"exception"
],
"Title": "Handling null exception when having multiple variables"
} | 18862 |
<p>I'm learning JavaScript and came up with this basic game code structure (using the CreateJS framework): </p>
<pre><code>var stage;
var totalLoaded = 0;
var manifest;
var game = game || {};
game.init = {
load: function () {
var canvas = document.getElementById('gameCanvas');
images = createjs.... | [] | [
{
"body": "<p>From a once over:</p>\n\n<ul>\n<li><p>Object notation does not require the properties to be quoted, you can simply do this:</p>\n\n<pre><code>{\n name: \"startText\",\n content: \"START\",\n style: \"bold 50px Arial\",\n color: \"red\",\n x: 325,\n y: 140,\n scaleX:1,\n scaleY:1\n}\n</code... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-20T23:33:25.460",
"Id": "18867",
"Score": "5",
"Tags": [
"javascript",
"game",
"canvas"
],
"Title": "Basic game code structure tips"
} | 18867 |
<p>I'm submitting this code in a couple of days as part of an an interview process. The company knows that I don't have any formal experience with Java. I'm hoping they are testing my ability to learn it on the fly. </p>
<p>This is my first non-trivial Java program and I'm looking for improvements and advice as if ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-21T20:46:13.920",
"Id": "30148",
"Score": "0",
"body": "Also, consider a more functional approach - instead of methods that work on instance variables (reading or mutating), use parameters and returns. This should help to limit side-e... | [
{
"body": "<p>Just a few quick notes:</p>\n\n<ol>\n<li><p>The catch block in the main method seems unnecessary. Throwing out exceptions has the same effect:</p>\n\n<pre><code>public static void main(final String[] args) {\n final Taxer taxer = new Taxer();\n taxer.run();\n}\n</code></pre></li>\n<li><p>Try... | {
"AcceptedAnswerId": "18872",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-20T23:50:25.080",
"Id": "18869",
"Score": "4",
"Tags": [
"java",
"interview-questions",
"finance"
],
"Title": "Swedish Tax Calculator"
} | 18869 |
<p>I'm trying to write a little page which will help me - when it ever gets finished - in my job to get some stuff done easier and faster. I'd like some hints and tricks for better structuring the code, i.e. to better divide logic from the UI.</p>
<p>I use jQuery a bit (need to expand my knowledge of using it) and wil... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-12-21T23:54:50.427",
"Id": "31744",
"Score": "0",
"body": "If you're still looking for an answer, can you say whether your code works as intended or not? Are there any specific problems with it, other than the one about jQuery event handl... | [
{
"body": "<p>This is only about your HTML as I don't know much about JS. I guess your page will only be used internally by you, so it is not that important, but it may help others that come by.</p>\n\n<ul>\n<li><a href=\"http://www.w3.org/TR/html5/the-legend-element.html#the-legend-element\" rel=\"nofollow\"><... | {
"AcceptedAnswerId": null,
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-21T01:01:23.637",
"Id": "18870",
"Score": "3",
"Tags": [
"javascript",
"performance",
"jquery",
"html5"
],
"Title": "Body mass index / Body surface area calculator"
} | 18870 |
<p>I am currently trying to learn Haskell (after taking a Scala course on Coursera); but while I can write functions that do what I want, I worry that I am not learning to write idomatic/clean/performant code. I am hoping that this is an acceptable place to receive feedback on how I am progressing. Please let me know i... | [] | [
{
"body": "<p>I would propose an even less performant solution, but maybe you can improve it...</p>\n\n<pre><code>balance xs = head cumulated == 0 && all (>= 0) cumulated where\n cumulated = scanr (+) 0 $ map depth xs\n depth '(' = -1 \n depth ')' = 1\n depth _ = 0\n</code></pre>\n\n<p>Note that ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-21T09:53:56.657",
"Id": "18878",
"Score": "2",
"Tags": [
"haskell",
"recursion",
"beginner"
],
"Title": "Which of these two paren-matching functions is better?"
} | 18878 |
<p>I am working on a code snippet to make a function which can be called with an object literal. </p>
<p>Problem area: If I do not need to track the product value, then a check has been placed for undefined. But do I really need to make check for each and every value if it's not there in the object literal?</p>
<pre>... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-21T10:43:33.687",
"Id": "30095",
"Score": "0",
"body": "Are you using jQuery?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-21T10:44:12.490",
"Id": "30096",
"Score": "0",
"body": "You are usin... | [
{
"body": "<p>First, just a note: You check against <code>undefined</code>, but <code>undefined</code> is unfortunately <em>not</em> a keyword, meaning it's mutable. Better to use <code>typeof something === 'undefined'</code></p>\n\n<p>If I understand you right, you want to be able to \"leave out\" anyone of th... | {
"AcceptedAnswerId": "18886",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-21T10:32:21.610",
"Id": "18879",
"Score": "2",
"Tags": [
"javascript"
],
"Title": "Making a function which can be called with an object literal"
} | 18879 |
<p>I am using this code to display the recent post from my subdomain to my main domain. I got it after spending 6-7 hours. Now I need to show the avatar image and username of the user of has posted the questions on questions.admissiontimes.com. Right now, it's coming in green and black.</p>
<pre><code>function print_r... | [] | [
{
"body": "<p>Take a look at <code>filter_input()</code>. It allows you to sanitize and validate GET/POST variables whether they exist or not. If no variable in that scope exists it will be set to FALSE/NULL which means all you have to do is set it to a variable and ensure it has a value.</p>\n\n<pre><code>$tem... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-21T12:06:05.143",
"Id": "18882",
"Score": "2",
"Tags": [
"php"
],
"Title": "Image placed with username in recent post of WordPress"
} | 18882 |
<p>I've written a hash-table implementation. This is the first time I've written such code. The hash-table uses open-addressing with linear probing. The hash function is still subject to change as I found out some properties of it that make it particulary bad for my application.</p>
<p>Could you please review the code... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-21T20:02:40.443",
"Id": "30143",
"Score": "1",
"body": "We prefer to review code that is on this site. Then comments here will be useful to future users even if the linked site is no longer available."
},
{
"ContentLicense": "C... | [
{
"body": "<h3>1. Bugs</h3>\n\n<ol>\n<li><p>The algorithm in <code>ht_get</code> is incorrect:</p>\n\n<pre><code>while (ht->table[index] != NULL\n && hash(ht,ckey = get_key(ht->table[index])) == hkey) {\n if (ckey == key) return ht->table[index];\n index = MODINC(ht->bits,index);\n}\n... | {
"AcceptedAnswerId": "18932",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-21T12:08:56.173",
"Id": "18883",
"Score": "5",
"Tags": [
"c",
"hash-map"
],
"Title": "Hash table using open-addressing with linear probing"
} | 18883 |
<p>I have a class like this one:</p>
<pre><code>class EmailClass
{
public string MailAdresse { get; set; }
public string MailAdresseCC { get; set; }
}
</code></pre>
<p>Through a JSON deserialization I obtain a <code>List<EmailClass></code> and two other strings <code>anotherMailAddress</code> and <code... | [] | [
{
"body": "<p>Use a <a href=\"http://msdn.microsoft.com/en-us/library/bb359438.aspx\">HashSet</a> then it will only contain unique values, duplicates will be discarded when calling <code>Add</code> based upon the hashcode of the string. This should be far more efficient than calling <code>Distinct</code>.</p>\n... | {
"AcceptedAnswerId": "18887",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-21T12:55:15.143",
"Id": "18884",
"Score": "11",
"Tags": [
"c#",
"performance",
"linq",
"strings"
],
"Title": "String join of distinct string"
} | 18884 |
<p>My alghoritm works and produces good result, but it takes too much time(6 s for 300 input items that is too much for branch and bound alghoritm), so I have maken a mistake somewhere, but really can't find it :( It is supposed to be depth-first branch and bound. Any help would be appreciated!</p>
<pre><code>public v... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-21T15:32:59.780",
"Id": "30113",
"Score": "2",
"body": "Out of curiosity -- what does that node object look like?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-21T17:19:36.337",
"Id": "30125",
"Sc... | [
{
"body": "<p>Branch&Bounding is not what you have implemented (at least I can't see the classic algorithm in there).</p>\n\n<p><a href=\"http://en.wikipedia.org/wiki/Branch_and_bound\" rel=\"nofollow\">Branch And Bound is normally implemented</a> as a recursive process. I don't see recursion here. Addition... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-21T15:23:20.557",
"Id": "18890",
"Score": "5",
"Tags": [
"java",
"algorithm",
"performance"
],
"Title": "What is wrong with my knapsack alghoritm?"
} | 18890 |
<p>(<code>getProperty</code> is the <code>deepCss</code> function from <a href="http://www.webdeveloper.com/forum/showthread.php?166053-Check-if-element-is-visible-when-style-not-set-in-the-tag&p=825130#post825130" rel="nofollow">here</a> and retrieves the current (computed) style of an element).</p>
<pre><code>fu... | [] | [
{
"body": "<p>I have found that there are two possibilities.</p>\n\n<h3>1. The literal translation:</h3>\n\n<pre><code>function toggleElements()\n{\n $(arguments).each(function (index, element) {\n $(element)[0].style.display = (\n getProperty($(element)[0], \"display\") !== \"none\"\n ... | {
"AcceptedAnswerId": "18895",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-21T17:07:10.360",
"Id": "18891",
"Score": "1",
"Tags": [
"javascript",
"jquery"
],
"Title": "JS element toggling"
} | 18891 |
<p>In <em>Cracking the Coding Interview</em> by Gayle Laakmann McDowell, there's a question that asks you to write code for the following:</p>
<blockquote>
<p>Given two sorted arrays, A and B. Write a method merging the elements
of B into A in sorted order. Assume A has a large enough buffer at the
end to hold a... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-21T23:12:16.720",
"Id": "30153",
"Score": "1",
"body": "In-place modification is silly though. A whole new array / list should be created instead. If only Java had a yield keyword ..."
},
{
"ContentLicense": "CC BY-SA 3.0",
... | [
{
"body": "<p>Both are equivalently readable, I'll nitpick on some details though :)</p>\n\n<p>Both solutions will fail with null elements.</p>\n\n<p>The generic type would be better named T instead of Type, as Type has another definition already.</p>\n\n<p>numElementsInArray() as a function looks a little odd ... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-21T17:16:12.070",
"Id": "18892",
"Score": "8",
"Tags": [
"java",
"interview-questions",
"mergesort",
"comparative-review"
],
"Title": "Given two sorted arrays, add the elements o... | 18892 |
<p>I've created my first jQuery plugin, so please try to understand :)</p>
<p>My plugin code looks like so:</p>
<pre><code>(function($) {
$.fn.ajaxSelect = function(options) {
var $this = this;
//options
var settings = $.extend({}, defaults, options);
//disable select
if ($.ui.selectmenu &&... | [] | [
{
"body": "<p>Your demo throws errors in console, something about <code>uniqueId</code> in ui.selectmenu.</p>\n\n<p>Anyway:</p>\n\n<ol>\n<li>You can expose <code>$.ajax</code> deferred so someone may use all features of <code>jQuery.Deferred</code> which is already there.</li>\n<li><p>Call success callback with... | {
"AcceptedAnswerId": "24780",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-21T20:37:13.453",
"Id": "18897",
"Score": "3",
"Tags": [
"javascript",
"jquery"
],
"Title": "jQuery plugin for ajax select fill"
} | 18897 |
<p>In current project I'm using a lot <code>ReaderWriterLockSlim</code> for synchronizing reading and writing values. Handling <code>try { EnterReadLock(); .... } finaly { ExitReadLock(); }</code> every time I need access value seems to me as copying code. So I created extension methods for <code>ReaderWriterLockSlim</... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-28T17:29:32.457",
"Id": "30548",
"Score": "0",
"body": "In cases like this, I prefer methods that work with `using`, instead of taking a delegate."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-29T00:17:17... | [
{
"body": "<p>It looks pretty good. I can't see anything less than great.<br>\nI'd just add that to your code:</p>\n\n<pre><code> private static void Critical(Action criticalAction)\n {\n try\n {\n Thread.BeginCriticalRegion();\n criticalAction();\n }\n fi... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-22T10:45:41.787",
"Id": "18908",
"Score": "4",
"Tags": [
"c#",
"multithreading"
],
"Title": "Extension methods for ReaderWriterLockSlim"
} | 18908 |
<p>I have the following code for my coupon system. It should work but I'm sure I can optimize it. </p>
<p>Any suggestions would be welcome.</p>
<pre><code>@price_to_pay = @booking_request.guests * @table_offer.price_cents / 100
@remaining = @coupon.current_amount - @price_to_pay
if @remaining > 0
@coupon.current... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-22T15:58:12.887",
"Id": "30168",
"Score": "2",
"body": "is this Rails? a lot of instance variables being used here, and some even updated (`@price_to_pay`), why is that? are they AR attributes?"
}
] | [
{
"body": "<p>I think this replicates the logic:</p>\n\n<pre><code>price = @booking_request.guests * @table_offer.price_cents / 100\n@remaining = @coupon.current_amount - price\n@coupon.current_amount = @remaining\n@price_to_play = @remaining >= 0 ? 0 : -@remaining\ncoupon.save\n</code></pre>\n\n<p>Note that... | {
"AcceptedAnswerId": "18914",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-22T15:23:33.390",
"Id": "18913",
"Score": "3",
"Tags": [
"performance",
"algorithm",
"ruby",
"e-commerce"
],
"Title": "Coupon system optimization"
} | 18913 |
<p>Is there a better way of writing this? I feel like there's a lot of lines for such a small thing. Can it be optimized?</p>
<pre><code>$j('#hideShowBtn').toggle(function() {
$j('.playlist-bar-tray').slideUp();
$j(this).attr("title","Show Playlist");
$j(this).children("div").html('Show Playli... | [] | [
{
"body": "<p>Well, it can be written <em>differently</em> with less repetition, but it's readable as it is. There are 4 things that need to happen when the toggling occurs; your code does exactly that. It's the simplest way to write it, really.</p>\n\n<p>My only real suggestion would be to cache <code>$j(this)... | {
"AcceptedAnswerId": "18918",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-22T20:33:43.483",
"Id": "18917",
"Score": "5",
"Tags": [
"javascript",
"jquery"
],
"Title": "Revealing and hiding a playlist"
} | 18917 |
<p>I am a Java beginner and I am looking for an idiomatic way of writing a function that involves generics. I wrote this helper class (below) that pushes items into a sorted generic collection and I wanted to ask for your feedback. Should I perhaps extends some base class of some collection? Or maybe there is some bett... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-23T16:55:47.093",
"Id": "30212",
"Score": "1",
"body": "Have you seen Collections#binarySearch? [link to javadoc (Java 6)](http://docs.oracle.com/javase/6/docs/api/java/util/Collections.html#binarySearch%28java.util.List,%20T,%20java.u... | [
{
"body": "<p>Parts this question have already been answered on StackOverflow - <a href=\"https://stackoverflow.com/a/13529644/139985\">https://stackoverflow.com/a/13529644/139985</a> So I'm going to treat this as a simple request for a code review.</p>\n\n<ol>\n<li><p>The method name is opaque ... <code>addOn... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-23T13:11:39.983",
"Id": "18931",
"Score": "3",
"Tags": [
"java",
"generics"
],
"Title": "how to write generic extensions for standard collection types in java?"
} | 18931 |
<p>I have this <code>GenericDataAccess</code> class to interact with database from my school. I want to ask for some suggestions and advice in how to to improve it and add new methods to it for future use and reference</p>
<pre><code>public static class GenericDataAccess
{
static GenericDataAccess()
{
}
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-24T16:29:41.967",
"Id": "30254",
"Score": "0",
"body": "IMO: too much code, too little functionality. I have written one of these before because I had to use an older way to connect to a database. I do not remember typing so much repet... | [
{
"body": "<p>First of all, there is no need to write a generic data access class. Use the <a href=\"http://www.microsoft.com/en-us/download/details.aspx?id=15104\" rel=\"nofollow noreferrer\">Data Access Application Block</a>. It gives you everything you need to access a database. Why reinvent the wheel. Y... | {
"AcceptedAnswerId": "18963",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-23T14:51:20.907",
"Id": "18933",
"Score": "2",
"Tags": [
"c#",
".net",
"database"
],
"Title": "Adding new methods to GenericDataAccess"
} | 18933 |
<p>The basic idea is for users of these classes to create derived polymorphic protocol specific messages. There is no protocol type in the interface, it is all hidden behind the scenes. But the serialised messages can be retrieved with the <code>getMessage</code> functions.</p>
<p>Does this look a logical approach? ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-23T14:52:00.370",
"Id": "30201",
"Score": "0",
"body": "It's perhaps not clear who allocates, owns, handles memory in calls to getMessage and constructor. Usable, but error-prone."
},
{
"ContentLicense": "CC BY-SA 3.0",
"Cr... | [
{
"body": "<p>OK. I doubt it is irrelevant.</p>\n\n<pre><code>//ref_type is a smart pointers class - not really so relevant to my question\n</code></pre>\n\n<p>Also smart pointers are very hard to get perfectly correct. The standard ones took years and thousands of people looking at them to get correct. So It i... | {
"AcceptedAnswerId": null,
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-23T14:48:42.260",
"Id": "18934",
"Score": "1",
"Tags": [
"c++"
],
"Title": "Encoding/decoding protocol messages to/from various bits of hardware"
} | 18934 |
<p>I want to search through an array of n numbers and find the numbers that are repeated. So far I have this code, which does the job, but I find it to be a rather cumbersome method, but I can't seem to find another method of doing it. </p>
<pre><code>class Checknumber{
int [] numbers = new int [5];
Scanner... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-23T15:19:26.537",
"Id": "30206",
"Score": "0",
"body": "You should tag the language you're using."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-23T15:27:06.080",
"Id": "30207",
"Score": "0",
"... | [
{
"body": "<p>Create a <code>Map<Integer, Integer></code> (first number is the number you are looking, second is the number of appearences).</p>\n\n<p>Run through your array. Each time you find a number, do <code>map.get(numberFound)</code> to see if you had already found it. If you had not, put the numbe... | {
"AcceptedAnswerId": "18939",
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-23T15:18:24.963",
"Id": "18936",
"Score": "17",
"Tags": [
"java",
"homework",
"interview-questions",
"sorting",
"search"
],
"Title": "Finding repeating numbers in an array... | 18936 |
<p>Ok, so given the string:</p>
<pre><code>s = "Born in Honolulu Hawaii Obama is a graduate of Columbia University and Harvard Law School"
</code></pre>
<p>I want to retrieve:</p>
<pre><code>[ ["Born"], ["Honolulu", "Hawaii", "Obama"], ["Columbia", "University"] ...]
</code></pre>
<p>Assuming that we have successfu... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-24T18:47:53.930",
"Id": "30257",
"Score": "0",
"body": "What is your question exactly?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-24T18:53:24.190",
"Id": "30258",
"Score": "0",
"body": "Yea... | [
{
"body": "<p>Here is a solution using regular expressions</p>\n\n<pre><code>import re\n\ndef reMethod(pat, s):\n return [m.group().split() for m in re.finditer(pat, s)]\n\nif __name__=='__main__':\n from timeit import Timer\n s = \"Born in Honolulu Hawaii Obama is a graduate of Columbia University and... | {
"AcceptedAnswerId": "18969",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-24T17:34:43.633",
"Id": "18965",
"Score": "3",
"Tags": [
"python",
"algorithm"
],
"Title": "Retrieving lists of consecutive capitalised words from a list"
} | 18965 |
<p><a href="http://projecteuler.net/problem=81" rel="nofollow">Project Euler problem 81</a> asks:</p>
<blockquote>
<p>In the 5 by 5 matrix below,</p>
<pre><code>131 673 234 103 18
201 96 342 965 150
630 803 746 422 111
537 699 497 121 956
805 732 524 37 331
</code></pre>
<p>the minimal path sum fro... | [] | [
{
"body": "<p>Your code could be less fragile and more idiomatic. For example,</p>\n\n<pre><code>package main\n\nimport (\n \"bufio\"\n \"container/heap\"\n \"errors\"\n \"fmt\"\n \"io\"\n \"os\"\n \"strconv\"\n \"strings\"\n)\n\ntype Matrix [][]int\n\ntype Node struct {\n x, y int\n}... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-24T19:05:42.233",
"Id": "18967",
"Score": "5",
"Tags": [
"algorithm",
"programming-challenge",
"matrix",
"search",
"go"
],
"Title": "Golang solution to Project Euler #81 (min... | 18967 |
<p>I have a method that contains a bunch of NSDictionaries (in fact, the only reason I have that method is to create those NSDictionaries). While I don't believe there are enough NSDictionaries initialized to visibly slow the code down as of yet, that is a good possibility in the future. I am currently just creating ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-04-20T22:55:10.783",
"Id": "39204",
"Score": "0",
"body": "Maybe this is sort of artificial (as perhaps you've simplified the code to show it here), but you have an ivar named `items` and a method named `items`. I would normally consider ... | [
{
"body": "<blockquote>\n <p>«Two or more, use a for»<br>\n — Edsger W. Dijkstra</p>\n</blockquote>\n\n<p>Okay, I am not using a for-loop, but an enumeration</p>\n\n<pre><code>NSArray *itemArray = @[\n @[@\"item1\",@\"item1-Icon\",@\"item1\"],\n @[@\"item2\",@\"item2-Icon\",@\"item2\"],\n @[@\"item3\... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-24T22:02:54.537",
"Id": "18971",
"Score": "2",
"Tags": [
"objective-c",
"hash-map"
],
"Title": "Is there a better way of showing multiple NSDictionaries?"
} | 18971 |
<p>JavaScript doesn't offer a module system. There are many third-party solutions, like <code>require.js</code> or jQuery's <code>$.getScript</code>. Most, while good, they bring dependencies, extra kbs and/or limit your folder structures. Sometimes it's necessary to make a .js file self-sufficient. This said, what is ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-24T22:04:14.460",
"Id": "30269",
"Score": "1",
"body": "Awful and should't be done, but http://www.phpied.com/javascript-include/"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-24T22:11:11.040",
"Id": ... | [
{
"body": "<p>Here is what I do:</p>\n\n<pre><code>var a_script= document.createElement('script');\na_script.src = 'http://www.blah.com/some_script.js';\ndocument.head.appendChild(a_script);\n</code></pre>\n\n<p>I should mention that in production I pretty much always combine all javascript files into one large... | {
"AcceptedAnswerId": "18980",
"CommentCount": "18",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-24T22:01:29.067",
"Id": "18973",
"Score": "4",
"Tags": [
"javascript",
"dom",
"http",
"modules"
],
"Title": "What is the shortest snippet that emulates `include` in JavaScrip... | 18973 |
<p>This implementation of range() is very fast:</p>
<pre><code>RANGE = []; for (var i=0; i<65536; ++i) RANGE.push(i-32768);
range = function(a,b){ return RANGE.slice(a+32768,b+32768); };
</code></pre>
<p>Are there downsides in using this approach?</p>
| [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-23T00:45:39.243",
"Id": "30286",
"Score": "0",
"body": "Why are you subtracting `32k`?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-23T00:46:33.843",
"Id": "30287",
"Score": "0",
"body": "@Ši... | [
{
"body": "<p>relatively speaking-</p>\n\n<p>1) its a bit heavy on the memory use, requiring the memory for a property + mem of a number for each integer in the possible range</p>\n\n<p>2) always consumes the memory and cpu needed to intialize, even if the script never has use for it.</p>\n",
"comments": [
... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-23T00:39:35.270",
"Id": "18975",
"Score": "0",
"Tags": [
"javascript",
"optimization"
],
"Title": "This JavaScript implementation of range is fast. What are it's downsides?"
} | 18975 |
<p>In SQL there is no way to do an "INSERT... SELECT". If you want to do it without using raw SQL in several places of your code you can create custom SQL compilation.</p>
<p>There is an example about how to do "INSERT...SELECT" in <a href="http://docs.sqlalchemy.org/en/rel_0_7/core/compiler.html#compiling-sub-element... | [] | [
{
"body": "<pre><code>columns.append(compiler.process(column, asfrom=True))\n</code></pre>\n\n<p>should be simply</p>\n\n<pre><code>columns.append(column.name)\n</code></pre>\n\n<p>and</p>\n\n<pre><code>table = compiler.process(element.insert_spec[0].table)\n</code></pre>\n\n<p>should be</p>\n\n<pre><code>table... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-24T22:55:26.473",
"Id": "18978",
"Score": "1",
"Tags": [
"python",
"sql"
],
"Title": "SQLAlchemy - InsertFromSelect with columns support"
} | 18978 |
<p>Here is a little interpreter I wrote for a simple stack-based language. It is my first attempt at a complete Haskell program, beyond glorified calculator use.</p>
<p>I'd like very much to get an expert's opinon on stylistic matters.</p>
<p>Also, although the thing runs fine, on a test program it seems to suffer fr... | [] | [
{
"body": "<ul>\n<li>Name of <code>Stack</code> type is misleading, you mean <em>Stack element</em>\n(<code>StackElt</code>), not a whole stack.</li>\n<li>Same for <code>withErrors</code>. <em>withX</em> is\nusually reserved for two or more argument function, such that the\nlast argument is function taking argu... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-24T23:17:22.297",
"Id": "18981",
"Score": "7",
"Tags": [
"haskell",
"interpreter"
],
"Title": "A stack-based language interpreter in Haskell"
} | 18981 |
<p>I've updated this question to be about code style only, as all of it's answered focused on this aspect. For the codes function, see <a href="https://codereview.stackexchange.com/questions/19153/review-c-algo-function">Randomizing and mutating algo class - functionality</a></p>
<p><code>algo</code> is an algorithm t... | [] | [
{
"body": "<p>For starters, code as written won't compile in GCC. :-(</p>\n\n<p><em>\"void main() is explicitly prohibited by the C++ standard and shouldn't be used\"</em></p>\n\n<p><a href=\"https://stackoverflow.com/questions/204476/what-should-main-return-in-c-c\">https://stackoverflow.com/questions/204476/... | {
"AcceptedAnswerId": "19001",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-25T00:26:23.190",
"Id": "18982",
"Score": "5",
"Tags": [
"c++",
"algorithm",
"search",
"random",
"simulation"
],
"Title": "Randomizing and mutating algo class - style"
} | 18982 |
<p>This is <a href="http://www.ict.kth.se/courses/IS1500/2012/nios2int/index.html" rel="nofollow">homework</a> for which we have prepared Nios 2 assembly:</p>
<pre><code>########################################
# Definitions of device-addresses
# and important constants.
#
# de2_pio_keys4 - 0x840
.equ keys4base,0x... | [] | [
{
"body": "<p>Macros in assembler language can be useful but you have to be careful not to\nover use them. Your <code>PUSH</code>/<code>POP</code> macros are overused and hence inefficient -\nand <strong>in interrupt related code, efficiency is king</strong>. </p>\n\n<p>For example your <code>PUSH</code> macr... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-25T01:49:51.817",
"Id": "18986",
"Score": "2",
"Tags": [
"c",
"assembly",
"embedded",
"trampoline"
],
"Title": "Nios 2 interrupt handler"
} | 18986 |
<p>I would like a fair minded critique of this code to get some feedback. I am not trying to re-invent the mold here, and I know there are plugins galore I could have used to do what I am doing here, but the point was to do it myself so that I can learn more and become better.</p>
<p>I have included comments to try an... | [] | [
{
"body": "<p>Here are some suggestions to simplify the syntax:</p>\n\n<ul>\n<li>For <code>pos</code>, use an array literal: <code>var pos = [0, 67, 133, 199, 267, 333]</code>\n<ul>\n<li>Similar thing for <code>compare</code>: <code>var compare = [];</code></li>\n</ul></li>\n<li>You're missing semi-colons after... | {
"AcceptedAnswerId": "18988",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-25T06:10:04.710",
"Id": "18987",
"Score": "0",
"Tags": [
"javascript",
"jquery"
],
"Title": "Wanted to write my own form slider, Jquery/JS"
} | 18987 |
<p>This is an iterative implementation of alpha beta tree search in C#. Please help me confirm the correctness of my code. <code>search()</code> is called when the search begins.</p>
<pre><code>int depth;
Func<board, int> value;
Func<board, List<string>> legalmoves;
Random randomgenerator = new Rand... | [] | [
{
"body": "<h3>Readability</h3>\n<p>The indentation is good and you have good variable names, but some of them are hard to read. Why? More or less because they're lowercase. <a href=\"http://msdn.microsoft.com/en-us/library/x2dbyw72(v=vs.71).aspx\" rel=\"nofollow noreferrer\">Variables and parameters should be ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-25T09:11:15.203",
"Id": "18989",
"Score": "2",
"Tags": [
"c#",
"tree",
"search"
],
"Title": "Iterative implementation of alpha beta tree search"
} | 18989 |
<p>I have this function definition which takes an r and applies the function <code>f</code> <code>n</code> times:</p>
<pre><code>r => (1 to n).foldLeft(r)((rx, _) => f(rx))
</code></pre>
<p>So for <code>n=3</code> this is equivalent to <code>f(f(f(r)))</code></p>
<p>I don't like this solution, because it defin... | [] | [
{
"body": "<p>What's wrong with straight recursion?</p>\n\n<pre><code>def ntimes[A](n:Int, f:A=>A, a:A):A = if (n==0) a else ntimes(n-1, f, f(a))\n</code></pre>\n\n<p>Another clean option is</p>\n\n<pre><code>Iterator.iterate(a)(f).drop(n).next\n</code></pre>\n",
"comments": [],
"meta_data": {
... | {
"AcceptedAnswerId": "18991",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-25T09:59:19.687",
"Id": "18990",
"Score": "5",
"Tags": [
"scala",
"functional-programming"
],
"Title": "Cleaner way for coding a repetitive application of a function"
} | 18990 |
<p>I'm new to C# and just tried the <a href="http://osherove.com/tdd-kata-1/" rel="nofollow">String Calculator Kata</a> for practice. What I like to know is if you (as more experienced C# programmers) have some suggestions for improvement with the end result (concerning readability, good practices, C# specific idioms ... | [] | [
{
"body": "<p>I think your answer was pretty well done. Really, for that test, you probably got near full marks. I know that wasn't much of an answer, but there really wasn't much to add to your code.</p>\n",
"comments": [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-25... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-25T11:21:57.843",
"Id": "18995",
"Score": "6",
"Tags": [
"c#",
"unit-testing",
"calculator"
],
"Title": "String calculator kata"
} | 18995 |
<p>I have written a simple VM in JavaScript and it interprets source code written in JSON.</p>
<p>The JSON object must have a "exports" property, which is a dictionary that matches a string into a integer value. This value is an index to "entries" property, which is an array of entries.</p>
<p>For each entry it conta... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-03-28T12:56:18.717",
"Id": "37748",
"Score": "0",
"body": "You mentioned 'move it to production', can you tell us what you are trying to solve? Is the JSON generated from yet another programming language?"
},
{
"ContentLicense": "... | [
{
"body": "<p>I have re-written the whole code to make it more modular as well as taking advantage of prototypes. The way your code was written was quite inefficient since everything had to be redefined for every newly created instances of <code>JsonVM</code> or <code>RunEngine</code>, since the whole code was ... | {
"AcceptedAnswerId": null,
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2012-11-25T12:23:43.043",
"Id": "18997",
"Score": "5",
"Tags": [
"javascript",
"json"
],
"Title": "A JavaScript VM that interprets code written in JSON"
} | 18997 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.