body stringlengths 25 86.7k | comments list | answers list | meta_data dict | question_id stringlengths 1 6 |
|---|---|---|---|---|
<p>Please review for readability.</p>
<pre><code>/*
Takes a screenshot of the current tab, then scales it to width and height.
Returns null if the tab is smaller than width and height.
Crops the screenshot to maintain aspect ratio.
Also crops the screenshot to avoid scaling down by more maximumScaleFactor.
*/
var GetC... | [] | [
{
"body": "<p>I'd break out that inner function - easier to see where it starts and ends.</p>\n\n<pre><code>/*\nTakes a screenshot of the current tab, then scales it to width and height.\nReturns null if the tab is smaller than width and height.\nCrops the screenshot to maintain aspect ratio.\nAlso crops the sc... | {
"AcceptedAnswerId": "39672",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-10T16:04:14.080",
"Id": "39012",
"Score": "0",
"Tags": [
"javascript",
"image"
],
"Title": "Screenshot-scaling code"
} | 39012 |
<p>Here's <a href="http://projecteuler.net/problem=451" rel="nofollow">Project Euler problem 451</a>: </p>
<blockquote>
<p>Consider the number \$15\$.
There are eight positive numbers less than \$15\$ which are coprime to \$15\$:
\begin{align*} 1, 2, 4, 7, 8, 11, 13, 14. \end{align*}
The modular inverses of th... | [] | [
{
"body": "<p>I'm not really sure I understand your code; it's not really organized in a way that aids readability. Use functions, so that I don't need to spend a minute or more reading the first few lines of the program to understand that they should be</p>\n\n<pre><code>def computePrimesUpTo(n):\n sieve = ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-10T17:52:16.903",
"Id": "39015",
"Score": "6",
"Tags": [
"python",
"performance",
"algorithm",
"programming-challenge",
"python-3.x"
],
"Title": "Performance of modular squar... | 39015 |
<p>I have a specific method that I like because it lets me decide whether or not I want to use the default. If I want anything different I enter in <code>:option => value</code> otherwise I get the default. Here's a concrete example that works, but is a little ugly.</p>
<p>How can I accomplish the same thing in a m... | [] | [
{
"body": "<p>You don't need the <code>||=</code> you can use <code>||</code>:</p>\n\n<pre><code>def connect_to_oracle( opts = {} )\n host_name = opts[:host_name] ||'a_default_host_name'\n db_name = opts[:db_name] || 'a_default_db_name'\n userid = opts[:userid] || 'a_default_userid'\n password = opts[:passw... | {
"AcceptedAnswerId": "39024",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-10T19:03:28.817",
"Id": "39017",
"Score": "29",
"Tags": [
"ruby"
],
"Title": "Setting defaults in a Ruby options hash"
} | 39017 |
<p>I've just complete a Pig Latin translator as a code kata and I was hoping someone would review it for me.</p>
<p>Here is the kata:</p>
<pre><code>PigLatin Kata
Create a PigLatin class that is initialized with a string
- detail: The string is a list of words separated by spaces: 'hello world'
- detai... | [] | [
{
"body": "<p>Good marks for:</p>\n\n<ul>\n<li>Formatting</li>\n<li>Naming</li>\n<li>Each spec tests just one thing</li>\n<li>Coverage of edge cases such as empty string.</li>\n</ul>\n\n<p>I think I would change the name from PigLatin to PigLatinTranslator. I can't think of a \"pig latin\" as a thing.</p>\n\n<... | {
"AcceptedAnswerId": "39028",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-10T19:27:40.807",
"Id": "39019",
"Score": "2",
"Tags": [
"ruby",
"rspec",
"pig-latin"
],
"Title": "Pig Latin Code Kata"
} | 39019 |
<ul>
<li>I want to first search for a specific regular expression.</li>
<li>If it is not found then I would like to search for another regular expression</li>
<li>If that one is also not found then I would like to search for a third</li>
<li>(And so on...)</li>
</ul>
<p>Whenever a matching regular expression is found,... | [] | [
{
"body": "<p>You could use the <code>(expression1|expression2|expression3)</code> syntax. It makes for a long string, but you won't have to nest.</p>\n",
"comments": [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-10T20:24:20.567",
"Id": "65279",
"Score"... | {
"AcceptedAnswerId": "39023",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-10T19:47:22.843",
"Id": "39020",
"Score": "13",
"Tags": [
"java",
"strings",
"regex"
],
"Title": "Recursive Regular Expressions"
} | 39020 |
<p>I'm trying to make a simple UI to better understand how interfaces and the <code>System.Windows.Forms</code> Controls behave.</p>
<p>Like the above namespace, I will be able to get and set the Focus on a particular control, with a helper method to drill down to see which Control (or child Control) actually has the ... | [] | [
{
"body": "<blockquote>\n <p>Here's what I have so far</p>\n</blockquote>\n\n<p>The code you wrote doesn't quite work properly; because, depending on the behaviour (which isn't clearly defined) of your <code>HasFocus</code> property:</p>\n\n<ul>\n<li>Either it will return too early (it returns immediately, if ... | {
"AcceptedAnswerId": "39036",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-10T20:52:29.987",
"Id": "39027",
"Score": "3",
"Tags": [
"c#",
"recursion",
"user-interface"
],
"Title": "Custom UI - Seeing which control has focus"
} | 39027 |
<p>I've been coding for a while, but this is the first actual project I've made. I generally do contest programming, and as you might imagine, good code practices are not exactly the top priority. I'd appreciate any pointers, whether overall design of the program, or variable naming, or things that I should have split ... | [] | [
{
"body": "<p>Ok a few things.</p>\n\n<p><em>JSHint</em></p>\n\n<p>First I'd run the code through <a href=\"http://www.jshint.com/\" rel=\"nofollow\">jshint</a> to conform to get some of the easy stuff out of the way. Depending on what editor you're using there are often plugins that will validate your JS with ... | {
"AcceptedAnswerId": "39085",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-11T01:10:54.570",
"Id": "39032",
"Score": "2",
"Tags": [
"javascript",
"jquery",
"google-chrome"
],
"Title": "Automated finals calculator in JavaScript/jQuery"
} | 39032 |
<p>I had an overloaded method, but Grails doesn't allow overloaded methods in controller actions. The overloaded method looked like this:</p>
<pre><code>def punch(User user, User source) {
user.userVersion++
punch(user, source, null, null)
}
def punch(User user, User source, String latitude, String longi... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-11T02:08:40.910",
"Id": "65293",
"Score": "0",
"body": "Shouldn't this also be tagged with the \"Groovy\" tag?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-11T03:00:19.127",
"Id": "65295",
"Score... | [
{
"body": "<p>If you use default parameters, you won't need to overload the function.</p>\n\n<pre><code>def punch(User user, User source, String latitude=null, String longitude=null)\n</code></pre>\n",
"comments": [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-11-17T08:02:... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-11T01:46:07.367",
"Id": "39033",
"Score": "2",
"Tags": [
"groovy",
"operator-overloading",
"grails"
],
"Title": "Grails overloaded controller workaround"
} | 39033 |
<p>I have been slowly getting more and more "at home" with Android development and I would like some guidance. I have made an app that uses a <code>ListActivity</code>, that attaches to an SQLite DB. I'm using the <code>onListItemClick</code> function to fire up a "single record view" where I can delete and edit the re... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-11T05:24:40.183",
"Id": "65304",
"Score": "0",
"body": "Do you think you could provide a little more context for what the app does? I think I understand most of what's going on, but it helps to have an explanation behind it."
},
{
... | [
{
"body": "<p>One of the tenets fo <a href=\"http://en.wikipedia.org/wiki/SOLID_%28object-oriented_design%29\" rel=\"nofollow\">SOLID programming</a> (the first one, in fact) is that classes should have a single responsibility.</p>\n\n<p>Here you have a class which has two distinct functions: view a card ; edit... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-11T02:28:10.810",
"Id": "39034",
"Score": "4",
"Tags": [
"java",
"android"
],
"Title": "Activity using multiple layouts"
} | 39034 |
<p>I'm working on a Project Euler problem and am trying to get the smallest prime factor of a <code>BigInteger</code>:</p>
<pre><code>private static BigInteger smallestPrimeFactor( BigInteger n ){
for( BigInteger i = new BigInteger("2"); n.compareTo(i) >= 0 ; i = i.add(BigInteger.ONE) ){
while( n.mod(i)... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-11T03:47:36.870",
"Id": "65298",
"Score": "0",
"body": "@boxed__l it will be prime, because the lowest factor is always prime ... if it was not prime, then the lowest prime-factor of the non-prime value would have been checked already"... | [
{
"body": "<p><code>BigInteger</code> should be compared using <code>compareTo()</code> rather than <code>==</code></p>\n\n<p>One optimization would be (search space):</p>\n\n<pre><code>private static BigInteger smallestPrimeFactor( BigInteger n ){\n BigInteger two=new BigInteger(\"2\");\n if(n.mod(two).... | {
"AcceptedAnswerId": "39039",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-11T03:16:25.580",
"Id": "39035",
"Score": "3",
"Tags": [
"java",
"project-euler",
"primes"
],
"Title": "Smallest prime factor of a large number (using BigInteger)"
} | 39035 |
<p>In our company we have a machine hostname as - </p>
<pre><code>dbx111.dc1.host.com
dbx112.dc2.host.com
dcx113.dc3.host.com
</code></pre>
<p>Here <code>dc1</code>, <code>dc2</code>, <code>dc3</code> are our datacenter and we will be having only three datacenter. But it might be possible that they can have more dot... | [] | [
{
"body": "<p>There are a few things which I think will simplify your code a lot, and it all centers around your Enum.</p>\n\n<p>Firstly, there is no need in your enum to have the <code>BY_CODE_MAP</code> system. Remove it. You can very efficiently (and with the identical results) use the method:</p>\n\n<pre><c... | {
"AcceptedAnswerId": "39053",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-11T05:32:56.847",
"Id": "39041",
"Score": "4",
"Tags": [
"java",
"optimization"
],
"Title": "Efficiently detect datacenter based on server hostname"
} | 39041 |
<p>I am studying Clojure and functional programming. I wrote this function to compute the centroid of a polygon specified as a vector of points, e.g. <code>[[10 20] [0 11] [50 30]]</code>).</p>
<p><a href="https://web.archive.org/web/20120722100030/http://paulbourke.net/geometry/polyarea/" rel="nofollow">Here you can... | [] | [
{
"body": "<p>You could replace the <code>dotimes</code>/<code>atom</code>s with more functional <code>loop</code>/<code>recur</code> recursion.</p>\n\n<pre><code>(defn centroid [p]\n (let [six*area (* 6 (polygon-area p))\n n (count p)\n first-vertex (p 0)\n polygon (co... | {
"AcceptedAnswerId": "39046",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-11T10:59:09.087",
"Id": "39045",
"Score": "4",
"Tags": [
"functional-programming",
"clojure",
"computational-geometry"
],
"Title": "Centroid of a polygon in Clojure"
} | 39045 |
<p>I am building a <a href="http://en.wikipedia.org/wiki/Webhook" rel="nofollow">Webhook</a> model so users can receive data from a messaging app.
I have never created such a system before, and I'd like to get some feedback on my attempt.</p>
<pre><code>$url = 'https://www.example.com/user-webhook-request.php';
$hands... | [] | [
{
"body": "<p>I'm not familiar with that pattern, but I'll see what I can comment on.</p>\n\n<ul>\n<li><code>$url</code> is not a good name. What kind of URL is it? What importantance does the page have?</li>\n<li>Is <code>$handshakeKey</code> an API key, or just some string that's checked on both ends? I'm ass... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-11T12:01:55.150",
"Id": "39047",
"Score": "2",
"Tags": [
"php",
"json",
"curl"
],
"Title": "Webhook Structuring"
} | 39047 |
<p>I have attempted the GUI controls creation in a prompt based on data from dictionary. Is this the best way of implementing this?</p>
<pre><code>import sys
from PyQt4 import QtCore, QtGui
class MessageBox(QtGui.QDialog):
"""docstring for MessageBox"""
def __init__(self, data=None, parent=None):
su... | [] | [
{
"body": "<p>This will work, but it may be hard to scale. At a minimum, I'd create a separate class for the work you're doing in the enumerate loop so that the dialog class is only concerned with populating a widget list and the details of what the widgets look like internally are handled in a class that just... | {
"AcceptedAnswerId": "39065",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-11T12:29:31.713",
"Id": "39048",
"Score": "3",
"Tags": [
"python",
"gui",
"pyqt"
],
"Title": "Dynamically generated controls based on data from dictionary"
} | 39048 |
<p>I would like to share a part of some code written several years ago (I have changed from mysql to mysqli); this code works perfectly. I am new to my company, and our senior programmers wrote some extra lines to optimize branch predictions. My question is: is it necessary to follow this code? Does it improve performa... | [] | [
{
"body": "<p>Performance tuning can be a strange thing sometimes. My instinct is to say that the explosion/implosion of the data will cost more than any branch-prediction benefits.</p>\n\n<p>Also, the only use of the sorted in clause is in the database itself... which should be efficient regardless of the orde... | {
"AcceptedAnswerId": "39050",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-11T12:50:36.877",
"Id": "39049",
"Score": "3",
"Tags": [
"php",
"optimization",
"mysql"
],
"Title": "Is code optimization for branch predictor necessary now?"
} | 39049 |
<p>Grails is a <a href="http://en.wikipedia.org/wiki/Convention_over_configuration" rel="nofollow">coding-by-convention</a> framework that leverages well-established <a href="/questions/tagged/java" class="post-tag" title="show questions tagged 'java'" rel="tag">java</a> frameworks (<a href="/questions/tagged/s... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-11T14:25:23.933",
"Id": "39051",
"Score": "0",
"Tags": null,
"Title": null
} | 39051 |
Web framework using the Groovy programming language. Groovy should also be tagged. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-11T14:25:23.933",
"Id": "39052",
"Score": "0",
"Tags": null,
"Title": null
} | 39052 |
<p>I'm doing a clock in javascript and I am not sure this way is the best way to rotate the pointers. </p>
<p>Is this ok, or is there a better way?</p>
<pre><code>// browser vendors
var browsers = [
'webkit',
'Moz',
'ms',
'O',
''];
// function to move the pointers
function moveMe(el, unit) {
... | [] | [
{
"body": "<p>First of all, your code use <code>Array.each()</code> method, which is a non-standard Javascript method, added by Mootools. I would rather use a standard loop, in order to keep a <em>vanilla</em> JS code.</p>\n\n<p>Then, instead of setting all properties every time, you should test which propertie... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-11T18:22:30.233",
"Id": "39057",
"Score": "2",
"Tags": [
"javascript",
"css"
],
"Title": "Rotate image via javascript using CSS"
} | 39057 |
<p>I wrote a simple emacs module that generates standard templates that I use for my blog's static site generator.</p>
<pre class="lang-lisp prettyprint-override"><code>(defun hakyll-site-location ()
"Return the location of the Hakyll files."
"~/Sites/hblog/")
(defun hakyll-new-post (title tags)
"Create a new H... | [] | [
{
"body": "<h2>DRY-ing it up:</h2>\n\n<p>It looks like variation is in:</p>\n\n<ul>\n<li>how the filename is obtained</li>\n<li>the contents of the inserted text</li>\n<li>the name of the file to write to.</li>\n</ul>\n\n<p>Also note that if <code>format</code> is given extra arguments not needed by its format-... | {
"AcceptedAnswerId": "39063",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-11T19:17:30.750",
"Id": "39059",
"Score": "5",
"Tags": [
"template",
"elisp"
],
"Title": "Emacs module that generates templates for my blog's static site generator"
} | 39059 |
<p>I have tried to design a class for a <a href="http://en.wikipedia.org/wiki/Complete_graph" rel="nofollow">complete graph</a>.</p>
<p>Needless to say, disadvantages of my current solution are very visible:</p>
<ul>
<li><p>dependent inputs have led to verification headaches.</p>
<p>In this code we rely on 2 inputs ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-12T01:39:07.090",
"Id": "65373",
"Score": "0",
"body": "Why was this code marked negative ? I am looking for suggestions is this out of place ?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-12T04:30:13.22... | [
{
"body": "<p>I think you expect addNodes to be called exactly once, and expect it to be called before any other method.</p>\n\n<p>Therefore, remove the addNodes method, and move the <code>Set<T> nodes</code> parameter to the constructor.</p>\n\n<p>The next thing you want to do is define all edges. To do ... | {
"AcceptedAnswerId": "39090",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-11T22:51:35.717",
"Id": "39064",
"Score": "6",
"Tags": [
"java",
"exception-handling",
"graph"
],
"Title": "Code to construct a complete graph"
} | 39064 |
<p>I'm very new to C, so pointing out better ways of doing things, errors, bad practices, etc would be optimal at this stage.</p>
<p><a href="https://github.com/brandonwamboldt/projects/blob/master/fibonacci/fib.c">Code on GitHub</a></p>
<pre><code>#include <stdio.h>
#include <stdlib.h>
int *calculateFib... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-14T00:26:33.143",
"Id": "65615",
"Score": "0",
"body": "Since you're just printing the numbers, what is your original task: to print them or to compute them in an array?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate... | [
{
"body": "<p>You C is very good. Just a few comments:</p>\n\n<p>The <code>start</code> parameter is pointless. Just print the whole sequence.</p>\n\n<p>Don't allocate memory until you know your parameters are valid. Else you have\na memory leak.</p>\n\n<p>You don't check that the <code>numbers[]</code> arra... | {
"AcceptedAnswerId": "39068",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-11T23:45:43.960",
"Id": "39066",
"Score": "13",
"Tags": [
"c",
"beginner",
"fibonacci-sequence"
],
"Title": "Fibonacci sequence in C"
} | 39066 |
<p>I have a naming problem: lists with un-named elements. I wish to get the names of the elements in the list, without going back upstream to where the list was created. An example is <code>modelList</code> below:</p>
<pre><code>## naming problem
lmNms <- c( "mod1", "mod2", "mod3", "mod4", "mod5", "mod6")
lapply(l... | [] | [
{
"body": "<p>You could have used <code>identical</code> to compare objects. However, I would recommend representing all objects by their MD5 digests, so you can then use <code>match</code> to find the matches:</p>\n\n<pre><code>nameListObjects <- function(LIST, ENV = NULL, NAMES.ONLY = FALSE) {\n\n if(is.n... | {
"AcceptedAnswerId": "39072",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-12T00:47:05.547",
"Id": "39069",
"Score": "2",
"Tags": [
"r"
],
"Title": "finding names of un-named list elements"
} | 39069 |
<p>Not long ago, I posted <a href="https://codereview.stackexchange.com/questions/38085/dynamic-stack-implementation">this dynamic stack</a> for review. Now I wrote a new version, which is hopefully a better one.</p>
<p>Please take a look and let me know how I could improve performance and increase code quality.</p>
... | [] | [
{
"body": "<p>Sorry, but I really don't like the use of raw <code>void*</code> and pointer arithmetic\neverywhere. The whole code would be simpler if you added a <code>typedef</code>:</p>\n\n<pre><code>typedef void* Slot;\n</code></pre>\n\n<p>and globally replace <code>void *</code> with <code>Slot</code></p>\... | {
"AcceptedAnswerId": "39317",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-12T04:34:25.220",
"Id": "39075",
"Score": "3",
"Tags": [
"c",
"performance",
"stack"
],
"Title": "Dynamic stack in C - new version"
} | 39075 |
<p>I am new to C++ and would like to know the most efficient way of forcing a user to enter an integer. Here is my function that I have created. Please show me the best way and explain why it's better than this.</p>
<pre><code>int getInt(){
int x;
while (true){
cout << "Enter an int." << en... | [] | [
{
"body": "<p>Your method isn't safe. If it receives a floating-point-number as an input or strings like <code>4vfdrefd</code>, it will not leave the buffer empty.</p>\n\n<p>It's pretty elegant to use <code>std::getline</code> to get the input, specially if you want to read some other types as an integer.</p>\n... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-12T05:26:06.983",
"Id": "39076",
"Score": "4",
"Tags": [
"c++",
"beginner",
"stream"
],
"Title": "Forcing user to enter an integer"
} | 39076 |
<p>I wrote this function for <a href="http://projecteuler.net/problem=1" rel="nofollow">Project Euler Problem 1</a>. </p>
<pre><code>prob001 :: (Integral a) => [a] -> [a] -> a
prob001 a b = sum [x | x <- a, product ( map (x `rem`) b ) == 0]
</code></pre>
<p>The use is like this</p>
<pre><code>GHCi> pr... | [] | [
{
"body": "<p>I think that <code>any</code> is your friend here.</p>\n\n<pre><code>aMultipleOf factors x = any (\\f -> x `rem` f == 0) factors\nprob001 :: (Integral a) => [a] -> [a] -> a\nprob001 nums factors = sum $ filter (aMultipleOf factors) nums\n</code></pre>\n",
"comments": [],
"meta_... | {
"AcceptedAnswerId": "39101",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-12T07:44:57.877",
"Id": "39079",
"Score": "4",
"Tags": [
"beginner",
"haskell",
"project-euler"
],
"Title": "Project Euler Problem 1 - Multiples of 3 and 5"
} | 39079 |
<p>I know that there is one more topic about the exercise 4-11, but the difference is that I solved this exercise and i just need some feedback on my solution. So, I'll explain how it works on an output like "3 4 +\n", for example. The static variable c is initialized with the value ' ' so the condition of the first if... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-12T12:56:10.043",
"Id": "65406",
"Score": "2",
"body": "In case anyone else is wondering, getop is being used to collect the next character or numeric operand. Here's the exercise: Modify getop so that it doesn't need to use ungetch. H... | [
{
"body": "<p>Comments on <code>getop()</code> only:</p>\n\n<p>Your initial loop repeats the exit condition twice. It (and subsequent code)\nalso contains double assignments, which are unnecessary and generally better\navoided:</p>\n\n<pre><code>if((s[0] = c) == ' ' || c == '\\t') {\n while((s[0] = c = getc... | {
"AcceptedAnswerId": "39248",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-12T08:26:53.513",
"Id": "39081",
"Score": "3",
"Tags": [
"c",
"parsing",
"static"
],
"Title": "feedback for exercise 4-11 in K&R"
} | 39081 |
<p>In several places, I have some code that looks like the following, the only difference is in the type of listener.</p>
<pre><code>public class CustomFragment extends android.app.Fragment {
SomeListener listener;
@Override
public void onAttach(android.app.Activity activity) {
super.onAttach(acti... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-12T14:15:26.663",
"Id": "65411",
"Score": "0",
"body": "I don't understand yourproblem but, instead of having a type converter, should CustomerFragment be a Generic class, whose type variable is the type of SomeListener (so that a spec... | [
{
"body": "<p>It seems to me like what you have done here is to create an entire class to avoid duplicating one line. (Or OK, 5 lines if counting the try-catch statement)</p>\n<p>I don't agree with the need to create a class for this. Especially not a generic one, since this line of code:</p>\n<pre><code>return... | {
"AcceptedAnswerId": "39096",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-12T12:55:44.713",
"Id": "39091",
"Score": "7",
"Tags": [
"java"
],
"Title": "Class for typecasting an Activity to an interface"
} | 39091 |
<p>I'm a Java/C coder getting started with some Python for a side-project. I've written some unit tests for a recent side-project I'm working on, but I have a sinking suspicion I'm just writing Java-code, translated into Python.</p>
<p>I've posted a small sample of some unit-tests I wrote. I'd really appreciate any ... | [] | [
{
"body": "<p>I have a few nitpicks:</p>\n\n<ul>\n<li>If you use <code>assertFalse</code> and <code>assertTrue</code> instead of <code>assertEquals(something, True/False)</code> where appropriate, the output of your unit tests will make more sense when they fail. (<a href=\"http://docs.python.org/2/library/unit... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-12T15:17:10.107",
"Id": "39092",
"Score": "12",
"Tags": [
"python",
"unit-testing"
],
"Title": "Unit test best-practices in Python"
} | 39092 |
<p>I think my code works pretty well, although I'm biased: <a href="http://jsfiddle.net/AHKb4/2/" rel="nofollow noreferrer">http://jsfiddle.net/AHKb4/2/</a></p>
<p><em><strong>Basic Overview:</strong> I'm working on building a math skill game, where the objective is to drag and drop div's to a container. Each div will ... | [] | [
{
"body": "<p>Assumptions I made:</p>\n\n<ul>\n<li>The <code>3</code> object will have 3 arrays, just as the <code>67</code> object will have 67 arrays</li>\n<li>The \"combined\" array can be computed on demand</li>\n<li>Each call to <code>pickNumbers</code> for a certain object will always have the same parame... | {
"AcceptedAnswerId": "39099",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-12T15:29:43.543",
"Id": "39093",
"Score": "4",
"Tags": [
"javascript",
"game"
],
"Title": "Math Skills Game Advice"
} | 39093 |
<p>For the code sample that I am asked to submit with most of my job applications (usually Gameplay Programmer), I created this console application in which I attempt to figure out what is the best loadout for a mech to win a match within the simple turn-based combat system that I came up with. Since I will submit this... | [] | [
{
"body": "<p><strong><code>#include</code>s:</strong></p>\n\n<ul>\n<li><s><code><time.h></code> is a C library; use <code><ctime></code> instead.</s></li>\n<li>Consider omitting <code><conio.h></code> as there could be some portability issues. It's also not widely used in C++, especially sin... | {
"AcceptedAnswerId": "39098",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-12T19:22:52.543",
"Id": "39097",
"Score": "7",
"Tags": [
"c++",
"c++11",
"ai"
],
"Title": "'Evolutionary AI' implementation"
} | 39097 |
<p>I have just started learning how to build websites, and I have been experimenting by creating a contact form.</p>
<p>Here is what I currently have - can anyone suggest and recommend ways enhance my current contact form system? </p>
<p><strong>JavaScript:</strong></p>
<pre><code>$("#contactForm").submit(function (... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2016-04-08T17:43:25.237",
"Id": "233539",
"Score": "0",
"body": "[Follow up Question](http://codereview.stackexchange.com/questions/39455/is-this-contact-form-secure)"
}
] | [
{
"body": "<h1>Php</h1>\n\n<p>I'm not a big Php guy so I can't be too thorough in this section. The biggest thing is that you seem to be writing ... well ... a php script. While that absolutely works it's incredibly old-school and doesn't do anything as far as guiding you into the pit of success. So first bit o... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-12T21:47:02.530",
"Id": "39103",
"Score": "5",
"Tags": [
"javascript",
"php",
"jquery",
"html",
"ajax"
],
"Title": "PHP e-mail contact form with AJAX"
} | 39103 |
<p>I am writing code to do some numerical task using the routines of the book <em>Numerical Recipes</em>. One of my objectives is to calculate the second derivative of a function and have a routine that calculates the first derivative of a function in a nice manner within a specified accuracy. However, I would like to ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-12T23:36:00.390",
"Id": "65445",
"Score": "0",
"body": "What is `h`? This seems like an important piece of information."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-13T01:45:50.050",
"Id": "65465",
... | [
{
"body": "<p>If you need compile-time controlled order of derivation you probably should play with C++ templates.<br>\nIf you need run-time (i.e. write own calculator) you'll need to extend that <code>dfridr</code> function (use same approximation of derivation).</p>\n\n<p>Naive implementation and modification... | {
"AcceptedAnswerId": "39120",
"CommentCount": "13",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-12T22:51:09.477",
"Id": "39106",
"Score": "4",
"Tags": [
"c",
"recursion",
"numerical-methods"
],
"Title": "Recursive calculation of second order derivative"
} | 39106 |
<p>Two integers <em>a</em> and <em>b</em> are relatively prime if and only if there are no integers:</p>
<blockquote>
<p>x > 1, y > 0, z > 0 such that a = xy and b = xz.</p>
</blockquote>
<p>I wrote a program that determines how many positive integers less than <code>n</code> are relatively prime to <code>n</code>.... | [] | [
{
"body": "<p>In order to determine whether two numbers are co-prime (relatively prime), you can check whether their <em>gcd</em> (greatest common divisor) is greater than 1.\nThe <em>gcd</em> can be calculated by Euclid's algorithm:</p>\n\n<pre><code>unsigned int gcd (unsigned int a, unsigned int b)\n {\n ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-12T23:31:22.490",
"Id": "39109",
"Score": "3",
"Tags": [
"c++",
"performance",
"primes"
],
"Title": "Relative prime numbers"
} | 39109 |
<p>I've been coding in a vacuum for several years and am trying to get up to speed on best practices, in anticipation of my eventual return to employment. I'm hoping this is the best forum in which to ask these types of questions. If not, please let me know.</p>
<p>My first question regards assigning the initial value... | [] | [
{
"body": "<p>I would recommend to use one common method for initialization of all the variables, constants, <code>NSUserDefault</code>s, etc.. </p>\n\n<p><code>viewDidLoad</code> should not be messy, it should mostly have calls to the methods.\nI believe you are all aware with code reusability and code optimiz... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-12T23:57:47.177",
"Id": "39111",
"Score": "5",
"Tags": [
"objective-c",
"ios"
],
"Title": "Assigning initial value via getter or viewDidLoad"
} | 39111 |
<p>When a button is pressed, an animation loop is triggered. At the start of the loop, I create a new time object.</p>
<p>I also have a pause button. A problem was created when paused and then started as the <code>Date</code> object would be recreated each time.</p>
<p>The variable is global and not defined to be a... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-13T02:12:20.997",
"Id": "65468",
"Score": "0",
"body": "You want us to review 2 lines of code?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-13T02:24:38.107",
"Id": "65469",
"Score": "0",
"bod... | [
{
"body": "<p>I can think of the following improvements:</p>\n\n<ol>\n<li>Hide <code>t</code>. If you're running other JS modules, you can't really be sure that no-one else writes to the same variable.</li>\n<li>If you want to be sure that your code doesn't mix up an uninitialized timer with a \"cleared\" timer... | {
"AcceptedAnswerId": "39137",
"CommentCount": "7",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-13T00:51:43.910",
"Id": "39117",
"Score": "2",
"Tags": [
"javascript",
"beginner",
"html5",
"datetime"
],
"Title": "Better way to check if Javascript Date object exists"
} | 39117 |
<p>I'm moderately new to programming in C and I'm not sure about programming practices with code; suddenly I have had fears that my code is messy and disorganized. I can read it when I come back a month later yet I'm still nervous if I'm doing anything that's considered taboo.</p>
<p>This isn't all the code that I've ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-13T08:22:56.613",
"Id": "65477",
"Score": "0",
"body": "Could you also include the corresponding header file?"
}
] | [
{
"body": "<ol>\n<li><p>In C the naming conventions typically are <code>lower_case_with_underscore</code> for function names and types (although for types some people also use <code>PascalCase</code>). <code>UPPERCASE</code> is only really used for macro definitions.</p></li>\n<li><p>In <code>CONNECTION_INIT</c... | {
"AcceptedAnswerId": "39134",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-13T06:00:13.067",
"Id": "39122",
"Score": "6",
"Tags": [
"c",
"mysql"
],
"Title": "Is my MySQL library wrapper neat? How can I do better?"
} | 39122 |
<p>I am working on a project in which I am supposed to make synchronous and asynchronous behavior of my client.</p>
<p>The customer will call our client with a <code>userId</code> and we will construct a URL from that <code>userId</code> and make an HTTP call to that URL and we will get a JSON string back after hittin... | [] | [
{
"body": "<p>This looks good. A synchronous call is always an async call plus a wait for the result. To make that clear, <code>execute()</code> should probably call <code>executeAsync()</code> instead of <code>getHandle()</code>.</p>\n",
"comments": [],
"meta_data": {
"CommentCount": "0",
... | {
"AcceptedAnswerId": "41299",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-13T06:11:48.850",
"Id": "39123",
"Score": "9",
"Tags": [
"java",
"multithreading",
"thread-safety"
],
"Title": "Synchronous and asynchronous behavior for client"
} | 39123 |
<p>I was not sure if I should post about 200 lines here. I want to make this ant simulation faster. The bottleneck is at <code>Ant.checkdistancebetweenantsandfood()</code>.</p>
<p>It would be great if you have some hints for some cleaner or more efficient code. I hope this is the right place to show this code.</p>
<p... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-13T09:43:51.693",
"Id": "65488",
"Score": "1",
"body": "Have you tried the \"slower\" code without calling `np.sqrt()`? (In other words, work using the square of the distance.)"
},
{
"ContentLicense": "CC BY-SA 3.0",
"Creat... | [
{
"body": "<p>It looks like you're looping through the ants twice, once inside checkdistancebetweenantsandfood() and once when you call it. That seems like it's probably wrong.</p>\n\n<p>Method:</p>\n\n<pre><code> def checkdistancebetweenantsandfood(self):\n for name in ants.keys():\n for i in rang... | {
"AcceptedAnswerId": null,
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-13T06:42:47.927",
"Id": "39124",
"Score": "3",
"Tags": [
"python",
"performance",
"numpy",
"simulation"
],
"Title": "How can I make my ant simulation faster?"
} | 39124 |
<p>I have issues with dynamically typed languages, and I tend to worry about type a lot.</p>
<p>Numpy has different behaviour depending on if something is a matrix or a plain ndarray, or a list. I didn't originally have all these asserts, but I inserted them while trying to debug a type error.</p>
<pre><code>from nu... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-13T14:23:20.240",
"Id": "65509",
"Score": "0",
"body": "The key point is that a compiler's static type checking is a kind of test, but an incomplete one (otherwise statically typed languages would have no bugs). In a dynamically typed... | [
{
"body": "<p>First, I recommend avoiding the <code>matrix</code> type altogether. The problems it causes outweighs the minor syntactical convenience it provides, in my (and quite a few others') opinion.</p>\n\n<p>Second, the idiomatic way to do this kind of thing in numpy is not to assert that the inputs are p... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-13T07:51:32.283",
"Id": "39125",
"Score": "5",
"Tags": [
"python",
"numpy",
"matrix",
"machine-learning",
"assertions"
],
"Title": "Defensive programming type-checking"
} | 39125 |
<p>Is there any way to reduce total execution time for the function <code>getSilhouetteIndex</code>? P.S. I am using <code>weka SimpleKMeans</code> for getting kmeans and <code>ceval</code>.</p>
<pre><code>private double getSilhouetteIndex(List<ITSPoI> _POIs, SimpleKMeans kmeans, ClusterEvaluation ceval)
{
d... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-13T18:49:36.407",
"Id": "65560",
"Score": "0",
"body": "I might be stupid but what **does** this method? What is a `ITSPoI`, what is `SimpleKMeans` and what is `ClusterEvaluation`. To me, you haven't provided much [context](http://meta... | [
{
"body": "<p>There are <a href=\"http://www.movable-type.co.uk/scripts/latlong.html\" rel=\"nofollow\">three methods</a> for computing a great circle distance between two points that are specified by latitude and longitude:</p>\n\n<ol>\n<li>You used the <a href=\"http://en.wikipedia.org/wiki/Spherical_law_of_c... | {
"AcceptedAnswerId": "39142",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-13T10:19:15.350",
"Id": "39133",
"Score": "2",
"Tags": [
"java",
"performance",
"mathematics",
"computational-geometry",
"floating-point"
],
"Title": "How to reduce execut... | 39133 |
<p>Based on the advice provided in <a href="https://codereview.stackexchange.com/questions/39097/how-can-i-improve-this-c-evolutionary-ai-implementation">my previous question</a>, I would like to post the other source file that actually implements all the combat mechanics and also the actual evolution process. </p>
<p... | [] | [
{
"body": "<p>Don't like all the switches (I suppose you are doing it for speed (doubt it makes a difference)).</p>\n\n<p>I would a couple of tests to see if using switches actually does make a significant difference, compared to virtual functions in terms of speed in your use case scenarios.</p>\n\n<p>But it (... | {
"AcceptedAnswerId": "39169",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-13T11:24:34.200",
"Id": "39141",
"Score": "7",
"Tags": [
"c++",
"c++11",
"ai"
],
"Title": "Follow-up: C++ 'evolutionary AI' implementation"
} | 39141 |
<p>The exercise is explained in the comments. Do you have any suggestion? </p>
<pre><code>package com.atreceno.it.javanese.attic;
import java.io.BufferedReader;
import java.io.FileReader;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Co... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-11-26T15:39:46.837",
"Id": "129631",
"Score": "0",
"body": "[What you can and cannot do after receiving answers.](http://meta.codereview.stackexchange.com/questions/1763/for-an-iterative-review-is-it-okay-to-edit-my-own-question-to-includ... | [
{
"body": "<p>Your code is really good and very well written. I think that's why you haven't received a response; not much to critique! You have good comments, good style, pretty much good everything. I wish I saw code like this in my production environment.</p>\n\n<p>The only thing I noticed that you might ... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-13T12:25:56.747",
"Id": "39143",
"Score": "7",
"Tags": [
"java"
],
"Title": "Fragments of paper"
} | 39143 |
<p>Asserts work differently in different langauges, and there are different variants of them in testing libraries. But the commonality of them all is that if the predicate passed to it evaluates as false then the user will be notified of this fact, sometimes by program termination.</p>
| [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-13T12:38:47.480",
"Id": "39145",
"Score": "0",
"Tags": null,
"Title": null
} | 39145 |
An assertion is a predicate (a true–false statement) placed in a program to indicate that the developer thinks that the predicate is always true at that place. If an assertion evaluates to false at run-time, an assertion failure results, which typically causes execution to abort. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-13T12:38:47.480",
"Id": "39146",
"Score": "0",
"Tags": null,
"Title": null
} | 39146 |
<p>I am practicing my recursion skills as I think I am really weak in this area.</p>
<p>I have written the following Java class whose purpose is to reverse a string but to do it 'in-place' - i.e. no additional arrays. I have two implementations - one iterative and one recursive. Why would I choose one implementation o... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-13T15:57:19.127",
"Id": "65523",
"Score": "0",
"body": "The JVM doesn't support full TCO and javac doesn't even attempt the partial TCO simulation that Scala uses. Java is not a good language to use recursion in."
},
{
"Conten... | [
{
"body": "<p>In this case Iteration is preferable.</p>\n\n<p>If your input string would cause StackOverflowError exceptions.\nBesides, iteration would be much faster because it does not require the overhead of creating a stack frame with the parameters, calling the function, and returning the value. Since Jav... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-13T12:44:23.447",
"Id": "39147",
"Score": "8",
"Tags": [
"java",
"optimization",
"recursion",
"iteration"
],
"Title": "Reversing a string in-place - recursion or iteration?"
} | 39147 |
<p>Visual Studio somehow optimizes the below code to be 20 times faster (release with optimization vs. release with no optimization). What could it be doing?</p>
<pre><code>for (unsigned n = 1; n != units.size(); n++)
for (unsigned j = 0; j != (units.size() - n); j++)
{
unsigned sizesMap[11... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-13T14:04:46.673",
"Id": "65505",
"Score": "0",
"body": "is it intentional that `sizesMap[0]` is untouched in the inner loop?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-13T15:40:07.213",
"Id": "6551... | [
{
"body": "<p>Educated guesses are: in this case, <a href=\"http://en.wikipedia.org/wiki/Loop_unwinding\" rel=\"nofollow noreferrer\">loop unrolling</a> will probably feature in a big way, and may account for most of the 20X improvement. Additionally, with the loop unroll it may make other things like <a href=\... | {
"AcceptedAnswerId": null,
"CommentCount": "8",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-13T12:56:17.910",
"Id": "39148",
"Score": "2",
"Tags": [
"c++",
"performance",
"vectors",
"iteration"
],
"Title": "Optimizing a vector loop"
} | 39148 |
<p>I've a application which runs with two threads. The main thread runs in one infinity-while-loop:</p>
<pre><code>while (true) {
try {
ArrayList<Info> infoList = zabbixHandler.APIRequest();
handleInfo.handleInformation(infoList);
Thread.sleep(5000);
}
}
</code></pre>
<p>The second thre... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-13T14:25:41.403",
"Id": "65510",
"Score": "0",
"body": "please provide the actual code inside the second code block."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-13T15:07:03.120",
"Id": "65514",
... | [
{
"body": "<p>don't use a busy wait but instead use a wait condition (here using the built-in monitor in Object):</p>\n\n<pre><code>public void run() {\n while(true){\n while(!finished){\n // do stuff\n }\n try{\n synchronized(this){\n while(finished)\n ... | {
"AcceptedAnswerId": "39155",
"CommentCount": "8",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-13T14:04:27.307",
"Id": "39152",
"Score": "4",
"Tags": [
"java",
"performance",
"multithreading"
],
"Title": "Decrease CPU usage in while loop"
} | 39152 |
<p>I am working on a haskell exercise where I have to compute the amount of people riding a rollercoaster in a day. I have the following data: the number of rides in a day, the number of seats, and the composition of the queue.</p>
<p>The queue is a list of groups. During each ride, the first few groups of the list e... | [] | [
{
"body": "<p>So I found a few improvements which solve my problem. First, I used a vector to represent the queue, and a rolling index to store the head of the queue:</p>\n\n<pre><code>type Queue = V.Vector Int\ndata RollingQ = RollingQ Queue Int\n\ncurrentVal :: RollingQ -> Int\ncurrentVal (RollingQ v i) = ... | {
"AcceptedAnswerId": "39301",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-13T14:31:05.620",
"Id": "39157",
"Score": "2",
"Tags": [
"optimization",
"haskell"
],
"Title": "optimizing a rollercoaster queue"
} | 39157 |
<p>I would like to test the following garbage collector code on a database of sessions.
It should be following the conditions below:</p>
<ul>
<li>if 'remember me' is enabled by the user, then it should delete all rows which are not active within 2 weeks.</li>
<li>if 'remember me' is disabled by the user, then it shoul... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-19T19:48:55.440",
"Id": "72645",
"Score": "0",
"body": "This probably belongs on StackOverflow."
}
] | [
{
"body": "<h3>Observations</h3>\n\n<ul>\n<li>Your <code>$maxlifetime</code> parameter is unused.</li>\n<li>One of the conditions is redundant: any session older than two weeks should be discarded unconditionally.</li>\n<li>The capitalization of your column names is unconventional. Usually, identifiers are <co... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-13T16:39:05.827",
"Id": "39161",
"Score": "2",
"Tags": [
"php",
"mysql",
"datetime",
"session"
],
"Title": "Update SQL query using UNIX time"
} | 39161 |
<p>I've been playing around with inheritance in JavaScript and I'm wondering if there are any drawbacks to this method which tries to emulate classical inheritance from C-based languages.</p>
<pre><code>Function.prototype.extends = function (parentClass) {
function temp () { this.constructor = this; };
temp.pr... | [] | [
{
"body": "<p>Observations:</p>\n\n<ul>\n<li>You changed the Function prototype, which is generally considered bad practice.</li>\n<li>The inheritance does work, <code>instanceof</code> checks work fine</li>\n<li><p>I do not see how it emulates classical inheritance better than this:</p>\n\n<pre><code>var Cat =... | {
"AcceptedAnswerId": "39480",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-13T17:08:41.393",
"Id": "39162",
"Score": "2",
"Tags": [
"javascript",
"inheritance"
],
"Title": "Classical inheritance in JavaScript"
} | 39162 |
<p>I have the following code to load an enumeration into a bound combo box, but am not quite happy with it. </p>
<p>I would prefer to store the actual <code>enum</code> value in the combo box and bind directly to it.
However, I can't quite figure out how to do so.</p>
<pre><code> public enum HemEnum
{
Hem... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-13T22:32:24.447",
"Id": "65600",
"Score": "0",
"body": "I've got a custom class devoted to solving this [over here](http://stackoverflow.com/questions/15557999/binding-to-enums/15558108#15558108). All the advice below is good advice, ... | [
{
"body": "<p>The easiest way to accomplish what you want is to create a list of the possible enum values and data bind that list to the combo box. You can do this through the designer (under Data) or with the following code:</p>\n\n<pre><code>cboHem.DataSource = enumList;\n</code></pre>\n\n<p>With an enum, it... | {
"AcceptedAnswerId": "39168",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-13T17:50:27.860",
"Id": "39163",
"Score": "13",
"Tags": [
"c#",
"algorithm",
"winforms",
"enum"
],
"Title": "Loading a combobox with an enum and binding to it"
} | 39163 |
<p>I have a class <code>Creator</code> which will execute a block code for a number of times. I'm not sure how to write this in a more elegant way in Ruby.</p>
<pre><code>class Creator
attr_accessor :block
def self.create(&block)
@block = block
return self
end
def self.for(number)
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-14T11:16:23.990",
"Id": "65655",
"Score": "1",
"body": "I am sure you have your reasons, but what about `30.times { SomeModel.create!(@attr) }`."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-14T11:25:49.7... | [
{
"body": "<p>With <code>attr_accessor :block</code> you define a accessor for an instance.</p>\n\n<p>You may use the variable <code>@block</code> directly:</p>\n\n<pre><code>class Creator\n def self.create(&block)\n @block = block\n return self\n end\n\n def self.for(number)\n ... | {
"AcceptedAnswerId": "39182",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-13T18:30:59.123",
"Id": "39166",
"Score": "3",
"Tags": [
"ruby",
"ruby-on-rails"
],
"Title": "How to write save block code like this more elegant in Ruby?"
} | 39166 |
<p>I've written a small <a href="https://github.com/r-darwish/gameoflife" rel="nofollow">Game of Life</a> module in Haskell, as well as a small testing application. I'm relatively new to the language, so any kind of comment about the code is welcome. The most important comments for me are comments about efficiency of t... | [] | [
{
"body": "\n\n<h3>First of all you should consider how you represent your board.</h3>\n\n<ul>\n<li>Using <code>Array</code> with two-dimension index (<code>Ix</code>) would be a good choice for the way you work right now. You define value for each cell individually no matter what is in that cell.</li>\n<li>Alt... | {
"AcceptedAnswerId": "39177",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-13T19:00:17.627",
"Id": "39170",
"Score": "7",
"Tags": [
"beginner",
"haskell",
"game-of-life"
],
"Title": "Game of Life implementation in Haskell"
} | 39170 |
<p>As <code>xts</code> objects are arrays, getting apply functions to work is a little tricky if you want to preserve the dates. For example, take the <code>xts</code> object <code>xx</code> below: </p>
<pre><code>xx <- xts(replicate(6, sample(c(1:10), 10, rep = T)),
order.by = Sys.Date() + 1:10)
</code>... | [] | [
{
"body": "<p>You can use the function <code>vapply</code>. The help page of <code>?vapply</code> says:</p>\n\n<blockquote>\n <p>vapply is similar to sapply, but has a pre-specified type of return\n value, so it can be safer (and sometimes faster) to use.</p>\n</blockquote>\n\n<p>You can use</p>\n\n<pre><code... | {
"AcceptedAnswerId": "39212",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-13T20:36:37.063",
"Id": "39180",
"Score": "4",
"Tags": [
"performance",
"r"
],
"Title": "best way to apply across an xts object"
} | 39180 |
<p>So I wrote this function to convert a given number to its interpretation in the English language as part of the <a href="http://projecteuler.net/problem=17" rel="nofollow">Project Euler exercises</a>. It works fine, but I sense that it's rather sloppy and inelegant, especially for Python where many things can be do... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-13T21:48:01.937",
"Id": "65589",
"Score": "0",
"body": "\"And\" is normally reserved for writing out fractions. 13,500 would be \"thirteen thousand and five hundred\" in your example, but would be said as \"thirteen thousand five hundr... | [
{
"body": "<p>Here's one using modulo <code>%</code> and list joining that uses your original <code>NUMBER_WORDS</code> dict:</p>\n\n<pre><code>def int_to_english(n):\n english_parts = []\n ones = n % 10\n tens = n % 100\n hundreds = math.floor(n / 100) % 10\n thousands = math.floor(n / 1000)\n\n... | {
"AcceptedAnswerId": "39201",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-13T21:24:35.967",
"Id": "39183",
"Score": "4",
"Tags": [
"python",
"programming-challenge",
"python-3.x",
"converting"
],
"Title": "Python converter: number-to-English - Proje... | 39183 |
<p>I am working on an app: a virtual sandbox of sorts, a lot like <a href="http://dan-ball.jp/en/javagame/dust/" rel="nofollow"><em>Powder Game</em></a>.</p>
<p>The problem is, when working with an app, you must deal with hardware limitations. Don't get me wrong, the speed isn't like 2 FPS or anything, but I would jus... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-14T16:58:17.313",
"Id": "65696",
"Score": "4",
"body": "The best way to optimize code is to profile it and optimize only the critical parts. Optimizing for the sake of it loses readability and does nothing for performance (I've worked ... | [
{
"body": "<p>The comment from fernando.reyes is 100% correct: if you haven't measured things, you can't tell what's slow, or if it gets faster. That said, there are two main things I see that I know from prior exposure are likely to be slow. Since I've not used python on android, much less pgs4a, even that is ... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-13T22:18:42.460",
"Id": "39185",
"Score": "3",
"Tags": [
"python",
"performance",
"android",
"pygame"
],
"Title": "Virtual sandbox game"
} | 39185 |
<p>I am working on building an <code>UndoManager</code> in C#. The concept is to store events and property changes in a <code>Stack<Action<T>></code> instance. I believe it is working, but I am also looking for peer review.</p>
<p>What can I improve? Do you see any bugs? </p>
<pre><code>public abstract c... | [] | [
{
"body": "<p>Calling Add ought to clear the MyRedoOperations stack, but not when you call it from Redo.</p>\n\n<p>Secondly, <code>Action<T></code> is an uncomplicated type. It works for properties, because replaying an old action will reset the property to its previous value. However it won't work if you... | {
"AcceptedAnswerId": "39211",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-13T23:21:42.253",
"Id": "39186",
"Score": "9",
"Tags": [
"c#",
"delegates"
],
"Title": "A custom Undo Manager"
} | 39186 |
<p>Looking for optimization, smart tips and verification of complexity: O (log (base 2) power).</p>
<p>NOTE: <code>System.out.println("Expected 16, Actual: " + Power.pow(2, 7));</code> is a typo. It correctly returns 128.</p>
<pre><code>/**
* Find power of a number.
*
* Complexity: O (log (base 2) power)
*/
pu... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-14T00:27:40.363",
"Id": "65616",
"Score": "2",
"body": "I assume you don't want to use the built-in `java.lang.Math.pow` function."
}
] | [
{
"body": "<p>This <strong>can</strong> get worse than \\$\\operatorname{O}(\\log \\verb~pow~)\\$. [Remark: in \\$\\operatorname{O}\\$-notation, the base of an logarithm is irrelevant, since it represents only a multiplication with a constant]</p>\n\n<p>Let \\$\\verb~pow~ = 2^n - 1\\$ for some \\$n\\$. Then you... | {
"AcceptedAnswerId": "39193",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-14T00:06:33.917",
"Id": "39190",
"Score": "3",
"Tags": [
"java",
"mathematics",
"reinventing-the-wheel"
],
"Title": "Find power of a number"
} | 39190 |
<p>I have a considerably large directive which is doing many things: First it renders a Google Map, then it adds a listener to check when the bounds of the map change, then it renders points on the map based where the bounds currently are, and finally it has a menu of options which allow the user to turn on and off var... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-14T14:50:14.910",
"Id": "65686",
"Score": "0",
"body": "Your code does not run, your return statement seems wrong."
}
] | [
{
"body": "<p>From a once over</p>\n\n<ul>\n<li>You seem to be missing a comma after <code></div>'</code></li>\n<li>You seem to be missing a comma after <code>SW_lng:map.getBounds().getSouthWest()</code></li>\n<li>This code is reviewable, still, next time make sure there are no syntax errors..</li>\n<li>H... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-14T01:40:07.797",
"Id": "39196",
"Score": "1",
"Tags": [
"javascript",
"angular.js",
"google-maps"
],
"Title": "Directive to create a Google map"
} | 39196 |
<p>I am writing a program to factor stupidly large integers (5000 digits+), and performance is obviously critical. A currently TODO feature is to factor semiprimes, specifically RSA, which is why the cube root function is included. Don't tell me it's impossible. I'm trying to learn, not actually do it. Before I start ... | [] | [
{
"body": "<p>The following review is about the style only, I'll leave the review of the functionality to somebody who can actually do the math.</p>\n<hr />\n<blockquote>\n<p>package pfactor;</p>\n</blockquote>\n<p>Package names should associate the package with a person or organization. For testing code it is ... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-14T02:59:23.580",
"Id": "39197",
"Score": "5",
"Tags": [
"java",
"performance"
],
"Title": "Performance of BigInteger square root and cube root functions in Java"
} | 39197 |
<p>This is my first relatively big program. First it shows an <code>askdirectory()</code> screen to get the path. It gets all subfolders of that path and appends them to a list. It checks every folders' items if they are wanted file types by checking extensions and puts them into a proper sqlite table. After all files ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-02-12T23:13:03.263",
"Id": "71351",
"Score": "0",
"body": "Have you considered using easygui? This is all good and well for a Tkinter practice, but at the end of the day easygui is a pretty well written, if limited, module. I could probab... | [
{
"body": "<p>In looking at your code, there are a few things I would do:</p>\n\n<ol>\n<li>Subclass TK.. <code>class MainGUI(Tk):</code></li>\n<li>Attach all gui components to this class.... your frame for example.</li>\n<li>Add a queue and a polling method for GUI updates to the MainGUI class (this may help fi... | {
"AcceptedAnswerId": "47664",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-14T04:28:19.590",
"Id": "39198",
"Score": "6",
"Tags": [
"python",
"python-3.x",
"tkinter"
],
"Title": "Tkinter file searching program"
} | 39198 |
<p>Not lock-free, but still only C++11 and no Boost. It also supports timeouts.</p>
<pre><code>#pragma once
#include <cstddef>
#include <chrono>
#include <memory>
#include <queue>
#include <mutex>
#include <condition_variable>
template<typename T>
class blocking_queue {
publ... | [] | [
{
"body": "<p>Your size is not mutating. So should declare it const.</p>\n<pre><code>std::size_t size() const\n // ^^^^^\n</code></pre>\n<p>Still in the <code>size()</code> I don't see any in point in lock on such short term. As soon as the function exits the value can be mutated and will thus be... | {
"AcceptedAnswerId": "39203",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-14T05:12:36.787",
"Id": "39199",
"Score": "10",
"Tags": [
"c++",
"c++11",
"queue"
],
"Title": "Multi producer/consumer queue (without Boost) in C++11"
} | 39199 |
<p>I have a the beginnings of a class (in this case for a NeuralNet). <br>
I'm not very happy with how I am initializing self.ws, seems a bit off.
What is the pythonic way to do this?</p>
<pre><code>import numpy as np
class NeuralNet:
def __init__(self,layerSizes):
self.ws = self._generateStartingWeights(l... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-14T07:14:01.603",
"Id": "65635",
"Score": "0",
"body": "Fixed, thanks. That was not what was feeling wrong though."
}
] | [
{
"body": "<p>I think the primary question here is one of whether <code>_generateStartingWeights</code> or <code>randMatrix</code> are reusable; the secondary question is of naming conventions.</p>\n\n<p>If <code>_generateStartingWeights</code> is not reusable, there's little reason not to write <code>__init__<... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-14T06:11:40.630",
"Id": "39202",
"Score": "1",
"Tags": [
"python",
"classes"
],
"Title": "Class initialisation of fields"
} | 39202 |
<p>Looking for code review, optimizations, good practice recommendations etc.</p>
<pre><code>/**
* This is utility class for operations on rotated one-d array.
*
* Note: a sorted array, reverse-sorted or a single element is array is not considered rotated sorted.
* Eg:
* [4, 5, 1, 2, 3] is condidered rotated.
*... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-14T09:06:27.613",
"Id": "65643",
"Score": "2",
"body": "I think you should put just a bit more effort an make it work for a \"non-rotated\" sorted buffer, since it's basically a special case of a rotated buffer (i.e. the case where the... | [
{
"body": "<p>As mentioned in my comment, the structure you are dealing with is more commonly called a <a href=\"http://en.wikipedia.org/wiki/Circular_buffer\" rel=\"nofollow\">circular buffer</a>. The Wikipedia link has several examples on how to efficiently provide thread safe read/write access (a producer/co... | {
"AcceptedAnswerId": "39207",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-14T08:25:12.980",
"Id": "39204",
"Score": "2",
"Tags": [
"java",
"binary-search"
],
"Title": "Binary search in rotated sorted array"
} | 39204 |
<p>I'm using C++11 and I have the following problem (pseudo C++):</p>
<pre><code>template<typename T, R1 (*F1)(Args1...)>
class one_size_fits_them_all {};
template<typename T, typename U, typename V, R1 (*F1)(Args1...), R2 (*F2)(Args1...)>
class one_size_fits_them_all {};
template<typename T, typename... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-17T19:27:13.720",
"Id": "66214",
"Score": "0",
"body": "Why function pointers? Why not use [function objects](http://www.cprogramming.com/tutorial/functors-function-objects-in-c++.html)?"
},
{
"ContentLicense": "CC BY-SA 3.0",
... | [] | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-14T12:00:26.673",
"Id": "39213",
"Score": "5",
"Tags": [
"c++",
"c++11",
"pointers",
"template-meta-programming"
],
"Title": "C++ class \"overload\" using variadic templates and ... | 39213 |
<p>I have the following code to get the ID of a <code><a href="#ID"> </ a></code> and go to their respective div <code><div id="" /></code>:</p>
<pre><code>$('a[href=#certificados]').click(function(e){
e.preventDefault();
$("html, body").animate({ scrollTop: $('#certificados').offset().top },... | [] | [
{
"body": "<p>If you want to make the code DRYer, you can do</p>\n\n<pre><code>['#certificados', '#team', '#house', '#contact'].forEach(function(anchor){\n $(\"a[href=\"+anchor+\"]\").click(function(e){\n e.preventDefault();\n $(\"html, body\").animate({ scrollTop: $(anchor).offset().top }, 100... | {
"AcceptedAnswerId": "39220",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-14T13:56:22.097",
"Id": "39216",
"Score": "7",
"Tags": [
"javascript",
"jquery",
"animation"
],
"Title": "Animated scrolling when intra-page links are clicked"
} | 39216 |
<p>I need to parse the data coming from a URL:</p>
<pre><code>haschanged=true
version=1
timestamp=1389562122310
DATACENTER=/pr/hello/plc
TotalNumberOfServers:4
primary:{0=1, 1=2, 2=1, 3=2, 4=1, 5=2, 6=1, 7=2, 8=1, 9=2, 10=1, 11=2, 12=1, 13=2}
secondary:{0=0, 1=0, 2=0, 3=1, 4=0, 5=0, 6=0, 7=1, 8=0, 9=0, 10=... | [] | [
{
"body": "<p>Regex to the rescue</p>\n\n<ul>\n<li><p>Regex for key: <code>(?<=DATACENTER=).*</code></p></li>\n<li><p>Regex for primary values: <code>(?<=primary:\\{).*(?=\\})</code></p></li>\n<li><p>Regex for secondary values: <code>(?<=secondary:\\{).*(?=\\})</code></p></li>\n<li><p>Regex for hostMac... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-14T18:31:31.800",
"Id": "39231",
"Score": "5",
"Tags": [
"java",
"performance",
"parsing",
"hash-map",
"url"
],
"Title": "Parsing data coming from a URL"
} | 39231 |
<p>I have used the <a href="http://en.wikipedia.org/wiki/Newton%27s_method" rel="nofollow">Newton-Raphson method</a> to solve <a href="http://en.wikipedia.org/wiki/Cubic_function" rel="nofollow">Cubic equations</a> of the form $$ax^3+bx^2+cx+d=0$$ by first iteratively finding one solution, and then reducing the polynom... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-18T06:06:35.080",
"Id": "66266",
"Score": "1",
"body": "What if the first root found (`g`) is zero?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-18T09:44:05.537",
"Id": "66275",
"Score": "0",
... | [
{
"body": "<h3>Handling of complex roots</h3>\n\n<p>When there are complex roots, you have two cases, for <code>a1 > 0</code> and <code>a1 < 0</code>. You could just collapse the two cases by using <code>abs(a1)</code> when defining <code>imagg</code>.</p>\n\n<p>Better yet, Python has built-in support fo... | {
"AcceptedAnswerId": "39518",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-14T18:33:11.847",
"Id": "39232",
"Score": "6",
"Tags": [
"python",
"beginner",
"python-3.x",
"mathematics",
"numerical-methods"
],
"Title": "Newton's method to solve cubic... | 39232 |
<p>In the first code snippet I am creating a generic class to hold configuration details. I am currently using it as a way to pass run time configuration options to plugins in a generic manner. The second snippet is a helper class that utilizes the class to provide the public methods for use which helps guarantee typ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-15T07:30:56.677",
"Id": "65744",
"Score": "0",
"body": "A \"Type-safe configuration class\" is called a [Java Bean](http://en.wikipedia.org/wiki/JavaBeans)."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-1... | [
{
"body": "<p>Generics can only go so far to help you, and, this is one of those times where it just does not help all that much.</p>\n\n<p>In essence, you have the following:</p>\n\n<ul>\n<li>a configuration system where you can get values based on names (a Map).</li>\n<li>when you set a value it is for a give... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-14T19:01:42.793",
"Id": "39233",
"Score": "2",
"Tags": [
"java",
"api"
],
"Title": "Generic java configuration class with type safety"
} | 39233 |
<p>Pretty printer in ABAP does not take care of all my aligning need, so I wrote a small JS script that tabulates/aligns with a custom string. It contains HTML, CSS and script in 1 file because this is a small tool.</p>
<p>Link : <a href="https://github.com/konijn/aligner" rel="nofollow">https://github.com/konijn/alig... | [] | [
{
"body": "<p>I'm just commenting on your HTML/CSS.</p>\n\n<ul>\n<li>I commented out some <code>br</code> tags, because they were not necessary</li>\n<li>I splitted the HTML in three parts with <code>div</code>'s</li>\n<li>Slightly adjusted the CSS rules</li>\n</ul>\n\n\n\n<pre><code><!DOCTYPE html>\n<... | {
"AcceptedAnswerId": "40091",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-14T19:01:47.230",
"Id": "39234",
"Score": "7",
"Tags": [
"javascript",
"html",
"strings",
"css"
],
"Title": "Tabulate text with JavaScript"
} | 39234 |
<p>I have a need to print the content of a jQueryUI Dialog to a printer, and I couldn't find anything to my liking. I developed the following simple jQuery plugin which prints one or more provided HTML elements, and am using it to print the jQueryUI Dialog DIV element. The code is below, and a live example is located... | [] | [
{
"body": "<p>From a once over: </p>\n\n<ul>\n<li>I am not a native English speaker but <code>//Element to print HTML</code> confused me. Maybe <code>//HTML elements to be printed</code>?</li>\n<li><code>delete settings;</code> is meaningless in <code>destroy</code> ( see comment )</li>\n<li><code>elems=$(setti... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-14T19:10:40.920",
"Id": "39235",
"Score": "8",
"Tags": [
"javascript",
"jquery"
],
"Title": "jQuery plugin which will print to a printer an element or a jQueryUI Dialog"
} | 39235 |
<p>I thought this was pretty slick - maybe not, I just wanted to share and maybe get some feedback:</p>
<p>As part of a REST client class:</p>
<p>Accepts the JSON response from REST or REST-like service, searches through to find multiple errors, or return success indicator.</p>
<p>You define success and failure in a... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-15T23:43:38.620",
"Id": "65852",
"Score": "0",
"body": "If you're writing your own restful service, why wouldn't you have it define whether it failed or not on its own? E.g. have every response in a format like: `{\"success\":true, \"e... | [] | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-14T20:03:41.940",
"Id": "39238",
"Score": "1",
"Tags": [
"php",
"recursion",
"iterator"
],
"Title": "REST Response: Checking for Success and Error"
} | 39238 |
<p>Can I improve this markup? Is it SEO friendly?</p>
<pre><code><div class="bloc-contenu group" itemscope itemtype="http://schema.org/Hotel" itemref="logo nom-hotel">
<p><iframe src="https://www.google.com/maps/embed?pb=!1m14!1m12!1m3!1d89225.49873817024!2d-74.4423141!3d45.664941!2m3!1f0!2f0!3f0!3m2!1... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-14T21:12:08.990",
"Id": "317179",
"Score": "0",
"body": "[There's a different standard microformat you could use](http://microformats.org/wiki/hcard). It's an HTML representation of [this](http://tools.ietf.org/html/rfc6350) and [this]... | [
{
"body": "<p>From some research:</p>\n\n<ul>\n<li><p>If your code will be used on mobile, I would look into making that phone tag ( which seems to miss <code></p></code> ) into a functional phone tag : <a href=\"https://stackoverflow.com/a/11143507/7602\">https://stackoverflow.com/a/11143507/7602</a></p>... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-14T20:57:26.817",
"Id": "39240",
"Score": "-1",
"Tags": [
"html",
"html5",
"microdata"
],
"Title": "Optimizing with microdata and address tag"
} | 39240 |
<p>I have fully working code, however I'd like to make it nice. I've got these three models:</p>
<blockquote>
<ol>
<li><p>User (can have both or either one)<br>
user can have one trucker<br>
user can have one owner_trucker</p></li>
<li><p>Trucker
belongs to user</p></li>
<li><p>OwnerTrucker
belongs to ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-15T03:13:48.277",
"Id": "65740",
"Score": "2",
"body": "Does the problem domain allow for a simplification of these roles? Are `owner_truckers` also a type of `trucker`? How is a `user` who is an `owner_trucker` different than if they ... | [
{
"body": "<p>I think your suspicion that the code is a \"wet\" is correct. I would start moving these predicates into the model whenever they are:</p>\n\n<ul>\n<li>Used more than once, or</li>\n<li>Can make the code clearer by having a named predicate.</li>\n</ul>\n\n<p>Consider replacing this:</p>\n\n<pre><c... | {
"AcceptedAnswerId": "39260",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-14T21:48:14.523",
"Id": "39245",
"Score": "0",
"Tags": [
"ruby",
"ruby-on-rails"
],
"Title": "Supporting two kinds of user profiles"
} | 39245 |
<p>I'm learning JavaScript and I was trying to make a custom addEvent function that would care about compatibility (I don't want to use jQuery [nor any other library] yet, in order for me to "master" the bases of JavaScript).</p>
<p>I came across this code on github (<a href="https://gist.github.com/eduardocereto/9556... | [] | [
{
"body": "<p>Your code is clean and consistent in style and formatting. Good job.</p>\n\n<p>I've noticed two small things that are not problems but rather they were unexpected to me and might trip you coming back to this code in 6 months tie</p>\n\n<ol>\n<li><p>you end all your code blocks with <code>};</code>... | {
"AcceptedAnswerId": "39250",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-14T22:29:07.293",
"Id": "39246",
"Score": "2",
"Tags": [
"javascript",
"event-handling"
],
"Title": "JavaScript custom addEvent function to add event handlers"
} | 39246 |
<p>I have an angle where I need to convert a 'normal' angle to an isometric angle (116 degrees), and I came up with this function. It works, but I was wondering if the math could be optimized/simplified, or if this is the way to go. It's for a mobile game. </p>
<pre><code>public static inline var ISO:Float = 0.4537856... | [] | [
{
"body": "<p>It seems to me that this is a math related question rather than code review. Let's simplified the code first,</p>\n\n<pre><code>var dx = Math.cos(a - b) - Math.cos(a - b) * r;\n</code></pre>\n\n<p>The above can be simplified to </p>\n\n<pre><code>var dx = (1 - r) * Math.cos(a - b);\n</code></pre>\... | {
"AcceptedAnswerId": "39606",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-14T23:08:52.607",
"Id": "39249",
"Score": "8",
"Tags": [
"optimization",
"mathematics",
"computational-geometry",
"haxe"
],
"Title": "Calculating angle in isometric view"
} | 39249 |
<p>Is this the best way to reverse a singly-linked list? Can it be done with two, or fewer pointers? Any other comments?</p>
<pre><code>public class ReverseLL {
Node start;
ReverseLL()
{
start=null;
}
class Node
{
Node next;
int data;
Node(int newData)
{... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-15T00:48:20.917",
"Id": "65728",
"Score": "0",
"body": "I have used temp, previous and previous1"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-15T00:49:13.530",
"Id": "65729",
"Score": "0",
"b... | [
{
"body": "<p>This is a nice, clean implementation of a Linked list... Generally a good job.</p>\n\n<p>You have a bug in your <code>reverse</code> method, a <code>NullPointerException</code> when the list is empty. There is an easy fix, but you should be aware.</p>\n\n<p>I also had a look at your reverse method... | {
"AcceptedAnswerId": "39261",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-15T00:43:54.287",
"Id": "39254",
"Score": "7",
"Tags": [
"java",
"linked-list"
],
"Title": "Reversing a singly-linked List"
} | 39254 |
<p>This feels like a simple question, but I'm wondering what the best way would be to manage the elements of a private, fixed-size array.</p>
<p>Context: I'm making a simple particle engine, and my <code>Emitter</code> class will smoothly interpolate between up to 8 colors per <code>Particle</code>, depending on the P... | [] | [
{
"body": "<p>If you expose it via a public property then it's not a \"private\" array any more:it's part of the public interface.</p>\n\n<p>If resetting its elements is something that you want clients to do, I'd choose the first option (because it's simplest).</p>\n\n<p>Or, these ...</p>\n\n<pre><code>public v... | {
"AcceptedAnswerId": "39256",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-15T01:04:21.623",
"Id": "39255",
"Score": "11",
"Tags": [
"c#",
"array",
"properties"
],
"Title": "Best way to handle elements of a private array"
} | 39255 |
<p>Looking for review, good practices, optimizations, clean code tips etc.</p>
<pre><code>/**
* Flip the columns.
*
* Complexity:
* O(row * col)
*
*/
public final class Mirror {
private Mirror () { }
/**
* Given a matrix create a mirror image,
*
* @param m the input matrix
* ... | [] | [
{
"body": "<p>In your top=level method <code>mirrorPatch</code> you have:</p>\n\n<pre><code> // for each row.\n for (int i = 0; i < m.length; i++) {\n // for each column\n flipRow(m[i]);\n }\n</code></pre>\n\n<p>This is unnecessarily verbose, using the iterable nature of arrays you cou... | {
"AcceptedAnswerId": "39266",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-15T05:49:18.593",
"Id": "39263",
"Score": "3",
"Tags": [
"java",
"matrix"
],
"Title": "Find mirror image of a matrix"
} | 39263 |
<p>Looking for review, good practices, optimizations, clean code tips etc.</p>
<pre><code>final class Pixel {
private final int color;
public Pixel(int color) {
this.color = color;
}
public int getColor() {
return color;
}
}
/**
* Rotates an image by ninety degrees.
*
* Comp... | [] | [
{
"body": "<p>Overall, your code is really nice looking! Below are just some basic suggestions.</p>\n\n<pre><code>final class Pixel {\n</code></pre>\n\n<p>In my opinion, you should always explicitly dictate whether classes are <code>public</code>, <code>private</code>, or <code>protected</code>.</p>\n\n<pre><c... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-15T05:59:06.780",
"Id": "39265",
"Score": "5",
"Tags": [
"java",
"matrix",
"image"
],
"Title": "Rotate an image by 90 degrees"
} | 39265 |
<p>I have an array of <code>Item</code> objects that each have a string <code>particular</code> and a numeric <code>amount</code>. I want to put all <code>particular</code>s (separated by newlines) into a single string and the same for all <code>amount</code>s.</p>
<p>Here's what I came up with:</p>
<pre><code>part... | [] | [
{
"body": "<p>You can get by with just two lines:</p>\n\n<pre><code>particulars_string = items.map(&:particular).join(\"\\n\")\namounts_string = items.map(&:amount).join(\"\\n\")\n</code></pre>\n\n<p><code>Enumerable#map</code>, which is mixed into <code>Array</code>, creates a new array from an exi... | {
"AcceptedAnswerId": "39269",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-15T07:15:20.240",
"Id": "39268",
"Score": "4",
"Tags": [
"ruby",
"strings",
"array"
],
"Title": "Processing array of objects into two strings"
} | 39268 |
<p>I have written this little tagging module to make it easier to generate small html snippets on the fly. The examples below show how this make things a bit easier. My question is about the handling of tags that contain either a single element like text or a list of other elements, like the tr element in the second ex... | [] | [
{
"body": "<p>The solution is to have <code>contents</code> always be a list. If we don't want to impose this onto the caller of the constructor, we have to use a variable number of arguments:</p>\n\n<pre><code>def __init__(self, name, *contents, **attrs):\n ...\n</code></pre>\n\n<p>Now the functions can be c... | {
"AcceptedAnswerId": "39271",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-15T07:59:58.057",
"Id": "39270",
"Score": "2",
"Tags": [
"python",
"html",
"array"
],
"Title": "Handling objects and arrays simply in this tagging library"
} | 39270 |
<p>I want to create all possible combinations of points (0,0),(0,1)...(12345,6789) and then all segments from these points.</p>
<p>The code I have written is simple and with no optimization. Is there any algorithm to generate it in less time?</p>
<pre><code>public static void main(String[] args) {
int m=12345;
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-15T11:15:46.063",
"Id": "65760",
"Score": "0",
"body": "Are the segments combined into another structure or are they operated on as is? Also, abstraction might do wonders, I'm not sure if you can drop all these loops, but you could hid... | [
{
"body": "<p>Google Guava has a <a href=\"http://docs.guava-libraries.googlecode.com/git/javadoc/com/google/common/collect/Sets.html#cartesianProduct%28java.util.List%29\"><code>cartesianProduct</code></a> helper method, I would try to use it instead of the nested loops. I don't think that it will be faster bu... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-15T09:58:53.887",
"Id": "39274",
"Score": "11",
"Tags": [
"java",
"performance",
"combinatorics"
],
"Title": "Creating all possible combinations of points"
} | 39274 |
<p>Depending on the width of the screen the JavaScript animates a node and then loops another animation.</p>
<p>I'm trying to understand DRY but my JavaScript skills aren't quite up to scratch to get this code as optimised as possible. I'm also wanting to implement <code>$(window).resize(function() { });</code> to det... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-15T12:53:02.770",
"Id": "65774",
"Score": "0",
"body": "Probably not because those constants may become incorrect (besides top and left which will be 0) when the window resizes"
}
] | [
{
"body": "<p>I would move all positions and other configuration to a simpleObject which contains a condition which is checked to determine if the configuration should be used for the current screen dimensions:</p>\n\n<ul>\n<li>Remove unneeded variables</li>\n<li>Added functions to remove duplication</li>\n<li>... | {
"AcceptedAnswerId": "39316",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-15T10:29:06.693",
"Id": "39276",
"Score": "3",
"Tags": [
"javascript",
"performance",
"jquery",
"animation",
"jquery-ui"
],
"Title": "Animating based on screen width"
} | 39276 |
<p>I have tried to write code of Box stacking problem (mentioned <a href="http://people.csail.mit.edu/bdean/6.046/dp/" rel="nofollow">here</a>) in C++ .
Kindly give me some views on what mistakes I might have made and how I can improve.
It is running for the two inputs I have provided.</p>
<pre><code>//===============... | [] | [
{
"body": "<ol>\n<li>Your header file is wrong. This is NOT an Hello World.</li>\n<li>Do not use <code>using namespace std</code> : <a href=\"https://stackoverflow.com/questions/1452721/why-is-using-namespace-std-considered-bad-practice\">https://stackoverflow.com/questions/1452721/why-is-using-namespace-std-co... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-15T10:59:12.047",
"Id": "39279",
"Score": "6",
"Tags": [
"c++",
"stl",
"dynamic-programming"
],
"Title": "Box-stacking problem in C++"
} | 39279 |
<p>I wrote this unbalanced binary tree and would like to know how to improve the code and performance. If you can point out any situations that are not being handled appropriately, that would be great too.</p>
<p>It supports element insertion, removal, search, iteration, tree balancing and encoding/decoding.</p>
<p><... | [] | [
{
"body": "<p>This is simple a first pass with mostly top level thoughts - I dig deeper later.</p>\n\n<ol>\n<li><p>Suggest moving all functions to bst.c including <code>bst_init() size_t bst_encode() bst_decode()</code>. By doing so, <code>ENCODING_SIZE_T MAX_CONTENT_LENGTH BST_Node</code> and the fields of <c... | {
"AcceptedAnswerId": "39423",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-15T11:58:57.183",
"Id": "39282",
"Score": "6",
"Tags": [
"c",
"tree"
],
"Title": "Unbalanced binary search tree"
} | 39282 |
<p>There is a recommendation not to use an Exception to control the flow of execution. This gives me a reason for doubt when I do something like this:</p>
<pre><code> public void initApplication(String input) {
try {
MyClass mClass = new mClass(input);
saveToDatabase(mClass);
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-15T14:03:54.163",
"Id": "65777",
"Score": "3",
"body": "You're not supposed to use Exceptions for \"normal\" control flow, f.e. iterating over collections, you only should use it for exceptional cases. If your insert into that database... | [
{
"body": "<p>I would say that this isn't controlling the flow of your application. This is handling an exceptional circumstance (i.e., failure of your code to perform what as it's meant to), which is what Exceptions are meant to accommodate.</p>\n\n<p>The recommendation is more for circumstances like this:</p... | {
"AcceptedAnswerId": "39295",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-15T13:07:32.290",
"Id": "39284",
"Score": "4",
"Tags": [
"java",
"object-oriented",
"exception-handling",
"exception"
],
"Title": "Throw an exception to control the flow of co... | 39284 |
<p>The question is very simple but also a bit theoretical. </p>
<p>Let's imagine you have a long jQuery script which modifies and animate the graphics of the web site. It's objective is to handle the UI. The UI has to be responsive so the real need for this jQuery is to mix some state of visualization (sportlist visib... | [] | [
{
"body": "<p>You are asking a high level question, so I am going to give a high level answer.</p>\n\n<ul>\n<li>Your listeners should have at most 2 lines of code inside, 1 line that changes data in the model if required, one line that updates the screen, if required.</li>\n</ul>\n\n<p>This means that you need ... | {
"AcceptedAnswerId": "39390",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-15T13:16:07.857",
"Id": "39285",
"Score": "2",
"Tags": [
"javascript",
"jquery"
],
"Title": "How to refactor JQuery interaction with interface?"
} | 39285 |
<p>I am quite new to event programming in C# specially in WPF. I have made a very simple core app which I am planning on extending. </p>
<p>It's very simple as its purpose is learning curve and doing things the right way that's why I am asking here for a review and not help on building as most of the building is easil... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-15T13:58:56.593",
"Id": "65776",
"Score": "0",
"body": "Do you know somethig about behaviors and attachable properties? Anythig about MVP, MVC, or MVVM design patterns?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate"... | [
{
"body": "<p>While you are only asking about event i feel like the general review will help you as well. So here it goes.</p>\n\n<ol>\n<li>You have a lot of junk in your xaml. Don't name an element if you dont use that name, don't set properties if they are no different from the default values.</li>\n<li>You s... | {
"AcceptedAnswerId": "39361",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-15T13:37:35.650",
"Id": "39286",
"Score": "3",
"Tags": [
"c#",
"wpf",
"event-handling"
],
"Title": "Optimizing a very simple wpf app - attempt on handling 2 buttons with a common ... | 39286 |
<p>I have to work with a 3rd-party API that allows me to define and execute "commands", using XML. Since I don't like seeing mixed abstraction levels, I managed to remove all the inline XML / string concatenations by creating a simple <code>XmlCmdBuilder</code> object - here is the C# implementation (I have one in VB6 ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-15T14:04:07.813",
"Id": "65778",
"Score": "0",
"body": "Diy you try to use enumerations for all of your commands?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-15T14:04:33.953",
"Id": "65779",
"Sc... | [
{
"body": "<p>not sure exactly how this will be used, so this might be a null point. </p>\n\n<p>you have <code>add</code> methods but you don't have any <code>remove</code> methods. not sure it would make extension easier, but it would probably provide you with a way to remove deprecated commands (you may or m... | {
"AcceptedAnswerId": "39305",
"CommentCount": "7",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-15T13:59:39.490",
"Id": "39288",
"Score": "10",
"Tags": [
"c#",
"xml",
"api"
],
"Title": "XmlCmdBuilder - doing away with inline xml"
} | 39288 |
<p>Microdata is a syntax for embedding machine-readable data in HTML5 documents.</p>
<ul>
<li>At <strong>W3C</strong>, it’s a separate specification (currently a <em>Note</em>): <a href="http://www.w3.org/TR/microdata/" rel="nofollow">http://www.w3.org/TR/microdata/</a></li>
<li>At <strong>WHATWG</strong>, it’s part o... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-15T14:02:11.450",
"Id": "39289",
"Score": "0",
"Tags": null,
"Title": null
} | 39289 |
Microdata is a syntax for embedding machine-readable data in HTML5 documents. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-15T14:02:11.450",
"Id": "39290",
"Score": "0",
"Tags": null,
"Title": null
} | 39290 |
<p>I have one file with indexes. For example, they are:</p>
<blockquote>
<pre class="lang-none prettyprint-override"><code>1 Fruit
2 Meat
3 Fish
4 Salmon
5 Pork
6 Apple
</code></pre>
</blockquote>
<p>And a dictionary, because I want to match entries that I choose:</p>
<pre class="lang-... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-06T09:31:30.003",
"Id": "65784",
"Score": "0",
"body": "`#Splits the CSV file on every \",\"` - no it doesn't. It splits the lines on every tab. Also, if this is supposed to be CSV, [there's a module for that](http://docs.python.org/2/... | [
{
"body": "<p>Can you store the content in the CSV file in the memory?It will be more effective to read from the memory than the disk. </p>\n\n<p>Maybe the CSV file will also be store in the memory cache by OS, but you can do it your self to make it more reliable.</p>\n\n<p>Of course it's only when there is eno... | {
"AcceptedAnswerId": "39293",
"CommentCount": "11",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-06T09:25:05.957",
"Id": "39292",
"Score": "3",
"Tags": [
"python",
"csv"
],
"Title": "Formatting inventory of parts"
} | 39292 |
<p>I used <a href="http://docs.angularjs.org/tutorial/step_04" rel="nofollow">step 4</a> from the <a href="http://angularjs.org/" rel="nofollow">Angular</a> tutorial to do some tinkering of my own. In that particular step of the tutorial, a <code>option</code> list is created that determines how a list is sorted (Alpha... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-04-19T07:41:17.003",
"Id": "83500",
"Score": "0",
"body": "Is this code tested, specifically `(opt,value)` inside `ng-repeat`?"
}
] | [
{
"body": "<p>I think it's a bad idea for several reasons:</p>\n\n<ul>\n<li>It is possible to have an empty data set in real-world app but it should not affect your sorting options in any way.</li>\n<li>It is possible to have some optional fields or fields that aren't suit for sorting - images, additional descr... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-15T14:36:46.757",
"Id": "39296",
"Score": "3",
"Tags": [
"javascript",
"html",
"angular.js"
],
"Title": "Dynamically generating a HTML option list using Angular.js"
} | 39296 |
<p>The idea of the below code is that I feed back to a Gridview if the user has permission to view the property otherwise that property is not show. </p>
<p>The data is passed in via SessionParameters</p>
<pre><code>USE [database]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
alter PROCEDURE [dbo].[spSafeguar... | [] | [
{
"body": "<p>Does your <code>EmployeeID</code> and <code>PropertyID</code> parameters really need to be <code>varchar(max)</code>, I find it hard to believe that an employee would have an ID with 8 000 characters. The same goes for the property ID. Change this to how many characters they are allowed to have (e... | {
"AcceptedAnswerId": "39304",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-15T14:40:14.140",
"Id": "39297",
"Score": "2",
"Tags": [
"sql",
"vb.net"
],
"Title": "SQL Look up in a Stored Procedure across three tables"
} | 39297 |
<p>After reading some texts regarding creation of files under Python, I've decided to create this class which creates a new file on a directory, and creating a backup on the other directory if the file already exists (and if it's older than x hours).</p>
<p>The main reason I opened this question is to know if this is ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-15T17:30:59.970",
"Id": "65821",
"Score": "0",
"body": "Close your question? We're not StackOverflow. We **do** put things on hold every now and then, but this question? Wouldn't dream of it."
},
{
"ContentLicense": "CC BY-SA 3... | [
{
"body": "<p>In your specific case, the second snippet shows the best way to go as your code is simplified and makes more sense. Make sure to seperate two if blocks when they're not the same, otherwise they might look like if/else and confuse anyone reading that code (including you in a few days!).</p>\n\n<pre... | {
"AcceptedAnswerId": null,
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-15T15:32:21.767",
"Id": "39302",
"Score": "3",
"Tags": [
"python",
"validation",
"file"
],
"Title": "Class for file creation and directory validation"
} | 39302 |
<p>I've heard that <code>Lbl</code> and <code>Goto</code> use up memory that they don't give back. I've noticed clearing the RAM on my calculator frees up a lot of space and makes my programs run a lot faster. Any suggestions on how to minimize memory leaks here would be greatly appreciated. (This code does function co... | [] | [
{
"body": "<blockquote>\n <p>I've heard that Lbl and Goto use up memory that they don't give back</p>\n</blockquote>\n\n<p>If you replace the following ...</p>\n\n<pre><code>:If B=95\n:Goto E\n... etc. ...\n:Goto V\n:Lbl E\n</code></pre>\n\n<p>... with ...</p>\n\n<pre><code>... etc. ...\n:If B<95\n:Goto V\n... | {
"AcceptedAnswerId": "39311",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-15T16:12:24.553",
"Id": "39308",
"Score": "5",
"Tags": [
"optimization",
"memory-management",
"ti-basic"
],
"Title": "Invert the colors of the graph"
} | 39308 |
<p>TI-BASIC is the unofficial name of a BASIC-like language built into Texas Instruments (TI)'s graphing calculators, including the TI-83 series, TI-84 Plus series, TI-89 series, TI-92 series (including Voyage 200), TI-73, and TI-Nspire.</p>
<p>For many applications, it is the most convenient way to program any TI cal... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-15T16:18:33.190",
"Id": "39309",
"Score": "0",
"Tags": null,
"Title": null
} | 39309 |
TI-BASIC is the unofficial name of a BASIC-like language built into Texas Instruments (TI)'s graphing calculators, including the TI-83 series, TI-84 Plus series, TI-89 series, TI-92 series (including Voyage 200), TI-73, and TI-Nspire. | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-15T16:18:33.190",
"Id": "39310",
"Score": "0",
"Tags": null,
"Title": null
} | 39310 |
<p>Below is a pretty simple Python script to ingest some data, massage it as necessary, append a column, sort it, and then write it back to another file. Still learning all the Python best practices and APIs, so as always, any tips and tricks are appreciated! Feel free to be brutal with me if it's horrible. It's my ... | [] | [
{
"body": "<p>To summarize, the things I expect could be improved include documentation (docstrings and/or comments), variable names (especially the ones that don't convey much, or convey things that don't match behavior), the coupling of functions (<code>write_file</code> may misbehave if <code>sys.argv[1]</co... | {
"AcceptedAnswerId": "39420",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-01-15T16:35:48.853",
"Id": "39312",
"Score": "3",
"Tags": [
"python",
"python-3.x"
],
"Title": "Python data massager"
} | 39312 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.