body stringlengths 25 86.7k | comments list | answers list | meta_data dict | question_id stringlengths 1 6 |
|---|---|---|---|---|
<p>I have an algorithm and the idea is to move over an array choosing as index the index of the neighboring cell that has the max value.<br>
I.e. </p>
<p>if array[i + 1][j + 1] has the largest value among the 3 then move there.</p>
<p><img src="https://i.stack.imgur.com/Zhhmg.png" alt="enter image description here">... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-26T21:14:58.233",
"Id": "33562",
"Score": "1",
"body": "In *Version 1* you can remove the line ` maxI = i + 1; ` in the first `if`-block, because it does not do anything."
}
] | [
{
"body": "<p>I think it's easier to follow the second version. I've extracted out some helper variables:</p>\n\n<pre><code> final int b = array[i][j + 1];\n final int c = array[i + 1][j];\n final int d = array[i + 1][j + 1];\n\n if (d > b && d > c) {\n i = i + 1;\n j = j... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-26T11:35:08.997",
"Id": "20929",
"Score": "3",
"Tags": [
"java",
"algorithm",
"array"
],
"Title": "Code to find the proper index comparing 3 values for max one"
} | 20929 |
<p>I am building a web app with a single (not pooled) full time (jdbc) connection between static classes and the database. This is expected to be a low traffic site and the static methods are synchronized. In an effort to speed up access to product information, I am trying PreparedStatements for the first time. As I te... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-27T08:42:19.953",
"Id": "33573",
"Score": "0",
"body": "So you need to restart the app if connection somehow is closed?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-27T08:48:20.767",
"Id": "33574",
... | [
{
"body": "<p>Yes, you're doing it right. The performance differences you're seeing are most likely due, as you noted, to the differences between your data volumes. Since you're using SQL Server, you can use examine the database trace information to see how the queries perform when you have similar data volum... | {
"AcceptedAnswerId": "43460",
"CommentCount": "8",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-26T12:05:18.587",
"Id": "20931",
"Score": "2",
"Tags": [
"java",
"sql",
"sql-server"
],
"Title": "SQL PreparedStatement; Am I doing it right?"
} | 20931 |
<p>I'm continuing to work on the <a href="http://rads.stackoverflow.com/amzn/click/0596007124" rel="nofollow noreferrer">Head First Design Patterns</a> book in an effort to become a more efficient and better Python programmer. Code review for the Strategy pattern in Chapter 1 is <a href="https://codereview.stackexchang... | [] | [
{
"body": "<p>A few random comments on pieces of the code:</p>\n\n<pre><code>class Subject:\n __metaclass__ = ABCMeta\n\n @abstractmethod\n def register_observer(observer):\n \"\"\"Registers an observer with Subject.\"\"\"\n pass\n\n @abstractmethod\n def remove_observer(observer):\... | {
"AcceptedAnswerId": "20940",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2013-01-26T17:59:59.730",
"Id": "20938",
"Score": "14",
"Tags": [
"python",
"unit-testing",
"observer-pattern"
],
"Title": "The Observer design pattern in Python, with unit tests"
} | 20938 |
<p>I have the code below I probably did not need to post the entirety of it but you can see in the code that I make multiple data base queries to generate each of the multiple tables. I am curious if there is a way to make one query and yet get the same results, and possibly clean up the code.</p>
<pre><code><!DOCT... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-26T21:35:35.790",
"Id": "33566",
"Score": "1",
"body": "I'm not sure whether this is offtopic. If you are asking a specific question, try stackoverflow."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-26T22... | [
{
"body": "<p>Unless I'm missing something, you're <code>SELECT</code>ing the entire table over an over, then do exactly the same thing with it every time (except with different HTML class names). If that's the case, you can replace the whole file with this:</p>\n\n<pre><code><!DOCTYPE HTML PUBLIC \"-//W3C/D... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-26T20:55:23.883",
"Id": "20943",
"Score": "1",
"Tags": [
"php",
"mysql"
],
"Title": "Cleaner more efficient way of multiple database queries"
} | 20943 |
<p>Here's a small module I've written that implements an animation which fades through the child elements in a container div on a continual loop. </p>
<p>I realise I could have done this way quicker using JQuery, but I wanted to write it from scratch in this case.</p>
<p>The module works well enough, but I'd be very ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-28T19:27:35.240",
"Id": "33706",
"Score": "0",
"body": "Available for fiddling @ http://jsfiddle.net/vudC2/ (with a 2-second delay because I am impatient)"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-28T... | [
{
"body": "<p>Small changes:</p>\n\n<p>Cache the length, and set the invariants only once:</p>\n\n<pre><code> // Initialise opacity and position for child Elements of the\n // container div\n for (var i = 0, l = ch.length; i < l; i++) {\n ch[i].style.opacity = 0;\n ch[i].style.position... | {
"AcceptedAnswerId": "21003",
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-27T01:30:30.313",
"Id": "20947",
"Score": "1",
"Tags": [
"javascript",
"dom",
"easing"
],
"Title": "Javascript looping fader animation"
} | 20947 |
<p>I am writing a small oauth2 library for Play! 2.1 scala. As I am still learning I got stuck trying to TDD and ended up writing the code first, then refactoring for testability. By testability I mean two things:</p>
<ol>
<li>make the code testable by me as the author</li>
<li>make it easy for users (since I will be ... | [] | [] | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-27T10:50:54.840",
"Id": "20952",
"Score": "3",
"Tags": [
"object-oriented",
"unit-testing",
"scala",
"authentication"
],
"Title": "Testing Scala code which depends on objects"
} | 20952 |
<p>I'm still teaching myself C out of KN King's C Programming: Modern Approach. Actually pretty excited I go this problem solved in under 2 hours. I asked this over on Stack Overflow and it was recommended I post it here.</p>
<p>The exercise is to print a magic square. My solution works but it feels incredibly convolu... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-27T16:03:48.150",
"Id": "33587",
"Score": "0",
"body": "Starting the for-loop at i=2 seems a bit weird to me. I would recommend starting at i=1 and putting current value at be beginning of the loop"
},
{
"ContentLicense": "CC B... | [
{
"body": "<p>I'm just using the <code>I</code>th row and <code>J</code>th column formula <a href=\"http://en.wikipedia.org/wiki/Magic_square#Method_for_constructing_a_magic_square_of_odd_order\" rel=\"nofollow\">here on wiki</a>.</p>\n\n<p>$$ n \\left(\\left(I + J - 1 + \\lfloor \\dfrac{n}{2} \\rfloor \\right)... | {
"AcceptedAnswerId": "20954",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-27T12:03:21.897",
"Id": "20953",
"Score": "5",
"Tags": [
"c",
"array"
],
"Title": "Magic Square in C"
} | 20953 |
<p>I am choosing to learn F# for my own enjoyment. I am getting to the point where concepts of F# seem to be pretty easy, but understanding some of the whys and whens is a bit harder.</p>
<p>Before I get into the code and the explanation, let me put my question up front. I am asking where can I find better advice on f... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-27T13:40:09.917",
"Id": "33584",
"Score": "0",
"body": "BTW, I believe the idiomatic way of ignoring the result of something is `System.Console.ReadKey(true) |> ignore`, not declaring an unused local. Also, I think you don't even need ... | [
{
"body": "<p>Your code formatting is very readable. The minor issue is that you don't have to indent after <code>namespace</code> declaration. I would choose to open module directly to save a level of indentation (see attached code later).</p>\n\n<blockquote>\n <p>So what are the best practices for code forma... | {
"AcceptedAnswerId": "20956",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-27T06:56:05.477",
"Id": "20955",
"Score": "5",
"Tags": [
"unit-testing",
"f#"
],
"Title": "Kata: Natural Sort"
} | 20955 |
<p>I am trying to solve the 8 queens problem using a heuristic similar to "the accessibility heuristic" used in Knight's Tour problem. this heuristic simply means that each square of the chess board has the value of the numbers of squares that will be attacked if the queen is placed on that square. and asks me to place... | [] | [
{
"body": "<blockquote>\n <p>I think I did it and here's my code, please check if there are an errors or better ways to do things.</p>\n</blockquote>\n\n<p>Do not get it wrong, but to ask it in a direct way: Did you try to run the code? You could see directly that the proposed solution is not a solution. There... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-27T13:09:38.533",
"Id": "20957",
"Score": "1",
"Tags": [
"java",
"chess"
],
"Title": "Eight Queens Heuristic"
} | 20957 |
<p>I am developing game portal content management system using java and j2ee technology. However i am stuck in my design implementation.</p>
<p>Here is the scenario:</p>
<p>Each Game object has attributes like id, name, developer, price, platformType, platformName and so on...</p>
<p>However the release date may be ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-28T22:20:23.257",
"Id": "33720",
"Score": "0",
"body": "`gameScore` and `gameRank` probably belong in `GamePlatform`, as a specific port may be considered 'bad'."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013... | [
{
"body": "<ol>\n<li><p><code>ArrayList<...></code> reference types should be simply <code>List<...></code>. See: <em>Effective Java, 2nd edition</em>, <em>Item 52: Refer to objects by their interfaces</em></p>\n\n<pre><code>List<GamePlatform> gamePlatforms;\n</code></pre></li>\n<li><p>I'd con... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-27T16:03:48.520",
"Id": "20958",
"Score": "1",
"Tags": [
"java",
"design-patterns"
],
"Title": "Do you think this design pattern is good for game portal content management system"
} | 20958 |
<p>My task was to build a multi-thread file server and a client that can upload or download a named file over sockets. It is assumed that the client will finish after its operation and there is no need to supply a file list from the server (although I plan to add that). There is no error check if the client enters a f... | [] | [
{
"body": "<p>The basic client / server code looks pretty good.</p>\n\n<p>If you want clearer vision for \"something\" in java, you need to start defining the boundary of that \"something\". In Java the ideal choice is the Class.</p>\n\n<p>Start by refactoring your code to separate what you consider the \"Prot... | {
"AcceptedAnswerId": "23117",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-27T17:36:56.010",
"Id": "20961",
"Score": "10",
"Tags": [
"java",
"multithreading",
"homework",
"socket",
"network-file-transfer"
],
"Title": "Java multi-thread file serve... | 20961 |
<p>Am supposed to capture user input as an integer, convert to a binary, reverse the binary equivalent and convert it to an integer.Am getting the right output but someone says the solution is wrong. Where is the problem?</p>
<pre><code>x = 0
while True:
try:
x = int(raw_input('input a decimal number \t... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-27T22:28:35.517",
"Id": "33596",
"Score": "2",
"body": "If you are asking us to find an error in your code, then I'm afraid your question if off topic on Code Review. This is site is for reviewing code that you think is correct."
},
... | [
{
"body": "<pre><code>x = 0\n</code></pre>\n\n<p>There is no point in doing this. You just replace it anyways</p>\n\n<pre><code>while True:\n\n try:\n x = int(raw_input('input a decimal number \\t'))\n\n\n if x in xrange(1,1000000001):\n</code></pre>\n\n<p>Probably better to use <code>if 1 <... | {
"AcceptedAnswerId": "20968",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-27T21:48:57.497",
"Id": "20965",
"Score": "3",
"Tags": [
"python"
],
"Title": "Python Reverse the binary equivalent of input and output the integer equivalent of the reverse binary"
} | 20965 |
<p>I am trying to set a <code>OnClickListener</code> to a image in a loop. If the params platform is "android" then use market app, instead of default browswer. Is there a better solution to my exception handling or eliminatingsome of the <code>if-else</code> ?</p>
<pre><code>private void setupListener(ImageView image... | [] | [
{
"body": "<p>Here is another version with <a href=\"http://www.codinghorror.com/blog/2006/01/flattening-arrow-code.html\" rel=\"nofollow noreferrer\">guard clauses</a>:</p>\n\n<pre><code>private void setupListener(final ImageView image, final String platform, \n final String urlLink) {\n image.setOnC... | {
"AcceptedAnswerId": "20972",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-27T21:52:00.857",
"Id": "20966",
"Score": "1",
"Tags": [
"java",
"android"
],
"Title": "Setting a OnClickListener in a loop"
} | 20966 |
<p>My code converts repeating decimals to fractions. It works but I am interested in feedback on how I could improve and/or simplify it?</p>
<p>jsFiddle: <a href="http://jsfiddle.net/tfgTu/" rel="nofollow">http://jsfiddle.net/tfgTu/</a></p>
<pre><code><script>
// Repeating decimal
// 21.83(35745857)
var decimal... | [] | [
{
"body": "<ol>\n<li>While the general code quality is good, the contract should be formalized by adding <code>\"use strict\";</code></li>\n<li>Even though <code>var</code> is used, everything is still in the global namespace, thereby polluting it and risking name collisions. Moving things into a namespace also... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-28T00:34:02.817",
"Id": "20969",
"Score": "4",
"Tags": [
"javascript"
],
"Title": "Convert Repeating Decimal to Fraction"
} | 20969 |
<p>The following is an implementation of Guava's <a href="http://docs.guava-libraries.googlecode.com/git/javadoc/com/google/common/base/Equivalence.html">Equivalence</a> for Jackson's <code>JsonNode</code> for the needs of JSON Schema: in certain situations, all JSON numbers need to be compared mathematically (ie, <cod... | [] | [
{
"body": "<p>Working through your code i Have found very few things to criticise....</p>\n\n<ol>\n<li>I like the way you are using <code>final</code>.</li>\n<li>I like the general layout and structure</li>\n<li>using compareTo on the BigDecimals is the right thing to do.</li>\n</ol>\n\n<p>If I have one complai... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-28T04:10:36.917",
"Id": "20970",
"Score": "8",
"Tags": [
"java"
],
"Title": "A better hash function for an Equivalence?"
} | 20970 |
<p>This code for the Raspberry Pi board waits for serial input then plays an arrow with a sound and message. I'd like any constructive comments or suggestions.</p>
<pre><code>#include <termios.h>
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <sys/signal.h>
#include &l... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-31T17:43:20.097",
"Id": "33918",
"Score": "1",
"body": "You may get better trackaction if you add C as a language. Though you use one C++ class the code for review is basically C no real C++ features used so you may as well ask for com... | [
{
"body": "<p>Nice. I am working on a similar project. In order to make your code more modular and object oriented, you can write a <code>Message</code> class and a <code>SerialPort</code> class. It makes it much easier to restructure your code when you want to change the behavior. e.g.</p>\n\n<pre><code>Ser... | {
"AcceptedAnswerId": "21152",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-28T09:41:43.017",
"Id": "20974",
"Score": "4",
"Tags": [
"c",
"serial-port",
"raspberry-pi"
],
"Title": "Responding to serial input"
} | 20974 |
<p>My objective has been to build a custom dropdown like the one on Amazon's search scope selector. I do this by positioning a styleable element on top of a standard select list. I then use jQuery to keep the styleable element in sync with the select list. My code works fine, but I would love to learn how to do it clea... | [] | [
{
"body": "<p>It's probably a bit too heavyweight for your task, but have you considered using <a href=\"http://knockoutjs.com/\" rel=\"nofollow\">knockoutJS</a> for it? It's a quite powerful MVVM javascript framework that uses the notion of <a href=\"http://knockoutjs.com/documentation/observables.html\" rel=\... | {
"AcceptedAnswerId": "20989",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-28T10:50:11.353",
"Id": "20976",
"Score": "3",
"Tags": [
"javascript",
"jquery"
],
"Title": "Maintain sync of select list"
} | 20976 |
<p>I was wondering if someone could take some time to look over my portfolio script and see let me know if it's secure enough to be uploaded live and connected to my database. My previous mySQL script was VERY insecure...</p>
<p><strong>The Database Connection:</strong>
<pre><code> public function __construc... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-03-10T16:32:34.520",
"Id": "36541",
"Score": "2",
"body": "Please do not edit the question in a way which makes existing answers meaningless."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-03-10T18:01:24.907",
... | [
{
"body": "<ul>\n<li><p>Your database queries are using bound parameters with prepared statements. Good.</p></li>\n<li><p>You need to <a href=\"http://php.net/manual/en/function.htmlspecialchars.php\" rel=\"nofollow\">escape your output</a>.</p></li>\n</ul>\n\n<p>Other observations:</p>\n\n<ul>\n<li>Your Databa... | {
"AcceptedAnswerId": "21012",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-28T12:55:39.303",
"Id": "20979",
"Score": "2",
"Tags": [
"php",
"mysql",
"pdo"
],
"Title": "How secure is this PDO Portfolio Script?"
} | 20979 |
<p>I've recently discovered how cool <code>reduce()</code> could be and I want to do this:</p>
<pre><code>>>> a = [1, 1] + [0] * 11
>>> count = 1
>>> def fib(x,n):
... global count
... r = x + n
... if count < len(a) - 1: a[count+1] = r
... count += 1
... return r
>... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-28T16:14:07.087",
"Id": "33681",
"Score": "2",
"body": "Why do you want to use reduce?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-28T16:18:40.630",
"Id": "33682",
"Score": "1",
"body": "Bec... | [
{
"body": "<p>If you set</p>\n\n<pre><code>def fib(x, _):\n x.append(sum(x[-2:]))\n return x\n</code></pre>\n\n<p>then:</p>\n\n<pre><code>>>> reduce(fib, xrange(10), [1, 1])\n[1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144]\n</code></pre>\n\n<p>But as long as you're looking for something cool rather t... | {
"AcceptedAnswerId": "21005",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-28T14:29:54.510",
"Id": "20986",
"Score": "4",
"Tags": [
"python",
"fibonacci-sequence"
],
"Title": "Making this reduce() Fibonacci generator better"
} | 20986 |
<p>I have a list with <code>contentlets</code> and want all languages from every <code>contentlet</code> (I get these with the method <code>languageAPI.getAllValuesByKey(key , contentList)</code>. I get a <code>HashMap</code> and iterate over it. There are 1000 keys available. In the beginning it only takes 2 ms per ke... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-28T07:36:42.193",
"Id": "33673",
"Score": "4",
"body": "Use a profiler to find out where the time is spent. Then you'll know what to optimize."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-28T07:37:40.303... | [
{
"body": "<ol>\n<li><p><code>getStringKey</code> iterates over the <code>contentlets</code> list for every <code>key</code>. It looks O(n^2) which does not scale well.\nYou could create a <code>HashMap<ContentletCacheKey, Contentlet></code> cache with a proper <code>hashCode</code> and <code>equals</code... | {
"AcceptedAnswerId": "42712",
"CommentCount": "9",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-28T07:32:49.027",
"Id": "20992",
"Score": "5",
"Tags": [
"java",
"performance",
"iterator"
],
"Title": "How to make an iteration in a for-loop faster?"
} | 20992 |
<p>I'm developing an Android app that performs several requests to a server using the <a href="http://loopj.com/android-async-http/" rel="nofollow">AndroidAsynchronousHttpClient</a>. One of these requests (as an example) is responsible to send the username and password. I created a class <code>Sign</code> that has a st... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-28T17:20:32.857",
"Id": "33694",
"Score": "0",
"body": "It's the singleton which indicates problems with the code."
}
] | [
{
"body": "<p>I see nothing bad with this code. I mean as far as I can see you do not want to store any data, you just want to get the answer from the server, but maybe you want to handle this by an other thread because it can cause delays. </p>\n",
"comments": [
{
"ContentLicense": "CC BY-SA ... | {
"AcceptedAnswerId": "20997",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-28T16:59:32.290",
"Id": "20994",
"Score": "4",
"Tags": [
"java",
"android",
"static"
],
"Title": "Android app for sending username and password requests"
} | 20994 |
<p>I am new to jQuery, and after spending weeks to convert my pages using jQuery, I am now reading about jQuery optimization. In that effort, I'm rewriting one of my functions. Please comment whether it is right (both are working).</p>
<p><strong>Previous</strong></p>
<pre><code>$("#mydiv").empty();
var i = 2;
$("#ax... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-28T19:36:07.640",
"Id": "33708",
"Score": "0",
"body": "you define `mydiv` as a variable, but then you still use `$('#mydiv')`. Could you throw this up into a jsFiddle with some target HTML? I'm not quite clear on what you are trying ... | [
{
"body": "<p>Here are some general optimizations that I usually do.</p>\n\n<p>When you have multiple var declarations you can separate with \",\" making it a bit easier to read and less of a hassle to write:</p>\n\n<pre><code>var mydiv = $(\"#mydiv\").empty(),\n mywid = $(\"#wd\").slider(\"value\"),\n my... | {
"AcceptedAnswerId": null,
"CommentCount": "5",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-28T17:39:31.483",
"Id": "20998",
"Score": "1",
"Tags": [
"javascript",
"jquery"
],
"Title": "Optimized jQuery code check"
} | 20998 |
<p>I have PostgreSQL 9.1.1 running in a shared hosting environment and I'm running this query:</p>
<pre><code>SELECT a.id,
CASE WHEN a.idpai IS NULL THEN a.nome
ELSE concat(a.nome, ' (', b.nome, ')')
END AS nome, a.idpai
FROM localidade a
LEFT OUTER JOIN localidade b ON a.idpai = b.id
WHERE a.idcidade = :idcidade AND ... | [] | [
{
"body": "<p>I think this part:</p>\n\n<pre><code>CASE WHEN a.idpai IS NULL THEN a.nome\nELSE concat(a.nome, ' (', b.nome, ')')\nEND AS nome\n</code></pre>\n\n<p>Can be replaced with:</p>\n\n<pre><code>CONCAT(a.nome, ' (' || b.nome || ')') AS nome\n</code></pre>\n\n<p>If b.nome is NULL, then \"' (' || b.nome ... | {
"AcceptedAnswerId": "23669",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-28T18:30:15.517",
"Id": "20999",
"Score": "4",
"Tags": [
"sql",
"postgresql"
],
"Title": "PostgreSQL simple query with repeated function calls"
} | 20999 |
<p>I'm pulling data from a list of images and passing it into an information container after click. After looking at my logic I assume there is a better way to do this. Any ideas would be helpful.</p>
<pre><code>var getData = function() {
$('.guest-image').html('<img src="' + $($this).data("image") + '" />');
... | [] | [
{
"body": "<p>squished and optimized, the code looks like this:</p>\n\n<pre><code>function getData() {\n var guestData = $('.guest-data'),\n knownFors = $('.known-for li', guestData),\n data = $($this).data();\n $('.guest-image').html('<img src=\"' + data.image + '\"/>');\n $.each(data.knowns, fu... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-28T22:47:39.913",
"Id": "21006",
"Score": "4",
"Tags": [
"javascript",
"jquery",
"html"
],
"Title": "Improving logic for pulling and passing data();"
} | 21006 |
<p>My task is:</p>
<p>Write a program that reads integers until 0 is entered. After input terminates, the
program should report the total number of even integers (excluding the 0)
entered, the average value of the even integers, the total number of odd integers
entered, and the average value of the odd integers.</p>
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-28T23:48:45.827",
"Id": "33724",
"Score": "0",
"body": "It's a little weird that you're using a `switch` for a 2-case scenario; an `if-else` would be more appropriate."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate":... | [
{
"body": "<ol>\n<li><p>It does not work well on my machine (gcc version 4.4.5):</p>\n\n<pre><code>please enter some numbers: \n1\n2\n3\n0\neven total: 1, even average: 134519058\nodd total: 2, odd average: 67257214\n</code></pre></li>\n<li><p>The size of <code>oddArray</code> and <code>evenArray</code> is zero... | {
"AcceptedAnswerId": "21009",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-28T23:33:53.673",
"Id": "21007",
"Score": "4",
"Tags": [
"c"
],
"Title": "Testing numbers using 'switch'"
} | 21007 |
<blockquote>
<p>Write a program that reads input up to # and reports the number of times that
the sequence ei occurs.</p>
</blockquote>
<p>Is this a decent code?</p>
<pre><code>#include <stdio.h>
int main(void)
{
int index = 0, combinationTimes = 0, total = 0;
char userInput;
char wordChar[ind... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-29T02:21:29.600",
"Id": "33730",
"Score": "0",
"body": "Posted my original comment as answer because spaces in comments are stupid."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-29T02:40:51.283",
"Id"... | [
{
"body": "<p>Here are some inputs on command line which break your code:</p>\n\n<pre><code>dan@albatross $ gcc -Wall f.c -o f\ndan@albatross $ ./f\nplease enter your input:\nbfiqwb23b r9pu3h2ru23r\n9aisdbfuiasdf\nadsf#asdf\n#\n#\n#\n adsfadsfasdf\n34324!\n^C\n</code></pre>\n\n<p>I assume your program is s... | {
"AcceptedAnswerId": "21011",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-29T01:12:22.937",
"Id": "21010",
"Score": "4",
"Tags": [
"c",
"io"
],
"Title": "Detecting a combination of characters from input"
} | 21010 |
<p>Here is a program which keeps track of the longest path in a graph. I think it can be written much better.</p>
<pre><code>from Tkinter import *
'''
This program tries to compute the longest path (largest number of
consecutive edges) currently in the graph at any point.
The edges will be labelled as roads, connect... | [] | [
{
"body": "<h3>1. Comments on your code</h3>\n\n<ol>\n<li><p>I didn't understand everything that the code was trying to do. What's the difference between a <em>road</em> and a <em>path</em>? What's going on with all that merging and branching? Is it important, or is it just part of your longest-path-finding alg... | {
"AcceptedAnswerId": "21022",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-29T03:10:12.670",
"Id": "21014",
"Score": "3",
"Tags": [
"python",
"graph",
"tk"
],
"Title": "Evaluating longest path"
} | 21014 |
<p>I'm using the following technologies: Google App Engine, GAE Datastore, Struts2. <code>Common lang</code> java library were also used.</p>
<p>Because of the limitation on aggregation for datastore, I'm using <a href="http://jagg.sourceforge.net" rel="nofollow">jagg</a> for aggregation on List of <code>Profile</code... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-29T21:42:24.197",
"Id": "33794",
"Score": "0",
"body": "You may want to look into [JodaTime](http://joda-time.sourceforge.net/), which is considered a superior implementation than the standard Java handling of date/time."
},
{
... | [
{
"body": "<blockquote>\n <p>Can I improve it's performance in terms of speed?</p>\n</blockquote>\n\n<p>Yes.</p>\n\n<p>As there is no specific value in my one word answer, the same does apply to your question for me. Are there any requirements for speed? If no, then just do not take care about it and save you... | {
"AcceptedAnswerId": "21030",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-29T04:46:26.477",
"Id": "21015",
"Score": "1",
"Tags": [
"java",
"google-app-engine",
"struts2"
],
"Title": "Aggregation on List"
} | 21015 |
<p>I am attempting to refactor my app using the MVC paradigm.</p>
<p>My site displays charts. The URLs are of the form</p>
<ul>
<li><code>app.com/category1/chart1</code></li>
<li><code>app.com/category1/chart2</code></li>
<li><code>app.com/category2/chart1</code></li>
<li><code>app.com/category2/chart2</code></li>
</... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-30T12:41:43.807",
"Id": "33826",
"Score": "0",
"body": "it is ideal situation when you need 1-to-1 route-to-controller. Real life case can be more complicated and I would use one controller to handle this identical operations"
},
{... | [
{
"body": "<p>You could try urls like this:</p>\n\n<pre><code>/category/1/chart/1\n/category/1/chart/2\n/category/2/chart/1\n</code></pre>\n\n<p>Where your application controller structure looks like this:</p>\n\n<pre><code>+-Application/\n +-Category/\n +-Controller/\n +-ChartController.php\n</cod... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-29T06:58:38.633",
"Id": "21016",
"Score": "2",
"Tags": [
"php",
"mvc",
"url-routing"
],
"Title": "Routing, Navigation and State in MVC"
} | 21016 |
<p>I want to perform standard additive carry on a vector. The base is a power of 2, so we can swap modulus for bitwise AND.</p>
<pre><code>def carry(z,direction='left',word_size=8):
v = z[:]
mod = (1<<word_size) - 1
if direction == 'left': v = v[::-1]
accum = 0
for i in xr... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-29T13:30:16.583",
"Id": "33753",
"Score": "0",
"body": "It would be very handy if you include some `assert`s (3 ó 4) so people can test their refactors easily."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-0... | [
{
"body": "<p>I got it:</p>\n\n<pre><code>def carry2(z,direction='left',word_size=8):\n x = z[:]\n v = []\n mod = (1<<word_size) - 1\n if direction == 'left': x.reverse()\n def cu(a,n):\n v.append((a+n)&mod)\n return (a+n) >> word_... | {
"AcceptedAnswerId": "21029",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-29T09:46:03.803",
"Id": "21019",
"Score": "2",
"Tags": [
"python",
"converting"
],
"Title": "Convert carry-add loop to a map or reduce to one-liner"
} | 21019 |
<p>My task is:</p>
<blockquote>
<p>Write a program that requests the hours worked in a week and then
prints the gross pay, the taxes, and the net pay. Assume the
following:</p>
<ol>
<li>Basic pay rate = $10.00/hr</li>
<li>Overtime (in excess of 40 hours) = time and a half</li>
<li>Tax rate: 15% of the... | [] | [
{
"body": "<p>I'd start extracting some more functions.</p>\n\n<p>What about decomposing</p>\n\n<pre><code>int NetPay(int hours){\n int payedBeforeTaxes = payedBeforeTaxes(hours);\n return applyTaxes(payedBeforeTaxes);\n}\n\nint payedBeforeTaxes(hours){\n return regularPay(hours) + overtimePay(hours);\... | {
"AcceptedAnswerId": "21028",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-29T13:16:20.383",
"Id": "21027",
"Score": "2",
"Tags": [
"c",
"finance"
],
"Title": "Calculate weekly net pay"
} | 21027 |
<p>I am working on a webforms project using c#/aspx/jquery. I'm not sure where to handle my <code>Onclick</code>. Both options (doing it in C# or jquery) seem feasible. Which would be better practice?</p>
<p>Here is the scenario:</p>
<p>I want to build a <code>checkbox</code> which will toggle a <code>textbox's textm... | [] | [
{
"body": "<p>You cannot change the type of the input field on client side in some or all browsers. I would create a custom hiding method in Javascript and leave the input type in text mode (SingleLine), but maybe this has some drawbacks in security.</p>\n\n<p>Other solution is to remove the original input and ... | {
"AcceptedAnswerId": "21034",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-29T15:29:25.757",
"Id": "21031",
"Score": "1",
"Tags": [
"c#",
"asp.net"
],
"Title": "Handle OnClick in Jquery or C#"
} | 21031 |
<p>I'm trying to learn how to write functional code with Python and have found some tutorials online. Please note that I know Python is not a promoter for functional programming. I just want to try it out. <a href="http://anandology.com/python-practice-book/functional-programming.html">One tutorial</a> in particular gi... | [] | [
{
"body": "<p>Your solution really isn't at all functional. You should return a flattened dict and then merge that into your current dictionary. You should also not modify the dictionary, instead create it with all the values it should have. Here is my approach:</p>\n\n<pre><code>def flatten_dict(d):\n def i... | {
"AcceptedAnswerId": "21035",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-29T16:08:41.920",
"Id": "21033",
"Score": "14",
"Tags": [
"python",
"functional-programming"
],
"Title": "Flatten dictionary in Python (functional style)"
} | 21033 |
<p>This is a working mergesort implementation I wrote as I'm trying to get back into C.</p>
<p>I am not so much interested in feedback on the optimality of the algorithm (as I could read up countless articles I'm sure), but deep criticism of my style would be greatly appreciated.</p>
<pre><code>#include<stdio.h>... | [] | [
{
"body": "<p>I can't fault too much here, it's generally looking pretty reasonable. I think the first point below is the most important, depending on how much experience you have with C, the second may or may not make much sense.</p>\n\n<h2>Information Hiding</h2>\n\n<p>Firstly, you should split this up into s... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-29T16:37:45.273",
"Id": "21036",
"Score": "5",
"Tags": [
"c",
"mergesort"
],
"Title": "ANSI C Mergesort"
} | 21036 |
<p>My task is ask this from the user:</p>
<pre><code>Enter the number corresponding to the desired pay rate or action:
1) $8.75/hr 2) $9.33/hr
3) $10.00/hr 4) $11.20/hr
5) quit
</code></pre>
<p>If choices 1 through 4 are selected, the program should request the hours
worked. The program should r... | [] | [
{
"body": "<ol>\n<li>Create better names for the rate levels, maybe you could use positions or titles (e.g. entry level rate, mid level rate, etc.). </li>\n<li>Consistent use of whitespace would help readability </li>\n<li>Pull the switch statement out into a different method </li>\n</ol>\n\n<p>like below: </p>... | {
"AcceptedAnswerId": "21054",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-29T16:48:33.373",
"Id": "21037",
"Score": "4",
"Tags": [
"c"
],
"Title": "Using 'switch to choose different rates to calculate net pay"
} | 21037 |
<p>I was interested in feedback on this architecture.</p>
<p>Objective: serialize / deserialize a network application protocol stream.</p>
<p>Approach: Create a class for each layer/object which exposes attributes as well as encapsulating the stream reader/writer.</p>
<p>If instantiated for serialization the object ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-29T21:01:07.650",
"Id": "33786",
"Score": "2",
"body": "Is there a reason why are you doing this all by yourself, instead of using a library like [Protocol Buffers](http://code.google.com/p/protobuf-net/)?"
},
{
"ContentLicense... | [
{
"body": "<p>I' not sure about having two constructors that would be used in different contexts i.e. one for serialization and one for serialization. It seems like to much of a constraint on the object before you even begin to use it.</p>\n\n<p>I think I would prefer to having a HdcpGammaDataReader and a Hdcp... | {
"AcceptedAnswerId": "21043",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-29T18:57:01.920",
"Id": "21042",
"Score": "3",
"Tags": [
"c#"
],
"Title": "Layered network protocol serialize / deserialize"
} | 21042 |
<p>I've got server running to make serial data available on a TCP/IP port. My goal is to collect data coming from a realtime device connected to the serial port and deliver it to web clients connected to an express server using socket.io as the data is collected from a backend socket. I want the backend socket to recon... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2014-03-17T14:21:33.167",
"Id": "77347",
"Score": "0",
"body": "You are defining a lot of constants at the beginning of the file. I would suggest that you use ONLY_CAPS_FOR_CONSTANTS like proposed here http://google-styleguide.googlecode.com/s... | [
{
"body": "<p>A fun piece of code, </p>\n\n<ul>\n<li><p>You clearly took the single comma separated <code>var</code> statement all the way, I would still group the related variables ( requires, module, server info, timeouts etc.):</p>\n\n<pre><code>var express = require('express'),\n routes = require('./rou... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-29T22:44:01.967",
"Id": "21047",
"Score": "3",
"Tags": [
"javascript",
"node.js",
"express.js",
"client",
"socket.io"
],
"Title": "Delivering realtime data from backend socke... | 21047 |
<p>This is my first code in C++. Since I'm new to the language, I'm just looking for pointers on what can be made better. I tried to cut out unnecessary stuff, but there are some comments in there. I know Java, so if you're trying to explain anything in Java, I can understand it.</p>
<p>Feel free to mention anythin... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-30T15:46:25.607",
"Id": "33838",
"Score": "3",
"body": "The main issue in this program is the program design. Most importantly, you need to use the most fundamental concept in object-oriented design: private encapsulation. C++ is no di... | [
{
"body": "<p>Without changing things too much...</p>\n\n<ul>\n<li><p>You need some <code>#include</code>s.</p></li>\n<li><p>Don't use <code>using namespace</code>. One of the issues is knowing where a function comes from (which one is being used) - this hides it. Using a short <code>std::</code> gains you a lo... | {
"AcceptedAnswerId": "21057",
"CommentCount": "6",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-30T03:10:07.243",
"Id": "21048",
"Score": "12",
"Tags": [
"c++",
"beginner",
"parsing",
"mathematics"
],
"Title": "Parsing numbers from equations into strings"
} | 21048 |
<p>I have some entities in use in my project, and to make things easier, I would like to have the type of the key for that entity defined via a generic. E.g.:</p>
<pre><code>public abstract class Entity<T>
{
public virtual T Id { get; set; }
}
</code></pre>
<p>This way, I can pull the Id field into the base... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-30T10:28:45.967",
"Id": "33809",
"Score": "3",
"body": "I think there is no tidier way, as long as you want to keep everything generic."
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-30T17:53:23.237",
... | [
{
"body": "<p>There is no way to simplify generic parameters if you want to keep Entity class generic, as noted by @svick. </p>\n\n<p>The only thing I can suggest as alternative here is to remove generic parameter from <code>Entity</code>. I don't think you need 10 different types for <code>Id</code> field, mo... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-30T05:40:43.140",
"Id": "21052",
"Score": "3",
"Tags": [
"c#",
"generics"
],
"Title": "Is there a better way of defining generic entity classes?"
} | 21052 |
<p>My task was:</p>
<p>Write a program that accepts an integer as input and then displays all the prime
numbers smaller than or equal to that number.</p>
<p>And my code is:</p>
<pre><code>#include <stdio.h>
void FindPrime(int number);
int main()
{
int userInput, counter;
printf("Please enter a... | [] | [
{
"body": "<p>To see if a number is prime, you only need to check that the <code>number</code> is divisible by any number between 2 and Square root of <code>number</code>. Cause if the <code>number</code> is divisible by any number between 2 and <code>sqrt(number)</code> then it will also have the corresponding... | {
"AcceptedAnswerId": "21062",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-30T11:09:15.880",
"Id": "21056",
"Score": "4",
"Tags": [
"c",
"primes"
],
"Title": "Get a limit number to test all the prime numbers it contains in C"
} | 21056 |
<p>I think understanding basic data compression and pattern finding / entropy reduction primitives is really important. Mostly the basic algorithms (before the many tweaks and optimizations are made) are really elegant and inspiring. What's even more impressive is how widespread they are, but perhaps also how little th... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-30T14:17:39.953",
"Id": "33828",
"Score": "0",
"body": "A couple of bugs: (i) in `rot` `v[-1]` should be `v[-1:]` (ii) in `lz78` there's a reference to an undefined variable `empty`."
},
{
"ContentLicense": "CC BY-SA 3.0",
... | [
{
"body": "<h3>1. Introduction</h3>\n\n<p>The only actual question you asked is about how to make the inverse Burrows–Wheeler transform go faster. But as you'll see below, that's plenty for one question here on Code Review. If you have anything to ask about your LZ77 and LZ78 implementations, I suggest you star... | {
"AcceptedAnswerId": "21120",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-30T12:06:23.913",
"Id": "21058",
"Score": "16",
"Tags": [
"python",
"performance",
"strings",
"compression"
],
"Title": "Increasing speed of BWT inverse"
} | 21058 |
<p>I'm new to Python and GAE, but years of procedural programming. I have this code, but I know that there must be some better solution to avoid retyping code.</p>
<p>The first and last section of code are identical in both GET and POST methods, so I suppose there must be another way to share the identical code.</p>
... | [] | [
{
"body": "<p>This line looks suspicious:</p>\n\n<pre><code> if person.email: self.request.get('email')\n</code></pre>\n\n<p>I assume it should be:</p>\n\n<pre><code> person.email = self.request.get('email')\n</code></pre>\n\n<p>Your code seem to be using excessive indentation. The python ... | {
"AcceptedAnswerId": "21065",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-30T12:42:09.623",
"Id": "21061",
"Score": "3",
"Tags": [
"python",
"beginner",
"google-app-engine"
],
"Title": "User account code with GET and POST"
} | 21061 |
<pre><code>List<int> types = new List<int>();
foreach (var d in myTableList)
{
if (!types.Contains((int)d.item_type))
types.Add((int)d.item_type);
}
</code></pre>
<p>I have a table in db called myTable. There is a column in it called item_type. It is integer.</p>
<p>I want to make a list which... | [] | [
{
"body": "<p>Try</p>\n\n<pre><code>types = myTableList\n .Select(x => (int)x.item_type)\n .Distinct();\n</code></pre>\n\n<p>You may also want to add <code>.ToList()</code> at the end if you want to match original code</p>\n",
"comments": [],
"meta_data": {
"CommentCount": "0",
"Con... | {
"AcceptedAnswerId": "21064",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-30T13:39:58.023",
"Id": "21063",
"Score": "1",
"Tags": [
"c#",
"linq",
"entity-framework"
],
"Title": "Optimizing a distinction code"
} | 21063 |
<p>I wrote my own version of <code>endswith</code> just like in high-level programming languages in C which I would like reviews on.</p>
<p>There are 2 versions. One is my own and the other is from <a href="https://github.com/rustyrussell/ccan/" rel="nofollow">ccan</a>. For some reason, I feel that <a href="https://gi... | [] | [
{
"body": "<p>I like the more the first, because it works at an higher level of abstraction and it makes it clear that you are interested in comparing a part of the string with the postfix.</p>\n\n<p>I'd probably introduce another variable to clearly represent that you are comparing the postfix with the latest ... | {
"AcceptedAnswerId": "21121",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-30T16:01:16.833",
"Id": "21066",
"Score": "6",
"Tags": [
"c"
],
"Title": "string manipulation, which version of those 2 functions is better?"
} | 21066 |
<p>I'm building a symfony project and at some point I've come up with a switch case to manage the acl rights. I would prefer using a dynamic access to the constant but havn't find a good solution. I've seen reflection but that doesn't seem to be the proper solution to me.</p>
<pre><code>$mask = null;
switch ($partici... | [] | [
{
"body": "<p>You mean something like this? </p>\n\n<pre><code>$mask = constant('Symfony\\Component\\Security\\Acl\\Permission\\MaskBuilder::MASK_' . $participant->getRight()) ?: null;\n$this->aclManager->addObjectPermission($project, $mask, $user);\n</code></pre>\n\n<p>Or if you don't care about reada... | {
"AcceptedAnswerId": "21127",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-30T18:56:27.680",
"Id": "21072",
"Score": "3",
"Tags": [
"php",
"authorization"
],
"Title": "Building an ACL based on permission level"
} | 21072 |
<p>I have the following bit of code the calls out to two different command line components (each wrapped in their own Task)</p>
<pre><code>public async Task<FileInfo> RasterizeAllPdfs(IEnumerable<Uri> targetUris, FileInfo destination = null)
{
// rasterize uris to files in the rasterizedOutput director... | [] | [
{
"body": "<p>You are using <code>async</code>/<code>await</code> absolutely correctly, that's how they were supposed to be used. </p>\n\n<p>Please note that from this code it's hard to tell whether the method will return the <code>Task</code> immediately, since it will be waiting synchronously for <code>raster... | {
"AcceptedAnswerId": "21081",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-30T21:43:47.353",
"Id": "21078",
"Score": "3",
"Tags": [
"c#",
"asynchronous",
"async-await"
],
"Title": "Am I using async C# correctly?"
} | 21078 |
<p>I created a quick program to test the precision of randomness generated by the <code>.rand</code> method. The primary question is whether I can use the <code>.times</code> method in place of the <code>while</code> code blocks to increase efficiency and: </p>
<ol>
<li>Whether such a practice would reduce the amount ... | [] | [
{
"body": "<p>It looks like you've done some procedural programming before? In Ruby you usually avoid using iterator variables like the i for simplicity.</p>\n\n<p>The first while loop could be: <code>4000.times { x << rand(2) }</code>\nA while loops is actually slightly quicker (>10%) but seldom used bec... | {
"AcceptedAnswerId": "21180",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-30T21:54:57.937",
"Id": "21080",
"Score": "5",
"Tags": [
"ruby",
"array",
"random",
"iterator",
"iteration"
],
"Title": "Most efficient way to iterate through arrays/can I... | 21080 |
<p>A basic shell function to <a href="https://unix.stackexchange.com/questions/9123/is-there-a-one-liner-that-allows-me-to-create-a-directory-and-move-into-it-at-th/9124#9124">create a directory and change to it</a> goes like this:</p>
<pre><code>mkcd () { mkdir "$1" && cd "$1"; }
</code></pre>
<p>This works ... | [] | [
{
"body": "<p>Some error messages may be confusing like:</p>\n\n<pre><code>$ mkcd /foo/../bar\nmkcd:cd:3: no such file or directory: /foo/..\n$ mkcd /bin/../bar\nmkdir: cannot create directory `./bar': Permission denied\n</code></pre>\n\n<p>Probably not much you can do about that.</p>\n",
"comments": [
... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-30T22:25:31.857",
"Id": "21082",
"Score": "11",
"Tags": [
"bash",
"shell",
"unix"
],
"Title": "Make a directory and change to it"
} | 21082 |
<p>My code blinks text for an interval of time then clears the text.</p>
<p>I plan to use this code in a quiz web app. When the user gets an answer right, "CORRECT!" will blink on the screen for 10 seconds. When the user gets an answer wrong, "INCORRECT!" will blink on the screen for 10 seconds.</p>
<p>I'm looking fo... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-31T15:08:28.713",
"Id": "33908",
"Score": "0",
"body": "I would suggest using a library, for example:\nhttp://docs.jquery.com/UI/Effects/Pulsate"
}
] | [
{
"body": "<p>It doesn't look very complex to me but the variable names could use some attention, as they're not very descriptive. I'd suggest:</p>\n\n<ul>\n<li><code>textHidden</code> instead of <code>flag</code></li>\n<li><code>timesBlinked</code> instead of <code>i</code></li>\n<li><code>targetElement</code>... | {
"AcceptedAnswerId": "21110",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-31T00:48:59.773",
"Id": "21086",
"Score": "1",
"Tags": [
"javascript",
"html"
],
"Title": "Blink Text with JavaScript"
} | 21086 |
<p>I have such method and have a hard time optimizing it to run better. It takes roughly 1 sec with 100 units to get between <code>NSLog(@"Debug2")</code> and <code>NSLog(@"Debug3")</code>. And 2 sec on iPhone.</p>
<p>Method idea: </p>
<p><strong>Input</strong>: </p>
<ul>
<li><code>NSMutableArray</code> <code>times<... | [] | [
{
"body": "<p><code>times.count</code> in <code>for(int x = 0; x != times.count; x++)</code> is a method call, move it to a variable. Also, you should probably use the <code><</code> instead of <code>!=</code> as it is more common.</p>\n\n<p>However, as you don't really need the index of the element, you can... | {
"AcceptedAnswerId": "21104",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-31T07:25:51.597",
"Id": "21099",
"Score": "1",
"Tags": [
"objective-c",
"ios"
],
"Title": "Optimizing iOS method in objective-c"
} | 21099 |
<p>Someone asked me if I can create factory pattern in java without using If-else construct. So I come with the following. Please provide your inputs if this seems a good example for using factories.</p>
<pre><code>public enum EnumButtonFactory {
RADIO(RadioButton.class),
SUBMIT(SubmitButton.class),
NORMAL(NormalButt... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-31T13:31:59.087",
"Id": "33899",
"Score": "2",
"body": "Can you provide an example for the use case? What do you want to replace with this implementation. This could help to get the direction. Because the typical factory pattern does n... | [
{
"body": "<p>This is a good example for demonstrating that you can implement factory pattern without conditional statements. Of course, no piece of code is good for every imaginable requirement.</p>\n\n<p>In real world cases factory pattern usually needed because some aspect of the object building is not trivi... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-31T08:36:57.780",
"Id": "21102",
"Score": "10",
"Tags": [
"java",
"design-patterns"
],
"Title": "FactoryPattern without If-else construct"
} | 21102 |
<p>I'm currently using this pattern to create and extend a globally accessible custom plugin to be used in a web application:</p>
<pre><code>; // defensive programming: script may be concatenated with others
(function($) {
"use strict";
// allow Plugin to be extended from other scripts
var window.Plugin ... | [] | [
{
"body": "<p>The usual way to create a plugin is to declare a namespace or use an existing and append to it. Usually done using the module pattern:</p>\n\n<pre><code>(function(ns){\n\n //private scoping\n var privVar = '...';\n function priv(){...}\n\n //expose a function\n ns.myFunc = function(){...};\n\... | {
"AcceptedAnswerId": "21147",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-31T10:57:01.853",
"Id": "21105",
"Score": "7",
"Tags": [
"javascript",
"design-patterns",
"plugin"
],
"Title": "Pattern for creating a globally accessible custom plugin"
} | 21105 |
<p>Could I code differently to slim down the point of this Python source code? The point of the program is to get the user's total amount and add it to the shipping cost. The shipping cost is determined by both country (Canada or USA) and price of product: The shipping of a product that is $125.00 in Canada is $12.00.<... | [] | [
{
"body": "<p>Sure you can condense some things, and improve the input loop. But I find your original code easy to read, whereas this is probably harder to read : </p>\n\n<pre><code>banner = 'Now we\\'ll calculate your total charge, including shipping.'\ncost_prompt = 'Enter your to... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-31T12:48:53.977",
"Id": "21113",
"Score": "5",
"Tags": [
"python"
],
"Title": "Calculate shipping cost"
} | 21113 |
<p>I need to write a procedure, that will take a dictionary consisting of server names and their available slots and a number of slots required, and redispatch it over the servers, so that every server would accept only that many assignments as he has free slots; servers with higher number of free slots would be assign... | [] | [
{
"body": "<p>You can solve this mathematically. Let's suppose there are \\$m\\$ hosts and \\$n\\$ jobs. Sort the hosts into ascending order by their slots, so that \\$s_i\\$ is the number of slots for host number \\$i\\$, and we have \\$s_0 ≤ s_1 ≤ \\dotsb ≤ s_{m−1}\\$.</p>\n\n<p>Now we can immediately figure ... | {
"AcceptedAnswerId": "21125",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-31T17:23:10.183",
"Id": "21122",
"Score": "2",
"Tags": [
"python",
"hash-map",
"iteration"
],
"Title": "Iterating X times (where X > Y) over Y element dictionary"
} | 21122 |
<p>So I'm curious about a few things that I did here design wise, as well as one space I'm sure I can be given improvements from real haskellers.</p>
<p><strong>The part I really think can be done better that I'm falling short is my validateItem/validateStore/validateUser methods, these just feel more convoluted than ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-01T07:25:33.187",
"Id": "33960",
"Score": "0",
"body": "I don't know enough Haskell to give this a full review, but it seems to me that record syntax could eliminate at least some of the annoying get functions, especially for `User`? A... | [] | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-31T18:36:17.803",
"Id": "21126",
"Score": "1",
"Tags": [
"haskell",
"validation"
],
"Title": "Data model with validation in haskell couple convoluted functions"
} | 21126 |
<p>I am learning MVC, and trying to understand routing.</p>
<p>I understand that if I want to show an individual blog post for site.com/54, my route would be something like</p>
<pre><code>//index.php
$controller = new Controller();
if ( preg_match("#/(0-9.)#", $uri, $matches) ) {
$controller->showAction($match... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2015-08-19T21:19:04.770",
"Id": "185417",
"Score": "0",
"body": "The desire to improve code is implied for all questions on this site. Question titles should reflect the purpose of the code, not how you wish to have it reworked. See [ask]."
... | [
{
"body": "<p>Have you thought about calling the overview only when the URI ends in \"overview\" and preceded by a product slug?</p>\n\n<pre><code>$controller = new Controller();\nif ( preg_match(\"#^/([a-zA-Z0-9_-]+)/overview/?$#\", $uri, $matches) ) {\n $controller->showOverview($matches[1]);\n}\n</code... | {
"AcceptedAnswerId": "21177",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-31T19:20:27.507",
"Id": "21128",
"Score": "1",
"Tags": [
"php",
"mvc",
"url-routing"
],
"Title": "Trying to understand appropriate routing in MVC"
} | 21128 |
<p>I have the following logic:</p>
<pre><code>bool a;
bool b;
int v = 0;
//code here to set the values of a and b...
if(b)
{
v = a ? 1 : 2;
}
else
{
v = a ? 0 : 1;
}
</code></pre>
<p>I believe that there may be a way to minimize this logic (or rewrite it in a more clever way) that I am not thinking of.</p>... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-03T09:04:20.133",
"Id": "34099",
"Score": "1",
"body": "I find this question too abstract; it can't be answered in a meaningful way. What do `a`, `b`, and `v` *represent?* The *clever way* is often the *wrong way*."
},
{
"Conte... | [
{
"body": "<pre><code>int v = b ? (a ? 1 : 2) : (a ? 0 : 1);\n</code></pre>\n\n<p><strong>EDIT #1:</strong></p>\n\n<p>As per <a href=\"https://codereview.stackexchange.com/users/2041/svick\">svick</a>, parsed out conditional operator on separate lines:</p>\n\n<pre><code>int v = b\n ? (a ? 1 : 2)\n : (a ? ... | {
"AcceptedAnswerId": "21148",
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-31T19:48:18.793",
"Id": "21130",
"Score": "4",
"Tags": [
"c#",
"optimization"
],
"Title": "Optimize boolean statements"
} | 21130 |
<p>Anyone have any comments? Just trying to better my code if can be done.</p>
<pre><code>public class SacWidget extends AppWidgetProvider {
String roseUrl;
AQuery aq;
public void onUpdate(Context context, AppWidgetManager appWidgetManager,
int[] appWidgetIds) {
final int N = appWidget... | [] | [
{
"body": "<p>I'm not too familiar with Android, so the following is just some generic Java notes:</p>\n\n<ol>\n<li><p>Fields <code>roseUrl</code> and <code>aq</code> seem unused as well as the <code>pendingIntent</code> local variable. You might remove them.</p></li>\n<li><p>You could use a foreach loop: </p>\... | {
"AcceptedAnswerId": "21133",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-31T19:57:34.903",
"Id": "21131",
"Score": "3",
"Tags": [
"java",
"android",
"file"
],
"Title": "Android widget code"
} | 21131 |
<p>I testing F# code which calculates "nearness" of two N-dimensional points using a least square euclidean distance algorithm. The class library is written in F# and the calling will be from VB.NET. The code will eventually be used for scientific binary data, however I wanted a simple real world test environment.</... | [] | [
{
"body": "<pre><code>type MyColor = \n { Name: string;\n Values: float[];\n }\n</code></pre>\n<p>The usual syntax is to put the opening <code>{</code> right after <code>=</code>.</p>\n<p>Also, why are you using <code>float</code>s (or <code>Double</code>s in VB) for the values? Integers should be enough... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-31T20:20:45.160",
"Id": "21134",
"Score": "2",
"Tags": [
"algorithm",
"vb.net",
"f#"
],
"Title": "VB.Net interfacing with F# Euclidean Distance Algorithm"
} | 21134 |
<p>I came up with this jQuery snippet to add/remove a class on <code><label></code> tags that contain either checkboxes or radio buttons, in order to improve usability so users can see what item(s) they have selected.</p>
<p>But I would like to know if there's a way to optimize the code (or not if that's the cas... | [] | [
{
"body": "<p>You are probably pretty good here. </p>\n\n<p>You might be able to micro optimize by only highlighting / un-highlighting the corresponding label of the input but unless you have 100s of labels on your form I wouldn't bother. Especially since the radio button implementation would not be simple.</... | {
"AcceptedAnswerId": "21163",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-31T20:27:58.383",
"Id": "21135",
"Score": "2",
"Tags": [
"javascript",
"jquery"
],
"Title": "Add/remove class to label tags"
} | 21135 |
<p>I am new to Python and I want to see how can I improve my code to make it faster and cleaner. Below you can see the code of Margrabe's Formula for pricing Exchange Options. </p>
<p>I think the part where I check if the argument is None and if not take predetermined values, can be improved but i don't know how to do... | [] | [
{
"body": "<p>First of all, when you compare to <code>None</code>, you are better off using <code>if stock1 is None:</code> - an object can define equality, so potentially using <code>==</code> could return <code>True</code> even when <code>stock1</code> is not <code>None</code>. Using <code>is</code> checks <e... | {
"AcceptedAnswerId": "21140",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-31T22:01:59.283",
"Id": "21139",
"Score": "2",
"Tags": [
"python"
],
"Title": "Improving my code of Margrabe Formula in Python"
} | 21139 |
<p>The problem with computing a radix using a non-imperative style of programming is you need to calculate a list of successive quotients, each new entry being the quotient of the last entry divided by the radix. The problem with this is (short of using despicable hacks like log) there is no way to know how many divisi... | [] | [
{
"body": "<p>From my perspective, I'd say use the generator. It's concise and easily readable to most people familiar with Python. I'm not sure if you can do this in a functional sense easily without recreating some of the toolkit of functional programming languages. For example, if I wanted to do this in Hask... | {
"AcceptedAnswerId": "21155",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-01T03:18:20.403",
"Id": "21151",
"Score": "2",
"Tags": [
"python",
"functional-programming"
],
"Title": "Most concise Python radix function using functional constructions?"
} | 21151 |
<p>This library is a markup parser which is intended to be used in node.js and browser environment. I've decided to use Jasmine for tests.</p>
<p>The library's name is ivy-markup. URL: <a href="https://github.com/AlexAtNet/ivy-markup" rel="nofollow">https://github.com/AlexAtNet/ivy-markup</a></p>
<p>It would be great... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-01T03:37:53.720",
"Id": "33945",
"Score": "0",
"body": "My first comment would be: Don't make people include 4 separate script files to use your library. Why not provide a fifth script that just includes the other 4 scripts when it r... | [
{
"body": "<p>I've stared at the code for a while;</p>\n\n<ul>\n<li><p>I assuming you wrote <code>whitespaceCharacter</code> to mimic the separation between <code>characters</code> and <code>character</code>. However, since you only refer once to <code>whitespaceCharacter</code> I would put that function inside... | {
"AcceptedAnswerId": "43706",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-01T03:29:23.530",
"Id": "21153",
"Score": "3",
"Tags": [
"javascript",
"parsing",
"node.js",
"template",
"modules"
],
"Title": "JavaScript templating language: ivy-markup"... | 21153 |
<p>Simplified working <a href="http://jsbin.com/efeyuw/1" rel="nofollow">demo code here</a>.</p>
<p>Relevant JS code:</p>
<pre><code>;(function(exports) {
//--------------------------------------------------------------------------
//
// Private properties:
//
//----------------------------------... | [] | [
{
"body": "<p>There is only one copy of <code>window.FOO</code> and <code>window.FOO.init</code>, despite its name does not create new objects. <code>window.FOO.init</code> just overwrites <code>_msg</code> that <code>(function(exports) {...</code> closed over each time it is called. <code>_listenForChange()</c... | {
"AcceptedAnswerId": "21170",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-01T04:32:24.777",
"Id": "21156",
"Score": "0",
"Tags": [
"javascript",
"design-patterns"
],
"Title": "Using closure, alias and namespace extension patterns: How to allow for independe... | 21156 |
<p>I use the following PHP Code to output the user's local time and the servers time (office time). <code>$local_time</code> and <code>$remote_time</code> are the corresponding UNIX timestamps:</p>
<pre><code><span class='icon-time' data-time='<?php echo $local_time; ?>' id='local-time'>
Local : <?php e... | [] | [
{
"body": "<p>The thing to understand with <code>setInterval()</code> and other timer-based functions in general is that they <em>do not guarantee precise timing</em>. You request an interval of 60000ms, and your mistake is assuming that what you get is in fact an interval of <em>exactly</em> 60000ms. </p>\n\... | {
"AcceptedAnswerId": "21158",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-01T05:17:18.867",
"Id": "21157",
"Score": "2",
"Tags": [
"javascript",
"php",
"jquery",
"optimization"
],
"Title": "Optimize Clock Update Code To Prevent Bottleneck Resulting ... | 21157 |
<p>I have a list of strings of variable lengths, and I want to pretty-print them so they are lining up in columns. I have the following code, which works as I want it to currently, but I feel it is a bit ugly. How can I simplify it/make it more pythonic (without changing the output behaviour)?</p>
<p>For starters I ... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-01T07:20:20.877",
"Id": "33959",
"Score": "1",
"body": "Not worth an answer, but you can get your rounded-up-not-down integer division to compute `nrows` in a much more compact form as `nrows = (len(words) - 1) // ncols + 1`. Seee e.g.... | [
{
"body": "<p>A slightly more readable version:</p>\n\n<pre><code>def tabulate(words, termwidth=79, pad=3):\n width = len(max(words, key=len)) + pad\n ncols = max(1, termwidth // width)\n nrows = (len(words) - 1) // ncols + 1\n table = []\n for i in xrange(nrows):\n row = words[i::nrows]\n... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-01T06:34:47.553",
"Id": "21159",
"Score": "5",
"Tags": [
"python",
"strings"
],
"Title": "Nicely tabulate a list of strings for printing"
} | 21159 |
<p>The following functional program factors an integer by trial division. I am not interested in improving the efficiency (but not in decreasing it either), I am interested how it can be made better or neater using functional constructions. I just seem to think there are a few tweaks to make this pattern more consisten... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-01T08:44:41.827",
"Id": "33965",
"Score": "0",
"body": "so `factorization` is the function you want out of this? because you don't need `primes` to get it (note also that factorization calls primes and primes calls factorization, that ... | [
{
"body": "<p>A functional recursive implementation:</p>\n\n<pre><code>def factorization(num, start=2):\n candidates = xrange(start, int(sqrt(num)) + 1)\n factor = next((x for x in candidates if num % x == 0), None)\n return ([factor] + factorization(num / factor, factor) if factor else [num]) \n\np... | {
"AcceptedAnswerId": "21168",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-01T07:58:40.743",
"Id": "21165",
"Score": "1",
"Tags": [
"python",
"functional-programming",
"integer"
],
"Title": "How to improve this functional python trial division routine?"
... | 21165 |
<p>I have made this HTML5 structure for a new website I am working on. I'd like to know if there is a more elegant approach to doing it.</p>
<p><img src="https://i.stack.imgur.com/Bhu3J.jpg" alt="Here is the Wireframe"></p>
<ol>
<li>Is the wrapper for the two column considered bad practice?</li>
<li>Should the second... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-01T14:43:09.570",
"Id": "33983",
"Score": "0",
"body": "When you say `Should the secondary navigation on the left should be a as well instead of an article or a div?` are you referring to the wireframe instead of an article or a div?"
... | [
{
"body": "<ol>\n<li><p>Don't worry about wrapping your content too much if the style cannot be achieved without it. If it can, the extra wrap may be overkill.</p></li>\n<li><p>Your markup relies a lot on the <code><article></code> where it may not be necessary. For instance, you put one <code><article... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2013-02-01T08:06:17.800",
"Id": "21166",
"Score": "5",
"Tags": [
"html5"
],
"Title": "Structure of website columns and navigation"
} | 21166 |
<p>I have the following python functions for <a href="http://en.wikipedia.org/wiki/Exponentiation_by_squaring" rel="nofollow noreferrer">exponentiation by squaring</a> :</p>
<pre><code>def rep_square(b,exp):
return reduce(lambda sq,i: sq + [sq[-1]*sq[-1]],xrange(len(radix(exp,2))),[b])
def exponentiate(b,exp)... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-01T10:16:07.310",
"Id": "33973",
"Score": "0",
"body": "A bit of a naive question but why don't you just rewrite the definition of Function exp-by-squaring(x,n) from Wikipedia in proper python ? It seems fine as far as I can tell."
}... | [
{
"body": "<p>You haven't said anything against <a href=\"http://docs.python.org/2/library/itertools.html\" rel=\"nofollow\"><code>itertools</code></a>, so here's how I'd do it with generators:</p>\n\n<pre><code>from itertools import compress\nfrom operator import mul\n\ndef radix(b) :\n while b :\n y... | {
"AcceptedAnswerId": "21183",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-01T09:36:59.913",
"Id": "21169",
"Score": "1",
"Tags": [
"python",
"functional-programming",
"recursion"
],
"Title": "How to improve this functional python fast exponentiation rou... | 21169 |
<p>This is my code:</p>
<pre><code>#include <stdio.h>
#include <ctype.h>
int main()
{
int ch;
int numberOfCharacters = 0;
printf("please enter a word, and ctrl + d to see the resault\n");
while ((ch = getchar()) != EOF && isprint(ch))
{
numberOfCharacters++;
}
... | [] | [
{
"body": "<p>Well, it doesn't do much. But it is not bad. A few issues:</p>\n\n<ul>\n<li>main() should have parameters</li>\n<li>excess blank lines (lines 5, 12, 16, 18) spoil the appearance</li>\n<li>no \\n on the last printf</li>\n<li>the spec doesn't say 'printable' characters, just characters.</li>\n<li>\"... | {
"AcceptedAnswerId": "21172",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-01T10:43:53.433",
"Id": "21171",
"Score": "1",
"Tags": [
"c"
],
"Title": "Devise a program that counts the number of characters in its input up to the end of file"
} | 21171 |
<p>My exercise was:</p>
<blockquote>
<p>Write a program that reads input as a stream of characters until encountering
EOF. Have the program print each input character and its ASCII decimal value.
Note that characters preceding the space character in the ASCII sequence are
nonprinting characters. Treat them spe... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-01T19:12:44.047",
"Id": "34019",
"Score": "2",
"body": "Surprised this works: `printf(\"%c,%d \", ch, ch);` %c is expecting a char while %d an int. While ch is always an int."
},
{
"ContentLicense": "CC BY-SA 3.0",
"Creatio... | [
{
"body": "<p>A few issues, in no particular order:</p>\n\n<ul>\n<li>put <code>main</code> last to avoid the need for a prototype.</li>\n<li><code>main</code> normally takes argc/argv parameters</li>\n<li><p><code>special_chars</code> should be static - but it is debateable whether a separate\nfunction is neces... | {
"AcceptedAnswerId": "21198",
"CommentCount": "2",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-01T14:36:45.537",
"Id": "21174",
"Score": "4",
"Tags": [
"c",
"homework",
"formatting"
],
"Title": "Print character + the ASCII value, 10 pairs per line"
} | 21174 |
<p><a href="http://en.wikipedia.org/wiki/Maximum_subarray_problem" rel="nofollow">Description of Kadane's algorithm</a>.
Please comment on the efficiency and approach.</p>
<pre><code>class Kadane {
int sum = 0;
int max = 0;
public static void main(String[] args) {
int[] full = { 1, 2, 3, 4, 5, -6, -77, 3, 14, -10... | [] | [
{
"body": "<p>Ok, let's take a look:</p>\n\n<pre><code>Kadane Kadane = new Kadane();\n</code></pre>\n\n<p>If there is no need for it, I would use static methods and avoid object creation:</p>\n\n<pre><code>public static int localMax(int[] full, int sublength) {...}\npublic static int splitArr(int[] full) {...}\... | {
"AcceptedAnswerId": "21190",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-01T14:40:23.500",
"Id": "21175",
"Score": "2",
"Tags": [
"java",
"algorithm"
],
"Title": "Kadane's Algorithm, finding maximum contiguous array"
} | 21175 |
<p>I understand that because of JavaScript's single-threaded execution, long loops or recursive calls could make the browser unresponsive while they execute.</p>
<p>I thought about simulating recursion using <code>setTimeout</code> with a delay of 0, so as to queue the next call to execute as soon as possible.</p>
<p... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-01T15:09:51.067",
"Id": "33984",
"Score": "0",
"body": "It may not be directly because of recursion. It may be how you are passing the values per iteration *plus* the fact that JS is known to mishandle floats."
},
{
"ContentLic... | [
{
"body": "<p>A few observations :</p>\n\n<p>Numbers in javascript are <a href=\"http://en.wikipedia.org/wiki/IEEE_floating_point\" rel=\"nofollow\">IEE754</a> double precision float. All of them. There is no integer type. Which means that only 53 bits are available to describe the integer part. So it doesn't m... | {
"AcceptedAnswerId": "21179",
"CommentCount": "10",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-01T14:45:25.713",
"Id": "21176",
"Score": "3",
"Tags": [
"javascript",
"recursion",
"timeout"
],
"Title": "JavaScript \"recursion\" via setTimeout"
} | 21176 |
<p>I have two classes with similar first checking codes, but different behaviors. I suppose there is a way to refactor the code, so I don't need to retype it every time. Is it possible to refactor this, or I must retype this code every time?</p>
<pre><code># Get actual logged user
user, msg = checkLoggedUser()
if use... | [] | [
{
"body": "<p>Create a class</p>\n\n<pre><code>class MyPageHandler(custom.PageHandler):\n def veryUserNotLoggedIn(self):\n if users.getCurrentUser():\n self.renderPage(\"customMessage.htm\", custom_msg=msg)\n return False\n else:\n return True\n</code></pr... | {
"AcceptedAnswerId": "21184",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-01T15:20:37.023",
"Id": "21178",
"Score": "1",
"Tags": [
"python",
"logging"
],
"Title": "Checking for a logged user"
} | 21178 |
<p>Does this code look okay?</p>
<pre><code>#include <stdio.h>
#include <ctype.h>
int case_letters();
int main(void)
{
case_letters();
return 0;
}
int case_letters()
{
int ch;
int numOfUpper = 0;
int numOfLower = 0;
printf("please enter a some characters, and ctrl + d to s... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-01T19:10:40.473",
"Id": "34018",
"Score": "1",
"body": "There are more characters that upper()/lower() and digit(). See http://www.chemie.fu-berlin.de/chemnet/use/info/libc/libc_4.html"
}
] | [
{
"body": "<p>This does not seem to handle if the user enters a special character. ex: <code>* & %</code> etc...</p>\n",
"comments": [],
"meta_data": {
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-01T17:33:09.797",
"Id": "21189",
"Pare... | {
"AcceptedAnswerId": "21189",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-01T15:59:22.143",
"Id": "21182",
"Score": "4",
"Tags": [
"c",
"stream"
],
"Title": "Ask for stream of character input and print number of uppercase/lowercase characters"
} | 21182 |
<p>What I'm trying to accomplish here is to pull a table of open employment positions with AJAX, filter out the garbage code that comes with it, put each <code><tr></code> from the response into its correct category <code><div></code> according to the type of position. </p>
<p>The trick is that there are n... | [] | [
{
"body": "<p>In my opinion, you are trying to solve the wrong issue here. If you want to optimize this entire routine, I have to say you start optimizing at the response.</p>\n\n<p>AJAX is made for a reason, and it was meant to load pages without page loads, or having to wait a lot. The JSON format was also cr... | {
"AcceptedAnswerId": "21217",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-01T17:06:05.940",
"Id": "21185",
"Score": "3",
"Tags": [
"javascript",
"jquery",
"html",
"ajax"
],
"Title": "Filtering and Sorting jQuery Ajax response"
} | 21185 |
<p>I'm trying to create daily, monthly and weekly SQL Query report to our services time we spent int task and total billing time just want to see if I'm on right track </p>
<pre><code>GO
--Daily
SELECT SUM(billingsTimes.actualTotalTime) AS TotalTime, Tasks.taskName, billableType.billableTypeName
FROM ... | [] | [
{
"body": "<p>Somewhat hard to judge without any idea of the schema, but here are a few observations:</p>\n\n<ol>\n<li><p>Join condition on billableType table is questionable: why comparing an ID to a rank in <code>INNER JOIN billableType ON billingsTimes.billableTypeID = billableType.rank</code>?</p></li>\n<li... | {
"AcceptedAnswerId": "22779",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-01T17:53:43.770",
"Id": "21191",
"Score": "0",
"Tags": [
"sql",
"sql-server",
"t-sql"
],
"Title": "Daily, Weekly, Monthly Individual Tech time in task Repoert"
} | 21191 |
<p>I wanted an elegant way to implement memoizing. Here is what I came up with:</p>
<pre><code>function memoize(fn) {
var cache = new WeakMap();
return function() {
if (!cache[arguments]) {
cache[arguments] = fn.call(this, arguments);
}
return cache[arguments];
}
}
</cod... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2015-11-19T10:56:48.450",
"Id": "204950",
"Score": "0",
"body": "You should use `fn.apply` instead of `fn.call` if you want to use the original arguments."
}
] | [
{
"body": "<p>I just thought about this:</p>\n\n<pre><code>function memoize(fn) {\n var cache = {};\n return function() {\n var args = Array.prototype.slice.call(arguments).toString();\n if (!cache[args]) {\n cache[args] = fn.call(this, arguments);\n }\n return cache... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-01T17:57:00.133",
"Id": "21192",
"Score": "7",
"Tags": [
"javascript",
"cache",
"memoization"
],
"Title": "Elegant memoizing"
} | 21192 |
<p>My intent is to use Bash functions defined in <code>functions.sh</code> in a C program. I am doing this so that I don't have to rewrite the Bash functionality again in C. I want to use one common library for functions I need. Here is my C code and <code>functions.sh</code>.</p>
<pre><code>#include <stdlib.h>
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-02T01:32:58.863",
"Id": "34037",
"Score": "0",
"body": "Could you either post the real `functions.sh`, or remove that from your post (as it is extraneous if it doesn't have the actual code)?"
}
] | [
{
"body": "<h3>Comments</h3>\n\n<p>Because your question is marked <a href=\"/questions/tagged/clean-code\" class=\"post-tag\" title=\"show questions tagged 'clean-code'\" rel=\"tag\">clean-code</a> and I see that you have commented your declaration of the variable <code>command</code> with the comment <code>co... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-01T19:55:23.263",
"Id": "21197",
"Score": "4",
"Tags": [
"c",
"bash",
"linux"
],
"Title": "Need some advice and feedback on my C code calling Bash functions"
} | 21197 |
<p>For the past few days I've been working on a AES-128 encrypt/decipher class. I needed something very scaled down from <code>Cryptolib</code> so that I didn't have to constantly import the .lib file on all my programming computers (work, home, laptop1, laptop2). I've decided that since I will only every use AES-128 ... | [] | [
{
"body": "<p>Before I say anything else, I feel obligated to say that you should use the library. Writing bug-free Crypto code is hard and dangerous. The rule for Crypto code is generally that you shouldn't write it unless you are an expert (and even then, you want a LOT of eyes on it to check it). If this cod... | {
"AcceptedAnswerId": "21215",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-01T20:17:29.367",
"Id": "21200",
"Score": "3",
"Tags": [
"c++",
"cryptography",
"portability",
"aes"
],
"Title": "AES-128 encrypt/decipher class"
} | 21200 |
<p>I created a Letterpress solver that will take a string of letters and return a list of valid words that can be constructer with the provided letters. Not all letters need to be used in each word.</p>
<p>This works by reading all words into a list named <code>dictionary</code>, transforming that list of words into a... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-01T22:35:29.280",
"Id": "62798",
"Score": "0",
"body": "I wondered about if distinct was lazy too.\nAlso, the dictionary is much smaller why not loop through that and see what can be made?"
}
] | [
{
"body": "<p>The <code>(distinct (combo/combinations letters %))</code> looks mighty troublesome to me. I don't know what the complexity function is for combinations offhand, but I'm going to guess it's got a factorial in it. Using distinct around it means that you will hold that entire set of combinations in ... | {
"AcceptedAnswerId": "21203",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-01T20:50:08.400",
"Id": "21201",
"Score": "2",
"Tags": [
"clojure",
"combinatorics"
],
"Title": "Discovering words from letters in Clojure (Letterpress Solver)"
} | 21201 |
<p>I'm learning Node. I'm working on a personal project that uses Node + Express + Node-MySQL + Generic-Pool (for MySQL pooling). I am new to the idea of module.exports and I'm still grokking it.</p>
<p>The following code works. However I want to organize my code in a way that is logical and optimal, and MVCish. I... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-12-20T18:38:19.750",
"Id": "62929",
"Score": "1",
"body": "what is the last line of `app.js` supposed to do? It lacks either an identifier to replace `function()`, or the actual body of the function (with the required arguments)"
}
] | [
{
"body": "<p>Your code looks fine.</p>\n\n<p>However, you are not showing us much to review, definitely come back when there is more to review.</p>\n\n<p>Some minor comments:</p>\n\n<ul>\n<li>Having your db connection config through ./config/db is good</li>\n<li>You probably want to throw an exception if <code... | {
"AcceptedAnswerId": null,
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-01T21:01:27.497",
"Id": "21202",
"Score": "7",
"Tags": [
"javascript",
"beginner",
"mvc",
"node.js"
],
"Title": "node.js + Express code critique"
} | 21202 |
<p>How to get rid of that duplicaiton in <code>if</code> conditional?</p>
<pre><code>def set_caption(result)
if result.respond_to?(:app_name)
content_tag(:div, result.type_name, class: 'type-name') +
content_tag(:div, result.app_name, class: 'app-name')
else
content_tag(:div, result.type_name, class... | [] | [
{
"body": "<p>Just use variables for repeated expressions:</p>\n\n<pre><code>def set_caption(result)\n type_div = content_tag(:div, result.type_name, class: 'type-name') \n if result.respond_to?(:app_name)\n type_div + content_tag(:div, result.app_name, class: 'app-name')\n else\n type_div\n end\nend\... | {
"AcceptedAnswerId": "21226",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-01T22:19:00.313",
"Id": "21205",
"Score": "2",
"Tags": [
"ruby",
"ruby-on-rails"
],
"Title": "How to refactor that content_tag adding method?"
} | 21205 |
<p>I am writing a JavaScript/HTML driven web application. For the user interface, I am not completely sure that my JavaScript is 'OK'. Mainly, I switch between "modes" by assigning a placeholder variable to a new function, which changes what the onclick event does for items in a table (either open, edit, or move them).... | [] | [
{
"body": "<p>Readability - the code reads fine. The modes concept is explained well just by reading the code, so I wouldn't worry about that.</p>\n\n<p>Code style - Javascript programmers are used to passing functions around and probably wouldn't bat an eyelid at the idea of assigning different functions to a... | {
"AcceptedAnswerId": "24773",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-02T03:37:25.927",
"Id": "21213",
"Score": "3",
"Tags": [
"javascript",
"user-interface"
],
"Title": "JavaScript/HTML web application - user interface logic"
} | 21213 |
<p>This is my code:</p>
<pre><code>#include <stdio.h>
#include <ctype.h>
int average_of_let_wor();
int main(void)
{
double answer;
answer = average_of_let_wor();
printf("%.2lf", answer);
return 0;
}
int average_of_let_wor()
{
double numberOfLetters = 0;
double numberOfWords = 0;... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-02T12:40:21.560",
"Id": "34050",
"Score": "0",
"body": "And your question is?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-02T13:01:49.287",
"Id": "34051",
"Score": "0",
"body": "Hi, my quest... | [
{
"body": "<p>First of all, be careful with types: to compute an average something, you will need a floating point number. However, the number of letters and words are countable and can therefore use the type <code>unsigned int</code> which are generally faster than floating point numbers.</p>\n\n<p>Moreover, t... | {
"AcceptedAnswerId": "21230",
"CommentCount": "4",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-02T03:44:58.450",
"Id": "21214",
"Score": "2",
"Tags": [
"c"
],
"Title": "Using a function to find the average for number of letters and words"
} | 21214 |
<p>Is there any way to simplify this code with loops or anything? I'm a beginner at JavaScript and my code is horrible. Please don't tell me to convert to jQuery or anything.</p>
<pre><code> function dragLeftdropLeft1(ev) {
ev.preventDefault();
var data=ev.dataTransfer.getData("Left");
... | [] | [
{
"body": "<p>Abstract out the parts that are common to all of your functions. For instance:</p>\n\n<pre><code>function processEvent(evt, hideElem, showElem) {\n evt.preventDefault();\n document.getElementById(hideElem).style.display = \"none\";\n document.getElementById(showElem).style.display = \"bl... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-02T08:57:13.913",
"Id": "21218",
"Score": "5",
"Tags": [
"javascript",
"html"
],
"Title": "Chopsticks game using HTML and JavaScript"
} | 21218 |
<p>I've a web form that allows users to create clusters of three sizes: small, medium and large. The form is sending a string of small, medium or large to a message queue, were job dispatcher determines how many jobs (cluster elements) it should build for a given cluster, like that:</p>
<pre><code># determine required... | [] | [
{
"body": "<p>You could keep an array of jobs, and the web application would send index instead of word 'small', 'medium', 'large'.</p>\n\n<p>So you could have an array [3, 5, 8] and instead of \"small\" you send 0, instead of \"medium\" you send 1, and instead of \"large\" you send 2. You only need to check if... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-02T09:15:49.903",
"Id": "21219",
"Score": "2",
"Tags": [
"python",
"strings",
"form"
],
"Title": "Flexible multiple string comparision to determine variable value"
} | 21219 |
<p>Below is the code for knowing all the prime factors of a number. I think there must be some better way of doing the same thing. Also, please tell me if there are some flaws in my code.</p>
<pre><code>def factorize(num):
res2 = "%s: "%num
res = []
while num != 1:
for each in range(2, num + 1):
... | [] | [
{
"body": "<pre><code>def factorize(num):\n res2 = \"%s: \"%num\n</code></pre>\n\n<p>You'd be much better off to put the string stuff in a seperate function. Just have this function return the list of factors, i.e. <code>res</code> and have a second function take <code>res</code> as a parameter and return th... | {
"AcceptedAnswerId": "21231",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-02T13:15:50.493",
"Id": "21229",
"Score": "2",
"Tags": [
"python",
"primes"
],
"Title": "Code review needed for my Prime factorization code"
} | 21229 |
<p>I am writing a program that will deal with formatting the text in a text area. </p>
<p>The user will use Ctrl + A, Ctrl + C to copy the entirety of a web page, then paste that text into a text area. The program will take the text area, remove the junk, and output the important information to then be copied and past... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-02T16:59:12.377",
"Id": "34065",
"Score": "0",
"body": "I'm sorry, but Code Review is for improving code that works, not how to fix program so that it works. For more information, see the [FAQ]."
}
] | [
{
"body": "<p>I have done this a lot in php with <a href=\"http://php.net/manual/de/function.preg-match-all.php\" rel=\"nofollow noreferrer\">preg_match_all()</a>. But this should also work in <a href=\"https://stackoverflow.com/questions/520611/how-can-i-match-multiple-occurrences-with-a-regex-in-javascript-si... | {
"AcceptedAnswerId": "21233",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-02T16:35:26.957",
"Id": "21232",
"Score": "-2",
"Tags": [
"javascript",
"parsing"
],
"Title": "Parsing large text area - difficulty extracting info - Javascript"
} | 21232 |
<p>Matlab profiler throws this horrible bottleneck which is called 700000 times:</p>
<pre><code>for k =1:model.nlf,
for r =1:model.nlf,
KuyDinvKyu = zeros(model.k,model.k);
for q =1:model.nout,
KuyDinvKyu = KuyDinvKyu + model.KuyDinv{k,q}*model.Kyu{q,r};
end
if (k == r)
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-27T17:50:35.673",
"Id": "34069",
"Score": "2",
"body": "some dimensions and sizes can be useful here. What are `size(model.KuyDinv{k,q})`, `size(model.Kyu{q,r})` and `size(model.Kuu{k})`?"
},
{
"ContentLicense": "CC BY-SA 3.0",... | [
{
"body": "<p>You will get a speed up by eliminating the if-statements in the inner loop. E.g. by splitting the inner loop via</p>\n\n<pre><code> for r = setdiff(1:model.nlf,k)\n %do the stuff to setup Model.A{k,r}\n end\n\n model.A{k,k} = ...\n</code></pre>\n",
"comments": [
{
... | {
"AcceptedAnswerId": null,
"CommentCount": "7",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-01-27T17:32:27.320",
"Id": "21234",
"Score": "2",
"Tags": [
"statistics",
"matlab"
],
"Title": "Calculating the posterior distribution in multivariate Gaussian processes"
} | 21234 |
<p>I've written a framework in MVC. I call it Midget MVC, as it's so darn small. The reason I wrote it is because I wanted a lightweight and extensible framework to use in projects. It eventually got abandoned due to it's break-ability and my lack of experience in the subject. However, I've got a bigger project I'm wor... | [] | [
{
"body": "<p>Nice initiative on a lightweight MVC framework!</p>\n\n<p><em><strong>Note</em></strong> wanted to add more reference links, but it won't allow me to do more thanb 2</p>\n\n<h2>Config</h2>\n\n<ul>\n<li>Pass the default controller setting to the function </li>\n</ul>\n\n<p><em>or</em> </p>\n\n<ul>\... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-02T19:22:54.047",
"Id": "21237",
"Score": "3",
"Tags": [
"php",
"mvc",
"pdo",
"url-routing"
],
"Title": "Breakable MVC framework written in PHP"
} | 21237 |
<pre><code>def divisible?(n)
if n % 1 == 0 &&
n % 2 == 0 &&
n % 3 == 0 &&
n % 4 == 0 &&
n % 5 == 0 &&
n % 6 == 0 &&
n % 7 == 0 &&
n % 8 == 0 &&
n % 9 == 0 &&
n % 10 == 0 &&
n % 11 == 0 &&
... | [] | [
{
"body": "<p>Ruby refactor: use <a href=\"http://ruby-doc.org/core-1.9.3/Enumerable.html#method-i-all-3F\" rel=\"nofollow\">Enumerable.all?</a>:</p>\n\n<pre><code>def divisible?(n)\n (1..20).all? { |x| n % x == 0 }\nend\n</code></pre>\n\n<p>Mathematical refactor:calculate the least common multiple of the inte... | {
"AcceptedAnswerId": "21240",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-02T21:05:54.407",
"Id": "21238",
"Score": "6",
"Tags": [
"ruby",
"mathematics"
],
"Title": "Simplify test for divisibility by all numbers 1…20"
} | 21238 |
<p>I put this together and it seems to work.</p>
<p>1channel.py -breakingbad 1</p>
<p>The Output (1-10): </p>
<pre><code>(1) - Currently 3.80/5
(2) - Currently 3.50/5
</code></pre>
<p>(1 opens the link in browser)</p>
<p>If anyone has any suggestions or wants to improve it:</p>
<pre><code>from bs4 import Beau... | [] | [
{
"body": "<p>Here's what I would start with:</p>\n\n<pre><code>import sys\nimport re\nimport urllib2\nimport webbrowser\n\nfrom bs4 import BeautifulSoup\n\ndef get_episodes(url):\n print '[*] Working...'\n\n soup = BeautifulSoup(urllib2.urlopen(url))\n links = {}\n\n for table in soup.find_all('tab... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-02T21:06:03.737",
"Id": "21239",
"Score": "4",
"Tags": [
"python",
"beginner",
"web-scraping",
"beautifulsoup",
"webdriver"
],
"Title": "Opening TV episodes in a web browser"... | 21239 |
<p>My question is really simple. Does this code cause memoryleaks? If so, where/how/why?</p>
<pre><code>HDC hDC, memDC = 0;
HBITMAP hBMP = 0;
HBITMAP hOldBMP = 0;
PAINTSTRUCT PS;
HBRUSH hb212121, hb141414, hb070707, hb000, hbF7F7F7, hb989898, hb707070, hb494949, hb984921 = 0;
HPEN hp353535 = 0;
case WM_PAINT:
... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-03T06:10:43.337",
"Id": "34095",
"Score": "0",
"body": "Have you seen anything to suggest that this code *does* cause a memory leak?"
}
] | [
{
"body": "<ul>\n<li><p>you select the pen in, but don't select out before delete.</p>\n\n<pre><code>SelectObject(memDC, hp353535);\n// snip\nDeleteObject(hp353535)\n</code></pre>\n\n<p>should be:</p>\n\n<pre><code>hOldPen = SelectObject(memDC, hp353535);\n// snip\nSelectObject( memDC, hOldPen );\nDeleteObject(... | {
"AcceptedAnswerId": "21246",
"CommentCount": "1",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-03T04:19:53.813",
"Id": "21243",
"Score": "2",
"Tags": [
"c++",
"memory-management",
"windows"
],
"Title": "Would this code cause memoryleaks?"
} | 21243 |
<p>I'm working on my first web app and would like some feedback on the code I have completed. I asked for a similar code review a few weeks ago but I have since improved my structure and added some user adjustable settings.</p>
<p>The app is a simple math quiz (addition, subtraction, multiplication, & division que... | [] | [
{
"body": "<p>If you introduced a client-side MVVM framework, I think you would get the modularization that you are looking for. I have worked with, and really enjoy, <a href=\"http://knockoutjs.com/\" rel=\"nofollow\">knockout</a>. Each frame could have it's own viewmodel, and you could create a single viewm... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-03T07:24:18.353",
"Id": "21244",
"Score": "2",
"Tags": [
"javascript",
"html5",
"quiz"
],
"Title": "Simple four-function math quiz"
} | 21244 |
<p>I'm brand new to AngularJS. I would like advice as to whether I'm approaching the design of a simple login section of an app built with Angular correctly.</p>
<p>The app consists of two view partials: <em>login.html</em> and <em>user-admin.html</em>. Of what I have so far, the user types their username into the log... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-28T13:19:37.030",
"Id": "43497",
"Score": "1",
"body": "do you have a working example fo this?"
},
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-06-28T17:43:53.160",
"Id": "43513",
"Score": "0",
"bod... | [
{
"body": "<p>There is much wrong with your code..</p>\n\n<ul>\n<li>You are iterating over every record to find a username, what happens if you have lots of users ?</li>\n<li>You are not verifying the password !?</li>\n<li>It seems like you are exposing the REST services with all the user id's and passwords !?<... | {
"AcceptedAnswerId": null,
"CommentCount": "3",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-03T08:24:11.457",
"Id": "21245",
"Score": "3",
"Tags": [
"javascript",
"mvc",
"angular.js"
],
"Title": "Creating a simple login with AngularJS"
} | 21245 |
<p>I would really like some advice from any DB gurus who have a few minutes free. After doing some reading and playing with sqlfiddle over the weekend I have constructed this PostgreSQL schema and it is the first proper one I've ever done, so I am sure I've made some poor choices.</p>
<p>This is what I've got for a "j... | [] | [
{
"body": "<p>This seems pretty good to me (disclaimer : I am NOT a Database guru).</p>\n\n<ul>\n<li><p>for payment.amount, it would be worth using something more relevant than varchar. You can have a look at the DO question <a href=\"https://stackoverflow.com/questions/628637/best-data-type-for-currency\">Best... | {
"AcceptedAnswerId": null,
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-03T10:57:35.007",
"Id": "21247",
"Score": "2",
"Tags": [
"sql",
"database",
"finance",
"postgresql",
"web-services"
],
"Title": "Payment application database"
} | 21247 |
<p>My conditional code here seems repetitive and long. Is there a better approach? I want to test for a string value in a <code>NSDictionary</code> object and then depending upon the value prefix a <code>UILabel</code> with $, £, ¥ currency symbols.</p>
<p>I've just shown 2 examples below. I have more currencies and ... | [] | [
{
"body": "<p>I'd create an NSDictionary holding those prefixes and wrap that whole thing into its own method, like so: </p>\n\n<pre><code>-(NSString *) prefixForCurrency:(NSString *)currency{\n NSDictionary *currencyPrefixes = @{@\"EUR\": @\"€\", @\"USD\" : @\"$\", @\"GBP\" : @\"£\", @\"NOK\" : @\"kr.\" };\... | {
"AcceptedAnswerId": "21250",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-03T11:38:15.483",
"Id": "21249",
"Score": "3",
"Tags": [
"strings",
"objective-c",
"ios",
"hash-map"
],
"Title": "Applying a currency symbol based on a tested string value"
} | 21249 |
<p>I have to do some encoding and then assign the result to a label. Is there a more optimal (or concise) way to write this?</p>
<pre><code>// encoding fix
NSString *correctStringTitle = [NSString stringWithCString: [[item objectForKey:@"main_tag"] cStringUsingEncoding:NSISOLatin1StringEncoding]
... | [] | [
{
"body": "<p>Here is a marginally more concise solution:</p>\n\n<pre><code>cell.titleLabel.text = [NSString stringWithCString:[[item[@\"main_tag\"] cStringUsingEncoding:NSISOLatin1StringEncoding] encoding:NSUTF8StringEncoding].capitalizedString;\n</code></pre>\n\n<p>If I had to do this more than once I would c... | {
"AcceptedAnswerId": "22871",
"CommentCount": "0",
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-03T15:00:44.293",
"Id": "21251",
"Score": "1",
"Tags": [
"objective-c",
"ios"
],
"Title": "Encoding and assigning the result to a label"
} | 21251 |
<p>I wrote a program to find the longest common subsequence among several strings. I used a naive algorithm and implementation.</p>
<p>The motivation was solving the Rosalind problem at <a href="http://rosalind.info/problems/lcs/" rel="nofollow noreferrer">http://rosalind.info/problems/lcs/</a> . You can find sample in... | [
{
"ContentLicense": "CC BY-SA 3.0",
"CreationDate": "2013-02-04T19:29:22.613",
"Id": "34193",
"Score": "0",
"body": "Nothing major for me. Just your one place using new_lcs instead of camel casing. Pretty consistent everywhere else though."
},
{
"ContentLicense": "CC BY-SA 4.0",
"C... | [
{
"body": "<p>Firstly some style.</p>\n\n<p>Short named variables don't help readability at all. <code>c1</code>, <code>c2</code>, <code>s1</code>, <code>s2</code> are a bad idea. I know this is just a challenge and not production code but keeping a consistent style is a good habit.</p>\n\n<p>Secondly I would s... | {
"AcceptedAnswerId": null,
"CommentCount": "2",
"ContentLicense": "CC BY-SA 4.0",
"CreationDate": "2013-02-03T17:54:40.570",
"Id": "21252",
"Score": "7",
"Tags": [
"c#",
"programming-challenge",
"strings",
"bioinformatics"
],
"Title": "Longest common substring"
} | 21252 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.